This is my first post and I am relatively new to python and wxpython and I use wxdesigner as well. I added the cool Widget Inspection Tool (WIT) to an admin menu to help with sizer/widget issues and that has really helped. Having used the python shell to test various python commands and behavior, I thought it would be very helpful to use pywrap to work with my actual python/wxpython application.
The first issue I ran into was that pywrap does not call my main(), which calls init_main() for most of the non-wx program initialization, but rather goes straight to my Main_App(wx.App) class. The second was that getopt was not processing my command line arguments (pywrap test2.py --verbose --fullxml). I saw that sys.argv was not adjusted by pywrap so sys.argv[1] was the module name, test2.py in this case, and that, of course, was considered a non-option. Not being sure the best way for my app to know it was being run by pywrap, I resolved those 2 issues in the Main_App(wx.App) class’s OnInit() method by testing sys.argv[0] for “pywrap”. If so, the app changes the options argument list from the standard sys.argv[1:] to sys.argv[2:] and then calls the init_main() that would normally have been called from main(). Then it proceeds to the rest of the initialization and creates the frame via Main_Frame(wx.Frame) class.
class Main_App(wx.App):
“”“Create wxWindow main app”""
def OnInit(self):
global appsys
global opt_pywrap
wx.InitAllImageHandlers()
···
#=======================================================================
# pywrap does not run the main code which calls init_main()
#=======================================================================
if __name__ != '__main__':
try:
dummy = AppSys.initialized
del(dummy)
except (NameError, AttributeError), dummy_err:
if sys.argv[0].endswith("pywrap"):
opt_pywrap = True
options = sys.argv[2:]
else:
options = sys.argv[1:]
if not init_main(options=options):
print "init_main() failed."
return False
. . .
I have not been able to figure out this next problem. I know that in the pycrust shell, app is the wx.App of my application so I can get to its instance variables, but how do I get to the rest of the test2.py module from the pycrust shell’s prompt? In order to interactively test different aspects of the actual application, I need to create new class instances, as well as access current global variables, class variables, class instances, etc. - interact with the actual running application. I tried typing in from test2 import * and that gives me access to the global variable and class names, but not the same objects as the application is using. The global and class variables that were updated in the application have the default values when referring to them from the shell after the import.
The wxPython Py documentation says that “PyWrap is a runtime utility that lets you run an existing wxPython
program with a PyCrust frame at the same time. Inside the PyCrust
shell namespace, the local variable app
is assigned to your
application instance. In this way you can introspect your entire
application within the PyCrust shell, as well as the PyFilling
namespace viewer.”. So how do I get to the “entire application” - I guess somehow the globals() of the test2.py being run by pywrap?
Thank you.