gdialogs.py 64 KB

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