[PythonCAD] Sample patch for selection highlighting

Stuart Brorson sdb at cloud9.net
Sat Nov 12 20:42:27 CET 2005


Art --

Please find my patch attached.  The diff was done against the version
in SVN.   The patch incorporates your changes as well as my change to
the gtkimage:reset fcn.  The purpose of the change is to implement my
preferred behavior for highlighting when you hit the <escape> key.
Try it out; maybe you'll like it too.

There's also some minor debug changes.  You can skip over them if you
like.  Diff file is small.

Stuart


Index: PythonCAD/Interface/Gtk/gtkimage.py
===================================================================
--- PythonCAD/Interface/Gtk/gtkimage.py (revision 2038)
+++ PythonCAD/Interface/Gtk/gtkimage.py (working copy)
@@ -53,7 +53,7 @@
 # Global variables
 #
  
-_debug = False ##  SDB debug stuff
+_debug = True ##  SDB debug stuff
 globals.gtkcolors = {}
 globals.gtklinetypes = {}
  
@@ -99,8 +99,8 @@
 #------------------------------------------------------------------
 def window_general_event(widget, event, gtkimage):
     _type = event.type
-    debug_print("window_general_event: Event type: %d" % _type)
-    debug_print("widget: " + `widget`)
+    # debug_print("window_general_event: Event type: %d" % _type)
+    # debug_print("widget: " + `widget`)
     if _type == gtk.gdk.BUTTON_PRESS:
         _button = event.button
         debug_print("BUTTON_PRESS: %d" % _button)
@@ -441,6 +441,11 @@
         self.__tolerance = 1e-10
  
         #
+
+        self.connect('selected_object', self._selectedObject)
+        self.connect('deselected_object', self._deselectedObject)
+
+        #
         # set the background color
         #
  
@@ -458,6 +463,41 @@
         self.__window.destroy()
  
     #------------------------------------------------------------------
+    def _selectedObject(self, img, *args):
+        _alen = len(args)
+        if _alen < 1:
+            raise ValueError, "Invalid argument count: %d" % _alen
+        _obj = args[0]
+        if _debug:
+            print("Selected object: " + `_obj`)
+        _parent = _obj.getParent()
+        if _parent.isVisible() and _obj.isVisible():
+            if _debug:
+                print "In _selectedObject . . . .calling obj.draw
..."
+            _obj.draw(self, self.getOption('BACKGROUND_COLOR'))
+            self.__da.queue_draw()
+            _color = Color('#ff7733')
+            _obj.draw(self, _color)
+            self.__da.queue_draw()
+
+
#------------------------------------------------------------------
+    def _deselectedObject(self, img, *args):
+        _alen = len(args)
+        if _alen < 1:
+            raise ValueError, "Invalid argument count: %d" % _alen
+        _obj = args[0]
+        if _debug:
+            print "Deselected object: " + `_obj`
+        _parent = _obj.getParent()
+        if _parent.isVisible() and _obj.isVisible():
+            if _debug:
+                print "In deselectedObject. . . . .calling obj.draw
..."
+            _obj.draw(self, self.getOption('BACKGROUND_COLOR'))
+            self.__da.queue_draw()
+            # _obj.draw(self)
+            # self.__da.queue_draw()
+
+
#------------------------------------------------------------------
     def getAccel(self):
         """Return the gtk.AccelGroup in the GTKImage.
  
@@ -1007,6 +1047,8 @@
  
 redraw()
         """
+        if _debug:
+            print ("Entered redraw")
         _da = self.__da
         if (_da.flags() & gtk.MAPPED):
             _xmin = self.__xmin
@@ -1060,8 +1102,21 @@
  
 reset()
         """
+        # If __tool is none, deselect any selected objects in view.
+        # This way, if you are currently using a tool, then the
+        # first time you hit escape, you just clear the tool.
+        # The second time clears all selections.
+        debug_print("Entered reset")
+        if self.__tool is None:
+            debug_print(".....This is second time to be in reset")
+            self.redraw()
+            _objs = self.getSelectedObjects()
+            if len(_objs):
+                for [_layer, _obj] in _objs:
+                    _obj.sendMessage('deselected_object', _obj)
+
+
         self.__tool = None
-        self.redraw()
         self.setPrompt("Enter command")
  
 #------------------------------------------------------------------


More information about the PythonCAD mailing list