Hi all,
I need to run Python from a FOX app, and would like to implement a simple debug facility (like single stepping through the Python code and putting breakpoints). Python has a "pdb" class for just this sort of thing. pdb, however, is console-based but I don't want to bother my users with a command-line.
Python has the ability to invoke a callback function (in C or C++) for each line executed, and several other useful events. Unfortunately, it does not have an easy way of executing line-by-line directly under the caller's control. In other words, one must either return normally from the callback in order to process the next line, or throw an exception in the callback to halt the whole thing. There's no API that can simply be called to execute one (and only one) line.
The FOX question is this: could I invoke FXApp::runWhileEvents() within the Python trace callback? Considering that the main app loop is already running, is this recursive invocation OK? Reading the documentation, I don't see any reason why not, but it doesn't hurt to ask.
Here is a more detailed scenario: suppose there is a text widget that has the Python code, and buttons which say "run", "stop" and "pause". "run" starts interpreting the code, and "stop" should always cancel it, and "pause" is a temporary halt so local variables can be examined etc. In all cases, the rest of the application should be active (no wait cursors or modal dialogs!).
. The "run" button handler sets a run flag if pressed, and registers the following chore.
. The "stop" button handler clears the run and pause flags.
. The "pause" button handler sets a pause flag.
In the chore:
. if run flag is set, call PyRun...() which invokes the following callback for each line.
. clear the run flag (because script terminated)
In the Python trace callback:
. do {
. call FXApp::runWhileEvents()
. (In this recursive invocation of the event loop, the run and pause flags may be manipulated.)
. } while (pause flag)
. If the run flag is not set then we throw an exception, otherwise we just return.
I'm hoping this will work. Anyone see any problems?
Is it best to invoke the event loop from within a chore, or would a normal FOX "onCmd..." handler be OK?
Regards,
SJH
------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, &
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship.
http://p.sf.net/sfu/creativitycat-com
_______________________________________________
Foxgui-users mailing list
Foxgui-users@...
https://lists.sourceforge.net/lists/listinfo/foxgui-users