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, title, id = wx.ID_ANY, loadsave = 'load',
441 """!Loading or 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()
495 """!Return region name"""
500 Controls setting options and displaying/hiding map overlay decorations
502 def __init__(self, parent, ovlId, title, cmd, name = None,
503 pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_DIALOG_STYLE,
504 checktxt =
'', ctrltxt =
''):
506 wx.Dialog.__init__(self, parent, wx.ID_ANY, title, pos, size, style)
513 sizer = wx.BoxSizer(wx.VERTICAL)
515 box = wx.BoxSizer(wx.HORIZONTAL)
516 self.
chkbox = wx.CheckBox(parent = self, id = wx.ID_ANY, label = checktxt)
517 if self.parent.Map.GetOverlay(self.
ovlId)
is None:
518 self.chkbox.SetValue(
True)
520 self.chkbox.SetValue(self.parent.MapWindow.overlays[self.
ovlId][
'layer'].IsActive())
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.
name ==
'legend':
532 box = wx.BoxSizer(wx.HORIZONTAL)
533 resize = wx.ToggleButton(parent = self, id = wx.ID_ANY, label = _(
"Set size and position"))
534 resize.SetToolTipString(_(
"Click and drag on the map display to set legend"
535 " size and position and then press OK"))
536 resize.SetName(
'resize')
538 box.Add(item = resize, 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 label = wx.StaticText(parent = self, id = wx.ID_ANY,
544 label = _(
"Drag %s with mouse in pointer mode to position.\n"
545 "Double-click to change options." % ctrltxt))
546 if self.
name ==
'legend':
547 label.SetLabel(label.GetLabel() + _(
'\nDefine raster map name for legend in '
548 'properties dialog.'))
549 box.Add(item = label, proportion = 0,
550 flag = wx.ALIGN_CENTRE|wx.ALL, border = 5)
551 sizer.Add(item = box, proportion = 0,
552 flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
554 line = wx.StaticLine(parent = self, id = wx.ID_ANY, size = (20,-1), style = wx.LI_HORIZONTAL)
555 sizer.Add(item = line, proportion = 0,
556 flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
559 btnsizer = wx.StdDialogButtonSizer()
561 self.
btnOK = wx.Button(parent = self, id = wx.ID_OK)
562 self.btnOK.SetDefault()
563 if self.
name ==
'legend':
564 self.btnOK.Enable(
False)
565 btnsizer.AddButton(self.
btnOK)
567 btnCancel = wx.Button(parent = self, id = wx.ID_CANCEL)
568 btnsizer.AddButton(btnCancel)
571 sizer.Add(item = btnsizer, proportion = 0,
572 flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border = 5)
577 self.Bind(wx.EVT_BUTTON, self.
OnOptions, optnbtn)
578 if self.
name ==
'legend':
579 self.Bind(wx.EVT_TOGGLEBUTTON, self.
OnResize, resize)
580 self.Bind(wx.EVT_BUTTON, self.
OnCancel, btnCancel)
581 self.Bind(wx.EVT_BUTTON, self.
OnOK, self.
btnOK)
589 if len(self.parent.MapWindow.overlays[self.
ovlId][
'cmd']) > 1:
595 if not self.parent.IsPaneShown(
'3d'):
596 self.FindWindowByName(
'resize').Enable()
599 self.SetTitle(_(
'Legend of raster map <%s>') % \
603 def _createOverlay(self):
604 """!Creates overlay"""
605 if not self.parent.Map.GetOverlay(self.
ovlId):
608 l_active =
False, l_render =
False, l_hidden =
True)
615 self.parent.MapWindow2D.overlays[self.
ovlId] = prop
616 if self.parent.MapWindow3D:
617 self.parent.MapWindow3D.overlays[self.
ovlId] = prop
620 if self.parent.MapWindow.overlays[self.
ovlId][
'propwin'] ==
None:
623 self.parent.MapWindow.overlays[self.
ovlId][
'propwin'].get_dcmd = self.
GetOptData
627 """!Sets option for decoration map overlays
629 if self.parent.MapWindow.overlays[self.
ovlId][
'propwin']
is None:
631 GUI(parent = self.
parent).ParseCommand(cmd = self.
cmd,
635 if self.parent.MapWindow.overlays[self.
ovlId][
'propwin'].IsShown():
636 self.parent.MapWindow.overlays[self.
ovlId][
'propwin'].SetFocus()
638 self.parent.MapWindow.overlays[self.
ovlId][
'propwin'].Show()
641 if self.FindWindowByName(
'resize').
GetValue():
642 self.parent.MapWindow.SetCursor(self.parent.cursors[
"cross"])
643 self.parent.MapWindow.mouse[
'use'] =
'legend'
644 self.parent.MapWindow.mouse[
'box'] =
'box'
645 self.parent.MapWindow.pen = wx.Pen(colour =
'Black', width = 2, style = wx.SHORT_DASH)
647 self.parent.MapWindow.SetCursor(self.parent.cursors[
"default"])
648 self.parent.MapWindow.mouse[
'use'] =
'pointer'
652 if self.
name ==
'legend' and self.FindWindowByName(
'resize').
GetValue():
653 self.FindWindowByName(
'resize').
SetValue(
False)
656 self.parent.dialogs[
'barscale'] =
None
658 if event
and hasattr(self,
'newOverlay'):
659 self.parent.Map.DeleteOverlay(self.
newOverlay)
664 """!Button 'OK' pressed"""
666 self.parent.Map.GetOverlay(self.
ovlId).SetActive(self.chkbox.IsChecked())
669 if self.parent.IsPaneShown(
'3d'):
670 self.parent.MapWindow.UpdateOverlays()
672 self.parent.MapWindow.UpdateMap()
678 """!Process decoration layer data"""
681 self.parent.MapWindow.overlays[self.
ovlId][
'params'] = params
683 self.parent.MapWindow.overlays[self.
ovlId][
'cmd'] = dcmd
684 self.parent.MapWindow.overlays[self.
ovlId][
'propwin'] = propwin
690 self.parent.MapWindow.overlays[self.
ovlId][
'cmd'].remove(
'-m')
694 self.parent.Map.ChangeOverlay(id = self.
ovlId, type = self.
name,
695 command = self.parent.MapWindow.overlays[self.
ovlId][
'cmd'],
696 l_active = self.parent.MapWindow.overlays[self.
ovlId][
'layer'].IsActive(),
697 l_render =
False, l_hidden =
True)
698 if self.
name ==
'legend':
699 if params
and not self.btnOK.IsEnabled():
701 if not self.parent.IsPaneShown(
'3d'):
702 self.FindWindowByName(
'resize').Enable()
706 Controls setting options and displaying/hiding map overlay decorations
709 def __init__(self, parent, ovlId, title, name = 'text',
710 pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_DIALOG_STYLE):
712 wx.Dialog.__init__(self, parent, wx.ID_ANY, title, pos, size, style)
713 from wx.lib.expando
import ExpandoTextCtrl, EVT_ETC_LAYOUT_NEEDED
718 if self.
ovlId in self.parent.MapWindow.textdict.keys():
733 self.
sizer = wx.BoxSizer(wx.VERTICAL)
734 box = wx.GridBagSizer(vgap = 5, hgap = 5)
737 self.
chkbox = wx.CheckBox(parent = self, id = wx.ID_ANY,
738 label = _(
'Show text object'))
739 if self.parent.Map.GetOverlay(self.
ovlId)
is None:
740 self.chkbox.SetValue(
True)
742 self.chkbox.SetValue(self.parent.MapWindow.overlays[self.
ovlId][
'layer'].IsActive())
743 box.Add(item = self.
chkbox, span = (1,2),
744 flag = wx.ALIGN_LEFT|wx.ALL, border = 5,
748 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _(
"Enter text:"))
749 box.Add(item = label,
750 flag = wx.ALIGN_CENTER_VERTICAL,
753 self.
textentry = ExpandoTextCtrl(parent = self, id = wx.ID_ANY, value =
"", size = (300,-1))
754 self.textentry.SetFont(self.
currFont)
755 self.textentry.SetForegroundColour(self.
currClr)
756 self.textentry.SetValue(self.
currText)
758 self.textentry.SetClientSize((300,-1))
764 label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _(
"Rotation:"))
765 box.Add(item = label,
766 flag = wx.ALIGN_CENTER_VERTICAL,
768 self.
rotation = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value =
"", pos = (30, 50),
769 size = (75,-1), style = wx.SP_ARROW_KEYS)
770 self.rotation.SetRange(-360, 360)
771 self.rotation.SetValue(int(self.
currRot))
773 flag = wx.ALIGN_RIGHT,
777 fontbtn = wx.Button(parent = self, id = wx.ID_ANY, label = _(
"Set font"))
778 box.Add(item = fontbtn,
779 flag = wx.ALIGN_RIGHT,
782 self.sizer.Add(item = box, proportion = 1,
783 flag = wx.ALL, border = 10)
786 box = wx.BoxSizer(wx.HORIZONTAL)
787 label = wx.StaticText(parent = self, id = wx.ID_ANY,
788 label = _(
"Drag text with mouse in pointer mode "
789 "to position.\nDouble-click to change options"))
790 box.Add(item = label, proportion = 0,
791 flag = wx.ALIGN_CENTRE | wx.ALL, border = 5)
792 self.sizer.Add(item = box, proportion = 0,
793 flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER | wx.ALL, border = 5)
795 line = wx.StaticLine(parent = self, id = wx.ID_ANY,
796 size = (20,-1), style = wx.LI_HORIZONTAL)
797 self.sizer.Add(item = line, proportion = 0,
798 flag = wx.EXPAND | wx.ALIGN_CENTRE | wx.ALL, border = 5)
800 btnsizer = wx.StdDialogButtonSizer()
802 btn = wx.Button(parent = self, id = wx.ID_OK)
804 btnsizer.AddButton(btn)
806 btn = wx.Button(parent = self, id = wx.ID_CANCEL)
807 btnsizer.AddButton(btn)
810 self.sizer.Add(item = btnsizer, proportion = 0,
811 flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
813 self.SetSizer(self.
sizer)
823 """!Resize text entry to match text"""
827 """!Change text string"""
831 """!Change rotation"""
839 data.EnableEffects(
True)
843 dlg = wx.FontDialog(self, data)
845 if dlg.ShowModal() == wx.ID_OK:
846 data = dlg.GetFontData()
847 self.
currFont = data.GetChosenFont()
848 self.
currClr = data.GetColour()
850 self.textentry.SetFont(self.
currFont)
851 self.textentry.SetForegroundColour(self.
currClr)
858 """!Get text properties"""
864 'active' : self.chkbox.IsChecked() }
867 """!Dialog for creating/editing groups"""
868 def __init__(self, parent = None, defaultGroup = None,
869 title = _(
"Create or edit imagery groups"),
870 style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
872 wx.Dialog.__init__(self, parent = parent, id = wx.ID_ANY, title = title,
873 style = style, **kwargs)
883 btnOk = wx.Button(parent = self, id = wx.ID_OK)
884 btnApply = wx.Button(parent = self, id = wx.ID_APPLY)
885 btnClose = wx.Button(parent = self, id = wx.ID_CANCEL)
887 btnOk.SetToolTipString(_(
"Apply changes to selected group and close dialog"))
888 btnApply.SetToolTipString(_(
"Apply changes to selected group"))
889 btnClose.SetToolTipString(_(
"Close dialog, changes are not applied"))
899 btnSizer = wx.StdDialogButtonSizer()
900 btnSizer.AddButton(btnOk)
901 btnSizer.AddButton(btnApply)
902 btnSizer.AddButton(btnClose)
905 mainSizer = wx.BoxSizer(wx.VERTICAL)
906 mainSizer.Add(item = self.
bodySizer, proportion = 1,
907 flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border = 10)
908 mainSizer.Add(item = wx.StaticLine(parent = self, id = wx.ID_ANY,
909 style = wx.LI_HORIZONTAL), proportion = 0,
910 flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border = 10)
912 mainSizer.Add(item = btnSizer, proportion = 0,
913 flag = wx.ALL | wx.ALIGN_RIGHT, border = 10)
915 self.SetSizer(mainSizer)
918 btnOk.Bind(wx.EVT_BUTTON, self.
OnOk)
919 btnApply.Bind(wx.EVT_BUTTON, self.
OnApply)
920 btnClose.Bind(wx.EVT_BUTTON, self.
OnClose)
923 self.SetMinSize(self.GetSize())
925 def _createDialogBody(self):
926 bodySizer = wx.BoxSizer(wx.VERTICAL)
929 bodySizer.Add(item = wx.StaticText(parent = self, id = wx.ID_ANY,
930 label = _(
"Select the group you want to edit or "
931 "enter name of new group:")),
932 flag = wx.ALIGN_CENTER_VERTICAL | wx.TOP, border = 10)
934 mapsets = [grass.gisenv()[
'MAPSET']],
935 size = globalvar.DIALOG_GSELECT_SIZE)
937 bodySizer.Add(item = self.
groupSelect, flag = wx.TOP | wx.EXPAND, border = 5)
939 bodySizer.AddSpacer(10)
941 bodySizer.Add(item = wx.StaticText(parent = self, label = _(
"Layers in selected group:")),
942 flag = wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM, border = 5)
944 gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
945 gridSizer.AddGrowableCol(0)
947 self.
layerBox = wx.ListBox(parent = self, id = wx.ID_ANY, size = (-1, 150),
948 style = wx.LB_MULTIPLE | wx.LB_NEEDED_SB)
950 gridSizer.Add(item = self.
layerBox, pos = (0, 0), span = (2, 1), flag = wx.EXPAND)
953 self.addLayer.SetToolTipString(_(
"Select map layers and add them to the list."))
954 gridSizer.Add(item = self.
addLayer, pos = (0, 1), flag = wx.EXPAND)
957 self.removeLayer.SetToolTipString(_(
"Remove selected layer(s) from list."))
958 gridSizer.Add(item = self.
removeLayer, pos = (1, 1))
960 bodySizer.Add(item = gridSizer, proportion = 1, flag = wx.EXPAND)
962 self.
infoLabel = wx.StaticText(parent = self, id = wx.ID_ANY)
964 flag = wx.ALIGN_CENTER_VERTICAL | wx.TOP | wx.BOTTOM, border = 5)
966 self.
subGroup = wx.CheckBox(parent = self, id = wx.ID_ANY,
967 label = _(
"Define also sub-group (same name as group)"))
968 self.subGroup.SetValue(
True)
969 bodySizer.Add(item = self.
subGroup, flag = wx.BOTTOM | wx.EXPAND, border = 5)
973 self.addLayer.Bind(wx.EVT_BUTTON, self.
OnAddLayer)
982 """!Add new layer to listbox"""
983 dlg =
MapLayersDialog(parent = self, title = _(
"Add selected map layers into group"),
984 mapType =
'raster', selectAll =
False,
985 fullyQualified =
True, showFullyQualified =
False)
986 if dlg.ShowModal() != wx.ID_OK:
990 layers = dlg.GetMapLayers()
993 self.layerBox.Append(layer)
998 """!Remove layer from listbox"""
999 while self.layerBox.GetSelections():
1000 sel = self.layerBox.GetSelections()[0]
1001 self.layerBox.Delete(sel)
1006 return self.layerBox.GetItems()
1009 """!Text changed in group selector"""
1014 """!Group was selected, check if changes were apllied"""
1017 dlg = wx.MessageDialog(self, message = _(
"Group <%s> was changed, "
1019 caption = _(
"Unapplied changes"),
1020 style = wx.YES_NO | wx.ICON_QUESTION | wx.YES_DEFAULT)
1021 if dlg.ShowModal() == wx.ID_YES:
1038 """!Show map layers in currently selected group"""
1039 self.layerBox.Set(mapList)
1043 """!Edit selected group"""
1049 for layerNew
in layersNew:
1050 if layerNew
not in layersOld:
1051 add.append(layerNew)
1053 for layerOld
in layersOld:
1054 if layerOld
not in layersNew:
1055 remove.append(layerOld)
1058 if self.subGroup.IsChecked():
1059 kwargs[
'subgroup'] = group
1067 input = ','.join(remove),
1074 input =
','.join(add),
1080 """!Create new group"""
1084 if self.subGroup.IsChecked():
1085 kwargs[
'subgroup'] = group
1094 """!Returns existing groups in current mapset"""
1095 return grass.list_grouped(
'group')[grass.gisenv()[
'MAPSET']]
1098 """!Show if operation was successfull."""
1099 group +=
'@' + grass.gisenv()[
'MAPSET']
1100 if returnCode
is None:
1101 label = _(
"No changes to apply in group <%s>.") % group
1102 elif returnCode == 0:
1104 label = _(
"Group <%s> was successfully created.") % group
1106 label = _(
"Group <%s> was successfully changed.") % group
1109 label = _(
"Creating of new group <%s> failed.") % group
1111 label = _(
"Changing of group <%s> failed.") % group
1113 self.infoLabel.SetLabel(label)
1117 """!Return currently selected group (without mapset)"""
1118 return self.groupSelect.GetValue().
split(
'@')[0]
1121 """!Get layers in group"""
1126 read =
True).strip()
1127 if res.split(
'\n')[0]:
1128 return res.split(
'\n')
1132 """!Clear notification string"""
1133 self.infoLabel.SetLabel(
"")
1136 """!Create or edit group"""
1139 GMessage(parent = self,
1140 message = _(
"No group selected."))
1146 self.
ShowResult(group = group, returnCode = ret, create =
False)
1150 self.
ShowResult(group = group, returnCode = ret, create =
True)
1157 """!Apply changes"""
1161 """!Apply changes and close dialog"""
1167 if not self.IsModal():
1172 def __init__(self, parent, title, modeler = False,
1173 mapType =
None, selectAll =
True, fullyQualified =
True, showFullyQualified =
True,
1174 style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
1175 """!Dialog for selecting map layers (raster, vector)
1177 Valid mapType values:
1182 @param mapType type of map (if None: raster, vector, 3d raster, if one only: selects it and disables selection)
1183 @param selectAll all/none maps should be selected by default
1184 @param fullyQualified True if dialog should return full map names by default
1185 @param showFullyQualified True to show 'fullyQualified' checkbox, otherwise hide it
1187 wx.Dialog.__init__(self, parent = parent, id = wx.ID_ANY, title = title,
1188 style = style, **kwargs)
1199 self.mapset.GetStringSelection())
1202 label = _(
"Use fully-qualified map names"))
1203 self.fullyQualified.SetValue(fullyQualified)
1204 self.fullyQualified.Show(showFullyQualified)
1208 self.
dseries = wx.CheckBox(parent = self, id = wx.ID_ANY,
1209 label = _(
"Dynamic series (%s)") %
'g.mlist')
1210 self.dseries.SetValue(
False)
1213 btnCancel = wx.Button(parent = self, id = wx.ID_CANCEL)
1214 btnOk = wx.Button(parent = self, id = wx.ID_OK)
1218 btnSizer = wx.StdDialogButtonSizer()
1219 btnSizer.AddButton(btnCancel)
1220 btnSizer.AddButton(btnOk)
1223 mainSizer = wx.BoxSizer(wx.VERTICAL)
1224 mainSizer.Add(item = self.
bodySizer, proportion = 1,
1225 flag = wx.EXPAND | wx.ALL, border = 5)
1227 flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border = 5)
1229 mainSizer.Add(item = self.
dseries, proportion = 0,
1230 flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border = 5)
1232 mainSizer.Add(item = btnSizer, proportion = 0,
1233 flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
1235 self.SetSizer(mainSizer)
1239 self.SetMinSize(self.GetSize())
1241 def _createDialogBody(self):
1242 bodySizer = wx.GridBagSizer(vgap = 3, hgap = 3)
1245 bodySizer.Add(item = wx.StaticText(parent = self, label = _(
"Map type:")),
1246 flag = wx.ALIGN_CENTER_VERTICAL,
1250 choices = [_(
'raster'), _(
'3D raster'), _(
'vector')], size = (100,-1))
1254 self.layerType.SetSelection(0)
1255 elif self.
mapType ==
'raster3d':
1256 self.layerType.SetSelection(1)
1257 elif self.
mapType ==
'vector':
1258 self.layerType.SetSelection(2)
1259 self.layerType.Disable()
1261 self.layerType.SetSelection(0)
1267 self.
toggle = wx.CheckBox(parent = self, id = wx.ID_ANY,
1268 label = _(
"Select toggle"))
1270 bodySizer.Add(item = self.
toggle,
1271 flag = wx.ALIGN_CENTER_VERTICAL,
1275 bodySizer.Add(item = wx.StaticText(parent = self, label = _(
"Mapset:")),
1276 flag = wx.ALIGN_CENTER_VERTICAL,
1279 self.
mapset = MapsetSelect(parent = self, searchPath =
True)
1280 self.mapset.SetStringSelection(grass.gisenv()[
'MAPSET'])
1281 bodySizer.Add(item = self.
mapset,
1282 pos = (1,1), span = (1, 2))
1285 bodySizer.Add(item = wx.StaticText(parent = self, label = _(
"Pattern:")),
1286 flag = wx.ALIGN_CENTER_VERTICAL,
1289 self.
filter = wx.TextCtrl(parent = self, id = wx.ID_ANY,
1292 bodySizer.Add(item = self.
filter,
1294 pos = (2,1), span = (1, 2))
1297 bodySizer.Add(item = wx.StaticText(parent = self, label = _(
"List of maps:")),
1298 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_TOP,
1300 self.
layers = wx.CheckListBox(parent = self, id = wx.ID_ANY,
1303 bodySizer.Add(item = self.
layers,
1305 pos = (3,1), span = (1, 2))
1307 bodySizer.AddGrowableCol(1)
1308 bodySizer.AddGrowableRow(3)
1312 self.layers.Bind(wx.EVT_RIGHT_DOWN, self.
OnMenu)
1313 self.filter.Bind(wx.EVT_TEXT, self.
OnFilter)
1314 self.toggle.Bind(wx.EVT_CHECKBOX, self.
OnToggle)
1319 """!Load list of map layers
1321 @param type layer type ('raster' or 'vector')
1322 @param mapset mapset name
1324 self.
map_layers = grass.mlist_grouped(type = type)[mapset]
1328 for item
in range(self.layers.GetCount()):
1330 self.layers.Check(item, check = self.
selectAll)
1333 """!Filter parameters changed by user"""
1336 self.mapset.GetStringSelection())
1341 """!Table description area, context menu"""
1342 if not hasattr(self,
"popupID1"):
1357 self.PopupMenu(menu)
1361 """!Select all map layer from list"""
1362 for item
in range(self.layers.GetCount()):
1363 self.layers.Check(item,
True)
1366 """!Invert current selection"""
1367 for item
in range(self.layers.GetCount()):
1368 if self.layers.IsChecked(item):
1369 self.layers.Check(item,
False)
1371 self.layers.Check(item,
True)
1374 """!Select all map layer from list"""
1375 for item
in range(self.layers.GetCount()):
1376 self.layers.Check(item,
False)
1379 """!Apply filter for map names"""
1380 if len(event.GetString()) == 0:
1387 if re.compile(
'^' + event.GetString()).search(layer):
1392 self.layers.Set(list)
1398 """!Select toggle (check or uncheck all layers)"""
1399 check = event.Checked()
1400 for item
in range(self.layers.GetCount()):
1401 self.layers.Check(item, check)
1406 """!Return list of checked map layers"""
1408 for indx
in self.layers.GetSelections():
1412 fullyQualified = self.fullyQualified.IsChecked()
1413 mapset = self.mapset.GetStringSelection()
1414 for item
in range(self.layers.GetCount()):
1415 if not self.layers.IsChecked(item):
1418 layerNames.append(self.layers.GetString(item) +
'@' + mapset)
1420 layerNames.append(self.layers.GetString(item))
1425 """!Get selected layer type
1427 @param cmd True for g.mlist
1430 return self.layerType.GetStringSelection()
1432 sel = self.layerType.GetSelection()
1443 """!Used by modeler only
1445 @return g.mlist command
1447 if not self.
dseries or not self.dseries.IsChecked():
1450 cond =
'map in `g.mlist type=%s ' % self.
GetLayerType(cmd =
True)
1451 patt = self.filter.GetValue()
1453 cond +=
'pattern=%s ' % patt
1454 cond +=
'mapset=%s`' % self.mapset.GetStringSelection()
1459 """!Dialog for bulk import of various data (base class)"""
1461 id = wx.ID_ANY, title = _(
"Multiple import"),
1462 style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
1469 wx.Dialog.__init__(self, parent, id, title, style = style,
1470 name =
"MultiImportDialog")
1472 self.
panel = wx.Panel(parent = self, id = wx.ID_ANY)
1475 label = _(
" List of %s layers ") % self.importType.upper())
1480 columns = [_(
'Layer id'),
1482 _(
'Name for GRASS map (editable)')]
1484 self.list.LoadData()
1487 label =
"%s" % _(
"Options"))
1490 task = gtask.parse_interface(cmd)
1491 for f
in task.get_options()[
'flags']:
1492 name = f.get(
'name',
'')
1493 desc = f.get(
'label',
'')
1495 desc = f.get(
'description',
'')
1496 if not name
and not desc:
1498 if cmd ==
'r.in.gdal' and name
not in (
'o',
'e',
'l',
'k'):
1500 elif cmd ==
'r.external' and name
not in (
'o',
'e',
'r', 'h', 'v'):
1502 elif cmd ==
'v.in.ogr' and name
not in (
'c',
'z',
't',
'o',
'r', 'e', 'w'):
1504 elif cmd ==
'v.external' and name
not in (
'b'):
1506 elif cmd ==
'v.in.dxf' and name
not in (
'e',
't',
'b',
'f',
'i'):
1508 self.
options[name] = wx.CheckBox(parent = self.
panel, id = wx.ID_ANY,
1512 self.optionBox.Hide()
1515 label = _(
"Allow output files to overwrite existing files"))
1516 self.overwrite.SetValue(UserSettings.Get(group =
'cmd', key =
'overwrite', subkey =
'enabled'))
1518 self.
add = wx.CheckBox(parent = self.
panel, id = wx.ID_ANY)
1520 label = _(
"Close dialog on finish"))
1521 self.closeOnFinish.SetValue(UserSettings.Get(group =
'cmd', key =
'closeDlg', subkey =
'enabled'))
1528 self.btn_close.SetToolTipString(_(
"Close dialog"))
1529 self.btn_close.Bind(wx.EVT_BUTTON, self.
OnClose)
1531 self.
btn_run = wx.Button(parent = self.
panel, id = wx.ID_OK, label = _(
"&Import"))
1532 self.btn_run.SetToolTipString(_(
"Import selected layers"))
1533 self.btn_run.SetDefault()
1534 self.btn_run.Enable(
False)
1535 self.btn_run.Bind(wx.EVT_BUTTON, self.
OnRun)
1538 label = _(
"Command dialog"))
1539 self.btn_cmd.Bind(wx.EVT_BUTTON, self.
OnCmdDialog)
1543 dialogSizer = wx.BoxSizer(wx.VERTICAL)
1546 dialogSizer.Add(item = self.dsnInput, proportion = 0,
1552 layerSizer = wx.StaticBoxSizer(self.
layerBox, wx.HORIZONTAL)
1554 layerSizer.Add(item = self.
list, proportion = 1,
1555 flag = wx.ALL | wx.EXPAND, border = 5)
1557 dialogSizer.Add(item = layerSizer, proportion = 1,
1558 flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
1561 if self.optionBox.IsShown():
1562 optionSizer = wx.StaticBoxSizer(self.
optionBox, wx.VERTICAL)
1563 for key
in self.options.keys():
1564 optionSizer.Add(item = self.
options[key], proportion = 0)
1566 dialogSizer.Add(item = optionSizer, proportion = 0,
1567 flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
1569 dialogSizer.Add(item = self.
overwrite, proportion = 0,
1570 flag = wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
1572 dialogSizer.Add(item = self.
add, proportion = 0,
1573 flag = wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
1576 flag = wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
1580 btnsizer = wx.BoxSizer(orient = wx.HORIZONTAL)
1582 btnsizer.Add(item = self.
btn_cmd, proportion = 0,
1583 flag = wx.RIGHT | wx.ALIGN_CENTER,
1586 btnsizer.Add(item = self.
btn_close, proportion = 0,
1587 flag = wx.LEFT | wx.RIGHT | wx.ALIGN_CENTER,
1590 btnsizer.Add(item = self.
btn_run, proportion = 0,
1591 flag = wx.RIGHT | wx.ALIGN_CENTER,
1594 dialogSizer.Add(item = btnsizer, proportion = 0,
1595 flag = wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.ALIGN_RIGHT,
1599 self.panel.SetAutoLayout(
True)
1600 self.panel.SetSizer(dialogSizer)
1601 dialogSizer.Fit(self.
panel)
1604 size = wx.Size(globalvar.DIALOG_GSELECT_SIZE[0] + 225, 550)
1605 self.SetMinSize(size)
1606 self.SetSize((size.width, size.height + 100))
1611 def _getCommand(self):
1620 """!Import/Link data (each layes as separate vector map)"""
1624 """!Show command dialog"""
1628 """!Add imported/linked layers into layer tree"""
1629 if not self.add.IsChecked()
or returncode != 0:
1633 maptree = self.parent.GetLayerTree()
1635 layer, output = self.list.GetLayers()[self.commandId]
1637 if '@' not in output:
1638 name = output +
'@' + grass.gisenv()[
'MAPSET']
1643 if self.importType ==
'gdal':
1646 if UserSettings.Get(group =
'cmd', key =
'rasterOverlay', subkey =
'enabled'):
1649 item = maptree.AddLayer(ltype =
'raster',
1650 lname = name, lchecked =
False,
1651 lcmd = cmd, multiple =
False)
1653 item = maptree.AddLayer(ltype =
'vector',
1654 lname = name, lchecked =
False,
1659 maptree.mapdisplay.MapWindow.ZoomToMap()
1662 """!Abort running import
1664 @todo not yet implemented
1668 class GdalImportDialog(ImportDialog):
1670 """!Dialog for bulk import of various raster/vector data
1672 @param parent parent window
1673 @param ogr True for OGR (vector) otherwise GDAL (raster)
1674 @param link True for linking data otherwise importing data
1680 ImportDialog.__init__(self, parent, itype =
'ogr')
1682 self.SetTitle(_(
"Link external vector data"))
1684 self.SetTitle(_(
"Import vector data"))
1686 ImportDialog.__init__(self, parent, itype =
'gdal')
1688 self.SetTitle(_(
"Link external raster data"))
1690 self.SetTitle(_(
"Import raster data"))
1693 ogr = ogr, link = link)
1696 self.add.SetLabel(_(
"Add linked layers into layer tree"))
1698 self.add.SetLabel(_(
"Add imported layers into layer tree"))
1700 self.add.SetValue(UserSettings.Get(group =
'cmd', key =
'addNewLayer', subkey =
'enabled'))
1703 self.btn_run.SetLabel(_(
"&Link"))
1704 self.btn_run.SetToolTipString(_(
"Link selected layers"))
1706 self.btn_cmd.SetToolTipString(_(
'Open %s dialog') %
'v.external')
1708 self.btn_cmd.SetToolTipString(_(
'Open %s dialog') %
'r.external')
1710 self.btn_run.SetLabel(_(
"&Import"))
1711 self.btn_run.SetToolTipString(_(
"Import selected layers"))
1713 self.btn_cmd.SetToolTipString(_(
'Open %s dialog') %
'v.in.ogr')
1715 self.btn_cmd.SetToolTipString(_(
'Open %s dialog') %
'r.in.gdal')
1720 """!Import/Link data (each layes as separate vector map)"""
1722 data = self.list.GetLayers()
1724 GMessage(_(
"No layers selected. Operation canceled."),
1728 dsn = self.dsnInput.GetDsn()
1729 ext = self.dsnInput.GetFormatExt()
1734 self.dsnInput.GetType() ==
'db' and \
1735 self.dsnInput.GetFormat() ==
'PostgreSQL' and \
1736 'GRASS_VECTOR_OGR' not in os.environ:
1738 os.environ[
'GRASS_VECTOR_OGR'] =
'1'
1740 for layer, output
in data:
1742 if ext
and layer.rfind(ext) > -1:
1743 layer = layer.replace(
'.' + ext,
'')
1745 cmd = [
'v.external',
1747 'output=%s' % output,
1753 'output=%s' % output]
1755 if self.dsnInput.GetType() ==
'dir':
1756 idsn = os.path.join(dsn, layer)
1761 cmd = [
'r.external',
1763 'output=%s' % output]
1767 'output=%s' % output]
1769 if self.overwrite.IsChecked():
1770 cmd.append(
'--overwrite')
1772 for key
in self.options.keys():
1773 if self.
options[key].IsChecked():
1774 cmd.append(
'-%s' % key)
1776 if UserSettings.Get(group =
'cmd', key =
'overwrite', subkey =
'enabled')
and \
1777 '--overwrite' not in cmd:
1778 cmd.append(
'--overwrite')
1781 self.parent.goutput.RunCmd(cmd, switchPage =
True,
1785 os.environ.pop(
'GRASS_VECTOR_OGR')
1787 if self.closeOnFinish.IsChecked():
1790 def _getCommand(self):
1806 """!Show command dialog"""
1808 GUI(parent = self, modal =
False).ParseCommand(cmd = [name])
1811 """!Dialog for bulk import of DXF layers"""
1813 ImportDialog.__init__(self, parent, itype =
'dxf',
1814 title = _(
"Import DXF layers"))
1816 self.
dsnInput = filebrowse.FileBrowseButton(parent = self.
panel, id = wx.ID_ANY,
1817 size = globalvar.DIALOG_GSELECT_SIZE, labelText =
'',
1818 dialogTitle = _(
'Choose DXF file to import'),
1819 buttonText = _(
'Browse'),
1820 startDirectory = os.getcwd(), fileMode = 0,
1822 fileMask =
"DXF File (*.dxf)|*.dxf")
1824 self.add.SetLabel(_(
"Add imported layers into layer tree"))
1826 self.add.SetValue(UserSettings.Get(group =
'cmd', key =
'addNewLayer', subkey =
'enabled'))
1830 def _getCommand(self):
1835 """!Import/Link data (each layes as separate vector map)"""
1836 data = self.list.GetLayers()
1841 inputDxf = self.dsnInput.GetValue()
1843 for layer, output
in data:
1845 'input=%s' % inputDxf,
1846 'layers=%s' % layer,
1847 'output=%s' % output]
1849 for key
in self.options.keys():
1850 if self.
options[key].IsChecked():
1851 cmd.append(
'-%s' % key)
1853 if self.overwrite.IsChecked()
or \
1854 UserSettings.Get(group =
'cmd', key =
'overwrite', subkey =
'enabled'):
1855 cmd.append(
'--overwrite')
1858 self.parent.goutput.RunCmd(cmd, switchPage =
True,
1864 """!Input DXF file defined, update list of layer widget"""
1865 path = event.GetString()
1877 self.list.LoadData()
1878 self.btn_run.Enable(
False)
1881 for line
in ret.splitlines():
1882 layerId = line.split(
':')[0].
split(
' ')[1]
1883 layerName = line.split(
':')[1].strip()
1885 data.append((layerId, layerName.strip(), grassName.strip()))
1887 self.list.LoadData(data)
1889 self.btn_run.Enable(
True)
1891 self.btn_run.Enable(
False)
1894 """!Show command dialog"""
1895 GUI(parent = self, modal =
True).ParseCommand(cmd = [
'v.in.dxf'])
1897 class LayersList(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin,
1898 listmix.CheckListCtrlMixin, listmix.TextEditMixin):
1899 """!List of layers to be imported (dxf, shp...)"""
1903 wx.ListCtrl.__init__(self, parent, wx.ID_ANY,
1904 style = wx.LC_REPORT)
1905 listmix.CheckListCtrlMixin.__init__(self)
1909 listmix.ListCtrlAutoWidthMixin.__init__(self)
1910 listmix.TextEditMixin.__init__(self)
1912 for i
in range(len(columns)):
1913 self.InsertColumn(i, columns[i])
1915 if len(columns) == 3:
1918 width = (65, 180, 110)
1920 for i
in range(len(width)):
1921 self.SetColumnWidth(col = i, width = width[i])
1923 self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.
OnPopupMenu)
1927 """!Load data into list"""
1928 self.DeleteAllItems()
1933 index = self.InsertStringItem(sys.maxint, str(item[0]))
1934 for i
in range(1, len(item)):
1935 self.SetStringItem(index, i,
"%s" % str(item[i]))
1939 self.CheckItem(index,
True)
1942 """!Show popup menu"""
1943 if self.GetItemCount() < 1:
1946 if not hasattr(self,
"popupDataID1"):
1958 self.PopupMenu(menu)
1962 """!Select all items"""
1966 item = self.GetNextItem(item)
1969 self.CheckItem(item,
True)
1974 """!Deselect items"""
1978 item = self.GetNextItem(item, wx.LIST_STATE_SELECTED)
1981 self.CheckItem(item,
False)
1986 """!Allow editing only output name
1988 Code taken from TextEditMixin class.
1990 x, y = event.GetPosition()
1994 for n
in range(self.GetColumnCount()):
1995 loc = loc + self.GetColumnWidth(n)
1998 col = bisect(colLocs, x + self.GetScrollPos(wx.HORIZONTAL)) - 1
2000 if col == self.GetColumnCount() - 1:
2001 listmix.TextEditMixin.OnLeftDown(self, event)
2006 """!Get list of layers (layer name, output name)"""
2010 item = self.GetNextItem(item)
2013 if not self.IsChecked(item):
2016 data.append((self.GetItem(item, 1).GetText(),
2017 self.GetItem(item, self.GetColumnCount() - 1).GetText()))
2022 """!Set opacity of map layers"""
2023 def __init__(self, parent, id = wx.ID_ANY, title = _(
"Set Map Layer Opacity"),
2024 size = wx.DefaultSize, pos = wx.DefaultPosition,
2025 style = wx.DEFAULT_DIALOG_STYLE, opacity = 100):
2030 super(SetOpacityDialog, self).
__init__(parent, id = id, pos = pos,
2031 size = size, style = style, title = title)
2033 panel = wx.Panel(parent = self, id = wx.ID_ANY)
2035 sizer = wx.BoxSizer(wx.VERTICAL)
2037 box = wx.GridBagSizer(vgap = 5, hgap = 5)
2039 style = wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | \
2040 wx.SL_TOP | wx.SL_LABELS,
2041 minValue = 0, maxValue = 100,
2044 box.Add(item = self.
value,
2045 flag = wx.ALIGN_CENTRE, pos = (0, 0), span = (1, 2))
2046 box.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
2047 label = _(
"transparent")),
2049 box.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
2050 label = _(
"opaque")),
2051 flag = wx.ALIGN_RIGHT,
2054 sizer.Add(item = box, proportion = 0,
2055 flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border = 5)
2057 line = wx.StaticLine(parent = panel, id = wx.ID_ANY,
2058 style = wx.LI_HORIZONTAL)
2059 sizer.Add(item = line, proportion = 0,
2060 flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border = 5)
2063 btnsizer = wx.StdDialogButtonSizer()
2065 btnOK = wx.Button(parent = panel, id = wx.ID_OK)
2067 btnsizer.AddButton(btnOK)
2069 btnCancel = wx.Button(parent = panel, id = wx.ID_CANCEL)
2070 btnsizer.AddButton(btnCancel)
2072 btnApply = wx.Button(parent = panel, id = wx.ID_APPLY)
2073 btnApply.Bind(wx.EVT_BUTTON, self.
OnApply)
2074 btnsizer.AddButton(btnApply)
2077 sizer.Add(item = btnsizer, proportion = 0,
2078 flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border = 5)
2080 panel.SetSizer(sizer)
2083 self.SetSize(self.GetBestSize())
2088 """!Button 'OK' pressed"""
2090 opacity = float(self.value.GetValue()) / 100
2094 event = wxApplyOpacity(value = self.
GetOpacity())
2095 wx.PostEvent(self, event)
2098 """!Get list of supported image handlers"""
2101 for h
in image.GetHandlers():
2102 lext.append(h.GetExtension())
2106 filetype +=
"PNG file (*.png)|*.png|"
2107 ltype.append({
'type' : wx.BITMAP_TYPE_PNG,
2109 filetype +=
"BMP file (*.bmp)|*.bmp|"
2110 ltype.append({
'type' : wx.BITMAP_TYPE_BMP,
2113 filetype +=
"GIF file (*.gif)|*.gif|"
2114 ltype.append({
'type' : wx.BITMAP_TYPE_GIF,
2118 filetype +=
"JPG file (*.jpg)|*.jpg|"
2119 ltype.append({
'type' : wx.BITMAP_TYPE_JPEG,
2123 filetype +=
"PCX file (*.pcx)|*.pcx|"
2124 ltype.append({
'type' : wx.BITMAP_TYPE_PCX,
2128 filetype +=
"PNM file (*.pnm)|*.pnm|"
2129 ltype.append({
'type' : wx.BITMAP_TYPE_PNM,
2133 filetype +=
"TIF file (*.tif)|*.tif|"
2134 ltype.append({
'type' : wx.BITMAP_TYPE_TIF,
2138 filetype +=
"XPM file (*.xpm)|*.xpm"
2139 ltype.append({
'type' : wx.BITMAP_TYPE_XPM,
2142 return filetype, ltype
2145 """!Set size for saved graphic file"""
2146 def __init__(self, parent, id = wx.ID_ANY, title = _(
"Set image size"),
2147 style = wx.DEFAULT_DIALOG_STYLE, **kwargs):
2150 wx.Dialog.__init__(self, parent, id = id, style = style, title = title, **kwargs)
2152 self.
panel = wx.Panel(parent = self, id = wx.ID_ANY)
2154 self.
box = wx.StaticBox(parent = self.
panel, id = wx.ID_ANY,
2155 label =
' % s' % _(
"Image size"))
2157 size = self.parent.GetWindow().GetClientSize()
2159 style = wx.SP_ARROW_KEYS)
2160 self.width.SetRange(20, 1e6)
2161 self.width.SetValue(size.width)
2162 wx.CallAfter(self.width.SetFocus)
2164 style = wx.SP_ARROW_KEYS)
2165 self.height.SetRange(20, 1e6)
2166 self.height.SetValue(size.height)
2178 self.btnOK.SetDefault()
2181 self.template.Bind(wx.EVT_CHOICE, self.
OnTemplate)
2184 self.SetSize(self.GetBestSize())
2188 sizer = wx.BoxSizer(wx.VERTICAL)
2191 box = wx.StaticBoxSizer(self.
box, wx.HORIZONTAL)
2192 fbox = wx.FlexGridSizer(cols = 2, vgap = 5, hgap = 5)
2193 fbox.Add(item = wx.StaticText(parent = self.
panel, id = wx.ID_ANY,
2194 label = _(
"Width:")),
2195 flag = wx.ALIGN_CENTER_VERTICAL)
2196 fbox.Add(item = self.
width)
2197 fbox.Add(item = wx.StaticText(parent = self.
panel, id = wx.ID_ANY,
2198 label = _(
"Height:")),
2199 flag = wx.ALIGN_CENTER_VERTICAL)
2200 fbox.Add(item = self.
height)
2201 fbox.Add(item = wx.StaticText(parent = self.
panel, id = wx.ID_ANY,
2202 label = _(
"Template:")),
2203 flag = wx.ALIGN_CENTER_VERTICAL)
2206 box.Add(item = fbox, proportion = 1,
2207 flag = wx.EXPAND | wx.ALL, border = 5)
2208 sizer.Add(item = box, proportion = 1,
2209 flag = wx.EXPAND | wx.ALL, border = 3)
2212 btnsizer = wx.StdDialogButtonSizer()
2213 btnsizer.AddButton(self.
btnOK)
2217 sizer.Add(item = btnsizer, proportion = 0,
2218 flag = wx.EXPAND | wx.ALIGN_RIGHT | wx.ALL, border = 5)
2220 self.panel.SetSizer(sizer)
2221 sizer.Fit(self.
panel)
2225 """!Get width/height values"""
2226 return self.width.GetValue(), self.height.GetValue()
2229 """!Template selected"""
2230 sel = event.GetString()
2232 width, height = self.parent.GetWindow().GetClientSize()
2234 width, height = map(int, sel.split(
'x'))
2235 self.width.SetValue(width)
2236 self.height.SetValue(height)
2239 """!Dialog for GRASS symbols selection.
2241 Dialog is called in gui_core::forms module.
2243 def __init__(self, parent, symbolPath, currentSymbol = None, title = _(
"Symbols")):
2244 """!Dialog constructor.
2246 It is assumed that symbolPath contains folders with symbols.
2248 @param parent dialog parent
2249 @param symbolPath absolute path to symbols
2250 @param currentSymbol currently selected symbol (e.g. 'basic/x')
2251 @param title dialog title
2253 wx.Dialog.__init__(self, parent = parent, title = title, id = wx.ID_ANY)
2263 mainPanel = wx.Panel(self, id = wx.ID_ANY)
2264 mainSizer = wx.BoxSizer(wx.VERTICAL)
2265 vSizer = wx.BoxSizer( wx.VERTICAL)
2266 fgSizer = wx.FlexGridSizer(rows = 2, vgap = 5, hgap = 5)
2270 fgSizer.Add(item = wx.StaticText(mainPanel, id = wx.ID_ANY, label = _(
"Symbol directory:")),
2272 flag = wx.ALIGN_CENTER_VERTICAL)
2275 flag = wx.ALIGN_CENTER, border = 0)
2278 fgSizer.Add(wx.StaticText(mainPanel, id = wx.ID_ANY, label = _(
"Symbol name:")),
2279 flag = wx.ALIGN_CENTRE_VERTICAL)
2280 fgSizer.Add(self.
infoLabel, proportion = 0,
2281 flag = wx.ALIGN_CENTRE_VERTICAL)
2282 vSizer.Add(fgSizer, proportion = 0, flag = wx.ALL, border = 5)
2285 for panel
in self.
panels:
2286 vSizer.Add(panel, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
2289 mainSizer.Add(vSizer, proportion = 1, flag = wx.ALL| wx.EXPAND, border = 5)
2290 self.
btnCancel = wx.Button(parent = mainPanel, id = wx.ID_CANCEL)
2291 self.
btnOK = wx.Button(parent = mainPanel, id = wx.ID_OK)
2292 self.btnOK.SetDefault()
2293 self.btnOK.Enable(
False)
2296 btnSizer = wx.StdDialogButtonSizer()
2298 btnSizer.AddButton(self.
btnOK)
2300 mainSizer.Add(item = btnSizer, proportion = 0,
2301 flag = wx.EXPAND | wx.ALL, border = 5)
2306 count.append(len(os.listdir(os.path.join(self.
symbolPath, folder))))
2308 index = count.index(
max(count))
2309 self.folderChoice.SetSelection(index)
2311 self.infoLabel.Show()
2313 mainPanel.SetSizerAndFit(mainSizer)
2314 self.SetSize(self.GetBestSize())
2320 self.folderChoice.SetStringSelection(self.
selectedDir)
2322 panelIdx = self.folderChoice.GetSelection()
2324 if panel.GetName() == self.
selected:
2327 self.folderChoice.SetSelection(0)
2331 def _createSymbolPanels(self, parent):
2332 """!Creates multiple panels with symbols.
2334 Panels are shown/hidden according to selected folder."""
2341 for folder
in folders:
2342 panel = wx.Panel(parent, style = wx.BORDER_RAISED)
2343 sizer = wx.GridSizer(cols = 6, vgap = 3, hgap = 3)
2348 iP = SingleSymbolPanel(parent = panel, symbolPath = img)
2349 sizer.Add(item = iP, proportion = 0, flag = wx.ALIGN_CENTER)
2350 symbolPanels.append(iP)
2352 panel.SetSizerAndFit(sizer)
2354 panels.append(panel)
2355 self.symbolPanels.append(symbolPanels)
2359 def _getSymbols(self, path):
2362 for image
in os.listdir(path):
2363 imageList.append(os.path.join(path, image))
2365 return sorted(imageList)
2368 """!Selected folder with symbols changed."""
2369 idx = self.folderChoice.GetSelection()
2371 sizer = self.
panels[i].GetContainingSizer()
2372 sizer.Show(self.
panels[i], i == idx, recursive =
True)
2375 if self.
selectedDir == self.folderChoice.GetStringSelection():
2377 self.infoLabel.SetLabel(self.
selected)
2379 self.btnOK.Disable()
2380 self.infoLabel.SetLabel(
'')
2383 """!Selected symbol changed."""
2384 if event.doubleClick:
2385 self.EndModal(wx.ID_OK)
2389 if panel.GetName() != event.name:
2395 self.
selectedDir = self.folderChoice.GetStringSelection()
2397 self.infoLabel.SetLabel(event.name)
2400 """!Returns currently selected symbol name (e.g. 'basic/x').
2406 """!Returns currently selected symbol full path.
2411 """!Simple dialog with text field.
2413 It differs from wx.TextEntryDialog because it allows adding validator.
2415 def __init__(self, parent, message, caption='',
2416 defaultValue=
'', pos=wx.DefaultPosition, validator=wx.DefaultValidator,
2417 style=wx.OK | wx.CANCEL):
2418 wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY, title=caption, pos=pos)
2420 vbox = wx.BoxSizer(wx.VERTICAL)
2422 stline = wx.StaticText(self, id=wx.ID_ANY, label=message)
2423 vbox.Add(item=stline, proportion=0, flag=wx.EXPAND | wx.ALL, border=10)
2425 self.
_textCtrl = wx.TextCtrl(self, id=wx.ID_ANY, size = (300, -1),
2426 value=defaultValue, validator=validator)
2427 vbox.Add(item=self.
_textCtrl, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=10)
2428 self._textCtrl.SetFocus()
2430 sizer = self.CreateSeparatedButtonSizer(style)
2431 vbox.Add(item=sizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=10)
2433 self.SetSizerAndFit(vbox)
2436 return self._textCtrl.GetValue()
2439 self._textCtrl.SetValue(value)
2443 """!Dialog for displaying message with hyperlink."""
2444 def __init__(self, parent, title, message, hyperlink,
2445 hyperlinkLabel=
None, style=wx.OK):
2448 @param parent gui parent
2449 @param title dialog title
2450 @param message message
2451 @param hyperlink url
2452 @param hyperlinkLabel label shown instead of url
2453 @param style button style
2455 wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY, title=title,
2456 style=wx.DEFAULT_DIALOG_STYLE)
2458 sizer = wx.BoxSizer(wx.VERTICAL)
2460 label = wx.StaticText(self, label=message)
2461 sizer.Add(item=label, proportion=0, flag=wx.ALIGN_CENTRE|wx.ALL, border=10)
2462 hyperlinkLabel = hyperlinkLabel
if hyperlinkLabel
else hyperlink
2463 hyperlinkCtrl = wx.HyperlinkCtrl(self, id=wx.ID_ANY,
2464 label=hyperlinkLabel, url=hyperlink,
2465 style=wx.HL_ALIGN_LEFT|wx.HL_CONTEXTMENU)
2466 sizer.Add(item=hyperlinkCtrl, proportion=0, flag=wx.EXPAND|wx.ALL, border=10)
2468 btnsizer = self.CreateSeparatedButtonSizer(style)
2469 sizer.Add(item=btnsizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=10)
2471 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 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 OnCancel
Cancel dialog.
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 GetName
Return region name.
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 _createOverlay
Creates overlay.
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 or 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.