Activating and Disabling button after process in python and pyGTK
Question: Essentially, I am trying to make a button "active" first, run a process, and
then after that process has finished running, disable the button again.

Using pyGTK and Python, the code in question looks like this...

    
    
    self.MEDIA_PLAYER_STOP_BUTTON.set_sensitive(True) #Set button to be "active"
    playProcess = Popen("aplay " + str(pathToWAV) + " >/dev/null 2>&1",shell=True) #Run Process
    playProcess.wait() #Wait for process to complete    
    self.MEDIA_PLAYER_STOP_BUTTON.set_sensitive(False) #After process is complete, disable the button again
    

However, this does not work at all.

Any help would be greatly appreciated.


Answer: All is working normally (python 2.7.3). But if you call playProcess.wait() in
gui thread - you freeze gui thread without redrawing (sorry, my english isn`t
very well). And are you sure that you try to use subprocess.popen()? Maybe
os.popen()?

My small test:

    
    
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    import pygtk, gtk, gtk.glade
    import subprocess
    
    def aplay_func(btn):
            btn.set_sensitive(True)
            print "init"
            playProcess = subprocess.Popen("aplay tara.wav>/dev/null 2>&1", shell=True)
            print "aaa"
            playProcess.wait()
            print "bbb"
            btn.set_sensitive(False)
    
    wTree = gtk.glade.XML("localize.glade")
    window = wTree.get_widget("window1")
    btn1 = wTree.get_widget("button1")
    window.connect("delete_event", lambda wid, we: gtk.main_quit())
    btn1.connect("clicked", aplay_func)
    window.show_all()
    gtk.main()
    

Result:

    
    
    init
    aaa
    bbb
    

And yes, button is working correctly. Sound too.

