ghelp.py 35 KB

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