[PythonCAD] New patches to PythonCAD . . . .

Art Haas ahaas at airmail.net
Mon Dec 12 23:33:42 CET 2005


On Mon, Dec 12, 2005 at 01:39:36PM -0600, Art Haas wrote:
>
> I'm going to make the change to the horizontal moving to behave as your
> patch would have it, and I'll use some of your changes as a starting
> point. I suspect that I'll tweak some of your changes a bit, so what
> I'll do is send out some diffs when things look like I think they
> should, then we can see how things looks.

I took the patch Stuart provided and after tweaking things for a while
I've produced the following diff. First, I've changed the 'gtkmenus.py'
file so that move operations are only available if something is
selected. Second, I've slightly simplified Stuart's code, and made
changes so that horizontal, vertical, and two-point moves are all
changed. The patch below is not committed to my repo, btw.

Art

Index: PythonCAD/Interface/Gtk/gtkmenus.py
===================================================================
--- PythonCAD/Interface/Gtk/gtkmenus.py	(revision 2089)
+++ PythonCAD/Interface/Gtk/gtkmenus.py	(working copy)
@@ -1877,7 +1877,7 @@
         _active = gtkimage.getActiveLayer()
         _act = _group.get_action('Move')
         if _act is not None:
-            _act.set_property('sensitive', _active.hasEntities())
+            _act.set_property('sensitive', gtkimage.hasSelection())
         _act = _group.get_action('Stretch')
         if _act is not None:
             _act.set_property('sensitive', _active.hasEntities())
Index: PythonCAD/Interface/Gtk/gtkmodify.py
===================================================================
--- PythonCAD/Interface/Gtk/gtkmodify.py	(revision 2089)
+++ PythonCAD/Interface/Gtk/gtkmodify.py	(working copy)
@@ -147,9 +147,12 @@
     if len(_text):
         _dist = util.get_float(eval(_text, gtkimage.getImageVariables()))
         tool.setDistance(_dist, 0.0)
-        gtkimage.setPrompt("Click on the objects to move.")
-        tool.setHandler("button_press", move_elem_button_press_cb)
-        tool.delHandler("entry_event")
+        _active_layer = gtkimage.getActiveLayer()
+        _objs = []
+        for _obj in gtkimage.getSelectedObjects():
+            if _obj.getParent() is _active_layer:
+                _objs.append(_obj)
+        move_objects(gtkimage, _objs, tool)
 
 def move_horizontal_second_button_press_cb(gtkimage, widget, event, tool):
     _x, _y = gtkimage.getCurrentPoint()
@@ -161,10 +164,12 @@
         _x, _y = _pc
     _x1, _y1 = tool.getLocation()
     tool.setDistance((_x - _x1), 0.0)
-    tool.clearLocation()
-    gtkimage.setPrompt("Select the objects to move.")
-    tool.setHandler("button_press", move_elem_button_press_cb)
-    tool.delHandler("entry_event")
+    _active_layer = gtkimage.getActiveLayer()
+    _objs = []
+    for _obj in gtkimage.getSelectedObjects():
+        if _obj.getParent() is _active_layer:
+            _objs.append(_obj)
+    move_objects(gtkimage, _objs, tool)
     return True
 
 def move_horizontal_first_button_press_cb(gtkimage, widget, event, tool):
@@ -196,9 +201,12 @@
     if len(_text):
         _dist = util.get_float(eval(_text, gtkimage.getImageVariables()))
         tool.setDistance(0.0, _dist)
-        gtkimage.setPrompt("Click on the objects to move.")
-        tool.setHandler("button_press", move_elem_button_press_cb)
-        tool.delHandler("entry_event")
+        _active_layer = gtkimage.getActiveLayer()
+        _objs = []
+        for _obj in gtkimage.getSelectedObjects():
+            if _obj.getParent() is _active_layer:
+                _objs.append(_obj)
+        move_objects(gtkimage, _objs, tool)
     
 def move_vertical_second_button_press_cb(gtkimage, widget, event, tool):
     _x, _y = gtkimage.getCurrentPoint()
@@ -210,10 +218,12 @@
         _x, _y = _pc
     _x1, _y1 = tool.getLocation()
     tool.setDistance(0.0, (_y - _y1))
-    tool.clearLocation()
-    gtkimage.setPrompt("Select the objects to move.")
-    tool.setHandler("button_press", move_elem_button_press_cb)
-    tool.delHandler("entry_event")
+    _active_layer = gtkimage.getActiveLayer()
+    _objs = []
+    for _obj in gtkimage.getSelectedObjects():
+        if _obj.getParent() is _active_layer:
+            _objs.append(_obj)
+    move_objects(gtkimage, _objs, tool)
     return True
 
 def move_vertical_first_button_press_cb(gtkimage, widget, event, tool):
@@ -245,9 +255,12 @@
     if len(_text):
         _x, _y = eval(_text, gtkimage.getImageVariables())
         tool.setDistance(util.get_float(_x), util.get_float(_y))
-        gtkimage.setPrompt("Click on the objects to move.")
-        tool.setHandler("button_press", move_elem_button_press_cb)
-        tool.delHandler("entry_event")
+        _active_layer = gtkimage.getActiveLayer()
+        _objs = []
+        for _obj in gtkimage.getSelectedObjects():
+            if _obj.getParent() is _active_layer:
+                _objs.append(_obj)
+        move_objects(gtkimage, _objs, tool)
 
 def move_xy_second_button_press_cb(gtkimage, widget, event, tool):
     _x, _y = gtkimage.getCurrentPoint()
@@ -259,10 +272,12 @@
         _x, _y = _pc
     _x1, _y1 = tool.getLocation()
     tool.setDistance((_x - _x1), (_y - _y1))
-    tool.clearLocation()
-    gtkimage.setPrompt("Select the objects to move.")
-    tool.setHandler("button_press", move_elem_button_press_cb)
-    tool.delHandler("entry_event")
+    _active_layer = gtkimage.getActiveLayer()
+    _objs = []
+    for _obj in gtkimage.getSelectedObjects():
+        if _obj.getParent() is _active_layer:
+            _objs.append(_obj)
+    move_objects(gtkimage, _objs, tool)
     return True
 
 def move_xy_first_button_press_cb(gtkimage, widget, event, tool):

-- 
Man once surrendering his reason, has no remaining guard against absurdities
the most monstrous, and like a ship without rudder, is the sport of every wind.

-Thomas Jefferson to James Smith, 1822


More information about the PythonCAD mailing list