1
2
3
4 """
5 Display any help (and code sample) available for the functions and
6 libraries that can be used in the shells and scripts.
7 """
8
9 import sys
10
11
12 import logging
13 import logging.handlers
14
15
16 import webbrowser
17
18
19 import wx
20 import wx.html as html
21 import wx.py.dispatcher as dispatcher
22
23 import lab_settings
24 from mathbench.basement.librarian import LibrarianSingleton
25
26
28 """
29 Catch the links that are cicked and send them to the platform's
30 web browser.
31 """
32
34 html.HtmlWindow.__init__(self, parent, id, style=wx.NO_FULL_REPAINT_ON_RESIZE)
35 if "gtk2" in wx.PlatformInfo:
36 self.SetStandardFonts()
37
39
40 if sys.version_info>=(2,5):
41 webbrowser.open_new_tab(linkinfo.GetHref())
42 else:
43 webbrowser.open_new(linkinfo.GetHref())
44
46 """
47 The library desk from where all info can be reach.
48
49 Handles search queries, page history, search history...
50 """
51
52
54 """
55 Create the html widget.
56
57 This widget remains callable through 'self.html'.
58 """
59 wx.InitAllImageHandlers()
60 self.html = OokOokHtmlWindow(parent=self)
61 if "gtk2" in wx.PlatformInfo:
62 self.html.SetStandardFonts()
63
65 """
66 Create the bar gathering all naviation items.
67 """
68 self.navbar = wx.BoxSizer(wx.HORIZONTAL)
69
70
71
72 tb = self.CreateToolBar( wx.TB_HORIZONTAL
73 | wx.NO_BORDER
74 | wx.TB_FLAT
75 | wx.TB_TEXT
76 )
77
78 tb_img_size = (16,16)
79 tb.SetToolBitmapSize(tb_img_size)
80
81
82 img = wx.ArtProvider_GetBitmap(wx.ART_GO_BACK,
83 wx.ART_TOOLBAR,
84 tb_img_size)
85 tb.AddSimpleTool(10,img,"Back","Go to previous page.")
86 self.Bind(wx.EVT_TOOL, self.OnToolClick, id=10)
87
88
89 img = wx.ArtProvider_GetBitmap(wx.ART_GO_FORWARD,
90 wx.ART_TOOLBAR,
91 tb_img_size)
92 tb.AddSimpleTool(20,img,"Forward","Go to next page.")
93 self.Bind(wx.EVT_TOOL, self.OnToolClick, id=20)
94
95 tb.AddSeparator()
96
97
98 img = wx.ArtProvider_GetBitmap(wx.ART_GO_HOME,
99 wx.ART_TOOLBAR,
100 tb_img_size)
101 tb.AddSimpleTool(50,img,"Home","Go to welcome page.")
102 self.Bind(wx.EVT_TOOL, self.OnToolClick, id=50)
103
104
105 dummylongtext = wx.StaticText(self,-1,"Type your query and press 'Enter'Type your query and press 'Enter'")
106 dummylongtext.Fit()
107 nice_width = dummylongtext.GetBestSize().width
108 dummylongtext.Hide()
109
110
111
112
113 self.query_widget = wx.ComboBox(
114 parent=tb, size = wx.Size(nice_width,-1),
115 style=wx.CB_DROPDOWN
116 )
117
118 self.query_widget.Bind(wx.EVT_TEXT_ENTER, self.OnQueryKeyDown)
119 self.query_widget.SetValue("Type your query and press 'Enter'")
120 self.query_widget.SelectAll()
121 tb.AddControl(self.query_widget)
122
123
124 img = wx.ArtProvider_GetBitmap(wx.ART_DELETE,
125 wx.ART_TOOLBAR,
126 tb_img_size)
127 tb.AddSimpleTool(30,img,"Clear","Clear the search form.")
128 self.Bind(wx.EVT_TOOL, self.OnToolClick, id=30)
129
130
131 img = wx.ArtProvider_GetBitmap(wx.ART_FIND,
132 wx.ART_TOOLBAR,
133 tb_img_size)
134 tb.AddSimpleTool(35,img,"Search","Answer your query.")
135 self.Bind(wx.EVT_TOOL, self.OnToolClick, id=35)
136
137 tb.AddSeparator()
138
139
140
141 self.printer = html.HtmlEasyPrinting()
142
143 img = wx.ArtProvider_GetBitmap(wx.ART_PRINT,
144 wx.ART_TOOLBAR,
145 tb_img_size)
146 tb.AddSimpleTool(40,img,"Print","Print current page.")
147 self.Bind(wx.EVT_TOOL, self.OnToolClick, id=40)
148
149
150
151 tb.Realize()
152
153
154 - def __init__(self, title="Library Desk", parent=None):
155
156 wx.Frame.__init__(self, parent, -1, title, size=wx.Size(800,600))
157
158 self.CreateStatusBar()
159
160
161 self._init_html_window()
162
163 self._init_navbar()
164
165
166 self.main_sizer = wx.BoxSizer(wx.VERTICAL)
167 self.main_sizer.Add(self.html, proportion=1, flag=wx.GROW)
168
169 self.SetSizer(self.main_sizer)
170 self.SetAutoLayout(True)
171
172 self.Bind(wx.EVT_CLOSE,self.OnClose)
173
174 wx.CallAfter(self.query_widget.SetFocus)
175 self.SetIcon(wx.ArtProvider().GetIcon(wx.ART_HELP_BOOK))
176 self.Show()
177
178 - def showPage(self,page_txt):
179 """
180 Show an html page
181 """
182 self.html.SetPage(page_txt)
183
184 - def addToHistory(self,query_txt):
185 """
186 Add an element to the search history.
187 """
188 self.query_widget.Append(query_txt,query_txt.upper())
189
190
191
193 """
194 When the frame is closed
195 """
196 dispatcher.send(signal='LibraryDeskClosed', sender=self)
197 event.Skip()
198
225
227 """
228 When user clicks on enter while typing in the query widget,
229 then launch the search !
230 """
231 LibrarianSingleton.search(self.query_widget.GetValue())
232 event.Skip()
233
234
235
236
237 if __name__ == "__main__":
238 app = wx.PySimpleApp()
240 """
241 Sample desk factory
242 """
243 return LibraryDeskHTML("Ooook!")
244
245 LibrarianSingleton.setDeskFactory(createDesk)
246 LibrarianSingleton.welcome()
247 app.MainLoop()
248