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

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Apr 19 04:10:38 EDT 2010


Author: martinl
Date: 2010-04-19 04:10:15 -0400 (Mon, 19 Apr 2010)
New Revision: 41921

Modified:
   grass/trunk/gui/wxpython/gui_modules/gmodeler.py
   grass/trunk/gui/wxpython/gui_modules/preferences.py
Log:
wxGUI/modeler: model properties


Modified: grass/trunk/gui/wxpython/gui_modules/gmodeler.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gmodeler.py	2010-04-19 06:49:36 UTC (rev 41920)
+++ grass/trunk/gui/wxpython/gui_modules/gmodeler.py	2010-04-19 08:10:15 UTC (rev 41921)
@@ -15,6 +15,7 @@
  - ProcessModelFile
  - WriteModelFile
  - PreferencesDialog
+ - PropertiesDialog
  
 (C) 2010 by the GRASS Development Team
 This program is free software under the GNU General Public License
@@ -256,6 +257,7 @@
         self.baseTitle = title
         self.modelFile = None    # loaded model
         self.modelChanged = False
+        self.properties = None
         
         self.cursors = {
             "default" : wx.StockCursor(wx.CURSOR_ARROW),
@@ -353,7 +355,19 @@
         
     def OnModelProperties(self, event):
         """!Model properties dialog"""
+        dlg = PropertiesDialog(parent = self)
+        dlg.CentreOnParent()
+        if self.properties:
+            dlg.Init(self.properties)
+        else:
+            dlg.Init({ 'name' : '',
+                       'desc' : '',
+                       'author' : getpass.getuser() })
+        if dlg.ShowModal() == wx.ID_OK:
+            self.properties = dlg.GetValues()
         
+        dlg.Destroy()
+        
     def OnDeleteData(self, event):
         """!Delete intermediate data"""
         rast, vect, rast3d, msg = self.model.GetIntermediateData()
@@ -683,21 +697,31 @@
 
     def _writePython(self, fd):
         """!Write model to file"""
+        if self.properties:
+            properties = self.properties
+        else:
+            properties = { 'name' : _("Graphical modeler script"),
+                           'desc' : _("Script generated by wxGUI Graphical Modeler"),
+                           'author' : getpass.getuser() }
+        
         fd.write(
 r"""#!/usr/bin/env python
 #
 ############################################################################
 #
-# MODULE:       Graphical modeler script
+# MODULE:       %s
 #
 # AUTHOR(S):	%s
 #               
-# PURPOSE:      Script generated by wxGUI Graphical Modeler
+# PURPOSE:      %s
 #
 # DATE:         %s
 #
 #############################################################################
-""" % (getpass.getuser(), time.asctime()))
+""" % (properties['name'],
+       properties['author'],
+       properties['desc'],
+       time.asctime()))
         
         fd.write(
 r"""
@@ -2103,7 +2127,98 @@
         
         self.parent.GetModel().Update()
         self.parent.GetCanvas().Refresh()
+
+class PropertiesDialog(wx.Dialog):
+    """!Model properties dialog
+    """
+    def __init__(self, parent, id = wx.ID_ANY,
+                 title = _('Model properties'),
+                 size = (350, 400),
+                 style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
+        wx.Dialog.__init__(self, parent, id, title, size = size,
+                           style = style)
+
+        self.name = wx.TextCtrl(parent = self, id = wx.ID_ANY,
+                                size = (300, 25))
+        self.desc = wx.TextCtrl(parent = self, id = wx.ID_ANY,
+                                style = wx.TE_MULTILINE,
+                                size = (300, 50))
+        self.author = wx.TextCtrl(parent = self, id = wx.ID_ANY,
+                                size = (300, 25))
         
+        # buttons
+        self.btnOk     = wx.Button(self, wx.ID_OK)
+        self.btnCancel = wx.Button(self, wx.ID_CANCEL)
+        self.btnOk.SetDefault()
+        
+        self.btnOk.SetToolTipString(_("Apply properties"))
+        self.btnOk.SetDefault()
+        self.btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
+        
+        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
+        
+        self._layout()
+
+    def _layout(self):
+        gridSizer = wx.GridBagSizer (hgap=3, vgap=3)
+        gridSizer.AddGrowableCol(0)
+        gridSizer.Add(item = wx.StaticText(parent = self, id = wx.ID_ANY,
+                                         label = _("Name:")),
+                      flag = wx.ALIGN_LEFT |
+                      wx.ALIGN_CENTER_VERTICAL,
+                      pos = (0, 0))
+        gridSizer.Add(item = self.name,
+                      flag = wx.ALIGN_LEFT |
+                      wx.ALIGN_CENTER_VERTICAL,
+                      pos = (0, 1))
+        gridSizer.Add(item = wx.StaticText(parent = self, id = wx.ID_ANY,
+                                         label = _("Description:")),
+                      flag = wx.ALIGN_LEFT |
+                      wx.ALIGN_CENTER_VERTICAL,
+                      pos = (1, 0))
+        gridSizer.Add(item = self.desc,
+                      flag = wx.ALIGN_LEFT |
+                      wx.ALIGN_CENTER_VERTICAL,
+                      pos = (1, 1))
+        gridSizer.Add(item = wx.StaticText(parent = self, id = wx.ID_ANY,
+                                         label = _("Author(s):")),
+                      flag = wx.ALIGN_LEFT |
+                      wx.ALIGN_CENTER_VERTICAL,
+                      pos = (2, 0))
+        gridSizer.Add(item = self.author,
+                      flag = wx.ALIGN_LEFT |
+                      wx.ALIGN_CENTER_VERTICAL,
+                      pos = (2, 1))
+
+        btnStdSizer = wx.StdDialogButtonSizer()
+        btnStdSizer.AddButton(self.btnCancel)
+        btnStdSizer.AddButton(self.btnOk)
+        btnStdSizer.Realize()
+        
+        mainSizer = wx.BoxSizer(wx.VERTICAL)
+        mainSizer.Add(item=gridSizer, proportion=0,
+                      flag=wx.EXPAND | wx.ALL, border=5)
+        mainSizer.Add(item=btnStdSizer, proportion=0,
+                      flag=wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border=5)
+        
+        self.SetSizer(mainSizer)
+        mainSizer.Fit(self)
+
+    def OnCloseWindow(self, event):
+        self.Hide()
+        
+    def GetValues(self):
+        """!Get values"""
+        return { 'name'   : self.name.GetValue(),
+                 'desc'   : self.desc.GetValue(),
+                 'author' : self.author.GetValue() }
+
+    def Init(self, prop):
+        """!Initialize dialog"""
+        self.name.SetValue(prop['name'])
+        self.desc.SetValue(prop['desc'])
+        self.author.SetValue(prop['author'])
+        
 def main():
     app = wx.PySimpleApp()
     wx.InitAllImageHandlers()

Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py	2010-04-19 06:49:36 UTC (rev 41920)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py	2010-04-19 08:10:15 UTC (rev 41921)
@@ -2102,9 +2102,9 @@
         return fontlist
 
 class MapsetAccess(wx.Dialog):
+    """!Controls setting options and displaying/hiding map overlay
+    decorations
     """
-    Controls setting options and displaying/hiding map overlay decorations
-    """
     def __init__(self, parent, id, title=_('Set/unset access to mapsets in current location'),
                  pos=wx.DefaultPosition, size=(350, 400),
                  style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER):



More information about the grass-commit mailing list