ghelp.py 34 KB

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