944,127 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 2578
  • Python RSS
May 3rd, 2006
0

pygtk Glade GUI freezes

Expand Post »
Hello!! I'm really new to python and pygtk and Glade, I'm sorry I'm still on the dark side using Windows 2000 :-(
What I'm trying to do is a simple Testing Program Simulator, that means that I will press a button and then I'm supposed to show a cross or a checkmark after simulating a test. Actually there are 4 tests.

So what I tried to do is to use a thread to run some for loops and time.sleep(1) for some seconds inside each for loop.

Then a textbox changes and an image appears.

The problem is that the program SOMETIMES works as it should, but some other times the GUI freezes and the images don't get loaded.

Sometimes the program seems to keep on running while the GUI freezes, some other times the program execution seems to freeze and the GUI freezes. Sometimes if I press ctrl + C in the console the program seems to go out of some hidden loop and then the GUI unfreezes.

I'm really frustrated, I already read like 5 examples for using threads and I can't find my mistake. Could somebody help me please???

Here's my code:

Python Syntax (Toggle Plain Text)
  1.  
  2. import pygtk
  3. import gtk
  4. import gtk.glade
  5. import time
  6. import threading
  7.  
  8. bandera1 = 0
  9.  
  10. class Sequence(threading.Thread):#subclass Thread
  11. def __init__(self):#make it possible to pass the time in seconds that we want the timer to run
  12.  
  13. threading.Thread.__init__(self)#call the Thread's constructor
  14.  
  15. def run(self):#define what we want our Timer thread to do
  16.  
  17. for i in range(0,4):
  18. time.sleep(1)#time.sleep(self.runTime)#have it sleep for runTime seconds
  19. print '0'
  20.  
  21. GUI.TarjetaProbada.set_from_file('C:\Documents and
  22.  
  23. Settings\practicantes\Escritorio\PracticasPython\GUIs\GUISimple\pixmaps\CPU.JPG')
  24. GUI.TextoPrueba1.set_markup('<big><big><big>Prueba de voltajes del Microcontrolador</big></big></big>')
  25.  
  26. for i in range(0,4):
  27. time.sleep(1)
  28. GUI.ImagenPrueba1.set_from_file('C:\Documents and
  29.  
  30. Settings\practicantes\Escritorio\PracticasPython\GUIs\GUISimple\pixmaps\check mark_Green.bmp')
  31. print '1'
  32.  
  33. GUI.TextoPrueba2.set_markup('<big><big><big>Prueba de voltajes del Regulador</big></big></big>')
  34. for i in range(0,4):
  35. time.sleep(1)
  36. GUI.ImagenPrueba2.set_from_file('C:\Documents and
  37.  
  38. Settings\practicantes\Escritorio\PracticasPython\GUIs\GUISimple\pixmaps\check mark_Green.bmp')
  39. print '2'
  40.  
  41. GUI.TextoPrueba3.set_markup('<big><big><big>Prueba de Polaridad en Diodo</big></big></big>')
  42. for i in range(0,4):
  43. time.sleep(1)
  44. GUI.ImagenPrueba3.set_from_file('C:\Documents and
  45.  
  46. Settings\practicantes\Escritorio\PracticasPython\GUIs\GUISimple\pixmaps\cross mark_RED.bmp')
  47. print '3'
  48.  
  49.  
  50. GUI.TextoPrueba4.set_markup('<big><big><big>Prueba de funcionamiento del IrDA</big></big></big>')
  51. for i in range(0,4):
  52. time.sleep(1)
  53. GUI.ImagenPrueba4.set_from_file('C:\Documents and
  54.  
  55. Settings\practicantes\Escritorio\PracticasPython\GUIs\GUISimple\pixmaps\check mark_Green.bmp')
  56. print '4'
  57.  
  58.  
  59. def botonazo(self):
  60.  
  61. GUI.ExplicacionPrueba.set_markup('<big><big><big><big><big><big>Iniciando Prueba del
  62.  
  63. CPU</big></big></big></big></big></big>')
  64.  
  65. for i in range(0,4):
  66.  
  67. t = Sequence()
  68.  
  69. global bandera1
  70. print 'bandera1 = ' + str(bandera1)
  71. #t.run()
  72. t.start()
  73. #t.join()
  74.  
  75.  
  76.  
  77.  
  78. class GUIPruebasAutomatizadas:
  79. def __init__(self):
  80.  
  81. self.GUI = gtk.glade.XML('guiejecucionpruebas.glade')
  82. self.VentanaPrincipal = self.GUI.get_widget('VentanaGUIPruebasAutomatizadas')
  83.  
  84.  
  85. self.vbox5 = self.GUI.get_widget('vbox5')
  86.  
  87. self.TarjetaProbada = self.GUI.get_widget('ImagenProbando')
  88.  
  89. self.Boton = self.GUI.get_widget('BotonIniciarPrueba') #this is a button widget in the glade GUI
  90. self.Boton.connect('clicked',botonazo)
  91.  
  92. self.ExplicacionPrueba = self.GUI.get_widget('ExplicacionPrueba')
  93. #self.ExplicacionPrueba.connect()
  94.  
  95. self.TextoPrueba1 = self.GUI.get_widget('TextoPrueba1') #This are all textboxes widgets in the glade GUI
  96. self.TextoPrueba2 = self.GUI.get_widget('TextoPrueba2')
  97. self.TextoPrueba3 = self.GUI.get_widget('TextoPrueba3')
  98. self.TextoPrueba4 = self.GUI.get_widget('TextoPrueba4')
  99.  
  100. self.ImagenPrueba1 = self.GUI.get_widget('ImagenPrueba1') #this are Images widgets in the glade GUI
  101. self.ImagenPrueba2 = self.GUI.get_widget('ImagenPrueba2')
  102. self.ImagenPrueba3 = self.GUI.get_widget('ImagenPrueba3')
  103. self.ImagenPrueba4 = self.GUI.get_widget('ImagenPrueba4')
  104.  
  105.  
  106. gtk.gdk.threads_init()
  107.  
  108.  
  109. GUI=GUIPruebasAutomatizadas()
  110.  
  111. print 'contando!!!!'
  112.  
  113. gtk.threads_enter()
  114. gtk.main()
  115. gtk.threads_leave()
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JoeM is offline Offline
2 posts
since May 2006
May 3rd, 2006
0

Re: pygtk Glade GUI freezes

My experience with pyGTK, I can not get it to work with Windows XP. The Linux folks have no problems. Before you go completely nuts with an unstable product, I would recommend switching to the wxPython GUI.

Just my opinion!
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Testing DCOM APIs using Python
Next Thread in Python Forum Timeline: Problems downloading Python





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC