X-Git-Url: https://harishankar.org/repos/?p=biagen.git;a=blobdiff_plain;f=progress_window.py;fp=progress_window.py;h=102b22205bd6d2440c74f5219ea74b3372feebcf;hp=0000000000000000000000000000000000000000;hb=12a84b1fe5750d8d967d19bb6067db04e87d2d1f;hpb=c18ee3d29cb7ed5bf70c97a65f6d5823744af0dd diff --git a/progress_window.py b/progress_window.py new file mode 100644 index 0000000..102b222 --- /dev/null +++ b/progress_window.py @@ -0,0 +1,81 @@ +# BiaGen - front end to genisoimage +# Copyright 2010 V.Harishankar +# Licensed under the GNU GPL v3 or above + +# window to run the executable + +import pygtk +pygtk.require ("2.0") +import gtk, gobject +import threading +import os, sys, subprocess, signal + +class BiaGenProgress: + + class burningprocess (threading.Thread): + def update_ui (self, data): + lines = data.split ("\n") + lastline = lines[len (lines) - 1] + words = lastline.split ("%") + pbar = self.parent.ui.get_object ("progress") + try: + perc = float (words[0].strip ()) / 100.0 + if perc >= 0 and perc <= 1: + pbar.set_fraction (perc) + else: + pbar.pulse () + except: + pass + + textview = self.parent.ui.get_object ("progressmessages") + textbuf = textview.get_buffer () + textbuf.set_text (data) + endmark = textbuf.get_insert () + textview.scroll_to_mark (endmark, 0.0) + + def run (self): + proc = subprocess.Popen (self.parent.command, stdout=subprocess.PIPE, + stdin=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1) + + data = "" + try: + ch = proc.stdout.read (1) + except: + pass + + while (ch): + data += ch + gobject.idle_add (self.update_ui, data) + try: + ch = proc.stdout.read (1) + except: + continue + + proc.wait () + data += "\ngenisoimage has completed. You can close this window now." + #gobject.idle_add (self.update_ui, data) + self.parent.ui.get_object ("progressmessages").get_buffer ().set_text (data) + self.parent.ui.get_object ("btnclose").set_sensitive (True) + self.parent.ui.get_object ("progress").set_fraction (1.0) + + def __init__ (self, parent): + super (BiaGenProgress.burningprocess, self).__init__ () + self.parent = parent + self.command = self.parent.command + + def on_btnclose_clicked (self, *args): + self.ui.get_object ("progress_window").destroy () + + def __init__ (self, parent_ui, command_args): + # initialize the window + self.parent_ui = parent_ui + self.command = command_args + self.ui = gtk.Builder () + self.ui.add_from_file ("progress_window.xml") + self.ui.connect_signals (self) + + self.ui.get_object ("progress_window").show () + + # now start the burning process in a separate thread + self.burn_proc = self.burningprocess (self) + self.burn_proc.start () \ No newline at end of file