ghelp.py 36 KB

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