ghelp.py 34 KB

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