[GRASS-SVN] r48915 - in grass/branches/develbranch_6/gui/wxpython:
. gui_modules xml
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Oct 23 03:20:26 EDT 2011
Author: annakrat
Date: 2011-10-23 00:20:26 -0700 (Sun, 23 Oct 2011)
New Revision: 48915
Modified:
grass/branches/develbranch_6/gui/wxpython/gui_modules/gcpmanager.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
grass/branches/develbranch_6/gui/wxpython/wxgui.py
grass/branches/develbranch_6/gui/wxpython/xml/menudata.xml
Log:
wxGUI: custom dialog (GroupDialog) for editing imagery groups added (merge from trunk)
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gcpmanager.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gcpmanager.py 2011-10-22 20:39:05 UTC (rev 48914)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gcpmanager.py 2011-10-23 07:20:26 UTC (rev 48915)
@@ -43,6 +43,7 @@
import toolbars
import menuform
import gselect
+import gdialogs
import gcmd
import utils
from debug import Debug as Debug
@@ -499,9 +500,19 @@
def OnMkGroup(self, event):
"""!Create new group in source location/mapset"""
- menuform.GUI(parent = self.parent.parent, modal = True).ParseCommand(['i.group'],
- completed = (self.GetOptData, None, ''))
+ dlg = gdialogs.GroupDialog(parent = self, defaultGroup = self.xygroup)
+
+ dlg.ShowModal()
+ gr = dlg.GetSelectedGroup()
+ if gr in dlg.GetExistGroups():
+ self.xygroup = gr
+ else:
+ gr = ''
+ dlg.Destroy()
+ self.OnEnterPage()
+ self.Update()
+
def OnVGroup(self, event):
"""!Add vector maps to group"""
dlg = VectGroup(parent = self,
@@ -517,15 +528,6 @@
dlg.MakeVGroup()
self.OnEnterPage()
- def GetOptData(self, dcmd, layer, params, propwin):
- """!Process i.group"""
- # update the page
- if dcmd:
- gcmd.Command(dcmd)
-
- self.OnEnterPage()
- self.Update()
-
def OnExtension(self, event):
self.extension = event.GetString()
@@ -581,10 +583,12 @@
utils.ListSortLower(self.groupList)
self.cb_group.SetItems(self.groupList)
- if len(self.groupList) > 0 and \
- self.xygroup == '':
- self.cb_group.SetSelection(0)
- self.xygroup = self.groupList[0]
+ if len(self.groupList) > 0:
+ if self.xygroup and self.xygroup in self.groupList:
+ self.cb_group.SetStringSelection(self.xygroup)
+ else:
+ self.cb_group.SetSelection(0)
+ self.xygroup = self.groupList[0]
if self.xygroup == '' or \
self.extension == '':
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py 2011-10-22 20:39:05 UTC (rev 48914)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py 2011-10-23 07:20:26 UTC (rev 48915)
@@ -11,6 +11,7 @@
- SavedRegion
- DecorationDialog
- TextLayerDialog
+ - GroupDialog
- MapLayersDialog
- ImportDialog
- GdalImportDialog
@@ -27,6 +28,7 @@
for details.
@author Martin Landa <landa.martin gmail.com>
+ at author Anna Kratochvilova <kratochanna gmail.com> (GroupDialog)
"""
import os
@@ -848,14 +850,313 @@
'coords' : self.currCoords,
'active' : self.chkbox.IsChecked() }
+class GroupDialog(wx.Dialog):
+ """!Dialog for creating/editing groups"""
+ def __init__(self, parent = None, defaultGroup = None,
+ title = _("Create or edit imagery groups"),
+ style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
+
+ wx.Dialog.__init__(self, parent = parent, id = wx.ID_ANY, title = title,
+ style = style, **kwargs)
+
+ self.parent = parent
+ self.defaultGroup = defaultGroup
+ self.currentGroup = self.defaultGroup
+ self.groupChanged = False
+
+ self.bodySizer = self._createDialogBody()
+
+ # buttons
+ btnOk = wx.Button(parent = self, id = wx.ID_OK)
+ btnApply = wx.Button(parent = self, id = wx.ID_APPLY)
+ btnClose = wx.Button(parent = self, id = wx.ID_CANCEL)
+
+ btnOk.SetToolTipString(_("Apply changes to selected group and close dialog"))
+ btnApply.SetToolTipString(_("Apply changes to selected group"))
+ btnClose.SetToolTipString(_("Close dialog, changes are not applied"))
+
+ btnOk.SetDefault()
+
+ # sizers & do layout
+ # btnSizer = wx.BoxSizer(wx.HORIZONTAL)
+ # btnSizer.Add(item = btnClose, proportion = 0,
+ # flag = wx.RIGHT | wx.ALIGN_RIGHT | wx.EXPAND, border = 5)
+ # btnSizer.Add(item = btnApply, proportion = 0,
+ # flag = wx.LEFT, border = 5)
+ btnSizer = wx.StdDialogButtonSizer()
+ btnSizer.AddButton(btnOk)
+ btnSizer.AddButton(btnApply)
+ btnSizer.AddButton(btnClose)
+ btnSizer.Realize()
+
+ mainSizer = wx.BoxSizer(wx.VERTICAL)
+ mainSizer.Add(item = self.bodySizer, proportion = 1,
+ flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border = 10)
+ mainSizer.Add(item = wx.StaticLine(parent = self, id = wx.ID_ANY,
+ style = wx.LI_HORIZONTAL), proportion = 0,
+ flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border = 10)
+
+ mainSizer.Add(item = btnSizer, proportion = 0,
+ flag = wx.ALL | wx.ALIGN_RIGHT, border = 10)
+
+ self.SetSizer(mainSizer)
+ mainSizer.Fit(self)
+
+ btnOk.Bind(wx.EVT_BUTTON, self.OnOk)
+ btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
+ btnClose.Bind(wx.EVT_BUTTON, self.OnClose)
+
+ # set dialog min size
+ self.SetMinSize(self.GetSize())
+
+ def _createDialogBody(self):
+ bodySizer = wx.BoxSizer(wx.VERTICAL)
+
+ # group selection
+ bodySizer.Add(item = wx.StaticText(parent = self, id = wx.ID_ANY,
+ label = _("Select the group you want to edit or "
+ "enter name of new group:")),
+ flag = wx.ALIGN_CENTER_VERTICAL | wx.TOP, border = 10)
+ self.groupSelect = gselect.Select(parent = self, type = 'group',
+ mapsets = [grass.gisenv()['MAPSET']],
+ size = globalvar.DIALOG_GSELECT_SIZE) # searchpath?
+
+ bodySizer.Add(item = self.groupSelect, flag = wx.TOP | wx.EXPAND, border = 5)
+
+ bodySizer.AddSpacer(10)
+ # layers in group
+ bodySizer.Add(item = wx.StaticText(parent = self, label = _("Layers in selected group:")),
+ flag = wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM, border = 5)
+
+ gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
+ gridSizer.AddGrowableCol(0)
+
+ self.layerBox = wx.ListBox(parent = self, id = wx.ID_ANY, size = (-1, 150),
+ style = wx.LB_MULTIPLE | wx.LB_NEEDED_SB)
+
+ gridSizer.Add(item = self.layerBox, pos = (0, 0), span = (2, 1), flag = wx.EXPAND)
+
+ self.addLayer = wx.Button(self, id = wx.ID_ADD)
+ self.addLayer.SetToolTipString(_("Select map layers and add them to the list."))
+ gridSizer.Add(item = self.addLayer, pos = (0, 1))
+
+ self.removeLayer = wx.Button(self, id = wx.ID_REMOVE)
+ self.removeLayer.SetToolTipString(_("Remove selected layer(s) from list."))
+ gridSizer.Add(item = self.removeLayer, pos = (1, 1))
+
+ bodySizer.Add(item = gridSizer, proportion = 1, flag = wx.EXPAND)
+
+ self.infoLabel = wx.StaticText(parent = self, id = wx.ID_ANY)
+ bodySizer.Add(item = self.infoLabel,
+ flag = wx.ALIGN_CENTER_VERTICAL | wx.TOP | wx.BOTTOM, border = 5)
+
+ # bindings
+ self.groupSelect.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnGroupSelected)
+ self.addLayer.Bind(wx.EVT_BUTTON, self.OnAddLayer)
+ self.removeLayer.Bind(wx.EVT_BUTTON, self.OnRemoveLayer)
+
+ if self.defaultGroup:
+ self.groupSelect.SetValue(self.defaultGroup)
+
+ return bodySizer
+
+ def OnAddLayer(self, event):
+ """!Add new layer to listbox"""
+ dlg = MapLayersDialog(parent = self, title = _("Add selected map layers into group"),
+ mapType = 'raster', selectAll = False,
+ fullyQualified = True, showFullyQualified = False)
+ if dlg.ShowModal() != wx.ID_OK:
+ dlg.Destroy()
+ return
+
+ layers = dlg.GetMapLayers()
+ for layer in layers:
+ if layer not in self.GetLayers():
+ self.layerBox.Append(layer)
+ self.groupChanged = True
+
+
+ def OnRemoveLayer(self, event):
+ """!Remove layer from listbox"""
+ while self.layerBox.GetSelections():
+ sel = self.layerBox.GetSelections()[0]
+ self.layerBox.Delete(sel)
+ self.groupChanged = True
+
+ def GetLayers(self):
+ """!Get layers"""
+ return self.layerBox.GetItems()
+
+ def OnGroupSelected(self, event):
+ """!Text changed in group selector"""
+ # callAfter must be called to close popup before other actions
+ wx.CallAfter(self.GroupSelected)
+
+ def GroupSelected(self):
+ """!Group was selected, check if changes were apllied"""
+ group = self.GetSelectedGroup()
+ if self.groupChanged:
+ dlg = wx.MessageDialog(self, message = _("Group <%s> was changed, "
+ "do you want to apply changes?") % self.currentGroup,
+ caption = _("Unapplied changes"),
+ style = wx.YES_NO | wx.ICON_QUESTION | wx.YES_DEFAULT)
+ if dlg.ShowModal() == wx.ID_YES:
+ self.ApplyChanges(showResult = True)
+
+ dlg.Destroy()
+
+
+
+ groups = self.GetExistGroups()
+ if group in groups:
+ self.ShowGroupLayers(self.GetGroupLayers(group))
+
+ self.currentGroup = group
+ self.groupChanged = False
+
+ self.ClearNotification()
+
+ def ShowGroupLayers(self, mapList):
+ """!Show map layers in currently selected group"""
+ self.layerBox.Set(mapList)
+
+
+ def EditGroup(self, group):
+ """!Edit selected group"""
+ layersNew = self.GetLayers()
+ layersOld = self.GetGroupLayers(group)
+
+ add = []
+ remove = []
+ for layerNew in layersNew:
+ if layerNew not in layersOld:
+ add.append(layerNew)
+
+ for layerOld in layersOld:
+ if layerOld not in layersNew:
+ remove.append(layerOld)
+
+ ret = None
+ if remove:
+ ret = gcmd.RunCommand('i.group',
+ parent = self,
+ group = group,
+ flags = 'r',
+ input = ','.join(remove))
+
+ if add:
+ ret = gcmd.RunCommand('i.group',
+ parent = self,
+ group = group,
+ input = ','.join(add))
+
+ return ret
+
+ def CreateNewGroup(self, group):
+ """!Create new group"""
+ layers = self.GetLayers()
+ ret = gcmd.RunCommand('i.group',
+ parent = self,
+ group = group,
+ input = layers)
+ return ret
+
+
+ def GetExistGroups(self):
+ """!Returns existing groups in current mapset"""
+ return grass.list_grouped('group')[grass.gisenv()['MAPSET']]
+
+ def ShowResult(self, group, returnCode, create):
+ """!Show if operation was successfull."""
+ group += '@' + grass.gisenv()['MAPSET']
+ if returnCode is None:
+ label = _("No changes to apply in group <%s>.") % group
+ elif returnCode == 0:
+ if create:
+ label = _("Group <%s> was successfully created.") % group
+ else:
+ label = _("Group <%s> was successfully changed.") % group
+ else:
+ if create:
+ label = _("Creating of new group <%s> failed.") % group
+ else:
+ label = _("Changing of group <%s> failed.") % group
+
+ self.infoLabel.SetLabel(label)
+ wx.FutureCall(4000, self.ClearNotification)
+
+ def GetSelectedGroup(self):
+ """!Return currently selected group (without mapset)"""
+ return self.groupSelect.GetValue().split('@')[0]
+
+ def GetGroupLayers(self, group):
+ """!Get layers in group"""
+ res = gcmd.RunCommand('i.group',
+ parent = self,
+ flags = 'g',
+ group = group,
+ read = True).strip()
+ if res.split('\n')[0]:
+ return res.split('\n')
+ return []
+
+ def ClearNotification(self):
+ """!Clear notification string"""
+ self.infoLabel.SetLabel("")
+
+ def ApplyChanges(self, showResult):
+ """!Create or edit group"""
+ group = self.currentGroup
+ if not group:
+ gcmd.GMessage(parent = self,
+ message = _("No group selected."))
+ return False
+
+ groups = self.GetExistGroups()
+ if group in groups:
+ ret = self.EditGroup(group)
+ self.ShowResult(group = group, returnCode = ret, create = False)
+
+ else:
+ ret = self.CreateNewGroup(group)
+ self.ShowResult(group = group, returnCode = ret, create = True)
+
+ self.groupChanged = False
+
+ return True
+
+ def OnApply(self, event):
+ """!Apply changes"""
+ self.ApplyChanges(showResult = True)
+
+ def OnOk(self, event):
+ """!Apply changes and close dialog"""
+ if self.ApplyChanges(showResult = False):
+ self.OnClose(event)
+
+ def OnClose(self, event):
+ """!Close dialog"""
+ if not self.IsModal():
+ self.Destroy()
+ event.Skip()
+
class MapLayersDialog(wx.Dialog):
def __init__(self, parent, title, modeler = False,
+ mapType = None, selectAll = True, fullyQualified = True, showFullyQualified = True,
style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
- """!Dialog for selecting map layers (raster, vector)"""
+ """!Dialog for selecting map layers (raster, vector)
+
+ @param mapType type of map (if None: raster, vector, 3d raster, if one only: selects it and disables selection)
+ @param selectAll all/none maps should be selected by default
+ @param fullyQualified True if dialog should return full map names by default
+ @param showFullyQualified True to show 'fullyQualified' checkbox, otherwise hide it
+ """
wx.Dialog.__init__(self, parent = parent, id = wx.ID_ANY, title = title,
style = style, **kwargs)
self.parent = parent # GMFrame or ?
+ self.mapType = mapType
+ self.selectAll = selectAll
# dialog body
self.bodySizer = self._createDialogBody()
@@ -866,7 +1167,8 @@
self.fullyQualified = wx.CheckBox(parent = self, id = wx.ID_ANY,
label = _("Use fully-qualified map names"))
- self.fullyQualified.SetValue(True)
+ self.fullyQualified.SetValue(fullyQualified)
+ self.fullyQualified.Show(showFullyQualified)
self.dseries = None
if modeler:
@@ -915,14 +1217,20 @@
self.layerType = wx.Choice(parent = self, id = wx.ID_ANY,
choices = [_('raster'), _('3D raster'), _('vector')], size = (100,-1))
- self.layerType.SetSelection(0)
+
+ if self.mapType:
+ self.layerType.SetStringSelection(self.mapType)
+ self.layerType.Disable()
+ else:
+ self.layerType.SetSelection(0)
+
bodySizer.Add(item = self.layerType,
pos = (0,1))
# select toggle
self.toggle = wx.CheckBox(parent = self, id = wx.ID_ANY,
label = _("Select toggle"))
- self.toggle.SetValue(True)
+ self.toggle.SetValue(self.selectAll)
bodySizer.Add(item = self.toggle,
flag = wx.ALIGN_CENTER_VERTICAL,
pos = (0,2))
@@ -980,7 +1288,8 @@
# check all items by default
for item in range(self.layers.GetCount()):
- self.layers.Check(item)
+
+ self.layers.Check(item, check = self.selectAll)
def OnChangeParams(self, event):
"""!Filter parameters changed by user"""
Modified: grass/branches/develbranch_6/gui/wxpython/wxgui.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/wxgui.py 2011-10-22 20:39:05 UTC (rev 48914)
+++ grass/branches/develbranch_6/gui/wxpython/wxgui.py 2011-10-23 07:20:26 UTC (rev 48915)
@@ -1089,6 +1089,13 @@
# reset display mode
os.environ['GRASS_RENDER_IMMEDIATE'] = 'TRUE'
+ def OnEditImageryGroups(self, event, cmd = None):
+ """!Show dialog for creating and editing groups.
+ """
+ dlg = gdialogs.GroupDialog(self)
+ dlg.CentreOnScreen()
+ dlg.Show()
+
def OnInstallExtension(self, event):
"""!Install extension from GRASS Addons SVN repository"""
win = InstallExtensionWindow(self, size = (650, 550))
Modified: grass/branches/develbranch_6/gui/wxpython/xml/menudata.xml
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/xml/menudata.xml 2011-10-22 20:39:05 UTC (rev 48914)
+++ grass/branches/develbranch_6/gui/wxpython/xml/menudata.xml 2011-10-23 07:20:26 UTC (rev 48915)
@@ -744,7 +744,7 @@
<menuitem>
<label>User access</label>
<help>Controls access to the current mapset for other users on the system.</help>
- <keywords>general,map management</keywords>
+ <keywords>general,map management,permission</keywords>
<handler>OnMenuCmd</handler>
<command>g.access</command>
</menuitem>
@@ -1792,8 +1792,8 @@
</menuitem>
<menuitem>
<label>Total corrected area</label>
- <help>Surface area estimation for rasters.</help>
- <keywords>raster,statistics</keywords>
+ <help>Prints estimation of surface area for raster map.</help>
+ <keywords>raster,surface,statistics,area estimation</keywords>
<handler>OnMenuCmd</handler>
<command>r.surf.area</command>
</menuitem>
@@ -2473,9 +2473,9 @@
<items>
<menuitem>
<label>Create/edit group</label>
- <help>Creates, edits, and lists groups and subgroups of imagery data.</help>
+ <help>Creates, edits, and lists groups of imagery files.</help>
<keywords>imagery,map management</keywords>
- <handler>OnMenuCmd</handler>
+ <handler>OnEditImageryGroups</handler>
<command>i.group</command>
</menuitem>
<menuitem>
More information about the grass-commit
mailing list