Python popup while bash script works

I made a simple PyGTK - Glade GUI for the application. I made a button, and on_button_click calls a bash script. I would like to show a popup while the bash script is running, and hide it after it completes. I made a window called runWindow 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 delete the hide () line, the window will display correctly, but only AFTER the run.sh process is complete.

The init function that launches the graphical user interface:

 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 a window before calling os.system? Thanks for the help!

+4
source share
2 answers

You probably want to learn the subprocess module and start the subprocess in the background job.

+1
source

I could not solve the problem, but I could get around it. Others may find this useful:

First you need to use subprocess.Popen () instead of subprocess.call (). It automatically places the subprocess in the background so that the current window is displayed. The problem was that if I did not delete the .hide () command, the window immediately disappeared after the ascent. Otherwise, I could not hide the window when the launch was completed.

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

Then I created a bash script wrapper that states:

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

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

0
source

Source: https://habr.com/ru/post/1444780/


All Articles