gdialogs.py 65 KB

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