[PythonCAD] Execution path

Art Haas ahaas at airmail.net
Wed Sep 1 18:38:40 CEST 2004


On Thu, Sep 02, 2004 at 02:23:42AM +1000, Russell Shaw wrote:
> 
> Hi,
> I had a look thru more of the code, but can't see the forest thru
> the trees. I've made programs in python and gtk, and pygtk before.
> Is there a debugger that lets you single-step thru the python code?
> 

There is the python debugger module "pdb" that is part of the standard
Python distribution. It should do what you want. Check the Python web
site for info about using it.

> I'm trying to get an overall idea of how the app works in a high-level
> kind of way, such as how the app guides the user thru a series of steps
> when drawing a shape:
> 
> First i select:
> 
>   Draw|Basic|Rectangles
> 
>   Statusbar: Click in the drawing area or enter a point
> 
> Does this menu cause a new callback for mouse-clicks to be connected 
> somewhere? Which one?
 
The menu choice is handled in 'Interface/Gtk/gtkmenus.py', in this case
the function draw_rectangle_cb(). This function creates an instance of
the RectangleTool in 'Generic/tools.py', and sets things up so that this
tool will be the one used for adding the new entities in the drawing.
The tool is then modified to handle various events by the call to
gtkentities.rectangle_mode_init() in 'Interface/Gtk/gtkentities.py'.
It is in this function that the handlers for mouse and keyboard events
are set.

> I move the mouse to a second point. Which callback is doing the redrawing
> of the rectangle in response to mouse movement? Is this callback always
> connected, or is it specific to each object being drawn?
 
The callback for redrawing the rectangle is
rectangle_motion_notify_cb(), again in the 'gtkentities.py' file. The
callback handling the "motion_notify" signals is different for each
entity.

> I click a point:
> 
>   Statusbar: Enter the second point or click in the drawing area
> 
> Which function holds this series of steps (or context) that guides
> the user thru each action of drawing a rectangle?

Clicking the second point invokes the rectangle_second_button_press_cb()
function, yet again in 'gtkentities.py'.

> I click the second point and the rectangle is drawn.
 
Success! Adding the rectangle to the drawing is really just adding four
segments. Look at the create() method in the RectangleTool class in the
file 'Generic/Tools.py'.

> I have lots of ideas for lots of cad programs, but am wondering
> about what 'architecture' to use.

Hope this info helps. When I started on the program, I looked at a
number of drawing programs to try and figure out how they handled
interaction with the user. The Gimp was helpful, though it is quite a
task to find where in the code various events get set and unset, and how
the handler gets invoked.

Art Haas
-- 
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