ghelp.py 34 KB

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