ghelp.py 49 KB

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