Torsten Landschoff writes:
> Hi Johann,
Hi,
Thanks for replying.
> On Tue, Mar 21, 2000 at 01:22:23PM -0800, Johann Hibschman wrote:
>> Could anyone explain the structure of the event loop to me? Or at
>> least point me at the right documentation?
> The event loop is quite simple. Once you have created all the GUI objects
> you call the main loop. This loop will monitor all event sources and
> deliver them as signals to the target. Those signal functions run without
> intervention by the main loop. As soon as they return the main loop
> continues monitoring the event sources.
I was wondering more how the python interpreter handles multiple entry
points. That's not clear, so I'll try to give an example.
> Sorry, but I can't reconstruct what you are doing from this. I tried
> to write a program as you describe but I did not run into a problem.
> This is my code:
This is just about it. I wanted non-modal dialog boxes, so I changed
file_open_box() to file_open_box(modal=FALSE), and added a print so
you can see what is going on.
--------------------------------------------------
from gtk import *
from GtkExtra import *
def quit(obj):
mainquit()
def create_dialog(obj):
val = file_open_box(modal=FALSE)
print val
main = GtkWindow(WINDOW_TOPLEVEL)
menu = MenuFactory()
menu.add_entries([
("File/Open...", "<control>O", create_dialog),
("File/Quit", "<control>Q", quit)])
main.add_accel_group(menu.accelerator)
main.add(menu)
main.connect("destroy", mainquit)
main.show_all()
mainloop()
--------------------------------------------------
Choose open twice. Then select files in the two dialog boxes. If you
choose a file in the first dialog box, and then in the second, the
first returns None, while the second returns what the first should
have returned. If you answer the boxes in "stack order", second then
first, everything works fine.
>> Why doesn't the existance of the first dialog box tie up the python
>> interpreter, preventing the second box from being created? How does
> It does here...
That's because you're creating modal boxes. I'd like to do non-modal
boxes. It seems to let me (I still don't quite understand how), but I
can't make sense of the results I'm getting.
> Simple - in the file_open_box code a second incarnation of the mainloop
> is created which is running until the file selector is closed. A grab
> is used to prevent interaction with other windows during that time.
> When you click on OK or Cancel, mainquit is called and the inner mainloop
> is terminated returning control to the caller of file_open_box.
Hm. I think I'm getting there, in a very schematic way. The Gtk main
loop calls python, pushing stuff on the stack. Python creates the new
dialog box, then calls back to Gtk. If I do things normally, I answer
the dialog box, pop back up the stack to python, and pop back up to
gtk.
Here, after calling gtk the second time, I call python again, pushing
another python call on the stack, creating a new window. But then I
answer the old window, which tries to go back and find its place on
the python stack. But I pushed something new there, so it finds that
instead and gets confused.
Modified example:
--------------------------------------------------
from gtk import *
from GtkExtra import *
def quit(obj):
mainquit()
def create_dialog_1(obj):
val = file_open_box(modal=FALSE)
print "create_dialog_1:", val
def create_dialog_2(obj):
val = file_open_box(modal=FALSE)
print "create_dialog_2:", val
main = GtkWindow(WINDOW_TOPLEVEL)
menu = MenuFactory()
menu.add_entries([
("File/Open1...", "<control>O", create_dialog_1),
("File/Open2...", None, create_dialog_2),
("File/Quit", "<control>Q", quit)])
main.add_accel_group(menu.accelerator)
main.add(menu)
main.connect("destroy", mainquit)
main.show_all()
mainloop()
--------------------------------------------------
Yep. If I call Open1, then Open2, but answer the dialog from Open1
first, the return value goes to create_dialog_2. Boy, this is
confusing.
>> (By the way, this seems like something which could be done in a very
>> flashy way with a combination of Stackless Python and microthreads.
> Stackless Python? Microthreads? Sound like nice buzzwords to me (and
> nothing more).
I haven't played with the packages much myself, but they let you
implement continuations, which should get around this weirdness. You
simply package up a continuation and hand it off to the dialog box.
Then, whenever the dialog box is answered, the continuation lets the
interpreter pick up where it left off, rather than relying on the
stack. Microthreads, if I understand the package correctly, would let
you manage these intependet threads through the interpreter in a nice
way.
But that's idle dreaming. I just want to understand why pygtk behaves
the way it does first.
--
Johann Hibschman [EMAIL PROTECTED]
To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]