Launching wxPython apps with an iPython shell

Suppose you want to run your fancy wxPython application but have a shell in the background to peek and poke at certains settings, help debug, and possibly even use an API that your program provides to automate tasks. iPython has built in wx support (as well as support for other GUIs and frontends). So anyway, I’ve been playing around with this lately and have noticed an inconsistency that needs addressed.

Launching other GUIs with iPython does not block. You instantly get a shell and your application loads. The “-wthread” option for wx applications executes any passed in script before dropping to the shell though.

Problem:

> ipython -wthread myapp.py
> # application runs here
> # no shell yet
> # you exit the application
"Welcome to iPython"
>>> 

If you happened to do things like this, you’d get the expected response:

> ipython -wthread
"Welcome to iPython"
>>> import myapp
# application loads
# you instantly have a prompt
>>>

Solution:

Tell iPython to launch your app after it starts:

> ipython -wthread -c "import myapp" -i
# app loads
"Welcome to iPython"
# you've got a shell
>>>

Anyway, for other threading backends in iPython, the shell doesn’t block while the application loads. Perhaps there is a way to get the wx backend to behave the same. In the mean time, I’m using this workaround without any serious issue. Perhaps I’ll find a better solution or submit a patch to iPython one of these days.

Custom Derived Classes for wxPython XRC resources

First of all, this isn’t a topic that is bran new or which requires new documentation. I have learned a few quirks about the process for creating custom controls, panels, frames, and other elements with XRC files in wxPython and I thought I’d write up a little post.

Let me point you to the two most important resources. The wxPython wiki has pretty much all you need to now to get started. First is the TwoStageCreation process that the XRC implementation uses to create classes. The second is the UsingXmlResources page.
There is also the XRCTutorial. But you should be past that if you’re trying to create custom controls.

Here is a summary of the basic process. Continue reading “Custom Derived Classes for wxPython XRC resources”