Python

From ThorstensHome
Revision as of 17:57, 1 December 2012 by WikiSysop (Talk)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

python gtk and threads

# testcase to show that closing does not work
import serial, gobject, time, sys, glob, os, gtk
from threading import Thread

gobject.threads_init()
program_running=42


def blinker(self):
  while program_running:
    print program_running
class counter:
  def ev_close(self, widget, event, data=None):
    print "ev_close"
    program_running=False
    quit()
    print "end ev_close"
  def __init__(self):
    self.window=gtk.Window(gtk.WINDOW_TOPLEVEL)
    self.window.connect("delete_event", self.ev_close)
    self.window.show()
    t=Thread(target=blinker, args=(1,))
    t.start()

  def main(self):
    gtk.main()

app=counter()
app.main()