[GRASS-SVN] r31073 - in grass/trunk/gui/wxpython: gui_modules icons icons/silk

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Apr 22 12:06:31 EDT 2008


Author: martinl
Date: 2008-04-22 12:06:31 -0400 (Tue, 22 Apr 2008)
New Revision: 31073

Modified:
   grass/trunk/gui/wxpython/gui_modules/mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/profile.py
   grass/trunk/gui/wxpython/gui_modules/toolbars.py
   grass/trunk/gui/wxpython/icons/icon.py
   grass/trunk/gui/wxpython/icons/silk/__init__.py
Log:
wxGUI: minor cleaning of profile analysis tool (initial)


Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-04-22 16:04:54 UTC (rev 31072)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-04-22 16:06:31 UTC (rev 31073)
@@ -3163,9 +3163,14 @@
         """
         Init profile canvas and tools
         """
+        raster = []
+        if self.tree.layer_selected and \
+               self.tree.GetPyData(self.tree.layer_selected)[0]['type'] == 'raster':
+            raster.append(self.tree.GetPyData(self.tree.layer_selected)[0]['maplayer'].name)
+
         self.profile = profile.ProfileFrame(self,
-                                           id=wx.ID_ANY, pos=wx.DefaultPosition, size=(700,300),
-                                           style=wx.DEFAULT_FRAME_STYLE)
+                                            id=wx.ID_ANY, pos=wx.DefaultPosition, size=(700,300),
+                                            style=wx.DEFAULT_FRAME_STYLE, rasterList=raster)
         self.profile.Show()
 
     def FormatDist(self, dist):

Modified: grass/trunk/gui/wxpython/gui_modules/profile.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/profile.py	2008-04-22 16:04:54 UTC (rev 31072)
+++ grass/trunk/gui/wxpython/gui_modules/profile.py	2008-04-22 16:06:31 UTC (rev 31073)
@@ -4,22 +4,25 @@
 CLASSES:
  * ProfileFrame
  * SetRaster
- * Textdialog
+ * TextDialog
  * OptDialog
 
 PURPOSE: Profile analysis of GRASS raster maps and images. Uses PyPlot (wx.lib.plot.py)
 
 AUTHORS: The GRASS Development Team. Michael Barton
 
