gdialogs.py 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765
  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. box = wx.BoxSizer(wx.HORIZONTAL)
  352. label = wx.StaticText(parent=self, id=wx.ID_ANY,
  353. label=_("Drag %s with mouse in pointer mode to position.\n"
  354. "Double-click to change options." % ctrltxt))
  355. if self.name == 'legend':
  356. label.SetLabel(label.GetLabel() + _('\nDefine raster map name for legend in '
  357. 'properties dialog.'))
  358. box.Add(item=label, proportion=0,
  359. 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. line = wx.StaticLine(parent=self, id=wx.ID_ANY, size=(20,-1), style=wx.LI_HORIZONTAL)
  363. sizer.Add(item=line, proportion=0,
  364. flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
  365. # buttons
  366. btnsizer = wx.StdDialogButtonSizer()
  367. self.btnOK = wx.Button(parent=self, id=wx.ID_OK)
  368. self.btnOK.SetDefault()
  369. if self.name == 'legend':
  370. self.btnOK.Enable(False)
  371. btnsizer.AddButton(self.btnOK)
  372. btnCancel = wx.Button(parent=self, id=wx.ID_CANCEL)
  373. btnsizer.AddButton(btnCancel)
  374. btnsizer.Realize()
  375. sizer.Add(item=btnsizer, proportion=0,
  376. flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
  377. #
  378. # bindings
  379. #
  380. self.Bind(wx.EVT_BUTTON, self.OnOptions, optnbtn)
  381. self.Bind(wx.EVT_BUTTON, self.OnCancel, btnCancel)
  382. self.Bind(wx.EVT_BUTTON, self.OnOK, self.btnOK)
  383. self.SetSizer(sizer)
  384. sizer.Fit(self)
  385. # create overlay if doesn't exist
  386. self._CreateOverlay()
  387. if len(self.parent.MapWindow.overlays[self.ovlId]['cmd']) > 1:
  388. mapName, found = utils.GetLayerNameFromCmd(self.parent.MapWindow.overlays[self.ovlId]['cmd'])
  389. if self.parent.MapWindow.overlays[self.ovlId]['propwin'] is None and mapName:
  390. # build properties dialog
  391. menuform.GUI(parent = self.parent, show = False).ParseCommand(cmd=self.cmd,
  392. completed=(self.GetOptData, self.name, ''))
  393. if found:
  394. # enable 'OK' button
  395. self.btnOK.Enable()
  396. if name == 'legend':
  397. # set title
  398. self.SetTitle(_('Legend of raster map <%s>') % \
  399. mapName)
  400. def _CreateOverlay(self):
  401. if not self.parent.Map.GetOverlay(self.ovlId):
  402. self.newOverlay = self.parent.Map.AddOverlay(id=self.ovlId, type=self.name,
  403. command=self.cmd,
  404. l_active=False, l_render=False, l_hidden=True)
  405. prop = { 'layer' : self.newOverlay,
  406. 'params' : None,
  407. 'propwin' : None,
  408. 'cmd' : self.cmd,
  409. 'coords': (10, 10),
  410. 'pdcType': 'image' }
  411. self.parent.MapWindow2D.overlays[self.ovlId] = prop
  412. if self.parent.MapWindow3D:
  413. self.parent.MapWindow3D.overlays[self.ovlId] = prop
  414. else:
  415. if self.parent.MapWindow.overlays[self.ovlId]['propwin'] == None:
  416. return
  417. self.parent.MapWindow.overlays[self.ovlId]['propwin'].get_dcmd = self.GetOptData
  418. def OnOptions(self, event):
  419. """ self.SetSizer(sizer)
  420. sizer.Fit(self)
  421. Sets option for decoration map overlays
  422. """
  423. if self.parent.MapWindow.overlays[self.ovlId]['propwin'] is None:
  424. # build properties dialog
  425. menuform.GUI(parent = self.parent).ParseCommand(cmd=self.cmd,
  426. completed=(self.GetOptData, self.name, ''))
  427. else:
  428. if self.parent.MapWindow.overlays[self.ovlId]['propwin'].IsShown():
  429. self.parent.MapWindow.overlays[self.ovlId]['propwin'].SetFocus()
  430. else:
  431. self.parent.MapWindow.overlays[self.ovlId]['propwin'].Show()
  432. def OnCancel(self, event):
  433. """!Cancel dialog"""
  434. self.parent.dialogs['barscale'] = None
  435. self.parent.Map.DeleteOverlay(self.newOverlay)
  436. self.Destroy()
  437. def OnOK(self, event):
  438. """!Button 'OK' pressed"""
  439. # enable or disable overlay
  440. self.parent.Map.GetOverlay(self.ovlId).SetActive(self.chkbox.IsChecked())
  441. # update map
  442. if self.parent.MapWindow.parent.toolbars['nviz']:
  443. self.parent.MapWindow.UpdateOverlays()
  444. self.parent.MapWindow.UpdateMap()
  445. # close dialog
  446. self.OnCancel(None)
  447. def GetOptData(self, dcmd, layer, params, propwin):
  448. """!Process decoration layer data"""
  449. # update layer data
  450. if params:
  451. self.parent.MapWindow.overlays[self.ovlId]['params'] = params
  452. if dcmd:
  453. self.parent.MapWindow.overlays[self.ovlId]['cmd'] = dcmd
  454. self.parent.MapWindow.overlays[self.ovlId]['propwin'] = propwin
  455. # change parameters for item in layers list in render.Map
  456. # "Use mouse..." (-m) flag causes GUI freeze and is pointless here, trac #119
  457. try:
  458. self.parent.MapWindow.overlays[self.ovlId]['cmd'].remove('-m')
  459. except ValueError:
  460. pass
  461. self.parent.Map.ChangeOverlay(id=self.ovlId, type=self.name,
  462. command=self.parent.MapWindow.overlays[self.ovlId]['cmd'],
  463. l_active=self.parent.MapWindow.overlays[self.ovlId]['layer'].IsActive(),
  464. l_render=False, l_hidden=True)
  465. if self.name == 'legend':
  466. if params and not self.btnOK.IsEnabled():
  467. self.btnOK.Enable()
  468. class TextLayerDialog(wx.Dialog):
  469. """
  470. Controls setting options and displaying/hiding map overlay decorations
  471. """
  472. def __init__(self, parent, ovlId, title, name='text',
  473. pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE):
  474. wx.Dialog.__init__(self, parent, wx.ID_ANY, title, pos, size, style)
  475. from wx.lib.expando import ExpandoTextCtrl, EVT_ETC_LAYOUT_NEEDED
  476. self.ovlId = ovlId
  477. self.parent = parent
  478. if self.ovlId in self.parent.MapWindow.textdict.keys():
  479. self.currText = self.parent.MapWindow.textdict[self.ovlId]['text']
  480. self.currFont = self.parent.MapWindow.textdict[self.ovlId]['font']
  481. self.currClr = self.parent.MapWindow.textdict[self.ovlId]['color']
  482. self.currRot = self.parent.MapWindow.textdict[self.ovlId]['rotation']
  483. self.currCoords = self.parent.MapWindow.textdict[self.ovlId]['coords']
  484. self.currBB = self.parent.MapWindow.textdict[self.ovlId]['bbox']
  485. else:
  486. self.currClr = wx.BLACK
  487. self.currText = ''
  488. self.currFont = self.GetFont()
  489. self.currRot = 0.0
  490. self.currCoords = [10, 10]
  491. self.currBB = wx.Rect()
  492. self.sizer = wx.BoxSizer(wx.VERTICAL)
  493. box = wx.GridBagSizer(vgap=5, hgap=5)
  494. # show/hide
  495. self.chkbox = wx.CheckBox(parent=self, id=wx.ID_ANY, \
  496. label='Show text object')
  497. if self.parent.Map.GetOverlay(self.ovlId) is None:
  498. self.chkbox.SetValue(True)
  499. else:
  500. self.chkbox.SetValue(self.parent.MapWindow.overlays[self.ovlId]['layer'].IsActive())
  501. box.Add(item=self.chkbox, span=(1,2),
  502. flag=wx.ALIGN_LEFT|wx.ALL, border=5,
  503. pos=(0, 0))
  504. # text entry
  505. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Enter text:"))
  506. box.Add(item=label,
  507. flag=wx.ALIGN_CENTER_VERTICAL,
  508. pos=(1, 0))
  509. self.textentry = ExpandoTextCtrl(parent=self, id=wx.ID_ANY, value="", size=(300,-1))
  510. self.textentry.SetFont(self.currFont)
  511. self.textentry.SetForegroundColour(self.currClr)
  512. self.textentry.SetValue(self.currText)
  513. # get rid of unneeded scrollbar when text box first opened
  514. self.textentry.SetClientSize((300,-1))
  515. box.Add(item=self.textentry,
  516. pos=(1, 1))
  517. # rotation
  518. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Rotation:"))
  519. box.Add(item=label,
  520. flag=wx.ALIGN_CENTER_VERTICAL,
  521. pos=(2, 0))
  522. self.rotation = wx.SpinCtrl(parent=self, id=wx.ID_ANY, value="", pos=(30, 50),
  523. size=(75,-1), style=wx.SP_ARROW_KEYS)
  524. self.rotation.SetRange(-360, 360)
  525. self.rotation.SetValue(int(self.currRot))
  526. box.Add(item=self.rotation,
  527. flag=wx.ALIGN_RIGHT,
  528. pos=(2, 1))
  529. # font
  530. fontbtn = wx.Button(parent=self, id=wx.ID_ANY, label=_("Set font"))
  531. box.Add(item=fontbtn,
  532. flag=wx.ALIGN_RIGHT,
  533. pos=(3, 1))
  534. self.sizer.Add(item=box, proportion=1,
  535. flag=wx.ALL, border=10)
  536. # note
  537. box = wx.BoxSizer(wx.HORIZONTAL)
  538. label = wx.StaticText(parent=self, id=wx.ID_ANY,
  539. label=_("Drag text with mouse in pointer mode "
  540. "to position.\nDouble-click to change options"))
  541. box.Add(item=label, proportion=0,
  542. flag=wx.ALIGN_CENTRE | wx.ALL, border=5)
  543. self.sizer.Add(item=box, proportion=0,
  544. flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER | wx.ALL, border=5)
  545. line = wx.StaticLine(parent=self, id=wx.ID_ANY,
  546. size=(20,-1), style=wx.LI_HORIZONTAL)
  547. self.sizer.Add(item=line, proportion=0,
  548. flag=wx.EXPAND | wx.ALIGN_CENTRE | wx.ALL, border=5)
  549. btnsizer = wx.StdDialogButtonSizer()
  550. btn = wx.Button(parent=self, id=wx.ID_OK)
  551. btn.SetDefault()
  552. btnsizer.AddButton(btn)
  553. btn = wx.Button(parent=self, id=wx.ID_CANCEL)
  554. btnsizer.AddButton(btn)
  555. btnsizer.Realize()
  556. self.sizer.Add(item=btnsizer, proportion=0,
  557. flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
  558. self.SetSizer(self.sizer)
  559. self.sizer.Fit(self)
  560. # bindings
  561. self.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnRefit, self.textentry)
  562. self.Bind(wx.EVT_BUTTON, self.OnSelectFont, fontbtn)
  563. self.Bind(wx.EVT_TEXT, self.OnText, self.textentry)
  564. self.Bind(wx.EVT_SPINCTRL, self.OnRotation, self.rotation)
  565. def OnRefit(self, event):
  566. """!Resize text entry to match text"""
  567. self.sizer.Fit(self)
  568. def OnText(self, event):
  569. """!Change text string"""
  570. self.currText = event.GetString()
  571. def OnRotation(self, event):
  572. """!Change rotation"""
  573. self.currRot = event.GetInt()
  574. event.Skip()
  575. def OnSelectFont(self, event):
  576. """!Change font"""
  577. data = wx.FontData()
  578. data.EnableEffects(True)
  579. data.SetColour(self.currClr) # set colour
  580. data.SetInitialFont(self.currFont)
  581. dlg = wx.FontDialog(self, data)
  582. if dlg.ShowModal() == wx.ID_OK:
  583. data = dlg.GetFontData()
  584. self.currFont = data.GetChosenFont()
  585. self.currClr = data.GetColour()
  586. self.textentry.SetFont(self.currFont)
  587. self.textentry.SetForegroundColour(self.currClr)
  588. self.Layout()
  589. dlg.Destroy()
  590. def GetValues(self):
  591. """!Get text properties"""
  592. return { 'text' : self.currText,
  593. 'font' : self.currFont,
  594. 'color' : self.currClr,
  595. 'rotation' : self.currRot,
  596. 'coords' : self.currCoords,
  597. 'active' : self.chkbox.IsChecked() }
  598. class AddMapLayersDialog(wx.Dialog):
  599. """!Add selected map layers (raster, vector) into layer tree"""
  600. def __init__(self, parent, title, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
  601. wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY, title=title, style=style)
  602. self.parent = parent # GMFrame
  603. #
  604. # dialog body
  605. #
  606. self.bodySizer = self.__createDialogBody()
  607. # update list of layer to be loaded
  608. self.map_layers = [] # list of map layers (full list type/mapset)
  609. self.LoadMapLayers(self.layerType.GetStringSelection()[:4],
  610. self.mapset.GetStringSelection())
  611. #
  612. # buttons
  613. #
  614. btnCancel = wx.Button(parent = self, id = wx.ID_CANCEL)
  615. btnOk = wx.Button(parent = self, id = wx.ID_OK, label = _("&Add"))
  616. btnOk.SetDefault()
  617. btnOk.SetToolTipString(_("Add selected map layers to current display"))
  618. #
  619. # sizers & do layout
  620. #
  621. btnSizer = wx.StdDialogButtonSizer()
  622. btnSizer.AddButton(btnCancel)
  623. btnSizer.AddButton(btnOk)
  624. btnSizer.Realize()
  625. mainSizer = wx.BoxSizer(wx.VERTICAL)
  626. mainSizer.Add(item=self.bodySizer, proportion=1,
  627. flag=wx.EXPAND | wx.ALL, border=5)
  628. mainSizer.Add(item=btnSizer, proportion=0,
  629. flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
  630. self.SetSizer(mainSizer)
  631. mainSizer.Fit(self)
  632. # set dialog min size
  633. self.SetMinSize(self.GetSize())
  634. def __createDialogBody(self):
  635. bodySizer = wx.GridBagSizer(vgap=3, hgap=3)
  636. bodySizer.AddGrowableCol(1)
  637. bodySizer.AddGrowableRow(3)
  638. # layer type
  639. bodySizer.Add(item=wx.StaticText(parent=self, label=_("Map layer type:")),
  640. flag=wx.ALIGN_CENTER_VERTICAL,
  641. pos=(0,0))
  642. self.layerType = wx.Choice(parent=self, id=wx.ID_ANY,
  643. choices=['raster', 'vector'], size=(100,-1))
  644. self.layerType.SetSelection(0)
  645. bodySizer.Add(item=self.layerType,
  646. pos=(0,1))
  647. # select toggle
  648. self.toggle = wx.CheckBox(parent=self, id=wx.ID_ANY,
  649. label=_("Select toggle"))
  650. self.toggle.SetValue(True)
  651. bodySizer.Add(item=self.toggle,
  652. flag=wx.ALIGN_CENTER_VERTICAL,
  653. pos=(0,2))
  654. # mapset filter
  655. bodySizer.Add(item=wx.StaticText(parent=self, label=_("Mapset:")),
  656. flag=wx.ALIGN_CENTER_VERTICAL,
  657. pos=(1,0))
  658. self.mapset = gselect.MapsetSelect(parent = self)
  659. self.mapset.SetStringSelection(grass.gisenv()['MAPSET'])
  660. bodySizer.Add(item=self.mapset,
  661. pos=(1,1), span=(1, 2))
  662. # map name filter
  663. bodySizer.Add(item=wx.StaticText(parent=self, label=_("Filter:")),
  664. flag=wx.ALIGN_CENTER_VERTICAL,
  665. pos=(2,0))
  666. self.filter = wx.TextCtrl(parent=self, id=wx.ID_ANY,
  667. value="",
  668. size=(250,-1))
  669. bodySizer.Add(item=self.filter,
  670. flag=wx.EXPAND,
  671. pos=(2,1), span=(1, 2))
  672. # layer list
  673. bodySizer.Add(item=wx.StaticText(parent=self, label=_("List of maps:")),
  674. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_TOP,
  675. pos=(3,0))
  676. self.layers = wx.CheckListBox(parent=self, id=wx.ID_ANY,
  677. size=(250, 100),
  678. choices=[])
  679. bodySizer.Add(item=self.layers,
  680. flag=wx.EXPAND,
  681. pos=(3,1), span=(1, 2))
  682. # bindings
  683. self.layerType.Bind(wx.EVT_CHOICE, self.OnChangeParams)
  684. self.mapset.Bind(wx.EVT_COMBOBOX, self.OnChangeParams)
  685. self.layers.Bind(wx.EVT_RIGHT_DOWN, self.OnMenu)
  686. self.filter.Bind(wx.EVT_TEXT, self.OnFilter)
  687. self.toggle.Bind(wx.EVT_CHECKBOX, self.OnToggle)
  688. return bodySizer
  689. def LoadMapLayers(self, type, mapset):
  690. """!Load list of map layers
  691. @param type layer type ('raster' or 'vector')
  692. @param mapset mapset name
  693. """
  694. self.map_layers = grass.mlist(type = type, mapset = mapset)
  695. self.layers.Set(self.map_layers)
  696. # check all items by default
  697. for item in range(self.layers.GetCount()):
  698. self.layers.Check(item)
  699. def OnChangeParams(self, event):
  700. """!Filter parameters changed by user"""
  701. # update list of layer to be loaded
  702. self.LoadMapLayers(self.layerType.GetStringSelection()[:4],
  703. self.mapset.GetStringSelection())
  704. event.Skip()
  705. def OnMenu(self, event):
  706. """!Table description area, context menu"""
  707. if not hasattr(self, "popupID1"):
  708. self.popupDataID1 = wx.NewId()
  709. self.popupDataID2 = wx.NewId()
  710. self.popupDataID3 = wx.NewId()
  711. self.Bind(wx.EVT_MENU, self.OnSelectAll, id=self.popupDataID1)
  712. self.Bind(wx.EVT_MENU, self.OnSelectInvert, id=self.popupDataID2)
  713. self.Bind(wx.EVT_MENU, self.OnDeselectAll, id=self.popupDataID3)
  714. # generate popup-menu
  715. menu = wx.Menu()
  716. menu.Append(self.popupDataID1, _("Select all"))
  717. menu.Append(self.popupDataID2, _("Invert selection"))
  718. menu.Append(self.popupDataID3, _("Deselect all"))
  719. self.PopupMenu(menu)
  720. menu.Destroy()
  721. def OnSelectAll(self, event):
  722. """!Select all map layer from list"""
  723. for item in range(self.layers.GetCount()):
  724. self.layers.Check(item, True)
  725. def OnSelectInvert(self, event):
  726. """!Invert current selection"""
  727. for item in range(self.layers.GetCount()):
  728. if self.layers.IsChecked(item):
  729. self.layers.Check(item, False)
  730. else:
  731. self.layers.Check(item, True)
  732. def OnDeselectAll(self, event):
  733. """!Select all map layer from list"""
  734. for item in range(self.layers.GetCount()):
  735. self.layers.Check(item, False)
  736. def OnFilter(self, event):
  737. """!Apply filter for map names"""
  738. if len(event.GetString()) == 0:
  739. self.layers.Set(self.map_layers)
  740. return
  741. list = []
  742. for layer in self.map_layers:
  743. try:
  744. if re.compile('^' + event.GetString()).search(layer):
  745. list.append(layer)
  746. except:
  747. pass
  748. self.layers.Set(list)
  749. self.OnSelectAll(None)
  750. event.Skip()
  751. def OnToggle(self, event):
  752. """!Select toggle (check or uncheck all layers)"""
  753. check = event.Checked()
  754. for item in range(self.layers.GetCount()):
  755. self.layers.Check(item, check)
  756. event.Skip()
  757. def GetMapLayers(self):
  758. """!Return list of checked map layers"""
  759. layerNames = []
  760. for indx in self.layers.GetSelections():
  761. # layers.append(self.layers.GetStringSelec(indx))
  762. pass
  763. # return fully qualified map names
  764. mapset = self.mapset.GetStringSelection()
  765. for item in range(self.layers.GetCount()):
  766. if not self.layers.IsChecked(item):
  767. continue
  768. layerNames.append(self.layers.GetString(item) + '@' + mapset)
  769. return layerNames
  770. def GetLayerType(self):
  771. """!Get selected layer type"""
  772. return self.layerType.GetStringSelection()
  773. class ImportDialog(wx.Dialog):
  774. """!Dialog for bulk import of various data (base class)"""
  775. def __init__(self, parent, itype,
  776. id = wx.ID_ANY, title = _("Multiple import"),
  777. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
  778. self.parent = parent # GMFrame
  779. self.importType = itype
  780. self.options = dict() # list of options
  781. self.commandId = -1 # id of running command
  782. wx.Dialog.__init__(self, parent, id, title, style=style,
  783. name = "MultiImportDialog")
  784. self.panel = wx.Panel(parent=self, id=wx.ID_ANY)
  785. self.layerBox = wx.StaticBox(parent=self.panel, id=wx.ID_ANY,
  786. label=_(" List of %s layers ") % self.importType.upper())
  787. #
  788. # list of layers
  789. #
  790. self.list = LayersList(self.panel)
  791. self.list.LoadData()
  792. self.optionBox = wx.StaticBox(parent=self.panel, id=wx.ID_ANY,
  793. label="%s" % _("Options"))
  794. cmd = self._getCommand()
  795. task = gtask.parse_interface(cmd)
  796. for f in task.get_options()['flags']:
  797. name = f.get('name', '')
  798. desc = f.get('label', '')
  799. if not desc:
  800. desc = f.get('description', '')
  801. if not name and not desc:
  802. continue
  803. if cmd == 'r.in.gdal' and name not in ('o', 'e', 'l', 'k'):
  804. continue
  805. elif cmd == 'r.external' and name not in ('o', 'e', 'r', 'h', 'v'):
  806. continue
  807. elif cmd == 'v.in.ogr' and name not in ('c', 'z', 't', 'o', 'r', 'e', 'w'):
  808. continue
  809. elif cmd == 'v.external' and name not in ('b'):
  810. continue
  811. elif cmd == 'v.in.dxf' and name not in ('e', 't', 'b', 'f', 'i'):
  812. continue
  813. self.options[name] = wx.CheckBox(parent = self.panel, id = wx.ID_ANY,
  814. label = desc)
  815. self.overwrite = wx.CheckBox(parent=self.panel, id=wx.ID_ANY,
  816. label=_("Allow output files to overwrite existing files"))
  817. self.overwrite.SetValue(UserSettings.Get(group='cmd', key='overwrite', subkey='enabled'))
  818. self.add = wx.CheckBox(parent=self.panel, id=wx.ID_ANY)
  819. #
  820. # buttons
  821. #
  822. # cancel
  823. self.btn_cancel = wx.Button(parent=self.panel, id=wx.ID_CANCEL)
  824. self.btn_cancel.SetToolTipString(_("Close dialog"))
  825. self.btn_cancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  826. # run
  827. self.btn_run = wx.Button(parent=self.panel, id=wx.ID_OK, label = _("&Import"))
  828. self.btn_run.SetToolTipString(_("Import selected layers"))
  829. self.btn_run.SetDefault()
  830. self.btn_run.Enable(False)
  831. self.btn_run.Bind(wx.EVT_BUTTON, self.OnRun)
  832. # run command dialog
  833. self.btn_cmd = wx.Button(parent = self.panel, id = wx.ID_ANY,
  834. label = _("Command dialog"))
  835. self.btn_cmd.Bind(wx.EVT_BUTTON, self.OnCmdDialog)
  836. def doLayout(self):
  837. """!Do layout"""
  838. dialogSizer = wx.BoxSizer(wx.VERTICAL)
  839. # dsn input
  840. dialogSizer.Add(item = self.dsnInput, proportion = 0,
  841. flag = wx.EXPAND)
  842. #
  843. # list of DXF layers
  844. #
  845. layerSizer = wx.StaticBoxSizer(self.layerBox, wx.HORIZONTAL)
  846. layerSizer.Add(item=self.list, proportion=1,
  847. flag=wx.ALL | wx.EXPAND, border=5)
  848. dialogSizer.Add(item=layerSizer, proportion=1,
  849. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=5)
  850. # options
  851. optionSizer = wx.StaticBoxSizer(self.optionBox, wx.VERTICAL)
  852. for key in self.options.keys():
  853. optionSizer.Add(item=self.options[key], proportion=0)
  854. dialogSizer.Add(item=optionSizer, proportion=0,
  855. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=5)
  856. dialogSizer.Add(item=self.overwrite, proportion=0,
  857. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM, border=5)
  858. dialogSizer.Add(item=self.add, proportion=0,
  859. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM, border=5)
  860. #
  861. # buttons
  862. #
  863. btnsizer = wx.BoxSizer(orient=wx.HORIZONTAL)
  864. btnsizer.Add(item=self.btn_cmd, proportion=0,
  865. flag=wx.ALL | wx.ALIGN_CENTER,
  866. border=10)
  867. btnsizer.Add(item=self.btn_run, proportion=0,
  868. flag=wx.ALL | wx.ALIGN_CENTER,
  869. border=10)
  870. btnsizer.Add(item=self.btn_cancel, proportion=0,
  871. flag=wx.ALL | wx.ALIGN_CENTER,
  872. border=10)
  873. dialogSizer.Add(item=btnsizer, proportion=0,
  874. flag=wx.ALIGN_CENTER)
  875. # dialogSizer.SetSizeHints(self.panel)
  876. self.panel.SetAutoLayout(True)
  877. self.panel.SetSizer(dialogSizer)
  878. dialogSizer.Fit(self.panel)
  879. # auto-layout seems not work here - FIXME
  880. size = wx.Size(globalvar.DIALOG_GSELECT_SIZE[0] + 225, 550)
  881. self.SetMinSize(size)
  882. self.SetSize((size.width, size.height + 100))
  883. width = self.GetSize()[0]
  884. self.list.SetColumnWidth(col=1, width=width/2 - 50)
  885. self.Layout()
  886. def _getCommand(self):
  887. """!Get command"""
  888. return ''
  889. def OnCancel(self, event=None):
  890. """!Close dialog"""
  891. self.Close()
  892. def OnRun(self, event):
  893. """!Import/Link data (each layes as separate vector map)"""
  894. pass
  895. def OnCmdDialog(self, event):
  896. """!Show command dialog"""
  897. pass
  898. def AddLayers(self, returncode, cmd = None):
  899. """!Add imported/linked layers into layer tree"""
  900. self.commandId += 1
  901. if not self.add.IsChecked() or returncode != 0:
  902. return
  903. maptree = self.parent.curr_page.maptree
  904. layer, output = self.list.GetLayers()[self.commandId]
  905. if '@' not in output:
  906. name = output + '@' + grass.gisenv()['MAPSET']
  907. else:
  908. name = output
  909. # add imported layers into layer tree
  910. if self.importType == 'gdal':
  911. cmd = ['d.rast',
  912. 'map=%s' % name]
  913. if UserSettings.Get(group='cmd', key='rasterOverlay', subkey='enabled'):
  914. cmd.append('-o')
  915. item = maptree.AddLayer(ltype='raster',
  916. lname=name,
  917. lcmd=cmd)
  918. else:
  919. item = maptree.AddLayer(ltype='vector',
  920. lname=name,
  921. lcmd=['d.vect',
  922. 'map=%s' % name])
  923. maptree.mapdisplay.MapWindow.ZoomToMap()
  924. def OnAbort(self, event):
  925. """!Abort running import
  926. @todo not yet implemented
  927. """
  928. pass
  929. class GdalImportDialog(ImportDialog):
  930. """!Dialog for bulk import of various raster/vector data"""
  931. def __init__(self, parent, ogr = False, link = False):
  932. self.link = link
  933. self.ogr = ogr
  934. if ogr:
  935. ImportDialog.__init__(self, parent, itype = 'ogr')
  936. if link:
  937. self.SetTitle(_("Link external vector data"))
  938. else:
  939. self.SetTitle(_("Import vector data"))
  940. else:
  941. ImportDialog.__init__(self, parent, itype = 'gdal')
  942. if link:
  943. self.SetTitle(_("Link external raster data"))
  944. else:
  945. self.SetTitle(_("Import raster data"))
  946. self.dsnInput = gselect.GdalSelect(parent = self, panel = self.panel, ogr = ogr)
  947. if link:
  948. self.add.SetLabel(_("Add linked layers into layer tree"))
  949. else:
  950. self.add.SetLabel(_("Add imported layers into layer tree"))
  951. self.add.SetValue(UserSettings.Get(group='cmd', key='addNewLayer', subkey='enabled'))
  952. if link:
  953. self.btn_run.SetLabel(_("&Link"))
  954. self.btn_run.SetToolTipString(_("Link selected layers"))
  955. if ogr:
  956. self.btn_cmd.SetToolTipString(_('Open %s dialog') % 'v.external')
  957. else:
  958. self.btn_cmd.SetToolTipString(_('Open %s dialog') % 'r.external')
  959. else:
  960. self.btn_run.SetLabel(_("&Import"))
  961. self.btn_run.SetToolTipString(_("Import selected layers"))
  962. if ogr:
  963. self.btn_cmd.SetToolTipString(_('Open %s dialog') % 'v.in.ogr')
  964. else:
  965. self.btn_cmd.SetToolTipString(_('Open %s dialog') % 'r.in.gdal')
  966. self.doLayout()
  967. def OnRun(self, event):
  968. """!Import/Link data (each layes as separate vector map)"""
  969. data = self.list.GetLayers()
  970. # hide dialog
  971. self.Hide()
  972. dsn = self.dsnInput.GetDsn()
  973. ext = self.dsnInput.GetFormatExt()
  974. for layer, output in data:
  975. if self.importType == 'ogr':
  976. if ext and layer.rfind(ext) > -1:
  977. layer = layer.replace('.' + ext, '')
  978. if self.link:
  979. cmd = ['v.external',
  980. 'dsn=%s' % dsn,
  981. 'output=%s' % output,
  982. 'layer=%s' % layer]
  983. else:
  984. cmd = ['v.in.ogr',
  985. 'dsn=%s' % dsn,
  986. 'layer=%s' % layer,
  987. 'output=%s' % output]
  988. else: # gdal
  989. if self.dsnInput.GetType() == 'dir':
  990. idsn = os.path.join(dsn, layer)
  991. else:
  992. idsn = dsn
  993. if self.link:
  994. cmd = ['r.external',
  995. 'input=%s' % idsn,
  996. 'output=%s' % output]
  997. else:
  998. cmd = ['r.in.gdal',
  999. 'input=%s' % idsn,
  1000. 'output=%s' % output]
  1001. if self.overwrite.IsChecked():
  1002. cmd.append('--overwrite')
  1003. for key in self.options.keys():
  1004. if self.options[key].IsChecked():
  1005. cmd.append('-%s' % key)
  1006. if UserSettings.Get(group='cmd', key='overwrite', subkey='enabled'):
  1007. cmd.append('--overwrite')
  1008. # run in Layer Manager
  1009. self.parent.goutput.RunCmd(cmd, switchPage = True,
  1010. onDone = self.AddLayers)
  1011. self.OnCancel()
  1012. def _getCommand(self):
  1013. """!Get command"""
  1014. if self.link:
  1015. if self.ogr:
  1016. return 'v.external'
  1017. else:
  1018. return 'r.external'
  1019. else:
  1020. if self.ogr:
  1021. return 'v.in.ogr'
  1022. else:
  1023. return 'r.in.gdal'
  1024. return ''
  1025. def OnCmdDialog(self, event):
  1026. """!Show command dialog"""
  1027. name = self._getCommand()
  1028. menuform.GUI(parent = self, modal = True).ParseCommand(cmd = [name])
  1029. class DxfImportDialog(ImportDialog):
  1030. """!Dialog for bulk import of DXF layers"""
  1031. def __init__(self, parent):
  1032. ImportDialog.__init__(self, parent, itype = 'dxf',
  1033. title = _("Import DXF layers"))
  1034. self.dsnInput = filebrowse.FileBrowseButton(parent=self.panel, id=wx.ID_ANY,
  1035. size=globalvar.DIALOG_GSELECT_SIZE, labelText='',
  1036. dialogTitle=_('Choose DXF file to import'),
  1037. buttonText=_('Browse'),
  1038. startDirectory=os.getcwd(), fileMode=0,
  1039. changeCallback=self.OnSetDsn,
  1040. fileMask="DXF File (*.dxf)|*.dxf")
  1041. self.add.SetLabel(_("Add imported layers into layer tree"))
  1042. self.add.SetValue(UserSettings.Get(group='cmd', key='addNewLayer', subkey='enabled'))
  1043. self.doLayout()
  1044. def _getCommand(self):
  1045. """!Get command"""
  1046. return 'v.in.dxf'
  1047. def OnRun(self, event):
  1048. """!Import/Link data (each layes as separate vector map)"""
  1049. data = self.list.GetLayers()
  1050. # hide dialog
  1051. self.Hide()
  1052. inputDxf = self.dsnInput.GetValue()
  1053. for layer, output in data:
  1054. cmd = ['v.in.dxf',
  1055. 'input=%s' % inputDxf,
  1056. 'layers=%s' % layer,
  1057. 'output=%s' % output]
  1058. for key in self.options.keys():
  1059. if self.options[key].IsChecked():
  1060. cmd.append('-%s' % key)
  1061. if self.overwrite.IsChecked() or \
  1062. UserSettings.Get(group='cmd', key='overwrite', subkey='enabled'):
  1063. cmd.append('--overwrite')
  1064. # run in Layer Manager
  1065. self.parent.goutput.RunCmd(cmd, switchPage=True,
  1066. onDone = self.AddLayers)
  1067. self.OnCancel()
  1068. def OnSetDsn(self, event):
  1069. """!Input DXF file defined, update list of layer widget"""
  1070. path = event.GetString()
  1071. if not path:
  1072. return
  1073. data = list()
  1074. ret = gcmd.RunCommand('v.in.dxf',
  1075. quiet = True,
  1076. parent = self,
  1077. read = True,
  1078. flags = 'l',
  1079. input = path)
  1080. if not ret:
  1081. self.list.LoadData()
  1082. self.btn_run.Enable(False)
  1083. return
  1084. for line in ret.splitlines():
  1085. layerId = line.split(':')[0].split(' ')[1]
  1086. layerName = line.split(':')[1].strip()
  1087. grassName = utils.GetValidLayerName(layerName)
  1088. data.append((layerId, layerName.strip(), grassName.strip()))
  1089. self.list.LoadData(data)
  1090. if len(data) > 0:
  1091. self.btn_run.Enable(True)
  1092. else:
  1093. self.btn_run.Enable(False)
  1094. def OnCmdDialog(self, event):
  1095. """!Show command dialog"""
  1096. menuform.GUI(parent = self, modal = True).ParseCommand(cmd = ['v.in.dxf'])
  1097. class LayersList(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin,
  1098. listmix.CheckListCtrlMixin, listmix.TextEditMixin):
  1099. """!List of layers to be imported (dxf, shp...)"""
  1100. def __init__(self, parent, pos = wx.DefaultPosition,
  1101. log = None):
  1102. self.parent = parent
  1103. wx.ListCtrl.__init__(self, parent, wx.ID_ANY,
  1104. style=wx.LC_REPORT)
  1105. listmix.CheckListCtrlMixin.__init__(self)
  1106. self.log = log
  1107. # setup mixins
  1108. listmix.ListCtrlAutoWidthMixin.__init__(self)
  1109. listmix.TextEditMixin.__init__(self)
  1110. self.InsertColumn(0, _('Layer'))
  1111. self.InsertColumn(1, _('Layer name'))
  1112. self.InsertColumn(2, _('Name for GRASS map'))
  1113. self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnPopupMenu) #wxMSW
  1114. self.Bind(wx.EVT_RIGHT_UP, self.OnPopupMenu) #wxGTK
  1115. def LoadData(self, data=None):
  1116. """!Load data into list"""
  1117. if data is None:
  1118. return
  1119. self.DeleteAllItems()
  1120. for id, name, grassName in data:
  1121. index = self.InsertStringItem(sys.maxint, str(id))
  1122. self.SetStringItem(index, 1, "%s" % str(name))
  1123. self.SetStringItem(index, 2, "%s" % str(grassName))
  1124. # check by default
  1125. self.CheckItem(index, True)
  1126. self.SetColumnWidth(col=0, width=wx.LIST_AUTOSIZE_USEHEADER)
  1127. def OnPopupMenu(self, event):
  1128. """!Show popup menu"""
  1129. if self.GetItemCount() < 1:
  1130. return
  1131. if not hasattr(self, "popupDataID1"):
  1132. self.popupDataID1 = wx.NewId()
  1133. self.popupDataID2 = wx.NewId()
  1134. self.Bind(wx.EVT_MENU, self.OnSelectAll, id=self.popupDataID1)
  1135. self.Bind(wx.EVT_MENU, self.OnSelectNone, id=self.popupDataID2)
  1136. # generate popup-menu
  1137. menu = wx.Menu()
  1138. menu.Append(self.popupDataID1, _("Select all"))
  1139. menu.Append(self.popupDataID2, _("Deselect all"))
  1140. self.PopupMenu(menu)
  1141. menu.Destroy()
  1142. def OnSelectAll(self, event):
  1143. """!Select all items"""
  1144. item = -1
  1145. while True:
  1146. item = self.GetNextItem(item)
  1147. if item == -1:
  1148. break
  1149. self.CheckItem(item, True)
  1150. event.Skip()
  1151. def OnSelectNone(self, event):
  1152. """!Deselect items"""
  1153. item = -1
  1154. while True:
  1155. item = self.GetNextItem(item, wx.LIST_STATE_SELECTED)
  1156. if item == -1:
  1157. break
  1158. self.CheckItem(item, False)
  1159. event.Skip()
  1160. def GetLayers(self):
  1161. """!Get list of layers (layer name, output name)"""
  1162. data = []
  1163. item = -1
  1164. while True:
  1165. item = self.GetNextItem(item)
  1166. if item == -1:
  1167. break
  1168. if self.IsChecked(item):
  1169. # layer / output name
  1170. data.append((self.GetItem(item, 1).GetText(),
  1171. self.GetItem(item, 2).GetText()))
  1172. return data
  1173. class SetOpacityDialog(wx.Dialog):
  1174. """!Set opacity of map layers"""
  1175. def __init__(self, parent, id=wx.ID_ANY, title=_("Set Map Layer Opacity"),
  1176. size=wx.DefaultSize, pos=wx.DefaultPosition,
  1177. style=wx.DEFAULT_DIALOG_STYLE, opacity=100):
  1178. self.parent = parent # GMFrame
  1179. self.opacity = opacity # current opacity
  1180. super(SetOpacityDialog, self).__init__(parent, id=id, pos=pos,
  1181. size=size, style=style, title=title)
  1182. panel = wx.Panel(parent=self, id=wx.ID_ANY)
  1183. sizer = wx.BoxSizer(wx.VERTICAL)
  1184. box = wx.GridBagSizer(vgap=5, hgap=5)
  1185. self.value = wx.Slider(panel, id=wx.ID_ANY, value=self.opacity,
  1186. style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | \
  1187. wx.SL_TOP | wx.SL_LABELS,
  1188. minValue=0, maxValue=100,
  1189. size=(350, -1))
  1190. box.Add(item=self.value,
  1191. flag=wx.ALIGN_CENTRE, pos=(0, 0), span=(1, 2))
  1192. box.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  1193. label=_("transparent")),
  1194. pos=(1, 0))
  1195. box.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  1196. label=_("opaque")),
  1197. flag=wx.ALIGN_RIGHT,
  1198. pos=(1, 1))
  1199. sizer.Add(item=box, proportion=0,
  1200. flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
  1201. line = wx.StaticLine(parent=panel, id=wx.ID_ANY,
  1202. style=wx.LI_HORIZONTAL)
  1203. sizer.Add(item=line, proportion=0,
  1204. flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
  1205. # buttons
  1206. btnsizer = wx.StdDialogButtonSizer()
  1207. btnOK = wx.Button(parent=panel, id=wx.ID_OK)
  1208. btnOK.SetDefault()
  1209. btnsizer.AddButton(btnOK)
  1210. btnCancel = wx.Button(parent=panel, id=wx.ID_CANCEL)
  1211. btnsizer.AddButton(btnCancel)
  1212. btnsizer.Realize()
  1213. sizer.Add(item=btnsizer, proportion=0,
  1214. flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
  1215. panel.SetSizer(sizer)
  1216. sizer.Fit(panel)
  1217. self.SetSize(self.GetBestSize())
  1218. self.Layout()
  1219. def GetOpacity(self):
  1220. """!Button 'OK' pressed"""
  1221. # return opacity value
  1222. opacity = float(self.value.GetValue()) / 100
  1223. return opacity
  1224. def GetImageHandlers(image):
  1225. """!Get list of supported image handlers"""
  1226. lext = list()
  1227. ltype = list()
  1228. for h in image.GetHandlers():
  1229. lext.append(h.GetExtension())
  1230. filetype = ''
  1231. if 'png' in lext:
  1232. filetype += "PNG file (*.png)|*.png|"
  1233. ltype.append({ 'type' : wx.BITMAP_TYPE_PNG,
  1234. 'ext' : 'png' })
  1235. filetype += "BMP file (*.bmp)|*.bmp|"
  1236. ltype.append({ 'type' : wx.BITMAP_TYPE_BMP,
  1237. 'ext' : 'bmp' })
  1238. if 'gif' in lext:
  1239. filetype += "GIF file (*.gif)|*.gif|"
  1240. ltype.append({ 'type' : wx.BITMAP_TYPE_GIF,
  1241. 'ext' : 'gif' })
  1242. if 'jpg' in lext:
  1243. filetype += "JPG file (*.jpg)|*.jpg|"
  1244. ltype.append({ 'type' : wx.BITMAP_TYPE_JPEG,
  1245. 'ext' : 'jpg' })
  1246. if 'pcx' in lext:
  1247. filetype += "PCX file (*.pcx)|*.pcx|"
  1248. ltype.append({ 'type' : wx.BITMAP_TYPE_PCX,
  1249. 'ext' : 'pcx' })
  1250. if 'pnm' in lext:
  1251. filetype += "PNM file (*.pnm)|*.pnm|"
  1252. ltype.append({ 'type' : wx.BITMAP_TYPE_PNM,
  1253. 'ext' : 'pnm' })
  1254. if 'tif' in lext:
  1255. filetype += "TIF file (*.tif)|*.tif|"
  1256. ltype.append({ 'type' : wx.BITMAP_TYPE_TIF,
  1257. 'ext' : 'tif' })
  1258. if 'xpm' in lext:
  1259. filetype += "XPM file (*.xpm)|*.xpm"
  1260. ltype.append({ 'type' : wx.BITMAP_TYPE_XPM,
  1261. 'ext' : 'xpm' })
  1262. return filetype, ltype
  1263. class StaticWrapText(wx.StaticText):
  1264. """!A Static Text field that wraps its text to fit its width,
  1265. enlarging its height if necessary.
  1266. """
  1267. def __init__(self, parent, id = wx.ID_ANY, label = '', *args, **kwds):
  1268. self.parent = parent
  1269. self.originalLabel = label
  1270. wx.StaticText.__init__(self, parent, id, label = '', *args, **kwds)
  1271. self.SetLabel(label)
  1272. self.Bind(wx.EVT_SIZE, self.OnResize)
  1273. def SetLabel(self, label):
  1274. self.originalLabel = label
  1275. self.wrappedSize = None
  1276. self.OnResize(None)
  1277. def OnResize(self, event):
  1278. if not getattr(self, "resizing", False):
  1279. self.resizing = True
  1280. newSize = wx.Size(self.parent.GetSize().width - 50,
  1281. self.GetSize().height)
  1282. if self.wrappedSize != newSize:
  1283. wx.StaticText.SetLabel(self, self.originalLabel)
  1284. self.Wrap(newSize.width)
  1285. self.wrappedSize = newSize
  1286. self.SetSize(self.wrappedSize)
  1287. del self.resizing
  1288. class ImageSizeDialog(wx.Dialog):
  1289. """!Set size for saved graphic file"""
  1290. def __init__(self, parent, id = wx.ID_ANY, title=_("Set image size"),
  1291. style = wx.DEFAULT_DIALOG_STYLE, **kwargs):
  1292. self.parent = parent
  1293. wx.Dialog.__init__(self, parent, id = id, style=style, title=title, **kwargs)
  1294. self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
  1295. self.box = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  1296. label = ' % s' % _("Image size"))
  1297. size = self.parent.GetWindow().GetClientSize()
  1298. self.width = wx.SpinCtrl(parent = self.panel, id = wx.ID_ANY,
  1299. style = wx.SP_ARROW_KEYS)
  1300. self.width.SetRange(20, 1e6)
  1301. self.width.SetValue(size.width)
  1302. wx.CallAfter(self.width.SetFocus)
  1303. self.height = wx.SpinCtrl(parent = self.panel, id = wx.ID_ANY,
  1304. style = wx.SP_ARROW_KEYS)
  1305. self.height.SetRange(20, 1e6)
  1306. self.height.SetValue(size.height)
  1307. self.template = wx.Choice(parent = self.panel, id = wx.ID_ANY,
  1308. size = (125, -1),
  1309. choices = [ "",
  1310. "640x480",
  1311. "800x600",
  1312. "1024x768",
  1313. "1280x960",
  1314. "1600x1200",
  1315. "1920x1440" ])
  1316. self.btnOK = wx.Button(parent = self.panel, id = wx.ID_OK)
  1317. self.btnOK.SetDefault()
  1318. self.btnCancel = wx.Button(parent = self.panel, id = wx.ID_CANCEL)
  1319. self.template.Bind(wx.EVT_CHOICE, self.OnTemplate)
  1320. self._layout()
  1321. self.SetSize(self.GetBestSize())
  1322. def _layout(self):
  1323. """!Do layout"""
  1324. sizer = wx.BoxSizer(wx.VERTICAL)
  1325. # body
  1326. box = wx.StaticBoxSizer(self.box, wx.HORIZONTAL)
  1327. fbox = wx.FlexGridSizer(cols = 2, vgap = 5, hgap = 5)
  1328. fbox.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  1329. label = _("Width:")),
  1330. flag = wx.ALIGN_CENTER_VERTICAL)
  1331. fbox.Add(item = self.width)
  1332. fbox.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  1333. label = _("Height:")),
  1334. flag = wx.ALIGN_CENTER_VERTICAL)
  1335. fbox.Add(item = self.height)
  1336. fbox.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  1337. label = _("Template:")),
  1338. flag = wx.ALIGN_CENTER_VERTICAL)
  1339. fbox.Add(item = self.template)
  1340. box.Add(item = fbox, proportion = 1,
  1341. flag = wx.EXPAND | wx.ALL, border = 5)
  1342. sizer.Add(item = box, proportion = 1,
  1343. flag=wx.EXPAND | wx.ALL, border = 3)
  1344. # buttons
  1345. btnsizer = wx.StdDialogButtonSizer()
  1346. btnsizer.AddButton(self.btnOK)
  1347. btnsizer.AddButton(self.btnCancel)
  1348. btnsizer.Realize()
  1349. sizer.Add(item = btnsizer, proportion = 0,
  1350. flag = wx.EXPAND | wx.ALIGN_RIGHT | wx.ALL, border=5)
  1351. self.panel.SetSizer(sizer)
  1352. sizer.Fit(self.panel)
  1353. self.Layout()
  1354. def GetValues(self):
  1355. """!Get width/height values"""
  1356. return self.width.GetValue(), self.height.GetValue()
  1357. def OnTemplate(self, event):
  1358. """!Template selected"""
  1359. sel = event.GetString()
  1360. if not sel:
  1361. width, height = self.parent.GetWindow().GetClientSize()
  1362. else:
  1363. width, height = map(int, sel.split('x'))
  1364. self.width.SetValue(width)
  1365. self.height.SetValue(height)
  1366. class SqlQueryFrame(wx.Frame):
  1367. def __init__(self, parent, id = wx.ID_ANY,
  1368. title = _("GRASS GIS SQL Query Utility"),
  1369. *kwargs):
  1370. """!SQL Query Utility window
  1371. """
  1372. self.parent = parent
  1373. wx.Frame.__init__(self, parent = parent, id = id, title = title, *kwargs)
  1374. self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass_sql.ico'), wx.BITMAP_TYPE_ICO))
  1375. self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
  1376. self.sqlBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  1377. label = _(" SQL statement "))
  1378. self.sql = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY,
  1379. style = wx.TE_MULTILINE)
  1380. self.btnApply = wx.Button(parent = self.panel, id = wx.ID_APPLY)
  1381. self.btnCancel = wx.Button(parent = self.panel, id = wx.ID_CANCEL)
  1382. self.Bind(wx.EVT_BUTTON, self.OnCloseWindow, self.btnCancel)
  1383. self._layout()
  1384. self.SetMinSize(wx.Size(300, 150))
  1385. self.SetSize(wx.Size(500, 200))
  1386. def _layout(self):
  1387. """!Do layout"""
  1388. sizer = wx.BoxSizer(wx.VERTICAL)
  1389. sqlSizer = wx.StaticBoxSizer(self.sqlBox, wx.HORIZONTAL)
  1390. sqlSizer.Add(item = self.sql, proportion = 1,
  1391. flag = wx.EXPAND)
  1392. btnSizer = wx.StdDialogButtonSizer()
  1393. btnSizer.AddButton(self.btnApply)
  1394. btnSizer.AddButton(self.btnCancel)
  1395. btnSizer.Realize()
  1396. sizer.Add(item = sqlSizer, proportion = 1,
  1397. flag = wx.EXPAND | wx.ALL, border = 5)
  1398. sizer.Add(item = btnSizer, proportion = 0,
  1399. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
  1400. self.panel.SetSizer(sizer)
  1401. self.Layout()
  1402. def OnCloseWindow(self, event):
  1403. """!Close window
  1404. """
  1405. self.Close()