[GRASS-SVN] r49827 - in grass/trunk/gui/wxpython: . iclass
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Dec 19 05:32:12 EST 2011
Author: annakrat
Date: 2011-12-19 02:32:12 -0800 (Mon, 19 Dec 2011)
New Revision: 49827
Modified:
grass/trunk/gui/wxpython/iclass/dialogs.py
grass/trunk/gui/wxpython/iclass/digit.py
grass/trunk/gui/wxpython/iclass/frame.py
grass/trunk/gui/wxpython/wxpythonlib.dox
Log:
wxIClass: saving signature file improved
Modified: grass/trunk/gui/wxpython/iclass/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/iclass/dialogs.py 2011-12-19 10:31:30 UTC (rev 49826)
+++ grass/trunk/gui/wxpython/iclass/dialogs.py 2011-12-19 10:32:12 UTC (rev 49827)
@@ -8,6 +8,7 @@
- dialogs::IClassMapDialog
- dialogs::IClassCategoryManagerDialog
- dialogs::CategoryListCtrl
+ - dialogs::IClassSignatureFileDialog
(C) 2006-2011 by the GRASS Development Team
This program is free software under the GNU General Public
@@ -17,10 +18,11 @@
@author Vaclav Petras <wenzeslaus gmail.com>
@author Anna Kratochvilova <kratochanna gmail.com>
"""
-
+import os
import wx
-import wx.lib.mixins.listctrl as listmix
+import wx.lib.mixins.listctrl as listmix
+import wx.lib.scrolledpanel as scrolled
from core import globalvar
from gui_core.dialogs import ElementDialog, GroupDialog
@@ -242,6 +244,8 @@
if attr == 'name':
self.mapWindow.UpdateRasterName(text, toolbar.GetSelectedCategoryIdx())
+ self.mapWindow.UpdateChangeState(changes = True)
+
def Populate(self, columns):
for i, col in enumerate(columns):
self.InsertColumn(i, col[0])#wx.LIST_FORMAT_RIGHT
@@ -263,6 +267,7 @@
self.SetItemCount(len(self.statisticsList))
self.UpdateChoice()
+ self.mapWindow.UpdateChangeState(changes = True)
def DeleteCategory(self):
indexList = sorted(self.GetSelectedIndices(), reverse = True)
@@ -276,6 +281,7 @@
self.SetItemCount(len(self.statisticsList))
self.UpdateChoice()
+ self.mapWindow.UpdateChangeState(changes = True)
# delete vector items!
@@ -334,3 +340,111 @@
def OnGetItemAttr(self, item):
return None
+
+class IClassSignatureFileDialog(wx.Dialog):
+ def __init__(self, parent, group, file = None, title = _("Save signature file"), id = wx.ID_ANY,
+ style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
+ **kwargs):
+ """!Dialog for saving signature file
+
+ @param parent window
+ @param group group name
+ @param file signature file name
+ @param title window title
+ """
+ wx.Dialog.__init__(self, parent, id, title, style = style, **kwargs)
+
+ self.fileName = file
+
+ env = grass.gisenv()
+
+ # inconsistent group and subgroup name
+ # path: grassdata/nc_spm_08/landsat/group/test_group/subgroup/test_group at landsat/sig/sigFile
+ self.baseFilePath = os.path.join(env['GISDBASE'],
+ env['LOCATION_NAME'],
+ env['MAPSET'],
+ 'group', group.split('@')[0], # !
+ 'subgroup', group,
+ 'sig')
+ self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
+
+ self.btnCancel = wx.Button(parent = self.panel, id = wx.ID_CANCEL)
+ self.btnOK = wx.Button(parent = self.panel, id = wx.ID_OK)
+ self.btnOK.SetDefault()
+ self.btnOK.Enable(False)
+
+ self.__layout()
+
+ self.fileNameCtrl.Bind(wx.EVT_TEXT, self.OnTextChanged)
+ self.OnTextChanged(None)
+
+ def OnTextChanged(self, event):
+ """!Name for signature file given"""
+ file = self.fileNameCtrl.GetValue()
+ if len(file) > 0:
+ self.btnOK.Enable(True)
+ else:
+ self.btnOK.Enable(False)
+
+ path = os.path.join(self.baseFilePath, file)
+ self.filePathText.SetLabel(path)
+ bestSize = self.pathPanel.GetBestVirtualSize()
+ self.pathPanel.SetVirtualSize(bestSize)
+ self.pathPanel.Scroll(*bestSize)
+
+ def __layout(self):
+ """!Do layout"""
+ sizer = wx.BoxSizer(wx.VERTICAL)
+
+ dataSizer = wx.BoxSizer(wx.VERTICAL)
+
+ dataSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
+ label = _("Enter name of signature file:")),
+ proportion = 0, flag = wx.ALL, border = 3)
+ self.fileNameCtrl = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY, size = (400, -1))
+ if self.fileName:
+ self.fileNameCtrl.SetValue(self.fileName)
+ dataSizer.Add(item = self.fileNameCtrl,
+ proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
+
+ dataSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
+ label = _("Signature file path:")),
+ proportion = 0, flag = wx.ALL, border = 3)
+
+ self.pathPanel = scrolled.ScrolledPanel(self.panel, size = (-1, 40))
+ pathSizer = wx.BoxSizer()
+ self.filePathText = wx.StaticText(parent = self.pathPanel, id = wx.ID_ANY,
+ label = self.baseFilePath)
+ pathSizer.Add(self.filePathText, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
+ self.pathPanel.SetupScrolling(scroll_x = True, scroll_y = False)
+ self.pathPanel.SetSizer(pathSizer)
+
+ dataSizer.Add(item = self.pathPanel,
+ proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
+
+ # buttons
+ btnSizer = wx.StdDialogButtonSizer()
+ btnSizer.AddButton(self.btnCancel)
+ btnSizer.AddButton(self.btnOK)
+ btnSizer.Realize()
+
+ sizer.Add(item = dataSizer, proportion = 1,
+ flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
+
+ sizer.Add(item = btnSizer, proportion = 0,
+ flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
+
+ self.panel.SetSizer(sizer)
+ sizer.Fit(self)
+
+ self.SetMinSize(self.GetSize())
+
+ def GetFileName(self, fullPath = False):
+ """!Returns signature file name
+
+ @param fullPath return full path of sig. file
+ """
+ if fullPath:
+ return os.path.join(self.baseFilePath, self.fileNameCtrl.GetValue())
+
+ return self.fileNameCtrl.GetValue()
Modified: grass/trunk/gui/wxpython/iclass/digit.py
===================================================================
--- grass/trunk/gui/wxpython/iclass/digit.py 2011-12-19 10:31:30 UTC (rev 49826)
+++ grass/trunk/gui/wxpython/iclass/digit.py 2011-12-19 10:32:12 UTC (rev 49827)
@@ -63,6 +63,10 @@
def _updateATM(self):
pass
+ def _onRightUp(self, event):
+ super(IClassVDigitWindow, self)._onRightUp(event)
+ self.parent.UpdateChangeState(changes = True)
+
def GetCurrentCategory(self):
"""!Returns current category (class).
Modified: grass/trunk/gui/wxpython/iclass/frame.py
===================================================================
--- grass/trunk/gui/wxpython/iclass/frame.py 2011-12-19 10:31:30 UTC (rev 49826)
+++ grass/trunk/gui/wxpython/iclass/frame.py 2011-12-19 10:32:12 UTC (rev 49827)
@@ -53,7 +53,7 @@
IClassToolbar, IClassMapManagerToolbar
from iclass.statistics import Statistics, BandStatistics
from iclass.dialogs import CategoryListCtrl, IClassCategoryManagerDialog,\
- IClassGroupDialog, IClassMapDialog
+ IClassGroupDialog, IClassMapDialog, IClassSignatureFileDialog
from iclass.plots import PlotPanel
@@ -143,8 +143,9 @@
Map = self.GetSecondMap())
self.InitStatistics()
- #self.InitTestStatistics()
+ self.changes = False
+
# PyPlot init
self.plotPanel = PlotPanel(self, statDict = self.statisticsDict,
statList = self.statisticsList)
@@ -445,6 +446,12 @@
stat.SetBandStatistics(cstat)
self.plotPanel.StddevChanged()
+ def UpdateChangeState(self, changes):
+ """!Informs if any important changes happened
+ since last analysis computaiton.
+ """
+ self.changes = changes
+
def AddRasterMap(self, name, firstMap = True, secondMap = True):
"""!Add raster map to Map"""
cmdlist = ['d.rast', 'map=%s' % name]
@@ -527,7 +534,7 @@
stats.SetReady()
self.statisticsDict[stats.category] = stats
- #self.ConvertToNull(name = stats.rasterName)
+ self.ConvertToNull(name = stats.rasterName)
self.previewMapManager.AddLayer(name = stats.rasterName,
alias = stats.name, resultsLayer = True)
# write statistics
@@ -535,6 +542,7 @@
else:
I_iclass_free_statistics(statistics)
+ self.UpdateChangeState(changes = False)
return True
def OnSaveSigFile(self, event):
@@ -543,16 +551,36 @@
GMessage(parent = self, message = _("No imagery group selected."))
return
- dlg = wx.TextEntryDialog(self, message = _("Enter name of signature file:"),
- caption = _("Save signature file"))
-
- if self.sigFile:
- dlg.SetValue(self.sigFile)
+ if self.changes:
+ qdlg = wx.MessageDialog(parent = self,
+ message = _("Due to recent changes in classes, "
+ "signatures can be outdated and should be recalculated. "
+ "Do you still want to continue?") ,
+ caption = _("Outdated signatures"),
+ style = wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION | wx.CENTRE)
+ if qdlg.ShowModal() == wx.ID_YES:
+ qdlg.Destroy()
+ else:
+ qdlg.Destroy()
+ return
+
+ dlg = IClassSignatureFileDialog(self, group = self.group, file = self.sigFile)
+
if dlg.ShowModal() == wx.ID_OK:
- file = dlg.GetValue()
+ if os.path.exists(dlg.GetFileName(fullPath = True)):
+ qdlg = wx.MessageDialog(parent = self,
+ message = _("A signature file named %s already exists.\n"
+ "Do you want to replace it?") % dlg.GetFileName(),
+ caption = _("File already exists"),
+ style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION | wx.CENTRE)
+ if qdlg.ShowModal() == wx.ID_YES:
+ qdlg.Destroy()
+ else:
+ qdlg.Destroy()
+ return
+ self.sigFile = dlg.GetFileName()
+ self.WriteSignatures(self.signatures, self.group, self.sigFile)
- self.WriteSignatures(self.signatures, self.group, file)
-
dlg.Destroy()
def InitStatistics(self):
Modified: grass/trunk/gui/wxpython/wxpythonlib.dox
===================================================================
--- grass/trunk/gui/wxpython/wxpythonlib.dox 2011-12-19 10:31:30 UTC (rev 49826)
+++ grass/trunk/gui/wxpython/wxpythonlib.dox 2011-12-19 10:32:12 UTC (rev 49827)
@@ -445,6 +445,7 @@
- dialogs::IClassMapDialog
- dialogs::IClassCategoryManagerDialog
- dialogs::CategoryListCtrl
+ - dialogs::IClassSignatureFileDialog
- iclass::digit
- digit::IClassVDigit
- digit::IClassVDigitWindow
More information about the grass-commit
mailing list