[GRASS-SVN] r55899 - grass/branches/releasebranch_6_4/gui/wxpython/gmodeler

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Apr 18 06:51:06 PDT 2013


Author: annakrat
Date: 2013-04-18 06:51:06 -0700 (Thu, 18 Apr 2013)
New Revision: 55899

Modified:
   grass/branches/releasebranch_6_4/gui/wxpython/gmodeler/frame.py
Log:
wxGUI/modeler: make random layout (avoid hidden actions), fix removing by right click (merge from trunk, r55898)

Modified: grass/branches/releasebranch_6_4/gui/wxpython/gmodeler/frame.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gmodeler/frame.py	2013-04-18 13:44:35 UTC (rev 55898)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gmodeler/frame.py	2013-04-18 13:51:06 UTC (rev 55899)
@@ -27,6 +27,7 @@
 import tempfile
 import copy
 import re
+import random
 
 if __name__ == "__main__":
     sys.path.append(os.path.join(os.getenv('GISBASE'), 'etc', 'wxpython'))
@@ -71,6 +72,7 @@
         self.baseTitle = title
         self.modelFile = None    # loaded model
         self.modelChanged = False
+        self.randomness = 40 # random layout
         
         self.cursors = {
             "default" : wx.StockCursor(wx.CURSOR_ARROW),
@@ -149,6 +151,10 @@
         evthandler.SetPreviousHandler(item.GetEventHandler())
         item.SetEventHandler(evthandler)
 
+    def _randomShift(self):
+        """!Returns random value to shift layout"""
+        return random.randint(-self.randomness, self.randomness)
+
     def GetCanvas(self):
         """!Get canvas"""
         return self.canvas
@@ -633,7 +639,9 @@
         
         # add action to canvas
         x, y = self.canvas.GetNewShapePos()
-        action = ModelAction(self.model, cmd = cmd, x = x, y = y,
+        action = ModelAction(self.model, cmd = cmd,
+                             x = x + self._randomShift(),
+                             y = y + self._randomShift(),
                              id = self.model.GetNextId())
         overwrite = self.model.GetProperties().get('overwrite', None)
         if overwrite is not None:
@@ -669,7 +677,8 @@
         """
         # add action to canvas
         width, height = self.canvas.GetSize()
-        data = ModelData(self, x = width/2, y = height/2)
+        data = ModelData(self, x = width/2 + self._randomShift(),
+                         y = height/2 + self._randomShift())
        
         dlg = ModelDataDialog(parent = self, shape = data)
         data.SetPropDialog(dlg)
@@ -714,7 +723,8 @@
         """!Process action data"""
         if params: # add data items
             width, height = self.canvas.GetSize()
-            x = [width/2 + 200, width/2 - 200]
+            x = width/2 - 200 + self._randomShift()
+            y = height/2 + self._randomShift()
             for p in params['params']:
                 if p.get('prompt', '') in ('raster', 'vector', 'raster3d') and \
                         (p.get('value', None) or \
@@ -742,7 +752,7 @@
                     
                     data = ModelData(self, value = p.get('value', ''),
                                      prompt = p.get('prompt', ''),
-                                     x = x.pop(), y = height/2)
+                                     x = x, y = y)
                     self._addEvent(data)
                     self.canvas.diagram.AddShape(data)
                     data.Show(True)
@@ -973,7 +983,7 @@
         self.SetDiagram(self.diagram)
         self.diagram.SetCanvas(self)
         
-        self.SetScrollbars(20, 20, 1000/20, 1000/20)
+        self.SetScrollbars(20, 20, 2000/20, 2000/20)
         
         self.Bind(wx.EVT_CHAR,  self.OnChar)
         
@@ -989,9 +999,14 @@
         self.parent.ModelChanged()
         
         diagram = self.GetDiagram()
-        for shape in diagram.GetShapeList():
-            if not shape.Selected():
-                continue
+        shapes = [shape for shape in diagram.GetShapeList() if shape.Selected()]
+        self.RemoveShapes(shapes)
+
+    def RemoveShapes(self, shapes):
+        """!Removes shapes"""
+        self.parent.ModelChanged()
+        diagram = self.GetDiagram()
+        for shape in shapes:
             remList, upList = self.parent.GetModel().RemoveItem(shape)
             shape.Select(False)
             diagram.RemoveShape(shape)
@@ -1004,7 +1019,7 @@
                 item.Update()
         
         self.Refresh()
-
+        
     def GetNewShapePos(self):
         """!Determine optimal position for newly added object
 
@@ -1018,7 +1033,7 @@
             yBox = shape.GetBoundingBoxMin()[1] / 2
             if yBox > 0 and y < yNew + yBox and y > yNew - yBox:
                 yNew += yBox * 3
-        
+
         return xNew, yNew
     
 class ModelEvtHandler(ogl.ShapeEvtHandler):
@@ -1249,7 +1264,7 @@
             
             for s in toUnselect:
                 s.Select(False, dc)
-        
+
         canvas.Refresh(False)
         
     def OnAddPoint(self, event):
@@ -1280,7 +1295,7 @@
     def OnRemove(self, event):
         """!Remove shape
         """
-        self.frame.GetCanvas().RemoveSelected()
+        self.frame.GetCanvas().RemoveShapes([self.GetShape()])
         self.frame.itemPanel.Update()
         
 class VariablePanel(wx.Panel):



More information about the grass-commit mailing list