Pygtk, libglade

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vams

    Pygtk, libglade

    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
  • Fredrik Arnerup

    #2
    Re: Pygtk, libglade

    Vams <gte181u@prism. gatech.edu> writes:
    [color=blue]
    >
    > 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?[/color]

    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.

    --
    Fredrik Arnerup <e97_far@e.kth. se>

    Comment

    • Graham Ashton

      #3
      Re: Pygtk, libglade

      On Tue, 09 Dec 2003 19:09:38 -0500, Vams wrote:
      [color=blue]
      > 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?[/color]

      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.
      [color=blue]
      > Any help would be appreciated.[/color]

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

      -- Graham

      Comment

      Working...