ghelp.py 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197
  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. 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.findBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  632. label=" %s " % _("Find extension by"))
  633. self.treeBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  634. label=" %s " % _("List of extensions"))
  635. self.repo = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY,
  636. value = 'https://svn.osgeo.org/grass/grass-addons')
  637. self.fullDesc = wx.CheckBox(parent = self.panel, id=wx.ID_ANY,
  638. label = _("Fetch full info including description and keywords (takes time)"))
  639. self.fullDesc.SetValue(False)
  640. self.search = SearchModuleWindow(parent = self.panel)
  641. self.search.SetSelection(2)
  642. self.tree = ExtensionTree(parent = self.panel, log = parent.GetLogWindow())
  643. self.statusbar = self.CreateStatusBar(0)
  644. self.btnFetch = wx.Button(parent = self.panel, id = wx.ID_ANY,
  645. label = _("&Fetch"))
  646. self.btnFetch.SetToolTipString(_("Fetch list of available modules from GRASS Addons SVN repository"))
  647. self.btnClose = wx.Button(parent = self.panel, id = wx.ID_CLOSE)
  648. self.btnInstall = wx.Button(parent = self.panel, id = wx.ID_ANY,
  649. label = _("&Install"))
  650. self.btnInstall.SetToolTipString(_("Install selected add-ons GRASS module"))
  651. self.btnInstall.Enable(False)
  652. self.btnClose.Bind(wx.EVT_BUTTON, self.OnCloseWindow)
  653. self.btnFetch.Bind(wx.EVT_BUTTON, self.OnFetch)
  654. self.btnInstall.Bind(wx.EVT_BUTTON, self.OnInstall)
  655. self.tree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnItemActivated)
  656. self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnItemSelected)
  657. self.search.Bind(wx.EVT_TEXT_ENTER, self.OnShowItem)
  658. self.search.Bind(wx.EVT_TEXT, self.OnUpdateStatusBar)
  659. self._layout()
  660. def _layout(self):
  661. """!Do layout"""
  662. sizer = wx.BoxSizer(wx.VERTICAL)
  663. repoSizer = wx.StaticBoxSizer(self.repoBox, wx.VERTICAL)
  664. repo1Sizer = wx.BoxSizer(wx.HORIZONTAL)
  665. repo1Sizer.Add(item = self.repo, proportion = 1,
  666. flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL, border = 1)
  667. repo1Sizer.Add(item = self.btnFetch, proportion = 0,
  668. flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL, border = 1)
  669. repoSizer.Add(item = repo1Sizer,
  670. flag = wx.EXPAND)
  671. repoSizer.Add(item = self.fullDesc)
  672. findSizer = wx.StaticBoxSizer(self.findBox, wx.HORIZONTAL)
  673. findSizer.Add(item = self.search, proportion = 1)
  674. treeSizer = wx.StaticBoxSizer(self.treeBox, wx.HORIZONTAL)
  675. treeSizer.Add(item = self.tree, proportion = 1,
  676. flag = wx.ALL | wx.EXPAND, border = 1)
  677. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  678. btnSizer.Add(item = self.btnClose, proportion = 0,
  679. flag = wx.RIGHT, border = 5)
  680. btnSizer.Add(item = self.btnInstall, proportion = 0)
  681. sizer.Add(item = repoSizer, proportion = 0,
  682. flag = wx.ALL | wx.EXPAND, border = 3)
  683. sizer.Add(item = findSizer, proportion = 0,
  684. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  685. sizer.Add(item = treeSizer, proportion = 1,
  686. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  687. sizer.Add(item = btnSizer, proportion=0,
  688. flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
  689. self.panel.SetSizer(sizer)
  690. sizer.Fit(self.panel)
  691. self.Layout()
  692. def _install(self, name):
  693. if not name:
  694. return
  695. log = self.parent.GetLogWindow()
  696. log.RunCmd(['g.extension', 'extension=' + name,
  697. 'svnurl=' + self.repo.GetValue().strip()])
  698. self.OnCloseWindow(None)
  699. def OnUpdateStatusBar(self, event):
  700. """!Update statusbar text"""
  701. element = self.search.GetSelection()
  702. if not self.tree.IsLoaded():
  703. self.SetStatusText(_("Fetch list of available extensions by clicking on 'Fetch' button"), 0)
  704. return
  705. self.tree.SearchItems(element = element,
  706. value = event.GetString())
  707. nItems = len(self.tree.itemsMarked)
  708. if event.GetString():
  709. self.SetStatusText(_("%d items match") % nItems, 0)
  710. else:
  711. self.SetStatusText("", 0)
  712. event.Skip()
  713. def OnCloseWindow(self, event):
  714. """!Close window"""
  715. self.Destroy()
  716. def OnFetch(self, event):
  717. """!Fetch list of available extensions"""
  718. self.SetStatusText(_("Fetching list of modules from GRASS-Addons SVN (be patient)..."), 0)
  719. self.tree.Load(url = self.repo.GetValue().strip(), full = self.fullDesc.IsChecked())
  720. self.SetStatusText("", 0)
  721. def OnItemActivated(self, event):
  722. item = event.GetItem()
  723. data = self.tree.GetPyData(item)
  724. if data and data.has_key('command'):
  725. self._install(data['command'])
  726. def OnInstall(self, event):
  727. """!Install selected extension"""
  728. item = self.tree.GetSelected()
  729. if not item.IsOk():
  730. return
  731. self._install(self.tree.GetItemText(item))
  732. def OnItemSelected(self, event):
  733. """!Item selected"""
  734. item = event.GetItem()
  735. self.tree.itemSelected = item
  736. data = self.tree.GetPyData(item)
  737. if not data:
  738. self.SetStatusText('', 0)
  739. self.btnInstall.Enable(False)
  740. else:
  741. self.SetStatusText(data.get('description', ''), 0)
  742. self.btnInstall.Enable(True)
  743. def OnShowItem(self, event):
  744. """!Show selected item"""
  745. self.tree.OnShowItem(event)
  746. if self.tree.GetSelected():
  747. self.btnInstall.Enable()
  748. else:
  749. self.btnInstall.Enable(False)
  750. class ExtensionTree(ItemTree):
  751. """!List of available extensions"""
  752. def __init__(self, parent, log, id = wx.ID_ANY,
  753. ctstyle = CT.TR_HIDE_ROOT | CT.TR_FULL_ROW_HIGHLIGHT | CT.TR_HAS_BUTTONS |
  754. CT.TR_LINES_AT_ROOT | CT.TR_SINGLE,
  755. **kwargs):
  756. self.parent = parent # GMFrame
  757. self.log = log
  758. super(ExtensionTree, self).__init__(parent, id, ctstyle = ctstyle, **kwargs)
  759. self._initTree()
  760. def _initTree(self):
  761. for prefix in ('display', 'database',
  762. 'general', 'imagery',
  763. 'misc', 'postscript', 'paint',
  764. 'raster', 'raster3D', 'sites', 'vector'):
  765. self.AppendItem(parentId = self.root,
  766. text = prefix)
  767. self._loaded = False
  768. def _expandPrefix(self, c):
  769. name = { 'd' : 'display',
  770. 'db' : 'database',
  771. 'g' : 'general',
  772. 'i' : 'imagery',
  773. 'm' : 'misc',
  774. 'ps' : 'postscript',
  775. 'p' : 'paint',
  776. 'r' : 'raster',
  777. 'r3' : 'raster3D',
  778. 's' : 'sites',
  779. 'v' : 'vector' }
  780. if name.has_key(c):
  781. return name[c]
  782. return c
  783. def _findItem(self, text):
  784. """!Find item"""
  785. item = self.GetFirstChild(self.root)[0]
  786. while item and item.IsOk():
  787. if text == self.GetItemText(item):
  788. return item
  789. item = self.GetNextSibling(item)
  790. return None
  791. def Load(self, url, full = False):
  792. """!Load list of extensions"""
  793. self.DeleteAllItems()
  794. self.root = self.AddRoot(_("Menu tree"))
  795. self._initTree()
  796. if full:
  797. flags = 'g'
  798. else:
  799. flags = 'l'
  800. ret = gcmd.RunCommand('g.extension', read = True,
  801. svnurl = url,
  802. flags = flags, quiet = True)
  803. if not ret:
  804. return
  805. mdict = dict()
  806. for line in ret.splitlines():
  807. if full:
  808. key, value = line.split('=', 1)
  809. if key == 'name':
  810. prefix, name = value.split('.', 1)
  811. if not mdict.has_key(prefix):
  812. mdict[prefix] = dict()
  813. mdict[prefix][name] = dict()
  814. else:
  815. mdict[prefix][name][key] = value
  816. else:
  817. prefix, name = line.strip().split('.', 1)
  818. if not mdict.has_key(prefix):
  819. mdict[prefix] = dict()
  820. mdict[prefix][name] = { 'command' : prefix + '.' + name }
  821. for prefix in mdict.keys():
  822. prefixName = self._expandPrefix(prefix)
  823. item = self._findItem(prefixName)
  824. names = mdict[prefix].keys()
  825. names.sort()
  826. for name in names:
  827. new = self.AppendItem(parentId = item,
  828. text = prefix + '.' + name)
  829. data = dict()
  830. for key in mdict[prefix][name].keys():
  831. data[key] = mdict[prefix][name][key]
  832. self.SetPyData(new, data)
  833. self._loaded = True
  834. def IsLoaded(self):
  835. """Check if items are loaded"""
  836. return self._loaded
  837. class HelpWindow(wx.html.HtmlWindow):
  838. """!This panel holds the text from GRASS docs.
  839. GISBASE must be set in the environment to find the html docs dir.
  840. The SYNOPSIS section is skipped, since this Panel is supposed to
  841. be integrated into the cmdPanel and options are obvious there.
  842. """
  843. def __init__(self, parent, grass_command, text, skip_description,
  844. **kwargs):
  845. """!If grass_command is given, the corresponding HTML help
  846. file will be presented, with all links pointing to absolute
  847. paths of local files.
  848. If 'skip_description' is True, the HTML corresponding to
  849. SYNOPSIS will be skipped, thus only presenting the help file
  850. from the DESCRIPTION section onwards.
  851. If 'text' is given, it must be the HTML text to be presented
  852. in the Panel.
  853. """
  854. self.parent = parent
  855. wx.InitAllImageHandlers()
  856. wx.html.HtmlWindow.__init__(self, parent = parent, **kwargs)
  857. gisbase = os.getenv("GISBASE")
  858. self.loaded = False
  859. self.history = list()
  860. self.historyIdx = 0
  861. self.fspath = os.path.join(gisbase, "docs", "html")
  862. self.SetStandardFonts (size = 10)
  863. self.SetBorders(10)
  864. if text is None:
  865. if skip_description:
  866. url = os.path.join(self.fspath, grass_command + ".html")
  867. self.fillContentsFromFile(url,
  868. skip_description = skip_description)
  869. self.history.append(url)
  870. self.loaded = True
  871. else:
  872. ### FIXME: calling LoadPage() is strangely time-consuming (only first call)
  873. # self.LoadPage(self.fspath + grass_command + ".html")
  874. self.loaded = False
  875. else:
  876. self.SetPage(text)
  877. self.loaded = True
  878. def OnLinkClicked(self, linkinfo):
  879. url = linkinfo.GetHref()
  880. if url[:4] != 'http':
  881. url = os.path.join(self.fspath, url)
  882. self.history.append(url)
  883. self.historyIdx += 1
  884. self.parent.OnHistory()
  885. super(HelpWindow, self).OnLinkClicked(linkinfo)
  886. def fillContentsFromFile(self, htmlFile, skip_description=True):
  887. """!Load content from file"""
  888. aLink = re.compile(r'(<a href="?)(.+\.html?["\s]*>)', re.IGNORECASE)
  889. imgLink = re.compile(r'(<img src="?)(.+\.[png|gif])', re.IGNORECASE)
  890. try:
  891. contents = []
  892. skip = False
  893. for l in file(htmlFile, "rb").readlines():
  894. if "DESCRIPTION" in l:
  895. skip = False
  896. if not skip:
  897. # do skip the options description if requested
  898. if "SYNOPSIS" in l:
  899. skip = skip_description
  900. else:
  901. # FIXME: find only first item
  902. findALink = aLink.search(l)
  903. if findALink is not None:
  904. contents.append(aLink.sub(findALink.group(1)+
  905. self.fspath+findALink.group(2),l))
  906. findImgLink = imgLink.search(l)
  907. if findImgLink is not None:
  908. contents.append(imgLink.sub(findImgLink.group(1)+
  909. self.fspath+findImgLink.group(2),l))
  910. if findALink is None and findImgLink is None:
  911. contents.append(l)
  912. self.SetPage("".join(contents))
  913. self.loaded = True
  914. except: # The Manual file was not found
  915. self.loaded = False
  916. class HelpPanel(wx.Panel):
  917. def __init__(self, parent, grass_command = "index", text = None,
  918. skip_description = False, **kwargs):
  919. self.grass_command = grass_command
  920. wx.Panel.__init__(self, parent = parent, id = wx.ID_ANY)
  921. self.content = HelpWindow(self, grass_command, text,
  922. skip_description)
  923. self.btnNext = wx.Button(parent = self, id = wx.ID_ANY,
  924. label = _("&Next"))
  925. self.btnNext.Enable(False)
  926. self.btnPrev = wx.Button(parent = self, id = wx.ID_ANY,
  927. label = _("&Previous"))
  928. self.btnPrev.Enable(False)
  929. self.btnNext.Bind(wx.EVT_BUTTON, self.OnNext)
  930. self.btnPrev.Bind(wx.EVT_BUTTON, self.OnPrev)
  931. self._layout()
  932. def _layout(self):
  933. """!Do layout"""
  934. sizer = wx.BoxSizer(wx.VERTICAL)
  935. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  936. btnSizer.Add(item = self.btnPrev, proportion = 0,
  937. flag = wx.ALL, border = 5)
  938. btnSizer.Add(item = wx.Size(1, 1), proportion = 1)
  939. btnSizer.Add(item = self.btnNext, proportion = 0,
  940. flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
  941. sizer.Add(item = self.content, proportion = 1,
  942. flag = wx.EXPAND)
  943. sizer.Add(item = btnSizer, proportion = 0,
  944. flag = wx.EXPAND)
  945. self.SetSizer(sizer)
  946. sizer.Fit(self)
  947. def LoadPage(self, path = None):
  948. """!Load page"""
  949. if not path:
  950. path = os.path.join(self.content.fspath, self.grass_command + ".html")
  951. self.content.history.append(path)
  952. self.content.LoadPage(path)
  953. def IsFile(self):
  954. """!Check if file exists"""
  955. return os.path.isfile(os.path.join(self.content.fspath, self.grass_command + ".html"))
  956. def IsLoaded(self):
  957. return self.content.loaded
  958. def OnHistory(self):
  959. """!Update buttons"""
  960. nH = len(self.content.history)
  961. iH = self.content.historyIdx
  962. if iH == nH - 1:
  963. self.btnNext.Enable(False)
  964. elif iH > -1:
  965. self.btnNext.Enable(True)
  966. if iH < 1:
  967. self.btnPrev.Enable(False)
  968. else:
  969. self.btnPrev.Enable(True)
  970. def OnNext(self, event):
  971. """Load next page"""
  972. self.content.historyIdx += 1
  973. idx = self.content.historyIdx
  974. path = self.content.history[idx]
  975. self.content.LoadPage(path)
  976. self.OnHistory()
  977. event.Skip()
  978. def OnPrev(self, event):
  979. """Load previous page"""
  980. self.content.historyIdx -= 1
  981. idx = self.content.historyIdx
  982. path = self.content.history[idx]
  983. self.content.LoadPage(path)
  984. self.OnHistory()
  985. event.Skip()