ghelp.py 33 KB

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