[Python-de] GTK + Threads
Fritz Cizmarov
fritz at sol.at
Fre Nov 5 15:06:50 CET 2004
Ich zeig dir mal wie ich das in meinem aktuellen Projekt (Gtkfrontend fü
r povray) gelöst habe.
----------------------------------------------------------------------
def do_render(self, *args):
statusbar = self.glade.get_widget("statusbar")
if not self.options.fname:
tf = os.tmpfile()
self.options.store(tf)
tf.close()
os.chdir(os.path.dirname(self.options.fname))
try:
os.unlink("/tmp/.povrayoutput")
except:
pass
pipe = os.mkfifo("/tmp/.povrayoutput")
pid = os.spawnlp(os.P_NOWAIT, "nice", "nice", "-n10", "povray",
self.options.fname, "-GA/tmp/.povrayoutput")
pipe = open("/tmp/.povrayoutput","rU")
while True:
line = pipe.readline()
if line.strip().startswith("Total Time:"):
break
if line.strip():
self.write_status(line.rstrip("\n\r"))
if "Rendering line" in line:
tmp = line.split()
percent = float(tmp[3])/float(tmp[5])
statusbar.set_progress_percentage(percent)
while gtk.events_pending():
gtk.main_iteration_do(False)
statusbar.set_progress_percentage(0.0)
self.write_status(line.strip(" \n\r\t"))
pipe.close()
---------------------------------------------------------------------
Du siehst, ich hab die Schleife mit gtk.events_pending() und
gtk.main_iteration_do(False) Innerhalb der Schleife wo ich die laufende
Ausgabe von povray in die Statuszeile ausgebe.
Gruß
Fritz
On Fri, 5 Nov 2004 13:20:41 +0100 (CET)
Dmitrij Repp <stiner_rd at yahoo.de> wrote:
> Weiss nicht. Ich versuche das heute die ganze Zeit
> hinzukriegen, aber das funktioniert nicht. Immer, wenn
> ich im draw_my_self gtk.events_pending() mache, wird
> Oberfläche nicht mehr erneut. Sogar, wenn das so
> aussieht:
> def draw_my_self(self):
> print gtk.events_pending()
> return 1
>
> Ein mahl bekomme ich 1 im Konsole und Programm stürzt
> ab.