2 @package gui_core.dialogs
4 @brief Various dialogs used in wxGUI.
7 - dialogs::ElementDialog
8 - dialogs::LocationDialog
9 - dialogs::MapsetDialog
10 - dialogs::NewVectorDialog
11 - dialogs::SavedRegion
12 - dialogs::DecorationDialog
13 - dialogs::TextLayerDialog
14 - dialogs::GroupDialog
15 - dialogs::MapLayersDialog
16 - dialogs::ImportDialog
17 - dialogs::GdalImportDialog
18 - dialogs::DxfImportDialog
19 - dialogs::LayersList (used by MultiImport)
20 - dialogs::SetOpacityDialog
21 - dialogs::ImageSizeDialog
23 (C) 2008-2011 by the GRASS Development Team
25 This program is free software under the GNU General Public License
26 (>=v2). Read the file COPYING that comes with GRASS for details.
28 @author Martin Landa <landa.martin gmail.com>
29 @author Anna Kratochvilova <kratochanna gmail.com> (GroupDialog)
35 from bisect
import bisect
38 import wx.lib.filebrowsebutton
as filebrowse
39 import wx.lib.mixins.listctrl
as listmix
40 from wx.lib.newevent
import NewEvent
45 from core
import globalvar
46 from core.gcmd import GError, RunCommand, GMessage
47 from gui_core.gselect import ElementSelect, LocationSelect, MapsetSelect, Select, GdalSelect
48 from gui_core.forms
import GUI
50 from core.utils import GetListOfMapsets, GetLayerNameFromCmd, GetValidLayerName
54 wxApplyOpacity, EVT_APPLY_OPACITY = NewEvent()
57 def __init__(self, parent, title, label, id = wx.ID_ANY,
58 etype =
False, style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
60 """!General dialog to choose given element (location, mapset, vector map, etc.)
63 @param title window title
64 @param label element label
65 @param etype show also ElementSelect
67 wx.Dialog.__init__(self, parent, id, title, style = style, **kwargs)
72 self.
panel = wx.Panel(parent = self, id = wx.ID_ANY)
75 self.
btnOK = wx.Button(parent = self.
panel, id = wx.ID_OK)
76 self.btnOK.SetDefault()
77 self.btnOK.Enable(
False)
81 size = globalvar.DIALOG_GSELECT_SIZE)
82 self.typeSelect.Bind(wx.EVT_CHOICE, self.
OnType)
89 self.element.SetFocus()
90 self.element.Bind(wx.EVT_TEXT, self.
OnElement)
93 """!Select element type"""
96 evalue = self.typeSelect.GetValue(event.GetString())
97 self.element.SetType(evalue)
100 """!Name for vector map layer given"""
101 if len(event.GetString()) > 0:
102 self.btnOK.Enable(
True)
104 self.btnOK.Enable(
False)
108 self.
sizer = wx.BoxSizer(wx.VERTICAL)
113 self.dataSizer.Add(item = wx.StaticText(parent = self.
panel, id = wx.ID_ANY,
114 label = _(
"Type of element:")),
115 proportion = 0, flag = wx.ALL, border = 1)
117 proportion = 0, flag = wx.ALL, border = 1)
119 self.dataSizer.Add(item = wx.StaticText(parent = self.
panel, id = wx.ID_ANY,
121 proportion = 0, flag = wx.ALL, border = 1)
124 btnSizer = wx.StdDialogButtonSizer()
126 btnSizer.AddButton(self.
btnOK)
129 self.sizer.Add(item = self.
dataSizer, proportion = 1,
130 flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
132 self.sizer.Add(item = btnSizer, proportion = 0,
133 flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
136 """!Return (mapName, overwrite)"""
137 return self.element.GetValue()
140 """!Get element type"""
141 return self.element.tcp.GetType()
144 """!Dialog used to select location"""
145 def __init__(self, parent, title = _(
"Select GRASS location and mapset"), id = wx.ID_ANY):
146 ElementDialog.__init__(self, parent, title, label = _(
"Name of GRASS location:"))
149 size = globalvar.DIALOG_GSELECT_SIZE)
152 size = globalvar.DIALOG_GSELECT_SIZE,
153 setItems =
False, skipCurrent =
True)
158 self.SetMinSize(self.GetSize())
162 self.dataSizer.Add(self.
element, proportion = 0,
163 flag = wx.EXPAND | wx.ALL, border = 1)
165 self.dataSizer.Add(wx.StaticText(parent = self.
panel, id = wx.ID_ANY,
166 label = _(
"Name of mapset:")), proportion = 0,
167 flag = wx.EXPAND | wx.ALL, border = 1)
169 self.dataSizer.Add(self.
element1, proportion = 0,
170 flag = wx.EXPAND | wx.ALL, border = 1)
172 self.panel.SetSizer(self.
sizer)
176 """!Select mapset given location name"""
177 location = event.GetString()
180 dbase = grass.gisenv()[
'GISDBASE']
181 self.element1.UpdateItems(dbase = dbase, location = location)
182 self.element1.SetSelection(0)
183 mapset = self.element1.GetStringSelection()
185 if location
and mapset:
186 self.btnOK.Enable(
True)
188 self.btnOK.Enable(
False)
191 """!Get location, mapset"""
192 return (self.
GetElement(), self.element1.GetStringSelection())
195 """!Dialog used to select mapset"""
196 def __init__(self, parent, title = _(
"Select mapset in GRASS location"),
197 location =
None, id = wx.ID_ANY):
198 ElementDialog.__init__(self, parent, title, label = _(
"Name of mapset:"))
200 self.SetTitle(self.GetTitle() +
' <%s>' % location)
202 self.SetTitle(self.GetTitle() +
' <%s>' % grass.gisenv()[
'LOCATION_NAME'])
204 self.
element = MapsetSelect(parent = self.
panel, id = wx.ID_ANY, skipCurrent =
True,
205 size = globalvar.DIALOG_GSELECT_SIZE)
210 self.SetMinSize(self.GetSize())
214 self.dataSizer.Add(self.
element, proportion = 0,
215 flag = wx.EXPAND | wx.ALL, border = 1)
217 self.panel.SetSizer(self.
sizer)
224 def __init__(self, parent, id = wx.ID_ANY, title = _(
'Create new vector map'),
225 disableAdd =
False, disableTable =
False,
226 style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, *kwargs):
227 """!Dialog for creating new vector map
229 @param parent parent window
231 @param title window title
232 @param disableAdd disable 'add layer' checkbox
233 @param disableTable disable 'create table' checkbox
234 @param style window style
235 @param kwargs other argumentes for ElementDialog
237 @return dialog instance
239 ElementDialog.__init__(self, parent, title, label = _(
"Name for new vector map:"))
241 self.
element = Select(parent = self.
panel, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
242 type =
'vector', mapsets = [grass.gisenv()[
'MAPSET'],])
244 self.
table = wx.CheckBox(parent = self.
panel, id = wx.ID_ANY,
245 label = _(
"Create attribute table"))
246 self.table.SetValue(
True)
248 self.table.Enable(
False)
251 size = globalvar.DIALOG_SPIN_SIZE)
252 self.keycol.SetValue(UserSettings.Get(group =
'atm', key =
'keycolumn', subkey =
'value'))
254 self.keycol.Enable(
False)
257 label = _(
'Add created map into layer tree'), style = wx.NO_BORDER)
259 self.addbox.SetValue(
True)
260 self.addbox.Enable(
False)
262 self.addbox.SetValue(UserSettings.Get(group =
'cmd', key =
'addNewLayer', subkey =
'enabled'))
264 self.table.Bind(wx.EVT_CHECKBOX, self.
OnTable)
269 self.SetMinSize(self.GetSize())
272 """!Name for vector map layer given"""
276 self.keycol.Enable(event.IsChecked())
280 self.dataSizer.Add(self.
element, proportion = 0,
281 flag = wx.EXPAND | wx.ALL, border = 1)
283 self.dataSizer.Add(self.
table, proportion = 0,
284 flag = wx.EXPAND | wx.ALL, border = 1)
286 keySizer = wx.BoxSizer(wx.HORIZONTAL)
287 keySizer.Add(item = wx.StaticText(parent = self.
panel, label = _(
"Key column:")),
289 flag = wx.ALIGN_CENTER_VERTICAL)
290 keySizer.AddSpacer(10)
291 keySizer.Add(item = self.
keycol, proportion = 0,
292 flag = wx.ALIGN_RIGHT)
293 self.dataSizer.Add(item = keySizer, proportion = 1,
294 flag = wx.EXPAND | wx.ALL, border = 1)
296 self.dataSizer.AddSpacer(5)
298 self.dataSizer.Add(item = self.
addbox, proportion = 0,
299 flag = wx.EXPAND | wx.ALL, border = 1)
301 self.panel.SetSizer(self.
sizer)
305 """!Get name of vector map to be created
307 @param full True to get fully qualified name
314 return name +
'@' + grass.gisenv()[
'MAPSET']
316 return name.split(
'@', 1)[0]
319 """!Get key column name"""
320 return self.keycol.GetValue()
323 """!Get dialog properties
325 @param key window key ('add', 'table')
328 @return None on error
331 return self.addbox.IsChecked()
333 return self.table.IsChecked()
338 exceptMap =
None, log =
None, disableAdd =
False, disableTable =
False):
339 """!Create new vector map layer
341 @param cmd (prog, **kwargs)
342 @param title window title
343 @param exceptMap list of maps to be excepted
345 @param disableAdd disable 'add layer' checkbox
346 @param disableTable disable 'create table' checkbox
348 @return dialog instance
349 @return None on error
352 disableAdd = disableAdd, disableTable = disableTable)
354 if dlg.ShowModal() != wx.ID_OK:
358 outmap = dlg.GetName()
360 if outmap == exceptMap:
361 GError(parent = parent,
362 message = _(
"Unable to create vector map <%s>.") % outmap)
365 if dlg.table.IsEnabled()
and not key:
366 GError(parent = parent,
367 message = _(
"Invalid or empty key column.\n"
368 "Unable to create vector map <%s>.") % outmap)
377 cmd[1][cmd[2]] = outmap
379 listOfVectors = grass.list_grouped(
'vect')[grass.gisenv()[
'MAPSET']]
382 if not UserSettings.Get(group =
'cmd', key =
'overwrite', subkey =
'enabled')
and \
383 outmap
in listOfVectors:
384 dlgOw = wx.MessageDialog(parent, message = _(
"Vector map <%s> already exists "
385 "in the current mapset. "
386 "Do you want to overwrite it?") % outmap,
387 caption = _(
"Overwrite?"),
388 style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
389 if dlgOw.ShowModal() == wx.ID_YES:
396 if UserSettings.Get(group =
'cmd', key =
'overwrite', subkey =
'enabled'):
401 overwrite = overwrite,
408 if dlg.table.IsEnabled()
and dlg.table.IsChecked():
409 sql =
'CREATE TABLE %s (%s INTEGER)' % (outmap, key)
414 Debug.msg(1,
"SQL: %s" % sql)
430 if '@' not in outmap:
431 outmap +=
'@' + grass.gisenv()[
'MAPSET']
434 log.WriteLog(_(
"New vector map <%s> created") % outmap)
439 def __init__(self, parent, id = wx.ID_ANY, title = "", loadsave = 'load',
441 """!Loading and saving of display extents to saved region file
443 @param loadsave load or save region?
445 wx.Dialog.__init__(self, parent, id, title, **kwargs)
450 sizer = wx.BoxSizer(wx.VERTICAL)
452 box = wx.BoxSizer(wx.HORIZONTAL)
453 label = wx.StaticText(parent = self, id = wx.ID_ANY)
454 box.Add(item = label, proportion = 0, flag = wx.ALIGN_CENTRE | wx.ALL, border = 5)
455 if loadsave ==
'load':
456 label.SetLabel(_(
"Load region:"))
457 selection = Select(parent = self, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
459 elif loadsave ==
'save':
460 label.SetLabel(_(
"Save region:"))
461 selection = Select(parent = self, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
462 type =
'windows', mapsets = [grass.gisenv()[
'MAPSET']], fullyQualified =
False)
464 box.Add(item = selection, proportion = 0, flag = wx.ALIGN_CENTRE | wx.ALL, border = 5)
466 selection.Bind(wx.EVT_TEXT, self.
OnRegion)
468 sizer.Add(item = box, proportion = 0, flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL,
471 line = wx.StaticLine(parent = self, id = wx.ID_ANY, size = (20, -1), style = wx.LI_HORIZONTAL)
472 sizer.Add(item = line, proportion = 0,
473 flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border = 5)
475 btnsizer = wx.StdDialogButtonSizer()
477 btn = wx.Button(parent = self, id = wx.ID_OK)
479 btnsizer.AddButton(btn)
481 btn = wx.Button(parent = self, id = wx.ID_CANCEL)
482 btnsizer.AddButton(btn)
485 sizer.Add(item = btnsizer, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
492 self.
wind = event.GetString()
494 DECOR_DIALOG_LEGEND = 0
495 DECOR_DIALOG_BARSCALE = 1
500 def __init__(self, parent, title, overlayController,
503 wx.Dialog.__init__(self, parent, wx.ID_ANY, title, **kwargs)
509 sizer = wx.BoxSizer(wx.VERTICAL)
511 box = wx.BoxSizer(wx.HORIZONTAL)
512 self.
chkbox = wx.CheckBox(parent = self, id = wx.ID_ANY)
513 self.chkbox.SetValue(
True)
515 if self.
_ddstyle == DECOR_DIALOG_LEGEND:
516 self.chkbox.SetLabel(
"Show legend")
518 self.chkbox.SetLabel(
"Show scale and North arrow")
521 box.Add(item = self.
chkbox, proportion = 0,
522 flag = wx.ALIGN_CENTRE|wx.ALL, border = 5)
523 sizer.Add(item = box, proportion = 0,
524 flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
526 box = wx.BoxSizer(wx.HORIZONTAL)
527 optnbtn = wx.Button(parent = self, id = wx.ID_ANY, label = _(
"Set options"))
528 box.Add(item = optnbtn, proportion = 0, flag = wx.ALIGN_CENTRE|wx.ALL, border = 5)
529 sizer.Add(item = box, proportion = 0,
530 flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
531 if self.
_ddstyle == DECOR_DIALOG_LEGEND:
532 box = wx.BoxSizer(wx.HORIZONTAL)
533 self.
resizeBtn = wx.ToggleButton(parent = self, id = wx.ID_ANY, label = _(
"Set size and position"))
534 self.resizeBtn.SetToolTipString(_(
"Click and drag on the map display to set legend "
535 "size and position and then press OK"))
536 self.resizeBtn.Disable()
537 self.resizeBtn.Bind(wx.EVT_TOGGLEBUTTON, self.
OnResize)
538 box.Add(item = self.
resizeBtn, proportion = 0, flag = wx.ALIGN_CENTRE|wx.ALL, border = 5)
539 sizer.Add(item = box, proportion = 0,
540 flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
542 box = wx.BoxSizer(wx.HORIZONTAL)
543 if self.
_ddstyle == DECOR_DIALOG_LEGEND:
544 labelText = _(
"Drag legend object with mouse in pointer mode to position.\n"
545 "Double-click to change options.\n"
546 "Define raster map name for legend in properties dialog.")
548 labelText = _(
"Drag scale object with mouse in pointer mode to position.\n"
549 "Double-click to change options.")
551 label = wx.StaticText(parent = self, id = wx.ID_ANY,
554 box.Add(item = label, proportion = 0,
555 flag = wx.ALIGN_CENTRE|wx.ALL, border = 5)
556 sizer.Add(item = box, proportion = 0,
557 flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
559 line = wx.StaticLine(parent = self, id = wx.ID_ANY, size = (20,-1), style = wx.LI_HORIZONTAL)
560 sizer.Add(item = line, proportion = 0,
561 flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
564 btnsizer = wx.StdDialogButtonSizer()
566 self.
btnOK = wx.Button(parent = self, id = wx.ID_OK)
567 self.btnOK.SetDefault()
568 self.btnOK.Enable(self.
_ddstyle != DECOR_DIALOG_LEGEND)
569 btnsizer.AddButton(self.
btnOK)
571 btnCancel = wx.Button(parent = self, id = wx.ID_CANCEL)
572 btnsizer.AddButton(btnCancel)
575 sizer.Add(item = btnsizer, proportion = 0,
576 flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border = 5)
581 optnbtn.Bind(wx.EVT_BUTTON, self.
OnOptions)
582 btnCancel.Bind(wx.EVT_BUTTON,
lambda evt: self.
CloseDialog())
583 self.btnOK.Bind(wx.EVT_BUTTON, self.
OnOK)
592 if not self.parent.IsPaneShown(
'3d'):
593 self.resizeBtn.Enable()
596 self.SetTitle(_(
'Legend of raster map <%s>') % \
600 """!Sets option for decoration map overlays
602 if self._overlay.propwin
is None:
604 GUI(parent = self.
parent).ParseCommand(cmd = self._overlay.cmd,
605 completed = (self.
GetOptData, self._overlay.name,
''))
608 if self._overlay.propwin.IsShown():
609 self._overlay.propwin.SetFocus()
611 self._overlay.propwin.Show()
615 self.parent.MapWindow.SetCursor(self.parent.cursors[
"cross"])
616 self.parent.MapWindow.mouse[
'use'] =
'legend'
617 self.parent.MapWindow.mouse[
'box'] =
'box'
618 self.parent.MapWindow.pen = wx.Pen(colour =
'Black', width = 2, style = wx.SHORT_DASH)
620 self.parent.MapWindow.SetCursor(self.parent.cursors[
"default"])
621 self.parent.MapWindow.mouse[
'use'] =
'pointer'
625 if self.
_ddstyle == DECOR_DIALOG_LEGEND
and self.resizeBtn.GetValue():
626 self.resizeBtn.SetValue(
False)
632 """!Button 'OK' pressed"""
634 self._overlay.Show(self.chkbox.IsChecked())
637 if self.parent.IsPaneShown(
'3d'):
638 self.parent.MapWindow.UpdateOverlays()
640 self.parent.MapWindow.UpdateMap()
646 """!Process decoration layer data"""
648 self._overlay.cmd = dcmd
649 self._overlay.propwin = propwin
652 if self.
_ddstyle == DECOR_DIALOG_LEGEND
and not self.parent.IsPaneShown(
'3d'):
653 self.resizeBtn.Enable()
658 Controls setting options and displaying/hiding map overlay decorations
661 def __init__(self, parent, ovlId, title, name = 'text',
662 pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_DIALOG_STYLE):
664 wx.Dialog.__init__(self, parent, wx.ID_ANY, title, pos, size, style)
665 from wx.lib.expando
import ExpandoTextCtrl, EVT_ETC_LAYOUT_NEEDED
670 if self.
ovlId in self.parent.MapWindow.textdict.keys():
685 self.
sizer = wx.BoxSizer(wx.VERTICAL)
686 box = wx.GridBagSizer(vgap = 5, hgap = 5)
689 self.
chkbox = wx.CheckBox(parent = self, id = wx.ID_ANY,
690 label = _(
'Show text object'))
691 if self.parent.Map.GetOverlay(self.
ovlId)
is None:
692 self.chkbox.SetValue(
True)
694 self.chkbox.SetValue(self.parent.MapWindow.overlays[self.
ovlId][
'layer'].IsActive())
695 box.Add(item = self.
chkbox, span = (1,2),
696 flag = wx.ALIGN_LEFT|wx.ALL, border = 5,
700 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _(
"Enter text:"))
701 box.Add(item = label,
702 flag = wx.ALIGN_CENTER_VERTICAL,
705 self.
textentry = ExpandoTextCtrl(parent = self, id = wx.ID_ANY, value =
"", size = (300,-1))
706 self.textentry.SetFont(self.
currFont)
707 self.textentry.SetForegroundColour(self.
currClr)
708 self.textentry.SetValue(self.
currText)
710 self.textentry.SetClientSize((300,-1))
716 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _(
"Rotation:"))
717 box.Add(item = label,
718 flag = wx.ALIGN_CENTER_VERTICAL,
720 self.
rotation = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value =
"", pos = (30, 50),
721 size = (75,-1), style = wx.SP_ARROW_KEYS)
722 self.rotation.SetRange(-360, 360)
723 self.rotation.SetValue(int(self.
currRot))
725 flag = wx.ALIGN_RIGHT,
729 fontbtn = wx.Button(parent = self, id = wx.ID_ANY, label = _(
"Set font"))
730 box.Add(item = fontbtn,
731 flag = wx.ALIGN_RIGHT,
734 self.sizer.Add(item = box, proportion = 1,
735 flag = wx.ALL, border = 10)
738 box = wx.BoxSizer(wx.HORIZONTAL)
739 label = wx.StaticText(parent = self, id = wx.ID_ANY,
740 label = _(
"Drag text with mouse in pointer mode "
741 "to position.\nDouble-click to change options"))
742 box.Add(item = label, proportion = 0,
743 flag = wx.ALIGN_CENTRE | wx.ALL, border = 5)
744 self.sizer.Add(item = box, proportion = 0,
745 flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER | wx.ALL, border = 5)
747 line = wx.StaticLine(parent = self, id = wx.ID_ANY,
748 size = (20,-1), style = wx.LI_HORIZONTAL)
749 self.sizer.Add(item = line, proportion = 0,
750 flag = wx.EXPAND | wx.ALIGN_CENTRE | wx.ALL, border = 5)
752 btnsizer = wx.StdDialogButtonSizer()
754 btn = wx.Button(parent = self, id = wx.ID_OK)
756 btnsizer.AddButton(btn)
758 btn = wx.Button(parent = self, id = wx.ID_CANCEL)
759 btnsizer.AddButton(btn)
762 self.sizer.Add(item = btnsizer, proportion = 0,
763 flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
765 self.SetSizer(self.
sizer)
775 """!Resize text entry to match text"""
779 """!Change text string"""
783 """!Change rotation"""
791 data.EnableEffects(
True)
795 dlg = wx.FontDialog(self, data)
797 if dlg.ShowModal() == wx.ID_OK:
798 data = dlg.GetFontData()
799 self.
currFont = data.GetChosenFont()
800 self.
currClr = data.GetColour()
802 self.textentry.SetFont(self.
currFont)
803 self.textentry.SetForegroundColour(self.
currClr)
810 """!Get text properties"""
816 'active' : self.chkbox.IsChecked() }
819 """!Dialog for creating/editing groups"""
820 def __init__(self, parent = None, defaultGroup = None,
821 title = _(
"Create or edit imagery groups"),
822 style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
824 wx.Dialog.__init__(self, parent = parent, id = wx.ID_ANY, title = title,
825 style = style, **kwargs)
835 btnOk = wx.Button(parent = self, id = wx.ID_OK)
836 btnApply = wx.Button(parent = self, id = wx.ID_APPLY)
837 btnClose = wx.Button(parent = self, id = wx.ID_CANCEL)
839 btnOk.SetToolTipString(_(
"Apply changes to selected group and close dialog"))
840 btnApply.SetToolTipString(_(
"Apply changes to selected group"))
841 btnClose.SetToolTipString(_(
"Close dialog, changes are not applied"))
851 btnSizer = wx.StdDialogButtonSizer()
852 btnSizer.AddButton(btnOk)
853 btnSizer.AddButton(btnApply)
854 btnSizer.AddButton(btnClose)
857 mainSizer = wx.BoxSizer(wx.VERTICAL)
858 mainSizer.Add(item = self.
bodySizer, proportion = 1,
859 flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border = 10)
860 mainSizer.Add(item = wx.StaticLine(parent = self, id = wx.ID_ANY,
861 style = wx.LI_HORIZONTAL), proportion = 0,
862 flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border = 10)
864 mainSizer.Add(item = btnSizer, proportion = 0,
865 flag = wx.ALL | wx.ALIGN_RIGHT, border = 10)
867 self.SetSizer(mainSizer)
870 btnOk.Bind(wx.EVT_BUTTON, self.
OnOk)
871 btnApply.Bind(wx.EVT_BUTTON, self.
OnApply)
872 btnClose.Bind(wx.EVT_BUTTON, self.
OnClose)
875 self.SetMinSize(self.GetSize())
877 def _createDialogBody(self):
878 bodySizer = wx.BoxSizer(wx.VERTICAL)
881 bodySizer.Add(item = wx.StaticText(parent = self, id = wx.ID_ANY,
882 label = _(
"Select the group you want to edit or "
883 "enter name of new group:")),
884 flag = wx.ALIGN_CENTER_VERTICAL | wx.TOP, border = 10)
886 mapsets = [grass.gisenv()[
'MAPSET']],
887 size = globalvar.DIALOG_GSELECT_SIZE)
889 bodySizer.Add(item = self.
groupSelect, flag = wx.TOP | wx.EXPAND, border = 5)
891 bodySizer.AddSpacer(10)
893 bodySizer.Add(item = wx.StaticText(parent = self, label = _(
"Layers in selected group:")),
894 flag = wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM, border = 5)
896 gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
897 gridSizer.AddGrowableCol(0)
899 self.
layerBox = wx.ListBox(parent = self, id = wx.ID_ANY, size = (-1, 150),
900 style = wx.LB_MULTIPLE | wx.LB_NEEDED_SB)
902 gridSizer.Add(item = self.
layerBox, pos = (0, 0), span = (2, 1), flag = wx.EXPAND)
905 self.addLayer.SetToolTipString(_(
"Select map layers and add them to the list."))
906 gridSizer.Add(item = self.
addLayer, pos = (0, 1), flag = wx.EXPAND)
909 self.removeLayer.SetToolTipString(_(
"Remove selected layer(s) from list."))
910 gridSizer.Add(item = self.
removeLayer, pos = (1, 1))
912 bodySizer.Add(item = gridSizer, proportion = 1, flag = wx.EXPAND)
914 self.
infoLabel = wx.StaticText(parent = self, id = wx.ID_ANY)
916 flag = wx.ALIGN_CENTER_VERTICAL | wx.TOP | wx.BOTTOM, border = 5)
918 self.
subGroup = wx.CheckBox(parent = self, id = wx.ID_ANY,
919 label = _(
"Define also sub-group (same name as group)"))
920 bodySizer.Add(item = self.
subGroup, flag = wx.BOTTOM | wx.EXPAND, border = 5)
924 self.addLayer.Bind(wx.EVT_BUTTON, self.
OnAddLayer)
933 """!Add new layer to listbox"""
934 dlg =
MapLayersDialog(parent = self, title = _(
"Add selected map layers into group"),
935 mapType =
'raster', selectAll =
False,
936 fullyQualified =
True, showFullyQualified =
False)
937 if dlg.ShowModal() != wx.ID_OK:
941 layers = dlg.GetMapLayers()
944 self.layerBox.Append(layer)
949 """!Remove layer from listbox"""
950 while self.layerBox.GetSelections():
951 sel = self.layerBox.GetSelections()[0]
952 self.layerBox.Delete(sel)
957 return self.layerBox.GetItems()
960 """!Text changed in group selector"""
965 """!Group was selected, check if changes were apllied"""
968 dlg = wx.MessageDialog(self, message = _(
"Group <%s> was changed, "
970 caption = _(
"Unapplied changes"),
971 style = wx.YES_NO | wx.ICON_QUESTION | wx.YES_DEFAULT)
972 if dlg.ShowModal() == wx.ID_YES:
989 """!Show map layers in currently selected group"""
990 self.layerBox.Set(mapList)
994 """!Edit selected group"""
1000 for layerNew
in layersNew:
1001 if layerNew
not in layersOld:
1002 add.append(layerNew)
1004 for layerOld
in layersOld:
1005 if layerOld
not in layersNew:
1006 remove.append(layerOld)
1009 if self.subGroup.IsChecked():
1010 kwargs[
'subgroup'] = group
1018 input = ','.join(remove),
1025 input =
','.join(add),
1031 """!Create new group"""
1035 if self.subGroup.IsChecked():
1036 kwargs[
'subgroup'] = group
1045 """!Returns existing groups in current mapset"""
1046 return grass.list_grouped(
'group')[grass.gisenv()[
'MAPSET']]
1049 """!Show if operation was successfull."""
1050 group +=
'@' + grass.gisenv()[
'MAPSET']
1051 if returnCode
is None:
1052 label = _(
"No changes to apply in group <%s>.") % group
1053 elif returnCode == 0:
1055 label = _(
"Group <%s> was successfully created.") % group
1057 label = _(
"Group <%s> was successfully changed.") % group
1060 label = _(
"Creating of new group <%s> failed.") % group
1062 label = _(
"Changing of group <%s> failed.") % group
1064 self.infoLabel.SetLabel(label)
1068 """!Return currently selected group (without mapset)"""
1069 return self.groupSelect.GetValue().
split(
'@')[0]
1072 """!Get layers in group"""
1077 read =
True).strip()
1078 if res.split(
'\n')[0]:
1079 return res.split(
'\n')
1083 """!Clear notification string"""
1084 self.infoLabel.SetLabel(
"")
1087 """!Create or edit group"""
1090 GMessage(parent = self,
1091 message = _(
"No group selected."))
1097 self.
ShowResult(group = group, returnCode = ret, create =
False)
1101 self.
ShowResult(group = group, returnCode = ret, create =
True)
1108 """!Apply changes"""
1112 """!Apply changes and close dialog"""
1118 if not self.IsModal():
1123 def __init__(self, parent, title, modeler = False,
1124 mapType =
None, selectAll =
True, fullyQualified =
True, showFullyQualified =
True,
1125 style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
1126 """!Dialog for selecting map layers (raster, vector)
1128 Valid mapType values:
1133 @param mapType type of map (if None: raster, vector, 3d raster, if one only: selects it and disables selection)
1134 @param selectAll all/none maps should be selected by default
1135 @param fullyQualified True if dialog should return full map names by default
1136 @param showFullyQualified True to show 'fullyQualified' checkbox, otherwise hide it
1138 wx.Dialog.__init__(self, parent = parent, id = wx.ID_ANY, title = title,
1139 style = style, **kwargs)
1150 self.mapset.GetStringSelection())
1153 label = _(
"Use fully-qualified map names"))
1154 self.fullyQualified.SetValue(fullyQualified)
1155 self.fullyQualified.Show(showFullyQualified)
1159 self.
dseries = wx.CheckBox(parent = self, id = wx.ID_ANY,
1160 label = _(
"Dynamic series (%s)") %
'g.mlist')
1161 self.dseries.SetValue(
False)
1164 btnCancel = wx.Button(parent = self, id = wx.ID_CANCEL)
1165 btnOk = wx.Button(parent = self, id = wx.ID_OK)
1169 btnSizer = wx.StdDialogButtonSizer()
1170 btnSizer.AddButton(btnCancel)
1171 btnSizer.AddButton(btnOk)
1174 mainSizer = wx.BoxSizer(wx.VERTICAL)
1175 mainSizer.Add(item = self.
bodySizer, proportion = 1,
1176 flag = wx.EXPAND | wx.ALL, border = 5)
1178 flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border = 5)
1180 mainSizer.Add(item = self.
dseries, proportion = 0,
1181 flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border = 5)
1183 mainSizer.Add(item = btnSizer, proportion = 0,
1184 flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
1186 self.SetSizer(mainSizer)
1190 self.SetMinSize(self.GetSize())
1192 def _createDialogBody(self):
1193 bodySizer = wx.GridBagSizer(vgap = 3, hgap = 3)
1196 bodySizer.Add(item = wx.StaticText(parent = self, label = _(
"Map type:")),
1197 flag = wx.ALIGN_CENTER_VERTICAL,
1201 choices = [_(
'raster'), _(
'3D raster'), _(
'vector')], size = (100,-1))
1205 self.layerType.SetSelection(0)
1206 elif self.
mapType ==
'raster3d':
1207 self.layerType.SetSelection(1)
1208 elif self.
mapType ==
'vector':
1209 self.layerType.SetSelection(2)
1210 self.layerType.Disable()
1212 self.layerType.SetSelection(0)
1218 self.
toggle = wx.CheckBox(parent = self, id = wx.ID_ANY,
1219 label = _(
"Select toggle"))
1221 bodySizer.Add(item = self.
toggle,
1222 flag = wx.ALIGN_CENTER_VERTICAL,
1226 bodySizer.Add(item = wx.StaticText(parent = self, label = _(
"Mapset:")),
1227 flag = wx.ALIGN_CENTER_VERTICAL,
1230 self.
mapset = MapsetSelect(parent = self, searchPath =
True)
1231 self.mapset.SetStringSelection(grass.gisenv()[
'MAPSET'])
1232 bodySizer.Add(item = self.
mapset,
1233 pos = (1,1), span = (1, 2))
1236 bodySizer.Add(item = wx.StaticText(parent = self, label = _(
"Pattern:")),
1237 flag = wx.ALIGN_CENTER_VERTICAL,
1240 self.
filter = wx.TextCtrl(parent = self, id = wx.ID_ANY,
1243 bodySizer.Add(item = self.
filter,
1245 pos = (2,1), span = (1, 2))
1248 bodySizer.Add(item = wx.StaticText(parent = self, label = _(
"List of maps:")),
1249 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_TOP,
1251 self.
layers = wx.CheckListBox(parent = self, id = wx.ID_ANY,
1254 bodySizer.Add(item = self.
layers,
1256 pos = (3,1), span = (1, 2))
1258 bodySizer.AddGrowableCol(1)
1259 bodySizer.AddGrowableRow(3)
1263 self.layers.Bind(wx.EVT_RIGHT_DOWN, self.
OnMenu)
1264 self.filter.Bind(wx.EVT_TEXT, self.
OnFilter)
1265 self.toggle.Bind(wx.EVT_CHECKBOX, self.
OnToggle)
1270 """!Load list of map layers
1272 @param type layer type ('raster' or 'vector')
1273 @param mapset mapset name
1275 self.
map_layers = grass.mlist_grouped(type = type)[mapset]
1279 for item
in range(self.layers.GetCount()):
1281 self.layers.Check(item, check = self.
selectAll)
1284 """!Filter parameters changed by user"""
1287 self.mapset.GetStringSelection())
1292 """!Table description area, context menu"""
1293 if not hasattr(self,
"popupID1"):
1308 self.PopupMenu(menu)
1312 """!Select all map layer from list"""
1313 for item
in range(self.layers.GetCount()):
1314 self.layers.Check(item,
True)
1317 """!Invert current selection"""
1318 for item
in range(self.layers.GetCount()):
1319 if self.layers.IsChecked(item):
1320 self.layers.Check(item,
False)
1322 self.layers.Check(item,
True)
1325 """!Select all map layer from list"""
1326 for item
in range(self.layers.GetCount()):
1327 self.layers.Check(item,
False)
1330 """!Apply filter for map names"""
1331 if len(event.GetString()) == 0:
1338 if re.compile(
'^' + event.GetString()).search(layer):
1343 self.layers.Set(list)
1349 """!Select toggle (check or uncheck all layers)"""
1350 check = event.Checked()
1351 for item
in range(self.layers.GetCount()):
1352 self.layers.Check(item, check)
1357 """!Return list of checked map layers"""
1359 for indx
in self.layers.GetSelections():
1363 fullyQualified = self.fullyQualified.IsChecked()
1364 mapset = self.mapset.GetStringSelection()
1365 for item
in range(self.layers.GetCount()):
1366 if not self.layers.IsChecked(item):
1369 layerNames.append(self.layers.GetString(item) +
'@' + mapset)
1371 layerNames.append(self.layers.GetString(item))
1376 """!Get selected layer type
1378 @param cmd True for g.mlist
1381 return self.layerType.GetStringSelection()
1383 sel = self.layerType.GetSelection()
1394 """!Used by modeler only
1396 @return g.mlist command
1398 if not self.
dseries or not self.dseries.IsChecked():
1401 cond =
'map in `g.mlist type=%s ' % self.
GetLayerType(cmd =
True)
1402 patt = self.filter.GetValue()
1404 cond +=
'pattern=%s ' % patt
1405 cond +=
'mapset=%s`' % self.mapset.GetStringSelection()
1410 """!Dialog for bulk import of various data (base class)"""
1412 id = wx.ID_ANY, title = _(
"Multiple import"),
1413 style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
1420 wx.Dialog.__init__(self, parent, id, title, style = style,
1421 name =
"MultiImportDialog")
1423 self.
panel = wx.Panel(parent = self, id = wx.ID_ANY)
1426 label = _(
" List of %s layers ") % self.importType.upper())
1431 columns = [_(
'Layer id'),
1433 _(
'Name for GRASS map (editable)')]
1435 self.list.LoadData()
1438 label =
"%s" % _(
"Options"))
1441 task = gtask.parse_interface(cmd)
1442 for f
in task.get_options()[
'flags']:
1443 name = f.get(
'name',
'')
1444 desc = f.get(
'label',
'')
1446 desc = f.get(
'description',
'')
1447 if not name
and not desc:
1449 if cmd ==
'r.in.gdal' and name
not in (
'o',
'e',
'l',
'k'):
1451 elif cmd ==
'r.external' and name
not in (
'o',
'e',
'r', 'h', 'v'):
1453 elif cmd ==
'v.in.ogr' and name
not in (
'c',
'z',
't',
'o',
'r', 'e', 'w'):
1455 elif cmd ==
'v.external' and name
not in (
'b'):
1457 elif cmd ==
'v.in.dxf' and name
not in (
'e',
't',
'b',
'f',
'i'):
1459 self.
options[name] = wx.CheckBox(parent = self.
panel, id = wx.ID_ANY,
1463 self.optionBox.Hide()
1466 label = _(
"Allow output files to overwrite existing files"))
1467 self.overwrite.SetValue(UserSettings.Get(group =
'cmd', key =
'overwrite', subkey =
'enabled'))
1469 self.
add = wx.CheckBox(parent = self.
panel, id = wx.ID_ANY)
1471 label = _(
"Close dialog on finish"))
1472 self.closeOnFinish.SetValue(UserSettings.Get(group =
'cmd', key =
'closeDlg', subkey =
'enabled'))
1479 self.btn_close.SetToolTipString(_(
"Close dialog"))
1480 self.btn_close.Bind(wx.EVT_BUTTON, self.
OnClose)
1482 self.
btn_run = wx.Button(parent = self.
panel, id = wx.ID_OK, label = _(
"&Import"))
1483 self.btn_run.SetToolTipString(_(
"Import selected layers"))
1484 self.btn_run.SetDefault()
1485 self.btn_run.Enable(
False)
1486 self.btn_run.Bind(wx.EVT_BUTTON, self.
OnRun)
1489 label = _(
"Command dialog"))
1490 self.btn_cmd.Bind(wx.EVT_BUTTON, self.
OnCmdDialog)
1494 dialogSizer = wx.BoxSizer(wx.VERTICAL)
1497 dialogSizer.Add(item = self.dsnInput, proportion = 0,
1503 layerSizer = wx.StaticBoxSizer(self.
layerBox, wx.HORIZONTAL)
1505 layerSizer.Add(item = self.
list, proportion = 1,
1506 flag = wx.ALL | wx.EXPAND, border = 5)
1508 dialogSizer.Add(item = layerSizer, proportion = 1,
1509 flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
1512 if self.optionBox.IsShown():
1513 optionSizer = wx.StaticBoxSizer(self.
optionBox, wx.VERTICAL)
1514 for key
in self.options.keys():
1515 optionSizer.Add(item = self.
options[key], proportion = 0)
1517 dialogSizer.Add(item = optionSizer, proportion = 0,
1518 flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
1520 dialogSizer.Add(item = self.
overwrite, proportion = 0,
1521 flag = wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
1523 dialogSizer.Add(item = self.
add, proportion = 0,
1524 flag = wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
1527 flag = wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
1531 btnsizer = wx.BoxSizer(orient = wx.HORIZONTAL)
1533 btnsizer.Add(item = self.
btn_cmd, proportion = 0,
1534 flag = wx.RIGHT | wx.ALIGN_CENTER,
1537 btnsizer.Add(item = self.
btn_close, proportion = 0,
1538 flag = wx.LEFT | wx.RIGHT | wx.ALIGN_CENTER,
1541 btnsizer.Add(item = self.
btn_run, proportion = 0,
1542 flag = wx.RIGHT | wx.ALIGN_CENTER,
1545 dialogSizer.Add(item = btnsizer, proportion = 0,
1546 flag = wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.ALIGN_RIGHT,
1550 self.panel.SetAutoLayout(
True)
1551 self.panel.SetSizer(dialogSizer)
1552 dialogSizer.Fit(self.
panel)
1555 size = wx.Size(globalvar.DIALOG_GSELECT_SIZE[0] + 225, 550)
1556 self.SetMinSize(size)
1557 self.SetSize((size.width, size.height + 100))
1562 def _getCommand(self):
1571 """!Import/Link data (each layes as separate vector map)"""
1575 """!Show command dialog"""
1579 """!Add imported/linked layers into layer tree"""
1580 if not self.add.IsChecked()
or returncode != 0:
1584 maptree = self.parent.curr_page.maptree
1586 layer, output = self.list.GetLayers()[self.commandId]
1588 if '@' not in output:
1589 name = output +
'@' + grass.gisenv()[
'MAPSET']
1594 if self.importType ==
'gdal':
1597 if UserSettings.Get(group =
'cmd', key =
'rasterOverlay', subkey =
'enabled'):
1600 item = maptree.AddLayer(ltype =
'raster',
1601 lname = name, lchecked =
False,
1602 lcmd = cmd, multiple =
False)
1604 item = maptree.AddLayer(ltype =
'vector',
1605 lname = name, lchecked =
False,
1610 maptree.mapdisplay.MapWindow.ZoomToMap()
1613 """!Abort running import
1615 @todo not yet implemented
1619 class GdalImportDialog(ImportDialog):
1621 """!Dialog for bulk import of various raster/vector data
1623 @param parent parent window
1624 @param ogr True for OGR (vector) otherwise GDAL (raster)
1625 @param link True for linking data otherwise importing data
1631 ImportDialog.__init__(self, parent, itype =
'ogr')
1633 self.SetTitle(_(
"Link external vector data"))
1635 self.SetTitle(_(
"Import vector data"))
1637 ImportDialog.__init__(self, parent, itype =
'gdal')
1639 self.SetTitle(_(
"Link external raster data"))
1641 self.SetTitle(_(
"Import raster data"))
1644 ogr = ogr, link = link)
1647 self.add.SetLabel(_(
"Add linked layers into layer tree"))
1649 self.add.SetLabel(_(
"Add imported layers into layer tree"))
1651 self.add.SetValue(UserSettings.Get(group =
'cmd', key =
'addNewLayer', subkey =
'enabled'))
1654 self.btn_run.SetLabel(_(
"&Link"))
1655 self.btn_run.SetToolTipString(_(
"Link selected layers"))
1657 self.btn_cmd.SetToolTipString(_(
'Open %s dialog') %
'v.external')
1659 self.btn_cmd.SetToolTipString(_(
'Open %s dialog') %
'r.external')
1661 self.btn_run.SetLabel(_(
"&Import"))
1662 self.btn_run.SetToolTipString(_(
"Import selected layers"))
1664 self.btn_cmd.SetToolTipString(_(
'Open %s dialog') %
'v.in.ogr')
1666 self.btn_cmd.SetToolTipString(_(
'Open %s dialog') %
'r.in.gdal')
1671 """!Import/Link data (each layes as separate vector map)"""
1673 data = self.list.GetLayers()
1675 GMessage(_(
"No layers selected. Operation canceled."),
1679 dsn = self.dsnInput.GetDsn()
1680 ext = self.dsnInput.GetFormatExt()
1685 self.dsnInput.GetType() ==
'db' and \
1686 self.dsnInput.GetFormat() ==
'PostgreSQL' and \
1687 'GRASS_VECTOR_OGR' not in os.environ:
1689 os.environ[
'GRASS_VECTOR_OGR'] =
'1'
1691 for layer, output
in data:
1693 if ext
and layer.rfind(ext) > -1:
1694 layer = layer.replace(
'.' + ext,
'')
1696 cmd = [
'v.external',
1698 'output=%s' % output,
1704 'output=%s' % output]
1706 if self.dsnInput.GetType() ==
'dir':
1707 idsn = os.path.join(dsn, layer)
1712 cmd = [
'r.external',
1714 'output=%s' % output]
1718 'output=%s' % output]
1720 if self.overwrite.IsChecked():
1721 cmd.append(
'--overwrite')
1723 for key
in self.options.keys():
1724 if self.
options[key].IsChecked():
1725 cmd.append(
'-%s' % key)
1727 if UserSettings.Get(group =
'cmd', key =
'overwrite', subkey =
'enabled')
and \
1728 '--overwrite' not in cmd:
1729 cmd.append(
'--overwrite')
1732 self.parent.goutput.RunCmd(cmd, switchPage =
True,
1736 os.environ.pop(
'GRASS_VECTOR_OGR')
1738 if self.closeOnFinish.IsChecked():
1741 def _getCommand(self):
1757 """!Show command dialog"""
1759 GUI(parent = self, modal =
False).ParseCommand(cmd = [name])
1762 """!Dialog for bulk import of DXF layers"""
1764 ImportDialog.__init__(self, parent, itype =
'dxf',
1765 title = _(
"Import DXF layers"))
1767 self.
dsnInput = filebrowse.FileBrowseButton(parent = self.
panel, id = wx.ID_ANY,
1768 size = globalvar.DIALOG_GSELECT_SIZE, labelText =
'',
1769 dialogTitle = _(
'Choose DXF file to import'),
1770 buttonText = _(
'Browse'),
1771 startDirectory = os.getcwd(), fileMode = 0,
1773 fileMask =
"DXF File (*.dxf)|*.dxf")
1775 self.add.SetLabel(_(
"Add imported layers into layer tree"))
1777 self.add.SetValue(UserSettings.Get(group =
'cmd', key =
'addNewLayer', subkey =
'enabled'))
1781 def _getCommand(self):
1786 """!Import/Link data (each layes as separate vector map)"""
1787 data = self.list.GetLayers()
1792 inputDxf = self.dsnInput.GetValue()
1794 for layer, output
in data:
1796 'input=%s' % inputDxf,
1797 'layers=%s' % layer,
1798 'output=%s' % output]
1800 for key
in self.options.keys():
1801 if self.
options[key].IsChecked():
1802 cmd.append(
'-%s' % key)
1804 if self.overwrite.IsChecked()
or \
1805 UserSettings.Get(group =
'cmd', key =
'overwrite', subkey =
'enabled'):
1806 cmd.append(
'--overwrite')
1809 self.parent.goutput.RunCmd(cmd, switchPage =
True,
1815 """!Input DXF file defined, update list of layer widget"""
1816 path = event.GetString()
1828 self.list.LoadData()
1829 self.btn_run.Enable(
False)
1832 for line
in ret.splitlines():
1833 layerId = line.split(
':')[0].
split(
' ')[1]
1834 layerName = line.split(
':')[1].strip()
1836 data.append((layerId, layerName.strip(), grassName.strip()))
1838 self.list.LoadData(data)
1840 self.btn_run.Enable(
True)
1842 self.btn_run.Enable(
False)
1845 """!Show command dialog"""
1846 GUI(parent = self, modal =
True).ParseCommand(cmd = [
'v.in.dxf'])
1848 class LayersList(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin,
1849 listmix.CheckListCtrlMixin, listmix.TextEditMixin):
1850 """!List of layers to be imported (dxf, shp...)"""
1854 wx.ListCtrl.__init__(self, parent, wx.ID_ANY,
1855 style = wx.LC_REPORT)
1856 listmix.CheckListCtrlMixin.__init__(self)
1860 listmix.ListCtrlAutoWidthMixin.__init__(self)
1861 listmix.TextEditMixin.__init__(self)
1863 for i
in range(len(columns)):
1864 self.InsertColumn(i, columns[i])
1866 if len(columns) == 3:
1869 width = (65, 180, 110)
1871 for i
in range(len(width)):
1872 self.SetColumnWidth(col = i, width = width[i])
1874 self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.
OnPopupMenu)
1878 """!Load data into list"""
1879 self.DeleteAllItems()
1884 index = self.InsertStringItem(sys.maxint, str(item[0]))
1885 for i
in range(1, len(item)):
1886 self.SetStringItem(index, i,
"%s" % str(item[i]))
1890 self.CheckItem(index,
True)
1893 """!Show popup menu"""
1894 if self.GetItemCount() < 1:
1897 if not hasattr(self,
"popupDataID1"):
1909 self.PopupMenu(menu)
1913 """!Select all items"""
1917 item = self.GetNextItem(item)
1920 self.CheckItem(item,
True)
1925 """!Deselect items"""
1929 item = self.GetNextItem(item, wx.LIST_STATE_SELECTED)
1932 self.CheckItem(item,
False)
1937 """!Allow editing only output name
1939 Code taken from TextEditMixin class.
1941 x, y = event.GetPosition()
1945 for n
in range(self.GetColumnCount()):
1946 loc = loc + self.GetColumnWidth(n)
1949 col = bisect(colLocs, x + self.GetScrollPos(wx.HORIZONTAL)) - 1
1951 if col == self.GetColumnCount() - 1:
1952 listmix.TextEditMixin.OnLeftDown(self, event)
1957 """!Get list of layers (layer name, output name)"""
1961 item = self.GetNextItem(item)
1964 if not self.IsChecked(item):
1967 data.append((self.GetItem(item, 1).GetText(),
1968 self.GetItem(item, self.GetColumnCount() - 1).GetText()))
1973 """!Set opacity of map layers"""
1974 def __init__(self, parent, id = wx.ID_ANY, title = _(
"Set Map Layer Opacity"),
1975 size = wx.DefaultSize, pos = wx.DefaultPosition,
1976 style = wx.DEFAULT_DIALOG_STYLE, opacity = 100):
1981 super(SetOpacityDialog, self).
__init__(parent, id = id, pos = pos,
1982 size = size, style = style, title = title)
1984 panel = wx.Panel(parent = self, id = wx.ID_ANY)
1986 sizer = wx.BoxSizer(wx.VERTICAL)
1988 box = wx.GridBagSizer(vgap = 5, hgap = 5)
1990 style = wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | \
1991 wx.SL_TOP | wx.SL_LABELS,
1992 minValue = 0, maxValue = 100,
1995 box.Add(item = self.
value,
1996 flag = wx.ALIGN_CENTRE, pos = (0, 0), span = (1, 2))
1997 box.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
1998 label = _(
"transparent")),
2000 box.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
2001 label = _(
"opaque")),
2002 flag = wx.ALIGN_RIGHT,
2005 sizer.Add(item = box, proportion = 0,
2006 flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border = 5)
2008 line = wx.StaticLine(parent = panel, id = wx.ID_ANY,
2009 style = wx.LI_HORIZONTAL)
2010 sizer.Add(item = line, proportion = 0,
2011 flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border = 5)
2014 btnsizer = wx.StdDialogButtonSizer()
2016 btnOK = wx.Button(parent = panel, id = wx.ID_OK)
2018 btnsizer.AddButton(btnOK)
2020 btnCancel = wx.Button(parent = panel, id = wx.ID_CANCEL)
2021 btnsizer.AddButton(btnCancel)
2023 btnApply = wx.Button(parent = panel, id = wx.ID_APPLY)
2024 btnApply.Bind(wx.EVT_BUTTON, self.
OnApply)
2025 btnsizer.AddButton(btnApply)
2028 sizer.Add(item = btnsizer, proportion = 0,
2029 flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border = 5)
2031 panel.SetSizer(sizer)
2034 self.SetSize(self.GetBestSize())
2039 """!Button 'OK' pressed"""
2041 opacity = float(self.value.GetValue()) / 100
2045 event = wxApplyOpacity(value = self.
GetOpacity())
2046 wx.PostEvent(self, event)
2049 """!Get list of supported image handlers"""
2052 for h
in image.GetHandlers():
2053 lext.append(h.GetExtension())
2057 filetype +=
"PNG file (*.png)|*.png|"
2058 ltype.append({
'type' : wx.BITMAP_TYPE_PNG,
2060 filetype +=
"BMP file (*.bmp)|*.bmp|"
2061 ltype.append({
'type' : wx.BITMAP_TYPE_BMP,
2064 filetype +=
"GIF file (*.gif)|*.gif|"
2065 ltype.append({
'type' : wx.BITMAP_TYPE_GIF,
2069 filetype +=
"JPG file (*.jpg)|*.jpg|"
2070 ltype.append({
'type' : wx.BITMAP_TYPE_JPEG,
2074 filetype +=
"PCX file (*.pcx)|*.pcx|"
2075 ltype.append({
'type' : wx.BITMAP_TYPE_PCX,
2079 filetype +=
"PNM file (*.pnm)|*.pnm|"
2080 ltype.append({
'type' : wx.BITMAP_TYPE_PNM,
2084 filetype +=
"TIF file (*.tif)|*.tif|"
2085 ltype.append({
'type' : wx.BITMAP_TYPE_TIF,
2089 filetype +=
"XPM file (*.xpm)|*.xpm"
2090 ltype.append({
'type' : wx.BITMAP_TYPE_XPM,
2093 return filetype, ltype
2096 """!Set size for saved graphic file"""
2097 def __init__(self, parent, id = wx.ID_ANY, title = _(
"Set image size"),
2098 style = wx.DEFAULT_DIALOG_STYLE, **kwargs):
2101 wx.Dialog.__init__(self, parent, id = id, style = style, title = title, **kwargs)
2103 self.
panel = wx.Panel(parent = self, id = wx.ID_ANY)
2105 self.
box = wx.StaticBox(parent = self.
panel, id = wx.ID_ANY,
2106 label =
' % s' % _(
"Image size"))
2108 size = self.parent.GetWindow().GetClientSize()
2110 style = wx.SP_ARROW_KEYS)
2111 self.width.SetRange(20, 1e6)
2112 self.width.SetValue(size.width)
2113 wx.CallAfter(self.width.SetFocus)
2115 style = wx.SP_ARROW_KEYS)
2116 self.height.SetRange(20, 1e6)
2117 self.height.SetValue(size.height)
2129 self.btnOK.SetDefault()
2132 self.template.Bind(wx.EVT_CHOICE, self.
OnTemplate)
2135 self.SetSize(self.GetBestSize())
2139 sizer = wx.BoxSizer(wx.VERTICAL)
2142 box = wx.StaticBoxSizer(self.
box, wx.HORIZONTAL)
2143 fbox = wx.FlexGridSizer(cols = 2, vgap = 5, hgap = 5)
2144 fbox.Add(item = wx.StaticText(parent = self.
panel, id = wx.ID_ANY,
2145 label = _(
"Width:")),
2146 flag = wx.ALIGN_CENTER_VERTICAL)
2147 fbox.Add(item = self.
width)
2148 fbox.Add(item = wx.StaticText(parent = self.
panel, id = wx.ID_ANY,
2149 label = _(
"Height:")),
2150 flag = wx.ALIGN_CENTER_VERTICAL)
2151 fbox.Add(item = self.
height)
2152 fbox.Add(item = wx.StaticText(parent = self.
panel, id = wx.ID_ANY,
2153 label = _(
"Template:")),
2154 flag = wx.ALIGN_CENTER_VERTICAL)
2157 box.Add(item = fbox, proportion = 1,
2158 flag = wx.EXPAND | wx.ALL, border = 5)
2159 sizer.Add(item = box, proportion = 1,
2160 flag = wx.EXPAND | wx.ALL, border = 3)
2163 btnsizer = wx.StdDialogButtonSizer()
2164 btnsizer.AddButton(self.
btnOK)
2168 sizer.Add(item = btnsizer, proportion = 0,
2169 flag = wx.EXPAND | wx.ALIGN_RIGHT | wx.ALL, border = 5)
2171 self.panel.SetSizer(sizer)
2172 sizer.Fit(self.
panel)
2176 """!Get width/height values"""
2177 return self.width.GetValue(), self.height.GetValue()
2180 """!Template selected"""
2181 sel = event.GetString()
2183 width, height = self.parent.GetWindow().GetClientSize()
2185 width, height = map(int, sel.split(
'x'))
2186 self.width.SetValue(width)
2187 self.height.SetValue(height)
2190 """!Dialog for GRASS symbols selection.
2192 Dialog is called in gui_core::forms module.
2194 def __init__(self, parent, symbolPath, currentSymbol = None, title = _(
"Symbols")):
2195 """!Dialog constructor.
2197 It is assumed that symbolPath contains folders with symbols.
2199 @param parent dialog parent
2200 @param symbolPath absolute path to symbols
2201 @param currentSymbol currently selected symbol (e.g. 'basic/x')
2202 @param title dialog title
2204 wx.Dialog.__init__(self, parent = parent, title = title, id = wx.ID_ANY)
2214 mainPanel = wx.Panel(self, id = wx.ID_ANY)
2215 mainSizer = wx.BoxSizer(wx.VERTICAL)
2216 vSizer = wx.BoxSizer( wx.VERTICAL)
2217 fgSizer = wx.FlexGridSizer(rows = 2, vgap = 5, hgap = 5)
2221 fgSizer.Add(item = wx.StaticText(mainPanel, id = wx.ID_ANY, label = _(
"Symbol directory:")),
2223 flag = wx.ALIGN_CENTER_VERTICAL)
2226 flag = wx.ALIGN_CENTER, border = 0)
2229 fgSizer.Add(wx.StaticText(mainPanel, id = wx.ID_ANY, label = _(
"Symbol name:")),
2230 flag = wx.ALIGN_CENTRE_VERTICAL)
2231 fgSizer.Add(self.
infoLabel, proportion = 0,
2232 flag = wx.ALIGN_CENTRE_VERTICAL)
2233 vSizer.Add(fgSizer, proportion = 0, flag = wx.ALL, border = 5)
2236 for panel
in self.
panels:
2237 vSizer.Add(panel, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
2240 mainSizer.Add(vSizer, proportion = 1, flag = wx.ALL| wx.EXPAND, border = 5)
2241 self.
btnCancel = wx.Button(parent = mainPanel, id = wx.ID_CANCEL)
2242 self.
btnOK = wx.Button(parent = mainPanel, id = wx.ID_OK)
2243 self.btnOK.SetDefault()
2244 self.btnOK.Enable(
False)
2247 btnSizer = wx.StdDialogButtonSizer()
2249 btnSizer.AddButton(self.
btnOK)
2251 mainSizer.Add(item = btnSizer, proportion = 0,
2252 flag = wx.EXPAND | wx.ALL, border = 5)
2257 count.append(len(os.listdir(os.path.join(self.
symbolPath, folder))))
2259 index = count.index(
max(count))
2260 self.folderChoice.SetSelection(index)
2262 self.infoLabel.Show()
2264 mainPanel.SetSizerAndFit(mainSizer)
2265 self.SetSize(self.GetBestSize())
2271 self.folderChoice.SetStringSelection(self.
selectedDir)
2273 panelIdx = self.folderChoice.GetSelection()
2275 if panel.GetName() == self.
selected:
2278 self.folderChoice.SetSelection(0)
2282 def _createSymbolPanels(self, parent):
2283 """!Creates multiple panels with symbols.
2285 Panels are shown/hidden according to selected folder."""
2292 for folder
in folders:
2293 panel = wx.Panel(parent, style = wx.BORDER_RAISED)
2294 sizer = wx.GridSizer(cols = 6, vgap = 3, hgap = 3)
2299 iP = SingleSymbolPanel(parent = panel, symbolPath = img)
2300 sizer.Add(item = iP, proportion = 0, flag = wx.ALIGN_CENTER)
2301 symbolPanels.append(iP)
2303 panel.SetSizerAndFit(sizer)
2305 panels.append(panel)
2306 self.symbolPanels.append(symbolPanels)
2310 def _getSymbols(self, path):
2313 for image
in os.listdir(path):
2314 imageList.append(os.path.join(path, image))
2316 return sorted(imageList)
2319 """!Selected folder with symbols changed."""
2320 idx = self.folderChoice.GetSelection()
2322 sizer = self.
panels[i].GetContainingSizer()
2323 sizer.Show(self.
panels[i], i == idx, recursive =
True)
2326 if self.
selectedDir == self.folderChoice.GetStringSelection():
2328 self.infoLabel.SetLabel(self.
selected)
2330 self.btnOK.Disable()
2331 self.infoLabel.SetLabel(
'')
2334 """!Selected symbol changed."""
2335 if event.doubleClick:
2336 self.EndModal(wx.ID_OK)
2340 if panel.GetName() != event.name:
2346 self.
selectedDir = self.folderChoice.GetStringSelection()
2348 self.infoLabel.SetLabel(event.name)
2351 """!Returns currently selected symbol name (e.g. 'basic/x').
2357 """!Returns currently selected symbol full path.
2362 """!Simple dialog with text field.
2364 It differs from wx.TextEntryDialog because it allows adding validator.
2366 def __init__(self, parent, message, caption='',
2367 defaultValue=
'', pos=wx.DefaultPosition, validator=wx.DefaultValidator,
2368 style=wx.OK | wx.CANCEL):
2369 wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY, title=caption, pos=pos)
2371 vbox = wx.BoxSizer(wx.VERTICAL)
2373 stline = wx.StaticText(self, id=wx.ID_ANY, label=message)
2374 vbox.Add(item=stline, proportion=0, flag=wx.EXPAND | wx.ALL, border=10)
2376 self.
_textCtrl = wx.TextCtrl(self, id=wx.ID_ANY, size = (300, -1),
2377 value=defaultValue, validator=validator)
2378 vbox.Add(item=self.
_textCtrl, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=10)
2379 self._textCtrl.SetFocus()
2381 sizer = self.CreateSeparatedButtonSizer(style)
2382 vbox.Add(item=sizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=10)
2384 self.SetSizerAndFit(vbox)
2387 return self._textCtrl.GetValue()
2390 self._textCtrl.SetValue(value)
2394 """!Dialog for displaying message with hyperlink."""
2395 def __init__(self, parent, title, message, hyperlink,
2396 hyperlinkLabel=
None, style=wx.OK):
2399 @param parent gui parent
2400 @param title dialog title
2401 @param message message
2402 @param hyperlink url
2403 @param hyperlinkLabel label shown instead of url
2404 @param style button style
2406 wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY, title=title,
2407 style=wx.DEFAULT_DIALOG_STYLE)
2409 sizer = wx.BoxSizer(wx.VERTICAL)
2411 label = wx.StaticText(self, label=message)
2412 sizer.Add(item=label, proportion=0, flag=wx.ALIGN_CENTRE|wx.ALL, border=10)
2413 hyperlinkLabel = hyperlinkLabel
if hyperlinkLabel
else hyperlink
2414 hyperlinkCtrl = wx.HyperlinkCtrl(self, id=wx.ID_ANY,
2415 label=hyperlinkLabel, url=hyperlink,
2416 style=wx.HL_ALIGN_LEFT|wx.HL_CONTEXTMENU)
2417 sizer.Add(item=hyperlinkCtrl, proportion=0, flag=wx.EXPAND|wx.ALL, border=10)
2419 btnsizer = self.CreateSeparatedButtonSizer(style)
2420 sizer.Add(item=btnsizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=10)
2422 self.SetSizer(sizer)
def OnFilter
Apply filter for map names.
def OnSetDsn
Input DXF file defined, update list of layer widget.
def GetSelectedSymbolPath
Returns currently selected symbol full path.
def OnCmdDialog
Show command dialog.
def CloseDialog
Hide dialog.
def GetKey
Get key column name.
Dialog for bulk import of DXF layers.
def OnRun
Import/Link data (each layes as separate vector map)
def OnRun
Import/Link data (each layes as separate vector map)
def OnSelectAll
Select all items.
def OnRemoveLayer
Remove layer from listbox.
Dialog for GRASS symbols selection.
def OnElement
Select mapset given location name.
def GetLayers
Get list of layers (layer name, output name)
def OnLeftDown
Allow editing only output name.
def OnOk
Apply changes and close dialog.
def GetLayerType
Get selected layer type.
def GetType
Get element type.
def GroupSelected
Group was selected, check if changes were apllied.
def OnCmdDialog
Show command dialog.
def OnSelectFont
Change font.
def GetOptData
Process decoration layer data.
def OnElement
Name for vector map layer given.
def LoadData
Load data into list.
def OnMenu
Table description area, context menu.
Simple dialog with text field.
def OnRotation
Change rotation.
def OnTemplate
Template selected.
def GetMapLayers
Return list of checked map layers.
def OnCmdDialog
Show command dialog.
Dialog for displaying message with hyperlink.
def IsChecked
Get dialog properties.
def CreateNewGroup
Create new group.
def EditGroup
Edit selected group.
def OnRefit
Resize text entry to match text.
Custom control that selects elements.
Dialog for creating/editing groups.
def split
Platform spefic shlex.split.
def OnPopupMenu
Show popup menu.
def OnSelectNone
Deselect items.
def ApplyChanges
Create or edit group.
def GetLayerNameFromCmd
Get map name from GRASS command.
Dialog for bulk import of various data (base class)
def LoadMapLayers
Load list of map layers.
def GetElement
Return (mapName, overwrite)
def __init__
Dialog for bulk import of various raster/vector data.
def OnGroupSelected
Text changed in group selector.
def __init__
Dialog constructor.
def GetValues
Get location, mapset.
def GetValidLayerName
Make layer name SQL compliant, based on G_str_to_sql()
def OnOK
Button 'OK' pressed.
def GetImageHandlers
Get list of supported image handlers.
Set size for saved graphic file.
def OnRun
Import/Link data (each layes as separate vector map)
def CreateNewVector
Create new vector map layer.
def OnType
Select element type.
List of layers to be imported (dxf, shp...)
def GetName
Get name of vector map to be created.
def OnAddLayer
Add new layer to listbox.
Misc utilities for wxGUI.
def OnToggle
Select toggle (check or uncheck all layers)
def OnSelectAll
Select all map layer from list.
def OnApply
Apply changes.
def AddLayers
Add imported/linked layers into layer tree.
def SelectionChanged
Selected symbol changed.
Set opacity of map layers.
def _createSymbolPanels
Creates multiple panels with symbols.
def _getCommand
Get command.
def __init__
Dialog for selecting map layers (raster, vector)
def GetOpacity
Button 'OK' pressed.
def __init__
Dialog for creating new vector map.
def GetExistGroups
Returns existing groups in current mapset.
def OnDeselectAll
Select all map layer from list.
def GetValues
Get text properties.
def __init__
General dialog to choose given element (location, mapset, vector map, etc.)
def ShowGroupLayers
Show map layers in currently selected group.
def ShowResult
Show if operation was successfull.
def GetSelectedGroup
Return currently selected group (without mapset)
def OnSelectInvert
Invert current selection.
def OnOptions
Sets option for decoration map overlays.
def GetGroupLayers
Get layers in group.
def OnFolderSelect
Selected folder with symbols changed.
def __init__
Loading and saving of display extents to saved region file.
def OnChangeParams
Filter parameters changed by user.
def ClearNotification
Clear notification string.
def GetDSeries
Used by modeler only.
def OnMapName
Name for vector map layer given.
def GetSelectedSymbolName
Returns currently selected symbol name (e.g.
def GetValues
Get width/height values.
def RunCommand
Run GRASS command.
Dialog used to select location.
def OnText
Change text string.
def OnAbort
Abort running import.
Dialog used to select mapset.