-COPYRIGHT: (C) 2007 by the GRASS Development Team
+COPYRIGHT: (C) 2007-2008 by the GRASS Development Team
            This program is free software under the GNU General Public
            License (>=v2). Read the file COPYING that comes with GRASS
            for details.
 """
 
+import os
+import sys
+import math
+
 import wx
-import os, sys, math
-import  wx.lib.colourselect as  csel
+import wx.lib.colourselect as  csel
 
 try:
     import wx.lib.plot as plot
@@ -42,50 +45,41 @@
     sys.path.append(CompatPath)
     from compat import subprocess as subprocess
 
-gmpath = os.path.join(globalvar.ETCWXDIR, "icons")
-sys.path.append(gmpath)
-
 import render
 import menuform
 import disp_print
 import gselect
 import gcmd
+import toolbars
 from debug import Debug as Debug
 from icon import Icons as Icons
 
-import images
-imagepath = images.__path__[0]
-sys.path.append(imagepath)
-
-icons = ""
-
-if not os.getenv("GRASS_ICONPATH"):
-    icons = os.getenv("GISBASE") + "/etc/gui/icons/"
-else:
-    icons = os.environ["GRASS_ICONPATH"]
-
 class ProfileFrame(wx.Frame):
     """
     Mainframe for displaying profile of raster map. Uses wx.lib.plot.
     """
 
-    def __init__(self, parent=None, id = wx.ID_ANY, title="Profile Analysis",
+    def __init__(self, parent=None, id=wx.ID_ANY, title=_("Profile Analysis"),
+                 rasterList=[],
                  pos=wx.DefaultPosition, size=wx.DefaultSize,
                  style=wx.DEFAULT_FRAME_STYLE):
 
-        wx.Frame.__init__(self, parent, id, title, pos, size, style)
-
-        toolbar = self.__createToolBar()
-
         self.parent = parent
-        self.mapwin = self.Parent.MapWindow
+        self.mapwin = self.parent.MapWindow
         self.Map = render.Map()  # instance of render.Map to be associated with display
 
+        wx.Frame.__init__(self, parent, id, title, pos, size, style)
+
         #
+        # Add toolbar
+        #
+        toolbar = toolbars.ProfileToolbar(parent=self, mapdisplay=self.mapwin, map=self.Map).GetToolbar()
+        self.SetToolBar(toolbar)
+        
+        #
         # Set the size & cursor
         #
         self.SetClientSize(size)
-        self.iconsize = (16, 16)
 
         #
         # Add statusbar
@@ -93,9 +87,9 @@
         self.statusbar = self.CreateStatusBar(number=2, style=0)
         self.statusbar.SetStatusWidths([-2, -1])
 
-        # Bind various events
-        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
-
+        #
+        # Define canvas
+        #
         # plot canvas settings
         self.client = plot.PlotCanvas(self)
         #define the function for drawing pointLabels
@@ -105,50 +99,58 @@
         # Show closest point when enabled
         self.client.canvas.Bind(wx.EVT_MOTION, self.OnMotion)
 
+        #
         # Init variables
+        #
         self.rast1 = '' # default raster map to profile
+        if len(rasterList) == 1:
+            self.rast1 = rasterList[0]
         self.rast2 = '' # optional raster map to profile
+        if len(rasterList) == 2:
+            self.rast1 = rasterList[1]
         self.rast3 = '' # optional raster map to profile
+        if len(rasterList) == 3:
+            self.rast1 = rasterList[2]
         self.rastunits1 = '' # map data units (used for y axis legend)
         self.rastunits2 = '' # map data units (used for y axis legend)
         self.rastunits3 = '' # map data units (used for y axis legend)
-        self.coordstr = '' #string of coordinates for r.profile
+        self.coordstr = '' # string of coordinates for r.profile
         self.seglist = [] # segment endpoint list
         self.plotlist = [] # list of things to plot
         self.ppoints = '' # segment endpoints data
         self.profile = None # plot draw object
 
-        self.ptitle = 'Profile of %s %s %s' % (self.rast1, self.rast2, self.rast3)
+        self.ptitle = _('Profile of ') + '%s %s %s' % (self.rast1, self.rast2, self.rast3)
         if self.parent.projinfo['units'] != '':
-            self.xlabel = 'Distance (%s)' % self.parent.projinfo['units']
+            self.xlabel = _('Distance (%s)') % self.parent.projinfo['units']
         else:
-            self.xlabel = "Distance along transect"
-        self.ylabel = "Cell values"
+            self.xlabel = _("Distance along transect")
+        self.ylabel = _("Cell values")
 
         self.datalist1 = [] #list of distance,value pairs for plotting profile
         self.pline1 = None # first (default) profile line
         self.pcolor1 = wx.Colour(0,0,255) # profile line color
         self.pwidth1 = 1 # profile line width
         self.pstyle1 = wx.SOLID # profile line pen style
-        self.plegend1 = 'Profile' # profile legend string
+        self.plegend1 = _('Profile') # profile legend string
         self.datalist2 = [] #list of distance,value pairs for plotting profile
         self.pline2 = None # second (optional) profile line
         self.pcolor2 = wx.Colour(255,0,0) # profile line color
         self.pwidth2 = 1 # profile line width
         self.pstyle2 = wx.SOLID # profile line pen style
-        self.plegend2 = 'Profile' # profile legend string
+        self.plegend2 = _('Profile') # profile legend string
         self.datalist3 = [] #list of distance,value pairs for plotting profile
         self.pline3 = None # third (optional) profile line
         self.pcolor3 = wx.Colour(0,255,0) # profile line color
         self.pwidth3 = 1 # profile line width
         self.pstyle3 = wx.SOLID # profile line pen style
-        self.plegend3 = 'Profile' # profile legend string
+        self.plegend3 = _('Profile') # profile legend string
 
         self.ptcolor = wx.Colour(0,0,0) # segmenet marker point color
         self.ptfill = wx.TRANSPARENT # segment marker point fill style
         self.ptsize = 2 # segment marker point size
         self.pttype = 'triangle' # segment marker point type
-        self.ptlegend = 'Segment break' # segment marker point legend string
+        self.ptlegend = _('Segment break') # segment marker point legend string
 
         self.font = wx.Font(12,wx.FONTFAMILY_SWISS,wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_NORMAL) # text font
         self.titlefontsize = 14 # title font size
@@ -178,43 +180,11 @@
         self.client.SetXSpec(self.xtype)
         self.client.SetYSpec(self.ytype)
 
+        #
+        # Bind various events
+        #
+        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
 
-
-
-    def __createToolBar(self):
-        """Creates toolbar"""
-
-        toolbar = self.CreateToolBar()
-        for each in self.toolbarData():
-            self.AddToolbarButton(toolbar, *each)
-        toolbar.Realize()
-
-    def AddToolbarButton(self, toolbar, label, icon, help, handler):
-        """Adds buttons to the toolbar"""
-
-        if not label:
-            toolbar.AddSeparator()
-            return
-        tool = toolbar.AddLabelTool(id=wx.ID_ANY, label=label, bitmap=icon, shortHelp=help)
-        self.Bind(wx.EVT_TOOL, handler, tool)
-
-    def toolbarData(self):
-
-        return   (
-                 ('transect', Icons["transect"].GetBitmap(), Icons["transect"].GetLabel(), self.DrawTransect),
-                 ('raster', Icons["addrast"].GetBitmap(), Icons["addrast"].GetLabel(), self.SelectRaster),
-                 ('profiledraw', Icons["profiledraw"].GetBitmap(), Icons["profiledraw"].GetLabel(), self.CreateProfile),
-                 ('options', Icons["profileopt"].GetBitmap(), 'Profile options', self.ProfileOptionsMenu),
-                 ('drag', Icons['pan'].GetBitmap(), 'Enable drag', self.OnDrag),
-                 ('zoom', Icons['zoom_in'].GetBitmap(), 'Enable zoom', self.OnZoom),
-                 ('unzoom', Icons['zoom_back'].GetBitmap(), 'Unzoom profile', self.OnRedraw),
-                 ('erase', Icons["erase"].GetBitmap(), 'Erase profile', self.OnErase),
-                 ('', '', '', ''),
-                 ('save',  Icons["savefile"].GetBitmap(),  'Save profile',  self.SaveToFile),
-                 ('print',  Icons["printmap"].GetBitmap(),  'Print profile',  self.PrintMenu),
-                 ('quit',  wx.ArtProvider.GetBitmap(wx.ART_QUIT, wx.ART_TOOLBAR, (16,16)),  Icons["quit"].GetLabel(), self.OnQuit),
-                  )
-
     def DrawTransect(self, event):
         """
         Draws transect to profile in map display
