Small changes to the progress window
[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.set_pulse_step (0.3)
27 pbar.pulse ()
28 except:
29 pass
30
31 textview = self.parent.ui.get_object ("progressmessages")
32 textbuf = textview.get_buffer ()
33 textbuf.set_text (data)
34 endmark = textbuf.get_insert ()
35 textview.scroll_to_mark (endmark, 0.0)
36
37 def run (self):
38 proc = subprocess.Popen (self.parent.command, stdout=subprocess.PIPE,
39 stdin=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1)
40
41 data = ""
42 try:
43 ch = proc.stdout.read (1)
44 except:
45 pass
46
47 while (ch):
48 data += ch
49 gobject.idle_add (self.update_ui, data)
50 try:
51 ch = proc.stdout.read (1)
52 except:
53 continue
54
55 proc.wait ()
56 data += "\ngenisoimage has completed. You can close this window now."
57 #gobject.idle_add (self.update_ui, data)
58 self.parent.ui.get_object ("progressmessages").get_buffer ().set_text (data)
59 self.parent.ui.get_object ("btnclose").set_sensitive (True)
60 self.parent.ui.get_object ("btncancel").set_sensitive (False)
61 self.parent.ui.get_object ("progress").set_fraction (1.0)
62
63 def __init__ (self, parent):
64 super (BiaGenProgress.burningprocess, self).__init__ ()
65 self.parent = parent
66 self.command = self.parent.command
67
68 def on_btnclose_clicked (self, *args):
69 self.ui.get_object ("progress_window").destroy ()
70
71 def __init__ (self, parent_ui, command_args):
72 # initialize the window
73 self.parent_ui = parent_ui
74 self.command = command_args
75 self.ui = gtk.Builder ()
76 self.ui.add_from_file ("progress_window.xml")
77 self.ui.connect_signals (self)
78
79 self.ui.get_object ("progress_window").show ()
80
81 # now start the burning process in a separate thread
82 self.burn_proc = self.burningprocess (self)
83 self.burn_proc.start ()