1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import os.path
20
21 import wx
22 import wx.html
23
24 from timelinelib.config.paths import HELP_RESOURCES_DIR
25 from timelinelib.config.paths import ICONS_DIR
26 from timelinelib.wxgui.utils import _display_error_message
27
28
30
31 HOME_ID = 10
32 BACKWARD_ID = 20
33 FORWARD_ID = 30
34
36 wx.Frame.__init__(self, parent, title=_("Help"),
37 size=(600, 550), style=wx.DEFAULT_FRAME_STYLE)
38 self.history = []
39 self.current_pos = -1
40 self._create_help_system()
41 self._create_gui()
42 self._update_buttons()
43
55
56 - def show_page(self, id, type="page", change_history=True):
57 """
58 Where which is a tuple (type, id):
59
60 * (page, page_id)
61 * (search, search_string)
62 """
63 if self.help_system is None:
64 _display_error_message(
65 _("Could not find markdown Python package. It is needed by the help system. See the Timeline website or the INSTALL file for instructions how to install it."),
66 self.GetParent())
67 return
68 if change_history:
69 same_page_as_last = False
70 if self.current_pos != -1:
71 current_type, current_id = self.history[self.current_pos]
72 if id == current_id:
73 same_page_as_last = True
74 if same_page_as_last == False:
75 self.history = self.history[:self.current_pos + 1]
76 self.history.append((type, id))
77 self.current_pos += 1
78 self._update_buttons()
79 if type == "page":
80 self.html_window.SetPage(self._generate_page(id))
81 elif type == "search":
82 self.html_window.SetPage(self.help_system.get_search_results_page(id))
83 self.Show()
84 self.Raise()
85
87 self.Bind(wx.EVT_CLOSE, self._window_on_close)
88 self.toolbar = self.CreateToolBar()
89 size = (24, 24)
90 if 'wxMSW' in wx.PlatformInfo:
91 home_bmp = wx.Bitmap(os.path.join(ICONS_DIR, "home.png"))
92 back_bmp = wx.Bitmap(os.path.join(ICONS_DIR, "backward.png"))
93 forward_bmp = wx.Bitmap(os.path.join(ICONS_DIR, "forward.png"))
94 else:
95 home_bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_HOME, wx.ART_TOOLBAR,
96 size)
97 back_bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_BACK, wx.ART_TOOLBAR,
98 size)
99 forward_bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_FORWARD,
100 wx.ART_TOOLBAR, size)
101 self.toolbar.SetToolBitmapSize(size)
102
103 home_str = _("Go to home page")
104 self.toolbar.AddLabelTool(HelpBrowser.HOME_ID, home_str,
105 home_bmp, shortHelp=home_str)
106 self.Bind(wx.EVT_TOOL, self._toolbar_on_click, id=HelpBrowser.HOME_ID)
107
108 self.toolbar.AddSeparator()
109
110 backward_str = _("Go back one page")
111 self.toolbar.AddLabelTool(HelpBrowser.BACKWARD_ID, backward_str,
112 back_bmp, shortHelp=backward_str)
113 self.Bind(wx.EVT_TOOL, self._toolbar_on_click,
114 id=HelpBrowser.BACKWARD_ID)
115
116 forward_str = _("Go forward one page")
117 self.toolbar.AddLabelTool(HelpBrowser.FORWARD_ID, forward_str,
118 forward_bmp, shortHelp=forward_str)
119 self.Bind(wx.EVT_TOOL, self._toolbar_on_click,
120 id=HelpBrowser.FORWARD_ID)
121
122 self.toolbar.AddSeparator()
123
124 self.search = wx.SearchCtrl(self.toolbar, size=(150, -1),
125 style=wx.TE_PROCESS_ENTER)
126 self.Bind(wx.EVT_TEXT_ENTER, self._search_on_text_enter, self.search)
127 self.toolbar.AddControl(self.search)
128 self.toolbar.Realize()
129
130 self.html_window = wx.html.HtmlWindow(self)
131 self.Bind(wx.html.EVT_HTML_LINK_CLICKED,
132 self._html_window_on_link_clicked, self.html_window)
133 self.html_window.Connect(wx.ID_ANY, wx.ID_ANY, wx.EVT_KEY_DOWN.typeId,
134 self._window_on_key_down)
135
138
140 """
141 Event handler used when a keyboard key has been pressed.
142
143 The following keys are handled:
144 Key Action
145 -------- ------------------------------------
146 Backspace Go to previous page
147 """
148 keycode = evt.GetKeyCode()
149 if keycode == wx.WXK_BACK:
150 self._go_back()
151 evt.Skip()
152
160
162 self._search(self.search.GetValue())
163
165 url = e.GetLinkInfo().GetHref()
166 if url.startswith("page:"):
167 self.show_page(url[5:])
168 else:
169 pass
170
171
173 self.show_page(self.help_system.home_page)
174
176 if self.current_pos > 0:
177 self.current_pos -= 1
178 current_type, current_id = self.history[self.current_pos]
179 self.show_page(current_id, type=current_type, change_history=False)
180
182 if self.current_pos < len(self.history) - 1:
183 self.current_pos += 1
184 current_type, current_id = self.history[self.current_pos]
185 self.show_page(current_id, type=current_type, change_history=False)
186
189
196
197 - def _generate_page(self, id):
198 page = self.help_system.get_page(id)
199 if page == None:
200 error_page_html = "<h1>%s</h1><p>%s</p>" % (
201 _("Page not found"),
202 _("Could not find page '%s'.") % id)
203 return self._wrap_in_html(error_page_html)
204 else:
205 return self._wrap_in_html(page.render_to_html())
206
208 HTML_SKELETON = """
209 <html>
210 <head>
211 </head>
212 <body>
213 %s
214 </body>
215 </html>
216 """
217 return HTML_SKELETON % content
218