[GRASS-SVN] r57724 - grass/trunk/gui/wxpython/iclass
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Sep 17 03:07:31 PDT 2013
Author: turek
Date: 2013-09-17 03:07:31 -0700 (Tue, 17 Sep 2013)
New Revision: 57724
Modified:
grass/trunk/gui/wxpython/iclass/dialogs.py
grass/trunk/gui/wxpython/iclass/frame.py
grass/trunk/gui/wxpython/iclass/plots.py
grass/trunk/gui/wxpython/iclass/toolbars.py
Log:
wx.iclass: support for any name of subgroup, not just same name as group
Modified: grass/trunk/gui/wxpython/iclass/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/iclass/dialogs.py 2013-09-17 10:04:24 UTC (rev 57723)
+++ grass/trunk/gui/wxpython/iclass/dialogs.py 2013-09-17 10:07:31 UTC (rev 57724)
@@ -28,7 +28,7 @@
from core import globalvar
from core.utils import _
from core.settings import UserSettings
-from core.gcmd import GMessage
+from core.gcmd import GError, RunCommand, GMessage
from gui_core.dialogs import SimpleDialog, GroupDialog
from gui_core import gselect
from gui_core.widgets import SimpleValidator
@@ -38,7 +38,8 @@
class IClassGroupDialog(SimpleDialog):
"""!Dialog for imagery group selection"""
- def __init__(self, parent, group = None, title = _("Select imagery group"), id = wx.ID_ANY):
+ def __init__(self, parent, group = None, subgroup = None,
+ title = _("Select imagery group"), id = wx.ID_ANY):
"""!
Does post init and layout.
@@ -48,16 +49,33 @@
"""
SimpleDialog.__init__(self, parent, title)
- self.element = gselect.Select(parent = self.panel, type = 'group',
+ self.use_subg = True
+
+ self.groupSelect = gselect.Select(parent = self.panel, type = 'group',
mapsets = [grass.gisenv()['MAPSET']],
size = globalvar.DIALOG_GSELECT_SIZE,
validator = SimpleValidator(callback = self.ValidatorCallback))
- self.element.SetFocus()
+
+ self.subg_panel = wx.Panel(self.panel)
+ # TODO use when subgroup will be optional
+ #self.subg_chbox = wx.CheckBox(parent = self.panel, id = wx.ID_ANY,
+ # label = _("Use subgroup"))
+ self.subGroupSelect = gselect.SubGroupSelect(parent = self.subg_panel)
+
+ self.groupSelect.SetFocus()
if group:
- self.element.SetValue(group)
+ self.groupSelect.SetValue(group)
+ self.GroupSelected()
+ if subgroup:
+ self.subGroupSelect.SetValue(subgroup)
+
+
self.editGroup = wx.Button(parent = self.panel, id = wx.ID_ANY,
label = _("Create/edit group..."))
+
self.editGroup.Bind(wx.EVT_BUTTON, self.OnEditGroup)
+ self.groupSelect.GetTextCtrl().Bind(wx.EVT_TEXT,
+ lambda event : wx.CallAfter(self.GroupSelected))
self.warning = _("Name of imagery group is missing.")
self._layout()
@@ -65,30 +83,148 @@
def _layout(self):
"""!Do layout"""
+ mainSizer = wx.BoxSizer(wx.VERTICAL)
+
self.dataSizer.Add(wx.StaticText(self.panel, id = wx.ID_ANY,
label = _("Name of imagery group:")),
- proportion = 0, flag = wx.EXPAND | wx.ALL, border = 5)
- self.dataSizer.Add(self.element, proportion = 0,
+ proportion = 0,
+ flag = wx.EXPAND | wx.BOTTOM | wx.LEFT | wx.RIGHT,
+ border = 5)
+ self.dataSizer.Add(self.groupSelect, proportion = 0,
flag = wx.EXPAND | wx.ALL, border = 5)
+
+ # TODO use when subgroup will be optional
+ #self.dataSizer.Add(self.subg_chbox, proportion = 0,
+ # flag = wx.EXPAND | wx.TOP | wx.LEFT | wx.RIGHT, border = 5)
+
+ subg_sizer = wx.BoxSizer(wx.VERTICAL)
+ subg_sizer.Add(wx.StaticText(self.subg_panel, id = wx.ID_ANY,
+ label = _("Name of imagery subgroup:")),
+ proportion = 0, flag = wx.EXPAND | wx.BOTTOM,
+ border = 5)
+ subg_sizer.Add(self.subGroupSelect, proportion = 0,
+ flag = wx.EXPAND)
+
+ self.subg_panel.SetSizer(subg_sizer)
+ self.dataSizer.Add(self.subg_panel, proportion = 0,
+ flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border = 5)
+
self.dataSizer.Add(self.editGroup, proportion = 0,
flag = wx.ALL, border = 5)
+
self.panel.SetSizer(self.sizer)
+
+ mainSizer.Add(self.panel, proportion = 1,
+ flag = wx.ALL, border = 5)
+
+ self.SetSizer(mainSizer)
self.sizer.Fit(self)
- def GetGroup(self):
- """!Returns selected group"""
- return self.element.GetValue()
+ #TODO use when subgroup will be optional
+ #self.subg_panel.Show(False)
+ #self.subg_chbox.Bind(wx.EVT_CHECKBOX, self.OnSubgChbox)
+
+ def OnSubgChbox(self, event):
+ self.use_subg = self.subg_chbox.GetValue()
+
+ if self.use_subg:
+ self.subg_panel.Show()
+ #self.SubGroupSelected()
+ else:
+ self.subg_panel.Hide()
+ #self.GroupSelected()
+ self.SetMinSize(self.GetBestSize())
+ self.Layout()
+
+ def GetData(self):
+ """!Returns selected group and subgroup"""
+
+ if self.use_subg:
+ ret = (self.groupSelect.GetValue(), self.subGroupSelect.GetValue())
+ else:
+ ret = (self.groupSelect.GetValue(), None)
+
+ return ret
def OnEditGroup(self, event):
"""!Launch edit group dialog"""
- dlg = GroupDialog(parent = self, defaultGroup = self.element.GetValue())
+ g, s = self.GetData()
+ dlg = GroupDialog(parent=self, defaultGroup=g, defaultSubgroup=s)
dlg.ShowModal()
- gr = dlg.GetSelectedGroup()
+ gr, s = dlg.GetSelectedGroup()
if gr in dlg.GetExistGroups():
- self.element.SetValue(gr)
+ self.groupSelect.SetValue(gr)
+ self.GroupSelected()
+ wx.CallAfter(self.subGroupSelect.SetValue, s)
dlg.Destroy()
+ def GroupSelected(self):
+ group = self.GetSelectedGroup()
+ self.subGroupSelect.Insert(group)
+
+ def GetSelectedGroup(self):
+ """!Return currently selected group (without mapset)"""
+ return self.groupSelect.GetValue().split('@')[0]
+
+ def GetGroupBandsErr(self, parent):
+ """!Get list of raster bands which are in the soubgroup of group with both having same name.
+ If the group does not exists or it does not contain any bands in subgoup with same name,
+ error dialog is shown.
+ """
+ gr, s = self.GetData()
+
+ group = grass.find_file(name=gr, element='group')
+
+ bands = []
+ g = group['name']
+
+ if g:
+ if self.use_subg:
+ if s == '':
+ GError(_("Please choose a subgroup."), parent=parent)
+ return bands
+ if s not in self.GetSubgroups(g):
+ GError(_("Subgroup <%s> not found in group <%s>") % (s, g), parent=parent)
+ return bands
+
+ bands = self.GetGroupBands(g, s)
+ if not bands:
+ if self.use_subg:
+ GError(_("No data found in subgroup <%s> of group <%s>.\n" \
+ ".") \
+ % (s, g), parent=parent)
+
+ else:
+ GError(_("No data found in group <%s>.\n" \
+ ".") \
+ % g, parent=parent)
+ else:
+ GError(_("Group <%s> not found") % gr, parent=parent)
+
+ return bands
+
+ def GetGroupBands(self, group, subgroup):
+ """!Get list of raster bands which are in the soubgroup of group with both having same name."""
+
+ kwargs = {}
+ if subgroup:
+ kwargs['subgroup'] = subgroup
+
+ res = RunCommand('i.group',
+ flags='g',
+ group=group,
+ read = True, **kwargs).strip()
+ bands = None
+ if res.split('\n')[0]:
+ bands = res.split('\n')
+
+ return bands
+
+ def GetSubgroups(self, group):
+ return RunCommand('i.group', group=group,
+ read=True, flags='sg').splitlines()
+
class IClassMapDialog(SimpleDialog):
"""!Dialog for adding raster/vector map"""
def __init__(self, parent, title, element):
@@ -425,7 +561,8 @@
return None
class IClassSignatureFileDialog(wx.Dialog):
- def __init__(self, parent, group, file = None, title = _("Save signature file"), id = wx.ID_ANY,
+ def __init__(self, parent, group, subgroup,
+ file = None, title = _("Save signature file"), id = wx.ID_ANY,
style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
**kwargs):
"""!Dialog for saving signature file
@@ -447,7 +584,7 @@
env['LOCATION_NAME'],
env['MAPSET'],
'group', group,
- 'subgroup', group,
+ 'subgroup', subgroup,
'sig')
self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
Modified: grass/trunk/gui/wxpython/iclass/frame.py
===================================================================
--- grass/trunk/gui/wxpython/iclass/frame.py 2013-09-17 10:04:24 UTC (rev 57723)
+++ grass/trunk/gui/wxpython/iclass/frame.py 2013-09-17 10:07:31 UTC (rev 57724)
@@ -477,20 +477,23 @@
self.Render(self.GetFirstWindow())
- def OnAddBands(self, event):
+ def AddBands(self):
"""!Add imagery group"""
- dlg = IClassGroupDialog(self, group = self.group)
- if dlg.ShowModal() == wx.ID_OK:
- self.SetGroup(dlg.GetGroup())
+ dlg = IClassGroupDialog(self, group=self.g['group'])
+
+ while True:
+ if dlg.ShowModal() == wx.ID_OK:
+
+ if dlg.GetGroupBandsErr(parent=self):
+ g, s = dlg.GetData()
+ group = grass.find_file(name=g, element='group')
+ self.g['group'] = group['name']
+ self.g['subgroup'] = s
+ break
+ else:
+ break
+
dlg.Destroy()
-
- def SetGroup(self, name):
- """!Set imagery group"""
- group = grass.find_file(name = name, element = 'group')
- if group['name']:
- self.group = group['name']
- else:
- GError(_("Group <%s> not found") % name, parent = self)
def OnImportAreas(self, event):
"""!Import training areas"""
@@ -699,7 +702,7 @@
"color varchar(11)",
"n_cells integer",]
- nbands = len(self.GetGroupLayers(self.group))
+ nbands = len(self.GetGroupLayers(self.g['group'], self.g['subgroup']))
for statistic, format in (("min", "integer"), ("mean", "double precision"), ("max", "integer")):
for i in range(nbands):
# 10 characters limit?
@@ -867,8 +870,8 @@
"""!Run analysis and update plots"""
if self.RunAnalysis():
currentCat = self.GetCurrentCategoryIdx()
- self.plotPanel.UpdatePlots(group = self.group, currentCat = currentCat,
- stats_data = self.stats_data)
+ self.plotPanel.UpdatePlots(group = self.g['group'], subgroup = self.g['subgroup'],
+ currentCat = currentCat, stats_data = self.stats_data)
def RunAnalysis(self):
"""!Run analysis
@@ -876,7 +879,7 @@
Calls C functions to compute all statistics and creates raster maps.
Signatures are created but signature file is not.
"""
- if not self.CheckInput(group = self.group, vector = self.trainingAreaVector):
+ if not self.CheckInput(group = self.g['group'], vector = self.trainingAreaVector):
return
for statistic in self.cStatisticsDict.values():
@@ -885,9 +888,8 @@
# init Ref struct with the files in group */
I_free_group_ref(self.refer)
- # we expect the subgroup name to be the same as the group name
- subgroup = self.group
- if (not I_iclass_init_group(self.group, subgroup, self.refer)):
+
+ if (not I_iclass_init_group(self.g['group'], self.g["subgroup"], self.refer)):
return False
I_free_signatures(self.signatures)
@@ -910,7 +912,7 @@
stats.nstd)
ret = I_iclass_analysis(statistics, self.refer, self.poMapInfo, "1",
- self.group, stats.rasterName)
+ self.g['group'], stats.rasterName)
if ret > 0:
# tests
self.cStatisticsDict[i] = statistics
@@ -939,7 +941,7 @@
def OnSaveSigFile(self, event):
"""!Asks for signature file name and saves it."""
- if not self.group:
+ if not self.g['group']:
GMessage(parent = self, message = _("No imagery group selected."))
return
@@ -956,7 +958,10 @@
qdlg.Destroy()
return
- dlg = IClassSignatureFileDialog(self, group = self.group, file = self.sigFile)
+ dlg = IClassSignatureFileDialog(self,
+ group = self.g['group'],
+ subgroup = self.g['subgroup'],
+ file = self.sigFile)
if dlg.ShowModal() == wx.ID_OK:
if os.path.exists(dlg.GetFileName(fullPath = True)):
@@ -971,7 +976,7 @@
qdlg.Destroy()
return
self.sigFile = dlg.GetFileName()
- self.WriteSignatures(self.signatures, self.group, self.sigFile)
+ self.WriteSignatures(self.signatures, self.g['group'], self.g['subgroup'], self.sigFile)
dlg.Destroy()
@@ -979,7 +984,7 @@
"""!Initialize variables and c structures neccessary for
computing statistics.
"""
- self.group = None
+ self.g = {'group' : None, 'subgroup' : None}
self.sigFile = None
self.stats_data = StatisticsData()
@@ -994,25 +999,26 @@
self.refer = pointer(refer_obj)
I_init_group_ref(self.refer) # must be freed on exit
- def WriteSignatures(self, signatures, group, filename):
+ def WriteSignatures(self, signatures, group, subgroup, filename):
"""!Writes current signatures to signature file
@param signatures signature (c structure)
@param group imagery group
@param filename signature file name
"""
- I_iclass_write_signatures(signatures, group, group, filename)
+ I_iclass_write_signatures(signatures, group, subgroup, filename)
def CheckInput(self, group, vector):
"""!Check if input is valid"""
# check if group is ok
+ #TODO check subgroup
if not group:
GMessage(parent = self,
message = _("No imagery group selected. "
"Operation canceled."))
return False
- groupLayers = self.GetGroupLayers(group)
+ groupLayers = self.GetGroupLayers(self.g['group'], self.g['subgroup'])
nLayers = len(groupLayers)
if nLayers <= 1:
@@ -1056,15 +1062,19 @@
count += 1
return count
- def GetGroupLayers(self, group):
+ def GetGroupLayers(self, group, subgroup=None):
"""!Get layers in subgroup (expecting same name for group and subgroup)
@todo consider moving this function to core module for convenient
"""
+ kwargs = {}
+ if subgroup:
+ kwargs['subgroup'] = subgroup
+
res = RunCommand('i.group',
flags = 'g',
- group = group, subgroup = group,
- read = True).strip()
+ group = group,
+ read = True, **kwargs).strip()
if res.split('\n')[0]:
return res.split('\n')
return []
Modified: grass/trunk/gui/wxpython/iclass/plots.py
===================================================================
--- grass/trunk/gui/wxpython/iclass/plots.py 2013-09-17 10:04:24 UTC (rev 57723)
+++ grass/trunk/gui/wxpython/iclass/plots.py 2013-09-17 10:07:31 UTC (rev 57724)
@@ -115,16 +115,17 @@
self.SetVirtualSize(self.GetBestVirtualSize())
self.Layout()
- def UpdatePlots(self, group, currentCat, stats_data):
+ def UpdatePlots(self, group, subgroup, currentCat, stats_data):
"""!Update plots after new analysis
@param group imagery group
+ @param subgroup imagery group
@param currentCat currently selected category (class)
@param stats_data StatisticsData instance (defined in statistics.py)
"""
self.stats_data = stats_data
self.currentCat = currentCat
- self.bandList = self.parent.GetGroupLayers(group)
+ self.bandList = self.parent.GetGroupLayers(group, subgroup)
graphType = self.plotSwitch.GetSelection()
Modified: grass/trunk/gui/wxpython/iclass/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/iclass/toolbars.py 2013-09-17 10:04:24 UTC (rev 57723)
+++ grass/trunk/gui/wxpython/iclass/toolbars.py 2013-09-17 10:07:31 UTC (rev 57724)
@@ -156,7 +156,7 @@
"""!Toolbar data"""
icons = iClassIcons
return self._getToolbarData((("selectGroup", icons['selectGroup'],
- self.parent.OnAddBands),
+ lambda event : self.parent.AddBands()),
(None, ),
("classManager", icons['classManager'],
self.parent.OnCategoryManager),
More information about the grass-commit
mailing list