|
@ -1,23 +1,15 @@ |
|
|
import re |
|
|
|
|
|
from collections import namedtuple |
|
|
|
|
|
|
|
|
|
|
|
import subprocess |
|
|
|
|
|
|
|
|
|
|
|
import sys |
|
|
import sys |
|
|
|
|
|
|
|
|
from gooey.gui import component_builder |
|
|
|
|
|
from gooey.gui.processor import ProcessController |
|
|
from gooey.gui.processor import ProcessController |
|
|
from gooey.gui.lang.i18n import _ |
|
|
|
|
|
from gooey.gui.model import States |
|
|
from gooey.gui.model import States |
|
|
from gooey.gui.pubsub import pub |
|
|
from gooey.gui.pubsub import pub |
|
|
from gooey.gui import events |
|
|
from gooey.gui import events |
|
|
from gooey.gui.windows import views |
|
|
|
|
|
from multiprocessing.dummy import Pool |
|
|
|
|
|
|
|
|
|
|
|
class Presenter(object): |
|
|
class Presenter(object): |
|
|
def __init__(self, view, model): |
|
|
def __init__(self, view, model): |
|
|
self.view = view |
|
|
self.view = view |
|
|
self.model = model |
|
|
self.model = model |
|
|
|
|
|
|
|
|
self.client_runner = ProcessController( |
|
|
self.client_runner = ProcessController( |
|
|
self.model.progress_regex, |
|
|
self.model.progress_regex, |
|
|
self.model.progress_expr |
|
|
self.model.progress_expr |
|
@ -30,8 +22,6 @@ class Presenter(object): |
|
|
pub.subscribe(self.on_edit, events.WINDOW_EDIT) |
|
|
pub.subscribe(self.on_edit, events.WINDOW_EDIT) |
|
|
pub.subscribe(self.on_close, events.WINDOW_CLOSE) |
|
|
pub.subscribe(self.on_close, events.WINDOW_CLOSE) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# console statuses from the other thread |
|
|
# console statuses from the other thread |
|
|
pub.subscribe(self.on_new_message, 'console_update') |
|
|
pub.subscribe(self.on_new_message, 'console_update') |
|
|
pub.subscribe(self.on_progress_change, 'progress_update') |
|
|
pub.subscribe(self.on_progress_change, 'progress_update') |
|
@ -55,12 +45,29 @@ class Presenter(object): |
|
|
|
|
|
|
|
|
self.syncronize_from_model() |
|
|
self.syncronize_from_model() |
|
|
|
|
|
|
|
|
def on_edit(self): |
|
|
|
|
|
self.model.update_state(States.CONFIGURING) |
|
|
|
|
|
|
|
|
def update_model(self): |
|
|
|
|
|
self.update_list(self.model.required_args, self.view.required_section.get_values()) |
|
|
|
|
|
self.update_list(self.model.optional_args, self.view.optional_section.get_values()) |
|
|
self.syncronize_from_model() |
|
|
self.syncronize_from_model() |
|
|
|
|
|
|
|
|
def on_restart(self): |
|
|
|
|
|
self.on_start() |
|
|
|
|
|
|
|
|
def syncronize_from_model(self): |
|
|
|
|
|
# update heading titles |
|
|
|
|
|
self.view.heading_title = self.model.heading_title |
|
|
|
|
|
self.view.heading_subtitle = self.model.heading_subtitle |
|
|
|
|
|
if not self.model.stop_button_disabled: |
|
|
|
|
|
self.view.enable_stop_button() |
|
|
|
|
|
|
|
|
|
|
|
# refresh the widgets |
|
|
|
|
|
for index, widget in enumerate(self.view.required_section): |
|
|
|
|
|
widget.set_value(self.model.required_args[index]._value) |
|
|
|
|
|
for index, widget in enumerate(self.view.optional_section): |
|
|
|
|
|
widget.set_value(self.model.optional_args[index]._value) |
|
|
|
|
|
|
|
|
|
|
|
# swap the views |
|
|
|
|
|
getattr(self, self.model.current_state)() |
|
|
|
|
|
|
|
|
|
|
|
def should_disable_stop_button(self): |
|
|
|
|
|
return self.model.stop_button_disabled |
|
|
|
|
|
|
|
|
def on_start(self): |
|
|
def on_start(self): |
|
|
self.update_model() |
|
|
self.update_model() |
|
@ -71,6 +78,25 @@ class Presenter(object): |
|
|
self.model.update_state(States.RUNNNING) |
|
|
self.model.update_state(States.RUNNNING) |
|
|
self.syncronize_from_model() |
|
|
self.syncronize_from_model() |
|
|
|
|
|
|
|
|
|
|
|
def on_stop(self): |
|
|
|
|
|
self.ask_stop() |
|
|
|
|
|
|
|
|
|
|
|
def on_edit(self): |
|
|
|
|
|
self.model.update_state(States.CONFIGURING) |
|
|
|
|
|
self.syncronize_from_model() |
|
|
|
|
|
|
|
|
|
|
|
def on_restart(self): |
|
|
|
|
|
self.on_start() |
|
|
|
|
|
|
|
|
|
|
|
def on_cancel(self): |
|
|
|
|
|
if self.view.confirm_exit_dialog(): |
|
|
|
|
|
self.view.Destroy() |
|
|
|
|
|
sys.exit() |
|
|
|
|
|
|
|
|
|
|
|
def on_close(self): |
|
|
|
|
|
self.view.Destroy() |
|
|
|
|
|
sys.exit() |
|
|
|
|
|
|
|
|
def on_new_message(self, msg): |
|
|
def on_new_message(self, msg): |
|
|
# observes changes coming from the subprocess |
|
|
# observes changes coming from the subprocess |
|
|
self.view.update_console_async(msg) |
|
|
self.view.update_console_async(msg) |
|
@ -86,24 +112,6 @@ class Presenter(object): |
|
|
self.model.update_state(States.ERROR) |
|
|
self.model.update_state(States.ERROR) |
|
|
self.syncronize_from_model() |
|
|
self.syncronize_from_model() |
|
|
|
|
|
|
|
|
def update_model(self): |
|
|
|
|
|
self.update_list(self.model.required_args, self.view.required_section.get_values()) |
|
|
|
|
|
self.update_list(self.model.optional_args, self.view.optional_section.get_values()) |
|
|
|
|
|
self.syncronize_from_model() |
|
|
|
|
|
|
|
|
|
|
|
def on_cancel(self): |
|
|
|
|
|
if self.view.confirm_exit_dialog(): |
|
|
|
|
|
self.view.Destroy() |
|
|
|
|
|
sys.exit() |
|
|
|
|
|
|
|
|
|
|
|
def on_stop(self): |
|
|
|
|
|
self.ask_stop() |
|
|
|
|
|
|
|
|
|
|
|
def on_close(self): |
|
|
|
|
|
if self.ask_stop(): |
|
|
|
|
|
self.view.Destroy() |
|
|
|
|
|
sys.exit() |
|
|
|
|
|
|
|
|
|
|
|
def ask_stop(self): |
|
|
def ask_stop(self): |
|
|
if self.view.confirm_stop_dialog(): |
|
|
if self.view.confirm_stop_dialog(): |
|
|
self.stop() |
|
|
self.stop() |
|
@ -113,32 +121,14 @@ class Presenter(object): |
|
|
def stop(self): |
|
|
def stop(self): |
|
|
self.client_runner.stop() |
|
|
self.client_runner.stop() |
|
|
|
|
|
|
|
|
def update_list(self, collection, new_values): |
|
|
|
|
|
for index, val in enumerate(new_values): |
|
|
|
|
|
collection[index].value = val |
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
@staticmethod |
|
|
def partition(collection, condition): |
|
|
def partition(collection, condition): |
|
|
return filter(condition, collection), filter(lambda x: not condition(x), collection) |
|
|
return filter(condition, collection), filter(lambda x: not condition(x), collection) |
|
|
|
|
|
|
|
|
def syncronize_from_model(self): |
|
|
|
|
|
# update heading titles |
|
|
|
|
|
self.view.heading_title = self.model.heading_title |
|
|
|
|
|
self.view.heading_subtitle = self.model.heading_subtitle |
|
|
|
|
|
if not self.model.stop_button_disabled: |
|
|
|
|
|
self.view.enable_stop_button() |
|
|
|
|
|
|
|
|
|
|
|
# refresh the widgets |
|
|
|
|
|
for index, widget in enumerate(self.view.required_section): |
|
|
|
|
|
widget.set_value(self.model.required_args[index]._value) |
|
|
|
|
|
for index, widget in enumerate(self.view.optional_section): |
|
|
|
|
|
widget.set_value(self.model.optional_args[index]._value) |
|
|
|
|
|
|
|
|
|
|
|
# swap the views |
|
|
|
|
|
getattr(self, self.model.current_state)() |
|
|
|
|
|
|
|
|
|
|
|
def should_disable_stop_button(self): |
|
|
|
|
|
return self.model.stop_button_disabled |
|
|
|
|
|
|
|
|
def update_list(self, collection, new_values): |
|
|
|
|
|
# convenience method for syncronizing the model -> widget list collections |
|
|
|
|
|
for index, val in enumerate(new_values): |
|
|
|
|
|
collection[index].value = val |
|
|
|
|
|
|
|
|
def configuring(self): |
|
|
def configuring(self): |
|
|
self.view.hide_all_buttons() |
|
|
self.view.hide_all_buttons() |
|
|