From: Harishankar Date: Mon, 31 May 2010 10:02:46 +0000 (+0530) Subject: Added the progress dialog X-Git-Url: https://harishankar.org/repos/?p=biagen.git;a=commitdiff_plain;h=12a84b1fe5750d8d967d19bb6067db04e87d2d1f Added the progress dialog Added the progress dialog for the genisoimage process --- diff --git a/biagen b/biagen index 86a337c..d78a501 100755 --- a/biagen +++ b/biagen @@ -6,8 +6,9 @@ import pygtk pygtk.require20 () -import gtk +import gtk, gobject import os, subprocess, sys +import progress_window as PW class BiaGen: def build_parameters (self): @@ -162,7 +163,7 @@ class BiaGen: for file in file_list: cmdlist.append (file) - print subprocess.list2cmdline (cmdlist) + wnd = PW.BiaGenProgress (self.ui, cmdlist) else: # display the error message msgdlg = gtk.MessageDialog (parent = self.ui.get_object ("main_window"), buttons = gtk.BUTTONS_OK, @@ -225,6 +226,7 @@ class BiaGen: gtk.main_quit () def __init__ (self): + gobject.threads_init () self.ui = gtk.Builder () self.ui.add_from_file ("main_window.xml") self.ui.get_object ("main_window").show () 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 diff --git a/progress_window.xml b/progress_window.xml new file mode 100644 index 0000000..6b0affa --- /dev/null +++ b/progress_window.xml @@ -0,0 +1,103 @@ + + + + + + True + center + False + + + True + 5 + vertical + + + True + genisoimage output + + + + + + False + False + 0 + + + + + True + True + automatic + in + + + 480 + 320 + True + True + 5 + False + word + + + + + 5 + 1 + + + + + True + + + 2 + + + + + True + 20 + end + + + _Cancel + True + True + True + True + + + False + False + 0 + + + + + Close + True + False + True + True + + + + False + False + 1 + + + + + False + 10 + 3 + + + + + +