ghelp.py 49 KB

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