Python Frontend/GUI for C Program

Mike Meyer mwm at mired.org
Fri Jan 11 14:13:54 EST 2008


On Fri, 11 Jan 2008 08:12:48 -0800 (PST) byte8bits at gmail.com wrote:
> I have a C program that works very well. However, being C it has no
> GUI.

What does C have to do with it not having a GUI? I've written more C
programs with a GUI than Python ones - and the C experience was
generally better. Of course, I was using Intuition, not X.

> I have experience using wxPython from within Python apps and I like it
> a lot for its cross-platform capabilities. I was hoping to use
> wxPython for this as well.

Sure, the GUI can be disconnected from the application. In fact,
that's the right way to do it - it allows you to change the GUI as
times move forward.

I've done this in three different ways. Diez pegged them two of them.

When the underlying C code is poorly organized, use subprocess to run
the the C application, build what you're going to send to it's
standard in, and watch what it writes to standard output.

If the C code is well-organized - structures with routines that
manipulate them, so you can identify objects - and command handling on
standard in is basically "parse the arguments, then invoke the the
right function with those values", then you can wrap the structures as
object - with the appropriate functions as methods, and use it in two
ways. One is to expose things via a shared library, and the use ctypes
to talk to it. The other is to embed a python into your application,
and have it launch the script that's going to provide the GUI.

    <mike
-- 
Mike Meyer <mwm at mired.org>		http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.



More information about the Python-list mailing list