ghelp.py 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  1. """!
  2. @package help.py
  3. @brief Help window
  4. Classes:
  5. - SearchModuleWindow
  6. - ItemTree
  7. - MenuTreeWindow
  8. - MenuTree
  9. - AboutWindow
  10. - InstallExtensionWindow
  11. - ExtensionTree
  12. - HelpFrame
  13. - HelpWindow
  14. - HelpPanel
  15. (C) 2008-2010 by the GRASS Development Team
  16. This program is free software under the GNU General Public License
  17. (>=v2). Read the file COPYING that comes with GRASS for details.
  18. @author Martin Landa <landa.martin gmail.com>
  19. """
  20. import os
  21. import wx
  22. try:
  23. import wx.lib.agw.customtreectrl as CT
  24. # import wx.lib.agw.hyperlink as hl
  25. except ImportError:
  26. import wx.lib.customtreectrl as CT
  27. # import wx.lib.hyperlink as hl
  28. import wx.lib.flatnotebook as FN
  29. import wx.lib.scrolledpanel as scrolled
  30. import menudata
  31. import gcmd
  32. import globalvar
  33. import gdialogs
  34. class HelpFrame(wx.Frame):
  35. """!GRASS Quickstart help window"""
  36. def __init__(self, parent, id, title, size, file):
  37. wx.Frame.__init__(self, parent=parent, id=id, title=title, size=size)
  38. sizer = wx.BoxSizer(wx.VERTICAL)
  39. # text
  40. content = HelpPanel(parent = self)
  41. content.LoadPage(file)
  42. sizer.Add(item = content, proportion=1, flag=wx.EXPAND)
  43. self.SetAutoLayout(True)
  44. self.SetSizer(sizer)
  45. self.Layout()
  46. class SearchModuleWindow(wx.Panel):
  47. """!Search module window (used in MenuTreeWindow)"""
  48. def __init__(self, parent, id = wx.ID_ANY, cmdPrompt = None,
  49. showChoice = True, showTip = False, **kwargs):
  50. self.showTip = showTip
  51. self.showChoice = showChoice
  52. self.cmdPrompt = cmdPrompt
  53. wx.Panel.__init__(self, parent = parent, id = id, **kwargs)
  54. self._searchDict = { _('description') : 'description',
  55. _('command') : 'command',
  56. _('keywords') : 'keywords' }
  57. self.box = wx.StaticBox(parent = self, id = wx.ID_ANY,
  58. label=" %s " % _("Find module(s)"))
  59. self.searchBy = wx.Choice(parent = self, id = wx.ID_ANY,
  60. choices = [_('description'),
  61. _('keywords'),
  62. _('command')])
  63. self.searchBy.SetSelection(0)
  64. self.search = wx.TextCtrl(parent = self, id = wx.ID_ANY,
  65. value = "", size = (-1, 25),
  66. style = wx.TE_PROCESS_ENTER)
  67. self.search.Bind(wx.EVT_TEXT, self.OnSearchModule)
  68. if self.showTip:
  69. self.searchTip = gdialogs.StaticWrapText(parent = self, id = wx.ID_ANY,
  70. size = (-1, 35))
  71. if self.showChoice:
  72. self.searchChoice = wx.Choice(parent = self, id = wx.ID_ANY)
  73. if self.cmdPrompt:
  74. self.searchChoice.SetItems(self.cmdPrompt.GetCommandItems())
  75. self.searchChoice.Bind(wx.EVT_CHOICE, self.OnSelectModule)
  76. self._layout()
  77. def _layout(self):
  78. """!Do layout"""
  79. sizer = wx.StaticBoxSizer(self.box, wx.HORIZONTAL)
  80. gridSizer = wx.GridBagSizer(hgap = 3, vgap = 3)
  81. gridSizer.AddGrowableCol(1)
  82. gridSizer.Add(item = self.searchBy,
  83. flag=wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
  84. gridSizer.Add(item = self.search,
  85. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, pos = (0, 1))
  86. row = 1
  87. if self.showTip:
  88. gridSizer.Add(item = self.searchTip,
  89. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, pos = (row, 0), span = (1, 2))
  90. row += 1
  91. if self.showChoice:
  92. gridSizer.Add(item = self.searchChoice,
  93. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, pos = (row, 0), span = (1, 2))
  94. sizer.Add(item = gridSizer, proportion = 1)
  95. self.SetSizer(sizer)
  96. sizer.Fit(self)
  97. def GetSelection(self):
  98. """!Get selected element"""
  99. selection = self.searchBy.GetStringSelection()
  100. return self._searchDict[selection]
  101. def SetSelection(self, i):
  102. """!Set selection element"""
  103. self.searchBy.SetSelection(i)
  104. def OnSearchModule(self, event):
  105. """!Search module by keywords or description"""
  106. if not self.cmdPrompt:
  107. event.Skip()
  108. return
  109. text = event.GetString()
  110. if not text:
  111. self.cmdPrompt.SetFilter(None)
  112. mList = self.cmdPrompt.GetCommandItems()
  113. self.searchChoice.SetItems(mList)
  114. if self.showTip:
  115. self.searchTip.SetLabel(_("%d modules found") % len(mList))
  116. event.Skip()
  117. return
  118. modules = dict()
  119. iFound = 0
  120. for module, data in self.cmdPrompt.moduleDesc.iteritems():
  121. found = False
  122. sel = self.searchBy.GetSelection()
  123. if sel == 0: # -> description
  124. if text in data['desc']:
  125. found = True
  126. elif sel == 1: # keywords
  127. if self.cmdPrompt.CheckKey(text, data['keywords']):
  128. found = True
  129. else: # command
  130. if module[:len(text)] == text:
  131. found = True
  132. if found:
  133. iFound += 1
  134. try:
  135. group, name = module.split('.')
  136. except ValueError:
  137. continue # TODO
  138. if not modules.has_key(group):
  139. modules[group] = list()
  140. modules[group].append(name)
  141. self.cmdPrompt.SetFilter(modules)
  142. self.searchChoice.SetItems(self.cmdPrompt.GetCommandItems())
  143. if self.showTip:
  144. self.searchTip.SetLabel(_("%d modules found") % iFound)
  145. event.Skip()
  146. def OnSelectModule(self, event):
  147. """!Module selected from choice, update command prompt"""
  148. cmd = event.GetString().split(' ', 1)[0]
  149. text = cmd + ' '
  150. pos = len(text)
  151. if self.cmdPrompt:
  152. self.cmdPrompt.SetText(text)
  153. self.cmdPrompt.SetSelectionStart(pos)
  154. self.cmdPrompt.SetCurrentPos(pos)
  155. self.cmdPrompt.SetFocus()
  156. desc = self.cmdPrompt.GetCommandDesc(cmd)
  157. if self.showTip:
  158. self.searchTip.SetLabel(desc)
  159. def Reset(self):
  160. """!Reset widget"""
  161. self.searchBy.SetSelection(0)
  162. self.search.SetValue('')
  163. class MenuTreeWindow(wx.Panel):
  164. """!Show menu tree"""
  165. def __init__(self, parent, id = wx.ID_ANY, **kwargs):
  166. self.parent = parent # LayerManager
  167. wx.Panel.__init__(self, parent = parent, id = id, **kwargs)
  168. self.dataBox = wx.StaticBox(parent = self, id = wx.ID_ANY,
  169. label=" %s " % _("Menu tree (double-click to run command)"))
  170. # tree
  171. self.tree = MenuTree(parent = self, data = menudata.ManagerData())
  172. self.tree.Load()
  173. # search widget
  174. self.search = SearchModuleWindow(parent = self, showChoice = False)
  175. # buttons
  176. self.btnRun = wx.Button(self, id = wx.ID_OK, label = _("&Run"))
  177. self.btnRun.SetToolTipString(_("Run selected command"))
  178. self.btnRun.Enable(False)
  179. # bindings
  180. self.btnRun.Bind(wx.EVT_BUTTON, self.OnRun)
  181. self.tree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnItemActivated)
  182. self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnItemSelected)
  183. self.search.Bind(wx.EVT_TEXT_ENTER, self.OnShowItem)
  184. self.search.Bind(wx.EVT_TEXT, self.OnUpdateStatusBar)
  185. self._layout()
  186. self.search.SetFocus()
  187. def _layout(self):
  188. """!Do dialog layout"""
  189. sizer = wx.BoxSizer(wx.VERTICAL)
  190. # body
  191. dataSizer = wx.StaticBoxSizer(self.dataBox, wx.HORIZONTAL)
  192. dataSizer.Add(item = self.tree, proportion =1,
  193. flag = wx.EXPAND)
  194. # buttons
  195. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  196. btnSizer.Add(item = self.btnRun, proportion = 0)
  197. sizer.Add(item = dataSizer, proportion = 1,
  198. flag = wx.EXPAND | wx.ALL, border = 5)
  199. sizer.Add(item = self.search, proportion=0,
  200. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
  201. sizer.Add(item = btnSizer, proportion=0,
  202. flag = wx.ALIGN_RIGHT | wx.BOTTOM | wx.RIGHT, border = 5)
  203. sizer.Fit(self)
  204. sizer.SetSizeHints(self)
  205. self.SetSizer(sizer)
  206. self.Fit()
  207. self.SetAutoLayout(True)
  208. self.Layout()
  209. def OnCloseWindow(self, event):
  210. """!Close window"""
  211. self.Destroy()
  212. def OnRun(self, event):
  213. """!Run selected command"""
  214. if not self.tree.GetSelected():
  215. return # should not happen
  216. data = self.tree.GetPyData(self.tree.GetSelected())
  217. if not data:
  218. return
  219. handler = 'self.parent.' + data['handler'].lstrip('self.')
  220. if data['handler'] == 'self.OnXTerm':
  221. wx.MessageBox(parent = self,
  222. message = _('You must run this command from the menu or command line',
  223. 'This command require an XTerm'),
  224. caption = _('Message'), style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
  225. elif data['command']:
  226. eval(handler)(event = None, cmd = data['command'].split())
  227. else:
  228. eval(handler)(None)
  229. def OnShowItem(self, event):
  230. """!Show selected item"""
  231. self.tree.OnShowItem(event)
  232. if self.tree.GetSelected():
  233. self.btnRun.Enable()
  234. else:
  235. self.btnRun.Enable(False)
  236. def OnItemActivated(self, event):
  237. """!Item activated (double-click)"""
  238. item = event.GetItem()
  239. if not item or not item.IsOk():
  240. return
  241. data = self.tree.GetPyData(item)
  242. if not data or not data.has_key('command'):
  243. return
  244. self.tree.itemSelected = item
  245. self.OnRun(None)
  246. def OnItemSelected(self, event):
  247. """!Item selected"""
  248. item = event.GetItem()
  249. if not item or not item.IsOk():
  250. return
  251. data = self.tree.GetPyData(item)
  252. if not data or not data.has_key('command'):
  253. return
  254. if data['command']:
  255. label = data['command'] + ' -- ' + data['description']
  256. else:
  257. label = data['description']
  258. self.parent.SetStatusText(label, 0)
  259. def OnUpdateStatusBar(self, event):
  260. """!Update statusbar text"""
  261. element = self.search.GetSelection()
  262. self.tree.SearchItems(element = element,
  263. value = event.GetString())
  264. nItems = len(self.tree.itemsMarked)
  265. if event.GetString():
  266. self.parent.SetStatusText(_("%d modules match") % nItems, 0)
  267. else:
  268. self.parent.SetStatusText("", 0)
  269. event.Skip()
  270. class ItemTree(CT.CustomTreeCtrl):
  271. def __init__(self, parent, id = wx.ID_ANY,
  272. ctstyle = CT.TR_HIDE_ROOT | CT.TR_FULL_ROW_HIGHLIGHT | CT.TR_HAS_BUTTONS |
  273. CT.TR_LINES_AT_ROOT | CT.TR_SINGLE, **kwargs):
  274. if 'style' in kwargs:
  275. ctstyle |= kwargs['style']
  276. del kwargs['style']
  277. super(ItemTree, self).__init__(parent, id, style = ctstyle, **kwargs)
  278. self.root = self.AddRoot(_("Menu tree"))
  279. self.itemsMarked = [] # list of marked items
  280. self.itemSelected = None
  281. def SearchItems(self, element, value):
  282. """!Search item
  283. @param element element index (see self.searchBy)
  284. @param value
  285. @return list of found tree items
  286. """
  287. items = list()
  288. if not value:
  289. return items
  290. item = self.GetFirstChild(self.root)[0]
  291. self._processItem(item, element, value, items)
  292. self.itemsMarked = items
  293. self.itemSelected = None
  294. return items
  295. def _processItem(self, item, element, value, listOfItems):
  296. """!Search items (used by SearchItems)
  297. @param item reference item
  298. @param listOfItems list of found items
  299. """
  300. while item and item.IsOk():
  301. subItem = self.GetFirstChild(item)[0]
  302. if subItem:
  303. self._processItem(subItem, element, value, listOfItems)
  304. data = self.GetPyData(item)
  305. if data and data.has_key(element) and \
  306. value.lower() in data[element].lower():
  307. listOfItems.append(item)
  308. item = self.GetNextSibling(item)
  309. def GetSelected(self):
  310. """!Get selected item"""
  311. return self.itemSelected
  312. def OnShowItem(self, event):
  313. """!Highlight first found item in menu tree"""
  314. if len(self.itemsMarked) > 0:
  315. if self.GetSelected():
  316. self.ToggleItemSelection(self.GetSelected())
  317. idx = self.itemsMarked.index(self.GetSelected()) + 1
  318. else:
  319. idx = 0
  320. try:
  321. self.ToggleItemSelection(self.itemsMarked[idx])
  322. self.itemSelected = self.itemsMarked[idx]
  323. self.EnsureVisible(self.itemsMarked[idx])
  324. except IndexError:
  325. self.ToggleItemSelection(self.itemsMarked[0]) # reselect first item
  326. self.EnsureVisible(self.itemsMarked[0])
  327. self.itemSelected = self.itemsMarked[0]
  328. else:
  329. for item in self.root.GetChildren():
  330. self.Collapse(item)
  331. itemSelected = self.GetSelection()
  332. if itemSelected:
  333. self.ToggleItemSelection(itemSelected)
  334. self.itemSelected = None
  335. class MenuTree(ItemTree):
  336. """!Menu tree class"""
  337. def __init__(self, parent, data, **kwargs):
  338. self.parent = parent
  339. self.menudata = data
  340. super(MenuTree, self).__init__(parent, **kwargs)
  341. def Load(self, data = None):
  342. """!Load menu data tree
  343. @param data menu data (None to use self.menudata)
  344. """
  345. if not data:
  346. data = self.menudata
  347. self.itemsMarked = [] # list of marked items
  348. for eachMenuData in data.GetMenu():
  349. for label, items in eachMenuData:
  350. item = self.AppendItem(parentId = self.root,
  351. text = label.replace('&', ''))
  352. self.__AppendItems(item, items)
  353. def __AppendItems(self, item, data):
  354. """!Append items into tree (used by Load()
  355. @param item tree item (parent)
  356. @parent data menu data"""
  357. for eachItem in data:
  358. if len(eachItem) == 2:
  359. if eachItem[0]:
  360. itemSub = self.AppendItem(parentId = item,
  361. text = eachItem[0])
  362. self.__AppendItems(itemSub, eachItem[1])
  363. else:
  364. if eachItem[0]:
  365. itemNew = self.AppendItem(parentId = item,
  366. text = eachItem[0])
  367. data = { 'item' : eachItem[0],
  368. 'description' : eachItem[1],
  369. 'handler' : eachItem[2],
  370. 'command' : eachItem[3],
  371. 'keywords' : eachItem[4] }
  372. self.SetPyData(itemNew, data)
  373. class AboutWindow(wx.Frame):
  374. def __init__(self, parent):
  375. """!Create custom About Window
  376. @todo improve styling
  377. """
  378. wx.Frame.__init__(self, parent=parent, id=wx.ID_ANY, size=(550,400),
  379. title=_('About GRASS GIS'))
  380. panel = wx.Panel(parent = self, id = wx.ID_ANY)
  381. # icon
  382. self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO))
  383. # get version and web site
  384. version, svn_gis_h_rev, svn_gis_h_date = gcmd.RunCommand('g.version',
  385. flags = 'r',
  386. read = True).splitlines()
  387. infoTxt = wx.Panel(parent = panel, id = wx.ID_ANY)
  388. infoSizer = wx.BoxSizer(wx.VERTICAL)
  389. infoGridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  390. infoGridSizer.AddGrowableCol(0)
  391. infoGridSizer.AddGrowableCol(1)
  392. logo = os.path.join(globalvar.ETCDIR, "gui", "icons", "grass.ico")
  393. logoBitmap = wx.StaticBitmap(parent = infoTxt, id = wx.ID_ANY,
  394. bitmap = wx.Bitmap(name = logo,
  395. type = wx.BITMAP_TYPE_ICO))
  396. infoSizer.Add(item = logoBitmap, proportion = 0,
  397. flag = wx.ALL | wx.ALIGN_CENTER, border = 25)
  398. info = wx.StaticText(parent = infoTxt, id = wx.ID_ANY,
  399. label = version.replace('GRASS', 'GRASS GIS').strip() + '\n\n')
  400. info.SetFont(wx.Font(13, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
  401. infoSizer.Add(item = info, proportion = 0,
  402. flag = wx.BOTTOM | wx.ALIGN_CENTER, border = 15)
  403. infoGridSizer.Add(item = wx.StaticText(parent = infoTxt, id = wx.ID_ANY,
  404. label = _('Official GRASS site:')),
  405. pos = (0, 0),
  406. flag = wx.ALIGN_RIGHT)
  407. infoGridSizer.Add(item = wx.StaticText(parent = infoTxt, id = wx.ID_ANY,
  408. label = 'http://grass.osgeo.org'),
  409. pos = (0, 1),
  410. flag = wx.ALIGN_LEFT)
  411. # infoGridSizer.Add(item = hl.HyperLinkCtrl(parent = self, id = wx.ID_ANY,
  412. # label = 'http://grass.osgeo.org',
  413. # URL = 'http://grass.osgeo.org'),
  414. # pos = (0, 1),
  415. # flag = wx.LEFT)
  416. infoGridSizer.Add(item = wx.StaticText(parent = infoTxt, id = wx.ID_ANY,
  417. label = _('GIS Library Revision:')),
  418. pos = (2, 0),
  419. flag = wx.ALIGN_RIGHT)
  420. infoGridSizer.Add(item = wx.StaticText(parent = infoTxt, id = wx.ID_ANY,
  421. label = svn_gis_h_rev.split(' ')[1] + ' (' +
  422. svn_gis_h_date.split(' ')[1] + ')'),
  423. pos = (2, 1),
  424. flag = wx.ALIGN_LEFT)
  425. infoSizer.Add(item = infoGridSizer,
  426. proportion = 1,
  427. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL,
  428. border = 25)
  429. #
  430. # create pages
  431. #
  432. copyrightwin = self.PageCopyright()
  433. licensewin = self.PageLicense()
  434. authorwin = self.PageCredit()
  435. contribwin = self.PageContributors()
  436. transwin = self.PageTranslators()
  437. # create a flat notebook for displaying information about GRASS
  438. nbstyle = FN.FNB_VC8 | \
  439. FN.FNB_BACKGROUND_GRADIENT | \
  440. FN.FNB_TABS_BORDER_SIMPLE | \
  441. FN.FNB_NO_X_BUTTON
  442. aboutNotebook = FN.FlatNotebook(panel, id=wx.ID_ANY, style=nbstyle)
  443. aboutNotebook.SetTabAreaColour(globalvar.FNPageColor)
  444. # make pages for About GRASS notebook
  445. pg1 = aboutNotebook.AddPage(infoTxt, text=_("Info"))
  446. pg2 = aboutNotebook.AddPage(copyrightwin, text=_("Copyright"))
  447. pg3 = aboutNotebook.AddPage(licensewin, text=_("License"))
  448. pg4 = aboutNotebook.AddPage(authorwin, text=_("Authors"))
  449. pg5 = aboutNotebook.AddPage(contribwin, text=_("Contributors"))
  450. pg5 = aboutNotebook.AddPage(transwin, text=_("Translators"))
  451. wx.CallAfter(aboutNotebook.SetSelection, 0)
  452. # buttons
  453. btnClose = wx.Button(parent = panel, id = wx.ID_CLOSE)
  454. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  455. btnSizer.Add(item = btnClose, proportion = 0,
  456. flag = wx.ALL | wx.ALIGN_RIGHT,
  457. border = 5)
  458. # bindings
  459. # self.aboutNotebook.Bind(FN.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.OnAGPageChanged)
  460. btnClose.Bind(wx.EVT_BUTTON, self.OnCloseWindow)
  461. infoTxt.SetSizer(infoSizer)
  462. infoSizer.Fit(infoTxt)
  463. sizer = wx.BoxSizer(wx.VERTICAL)
  464. sizer.Add(item=aboutNotebook, proportion=1,
  465. flag=wx.EXPAND | wx.ALL, border=1)
  466. sizer.Add(item=btnSizer, proportion=0,
  467. flag=wx.ALL | wx.ALIGN_RIGHT, border=1)
  468. panel.SetSizer(sizer)
  469. self.Layout()
  470. def PageCopyright(self):
  471. """Copyright information"""
  472. copyfile = os.path.join(os.getenv("GISBASE"), "COPYING")
  473. if os.path.exists(copyfile):
  474. copyrightFile = open(copyfile, 'r')
  475. copytext = copyrightFile.read()
  476. copyrightFile.close()
  477. else:
  478. copytext = _('%s file missing') % 'COPYING'
  479. # put text into a scrolling panel
  480. copyrightwin = scrolled.ScrolledPanel(self, id=wx.ID_ANY,
  481. size=wx.DefaultSize,
  482. style = wx.TAB_TRAVERSAL | wx.SUNKEN_BORDER)
  483. copyrighttxt = wx.StaticText(copyrightwin, id=wx.ID_ANY, label=copytext)
  484. copyrightwin.SetAutoLayout(True)
  485. copyrightwin.sizer = wx.BoxSizer(wx.VERTICAL)
  486. copyrightwin.sizer.Add(item=copyrighttxt, proportion=1,
  487. flag=wx.EXPAND | wx.ALL, border=3)
  488. copyrightwin.SetSizer(copyrightwin.sizer)
  489. copyrightwin.Layout()
  490. copyrightwin.SetupScrolling()
  491. return copyrightwin
  492. def PageLicense(self):
  493. """Licence about"""
  494. licfile = os.path.join(os.getenv("GISBASE"), "GPL.TXT")
  495. if os.path.exists(licfile):
  496. licenceFile = open(licfile, 'r')
  497. license = ''.join(licenceFile.readlines())
  498. licenceFile.close()
  499. else:
  500. license = _('%s file missing') % 'GPL.TXT'
  501. # put text into a scrolling panel
  502. licensewin = scrolled.ScrolledPanel(self, id=wx.ID_ANY,
  503. style = wx.TAB_TRAVERSAL | wx.SUNKEN_BORDER)
  504. licensetxt = wx.StaticText(licensewin, id=wx.ID_ANY, label=license)
  505. licensewin.SetAutoLayout(True)
  506. licensewin.sizer = wx.BoxSizer(wx.VERTICAL)
  507. licensewin.sizer.Add(item=licensetxt, proportion=1,
  508. flag=wx.EXPAND | wx.ALL, border=3)
  509. licensewin.SetSizer(licensewin.sizer)
  510. licensewin.Layout()
  511. licensewin.SetupScrolling()
  512. return licensewin
  513. def PageCredit(self):
  514. """Credit about"""
  515. # credits
  516. authfile = os.path.join(os.getenv("GISBASE"), "AUTHORS")
  517. if os.path.exists(authfile):
  518. authorsFile = open(authfile, 'r')
  519. authors = unicode(''.join(authorsFile.readlines()), "utf-8")
  520. authorsFile.close()
  521. else:
  522. authors = _('%s file missing') % 'AUTHORS'
  523. authorwin = scrolled.ScrolledPanel(self, id=wx.ID_ANY,
  524. style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER)
  525. authortxt = wx.StaticText(authorwin, id=wx.ID_ANY, label=authors)
  526. authorwin.SetAutoLayout(1)
  527. authorwin.SetupScrolling()
  528. authorwin.sizer = wx.BoxSizer(wx.VERTICAL)
  529. authorwin.sizer.Add(item=authortxt, proportion=1,
  530. flag=wx.EXPAND | wx.ALL, border=3)
  531. authorwin.SetSizer(authorwin.sizer)
  532. authorwin.Layout()
  533. return authorwin
  534. def PageContributors(self):
  535. """Contributors info"""
  536. contribfile = os.path.join(os.getenv("GISBASE"), "contributors.csv")
  537. if os.path.exists(contribfile):
  538. contribFile = open(contribfile, 'r')
  539. contribs = list()
  540. for line in contribFile.readlines():
  541. cvs_id, name, email, country, osgeo_id, rfc2_agreed = line.split(',')
  542. contribs.append((name, email, country, osgeo_id))
  543. contribs[0] = (_('Name'), _('E-mail'), _('Country'), _('OSGeo_ID'))
  544. contribFile.close()
  545. else:
  546. contribs = None
  547. contribwin = scrolled.ScrolledPanel(self, id=wx.ID_ANY,
  548. style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER)
  549. contribwin.SetAutoLayout(1)
  550. contribwin.SetupScrolling()
  551. contribwin.sizer = wx.BoxSizer(wx.VERTICAL)
  552. if not contribs:
  553. contribtxt = wx.StaticText(contribwin, id=wx.ID_ANY,
  554. label=_('%s file missing') % 'contibutors.csv')
  555. contribwin.sizer.Add(item=contribtxt, proportion=1,
  556. flag=wx.EXPAND | wx.ALL, border=3)
  557. else:
  558. contribBox = wx.FlexGridSizer(cols=4, vgap=5, hgap=5)
  559. for developer in contribs:
  560. for item in developer:
  561. contribBox.Add(item = wx.StaticText(parent = contribwin, id = wx.ID_ANY,
  562. label = item))
  563. contribwin.sizer.Add(item=contribBox, proportion=1,
  564. flag=wx.EXPAND | wx.ALL, border=3)
  565. contribwin.SetSizer(contribwin.sizer)
  566. contribwin.Layout()
  567. return contribwin
  568. def PageTranslators(self):
  569. """Translators info"""
  570. translatorsfile = os.path.join(os.getenv("GISBASE"), "translators.csv")
  571. if os.path.exists(translatorsfile):
  572. translatorsFile = open(translatorsfile, 'r')
  573. translators = dict()
  574. for line in translatorsFile.readlines()[1:]:
  575. name, email, languages = line.rstrip('\n').split(',')
  576. for language in languages.split(' '):
  577. if not translators.has_key(language):
  578. translators[language] = list()
  579. translators[language].append((name, email))
  580. translatorsFile.close()
  581. else:
  582. translators = None
  583. translatorswin = scrolled.ScrolledPanel(self, id=wx.ID_ANY,
  584. style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER)
  585. translatorswin.SetAutoLayout(1)
  586. translatorswin.SetupScrolling()
  587. translatorswin.sizer = wx.BoxSizer(wx.VERTICAL)
  588. if not translators:
  589. translatorstxt = wx.StaticText(translatorswin, id=wx.ID_ANY,
  590. label=_('%s file missing') % 'translators.csv')
  591. translatorswin.sizer.Add(item=translatorstxt, proportion=1,
  592. flag=wx.EXPAND | wx.ALL, border=3)
  593. else:
  594. translatorsBox = wx.FlexGridSizer(cols=3, vgap=5, hgap=5)
  595. languages = translators.keys()
  596. languages.sort()
  597. translatorsBox.Add(item = wx.StaticText(parent = translatorswin, id = wx.ID_ANY,
  598. label = _('Name')))
  599. translatorsBox.Add(item = wx.StaticText(parent = translatorswin, id = wx.ID_ANY,
  600. label = _('E-mail')))
  601. translatorsBox.Add(item = wx.StaticText(parent = translatorswin, id = wx.ID_ANY,
  602. label = _('Language')))
  603. for lang in languages:
  604. for translator in translators[lang]:
  605. name, email = translator
  606. translatorsBox.Add(item = wx.StaticText(parent = translatorswin, id = wx.ID_ANY,
  607. label = unicode(name, "utf-8")))
  608. translatorsBox.Add(item = wx.StaticText(parent = translatorswin, id = wx.ID_ANY,
  609. label = email))
  610. translatorsBox.Add(item = wx.StaticText(parent = translatorswin, id = wx.ID_ANY,
  611. label = lang))
  612. translatorswin.sizer.Add(item=translatorsBox, proportion=1,
  613. flag=wx.EXPAND | wx.ALL, border=3)
  614. translatorswin.SetSizer(translatorswin.sizer)
  615. translatorswin.Layout()
  616. return translatorswin
  617. def OnCloseWindow(self, event):
  618. """!Close window"""
  619. self.Close()
  620. class InstallExtensionWindow(wx.Frame):
  621. def __init__(self, parent, id = wx.ID_ANY,
  622. title = _("Fetch & install new extension from GRASS Addons"), **kwargs):
  623. self.parent = parent
  624. wx.Frame.__init__(self, parent = parent, id = id, title = title, **kwargs)
  625. self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
  626. self.repoBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  627. label=" %s " % _("Repository"))
  628. self.findBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  629. label=" %s " % _("Find extension by"))
  630. self.treeBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  631. label=" %s " % _("List of extensions"))
  632. self.repo = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY,
  633. value = 'https://svn.osgeo.org/grass/grass-addons')
  634. self.fullDesc = wx.CheckBox(parent = self.panel, id=wx.ID_ANY,
  635. label = _("Fetch full info including description and keywords (takes time)"))
  636. self.fullDesc.SetValue(False)
  637. self.search = SearchModuleWindow(parent = self.panel)
  638. self.search.SetSelection(2)
  639. self.tree = ExtensionTree(parent = self.panel, log = parent.GetLogWindow())
  640. self.statusbar = self.CreateStatusBar(0)
  641. self.btnFetch = wx.Button(parent = self.panel, id = wx.ID_ANY,
  642. label = _("&Fetch"))
  643. self.btnFetch.SetToolTipString(_("Fetch list of available modules from GRASS Addons SVN repository"))
  644. self.btnClose = wx.Button(parent = self.panel, id = wx.ID_CLOSE)
  645. self.btnInstall = wx.Button(parent = self.panel, id = wx.ID_ANY,
  646. label = _("&Install"))
  647. self.btnInstall.SetToolTipString(_("Install selected add-ons GRASS module"))
  648. self.btnInstall.Enable(False)
  649. self.btnClose.Bind(wx.EVT_BUTTON, self.OnCloseWindow)
  650. self.btnFetch.Bind(wx.EVT_BUTTON, self.OnFetch)
  651. self.btnInstall.Bind(wx.EVT_BUTTON, self.OnInstall)
  652. self.tree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnItemActivated)
  653. self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnItemSelected)
  654. self.search.Bind(wx.EVT_TEXT_ENTER, self.OnShowItem)
  655. self.search.Bind(wx.EVT_TEXT, self.OnUpdateStatusBar)
  656. self._layout()
  657. def _layout(self):
  658. """!Do layout"""
  659. sizer = wx.BoxSizer(wx.VERTICAL)
  660. repoSizer = wx.StaticBoxSizer(self.repoBox, wx.VERTICAL)
  661. repo1Sizer = wx.BoxSizer(wx.HORIZONTAL)
  662. repo1Sizer.Add(item = self.repo, proportion = 1,
  663. flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL, border = 1)
  664. repo1Sizer.Add(item = self.btnFetch, proportion = 0,
  665. flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL, border = 1)
  666. repoSizer.Add(item = repo1Sizer,
  667. flag = wx.EXPAND)
  668. repoSizer.Add(item = self.fullDesc)
  669. findSizer = wx.StaticBoxSizer(self.findBox, wx.HORIZONTAL)
  670. findSizer.Add(item = self.search, proportion = 1)
  671. treeSizer = wx.StaticBoxSizer(self.treeBox, wx.HORIZONTAL)
  672. treeSizer.Add(item = self.tree, proportion = 1,
  673. flag = wx.ALL | wx.EXPAND, border = 1)
  674. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  675. btnSizer.Add(item = self.btnClose, proportion = 0,
  676. flag = wx.RIGHT, border = 5)
  677. btnSizer.Add(item = self.btnInstall, proportion = 0)
  678. sizer.Add(item = repoSizer, proportion = 0,
  679. flag = wx.ALL | wx.EXPAND, border = 3)
  680. sizer.Add(item = findSizer, proportion = 0,
  681. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  682. sizer.Add(item = treeSizer, proportion = 1,
  683. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  684. sizer.Add(item = btnSizer, proportion=0,
  685. flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
  686. self.panel.SetSizer(sizer)
  687. sizer.Fit(self.panel)
  688. self.Layout()
  689. def _install(self, name):
  690. if not name:
  691. return
  692. log = self.parent.GetLogWindow()
  693. log.RunCmd(['g.extension', 'extension=' + name,
  694. 'svnurl=' + self.repo.GetValue().strip()])
  695. self.OnCloseWindow(None)
  696. def OnUpdateStatusBar(self, event):
  697. """!Update statusbar text"""
  698. element = self.search.GetSelection()
  699. if not self.tree.IsLoaded():
  700. self.SetStatusText(_("Fetch list of available extensions by clicking on 'Fetch' button"), 0)
  701. return
  702. self.tree.SearchItems(element = element,
  703. value = event.GetString())
  704. nItems = len(self.tree.itemsMarked)
  705. if event.GetString():
  706. self.SetStatusText(_("%d items match") % nItems, 0)
  707. else:
  708. self.SetStatusText("", 0)
  709. event.Skip()
  710. def OnCloseWindow(self, event):
  711. """!Close window"""
  712. self.Destroy()
  713. def OnFetch(self, event):
  714. """!Fetch list of available extensions"""
  715. self.SetStatusText(_("Fetching list of modules from GRASS-Addons SVN (be patient)..."), 0)
  716. self.tree.Load(url = self.repo.GetValue().strip(), full = self.fullDesc.IsChecked())
  717. self.SetStatusText("", 0)
  718. def OnItemActivated(self, event):
  719. item = event.GetItem()
  720. data = self.tree.GetPyData(item)
  721. if data and data.has_key('command'):
  722. self._install(data['command'])
  723. def OnInstall(self, event):
  724. """!Install selected extension"""
  725. item = self.tree.GetSelected()
  726. if not item.IsOk():
  727. return
  728. self._install(self.tree.GetItemText(item))
  729. def OnItemSelected(self, event):
  730. """!Item selected"""
  731. item = event.GetItem()
  732. self.tree.itemSelected = item
  733. data = self.tree.GetPyData(item)
  734. if not data:
  735. self.SetStatusText('', 0)
  736. self.btnInstall.Enable(False)
  737. else:
  738. self.SetStatusText(data.get('description', ''), 0)
  739. self.btnInstall.Enable(True)
  740. def OnShowItem(self, event):
  741. """!Show selected item"""
  742. self.tree.OnShowItem(event)
  743. if self.tree.GetSelected():
  744. self.btnInstall.Enable()
  745. else:
  746. self.btnInstall.Enable(False)
  747. class ExtensionTree(ItemTree):
  748. """!List of available extensions"""
  749. def __init__(self, parent, log, id = wx.ID_ANY,
  750. ctstyle = CT.TR_HIDE_ROOT | CT.TR_FULL_ROW_HIGHLIGHT | CT.TR_HAS_BUTTONS |
  751. CT.TR_LINES_AT_ROOT | CT.TR_SINGLE,
  752. **kwargs):
  753. self.parent = parent # GMFrame
  754. self.log = log
  755. super(ExtensionTree, self).__init__(parent, id, ctstyle = ctstyle, **kwargs)
  756. self._initTree()
  757. def _initTree(self):
  758. for prefix in ('display', 'database',
  759. 'general', 'imagery',
  760. 'misc', 'postscript', 'paint',
  761. 'raster', 'raster3D', 'sites', 'vector'):
  762. self.AppendItem(parentId = self.root,
  763. text = prefix)
  764. self._loaded = False
  765. def _expandPrefix(self, c):
  766. name = { 'd' : 'display',
  767. 'db' : 'database',
  768. 'g' : 'general',
  769. 'i' : 'imagery',
  770. 'm' : 'misc',
  771. 'ps' : 'postscript',
  772. 'p' : 'paint',
  773. 'r' : 'raster',
  774. 'r3' : 'raster3D',
  775. 's' : 'sites',
  776. 'v' : 'vector' }
  777. if name.has_key(c):
  778. return name[c]
  779. return c
  780. def _findItem(self, text):
  781. """!Find item"""
  782. item = self.GetFirstChild(self.root)[0]
  783. while item and item.IsOk():
  784. if text == self.GetItemText(item):
  785. return item
  786. item = self.GetNextSibling(item)
  787. return None
  788. def Load(self, url, full = False):
  789. """!Load list of extensions"""
  790. self.DeleteAllItems()
  791. self.root = self.AddRoot(_("Menu tree"))
  792. self._initTree()
  793. if full:
  794. flags = 'g'
  795. else:
  796. flags = 'l'
  797. ret = gcmd.RunCommand('g.extension', read = True,
  798. svnurl = url,
  799. flags = flags, quiet = True)
  800. if not ret:
  801. return
  802. mdict = dict()
  803. for line in ret.splitlines():
  804. if full:
  805. key, value = line.split('=', 1)
  806. if key == 'name':
  807. prefix, name = value.split('.', 1)
  808. if not mdict.has_key(prefix):
  809. mdict[prefix] = dict()
  810. mdict[prefix][name] = dict()
  811. else:
  812. mdict[prefix][name][key] = value
  813. else:
  814. prefix, name = line.strip().split('.', 1)
  815. if not mdict.has_key(prefix):
  816. mdict[prefix] = dict()
  817. mdict[prefix][name] = { 'command' : prefix + '.' + name }
  818. for prefix in mdict.keys():
  819. prefixName = self._expandPrefix(prefix)
  820. item = self._findItem(prefixName)
  821. names = mdict[prefix].keys()
  822. names.sort()
  823. for name in names:
  824. new = self.AppendItem(parentId = item,
  825. text = prefix + '.' + name)
  826. data = dict()
  827. for key in mdict[prefix][name].keys():
  828. data[key] = mdict[prefix][name][key]
  829. self.SetPyData(new, data)
  830. self._loaded = True
  831. def IsLoaded(self):
  832. """Check if items are loaded"""
  833. return self._loaded
  834. class HelpWindow(wx.html.HtmlWindow):
  835. """!This panel holds the text from GRASS docs.
  836. GISBASE must be set in the environment to find the html docs dir.
  837. The SYNOPSIS section is skipped, since this Panel is supposed to
  838. be integrated into the cmdPanel and options are obvious there.
  839. """
  840. def __init__(self, parent, grass_command, text, skip_description,
  841. **kwargs):
  842. """!If grass_command is given, the corresponding HTML help
  843. file will be presented, with all links pointing to absolute
  844. paths of local files.
  845. If 'skip_description' is True, the HTML corresponding to
  846. SYNOPSIS will be skipped, thus only presenting the help file
  847. from the DESCRIPTION section onwards.
  848. If 'text' is given, it must be the HTML text to be presented
  849. in the Panel.
  850. """
  851. self.parent = parent
  852. wx.InitAllImageHandlers()
  853. wx.html.HtmlWindow.__init__(self, parent = parent, **kwargs)
  854. gisbase = os.getenv("GISBASE")
  855. self.loaded = False
  856. self.history = list()
  857. self.historyIdx = 0
  858. self.fspath = os.path.join(gisbase, "docs", "html")
  859. self.SetStandardFonts (size = 10)
  860. self.SetBorders(10)
  861. if text is None:
  862. if skip_description:
  863. url = os.path.join(self.fspath, grass_command + ".html")
  864. self.fillContentsFromFile(url,
  865. skip_description = skip_description)
  866. self.history.append(url)
  867. self.loaded = True
  868. else:
  869. ### FIXME: calling LoadPage() is strangely time-consuming (only first call)
  870. # self.LoadPage(self.fspath + grass_command + ".html")
  871. self.loaded = False
  872. else:
  873. self.SetPage(text)
  874. self.loaded = True
  875. def OnLinkClicked(self, linkinfo):
  876. url = linkinfo.GetHref()
  877. if url[:4] != 'http':
  878. url = os.path.join(self.fspath, url)
  879. self.history.append(url)
  880. self.historyIdx += 1
  881. self.parent.OnHistory()
  882. super(HelpWindow, self).OnLinkClicked(linkinfo)
  883. def fillContentsFromFile(self, htmlFile, skip_description=True):
  884. """!Load content from file"""
  885. aLink = re.compile(r'(<a href="?)(.+\.html?["\s]*>)', re.IGNORECASE)
  886. imgLink = re.compile(r'(<img src="?)(.+\.[png|gif])', re.IGNORECASE)
  887. try:
  888. contents = []
  889. skip = False
  890. for l in file(htmlFile, "rb").readlines():
  891. if "DESCRIPTION" in l:
  892. skip = False
  893. if not skip:
  894. # do skip the options description if requested
  895. if "SYNOPSIS" in l:
  896. skip = skip_description
  897. else:
  898. # FIXME: find only first item
  899. findALink = aLink.search(l)
  900. if findALink is not None:
  901. contents.append(aLink.sub(findALink.group(1)+
  902. self.fspath+findALink.group(2),l))
  903. findImgLink = imgLink.search(l)
  904. if findImgLink is not None:
  905. contents.append(imgLink.sub(findImgLink.group(1)+
  906. self.fspath+findImgLink.group(2),l))
  907. if findALink is None and findImgLink is None:
  908. contents.append(l)
  909. self.SetPage("".join(contents))
  910. self.loaded = True
  911. except: # The Manual file was not found
  912. self.loaded = False
  913. class HelpPanel(wx.Panel):
  914. def __init__(self, parent, grass_command = "index", text = None,
  915. skip_description = False, **kwargs):
  916. self.grass_command = grass_command
  917. wx.Panel.__init__(self, parent = parent, id = wx.ID_ANY)
  918. self.content = HelpWindow(self, grass_command, text,
  919. skip_description)
  920. self.btnNext = wx.Button(parent = self, id = wx.ID_ANY,
  921. label = _("&Next"))
  922. self.btnNext.Enable(False)
  923. self.btnPrev = wx.Button(parent = self, id = wx.ID_ANY,
  924. label = _("&Previous"))
  925. self.btnPrev.Enable(False)
  926. self.btnNext.Bind(wx.EVT_BUTTON, self.OnNext)
  927. self.btnPrev.Bind(wx.EVT_BUTTON, self.OnPrev)
  928. self._layout()
  929. def _layout(self):
  930. """!Do layout"""
  931. sizer = wx.BoxSizer(wx.VERTICAL)
  932. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  933. btnSizer.Add(item = self.btnPrev, proportion = 0,
  934. flag = wx.ALL, border = 5)
  935. btnSizer.Add(item = wx.Size(1, 1), proportion = 1)
  936. btnSizer.Add(item = self.btnNext, proportion = 0,
  937. flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
  938. sizer.Add(item = self.content, proportion = 1,
  939. flag = wx.EXPAND)
  940. sizer.Add(item = btnSizer, proportion = 0,
  941. flag = wx.EXPAND)
  942. self.SetSizer(sizer)
  943. sizer.Fit(self)
  944. def LoadPage(self, path = None):
  945. """!Load page"""
  946. if not path:
  947. path = os.path.join(self.content.fspath, self.grass_command + ".html")
  948. self.content.history.append(path)
  949. self.content.LoadPage(path)
  950. def IsFile(self):
  951. """!Check if file exists"""
  952. return os.path.isfile(os.path.join(self.content.fspath, self.grass_command + ".html"))
  953. def IsLoaded(self):
  954. return self.content.loaded
  955. def OnHistory(self):
  956. """!Update buttons"""
  957. nH = len(self.content.history)
  958. iH = self.content.historyIdx
  959. if iH == nH - 1:
  960. self.btnNext.Enable(False)
  961. elif iH > -1:
  962. self.btnNext.Enable(True)
  963. if iH < 1:
  964. self.btnPrev.Enable(False)
  965. else:
  966. self.btnPrev.Enable(True)
  967. def OnNext(self, event):
  968. """Load next page"""
  969. self.content.historyIdx += 1
  970. idx = self.content.historyIdx
  971. path = self.content.history[idx]
  972. self.content.LoadPage(path)
  973. self.OnHistory()
  974. event.Skip()
  975. def OnPrev(self, event):
  976. """Load previous page"""
  977. self.content.historyIdx -= 1
  978. idx = self.content.historyIdx
  979. path = self.content.history[idx]
  980. self.content.LoadPage(path)
  981. self.OnHistory()
  982. event.Skip()