[GRASS-SVN] r61354 - grass/trunk/gui/wxpython/modules

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jul 22 19:04:34 PDT 2014


Author: annakrat
Date: 2014-07-22 19:04:34 -0700 (Tue, 22 Jul 2014)
New Revision: 61354

Modified:
   grass/trunk/gui/wxpython/modules/mcalc_builder.py
Log:
wxGUI/mapcalc: seed handling added to the interface

Modified: grass/trunk/gui/wxpython/modules/mcalc_builder.py
===================================================================
--- grass/trunk/gui/wxpython/modules/mcalc_builder.py	2014-07-22 23:51:12 UTC (rev 61353)
+++ grass/trunk/gui/wxpython/modules/mcalc_builder.py	2014-07-23 02:04:34 UTC (rev 61354)
@@ -28,6 +28,7 @@
 from core.utils import _
 from gui_core.gselect import Select
 from gui_core.forms   import GUI
+from gui_core.widgets import IntegerValidator
 from core.settings    import UserSettings
 
 class MapCalcFrame(wx.Frame):
@@ -230,7 +231,18 @@
         self.overwrite = wx.CheckBox(parent = self.panel, id = wx.ID_ANY,
                                      label=_("Allow output files to overwrite existing files"))
         self.overwrite.SetValue(UserSettings.Get(group='cmd', key='overwrite', subkey='enabled'))
+
+        self.randomSeed = wx.CheckBox(parent=self.panel,
+                                      label=_("Generate random seed for rand()"))
+        self.randomSeedStaticText = wx.StaticText(parent=self.panel, label=_("Seed:"))
+        self.randomSeedText = wx.TextCtrl(parent=self.panel, size=(100, -1),
+                                          validator=IntegerValidator())
+        self.randomSeedText.SetToolTipString(_("Integer seed for rand() function"))
+        self.randomSeed.SetValue(True)
+        self.randomSeedStaticText.Disable()
+        self.randomSeedText.Disable()
         
+
         self.addbox = wx.CheckBox(parent=self.panel,
                                   label=_('Add created raster map into layer tree'), style = wx.NO_BORDER)
         self.addbox.SetValue(UserSettings.Get(group='cmd', key='addNewLayer', subkey='enabled'))
@@ -258,6 +270,9 @@
         self.newmaptxt.Bind(wx.EVT_TEXT, self.OnUpdateStatusBar)
         self.text_mcalc.Bind(wx.EVT_TEXT, self.OnUpdateStatusBar)
         self.overwrite.Bind(wx.EVT_CHECKBOX, self.OnUpdateStatusBar)
+        self.randomSeed.Bind(wx.EVT_CHECKBOX, self.OnUpdateStatusBar)
+        self.randomSeed.Bind(wx.EVT_CHECKBOX, self.OnSeedFlag)
+        self.randomSeedText.Bind(wx.EVT_TEXT, self.OnUpdateStatusBar)
 
         self._layout()
 
@@ -379,7 +394,17 @@
                   border = 5)
         sizer.Add(item = buttonSizer4, proportion = 0,
                   flag = wx.ALIGN_RIGHT | wx.ALL, border = 3)
-        
+
+        randomSizer = wx.BoxSizer(wx.HORIZONTAL)
+        randomSizer.Add(item=self.randomSeed, proportion=0,
+                        flag=wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, border=20)
+        randomSizer.Add(item=self.randomSeedStaticText, proportion=0,
+                        flag=wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, border=5)
+        randomSizer.Add(item=self.randomSeedText, proportion=0)
+        sizer.Add(item=randomSizer, proportion=0,
+                  flag=wx.LEFT | wx.RIGHT,
+                  border=5)
+
         sizer.Add(item = self.overwrite, proportion = 0,
                   flag = wx.LEFT | wx.RIGHT,
                   border = 5)
@@ -458,6 +483,13 @@
         self.SetStatusText(command)
         event.Skip()
 
+    def OnSeedFlag(self, event):
+        checked = self.randomSeed.IsChecked()
+        self.randomSeedText.Enable(not checked)
+        self.randomSeedStaticText.Enable(not checked)
+
+        event.Skip()
+
     def _getCommand(self):
         """Returns entire command as string."""
         expr = self.text_mcalc.GetValue().strip().replace("\n", " ")
@@ -467,10 +499,17 @@
         overwrite = ''
         if self.overwrite.IsChecked():
             overwrite = ' --overwrite'
-        return '{cmd} "{new} = {expr}"{overwrite}'.format(cmd=cmd, expr=expr,
-                                                          new=self.newmaptxt.GetValue(),
-                                                          overwrite=overwrite)
+        seed_flag = seed = ''
+        if re.search(pattern="rand *\(.+\)", string=expr):
+            if self.randomSeed.IsChecked():
+                seed_flag = ' -s'
+            else:
+                seed = " seed={val}".format(val=self.randomSeedText.GetValue().strip())
 
+        return ('{cmd} "{new} = {expr}"{seed}{seed_flag}{overwrite}'
+                .format(cmd=cmd, expr=expr, new=self.newmaptxt.GetValue(),
+                        seed_flag=seed_flag, seed=seed, overwrite=overwrite))
+
     def _addSomething(self, what):
         """Inserts operators, map names, and functions into text area
         """
@@ -520,11 +559,23 @@
                    message = _("You must enter an expression "
                                "to create a new raster map."))
             return
-        
+
+        seed_flag = seed = None
+        if re.search(pattern="rand *\(.+\)", string=expr):
+            if self.randomSeed.IsChecked():
+                seed_flag = '-s'
+            else:
+                seed = self.randomSeedText.GetValue().strip()
         if self.log:
-            cmd = [self.cmd, str('expression=%s = %s' % (name, expr))]
+            cmd = [self.cmd]
+            if seed_flag:
+                cmd.append('-s')
+            if seed:
+                cmd.append("seed={val}".format(val=seed))
             if self.overwrite.IsChecked():
                 cmd.append('--overwrite')
+            cmd.append(str('expression=%s = %s' % (name, expr)))
+
             self.log.RunCmd(cmd, onDone = self.OnDone)
             self.parent.Raise()
         else:
@@ -532,10 +583,16 @@
                 overwrite = True
             else:
                 overwrite = False
+            params = dict(expression="%s=%s" % (name, expr),
+                          overwrite=overwrite)
+            if seed_flag:
+                params['flags'] = 's'
+            if seed:
+                params['seed'] = seed
+
             RunCommand(self.cmd,
-                       expression = "%s=%s" % (name, expr),
-                       overwrite = overwrite)
-        
+                       **params)
+
     def OnDone(self, cmd, returncode):
         """Add create map to the layer tree
 



More information about the grass-commit mailing list