ghelp.py 33 KB

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