ghelp.py 32 KB

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