4 @brief Various dialogs used in wxGUI.
18 - LayersList (used by MultiImport)
23 (C) 2008-2011 by the GRASS Development Team
25 This program is free software under the GNU General Public
26 License (>=v2). Read the file COPYING that comes with GRASS
29 @author Martin Landa <landa.martin gmail.com>
35 from bisect
import bisect
38 import wx.lib.filebrowsebutton
as filebrowse
39 import wx.lib.mixins.listctrl
as listmix
49 from debug
import Debug
50 from preferences
import globalSettings
as UserSettings
53 def __init__(self, parent, title, label, id = wx.ID_ANY,
54 etype =
False, style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
56 """!General dialog to choose given element (location, mapset, vector map, etc.)
59 @param title window title
60 @param label element label
61 @param etype show also ElementSelect
63 wx.Dialog.__init__(self, parent, id, title, style = style, **kwargs)
68 self.
panel = wx.Panel(parent = self, id = wx.ID_ANY)
71 self.
btnOK = wx.Button(parent = self.
panel, id = wx.ID_OK)
72 self.btnOK.SetDefault()
73 self.btnOK.Enable(
False)
77 size = globalvar.DIALOG_GSELECT_SIZE)
78 self.typeSelect.Bind(wx.EVT_CHOICE, self.
OnType)
85 self.element.SetFocus()
86 self.element.Bind(wx.EVT_TEXT, self.
OnElement)
89 """!Select element type"""
92 evalue = self.typeSelect.GetValue(event.GetString())
93 self.element.SetType(evalue)
96 """!Name for vector map layer given"""
97 if len(event.GetString()) > 0:
98 self.btnOK.Enable(
True)
100 self.btnOK.Enable(
False)
104 self.
sizer = wx.BoxSizer(wx.VERTICAL)
109 self.dataSizer.Add(item = wx.StaticText(parent = self.
panel, id = wx.ID_ANY,
110 label = _(
"Type of element:")),
111 proportion=0, flag=wx.ALL, border=1)
113 proportion=0, flag=wx.ALL, border=1)
115 self.dataSizer.Add(item = wx.StaticText(parent = self.
panel, id = wx.ID_ANY,
117 proportion=0, flag=wx.ALL, border=1)
120 btnSizer = wx.StdDialogButtonSizer()
122 btnSizer.AddButton(self.
btnOK)
125 self.sizer.Add(item=self.
dataSizer, proportion=1,
126 flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
128 self.sizer.Add(item=btnSizer, proportion=0,
129 flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
132 """!Return (mapName, overwrite)"""
133 return self.element.GetValue()
136 """!Get element type"""
137 return self.element.tcp.GetType()
140 """!Dialog used to select location"""
141 def __init__(self, parent, title = _(
"Select GRASS location and mapset"), id = wx.ID_ANY):
142 ElementDialog.__init__(self, parent, title, label = _(
"Name of GRASS location:"))
145 size = globalvar.DIALOG_GSELECT_SIZE)
148 size = globalvar.DIALOG_GSELECT_SIZE,
154 self.SetMinSize(self.GetSize())
158 self.dataSizer.Add(self.
element, proportion=0,
159 flag=wx.EXPAND | wx.ALL, border=1)
161 self.dataSizer.Add(wx.StaticText(parent = self.
panel, id = wx.ID_ANY,
162 label = _(
"Name of mapset:")), proportion=0,
163 flag=wx.EXPAND | wx.ALL, border=1)
165 self.dataSizer.Add(self.
element1, proportion=0,
166 flag=wx.EXPAND | wx.ALL, border=1)
168 self.panel.SetSizer(self.
sizer)
172 """!Select mapset given location name"""
173 location = event.GetString()
176 dbase = grass.gisenv()[
'GISDBASE']
177 self.element1.SetItems(utils.GetListOfMapsets(dbase, location, selectable =
True))
178 self.element1.SetSelection(0)
179 mapset = self.element1.GetStringSelection()
181 if location
and mapset:
182 self.btnOK.Enable(
True)
184 self.btnOK.Enable(
False)
187 """!Get location, mapset"""
188 return (self.
GetElement(), self.element1.GetStringSelection())
191 """!Dialog used to select mapset"""
192 def __init__(self, parent, title = _(
"Select mapset in GRASS location"),
193 location =
None, id = wx.ID_ANY):
194 ElementDialog.__init__(self, parent, title, label = _(
"Name of mapset:"))
196 self.SetTitle(self.GetTitle() +
' <%s>' % location)
198 self.SetTitle(self.GetTitle() +
' <%s>' % grass.gisenv()[
'LOCATION_NAME'])
201 size = globalvar.DIALOG_GSELECT_SIZE)
206 self.SetMinSize(self.GetSize())
210 self.dataSizer.Add(self.
element, proportion=0,
211 flag=wx.EXPAND | wx.ALL, border=1)
213 self.panel.SetSizer(self.
sizer)
220 def __init__(self, parent, id = wx.ID_ANY, title = _(
'Create new vector map'),
221 disableAdd =
False, disableTable =
False,
222 style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, *kwargs):
223 """!Dialog for creating new vector map
225 @param parent parent window
227 @param title window title
228 @param disableAdd disable 'add layer' checkbox
229 @param disableTable disable 'create table' checkbox
230 @param style window style
231 @param kwargs other argumentes for ElementDialog
233 @return dialog instance
235 ElementDialog.__init__(self, parent, title, label = _(
"Name for new vector map:"))
238 type =
'vector', mapsets = [grass.gisenv()[
'MAPSET'],])
240 self.
table = wx.CheckBox(parent = self.
panel, id = wx.ID_ANY,
241 label = _(
"Create attribute table"))
242 self.table.SetValue(
True)
244 self.table.Enable(
False)
247 size = globalvar.DIALOG_SPIN_SIZE)
248 self.keycol.SetValue(UserSettings.Get(group =
'atm', key =
'keycolumn', subkey =
'value'))
250 self.keycol.Enable(
False)
253 label = _(
'Add created map into layer tree'), style = wx.NO_BORDER)
255 self.addbox.SetValue(
True)
256 self.addbox.Enable(
False)
258 self.addbox.SetValue(UserSettings.Get(group =
'cmd', key =
'addNewLayer', subkey =
'enabled'))
260 self.table.Bind(wx.EVT_CHECKBOX, self.
OnTable)
265 self.SetMinSize(self.GetSize())
268 """!Name for vector map layer given"""
272 self.keycol.Enable(event.IsChecked())
276 self.dataSizer.Add(self.
element, proportion = 0,
277 flag = wx.EXPAND | wx.ALL, border = 1)
279 self.dataSizer.Add(self.
table, proportion = 0,
280 flag = wx.EXPAND | wx.ALL, border = 1)
282 keySizer = wx.BoxSizer(wx.HORIZONTAL)
283 keySizer.Add(item = wx.StaticText(parent = self.
panel, label = _(
"Key column:")),
285 flag = wx.ALIGN_CENTER_VERTICAL)
286 keySizer.AddSpacer(10)
287 keySizer.Add(item = self.
keycol, proportion = 0,
288 flag = wx.ALIGN_RIGHT)
289 self.dataSizer.Add(item = keySizer, proportion = 1,
290 flag = wx.EXPAND | wx.ALL, border = 1)
292 self.dataSizer.AddSpacer(5)
294 self.dataSizer.Add(item = self.
addbox, proportion = 0,
295 flag = wx.EXPAND | wx.ALL, border = 1)
297 self.panel.SetSizer(self.
sizer)
301 """!Get name of vector map to be created
303 @param full True to get fully qualified name
310 return name +
'@' + grass.gisenv()[
'MAPSET']
312 return name.split(
'@', 1)[0]
315 """!Get key column name"""
316 return self.keycol.GetValue()
319 """!Get dialog properties
321 @param key window key ('add', 'table')
324 @return None on error
327 return self.addbox.IsChecked()
329 return self.table.IsChecked()
334 exceptMap =
None, log =
None, disableAdd =
False, disableTable =
False):
335 """!Create new vector map layer
337 @param cmd (prog, **kwargs)
338 @param title window title
339 @param exceptMap list of maps to be excepted
341 @param disableAdd disable 'add layer' checkbox
342 @param disableTable disable 'create table' checkbox
344 @return dialog instance
345 @return None on error
348 disableAdd = disableAdd, disableTable = disableTable)
350 if dlg.ShowModal() != wx.ID_OK:
354 outmap = dlg.GetName()
356 if outmap == exceptMap:
358 message = _(
"Unable to create vector map <%s>.") % outmap)
361 if dlg.table.IsEnabled()
and not key:
363 message = _(
"Invalid or empty key column.\n"
364 "Unable to create vector map <%s>.") % outmap)
373 cmd[1][cmd[2]] = outmap
375 listOfVectors = grass.list_grouped(
'vect')[grass.gisenv()[
'MAPSET']]
378 if not UserSettings.Get(group =
'cmd', key =
'overwrite', subkey =
'enabled')
and \
379 outmap
in listOfVectors:
380 dlgOw = wx.MessageDialog(parent, message = _(
"Vector map <%s> already exists "
381 "in the current mapset. "
382 "Do you want to overwrite it?") % outmap,
383 caption = _(
"Overwrite?"),
384 style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
385 if dlgOw.ShowModal() == wx.ID_YES:
392 if UserSettings.Get(group =
'cmd', key =
'overwrite', subkey =
'enabled'):
395 ret = gcmd.RunCommand(prog = cmd[0],
397 overwrite = overwrite,
404 if dlg.table.IsEnabled()
and dlg.table.IsChecked():
405 sql =
'CREATE TABLE %s (%s INTEGER)' % (outmap, key)
407 gcmd.RunCommand(
'db.connect',
410 Debug.msg(1,
"SQL: %s" % sql)
411 gcmd.RunCommand(
'db.execute',
416 gcmd.RunCommand(
'v.db.connect',
425 if '@' not in outmap:
426 outmap +=
'@' + grass.gisenv()[
'MAPSET']
429 log.WriteLog(_(
"New vector map <%s> created") % outmap)
434 def __init__(self, parent, id = wx.ID_ANY, title="", loadsave='load',
436 """!Loading and saving of display extents to saved region file
438 @param loadsave load or save region?
440 wx.Dialog.__init__(self, parent, id, title, **kwargs)
445 sizer = wx.BoxSizer(wx.VERTICAL)
447 box = wx.BoxSizer(wx.HORIZONTAL)
448 label = wx.StaticText(parent=self, id=wx.ID_ANY)
449 box.Add(item=label, proportion=0, flag=wx.ALIGN_CENTRE | wx.ALL, border=5)
450 if loadsave ==
'load':
451 label.SetLabel(_(
"Load region:"))
452 selection =
gselect.Select(parent=self, id=wx.ID_ANY, size=globalvar.DIALOG_GSELECT_SIZE,
454 elif loadsave ==
'save':
455 label.SetLabel(_(
"Save region:"))
456 selection =
gselect.Select(parent=self, id=wx.ID_ANY, size=globalvar.DIALOG_GSELECT_SIZE,
457 type=
'windows', mapsets = [grass.gisenv()[
'MAPSET']])
459 box.Add(item=selection, proportion=0, flag=wx.ALIGN_CENTRE | wx.ALL, border=5)
461 selection.Bind(wx.EVT_TEXT, self.
OnRegion)
463 sizer.Add(item=box, proportion=0, flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL,
466 line = wx.StaticLine(parent=self, id=wx.ID_ANY, size=(20, -1), style=wx.LI_HORIZONTAL)
467 sizer.Add(item=line, proportion=0,
468 flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border=5)
470 btnsizer = wx.StdDialogButtonSizer()
472 btn = wx.Button(parent = self, id = wx.ID_OK)
474 btnsizer.AddButton(btn)
476 btn = wx.Button(parent = self, id = wx.ID_CANCEL)
477 btnsizer.AddButton(btn)
480 sizer.Add(item=btnsizer, proportion=0, flag=wx.ALIGN_RIGHT | wx.ALL, border=5)
487 self.
wind = event.GetString()
491 Controls setting options and displaying/hiding map overlay decorations
493 def __init__(self, parent, ovlId, title, cmd, name=None,
494 pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE,
495 checktxt=
'', ctrltxt=
''):
497 wx.Dialog.__init__(self, parent, wx.ID_ANY, title, pos, size, style)
504 sizer = wx.BoxSizer(wx.VERTICAL)
506 box = wx.BoxSizer(wx.HORIZONTAL)
507 self.
chkbox = wx.CheckBox(parent=self, id=wx.ID_ANY, label=checktxt)
508 if self.parent.Map.GetOverlay(self.
ovlId)
is None:
509 self.chkbox.SetValue(
True)
511 self.chkbox.SetValue(self.parent.MapWindow.overlays[self.
ovlId][
'layer'].IsActive())
512 box.Add(item=self.
chkbox, proportion=0,
513 flag=wx.ALIGN_CENTRE|wx.ALL, border=5)
514 sizer.Add(item=box, proportion=0,
515 flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
517 box = wx.BoxSizer(wx.HORIZONTAL)
518 optnbtn = wx.Button(parent=self, id=wx.ID_ANY, label=_(
"Set options"))
519 box.Add(item=optnbtn, proportion=0, flag=wx.ALIGN_CENTRE|wx.ALL, border=5)
520 sizer.Add(item=box, proportion=0,
521 flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
523 box = wx.BoxSizer(wx.HORIZONTAL)
524 label = wx.StaticText(parent=self, id=wx.ID_ANY,
525 label=_(
"Drag %s with mouse in pointer mode to position.\n"
526 "Double-click to change options." % ctrltxt))
527 if self.
name ==
'legend':
528 label.SetLabel(label.GetLabel() + _(
'\nDefine raster map name for legend in '
529 'properties dialog.'))
530 box.Add(item=label, proportion=0,
531 flag=wx.ALIGN_CENTRE|wx.ALL, border=5)
532 sizer.Add(item=box, proportion=0,
533 flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
535 line = wx.StaticLine(parent=self, id=wx.ID_ANY, size=(20,-1), style=wx.LI_HORIZONTAL)
536 sizer.Add(item=line, proportion=0,
537 flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
540 btnsizer = wx.StdDialogButtonSizer()
542 self.
btnOK = wx.Button(parent=self, id=wx.ID_OK)
543 self.btnOK.SetDefault()
544 if self.
name ==
'legend':
545 self.btnOK.Enable(
False)
546 btnsizer.AddButton(self.
btnOK)
548 btnCancel = wx.Button(parent=self, id=wx.ID_CANCEL)
549 btnsizer.AddButton(btnCancel)
552 sizer.Add(item=btnsizer, proportion=0,
553 flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
558 self.Bind(wx.EVT_BUTTON, self.
OnOptions, optnbtn)
559 self.Bind(wx.EVT_BUTTON, self.
OnCancel, btnCancel)
560 self.Bind(wx.EVT_BUTTON, self.
OnOK, self.
btnOK)
568 if len(self.parent.MapWindow.overlays[self.
ovlId][
'cmd']) > 1:
569 mapName, found = utils.GetLayerNameFromCmd(self.parent.MapWindow.overlays[self.
ovlId][
'cmd'])
570 if self.parent.MapWindow.overlays[self.
ovlId][
'propwin']
is None and mapName:
580 self.SetTitle(_(
'Legend of raster map <%s>') % \
583 def _CreateOverlay(self):
584 if not self.parent.Map.GetOverlay(self.
ovlId):
585 overlay = self.parent.Map.AddOverlay(id=self.
ovlId, type=self.
name,
587 l_active=
False, l_render=
False, l_hidden=
True)
589 self.parent.MapWindow.overlays[self.
ovlId] = {}
590 self.parent.MapWindow.overlays[self.
ovlId] = {
'layer' : overlay,
597 if self.parent.MapWindow.overlays[self.
ovlId][
'propwin'] ==
None:
600 self.parent.MapWindow.overlays[self.
ovlId][
'propwin'].get_dcmd = self.
GetOptData
604 """ self.SetSizer(sizer)
607 Sets option for decoration map overlays
609 if self.parent.MapWindow.overlays[self.
ovlId][
'propwin']
is None:
615 if self.parent.MapWindow.overlays[self.
ovlId][
'propwin'].IsShown():
616 self.parent.MapWindow.overlays[self.
ovlId][
'propwin'].SetFocus()
618 self.parent.MapWindow.overlays[self.
ovlId][
'propwin'].Show()
622 self.parent.dialogs[
'barscale'] =
None
627 """!Button 'OK' pressed"""
629 self.parent.Map.GetOverlay(self.
ovlId).SetActive(self.chkbox.IsChecked())
632 self.parent.MapWindow.UpdateMap()
638 """!Process decoration layer data"""
641 self.parent.MapWindow.overlays[self.
ovlId][
'params'] = params
643 self.parent.MapWindow.overlays[self.
ovlId][
'cmd'] = dcmd
644 self.parent.MapWindow.overlays[self.
ovlId][
'propwin'] = propwin
650 self.parent.MapWindow.overlays[self.
ovlId][
'cmd'].remove(
'-m')
654 self.parent.Map.ChangeOverlay(id=self.
ovlId, type=self.
name,
655 command=self.parent.MapWindow.overlays[self.
ovlId][
'cmd'],
656 l_active=self.parent.MapWindow.overlays[self.
ovlId][
'layer'].IsActive(),
657 l_render=
False, l_hidden=
True)
658 if self.
name ==
'legend':
659 if params
and not self.btnOK.IsEnabled():
664 Controls setting options and displaying/hiding map overlay decorations
667 def __init__(self, parent, ovlId, title, name='text',
668 pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE):
670 wx.Dialog.__init__(self, parent, wx.ID_ANY, title, pos, size, style)
671 from wx.lib.expando
import ExpandoTextCtrl, EVT_ETC_LAYOUT_NEEDED
676 if self.
ovlId in self.parent.MapWindow.textdict.keys():
689 self.
sizer = wx.BoxSizer(wx.VERTICAL)
690 box = wx.GridBagSizer(vgap=5, hgap=5)
693 self.
chkbox = wx.CheckBox(parent=self, id=wx.ID_ANY, \
694 label = _(
'Show text object'))
695 if self.parent.Map.GetOverlay(self.
ovlId)
is None:
696 self.chkbox.SetValue(
True)
698 self.chkbox.SetValue(self.parent.MapWindow.overlays[self.
ovlId][
'layer'].IsActive())
699 box.Add(item=self.
chkbox, span=(1,2),
700 flag=wx.ALIGN_LEFT|wx.ALL, border=5,
704 label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Enter text:"))
706 flag=wx.ALIGN_CENTER_VERTICAL,
709 self.
textentry = ExpandoTextCtrl(parent=self, id=wx.ID_ANY, value=
"", size=(300,-1))
710 self.textentry.SetFont(self.
currFont)
711 self.textentry.SetForegroundColour(self.
currClr)
712 self.textentry.SetValue(self.
currText)
714 self.textentry.SetClientSize((300,-1))
720 label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Rotation:"))
722 flag=wx.ALIGN_CENTER_VERTICAL,
724 self.
rotation = wx.SpinCtrl(parent=self, id=wx.ID_ANY, value=
"", pos=(30, 50),
725 size=(75,-1), style=wx.SP_ARROW_KEYS)
726 self.rotation.SetRange(-360, 360)
727 self.rotation.SetValue(int(self.
currRot))
733 fontbtn = wx.Button(parent=self, id=wx.ID_ANY, label=_(
"Set font"))
734 box.Add(item=fontbtn,
738 self.sizer.Add(item=box, proportion=1,
739 flag=wx.ALL, border=10)
742 box = wx.BoxSizer(wx.HORIZONTAL)
743 label = wx.StaticText(parent=self, id=wx.ID_ANY,
744 label=_(
"Drag text with mouse in pointer mode "
745 "to position.\nDouble-click to change options"))
746 box.Add(item=label, proportion=0,
747 flag=wx.ALIGN_CENTRE | wx.ALL, border=5)
748 self.sizer.Add(item=box, proportion=0,
749 flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER | wx.ALL, border=5)
751 line = wx.StaticLine(parent=self, id=wx.ID_ANY,
752 size=(20,-1), style=wx.LI_HORIZONTAL)
753 self.sizer.Add(item=line, proportion=0,
754 flag=wx.EXPAND | wx.ALIGN_CENTRE | wx.ALL, border=5)
756 btnsizer = wx.StdDialogButtonSizer()
758 btn = wx.Button(parent=self, id=wx.ID_OK)
760 btnsizer.AddButton(btn)
762 btn = wx.Button(parent=self, id=wx.ID_CANCEL)
763 btnsizer.AddButton(btn)
766 self.sizer.Add(item=btnsizer, proportion=0,
767 flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
769 self.SetSizer(self.
sizer)
779 """!Resize text entry to match text"""
783 """!Change text string"""
787 """!Change rotation"""
795 data.EnableEffects(
True)
799 dlg = wx.FontDialog(self, data)
801 if dlg.ShowModal() == wx.ID_OK:
802 data = dlg.GetFontData()
803 self.
currFont = data.GetChosenFont()
804 self.
currClr = data.GetColour()
806 self.textentry.SetFont(self.
currFont)
807 self.textentry.SetForegroundColour(self.
currClr)
814 """!Get text properties"""
820 'active' : self.chkbox.IsChecked() }
823 """!Add selected map layers (raster, vector) into layer tree"""
824 def __init__(self, parent, title, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
825 wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY, title=title, style=style)
836 self.mapset.GetStringSelection())
840 btnCancel = wx.Button(parent = self, id = wx.ID_CANCEL)
841 btnOk = wx.Button(parent = self, id = wx.ID_OK, label = _(
"&Add"))
843 btnOk.SetToolTipString(_(
"Add selected map layers to current display"))
848 btnSizer = wx.StdDialogButtonSizer()
849 btnSizer.AddButton(btnCancel)
850 btnSizer.AddButton(btnOk)
853 mainSizer = wx.BoxSizer(wx.VERTICAL)
854 mainSizer.Add(item=self.
bodySizer, proportion=1,
855 flag=wx.EXPAND | wx.ALL, border=5)
856 mainSizer.Add(item=btnSizer, proportion=0,
857 flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
859 self.SetSizer(mainSizer)
863 self.SetMinSize(self.GetSize())
865 def __createDialogBody(self):
866 bodySizer = wx.GridBagSizer(vgap=3, hgap=3)
867 bodySizer.AddGrowableCol(1)
868 bodySizer.AddGrowableRow(3)
871 bodySizer.Add(item=wx.StaticText(parent=self, label=_(
"Map layer type:")),
872 flag=wx.ALIGN_CENTER_VERTICAL,
876 choices=[
'raster',
'vector'], size=(100,-1))
877 self.layerType.SetSelection(0)
882 self.
toggle = wx.CheckBox(parent=self, id=wx.ID_ANY,
883 label=_(
"Select toggle"))
884 self.toggle.SetValue(
True)
885 bodySizer.Add(item=self.
toggle,
886 flag=wx.ALIGN_CENTER_VERTICAL,
890 bodySizer.Add(item=wx.StaticText(parent=self, label=_(
"Mapset:")),
891 flag=wx.ALIGN_CENTER_VERTICAL,
895 self.mapset.SetStringSelection(grass.gisenv()[
'MAPSET'])
896 bodySizer.Add(item=self.
mapset,
897 pos=(1,1), span=(1, 2))
900 bodySizer.Add(item=wx.StaticText(parent=self, label=_(
"Filter:")),
901 flag=wx.ALIGN_CENTER_VERTICAL,
904 self.
filter = wx.TextCtrl(parent=self, id=wx.ID_ANY,
907 bodySizer.Add(item=self.
filter,
909 pos=(2,1), span=(1, 2))
912 bodySizer.Add(item=wx.StaticText(parent=self, label=_(
"List of maps:")),
913 flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_TOP,
915 self.
layers = wx.CheckListBox(parent=self, id=wx.ID_ANY,
918 bodySizer.Add(item=self.
layers,
920 pos=(3,1), span=(1, 2))
925 self.layers.Bind(wx.EVT_RIGHT_DOWN, self.
OnMenu)
926 self.filter.Bind(wx.EVT_TEXT, self.
OnFilter)
927 self.toggle.Bind(wx.EVT_CHECKBOX, self.
OnToggle)
931 """!Load list of map layers
933 @param type layer type ('raster' or 'vector')
934 @param mapset mapset name
936 self.
map_layers = grass.mlist_grouped(type = type)[mapset]
940 for item
in range(self.layers.GetCount()):
941 self.layers.Check(item)
944 """!Filter parameters changed by user"""
947 self.mapset.GetStringSelection())
952 """!Table description area, context menu"""
953 if not hasattr(self,
"popupID1"):
972 """!Select all map layer from list"""
973 for item
in range(self.layers.GetCount()):
974 self.layers.Check(item,
True)
977 """!Invert current selection"""
978 for item
in range(self.layers.GetCount()):
979 if self.layers.IsChecked(item):
980 self.layers.Check(item,
False)
982 self.layers.Check(item,
True)
985 """!Select all map layer from list"""
986 for item
in range(self.layers.GetCount()):
987 self.layers.Check(item,
False)
990 """!Apply filter for map names"""
991 if len(event.GetString()) == 0:
998 if re.compile(
'^' + event.GetString()).search(layer):
1003 self.layers.Set(list)
1009 """!Select toggle (check or uncheck all layers)"""
1010 check = event.Checked()
1011 for item
in range(self.layers.GetCount()):
1012 self.layers.Check(item, check)
1017 """!Return list of checked map layers"""
1019 for indx
in self.layers.GetSelections():
1024 mapset = self.mapset.GetStringSelection()
1025 for item
in range(self.layers.GetCount()):
1026 if not self.layers.IsChecked(item):
1028 layerNames.append(self.layers.GetString(item) +
'@' + mapset)
1033 """!Get selected layer type"""
1034 return self.layerType.GetStringSelection()
1037 """!Dialog for bulk import of various data (base class)"""
1039 id = wx.ID_ANY, title = _(
"Multiple import"),
1040 style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
1047 wx.Dialog.__init__(self, parent, id, title, style=style,
1048 name =
"MultiImportDialog")
1050 self.
panel = wx.Panel(parent=self, id=wx.ID_ANY)
1053 label=_(
" List of %s layers ") % self.importType.upper())
1059 self.list.LoadData()
1062 label=
"%s" % _(
"Options"))
1065 task = gtask.parse_interface(cmd)
1066 for f
in task.get_options()[
'flags']:
1067 name = f.get(
'name',
'')
1068 desc = f.get(
'label',
'')
1070 desc = f.get(
'description',
'')
1071 if not name
and not desc:
1073 if cmd ==
'r.in.gdal' and name
not in (
'o',
'e',
'l',
'k'):
1075 elif cmd ==
'r.external' and name
not in (
'o',
'e',
'r', 'h', 'v'):
1077 elif cmd ==
'v.in.ogr' and name
not in (
'c',
'z',
't',
'o',
'r', 'e', 'w'):
1079 elif cmd ==
'v.external' and name
not in (
'b'):
1081 elif cmd ==
'v.in.dxf' and name
not in (
'e',
't',
'b',
'f',
'i'):
1083 self.
options[name] = wx.CheckBox(parent = self.
panel, id = wx.ID_ANY,
1088 label=_(
"Allow output files to overwrite existing files"))
1089 self.overwrite.SetValue(UserSettings.Get(group=
'cmd', key=
'overwrite', subkey=
'enabled'))
1091 self.
add = wx.CheckBox(parent=self.
panel, id=wx.ID_ANY)
1098 self.btn_cancel.SetToolTipString(_(
"Close dialog"))
1099 self.btn_cancel.Bind(wx.EVT_BUTTON, self.
OnCancel)
1101 self.
btn_run = wx.Button(parent=self.
panel, id=wx.ID_OK, label = _(
"&Import"))
1102 self.btn_run.SetToolTipString(_(
"Import selected layers"))
1103 self.btn_run.SetDefault()
1104 self.btn_run.Enable(
False)
1105 self.btn_run.Bind(wx.EVT_BUTTON, self.
OnRun)
1108 label = _(
"Command dialog"))
1109 self.btn_cmd.Bind(wx.EVT_BUTTON, self.
OnCmdDialog)
1113 dialogSizer = wx.BoxSizer(wx.VERTICAL)
1116 dialogSizer.Add(item = self.dsnInput, proportion = 0,
1122 layerSizer = wx.StaticBoxSizer(self.
layerBox, wx.HORIZONTAL)
1124 layerSizer.Add(item=self.
list, proportion=1,
1125 flag=wx.ALL | wx.EXPAND, border=5)
1127 dialogSizer.Add(item=layerSizer, proportion=1,
1128 flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=5)
1131 optionSizer = wx.StaticBoxSizer(self.
optionBox, wx.VERTICAL)
1132 for key
in self.options.keys():
1133 optionSizer.Add(item=self.
options[key], proportion=0)
1135 dialogSizer.Add(item=optionSizer, proportion=0,
1136 flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=5)
1138 dialogSizer.Add(item=self.
overwrite, proportion=0,
1139 flag=wx.LEFT | wx.RIGHT | wx.BOTTOM, border=5)
1141 dialogSizer.Add(item=self.
add, proportion=0,
1142 flag=wx.LEFT | wx.RIGHT | wx.BOTTOM, border=5)
1147 btnsizer = wx.BoxSizer(orient=wx.HORIZONTAL)
1149 btnsizer.Add(item=self.
btn_cmd, proportion=0,
1150 flag=wx.ALL | wx.ALIGN_CENTER,
1153 btnsizer.Add(item=self.
btn_run, proportion=0,
1154 flag=wx.ALL | wx.ALIGN_CENTER,
1157 btnsizer.Add(item=self.
btn_cancel, proportion=0,
1158 flag=wx.ALL | wx.ALIGN_CENTER,
1161 dialogSizer.Add(item=btnsizer, proportion=0,
1162 flag=wx.ALIGN_CENTER)
1165 self.panel.SetAutoLayout(
True)
1166 self.panel.SetSizer(dialogSizer)
1167 dialogSizer.Fit(self.
panel)
1170 size = wx.Size(globalvar.DIALOG_GSELECT_SIZE[0] + 225, 550)
1171 self.SetMinSize(size)
1172 self.SetSize((size.width, size.height + 100))
1173 width = self.GetSize()[0]
1174 self.list.SetColumnWidth(col=1, width=width/2 - 50)
1177 def _getCommand(self):
1186 """!Import/Link data (each layes as separate vector map)"""
1190 """!Show command dialog"""
1194 """!Add imported/linked layers into layer tree"""
1195 if not self.add.IsChecked()
or returncode != 0:
1199 maptree = self.parent.curr_page.maptree
1200 layer, output = self.list.GetLayers()[self.commandId]
1202 if '@' not in output:
1203 name = output +
'@' + grass.gisenv()[
'MAPSET']
1208 if self.importType ==
'gdal':
1211 if UserSettings.Get(group=
'cmd', key=
'rasterOverlay', subkey=
'enabled'):
1214 item = maptree.AddLayer(ltype =
'raster',
1215 lname = name, lchecked =
False,
1218 item = maptree.AddLayer(ltype =
'vector',
1219 lname = name, lchecked =
False,
1223 maptree.mapdisplay.MapWindow.ZoomToMap()
1226 """!Abort running import
1228 @todo not yet implemented
1232 class GdalImportDialog(ImportDialog):
1233 """!Dialog for bulk import of various raster/vector data"""
1239 ImportDialog.__init__(self, parent, itype =
'ogr')
1241 self.SetTitle(_(
"Link external vector data"))
1243 self.SetTitle(_(
"Import vector data"))
1245 ImportDialog.__init__(self, parent, itype =
'gdal')
1247 self.SetTitle(_(
"Link external raster data"))
1249 self.SetTitle(_(
"Import raster data"))
1254 self.add.SetLabel(_(
"Add linked layers into layer tree"))
1256 self.add.SetLabel(_(
"Add imported layers into layer tree"))
1258 self.add.SetValue(UserSettings.Get(group=
'cmd', key=
'addNewLayer', subkey=
'enabled'))
1261 self.btn_run.SetLabel(_(
"&Link"))
1262 self.btn_run.SetToolTipString(_(
"Link selected layers"))
1264 self.btn_cmd.SetToolTipString(_(
'Open %s dialog') %
'v.external')
1266 self.btn_cmd.SetToolTipString(_(
'Open %s dialog') %
'r.external')
1268 self.btn_run.SetLabel(_(
"&Import"))
1269 self.btn_run.SetToolTipString(_(
"Import selected layers"))
1271 self.btn_cmd.SetToolTipString(_(
'Open %s dialog') %
'v.in.ogr')
1273 self.btn_cmd.SetToolTipString(_(
'Open %s dialog') %
'r.in.gdal')
1278 """!Import/Link data (each layes as separate vector map)"""
1280 data = self.list.GetLayers()
1283 message = _(
"No layers marked for import.\nOperation canceled."))
1286 dsn = self.dsnInput.GetDsn()
1287 ext = self.dsnInput.GetFormatExt()
1289 for layer, output
in data:
1291 if ext
and layer.rfind(ext) > -1:
1292 layer = layer.replace(
'.' + ext,
'')
1294 cmd = [
'v.external',
1296 'output=%s' % output,
1302 'output=%s' % output]
1304 if self.dsnInput.GetType() ==
'dir':
1305 idsn = os.path.join(dsn, layer)
1310 cmd = [
'r.external',
1312 'output=%s' % output]
1316 'output=%s' % output]
1318 if self.overwrite.IsChecked():
1319 cmd.append(
'--overwrite')
1321 for key
in self.options.keys():
1322 if self.
options[key].IsChecked():
1323 cmd.append(
'-%s' % key)
1325 if UserSettings.Get(group=
'cmd', key=
'overwrite', subkey=
'enabled'):
1326 cmd.append(
'--overwrite')
1329 self.parent.goutput.RunCmd(cmd, switchPage =
True,
1332 def _getCommand(self):
1348 """!Show command dialog"""
1350 menuform.GUI(parent = self, modal =
True).ParseCommand(cmd = [name])
1353 """!Dialog for bulk import of DXF layers"""
1355 ImportDialog.__init__(self, parent, itype =
'dxf',
1356 title = _(
"Import DXF layers"))
1359 size=globalvar.DIALOG_GSELECT_SIZE, labelText=
'',
1360 dialogTitle=_(
'Choose DXF file to import'),
1361 buttonText=_(
'Browse'),
1362 startDirectory=os.getcwd(), fileMode=0,
1364 fileMask=
"DXF File (*.dxf)|*.dxf")
1366 self.add.SetLabel(_(
"Add imported layers into layer tree"))
1368 self.add.SetValue(UserSettings.Get(group=
'cmd', key=
'addNewLayer', subkey=
'enabled'))
1372 def _getCommand(self):
1377 """!Import/Link data (each layes as separate vector map)"""
1378 data = self.list.GetLayers()
1383 inputDxf = self.dsnInput.GetValue()
1385 for layer, output
in data:
1387 'input=%s' % inputDxf,
1388 'layers=%s' % layer,
1389 'output=%s' % output]
1391 for key
in self.options.keys():
1392 if self.
options[key].IsChecked():
1393 cmd.append(
'-%s' % key)
1395 if self.overwrite.IsChecked()
or \
1396 UserSettings.Get(group=
'cmd', key=
'overwrite', subkey=
'enabled'):
1397 cmd.append(
'--overwrite')
1400 self.parent.goutput.RunCmd(cmd, switchPage=
True,
1406 """!Input DXF file defined, update list of layer widget"""
1407 path = event.GetString()
1412 ret = gcmd.RunCommand(
'v.in.dxf',
1419 self.list.LoadData()
1420 self.btn_run.Enable(
False)
1423 for line
in ret.splitlines():
1424 layerId = line.split(
':')[0].
split(
' ')[1]
1425 layerName = line.split(
':')[1].strip()
1426 grassName = utils.GetValidLayerName(layerName)
1427 data.append((layerId, layerName.strip(), grassName.strip()))
1429 self.list.LoadData(data)
1431 self.btn_run.Enable(
True)
1433 self.btn_run.Enable(
False)
1436 """!Show command dialog"""
1437 menuform.GUI(parent = self, modal =
True).ParseCommand(cmd = [
'v.in.dxf'])
1439 class LayersList(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin,
1440 listmix.CheckListCtrlMixin, listmix.TextEditMixin):
1441 """!List of layers to be imported (dxf, shp...)"""
1442 def __init__(self, parent, pos = wx.DefaultPosition,
1446 wx.ListCtrl.__init__(self, parent, wx.ID_ANY,
1448 listmix.CheckListCtrlMixin.__init__(self)
1452 listmix.ListCtrlAutoWidthMixin.__init__(self)
1453 listmix.TextEditMixin.__init__(self)
1455 self.InsertColumn(0, _(
'Layer id'))
1456 self.InsertColumn(1, _(
'Layer name'))
1457 self.InsertColumn(2, _(
'Name for GRASS map (editable)'))
1459 self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.
OnPopupMenu)
1463 """!Load data into list"""
1467 self.DeleteAllItems()
1469 for id, name, grassName
in data:
1470 index = self.InsertStringItem(sys.maxint, str(id))
1471 self.SetStringItem(index, 1,
"%s" % str(name))
1472 self.SetStringItem(index, 2,
"%s" % str(grassName))
1475 self.CheckItem(0,
True)
1477 self.SetColumnWidth(col = 0, width = wx.LIST_AUTOSIZE_USEHEADER)
1480 """!Show popup menu"""
1481 if self.GetItemCount() < 1:
1484 if not hasattr(self,
"popupDataID1"):
1496 self.PopupMenu(menu)
1500 """!Select all items"""
1504 item = self.GetNextItem(item)
1507 self.CheckItem(item,
True)
1512 """!Deselect items"""
1516 item = self.GetNextItem(item, wx.LIST_STATE_SELECTED)
1519 self.CheckItem(item,
False)
1524 """!Allow editing only output name
1526 Code taken from TextEditMixin class.
1528 x, y = event.GetPosition()
1532 for n
in range(self.GetColumnCount()):
1533 loc = loc + self.GetColumnWidth(n)
1536 col = bisect(colLocs, x + self.GetScrollPos(wx.HORIZONTAL)) - 1
1539 listmix.TextEditMixin.OnLeftDown(self, event)
1544 """!Get list of layers (layer name, output name)"""
1548 item = self.GetNextItem(item)
1551 if self.IsChecked(item):
1553 data.append((self.GetItem(item, 1).GetText(),
1554 self.GetItem(item, 2).GetText()))
1559 """!Set opacity of map layers"""
1560 def __init__(self, parent, id=wx.ID_ANY, title=_(
"Set Map Layer Opacity"),
1561 size=wx.DefaultSize, pos=wx.DefaultPosition,
1562 style=wx.DEFAULT_DIALOG_STYLE, opacity=100):
1567 super(SetOpacityDialog, self).
__init__(parent, id=id, pos=pos,
1568 size=size, style=style, title=title)
1570 panel = wx.Panel(parent=self, id=wx.ID_ANY)
1572 sizer = wx.BoxSizer(wx.VERTICAL)
1574 box = wx.GridBagSizer(vgap=5, hgap=5)
1576 style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | \
1577 wx.SL_TOP | wx.SL_LABELS,
1578 minValue=0, maxValue=100,
1581 box.Add(item=self.
value,
1582 flag=wx.ALIGN_CENTRE, pos=(0, 0), span=(1, 2))
1583 box.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
1584 label=_(
"transparent")),
1586 box.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
1588 flag=wx.ALIGN_RIGHT,
1591 sizer.Add(item=box, proportion=0,
1592 flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
1594 line = wx.StaticLine(parent=panel, id=wx.ID_ANY,
1595 style=wx.LI_HORIZONTAL)
1596 sizer.Add(item=line, proportion=0,
1597 flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
1600 btnsizer = wx.StdDialogButtonSizer()
1602 btnOK = wx.Button(parent=panel, id=wx.ID_OK)
1604 btnsizer.AddButton(btnOK)
1606 btnCancel = wx.Button(parent=panel, id=wx.ID_CANCEL)
1607 btnsizer.AddButton(btnCancel)
1610 sizer.Add(item=btnsizer, proportion=0,
1611 flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border=5)
1613 panel.SetSizer(sizer)
1616 self.SetSize(self.GetBestSize())
1621 """!Button 'OK' pressed"""
1623 opacity = float(self.value.GetValue()) / 100
1627 """!Get list of supported image handlers"""
1630 for h
in image.GetHandlers():
1631 lext.append(h.GetExtension())
1635 filetype +=
"PNG file (*.png)|*.png|"
1636 ltype.append({
'type' : wx.BITMAP_TYPE_PNG,
1638 filetype +=
"BMP file (*.bmp)|*.bmp|"
1639 ltype.append({
'type' : wx.BITMAP_TYPE_BMP,
1642 filetype +=
"GIF file (*.gif)|*.gif|"
1643 ltype.append({
'type' : wx.BITMAP_TYPE_GIF,
1647 filetype +=
"JPG file (*.jpg)|*.jpg|"
1648 ltype.append({
'type' : wx.BITMAP_TYPE_JPEG,
1652 filetype +=
"PCX file (*.pcx)|*.pcx|"
1653 ltype.append({
'type' : wx.BITMAP_TYPE_PCX,
1657 filetype +=
"PNM file (*.pnm)|*.pnm|"
1658 ltype.append({
'type' : wx.BITMAP_TYPE_PNM,
1662 filetype +=
"TIF file (*.tif)|*.tif|"
1663 ltype.append({
'type' : wx.BITMAP_TYPE_TIF,
1667 filetype +=
"XPM file (*.xpm)|*.xpm"
1668 ltype.append({
'type' : wx.BITMAP_TYPE_XPM,
1671 return filetype, ltype
1674 """!A Static Text field that wraps its text to fit its width,
1675 enlarging its height if necessary.
1677 def __init__(self, parent, id = wx.ID_ANY, label = '', *args, **kwds):
1681 wx.StaticText.__init__(self, parent, id, label =
'', *args, **kwds)
1684 self.Bind(wx.EVT_SIZE, self.
OnResize)
1692 if not getattr(self,
"resizing",
False):
1694 newSize = wx.Size(self.parent.GetSize().width - 50,
1695 self.GetSize().height)
1698 self.Wrap(newSize.width)
1705 """!Set size for saved graphic file"""
1706 def __init__(self, parent, id = wx.ID_ANY, title=_(
"Set image size"),
1707 style = wx.DEFAULT_DIALOG_STYLE, **kwargs):
1710 wx.Dialog.__init__(self, parent, id = id, style=style, title=title, **kwargs)
1712 self.
panel = wx.Panel(parent = self, id = wx.ID_ANY)
1714 self.
box = wx.StaticBox(parent = self.
panel, id = wx.ID_ANY,
1715 label =
' % s' % _(
"Image size"))
1717 size = self.parent.GetWindow().GetClientSize()
1719 style = wx.SP_ARROW_KEYS)
1720 self.width.SetRange(20, 1e6)
1721 self.width.SetValue(size.width)
1722 wx.CallAfter(self.width.SetFocus)
1724 style = wx.SP_ARROW_KEYS)
1725 self.height.SetRange(20, 1e6)
1726 self.height.SetValue(size.height)
1738 self.btnOK.SetDefault()
1741 self.template.Bind(wx.EVT_CHOICE, self.
OnTemplate)
1744 self.SetSize(self.GetBestSize())
1748 sizer = wx.BoxSizer(wx.VERTICAL)
1751 box = wx.StaticBoxSizer(self.
box, wx.HORIZONTAL)
1752 fbox = wx.FlexGridSizer(cols = 2, vgap = 5, hgap = 5)
1753 fbox.Add(item = wx.StaticText(parent = self.
panel, id = wx.ID_ANY,
1754 label = _(
"Width:")),
1755 flag = wx.ALIGN_CENTER_VERTICAL)
1756 fbox.Add(item = self.
width)
1757 fbox.Add(item = wx.StaticText(parent = self.
panel, id = wx.ID_ANY,
1758 label = _(
"Height:")),
1759 flag = wx.ALIGN_CENTER_VERTICAL)
1760 fbox.Add(item = self.
height)
1761 fbox.Add(item = wx.StaticText(parent = self.
panel, id = wx.ID_ANY,
1762 label = _(
"Template:")),
1763 flag = wx.ALIGN_CENTER_VERTICAL)
1766 box.Add(item = fbox, proportion = 1,
1767 flag = wx.EXPAND | wx.ALL, border = 5)
1768 sizer.Add(item = box, proportion = 1,
1769 flag=wx.EXPAND | wx.ALL, border = 3)
1772 btnsizer = wx.StdDialogButtonSizer()
1773 btnsizer.AddButton(self.
btnOK)
1777 sizer.Add(item = btnsizer, proportion = 0,
1778 flag = wx.EXPAND | wx.ALIGN_RIGHT | wx.ALL, border=5)
1780 self.panel.SetSizer(sizer)
1781 sizer.Fit(self.
panel)
1785 """!Get width/height values"""
1786 return self.width.GetValue(), self.height.GetValue()
1789 """!Template selected"""
1790 sel = event.GetString()
1792 width, height = self.parent.GetWindow().GetClientSize()
1794 width, height =
map(int, sel.split(
'x'))
1795 self.width.SetValue(width)
1796 self.height.SetValue(height)