ghelp.py 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  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 globalvar.hasAgw:
  275. super(ItemTree, self).__init__(parent, id, agwStyle = ctstyle, **kwargs)
  276. else:
  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. if globalvar.hasAgw:
  443. aboutNotebook = FN.FlatNotebook(panel, id = wx.ID_ANY, agwStyle = nbstyle)
  444. else:
  445. aboutNotebook = FN.FlatNotebook(panel, id = wx.ID_ANY, style = nbstyle)
  446. aboutNotebook.SetTabAreaColour(globalvar.FNPageColor)
  447. # make pages for About GRASS notebook
  448. pg1 = aboutNotebook.AddPage(infoTxt, text = _("Info"))
  449. pg2 = aboutNotebook.AddPage(copyrightwin, text = _("Copyright"))
  450. pg3 = aboutNotebook.AddPage(licensewin, text = _("License"))
  451. pg4 = aboutNotebook.AddPage(authorwin, text = _("Authors"))
  452. pg5 = aboutNotebook.AddPage(contribwin, text = _("Contributors"))
  453. pg5 = aboutNotebook.AddPage(transwin, text = _("Translators"))
  454. wx.CallAfter(aboutNotebook.SetSelection, 0)
  455. # buttons
  456. btnClose = wx.Button(parent = panel, id = wx.ID_CLOSE)
  457. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  458. btnSizer.Add(item = btnClose, proportion = 0,
  459. flag = wx.ALL | wx.ALIGN_RIGHT,
  460. border = 5)
  461. # bindings
  462. # self.aboutNotebook.Bind(FN.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.OnAGPageChanged)
  463. btnClose.Bind(wx.EVT_BUTTON, self.OnCloseWindow)
  464. infoTxt.SetSizer(infoSizer)
  465. infoSizer.Fit(infoTxt)
  466. sizer = wx.BoxSizer(wx.VERTICAL)
  467. sizer.Add(item = aboutNotebook, proportion = 1,
  468. flag = wx.EXPAND | wx.ALL, border = 1)
  469. sizer.Add(item = btnSizer, proportion = 0,
  470. flag = wx.ALL | wx.ALIGN_RIGHT, border = 1)
  471. panel.SetSizer(sizer)
  472. self.Layout()
  473. def PageCopyright(self):
  474. """Copyright information"""
  475. copyfile = os.path.join(os.getenv("GISBASE"), "COPYING")
  476. if os.path.exists(copyfile):
  477. copyrightFile = open(copyfile, 'r')
  478. copytext = copyrightFile.read()
  479. copyrightFile.close()
  480. else:
  481. copytext = _('%s file missing') % 'COPYING'
  482. # put text into a scrolling panel
  483. copyrightwin = scrolled.ScrolledPanel(self, id = wx.ID_ANY,
  484. size = wx.DefaultSize,
  485. style = wx.TAB_TRAVERSAL | wx.SUNKEN_BORDER)
  486. copyrighttxt = wx.StaticText(copyrightwin, id = wx.ID_ANY, label = copytext)
  487. copyrightwin.SetAutoLayout(True)
  488. copyrightwin.sizer = wx.BoxSizer(wx.VERTICAL)
  489. copyrightwin.sizer.Add(item = copyrighttxt, proportion = 1,
  490. flag = wx.EXPAND | wx.ALL, border = 3)
  491. copyrightwin.SetSizer(copyrightwin.sizer)
  492. copyrightwin.Layout()
  493. copyrightwin.SetupScrolling()
  494. return copyrightwin
  495. def PageLicense(self):
  496. """Licence about"""
  497. licfile = os.path.join(os.getenv("GISBASE"), "GPL.TXT")
  498. if os.path.exists(licfile):
  499. licenceFile = open(licfile, 'r')
  500. license = ''.join(licenceFile.readlines())
  501. licenceFile.close()
  502. else:
  503. license = _('%s file missing') % 'GPL.TXT'
  504. # put text into a scrolling panel
  505. licensewin = scrolled.ScrolledPanel(self, id = wx.ID_ANY,
  506. style = wx.TAB_TRAVERSAL | wx.SUNKEN_BORDER)
  507. licensetxt = wx.StaticText(licensewin, id = wx.ID_ANY, label = license)
  508. licensewin.SetAutoLayout(True)
  509. licensewin.sizer = wx.BoxSizer(wx.VERTICAL)
  510. licensewin.sizer.Add(item = licensetxt, proportion = 1,
  511. flag = wx.EXPAND | wx.ALL, border = 3)
  512. licensewin.SetSizer(licensewin.sizer)
  513. licensewin.Layout()
  514. licensewin.SetupScrolling()
  515. return licensewin
  516. def PageCredit(self):
  517. """Credit about"""
  518. # credits
  519. authfile = os.path.join(os.getenv("GISBASE"), "AUTHORS")
  520. if os.path.exists(authfile):
  521. authorsFile = open(authfile, 'r')
  522. authors = unicode(''.join(authorsFile.readlines()), "utf-8")
  523. authorsFile.close()
  524. else:
  525. authors = _('%s file missing') % 'AUTHORS'
  526. authorwin = scrolled.ScrolledPanel(self, id = wx.ID_ANY,
  527. style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER)
  528. authortxt = wx.StaticText(authorwin, id = wx.ID_ANY, label = authors)
  529. authorwin.SetAutoLayout(1)
  530. authorwin.SetupScrolling()
  531. authorwin.sizer = wx.BoxSizer(wx.VERTICAL)
  532. authorwin.sizer.Add(item = authortxt, proportion = 1,
  533. flag = wx.EXPAND | wx.ALL, border = 3)
  534. authorwin.SetSizer(authorwin.sizer)
  535. authorwin.Layout()
  536. return authorwin
  537. def PageContributors(self):
  538. """Contributors info"""
  539. contribfile = os.path.join(os.getenv("GISBASE"), "contributors.csv")
  540. if os.path.exists(contribfile):
  541. contribFile = open(contribfile, 'r')
  542. contribs = list()
  543. for line in contribFile.readlines():
  544. cvs_id, name, email, country, osgeo_id, rfc2_agreed = line.split(',')
  545. contribs.append((name, email, country, osgeo_id))
  546. contribs[0] = (_('Name'), _('E-mail'), _('Country'), _('OSGeo_ID'))
  547. contribFile.close()
  548. else:
  549. contribs = None
  550. contribwin = scrolled.ScrolledPanel(self, id = wx.ID_ANY,
  551. style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER)
  552. contribwin.SetAutoLayout(1)
  553. contribwin.SetupScrolling()
  554. contribwin.sizer = wx.BoxSizer(wx.VERTICAL)
  555. if not contribs:
  556. contribtxt = wx.StaticText(contribwin, id = wx.ID_ANY,
  557. label = _('%s file missing') % 'contibutors.csv')
  558. contribwin.sizer.Add(item = contribtxt, proportion = 1,
  559. flag = wx.EXPAND | wx.ALL, border = 3)
  560. else:
  561. contribBox = wx.FlexGridSizer(cols = 4, vgap = 5, hgap = 5)
  562. for developer in contribs:
  563. for item in developer:
  564. contribBox.Add(item = wx.StaticText(parent = contribwin, id = wx.ID_ANY,
  565. label = item))
  566. contribwin.sizer.Add(item = contribBox, proportion = 1,
  567. flag = wx.EXPAND | wx.ALL, border = 3)
  568. contribwin.SetSizer(contribwin.sizer)
  569. contribwin.Layout()
  570. return contribwin
  571. def PageTranslators(self):
  572. """Translators info"""
  573. translatorsfile = os.path.join(os.getenv("GISBASE"), "translators.csv")
  574. if os.path.exists(translatorsfile):
  575. translatorsFile = open(translatorsfile, 'r')
  576. translators = dict()
  577. for line in translatorsFile.readlines()[1:]:
  578. name, email, languages = line.rstrip('\n').split(',')
  579. for language in languages.split(' '):
  580. if not translators.has_key(language):
  581. translators[language] = list()
  582. translators[language].append((name, email))
  583. translatorsFile.close()
  584. else:
  585. translators = None
  586. translatorswin = scrolled.ScrolledPanel(self, id = wx.ID_ANY,
  587. style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER)
  588. translatorswin.SetAutoLayout(1)
  589. translatorswin.SetupScrolling()
  590. translatorswin.sizer = wx.BoxSizer(wx.VERTICAL)
  591. if not translators:
  592. translatorstxt = wx.StaticText(translatorswin, id = wx.ID_ANY,
  593. label = _('%s file missing') % 'translators.csv')
  594. translatorswin.sizer.Add(item = translatorstxt, proportion = 1,
  595. flag = wx.EXPAND | wx.ALL, border = 3)
  596. else:
  597. translatorsBox = wx.FlexGridSizer(cols = 3, vgap = 5, hgap = 5)
  598. languages = translators.keys()
  599. languages.sort()
  600. translatorsBox.Add(item = wx.StaticText(parent = translatorswin, id = wx.ID_ANY,
  601. label = _('Name')))
  602. translatorsBox.Add(item = wx.StaticText(parent = translatorswin, id = wx.ID_ANY,
  603. label = _('E-mail')))
  604. translatorsBox.Add(item = wx.StaticText(parent = translatorswin, id = wx.ID_ANY,
  605. label = _('Language')))
  606. for lang in languages:
  607. for translator in translators[lang]:
  608. name, email = translator
  609. translatorsBox.Add(item = wx.StaticText(parent = translatorswin, id = wx.ID_ANY,
  610. label = unicode(name, "utf-8")))
  611. translatorsBox.Add(item = wx.StaticText(parent = translatorswin, id = wx.ID_ANY,
  612. label = email))
  613. translatorsBox.Add(item = wx.StaticText(parent = translatorswin, id = wx.ID_ANY,
  614. label = lang))
  615. translatorswin.sizer.Add(item = translatorsBox, proportion = 1,
  616. flag = wx.EXPAND | wx.ALL, border = 3)
  617. translatorswin.SetSizer(translatorswin.sizer)
  618. translatorswin.Layout()
  619. return translatorswin
  620. def OnCloseWindow(self, event):
  621. """!Close window"""
  622. self.Close()
  623. class InstallExtensionWindow(wx.Frame):
  624. def __init__(self, parent, id = wx.ID_ANY,
  625. title = _("Fetch & install new extension from GRASS Addons"), **kwargs):
  626. self.parent = parent
  627. wx.Frame.__init__(self, parent = parent, id = id, title = title, **kwargs)
  628. self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
  629. self.repoBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  630. label = " %s " % _("Repository"))
  631. self.treeBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  632. label = " %s " % _("List of extensions"))
  633. self.repo = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY,
  634. value = 'https://svn.osgeo.org/grass/grass-addons')
  635. self.fullDesc = wx.CheckBox(parent = self.panel, id = wx.ID_ANY,
  636. label = _("Fetch full info including description and keywords (takes time)"))
  637. self.fullDesc.SetValue(False)
  638. self.search = SearchModuleWindow(parent = self.panel)
  639. self.search.SetSelection(2)
  640. self.tree = ExtensionTree(parent = self.panel, log = parent.GetLogWindow())
  641. self.statusbar = self.CreateStatusBar(0)
  642. self.btnFetch = wx.Button(parent = self.panel, id = wx.ID_ANY,
  643. label = _("&Fetch"))
  644. self.btnFetch.SetToolTipString(_("Fetch list of available modules from GRASS Addons SVN repository"))
  645. self.btnClose = wx.Button(parent = self.panel, id = wx.ID_CLOSE)
  646. self.btnInstall = wx.Button(parent = self.panel, id = wx.ID_ANY,
  647. label = _("&Install"))
  648. self.btnInstall.SetToolTipString(_("Install selected add-ons GRASS module"))
  649. self.btnInstall.Enable(False)
  650. self.btnClose.Bind(wx.EVT_BUTTON, self.OnCloseWindow)
  651. self.btnFetch.Bind(wx.EVT_BUTTON, self.OnFetch)
  652. self.btnInstall.Bind(wx.EVT_BUTTON, self.OnInstall)
  653. self.tree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnItemActivated)
  654. self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnItemSelected)
  655. self.search.Bind(wx.EVT_TEXT_ENTER, self.OnShowItem)
  656. self.search.Bind(wx.EVT_TEXT, self.OnUpdateStatusBar)
  657. self._layout()
  658. def _layout(self):
  659. """!Do layout"""
  660. sizer = wx.BoxSizer(wx.VERTICAL)
  661. repoSizer = wx.StaticBoxSizer(self.repoBox, wx.VERTICAL)
  662. repo1Sizer = wx.BoxSizer(wx.HORIZONTAL)
  663. repo1Sizer.Add(item = self.repo, proportion = 1,
  664. flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL, border = 1)
  665. repo1Sizer.Add(item = self.btnFetch, proportion = 0,
  666. flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL, border = 1)
  667. repoSizer.Add(item = repo1Sizer,
  668. flag = wx.EXPAND)
  669. repoSizer.Add(item = self.fullDesc)
  670. findSizer = wx.BoxSizer(wx.HORIZONTAL)
  671. findSizer.Add(item = self.search, proportion = 1)
  672. treeSizer = wx.StaticBoxSizer(self.treeBox, wx.HORIZONTAL)
  673. treeSizer.Add(item = self.tree, proportion = 1,
  674. flag = wx.ALL | wx.EXPAND, border = 1)
  675. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  676. btnSizer.Add(item = self.btnClose, proportion = 0,
  677. flag = wx.RIGHT, border = 5)
  678. btnSizer.Add(item = self.btnInstall, proportion = 0)
  679. sizer.Add(item = repoSizer, proportion = 0,
  680. flag = wx.ALL | wx.EXPAND, border = 3)
  681. sizer.Add(item = findSizer, proportion = 0,
  682. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  683. sizer.Add(item = treeSizer, proportion = 1,
  684. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  685. sizer.Add(item = btnSizer, proportion = 0,
  686. flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
  687. self.panel.SetSizer(sizer)
  688. sizer.Fit(self.panel)
  689. self.Layout()
  690. def _install(self, name):
  691. if not name:
  692. return
  693. log = self.parent.GetLogWindow()
  694. log.RunCmd(['g.extension', 'extension=' + name,
  695. 'svnurl=' + self.repo.GetValue().strip()])
  696. self.OnCloseWindow(None)
  697. def OnUpdateStatusBar(self, event):
  698. """!Update statusbar text"""
  699. element = self.search.GetSelection()
  700. if not self.tree.IsLoaded():
  701. self.SetStatusText(_("Fetch list of available extensions by clicking on 'Fetch' button"), 0)
  702. return
  703. self.tree.SearchItems(element = element,
  704. value = event.GetString())
  705. nItems = len(self.tree.itemsMarked)
  706. if event.GetString():
  707. self.SetStatusText(_("%d items match") % nItems, 0)
  708. else:
  709. self.SetStatusText("", 0)
  710. event.Skip()
  711. def OnCloseWindow(self, event):
  712. """!Close window"""
  713. self.Destroy()
  714. def OnFetch(self, event):
  715. """!Fetch list of available extensions"""
  716. self.SetStatusText(_("Fetching list of modules from GRASS-Addons SVN (be patient)..."), 0)
  717. self.tree.Load(url = self.repo.GetValue().strip(), full = self.fullDesc.IsChecked())
  718. self.SetStatusText("", 0)
  719. def OnItemActivated(self, event):
  720. item = event.GetItem()
  721. data = self.tree.GetPyData(item)
  722. if data and data.has_key('command'):
  723. self._install(data['command'])
  724. def OnInstall(self, event):
  725. """!Install selected extension"""
  726. item = self.tree.GetSelected()
  727. if not item.IsOk():
  728. return
  729. self._install(self.tree.GetItemText(item))
  730. def OnItemSelected(self, event):
  731. """!Item selected"""
  732. item = event.GetItem()
  733. self.tree.itemSelected = item
  734. data = self.tree.GetPyData(item)
  735. if not data:
  736. self.SetStatusText('', 0)
  737. self.btnInstall.Enable(False)
  738. else:
  739. self.SetStatusText(data.get('description', ''), 0)
  740. self.btnInstall.Enable(True)
  741. def OnShowItem(self, event):
  742. """!Show selected item"""
  743. self.tree.OnShowItem(event)
  744. if self.tree.GetSelected():
  745. self.btnInstall.Enable()
  746. else:
  747. self.btnInstall.Enable(False)
  748. class ExtensionTree(ItemTree):
  749. """!List of available extensions"""
  750. def __init__(self, parent, log, id = wx.ID_ANY,
  751. ctstyle = CT.TR_HIDE_ROOT | CT.TR_FULL_ROW_HIGHLIGHT | CT.TR_HAS_BUTTONS |
  752. CT.TR_LINES_AT_ROOT | CT.TR_SINGLE,
  753. **kwargs):
  754. self.parent = parent # GMFrame
  755. self.log = log
  756. super(ExtensionTree, self).__init__(parent, id, ctstyle = ctstyle, **kwargs)
  757. self._initTree()
  758. def _initTree(self):
  759. for prefix in ('display', 'database',
  760. 'general', 'imagery',
  761. 'misc', 'postscript', 'paint',
  762. 'raster', 'raster3D', 'sites', 'vector'):
  763. self.AppendItem(parentId = self.root,
  764. text = prefix)
  765. self._loaded = False
  766. def _expandPrefix(self, c):
  767. name = { 'd' : 'display',
  768. 'db' : 'database',
  769. 'g' : 'general',
  770. 'i' : 'imagery',
  771. 'm' : 'misc',
  772. 'ps' : 'postscript',
  773. 'p' : 'paint',
  774. 'r' : 'raster',
  775. 'r3' : 'raster3D',
  776. 's' : 'sites',
  777. 'v' : 'vector' }
  778. if name.has_key(c):
  779. return name[c]
  780. return c
  781. def _findItem(self, text):
  782. """!Find item"""
  783. item = self.GetFirstChild(self.root)[0]
  784. while item and item.IsOk():
  785. if text == self.GetItemText(item):
  786. return item
  787. item = self.GetNextSibling(item)
  788. return None
  789. def Load(self, url, full = False):
  790. """!Load list of extensions"""
  791. self.DeleteAllItems()
  792. self.root = self.AddRoot(_("Menu tree"))
  793. self._initTree()
  794. if full:
  795. flags = 'g'
  796. else:
  797. flags = 'l'
  798. ret = gcmd.RunCommand('g.extension', read = True,
  799. svnurl = url,
  800. flags = flags, quiet = True)
  801. if not ret:
  802. return
  803. mdict = dict()
  804. for line in ret.splitlines():
  805. if full:
  806. key, value = line.split('=', 1)
  807. if key == 'name':
  808. prefix, name = value.split('.', 1)
  809. if not mdict.has_key(prefix):
  810. mdict[prefix] = dict()
  811. mdict[prefix][name] = dict()
  812. else:
  813. mdict[prefix][name][key] = value
  814. else:
  815. prefix, name = line.strip().split('.', 1)
  816. if not mdict.has_key(prefix):
  817. mdict[prefix] = dict()
  818. mdict[prefix][name] = { 'command' : prefix + '.' + name }
  819. for prefix in mdict.keys():
  820. prefixName = self._expandPrefix(prefix)
  821. item = self._findItem(prefixName)
  822. names = mdict[prefix].keys()
  823. names.sort()
  824. for name in names:
  825. new = self.AppendItem(parentId = item,
  826. text = prefix + '.' + name)
  827. data = dict()
  828. for key in mdict[prefix][name].keys():
  829. data[key] = mdict[prefix][name][key]
  830. self.SetPyData(new, data)
  831. self._loaded = True
  832. def IsLoaded(self):
  833. """Check if items are loaded"""
  834. return self._loaded
  835. class HelpWindow(wx.html.HtmlWindow):
  836. """!This panel holds the text from GRASS docs.
  837. GISBASE must be set in the environment to find the html docs dir.
  838. The SYNOPSIS section is skipped, since this Panel is supposed to
  839. be integrated into the cmdPanel and options are obvious there.
  840. """
  841. def __init__(self, parent, grass_command, text, skip_description,
  842. **kwargs):
  843. """!If grass_command is given, the corresponding HTML help
  844. file will be presented, with all links pointing to absolute
  845. paths of local files.
  846. If 'skip_description' is True, the HTML corresponding to
  847. SYNOPSIS will be skipped, thus only presenting the help file
  848. from the DESCRIPTION section onwards.
  849. If 'text' is given, it must be the HTML text to be presented
  850. in the Panel.
  851. """
  852. self.parent = parent
  853. wx.InitAllImageHandlers()
  854. wx.html.HtmlWindow.__init__(self, parent = parent, **kwargs)
  855. gisbase = os.getenv("GISBASE")
  856. self.loaded = False
  857. self.history = list()
  858. self.historyIdx = 0
  859. self.fspath = os.path.join(gisbase, "docs", "html")
  860. self.SetStandardFonts (size = 10)
  861. self.SetBorders(10)
  862. if text is None:
  863. if skip_description:
  864. url = os.path.join(self.fspath, grass_command + ".html")
  865. self.fillContentsFromFile(url,
  866. skip_description = skip_description)
  867. self.history.append(url)
  868. self.loaded = True
  869. else:
  870. ### FIXME: calling LoadPage() is strangely time-consuming (only first call)
  871. # self.LoadPage(self.fspath + grass_command + ".html")
  872. self.loaded = False
  873. else:
  874. self.SetPage(text)
  875. self.loaded = True
  876. def OnLinkClicked(self, linkinfo):
  877. url = linkinfo.GetHref()
  878. if url[:4] != 'http':
  879. url = os.path.join(self.fspath, url)
  880. self.history.append(url)
  881. self.historyIdx += 1
  882. self.parent.OnHistory()
  883. super(HelpWindow, self).OnLinkClicked(linkinfo)
  884. def fillContentsFromFile(self, htmlFile, skip_description = True):
  885. """!Load content from file"""
  886. aLink = re.compile(r'(<a href="?)(.+\.html?["\s]*>)', re.IGNORECASE)
  887. imgLink = re.compile(r'(<img src="?)(.+\.[png|gif])', re.IGNORECASE)
  888. try:
  889. contents = []
  890. skip = False
  891. for l in file(htmlFile, "rb").readlines():
  892. if "DESCRIPTION" in l:
  893. skip = False
  894. if not skip:
  895. # do skip the options description if requested
  896. if "SYNOPSIS" in l:
  897. skip = skip_description
  898. else:
  899. # FIXME: find only first item
  900. findALink = aLink.search(l)
  901. if findALink is not None:
  902. contents.append(aLink.sub(findALink.group(1)+
  903. self.fspath+findALink.group(2),l))
  904. findImgLink = imgLink.search(l)
  905. if findImgLink is not None:
  906. contents.append(imgLink.sub(findImgLink.group(1)+
  907. self.fspath+findImgLink.group(2),l))
  908. if findALink is None and findImgLink is None:
  909. contents.append(l)
  910. self.SetPage("".join(contents))
  911. self.loaded = True
  912. except: # The Manual file was not found
  913. self.loaded = False
  914. class HelpPanel(wx.Panel):
  915. def __init__(self, parent, grass_command = "index", text = None,
  916. skip_description = False, **kwargs):
  917. self.grass_command = grass_command
  918. wx.Panel.__init__(self, parent = parent, id = wx.ID_ANY)
  919. self.content = HelpWindow(self, grass_command, text,
  920. skip_description)
  921. self.btnNext = wx.Button(parent = self, id = wx.ID_ANY,
  922. label = _("&Next"))
  923. self.btnNext.Enable(False)
  924. self.btnPrev = wx.Button(parent = self, id = wx.ID_ANY,
  925. label = _("&Previous"))
  926. self.btnPrev.Enable(False)
  927. self.btnNext.Bind(wx.EVT_BUTTON, self.OnNext)
  928. self.btnPrev.Bind(wx.EVT_BUTTON, self.OnPrev)
  929. self._layout()
  930. def _layout(self):
  931. """!Do layout"""
  932. sizer = wx.BoxSizer(wx.VERTICAL)
  933. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  934. btnSizer.Add(item = self.btnPrev, proportion = 0,
  935. flag = wx.ALL, border = 5)
  936. btnSizer.Add(item = wx.Size(1, 1), proportion = 1)
  937. btnSizer.Add(item = self.btnNext, proportion = 0,
  938. flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
  939. sizer.Add(item = self.content, proportion = 1,
  940. flag = wx.EXPAND)
  941. sizer.Add(item = btnSizer, proportion = 0,
  942. flag = wx.EXPAND)
  943. self.SetSizer(sizer)
  944. sizer.Fit(self)
  945. def LoadPage(self, path = None):
  946. """!Load page"""
  947. if not path:
  948. path = os.path.join(self.content.fspath, self.grass_command + ".html")
  949. self.content.history.append(path)
  950. self.content.LoadPage(path)
  951. def IsFile(self):
  952. """!Check if file exists"""
  953. return os.path.isfile(os.path.join(self.content.fspath, self.grass_command + ".html"))
  954. def IsLoaded(self):
  955. return self.content.loaded
  956. def OnHistory(self):
  957. """!Update buttons"""
  958. nH = len(self.content.history)
  959. iH = self.content.historyIdx
  960. if iH == nH - 1:
  961. self.btnNext.Enable(False)
  962. elif iH > -1:
  963. self.btnNext.Enable(True)
  964. if iH < 1:
  965. self.btnPrev.Enable(False)
  966. else:
  967. self.btnPrev.Enable(True)
  968. def OnNext(self, event):
  969. """Load next page"""
  970. self.content.historyIdx += 1
  971. idx = self.content.historyIdx
  972. path = self.content.history[idx]
  973. self.content.LoadPage(path)
  974. self.OnHistory()
  975. event.Skip()
  976. def OnPrev(self, event):
  977. """Load previous page"""
  978. self.content.historyIdx -= 1
  979. idx = self.content.historyIdx
  980. path = self.content.history[idx]
  981. self.content.LoadPage(path)
  982. self.OnHistory()
  983. event.Skip()