@@ -223,8 +193,10 @@
         self.seglist = []
         self.mapwin.ClearLines(self.mapwin.pdc)
         self.ppoints = ''
-        self.Parent.SetFocus()
-        self.Parent.Raise()
+
+        self.parent.SetFocus()
+        self.parent.Raise()
+        
         self.mapwin.mouse['use'] = 'profile'
         self.mapwin.mouse['box'] = 'line'
         self.mapwin.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
@@ -364,7 +336,6 @@
             except:
                 pass
 
-
     def SetGraphStyle(self):
         """
         Set plot and text options
@@ -1073,7 +1044,6 @@
         self.ylabelentry.SetFont(self.font)
         self.Layout()
 
-
 class OptDialog(wx.Dialog):
     def __init__(self, parent, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize,
             style=wx.DEFAULT_DIALOG_STYLE):

Modified: grass/trunk/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/toolbars.py	2008-04-22 16:04:54 UTC (rev 31072)
+++ grass/trunk/gui/wxpython/gui_modules/toolbars.py	2008-04-22 16:06:31 UTC (rev 31073)
@@ -4,14 +4,16 @@
 CLASSES:
     * AbstractToolbar
     * MapToolbar
+    * GRToolbar
     * DigitToolbar
-
+    * ProfileToolbar
+    
 PURPOSE: Toolbars for Map Display window
 
 AUTHORS: The GRASS Development Team
          Michael Barton, Martin Landa, Jachym Cepicky
 
-COPYRIGHT: (C) 2007 by the GRASS Development Team
+COPYRIGHT: (C) 2007-2008 by the GRASS Development Team
            This program is free software under the GNU General Public
            License (>=v2). Read the file COPYING that comes with GRASS
            for details.
@@ -33,7 +35,7 @@
 gmpath = os.path.join(globalvar.ETCWXDIR, "icons")
 sys.path.append(gmpath)
 
-class AbstractToolbar:
+class AbstractToolbar(object):
     """Abstract toolbar class"""
     def __init__():
         pass
@@ -46,7 +48,9 @@
 
         for tool in toolData:
             self.CreateTool(parent, toolbar, *tool)
-            
+
+        self.toolbar = toolbar
+        
     def ToolbarData(self):
         """Toolbar data"""
 
@@ -70,6 +74,10 @@
             toolbar.AddSeparator()
 
         return tool
+
+    def GetToolbar(self):
+        """Get toolbar widget reference"""
+        return self.toolbar
     
 class MapToolbar(AbstractToolbar):
     """
