Added the progress dialog
[biagen.git] / progress_window.py
1 # BiaGen - front end to genisoimage
2 # Copyright 2010 V.Harishankar
3 # Licensed under the GNU GPL v3 or above
4
5 # window to run the executable
6
7 import pygtk
8 pygtk.require ("2.0")
9 import gtk, gobject
10 import threading
11 import os, sys, subprocess, signal
12
13 class BiaGenProgress:
14
15 class burningprocess (threading.Thread):
16 def update_ui (self, data):
17 lines = data.split ("\n")
18 lastline = lines[len (lines) - 1]
19 words = lastline.split ("%")
20 pbar = self.parent.ui.get_object ("progress")
21 try:
22 perc = float (words[0].strip ()) / 100.0
23 if perc >= 0 and perc <= 1:
24 pbar.set_fraction (perc)
25 else:
26 pbar.pulse ()
27 except:
28 pass
29
30 textview = self.parent.ui.get_object ("progressmessages")
31 textbuf = textview.get_buffer ()
32 textbuf.set_text (data)
33 endmark = textbuf.get_insert ()
34 textview.scroll_to_mark (endmark, 0.0)
35
36 def run (self):
37 proc = subprocess.Popen (self.parent.command, stdout=subprocess.PIPE,
38 stdin=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1)
39
40 data = ""
41 try:
42 ch = proc.stdout.read (1)
43 except:
44 pass
45
46 while (ch):
47 data += ch
48 gobject.idle_add (self.update_ui, data)
49 try:
50 ch = proc.stdout.read (1)
51 except:
52 continue
53
54 proc.wait ()
55 data += "\ngenisoimage has completed. You can close this window now."
56 #gobject.idle_add (self.update_ui, data)
57 self.parent.ui.get_object ("progressmessages").get_buffer ().set_text (data)
58 self.parent.ui.get_object ("btnclose").set_sensitive (True)
59 self.parent.ui.get_object ("progress").set_fraction (1.0)
60
61 def __init__ (self, parent):
62 super (BiaGenProgress.burningprocess, self).__init__ ()
63 self.parent = parent
64 self.command = self.parent.command
65
66 def on_btnclose_clicked (self, *args):
67 self.ui.get_object ("progress_window").destroy ()
68
69 def __init__ (self, parent_ui, command_args):
70 # initialize the window
71 self.parent_ui = parent_ui
72 self.command = command_args
73 self.ui = gtk.Builder ()
74 self.ui.add_from_file ("progress_window.xml")
75 self.ui.connect_signals (self)
76
77 self.ui.get_object ("progress_window").show ()
78
79 # now start the burning process in a separate thread
80 self.burn_proc = self.burningprocess (self)
81 self.burn_proc.start ()