瀏覽代碼

wxGUI: contex menu for rasters - switch from d.histogram-based dialog to
HistogramPlotFrame


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@56430 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 12 年之前
父節點
當前提交
b676e4204a

+ 5 - 8
gui/wxpython/lmgr/layertree.py

@@ -35,7 +35,7 @@ from gui_core.dialogs     import SqlQueryFrame, SetOpacityDialog
 from gui_core.forms       import GUI
 from mapdisp.frame        import MapFrame
 from core.render          import Map
-from modules.histogram    import HistogramFrame
+from wxplot.histogram     import HistogramPlotFrame
 from core.utils           import GetLayerNameFromCmd, ltype2command
 from wxplot.profile       import ProfileFrame
 from core.debug           import Debug
@@ -646,7 +646,7 @@ class LayerTree(treemixin.DragAndDrop, CT.CustomTreeCtrl):
             self.profileFrame = self.mapdisplay.profile
 
         if not self.profileFrame:
-            self.profileFrame = ProfileFrame(parent = self.mapdisplay,
+            self.profileFrame = ProfileFrame(parent = self.mapdisplay, mapwindow = self.mapdisplay.GetMapWindow(),
                                              rasterList = [mapLayer.GetName()])
             # show new display
             self.profileFrame.Show()
@@ -673,15 +673,12 @@ class LayerTree(treemixin.DragAndDrop, CT.CustomTreeCtrl):
                                "raster map. No map name defined."))
             return
         
-        win = HistogramFrame(parent = self)
+        win = HistogramPlotFrame(parent = self, rasterList = [mapLayer.GetName()])
         
         win.CentreOnScreen()
         win.Show()
-        win.SetHistLayer(mapLayer.GetName())
-        win.HistWindow.UpdateHist()
-        win.Refresh()
-        win.Update()
-
+        win.OnSelectRaster(None)
+        
     def OnUnivariateStats(self, event):
         """!Univariate raster statistics"""
         name = self.GetLayerInfo(self.layer_selected, key = 'maplayer').GetName()

+ 3 - 3
gui/wxpython/mapdisp/frame.py

@@ -52,7 +52,7 @@ from gui_core.query     import QueryDialog, PrepareQueryResults
 from mapdisp.mapwindow  import BufferedWindow
 from mapdisp.overlays   import LegendController, BarscaleController
 from modules.histogram  import HistogramFrame
-from wxplot.histogram   import Histogram2Frame
+from wxplot.histogram   import HistogramPlotFrame
 from wxplot.profile     import ProfileFrame
 from wxplot.scatter     import ScatterFrame
 
@@ -955,7 +955,7 @@ class MapFrame(SingleMapFrame):
             if layer.type == 'raster':
                 rasters.append(layer.maplayer.name)
 
-        win = ProfileFrame(parent = self, rasterList = rasters)
+        win = ProfileFrame(parent = self, mapwindow = self.GetMapWindow(), rasterList = rasters)
         
         win.CentreOnParent()
         win.Show()
@@ -1023,7 +1023,7 @@ class MapFrame(SingleMapFrame):
             if layer.maplayer.GetType() == 'raster':
                 raster.append(layer.maplayer.GetName())
 
-        win = Histogram2Frame(parent = self, rasterList = raster)
+        win = HistogramPlotFrame(parent = self, rasterList = raster)
         win.CentreOnParent()
         win.Show()
         # Open raster select dialog to make sure that a raster (and the desired raster)

+ 6 - 5
gui/wxpython/wxplot/base.py

