Difference between revisions of "Python"

From ThorstensHome
Jump to: navigation, search
(Created page with "= python gtk and threads = <pre> # testcase to show that closing does not work import serial, gobject, time, sys, glob, os, gtk from threading import Thread gobject.threads_i...")
 
 
Line 2: Line 2:
 
<pre>
 
<pre>
 
# testcase to show that closing does not work
 
# testcase to show that closing does not work
import serial, gobject, time, sys, glob, os, gtk
+
import gobject, gtk
 
from threading import Thread
 
from threading import Thread
  
Line 9: Line 9:
  
  
def blinker(self):
+
def blinker():
 
   while program_running:
 
   while program_running:
 
     print program_running
 
     print program_running
Line 22: Line 22:
 
     self.window.connect("delete_event", self.ev_close)
 
     self.window.connect("delete_event", self.ev_close)
 
     self.window.show()
 
     self.window.show()
     t=Thread(target=blinker, args=(1,))
+
     t=Thread(target=blinker)
 
     t.start()
 
     t.start()
  
Line 31: Line 31:
 
app.main()
 
app.main()
 
</pre>
 
</pre>
 +
quit() does not return here because a thread is still running

Latest revision as of 18:04, 1 December 2012

python gtk and threads

# testcase to show that closing does not work
import gobject, gtk
from threading import Thread

gobject.threads_init()
program_running=42


def blinker():
  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)
    t.start()

  def main(self):
    gtk.main()

app=counter()
app.main()

quit() does not return here because a thread is still running