gdialogs.py 66 KB

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