@@ -384,7 +392,7 @@
             data.append((self.settings, "digSettings", Icons["digSettings"].GetBitmap(),
                          wx.ITEM_NORMAL, Icons["digSettings"].GetLabel(), Icons["digSettings"].GetDesc(),
                          self.OnSettings))
-            data.append((self.exit, "digExit", Icons["digExit"].GetBitmap(),
+            data.append((self.exit, "digExit", Icons["quit"].GetBitmap(),
                          wx.ITEM_NORMAL, Icons["digExit"].GetLabel(), Icons["digExit"].GetDesc(),
                          self.OnExit))
 
@@ -837,3 +845,75 @@
             self.toolbar[self.numOfRows-1].Realize()
 
         return layerNameList
+
+class ProfileToolbar(AbstractToolbar):
+    """
+    Toolbar for digitization
+    """
+    def __init__(self, parent, mapdisplay, map):
+        self.parent     = parent
+        self.mapcontent = map
+        self.mapdisplay = mapdisplay
+
+        self.toolbar = wx.ToolBar(parent=self.mapdisplay, id=wx.ID_ANY)
+
+        # self.SetToolBar(self.toolbar)
+        self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
+
+        self.InitToolbar(self.mapdisplay, self.toolbar, self.ToolbarData())
+
+        # realize the toolbar
+        self.toolbar.Realize()
+
+    def ToolbarData(self):
+        """Toolbar data"""
+
+        self.transect = wx.NewId()
+        self.addraster = wx.NewId()
+        self.draw = wx.NewId()
+        self.options = wx.NewId()
+        self.drag = wx.NewId()
+        self.zoom = wx.NewId()
+        self.unzoom = wx.NewId()
+        self.erase = wx.NewId()
+        self.save = wx.NewId()
+        self.printer = wx.NewId()
+        self.quit = wx.NewId()
+                
+        # tool, label, bitmap, kind, shortHelp, longHelp, handler
+        return   (
+            (self.transect, 'transect', Icons["transect"].GetBitmap(),
+             wx.ITEM_NORMAL, Icons["transect"].GetLabel(), Icons["transect"].GetDesc(),
+             self.parent.DrawTransect),
+            (self.addraster, 'raster', Icons["addrast"].GetBitmap(),
+             wx.ITEM_NORMAL, Icons["addrast"].GetLabel(), Icons["addrast"].GetDesc(),
+             self.parent.SelectRaster),
+            (self.draw, 'profiledraw', Icons["profiledraw"].GetBitmap(),
+             wx.ITEM_NORMAL, Icons["profiledraw"].GetLabel(), Icons["profiledraw"].GetDesc(),
+             self.parent.CreateProfile),
+            (self.options, 'options', Icons["profileopt"].GetBitmap(),
+             wx.ITEM_NORMAL, Icons["profileopt"].GetLabel(), Icons["profileopt"].GetDesc(),
+             self.parent.ProfileOptionsMenu),
+            (self.drag, 'drag', Icons['pan'].GetBitmap(),
+             wx.ITEM_NORMAL, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
+             self.parent.OnDrag),
+            (self.zoom, 'zoom', Icons['zoom_in'].GetBitmap(),
+             wx.ITEM_NORMAL, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
+             self.parent.OnZoom),
+            (self.unzoom, 'unzoom', Icons['zoom_back'].GetBitmap(),
+             wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
+             self.parent.OnRedraw),
+            (self.erase, 'erase', Icons["erase"].GetBitmap(),
+             wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
+             self.parent.OnErase),
+            ("", "", "", "", "", "", ""),
+            (self.save, 'save', Icons["savefile"].GetBitmap(),
+             wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
+             self.parent.SaveToFile),
+            (self.printer, 'print', Icons["printmap"].GetBitmap(),
+             wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
+             self.parent.PrintMenu),
+            (self.quit, 'quit', Icons["quit"].GetBitmap(),
+             wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
+             self.parent.OnQuit),
+            )

Modified: grass/trunk/gui/wxpython/icons/icon.py
===================================================================
--- grass/trunk/gui/wxpython/icons/icon.py	2008-04-22 16:04:54 UTC (rev 31072)
+++ grass/trunk/gui/wxpython/icons/icon.py	2008-04-22 16:06:31 UTC (rev 31073)
@@ -80,7 +80,6 @@
     "digUndo" : wx.ART_ERROR,
     "digSettings" : 'settings.gif',
     "digAdditionalTools" : wx.ART_ERROR,
-    "digExit"    : 'exit.gif',
     # gis manager
     "newdisplay" : 'gui-startmon.gif',
     "workspaceNew" : 'file-new.gif',
@@ -109,7 +108,7 @@
     "addtext"    : 'module-d.text.gif',
     "addbarscale": 'module-d.barscale.gif',
     "addlegend"  : 'module-d.legend.gif',
-    "quit"       : wx.ART_ERROR,
+    "quit"       : 'gui-exit.gif',
     # analyze raster
     "analyze"    : 'gui-rastanalyze.gif',
     "measure"    : 'gui-measure.gif',
@@ -298,7 +297,7 @@
                               desc="Settings dialog for digitization tool"),
     "digSplitLine": MetaIcon (img=icons_img["digSplitLine"], label="Split line/boundary",
                               desc="Left: Select; Middle: Unselect; Right: Confirm"),
-    "digExit"    : MetaIcon (img=icons_img["digExit"], label="Quit digitization tool"),
+    "digExit"    : MetaIcon (img=icons_img["quit"], label="Quit digitization tool"),
     "digAdditionalTools" : MetaIcon (img=icons_img["digAdditionalTools"], label="Additional tools " \
                                          "(copy, flip, connect, etc.)",
                                      desc="Left: Select; Middle: Unselect; Right: Confirm"),

Modified: grass/trunk/gui/wxpython/icons/silk/__init__.py
===================================================================
--- grass/trunk/gui/wxpython/icons/silk/__init__.py	2008-04-22 16:04:54 UTC (rev 31072)
+++ grass/trunk/gui/wxpython/icons/silk/__init__.py	2008-04-22 16:06:31 UTC (rev 31073)
@@ -32,6 +32,7 @@
     "addtext"    : 'textfield_add.png',
     "addbarscale": 'page_white_picture.png',
     "addlegend"  : 'page_green.png',
+    "quit"       : 'door_in.png',
     # digit
     ## add feature
     "digAddPoint": 'bullet_add.png',
@@ -56,7 +57,6 @@
     "digUndo" : 'arrow_undo.png',
     "digSettings" : 'color_swatch.png',
     "digAdditionalTools" : 'plugin.png',
-    "digExit"     : 'door_in.png',
     # gis manager
     "newdisplay" : 'application_add.png',
     "workspaceNew" : 'page_white.png',
@@ -77,5 +77,9 @@
     "addrgb"     : 'rgb.png',
     "addhis"     : 'his.png',
     "addthematic": 'thematic.png',
-    "addchart"   : 'chart_bar.png'
+    "addchart"   : 'chart_bar.png',
+    # profile analysis
+    "transect"   : 'image_edit.png',
+    "profiledraw"   : 'page_white_lightning.png',
+    "profileopt"   : 'color_swatch.png',
     }



More information about the grass-commit mailing list