dialogs.py 86 KB

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