mcalc_builder.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. """!
  2. @package mcalc_builder.py
  3. @brief Map calculator, wrapper for r.mapcalc
  4. Classes:
  5. - MapCalcFrame
  6. (C) 2008, 2010 by the GRASS Development Team
  7. This program is free software under the GNU General Public License
  8. (>=v2). Read the file COPYING that comes with GRASS for details.
  9. @author Michael Barton, Arizona State University
  10. @author Martin Landa <landa.martin gmail.com>
  11. """
  12. import os
  13. import sys
  14. import time
  15. import globalvar
  16. if not os.getenv("GRASS_WXBUNDLED"):
  17. globalvar.CheckForWx()
  18. import wx
  19. import grass.script as grass
  20. import gcmd
  21. import gselect
  22. import menuform
  23. try:
  24. import subprocess
  25. except:
  26. sys.path.append(os.path.join(globalvar.ETCWXDIR, "compat"))
  27. import subprocess
  28. from preferences import globalSettings as UserSettings
  29. class MapCalcFrame(wx.Frame):
  30. """!Mapcalc Frame class. Calculator-style window to create and run
  31. r(3).mapcalc statements
  32. """
  33. def __init__(self, parent, cmd, id = wx.ID_ANY,
  34. style = wx.DEFAULT_FRAME_STYLE | wx.RESIZE_BORDER, **kwargs):
  35. self.parent = parent
  36. if self.parent:
  37. self.log = self.parent.GetLogWindow()
  38. else:
  39. self.log = None
  40. # grass command
  41. self.cmd = cmd
  42. if self.cmd == 'r.mapcalc':
  43. self.rast3d = False
  44. title = _('GRASS GIS Raster Map Calculator')
  45. if self.cmd == 'r3.mapcalc':
  46. self.rast3d = True
  47. title = _('GRASS GIS 3D Raster Map Calculator')
  48. wx.Frame.__init__(self, parent, id = id, title = title, **kwargs)
  49. self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO))
  50. self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
  51. #
  52. # variables
  53. #
  54. self.heading = _('mapcalc statement')
  55. self.funct_list = [
  56. 'abs(x)',
  57. 'acos(x)',
  58. 'asin(x)',
  59. 'atan(x)',
  60. 'atan(x,y)',
  61. 'cos(x)',
  62. 'double(x)',
  63. 'eval([x,y,...,]z)',
  64. 'exp(x)',
  65. 'exp(x,y)',
  66. 'float(x)',
  67. 'graph(x,x1,y1[x2,y2..])',
  68. 'if(x)',
  69. 'if(x,a)',
  70. 'if(x,a,b)',
  71. 'if(x,a,b,c)',
  72. 'int(x)',
  73. 'isnull(x)',
  74. 'log(x)',
  75. 'log(x,b)',
  76. 'max(x,y[,z...])',
  77. 'median(x,y[,z...])',
  78. 'min(x,y[,z...])',
  79. 'mode(x,y[,z...])',
  80. 'not(x)',
  81. 'pow(x,y)',
  82. 'rand(a,b)',
  83. 'round(x)',
  84. 'sin(x)',
  85. 'sqrt(x)',
  86. 'tan(x)',
  87. 'xor(x,y)',
  88. 'row()',
  89. 'col()',
  90. 'x()',
  91. 'y()',
  92. 'ewres()',
  93. 'nsres()',
  94. 'null()'
  95. ]
  96. if self.rast3d:
  97. indx = self.funct_list.index('y()') +1
  98. self.funct_list.insert(indx, 'z()')
  99. indx = self.funct_list.index('nsres()') +1
  100. self.funct_list.insert(indx, 'tbres()')
  101. maplabel = _('3D raster map')
  102. element = 'rast3d'
  103. else:
  104. maplabel = _('raster map')
  105. element = 'cell'
  106. self.operatorBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  107. label=" %s " % _('Operators'))
  108. self.operandBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  109. label=" %s " % _('Operands'))
  110. self.expressBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  111. label=" %s " % _('Expression'))
  112. #
  113. # Buttons
  114. #
  115. self.btn_clear = wx.Button(parent = self.panel, id = wx.ID_CLEAR)
  116. self.btn_help = wx.Button(parent = self.panel, id = wx.ID_HELP)
  117. self.btn_run = wx.Button(parent = self.panel, id = wx.ID_ANY, label = _("&Run"))
  118. self.btn_run.SetDefault()
  119. self.btn_close = wx.Button(parent = self.panel, id = wx.ID_CLOSE)
  120. self.btn_cmd = wx.Button(parent = self.panel, id = wx.ID_ANY,
  121. label = _("Command dialog"))
  122. self.btn_cmd.SetToolTipString(_('Open %s dialog') % self.cmd)
  123. self.btn = dict()
  124. self.btn['pow'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = "^")
  125. self.btn['pow'].SetToolTipString(_('exponent'))
  126. self.btn['div'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = "/")
  127. self.btn['div'].SetToolTipString(_('divide'))
  128. self.btn['add'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = "+")
  129. self.btn['add'].SetToolTipString(_('add'))
  130. self.btn['minus'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = "-")
  131. self.btn['minus'].SetToolTipString(_('subtract'))
  132. self.btn['mod'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = "%")
  133. self.btn['mod'].SetToolTipString(_('modulus'))
  134. self.btn['mult'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = "*")
  135. self.btn['mult'].SetToolTipString(_('multiply'))
  136. self.btn['paren'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = "( )")
  137. self.btn['lshift'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = "<<")
  138. self.btn['lshift'].SetToolTipString(_('left shift'))
  139. self.btn['rshift'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = ">>")
  140. self.btn['rshift'].SetToolTipString(_('right shift'))
  141. self.btn['rshiftu'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = ">>>")
  142. self.btn['rshiftu'].SetToolTipString(_('right shift (unsigned)'))
  143. self.btn['gt'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = ">")
  144. self.btn['gt'].SetToolTipString(_('greater than'))
  145. self.btn['gteq'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = ">=")
  146. self.btn['gteq'].SetToolTipString(_('greater than or equal to'))
  147. self.btn['lt'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = "<")
  148. self.btn['lt'].SetToolTipString(_('less than'))
  149. self.btn['lteq'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = "<=")
  150. self.btn['lteq'].SetToolTipString(_('less than or equal to'))
  151. self.btn['eq'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = "==")
  152. self.btn['eq'].SetToolTipString(_('equal to'))
  153. self.btn['noteq'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = "!=")
  154. self.btn['noteq'].SetToolTipString(_('not equal to'))
  155. self.btn['compl'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = "~")
  156. self.btn['compl'].SetToolTipString(_('one\'s complement'))
  157. self.btn['not'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = "!")
  158. self.btn['not'].SetToolTipString(_('NOT'))
  159. self.btn['andbit'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = '&&')
  160. self.btn['andbit'].SetToolTipString(_('bitwise AND'))
  161. self.btn['orbit'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = "|")
  162. self.btn['orbit'].SetToolTipString(_('bitwise OR'))
  163. self.btn['and'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = "&&&&")
  164. self.btn['and'].SetToolTipString(_('logical AND'))
  165. self.btn['andnull'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = "&&&&&&")
  166. self.btn['andnull'].SetToolTipString(_('logical AND (ignores NULLs)'))
  167. self.btn['or'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = "||")
  168. self.btn['or'].SetToolTipString(_('logical OR'))
  169. self.btn['ornull'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = "|||")
  170. self.btn['ornull'].SetToolTipString(_('logical OR (ignores NULLs)'))
  171. self.btn['cond'] = wx.Button(parent = self.panel, id = wx.ID_ANY, label = "a ? b : c")
  172. self.btn['cond'].SetToolTipString(_('conditional'))
  173. #
  174. # Text area
  175. #
  176. self.text_mcalc = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY, size = (-1, 75),
  177. style = wx.TE_MULTILINE)
  178. wx.CallAfter(self.text_mcalc.SetFocus)
  179. #
  180. # Map and function insertion text and ComboBoxes
  181. self.newmaplabel = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  182. label= _('Name for new %s to create') % maplabel)
  183. self.newmaptxt = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY, size=(250, -1))
  184. self.mapsellabel = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  185. label = _('Insert existing %s') % maplabel)
  186. self.mapselect = gselect.Select(parent = self.panel, id = wx.ID_ANY, size = (250, -1),
  187. type = element, multiple = False)
  188. self.functlabel = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  189. label = _('Insert mapcalc function'))
  190. self.function = wx.ComboBox(parent = self.panel, id = wx.ID_ANY,
  191. size = (250, -1), choices = self.funct_list,
  192. style = wx.CB_DROPDOWN |
  193. wx.CB_READONLY | wx.TE_PROCESS_ENTER)
  194. self.overwrite = wx.CheckBox(parent = self.panel, id = wx.ID_ANY,
  195. label=_("Allow output files to overwrite existing files"))
  196. self.overwrite.SetValue(UserSettings.Get(group='cmd', key='overwrite', subkey='enabled'))
  197. self.addbox = wx.CheckBox(parent=self.panel,
  198. label=_('Add created raster map into layer tree'), style = wx.NO_BORDER)
  199. self.addbox.SetValue(UserSettings.Get(group='cmd', key='addNewLayer', subkey='enabled'))
  200. if not self.parent or self.parent.GetName() != 'LayerManager':
  201. self.addbox.Hide()
  202. #
  203. # Bindings
  204. #
  205. for btn in self.btn.keys():
  206. self.btn[btn].Bind(wx.EVT_BUTTON, self.AddMark)
  207. self.btn_close.Bind(wx.EVT_BUTTON, self.OnClose)
  208. self.btn_clear.Bind(wx.EVT_BUTTON, self.OnClear)
  209. self.btn_run.Bind(wx.EVT_BUTTON, self.OnMCalcRun)
  210. self.btn_help.Bind(wx.EVT_BUTTON, self.OnHelp)
  211. self.btn_cmd.Bind(wx.EVT_BUTTON, self.OnCmdDialog)
  212. self.mapselect.Bind(wx.EVT_TEXT, self.OnSelect)
  213. self.function.Bind(wx.EVT_COMBOBOX, self.OnSelect)
  214. self.function.Bind(wx.EVT_TEXT_ENTER, self.OnSelect)
  215. self._layout()
  216. self.SetMinSize(self.GetBestSize())
  217. def _layout(self):
  218. sizer = wx.BoxSizer(wx.VERTICAL)
  219. controlSizer = wx.BoxSizer(wx.HORIZONTAL)
  220. operatorSizer = wx.StaticBoxSizer(self.operatorBox, wx.HORIZONTAL)
  221. buttonSizer1 = wx.GridBagSizer(5, 1)
  222. buttonSizer1.Add(item = self.btn['add'], pos = (0,0))
  223. buttonSizer1.Add(item = self.btn['minus'], pos = (0,1))
  224. buttonSizer1.Add(item = self.btn['mod'], pos = (5,0))
  225. buttonSizer1.Add(item = self.btn['mult'], pos = (1,0))
  226. buttonSizer1.Add(item = self.btn['div'], pos = (1,1))
  227. buttonSizer1.Add(item = self.btn['pow'], pos = (5,1))
  228. buttonSizer1.Add(item = self.btn['gt'], pos = (2,0))
  229. buttonSizer1.Add(item = self.btn['gteq'], pos = (2,1))
  230. buttonSizer1.Add(item = self.btn['eq'], pos = (4,0))
  231. buttonSizer1.Add(item = self.btn['lt'], pos = (3,0))
  232. buttonSizer1.Add(item = self.btn['lteq'], pos = (3,1))
  233. buttonSizer1.Add(item = self.btn['noteq'], pos = (4,1))
  234. buttonSizer2 = wx.GridBagSizer(5, 1)
  235. buttonSizer2.Add(item = self.btn['and'], pos = (0,0))
  236. buttonSizer2.Add(item = self.btn['andbit'], pos = (1,0))
  237. buttonSizer2.Add(item = self.btn['andnull'], pos = (2,0))
  238. buttonSizer2.Add(item = self.btn['or'], pos = (0,1))
  239. buttonSizer2.Add(item = self.btn['orbit'], pos = (1,1))
  240. buttonSizer2.Add(item = self.btn['ornull'], pos = (2,1))
  241. buttonSizer2.Add(item = self.btn['lshift'], pos = (3,0))
  242. buttonSizer2.Add(item = self.btn['rshift'], pos = (3,1))
  243. buttonSizer2.Add(item = self.btn['rshiftu'], pos = (4,0))
  244. buttonSizer2.Add(item = self.btn['cond'], pos = (5,0))
  245. buttonSizer2.Add(item = self.btn['compl'], pos = (5,1))
  246. buttonSizer2.Add(item = self.btn['not'], pos = (4,1))
  247. operandSizer = wx.StaticBoxSizer(self.operandBox, wx.HORIZONTAL)
  248. buttonSizer3 = wx.GridBagSizer(7, 1)
  249. buttonSizer3.Add(item = self.newmaplabel, pos = (0, 0),
  250. span = (1, 2), flag = wx.ALIGN_CENTER)
  251. buttonSizer3.Add(item = self.newmaptxt, pos = (1, 0),
  252. span = (1, 2))
  253. buttonSizer3.Add(item = self.mapsellabel, pos = (2, 0),
  254. span = (1, 2), flag = wx.ALIGN_CENTER)
  255. buttonSizer3.Add(item = self.mapselect, pos = (3, 0),
  256. span = (1, 2))
  257. buttonSizer3.Add(item = self.functlabel, pos = (4, 0),
  258. span = (1, 2), flag = wx.ALIGN_CENTER)
  259. buttonSizer3.Add(item = self.function, pos = (5, 0),
  260. span = (1, 2))
  261. buttonSizer3.Add(item = self.btn['paren'], pos = (6, 0),
  262. flag = wx.ALIGN_LEFT)
  263. buttonSizer3.Add(item = self.btn_clear, pos = (6, 1),
  264. flag = wx.ALIGN_RIGHT)
  265. buttonSizer4 = wx.BoxSizer(wx.HORIZONTAL)
  266. buttonSizer4.Add(item = self.btn_cmd,
  267. flag = wx.ALL, border = 5)
  268. buttonSizer4.Add(item = self.btn_close,
  269. flag = wx.ALL, border = 5)
  270. buttonSizer4.Add(item = self.btn_run,
  271. flag = wx.ALL, border = 5)
  272. buttonSizer4.Add(item = self.btn_help,
  273. flag = wx.ALL, border = 5)
  274. operatorSizer.Add(item = buttonSizer1, proportion = 0,
  275. flag = wx.ALL | wx.EXPAND, border = 5)
  276. operatorSizer.Add(item = buttonSizer2, proportion = 0,
  277. flag = wx.TOP | wx.BOTTOM | wx.RIGHT | wx.EXPAND, border = 5)
  278. operandSizer.Add(item = buttonSizer3, proportion = 0,
  279. flag = wx.TOP | wx.BOTTOM | wx.RIGHT, border = 5)
  280. controlSizer.Add(item = operatorSizer, proportion = 1,
  281. flag = wx.RIGHT, border = 5)
  282. controlSizer.Add(item = operandSizer, proportion = 0,
  283. flag = wx.EXPAND)
  284. expressSizer = wx.StaticBoxSizer(self.expressBox, wx.HORIZONTAL)
  285. expressSizer.Add(item = self.text_mcalc, proportion = 1,
  286. flag = wx.EXPAND)
  287. sizer.Add(item = controlSizer, proportion = 0,
  288. flag = wx.EXPAND | wx.ALL,
  289. border = 5)
  290. sizer.Add(item = expressSizer, proportion = 1,
  291. flag = wx.EXPAND | wx.LEFT | wx.RIGHT,
  292. border = 5)
  293. sizer.Add(item = self.overwrite, proportion = 0,
  294. flag = wx.EXPAND | wx.LEFT | wx.RIGHT,
  295. border = 5)
  296. if self.addbox.IsShown():
  297. sizer.Add(item = self.addbox, proportion = 0,
  298. flag = wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT,
  299. border = 5)
  300. sizer.Add(item = buttonSizer4, proportion = 0,
  301. flag = wx.ALL | wx.ALIGN_RIGHT, border = 1)
  302. self.panel.SetAutoLayout(True)
  303. self.panel.SetSizer(sizer)
  304. sizer.Fit(self.panel)
  305. self.Layout()
  306. def AddMark(self,event):
  307. """!Sends operators to insertion method
  308. """
  309. if event.GetId() == self.btn['compl'].GetId(): mark = "~"
  310. elif event.GetId() == self.btn['not'].GetId(): mark = "!"
  311. elif event.GetId() == self.btn['pow'].GetId(): mark = "^"
  312. elif event.GetId() == self.btn['div'].GetId(): mark = "/"
  313. elif event.GetId() == self.btn['add'].GetId(): mark = "+"
  314. elif event.GetId() == self.btn['minus'].GetId(): mark = "-"
  315. elif event.GetId() == self.btn['mod'].GetId(): mark = "%"
  316. elif event.GetId() == self.btn['mult'].GetId(): mark = "*"
  317. elif event.GetId() == self.btn['lshift'].GetId(): mark = "<<"
  318. elif event.GetId() == self.btn['rshift'].GetId(): mark = ">>"
  319. elif event.GetId() == self.btn['rshiftu'].GetId(): mark = ">>>"
  320. elif event.GetId() == self.btn['gt'].GetId(): mark = ">"
  321. elif event.GetId() == self.btn['gteq'].GetId(): mark = ">="
  322. elif event.GetId() == self.btn['lt'].GetId(): mark = "<"
  323. elif event.GetId() == self.btn['lteq'].GetId(): mark = "<="
  324. elif event.GetId() == self.btn['eq'].GetId(): mark = "=="
  325. elif event.GetId() == self.btn['noteq'].GetId(): mark = "!="
  326. elif event.GetId() == self.btn['andbit'].GetId(): mark = "&"
  327. elif event.GetId() == self.btn['orbit'].GetId(): mark = "|"
  328. elif event.GetId() == self.btn['or'].GetId(): mark = "||"
  329. elif event.GetId() == self.btn['ornull'].GetId(): mark = "|||"
  330. elif event.GetId() == self.btn['and'].GetId(): mark = "&&"
  331. elif event.GetId() == self.btn['andnull'].GetId(): mark = "&&&"
  332. elif event.GetId() == self.btn['cond'].GetId(): mark = " ? : "
  333. elif event.GetId() == self.btn['paren'].GetId(): mark = "( )"
  334. self._addSomething(mark)
  335. def OnSelect(self, event):
  336. """!Gets raster map or function selection and send it to
  337. insertion method
  338. """
  339. item = event.GetString()
  340. self._addSomething(item)
  341. def _addSomething(self, what):
  342. """!Inserts operators, map names, and functions into text area
  343. """
  344. self.text_mcalc.SetFocus()
  345. mcalcstr = self.text_mcalc.GetValue()
  346. position = self.text_mcalc.GetInsertionPoint()
  347. newmcalcstr = mcalcstr[:position]
  348. position_offset = 0
  349. try:
  350. if newmcalcstr[-1] != ' ':
  351. newmcalcstr += ' '
  352. position_offset += 1
  353. except:
  354. pass
  355. newmcalcstr += what
  356. position_offset += len(what)
  357. newmcalcstr += ' ' + mcalcstr[position:]
  358. self.text_mcalc.SetValue(newmcalcstr)
  359. if what == '()':
  360. position_offset -= 1
  361. self.text_mcalc.SetInsertionPoint(position + position_offset)
  362. self.text_mcalc.Update()
  363. def OnMCalcRun(self,event):
  364. """!Builds and runs r.mapcalc statement
  365. """
  366. name = self.newmaptxt.GetValue().strip()
  367. if not name:
  368. gcmd.GError(parent = self,
  369. message = _("You must enter the name of a new map to create"))
  370. return
  371. if not self.text_mcalc.GetValue().strip():
  372. gcmd.GError(parent = self,
  373. message = _("You must enter a mapcalc statement to create a new map"))
  374. return
  375. mctxt = self.text_mcalc.GetValue().strip().replace("\n"," ")
  376. mctxt = mctxt.replace(" " , "")
  377. if self.log:
  378. cmd = [self.cmd, str('expression=%s = %s' % (name, mctxt))]
  379. if self.overwrite.IsChecked():
  380. cmd.append('--overwrite')
  381. self.log.RunCmd(cmd, onDone = self.OnDone)
  382. self.parent.Raise()
  383. else:
  384. if self.overwrite.IsChecked():
  385. overwrite = True
  386. else:
  387. overwrite = False
  388. gcmd.RunCommand(self.cmd,
  389. expression = "%s=%s" % (name, mctxt),
  390. overwrite = overwrite)
  391. def OnDone(self, cmd, returncode):
  392. """!Add create map to the layer tree"""
  393. if not self.addbox.IsChecked():
  394. return
  395. name = self.newmaptxt.GetValue().strip() + '@' + grass.gisenv()['MAPSET']
  396. self.parent.GetLayerTree().AddLayer(ltype = 'vector',
  397. lname = name,
  398. lcmd = ['d.rast', 'map=%s' % name],
  399. multiple = False)
  400. display = self.parent.GetLayerTree().GetMapDisplay()
  401. if display and display.IsAutoRendered():
  402. display.GetWindow().UpdateMap(render = True)
  403. def OnClear(self, event):
  404. """!Clears text area
  405. """
  406. self.text_mcalc.SetValue('')
  407. def OnHelp(self, event):
  408. """!Launches r.mapcalc help
  409. """
  410. gcmd.RunCommand('g.manual', parent = self, entry = self.cmd)
  411. def OnClose(self,event):
  412. """!Close window"""
  413. self.Destroy()
  414. def OnCmdDialog(self, event):
  415. """!Shows command dialog"""
  416. name = self.newmaptxt.GetValue().strip()
  417. mctxt = self.text_mcalc.GetValue().strip().replace("\n"," ")
  418. mctxt = mctxt.replace(" " , "")
  419. expr = name
  420. if expr:
  421. expr += '='
  422. expr += mctxt
  423. menuform.GUI().ParseCommand(cmd = [self.cmd, 'expression=' + expr],
  424. parentframe = self)
  425. if __name__ == "__main__":
  426. app = wx.App(0)
  427. frame = MapCalcFrame(None, cmd = 'r.mapcalc')
  428. frame.Show()
  429. app.MainLoop()