@@ -46,13 +46,13 @@ PlotIcons = {
 
 class BasePlotFrame(wx.Frame):
     """!Abstract PyPlot display frame class"""
-    def __init__(self, parent = None, id = wx.ID_ANY, size = wx.Size(700, 400),
+    def __init__(self, parent = None, mapwindow = None, id = wx.ID_ANY, size = wx.Size(700, 400),
                  style = wx.DEFAULT_FRAME_STYLE, rasterList = [],  **kwargs):
 
         wx.Frame.__init__(self, parent, id, size = size, style = style, **kwargs)
         
-        self.parent = parent            # MapFrame for a plot type
-        self.mapwin = self.parent.MapWindow
+        self.parent = parent # MapFrame for a plot type
+        self.mapwin = mapwindow
         self.Map    = Map()             # instance of render.Map to be associated with display
         self.rasterList = rasterList    #list of rasters to plot
         self.raster = {}    # dictionary of raster maps and their plotting parameters
@@ -577,7 +577,8 @@ class BasePlotFrame(wx.Frame):
             self.mapwin.UpdateMap(render = False, renderVector = False)
         except:
             pass
-        
-        self.mapwin.SetCursor(self.Parent.cursors["default"])
+
+        if self.mapwin:
+            self.mapwin.SetCursor(self.Parent.cursors["default"])
         self.Destroy()
         

+ 16 - 13
gui/wxpython/wxplot/histogram.py

@@ -4,8 +4,8 @@
 @brief Histogramming using PyPlot
 
 Classes:
- - histogram::Histogram2Frame
- - histogram::Histogram2Toolbar
+ - histogram::HistogramPlotFrame
+ - histogram::HistogramPlotToolbar
 
 (C) 2011 by the GRASS Development Team
 
@@ -27,18 +27,17 @@ from wxplot.base       import BasePlotFrame, PlotIcons
 from wxplot.dialogs    import HistRasterDialog, PlotStatsFrame
 from core.gcmd         import RunCommand, GException, GError
 
-class Histogram2Frame(BasePlotFrame):
+class HistogramPlotFrame(BasePlotFrame):
     """!Mainframe for displaying histogram of raster map. Uses wx.lib.plot.
     """
     def __init__(self, parent, id = wx.ID_ANY, style = wx.DEFAULT_FRAME_STYLE, 
-                 size = wx.Size(700, 400),
-                 rasterList = [], **kwargs):
+                 size = wx.Size(700, 400), rasterList = [], **kwargs):
         BasePlotFrame.__init__(self, parent, size = size, **kwargs)
         
-        self.toolbar = Histogram2Toolbar(parent = self)
+        self.toolbar = HistogramPlotToolbar(parent = self)
         self.SetToolBar(self.toolbar)
         self.SetTitle(_("GRASS Histogramming Tool"))
-
+        
         #
         # Init variables
         #
@@ -51,12 +50,12 @@ class Histogram2Frame(BasePlotFrame):
         self.maptype = 'raster'                 # default type of histogram to plot
         self.histtype = 'count' 
         self.bins = 255
-        self.colorList = ["blue", "green", "red", "yellow", "magenta", "cyan", \
-                    "aqua", "black", "grey", "orange", "brown", "purple", "violet", \
-                    "indigo"]
+        self.colorList = ["blue", "green", "red", "yellow", "magenta", "cyan", 
+                          "aqua", "black", "grey", "orange", "brown", "purple", "violet",
+                          "indigo"]
         
         self._initOpts()
-
+        
         if len(self.rasterList) > 0: # set raster name(s) from layer manager if a map is selected
             self.InitRasterOpts(self.rasterList, self.plottype)
         else:
@@ -72,7 +71,11 @@ class Histogram2Frame(BasePlotFrame):
         create a list of cell value and count/percent/area pairs. This is passed to
         plot to create a line graph of the histogram.
         """
-        self.SetCursor(self.parent.cursors["default"])
+        try:
+            self.SetCursor(self.parent.cursors["default"])
+        except:
+            pass
+        
         self.SetGraphStyle()
         self.SetupHistogram()
         p = self.CreatePlotList()
@@ -232,7 +235,7 @@ class Histogram2Frame(BasePlotFrame):
         if stats.Show() == wx.ID_CLOSE:
             stats.Destroy()       
 
-class Histogram2Toolbar(BaseToolbar):
+class HistogramPlotToolbar(BaseToolbar):
     """!Toolbar for histogramming raster map
     """ 
     def __init__(self, parent):

+ 2 - 2
gui/wxpython/wxplot/profile.py

@@ -42,10 +42,10 @@ from core.gcmd         import RunCommand, GWarning, GError, GMessage
 class ProfileFrame(BasePlotFrame):
     """!Mainframe for displaying profile of one or more raster maps. Uses wx.lib.plot.
     """
-    def __init__(self, parent, id = wx.ID_ANY, style = wx.DEFAULT_FRAME_STYLE, 
+    def __init__(self, parent, mapwindow, id = wx.ID_ANY, style = wx.DEFAULT_FRAME_STYLE, 
                  size = wx.Size(700, 400),
                  rasterList = [], **kwargs):
-        BasePlotFrame.__init__(self, parent, size = size, **kwargs)
+        BasePlotFrame.__init__(self, parent, mapwindow = mapwindow, size = size, **kwargs)
 
         self.toolbar = ProfileToolbar(parent = self)
         self.SetToolBar(self.toolbar)