ghelp.py 32 KB

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