ghelp.py 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. """!
  2. @package gui_core.ghelp
  3. @brief Help/about window, menu tree, search module tree
  4. Classes:
  5. - ghelp::SearchModuleWindow
  6. - ghelp::AboutWindow
  7. - ghelp::HelpFrame
  8. - ghelp::HelpWindow
  9. - ghelp::HelpPanel
  10. (C) 2008-2012 by the GRASS Development Team
  11. This program is free software under the GNU General Public License
  12. (>=v2). Read the file COPYING that comes with GRASS for details.
  13. @author Martin Landa <landa.martin gmail.com>
  14. """
  15. import os
  16. import sys
  17. import codecs
  18. import platform
  19. import wx
  20. from wx.html import HtmlWindow
  21. try:
  22. import wx.lib.agw.customtreectrl as CT
  23. from wx.lib.agw.hyperlink import HyperLinkCtrl
  24. except ImportError:
  25. import wx.lib.customtreectrl as CT
  26. from wx.lib.hyperlink import HyperLinkCtrl
  27. import wx.lib.flatnotebook as FN
  28. import grass.script as grass
  29. from core import globalvar
  30. from core import utils
  31. from core.gcmd import GError, DecodeString
  32. from gui_core.widgets import FormListbook, StaticWrapText, ScrolledPanel
  33. from core.debug import Debug
  34. from core.settings import UserSettings
  35. class SearchModuleWindow(wx.Panel):
  36. """!Search module window (used in MenuTreeWindow)"""
  37. def __init__(self, parent, id = wx.ID_ANY, cmdPrompt = None,
  38. showChoice = True, showTip = False, **kwargs):
  39. self.showTip = showTip
  40. self.showChoice = showChoice
  41. self.cmdPrompt = cmdPrompt
  42. wx.Panel.__init__(self, parent = parent, id = id, **kwargs)
  43. self._searchDict = { _('description') : 'description',
  44. _('command') : 'command',
  45. _('keywords') : 'keywords' }
  46. self.box = wx.StaticBox(parent = self, id = wx.ID_ANY,
  47. label = " %s " % _("Find module - (press Enter for next match)"))
  48. self.searchBy = wx.Choice(parent = self, id = wx.ID_ANY,
  49. choices = [_('description'),
  50. _('keywords'),
  51. _('command')])
  52. self.searchBy.SetSelection(0)
  53. self.search = wx.SearchCtrl(parent = self, id = wx.ID_ANY,
  54. size = (-1, 25), style = wx.TE_PROCESS_ENTER)
  55. if self.cmdPrompt:
  56. self.search.Bind(wx.EVT_TEXT, self.OnSearchModule)
  57. if self.showTip:
  58. self.searchTip = StaticWrapText(parent = self, id = wx.ID_ANY,
  59. size = (-1, 35))
  60. if self.showChoice:
  61. self.searchChoice = wx.Choice(parent = self, id = wx.ID_ANY)
  62. if self.cmdPrompt:
  63. self.searchChoice.SetItems(self.cmdPrompt.GetCommandItems())
  64. self.searchChoice.Bind(wx.EVT_CHOICE, self.OnSelectModule)
  65. self._layout()
  66. def _layout(self):
  67. """!Do layout"""
  68. sizer = wx.StaticBoxSizer(self.box, wx.HORIZONTAL)
  69. gridSizer = wx.GridBagSizer(hgap = 3, vgap = 3)
  70. gridSizer.Add(item = self.searchBy,
  71. flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
  72. gridSizer.Add(item = self.search,
  73. flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, pos = (0, 1))
  74. row = 1
  75. if self.showTip:
  76. gridSizer.Add(item = self.searchTip,
  77. flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, pos = (row, 0), span = (1, 2))
  78. row += 1
  79. if self.showChoice:
  80. gridSizer.Add(item = self.searchChoice,
  81. flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, pos = (row, 0), span = (1, 2))
  82. gridSizer.AddGrowableCol(1)
  83. sizer.Add(item = gridSizer, proportion = 1)
  84. self.SetSizer(sizer)
  85. sizer.Fit(self)
  86. def GetCtrl(self):
  87. """!Get SearchCtrl widget"""
  88. return self.search
  89. def GetSelection(self):
  90. """!Get selected element"""
  91. selection = self.searchBy.GetStringSelection()
  92. return self._searchDict[selection]
  93. def SetSelection(self, i):
  94. """!Set selection element"""
  95. self.searchBy.SetSelection(i)
  96. def OnSearchModule(self, event):
  97. """!Search module by keywords or description"""
  98. if not self.cmdPrompt:
  99. event.Skip()
  100. return
  101. text = event.GetString()
  102. if not text:
  103. self.cmdPrompt.SetFilter(None)
  104. mList = self.cmdPrompt.GetCommandItems()
  105. self.searchChoice.SetItems(mList)
  106. if self.showTip:
  107. self.searchTip.SetLabel(_("%d modules found") % len(mList))
  108. event.Skip()
  109. return
  110. modules = dict()
  111. iFound = 0
  112. for module, data in self.cmdPrompt.moduleDesc.iteritems():
  113. found = False
  114. sel = self.searchBy.GetSelection()
  115. if sel == 0: # -> description
  116. if text in data['desc']:
  117. found = True
  118. elif sel == 1: # keywords
  119. if text in ','.join(data['keywords']):
  120. found = True
  121. else: # command
  122. if module[:len(text)] == text:
  123. found = True
  124. if found:
  125. iFound += 1
  126. try:
  127. group, name = module.split('.')
  128. except ValueError:
  129. continue # TODO
  130. if group not in modules:
  131. modules[group] = list()
  132. modules[group].append(name)
  133. self.cmdPrompt.SetFilter(modules)
  134. self.searchChoice.SetItems(self.cmdPrompt.GetCommandItems())
  135. if self.showTip:
  136. self.searchTip.SetLabel(_("%d modules found") % iFound)
  137. event.Skip()
  138. def OnSelectModule(self, event):
  139. """!Module selected from choice, update command prompt"""
  140. cmd = event.GetString().split(' ', 1)[0]
  141. text = cmd + ' '
  142. pos = len(text)
  143. if self.cmdPrompt:
  144. self.cmdPrompt.SetText(text)
  145. self.cmdPrompt.SetSelectionStart(pos)
  146. self.cmdPrompt.SetCurrentPos(pos)
  147. self.cmdPrompt.SetFocus()
  148. desc = self.cmdPrompt.GetCommandDesc(cmd)
  149. if self.showTip:
  150. self.searchTip.SetLabel(desc)
  151. def Reset(self):
  152. """!Reset widget"""
  153. self.searchBy.SetSelection(0)
  154. self.search.SetValue('')
  155. if self.showTip:
  156. self.searchTip.SetLabel('')
  157. class AboutWindow(wx.Frame):
  158. """!Create custom About Window
  159. """
  160. def __init__(self, parent, size = (650, 460),
  161. title = _('About GRASS GIS'), **kwargs):
  162. wx.Frame.__init__(self, parent = parent, id = wx.ID_ANY, title = title, size = size, **kwargs)
  163. self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
  164. # icon
  165. self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO))
  166. # notebook
  167. self.aboutNotebook = FormListbook(self.panel, style = wx.BK_LEFT)
  168. for title, win in ((_("Info"), self._pageInfo()),
  169. (_("Copyright"), self._pageCopyright()),
  170. (_("License"), self._pageLicense()),
  171. (_("Authors"), self._pageCredit()),
  172. (_("Contributors"), self._pageContributors()),
  173. (_("Extra contributors"), self._pageContributors(extra = True)),
  174. (_("Translators"), self._pageTranslators()),
  175. (_("Translation status"), self._pageStats())):
  176. self.aboutNotebook.AddPage(page = win, text = title)
  177. self.aboutNotebook.Refresh()
  178. wx.CallAfter(self.aboutNotebook.SetSelection, 0)
  179. # buttons
  180. self.btnClose = wx.Button(parent = self.panel, id = wx.ID_CLOSE)
  181. self.btnClose.Bind(wx.EVT_BUTTON, self.OnCloseWindow)
  182. self._doLayout()
  183. def _doLayout(self):
  184. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  185. btnSizer.Add(item = self.btnClose, proportion = 0,
  186. flag = wx.ALL | wx.ALIGN_RIGHT,
  187. border = 5)
  188. sizer = wx.BoxSizer(wx.VERTICAL)
  189. sizer.Add(item = self.aboutNotebook, proportion = 1,
  190. flag = wx.EXPAND | wx.ALL, border = 1)
  191. sizer.Add(item = btnSizer, proportion = 0,
  192. flag = wx.ALL | wx.ALIGN_RIGHT, border = 1)
  193. self.SetMinSize((400, 400))
  194. self.panel.SetSizer(sizer)
  195. sizer.Fit(self.panel)
  196. self.Layout()
  197. def _pageInfo(self):
  198. """!Info page"""
  199. # get version and web site
  200. vInfo = grass.version()
  201. infoTxt = ScrolledPanel(self.aboutNotebook)
  202. infoTxt.SetBackgroundColour('WHITE')
  203. infoTxt.SetupScrolling()
  204. infoSizer = wx.BoxSizer(wx.VERTICAL)
  205. infoGridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  206. infoGridSizer.AddGrowableCol(0)
  207. infoGridSizer.AddGrowableCol(1)
  208. logo = os.path.join(globalvar.ETCDIR, "gui", "icons", "grass-64x64.png")
  209. logoBitmap = wx.StaticBitmap(parent = infoTxt, id = wx.ID_ANY,
  210. bitmap = wx.Bitmap(name = logo,
  211. type = wx.BITMAP_TYPE_PNG))
  212. infoSizer.Add(item = logoBitmap, proportion = 0,
  213. flag = wx.ALL | wx.ALIGN_CENTER, border = 20)
  214. info = wx.StaticText(parent = infoTxt, id = wx.ID_ANY,
  215. label = 'GRASS GIS ' + vInfo['version'] + '\n\n')
  216. info.SetFont(wx.Font(13, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
  217. info.SetForegroundColour(wx.Colour(35, 142, 35))
  218. infoSizer.Add(item = info, proportion = 0,
  219. flag = wx.BOTTOM | wx.ALIGN_CENTER, border = 1)
  220. row = 0
  221. infoGridSizer.Add(item = wx.StaticText(parent = infoTxt, id = wx.ID_ANY,
  222. label = _('Official GRASS site:')),
  223. pos = (row, 0),
  224. flag = wx.ALIGN_RIGHT)
  225. infoGridSizer.Add(item = HyperLinkCtrl(parent = infoTxt, id = wx.ID_ANY,
  226. label = 'http://grass.osgeo.org'),
  227. pos = (row, 1),
  228. flag = wx.ALIGN_LEFT)
  229. row += 2
  230. infoGridSizer.Add(item = wx.StaticText(parent = infoTxt, id = wx.ID_ANY,
  231. label = '%s:' % _('SVN Revision')),
  232. pos = (row, 0),
  233. flag = wx.ALIGN_RIGHT)
  234. infoGridSizer.Add(item = wx.StaticText(parent = infoTxt, id = wx.ID_ANY,
  235. label = vInfo['revision']),
  236. pos = (row, 1),
  237. flag = wx.ALIGN_LEFT)
  238. row += 1
  239. infoGridSizer.Add(item = wx.StaticText(parent = infoTxt, id = wx.ID_ANY,
  240. label = '%s:' % _('GIS Library Revision')),
  241. pos = (row, 0),
  242. flag = wx.ALIGN_RIGHT)
  243. infoGridSizer.Add(item = wx.StaticText(parent = infoTxt, id = wx.ID_ANY,
  244. label = vInfo['libgis_revision'] + ' (' +
  245. vInfo['libgis_date'].split(' ')[0] + ')'),
  246. pos = (row, 1),
  247. flag = wx.ALIGN_LEFT)
  248. row += 2
  249. infoGridSizer.Add(item = wx.StaticText(parent = infoTxt, id = wx.ID_ANY,
  250. label = 'Python:'),
  251. pos = (row, 0),
  252. flag = wx.ALIGN_RIGHT)
  253. infoGridSizer.Add(item = wx.StaticText(parent = infoTxt, id = wx.ID_ANY,
  254. label = platform.python_version()),
  255. pos = (row, 1),
  256. flag = wx.ALIGN_LEFT)
  257. row += 1
  258. infoGridSizer.Add(item = wx.StaticText(parent = infoTxt, id = wx.ID_ANY,
  259. label = 'wxPython:'),
  260. pos = (row, 0),
  261. flag = wx.ALIGN_RIGHT)
  262. infoGridSizer.Add(item = wx.StaticText(parent = infoTxt, id = wx.ID_ANY,
  263. label = wx.__version__),
  264. pos = (row, 1),
  265. flag = wx.ALIGN_LEFT)
  266. infoSizer.Add(item = infoGridSizer,
  267. proportion = 1,
  268. flag = wx.EXPAND | wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
  269. row += 2
  270. infoGridSizer.Add(item = wx.StaticText(parent = infoTxt, id = wx.ID_ANY,
  271. label = "%s:" % _('Language')),
  272. pos = (row, 0),
  273. flag = wx.ALIGN_RIGHT)
  274. self.langUsed = grass.gisenv().get('LANG', None)
  275. if not self.langUsed:
  276. import locale
  277. loc = locale.getdefaultlocale()
  278. if loc == (None, None):
  279. self.langUsed = _('unknown')
  280. else:
  281. self.langUsed = u'%s.%s' % (loc[0], loc[1])
  282. infoGridSizer.Add(item = wx.StaticText(parent = infoTxt, id = wx.ID_ANY,
  283. label = self.langUsed),
  284. pos = (row, 1),
  285. flag = wx.ALIGN_LEFT)
  286. infoTxt.SetSizer(infoSizer)
  287. infoSizer.Fit(infoTxt)
  288. return infoTxt
  289. def _pageCopyright(self):
  290. """Copyright information"""
  291. copyfile = os.path.join(os.getenv("GISBASE"), "COPYING")
  292. if os.path.exists(copyfile):
  293. copyrightFile = open(copyfile, 'r')
  294. copytext = copyrightFile.read()
  295. copyrightFile.close()
  296. else:
  297. copytext = _('%s file missing') % 'COPYING'
  298. # put text into a scrolling panel
  299. copyrightwin = ScrolledPanel(self.aboutNotebook)
  300. copyrightwin.SetBackgroundColour('WHITE')
  301. copyrighttxt = wx.StaticText(copyrightwin, id = wx.ID_ANY, label = copytext)
  302. copyrightwin.SetAutoLayout(True)
  303. copyrightwin.sizer = wx.BoxSizer(wx.VERTICAL)
  304. copyrightwin.sizer.Add(item = copyrighttxt, proportion = 1,
  305. flag = wx.EXPAND | wx.ALL, border = 3)
  306. copyrightwin.SetSizer(copyrightwin.sizer)
  307. copyrightwin.Layout()
  308. copyrightwin.SetupScrolling()
  309. return copyrightwin
  310. def _pageLicense(self):
  311. """Licence about"""
  312. licfile = os.path.join(os.getenv("GISBASE"), "GPL.TXT")
  313. if os.path.exists(licfile):
  314. licenceFile = open(licfile, 'r')
  315. license = ''.join(licenceFile.readlines())
  316. licenceFile.close()
  317. else:
  318. license = _('%s file missing') % 'GPL.TXT'
  319. # put text into a scrolling panel
  320. licensewin = ScrolledPanel(self.aboutNotebook)
  321. licensewin.SetBackgroundColour('WHITE')
  322. licensetxt = wx.StaticText(licensewin, id = wx.ID_ANY, label = license)
  323. licensewin.SetAutoLayout(True)
  324. licensewin.sizer = wx.BoxSizer(wx.VERTICAL)
  325. licensewin.sizer.Add(item = licensetxt, proportion = 1,
  326. flag = wx.EXPAND | wx.ALL, border = 3)
  327. licensewin.SetSizer(licensewin.sizer)
  328. licensewin.Layout()
  329. licensewin.SetupScrolling()
  330. return licensewin
  331. def _pageCredit(self):
  332. """Credit about"""
  333. # credits
  334. authfile = os.path.join(os.getenv("GISBASE"), "AUTHORS")
  335. if os.path.exists(authfile):
  336. authorsFile = open(authfile, 'r')
  337. authors = unicode(''.join(authorsFile.readlines()), "utf-8")
  338. authorsFile.close()
  339. else:
  340. authors = _('%s file missing') % 'AUTHORS'
  341. authorwin = ScrolledPanel(self.aboutNotebook)
  342. authorwin.SetBackgroundColour('WHITE')
  343. authortxt = wx.StaticText(authorwin, id = wx.ID_ANY, label = authors)
  344. authorwin.SetAutoLayout(True)
  345. authorwin.SetupScrolling()
  346. authorwin.sizer = wx.BoxSizer(wx.VERTICAL)
  347. authorwin.sizer.Add(item = authortxt, proportion = 1,
  348. flag = wx.EXPAND | wx.ALL, border = 3)
  349. authorwin.SetSizer(authorwin.sizer)
  350. authorwin.Layout()
  351. return authorwin
  352. def _pageContributors(self, extra = False):
  353. """Contributors info"""
  354. if extra:
  355. contribfile = os.path.join(os.getenv("GISBASE"), "contributors_extra.csv")
  356. else:
  357. contribfile = os.path.join(os.getenv("GISBASE"), "contributors.csv")
  358. if os.path.exists(contribfile):
  359. contribFile = codecs.open(contribfile, encoding = 'utf-8', mode = 'r')
  360. contribs = list()
  361. errLines = list()
  362. for line in contribFile.readlines()[1:]:
  363. line = line.rstrip('\n')
  364. try:
  365. if extra:
  366. name, email, country, rfc2_agreed = line.split(',')
  367. else:
  368. cvs_id, name, email, country, osgeo_id, rfc2_agreed = line.split(',')
  369. except ValueError:
  370. errLines.append(line)
  371. continue
  372. if extra:
  373. contribs.append((name, email, country))
  374. else:
  375. contribs.append((name, email, country, osgeo_id))
  376. contribFile.close()
  377. if errLines:
  378. GError(parent = self,
  379. message = _("Error when reading file '%s'.") % contribfile + \
  380. "\n\n" + _("Lines:") + " %s" % \
  381. os.linesep.join(map(DecodeString, errLines)))
  382. else:
  383. contribs = None
  384. contribwin = ScrolledPanel(self.aboutNotebook)
  385. contribwin.SetBackgroundColour('WHITE')
  386. contribwin.SetAutoLayout(True)
  387. contribwin.SetupScrolling()
  388. contribwin.sizer = wx.BoxSizer(wx.VERTICAL)
  389. if not contribs:
  390. contribtxt = wx.StaticText(contribwin, id = wx.ID_ANY,
  391. label = _('%s file missing') % contribfile)
  392. contribwin.sizer.Add(item = contribtxt, proportion = 1,
  393. flag = wx.EXPAND | wx.ALL, border = 3)
  394. else:
  395. if extra:
  396. items = (_('Name'), _('E-mail'), _('Country'))
  397. else:
  398. items = (_('Name'), _('E-mail'), _('Country'), _('OSGeo_ID'))
  399. contribBox = wx.FlexGridSizer(cols = len(items), vgap = 5, hgap = 5)
  400. for item in items:
  401. text = wx.StaticText(parent = contribwin, id = wx.ID_ANY,
  402. label = item)
  403. text.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
  404. contribBox.Add(item = text)
  405. for vals in sorted(contribs, key = lambda x: x[0]):
  406. for item in vals:
  407. contribBox.Add(item = wx.StaticText(parent = contribwin, id = wx.ID_ANY,
  408. label = item))
  409. contribwin.sizer.Add(item = contribBox, proportion = 1,
  410. flag = wx.EXPAND | wx.ALL, border = 3)
  411. contribwin.SetSizer(contribwin.sizer)
  412. contribwin.Layout()
  413. return contribwin
  414. def _pageTranslators(self):
  415. """Translators info"""
  416. translatorsfile = os.path.join(os.getenv("GISBASE"), "translators.csv")
  417. if os.path.exists(translatorsfile):
  418. translatorsFile = open(translatorsfile, 'r')
  419. translators = dict()
  420. errLines = list()
  421. for line in translatorsFile.readlines()[1:]:
  422. line = line.rstrip('\n')
  423. try:
  424. name, email, languages = line.split(',')
  425. except ValueError:
  426. errLines.append(line)
  427. continue
  428. for language in languages.split(' '):
  429. if language not in translators:
  430. translators[language] = list()
  431. translators[language].append((name, email))
  432. translatorsFile.close()
  433. if errLines:
  434. GError(parent = self,
  435. message = _("Error when reading file '%s'.") % translatorsfile + \
  436. "\n\n" + _("Lines:") + " %s" % \
  437. os.linesep.join(map(DecodeString, errLines)))
  438. else:
  439. translators = None
  440. translatorswin = ScrolledPanel(self.aboutNotebook)
  441. translatorswin.SetBackgroundColour('WHITE')
  442. translatorswin.SetAutoLayout(True)
  443. translatorswin.SetupScrolling()
  444. translatorswin.sizer = wx.BoxSizer(wx.VERTICAL)
  445. if not translators:
  446. translatorstxt = wx.StaticText(translatorswin, id = wx.ID_ANY,
  447. label = _('%s file missing') % 'translators.csv')
  448. translatorswin.sizer.Add(item = translatorstxt, proportion = 1,
  449. flag = wx.EXPAND | wx.ALL, border = 3)
  450. else:
  451. translatorsBox = wx.FlexGridSizer(cols = 4, vgap = 5, hgap = 5)
  452. languages = translators.keys()
  453. languages.sort()
  454. tname = wx.StaticText(parent = translatorswin, id = wx.ID_ANY,
  455. label = _('Name'))
  456. tname.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
  457. translatorsBox.Add(item = tname)
  458. temail = wx.StaticText(parent = translatorswin, id = wx.ID_ANY,
  459. label = _('E-mail'))
  460. temail.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
  461. translatorsBox.Add(item = temail)
  462. tlang = wx.StaticText(parent = translatorswin, id = wx.ID_ANY,
  463. label = _('Language'))
  464. tlang.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
  465. translatorsBox.Add(item = tlang)
  466. tnat = wx.StaticText(parent = translatorswin, id = wx.ID_ANY,
  467. label = _('Nation'))
  468. tnat.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
  469. translatorsBox.Add(item = tnat)
  470. for lang in languages:
  471. for translator in translators[lang]:
  472. name, email = translator
  473. translatorsBox.Add(item = wx.StaticText(parent = translatorswin, id = wx.ID_ANY,
  474. label = unicode(name, "utf-8")))
  475. translatorsBox.Add(item = wx.StaticText(parent = translatorswin, id = wx.ID_ANY,
  476. label = email))
  477. translatorsBox.Add(item = wx.StaticText(parent = translatorswin, id = wx.ID_ANY,
  478. label = lang))
  479. flag = os.path.join(os.getenv("GISBASE"), "etc", "gui",
  480. "icons", "flags", "%s.png" % lang.lower())
  481. if os.path.exists(flag):
  482. flagBitmap = wx.StaticBitmap(parent = translatorswin, id = wx.ID_ANY,
  483. bitmap = wx.Bitmap(name = flag,
  484. type = wx.BITMAP_TYPE_PNG))
  485. translatorsBox.Add(item = flagBitmap)
  486. else:
  487. translatorsBox.Add(item = wx.StaticText(parent = translatorswin,
  488. id = wx.ID_ANY, label = lang))
  489. translatorswin.sizer.Add(item = translatorsBox, proportion = 1,
  490. flag = wx.EXPAND | wx.ALL, border = 3)
  491. translatorswin.SetSizer(translatorswin.sizer)
  492. translatorswin.Layout()
  493. return translatorswin
  494. def _langString(self, k, v):
  495. """Return string for the status of translation"""
  496. allStr = "%s :" % k.upper()
  497. try:
  498. allStr += _(" %d translated" % v['good'])
  499. except:
  500. pass
  501. try:
  502. allStr += _(" %d fuzzy" % v['fuzzy'])
  503. except:
  504. pass
  505. try:
  506. allStr += _(" %d untranslated" % v['bad'])
  507. except:
  508. pass
  509. return allStr
  510. def _langBox(self, par, k, v):
  511. """Return box"""
  512. langBox = wx.FlexGridSizer(cols = 4, vgap = 5, hgap = 5)
  513. tkey = wx.StaticText(parent = par, id = wx.ID_ANY,
  514. label = k.upper())
  515. langBox.Add(item = tkey)
  516. try:
  517. tgood = wx.StaticText(parent = par, id = wx.ID_ANY,
  518. label = _("%d translated" % v['good']))
  519. tgood.SetForegroundColour(wx.Colour(35, 142, 35))
  520. langBox.Add(item = tgood)
  521. except:
  522. tgood = wx.StaticText(parent = par, id = wx.ID_ANY,
  523. label = "")
  524. langBox.Add(item = tgood)
  525. try:
  526. tfuzzy = wx.StaticText(parent = par, id = wx.ID_ANY,
  527. label = _(" %d fuzzy" % v['fuzzy']))
  528. tfuzzy.SetForegroundColour(wx.Colour(255, 142, 0))
  529. langBox.Add(item = tfuzzy)
  530. except:
  531. tfuzzy = wx.StaticText(parent = par, id = wx.ID_ANY,
  532. label = "")
  533. langBox.Add(item = tfuzzy)
  534. try:
  535. tbad = wx.StaticText(parent = par, id = wx.ID_ANY,
  536. label = _(" %d untranslated" % v['bad']))
  537. tbad.SetForegroundColour(wx.Colour(255, 0, 0))
  538. langBox.Add(item = tbad)
  539. except:
  540. tbad = wx.StaticText(parent = par, id = wx.ID_ANY,
  541. label = "")
  542. langBox.Add(item = tbad)
  543. return langBox
  544. def _langPanel(self, lang, js):
  545. """Create panel for each languages"""
  546. text = self._langString(lang, js['total'])
  547. panel = wx.CollapsiblePane(self.statswin, -1, label=text, style=wx.CP_DEFAULT_STYLE|wx.CP_NO_TLW_RESIZE)
  548. panel.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnPaneChanged)
  549. win = panel.GetPane()
  550. # TODO IT DOESN'T WORK
  551. # TO ADD ONLY WHEN TAB IS OPENED
  552. #if lang == self.langUsed.split('_')[0]:
  553. #panel.Collapse(False)
  554. #else:
  555. #panel.Collapse(True)
  556. pageSizer = wx.BoxSizer(wx.VERTICAL)
  557. for k,v in js.iteritems():
  558. if k != 'total' and k!= 'name':
  559. box = self._langBox(win, k,v)
  560. pageSizer.Add(item = box, proportion = 1,
  561. flag = wx.EXPAND | wx.ALL, border = 3)
  562. win.SetSizer(pageSizer)
  563. pageSizer.SetSizeHints(win)
  564. return panel
  565. def OnPaneChanged(self, evt):
  566. """Redo the layout"""
  567. # TODO better to test on Windows
  568. self.statswin.SetupScrolling(scrollToTop = False)
  569. def _pageStats(self):
  570. """Translation statistics info"""
  571. fname = "translation_status.json"
  572. statsfile = os.path.join(os.getenv("GISBASE"), fname)
  573. if os.path.exists(statsfile):
  574. statsFile = open(statsfile)
  575. import json
  576. jsStats = json.load(statsFile)
  577. else:
  578. jsStats = None
  579. self.statswin = ScrolledPanel(self.aboutNotebook)
  580. self.statswin.SetBackgroundColour('WHITE')
  581. self.statswin.SetAutoLayout(True)
  582. if not jsStats:
  583. Debug.msg(5, _("File <%s> not found") % fname)
  584. statsSizer = wx.BoxSizer(wx.VERTICAL)
  585. statstext = wx.StaticText(self.statswin, id = wx.ID_ANY,
  586. label = _('%s file missing') % fname)
  587. statsSizer.Add(item = statstext, proportion = 1,
  588. flag = wx.EXPAND | wx.ALL, border = 3)
  589. else:
  590. languages = jsStats['langs'].keys()
  591. languages.sort()
  592. statsSizer = wx.BoxSizer(wx.VERTICAL)
  593. for lang in languages:
  594. v = jsStats['langs'][lang]
  595. panel = self._langPanel(lang, v)
  596. statsSizer.Add(panel)
  597. self.statswin.SetSizer(statsSizer)
  598. self.statswin.SetupScrolling(scroll_x = False, scroll_y = True)
  599. self.statswin.Layout()
  600. self.statswin.Fit()
  601. return self.statswin
  602. def OnCloseWindow(self, event):
  603. """!Close window"""
  604. self.Close()
  605. class HelpFrame(wx.Dialog):
  606. """!GRASS Quickstart help window
  607. As a base class wx.Dialog is used, because of not working
  608. close button with wx.Frame when dialog is called from wizard.
  609. If parent is None, application TopLevelWindow is used (wxPython standard behaviour).
  610. Currently not used (was in location wizard before)
  611. due to unsolved problems - window sometimes does not respond.
  612. """
  613. def __init__(self, parent, id, title, size, file):
  614. wx.Dialog.__init__(self, parent = parent, id = id, title = title,
  615. size = size, style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER | wx.MINIMIZE_BOX)
  616. sizer = wx.BoxSizer(wx.VERTICAL)
  617. # text
  618. content = HelpPanel(parent = self)
  619. content.LoadPage(file)
  620. sizer.Add(item = content, proportion = 1, flag = wx.EXPAND)
  621. self.SetAutoLayout(True)
  622. self.SetSizer(sizer)
  623. self.Layout()
  624. class HelpWindow(HtmlWindow):
  625. """!This panel holds the text from GRASS docs.
  626. GISBASE must be set in the environment to find the html docs dir.
  627. The SYNOPSIS section is skipped, since this Panel is supposed to
  628. be integrated into the cmdPanel and options are obvious there.
  629. """
  630. def __init__(self, parent, command, text, skipDescription,
  631. **kwargs):
  632. """!If command is given, the corresponding HTML help
  633. file will be presented, with all links pointing to absolute
  634. paths of local files.
  635. If 'skipDescription' is True, the HTML corresponding to
  636. SYNOPSIS will be skipped, thus only presenting the help file
  637. from the DESCRIPTION section onwards.
  638. If 'text' is given, it must be the HTML text to be presented
  639. in the Panel.
  640. """
  641. self.parent = parent
  642. wx.InitAllImageHandlers()
  643. HtmlWindow.__init__(self, parent = parent, **kwargs)
  644. self.loaded = False
  645. self.history = list()
  646. self.historyIdx = 0
  647. self.fspath = os.path.join(os.getenv("GISBASE"), "docs", "html")
  648. self.SetStandardFonts (size = 10)
  649. self.SetBorders(10)
  650. if text is None:
  651. if skipDescription:
  652. url = os.path.join(self.fspath, command + ".html")
  653. self.fillContentsFromFile(url,
  654. skipDescription = skipDescription)
  655. self.history.append(url)
  656. self.loaded = True
  657. else:
  658. ### FIXME: calling LoadPage() is strangely time-consuming (only first call)
  659. # self.LoadPage(self.fspath + command + ".html")
  660. self.loaded = False
  661. else:
  662. self.SetPage(text)
  663. self.loaded = True
  664. def OnLinkClicked(self, linkinfo):
  665. url = linkinfo.GetHref()
  666. if url[:4] != 'http':
  667. url = os.path.join(self.fspath, url)
  668. self.history.append(url)
  669. self.historyIdx += 1
  670. self.parent.OnHistory()
  671. super(HelpWindow, self).OnLinkClicked(linkinfo)
  672. def fillContentsFromFile(self, htmlFile, skipDescription = True):
  673. """!Load content from file"""
  674. aLink = re.compile(r'(<a href="?)(.+\.html?["\s]*>)', re.IGNORECASE)
  675. imgLink = re.compile(r'(<img src="?)(.+\.[png|gif])', re.IGNORECASE)
  676. try:
  677. contents = []
  678. skip = False
  679. for l in file(htmlFile, "rb").readlines():
  680. if "DESCRIPTION" in l:
  681. skip = False
  682. if not skip:
  683. # do skip the options description if requested
  684. if "SYNOPSIS" in l:
  685. skip = skipDescription
  686. else:
  687. # FIXME: find only first item
  688. findALink = aLink.search(l)
  689. if findALink is not None:
  690. contents.append(aLink.sub(findALink.group(1)+
  691. self.fspath+findALink.group(2),l))
  692. findImgLink = imgLink.search(l)
  693. if findImgLink is not None:
  694. contents.append(imgLink.sub(findImgLink.group(1)+
  695. self.fspath+findImgLink.group(2),l))
  696. if findALink is None and findImgLink is None:
  697. contents.append(l)
  698. self.SetPage("".join(contents))
  699. self.loaded = True
  700. except: # The Manual file was not found
  701. self.loaded = False
  702. class HelpPanel(wx.Panel):
  703. def __init__(self, parent, command = "index", text = None,
  704. skipDescription = False, **kwargs):
  705. self.command = command
  706. wx.Panel.__init__(self, parent = parent, id = wx.ID_ANY)
  707. self.content = HelpWindow(self, command, text, skipDescription)
  708. self.btnNext = wx.Button(parent = self, id = wx.ID_ANY,
  709. label = _("&Next"))
  710. self.btnNext.Enable(False)
  711. self.btnPrev = wx.Button(parent = self, id = wx.ID_ANY,
  712. label = _("&Previous"))
  713. self.btnPrev.Enable(False)
  714. self.btnNext.Bind(wx.EVT_BUTTON, self.OnNext)
  715. self.btnPrev.Bind(wx.EVT_BUTTON, self.OnPrev)
  716. self._layout()
  717. def _layout(self):
  718. """!Do layout"""
  719. sizer = wx.BoxSizer(wx.VERTICAL)
  720. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  721. btnSizer.Add(item = self.btnPrev, proportion = 0,
  722. flag = wx.ALL, border = 5)
  723. btnSizer.Add(item = wx.Size(1, 1), proportion = 1)
  724. btnSizer.Add(item = self.btnNext, proportion = 0,
  725. flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
  726. sizer.Add(item = self.content, proportion = 1,
  727. flag = wx.EXPAND)
  728. sizer.Add(item = btnSizer, proportion = 0,
  729. flag = wx.EXPAND)
  730. self.SetSizer(sizer)
  731. sizer.Fit(self)
  732. def LoadPage(self, path = None):
  733. """!Load page"""
  734. if not path:
  735. path = self.GetFile()
  736. self.content.history.append(path)
  737. self.content.LoadPage(path)
  738. def GetFile(self):
  739. """!Get HTML file"""
  740. fMan = os.path.join(self.content.fspath, self.command + ".html")
  741. if os.path.isfile(fMan):
  742. return fMan
  743. # check also addons
  744. faMan = os.path.join(os.getenv('GRASS_ADDON_BASE'), "docs", "html",
  745. self.command + ".html")
  746. if os.getenv('GRASS_ADDON_BASE') and \
  747. os.path.isfile(faMan):
  748. return faMan
  749. return None
  750. def IsLoaded(self):
  751. return self.content.loaded
  752. def OnHistory(self):
  753. """!Update buttons"""
  754. nH = len(self.content.history)
  755. iH = self.content.historyIdx
  756. if iH == nH - 1:
  757. self.btnNext.Enable(False)
  758. elif iH > -1:
  759. self.btnNext.Enable(True)
  760. if iH < 1:
  761. self.btnPrev.Enable(False)
  762. else:
  763. self.btnPrev.Enable(True)
  764. def OnNext(self, event):
  765. """Load next page"""
  766. self.content.historyIdx += 1
  767. idx = self.content.historyIdx
  768. path = self.content.history[idx]
  769. self.content.LoadPage(path)
  770. self.OnHistory()
  771. event.Skip()
  772. def OnPrev(self, event):
  773. """Load previous page"""
  774. self.content.historyIdx -= 1
  775. idx = self.content.historyIdx
  776. path = self.content.history[idx]
  777. self.content.LoadPage(path)
  778. self.OnHistory()
  779. event.Skip()