gdialogs.py 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791
  1. """!
  2. @package gdialogs.py
  3. @brief Various dialogs used in wxGUI.
  4. List of classes:
  5. - ElementDialog
  6. - LocationDialog
  7. - MapsetDialog
  8. - NewVectorDialog
  9. - SavedRegion
  10. - DecorationDialog
  11. - TextLayerDialog
  12. - AddMapLayersDialog
  13. - ImportDialog
  14. - GdalImportDialog
  15. - DxfImportDialog
  16. - LayersList (used by MultiImport)
  17. - SetOpacityDialog
  18. - StaticWrapText
  19. - ImageSizeDialog
  20. - SqlQueryFrame
  21. (C) 2008-2011 by the GRASS Development Team
  22. This program is free software under the GNU General Public
  23. License (>=v2). Read the file COPYING that comes with GRASS
  24. for details.
  25. @author Martin Landa <landa.martin gmail.com>
  26. """
  27. import os
  28. import sys
  29. import re
  30. import wx
  31. import wx.lib.filebrowsebutton as filebrowse
  32. import wx.lib.mixins.listctrl as listmix
  33. from grass.script import core as grass
  34. from grass.script import task as gtask
  35. import gcmd
  36. import globalvar
  37. import gselect
  38. import menuform
  39. import utils
  40. from preferences import globalSettings as UserSettings
  41. class ElementDialog(wx.Dialog):
  42. def __init__(self, parent, title, label, id = wx.ID_ANY,
  43. etype = False, style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
  44. **kwargs):
  45. """!General dialog to choose given element (location, mapset, vector map, etc.)
  46. @param parent window
  47. @param title window title
  48. @param label element label
  49. @param etype show also ElementSelect
  50. """
  51. wx.Dialog.__init__(self, parent, id, title, style = style, **kwargs)
  52. self.etype = etype
  53. self.label = label
  54. self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
  55. self.btnCancel = wx.Button(parent = self.panel, id = wx.ID_CANCEL)
  56. self.btnOK = wx.Button(parent = self.panel, id = wx.ID_OK)
  57. self.btnOK.SetDefault()
  58. self.btnOK.Enable(False)
  59. if self.etype:
  60. self.typeSelect = gselect.ElementSelect(parent = self.panel,
  61. size = globalvar.DIALOG_GSELECT_SIZE)
  62. self.typeSelect.Bind(wx.EVT_CHOICE, self.OnType)
  63. self.element = None # must be defined
  64. self.__layout()
  65. def PostInit(self):
  66. self.element.SetFocus()
  67. self.element.Bind(wx.EVT_TEXT, self.OnElement)
  68. def OnType(self, event):
  69. """!Select element type"""
  70. if not self.etype:
  71. return
  72. evalue = self.typeSelect.GetValue(event.GetString())
  73. self.element.SetType(evalue)
  74. def OnElement(self, event):
  75. """!Name for vector map layer given"""
  76. if len(event.GetString()) > 0:
  77. self.btnOK.Enable(True)
  78. else:
  79. self.btnOK.Enable(False)
  80. def __layout(self):
  81. """!Do layout"""
  82. self.sizer = wx.BoxSizer(wx.VERTICAL)
  83. self.dataSizer = wx.BoxSizer(wx.VERTICAL)
  84. if self.etype:
  85. self.dataSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  86. label = _("Type of element:")),
  87. proportion=0, flag=wx.ALL, border=1)
  88. self.dataSizer.Add(item = self.typeSelect,
  89. proportion=0, flag=wx.ALL, border=1)
  90. self.dataSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  91. label = self.label),
  92. proportion=0, flag=wx.ALL, border=1)
  93. # buttons
  94. btnSizer = wx.StdDialogButtonSizer()
  95. btnSizer.AddButton(self.btnCancel)
  96. btnSizer.AddButton(self.btnOK)
  97. btnSizer.Realize()
  98. self.sizer.Add(item=self.dataSizer, proportion=1,
  99. flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
  100. self.sizer.Add(item=btnSizer, proportion=0,
  101. flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
  102. def GetElement(self):
  103. """!Return (mapName, overwrite)"""
  104. return self.element.GetValue()
  105. def GetType(self):
  106. """!Get element type"""
  107. return self.element.tcp.GetType()
  108. class LocationDialog(ElementDialog):
  109. """!Dialog used to select location"""
  110. def __init__(self, parent, title = _("Select GRASS location and mapset"), id = wx.ID_ANY):
  111. ElementDialog.__init__(self, parent, title, label = _("Name of GRASS location:"))
  112. self.element = gselect.LocationSelect(parent = self.panel, id = wx.ID_ANY,
  113. size = globalvar.DIALOG_GSELECT_SIZE)
  114. self.element1 = gselect.MapsetSelect(parent = self.panel, id = wx.ID_ANY,
  115. size = globalvar.DIALOG_GSELECT_SIZE,
  116. setItems = False)
  117. self.PostInit()
  118. self.__Layout()
  119. self.SetMinSize(self.GetSize())
  120. def __Layout(self):
  121. """!Do layout"""
  122. self.dataSizer.Add(self.element, proportion=0,
  123. flag=wx.EXPAND | wx.ALL, border=1)
  124. self.dataSizer.Add(wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  125. label = _("Name of mapset:")), proportion=0,
  126. flag=wx.EXPAND | wx.ALL, border=1)
  127. self.dataSizer.Add(self.element1, proportion=0,
  128. flag=wx.EXPAND | wx.ALL, border=1)
  129. self.panel.SetSizer(self.sizer)
  130. self.sizer.Fit(self)
  131. def OnElement(self, event):
  132. """!Select mapset given location name"""
  133. location = event.GetString()
  134. if location:
  135. dbase = grass.gisenv()['GISDBASE']
  136. self.element1.SetItems(utils.GetListOfMapsets(dbase, location, selectable = True))
  137. self.element1.SetSelection(0)
  138. mapset = self.element1.GetStringSelection()
  139. if location and mapset:
  140. self.btnOK.Enable(True)
  141. else:
  142. self.btnOK.Enable(False)
  143. def GetValues(self):
  144. """!Get location, mapset"""
  145. return (self.GetElement(), self.element1.GetStringSelection())
  146. class MapsetDialog(ElementDialog):
  147. """!Dialog used to select mapset"""
  148. def __init__(self, parent, title = _("Select mapset in GRASS location"),
  149. location = None, id = wx.ID_ANY):
  150. ElementDialog.__init__(self, parent, title, label = _("Name of mapset:"))
  151. if location:
  152. self.SetTitle(self.GetTitle() + ' <%s>' % location)
  153. else:
  154. self.SetTitle(self.GetTitle() + ' <%s>' % grass.gisenv()['LOCATION_NAME'])
  155. self.element = gselect.MapsetSelect(parent = self.panel, id = wx.ID_ANY,
  156. size = globalvar.DIALOG_GSELECT_SIZE)
  157. self.PostInit()
  158. self.__Layout()
  159. self.SetMinSize(self.GetSize())
  160. def __Layout(self):
  161. """!Do layout"""
  162. self.dataSizer.Add(self.element, proportion=0,
  163. flag=wx.EXPAND | wx.ALL, border=1)
  164. self.panel.SetSizer(self.sizer)
  165. self.sizer.Fit(self)
  166. def GetMapset(self):
  167. return self.GetElement()
  168. class NewVectorDialog(ElementDialog):
  169. """!Dialog for creating new vector map"""
  170. def __init__(self, parent, id, title, disableAdd=False, disableTable=False,
  171. style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
  172. ElementDialog.__init__(self, parent, title, label = _("Name for new vector map:"))
  173. self.element = gselect.Select(parent=self.panel, id=wx.ID_ANY, size=globalvar.DIALOG_GSELECT_SIZE,
  174. type='vector', mapsets=[grass.gisenv()['MAPSET'],])
  175. self.table = wx.CheckBox(parent = self.panel, id = wx.ID_ANY,
  176. label = _("Create attribute table"))
  177. self.table.SetValue(True)
  178. if disableTable:
  179. self.table.Enable(False)
  180. self.addbox = wx.CheckBox(parent = self.panel,
  181. label = _('Add created map into layer tree'), style = wx.NO_BORDER)
  182. if disableAdd:
  183. self.addbox.SetValue(True)
  184. self.addbox.Enable(False)
  185. else:
  186. self.addbox.SetValue(UserSettings.Get(group = 'cmd', key = 'addNewLayer', subkey = 'enabled'))
  187. self.PostInit()
  188. self.__Layout()
  189. self.SetMinSize(self.GetSize())
  190. def OnMapName(self, event):
  191. """!Name for vector map layer given"""
  192. self.OnElement(event)
  193. def __Layout(self):
  194. """!Do layout"""
  195. self.dataSizer.Add(self.element, proportion=0,
  196. flag=wx.EXPAND | wx.ALL, border=1)
  197. self.dataSizer.Add(self.table, proportion=0,
  198. flag=wx.EXPAND | wx.ALL, border=1)
  199. self.dataSizer.AddSpacer(5)
  200. self.dataSizer.Add(item=self.addbox, proportion=0,
  201. flag=wx.EXPAND | wx.ALL, border=1)
  202. self.panel.SetSizer(self.sizer)
  203. self.sizer.Fit(self)
  204. def GetName(self):
  205. """!Return (mapName, overwrite)"""
  206. return self.GetElement().split('@', 1)[0]
  207. def CreateNewVector(parent, cmd, title=_('Create new vector map'),
  208. exceptMap=None, log=None, disableAdd=False, disableTable=False):
  209. """!Create new vector map layer
  210. @cmd cmd (prog, **kwargs)
  211. @return tuple (name of create vector map, add to layer tree)
  212. @return None of failure
  213. """
  214. dlg = NewVectorDialog(parent, wx.ID_ANY, title,
  215. disableAdd, disableTable)
  216. if dlg.ShowModal() == wx.ID_OK:
  217. outmap = dlg.GetName()
  218. if outmap == exceptMap:
  219. wx.MessageBox(parent=parent,
  220. message=_("Unable to create vector map <%s>.") % outmap,
  221. caption=_("Error"),
  222. style=wx.ID_OK | wx.ICON_ERROR | wx.CENTRE)
  223. return (None, None)
  224. if outmap == '': # should not happen
  225. return (None, None)
  226. cmd[1][cmd[2]] = outmap
  227. try:
  228. listOfVectors = grass.list_grouped('vect')[grass.gisenv()['MAPSET']]
  229. except KeyError:
  230. listOfVectors = []
  231. overwrite = False
  232. if not UserSettings.Get(group='cmd', key='overwrite', subkey='enabled') and \
  233. outmap in listOfVectors:
  234. dlgOw = wx.MessageDialog(parent, message=_("Vector map <%s> already exists "
  235. "in the current mapset. "
  236. "Do you want to overwrite it?") % outmap,
  237. caption=_("Overwrite?"),
  238. style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
  239. if dlgOw.ShowModal() == wx.ID_YES:
  240. overwrite = True
  241. else:
  242. dlgOw.Destroy()
  243. return (None, None)
  244. if UserSettings.Get(group='cmd', key='overwrite', subkey='enabled') is True:
  245. overwrite = True
  246. try:
  247. gcmd.RunCommand(prog = cmd[0],
  248. overwrite = overwrite,
  249. **cmd[1])
  250. except gcmd.GException, e:
  251. gcmd.GError(parent = self,
  252. message = e.value)
  253. return (None, None)
  254. #
  255. # create attribute table
  256. #
  257. if dlg.table.IsEnabled() and dlg.table.IsChecked():
  258. key = UserSettings.Get(group='atm', key='keycolumn', subkey='value')
  259. sql = 'CREATE TABLE %s (%s INTEGER)' % (outmap, key)
  260. gcmd.RunCommand('db.connect',
  261. flags = 'c')
  262. gcmd.RunCommand('db.execute',
  263. quiet = True,
  264. parent = parent,
  265. input = '-',
  266. stdin = sql)
  267. gcmd.RunCommand('v.db.connect',
  268. quiet = True,
  269. parent = parent,
  270. map = outmap,
  271. table = outmap,
  272. key = key,
  273. layer = '1')
  274. # return fully qualified map name
  275. if '@' not in outmap:
  276. outmap += '@' + grass.gisenv()['MAPSET']
  277. if log:
  278. log.WriteLog(_("New vector map <%s> created") % outmap)
  279. return (outmap, dlg.addbox.IsChecked())
  280. return (None, dlg.addbox.IsChecked())
  281. class SavedRegion(wx.Dialog):
  282. def __init__(self, parent, id = wx.ID_ANY, title="", loadsave='load',
  283. **kwargs):
  284. """!Loading and saving of display extents to saved region file
  285. @param loadsave load or save region?
  286. """
  287. wx.Dialog.__init__(self, parent, id, title, **kwargs)
  288. self.loadsave = loadsave
  289. self.wind = ''
  290. sizer = wx.BoxSizer(wx.VERTICAL)
  291. box = wx.BoxSizer(wx.HORIZONTAL)
  292. label = wx.StaticText(parent=self, id=wx.ID_ANY)
  293. box.Add(item=label, proportion=0, flag=wx.ALIGN_CENTRE | wx.ALL, border=5)
  294. if loadsave == 'load':
  295. label.SetLabel(_("Load region:"))
  296. selection = gselect.Select(parent=self, id=wx.ID_ANY, size=globalvar.DIALOG_GSELECT_SIZE,
  297. type='windows')
  298. elif loadsave == 'save':
  299. label.SetLabel(_("Save region:"))
  300. selection = gselect.Select(parent=self, id=wx.ID_ANY, size=globalvar.DIALOG_GSELECT_SIZE,
  301. type='windows', mapsets = [grass.gisenv()['MAPSET']])
  302. box.Add(item=selection, proportion=0, flag=wx.ALIGN_CENTRE | wx.ALL, border=5)
  303. selection.SetFocus()
  304. selection.Bind(wx.EVT_TEXT, self.OnRegion)
  305. sizer.Add(item=box, proportion=0, flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL,
  306. border=5)
  307. line = wx.StaticLine(parent=self, id=wx.ID_ANY, size=(20, -1), style=wx.LI_HORIZONTAL)
  308. sizer.Add(item=line, proportion=0,
  309. flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border=5)
  310. btnsizer = wx.StdDialogButtonSizer()
  311. btn = wx.Button(parent = self, id = wx.ID_OK)
  312. btn.SetDefault()
  313. btnsizer.AddButton(btn)
  314. btn = wx.Button(parent = self, id = wx.ID_CANCEL)
  315. btnsizer.AddButton(btn)
  316. btnsizer.Realize()
  317. sizer.Add(item=btnsizer, proportion=0, flag=wx.ALIGN_RIGHT | wx.ALL, border=5)
  318. self.SetSizer(sizer)
  319. sizer.Fit(self)
  320. self.Layout()
  321. def OnRegion(self, event):
  322. self.wind = event.GetString()
  323. class DecorationDialog(wx.Dialog):
  324. """
  325. Controls setting options and displaying/hiding map overlay decorations
  326. """
  327. def __init__(self, parent, ovlId, title, cmd, name=None,
  328. pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE,
  329. checktxt='', ctrltxt=''):
  330. wx.Dialog.__init__(self, parent, wx.ID_ANY, title, pos, size, style)
  331. self.ovlId = ovlId # PseudoDC id
  332. self.cmd = cmd
  333. self.name = name # overlay name
  334. self.parent = parent # MapFrame
  335. sizer = wx.BoxSizer(wx.VERTICAL)
  336. box = wx.BoxSizer(wx.HORIZONTAL)
  337. self.chkbox = wx.CheckBox(parent=self, id=wx.ID_ANY, label=checktxt)
  338. if self.parent.Map.GetOverlay(self.ovlId) is None:
  339. self.chkbox.SetValue(True)
  340. else:
  341. self.chkbox.SetValue(self.parent.MapWindow.overlays[self.ovlId]['layer'].IsActive())
  342. box.Add(item=self.chkbox, proportion=0,
  343. flag=wx.ALIGN_CENTRE|wx.ALL, border=5)
  344. sizer.Add(item=box, proportion=0,
  345. flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
  346. box = wx.BoxSizer(wx.HORIZONTAL)
  347. optnbtn = wx.Button(parent=self, id=wx.ID_ANY, label=_("Set options"))
  348. box.Add(item=optnbtn, proportion=0, flag=wx.ALIGN_CENTRE|wx.ALL, border=5)
  349. sizer.Add(item=box, proportion=0,
  350. flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
  351. if self.name == 'legend':
  352. box = wx.BoxSizer(wx.HORIZONTAL)
  353. resize = wx.ToggleButton(parent=self, id=wx.ID_ANY, label=_("Set size and position"))
  354. resize.SetToolTipString(_("Click and drag on the map display to set legend"
  355. " size and position and then press OK"))
  356. resize.SetName('resize')
  357. if self.parent.toolbars['nviz']:
  358. resize.Disable()
  359. box.Add(item=resize, proportion=0, flag=wx.ALIGN_CENTRE|wx.ALL, border=5)
  360. sizer.Add(item=box, proportion=0,
  361. flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
  362. box = wx.BoxSizer(wx.HORIZONTAL)
  363. label = wx.StaticText(parent=self, id=wx.ID_ANY,
  364. label=_("Drag %s with mouse in pointer mode to position.\n"
  365. "Double-click to change options." % ctrltxt))
  366. if self.name == 'legend':
  367. label.SetLabel(label.GetLabel() + _('\nDefine raster map name for legend in '
  368. 'properties dialog.'))
  369. box.Add(item=label, proportion=0,
  370. flag=wx.ALIGN_CENTRE|wx.ALL, border=5)
  371. sizer.Add(item=box, proportion=0,
  372. flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
  373. line = wx.StaticLine(parent=self, id=wx.ID_ANY, size=(20,-1), style=wx.LI_HORIZONTAL)
  374. sizer.Add(item=line, proportion=0,
  375. flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
  376. # buttons
  377. btnsizer = wx.StdDialogButtonSizer()
  378. self.btnOK = wx.Button(parent=self, id=wx.ID_OK)
  379. self.btnOK.SetDefault()
  380. if self.name == 'legend':
  381. self.btnOK.Enable(False)
  382. btnsizer.AddButton(self.btnOK)
  383. btnCancel = wx.Button(parent=self, id=wx.ID_CANCEL)
  384. btnsizer.AddButton(btnCancel)
  385. btnsizer.Realize()
  386. sizer.Add(item=btnsizer, proportion=0,
  387. flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
  388. #
  389. # bindings
  390. #
  391. self.Bind(wx.EVT_BUTTON, self.OnOptions, optnbtn)
  392. if self.name == 'legend':
  393. self.Bind(wx.EVT_TOGGLEBUTTON, self.OnResize, resize)
  394. self.Bind(wx.EVT_BUTTON, self.OnCancel, btnCancel)
  395. self.Bind(wx.EVT_BUTTON, self.OnOK, self.btnOK)
  396. self.SetSizer(sizer)
  397. sizer.Fit(self)
  398. # create overlay if doesn't exist
  399. self._CreateOverlay()
  400. if len(self.parent.MapWindow.overlays[self.ovlId]['cmd']) > 1:
  401. if name == 'legend':
  402. mapName, found = utils.GetLayerNameFromCmd(self.parent.MapWindow.overlays[self.ovlId]['cmd'])
  403. if found:
  404. # enable 'OK' button
  405. self.btnOK.Enable()
  406. # set title
  407. self.SetTitle(_('Legend of raster map <%s>') % \
  408. mapName)
  409. def _CreateOverlay(self):
  410. if not self.parent.Map.GetOverlay(self.ovlId):
  411. self.newOverlay = self.parent.Map.AddOverlay(id=self.ovlId, type=self.name,
  412. command=self.cmd,
  413. l_active=False, l_render=False, l_hidden=True)
  414. prop = { 'layer' : self.newOverlay,
  415. 'params' : None,
  416. 'propwin' : None,
  417. 'cmd' : self.cmd,
  418. 'coords': (0, 0),
  419. 'pdcType': 'image' }
  420. self.parent.MapWindow2D.overlays[self.ovlId] = prop
  421. if self.parent.MapWindow3D:
  422. self.parent.MapWindow3D.overlays[self.ovlId] = prop
  423. else:
  424. if self.parent.MapWindow.overlays[self.ovlId]['propwin'] == None:
  425. return
  426. self.parent.MapWindow.overlays[self.ovlId]['propwin'].get_dcmd = self.GetOptData
  427. def OnOptions(self, event):
  428. """ self.SetSizer(sizer)
  429. sizer.Fit(self)
  430. Sets option for decoration map overlays
  431. """
  432. if self.parent.MapWindow.overlays[self.ovlId]['propwin'] is None:
  433. # build properties dialog
  434. menuform.GUI(parent = self.parent).ParseCommand(cmd=self.cmd,
  435. completed=(self.GetOptData, self.name, ''))
  436. else:
  437. if self.parent.MapWindow.overlays[self.ovlId]['propwin'].IsShown():
  438. self.parent.MapWindow.overlays[self.ovlId]['propwin'].SetFocus()
  439. else:
  440. self.parent.MapWindow.overlays[self.ovlId]['propwin'].Show()
  441. def OnResize(self, event):
  442. if self.FindWindowByName('resize').GetValue():
  443. self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
  444. self.parent.MapWindow.mouse['use'] = 'legend'
  445. self.parent.MapWindow.mouse['box'] = 'box'
  446. self.parent.MapWindow.pen = wx.Pen(colour = 'Black', width = 2, style = wx.SHORT_DASH)
  447. else:
  448. self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
  449. self.parent.MapWindow.mouse['use'] = 'pointer'
  450. def OnCancel(self, event):
  451. """!Cancel dialog"""
  452. if self.name == 'legend' and self.FindWindowByName('resize').GetValue():
  453. self.FindWindowByName('resize').SetValue(False)
  454. self.OnResize(None)
  455. self.parent.dialogs['barscale'] = None
  456. if event and hasattr(self, 'newOverlay'):
  457. self.parent.Map.DeleteOverlay(self.newOverlay)
  458. self.Destroy()
  459. def OnOK(self, event):
  460. """!Button 'OK' pressed"""
  461. # enable or disable overlay
  462. self.parent.Map.GetOverlay(self.ovlId).SetActive(self.chkbox.IsChecked())
  463. # update map
  464. if self.parent.MapWindow.parent.toolbars['nviz']:
  465. self.parent.MapWindow.UpdateOverlays()
  466. self.parent.MapWindow.UpdateMap()
  467. # close dialog
  468. self.OnCancel(None)
  469. def GetOptData(self, dcmd, layer, params, propwin):
  470. """!Process decoration layer data"""
  471. # update layer data
  472. if params:
  473. self.parent.MapWindow.overlays[self.ovlId]['params'] = params
  474. if dcmd:
  475. self.parent.MapWindow.overlays[self.ovlId]['cmd'] = dcmd
  476. self.parent.MapWindow.overlays[self.ovlId]['propwin'] = propwin
  477. # change parameters for item in layers list in render.Map
  478. # "Use mouse..." (-m) flag causes GUI freeze and is pointless here, trac #119
  479. try:
  480. self.parent.MapWindow.overlays[self.ovlId]['cmd'].remove('-m')
  481. except ValueError:
  482. pass
  483. self.parent.Map.ChangeOverlay(id=self.ovlId, type=self.name,
  484. command=self.parent.MapWindow.overlays[self.ovlId]['cmd'],
  485. l_active=self.parent.MapWindow.overlays[self.ovlId]['layer'].IsActive(),
  486. l_render=False, l_hidden=True)
  487. if self.name == 'legend':
  488. if params and not self.btnOK.IsEnabled():
  489. self.btnOK.Enable()
  490. class TextLayerDialog(wx.Dialog):
  491. """
  492. Controls setting options and displaying/hiding map overlay decorations
  493. """
  494. def __init__(self, parent, ovlId, title, name='text',
  495. pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE):
  496. wx.Dialog.__init__(self, parent, wx.ID_ANY, title, pos, size, style)
  497. from wx.lib.expando import ExpandoTextCtrl, EVT_ETC_LAYOUT_NEEDED
  498. self.ovlId = ovlId
  499. self.parent = parent
  500. if self.ovlId in self.parent.MapWindow.textdict.keys():
  501. self.currText = self.parent.MapWindow.textdict[self.ovlId]['text']
  502. self.currFont = self.parent.MapWindow.textdict[self.ovlId]['font']
  503. self.currClr = self.parent.MapWindow.textdict[self.ovlId]['color']
  504. self.currRot = self.parent.MapWindow.textdict[self.ovlId]['rotation']
  505. self.currCoords = self.parent.MapWindow.textdict[self.ovlId]['coords']
  506. self.currBB = self.parent.MapWindow.textdict[self.ovlId]['bbox']
  507. else:
  508. self.currClr = wx.BLACK
  509. self.currText = ''
  510. self.currFont = self.GetFont()
  511. self.currRot = 0.0
  512. self.currCoords = [10, 10]
  513. self.currBB = wx.Rect()
  514. self.sizer = wx.BoxSizer(wx.VERTICAL)
  515. box = wx.GridBagSizer(vgap=5, hgap=5)
  516. # show/hide
  517. self.chkbox = wx.CheckBox(parent=self, id=wx.ID_ANY, \
  518. label='Show text object')
  519. if self.parent.Map.GetOverlay(self.ovlId) is None:
  520. self.chkbox.SetValue(True)
  521. else:
  522. self.chkbox.SetValue(self.parent.MapWindow.overlays[self.ovlId]['layer'].IsActive())
  523. box.Add(item=self.chkbox, span=(1,2),
  524. flag=wx.ALIGN_LEFT|wx.ALL, border=5,
  525. pos=(0, 0))
  526. # text entry
  527. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Enter text:"))
  528. box.Add(item=label,
  529. flag=wx.ALIGN_CENTER_VERTICAL,
  530. pos=(1, 0))
  531. self.textentry = ExpandoTextCtrl(parent=self, id=wx.ID_ANY, value="", size=(300,-1))
  532. self.textentry.SetFont(self.currFont)
  533. self.textentry.SetForegroundColour(self.currClr)
  534. self.textentry.SetValue(self.currText)
  535. # get rid of unneeded scrollbar when text box first opened
  536. self.textentry.SetClientSize((300,-1))
  537. box.Add(item=self.textentry,
  538. pos=(1, 1))
  539. # rotation
  540. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Rotation:"))
  541. box.Add(item=label,
  542. flag=wx.ALIGN_CENTER_VERTICAL,
  543. pos=(2, 0))
  544. self.rotation = wx.SpinCtrl(parent=self, id=wx.ID_ANY, value="", pos=(30, 50),
  545. size=(75,-1), style=wx.SP_ARROW_KEYS)
  546. self.rotation.SetRange(-360, 360)
  547. self.rotation.SetValue(int(self.currRot))
  548. box.Add(item=self.rotation,
  549. flag=wx.ALIGN_RIGHT,
  550. pos=(2, 1))
  551. # font
  552. fontbtn = wx.Button(parent=self, id=wx.ID_ANY, label=_("Set font"))
  553. box.Add(item=fontbtn,
  554. flag=wx.ALIGN_RIGHT,
  555. pos=(3, 1))
  556. self.sizer.Add(item=box, proportion=1,
  557. flag=wx.ALL, border=10)
  558. # note
  559. box = wx.BoxSizer(wx.HORIZONTAL)
  560. label = wx.StaticText(parent=self, id=wx.ID_ANY,
  561. label=_("Drag text with mouse in pointer mode "
  562. "to position.\nDouble-click to change options"))
  563. box.Add(item=label, proportion=0,
  564. flag=wx.ALIGN_CENTRE | wx.ALL, border=5)
  565. self.sizer.Add(item=box, proportion=0,
  566. flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER | wx.ALL, border=5)
  567. line = wx.StaticLine(parent=self, id=wx.ID_ANY,
  568. size=(20,-1), style=wx.LI_HORIZONTAL)
  569. self.sizer.Add(item=line, proportion=0,
  570. flag=wx.EXPAND | wx.ALIGN_CENTRE | wx.ALL, border=5)
  571. btnsizer = wx.StdDialogButtonSizer()
  572. btn = wx.Button(parent=self, id=wx.ID_OK)
  573. btn.SetDefault()
  574. btnsizer.AddButton(btn)
  575. btn = wx.Button(parent=self, id=wx.ID_CANCEL)
  576. btnsizer.AddButton(btn)
  577. btnsizer.Realize()
  578. self.sizer.Add(item=btnsizer, proportion=0,
  579. flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
  580. self.SetSizer(self.sizer)
  581. self.sizer.Fit(self)
  582. # bindings
  583. self.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnRefit, self.textentry)
  584. self.Bind(wx.EVT_BUTTON, self.OnSelectFont, fontbtn)
  585. self.Bind(wx.EVT_TEXT, self.OnText, self.textentry)
  586. self.Bind(wx.EVT_SPINCTRL, self.OnRotation, self.rotation)
  587. def OnRefit(self, event):
  588. """!Resize text entry to match text"""
  589. self.sizer.Fit(self)
  590. def OnText(self, event):
  591. """!Change text string"""
  592. self.currText = event.GetString()
  593. def OnRotation(self, event):
  594. """!Change rotation"""
  595. self.currRot = event.GetInt()
  596. event.Skip()
  597. def OnSelectFont(self, event):
  598. """!Change font"""
  599. data = wx.FontData()
  600. data.EnableEffects(True)
  601. data.SetColour(self.currClr) # set colour
  602. data.SetInitialFont(self.currFont)
  603. dlg = wx.FontDialog(self, data)
  604. if dlg.ShowModal() == wx.ID_OK:
  605. data = dlg.GetFontData()
  606. self.currFont = data.GetChosenFont()
  607. self.currClr = data.GetColour()
  608. self.textentry.SetFont(self.currFont)
  609. self.textentry.SetForegroundColour(self.currClr)
  610. self.Layout()
  611. dlg.Destroy()
  612. def GetValues(self):
  613. """!Get text properties"""
  614. return { 'text' : self.currText,
  615. 'font' : self.currFont,
  616. 'color' : self.currClr,
  617. 'rotation' : self.currRot,
  618. 'coords' : self.currCoords,
  619. 'active' : self.chkbox.IsChecked() }
  620. class AddMapLayersDialog(wx.Dialog):
  621. """!Add selected map layers (raster, vector) into layer tree"""
  622. def __init__(self, parent, title, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
  623. wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY, title=title, style=style)
  624. self.parent = parent # GMFrame
  625. #
  626. # dialog body
  627. #
  628. self.bodySizer = self.__createDialogBody()
  629. # update list of layer to be loaded
  630. self.map_layers = [] # list of map layers (full list type/mapset)
  631. self.LoadMapLayers(self.layerType.GetStringSelection()[:4],
  632. self.mapset.GetStringSelection())
  633. #
  634. # buttons
  635. #
  636. btnCancel = wx.Button(parent = self, id = wx.ID_CANCEL)
  637. btnOk = wx.Button(parent = self, id = wx.ID_OK, label = _("&Add"))
  638. btnOk.SetDefault()
  639. btnOk.SetToolTipString(_("Add selected map layers to current display"))
  640. #
  641. # sizers & do layout
  642. #
  643. btnSizer = wx.StdDialogButtonSizer()
  644. btnSizer.AddButton(btnCancel)
  645. btnSizer.AddButton(btnOk)
  646. btnSizer.Realize()
  647. mainSizer = wx.BoxSizer(wx.VERTICAL)
  648. mainSizer.Add(item=self.bodySizer, proportion=1,
  649. flag=wx.EXPAND | wx.ALL, border=5)
  650. mainSizer.Add(item=btnSizer, proportion=0,
  651. flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
  652. self.SetSizer(mainSizer)
  653. mainSizer.Fit(self)
  654. # set dialog min size
  655. self.SetMinSize(self.GetSize())
  656. def __createDialogBody(self):
  657. bodySizer = wx.GridBagSizer(vgap=3, hgap=3)
  658. bodySizer.AddGrowableCol(1)
  659. bodySizer.AddGrowableRow(3)
  660. # layer type
  661. bodySizer.Add(item=wx.StaticText(parent=self, label=_("Map layer type:")),
  662. flag=wx.ALIGN_CENTER_VERTICAL,
  663. pos=(0,0))
  664. self.layerType = wx.Choice(parent=self, id=wx.ID_ANY,
  665. choices=['raster', 'vector'], size=(100,-1))
  666. self.layerType.SetSelection(0)
  667. bodySizer.Add(item=self.layerType,
  668. pos=(0,1))
  669. # select toggle
  670. self.toggle = wx.CheckBox(parent=self, id=wx.ID_ANY,
  671. label=_("Select toggle"))
  672. self.toggle.SetValue(True)
  673. bodySizer.Add(item=self.toggle,
  674. flag=wx.ALIGN_CENTER_VERTICAL,
  675. pos=(0,2))
  676. # mapset filter
  677. bodySizer.Add(item=wx.StaticText(parent=self, label=_("Mapset:")),
  678. flag=wx.ALIGN_CENTER_VERTICAL,
  679. pos=(1,0))
  680. self.mapset = gselect.MapsetSelect(parent = self)
  681. self.mapset.SetStringSelection(grass.gisenv()['MAPSET'])
  682. bodySizer.Add(item=self.mapset,
  683. pos=(1,1), span=(1, 2))
  684. # map name filter
  685. bodySizer.Add(item=wx.StaticText(parent=self, label=_("Filter:")),
  686. flag=wx.ALIGN_CENTER_VERTICAL,
  687. pos=(2,0))
  688. self.filter = wx.TextCtrl(parent=self, id=wx.ID_ANY,
  689. value="",
  690. size=(250,-1))
  691. bodySizer.Add(item=self.filter,
  692. flag=wx.EXPAND,
  693. pos=(2,1), span=(1, 2))
  694. # layer list
  695. bodySizer.Add(item=wx.StaticText(parent=self, label=_("List of maps:")),
  696. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_TOP,
  697. pos=(3,0))
  698. self.layers = wx.CheckListBox(parent=self, id=wx.ID_ANY,
  699. size=(250, 100),
  700. choices=[])
  701. bodySizer.Add(item=self.layers,
  702. flag=wx.EXPAND,
  703. pos=(3,1), span=(1, 2))
  704. # bindings
  705. self.layerType.Bind(wx.EVT_CHOICE, self.OnChangeParams)
  706. self.mapset.Bind(wx.EVT_COMBOBOX, self.OnChangeParams)
  707. self.layers.Bind(wx.EVT_RIGHT_DOWN, self.OnMenu)
  708. self.filter.Bind(wx.EVT_TEXT, self.OnFilter)
  709. self.toggle.Bind(wx.EVT_CHECKBOX, self.OnToggle)
  710. return bodySizer
  711. def LoadMapLayers(self, type, mapset):
  712. """!Load list of map layers
  713. @param type layer type ('raster' or 'vector')
  714. @param mapset mapset name
  715. """
  716. self.map_layers = grass.mlist(type = type, mapset = mapset)
  717. self.layers.Set(self.map_layers)
  718. # check all items by default
  719. for item in range(self.layers.GetCount()):
  720. self.layers.Check(item)
  721. def OnChangeParams(self, event):
  722. """!Filter parameters changed by user"""
  723. # update list of layer to be loaded
  724. self.LoadMapLayers(self.layerType.GetStringSelection()[:4],
  725. self.mapset.GetStringSelection())
  726. event.Skip()
  727. def OnMenu(self, event):
  728. """!Table description area, context menu"""
  729. if not hasattr(self, "popupID1"):
  730. self.popupDataID1 = wx.NewId()
  731. self.popupDataID2 = wx.NewId()
  732. self.popupDataID3 = wx.NewId()
  733. self.Bind(wx.EVT_MENU, self.OnSelectAll, id=self.popupDataID1)
  734. self.Bind(wx.EVT_MENU, self.OnSelectInvert, id=self.popupDataID2)
  735. self.Bind(wx.EVT_MENU, self.OnDeselectAll, id=self.popupDataID3)
  736. # generate popup-menu
  737. menu = wx.Menu()
  738. menu.Append(self.popupDataID1, _("Select all"))
  739. menu.Append(self.popupDataID2, _("Invert selection"))
  740. menu.Append(self.popupDataID3, _("Deselect all"))
  741. self.PopupMenu(menu)
  742. menu.Destroy()
  743. def OnSelectAll(self, event):
  744. """!Select all map layer from list"""
  745. for item in range(self.layers.GetCount()):
  746. self.layers.Check(item, True)
  747. def OnSelectInvert(self, event):
  748. """!Invert current selection"""
  749. for item in range(self.layers.GetCount()):
  750. if self.layers.IsChecked(item):
  751. self.layers.Check(item, False)
  752. else:
  753. self.layers.Check(item, True)
  754. def OnDeselectAll(self, event):
  755. """!Select all map layer from list"""
  756. for item in range(self.layers.GetCount()):
  757. self.layers.Check(item, False)
  758. def OnFilter(self, event):
  759. """!Apply filter for map names"""
  760. if len(event.GetString()) == 0:
  761. self.layers.Set(self.map_layers)
  762. return
  763. list = []
  764. for layer in self.map_layers:
  765. try:
  766. if re.compile('^' + event.GetString()).search(layer):
  767. list.append(layer)
  768. except:
  769. pass
  770. self.layers.Set(list)
  771. self.OnSelectAll(None)
  772. event.Skip()
  773. def OnToggle(self, event):
  774. """!Select toggle (check or uncheck all layers)"""
  775. check = event.Checked()
  776. for item in range(self.layers.GetCount()):
  777. self.layers.Check(item, check)
  778. event.Skip()
  779. def GetMapLayers(self):
  780. """!Return list of checked map layers"""
  781. layerNames = []
  782. for indx in self.layers.GetSelections():
  783. # layers.append(self.layers.GetStringSelec(indx))
  784. pass
  785. # return fully qualified map names
  786. mapset = self.mapset.GetStringSelection()
  787. for item in range(self.layers.GetCount()):
  788. if not self.layers.IsChecked(item):
  789. continue
  790. layerNames.append(self.layers.GetString(item) + '@' + mapset)
  791. return layerNames
  792. def GetLayerType(self):
  793. """!Get selected layer type"""
  794. return self.layerType.GetStringSelection()
  795. class ImportDialog(wx.Dialog):
  796. """!Dialog for bulk import of various data (base class)"""
  797. def __init__(self, parent, itype,
  798. id = wx.ID_ANY, title = _("Multiple import"),
  799. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
  800. self.parent = parent # GMFrame
  801. self.importType = itype
  802. self.options = dict() # list of options
  803. self.commandId = -1 # id of running command
  804. wx.Dialog.__init__(self, parent, id, title, style=style,
  805. name = "MultiImportDialog")
  806. self.panel = wx.Panel(parent=self, id=wx.ID_ANY)
  807. self.layerBox = wx.StaticBox(parent=self.panel, id=wx.ID_ANY,
  808. label=_(" List of %s layers ") % self.importType.upper())
  809. #
  810. # list of layers
  811. #
  812. self.list = LayersList(self.panel)
  813. self.list.LoadData()
  814. self.optionBox = wx.StaticBox(parent=self.panel, id=wx.ID_ANY,
  815. label="%s" % _("Options"))
  816. cmd = self._getCommand()
  817. task = gtask.parse_interface(cmd)
  818. for f in task.get_options()['flags']:
  819. name = f.get('name', '')
  820. desc = f.get('label', '')
  821. if not desc:
  822. desc = f.get('description', '')
  823. if not name and not desc:
  824. continue
  825. if cmd == 'r.in.gdal' and name not in ('o', 'e', 'l', 'k'):
  826. continue
  827. elif cmd == 'r.external' and name not in ('o', 'e', 'r', 'h', 'v'):
  828. continue
  829. elif cmd == 'v.in.ogr' and name not in ('c', 'z', 't', 'o', 'r', 'e', 'w'):
  830. continue
  831. elif cmd == 'v.external' and name not in ('b'):
  832. continue
  833. elif cmd == 'v.in.dxf' and name not in ('e', 't', 'b', 'f', 'i'):
  834. continue
  835. self.options[name] = wx.CheckBox(parent = self.panel, id = wx.ID_ANY,
  836. label = desc)
  837. self.overwrite = wx.CheckBox(parent=self.panel, id=wx.ID_ANY,
  838. label=_("Allow output files to overwrite existing files"))
  839. self.overwrite.SetValue(UserSettings.Get(group='cmd', key='overwrite', subkey='enabled'))
  840. self.add = wx.CheckBox(parent=self.panel, id=wx.ID_ANY)
  841. #
  842. # buttons
  843. #
  844. # cancel
  845. self.btn_cancel = wx.Button(parent=self.panel, id=wx.ID_CANCEL)
  846. self.btn_cancel.SetToolTipString(_("Close dialog"))
  847. self.btn_cancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  848. # run
  849. self.btn_run = wx.Button(parent=self.panel, id=wx.ID_OK, label = _("&Import"))
  850. self.btn_run.SetToolTipString(_("Import selected layers"))
  851. self.btn_run.SetDefault()
  852. self.btn_run.Enable(False)
  853. self.btn_run.Bind(wx.EVT_BUTTON, self.OnRun)
  854. # run command dialog
  855. self.btn_cmd = wx.Button(parent = self.panel, id = wx.ID_ANY,
  856. label = _("Command dialog"))
  857. self.btn_cmd.Bind(wx.EVT_BUTTON, self.OnCmdDialog)
  858. def doLayout(self):
  859. """!Do layout"""
  860. dialogSizer = wx.BoxSizer(wx.VERTICAL)
  861. # dsn input
  862. dialogSizer.Add(item = self.dsnInput, proportion = 0,
  863. flag = wx.EXPAND)
  864. #
  865. # list of DXF layers
  866. #
  867. layerSizer = wx.StaticBoxSizer(self.layerBox, wx.HORIZONTAL)
  868. layerSizer.Add(item=self.list, proportion=1,
  869. flag=wx.ALL | wx.EXPAND, border=5)
  870. dialogSizer.Add(item=layerSizer, proportion=1,
  871. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=5)
  872. # options
  873. optionSizer = wx.StaticBoxSizer(self.optionBox, wx.VERTICAL)
  874. for key in self.options.keys():
  875. optionSizer.Add(item=self.options[key], proportion=0)
  876. dialogSizer.Add(item=optionSizer, proportion=0,
  877. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=5)
  878. dialogSizer.Add(item=self.overwrite, proportion=0,
  879. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM, border=5)
  880. dialogSizer.Add(item=self.add, proportion=0,
  881. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM, border=5)
  882. #
  883. # buttons
  884. #
  885. btnsizer = wx.BoxSizer(orient=wx.HORIZONTAL)
  886. btnsizer.Add(item=self.btn_cmd, proportion=0,
  887. flag=wx.ALL | wx.ALIGN_CENTER,
  888. border=10)
  889. btnsizer.Add(item=self.btn_run, proportion=0,
  890. flag=wx.ALL | wx.ALIGN_CENTER,
  891. border=10)
  892. btnsizer.Add(item=self.btn_cancel, proportion=0,
  893. flag=wx.ALL | wx.ALIGN_CENTER,
  894. border=10)
  895. dialogSizer.Add(item=btnsizer, proportion=0,
  896. flag=wx.ALIGN_CENTER)
  897. # dialogSizer.SetSizeHints(self.panel)
  898. self.panel.SetAutoLayout(True)
  899. self.panel.SetSizer(dialogSizer)
  900. dialogSizer.Fit(self.panel)
  901. # auto-layout seems not work here - FIXME
  902. size = wx.Size(globalvar.DIALOG_GSELECT_SIZE[0] + 225, 550)
  903. self.SetMinSize(size)
  904. self.SetSize((size.width, size.height + 100))
  905. width = self.GetSize()[0]
  906. self.list.SetColumnWidth(col=1, width=width/2 - 50)
  907. self.Layout()
  908. def _getCommand(self):
  909. """!Get command"""
  910. return ''
  911. def OnCancel(self, event=None):
  912. """!Close dialog"""
  913. self.Close()
  914. def OnRun(self, event):
  915. """!Import/Link data (each layes as separate vector map)"""
  916. pass
  917. def OnCmdDialog(self, event):
  918. """!Show command dialog"""
  919. pass
  920. def AddLayers(self, returncode, cmd = None):
  921. """!Add imported/linked layers into layer tree"""
  922. self.commandId += 1
  923. if not self.add.IsChecked() or returncode != 0:
  924. return
  925. maptree = self.parent.curr_page.maptree
  926. layer, output = self.list.GetLayers()[self.commandId]
  927. if '@' not in output:
  928. name = output + '@' + grass.gisenv()['MAPSET']
  929. else:
  930. name = output
  931. # add imported layers into layer tree
  932. if self.importType == 'gdal':
  933. cmd = ['d.rast',
  934. 'map=%s' % name]
  935. if UserSettings.Get(group='cmd', key='rasterOverlay', subkey='enabled'):
  936. cmd.append('-o')
  937. item = maptree.AddLayer(ltype = 'raster',
  938. lname = name, lchecked = False,
  939. lcmd = cmd)
  940. else:
  941. item = maptree.AddLayer(ltype = 'vector',
  942. lname = name, lchecked = False,
  943. lcmd = ['d.vect',
  944. 'map=%s' % name])
  945. maptree.mapdisplay.MapWindow.ZoomToMap()
  946. def OnAbort(self, event):
  947. """!Abort running import
  948. @todo not yet implemented
  949. """
  950. pass
  951. class GdalImportDialog(ImportDialog):
  952. """!Dialog for bulk import of various raster/vector data"""
  953. def __init__(self, parent, ogr = False, link = False):
  954. self.link = link
  955. self.ogr = ogr
  956. if ogr:
  957. ImportDialog.__init__(self, parent, itype = 'ogr')
  958. if link:
  959. self.SetTitle(_("Link external vector data"))
  960. else:
  961. self.SetTitle(_("Import vector data"))
  962. else:
  963. ImportDialog.__init__(self, parent, itype = 'gdal')
  964. if link:
  965. self.SetTitle(_("Link external raster data"))
  966. else:
  967. self.SetTitle(_("Import raster data"))
  968. self.dsnInput = gselect.GdalSelect(parent = self, panel = self.panel, ogr = ogr)
  969. if link:
  970. self.add.SetLabel(_("Add linked layers into layer tree"))
  971. else:
  972. self.add.SetLabel(_("Add imported layers into layer tree"))
  973. self.add.SetValue(UserSettings.Get(group='cmd', key='addNewLayer', subkey='enabled'))
  974. if link:
  975. self.btn_run.SetLabel(_("&Link"))
  976. self.btn_run.SetToolTipString(_("Link selected layers"))
  977. if ogr:
  978. self.btn_cmd.SetToolTipString(_('Open %s dialog') % 'v.external')
  979. else:
  980. self.btn_cmd.SetToolTipString(_('Open %s dialog') % 'r.external')
  981. else:
  982. self.btn_run.SetLabel(_("&Import"))
  983. self.btn_run.SetToolTipString(_("Import selected layers"))
  984. if ogr:
  985. self.btn_cmd.SetToolTipString(_('Open %s dialog') % 'v.in.ogr')
  986. else:
  987. self.btn_cmd.SetToolTipString(_('Open %s dialog') % 'r.in.gdal')
  988. self.doLayout()
  989. def OnRun(self, event):
  990. """!Import/Link data (each layes as separate vector map)"""
  991. data = self.list.GetLayers()
  992. # hide dialog
  993. self.Hide()
  994. dsn = self.dsnInput.GetDsn()
  995. ext = self.dsnInput.GetFormatExt()
  996. for layer, output in data:
  997. if self.importType == 'ogr':
  998. if ext and layer.rfind(ext) > -1:
  999. layer = layer.replace('.' + ext, '')
  1000. if self.link:
  1001. cmd = ['v.external',
  1002. 'dsn=%s' % dsn,
  1003. 'output=%s' % output,
  1004. 'layer=%s' % layer]
  1005. else:
  1006. cmd = ['v.in.ogr',
  1007. 'dsn=%s' % dsn,
  1008. 'layer=%s' % layer,
  1009. 'output=%s' % output]
  1010. else: # gdal
  1011. if self.dsnInput.GetType() == 'dir':
  1012. idsn = os.path.join(dsn, layer)
  1013. else:
  1014. idsn = dsn
  1015. if self.link:
  1016. cmd = ['r.external',
  1017. 'input=%s' % idsn,
  1018. 'output=%s' % output]
  1019. else:
  1020. cmd = ['r.in.gdal',
  1021. 'input=%s' % idsn,
  1022. 'output=%s' % output]
  1023. if self.overwrite.IsChecked():
  1024. cmd.append('--overwrite')
  1025. for key in self.options.keys():
  1026. if self.options[key].IsChecked():
  1027. cmd.append('-%s' % key)
  1028. if UserSettings.Get(group='cmd', key='overwrite', subkey='enabled'):
  1029. cmd.append('--overwrite')
  1030. # run in Layer Manager
  1031. self.parent.goutput.RunCmd(cmd, switchPage = True,
  1032. onDone = self.AddLayers)
  1033. self.OnCancel()
  1034. def _getCommand(self):
  1035. """!Get command"""
  1036. if self.link:
  1037. if self.ogr:
  1038. return 'v.external'
  1039. else:
  1040. return 'r.external'
  1041. else:
  1042. if self.ogr:
  1043. return 'v.in.ogr'
  1044. else:
  1045. return 'r.in.gdal'
  1046. return ''
  1047. def OnCmdDialog(self, event):
  1048. """!Show command dialog"""
  1049. name = self._getCommand()
  1050. menuform.GUI(parent = self, modal = True).ParseCommand(cmd = [name])
  1051. class DxfImportDialog(ImportDialog):
  1052. """!Dialog for bulk import of DXF layers"""
  1053. def __init__(self, parent):
  1054. ImportDialog.__init__(self, parent, itype = 'dxf',
  1055. title = _("Import DXF layers"))
  1056. self.dsnInput = filebrowse.FileBrowseButton(parent=self.panel, id=wx.ID_ANY,
  1057. size=globalvar.DIALOG_GSELECT_SIZE, labelText='',
  1058. dialogTitle=_('Choose DXF file to import'),
  1059. buttonText=_('Browse'),
  1060. startDirectory=os.getcwd(), fileMode=0,
  1061. changeCallback=self.OnSetDsn,
  1062. fileMask="DXF File (*.dxf)|*.dxf")
  1063. self.add.SetLabel(_("Add imported layers into layer tree"))
  1064. self.add.SetValue(UserSettings.Get(group='cmd', key='addNewLayer', subkey='enabled'))
  1065. self.doLayout()
  1066. def _getCommand(self):
  1067. """!Get command"""
  1068. return 'v.in.dxf'
  1069. def OnRun(self, event):
  1070. """!Import/Link data (each layes as separate vector map)"""
  1071. data = self.list.GetLayers()
  1072. # hide dialog
  1073. self.Hide()
  1074. inputDxf = self.dsnInput.GetValue()
  1075. for layer, output in data:
  1076. cmd = ['v.in.dxf',
  1077. 'input=%s' % inputDxf,
  1078. 'layers=%s' % layer,
  1079. 'output=%s' % output]
  1080. for key in self.options.keys():
  1081. if self.options[key].IsChecked():
  1082. cmd.append('-%s' % key)
  1083. if self.overwrite.IsChecked() or \
  1084. UserSettings.Get(group='cmd', key='overwrite', subkey='enabled'):
  1085. cmd.append('--overwrite')
  1086. # run in Layer Manager
  1087. self.parent.goutput.RunCmd(cmd, switchPage=True,
  1088. onDone = self.AddLayers)
  1089. self.OnCancel()
  1090. def OnSetDsn(self, event):
  1091. """!Input DXF file defined, update list of layer widget"""
  1092. path = event.GetString()
  1093. if not path:
  1094. return
  1095. data = list()
  1096. ret = gcmd.RunCommand('v.in.dxf',
  1097. quiet = True,
  1098. parent = self,
  1099. read = True,
  1100. flags = 'l',
  1101. input = path)
  1102. if not ret:
  1103. self.list.LoadData()
  1104. self.btn_run.Enable(False)
  1105. return
  1106. for line in ret.splitlines():
  1107. layerId = line.split(':')[0].split(' ')[1]
  1108. layerName = line.split(':')[1].strip()
  1109. grassName = utils.GetValidLayerName(layerName)
  1110. data.append((layerId, layerName.strip(), grassName.strip()))
  1111. self.list.LoadData(data)
  1112. if len(data) > 0:
  1113. self.btn_run.Enable(True)
  1114. else:
  1115. self.btn_run.Enable(False)
  1116. def OnCmdDialog(self, event):
  1117. """!Show command dialog"""
  1118. menuform.GUI(parent = self, modal = True).ParseCommand(cmd = ['v.in.dxf'])
  1119. class LayersList(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin,
  1120. listmix.CheckListCtrlMixin, listmix.TextEditMixin):
  1121. """!List of layers to be imported (dxf, shp...)"""
  1122. def __init__(self, parent, pos = wx.DefaultPosition,
  1123. log = None):
  1124. self.parent = parent
  1125. wx.ListCtrl.__init__(self, parent, wx.ID_ANY,
  1126. style=wx.LC_REPORT)
  1127. listmix.CheckListCtrlMixin.__init__(self)
  1128. self.log = log
  1129. # setup mixins
  1130. listmix.ListCtrlAutoWidthMixin.__init__(self)
  1131. listmix.TextEditMixin.__init__(self)
  1132. self.InsertColumn(0, _('Layer'))
  1133. self.InsertColumn(1, _('Layer name'))
  1134. self.InsertColumn(2, _('Name for GRASS map'))
  1135. self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnPopupMenu) #wxMSW
  1136. self.Bind(wx.EVT_RIGHT_UP, self.OnPopupMenu) #wxGTK
  1137. def LoadData(self, data=None):
  1138. """!Load data into list"""
  1139. if data is None:
  1140. return
  1141. self.DeleteAllItems()
  1142. for id, name, grassName in data:
  1143. index = self.InsertStringItem(sys.maxint, str(id))
  1144. self.SetStringItem(index, 1, "%s" % str(name))
  1145. self.SetStringItem(index, 2, "%s" % str(grassName))
  1146. # check by default
  1147. self.CheckItem(index, True)
  1148. self.SetColumnWidth(col=0, width=wx.LIST_AUTOSIZE_USEHEADER)
  1149. def OnPopupMenu(self, event):
  1150. """!Show popup menu"""
  1151. if self.GetItemCount() < 1:
  1152. return
  1153. if not hasattr(self, "popupDataID1"):
  1154. self.popupDataID1 = wx.NewId()
  1155. self.popupDataID2 = wx.NewId()
  1156. self.Bind(wx.EVT_MENU, self.OnSelectAll, id=self.popupDataID1)
  1157. self.Bind(wx.EVT_MENU, self.OnSelectNone, id=self.popupDataID2)
  1158. # generate popup-menu
  1159. menu = wx.Menu()
  1160. menu.Append(self.popupDataID1, _("Select all"))
  1161. menu.Append(self.popupDataID2, _("Deselect all"))
  1162. self.PopupMenu(menu)
  1163. menu.Destroy()
  1164. def OnSelectAll(self, event):
  1165. """!Select all items"""
  1166. item = -1
  1167. while True:
  1168. item = self.GetNextItem(item)
  1169. if item == -1:
  1170. break
  1171. self.CheckItem(item, True)
  1172. event.Skip()
  1173. def OnSelectNone(self, event):
  1174. """!Deselect items"""
  1175. item = -1
  1176. while True:
  1177. item = self.GetNextItem(item, wx.LIST_STATE_SELECTED)
  1178. if item == -1:
  1179. break
  1180. self.CheckItem(item, False)
  1181. event.Skip()
  1182. def GetLayers(self):
  1183. """!Get list of layers (layer name, output name)"""
  1184. data = []
  1185. item = -1
  1186. while True:
  1187. item = self.GetNextItem(item)
  1188. if item == -1:
  1189. break
  1190. if self.IsChecked(item):
  1191. # layer / output name
  1192. data.append((self.GetItem(item, 1).GetText(),
  1193. self.GetItem(item, 2).GetText()))
  1194. return data
  1195. class SetOpacityDialog(wx.Dialog):
  1196. """!Set opacity of map layers"""
  1197. def __init__(self, parent, id=wx.ID_ANY, title=_("Set Map Layer Opacity"),
  1198. size=wx.DefaultSize, pos=wx.DefaultPosition,
  1199. style=wx.DEFAULT_DIALOG_STYLE, opacity=100):
  1200. self.parent = parent # GMFrame
  1201. self.opacity = opacity # current opacity
  1202. super(SetOpacityDialog, self).__init__(parent, id=id, pos=pos,
  1203. size=size, style=style, title=title)
  1204. panel = wx.Panel(parent=self, id=wx.ID_ANY)
  1205. sizer = wx.BoxSizer(wx.VERTICAL)
  1206. box = wx.GridBagSizer(vgap=5, hgap=5)
  1207. self.value = wx.Slider(panel, id=wx.ID_ANY, value=self.opacity,
  1208. style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | \
  1209. wx.SL_TOP | wx.SL_LABELS,
  1210. minValue=0, maxValue=100,
  1211. size=(350, -1))
  1212. box.Add(item=self.value,
  1213. flag=wx.ALIGN_CENTRE, pos=(0, 0), span=(1, 2))
  1214. box.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  1215. label=_("transparent")),
  1216. pos=(1, 0))
  1217. box.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  1218. label=_("opaque")),
  1219. flag=wx.ALIGN_RIGHT,
  1220. pos=(1, 1))
  1221. sizer.Add(item=box, proportion=0,
  1222. flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
  1223. line = wx.StaticLine(parent=panel, id=wx.ID_ANY,
  1224. style=wx.LI_HORIZONTAL)
  1225. sizer.Add(item=line, proportion=0,
  1226. flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
  1227. # buttons
  1228. btnsizer = wx.StdDialogButtonSizer()
  1229. btnOK = wx.Button(parent=panel, id=wx.ID_OK)
  1230. btnOK.SetDefault()
  1231. btnsizer.AddButton(btnOK)
  1232. btnCancel = wx.Button(parent=panel, id=wx.ID_CANCEL)
  1233. btnsizer.AddButton(btnCancel)
  1234. btnsizer.Realize()
  1235. sizer.Add(item=btnsizer, proportion=0,
  1236. flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
  1237. panel.SetSizer(sizer)
  1238. sizer.Fit(panel)
  1239. self.SetSize(self.GetBestSize())
  1240. self.Layout()
  1241. def GetOpacity(self):
  1242. """!Button 'OK' pressed"""
  1243. # return opacity value
  1244. opacity = float(self.value.GetValue()) / 100
  1245. return opacity
  1246. def GetImageHandlers(image):
  1247. """!Get list of supported image handlers"""
  1248. lext = list()
  1249. ltype = list()
  1250. for h in image.GetHandlers():
  1251. lext.append(h.GetExtension())
  1252. filetype = ''
  1253. if 'png' in lext:
  1254. filetype += "PNG file (*.png)|*.png|"
  1255. ltype.append({ 'type' : wx.BITMAP_TYPE_PNG,
  1256. 'ext' : 'png' })
  1257. filetype += "BMP file (*.bmp)|*.bmp|"
  1258. ltype.append({ 'type' : wx.BITMAP_TYPE_BMP,
  1259. 'ext' : 'bmp' })
  1260. if 'gif' in lext:
  1261. filetype += "GIF file (*.gif)|*.gif|"
  1262. ltype.append({ 'type' : wx.BITMAP_TYPE_GIF,
  1263. 'ext' : 'gif' })
  1264. if 'jpg' in lext:
  1265. filetype += "JPG file (*.jpg)|*.jpg|"
  1266. ltype.append({ 'type' : wx.BITMAP_TYPE_JPEG,
  1267. 'ext' : 'jpg' })
  1268. if 'pcx' in lext:
  1269. filetype += "PCX file (*.pcx)|*.pcx|"
  1270. ltype.append({ 'type' : wx.BITMAP_TYPE_PCX,
  1271. 'ext' : 'pcx' })
  1272. if 'pnm' in lext:
  1273. filetype += "PNM file (*.pnm)|*.pnm|"
  1274. ltype.append({ 'type' : wx.BITMAP_TYPE_PNM,
  1275. 'ext' : 'pnm' })
  1276. if 'tif' in lext:
  1277. filetype += "TIF file (*.tif)|*.tif|"
  1278. ltype.append({ 'type' : wx.BITMAP_TYPE_TIF,
  1279. 'ext' : 'tif' })
  1280. if 'xpm' in lext:
  1281. filetype += "XPM file (*.xpm)|*.xpm"
  1282. ltype.append({ 'type' : wx.BITMAP_TYPE_XPM,
  1283. 'ext' : 'xpm' })
  1284. return filetype, ltype
  1285. class StaticWrapText(wx.StaticText):
  1286. """!A Static Text field that wraps its text to fit its width,
  1287. enlarging its height if necessary.
  1288. """
  1289. def __init__(self, parent, id = wx.ID_ANY, label = '', *args, **kwds):
  1290. self.parent = parent
  1291. self.originalLabel = label
  1292. wx.StaticText.__init__(self, parent, id, label = '', *args, **kwds)
  1293. self.SetLabel(label)
  1294. self.Bind(wx.EVT_SIZE, self.OnResize)
  1295. def SetLabel(self, label):
  1296. self.originalLabel = label
  1297. self.wrappedSize = None
  1298. self.OnResize(None)
  1299. def OnResize(self, event):
  1300. if not getattr(self, "resizing", False):
  1301. self.resizing = True
  1302. newSize = wx.Size(self.parent.GetSize().width - 50,
  1303. self.GetSize().height)
  1304. if self.wrappedSize != newSize:
  1305. wx.StaticText.SetLabel(self, self.originalLabel)
  1306. self.Wrap(newSize.width)
  1307. self.wrappedSize = newSize
  1308. self.SetSize(self.wrappedSize)
  1309. del self.resizing
  1310. class ImageSizeDialog(wx.Dialog):
  1311. """!Set size for saved graphic file"""
  1312. def __init__(self, parent, id = wx.ID_ANY, title=_("Set image size"),
  1313. style = wx.DEFAULT_DIALOG_STYLE, **kwargs):
  1314. self.parent = parent
  1315. wx.Dialog.__init__(self, parent, id = id, style=style, title=title, **kwargs)
  1316. self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
  1317. self.box = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  1318. label = ' % s' % _("Image size"))
  1319. size = self.parent.GetWindow().GetClientSize()
  1320. self.width = wx.SpinCtrl(parent = self.panel, id = wx.ID_ANY,
  1321. style = wx.SP_ARROW_KEYS)
  1322. self.width.SetRange(20, 1e6)
  1323. self.width.SetValue(size.width)
  1324. wx.CallAfter(self.width.SetFocus)
  1325. self.height = wx.SpinCtrl(parent = self.panel, id = wx.ID_ANY,
  1326. style = wx.SP_ARROW_KEYS)
  1327. self.height.SetRange(20, 1e6)
  1328. self.height.SetValue(size.height)
  1329. self.template = wx.Choice(parent = self.panel, id = wx.ID_ANY,
  1330. size = (125, -1),
  1331. choices = [ "",
  1332. "640x480",
  1333. "800x600",
  1334. "1024x768",
  1335. "1280x960",
  1336. "1600x1200",
  1337. "1920x1440" ])
  1338. self.btnOK = wx.Button(parent = self.panel, id = wx.ID_OK)
  1339. self.btnOK.SetDefault()
  1340. self.btnCancel = wx.Button(parent = self.panel, id = wx.ID_CANCEL)
  1341. self.template.Bind(wx.EVT_CHOICE, self.OnTemplate)
  1342. self._layout()
  1343. self.SetSize(self.GetBestSize())
  1344. def _layout(self):
  1345. """!Do layout"""
  1346. sizer = wx.BoxSizer(wx.VERTICAL)
  1347. # body
  1348. box = wx.StaticBoxSizer(self.box, wx.HORIZONTAL)
  1349. fbox = wx.FlexGridSizer(cols = 2, vgap = 5, hgap = 5)
  1350. fbox.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  1351. label = _("Width:")),
  1352. flag = wx.ALIGN_CENTER_VERTICAL)
  1353. fbox.Add(item = self.width)
  1354. fbox.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  1355. label = _("Height:")),
  1356. flag = wx.ALIGN_CENTER_VERTICAL)
  1357. fbox.Add(item = self.height)
  1358. fbox.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  1359. label = _("Template:")),
  1360. flag = wx.ALIGN_CENTER_VERTICAL)
  1361. fbox.Add(item = self.template)
  1362. box.Add(item = fbox, proportion = 1,
  1363. flag = wx.EXPAND | wx.ALL, border = 5)
  1364. sizer.Add(item = box, proportion = 1,
  1365. flag=wx.EXPAND | wx.ALL, border = 3)
  1366. # buttons
  1367. btnsizer = wx.StdDialogButtonSizer()
  1368. btnsizer.AddButton(self.btnOK)
  1369. btnsizer.AddButton(self.btnCancel)
  1370. btnsizer.Realize()
  1371. sizer.Add(item = btnsizer, proportion = 0,
  1372. flag = wx.EXPAND | wx.ALIGN_RIGHT | wx.ALL, border=5)
  1373. self.panel.SetSizer(sizer)
  1374. sizer.Fit(self.panel)
  1375. self.Layout()
  1376. def GetValues(self):
  1377. """!Get width/height values"""
  1378. return self.width.GetValue(), self.height.GetValue()
  1379. def OnTemplate(self, event):
  1380. """!Template selected"""
  1381. sel = event.GetString()
  1382. if not sel:
  1383. width, height = self.parent.GetWindow().GetClientSize()
  1384. else:
  1385. width, height = map(int, sel.split('x'))
  1386. self.width.SetValue(width)
  1387. self.height.SetValue(height)
  1388. class SqlQueryFrame(wx.Frame):
  1389. def __init__(self, parent, id = wx.ID_ANY,
  1390. title = _("GRASS GIS SQL Query Utility"),
  1391. *kwargs):
  1392. """!SQL Query Utility window
  1393. """
  1394. self.parent = parent
  1395. wx.Frame.__init__(self, parent = parent, id = id, title = title, *kwargs)
  1396. self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass_sql.ico'), wx.BITMAP_TYPE_ICO))
  1397. self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
  1398. self.sqlBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  1399. label = _(" SQL statement "))
  1400. self.sql = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY,
  1401. style = wx.TE_MULTILINE)
  1402. self.btnApply = wx.Button(parent = self.panel, id = wx.ID_APPLY)
  1403. self.btnCancel = wx.Button(parent = self.panel, id = wx.ID_CANCEL)
  1404. self.Bind(wx.EVT_BUTTON, self.OnCloseWindow, self.btnCancel)
  1405. self._layout()
  1406. self.SetMinSize(wx.Size(300, 150))
  1407. self.SetSize(wx.Size(500, 200))
  1408. def _layout(self):
  1409. """!Do layout"""
  1410. sizer = wx.BoxSizer(wx.VERTICAL)
  1411. sqlSizer = wx.StaticBoxSizer(self.sqlBox, wx.HORIZONTAL)
  1412. sqlSizer.Add(item = self.sql, proportion = 1,
  1413. flag = wx.EXPAND)
  1414. btnSizer = wx.StdDialogButtonSizer()
  1415. btnSizer.AddButton(self.btnApply)
  1416. btnSizer.AddButton(self.btnCancel)
  1417. btnSizer.Realize()
  1418. sizer.Add(item = sqlSizer, proportion = 1,
  1419. flag = wx.EXPAND | wx.ALL, border = 5)
  1420. sizer.Add(item = btnSizer, proportion = 0,
  1421. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
  1422. self.panel.SetSizer(sizer)
  1423. self.Layout()
  1424. def OnCloseWindow(self, event):
  1425. """!Close window
  1426. """
  1427. self.Close()