|
|
@ -5,6 +5,7 @@ Created on Dec 22, 2013 |
|
|
|
''' |
|
|
|
|
|
|
|
import wx |
|
|
|
import os |
|
|
|
import sys |
|
|
|
import subprocess |
|
|
|
|
|
|
@ -14,12 +15,13 @@ from multiprocessing.dummy import Pool |
|
|
|
from gooey.gui import events |
|
|
|
from gooey.gui.lang import i18n |
|
|
|
from gooey.gui.windows import views |
|
|
|
from gooey.gui.util.taskkill import taskkill |
|
|
|
|
|
|
|
|
|
|
|
YES = 5103 |
|
|
|
NO = 5104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Controller(object): |
|
|
|
''' |
|
|
|
Main controller for the gui. |
|
|
@ -34,9 +36,11 @@ class Controller(object): |
|
|
|
''' |
|
|
|
self.core_gui = base_frame |
|
|
|
self.build_spec = build_spec |
|
|
|
self._process = None |
|
|
|
|
|
|
|
# wire up all the observers |
|
|
|
pub.subscribe(self.on_cancel, events.WINDOW_CANCEL) |
|
|
|
pub.subscribe(self.on_stop, events.WINDOW_STOP) |
|
|
|
pub.subscribe(self.on_start, events.WINDOW_START) |
|
|
|
pub.subscribe(self.on_restart, events.WINDOW_RESTART) |
|
|
|
pub.subscribe(self.on_close, events.WINDOW_CLOSE) |
|
|
@ -74,8 +78,32 @@ class Controller(object): |
|
|
|
pub.send_message(events.WINDOW_CHANGE, view_name=views.RUNNING_SCREEN) |
|
|
|
self.run_client_code(command) |
|
|
|
|
|
|
|
def on_stop(self): |
|
|
|
if not self.running(): |
|
|
|
return True |
|
|
|
msg = i18n._('sure_you_want_to_stop') |
|
|
|
dlg = wx.MessageDialog(None, msg, i18n._('stop_task'), wx.YES_NO) |
|
|
|
result = dlg.ShowModal() |
|
|
|
dlg.Destroy() |
|
|
|
if result == YES: |
|
|
|
self.stop() |
|
|
|
return True |
|
|
|
return False |
|
|
|
|
|
|
|
def stop(self): |
|
|
|
if self.running(): |
|
|
|
taskkill(self._process.pid) |
|
|
|
|
|
|
|
def running(self): |
|
|
|
return self._process and self._process.poll() is None |
|
|
|
|
|
|
|
def run_client_code(self, command): |
|
|
|
p = subprocess.Popen(command, bufsize=1, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) |
|
|
|
env = os.environ.copy() |
|
|
|
env["GOOEY"] = "1" |
|
|
|
print "run command:", command |
|
|
|
p = subprocess.Popen(command, bufsize=1, stdout=subprocess.PIPE, |
|
|
|
stderr=subprocess.STDOUT, shell=True, env=env) |
|
|
|
self._process = p |
|
|
|
pool = Pool(1) |
|
|
|
pool.apply_async(self.read_stdout, (p, self.process_result)) |
|
|
|
|
|
|
@ -88,13 +116,13 @@ class Controller(object): |
|
|
|
wx.CallAfter(callback, process) |
|
|
|
|
|
|
|
def process_result(self, process): |
|
|
|
_stdout, _stderr = process.communicate() |
|
|
|
_stdout, _ = process.communicate() |
|
|
|
if process.returncode == 0: |
|
|
|
pub.send_message(events.WINDOW_CHANGE, view_name=views.SUCCESS_SCREEN) |
|
|
|
self.success_dialog() |
|
|
|
else: |
|
|
|
pub.send_message(events.WINDOW_CHANGE, view_name=views.ERROR_SCREEN) |
|
|
|
self.error_dialog(_stderr) |
|
|
|
self.error_dialog() |
|
|
|
|
|
|
|
def skipping_config(self): |
|
|
|
return self.build_spec['manual_start'] |
|
|
@ -108,8 +136,8 @@ class Controller(object): |
|
|
|
def success_dialog(self): |
|
|
|
self.show_dialog(i18n._("execution_finished"), i18n._('success_message'), wx.ICON_INFORMATION) |
|
|
|
|
|
|
|
def error_dialog(self, error_msg): |
|
|
|
self.show_dialog(i18n._('error_title'), i18n._('uh_oh').format(error_msg), wx.ICON_ERROR) |
|
|
|
def error_dialog(self): |
|
|
|
self.show_dialog(i18n._('error_title'), i18n._('uh_oh'), wx.ICON_ERROR) |
|
|
|
|
|
|
|
def show_dialog(self, title, content, style): |
|
|
|
a = wx.MessageDialog(None, content, title, style) |
|
|
|