[GRASS-SVN] r42598 - grass/trunk/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jun 20 10:52:04 EDT 2010


Author: martinl
Date: 2010-06-20 14:52:03 +0000 (Sun, 20 Jun 2010)
New Revision: 42598

Modified:
   grass/trunk/gui/wxpython/gui_modules/profile.py
   grass/trunk/gui/wxpython/gui_modules/toolbars.py
Log:
wxGUI/profile: toolbar clean up, cosmetics in profile.py + doxygenization


Modified: grass/trunk/gui/wxpython/gui_modules/profile.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/profile.py	2010-06-20 13:19:44 UTC (rev 42597)
+++ grass/trunk/gui/wxpython/gui_modules/profile.py	2010-06-20 14:52:03 UTC (rev 42598)
@@ -1,4 +1,4 @@
-"""
+"""!
 @package profile
 
 Profile analysis of GRASS raster maps and images.
@@ -11,13 +11,13 @@
  - TextDialog
  - OptDialog
 
-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.
+(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.
+
 @author Michael Barton
-Various updates: Martin Landa <landa.martin gmail.com>
+ at author Various updates by Martin Landa <landa.martin gmail.com>
 """
 
 import os
@@ -31,22 +31,14 @@
     import numpy
     import wx.lib.plot as plot
 except ImportError:
-    msg= """
-    This module requires the NumPy module, which could not be
-    imported. It probably is not installed (it's not part of the
-    standard Python distribution). See the Numeric Python site
-    (http://numpy.scipy.org) for information on downloading source or
-    binaries."""
+    msg= _("This module requires the NumPy module, which could not be "
+           "imported. It probably is not installed (it's not part of the "
+           "standard Python distribution). See the Numeric Python site "
+           "(http://numpy.scipy.org) for information on downloading source or "
+           "binaries.")
     print >> sys.stderr, "profile.py: " + msg
 
 import globalvar
-try:
-    import subprocess
-except:
-    CompatPath = os.path.join(globalvar.ETCWXDIR)
-    sys.path.append(CompatPath)
-    from compat import subprocess as subprocess
-
 import render
 import menuform
 import disp_print
@@ -59,10 +51,8 @@
 from grass.script import core as grass
 
 class ProfileFrame(wx.Frame):
+    """!Mainframe for displaying profile of raster map. Uses wx.lib.plot.
     """
-    Mainframe for displaying profile of raster map. Uses wx.lib.plot.
-    """
-
     def __init__(self, parent=None, id=wx.ID_ANY, title=_("Profile Analysis"),
                  rasterList=[],
                  pos=wx.DefaultPosition, size=wx.DefaultSize,
@@ -86,7 +76,7 @@
         #
         # Icon
         #
-        self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass_map.ico'), wx.BITMAP_TYPE_ICO))
+        self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO))
         
         #
         # Add toolbar
@@ -221,9 +211,8 @@
         self.CentreOnScreen()
 
     def OnDrawTransect(self, event):
+        """!Draws transect to profile in map display
         """
-        Draws transect to profile in map display
-        """
         self.mapwin.polycoords = []
         self.seglist = []
         self.mapwin.ClearLines(self.mapwin.pdc)
@@ -239,10 +228,8 @@
         self.mapwin.SetCursor(self.Parent.cursors["cross"])
 
     def OnSelectRaster(self, event):
+        """!Select raster map(s) to profile
         """
-        Select raster map(s) to profile
-        """
-        
         dlg = SetRasterDialog(parent=self)
 
         if dlg.ShowModal() == wx.ID_OK:
@@ -256,11 +243,9 @@
         dlg.Destroy()
 
     def SetRaster(self):
-        """
-        Create coordinate string for profiling. Create segment list for
+        """!Create coordinate string for profiling. Create segment list for
         transect segment markers.
         """
-
         #
         # create list of coordinate points for r.profile
         #
@@ -362,9 +347,8 @@
             self.ylabel = self.ylabel.rstrip(',')
 
     def SetGraphStyle(self):
+        """!Set plot and text options
         """
-        Set plot and text options
-        """
         self.client.SetFont(self.properties['font']['wxfont'])
         self.client.SetFontSizeTitle(self.properties['font']['prop']['titleSize'])
         self.client.SetFontSizeAxis(self.properties['font']['prop']['axisSize'])
@@ -422,24 +406,19 @@
         # self.client.SetPointLabelFunc(self.DrawPointLabel())
 
     def CreateDatalist(self, raster, coords):
+        """!Build a list of distance, value pairs for points along transect
         """
-        Build a list of distance, value pairs for points along transect
-        """
         datalist = []
-        import subprocess
-                
+        
         # keep total number of transect points to 500 or less to avoid 
         # freezing with large, high resolution maps
         region = grass.region()
         curr_res = min(float(region['nsres']),float(region['ewres']))
         transect_rec = 0
-        print "transect length = "+str(self.transect_length)
-        print "current resolution = "+str(curr_res)
         if self.transect_length / curr_res > 500:
             transect_res = self.transect_length / 500
         else: transect_res = curr_res
-        print "transect resolution = "+str(transect_res)
-                
+        
         try:
             ret = gcmd.RunCommand("r.profile",
                              input=raster,
@@ -463,13 +442,12 @@
             return None
 
     def OnCreateProfile(self, event):
+        """!Main routine for creating a profile. Uses r.profile to
+        create a list of distance,cell value pairs. This is passed to
+        plot to create a line graph of the profile. If the profile
+        transect is in multiple segments, these are drawn as
+        points. Profile transect is drawn, using methods in mapdisp.py
         """
-        Main routine for creating a profile. Uses r.profile to create a list
-        of distance,cell value pairs. This is passed to plot to create a
-        line graph of the profile. If the profile transect is in multiple
-        segments, these are drawn as points. Profile transect is drawn, using
-        methods in mapdisp.py
-        """
     
         if len(self.mapwin.polycoords) == 0 or self.raster[0]['name'] == '':
             dlg = wx.MessageDialog(parent=self,
@@ -494,11 +472,9 @@
         self.mapwin.mouse['box'] = 'point'
 
     def DrawPlot(self):
-        """
-        Draw line and point plot from transect datalist and
+        """!Draw line and point plot from transect datalist and
         transect segment endpoint coordinates.
         """
-
         # graph the distance, value pairs for the transect
         self.plotlist = []
         if len(self.seglist) > 0 :
@@ -546,44 +522,36 @@
                          self.properties['y-axis']['axis'])
 
     def OnZoom(self, event):
+        """!Enable zooming and disable dragging
         """
-        Enable zooming and disable dragging
-        """
-
         self.zoom = True
         self.drag = False
         self.client.SetEnableZoom(self.zoom)
         self.client.SetEnableDrag(self.drag)
 
     def OnDrag(self, event):
+        """!Enable dragging and disable zooming
         """
-        Enable dragging and disable zooming
-        """
-
         self.zoom = False
         self.drag = True
         self.client.SetEnableDrag(self.drag)
         self.client.SetEnableZoom(self.zoom)
 
     def OnRedraw(self, event):
+        """!Redraw the profile window. Unzoom to original size
         """
-        Redraw the profile window. Unzoom to original size
-        """
         self.client.Reset()
         self.client.Redraw()
 
     def Update(self):
+        """!Update profile after changing options
         """
-        Update profile after changing options
-        """
-
         self.SetGraphStyle()
         self.DrawPlot()
 
     def OnErase(self, event):
+        """!Erase the profile window
         """
-        Erase the profile window
-        """
         self.client.Clear()
         self.mapwin.ClearLines(self.mapwin.pdc)
         self.mapwin.ClearLines(self.mapwin.pdcTmp)
@@ -597,20 +565,18 @@
         #            pass
 
     def SaveToFile(self, event):
+        """!Save profile to graphics file
         """
-        Save profile to graphics file
-        """
         self.client.SaveFile()
 
     def SaveProfileToFile(self, event):
-        """
-        Save r.profile data to a csv file
+        """!Save r.profile data to a csv file
         """    
+        wildcard = _("Comma separated value (*.csv)|*.csv")
         
-        wildcard = "Comma separated value (*.csv)|*.csv" 
-        
         dlg = wx.FileDialog(
-            self, message="Path and prefix (for raster name) to save profile values...", defaultDir=os.getcwd(), 
+            self, message=_("Path and prefix (for raster name) to save profile values..."),
+            defaultDir=os.getcwd(), 
             defaultFile="",  wildcard=wildcard, style=wx.SAVE
             )
         if dlg.ShowModal() == wx.ID_OK:
@@ -638,15 +604,14 @@
         dlg.Destroy()
 
     def DrawPointLabel(self, dc, mDataDict):
-        """!This is the fuction that defines how the pointLabels are plotted
-            dc - DC that will be passed
-            mDataDict - Dictionary of data that you want to use for the pointLabel
+        """!This is the fuction that defines how the pointLabels are
+            plotted dc - DC that will be passed mDataDict - Dictionary
+            of data that you want to use for the pointLabel
 
-            As an example I have decided I want a box at the curve point
-            with some text information about the curve plotted below.
-            Any wxDC method can be used.
+            As an example I have decided I want a box at the curve
+            point with some text information about the curve plotted
+            below.  Any wxDC method can be used.
         """
-        # ----------
         dc.SetPen(wx.Pen(wx.BLACK))
         dc.SetBrush(wx.Brush( wx.BLACK, wx.SOLID ) )
 
@@ -659,7 +624,6 @@
         #make a string to display
         s = "Crv# %i, '%s', Pt. (%.2f,%.2f), PtInd %i" %(cNum, legend, px, py, pntIn)
         dc.DrawText(s, sx , sy+1)
-        # -----------
 
     def OnMouseLeftDown(self,event):
         s= "Left Mouse Down at Point: (%.4f, %.4f)" % self.client._getXY(event)
@@ -684,10 +648,8 @@
         event.Skip()           #go to next handler
 
     def ProfileOptionsMenu(self, event):
+        """!Popup menu for profile and text options
         """
-        Popup menu for profile and text options
-        """
-
         point = wx.GetMousePosition()
         popt = wx.Menu()
         # Add items to the menu
@@ -705,19 +667,18 @@
         popt.Destroy()
 
     def NotFunctional(self):
+        """!Creates a 'not functional' message dialog
         """
-        Creates a 'not functional' message dialog
-        """
-
-        dlg = wx.MessageDialog(self, 'This feature is not yet functional',
-                           'Under Construction', wx.OK | wx.ICON_INFORMATION)
+        dlg = wx.MessageDialog(parent = self,
+                               message = _('This feature is not yet functional'),
+                               caption = _('Under Construction'),
+                               style = wx.OK | wx.ICON_INFORMATION)
         dlg.ShowModal()
         dlg.Destroy()
 
     def OnPText(self, dlg):
+        """!Use user's provided profile text settings.
         """
-        Use user's provided profile text settings.
-        """
         self.ptitle = dlg.ptitle
         self.xlabel = dlg.xlabel
         self.ylabel = dlg.ylabel
@@ -735,10 +696,8 @@
         self.OnRedraw(event=None)
     
     def PText(self, event):
+        """!Set custom text values for profile title and axis labels.
         """
-        Set custom text values for profile
-        title and axis labels.
-        """
         dlg = TextDialog(parent=self, id=wx.ID_ANY, title=_('Profile text settings'))
 
         if dlg.ShowModal() == wx.ID_OK:
@@ -747,11 +706,10 @@
         dlg.Destroy()
 
     def POptions(self, event):
+        """!Set various profile options, including: line width, color,
+        style; marker size, color, fill, and style; grid and legend
+        options.  Calls OptDialog class.
         """
-        Set various profile options, including: line width, color, style;
-        marker size, color, fill, and style; grid and legend options.
-        Calls OptDialog class.
-        """
         dlg = OptDialog(parent=self, id=wx.ID_ANY, title=_('Profile settings'))
         btnval = dlg.ShowModal()
 
@@ -763,9 +721,8 @@
             dlg.Destroy()
 
     def PrintMenu(self, event):
+        """!Print options and output menu
         """
-        Print options and output menu
-        """
         point = wx.GetMousePosition()
         printmenu = wx.Menu()
         # Add items to the menu
@@ -817,9 +774,8 @@
     def __init__(self, parent, id=wx.ID_ANY, title=_("Select raster map to profile"),
                  pos=wx.DefaultPosition, size=wx.DefaultSize,
                  style=wx.DEFAULT_DIALOG_STYLE):
+        """!Dialog to select raster maps to profile.
         """
-        Dialog to select raster maps to profile.
-        """
 
         wx.Dialog.__init__(self, parent, id, title, pos, size, style)
 
@@ -899,11 +855,10 @@
 class TextDialog(wx.Dialog):
     def __init__(self, parent, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize,
                  style=wx.DEFAULT_DIALOG_STYLE):
-        wx.Dialog.__init__(self, parent, id, title, pos, size, style)
-        """
-        Dialog to set profile text options: font, title
+        """!Dialog to set profile text options: font, title
         and font size, axis labels and font size
         """
+        wx.Dialog.__init__(self, parent, id, title, pos, size, style)
         #
         # initialize variables
         #
@@ -1151,12 +1106,12 @@
         
 class OptDialog(wx.Dialog):
     def __init__(self, parent, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize,
-            style=wx.DEFAULT_DIALOG_STYLE):
-        wx.Dialog.__init__(self, parent, id, title, pos, size, style)
+                 style=wx.DEFAULT_DIALOG_STYLE): 
+        """!Dialog to set various profile options, including: line
+        width, color, style; marker size, color, fill, and style; grid
+        and legend options.
         """
-        Dialog to set various profile options, including: line width, color, style;
-        marker size, color, fill, and style; grid and legend options.
-        """
+        wx.Dialog.__init__(self, parent, id, title, pos, size, style)
         # init variables
         self.pstyledict = parent.pstyledict
         self.ptfilldict = parent.ptfilldict

Modified: grass/trunk/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/toolbars.py	2010-06-20 13:19:44 UTC (rev 42597)
+++ grass/trunk/gui/wxpython/gui_modules/toolbars.py	2010-06-20 14:52:03 UTC (rev 42598)
@@ -1267,8 +1267,7 @@
         return self.mapLayer
     
 class ProfileToolbar(AbstractToolbar):
-    """!
-    Toolbar for profiling raster map
+    """!Toolbar for profiling raster map
     """ 
     def __init__(self, parent):
         AbstractToolbar.__init__(self, parent)
@@ -1301,12 +1300,13 @@
             (self.transect, 'transect', Icons["transect"].GetBitmap(),
              wx.ITEM_NORMAL, Icons["transect"].GetLabel(), Icons["transect"].GetDesc(),
              self.parent.OnDrawTransect),
+            ("", "", "", "", "", "", ""),
             (self.draw, 'profiledraw', Icons["profiledraw"].GetBitmap(),
              wx.ITEM_NORMAL, Icons["profiledraw"].GetLabel(), Icons["profiledraw"].GetDesc(),
              self.parent.OnCreateProfile),
-            (self.options, 'options', Icons["profileopt"].GetBitmap(),
-             wx.ITEM_NORMAL, Icons["profileopt"].GetLabel(), Icons["profileopt"].GetDesc(),
-             self.parent.ProfileOptionsMenu),
+            (self.erase, 'erase', Icons["erase"].GetBitmap(),
+             wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
+             self.parent.OnErase),
             (self.drag, 'drag', Icons['pan'].GetBitmap(),
              wx.ITEM_NORMAL, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
              self.parent.OnDrag),
@@ -1316,19 +1316,20 @@
             (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.datasave, 'save data', Icons["datasave"].GetBitmap(),
+             wx.ITEM_NORMAL, Icons["datasave"].GetLabel(), Icons["datasave"].GetDesc(),
+             self.parent.SaveProfileToFile),
             (self.save, 'save image', Icons["savefile"].GetBitmap(),
              wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
              self.parent.SaveToFile),
-            (self.datasave, 'save data', Icons["datasave"].GetBitmap(),
-             wx.ITEM_NORMAL, Icons["datasave"].GetLabel(), Icons["datasave"].GetDesc(),
-             self.parent.SaveProfileToFile),
             (self.printer, 'print', Icons["printmap"].GetBitmap(),
              wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
              self.parent.PrintMenu),
+            ("", "", "", "", "", "", ""),
+            (self.options, 'options', Icons["profileopt"].GetBitmap(),
+             wx.ITEM_NORMAL, Icons["profileopt"].GetLabel(), Icons["profileopt"].GetDesc(),
+             self.parent.ProfileOptionsMenu),
             (self.quit, 'quit', Icons["quit"].GetBitmap(),
              wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
              self.parent.OnQuit),



More information about the grass-commit mailing list