gdialogs.py 86 KB

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