Added the progress dialog
authorHarishankar <v.harishankar@gmail.com>
Mon, 31 May 2010 10:02:46 +0000 (15:32 +0530)
committerHarishankar <v.harishankar@gmail.com>
Mon, 31 May 2010 10:02:46 +0000 (15:32 +0530)
Added the progress dialog for the genisoimage process

biagen
progress_window.py [new file with mode: 0644]
progress_window.xml [new file with mode: 0644]

diff --git a/biagen b/biagen
index 86a337c..d78a501 100755 (executable)
--- 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 (file)
index 0000000..102b222
--- /dev/null
@@ -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 (file)
index 0000000..6b0affa
--- /dev/null
@@ -0,0 +1,103 @@
+<?xml version="1.0"?>
+<interface>
+  <requires lib="gtk+" version="2.16"/>
+  <!-- interface-naming-policy project-wide -->
+  <object class="GtkWindow" id="progress_window">
+    <property name="modal">True</property>
+    <property name="window_position">center</property>
+    <property name="deletable">False</property>
+    <child>
+      <object class="GtkVBox" id="vbox1">
+        <property name="visible">True</property>
+        <property name="border_width">5</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkLabel" id="label1">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">genisoimage output</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+            </attributes>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkScrolledWindow" id="scrolledwindow1">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="hscrollbar_policy">automatic</property>
+            <property name="shadow_type">in</property>
+            <child>
+              <object class="GtkTextView" id="progressmessages">
+                <property name="width_request">480</property>
+                <property name="height_request">320</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="pixels_above_lines">5</property>
+                <property name="editable">False</property>
+                <property name="wrap_mode">word</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="padding">5</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkProgressBar" id="progress">
+            <property name="visible">True</property>
+          </object>
+          <packing>
+            <property name="position">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkHButtonBox" id="hbuttonbox1">
+            <property name="visible">True</property>
+            <property name="spacing">20</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="btncancel">
+                <property name="label" translatable="yes">_Cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="btnclose">
+                <property name="label" translatable="yes">Close</property>
+                <property name="visible">True</property>
+                <property name="sensitive">False</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <signal name="clicked" handler="on_btnclose_clicked"/>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="padding">10</property>
+            <property name="position">3</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>