ghelp.py 48 KB

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