forms.py 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298
  1. """
  2. @package gui_core.forms
  3. @brief Construct simple wxPython GUI from a GRASS command interface
  4. description.
  5. Classes:
  6. - forms::UpdateThread
  7. - forms::UpdateQThread
  8. - forms::TaskFrame
  9. - forms::CmdPanel
  10. - forms::GUI
  11. - forms::GrassGUIApp
  12. This program is just a coarse approach to automatically build a GUI
  13. from a xml-based GRASS user interface description.
  14. You need to have Python 2.4, wxPython 2.8 and python-xml.
  15. The XML stream is read from executing the command given in the
  16. command line, thus you may call it for instance this way:
  17. python <this file.py> r.basins.fill
  18. Or you set an alias or wrap the call up in a nice shell script, GUI
  19. environment ... please contribute your idea.
  20. Updated to wxPython 2.8 syntax and contrib widgets. Methods added to
  21. make it callable by gui. Method added to automatically re-run with
  22. pythonw on a Mac.
  23. @todo
  24. - verify option value types
  25. Copyright(C) 2000-2012 by the GRASS Development Team
  26. This program is free software under the GPL(>=v2) Read the file
  27. COPYING coming with GRASS for details.
  28. @author Jan-Oliver Wagner <jan@intevation.de>
  29. @author Bernhard Reiter <bernhard@intevation.de>
  30. @author Michael Barton, Arizona State University
  31. @author Daniel Calvelo <dca.gis@gmail.com>
  32. @author Martin Landa <landa.martin@gmail.com>
  33. @author Luca Delucchi <lucadeluge@gmail.com>
  34. @author Stepan Turek <stepan.turek seznam.cz> (CoordinatesSelect)
  35. """
  36. import sys
  37. import string
  38. import textwrap
  39. import os
  40. import time
  41. import copy
  42. import locale
  43. from threading import Thread
  44. import Queue
  45. gisbase = os.getenv("GISBASE")
  46. if gisbase is None:
  47. print >>sys.stderr, "We don't seem to be properly installed, or we are being run outside GRASS. Expect glitches."
  48. gisbase = os.path.join(os.path.dirname(sys.argv[0]), os.path.pardir)
  49. wxbase = gisbase
  50. else:
  51. wxbase = os.path.join(gisbase, 'etc', 'gui', 'wxpython')
  52. sys.path.append(wxbase)
  53. from core import globalvar
  54. import wx
  55. try:
  56. import wx.lib.agw.flatnotebook as FN
  57. except ImportError:
  58. import wx.lib.flatnotebook as FN
  59. import wx.lib.colourselect as csel
  60. import wx.lib.filebrowsebutton as filebrowse
  61. from wx.lib.newevent import NewEvent
  62. try:
  63. import xml.etree.ElementTree as etree
  64. except ImportError:
  65. import elementtree.ElementTree as etree # Python <= 2.4
  66. from grass.script import core as grass
  67. from grass.script import task as gtask
  68. from gui_core.widgets import StaticWrapText, ScrolledPanel
  69. from gui_core.ghelp import HelpPanel
  70. from gui_core import gselect
  71. from core import gcmd
  72. from core import utils
  73. from core.settings import UserSettings
  74. from gui_core.widgets import FloatValidator, GNotebook, FormNotebook, FormListbook
  75. wxUpdateDialog, EVT_DIALOG_UPDATE = NewEvent()
  76. """!Hide some options in the GUI"""
  77. #_blackList = { 'enabled' : False,
  78. # 'items' : { 'r.buffer' : {'params' : ['input', 'output'],
  79. # 'flags' : ['z', 'overwrite']}}}
  80. _blackList = { 'enabled' : False,
  81. 'items' : {} }
  82. def text_beautify(someString , width = 70):
  83. """!Make really long texts shorter, clean up whitespace and remove
  84. trailing punctuation.
  85. """
  86. if width > 0:
  87. return escape_ampersand(string.strip(
  88. os.linesep.join(textwrap.wrap(utils.normalize_whitespace(someString), width)),
  89. ".,;:"))
  90. else:
  91. return escape_ampersand(string.strip(utils.normalize_whitespace(someString), ".,;:"))
  92. def escape_ampersand(text):
  93. """!Escapes ampersands with additional ampersand for GUI"""
  94. return string.replace(text, "&", "&&")
  95. class UpdateThread(Thread):
  96. """!Update dialog widgets in the thread"""
  97. def __init__(self, parent, event, eventId, task):
  98. Thread.__init__(self)
  99. self.parent = parent
  100. self.event = event
  101. self.eventId = eventId
  102. self.task = task
  103. self.setDaemon(True)
  104. # list of functions which updates the dialog
  105. self.data = {}
  106. def run(self):
  107. # get widget id
  108. if not self.eventId:
  109. for p in self.task.params:
  110. if p.get('gisprompt', False) == False:
  111. continue
  112. prompt = p.get('element', '')
  113. if prompt == 'vector':
  114. name = p.get('name', '')
  115. if name in ('map', 'input'):
  116. self.eventId = p['wxId'][0]
  117. if self.eventId is None:
  118. return
  119. p = self.task.get_param(self.eventId, element = 'wxId', raiseError = False)
  120. if not p or 'wxId-bind' not in p:
  121. return
  122. # get widget prompt
  123. pType = p.get('prompt', '')
  124. if not pType:
  125. return
  126. # check for map/input parameter
  127. pMap = self.task.get_param('map', raiseError = False)
  128. if not pMap:
  129. pMap = self.task.get_param('input', raiseError = False)
  130. if pMap:
  131. map = pMap.get('value', '')
  132. else:
  133. map = None
  134. # avoid running db.describe several times
  135. cparams = dict()
  136. cparams[map] = { 'dbInfo' : None,
  137. 'layers' : None, }
  138. # update reference widgets
  139. for uid in p['wxId-bind']:
  140. win = self.parent.FindWindowById(uid)
  141. if not win:
  142. continue
  143. name = win.GetName()
  144. pBind = self.task.get_param(uid, element = 'wxId', raiseError = False)
  145. if pBind:
  146. pBind['value'] = ''
  147. map = layer = None
  148. driver = db = table = None
  149. if name in ('LayerSelect', 'ColumnSelect'):
  150. if p.get('element', '') == 'vector': # -> vector
  151. # get map name
  152. map = p.get('value', '')
  153. # get layer
  154. for bid in p['wxId-bind']:
  155. p = self.task.get_param(bid, element = 'wxId', raiseError = False)
  156. if not p:
  157. continue
  158. if p.get('element', '') == 'layer':
  159. layer = p.get('value', '')
  160. if layer != '':
  161. layer = p.get('value', '')
  162. else:
  163. layer = p.get('default', '')
  164. break
  165. elif p.get('element', '') == 'layer': # -> layer
  166. # get layer
  167. layer = p.get('value', '')
  168. if layer != '':
  169. layer = p.get('value', '')
  170. else:
  171. layer = p.get('default', '')
  172. # get map name
  173. pMapL = self.task.get_param(p['wxId'][0], element = 'wxId-bind', raiseError = False)
  174. if pMapL:
  175. map = pMapL.get('value', '')
  176. if name == 'TableSelect' or \
  177. (name == 'ColumnSelect' and not map):
  178. pDriver = self.task.get_param('dbdriver', element = 'prompt', raiseError = False)
  179. if pDriver:
  180. driver = pDriver.get('value', '')
  181. pDb = self.task.get_param('dbname', element = 'prompt', raiseError = False)
  182. if pDb:
  183. db = pDb.get('value', '')
  184. if name == 'ColumnSelect':
  185. pTable = self.task.get_param('dbtable', element = 'element', raiseError = False)
  186. if pTable:
  187. table = pTable.get('value', '')
  188. if name == 'LayerSelect':
  189. # determine format
  190. native = True
  191. for id in pMap['wxId']:
  192. winVec = self.parent.FindWindowById(id)
  193. if winVec.GetName() == 'VectorFormat' and \
  194. winVec.GetSelection() != 0:
  195. native = False
  196. break
  197. # TODO: update only if needed
  198. if native:
  199. if map:
  200. self.data[win.InsertLayers] = { 'vector' : map }
  201. else:
  202. self.data[win.InsertLayers] = { }
  203. else:
  204. if map:
  205. self.data[win.InsertLayers] = { 'dsn' : map.rstrip('@OGR') }
  206. else:
  207. self.data[win.InsertLayers] = { }
  208. elif name == 'TableSelect':
  209. self.data[win.InsertTables] = { 'driver' : driver,
  210. 'database' : db }
  211. elif name == 'ColumnSelect':
  212. if map:
  213. if map in cparams:
  214. if not cparams[map]['dbInfo']:
  215. cparams[map]['dbInfo'] = gselect.VectorDBInfo(map)
  216. self.data[win.InsertColumns] = { 'vector' : map, 'layer' : layer,
  217. 'dbInfo' : cparams[map]['dbInfo'] }
  218. else: # table
  219. if driver and db:
  220. self.data[win.InsertTableColumns] = { 'table' : pTable.get('value'),
  221. 'driver' : driver,
  222. 'database' : db }
  223. elif pTable:
  224. self.data[win.InsertTableColumns] = { 'table' : pTable.get('value') }
  225. elif name == 'SubGroupSelect':
  226. self.data[win.Insert] = { 'group' : p.get('value', '')}
  227. elif name == 'LocationSelect':
  228. pDbase = self.task.get_param('dbase', element = 'element', raiseError = False)
  229. if pDbase:
  230. self.data[win.UpdateItems] = { 'dbase' : pDbase.get('value', '')}
  231. elif name == 'MapsetSelect':
  232. pDbase = self.task.get_param('dbase', element = 'element', raiseError = False)
  233. pLocation = self.task.get_param('location', element = 'element', raiseError = False)
  234. if pDbase and pLocation:
  235. self.data[win.UpdateItems] = { 'dbase' : pDbase.get('value', ''),
  236. 'location' : pLocation.get('value', '')}
  237. elif name == 'ProjSelect':
  238. pDbase = self.task.get_param('dbase', element = 'element', raiseError = False)
  239. pLocation = self.task.get_param('location', element = 'element', raiseError = False)
  240. pMapset = self.task.get_param('mapset', element = 'element', raiseError = False)
  241. if pDbase and pLocation and pMapset:
  242. self.data[win.UpdateItems] = { 'dbase' : pDbase.get('value', ''),
  243. 'location' : pLocation.get('value', ''),
  244. 'mapset' : pMapset.get('value', '')}
  245. def UpdateDialog(parent, event, eventId, task):
  246. return UpdateThread(parent, event, eventId, task)
  247. class UpdateQThread(Thread):
  248. """!Update dialog widgets in the thread"""
  249. requestId = 0
  250. def __init__(self, parent, requestQ, resultQ, **kwds):
  251. Thread.__init__(self, **kwds)
  252. self.parent = parent # cmdPanel
  253. self.setDaemon(True)
  254. self.requestQ = requestQ
  255. self.resultQ = resultQ
  256. self.start()
  257. def Update(self, callable, *args, **kwds):
  258. UpdateQThread.requestId += 1
  259. self.request = None
  260. self.requestQ.put((UpdateQThread.requestId, callable, args, kwds))
  261. return UpdateQThread.requestId
  262. def run(self):
  263. while True:
  264. requestId, callable, args, kwds = self.requestQ.get()
  265. requestTime = time.time()
  266. self.request = callable(*args, **kwds)
  267. self.resultQ.put((requestId, self.request.run()))
  268. if self.request:
  269. event = wxUpdateDialog(data = self.request.data)
  270. wx.PostEvent(self.parent, event)
  271. class TaskFrame(wx.Frame):
  272. """!This is the Frame containing the dialog for options input.
  273. The dialog is organized in a notebook according to the guisections
  274. defined by each GRASS command.
  275. If run with a parent, it may Apply, Ok or Cancel; the latter two
  276. close the dialog. The former two trigger a callback.
  277. If run standalone, it will allow execution of the command.
  278. The command is checked and sent to the clipboard when clicking
  279. 'Copy'.
  280. """
  281. def __init__(self, parent, task_description, id = wx.ID_ANY,
  282. get_dcmd = None, layer = None,
  283. style = wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL, lmgr = None, **kwargs):
  284. self.get_dcmd = get_dcmd
  285. self.layer = layer
  286. self.task = task_description
  287. self.parent = parent # LayerTree | Modeler | None | ...
  288. self.lmgr = lmgr
  289. if parent and parent.GetName() == 'Modeler':
  290. self.modeler = self.parent
  291. else:
  292. self.modeler = None
  293. # module name + keywords
  294. if self.task.name.split('.')[-1] in ('py', 'sh'):
  295. title = str(self.task.name.rsplit('.',1)[0])
  296. else:
  297. title = self.task.name
  298. try:
  299. if self.task.keywords != ['']:
  300. title += " [" + ', '.join(self.task.keywords) + "]"
  301. except ValueError:
  302. pass
  303. wx.Frame.__init__(self, parent = parent, id = id, title = title,
  304. name = "MainFrame", **kwargs)
  305. self.locale = wx.Locale(language = wx.LANGUAGE_DEFAULT)
  306. self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
  307. # statusbar
  308. self.CreateStatusBar()
  309. # icon
  310. self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass_dialog.ico'), wx.BITMAP_TYPE_ICO))
  311. guisizer = wx.BoxSizer(wx.VERTICAL)
  312. # set apropriate output window
  313. if self.parent:
  314. self.standalone = False
  315. else:
  316. self.standalone = True
  317. # logo + description
  318. topsizer = wx.BoxSizer(wx.HORIZONTAL)
  319. # GRASS logo
  320. self.logo = wx.StaticBitmap(parent = self.panel,
  321. bitmap = wx.Bitmap(name = os.path.join(globalvar.ETCIMGDIR,
  322. 'grass_form.png'),
  323. type = wx.BITMAP_TYPE_PNG))
  324. topsizer.Add(item = self.logo, proportion = 0, border = 3,
  325. flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL)
  326. # add module description
  327. if self.task.label:
  328. module_desc = self.task.label + ' ' + self.task.description
  329. else:
  330. module_desc = self.task.description
  331. self.description = StaticWrapText(parent = self.panel,
  332. label = module_desc)
  333. topsizer.Add(item = self.description, proportion = 1, border = 5,
  334. flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  335. guisizer.Add(item = topsizer, proportion = 0, flag = wx.EXPAND)
  336. self.panel.SetSizerAndFit(guisizer)
  337. self.Layout()
  338. # notebooks
  339. self.notebookpanel = CmdPanel(parent = self.panel, task = self.task,
  340. frame = self, lmgr = self.lmgr)
  341. self.goutput = self.notebookpanel.goutput
  342. self.notebookpanel.OnUpdateValues = self.updateValuesHook
  343. guisizer.Add(item = self.notebookpanel, proportion = 1, flag = wx.EXPAND)
  344. # status bar
  345. status_text = _("Enter parameters for '") + self.task.name + "'"
  346. try:
  347. self.task.get_cmd()
  348. self.updateValuesHook()
  349. except ValueError:
  350. self.SetStatusText(status_text)
  351. # buttons
  352. btnsizer = wx.BoxSizer(orient = wx.HORIZONTAL)
  353. # cancel
  354. self.btn_cancel = wx.Button(parent = self.panel, id = wx.ID_CLOSE)
  355. self.btn_cancel.SetToolTipString(_("Close this window without executing the command (Ctrl+Q)"))
  356. btnsizer.Add(item = self.btn_cancel, proportion = 0, flag = wx.ALL | wx.ALIGN_CENTER, border = 10)
  357. self.btn_cancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  358. if self.get_dcmd is not None: # A callback has been set up
  359. btn_apply = wx.Button(parent = self.panel, id = wx.ID_APPLY)
  360. btn_ok = wx.Button(parent = self.panel, id = wx.ID_OK)
  361. btn_ok.SetDefault()
  362. btnsizer.Add(item = btn_apply, proportion = 0,
  363. flag = wx.ALL | wx.ALIGN_CENTER,
  364. border = 10)
  365. btnsizer.Add(item = btn_ok, proportion = 0,
  366. flag = wx.ALL | wx.ALIGN_CENTER,
  367. border = 10)
  368. btn_apply.Bind(wx.EVT_BUTTON, self.OnApply)
  369. btn_ok.Bind(wx.EVT_BUTTON, self.OnOK)
  370. else: # We're standalone
  371. # run
  372. self.btn_run = wx.Button(parent = self.panel, id = wx.ID_OK, label = _("&Run"))
  373. self.btn_run.SetToolTipString(_("Run the command (Ctrl+R)"))
  374. self.btn_run.SetDefault()
  375. self.btn_run.SetForegroundColour(wx.Colour(35, 142, 35))
  376. # copy
  377. self.btn_clipboard = wx.Button(parent = self.panel, id = wx.ID_COPY)
  378. self.btn_clipboard.SetToolTipString(_("Copy the current command string to the clipboard (Ctrl+C)"))
  379. btnsizer.Add(item = self.btn_run, proportion = 0,
  380. flag = wx.ALL | wx.ALIGN_CENTER,
  381. border = 10)
  382. btnsizer.Add(item = self.btn_clipboard, proportion = 0,
  383. flag = wx.ALL | wx.ALIGN_CENTER,
  384. border = 10)
  385. self.btn_run.Bind(wx.EVT_BUTTON, self.OnRun)
  386. self.btn_clipboard.Bind(wx.EVT_BUTTON, self.OnCopy)
  387. # help
  388. self.btn_help = wx.Button(parent = self.panel, id = wx.ID_HELP)
  389. self.btn_help.SetToolTipString(_("Show manual page of the command (Ctrl+H)"))
  390. self.btn_help.Bind(wx.EVT_BUTTON, self.OnHelp)
  391. if self.notebookpanel.notebook.GetPageIndexByName('manual') < 0:
  392. self.btn_help.Hide()
  393. # add help button
  394. btnsizer.Add(item = self.btn_help, proportion = 0, flag = wx.ALL | wx.ALIGN_CENTER, border = 10)
  395. guisizer.Add(item = btnsizer, proportion = 0, flag = wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT,
  396. border = 30)
  397. if self.parent and not self.modeler:
  398. addLayer = False
  399. for p in self.task.params:
  400. if p.get('age', 'old') == 'new' and \
  401. p.get('prompt', '') in ('raster', 'vector', '3d-raster'):
  402. addLayer = True
  403. if addLayer:
  404. # add newly created map into layer tree
  405. self.addbox = wx.CheckBox(parent = self.panel,
  406. label = _('Add created map(s) into layer tree'), style = wx.NO_BORDER)
  407. self.addbox.SetValue(UserSettings.Get(group = 'cmd', key = 'addNewLayer', subkey = 'enabled'))
  408. guisizer.Add(item = self.addbox, proportion = 0,
  409. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  410. border = 5)
  411. hasNew = False
  412. for p in self.task.params:
  413. if p.get('age', 'old') == 'new':
  414. hasNew = True
  415. break
  416. if self.get_dcmd is None and hasNew:
  417. # close dialog when command is terminated
  418. self.closebox = wx.CheckBox(parent = self.panel,
  419. label = _('Close dialog on finish'), style = wx.NO_BORDER)
  420. self.closebox.SetValue(UserSettings.Get(group = 'cmd', key = 'closeDlg', subkey = 'enabled'))
  421. self.closebox.SetToolTipString(_("Close dialog when command is successfully finished. "
  422. "Change this settings in Preferences dialog ('Command' tab)."))
  423. guisizer.Add(item = self.closebox, proportion = 0,
  424. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  425. border = 5)
  426. self.Bind(wx.EVT_CLOSE, self.OnCancel)
  427. self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
  428. # do layout
  429. # called automatically by SetSizer()
  430. self.panel.SetAutoLayout(True)
  431. self.panel.SetSizerAndFit(guisizer)
  432. sizeFrame = self.GetBestSize()
  433. self.SetMinSize(sizeFrame)
  434. if hasattr(self, "closebox"):
  435. scale = 0.33
  436. else:
  437. scale = 0.50
  438. self.SetSize(wx.Size(sizeFrame[0], sizeFrame[1] + scale * max(self.notebookpanel.panelMinHeight,
  439. self.notebookpanel.constrained_size[1])))
  440. # thread to update dialog
  441. # create queues
  442. self.requestQ = Queue.Queue()
  443. self.resultQ = Queue.Queue()
  444. self.updateThread = UpdateQThread(self.notebookpanel, self.requestQ, self.resultQ)
  445. self.Layout()
  446. # keep initial window size limited for small screens
  447. width, height = self.GetSizeTuple()
  448. self.SetSize(wx.Size(min(width, 650),
  449. min(height, 500)))
  450. # fix goutput's pane size (required for Mac OSX)
  451. if self.goutput:
  452. self.goutput.SetSashPosition(int(self.GetSize()[1] * .75))
  453. def updateValuesHook(self, event = None):
  454. """!Update status bar data"""
  455. self.SetStatusText(' '.join(self.notebookpanel.createCmd(ignoreErrors = True)))
  456. if event:
  457. event.Skip()
  458. def OnKeyUp(self, event):
  459. """!Key released (check hot-keys)"""
  460. try:
  461. kc = chr(event.GetKeyCode())
  462. except ValueError:
  463. event.Skip()
  464. return
  465. if not event.ControlDown():
  466. event.Skip()
  467. return
  468. if kc == 'Q':
  469. self.OnCancel(None)
  470. elif kc == 'S':
  471. self.OnAbort(None)
  472. elif kc == 'H':
  473. self.OnHelp(None)
  474. elif kc == 'R':
  475. self.OnRun(None)
  476. elif kc == 'C':
  477. self.OnCopy(None)
  478. event.Skip()
  479. def OnDone(self, cmd, returncode):
  480. """!This function is launched from OnRun() when command is
  481. finished
  482. @param returncode command's return code (0 for success)
  483. """
  484. if not self.parent or returncode != 0:
  485. return
  486. if self.parent.GetName() not in ('LayerTree', 'LayerManager'):
  487. return
  488. if self.parent.GetName() == 'LayerTree':
  489. display = self.parent.GetMapDisplay()
  490. else: # Layer Manager
  491. display = self.parent.GetLayerTree().GetMapDisplay()
  492. if not display or not display.IsAutoRendered():
  493. return
  494. mapLayers = map(lambda x: x.GetName(),
  495. display.GetMap().GetListOfLayers(l_type = 'raster') +
  496. display.GetMap().GetListOfLayers(l_type = 'vector'))
  497. task = GUI(show = None).ParseCommand(cmd)
  498. for p in task.get_options()['params']:
  499. if p.get('prompt', '') not in ('raster', 'vector'):
  500. continue
  501. mapName = p.get('value', '')
  502. if '@' not in mapName:
  503. mapName = mapName + '@' + grass.gisenv()['MAPSET']
  504. if mapName in mapLayers:
  505. display.GetWindow().UpdateMap(render = True)
  506. return
  507. def OnOK(self, event):
  508. """!OK button pressed"""
  509. cmd = self.OnApply(event)
  510. if cmd is not None and self.get_dcmd is not None:
  511. self.OnCancel(event)
  512. def OnApply(self, event):
  513. """!Apply the command"""
  514. if self.modeler:
  515. cmd = self.createCmd(ignoreErrors = True, ignoreRequired = True)
  516. else:
  517. cmd = self.createCmd()
  518. if cmd is not None and self.get_dcmd is not None:
  519. # return d.* command to layer tree for rendering
  520. self.get_dcmd(cmd, self.layer, {"params": self.task.params,
  521. "flags" : self.task.flags},
  522. self)
  523. # echo d.* command to output console
  524. # self.parent.writeDCommand(cmd)
  525. return cmd
  526. def OnRun(self, event):
  527. """!Run the command"""
  528. cmd = self.createCmd()
  529. if not cmd or len(cmd) < 1:
  530. return
  531. ret = 0
  532. if self.standalone or cmd[0][0:2] != "d.":
  533. # Send any non-display command to parent window (probably wxgui.py)
  534. # put to parents switch to 'Command output'
  535. self.notebookpanel.notebook.SetSelectionByName('output')
  536. try:
  537. if self.task.path:
  538. cmd[0] = self.task.path # full path
  539. ret = self.goutput.RunCmd(cmd, onDone = self.OnDone)
  540. except AttributeError, e:
  541. print >> sys.stderr, "%s: Probably not running in wxgui.py session?" % (e)
  542. print >> sys.stderr, "parent window is: %s" % (str(self.parent))
  543. else:
  544. gcmd.Command(cmd)
  545. if ret != 0:
  546. self.notebookpanel.notebook.SetSelection(0)
  547. return
  548. # update buttons status
  549. for btn in (self.btn_run,
  550. self.btn_cancel,
  551. self.btn_clipboard,
  552. self.btn_help):
  553. btn.Enable(False)
  554. def OnAbort(self, event):
  555. """!Abort running command"""
  556. from gui_core.goutput import wxCmdAbort
  557. event = wxCmdAbort(aborted = True)
  558. wx.PostEvent(self.goutput, event)
  559. def OnCopy(self, event):
  560. """!Copy the command"""
  561. cmddata = wx.TextDataObject()
  562. # list -> string
  563. cmdstring = ' '.join(self.createCmd(ignoreErrors = True))
  564. cmddata.SetText(cmdstring)
  565. if wx.TheClipboard.Open():
  566. # wx.TheClipboard.UsePrimarySelection(True)
  567. wx.TheClipboard.SetData(cmddata)
  568. wx.TheClipboard.Close()
  569. self.SetStatusText(_("'%s' copied to clipboard") % \
  570. (cmdstring))
  571. def OnCancel(self, event):
  572. """!Cancel button pressed"""
  573. self.MakeModal(False)
  574. if self.get_dcmd and \
  575. self.parent and \
  576. self.parent.GetName() in ('LayerTree',
  577. 'MapWindow'):
  578. # display decorations and
  579. # pressing OK or cancel after setting layer properties
  580. if self.task.name in ['d.barscale','d.legend','d.histogram'] \
  581. or len(self.parent.GetPyData(self.layer)[0]['cmd']) >= 1:
  582. self.Hide()
  583. # canceled layer with nothing set
  584. elif len(self.parent.GetPyData(self.layer)[0]['cmd']) < 1:
  585. self.parent.Delete(self.layer)
  586. self.Destroy()
  587. else:
  588. # cancel for non-display commands
  589. self.Destroy()
  590. def OnHelp(self, event):
  591. """!Show manual page (switch to the 'Manual' notebook page)"""
  592. if self.notebookpanel.notebook.GetPageIndexByName('manual') > -1:
  593. self.notebookpanel.notebook.SetSelectionByName('manual')
  594. self.notebookpanel.OnPageChange(None)
  595. if event:
  596. event.Skip()
  597. def createCmd(self, ignoreErrors = False, ignoreRequired = False):
  598. """!Create command string (python list)"""
  599. return self.notebookpanel.createCmd(ignoreErrors = ignoreErrors,
  600. ignoreRequired = ignoreRequired)
  601. class CmdPanel(wx.Panel):
  602. """!A panel containing a notebook dividing in tabs the different
  603. guisections of the GRASS cmd.
  604. """
  605. def __init__(self, parent, task, id = wx.ID_ANY, frame = None, lmgr = None, *args, **kwargs):
  606. if frame:
  607. self.parent = frame
  608. else:
  609. self.parent = parent
  610. self.task = task
  611. wx.Panel.__init__(self, parent, id = id, *args, **kwargs)
  612. # Determine tab layout
  613. sections = []
  614. is_section = {}
  615. not_hidden = [ p for p in self.task.params + self.task.flags if not p.get('hidden', False) == True ]
  616. self.label_id = [] # wrap titles on resize
  617. self.Bind(wx.EVT_SIZE, self.OnSize)
  618. for task in not_hidden:
  619. if task.get('required', False):
  620. # All required go into Main, even if they had defined another guisection
  621. task['guisection'] = _('Required')
  622. if task.get('guisection','') == '':
  623. # Undefined guisections end up into Options
  624. task['guisection'] = _('Optional')
  625. if task['guisection'] not in is_section:
  626. # We do it like this to keep the original order, except for Main which goes first
  627. is_section[task['guisection']] = 1
  628. sections.append(task['guisection'])
  629. else:
  630. is_section[ task['guisection'] ] += 1
  631. del is_section
  632. # 'Required' tab goes first, 'Optional' as the last one
  633. for (newidx,content) in [ (0,_('Required')), (len(sections)-1,_('Optional')) ]:
  634. if content in sections:
  635. idx = sections.index(content)
  636. sections[idx:idx+1] = []
  637. sections[newidx:newidx] = [content]
  638. panelsizer = wx.BoxSizer(orient = wx.VERTICAL)
  639. # build notebook
  640. style = UserSettings.Get(group = 'appearance', key = 'commandNotebook', subkey = 'selection')
  641. if style == 0: # basic top
  642. self.notebook = FormNotebook(self, style = wx.BK_TOP)
  643. self.notebook.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChange)
  644. elif style == 1: # basic left
  645. self.notebook = FormNotebook(self, style = wx.BK_LEFT)
  646. self.notebook.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChange)
  647. elif style == 2: # fancy green
  648. self.notebook = GNotebook(self, style = globalvar.FNPageStyle | FN.FNB_NO_X_BUTTON )
  649. self.notebook.SetTabAreaColour(globalvar.FNPageColor)
  650. self.notebook.Bind(FN.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.OnPageChange)
  651. elif style == 3:
  652. self.notebook = FormListbook(self, style = wx.BK_LEFT)
  653. self.notebook.Bind(wx.EVT_LISTBOOK_PAGE_CHANGED, self.OnPageChange)
  654. self.notebook.Refresh()
  655. imageList = wx.ImageList(16, 16)
  656. self.notebook.AssignImageList(imageList)
  657. tab = {}
  658. tabsizer = {}
  659. for section in sections:
  660. tab[section] = ScrolledPanel(parent = self.notebook)
  661. tab[section].SetScrollRate(10, 10)
  662. tabsizer[section] = wx.BoxSizer(orient = wx.VERTICAL)
  663. self.notebook.AddPage(page = tab[section], text = section, name = section)
  664. index = self.AddBitmapToImageList(section, imageList)
  665. if index >= 0:
  666. self.notebook.SetPageImage(section, index)
  667. # are we running from command line?
  668. ### add 'command output' tab regardless standalone dialog
  669. if self.parent.GetName() == "MainFrame" and self.parent.get_dcmd is None:
  670. from gui_core.goutput import GMConsole
  671. self.goutput = GMConsole(parent = self.notebook, frame = self.parent, margin = False, notebook = self.notebook)
  672. self.outpage = self.notebook.AddPage(page = self.goutput, text = _("Command output"), name = 'output')
  673. index = self.AddBitmapToImageList(section = 'output', imageList = imageList)
  674. if index >= 0:
  675. self.notebook.SetPageImage('output', index)
  676. else:
  677. self.goutput = None
  678. self.manual_tab = HelpPanel(parent = self.notebook, grass_command = self.task.name)
  679. if not self.manual_tab.IsFile():
  680. self.manual_tab.Hide()
  681. else:
  682. self.notebook.AddPage(page = self.manual_tab, text = _("Manual"), name = 'manual')
  683. index = self.AddBitmapToImageList(section = 'manual', imageList = imageList)
  684. if index >= 0:
  685. self.notebook.SetPageImage('manual', index)
  686. self.notebook.SetSelection(0)
  687. panelsizer.Add(item = self.notebook, proportion = 1, flag = wx.EXPAND)
  688. #
  689. # flags
  690. #
  691. text_style = wx.FONTWEIGHT_NORMAL
  692. visible_flags = [ f for f in self.task.flags if not f.get('hidden', False) == True ]
  693. for f in visible_flags:
  694. which_sizer = tabsizer[ f['guisection'] ]
  695. which_panel = tab[ f['guisection'] ]
  696. # if label is given: description -> tooltip
  697. if f.get('label','') != '':
  698. title = text_beautify(f['label'])
  699. tooltip = text_beautify(f['description'], width = -1)
  700. else:
  701. title = text_beautify(f['description'])
  702. tooltip = None
  703. title_sizer = wx.BoxSizer(wx.HORIZONTAL)
  704. rtitle_txt = wx.StaticText(parent = which_panel,
  705. label = '(' + f['name'] + ')')
  706. chk = wx.CheckBox(parent = which_panel, label = title, style = wx.NO_BORDER)
  707. self.label_id.append(chk.GetId())
  708. if tooltip:
  709. chk.SetToolTipString(tooltip)
  710. chk.SetValue(f.get('value', False))
  711. title_sizer.Add(item = chk, proportion = 1,
  712. flag = wx.EXPAND)
  713. title_sizer.Add(item = rtitle_txt, proportion = 0,
  714. flag = wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
  715. which_sizer.Add(item = title_sizer, proportion = 0,
  716. flag = wx.EXPAND | wx.TOP | wx.LEFT | wx.RIGHT, border = 5)
  717. f['wxId'] = [ chk.GetId(), ]
  718. chk.Bind(wx.EVT_CHECKBOX, self.OnSetValue)
  719. if self.parent.GetName() == 'MainFrame' and self.parent.modeler:
  720. parChk = wx.CheckBox(parent = which_panel, id = wx.ID_ANY,
  721. label = _("Parameterized in model"))
  722. parChk.SetName('ModelParam')
  723. parChk.SetValue(f.get('parameterized', False))
  724. if 'wxId' in f:
  725. f['wxId'].append(parChk.GetId())
  726. else:
  727. f['wxId'] = [ parChk.GetId() ]
  728. parChk.Bind(wx.EVT_CHECKBOX, self.OnSetValue)
  729. which_sizer.Add(item = parChk, proportion = 0,
  730. flag = wx.LEFT, border = 20)
  731. if f['name'] in ('verbose', 'quiet'):
  732. chk.Bind(wx.EVT_CHECKBOX, self.OnVerbosity)
  733. vq = UserSettings.Get(group = 'cmd', key = 'verbosity', subkey = 'selection')
  734. if f['name'] == vq:
  735. chk.SetValue(True)
  736. f['value'] = True
  737. elif f['name'] == 'overwrite' and 'value' not in f:
  738. chk.SetValue(UserSettings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled'))
  739. f['value'] = UserSettings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled')
  740. #
  741. # parameters
  742. #
  743. visible_params = [ p for p in self.task.params if not p.get('hidden', False) == True ]
  744. try:
  745. first_param = visible_params[0]
  746. except IndexError:
  747. first_param = None
  748. for p in visible_params:
  749. which_sizer = tabsizer[p['guisection']]
  750. which_panel = tab[p['guisection']]
  751. # if label is given -> label and description -> tooltip
  752. # otherwise description -> lavel
  753. if p.get('label','') != '':
  754. title = text_beautify(p['label'])
  755. tooltip = text_beautify(p['description'], width = -1)
  756. else:
  757. title = text_beautify(p['description'])
  758. tooltip = None
  759. txt = None
  760. prompt = p.get('prompt', '')
  761. # text style (required -> bold)
  762. if not p.get('required', False):
  763. text_style = wx.FONTWEIGHT_NORMAL
  764. else:
  765. text_style = wx.FONTWEIGHT_BOLD
  766. # title sizer (description, name, type)
  767. if (len(p.get('values', [])) > 0) and \
  768. p.get('multiple', False) and \
  769. p.get('gisprompt', False) == False and \
  770. p.get('type', '') == 'string':
  771. title_txt = wx.StaticBox(parent = which_panel, id = wx.ID_ANY)
  772. else:
  773. title_sizer = wx.BoxSizer(wx.HORIZONTAL)
  774. title_txt = wx.StaticText(parent = which_panel)
  775. if p['key_desc']:
  776. ltype = ','.join(p['key_desc'])
  777. else:
  778. ltype = p['type']
  779. rtitle_txt = wx.StaticText(parent = which_panel,
  780. label = '(' + p['name'] + '=' + ltype + ')')
  781. title_sizer.Add(item = title_txt, proportion = 1,
  782. flag = wx.LEFT | wx.TOP | wx.EXPAND, border = 5)
  783. title_sizer.Add(item = rtitle_txt, proportion = 0,
  784. flag = wx.ALIGN_RIGHT | wx.RIGHT | wx.TOP, border = 5)
  785. which_sizer.Add(item = title_sizer, proportion = 0,
  786. flag = wx.EXPAND)
  787. self.label_id.append(title_txt.GetId())
  788. # title expansion
  789. if p.get('multiple', False) and len(p.get('values','')) == 0:
  790. title = _("[multiple]") + " " + title
  791. if p.get('value','') == '' :
  792. p['value'] = p.get('default','')
  793. if (len(p.get('values', [])) > 0):
  794. valuelist = map(str, p.get('values',[]))
  795. valuelist_desc = map(unicode, p.get('values_desc',[]))
  796. if p.get('multiple', False) and \
  797. p.get('gisprompt',False) == False and \
  798. p.get('type', '') == 'string':
  799. title_txt.SetLabel(" %s: (%s, %s) " % (title, p['name'], p['type']))
  800. if valuelist_desc:
  801. hSizer = wx.StaticBoxSizer(box = title_txt, orient = wx.VERTICAL)
  802. else:
  803. hSizer = wx.StaticBoxSizer(box = title_txt, orient = wx.HORIZONTAL)
  804. isEnabled = {}
  805. # copy default values
  806. if p['value'] == '':
  807. p['value'] = p.get('default', '')
  808. for defval in p.get('value', '').split(','):
  809. isEnabled[ defval ] = 'yes'
  810. # for multi checkboxes, this is an array of all wx IDs
  811. # for each individual checkbox
  812. p[ 'wxId' ] = list()
  813. idx = 0
  814. for val in valuelist:
  815. try:
  816. label = valuelist_desc[idx]
  817. except IndexError:
  818. label = val
  819. chkbox = wx.CheckBox(parent = which_panel,
  820. label = text_beautify(label))
  821. p[ 'wxId' ].append(chkbox.GetId())
  822. if val in isEnabled:
  823. chkbox.SetValue(True)
  824. hSizer.Add(item = chkbox, proportion = 0,
  825. flag = wx.ADJUST_MINSIZE | wx.ALL, border = 1)
  826. chkbox.Bind(wx.EVT_CHECKBOX, self.OnCheckBoxMulti)
  827. idx += 1
  828. which_sizer.Add(item = hSizer, proportion = 0,
  829. flag = wx.EXPAND | wx.TOP | wx.RIGHT | wx.LEFT, border = 5)
  830. elif p.get('gisprompt', False) == False:
  831. if len(valuelist) == 1: # -> textctrl
  832. title_txt.SetLabel("%s (%s %s):" % (title, _('valid range'),
  833. str(valuelist[0])))
  834. if p.get('type', '') == 'integer' and \
  835. not p.get('multiple', False):
  836. # for multiple integers use textctrl instead of spinsctrl
  837. try:
  838. minValue, maxValue = map(int, valuelist[0].split('-'))
  839. except ValueError:
  840. minValue = -1e6
  841. maxValue = 1e6
  842. txt2 = wx.SpinCtrl(parent = which_panel, id = wx.ID_ANY, size = globalvar.DIALOG_SPIN_SIZE,
  843. min = minValue, max = maxValue)
  844. txt2.SetName("SpinCtrl")
  845. style = wx.BOTTOM | wx.LEFT
  846. else:
  847. txt2 = wx.TextCtrl(parent = which_panel, value = p.get('default',''))
  848. txt2.SetName("TextCtrl")
  849. style = wx.EXPAND | wx.BOTTOM | wx.LEFT
  850. value = self._getValue(p)
  851. # parameter previously set
  852. if value:
  853. if txt2.GetName() == "SpinCtrl":
  854. txt2.SetValue(int(value))
  855. else:
  856. txt2.SetValue(value)
  857. which_sizer.Add(item = txt2, proportion = 0,
  858. flag = style, border = 5)
  859. p['wxId'] = [ txt2.GetId(), ]
  860. txt2.Bind(wx.EVT_TEXT, self.OnSetValue)
  861. else:
  862. title_txt.SetLabel(title + ':')
  863. value = self._getValue(p)
  864. if p['name'] == 'icon': # symbols
  865. bitmap = wx.Bitmap(os.path.join(globalvar.ETCSYMBOLDIR, value) + '.png')
  866. bb = wx.BitmapButton(parent = which_panel, id = wx.ID_ANY,
  867. bitmap = bitmap)
  868. iconLabel = wx.StaticText(parent = which_panel, id = wx.ID_ANY)
  869. iconLabel.SetLabel(value)
  870. p['value'] = value
  871. p['wxId'] = [bb.GetId(), iconLabel.GetId()]
  872. bb.Bind(wx.EVT_BUTTON, self.OnSetSymbol)
  873. this_sizer = wx.BoxSizer(wx.HORIZONTAL)
  874. this_sizer.Add(item = bb, proportion = 0,
  875. flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT, border = 5)
  876. this_sizer.Add(item = iconLabel, proportion = 0,
  877. flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border = 5)
  878. which_sizer.Add(item = this_sizer, proportion = 0,
  879. flag = wx.ADJUST_MINSIZE, border = 0)
  880. else:
  881. # list of values (combo)
  882. cb = wx.ComboBox(parent = which_panel, id = wx.ID_ANY, value = p.get('default',''),
  883. size = globalvar.DIALOG_COMBOBOX_SIZE,
  884. choices = valuelist, style = wx.CB_DROPDOWN)
  885. if value:
  886. cb.SetValue(value) # parameter previously set
  887. which_sizer.Add(item = cb, proportion = 0,
  888. flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT, border = 5)
  889. p['wxId'] = [cb.GetId(),]
  890. cb.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
  891. cb.Bind(wx.EVT_TEXT, self.OnSetValue)
  892. # text entry
  893. if (p.get('type','string') in ('string','integer','float')
  894. and len(p.get('values',[])) == 0
  895. and p.get('gisprompt',False) == False
  896. and p.get('prompt','') != 'color'):
  897. title_txt.SetLabel(title + ':')
  898. if p.get('multiple', False) or \
  899. p.get('type', 'string') == 'string' or \
  900. len(p.get('key_desc', [])) > 1:
  901. txt3 = wx.TextCtrl(parent = which_panel, value = p.get('default',''))
  902. value = self._getValue(p)
  903. if value:
  904. # parameter previously set
  905. txt3.SetValue(str(value))
  906. txt3.Bind(wx.EVT_TEXT, self.OnSetValue)
  907. style = wx.EXPAND | wx.BOTTOM | wx.LEFT | wx.RIGHT
  908. else:
  909. minValue = -1e9
  910. maxValue = 1e9
  911. if p.get('type', '') == 'integer':
  912. txt3 = wx.SpinCtrl(parent = which_panel, value = p.get('default',''),
  913. size = globalvar.DIALOG_SPIN_SIZE,
  914. min = minValue, max = maxValue)
  915. style = wx.BOTTOM | wx.LEFT | wx.RIGHT
  916. value = self._getValue(p)
  917. if value:
  918. txt3.SetValue(int(value)) # parameter previously set
  919. txt3.Bind(wx.EVT_SPINCTRL, self.OnSetValue)
  920. else:
  921. txt3 = wx.TextCtrl(parent = which_panel, value = p.get('default',''),
  922. validator = FloatValidator())
  923. style = wx.EXPAND | wx.BOTTOM | wx.LEFT | wx.RIGHT
  924. value = self._getValue(p)
  925. if value:
  926. txt3.SetValue(str(value)) # parameter previously set
  927. txt3.Bind(wx.EVT_TEXT, self.OnSetValue)
  928. which_sizer.Add(item = txt3, proportion = 0,
  929. flag = style, border = 5)
  930. p['wxId'] = [ txt3.GetId(), ]
  931. #
  932. # element selection tree combobox (maps, icons, regions, etc.)
  933. #
  934. if p.get('gisprompt', False):
  935. title_txt.SetLabel(title + ':')
  936. # GIS element entry
  937. if p.get('prompt','') not in ('color',
  938. 'color_none',
  939. 'subgroup',
  940. 'dbdriver',
  941. 'dbname',
  942. 'dbtable',
  943. 'dbcolumn',
  944. 'layer',
  945. 'layer_all',
  946. 'location',
  947. 'mapset',
  948. 'dbase',
  949. 'coords') and \
  950. p.get('element', '') not in ('file', 'dir'):
  951. multiple = p.get('multiple', False)
  952. if p.get('age', '') == 'new':
  953. mapsets = [grass.gisenv()['MAPSET'],]
  954. else:
  955. mapsets = None
  956. if self.task.name in ('r.proj', 'v.proj') \
  957. and p.get('name', '') == 'input':
  958. if self.task.name == 'r.proj':
  959. isRaster = True
  960. else:
  961. isRaster = False
  962. selection = gselect.ProjSelect(parent = which_panel,
  963. isRaster = isRaster)
  964. p['wxId'] = [ selection.GetId(), ]
  965. selection.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
  966. formatSelector = False
  967. selection.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
  968. else:
  969. selection = gselect.Select(parent = which_panel, id = wx.ID_ANY,
  970. size = globalvar.DIALOG_GSELECT_SIZE,
  971. type = p.get('element', ''),
  972. multiple = multiple, mapsets = mapsets,
  973. fullyQualified = p.get('age', 'old') == 'old')
  974. value = self._getValue(p)
  975. if value:
  976. selection.SetValue(value)
  977. formatSelector = True
  978. # A select.Select is a combobox with two children: a textctl and a popupwindow;
  979. # we target the textctl here
  980. textWin = selection.GetTextCtrl()
  981. p['wxId'] = [ textWin.GetId(), ]
  982. textWin.Bind(wx.EVT_TEXT, self.OnSetValue)
  983. if prompt == 'vector':
  984. selection.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
  985. # if formatSelector and p.get('age', 'old') == 'old':
  986. # # OGR supported (read-only)
  987. # self.hsizer = wx.BoxSizer(wx.HORIZONTAL)
  988. # self.hsizer.Add(item = selection,
  989. # flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT | wx.RIGHT | wx.TOP | wx.ALIGN_TOP,
  990. # border = 5)
  991. # # format (native / ogr)
  992. # rbox = wx.RadioBox(parent = which_panel, id = wx.ID_ANY,
  993. # label = " %s " % _("Format"),
  994. # style = wx.RA_SPECIFY_ROWS,
  995. # choices = [_("Native / Linked OGR"), _("Direct OGR")])
  996. # if p.get('value', '').lower().rfind('@ogr') > -1:
  997. # rbox.SetSelection(1)
  998. # rbox.SetName('VectorFormat')
  999. # rbox.Bind(wx.EVT_RADIOBOX, self.OnVectorFormat)
  1000. # self.hsizer.Add(item = rbox,
  1001. # flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT |
  1002. # wx.RIGHT | wx.ALIGN_TOP,
  1003. # border = 5)
  1004. # ogrSelection = gselect.GdalSelect(parent = self, panel = which_panel, ogr = True,
  1005. # default = 'dir',
  1006. # exclude = ['file'])
  1007. # self.Bind(gselect.EVT_GDALSELECT, self.OnUpdateSelection)
  1008. # self.Bind(gselect.EVT_GDALSELECT, self.OnSetValue)
  1009. # ogrSelection.SetName('OgrSelect')
  1010. # ogrSelection.Hide()
  1011. # which_sizer.Add(item = self.hsizer, proportion = 0)
  1012. # p['wxId'].append(rbox.GetId())
  1013. # p['wxId'].append(ogrSelection.GetId())
  1014. # for win in ogrSelection.GetDsnWin():
  1015. # p['wxId'].append(win.GetId())
  1016. # else:
  1017. which_sizer.Add(item = selection, proportion = 0,
  1018. flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT | wx.RIGHT | wx.TOP | wx.ALIGN_CENTER_VERTICAL,
  1019. border = 5)
  1020. elif prompt == 'group':
  1021. selection.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
  1022. which_sizer.Add(item = selection, proportion = 0,
  1023. flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT | wx.RIGHT | wx.TOP | wx.ALIGN_CENTER_VERTICAL,
  1024. border = 5)
  1025. else:
  1026. which_sizer.Add(item = selection, proportion = 0,
  1027. flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT | wx.RIGHT | wx.TOP | wx.ALIGN_CENTER_VERTICAL,
  1028. border = 5)
  1029. # subgroup
  1030. elif prompt == 'subgroup':
  1031. selection = gselect.SubGroupSelect(parent = which_panel)
  1032. p['wxId'] = [ selection.GetId() ]
  1033. selection.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
  1034. selection.Bind(wx.EVT_TEXT, self.OnSetValue)
  1035. which_sizer.Add(item = selection, proportion = 0,
  1036. flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT | wx.RIGHT | wx.TOP | wx.ALIGN_CENTER_VERTICAL,
  1037. border = 5)
  1038. # layer, dbdriver, dbname, dbcolumn, dbtable entry
  1039. elif prompt in ('dbdriver',
  1040. 'dbname',
  1041. 'dbtable',
  1042. 'dbcolumn',
  1043. 'layer',
  1044. 'layer_all',
  1045. 'location',
  1046. 'mapset',
  1047. 'dbase'):
  1048. if p.get('multiple', 'no') == 'yes':
  1049. win = wx.TextCtrl(parent = which_panel, value = p.get('default',''),
  1050. size = globalvar.DIALOG_TEXTCTRL_SIZE)
  1051. win.Bind(wx.EVT_TEXT, self.OnSetValue)
  1052. else:
  1053. value = self._getValue(p)
  1054. if prompt in ('layer', 'layer_all'):
  1055. if prompt == 'layer_all':
  1056. all = True
  1057. else:
  1058. all = False
  1059. if p.get('age', 'old') == 'old':
  1060. win = gselect.LayerSelect(parent = which_panel,
  1061. all = all,
  1062. default = p['default'])
  1063. win.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
  1064. win.Bind(wx.EVT_TEXT, self.OnSetValue)
  1065. win.SetValue(str(value)) # default or previously set value
  1066. else:
  1067. win = wx.SpinCtrl(parent = which_panel, id = wx.ID_ANY,
  1068. min = 1, max = 100, initial = int(p['default']))
  1069. win.Bind(wx.EVT_SPINCTRL, self.OnSetValue)
  1070. win.SetValue(int(value)) # default or previously set value
  1071. p['wxId'] = [ win.GetId() ]
  1072. elif prompt == 'dbdriver':
  1073. win = gselect.DriverSelect(parent = which_panel,
  1074. choices = p.get('values', []),
  1075. value = value)
  1076. win.Bind(wx.EVT_COMBOBOX, self.OnUpdateSelection)
  1077. win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
  1078. elif prompt == 'dbname':
  1079. win = gselect.DatabaseSelect(parent = which_panel,
  1080. value = value)
  1081. win.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
  1082. win.Bind(wx.EVT_TEXT, self.OnSetValue)
  1083. elif prompt == 'dbtable':
  1084. if p.get('age', 'old') == 'old':
  1085. win = gselect.TableSelect(parent = which_panel)
  1086. win.Bind(wx.EVT_COMBOBOX, self.OnUpdateSelection)
  1087. win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
  1088. else:
  1089. win = wx.TextCtrl(parent = which_panel, value = p.get('default',''),
  1090. size = globalvar.DIALOG_TEXTCTRL_SIZE)
  1091. win.Bind(wx.EVT_TEXT, self.OnSetValue)
  1092. elif prompt == 'dbcolumn':
  1093. win = gselect.ColumnSelect(parent = which_panel,
  1094. value = value,
  1095. param = p)
  1096. win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
  1097. win.Bind(wx.EVT_TEXT, self.OnSetValue)
  1098. elif prompt == 'location':
  1099. win = gselect.LocationSelect(parent = which_panel,
  1100. value = value)
  1101. win.Bind(wx.EVT_COMBOBOX, self.OnUpdateSelection)
  1102. win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
  1103. elif prompt == 'mapset':
  1104. if p.get('age', 'old') == 'old':
  1105. new = False
  1106. else:
  1107. new = True
  1108. win = gselect.MapsetSelect(parent = which_panel,
  1109. value = value, new = new)
  1110. win.Bind(wx.EVT_COMBOBOX, self.OnUpdateSelection)
  1111. win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
  1112. win.Bind(wx.EVT_TEXT, self.OnSetValue)
  1113. elif prompt == 'dbase':
  1114. win = gselect.DbaseSelect(parent = which_panel,
  1115. changeCallback = self.OnSetValue)
  1116. win.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
  1117. p['wxId'] = [ win.GetChildren()[1].GetId() ]
  1118. if 'wxId' not in p:
  1119. try:
  1120. p['wxId'] = [ win.GetId(), ]
  1121. except AttributeError:
  1122. pass
  1123. flags = wx.BOTTOM | wx.LEFT | wx.RIGHT
  1124. if prompt == 'dbname':
  1125. flags |= wx.EXPAND
  1126. which_sizer.Add(item = win, proportion = 0,
  1127. flag = flags, border = 5)
  1128. # color entry
  1129. elif prompt in ('color',
  1130. 'color_none'):
  1131. default_color = (200,200,200)
  1132. label_color = _("Select Color")
  1133. if p.get('default','') != '':
  1134. default_color, label_color = utils.color_resolve(p['default'])
  1135. if p.get('value','') != '' and p.get('value','') != 'none': # parameter previously set
  1136. default_color, label_color = utils.color_resolve(p['value'])
  1137. if prompt == 'color_none':
  1138. this_sizer = wx.BoxSizer(orient = wx.HORIZONTAL)
  1139. else:
  1140. this_sizer = which_sizer
  1141. btn_colour = csel.ColourSelect(parent = which_panel, id = wx.ID_ANY,
  1142. label = label_color, colour = default_color,
  1143. pos = wx.DefaultPosition, size = (150,-1))
  1144. this_sizer.Add(item = btn_colour, proportion = 0,
  1145. flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT, border = 5)
  1146. # For color selectors, this is a two-member array, holding the IDs of
  1147. # the selector proper and either a "transparent" button or None
  1148. p['wxId'] = [btn_colour.GetId(),]
  1149. btn_colour.Bind(csel.EVT_COLOURSELECT, self.OnColorChange)
  1150. if prompt == 'color_none':
  1151. none_check = wx.CheckBox(which_panel, wx.ID_ANY, _("Transparent"))
  1152. if p.get('value','') == "none":
  1153. none_check.SetValue(True)
  1154. else:
  1155. none_check.SetValue(False)
  1156. this_sizer.Add(item = none_check, proportion = 0,
  1157. flag = wx.ADJUST_MINSIZE | wx.LEFT | wx.RIGHT | wx.TOP, border = 5)
  1158. which_sizer.Add(this_sizer)
  1159. none_check.Bind(wx.EVT_CHECKBOX, self.OnColorChange)
  1160. p['wxId'].append(none_check.GetId())
  1161. else:
  1162. p['wxId'].append(None)
  1163. # file selector
  1164. elif p.get('prompt','') != 'color' and p.get('element', '') == 'file':
  1165. if p.get('age', 'new') == 'new':
  1166. fmode = wx.SAVE
  1167. else:
  1168. fmode = wx.OPEN
  1169. fbb = filebrowse.FileBrowseButton(parent = which_panel, id = wx.ID_ANY, fileMask = '*',
  1170. size = globalvar.DIALOG_GSELECT_SIZE, labelText = '',
  1171. dialogTitle = _('Choose %s') % \
  1172. p.get('description',_('File')),
  1173. buttonText = _('Browse'),
  1174. startDirectory = os.getcwd(), fileMode = fmode,
  1175. changeCallback = self.OnSetValue)
  1176. value = self._getValue(p)
  1177. if value:
  1178. fbb.SetValue(value) # parameter previously set
  1179. which_sizer.Add(item = fbb, proportion = 0,
  1180. flag = wx.EXPAND | wx.RIGHT, border = 5)
  1181. # A file browse button is a combobox with two children:
  1182. # a textctl and a button;
  1183. # we have to target the button here
  1184. p['wxId'] = [ fbb.GetChildren()[1].GetId() ]
  1185. if p.get('age', 'new') == 'old' and \
  1186. p.get('prompt', 'input') == 'input' and \
  1187. UserSettings.Get(group = 'cmd', key = 'interactiveInput', subkey = 'enabled'):
  1188. # widget for interactive input
  1189. ifbb = wx.TextCtrl(parent = which_panel, id = wx.ID_ANY,
  1190. style = wx.TE_MULTILINE,
  1191. size = (-1, 75))
  1192. if p.get('value', '') and os.path.isfile(p['value']):
  1193. f = open(p['value'])
  1194. ifbb.SetValue(''.join(f.readlines()))
  1195. f.close()
  1196. ifbb.Bind(wx.EVT_TEXT, self.OnFileText)
  1197. btnLoad = wx.Button(parent = which_panel, id = wx.ID_ANY, label = _("&Load"))
  1198. btnLoad.Bind(wx.EVT_BUTTON, self.OnFileLoad)
  1199. btnSave = wx.Button(parent = which_panel, id = wx.ID_SAVEAS)
  1200. btnSave.Bind(wx.EVT_BUTTON, self.OnFileSave)
  1201. which_sizer.Add(item = wx.StaticText(parent = which_panel, id = wx.ID_ANY,
  1202. label = _('or enter values interactively')),
  1203. proportion = 0,
  1204. flag = wx.EXPAND | wx.RIGHT | wx.LEFT | wx.BOTTOM, border = 5)
  1205. which_sizer.Add(item = ifbb, proportion = 1,
  1206. flag = wx.EXPAND | wx.RIGHT | wx.LEFT, border = 5)
  1207. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  1208. btnSizer.Add(item = btnLoad, proportion = 0,
  1209. flag = wx.ALIGN_RIGHT | wx.RIGHT, border = 10)
  1210. btnSizer.Add(item = btnSave, proportion = 0,
  1211. flag = wx.ALIGN_RIGHT)
  1212. which_sizer.Add(item = btnSizer, proportion = 0,
  1213. flag = wx.ALIGN_RIGHT | wx.RIGHT | wx.TOP, border = 5)
  1214. p['wxId'].append(ifbb.GetId())
  1215. p['wxId'].append(btnLoad.GetId())
  1216. p['wxId'].append(btnSave.GetId())
  1217. # directory selector
  1218. elif p.get('prompt','') != 'color' and p.get('element', '') == 'dir':
  1219. fbb = filebrowse.DirBrowseButton(parent = which_panel, id = wx.ID_ANY,
  1220. size = globalvar.DIALOG_GSELECT_SIZE, labelText = '',
  1221. dialogTitle = _('Choose %s') % \
  1222. p.get('description', _('Directory')),
  1223. buttonText = _('Browse'),
  1224. startDirectory = os.getcwd(),
  1225. changeCallback = self.OnSetValue)
  1226. value = self._getValue(p)
  1227. if value:
  1228. fbb.SetValue(value) # parameter previously set
  1229. which_sizer.Add(item = fbb, proportion = 0,
  1230. flag = wx.EXPAND | wx.RIGHT, border = 5)
  1231. # A file browse button is a combobox with two children:
  1232. # a textctl and a button;
  1233. # we have to target the button here
  1234. p['wxId'] = [ fbb.GetChildren()[1].GetId() ]
  1235. # interactive inserting of coordinates from map window
  1236. elif prompt == 'coords':
  1237. # interactive inserting if layer manager is accessible
  1238. if lmgr:
  1239. win = gselect.CoordinatesSelect(parent = which_panel,
  1240. lmgr = lmgr,
  1241. multiple = p.get('multiple', False),
  1242. param = p)
  1243. p['wxId'] = [win.GetTextWin().GetId()]
  1244. win.GetTextWin().Bind(wx.EVT_TEXT, self.OnSetValue)
  1245. # normal text field
  1246. else:
  1247. win = wx.TextCtrl(parent = which_panel)
  1248. p['wxId'] = [win.GetId()]
  1249. win.Bind(wx.EVT_TEXT, self.OnSetValue)
  1250. which_sizer.Add(item = win,
  1251. proportion = 0,
  1252. flag = wx.EXPAND | wx.BOTTOM | wx.LEFT | wx.RIGHT,
  1253. border = 5)
  1254. if self.parent.GetName() == 'MainFrame' and self.parent.modeler:
  1255. parChk = wx.CheckBox(parent = which_panel, id = wx.ID_ANY,
  1256. label = _("Parameterized in model"))
  1257. parChk.SetName('ModelParam')
  1258. parChk.SetValue(p.get('parameterized', False))
  1259. if 'wxId' in p:
  1260. p['wxId'].append(parChk.GetId())
  1261. else:
  1262. p['wxId'] = [ parChk.GetId() ]
  1263. parChk.Bind(wx.EVT_CHECKBOX, self.OnSetValue)
  1264. which_sizer.Add(item = parChk, proportion = 0,
  1265. flag = wx.LEFT, border = 20)
  1266. if title_txt is not None:
  1267. # create tooltip if given
  1268. if len(p['values_desc']) > 0:
  1269. if tooltip:
  1270. tooltip += 2 * os.linesep
  1271. else:
  1272. tooltip = ''
  1273. if len(p['values']) == len(p['values_desc']):
  1274. for i in range(len(p['values'])):
  1275. tooltip += p['values'][i] + ': ' + p['values_desc'][i] + os.linesep
  1276. tooltip.strip(os.linesep)
  1277. if tooltip:
  1278. title_txt.SetToolTipString(tooltip)
  1279. if p == first_param:
  1280. if 'wxId' in p and len(p['wxId']) > 0:
  1281. win = self.FindWindowById(p['wxId'][0])
  1282. win.SetFocus()
  1283. #
  1284. # set widget relations for OnUpdateSelection
  1285. #
  1286. pMap = None
  1287. pLayer = []
  1288. pDriver = None
  1289. pDatabase = None
  1290. pTable = None
  1291. pColumn = []
  1292. pGroup = None
  1293. pSubGroup = None
  1294. pDbase = None
  1295. pLocation = None
  1296. pMapset = None
  1297. for p in self.task.params:
  1298. if p.get('gisprompt', False) == False:
  1299. continue
  1300. guidep = p.get('guidependency', '')
  1301. if guidep:
  1302. # fixed options dependency defined
  1303. options = guidep.split(',')
  1304. for opt in options:
  1305. pOpt = self.task.get_param(opt, element = 'name', raiseError = False)
  1306. if id:
  1307. if 'wxId-bind' not in p:
  1308. p['wxId-bind'] = list()
  1309. p['wxId-bind'] += pOpt['wxId']
  1310. continue
  1311. prompt = p.get('element', '')
  1312. if prompt in ('cell', 'vector'):
  1313. name = p.get('name', '')
  1314. if name in ('map', 'input'):
  1315. pMap = p
  1316. elif prompt == 'layer':
  1317. pLayer.append(p)
  1318. elif prompt == 'dbcolumn':
  1319. pColumn.append(p)
  1320. elif prompt == 'dbdriver':
  1321. pDriver = p
  1322. elif prompt == 'dbname':
  1323. pDatabase = p
  1324. elif prompt == 'dbtable':
  1325. pTable = p
  1326. elif prompt == 'group':
  1327. pGroup = p
  1328. elif prompt == 'subgroup':
  1329. pSubGroup = p
  1330. elif prompt == 'dbase':
  1331. pDbase = p
  1332. elif prompt == 'location':
  1333. pLocation = p
  1334. elif prompt == 'mapset':
  1335. pMapset = p
  1336. # collect ids
  1337. pColumnIds = []
  1338. for p in pColumn:
  1339. pColumnIds += p['wxId']
  1340. pLayerIds = []
  1341. for p in pLayer:
  1342. pLayerIds += p['wxId']
  1343. # set wxId-bindings
  1344. if pMap:
  1345. pMap['wxId-bind'] = copy.copy(pColumnIds)
  1346. if pLayer:
  1347. pMap['wxId-bind'] += pLayerIds
  1348. if pLayer:
  1349. for p in pLayer:
  1350. p['wxId-bind'] = copy.copy(pColumnIds)
  1351. if pDriver and pTable:
  1352. pDriver['wxId-bind'] = pTable['wxId']
  1353. if pDatabase and pTable:
  1354. pDatabase['wxId-bind'] = pTable['wxId']
  1355. if pTable and pColumnIds:
  1356. pTable['wxId-bind'] = pColumnIds
  1357. if pGroup and pSubGroup:
  1358. pGroup['wxId-bind'] = pSubGroup['wxId']
  1359. if pDbase and pLocation:
  1360. pDbase['wxId-bind'] = pLocation['wxId']
  1361. if pLocation and pMapset:
  1362. pLocation['wxId-bind'] = pMapset['wxId']
  1363. if pLocation and pMapset and pMap:
  1364. pLocation['wxId-bind'] += pMap['wxId']
  1365. pMapset['wxId-bind'] = pMap['wxId']
  1366. #
  1367. # determine panel size
  1368. #
  1369. maxsizes = (0, 0)
  1370. for section in sections:
  1371. tab[section].SetSizer(tabsizer[section])
  1372. tabsizer[section].Fit(tab[section])
  1373. tab[section].Layout()
  1374. minsecsizes = tabsizer[section].GetSize()
  1375. maxsizes = map(lambda x: max(maxsizes[x], minsecsizes[x]), (0, 1))
  1376. # TODO: be less arbitrary with these 600
  1377. self.panelMinHeight = 100
  1378. self.constrained_size = (min(600, maxsizes[0]) + 25, min(400, maxsizes[1]) + 25)
  1379. for section in sections:
  1380. tab[section].SetMinSize((self.constrained_size[0], self.panelMinHeight))
  1381. if self.manual_tab.IsLoaded():
  1382. self.manual_tab.SetMinSize((self.constrained_size[0], self.panelMinHeight))
  1383. self.SetSizer(panelsizer)
  1384. panelsizer.Fit(self.notebook)
  1385. self.Bind(EVT_DIALOG_UPDATE, self.OnUpdateDialog)
  1386. def _getValue(self, p):
  1387. """!Get value or default value of given parameter
  1388. @param p parameter directory
  1389. """
  1390. if p.get('value', '') != '':
  1391. return p['value']
  1392. return p.get('default', '')
  1393. def OnFileLoad(self, event):
  1394. """!Load file to interactive input"""
  1395. me = event.GetId()
  1396. win = dict()
  1397. for p in self.task.params:
  1398. if 'wxId' in p and me in p['wxId']:
  1399. win['file'] = self.FindWindowById(p['wxId'][0])
  1400. win['text'] = self.FindWindowById(p['wxId'][1])
  1401. break
  1402. if not win:
  1403. return
  1404. path = win['file'].GetValue()
  1405. if not path:
  1406. gcmd.GMessage(parent = self,
  1407. message = _("Nothing to load."))
  1408. return
  1409. data = ''
  1410. f = open(path, "r")
  1411. try:
  1412. data = f.read()
  1413. finally:
  1414. f.close()
  1415. win['text'].SetValue(data)
  1416. def OnFileSave(self, event):
  1417. """!Save interactive input to the file"""
  1418. wId = event.GetId()
  1419. win = {}
  1420. for p in self.task.params:
  1421. if wId in p.get('wxId', []):
  1422. win['file'] = self.FindWindowById(p['wxId'][0])
  1423. win['text'] = self.FindWindowById(p['wxId'][1])
  1424. break
  1425. if not win:
  1426. return
  1427. text = win['text'].GetValue()
  1428. if not text:
  1429. gcmd.GMessage(parent = self,
  1430. message = _("Nothing to save."))
  1431. return
  1432. dlg = wx.FileDialog(parent = self,
  1433. message = _("Save input as..."),
  1434. defaultDir = os.getcwd(),
  1435. style = wx.SAVE | wx.FD_OVERWRITE_PROMPT)
  1436. if dlg.ShowModal() == wx.ID_OK:
  1437. path = dlg.GetPath()
  1438. f = open(path, "w")
  1439. try:
  1440. f.write(text + os.linesep)
  1441. finally:
  1442. f.close()
  1443. win['file'].SetValue(path)
  1444. dlg.Destroy()
  1445. def OnFileText(self, event):
  1446. """File input interactively entered"""
  1447. text = event.GetString()
  1448. p = self.task.get_param(value = event.GetId(), element = 'wxId', raiseError = False)
  1449. if not p:
  1450. return # should not happen
  1451. win = self.FindWindowById(p['wxId'][0])
  1452. if text:
  1453. filename = win.GetValue()
  1454. if not filename:
  1455. # outFile = tempfile.NamedTemporaryFile(mode = 'w+b')
  1456. filename = grass.tempfile()
  1457. win.SetValue(filename)
  1458. f = open(filename, "w")
  1459. try:
  1460. f.write(text)
  1461. if text[-1] != os.linesep:
  1462. f.write(os.linesep)
  1463. finally:
  1464. f.close()
  1465. else:
  1466. win.SetValue('')
  1467. def OnVectorFormat(self, event):
  1468. """!Change vector format (native / ogr)"""
  1469. sel = event.GetSelection()
  1470. idEvent = event.GetId()
  1471. p = self.task.get_param(value = idEvent, element = 'wxId', raiseError = False)
  1472. if not p:
  1473. return # should not happen
  1474. # detect windows
  1475. winNative = None
  1476. winOgr = None
  1477. for id in p['wxId']:
  1478. if id == idEvent:
  1479. continue
  1480. name = self.FindWindowById(id).GetName()
  1481. if name == 'Select':
  1482. winNative = self.FindWindowById(id + 1) # fix the mystery (also in nviz_tools.py)
  1483. elif name == 'OgrSelect':
  1484. winOgr = self.FindWindowById(id)
  1485. # enable / disable widgets & update values
  1486. rbox = self.FindWindowByName('VectorFormat')
  1487. self.hsizer.Remove(rbox)
  1488. if sel == 0: # -> native
  1489. winOgr.Hide()
  1490. self.hsizer.Remove(winOgr)
  1491. self.hsizer.Add(item = winNative,
  1492. flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT | wx.RIGHT | wx.TOP | wx.ALIGN_TOP,
  1493. border = 5)
  1494. winNative.Show()
  1495. p['value'] = winNative.GetValue()
  1496. elif sel == 1: # -> OGR
  1497. sizer = wx.BoxSizer(wx.VERTICAL)
  1498. winNative.Hide()
  1499. self.hsizer.Remove(winNative)
  1500. sizer.Add(item = winOgr)
  1501. winOgr.Show()
  1502. p['value'] = winOgr.GetDsn()
  1503. self.hsizer.Add(item = sizer,
  1504. flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT | wx.RIGHT | wx.TOP | wx.ALIGN_TOP,
  1505. border = 5)
  1506. self.hsizer.Add(item = rbox,
  1507. flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT |
  1508. wx.RIGHT | wx.ALIGN_TOP,
  1509. border = 5)
  1510. self.hsizer.Layout()
  1511. self.Layout()
  1512. self.OnUpdateValues()
  1513. self.OnUpdateSelection(event)
  1514. def OnUpdateDialog(self, event):
  1515. for fn, kwargs in event.data.iteritems():
  1516. fn(**kwargs)
  1517. self.parent.updateValuesHook()
  1518. def OnVerbosity(self, event):
  1519. """!Verbosity level changed"""
  1520. verbose = self.FindWindowById(self.task.get_flag('verbose')['wxId'][0])
  1521. quiet = self.FindWindowById(self.task.get_flag('quiet')['wxId'][0])
  1522. if event.IsChecked():
  1523. if event.GetId() == verbose.GetId():
  1524. if quiet.IsChecked():
  1525. quiet.SetValue(False)
  1526. self.task.get_flag('quiet')['value'] = False
  1527. else:
  1528. if verbose.IsChecked():
  1529. verbose.SetValue(False)
  1530. self.task.get_flag('verbose')['value'] = False
  1531. event.Skip()
  1532. def OnPageChange(self, event):
  1533. if not event:
  1534. sel = self.notebook.GetSelection()
  1535. else:
  1536. sel = event.GetSelection()
  1537. idx = self.notebook.GetPageIndexByName('manual')
  1538. if idx > -1 and sel == idx:
  1539. # calling LoadPage() is strangely time-consuming (only first call)
  1540. # FIXME: move to helpPage.__init__()
  1541. if not self.manual_tab.IsLoaded():
  1542. wx.Yield()
  1543. self.manual_tab.LoadPage()
  1544. self.Layout()
  1545. def OnColorChange(self, event):
  1546. myId = event.GetId()
  1547. for p in self.task.params:
  1548. if 'wxId' in p and myId in p['wxId']:
  1549. has_button = p['wxId'][1] is not None
  1550. if has_button and wx.FindWindowById(p['wxId'][1]).GetValue() == True:
  1551. p[ 'value' ] = 'none'
  1552. else:
  1553. colorchooser = wx.FindWindowById(p['wxId'][0])
  1554. new_color = colorchooser.GetValue()[:]
  1555. # This is weird: new_color is a 4-tuple and new_color[:] is a 3-tuple
  1556. # under wx2.8.1
  1557. new_label = utils.rgb2str.get(new_color, ':'.join(map(str,new_color)))
  1558. colorchooser.SetLabel(new_label)
  1559. colorchooser.SetColour(new_color)
  1560. colorchooser.Refresh()
  1561. p[ 'value' ] = colorchooser.GetLabel()
  1562. self.OnUpdateValues()
  1563. def OnUpdateValues(self, event = None):
  1564. """!If we were part of a richer interface, report back the
  1565. current command being built.
  1566. This method should be set by the parent of this panel if
  1567. needed. It's a hook, actually. Beware of what is 'self' in
  1568. the method def, though. It will be called with no arguments.
  1569. """
  1570. pass
  1571. def OnCheckBoxMulti(self, event):
  1572. """!Fill the values as a ','-separated string according to
  1573. current status of the checkboxes.
  1574. """
  1575. me = event.GetId()
  1576. theParam = None
  1577. for p in self.task.params:
  1578. if 'wxId' in p and me in p['wxId']:
  1579. theParam = p
  1580. myIndex = p['wxId'].index(me)
  1581. # Unpack current value list
  1582. currentValues = {}
  1583. for isThere in theParam.get('value', '').split(','):
  1584. currentValues[isThere] = 1
  1585. theValue = theParam['values'][myIndex]
  1586. if event.Checked():
  1587. currentValues[ theValue ] = 1
  1588. else:
  1589. del currentValues[ theValue ]
  1590. # Keep the original order, so that some defaults may be recovered
  1591. currentValueList = []
  1592. for v in theParam['values']:
  1593. if v in currentValues:
  1594. currentValueList.append(v)
  1595. # Pack it back
  1596. theParam['value'] = ','.join(currentValueList)
  1597. self.OnUpdateValues()
  1598. def OnSetValue(self, event):
  1599. """!Retrieve the widget value and set the task value field
  1600. accordingly.
  1601. Use for widgets that have a proper GetValue() method, i.e. not
  1602. for selectors.
  1603. """
  1604. myId = event.GetId()
  1605. me = wx.FindWindowById(myId)
  1606. name = me.GetName()
  1607. found = False
  1608. for porf in self.task.params + self.task.flags:
  1609. if 'wxId' not in porf:
  1610. continue
  1611. if myId in porf['wxId']:
  1612. found = True
  1613. break
  1614. if not found:
  1615. return
  1616. if name == 'GdalSelect':
  1617. porf['value'] = event.dsn
  1618. elif name == 'ModelParam':
  1619. porf['parameterized'] = me.IsChecked()
  1620. else:
  1621. porf['value'] = me.GetValue()
  1622. self.OnUpdateValues(event)
  1623. event.Skip()
  1624. def OnSetSymbol(self, event):
  1625. """!Shows dialog for symbol selection"""
  1626. myId = event.GetId()
  1627. for p in self.task.params:
  1628. if 'wxId' in p and myId in p['wxId']:
  1629. from gui_core.dialogs import SymbolDialog
  1630. dlg = SymbolDialog(self, symbolPath = globalvar.ETCSYMBOLDIR,
  1631. currentSymbol = p['value'])
  1632. if dlg.ShowModal() == wx.ID_OK:
  1633. img = dlg.GetSelectedSymbolPath()
  1634. p['value'] = dlg.GetSelectedSymbolName()
  1635. bitmapButton = wx.FindWindowById(p['wxId'][0])
  1636. label = wx.FindWindowById(p['wxId'][1])
  1637. bitmapButton.SetBitmapLabel(wx.Bitmap(img + '.png'))
  1638. label.SetLabel(p['value'])
  1639. self.OnUpdateValues(event)
  1640. dlg.Destroy()
  1641. def OnUpdateSelection(self, event):
  1642. """!Update dialog (layers, tables, columns, etc.)
  1643. """
  1644. if not hasattr(self.parent, "updateThread"):
  1645. if event:
  1646. event.Skip()
  1647. return
  1648. if event:
  1649. self.parent.updateThread.Update(UpdateDialog,
  1650. self,
  1651. event,
  1652. event.GetId(),
  1653. self.task)
  1654. else:
  1655. self.parent.updateThread.Update(UpdateDialog,
  1656. self,
  1657. None,
  1658. None,
  1659. self.task)
  1660. def createCmd(self, ignoreErrors = False, ignoreRequired = False):
  1661. """!Produce a command line string (list) or feeding into GRASS.
  1662. @param ignoreErrors True then it will return whatever has been
  1663. built so far, even though it would not be a correct command
  1664. for GRASS
  1665. """
  1666. try:
  1667. cmd = self.task.get_cmd(ignoreErrors = ignoreErrors,
  1668. ignoreRequired = ignoreRequired)
  1669. except ValueError, err:
  1670. dlg = wx.MessageDialog(parent = self,
  1671. message = unicode(err),
  1672. caption = _("Error in %s") % self.task.name,
  1673. style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1674. dlg.ShowModal()
  1675. dlg.Destroy()
  1676. cmd = None
  1677. return cmd
  1678. def OnSize(self, event):
  1679. width = event.GetSize()[0]
  1680. fontsize = self.GetFont().GetPointSize()
  1681. text_width = max(width / (fontsize - 3), 70)
  1682. for id in self.label_id:
  1683. win = self.FindWindowById(id)
  1684. label = win.GetLabel()
  1685. label_new = '\n'.join(textwrap.wrap(label, text_width))
  1686. win.SetLabel(label_new)
  1687. event.Skip()
  1688. def AddBitmapToImageList(self, section, imageList):
  1689. iconTheme = UserSettings.Get(group = 'appearance', key = 'iconTheme', subkey = 'type')
  1690. iconSectionDict = {'manual': os.path.join(globalvar.ETCICONDIR, iconTheme, 'help.png'),
  1691. _("Optional"): os.path.join(globalvar.ETCICONDIR, iconTheme, 'settings.png')}
  1692. if section in iconSectionDict.keys():
  1693. bitmap = wx.Bitmap(iconSectionDict[section])
  1694. bitmap.SetSize((16, 16))
  1695. idx = imageList.Add(bitmap)
  1696. return idx
  1697. return -1
  1698. class GUI:
  1699. def __init__(self, parent = None, show = True, modal = False,
  1700. centreOnParent = False, checkError = False, lmgr = None):
  1701. """!Parses GRASS commands when module is imported and used from
  1702. Layer Manager.
  1703. """
  1704. self.parent = parent
  1705. self.show = show
  1706. self.modal = modal
  1707. self.lmgr = lmgr
  1708. self.centreOnParent = centreOnParent
  1709. self.checkError = checkError
  1710. self.grass_task = None
  1711. self.cmd = list()
  1712. global _blackList
  1713. if self.parent:
  1714. _blackList['enabled'] = True
  1715. else:
  1716. _blackList['enabled'] = False
  1717. def GetCmd(self):
  1718. """!Get validated command"""
  1719. return self.cmd
  1720. def ParseCommand(self, cmd, gmpath = None, completed = None):
  1721. """!Parse command
  1722. Note: cmd is given as list
  1723. If command is given with options, return validated cmd list:
  1724. - add key name for first parameter if not given
  1725. - change mapname to mapname@mapset
  1726. """
  1727. start = time.time()
  1728. dcmd_params = {}
  1729. if completed == None:
  1730. get_dcmd = None
  1731. layer = None
  1732. dcmd_params = None
  1733. else:
  1734. get_dcmd = completed[0]
  1735. layer = completed[1]
  1736. if completed[2]:
  1737. dcmd_params.update(completed[2])
  1738. # parse the interface decription
  1739. try:
  1740. global _blackList
  1741. self.grass_task = gtask.parse_interface(gcmd.GetRealCmd(cmd[0]),
  1742. blackList = _blackList)
  1743. except (grass.ScriptError, ValueError), e:
  1744. raise gcmd.GException(e.value)
  1745. # if layer parameters previously set, re-insert them into dialog
  1746. if completed is not None:
  1747. if 'params' in dcmd_params:
  1748. self.grass_task.params = dcmd_params['params']
  1749. if 'flags' in dcmd_params:
  1750. self.grass_task.flags = dcmd_params['flags']
  1751. err = list()
  1752. # update parameters if needed && validate command
  1753. if len(cmd) > 1:
  1754. i = 0
  1755. cmd_validated = [cmd[0]]
  1756. for option in cmd[1:]:
  1757. if option[0] == '-': # flag
  1758. if option[1] == '-':
  1759. self.grass_task.set_flag(option[2:], True)
  1760. else:
  1761. self.grass_task.set_flag(option[1], True)
  1762. cmd_validated.append(option)
  1763. else: # parameter
  1764. try:
  1765. key, value = option.split('=', 1)
  1766. except:
  1767. if self.grass_task.firstParam:
  1768. if i == 0: # add key name of first parameter if not given
  1769. key = self.grass_task.firstParam
  1770. value = option
  1771. else:
  1772. raise GException, _("Unable to parse command '%s'") % ' '.join(cmd)
  1773. else:
  1774. continue
  1775. element = self.grass_task.get_param(key, raiseError = False)
  1776. if not element:
  1777. err.append(_("%(cmd)s: parameter '%(key)s' not available") % \
  1778. { 'cmd' : cmd[0],
  1779. 'key' : key })
  1780. continue
  1781. element = element['element']
  1782. if element in ['cell', 'vector']:
  1783. # mapname -> mapname@mapset
  1784. try:
  1785. name, mapset = value.split('@')
  1786. except ValueError:
  1787. mapset = grass.find_file(value, element)['mapset']
  1788. curr_mapset = grass.gisenv()['MAPSET']
  1789. if mapset and mapset != curr_mapset:
  1790. value = value + '@' + mapset
  1791. self.grass_task.set_param(key, value)
  1792. cmd_validated.append(key + '=' + value)
  1793. i += 1
  1794. # update original command list
  1795. cmd = cmd_validated
  1796. if self.show is not None:
  1797. self.mf = TaskFrame(parent = self.parent,
  1798. task_description = self.grass_task,
  1799. get_dcmd = get_dcmd, layer = layer,
  1800. lmgr = self.lmgr)
  1801. else:
  1802. self.mf = None
  1803. if get_dcmd is not None:
  1804. # update only propwin reference
  1805. get_dcmd(dcmd = None, layer = layer, params = None,
  1806. propwin = self.mf)
  1807. if self.show is not None:
  1808. self.mf.notebookpanel.OnUpdateSelection(None)
  1809. if self.show is True:
  1810. if self.parent and self.centreOnParent:
  1811. self.mf.CentreOnParent()
  1812. else:
  1813. self.mf.CenterOnScreen()
  1814. self.mf.Show(self.show)
  1815. self.mf.MakeModal(self.modal)
  1816. else:
  1817. self.mf.OnApply(None)
  1818. self.cmd = cmd
  1819. if self.checkError:
  1820. return self.grass_task, err
  1821. else:
  1822. return self.grass_task
  1823. def GetCommandInputMapParamKey(self, cmd):
  1824. """!Get parameter key for input raster/vector map
  1825. @param cmd module name
  1826. @return parameter key
  1827. @return None on failure
  1828. """
  1829. # parse the interface decription
  1830. if not self.grass_task:
  1831. enc = locale.getdefaultlocale()[1]
  1832. if enc and enc.lower() == "cp932":
  1833. p = re.compile('encoding="' + enc + '"', re.IGNORECASE)
  1834. tree = etree.fromstring(p.sub('encoding="utf-8"',
  1835. gtask.get_interface_description(cmd).decode(enc).encode('utf-8')))
  1836. else:
  1837. tree = etree.fromstring(gtask.get_interface_description(cmd))
  1838. self.grass_task = gtask.processTask(tree).get_task()
  1839. for p in self.grass_task.params:
  1840. if p.get('name', '') in ('input', 'map'):
  1841. age = p.get('age', '')
  1842. prompt = p.get('prompt', '')
  1843. element = p.get('element', '')
  1844. if age == 'old' and \
  1845. element in ('cell', 'grid3', 'vector') and \
  1846. prompt in ('raster', '3d-raster', 'vector'):
  1847. return p.get('name', None)
  1848. return None
  1849. class GrassGUIApp(wx.App):
  1850. """!Stand-alone GRASS command GUI
  1851. """
  1852. def __init__(self, grass_task):
  1853. self.grass_task = grass_task
  1854. wx.App.__init__(self, False)
  1855. def OnInit(self):
  1856. msg = self.grass_task.get_error_msg()
  1857. if msg:
  1858. gcmd.GError(msg + '\n\n' +
  1859. _('Try to set up GRASS_ADDON_PATH or GRASS_ADDON_BASE variable.'))
  1860. return True
  1861. self.mf = TaskFrame(parent = None, task_description = self.grass_task)
  1862. self.mf.CentreOnScreen()
  1863. self.mf.Show(True)
  1864. self.SetTopWindow(self.mf)
  1865. return True
  1866. if __name__ == "__main__":
  1867. import gettext
  1868. gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
  1869. if len(sys.argv) == 1:
  1870. sys.exit(_("usage: %s <grass command>") % sys.argv[0])
  1871. if sys.argv[1] != 'test':
  1872. q = wx.LogNull()
  1873. cmd = utils.split(sys.argv[1])
  1874. task = gtask.grassTask(gcmd.GetRealCmd(cmd[0]))
  1875. task.set_options(cmd[1:])
  1876. app = GrassGUIApp(task)
  1877. app.MainLoop()
  1878. else: #Test
  1879. # Test grassTask from within a GRASS session
  1880. if os.getenv("GISBASE") is not None:
  1881. task = gtask.grassTask("d.vect")
  1882. task.get_param('map')['value'] = "map_name"
  1883. task.get_flag('v')['value'] = True
  1884. task.get_param('layer')['value'] = 1
  1885. task.get_param('bcolor')['value'] = "red"
  1886. assert ' '.join(task.get_cmd()) == "d.vect -v map = map_name layer = 1 bcolor = red"
  1887. # Test interface building with handmade grassTask,
  1888. # possibly outside of a GRASS session.
  1889. task = gtask.grassTask()
  1890. task.name = "TestTask"
  1891. task.description = "This is an artificial grassTask() object intended for testing purposes."
  1892. task.keywords = ["grass","test","task"]
  1893. task.params = [
  1894. {
  1895. "name" : "text",
  1896. "description" : "Descriptions go into tooltips if labels are present, like this one",
  1897. "label" : "Enter some text",
  1898. },{
  1899. "name" : "hidden_text",
  1900. "description" : "This text should not appear in the form",
  1901. "hidden" : True
  1902. },{
  1903. "name" : "text_default",
  1904. "description" : "Enter text to override the default",
  1905. "default" : "default text"
  1906. },{
  1907. "name" : "text_prefilled",
  1908. "description" : "You should see a friendly welcome message here",
  1909. "value" : "hello, world"
  1910. },{
  1911. "name" : "plain_color",
  1912. "description" : "This is a plain color, and it is a compulsory parameter",
  1913. "required" : False,
  1914. "gisprompt" : True,
  1915. "prompt" : "color"
  1916. },{
  1917. "name" : "transparent_color",
  1918. "description" : "This color becomes transparent when set to none",
  1919. "guisection" : "tab",
  1920. "gisprompt" : True,
  1921. "prompt" : "color"
  1922. },{
  1923. "name" : "multi",
  1924. "description" : "A multiple selection",
  1925. 'default': u'red,green,blue',
  1926. 'gisprompt': False,
  1927. 'guisection': 'tab',
  1928. 'multiple': u'yes',
  1929. 'type': u'string',
  1930. 'value': '',
  1931. 'values': ['red', 'green', u'yellow', u'blue', u'purple', u'other']
  1932. },{
  1933. "name" : "single",
  1934. "description" : "A single multiple-choice selection",
  1935. 'values': ['red', 'green', u'yellow', u'blue', u'purple', u'other'],
  1936. "guisection" : "tab"
  1937. },{
  1938. "name" : "large_multi",
  1939. "description" : "A large multiple selection",
  1940. "gisprompt" : False,
  1941. "multiple" : "yes",
  1942. # values must be an array of strings
  1943. "values" : utils.str2rgb.keys() + map(str, utils.str2rgb.values())
  1944. },{
  1945. "name" : "a_file",
  1946. "description" : "A file selector",
  1947. "gisprompt" : True,
  1948. "element" : "file"
  1949. }
  1950. ]
  1951. task.flags = [
  1952. {
  1953. "name" : "a",
  1954. "description" : "Some flag, will appear in Main since it is required",
  1955. "required" : True
  1956. },{
  1957. "name" : "b",
  1958. "description" : "pre-filled flag, will appear in options since it is not required",
  1959. "value" : True
  1960. },{
  1961. "name" : "hidden_flag",
  1962. "description" : "hidden flag, should not be changeable",
  1963. "hidden" : "yes",
  1964. "value" : True
  1965. }
  1966. ]
  1967. q = wx.LogNull()
  1968. GrassGUIApp(task).MainLoop()