4

I made a simple PyGTK - Glade GUI for an application. I made the button, and the on_button_click calls a bash script. I would like to show a popup window while the bash script is running, and hide it after it is done. I made the window called runningWindow in Glade and wrote the following code:

def on_button1_clicked(self,widget):
   self.glade.get_object("runningWindow").show()
   os.system('bash run.sh')
   self.glade.get_object("runningWindow").hide()

This code shows nothing while run.sh is running. If I remove the hide() line, the window is displayed correctly, but only AFTER the run.sh process has finished.

The init function that starts the GUI:

def __init__(self):
        self.gladefile = "MyFile.glade" 
        self.glade = gtk.Builder()
        self.glade.add_from_file(self.gladefile)
        self.glade.connect_signals(self)
        self.glade.get_object("MainWindow").show_all()

How can I display the window before the os.system is called? Thank you for your help!

leeladam
  • 1,748
  • 10
  • 15

2 Answers2

1

You probably want to look into the subprocess module, and run your subprocess in a background task.

Michael
  • 776
  • 6
  • 13
0

I couldn't solve the problem, but I could get around it. Maybe others find it useful:

First, one should use subprocess.Popen() instead of subprocess.call(). It puts the subprocess automatically in background, so the running window is displayed. The problem was that if I didn't remove the .hide() command, the window immediately disappeared after popping up. Otherwise, I couldn't hide the window when the run was finished.

To solve this, I created the runningWindow in a new (runningWindow.glade and runningWindow.py) file.

Then I created a wrapper bash script that says:

python runningWindow.py &
pid=$!
bash run.sh
kill pid

And called this bash script with subprocess.Popen() from the main python script.

leeladam
  • 1,748
  • 10
  • 15