[GRASS-SVN] r50310 - grass/trunk/gui/wxpython/iclass
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jan 20 04:28:44 EST 2012
Author: annakrat
Date: 2012-01-20 01:28:44 -0800 (Fri, 20 Jan 2012)
New Revision: 50310
Modified:
grass/trunk/gui/wxpython/iclass/dialogs.py
grass/trunk/gui/wxpython/iclass/digit.py
grass/trunk/gui/wxpython/iclass/frame.py
Log:
wxGUI/wxIClass: various improvements related to class manager
Modified: grass/trunk/gui/wxpython/iclass/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/iclass/dialogs.py 2012-01-19 22:36:31 UTC (rev 50309)
+++ grass/trunk/gui/wxpython/iclass/dialogs.py 2012-01-20 09:28:44 UTC (rev 50310)
@@ -190,6 +190,8 @@
self.catList.DeleteCategory()
def OnClose(self, event):
+ self.catList.DeselectAll()
+
self.catList.UpdateChoice()
if not isinstance(event, wx.CloseEvent):
self.Destroy()
@@ -227,12 +229,18 @@
self.statisticsList = statisticsList
self.SetItemCount(len(statisticsList))
+ self.rightClickedItemIdx = wx.NOT_FOUND
+
listmix.ListCtrlAutoWidthMixin.__init__(self)
listmix.TextEditMixin.__init__(self)
self.Bind(wx.EVT_LIST_BEGIN_LABEL_EDIT, self.OnEdit)
+ self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnCategorySelected)
+ self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnClassRightUp) #wxMSW
+ self.Bind(wx.EVT_RIGHT_UP, self.OnClassRightUp) #wxGTK
+
def SetVirtualData(self, row, column, text):
attr = self.columns[column][1]
setattr(self.statisticsDict[self.statisticsList[row]], attr, text)
@@ -240,6 +248,7 @@
self.UpdateChoice()
toolbar = self.mapWindow.toolbars['iClass']
toolbar.choice.SetSelection(row)
+ self.Select(row)
if attr == 'name':
self.mapWindow.UpdateRasterName(text, toolbar.GetSelectedCategoryIdx())
@@ -271,20 +280,22 @@
def DeleteCategory(self):
indexList = sorted(self.GetSelectedIndices(), reverse = True)
+ cats = []
for i in indexList:
# remove temporary raster
name = self.statisticsDict[self.statisticsList[i]].rasterName
self.mapWindow.RemoveTempRaster(name)
+ cats.append(self.statisticsList[i])
del self.statisticsDict[self.statisticsList[i]]
del self.statisticsList[i]
+
self.SetItemCount(len(self.statisticsList))
self.UpdateChoice()
self.mapWindow.UpdateChangeState(changes = True)
-
- # delete vector items!
+ self.mapWindow.DeleteAreas(cats = cats)
def UpdateChoice(self):
toolbar = self.mapWindow.toolbars['iClass']
@@ -331,6 +342,48 @@
event.Skip()
+ def OnCategorySelected(self, event):
+ """!Highlight selected areas"""
+ indexList = self.GetSelectedIndices()
+ cats = []
+ for i in indexList:
+ cats.append(self.statisticsList[i])
+
+ self.mapWindow.HighlightCategory(cats)
+ if event:
+ event.Skip()
+
+ def OnClassRightUp(self, event):
+ """!Show context menu on right click"""
+ item, flags = self.HitTest((event.GetX(), event.GetY()))
+ if item != wx.NOT_FOUND and flags & wx.LIST_HITTEST_ONITEM:
+ self.rightClickedItemIdx = item
+
+ self.popupZoomtoAreas = wx.NewId()
+
+ self.Bind(wx.EVT_MENU, self.OnZoomToAreasByCat, id = self.popupZoomtoAreas)
+
+ # generate popup-menu
+ menu = wx.Menu()
+ menu.Append(self.popupZoomtoAreas, _("Zoom to training areas of selected class"))
+
+ self.PopupMenu(menu)
+ menu.Destroy()
+
+ def OnZoomToAreasByCat(self, event):
+ """!Zoom to areas of given category"""
+ cat = self.statisticsList[self.rightClickedItemIdx]
+ self.mapWindow.ZoomToAreasByCat(cat)
+
+ def DeselectAll(self):
+ """!Deselect all items"""
+ indexList = self.GetSelectedIndices()
+ for i in indexList:
+ self.Select(i, on = 0)
+
+ # no highlight
+ self.OnCategorySelected(None)
+
def OnGetItemText(self, item, col):
cat = self.statisticsList[item]
return getattr(self.statisticsDict[cat], self.columns[col][1])
Modified: grass/trunk/gui/wxpython/iclass/digit.py
===================================================================
--- grass/trunk/gui/wxpython/iclass/digit.py 2012-01-19 22:36:31 UTC (rev 50309)
+++ grass/trunk/gui/wxpython/iclass/digit.py 2012-01-20 09:28:44 UTC (rev 50310)
@@ -21,6 +21,11 @@
from vdigit.mapwindow import VDigitWindow
from vdigit.wxdigit import IVDigit
+try:
+ from grass.lib.vedit import *
+except ImportError:
+ pass
+
class IClassVDigitWindow(VDigitWindow):
"""! Class similar to VDigitWindow but specialized for wxIClass."""
def __init__(self, parent, map):
@@ -86,3 +91,13 @@
def _getNewFeaturesCat(self):
cat = self.mapWindow.GetCurrentCategory()
return cat
+
+ def DeleteAreasByCat(self, cats):
+ """!Delete areas (centroid+boundaries) by categories
+
+ @param cats list of categories
+ """
+
+ for cat in cats:
+ Vedit_delete_areas_cat(self.poMapInfo, 1, cat)
+
Modified: grass/trunk/gui/wxpython/iclass/frame.py
===================================================================
--- grass/trunk/gui/wxpython/iclass/frame.py 2012-01-19 22:36:31 UTC (rev 50309)
+++ grass/trunk/gui/wxpython/iclass/frame.py 2012-01-20 09:28:44 UTC (rev 50310)
@@ -271,7 +271,7 @@
digitClass = IClassVDigit,
tools = ['addArea', 'moveVertex', 'addVertex',
'removeVertex', 'editLine',
- 'moveLine', 'deleteLine'])
+ 'moveLine', 'deleteArea', 'undo', 'redo'])
self._mgr.AddPane(self.toolbars[name],
wx.aui.AuiPaneInfo().
@@ -437,6 +437,28 @@
if name:
self.previewMapManager.SelectLayer(name)
+ def DeleteAreas(self, cats):
+ """!Removes all training areas of given categories
+
+ @param cats list of categories to be deleted
+ """
+ self.firstMapWindow.digit.DeleteAreasByCat(cats)
+ self.firstMapWindow.UpdateMap(render=False, renderVector=True)
+
+ def HighlightCategory(self, cats):
+ """!Highlight araes given by category"""
+ self.firstMapWindow.digit.GetDisplay().SetSelected(cats, layer = 1)
+ self.firstMapWindow.UpdateMap(render=False, renderVector=True)
+
+ def ZoomToAreasByCat(self, cat):
+ """!Zoom to areas given by category"""
+ n, s, w, e = self.GetFirstWindow().digit.GetDisplay().GetRegionSelected()
+ self.GetFirstMap().GetRegion(n = n, s = s, w = w, e = e, update = True)
+ self.GetFirstMap().AdjustRegion()
+ self.GetFirstMap().AlignExtentFromDisplay()
+
+ self.GetFirstWindow().UpdateMap(render = True, renderVector = True)
+
def UpdateRasterName(self, newName, cat):
"""!Update alias of raster map when category name is changed"""
origName = self.statisticsDict[cat].rasterName
@@ -555,6 +577,8 @@
# write statistics
I_iclass_add_signature(self.signatures, statistics)
else:
+ GMessage(parent = self, message = _("Analysis failed. "
+ "Check training areas and their categories."))
I_iclass_free_statistics(statistics)
self.UpdateChangeState(changes = False)
More information about the grass-commit
mailing list