[PythonCAD] Patches to highlight selected objects

Stuart Brorson sdb at cloud9.net
Sat Oct 22 17:06:10 CEST 2005

Hi PythonCADsters --
I have made some mods to PythonCAD in order to implement highlighting
after selection.  That is, my mods change PythonCAD's behavior so that
when you select a graphic object, it turns white.  This sees to be the
desired behavior for selection.  I have submitted the patches to Art
in a separate e-mail.  The diff is against the the latest svn version
(updated yesterday -- Friday, Oct 21st, 2005).
Please read about the detailed mods and some other discussion points
Code modifications made:
*  Changed image.selectObject and image.deselectObject to change
object's color upon selection/deselection.  Specifically, upon
selection the object turns white.
*  Connected GTKImage to the "color_changed" signal.  When it receives
the "color_changed" signal, it invokes self.redraw().
*  Added getColor and setColor methods to point class.  These methods
are just dummy methods.  Note:  this is a hack.  I needed to do this
so that I'd get no exception in selectObject/deselectObject when
trying to set the color of a point. More discussion below.
*  Modified gtkimage.reset() so that it would invoke deselect.Object
the *second* time the user hits <escape>.  (The first time you hit
<escape> reset just clears the tool.)
*  Changed default color for segments and circles to yellow (it was
white).  This way, when you select an object, it turns white and you
can see that it is selected.  Note that this is currently a hack -- I
just hardcoded the colors into a __default_color variable in each
file.  Perhaps there is a global config file where this can go?
*  Changed the local variable "gtkimage" to "_gtkimage" in gtkmenu.py.
I did this while tracking a different bug.  I thought that the usage
of gtkimage as both a file qualifier ("gtkimage.fooMethod()") and as a
local variable ("def fooMethod(self, gtkimage)") was causing a
problem.  I was wrong, but changing this was so much hassle that I
left my change standing.  My change doesn't hurt anything.
*  Added more debug printing calls.  This helps me figure out what is
going on when PythonCAD is running.
*  My method to set the color upon selection/deselection is a hack.
This needs to be fixed. I propose that all graphic objects have an
attribute __default_color.  This can be set in GraphicObject, and
overridden in the individual classes.  Then, when you select an
object, it can go white ("obj.setColor(0xffffff)").  When you deselect
an object, it can revert to its normal default color by
*  Sending the signal "color_changed" has the problem that it invokes
the graphicObjectLog class to store the last color.  When doing a highlight,
it makes no sense to store the last color.  Therefore, I propose to
create a different message "highlighted" which will not cause the
graphicObjectLog class to wake up.
*  One issue with the current architecture is that the point class
inherits from Subpart, not from Graphic object.  The issue is that the
color attribute is set in GraphicObject, so a point doesn't have a
color, and doesn't have color methods.  I overcame this by
implementing dummy color methods in the point class, but this is a
   Is there a reason that point can't inherit from GraphicObject?  And
what distinction is made between GraphicObject and Subpart and Entity?
*  After doing this I noticed that "Edit -> Select" doesn't do
anything.  That is, when you try to move an object, you do "Modify ->
Move -> Horizontal", and you thereafter need to select the objects to
move.  What is the point behind "Edit -> Select" anyway?  Does it do
   I propose that any "Modify" actions should use the selected parts,
instead of requiring the user to re-select the parts to modify.
Comments on the above?

More information about the PythonCAD mailing list