ghelp.py 33 KB

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