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:

import pygtk
import gtk
import gtk.glade
import time
import threading

bandera1 = 0
 
class Sequence(threading.Thread):#subclass Thread
	def __init__(self):#make it possible to pass the time in seconds that we want the timer to run
		
		threading.Thread.__init__(self)#call the Thread's constructor
		
	def run(self):#define what we want our Timer thread to do
		
		for i in range(0,4):
			time.sleep(1)#time.sleep(self.runTime)#have it sleep for runTime seconds
		print '0'

		GUI.TarjetaProbada.set_from_file('C:\Documents and 

Settings\practicantes\Escritorio\PracticasPython\GUIs\GUISimple\pixmaps\CPU.JPG')
		GUI.TextoPrueba1.set_markup('<big><big><big>Prueba de voltajes del Microcontrolador</big></big></big>')
		
		for i in range(0,4):
			time.sleep(1)
		GUI.ImagenPrueba1.set_from_file('C:\Documents and 

Settings\practicantes\Escritorio\PracticasPython\GUIs\GUISimple\pixmaps\check mark_Green.bmp')
		print '1'
		
		GUI.TextoPrueba2.set_markup('<big><big><big>Prueba de voltajes del Regulador</big></big></big>')
		for i in range(0,4):
			time.sleep(1)
		GUI.ImagenPrueba2.set_from_file('C:\Documents and 

Settings\practicantes\Escritorio\PracticasPython\GUIs\GUISimple\pixmaps\check mark_Green.bmp')
		print '2'
		
		GUI.TextoPrueba3.set_markup('<big><big><big>Prueba de Polaridad en Diodo</big></big></big>')
		for i in range(0,4):
			time.sleep(1)
		GUI.ImagenPrueba3.set_from_file('C:\Documents and 

Settings\practicantes\Escritorio\PracticasPython\GUIs\GUISimple\pixmaps\cross mark_RED.bmp')
		print '3'
		
		
		GUI.TextoPrueba4.set_markup('<big><big><big>Prueba de funcionamiento del IrDA</big></big></big>')
		for i in range(0,4):
			time.sleep(1)
		GUI.ImagenPrueba4.set_from_file('C:\Documents and 

Settings\practicantes\Escritorio\PracticasPython\GUIs\GUISimple\pixmaps\check mark_Green.bmp')
		print '4'

		
def botonazo(self):

	GUI.ExplicacionPrueba.set_markup('<big><big><big><big><big><big>Iniciando Prueba del 

CPU</big></big></big></big></big></big>')
	
	for i in range(0,4):
	
		t = Sequence()
		
		global bandera1
		print 'bandera1 = ' + str(bandera1)
		#t.run()
		t.start()
		#t.join()
	



class GUIPruebasAutomatizadas:
	def __init__(self):
		
		self.GUI = gtk.glade.XML('guiejecucionpruebas.glade')
		self.VentanaPrincipal = self.GUI.get_widget('VentanaGUIPruebasAutomatizadas')
		
		
		self.vbox5 = self.GUI.get_widget('vbox5')
		
		self.TarjetaProbada = self.GUI.get_widget('ImagenProbando')
	
		self.Boton = self.GUI.get_widget('BotonIniciarPrueba') #this is a button widget in the glade GUI
		self.Boton.connect('clicked',botonazo)
		
		self.ExplicacionPrueba = self.GUI.get_widget('ExplicacionPrueba')
		#self.ExplicacionPrueba.connect()
		
		self.TextoPrueba1 = self.GUI.get_widget('TextoPrueba1') #This are all textboxes widgets in the glade GUI
		self.TextoPrueba2 = self.GUI.get_widget('TextoPrueba2')
		self.TextoPrueba3 = self.GUI.get_widget('TextoPrueba3')
		self.TextoPrueba4 = self.GUI.get_widget('TextoPrueba4')
		
		self.ImagenPrueba1 = self.GUI.get_widget('ImagenPrueba1') #this are Images widgets in the glade GUI
		self.ImagenPrueba2 = self.GUI.get_widget('ImagenPrueba2')
		self.ImagenPrueba3 = self.GUI.get_widget('ImagenPrueba3')
		self.ImagenPrueba4 = self.GUI.get_widget('ImagenPrueba4')
		

gtk.gdk.threads_init()


GUI=GUIPruebasAutomatizadas()

print 'contando!!!!'

gtk.threads_enter()
gtk.main()
gtk.threads_leave()

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.