diff options
-rw-r--r-- | grc/gui/ActionHandler.py | 12 | ||||
-rw-r--r-- | grc/gui/Executor.py | 34 | ||||
-rw-r--r-- | grc/gui/NotebookPage.py | 9 |
3 files changed, 29 insertions, 26 deletions
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py index 4866a34ad9..2b39079f76 100644 --- a/grc/gui/ActionHandler.py +++ b/grc/gui/ActionHandler.py @@ -580,8 +580,10 @@ class ActionHandler: try: Messages.send_start_gen(generator.get_file_path()) generator.write() - except Exception,e: Messages.send_fail_gen(e) - else: self.generator = None + except Exception as e: + Messages.send_fail_gen(e) + else: + self.generator = None elif action == Actions.FLOW_GRAPH_EXEC: if not page.get_proc(): Actions.FLOW_GRAPH_GEN() @@ -591,7 +593,11 @@ class ActionHandler: Dialogs.MissingXTermDialog(xterm) Preferences.xterm_missing(xterm) if page.get_saved() and page.get_file_path(): - Executor.ExecFlowGraphThread(self) + Executor.ExecFlowGraphThread( + flow_graph_page=page, + xterm_executable=xterm, + callback=self.update_exec_stop + ) elif action == Actions.FLOW_GRAPH_KILL: if page.get_proc(): try: diff --git a/grc/gui/Executor.py b/grc/gui/Executor.py index f75f514cdb..bf9eecb9a8 100644 --- a/grc/gui/Executor.py +++ b/grc/gui/Executor.py @@ -30,7 +30,7 @@ from ..core import Messages class ExecFlowGraphThread(threading.Thread): """Execute the flow graph as a new process and wait on it to finish.""" - def __init__(self, action_handler): + def __init__(self, flow_graph_page, xterm_executable, callback): """ ExecFlowGraphThread constructor. @@ -38,19 +38,17 @@ class ExecFlowGraphThread(threading.Thread): action_handler: an instance of an ActionHandler """ threading.Thread.__init__(self) - self.update_exec_stop = action_handler.update_exec_stop - self.flow_graph = action_handler.get_flow_graph() - self.xterm_executable = action_handler.platform.config.xterm_executable - #store page and dont use main window calls in run - self.page = action_handler.get_page() - #get the popen + + self.page = flow_graph_page # store page and dont use main window calls in run + self.xterm_executable = xterm_executable + self.update_callback = callback + try: - self.p = self._popen() - self.page.set_proc(self.p) - #update - self.update_exec_stop() + self.process = self._popen() + self.page.set_proc(self.process) + self.update_callback() self.start() - except Exception, e: + except Exception as e: Messages.send_verbose_exec(str(e)) Messages.send_end_exec() @@ -58,7 +56,7 @@ class ExecFlowGraphThread(threading.Thread): """ Execute this python flow graph. """ - run_command = self.flow_graph.get_option('run_command') + run_command = self.page.get_flow_graph().get_option('run_command') generator = self.page.get_generator() try: @@ -90,19 +88,19 @@ class ExecFlowGraphThread(threading.Thread): Wait on the executing process by reading from its stdout. Use gobject.idle_add when calling functions that modify gtk objects. """ - #handle completion + # handle completion r = "\n" while r: gobject.idle_add(Messages.send_verbose_exec, r) - r = os.read(self.p.stdout.fileno(), 1024) - self.p.poll() + r = os.read(self.process.stdout.fileno(), 1024) + self.process.poll() gobject.idle_add(self.done) def done(self): """Perform end of execution tasks.""" - Messages.send_end_exec(self.p.returncode) + Messages.send_end_exec(self.process.returncode) self.page.set_proc(None) - self.update_exec_stop() + self.update_callback() ########################################################### diff --git a/grc/gui/NotebookPage.py b/grc/gui/NotebookPage.py index 6614649c89..c9e8d0f186 100644 --- a/grc/gui/NotebookPage.py +++ b/grc/gui/NotebookPage.py @@ -39,13 +39,13 @@ class NotebookPage(gtk.HBox): file_path: path to a flow graph file """ self._flow_graph = flow_graph - self.set_proc(None) + self.process = None #import the file self.main_window = main_window - self.set_file_path(file_path) + self.file_path = file_path initial_state = flow_graph.get_parent().parse_flow_graph(file_path) self.state_cache = StateCache(initial_state) - self.set_saved(True) + self.saved = True #import the data to the flow graph self.get_flow_graph().import_data(initial_state) #initialize page gui @@ -189,8 +189,7 @@ class NotebookPage(gtk.HBox): Args: file_path: file path string """ - if file_path: self.file_path = os.path.abspath(file_path) - else: self.file_path = '' + self.file_path = os.path.abspath(file_path) if file_path else '' def get_saved(self): """ |