ghelp.py 33 KB

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