[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Python Frontend/GUI for C Program

byte8bits

1/11/2008 4:13:00 PM

I have a C program that works very well. However, being C it has no
GUI. Input and Output are stdin and stdout... works great from a
terminal. Just wondering, has anyone every written a Python GUI for an
existing C program? Any notes or documentation available?

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.

Thanks,
Brad
2 Answers

Diez B. Roggisch

1/11/2008 4:16:00 PM

0

byte8bits@gmail.com schrieb:
> I have a C program that works very well. However, being C it has no
> GUI. Input and Output are stdin and stdout... works great from a
> terminal. Just wondering, has anyone every written a Python GUI for an
> existing C program? Any notes or documentation available?
>
> 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.

Modules subprocess and pexpect (3rd-party-package) are your friends.
Alternatively, if you have the source for the C-app, exposing it's
functionality as DLL/SO and using ctypes as means to access it might
work as well.

Diez

Mike Meyer

1/11/2008 7:14:00 PM

0

On Fri, 11 Jan 2008 08:12:48 -0800 (PST) byte8bits@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@mired.org> http://www.mired.org/consu...
Independent Network/Unix/Perforce consultant, email for more information.