gdialogs.py 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334
  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. - MapLayersDialog
  13. - ImportDialog
  14. - GdalImportDialog
  15. - GdalOutputDialog
  16. - DxfImportDialog
  17. - LayersList (used by MultiImport)
  18. - SetOpacityDialog
  19. - StaticWrapText
  20. - ImageSizeDialog
  21. - SqlQueryFrame
  22. (C) 2008-2011 by the GRASS Development Team
  23. This program is free software under the GNU General Public
  24. License (>=v2). Read the file COPYING that comes with GRASS
  25. for details.
  26. @author Martin Landa <landa.martin gmail.com>
  27. """
  28. import os
  29. import sys
  30. import re
  31. from bisect import bisect
  32. import wx
  33. import wx.lib.filebrowsebutton as filebrowse
  34. import wx.lib.mixins.listctrl as listmix
  35. from grass.script import core as grass
  36. from grass.script import task as gtask
  37. import gcmd
  38. import globalvar
  39. import gselect
  40. import menuform
  41. import utils
  42. from preferences import globalSettings as UserSettings
  43. from debug import Debug
  44. class ElementDialog(wx.Dialog):
  45. def __init__(self, parent, title, label, id = wx.ID_ANY,
  46. etype = False, style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
  47. **kwargs):
  48. """!General dialog to choose given element (location, mapset, vector map, etc.)
  49. @param parent window
  50. @param title window title
  51. @param label element label
  52. @param etype show also ElementSelect
  53. """
  54. wx.Dialog.__init__(self, parent, id, title, style = style, **kwargs)
  55. self.etype = etype
  56. self.label = label
  57. self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
  58. self.btnCancel = wx.Button(parent = self.panel, id = wx.ID_CANCEL)
  59. self.btnOK = wx.Button(parent = self.panel, id = wx.ID_OK)
  60. self.btnOK.SetDefault()
  61. self.btnOK.Enable(False)
  62. if self.etype:
  63. self.typeSelect = gselect.ElementSelect(parent = self.panel,
  64. size = globalvar.DIALOG_GSELECT_SIZE)
  65. self.typeSelect.Bind(wx.EVT_CHOICE, self.OnType)
  66. self.element = None # must be defined
  67. self.__layout()
  68. def PostInit(self):
  69. self.element.SetFocus()
  70. self.element.Bind(wx.EVT_TEXT, self.OnElement)
  71. def OnType(self, event):
  72. """!Select element type"""
  73. if not self.etype:
  74. return
  75. evalue = self.typeSelect.GetValue(event.GetString())
  76. self.element.SetType(evalue)
  77. def OnElement(self, event):
  78. """!Name for vector map layer given"""
  79. if len(event.GetString()) > 0:
  80. self.btnOK.Enable(True)
  81. else:
  82. self.btnOK.Enable(False)
  83. def __layout(self):
  84. """!Do layout"""
  85. self.sizer = wx.BoxSizer(wx.VERTICAL)
  86. self.dataSizer = wx.BoxSizer(wx.VERTICAL)
  87. if self.etype:
  88. self.dataSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  89. label = _("Type of element:")),
  90. proportion = 0, flag = wx.ALL, border = 1)
  91. self.dataSizer.Add(item = self.typeSelect,
  92. proportion = 0, flag = wx.ALL, border = 1)
  93. self.dataSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  94. label = self.label),
  95. proportion = 0, flag = wx.ALL, border = 1)
  96. # buttons
  97. btnSizer = wx.StdDialogButtonSizer()
  98. btnSizer.AddButton(self.btnCancel)
  99. btnSizer.AddButton(self.btnOK)
  100. btnSizer.Realize()
  101. self.sizer.Add(item = self.dataSizer, proportion = 1,
  102. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
  103. self.sizer.Add(item = btnSizer, proportion = 0,
  104. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
  105. def GetElement(self):
  106. """!Return (mapName, overwrite)"""
  107. return self.element.GetValue()
  108. def GetType(self):
  109. """!Get element type"""
  110. return self.element.tcp.GetType()
  111. class LocationDialog(ElementDialog):
  112. """!Dialog used to select location"""
  113. def __init__(self, parent, title = _("Select GRASS location and mapset"), id = wx.ID_ANY):
  114. ElementDialog.__init__(self, parent, title, label = _("Name of GRASS location:"))
  115. self.element = gselect.LocationSelect(parent = self.panel, id = wx.ID_ANY,
  116. size = globalvar.DIALOG_GSELECT_SIZE)
  117. self.element1 = gselect.MapsetSelect(parent = self.panel, id = wx.ID_ANY,
  118. size = globalvar.DIALOG_GSELECT_SIZE,
  119. setItems = False)
  120. self.PostInit()
  121. self.__Layout()
  122. self.SetMinSize(self.GetSize())
  123. def __Layout(self):
  124. """!Do layout"""
  125. self.dataSizer.Add(self.element, proportion = 0,
  126. flag = wx.EXPAND | wx.ALL, border = 1)
  127. self.dataSizer.Add(wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  128. label = _("Name of mapset:")), proportion = 0,
  129. flag = wx.EXPAND | wx.ALL, border = 1)
  130. self.dataSizer.Add(self.element1, proportion = 0,
  131. flag = wx.EXPAND | wx.ALL, border = 1)
  132. self.panel.SetSizer(self.sizer)
  133. self.sizer.Fit(self)
  134. def OnElement(self, event):
  135. """!Select mapset given location name"""
  136. location = event.GetString()
  137. if location:
  138. dbase = grass.gisenv()['GISDBASE']
  139. self.element1.SetItems(utils.GetListOfMapsets(dbase, location, selectable = True))
  140. self.element1.SetSelection(0)
  141. mapset = self.element1.GetStringSelection()
  142. if location and mapset:
  143. self.btnOK.Enable(True)
  144. else:
  145. self.btnOK.Enable(False)
  146. def GetValues(self):
  147. """!Get location, mapset"""
  148. return (self.GetElement(), self.element1.GetStringSelection())
  149. class MapsetDialog(ElementDialog):
  150. """!Dialog used to select mapset"""
  151. def __init__(self, parent, title = _("Select mapset in GRASS location"),
  152. location = None, id = wx.ID_ANY):
  153. ElementDialog.__init__(self, parent, title, label = _("Name of mapset:"))
  154. if location:
  155. self.SetTitle(self.GetTitle() + ' <%s>' % location)
  156. else:
  157. self.SetTitle(self.GetTitle() + ' <%s>' % grass.gisenv()['LOCATION_NAME'])
  158. self.element = gselect.MapsetSelect(parent = self.panel, id = wx.ID_ANY,
  159. size = globalvar.DIALOG_GSELECT_SIZE)
  160. self.PostInit()
  161. self.__Layout()
  162. self.SetMinSize(self.GetSize())
  163. def __Layout(self):
  164. """!Do layout"""
  165. self.dataSizer.Add(self.element, proportion = 0,
  166. flag = wx.EXPAND | wx.ALL, border = 1)
  167. self.panel.SetSizer(self.sizer)
  168. self.sizer.Fit(self)
  169. def GetMapset(self):
  170. return self.GetElement()
  171. class NewVectorDialog(ElementDialog):
  172. def __init__(self, parent, id = wx.ID_ANY, title = _('Create new vector map'),
  173. disableAdd = False, disableTable = False, showType = False,
  174. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, *kwargs):
  175. """!Dialog for creating new vector map
  176. @param parent parent window
  177. @param id window id
  178. @param title window title
  179. @param disableAdd disable 'add layer' checkbox
  180. @param disableTable disable 'create table' checkbox
  181. @param showType True to show feature type selector (used for creating new empty OGR layers)
  182. @param style window style
  183. @param kwargs other argumentes for ElementDialog
  184. @return dialog instance
  185. """
  186. ElementDialog.__init__(self, parent, title, label = _("Name for new vector map:"))
  187. self.element = gselect.Select(parent = self.panel, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
  188. type = 'vector', mapsets = [grass.gisenv()['MAPSET'],])
  189. # determine output format
  190. if showType:
  191. self.ftype = gselect.OgrTypeSelect(parent = self, panel = self.panel)
  192. else:
  193. self.ftype = None
  194. self.table = wx.CheckBox(parent = self.panel, id = wx.ID_ANY,
  195. label = _("Create attribute table"))
  196. self.table.SetValue(True)
  197. if disableTable:
  198. self.table.Enable(False)
  199. self.keycol = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY,
  200. size = globalvar.DIALOG_SPIN_SIZE)
  201. self.keycol.SetValue(UserSettings.Get(group = 'atm', key = 'keycolumn', subkey = 'value'))
  202. if disableTable:
  203. self.keycol.Enable(False)
  204. self.addbox = wx.CheckBox(parent = self.panel,
  205. label = _('Add created map into layer tree'), style = wx.NO_BORDER)
  206. if disableAdd:
  207. self.addbox.SetValue(True)
  208. self.addbox.Enable(False)
  209. else:
  210. self.addbox.SetValue(UserSettings.Get(group = 'cmd', key = 'addNewLayer', subkey = 'enabled'))
  211. self.table.Bind(wx.EVT_CHECKBOX, self.OnTable)
  212. self.PostInit()
  213. self._layout()
  214. self.SetMinSize(self.GetSize())
  215. def OnMapName(self, event):
  216. """!Name for vector map layer given"""
  217. self.OnElement(event)
  218. def OnTable(self, event):
  219. self.keycol.Enable(event.IsChecked())
  220. def _layout(self):
  221. """!Do layout"""
  222. self.dataSizer.Add(item = self.element, proportion = 0,
  223. flag = wx.EXPAND | wx.ALL, border = 1)
  224. if self.ftype:
  225. self.dataSizer.AddSpacer(1)
  226. self.dataSizer.Add(item = self.ftype, proportion = 0,
  227. flag = wx.EXPAND | wx.ALL, border = 1)
  228. self.dataSizer.Add(item = self.table, proportion = 0,
  229. flag = wx.EXPAND | wx.ALL, border = 1)
  230. keySizer = wx.BoxSizer(wx.HORIZONTAL)
  231. keySizer.Add(item = wx.StaticText(parent = self.panel, label = _("Key column:")),
  232. proportion = 0,
  233. flag = wx.ALIGN_CENTER_VERTICAL)
  234. keySizer.AddSpacer(10)
  235. keySizer.Add(item = self.keycol, proportion = 0,
  236. flag = wx.ALIGN_RIGHT)
  237. self.dataSizer.Add(item = keySizer, proportion = 1,
  238. flag = wx.EXPAND | wx.ALL, border = 1)
  239. self.dataSizer.AddSpacer(5)
  240. self.dataSizer.Add(item = self.addbox, proportion = 0,
  241. flag = wx.EXPAND | wx.ALL, border = 1)
  242. self.panel.SetSizer(self.sizer)
  243. self.sizer.Fit(self)
  244. def GetName(self, full = False):
  245. """!Get name of vector map to be created
  246. @param full True to get fully qualified name
  247. """
  248. name = self.GetElement()
  249. if full:
  250. if '@' in name:
  251. return name
  252. else:
  253. return name + '@' + grass.gisenv()['MAPSET']
  254. return name.split('@', 1)[0]
  255. def GetKey(self):
  256. """!Get key column name"""
  257. return self.keycol.GetValue()
  258. def IsChecked(self, key):
  259. """!Get dialog properties
  260. @param key window key ('add', 'table')
  261. @return True/False
  262. @return None on error
  263. """
  264. if key == 'add':
  265. return self.addbox.IsChecked()
  266. elif key == 'table':
  267. return self.table.IsChecked()
  268. return None
  269. def GetFeatureType(self):
  270. """!Get feature type for OGR
  271. @return feature type as string
  272. @return None for native format
  273. """
  274. if self.ftype:
  275. return self.ftype.GetType()
  276. return None
  277. def CreateNewVector(parent, cmd, title = _('Create new vector map'),
  278. exceptMap = None, log = None,
  279. disableAdd = False, disableTable = False):
  280. """!Create new vector map layer
  281. @param cmd (prog, **kwargs)
  282. @param title window title
  283. @param exceptMap list of maps to be excepted
  284. @param log
  285. @param disableAdd disable 'add layer' checkbox
  286. @param disableTable disable 'create table' checkbox
  287. @return dialog instance
  288. @return None on error
  289. """
  290. vExternalOut = grass.parse_command('v.external.out', flags = 'g')
  291. isNative = vExternalOut['format'] == 'native'
  292. if cmd[0] == 'v.edit' and not isNative:
  293. showType = True
  294. else:
  295. showType = False
  296. dlg = NewVectorDialog(parent, title = title,
  297. disableAdd = disableAdd, disableTable = disableTable,
  298. showType = showType)
  299. if dlg.ShowModal() != wx.ID_OK:
  300. dlg.Destroy()
  301. return None
  302. outmap = dlg.GetName()
  303. key = dlg.GetKey()
  304. if outmap == exceptMap:
  305. gcmd.GError(parent = parent,
  306. message = _("Unable to create vector map <%s>.") % outmap)
  307. dlg.Destroy()
  308. return None
  309. if dlg.table.IsEnabled() and not key:
  310. gcmd.GError(parent = parent,
  311. message = _("Invalid or empty key column.\n"
  312. "Unable to create vector map <%s>.") % outmap)
  313. dlg.Destroy()
  314. return
  315. if outmap == '': # should not happen
  316. dlg.Destroy()
  317. return None
  318. # update cmd -> output name defined
  319. cmd[1][cmd[2]] = outmap
  320. if showType:
  321. cmd[1]['type'] = dlg.GetFeatureType()
  322. if isNative:
  323. listOfVectors = grass.list_grouped('vect')[grass.gisenv()['MAPSET']]
  324. else:
  325. listOfVectors = gcmd.RunCommand('v.external',
  326. quiet = True,
  327. parent = parent,
  328. read = True,
  329. flags = 'l',
  330. dsn = vExternalOut['dsn'])
  331. overwrite = False
  332. if not UserSettings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled') and \
  333. outmap in listOfVectors:
  334. dlgOw = wx.MessageDialog(parent, message = _("Vector map <%s> already exists "
  335. "in the current mapset. "
  336. "Do you want to overwrite it?") % outmap,
  337. caption = _("Overwrite?"),
  338. style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
  339. if dlgOw.ShowModal() == wx.ID_YES:
  340. overwrite = True
  341. else:
  342. dlgOw.Destroy()
  343. dlg.Destroy()
  344. return None
  345. if UserSettings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled'):
  346. overwrite = True
  347. ret = gcmd.RunCommand(prog = cmd[0],
  348. parent = parent,
  349. overwrite = overwrite,
  350. **cmd[1])
  351. if ret != 0:
  352. dlg.Destroy()
  353. return None
  354. if not isNative:
  355. # create link for OGR layers
  356. gcmd.RunCommand('v.external',
  357. overwrite = overwrite,
  358. parent = parent,
  359. dsn = vExternalOut['dsn'],
  360. layer = outmap)
  361. # create attribute table
  362. if dlg.table.IsEnabled() and dlg.table.IsChecked():
  363. if isNative:
  364. sql = 'CREATE TABLE %s (%s INTEGER)' % (outmap, key)
  365. gcmd.RunCommand('db.connect',
  366. flags = 'c')
  367. Debug.msg(1, "SQL: %s" % sql)
  368. gcmd.RunCommand('db.execute',
  369. quiet = True,
  370. parent = parent,
  371. input = '-',
  372. stdin = sql)
  373. gcmd.RunCommand('v.db.connect',
  374. quiet = True,
  375. parent = parent,
  376. map = outmap,
  377. table = outmap,
  378. key = key,
  379. layer = '1')
  380. # TODO: how to deal with attribute tables for OGR layers?
  381. # return fully qualified map name
  382. if '@' not in outmap:
  383. outmap += '@' + grass.gisenv()['MAPSET']
  384. if log:
  385. log.WriteLog(_("New vector map <%s> created") % outmap)
  386. return dlg
  387. class SavedRegion(wx.Dialog):
  388. def __init__(self, parent, id = wx.ID_ANY, title = "", loadsave = 'load',
  389. **kwargs):
  390. """!Loading and saving of display extents to saved region file
  391. @param loadsave load or save region?
  392. """
  393. wx.Dialog.__init__(self, parent, id, title, **kwargs)
  394. self.loadsave = loadsave
  395. self.wind = ''
  396. sizer = wx.BoxSizer(wx.VERTICAL)
  397. box = wx.BoxSizer(wx.HORIZONTAL)
  398. label = wx.StaticText(parent = self, id = wx.ID_ANY)
  399. box.Add(item = label, proportion = 0, flag = wx.ALIGN_CENTRE | wx.ALL, border = 5)
  400. if loadsave == 'load':
  401. label.SetLabel(_("Load region:"))
  402. selection = gselect.Select(parent = self, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
  403. type = 'windows')
  404. elif loadsave == 'save':
  405. label.SetLabel(_("Save region:"))
  406. selection = gselect.Select(parent = self, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
  407. type = 'windows', mapsets = [grass.gisenv()['MAPSET']])
  408. box.Add(item = selection, proportion = 0, flag = wx.ALIGN_CENTRE | wx.ALL, border = 5)
  409. selection.SetFocus()
  410. selection.Bind(wx.EVT_TEXT, self.OnRegion)
  411. sizer.Add(item = box, proportion = 0, flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL,
  412. border = 5)
  413. line = wx.StaticLine(parent = self, id = wx.ID_ANY, size = (20, -1), style = wx.LI_HORIZONTAL)
  414. sizer.Add(item = line, proportion = 0,
  415. flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border = 5)
  416. btnsizer = wx.StdDialogButtonSizer()
  417. btn = wx.Button(parent = self, id = wx.ID_OK)
  418. btn.SetDefault()
  419. btnsizer.AddButton(btn)
  420. btn = wx.Button(parent = self, id = wx.ID_CANCEL)
  421. btnsizer.AddButton(btn)
  422. btnsizer.Realize()
  423. sizer.Add(item = btnsizer, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
  424. self.SetSizer(sizer)
  425. sizer.Fit(self)
  426. self.Layout()
  427. def OnRegion(self, event):
  428. self.wind = event.GetString()
  429. class DecorationDialog(wx.Dialog):
  430. """!Controls setting options and displaying/hiding map overlay
  431. decorations
  432. """
  433. def __init__(self, parent, ovlId, title, cmd, name = None,
  434. pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_DIALOG_STYLE,
  435. checktxt = '', ctrltxt = ''):
  436. wx.Dialog.__init__(self, parent, wx.ID_ANY, title, pos, size, style)
  437. self.ovlId = ovlId # PseudoDC id
  438. self.cmd = cmd
  439. self.name = name # overlay name
  440. self.parent = parent # MapFrame
  441. sizer = wx.BoxSizer(wx.VERTICAL)
  442. box = wx.BoxSizer(wx.HORIZONTAL)
  443. self.chkbox = wx.CheckBox(parent = self, id = wx.ID_ANY, label = checktxt)
  444. if self.parent.Map.GetOverlay(self.ovlId) is None:
  445. self.chkbox.SetValue(True)
  446. else:
  447. self.chkbox.SetValue(self.parent.MapWindow.overlays[self.ovlId]['layer'].IsActive())
  448. box.Add(item = self.chkbox, proportion = 0,
  449. flag = wx.ALIGN_CENTRE|wx.ALL, border = 5)
  450. sizer.Add(item = box, proportion = 0,
  451. flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
  452. box = wx.BoxSizer(wx.HORIZONTAL)
  453. optnbtn = wx.Button(parent = self, id = wx.ID_ANY, label = _("Set options"))
  454. box.Add(item = optnbtn, proportion = 0, flag = wx.ALIGN_CENTRE|wx.ALL, border = 5)
  455. sizer.Add(item = box, proportion = 0,
  456. flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
  457. if self.name == 'legend':
  458. box = wx.BoxSizer(wx.HORIZONTAL)
  459. resize = wx.ToggleButton(parent = self, id = wx.ID_ANY, label = _("Set size and position"))
  460. resize.SetToolTipString(_("Click and drag on the map display to set legend"
  461. " size and position and then press OK"))
  462. resize.SetName('resize')
  463. if self.parent.IsPaneShown('3d'):
  464. resize.Disable()
  465. box.Add(item = resize, proportion = 0, flag = wx.ALIGN_CENTRE|wx.ALL, border = 5)
  466. sizer.Add(item = box, proportion = 0,
  467. flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
  468. box = wx.BoxSizer(wx.HORIZONTAL)
  469. label = wx.StaticText(parent = self, id = wx.ID_ANY,
  470. label = _("Drag %s with mouse in pointer mode to position.\n"
  471. "Double-click to change options." % ctrltxt))
  472. if self.name == 'legend':
  473. label.SetLabel(label.GetLabel() + _('\nDefine raster map name for legend in '
  474. 'properties dialog.'))
  475. box.Add(item = label, proportion = 0,
  476. flag = wx.ALIGN_CENTRE|wx.ALL, border = 5)
  477. sizer.Add(item = box, proportion = 0,
  478. flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
  479. line = wx.StaticLine(parent = self, id = wx.ID_ANY, size = (20,-1), style = wx.LI_HORIZONTAL)
  480. sizer.Add(item = line, proportion = 0,
  481. flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
  482. # buttons
  483. btnsizer = wx.StdDialogButtonSizer()
  484. self.btnOK = wx.Button(parent = self, id = wx.ID_OK)
  485. self.btnOK.SetDefault()
  486. if self.name == 'legend':
  487. self.btnOK.Enable(False)
  488. btnsizer.AddButton(self.btnOK)
  489. btnCancel = wx.Button(parent = self, id = wx.ID_CANCEL)
  490. btnsizer.AddButton(btnCancel)
  491. btnsizer.Realize()
  492. sizer.Add(item = btnsizer, proportion = 0,
  493. flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border = 5)
  494. #
  495. # bindings
  496. #
  497. self.Bind(wx.EVT_BUTTON, self.OnOptions, optnbtn)
  498. if self.name == 'legend':
  499. self.Bind(wx.EVT_TOGGLEBUTTON, self.OnResize, resize)
  500. self.Bind(wx.EVT_BUTTON, self.OnCancel, btnCancel)
  501. self.Bind(wx.EVT_BUTTON, self.OnOK, self.btnOK)
  502. self.SetSizer(sizer)
  503. sizer.Fit(self)
  504. # create overlay if doesn't exist
  505. self._createOverlay()
  506. if len(self.parent.MapWindow.overlays[self.ovlId]['cmd']) > 1:
  507. if name == 'legend':
  508. mapName, found = utils.GetLayerNameFromCmd(self.parent.MapWindow.overlays[self.ovlId]['cmd'])
  509. if found:
  510. # enable 'OK' button
  511. self.btnOK.Enable()
  512. # set title
  513. self.SetTitle(_('Legend of raster map <%s>') % \
  514. mapName)
  515. def _createOverlay(self):
  516. """!Creates overlay"""
  517. if not self.parent.GetMap().GetOverlay(self.ovlId):
  518. self.newOverlay = self.parent.Map.AddOverlay(id = self.ovlId, type = self.name,
  519. command = self.cmd,
  520. l_active = False, l_render = False, l_hidden = True)
  521. prop = { 'layer' : self.newOverlay,
  522. 'params' : None,
  523. 'propwin' : None,
  524. 'cmd' : self.cmd,
  525. 'coords': (0, 0),
  526. 'pdcType': 'image' }
  527. self.parent.MapWindow2D.overlays[self.ovlId] = prop
  528. if self.parent.MapWindow3D:
  529. self.parent.MapWindow3D.overlays[self.ovlId] = prop
  530. else:
  531. if self.parent.MapWindow.overlays[self.ovlId]['propwin'] == None:
  532. return
  533. self.parent.MapWindow.overlays[self.ovlId]['propwin'].get_dcmd = self.GetOptData
  534. def OnOptions(self, event):
  535. """!Sets option for decoration map overlays
  536. """
  537. if self.parent.MapWindow.overlays[self.ovlId]['propwin'] is None:
  538. # build properties dialog
  539. menuform.GUI(parent = self.parent).ParseCommand(cmd = self.cmd,
  540. completed = (self.GetOptData, self.name, ''))
  541. else:
  542. if self.parent.MapWindow.overlays[self.ovlId]['propwin'].IsShown():
  543. self.parent.MapWindow.overlays[self.ovlId]['propwin'].SetFocus()
  544. else:
  545. self.parent.MapWindow.overlays[self.ovlId]['propwin'].Show()
  546. def OnResize(self, event):
  547. if self.FindWindowByName('resize').GetValue():
  548. self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
  549. self.parent.MapWindow.mouse['use'] = 'legend'
  550. self.parent.MapWindow.mouse['box'] = 'box'
  551. self.parent.MapWindow.pen = wx.Pen(colour = 'Black', width = 2, style = wx.SHORT_DASH)
  552. else:
  553. self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
  554. self.parent.MapWindow.mouse['use'] = 'pointer'
  555. def OnCancel(self, event):
  556. """!Cancel dialog"""
  557. if self.name == 'legend' and self.FindWindowByName('resize').GetValue():
  558. self.FindWindowByName('resize').SetValue(False)
  559. self.OnResize(None)
  560. self.parent.dialogs['barscale'] = None
  561. if event and hasattr(self, 'newOverlay'):
  562. self.parent.Map.DeleteOverlay(self.newOverlay)
  563. self.Destroy()
  564. def OnOK(self, event):
  565. """!Button 'OK' pressed"""
  566. # enable or disable overlay
  567. self.parent.Map.GetOverlay(self.ovlId).SetActive(self.chkbox.IsChecked())
  568. # update map
  569. if self.parent.IsPaneShown('3d'):
  570. self.parent.MapWindow.UpdateOverlays()
  571. self.parent.MapWindow.UpdateMap()
  572. # close dialog
  573. self.OnCancel(None)
  574. def GetOptData(self, dcmd, layer, params, propwin):
  575. """!Process decoration layer data"""
  576. # update layer data
  577. if params:
  578. self.parent.MapWindow.overlays[self.ovlId]['params'] = params
  579. if dcmd:
  580. self.parent.MapWindow.overlays[self.ovlId]['cmd'] = dcmd
  581. self.parent.MapWindow.overlays[self.ovlId]['propwin'] = propwin
  582. # change parameters for item in layers list in render.Map
  583. # "Use mouse..." (-m) flag causes GUI freeze and is pointless here, trac #119
  584. try:
  585. self.parent.MapWindow.overlays[self.ovlId]['cmd'].remove('-m')
  586. except ValueError:
  587. pass
  588. self.parent.Map.ChangeOverlay(id = self.ovlId, type = self.name,
  589. command = self.parent.MapWindow.overlays[self.ovlId]['cmd'],
  590. l_active = self.parent.MapWindow.overlays[self.ovlId]['layer'].IsActive(),
  591. l_render = False, l_hidden = True)
  592. if self.name == 'legend':
  593. if params and not self.btnOK.IsEnabled():
  594. self.btnOK.Enable()
  595. class TextLayerDialog(wx.Dialog):
  596. """
  597. Controls setting options and displaying/hiding map overlay decorations
  598. """
  599. def __init__(self, parent, ovlId, title, name = 'text',
  600. pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_DIALOG_STYLE):
  601. wx.Dialog.__init__(self, parent, wx.ID_ANY, title, pos, size, style)
  602. from wx.lib.expando import ExpandoTextCtrl, EVT_ETC_LAYOUT_NEEDED
  603. self.ovlId = ovlId
  604. self.parent = parent
  605. if self.ovlId in self.parent.MapWindow.textdict.keys():
  606. self.currText = self.parent.MapWindow.textdict[self.ovlId]['text']
  607. self.currFont = self.parent.MapWindow.textdict[self.ovlId]['font']
  608. self.currClr = self.parent.MapWindow.textdict[self.ovlId]['color']
  609. self.currRot = self.parent.MapWindow.textdict[self.ovlId]['rotation']
  610. self.currCoords = self.parent.MapWindow.textdict[self.ovlId]['coords']
  611. self.currBB = self.parent.MapWindow.textdict[self.ovlId]['bbox']
  612. else:
  613. self.currClr = wx.BLACK
  614. self.currText = ''
  615. self.currFont = self.GetFont()
  616. self.currRot = 0.0
  617. self.currCoords = [10, 10]
  618. self.currBB = wx.Rect()
  619. self.sizer = wx.BoxSizer(wx.VERTICAL)
  620. box = wx.GridBagSizer(vgap = 5, hgap = 5)
  621. # show/hide
  622. self.chkbox = wx.CheckBox(parent = self, id = wx.ID_ANY,
  623. label = _('Show text object'))
  624. if self.parent.Map.GetOverlay(self.ovlId) is None:
  625. self.chkbox.SetValue(True)
  626. else:
  627. self.chkbox.SetValue(self.parent.MapWindow.overlays[self.ovlId]['layer'].IsActive())
  628. box.Add(item = self.chkbox, span = (1,2),
  629. flag = wx.ALIGN_LEFT|wx.ALL, border = 5,
  630. pos = (0, 0))
  631. # text entry
  632. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Enter text:"))
  633. box.Add(item = label,
  634. flag = wx.ALIGN_CENTER_VERTICAL,
  635. pos = (1, 0))
  636. self.textentry = ExpandoTextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (300,-1))
  637. self.textentry.SetFont(self.currFont)
  638. self.textentry.SetForegroundColour(self.currClr)
  639. self.textentry.SetValue(self.currText)
  640. # get rid of unneeded scrollbar when text box first opened
  641. self.textentry.SetClientSize((300,-1))
  642. box.Add(item = self.textentry,
  643. pos = (1, 1))
  644. # rotation
  645. label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Rotation:"))
  646. box.Add(item = label,
  647. flag = wx.ALIGN_CENTER_VERTICAL,
  648. pos = (2, 0))
  649. self.rotation = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value = "", pos = (30, 50),
  650. size = (75,-1), style = wx.SP_ARROW_KEYS)
  651. self.rotation.SetRange(-360, 360)
  652. self.rotation.SetValue(int(self.currRot))
  653. box.Add(item = self.rotation,
  654. flag = wx.ALIGN_RIGHT,
  655. pos = (2, 1))
  656. # font
  657. fontbtn = wx.Button(parent = self, id = wx.ID_ANY, label = _("Set font"))
  658. box.Add(item = fontbtn,
  659. flag = wx.ALIGN_RIGHT,
  660. pos = (3, 1))
  661. self.sizer.Add(item = box, proportion = 1,
  662. flag = wx.ALL, border = 10)
  663. # note
  664. box = wx.BoxSizer(wx.HORIZONTAL)
  665. label = wx.StaticText(parent = self, id = wx.ID_ANY,
  666. label = _("Drag text with mouse in pointer mode "
  667. "to position.\nDouble-click to change options"))
  668. box.Add(item = label, proportion = 0,
  669. flag = wx.ALIGN_CENTRE | wx.ALL, border = 5)
  670. self.sizer.Add(item = box, proportion = 0,
  671. flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER | wx.ALL, border = 5)
  672. line = wx.StaticLine(parent = self, id = wx.ID_ANY,
  673. size = (20,-1), style = wx.LI_HORIZONTAL)
  674. self.sizer.Add(item = line, proportion = 0,
  675. flag = wx.EXPAND | wx.ALIGN_CENTRE | wx.ALL, border = 5)
  676. btnsizer = wx.StdDialogButtonSizer()
  677. btn = wx.Button(parent = self, id = wx.ID_OK)
  678. btn.SetDefault()
  679. btnsizer.AddButton(btn)
  680. btn = wx.Button(parent = self, id = wx.ID_CANCEL)
  681. btnsizer.AddButton(btn)
  682. btnsizer.Realize()
  683. self.sizer.Add(item = btnsizer, proportion = 0,
  684. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
  685. self.SetSizer(self.sizer)
  686. self.sizer.Fit(self)
  687. # bindings
  688. self.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnRefit, self.textentry)
  689. self.Bind(wx.EVT_BUTTON, self.OnSelectFont, fontbtn)
  690. self.Bind(wx.EVT_TEXT, self.OnText, self.textentry)
  691. self.Bind(wx.EVT_SPINCTRL, self.OnRotation, self.rotation)
  692. def OnRefit(self, event):
  693. """!Resize text entry to match text"""
  694. self.sizer.Fit(self)
  695. def OnText(self, event):
  696. """!Change text string"""
  697. self.currText = event.GetString()
  698. def OnRotation(self, event):
  699. """!Change rotation"""
  700. self.currRot = event.GetInt()
  701. event.Skip()
  702. def OnSelectFont(self, event):
  703. """!Change font"""
  704. data = wx.FontData()
  705. data.EnableEffects(True)
  706. data.SetColour(self.currClr) # set colour
  707. data.SetInitialFont(self.currFont)
  708. dlg = wx.FontDialog(self, data)
  709. if dlg.ShowModal() == wx.ID_OK:
  710. data = dlg.GetFontData()
  711. self.currFont = data.GetChosenFont()
  712. self.currClr = data.GetColour()
  713. self.textentry.SetFont(self.currFont)
  714. self.textentry.SetForegroundColour(self.currClr)
  715. self.Layout()
  716. dlg.Destroy()
  717. def GetValues(self):
  718. """!Get text properties"""
  719. return { 'text' : self.currText,
  720. 'font' : self.currFont,
  721. 'color' : self.currClr,
  722. 'rotation' : self.currRot,
  723. 'coords' : self.currCoords,
  724. 'active' : self.chkbox.IsChecked() }
  725. class GroupDialog(wx.Dialog):
  726. """!Dialog for creating/editing groups"""
  727. def __init__(self, parent = None, defaultGroup = None,
  728. title = _("Create or edit imagery groups"),
  729. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
  730. wx.Dialog.__init__(self, parent = parent, id = wx.ID_ANY, title = title,
  731. style = style, **kwargs)
  732. self.parent = parent
  733. self.defaultGroup = defaultGroup
  734. self.bodySizer = self._createDialogBody()
  735. # buttons
  736. btnApply = wx.Button(parent = self, id = wx.ID_APPLY)
  737. btnClose = wx.Button(parent = self, id = wx.ID_CANCEL)
  738. # workaround, problem to place ID_CLOSE
  739. btnClose.SetLabel(_("&Close"))
  740. btnApply.SetToolTipString(_("Apply changes to selected group."))
  741. btnClose.SetToolTipString(_("Close dialog, changes are not applied."))
  742. btnApply.SetDefault()
  743. # sizers & do layout
  744. btnSizer = wx.StdDialogButtonSizer()
  745. btnSizer.AddButton(btnApply)
  746. btnSizer.AddButton(btnClose)
  747. btnSizer.Realize()
  748. mainSizer = wx.BoxSizer(wx.VERTICAL)
  749. mainSizer.Add(item = self.bodySizer, proportion = 1,
  750. flag = wx.EXPAND | wx.ALL, border = 10)
  751. mainSizer.Add(item = wx.StaticLine(parent = self, id = wx.ID_ANY,
  752. style = wx.LI_HORIZONTAL), proportion = 0,
  753. flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border = 10)
  754. mainSizer.Add(item = btnSizer, proportion = 0,
  755. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 10)
  756. self.SetSizer(mainSizer)
  757. mainSizer.Fit(self)
  758. btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
  759. btnClose.Bind(wx.EVT_BUTTON, self.OnClose)
  760. # set dialog min size
  761. self.SetMinSize(self.GetSize())
  762. def _createDialogBody(self):
  763. bodySizer = wx.BoxSizer(wx.VERTICAL)
  764. # group selection
  765. bodySizer.Add(item = wx.StaticText(parent = self, id = wx.ID_ANY,
  766. label = _("Select the group you want to edit or "
  767. "enter name of new group:")),
  768. flag = wx.ALIGN_CENTER_VERTICAL | wx.TOP, border = 5)
  769. self.groupSelect = gselect.Select(parent = self, type = 'group',
  770. mapsets = [grass.gisenv()['MAPSET']],
  771. size = globalvar.DIALOG_GSELECT_SIZE) # searchpath?
  772. bodySizer.Add(item = self.groupSelect, flag = wx.TOP | wx.EXPAND, border = 5)
  773. bodySizer.AddSpacer(20)
  774. # layers in group
  775. bodySizer.Add(item = wx.StaticText(parent = self, label = _("Layers in selected group:")),
  776. flag = wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM, border = 5)
  777. gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
  778. gridSizer.AddGrowableCol(0)
  779. gridSizer.AddGrowableRow(1)
  780. self.layerBox = wx.ListBox(parent = self, id = wx.ID_ANY, size = (-1, 150),
  781. style = wx.LB_MULTIPLE | wx.LB_NEEDED_SB)
  782. gridSizer.Add(item = self.layerBox, pos = (0,0), span = (4, 1), flag = wx.EXPAND)
  783. self.addLayer = wx.Button(self, id = wx.ID_ANY, label = _("Add..."))
  784. self.addLayer.SetToolTipString(_("Select map layers and add them to the list."))
  785. gridSizer.Add(item = self.addLayer, pos = (0,1))
  786. self.removeLayer = wx.Button(self, id = wx.ID_ANY, label = _("Remove"))
  787. self.removeLayer.SetToolTipString(_("Remove selected layer(s) from list."))
  788. gridSizer.Add(item = self.removeLayer, pos = (1,1))
  789. bodySizer.Add(item = gridSizer, proportion = 1, flag = wx.EXPAND)
  790. self.infoLabel = wx.StaticText(parent = self, id = wx.ID_ANY)
  791. bodySizer.Add(item = self.infoLabel,
  792. flag = wx.ALIGN_CENTER_VERTICAL | wx.TOP | wx.BOTTOM, border = 5)
  793. # bindings
  794. self.groupSelect.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnGroupSelected)
  795. self.addLayer.Bind(wx.EVT_BUTTON, self.OnAddLayer)
  796. self.removeLayer.Bind(wx.EVT_BUTTON, self.OnRemoveLayer)
  797. if self.defaultGroup:
  798. self.groupSelect.SetValue(self.defaultGroup)
  799. return bodySizer
  800. def OnAddLayer(self, event):
  801. """!Add new layer to listbox"""
  802. dlg = MapLayersDialog(parent = self, title = _("Add selected map layers into group"),
  803. mapType = 'raster', selectAll = False,
  804. fullyQualified = True, showFullyQualified = False)
  805. if dlg.ShowModal() != wx.ID_OK:
  806. dlg.Destroy()
  807. return
  808. layers = dlg.GetMapLayers()
  809. for layer in layers:
  810. if layer not in self.GetLayers():
  811. self.layerBox.Append(layer)
  812. def OnRemoveLayer(self, event):
  813. """!Remove layer from listbox"""
  814. while self.layerBox.GetSelections():
  815. sel = self.layerBox.GetSelections()[0]
  816. self.layerBox.Delete(sel)
  817. def GetLayers(self):
  818. """!Get layers"""
  819. return self.layerBox.GetItems()
  820. def OnGroupSelected(self, event):
  821. """!Text changed in group selector"""
  822. group = self.GetSelectedGroup()
  823. groups = self.GetExistGroups()
  824. if group in groups:
  825. self.ShowGroupLayers(self.GetGroupLayers(group))
  826. def ShowGroupLayers(self, mapList):
  827. """!Show map layers in currently selected group"""
  828. self.layerBox.Set(mapList)
  829. def EditGroup(self, group):
  830. """!Edit selected group"""
  831. layersNew = self.GetLayers()
  832. layersOld = self.GetGroupLayers(group)
  833. add = []
  834. remove = []
  835. for layerNew in layersNew:
  836. if layerNew not in layersOld:
  837. add.append(layerNew)
  838. for layerOld in layersOld:
  839. if layerOld not in layersNew:
  840. remove.append(layerOld)
  841. ret = None
  842. if remove:
  843. ret = gcmd.RunCommand('i.group',
  844. parent = self,
  845. group = group,
  846. flags = 'r',
  847. input = ','.join(remove))
  848. if add:
  849. ret = gcmd.RunCommand('i.group',
  850. parent = self,
  851. group = group,
  852. input = ','.join(add))
  853. self.ShowResult(group = group, returnCode = ret, create = False)
  854. def CreateNewGroup(self, group):
  855. """!Create new group"""
  856. layers = self.GetLayers()
  857. ret = gcmd.RunCommand('i.group',
  858. parent = self,
  859. group = group,
  860. input = layers)
  861. self.ShowResult(group = group, returnCode = ret, create = True)
  862. def GetExistGroups(self):
  863. """!Returns existing groups in current mapset"""
  864. return grass.list_grouped('group')[grass.gisenv()['MAPSET']]
  865. def ShowResult(self, group, returnCode, create):
  866. """!Show if operation was successfull."""
  867. group += '@' + grass.gisenv()['MAPSET']
  868. if returnCode is None:
  869. label = _("No changes to apply in group <%s>.") % group
  870. elif returnCode == 0:
  871. if create:
  872. label = _("Group <%s> was successfully created.") % group
  873. else:
  874. label = _("Group <%s> was successfully changed.") % group
  875. else:
  876. if create:
  877. label = _("Creating of new group <%s> failed.") % group
  878. else:
  879. label = _("Changing of group <%s> failed.") % group
  880. self.infoLabel.SetLabel(label)
  881. wx.FutureCall(4000, self.ClearNotification)
  882. def GetSelectedGroup(self):
  883. """!Return currently selected group (without mapset)"""
  884. return self.groupSelect.GetValue().split('@')[0]
  885. def GetGroupLayers(self, group):
  886. """!Get layers in group"""
  887. res = gcmd.RunCommand('i.group',
  888. parent = self,
  889. flags = 'g',
  890. group = group,
  891. read = True).strip()
  892. return res.split('\n')
  893. def ClearNotification(self):
  894. """!Clear notification string"""
  895. self.infoLabel.SetLabel("")
  896. def OnApply(self, event):
  897. """!Create or edit group"""
  898. group = self.GetSelectedGroup()
  899. if not group:
  900. gcmd.GMessage(parent = self,
  901. message = _("No group selected."))
  902. return
  903. groups = self.GetExistGroups()
  904. if group in groups:
  905. self.EditGroup(group)
  906. else:
  907. self.CreateNewGroup(group)
  908. def OnClose(self, event):
  909. """!Close dialog"""
  910. if not self.IsModal():
  911. self.Destroy()
  912. event.Skip()
  913. class MapLayersDialog(wx.Dialog):
  914. def __init__(self, parent, title, modeler = False,
  915. mapType = None, selectAll = True, fullyQualified = True, showFullyQualified = True,
  916. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
  917. """!Dialog for selecting map layers (raster, vector)
  918. @param mapType type of map (if None: raster, vector, 3d raster, if one only: selects it and disables selection)
  919. @param selectAll all/none maps should be selected by default
  920. @param fullyQualified True if dialog should return full map names by default
  921. @param showFullyQualified True to show 'fullyQualified' checkbox, otherwise hide it
  922. """
  923. wx.Dialog.__init__(self, parent = parent, id = wx.ID_ANY, title = title,
  924. style = style, **kwargs)
  925. self.parent = parent # GMFrame or ?
  926. self.mapType = mapType
  927. self.selectAll = selectAll
  928. # dialog body
  929. self.bodySizer = self._createDialogBody()
  930. # update list of layer to be loaded
  931. self.map_layers = [] # list of map layers (full list type/mapset)
  932. self.LoadMapLayers(self.GetLayerType(cmd = True),
  933. self.mapset.GetStringSelection())
  934. self.fullyQualified = wx.CheckBox(parent = self, id = wx.ID_ANY,
  935. label = _("Use fully-qualified map names"))
  936. self.fullyQualified.SetValue(fullyQualified)
  937. self.fullyQualified.Show(showFullyQualified)
  938. self.dseries = None
  939. if modeler:
  940. self.dseries = wx.CheckBox(parent = self, id = wx.ID_ANY,
  941. label = _("Dynamic series (%s)") % 'g.mlist')
  942. self.dseries.SetValue(False)
  943. # buttons
  944. btnCancel = wx.Button(parent = self, id = wx.ID_CANCEL)
  945. btnOk = wx.Button(parent = self, id = wx.ID_OK)
  946. btnOk.SetDefault()
  947. # sizers & do layout
  948. btnSizer = wx.StdDialogButtonSizer()
  949. btnSizer.AddButton(btnCancel)
  950. btnSizer.AddButton(btnOk)
  951. btnSizer.Realize()
  952. mainSizer = wx.BoxSizer(wx.VERTICAL)
  953. mainSizer.Add(item = self.bodySizer, proportion = 1,
  954. flag = wx.EXPAND | wx.ALL, border = 5)
  955. mainSizer.Add(item = self.fullyQualified, proportion = 0,
  956. flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border = 5)
  957. if self.dseries:
  958. mainSizer.Add(item = self.dseries, proportion = 0,
  959. flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border = 5)
  960. mainSizer.Add(item = btnSizer, proportion = 0,
  961. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
  962. self.SetSizer(mainSizer)
  963. mainSizer.Fit(self)
  964. # set dialog min size
  965. self.SetMinSize(self.GetSize())
  966. def _createDialogBody(self):
  967. bodySizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  968. bodySizer.AddGrowableCol(1)
  969. bodySizer.AddGrowableRow(3)
  970. # layer type
  971. bodySizer.Add(item = wx.StaticText(parent = self, label = _("Map type:")),
  972. flag = wx.ALIGN_CENTER_VERTICAL,
  973. pos = (0,0))
  974. self.layerType = wx.Choice(parent = self, id = wx.ID_ANY,
  975. choices = [_('raster'), _('3D raster'), _('vector')], size = (100,-1))
  976. if self.mapType:
  977. self.layerType.SetStringSelection(self.mapType)
  978. self.layerType.Disable()
  979. else:
  980. self.layerType.SetSelection(0)
  981. bodySizer.Add(item = self.layerType,
  982. pos = (0,1))
  983. # select toggle
  984. self.toggle = wx.CheckBox(parent = self, id = wx.ID_ANY,
  985. label = _("Select toggle"))
  986. self.toggle.SetValue(self.selectAll)
  987. bodySizer.Add(item = self.toggle,
  988. flag = wx.ALIGN_CENTER_VERTICAL,
  989. pos = (0,2))
  990. # mapset filter
  991. bodySizer.Add(item = wx.StaticText(parent = self, label = _("Mapset:")),
  992. flag = wx.ALIGN_CENTER_VERTICAL,
  993. pos = (1,0))
  994. self.mapset = gselect.MapsetSelect(parent = self, searchPath = True)
  995. self.mapset.SetStringSelection(grass.gisenv()['MAPSET'])
  996. bodySizer.Add(item = self.mapset,
  997. pos = (1,1), span = (1, 2))
  998. # map name filter
  999. bodySizer.Add(item = wx.StaticText(parent = self, label = _("Pattern:")),
  1000. flag = wx.ALIGN_CENTER_VERTICAL,
  1001. pos = (2,0))
  1002. self.filter = wx.TextCtrl(parent = self, id = wx.ID_ANY,
  1003. value = "",
  1004. size = (250,-1))
  1005. bodySizer.Add(item = self.filter,
  1006. flag = wx.EXPAND,
  1007. pos = (2,1), span = (1, 2))
  1008. # layer list
  1009. bodySizer.Add(item = wx.StaticText(parent = self, label = _("List of maps:")),
  1010. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_TOP,
  1011. pos = (3,0))
  1012. self.layers = wx.CheckListBox(parent = self, id = wx.ID_ANY,
  1013. size = (250, 100),
  1014. choices = [])
  1015. bodySizer.Add(item = self.layers,
  1016. flag = wx.EXPAND,
  1017. pos = (3,1), span = (1, 2))
  1018. # bindings
  1019. self.layerType.Bind(wx.EVT_CHOICE, self.OnChangeParams)
  1020. self.mapset.Bind(wx.EVT_COMBOBOX, self.OnChangeParams)
  1021. self.layers.Bind(wx.EVT_RIGHT_DOWN, self.OnMenu)
  1022. self.filter.Bind(wx.EVT_TEXT, self.OnFilter)
  1023. self.toggle.Bind(wx.EVT_CHECKBOX, self.OnToggle)
  1024. return bodySizer
  1025. def LoadMapLayers(self, type, mapset):
  1026. """!Load list of map layers
  1027. @param type layer type ('raster' or 'vector')
  1028. @param mapset mapset name
  1029. """
  1030. self.map_layers = grass.mlist_grouped(type = type)[mapset]
  1031. self.layers.Set(self.map_layers)
  1032. # check all items by default
  1033. for item in range(self.layers.GetCount()):
  1034. self.layers.Check(item, check = self.selectAll)
  1035. def OnChangeParams(self, event):
  1036. """!Filter parameters changed by user"""
  1037. # update list of layer to be loaded
  1038. self.LoadMapLayers(self.GetLayerType(cmd = True),
  1039. self.mapset.GetStringSelection())
  1040. event.Skip()
  1041. def OnMenu(self, event):
  1042. """!Table description area, context menu"""
  1043. if not hasattr(self, "popupID1"):
  1044. self.popupDataID1 = wx.NewId()
  1045. self.popupDataID2 = wx.NewId()
  1046. self.popupDataID3 = wx.NewId()
  1047. self.Bind(wx.EVT_MENU, self.OnSelectAll, id = self.popupDataID1)
  1048. self.Bind(wx.EVT_MENU, self.OnSelectInvert, id = self.popupDataID2)
  1049. self.Bind(wx.EVT_MENU, self.OnDeselectAll, id = self.popupDataID3)
  1050. # generate popup-menu
  1051. menu = wx.Menu()
  1052. menu.Append(self.popupDataID1, _("Select all"))
  1053. menu.Append(self.popupDataID2, _("Invert selection"))
  1054. menu.Append(self.popupDataID3, _("Deselect all"))
  1055. self.PopupMenu(menu)
  1056. menu.Destroy()
  1057. def OnSelectAll(self, event):
  1058. """!Select all map layer from list"""
  1059. for item in range(self.layers.GetCount()):
  1060. self.layers.Check(item, True)
  1061. def OnSelectInvert(self, event):
  1062. """!Invert current selection"""
  1063. for item in range(self.layers.GetCount()):
  1064. if self.layers.IsChecked(item):
  1065. self.layers.Check(item, False)
  1066. else:
  1067. self.layers.Check(item, True)
  1068. def OnDeselectAll(self, event):
  1069. """!Select all map layer from list"""
  1070. for item in range(self.layers.GetCount()):
  1071. self.layers.Check(item, False)
  1072. def OnFilter(self, event):
  1073. """!Apply filter for map names"""
  1074. if len(event.GetString()) == 0:
  1075. self.layers.Set(self.map_layers)
  1076. return
  1077. list = []
  1078. for layer in self.map_layers:
  1079. try:
  1080. if re.compile('^' + event.GetString()).search(layer):
  1081. list.append(layer)
  1082. except:
  1083. pass
  1084. self.layers.Set(list)
  1085. self.OnSelectAll(None)
  1086. event.Skip()
  1087. def OnToggle(self, event):
  1088. """!Select toggle (check or uncheck all layers)"""
  1089. check = event.Checked()
  1090. for item in range(self.layers.GetCount()):
  1091. self.layers.Check(item, check)
  1092. event.Skip()
  1093. def GetMapLayers(self):
  1094. """!Return list of checked map layers"""
  1095. layerNames = []
  1096. for indx in self.layers.GetSelections():
  1097. # layers.append(self.layers.GetStringSelec(indx))
  1098. pass
  1099. fullyQualified = self.fullyQualified.IsChecked()
  1100. mapset = self.mapset.GetStringSelection()
  1101. for item in range(self.layers.GetCount()):
  1102. if not self.layers.IsChecked(item):
  1103. continue
  1104. if fullyQualified:
  1105. layerNames.append(self.layers.GetString(item) + '@' + mapset)
  1106. else:
  1107. layerNames.append(self.layers.GetString(item))
  1108. return layerNames
  1109. def GetLayerType(self, cmd = False):
  1110. """!Get selected layer type
  1111. @param cmd True for g.mlist
  1112. """
  1113. if not cmd:
  1114. return self.layerType.GetStringSelection()
  1115. sel = self.layerType.GetSelection()
  1116. if sel == 0:
  1117. ltype = 'rast'
  1118. elif sel == 1:
  1119. ltype = 'rast3d'
  1120. else:
  1121. ltype = 'vect'
  1122. return ltype
  1123. def GetDSeries(self):
  1124. """!Used by modeler only
  1125. @return g.mlist command
  1126. """
  1127. if not self.dseries or not self.dseries.IsChecked():
  1128. return ''
  1129. cond = 'map in `g.mlist type=%s ' % self.GetLayerType(cmd = True)
  1130. patt = self.filter.GetValue()
  1131. if patt:
  1132. cond += 'pattern=%s ' % patt
  1133. cond += 'mapset=%s`' % self.mapset.GetStringSelection()
  1134. return cond
  1135. class ImportDialog(wx.Dialog):
  1136. """!Dialog for bulk import of various data (base class)"""
  1137. def __init__(self, parent, itype,
  1138. id = wx.ID_ANY, title = _("Multiple import"),
  1139. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
  1140. self.parent = parent # GMFrame
  1141. self.importType = itype
  1142. self.options = dict() # list of options
  1143. self.commandId = -1 # id of running command
  1144. wx.Dialog.__init__(self, parent, id, title, style = style,
  1145. name = "MultiImportDialog")
  1146. self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
  1147. self.layerBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  1148. label = _(" List of %s layers ") % self.importType.upper())
  1149. #
  1150. # list of layers
  1151. #
  1152. columns = [_('Layer id'),
  1153. _('Layer name'),
  1154. _('Name for GRASS map (editable)')]
  1155. if itype == 'ogr':
  1156. columns.insert(2, _('Feature type'))
  1157. self.list = LayersList(parent = self.panel, columns = columns)
  1158. self.list.LoadData()
  1159. self.optionBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  1160. label = "%s" % _("Options"))
  1161. cmd = self._getCommand()
  1162. task = gtask.parse_interface(cmd)
  1163. for f in task.get_options()['flags']:
  1164. name = f.get('name', '')
  1165. desc = f.get('label', '')
  1166. if not desc:
  1167. desc = f.get('description', '')
  1168. if not name and not desc:
  1169. continue
  1170. if cmd == 'r.in.gdal' and name not in ('o', 'e', 'l', 'k'):
  1171. continue
  1172. elif cmd == 'r.external' and name not in ('o', 'e', 'r', 'h', 'v'):
  1173. continue
  1174. elif cmd == 'v.in.ogr' and name not in ('c', 'z', 't', 'o', 'r', 'e', 'w'):
  1175. continue
  1176. elif cmd == 'v.external' and name not in ('b'):
  1177. continue
  1178. elif cmd == 'v.in.dxf' and name not in ('e', 't', 'b', 'f', 'i'):
  1179. continue
  1180. self.options[name] = wx.CheckBox(parent = self.panel, id = wx.ID_ANY,
  1181. label = desc)
  1182. self.overwrite = wx.CheckBox(parent = self.panel, id = wx.ID_ANY,
  1183. label = _("Allow output files to overwrite existing files"))
  1184. self.overwrite.SetValue(UserSettings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled'))
  1185. self.add = wx.CheckBox(parent = self.panel, id = wx.ID_ANY)
  1186. #
  1187. # buttons
  1188. #
  1189. # cancel
  1190. self.btn_cancel = wx.Button(parent = self.panel, id = wx.ID_CANCEL)
  1191. self.btn_cancel.SetToolTipString(_("Close dialog"))
  1192. self.btn_cancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  1193. # run
  1194. self.btn_run = wx.Button(parent = self.panel, id = wx.ID_OK, label = _("&Import"))
  1195. self.btn_run.SetToolTipString(_("Import selected layers"))
  1196. self.btn_run.SetDefault()
  1197. self.btn_run.Enable(False)
  1198. self.btn_run.Bind(wx.EVT_BUTTON, self.OnRun)
  1199. # run command dialog
  1200. self.btn_cmd = wx.Button(parent = self.panel, id = wx.ID_ANY,
  1201. label = _("Command dialog"))
  1202. self.btn_cmd.Bind(wx.EVT_BUTTON, self.OnCmdDialog)
  1203. def doLayout(self):
  1204. """!Do layout"""
  1205. dialogSizer = wx.BoxSizer(wx.VERTICAL)
  1206. # dsn input
  1207. dialogSizer.Add(item = self.dsnInput, proportion = 0,
  1208. flag = wx.EXPAND)
  1209. #
  1210. # list of DXF layers
  1211. #
  1212. layerSizer = wx.StaticBoxSizer(self.layerBox, wx.HORIZONTAL)
  1213. layerSizer.Add(item = self.list, proportion = 1,
  1214. flag = wx.ALL | wx.EXPAND, border = 5)
  1215. dialogSizer.Add(item = layerSizer, proportion = 1,
  1216. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
  1217. # options
  1218. optionSizer = wx.StaticBoxSizer(self.optionBox, wx.VERTICAL)
  1219. for key in self.options.keys():
  1220. optionSizer.Add(item = self.options[key], proportion = 0)
  1221. dialogSizer.Add(item = optionSizer, proportion = 0,
  1222. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
  1223. dialogSizer.Add(item = self.overwrite, proportion = 0,
  1224. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
  1225. dialogSizer.Add(item = self.add, proportion = 0,
  1226. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
  1227. #
  1228. # buttons
  1229. #
  1230. btnsizer = wx.BoxSizer(orient = wx.HORIZONTAL)
  1231. btnsizer.Add(item = self.btn_cmd, proportion = 0,
  1232. flag = wx.ALL | wx.ALIGN_CENTER,
  1233. border = 10)
  1234. btnsizer.Add(item = self.btn_run, proportion = 0,
  1235. flag = wx.ALL | wx.ALIGN_CENTER,
  1236. border = 10)
  1237. btnsizer.Add(item = self.btn_cancel, proportion = 0,
  1238. flag = wx.ALL | wx.ALIGN_CENTER,
  1239. border = 10)
  1240. dialogSizer.Add(item = btnsizer, proportion = 0,
  1241. flag = wx.ALIGN_CENTER)
  1242. # dialogSizer.SetSizeHints(self.panel)
  1243. self.panel.SetAutoLayout(True)
  1244. self.panel.SetSizer(dialogSizer)
  1245. dialogSizer.Fit(self.panel)
  1246. # auto-layout seems not work here - FIXME
  1247. size = wx.Size(globalvar.DIALOG_GSELECT_SIZE[0] + 225, 550)
  1248. self.SetMinSize(size)
  1249. self.SetSize((size.width, size.height + 100))
  1250. # width = self.GetSize()[0]
  1251. # self.list.SetColumnWidth(col = 1, width = width / 2 - 50)
  1252. self.Layout()
  1253. def _getCommand(self):
  1254. """!Get command"""
  1255. return ''
  1256. def OnCancel(self, event = None):
  1257. """!Close dialog"""
  1258. self.Close()
  1259. def OnRun(self, event):
  1260. """!Import/Link data (each layes as separate vector map)"""
  1261. pass
  1262. def OnCmdDialog(self, event):
  1263. """!Show command dialog"""
  1264. pass
  1265. def AddLayers(self, returncode, cmd = None):
  1266. """!Add imported/linked layers into layer tree"""
  1267. self.commandId += 1
  1268. if not self.add.IsChecked() or returncode != 0:
  1269. return
  1270. maptree = self.parent.curr_page.maptree
  1271. layer, output = self.list.GetLayers()[self.commandId]
  1272. if '@' not in output:
  1273. name = output + '@' + grass.gisenv()['MAPSET']
  1274. else:
  1275. name = output
  1276. # add imported layers into layer tree
  1277. if self.importType == 'gdal':
  1278. cmd = ['d.rast',
  1279. 'map=%s' % name]
  1280. if UserSettings.Get(group = 'cmd', key = 'rasterOverlay', subkey = 'enabled'):
  1281. cmd.append('-o')
  1282. item = maptree.AddLayer(ltype = 'raster',
  1283. lname = name, lchecked = False,
  1284. lcmd = cmd)
  1285. else:
  1286. item = maptree.AddLayer(ltype = 'vector',
  1287. lname = name, lchecked = False,
  1288. lcmd = ['d.vect',
  1289. 'map=%s' % name])
  1290. maptree.mapdisplay.MapWindow.ZoomToMap()
  1291. def OnAbort(self, event):
  1292. """!Abort running import
  1293. @todo not yet implemented
  1294. """
  1295. pass
  1296. class GdalImportDialog(ImportDialog):
  1297. def __init__(self, parent, ogr = False, link = False):
  1298. """!Dialog for bulk import of various raster/vector data
  1299. @param parent parent window
  1300. @param ogr True for OGR (vector) otherwise GDAL (raster)
  1301. @param link True for linking data otherwise importing data
  1302. """
  1303. self.link = link
  1304. self.ogr = ogr
  1305. if ogr:
  1306. ImportDialog.__init__(self, parent, itype = 'ogr')
  1307. if link:
  1308. self.SetTitle(_("Link external vector data"))
  1309. else:
  1310. self.SetTitle(_("Import vector data"))
  1311. else:
  1312. ImportDialog.__init__(self, parent, itype = 'gdal')
  1313. if link:
  1314. self.SetTitle(_("Link external raster data"))
  1315. else:
  1316. self.SetTitle(_("Import raster data"))
  1317. self.dsnInput = gselect.GdalSelect(parent = self, panel = self.panel, ogr = ogr)
  1318. if link:
  1319. self.add.SetLabel(_("Add linked layers into layer tree"))
  1320. else:
  1321. self.add.SetLabel(_("Add imported layers into layer tree"))
  1322. self.add.SetValue(UserSettings.Get(group = 'cmd', key = 'addNewLayer', subkey = 'enabled'))
  1323. if link:
  1324. self.btn_run.SetLabel(_("&Link"))
  1325. self.btn_run.SetToolTipString(_("Link selected layers"))
  1326. if ogr:
  1327. self.btn_cmd.SetToolTipString(_('Open %s dialog') % 'v.external')
  1328. else:
  1329. self.btn_cmd.SetToolTipString(_('Open %s dialog') % 'r.external')
  1330. else:
  1331. self.btn_run.SetLabel(_("&Import"))
  1332. self.btn_run.SetToolTipString(_("Import selected layers"))
  1333. if ogr:
  1334. self.btn_cmd.SetToolTipString(_('Open %s dialog') % 'v.in.ogr')
  1335. else:
  1336. self.btn_cmd.SetToolTipString(_('Open %s dialog') % 'r.in.gdal')
  1337. self.doLayout()
  1338. def OnRun(self, event):
  1339. """!Import/Link data (each layes as separate vector map)"""
  1340. data = self.list.GetLayers()
  1341. # hide dialog
  1342. self.Hide()
  1343. dsn = self.dsnInput.GetDsn()
  1344. ext = self.dsnInput.GetFormatExt()
  1345. for layer, output in data:
  1346. if self.importType == 'ogr':
  1347. if ext and layer.rfind(ext) > -1:
  1348. layer = layer.replace('.' + ext, '')
  1349. if self.link:
  1350. cmd = ['v.external',
  1351. 'dsn=%s' % dsn,
  1352. 'output=%s' % output,
  1353. 'layer=%s' % layer]
  1354. else:
  1355. cmd = ['v.in.ogr',
  1356. 'dsn=%s' % dsn,
  1357. 'layer=%s' % layer,
  1358. 'output=%s' % output]
  1359. else: # gdal
  1360. if self.dsnInput.GetType() == 'dir':
  1361. idsn = os.path.join(dsn, layer)
  1362. else:
  1363. idsn = dsn
  1364. if self.link:
  1365. cmd = ['r.external',
  1366. 'input=%s' % idsn,
  1367. 'output=%s' % output]
  1368. else:
  1369. cmd = ['r.in.gdal',
  1370. 'input=%s' % idsn,
  1371. 'output=%s' % output]
  1372. if self.overwrite.IsChecked():
  1373. cmd.append('--overwrite')
  1374. for key in self.options.keys():
  1375. if self.options[key].IsChecked():
  1376. cmd.append('-%s' % key)
  1377. if UserSettings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled'):
  1378. cmd.append('--overwrite')
  1379. # run in Layer Manager
  1380. self.parent.goutput.RunCmd(cmd, switchPage = True,
  1381. onDone = self.AddLayers)
  1382. self.OnCancel()
  1383. def _getCommand(self):
  1384. """!Get command"""
  1385. if self.link:
  1386. if self.ogr:
  1387. return 'v.external'
  1388. else:
  1389. return 'r.external'
  1390. else:
  1391. if self.ogr:
  1392. return 'v.in.ogr'
  1393. else:
  1394. return 'r.in.gdal'
  1395. return ''
  1396. def OnCmdDialog(self, event):
  1397. """!Show command dialog"""
  1398. name = self._getCommand()
  1399. menuform.GUI(parent = self, modal = True).ParseCommand(cmd = [name])
  1400. class GdalOutputDialog(wx.Dialog):
  1401. def __init__(self, parent, id = wx.ID_ANY, ogr = False,
  1402. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, *kwargs):
  1403. """!Dialog for setting output format for rasters/vectors
  1404. @param parent parent window
  1405. @param id window id
  1406. @param ogr True for OGR (vector) otherwise GDAL (raster)
  1407. @param style window style
  1408. @param *kwargs other wx.Dialog's arguments
  1409. """
  1410. self.parent = parent # GMFrame
  1411. self.ogr = ogr
  1412. wx.Dialog.__init__(self, parent, id = id, style = style, *kwargs)
  1413. if self.ogr:
  1414. self.SetTitle(_("Define output format for vector data"))
  1415. else:
  1416. self.SetTitle(_("Define output format for raster data"))
  1417. self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
  1418. # buttons
  1419. self.btnCancel = wx.Button(parent = self.panel, id = wx.ID_CANCEL)
  1420. self.btnCancel.SetToolTipString(_("Close dialog"))
  1421. self.btnOk = wx.Button(parent = self.panel, id = wx.ID_OK)
  1422. self.btnOk.SetToolTipString(_("Set external format and close dialog"))
  1423. self.btnOk.SetDefault()
  1424. self.btnOk.Enable(False)
  1425. self.dsnInput = gselect.GdalSelect(parent = self, panel = self.panel,
  1426. ogr = ogr,
  1427. exclude = ['file', 'protocol'], dest = True)
  1428. self.Bind(wx.EVT_BUTTON, self.OnCancel, self.btnCancel)
  1429. self.Bind(wx.EVT_BUTTON, self.OnOK, self.btnOk)
  1430. self._layout()
  1431. def _layout(self):
  1432. dialogSizer = wx.BoxSizer(wx.VERTICAL)
  1433. dialogSizer.Add(item = self.dsnInput, proportion = 0,
  1434. flag = wx.EXPAND)
  1435. btnSizer = wx.StdDialogButtonSizer()
  1436. btnSizer.AddButton(self.btnOk)
  1437. btnSizer.AddButton(self.btnCancel)
  1438. btnSizer.Realize()
  1439. dialogSizer.Add(item = btnSizer, proportion = 0,
  1440. flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
  1441. border = 5)
  1442. self.panel.SetAutoLayout(True)
  1443. self.panel.SetSizer(dialogSizer)
  1444. dialogSizer.Fit(self.panel)
  1445. size = wx.Size(globalvar.DIALOG_GSELECT_SIZE[0] + 225, self.GetBestSize()[1])
  1446. self.SetMinSize(size)
  1447. self.SetSize((size.width, size.height))
  1448. self.Layout()
  1449. def OnCancel(self, event):
  1450. self.Destroy()
  1451. def OnOK(self, event):
  1452. if self.dsnInput.GetType() == 'native':
  1453. gcmd.RunCommand('v.external.out',
  1454. parent = self,
  1455. flags = 'r')
  1456. else:
  1457. dsn = self.dsnInput.GetDsn()
  1458. frmt = self.dsnInput.GetFormat()
  1459. options = self.dsnInput.GetOptions()
  1460. gcmd.RunCommand('v.external.out',
  1461. parent = self,
  1462. dsn = dsn, format = frmt,
  1463. options = options)
  1464. self.Close()
  1465. class DxfImportDialog(ImportDialog):
  1466. """!Dialog for bulk import of DXF layers"""
  1467. def __init__(self, parent):
  1468. ImportDialog.__init__(self, parent, itype = 'dxf',
  1469. title = _("Import DXF layers"))
  1470. self.dsnInput = filebrowse.FileBrowseButton(parent = self.panel, id = wx.ID_ANY,
  1471. size = globalvar.DIALOG_GSELECT_SIZE, labelText = '',
  1472. dialogTitle = _('Choose DXF file to import'),
  1473. buttonText = _('Browse'),
  1474. startDirectory = os.getcwd(), fileMode = 0,
  1475. changeCallback = self.OnSetDsn,
  1476. fileMask = "DXF File (*.dxf)|*.dxf")
  1477. self.add.SetLabel(_("Add imported layers into layer tree"))
  1478. self.add.SetValue(UserSettings.Get(group = 'cmd', key = 'addNewLayer', subkey = 'enabled'))
  1479. self.doLayout()
  1480. def _getCommand(self):
  1481. """!Get command"""
  1482. return 'v.in.dxf'
  1483. def OnRun(self, event):
  1484. """!Import/Link data (each layes as separate vector map)"""
  1485. data = self.list.GetLayers()
  1486. # hide dialog
  1487. self.Hide()
  1488. inputDxf = self.dsnInput.GetValue()
  1489. for layer, output in data:
  1490. cmd = ['v.in.dxf',
  1491. 'input=%s' % inputDxf,
  1492. 'layers=%s' % layer,
  1493. 'output=%s' % output]
  1494. for key in self.options.keys():
  1495. if self.options[key].IsChecked():
  1496. cmd.append('-%s' % key)
  1497. if self.overwrite.IsChecked() or \
  1498. UserSettings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled'):
  1499. cmd.append('--overwrite')
  1500. # run in Layer Manager
  1501. self.parent.goutput.RunCmd(cmd, switchPage = True,
  1502. onDone = self.AddLayers)
  1503. self.OnCancel()
  1504. def OnSetDsn(self, event):
  1505. """!Input DXF file defined, update list of layer widget"""
  1506. path = event.GetString()
  1507. if not path:
  1508. return
  1509. data = list()
  1510. ret = gcmd.RunCommand('v.in.dxf',
  1511. quiet = True,
  1512. parent = self,
  1513. read = True,
  1514. flags = 'l',
  1515. input = path)
  1516. if not ret:
  1517. self.list.LoadData()
  1518. self.btn_run.Enable(False)
  1519. return
  1520. for line in ret.splitlines():
  1521. layerId = line.split(':')[0].split(' ')[1]
  1522. layerName = line.split(':')[1].strip()
  1523. grassName = utils.GetValidLayerName(layerName)
  1524. data.append((layerId, layerName.strip(), grassName.strip()))
  1525. self.list.LoadData(data)
  1526. if len(data) > 0:
  1527. self.btn_run.Enable(True)
  1528. else:
  1529. self.btn_run.Enable(False)
  1530. def OnCmdDialog(self, event):
  1531. """!Show command dialog"""
  1532. menuform.GUI(parent = self, modal = True).ParseCommand(cmd = ['v.in.dxf'])
  1533. class LayersList(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin,
  1534. listmix.CheckListCtrlMixin, listmix.TextEditMixin):
  1535. """!List of layers to be imported (dxf, shp...)"""
  1536. def __init__(self, parent, columns, log = None):
  1537. self.parent = parent
  1538. wx.ListCtrl.__init__(self, parent, wx.ID_ANY,
  1539. style = wx.LC_REPORT)
  1540. listmix.CheckListCtrlMixin.__init__(self)
  1541. self.log = log
  1542. # setup mixins
  1543. listmix.ListCtrlAutoWidthMixin.__init__(self)
  1544. listmix.TextEditMixin.__init__(self)
  1545. for i in range(len(columns)):
  1546. self.InsertColumn(i, columns[i])
  1547. if len(columns) == 3:
  1548. width = (65, 200)
  1549. else:
  1550. width = (65, 200, 90)
  1551. for i in range(len(width)):
  1552. self.SetColumnWidth(col = i, width = width[i])
  1553. self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnPopupMenu) #wxMSW
  1554. self.Bind(wx.EVT_RIGHT_UP, self.OnPopupMenu) #wxGTK
  1555. def LoadData(self, data = None):
  1556. """!Load data into list"""
  1557. if data is None:
  1558. return
  1559. self.DeleteAllItems()
  1560. for item in data:
  1561. index = self.InsertStringItem(sys.maxint, str(item[0]))
  1562. for i in range(1, len(item)):
  1563. self.SetStringItem(index, i, "%s" % str(item[i]))
  1564. # check by default
  1565. ### self.CheckItem(index, True)
  1566. def OnPopupMenu(self, event):
  1567. """!Show popup menu"""
  1568. if self.GetItemCount() < 1:
  1569. return
  1570. if not hasattr(self, "popupDataID1"):
  1571. self.popupDataID1 = wx.NewId()
  1572. self.popupDataID2 = wx.NewId()
  1573. self.Bind(wx.EVT_MENU, self.OnSelectAll, id = self.popupDataID1)
  1574. self.Bind(wx.EVT_MENU, self.OnSelectNone, id = self.popupDataID2)
  1575. # generate popup-menu
  1576. menu = wx.Menu()
  1577. menu.Append(self.popupDataID1, _("Select all"))
  1578. menu.Append(self.popupDataID2, _("Deselect all"))
  1579. self.PopupMenu(menu)
  1580. menu.Destroy()
  1581. def OnSelectAll(self, event):
  1582. """!Select all items"""
  1583. item = -1
  1584. while True:
  1585. item = self.GetNextItem(item)
  1586. if item == -1:
  1587. break
  1588. self.CheckItem(item, True)
  1589. event.Skip()
  1590. def OnSelectNone(self, event):
  1591. """!Deselect items"""
  1592. item = -1
  1593. while True:
  1594. item = self.GetNextItem(item, wx.LIST_STATE_SELECTED)
  1595. if item == -1:
  1596. break
  1597. self.CheckItem(item, False)
  1598. event.Skip()
  1599. def OnLeftDown(self, event):
  1600. """!Allow editing only output name
  1601. Code taken from TextEditMixin class.
  1602. """
  1603. x, y = event.GetPosition()
  1604. colLocs = [0]
  1605. loc = 0
  1606. for n in range(self.GetColumnCount()):
  1607. loc = loc + self.GetColumnWidth(n)
  1608. colLocs.append(loc)
  1609. col = bisect(colLocs, x + self.GetScrollPos(wx.HORIZONTAL)) - 1
  1610. if col == self.GetColumnCount() - 1:
  1611. listmix.TextEditMixin.OnLeftDown(self, event)
  1612. else:
  1613. event.Skip()
  1614. def GetLayers(self):
  1615. """!Get list of layers (layer name, output name)"""
  1616. data = []
  1617. item = -1
  1618. while True:
  1619. item = self.GetNextItem(item)
  1620. if item == -1:
  1621. break
  1622. if not self.IsChecked(item):
  1623. continue
  1624. # layer / output name
  1625. data.append((self.GetItem(item, 1).GetText(),
  1626. self.GetItem(item, self.GetColumnCount() - 1).GetText()))
  1627. return data
  1628. class SetOpacityDialog(wx.Dialog):
  1629. """!Set opacity of map layers"""
  1630. def __init__(self, parent, id = wx.ID_ANY, title = _("Set Map Layer Opacity"),
  1631. size = wx.DefaultSize, pos = wx.DefaultPosition,
  1632. style = wx.DEFAULT_DIALOG_STYLE, opacity = 100):
  1633. self.parent = parent # GMFrame
  1634. self.opacity = opacity # current opacity
  1635. super(SetOpacityDialog, self).__init__(parent, id = id, pos = pos,
  1636. size = size, style = style, title = title)
  1637. panel = wx.Panel(parent = self, id = wx.ID_ANY)
  1638. sizer = wx.BoxSizer(wx.VERTICAL)
  1639. box = wx.GridBagSizer(vgap = 5, hgap = 5)
  1640. self.value = wx.Slider(panel, id = wx.ID_ANY, value = self.opacity,
  1641. style = wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | \
  1642. wx.SL_TOP | wx.SL_LABELS,
  1643. minValue = 0, maxValue = 100,
  1644. size = (350, -1))
  1645. box.Add(item = self.value,
  1646. flag = wx.ALIGN_CENTRE, pos = (0, 0), span = (1, 2))
  1647. box.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1648. label = _("transparent")),
  1649. pos = (1, 0))
  1650. box.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1651. label = _("opaque")),
  1652. flag = wx.ALIGN_RIGHT,
  1653. pos = (1, 1))
  1654. sizer.Add(item = box, proportion = 0,
  1655. flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border = 5)
  1656. line = wx.StaticLine(parent = panel, id = wx.ID_ANY,
  1657. style = wx.LI_HORIZONTAL)
  1658. sizer.Add(item = line, proportion = 0,
  1659. flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border = 5)
  1660. # buttons
  1661. btnsizer = wx.StdDialogButtonSizer()
  1662. btnOK = wx.Button(parent = panel, id = wx.ID_OK)
  1663. btnOK.SetDefault()
  1664. btnsizer.AddButton(btnOK)
  1665. btnCancel = wx.Button(parent = panel, id = wx.ID_CANCEL)
  1666. btnsizer.AddButton(btnCancel)
  1667. btnsizer.Realize()
  1668. sizer.Add(item = btnsizer, proportion = 0,
  1669. flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border = 5)
  1670. panel.SetSizer(sizer)
  1671. sizer.Fit(panel)
  1672. self.SetSize(self.GetBestSize())
  1673. self.Layout()
  1674. def GetOpacity(self):
  1675. """!Button 'OK' pressed"""
  1676. # return opacity value
  1677. opacity = float(self.value.GetValue()) / 100
  1678. return opacity
  1679. def GetImageHandlers(image):
  1680. """!Get list of supported image handlers"""
  1681. lext = list()
  1682. ltype = list()
  1683. for h in image.GetHandlers():
  1684. lext.append(h.GetExtension())
  1685. filetype = ''
  1686. if 'png' in lext:
  1687. filetype += "PNG file (*.png)|*.png|"
  1688. ltype.append({ 'type' : wx.BITMAP_TYPE_PNG,
  1689. 'ext' : 'png' })
  1690. filetype += "BMP file (*.bmp)|*.bmp|"
  1691. ltype.append({ 'type' : wx.BITMAP_TYPE_BMP,
  1692. 'ext' : 'bmp' })
  1693. if 'gif' in lext:
  1694. filetype += "GIF file (*.gif)|*.gif|"
  1695. ltype.append({ 'type' : wx.BITMAP_TYPE_GIF,
  1696. 'ext' : 'gif' })
  1697. if 'jpg' in lext:
  1698. filetype += "JPG file (*.jpg)|*.jpg|"
  1699. ltype.append({ 'type' : wx.BITMAP_TYPE_JPEG,
  1700. 'ext' : 'jpg' })
  1701. if 'pcx' in lext:
  1702. filetype += "PCX file (*.pcx)|*.pcx|"
  1703. ltype.append({ 'type' : wx.BITMAP_TYPE_PCX,
  1704. 'ext' : 'pcx' })
  1705. if 'pnm' in lext:
  1706. filetype += "PNM file (*.pnm)|*.pnm|"
  1707. ltype.append({ 'type' : wx.BITMAP_TYPE_PNM,
  1708. 'ext' : 'pnm' })
  1709. if 'tif' in lext:
  1710. filetype += "TIF file (*.tif)|*.tif|"
  1711. ltype.append({ 'type' : wx.BITMAP_TYPE_TIF,
  1712. 'ext' : 'tif' })
  1713. if 'xpm' in lext:
  1714. filetype += "XPM file (*.xpm)|*.xpm"
  1715. ltype.append({ 'type' : wx.BITMAP_TYPE_XPM,
  1716. 'ext' : 'xpm' })
  1717. return filetype, ltype
  1718. class StaticWrapText(wx.StaticText):
  1719. """!A Static Text field that wraps its text to fit its width,
  1720. enlarging its height if necessary.
  1721. """
  1722. def __init__(self, parent, id = wx.ID_ANY, label = '', *args, **kwds):
  1723. self.parent = parent
  1724. self.originalLabel = label
  1725. wx.StaticText.__init__(self, parent, id, label = '', *args, **kwds)
  1726. self.SetLabel(label)
  1727. self.Bind(wx.EVT_SIZE, self.OnResize)
  1728. def SetLabel(self, label):
  1729. self.originalLabel = label
  1730. self.wrappedSize = None
  1731. self.OnResize(None)
  1732. def OnResize(self, event):
  1733. if not getattr(self, "resizing", False):
  1734. self.resizing = True
  1735. newSize = wx.Size(self.parent.GetSize().width - 50,
  1736. self.GetSize().height)
  1737. if self.wrappedSize != newSize:
  1738. wx.StaticText.SetLabel(self, self.originalLabel)
  1739. self.Wrap(newSize.width)
  1740. self.wrappedSize = newSize
  1741. self.SetSize(self.wrappedSize)
  1742. del self.resizing
  1743. class ImageSizeDialog(wx.Dialog):
  1744. """!Set size for saved graphic file"""
  1745. def __init__(self, parent, id = wx.ID_ANY, title = _("Set image size"),
  1746. style = wx.DEFAULT_DIALOG_STYLE, **kwargs):
  1747. self.parent = parent
  1748. wx.Dialog.__init__(self, parent, id = id, style = style, title = title, **kwargs)
  1749. self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
  1750. self.box = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  1751. label = ' % s' % _("Image size"))
  1752. size = self.parent.GetWindow().GetClientSize()
  1753. self.width = wx.SpinCtrl(parent = self.panel, id = wx.ID_ANY,
  1754. style = wx.SP_ARROW_KEYS)
  1755. self.width.SetRange(20, 1e6)
  1756. self.width.SetValue(size.width)
  1757. wx.CallAfter(self.width.SetFocus)
  1758. self.height = wx.SpinCtrl(parent = self.panel, id = wx.ID_ANY,
  1759. style = wx.SP_ARROW_KEYS)
  1760. self.height.SetRange(20, 1e6)
  1761. self.height.SetValue(size.height)
  1762. self.template = wx.Choice(parent = self.panel, id = wx.ID_ANY,
  1763. size = (125, -1),
  1764. choices = [ "",
  1765. "640x480",
  1766. "800x600",
  1767. "1024x768",
  1768. "1280x960",
  1769. "1600x1200",
  1770. "1920x1440" ])
  1771. self.btnOK = wx.Button(parent = self.panel, id = wx.ID_OK)
  1772. self.btnOK.SetDefault()
  1773. self.btnCancel = wx.Button(parent = self.panel, id = wx.ID_CANCEL)
  1774. self.template.Bind(wx.EVT_CHOICE, self.OnTemplate)
  1775. self._layout()
  1776. self.SetSize(self.GetBestSize())
  1777. def _layout(self):
  1778. """!Do layout"""
  1779. sizer = wx.BoxSizer(wx.VERTICAL)
  1780. # body
  1781. box = wx.StaticBoxSizer(self.box, wx.HORIZONTAL)
  1782. fbox = wx.FlexGridSizer(cols = 2, vgap = 5, hgap = 5)
  1783. fbox.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  1784. label = _("Width:")),
  1785. flag = wx.ALIGN_CENTER_VERTICAL)
  1786. fbox.Add(item = self.width)
  1787. fbox.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  1788. label = _("Height:")),
  1789. flag = wx.ALIGN_CENTER_VERTICAL)
  1790. fbox.Add(item = self.height)
  1791. fbox.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
  1792. label = _("Template:")),
  1793. flag = wx.ALIGN_CENTER_VERTICAL)
  1794. fbox.Add(item = self.template)
  1795. box.Add(item = fbox, proportion = 1,
  1796. flag = wx.EXPAND | wx.ALL, border = 5)
  1797. sizer.Add(item = box, proportion = 1,
  1798. flag=wx.EXPAND | wx.ALL, border = 3)
  1799. # buttons
  1800. btnsizer = wx.StdDialogButtonSizer()
  1801. btnsizer.AddButton(self.btnOK)
  1802. btnsizer.AddButton(self.btnCancel)
  1803. btnsizer.Realize()
  1804. sizer.Add(item = btnsizer, proportion = 0,
  1805. flag = wx.EXPAND | wx.ALIGN_RIGHT | wx.ALL, border=5)
  1806. self.panel.SetSizer(sizer)
  1807. sizer.Fit(self.panel)
  1808. self.Layout()
  1809. def GetValues(self):
  1810. """!Get width/height values"""
  1811. return self.width.GetValue(), self.height.GetValue()
  1812. def OnTemplate(self, event):
  1813. """!Template selected"""
  1814. sel = event.GetString()
  1815. if not sel:
  1816. width, height = self.parent.GetWindow().GetClientSize()
  1817. else:
  1818. width, height = map(int, sel.split('x'))
  1819. self.width.SetValue(width)
  1820. self.height.SetValue(height)
  1821. class SqlQueryFrame(wx.Frame):
  1822. def __init__(self, parent, id = wx.ID_ANY,
  1823. title = _("GRASS GIS SQL Query Utility"),
  1824. *kwargs):
  1825. """!SQL Query Utility window
  1826. """
  1827. self.parent = parent
  1828. wx.Frame.__init__(self, parent = parent, id = id, title = title, *kwargs)
  1829. self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass_sql.ico'), wx.BITMAP_TYPE_ICO))
  1830. self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
  1831. self.sqlBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
  1832. label = _(" SQL statement "))
  1833. self.sql = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY,
  1834. style = wx.TE_MULTILINE)
  1835. self.btnApply = wx.Button(parent = self.panel, id = wx.ID_APPLY)
  1836. self.btnCancel = wx.Button(parent = self.panel, id = wx.ID_CANCEL)
  1837. self.Bind(wx.EVT_BUTTON, self.OnCloseWindow, self.btnCancel)
  1838. self._layout()
  1839. self.SetMinSize(wx.Size(300, 150))
  1840. self.SetSize(wx.Size(500, 200))
  1841. def _layout(self):
  1842. """!Do layout"""
  1843. sizer = wx.BoxSizer(wx.VERTICAL)
  1844. sqlSizer = wx.StaticBoxSizer(self.sqlBox, wx.HORIZONTAL)
  1845. sqlSizer.Add(item = self.sql, proportion = 1,
  1846. flag = wx.EXPAND)
  1847. btnSizer = wx.StdDialogButtonSizer()
  1848. btnSizer.AddButton(self.btnApply)
  1849. btnSizer.AddButton(self.btnCancel)
  1850. btnSizer.Realize()
  1851. sizer.Add(item = sqlSizer, proportion = 1,
  1852. flag = wx.EXPAND | wx.ALL, border = 5)
  1853. sizer.Add(item = btnSizer, proportion = 0,
  1854. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
  1855. self.panel.SetSizer(sizer)
  1856. self.Layout()
  1857. def OnCloseWindow(self, event):
  1858. """!Close window
  1859. """
  1860. self.Close()