ghelp.py 47 KB

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