ghelp.py 49 KB

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