ghelp.py 31 KB

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