Hi everybody
I am building a GUI for a scaling application that every
few milliseconds outputs four or five lines of status information
on how each Client is proceeding etc.etc.
I've got the layout, buttons, menus etc. all laid out as I
wish. My only problem is how to periodically have the
app. write to the console window (a GtkText and GtkScrollbar
in a GtkVbox).
In trying to figure this out (I am a GUI novice) I came up with
simple little app below. All it wants to do is write to a console
periodically and see what it writes appear correctly..However
I have had mixed and somewhat bewildring results (I shudder
to think of having to deal with this in C++ and the burden of
increased complexity and endless recompilations)
Basically it forks a child process that tries to write to the
console while the parent spins on GTK mainloop() or something
close to it....Here's what happened for various parent/child
scenarios (the complete app appears at the end of my mail)
(1)
pid = os.fork()
if pid != 0:
mainloop()
else:
for ndx in range(1,100):
text.insert (title,text.fg,text.bg,' Starting subscriber
'+str(ndx)+'\n' )
os._exit(0)
Messages from only the first two subscribers appear. The window
won't go away, the destroy() handler is not being called?
(2)
pid = os.fork()
if pid != 0:
while(1):
win.show_all()
else:
for ndx in range(1,100):
text.insert (title,text.fg,text.bg,' Starting subscriber
'+str(ndx)+'\n' )
os._exit(0)
I get the desired result!! All subscriber messages appear...*but* I can't
kill the
app, destroy the window etc.etc. no events being handled obivously....
====================== The complete Application in one of it's
guises....====================
if __name__ == '__main__':
#!/usr/bin/env python
from gtk import *
import os,time
def destroy(*args):
win.hide()
mainquit()
os._exit(0)
win = GtkWindow(WINDOW_TOPLEVEL,'Simple Text Console')
win.connect("destroy",destroy)
text = GtkText()
text.set_editable(FALSE)
text.set_word_wrap(TRUE)
text.set_usize(200, 200)
text.style = text.get_style()
text.fg = text.style.fg[STATE_NORMAL]
text.bg = text.style.white
title = load_font("-*-helvetica-bold-r-normal-*-*-100-*-*-*-*-*-*")
text.show()
text.insert (title,text.fg,text.bg,'Client 1\nClient 2\nClient 3\nClient
4\n')
win.add(text)
win.show_all()
pid = os.fork()
if pid != 0:
while(1):
# Too slow below, without the sleep(1) its all a mess!!!
#while events_pending():
# mainiteration(block=FALSE)
win.show_all()
else:
for ndx in range(1,100):
#time.sleep(1)
text.insert (title,text.fg,text.bg,' Starting subscriber
'+str(ndx)+'\n' )
os._exit(0)
print 'Main process exiting...'
----------------------------------------------------------------------
Martin Dunford
Unisphere Networks Office (978) 589 0786
10 Technology Park Cell (617) 697 5380
Westford
MA 01886 [EMAIL PROTECTED]
-----------------------------------------------------------------------
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk