我正在使用 growisofs 通过我的 Python 应用程序刻录 iso。我在两个不同的文件中有两个类;GUI() (main.py) 和 Boxblaze() (core.py)。GUI() 构建窗口并处理所有事件和内容,而 Boxblaze() 具有 GUI() 调用的所有方法。
现在,当用户选择了要刻录的设备和要刻录的文件时,我需要调用一个调用以下命令的方法:`
growisofs -use-the-force-luke=dao -use-the-force-luke=break:1913760 -dvd-compat -speed=2 -Z /burner/device=/full/path/to.iso
此命令应提供类似于以下内容的输出:
Executing 'builtin_dd if=/home/nevon/games/Xbox 360 isos/The Godfather 2/alls-tgod2.iso of=/dev/scd0 obs=32k seek=0'
/dev/scd0: "Current Write Speed" is 2.5x1352KBps.
#more of the lines below, indicating progress.
7798128640/7835492352 (99.5%) @3.8x, remaining 0:06 RBU 100.0% UBU 99.8%
7815495680/7835492352 (99.7%) @3.8x, remaining 0:03 RBU 59.7% UBU 99.8%
7832862720/7835492352 (100.0%) @3.8x, remaining 0:00 RBU 7.9% UBU 99.8%
builtin_dd: 3825936*2KB out @ average 3.9x1352KBps
/dev/burner: flushing cache
/dev/burner: closing track
/dev/burner: closing disc
此命令在 Boxblaze() 中名为 burn() 的方法中运行。它看起来很简单:
def burn(self, file, device):
subprocess.call(["growisofs", '-dry-run', "-use-the-force-luke=dao", "-use-the-force-luke=break:1913760", "-dvd-compat", "-speed=2", "-Z", device +'='+ file])
现在我的问题如下:
如何从输出中获取进度(括号中的百分比)并将进度条设置为“跟随”该进度?我的进度条在 GUI() 类中调用,如下所示:
获取 = builder.get_object
self.progress_window = get("progressWindow")
self.progressbar = get("进度条")
我是否必须在单独的线程中运行此命令才能使 GUI 保持响应(以便我可以更新进度条并允许用户根据需要取消刻录)?如果是这样,我该怎么做并且仍然能够将进度传递到进度条?
如果您有兴趣,可以在 Launchpad 上找到完整的代码。如果您安装了集市,只需运行:
bzr branch lp:boxblaze
哦,如果你想知道,这个应用程序只适用于 Linux - 所以不要担心跨平台兼容性。