From 3e7a75e7209105d50e55bf9f7781bb2b1e3a8147 Mon Sep 17 00:00:00 2001 From: Kristian Rumberg Date: Sun, 10 Aug 2008 23:48:37 +0200 Subject: [PATCH] displays dialog on finished --- command_executer.py | 42 +++++++++++++++++++++++------------------- gui.py | 26 ++++++-------------------- 2 files changed, 29 insertions(+), 39 deletions(-) diff --git a/command_executer.py b/command_executer.py index f4e6c41..f9d63a6 100644 --- a/command_executer.py +++ b/command_executer.py @@ -22,10 +22,10 @@ from commands import Variable class CommandExecuterView: def __init__(self): - pass + pass def recieve_executor(self, executor): - pass + pass def starting_conversion(self, infile, index, total, outfile): pass @@ -33,7 +33,7 @@ class CommandExecuterView: def update_progress(self, logline): pass - def finished_conversion(self, infile, outfile): + def error(self): pass def finished_all(self): @@ -46,24 +46,24 @@ class CommandExecuter: self.infilelist = infilelist self.outdir = outdir - self.please_abort = False + self.please_abort = False - self.shared_vars_lock = threading.Lock() + self.shared_vars_lock = threading.Lock() thread.start_new_thread(self._run_conversion, ()) def abort(self): - self.shared_vars_lock.acquire() - self.please_abort = True - self.shared_vars_lock.release() + self.shared_vars_lock.acquire() + self.please_abort = True + self.shared_vars_lock.release() def _run_conversion(self): - index = 0 - total = len(self.infilelist) + index = 0 + total = len(self.infilelist) for infile in self.infilelist: outfile = self.outdir + "/" + os.path.basename(infile) + "_converted" - index = index + 1 + index = index + 1 self.command.put_var(Variable("in", infile)) self.command.put_var(Variable("out", outfile)) @@ -73,7 +73,7 @@ class CommandExecuter: p = subprocess.Popen(str(self.command), shell = True, universal_newlines=True, stderr = subprocess.PIPE) ostream = p.stderr - self.cmdexecview.recieve_executor(self) + self.cmdexecview.recieve_executor(self) newline = str(chr(32) * 4) buff = "" @@ -90,15 +90,19 @@ class CommandExecuter: self.cmdexecview.update_progress(buff.strip()) buff = "" - self.shared_vars_lock.acquire() - if self.please_abort == True: - ostream.close() - os.kill(p.pid, signal.SIGTERM) - return - self.shared_vars_lock.release() + self.shared_vars_lock.acquire() + if self.please_abort == True: + ostream.close() + os.kill(p.pid, signal.SIGTERM) + return + self.shared_vars_lock.release() ostream.close() - self.cmdexecview.finished_conversion(infile, outfile) + res = p.wait() + + if res < 0: + self.cmdexecview.error() + return self.cmdexecview.finished_all() diff --git a/gui.py b/gui.py index a365732..54499ca 100644 --- a/gui.py +++ b/gui.py @@ -21,23 +21,6 @@ import gtk.glade from command_executer import CommandExecuterView from command_executer import CommandExecuter -class ConsoleCommandExecuterView(CommandExecuterView): - def __init__(self): - CommandExecuterView.__init__(self) - print "About to convert a list of files" - - def starting_conversion(self, infile, index, total, outfile): - print "Began converting " + infile + " to " + outfile - - def update_progress(self, logline): - print logline - - def finished_conversion(self, infile, outfile): - print "Done converting " + infile + " to " + outfile - - def finished_all(self): - print "All convertings done" - class GtkCommandExecuterView(CommandExecuterView): def on_abortbutton_clicked(self, data): @@ -65,11 +48,14 @@ class GtkCommandExecuterView(CommandExecuterView): def update_progress(self, logline): self.progresslabel.set_text(logline) - def finished_conversion(self, infile, outfile): - pass + def error(self): + gtk.MessageDialog(message_format="There was an error during the conversion", type=gtk.MESSAGE_ERROR).show() + self.progresswindow.destroy() def finished_all(self): - pass + print "finished_all" + gtk.MessageDialog(message_format="All conversions succeded :)").show() + self.progresswindow.destroy() class MyGui: def _enable_or_disable_convertbutton(self): -- 2.11.4.GIT