PyGTK ProgressBar在子进程启动前显示内容 [英] PyGTK ProgressBar to display something before subprocess starts
问题描述
当我点击之前的按钮时,我试图获得 gtk.ProgressBar.set_text('Text')
启动我的子流程
。
这是我的代码(全源代码 here ):
def on_button_clicked(self,button,progress_bar,filename):
/ pre>
self.execute(progress_bar,filename)
def execute(self,progress_bar,filename) :
progress_bar.set_text('Encoding')
progress_bar.pulse()
cmd = ['ffmpeg','-y',
'-i' ,文件名,
'-r','30',
'/tmp/test-encode.mkv']
process = sp.Popen(cmd,stdout = sp .PIPE,stderr = sp.PIPE)
process.wait()
progress_bar.set_text('Done')
我尝试移动
progress_bar.set_text('Encoding')
但是它并没有改变任何东西:我点击按钮,工作已经完成(该文件已正确生成并确定),只有在进度条上说完成。
我做了我的家庭作业,并阅读了所有相关问题,但他们不要使用 subprocess 或解析常规命令输出。
解决方案只需添加
progress_bar.set_text('Encoding')
while gtk.events_pending( ):#这会强制GTK刷新屏幕
gtk.main_iteration()
code> on_button_clicked()强制GTK在继续之前刷新屏幕。
您甚至可以添加
progress_bar.set_text('Finished')
I'm trying to get
而gtk.events_pending():#这将强制GTK刷新屏幕
gtk .main_iteration()
gtk.ProgressBar.set_text('Text')
to work when I click on a button, prior to launch mysubprocess
.Here is my code (full source here):
def on_button_clicked(self, button, progress_bar, filename): self.execute(progress_bar, filename) def execute(self, progress_bar, filename): progress_bar.set_text('Encoding') progress_bar.pulse() cmd = ['ffmpeg', '-y', '-i', filename, '-r', '30', '/tmp/test-encode.mkv'] process = sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.PIPE) process.wait() progress_bar.set_text('Done')
I tried moving
progress_bar.set_text('Encoding')
inon_button_clicked()
but it doesn't change anything: I click the button, the job is done (the file is duly produced and OK) and only then the progress bar says "Done".I did my homework and read all related questions, but they either don't use subprocess, or parse "regular" command outputs.
解决方案Just add
progress_bar.set_text('Encoding') while gtk.events_pending(): # this forces GTK to refresh the screen gtk.main_iteration()
in
on_button_clicked()
to force GTK to refresh the screen before continuing.You could even add
progress_bar.set_text('Finished') while gtk.events_pending(): # this forces GTK to refresh the screen gtk.main_iteration()
in
execute
once the file is written.这篇关于PyGTK ProgressBar在子进程启动前显示内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!