Pygtk, libglade

V

Vams

Hi everyone,
I got a little problem that I hope someone can help me out w/ or
atleast point me in the right direction.

Situation:
- I have a python program that continuously runs and does some tasks
automatically on a daily basis.
- Now, I want to create a gtk frontend that displays its status and
provides an exit button so I don't need to keep sending the daemon a
kill signal.

What I wanted to do:
- make a class that creates the GUI using libglade and pygtk.
- create the GUI using the outside class and make a function within my
main program that continuously updates the GUI instance when called on.

Problem:
---------- gtk.main() -------------
The GUI won't show up w/o calling this function. And if I do call this
function, the control of my program will stay in the mainloop until it
exists (GUI closes). This stops the daemon from doing what it normally
does.

So, what do I need to do? Should I have the gtk.main() in its own
thread or something? Or can I somehow extend the gtk.main() so that it
does my program's tasks while keeping an eye on the GUI?

Any help would be appreciated.

Thank you,
Vams
 
F

Fredrik Arnerup

Vams said:
Problem:
---------- gtk.main() -------------
The GUI won't show up w/o calling this function. And if I do call
this function, the control of my program will stay in the mainloop
until it exists (GUI closes). This stops the daemon from doing what
it normally does.

So, what do I need to do? Should I have the gtk.main() in its own
thread or something? Or can I somehow extend the gtk.main() so that
it does my program's tasks while keeping an eye on the GUI?

I don't know if running mainloop in separate thread is a good idea. I
suggest running your main program in a separate thread.
(See the faq on threading:
http://www.async.com.br/faq/pygtk/index.py?req=index)

An alternative is to use gtk.timeout_add() to call the main program at
regular intervals.
 
G

Graham Ashton

Problem:
---------- gtk.main() -------------
The GUI won't show up w/o calling this function. And if I do call this
function, the control of my program will stay in the mainloop until it
exists (GUI closes). This stops the daemon from doing what it normally
does.

So, what do I need to do? Should I have the gtk.main() in its own
thread or something? Or can I somehow extend the gtk.main() so that it
does my program's tasks while keeping an eye on the GUI?

You could split it into two programs; the daemon and the GUI. Then use
gtk.timeout_add() to specify a call back function that the GUI can run to
query the status of the daemon.

It'd certainly be cleaner than threads. An alternative would be to use
some file based IPC between the GUI and the daemon and use
gtk.input_add() to get GTK to monitor the file handle for changes and run
a function whenever it becomes readable.
Any help would be appreciated.

Don't go near threads unless the above two approaches don't do what you
want!

-- Graham
 

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

Forum statistics

Threads
473,780
Messages
2,569,609
Members
45,253
Latest member
BlytheFant

Latest Threads

Top