ghelp.py 32 KB

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