Python Frontend/GUI for C Program

B

byte8bits

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
 
D

Diez B. Roggisch

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
 
M

Mike Meyer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top