From a907e8ba37dc7c2f7b56f2e7032e9c8ba623d236 Mon Sep 17 00:00:00 2001 From: chriskiehl Date: Thu, 24 Dec 2015 16:10:16 -0500 Subject: [PATCH] Remove old controller implementation --- gooey/gui/application.py | 9 ++-- gooey/gui/controller.py | 70 +++++++++++----------------- gooey/gui/widgets/widget_pack.py | 15 +++--- gooey/gui/windows/advanced_config.py | 6 --- gooey/gui/windows/base_window.py | 22 +++------ gooey/gui/windows/footer.py | 6 --- gooey/gui/windows/header.py | 5 -- gooey/gui/windows/sidebar.py | 2 - 8 files changed, 44 insertions(+), 91 deletions(-) diff --git a/gooey/gui/application.py b/gooey/gui/application.py index 209599e..d63428a 100644 --- a/gooey/gui/application.py +++ b/gooey/gui/application.py @@ -8,11 +8,8 @@ import sys import json import argparse -from functools import partial - from gooey.gui.lang import i18n -from gooey.gui.windows.base_window import BaseWindow -from gooey.gui.windows.advanced_config import ConfigPanel +from gooey.gui.controller import Controller from gooey.python_bindings import config_generator, source_parser from gooey.gui import image_repository @@ -73,8 +70,8 @@ def run(build_spec): i18n.load(build_spec['language_dir'], build_spec['language']) image_repository.patch_images(build_spec['image_dir']) - frame = BaseWindow(build_spec) - frame.Show(True) + controller = Controller(build_spec) + controller.run() app.MainLoop() diff --git a/gooey/gui/controller.py b/gooey/gui/controller.py index c0cb18c..245d48c 100644 --- a/gooey/gui/controller.py +++ b/gooey/gui/controller.py @@ -1,42 +1,31 @@ -''' -Created on Dec 22, 2013 - -@author: Chris -''' - -import wx import os import re +import wx import sys -import subprocess -from gooey.gui.pubsub import pub +import subprocess 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 import events +from gooey.gui.pubsub import pub from gooey.gui.util.taskkill import taskkill +from gooey.gui.windows import views +from gooey.gui.windows.base_window import BaseWindow YES = 5103 NO = 5104 - class Controller(object): - ''' - Main controller for the gui. - - All controlls are delegated to this central control point. - ''' - - def __init__(self, base_frame, build_spec): - ''' - :type base_frame: BaseWindow - :type build_spec: dict - ''' - self.core_gui = base_frame + + def __init__(self, build_spec): + # todo: model! self.build_spec = build_spec + + self.view = BaseWindow(build_spec) + self._process = None # wire up all the observers @@ -52,7 +41,7 @@ class Controller(object): def on_close(self): if self.ask_stop(): - self.core_gui.Destroy() + self.view.Destroy() sys.exit() def on_restart(self): @@ -63,19 +52,16 @@ class Controller(object): def on_cancel(self): msg = i18n._('sure_you_want_to_exit') - dlg = wx.MessageDialog(None, msg, i18n._('close_program'), wx.YES_NO) - result = dlg.ShowModal() + result = self.view.show_dialog(msg, i18n._('close_program'), wx.YES_NO) if result == YES: - dlg.Destroy() - self.core_gui.Destroy() + self.view.Destroy() sys.exit() - dlg.Destroy() def on_start(self): if not self.skipping_config() and not self.required_section_complete(): - return self.show_dialog(i18n._('error_title'), i18n._('error_required_fields'), wx.ICON_ERROR) + return self.view.show_dialog(i18n._('error_title'), i18n._('error_required_fields'), wx.ICON_ERROR) - cmd_line_args = self.core_gui.GetOptions() + cmd_line_args = self.view.GetOptions() command = '{} --ignore-gooey {}'.format(self.build_spec['target'], cmd_line_args) pub.send_message(events.WINDOW_CHANGE, view_name=views.RUNNING_SCREEN) self.run_client_code(command) @@ -89,9 +75,7 @@ class Controller(object): if self.build_spec['disable_stop_button']: return False msg = i18n._('sure_you_want_to_stop') - dlg = wx.MessageDialog(None, msg, i18n._('stop_task'), wx.YES_NO) - result = dlg.ShowModal() - dlg.Destroy() + result = self.view.show_dialog(msg, i18n._('stop_task'), wx.YES_NO) if result == YES: self.stop() return True @@ -119,10 +103,10 @@ class Controller(object): line = process.stdout.readline() if not line: break - wx.CallAfter(self.core_gui.PublishConsoleMsg, line) + wx.CallAfter(self.view.PublishConsoleMsg, line) progress = self.progress_from_line(line) if progress is not None: - wx.CallAfter(self.core_gui.UpdateProgressBar, progress) + wx.CallAfter(self.view.UpdateProgressBar, progress) wx.CallAfter(callback, process) def progress_from_line(self, text): @@ -171,19 +155,17 @@ class Controller(object): return self.build_spec['manual_start'] def required_section_complete(self): - required_section = self.core_gui.GetRequiredArgs() + required_section = self.view.GetRequiredArgs() if len(required_section) == 0: return True # no requirements! return not any(req == '' for req in required_section) def success_dialog(self): - self.show_dialog(i18n._("execution_finished"), i18n._('success_message'), wx.ICON_INFORMATION) + self.view.show_dialog(i18n._("execution_finished"), i18n._('success_message'), wx.ICON_INFORMATION) def error_dialog(self): - self.show_dialog(i18n._('error_title'), i18n._('uh_oh'), wx.ICON_ERROR) + self.view.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) - a.ShowModal() - a.Destroy() + def run(self): + self.view.Show(True) diff --git a/gooey/gui/widgets/widget_pack.py b/gooey/gui/widgets/widget_pack.py index b197522..d566a16 100644 --- a/gooey/gui/widgets/widget_pack.py +++ b/gooey/gui/widgets/widget_pack.py @@ -129,12 +129,6 @@ def build_dialog(style, exist_constraint=True, **kwargs): else: return lambda panel: wx.FileDialog(panel, style=style, **kwargs) -FileChooserPayload = partial(BaseFileChooser, dialog=build_dialog(wx.FD_OPEN)) -FileSaverPayload = partial(BaseFileChooser, dialog=build_dialog(wx.FD_SAVE, False, defaultFile="Enter Filename")) -MultiFileSaverPayload = partial(BaseMultiFileChooser, dialog=build_dialog(wx.FD_MULTIPLE, False)) -DirChooserPayload = partial(BaseFileChooser, dialog=lambda parent: wx.DirDialog(parent, 'Select Directory', style=wx.DD_DEFAULT_STYLE)) -DateChooserPayload = partial(BaseFileChooser, dialog=CalendarDlg) -MultiDirChooserPayload = partial(BaseMultiFileChooser, dialog=lambda parent: MyMultiDirChooser(parent, title="Select Directories", defaultPath=os.getcwd(), agwStyle=MDD.DD_MULTIPLE|MDD.DD_DIR_MUST_EXIST)) class TextInputPayload(WidgetPack): def __init__(self, no_quoting=False): @@ -242,3 +236,12 @@ class CounterPayload(WidgetPack): def safe_default(data, default): # str(None) is 'None'!? Whaaaaat...? return str(data['default']) if data['default'] else default + + + +FileChooserPayload = partial(BaseFileChooser, dialog=build_dialog(wx.FD_OPEN)) +FileSaverPayload = partial(BaseFileChooser, dialog=build_dialog(wx.FD_SAVE, False, defaultFile="Enter Filename")) +MultiFileSaverPayload = partial(BaseMultiFileChooser, dialog=build_dialog(wx.FD_MULTIPLE, False)) +DirChooserPayload = partial(BaseFileChooser, dialog=lambda parent: wx.DirDialog(parent, 'Select Directory', style=wx.DD_DEFAULT_STYLE)) +DateChooserPayload = partial(BaseFileChooser, dialog=CalendarDlg) +MultiDirChooserPayload = partial(BaseMultiFileChooser, dialog=lambda parent: MyMultiDirChooser(parent, title="Select Directories", defaultPath=os.getcwd(), agwStyle=MDD.DD_MULTIPLE|MDD.DD_DIR_MUST_EXIST)) diff --git a/gooey/gui/windows/advanced_config.py b/gooey/gui/windows/advanced_config.py index c4276e9..79fac14 100644 --- a/gooey/gui/windows/advanced_config.py +++ b/gooey/gui/windows/advanced_config.py @@ -34,8 +34,6 @@ class ConfigPanel(ScrolledPanel, OptionReader): self._num_req_cols = req_cols self._num_opt_cols = opt_cols - self._controller = None - self._do_layout() self.Bind(wx.EVT_SIZE, self.OnResize) @@ -85,10 +83,6 @@ class ConfigPanel(ScrolledPanel, OptionReader): self.SetupScrolling(scroll_x=False, scrollToTop=False) evt.Skip() - def RegisterController(self, controller): - if self._controller is None: - self._controller = controller - def GetOptions(self): """ returns the collective values from all of the diff --git a/gooey/gui/windows/base_window.py b/gooey/gui/windows/base_window.py index 0a7d9b4..31d9f6d 100644 --- a/gooey/gui/windows/base_window.py +++ b/gooey/gui/windows/base_window.py @@ -8,7 +8,6 @@ import sys import wx from gooey.gui.pubsub import pub -from gooey.gui.controller import Controller from gooey.gui.lang import i18n from gooey.gui.windows.advanced_config import ConfigPanel from gooey.gui.windows.runtime_display_panel import RuntimeDisplay @@ -23,8 +22,6 @@ class BaseWindow(wx.Frame): self.build_spec = build_spec - self._controller = None - self.SetDoubleBuffered(True) # Components @@ -39,8 +36,6 @@ class BaseWindow(wx.Frame): self._init_components() self._do_layout() self._init_pages() - self._init_controller() - self.registerControllers() self.Bind(wx.EVT_SIZE, self.onResize) self.Bind(wx.EVT_CLOSE, self.onClose) @@ -99,13 +94,6 @@ class BaseWindow(wx.Frame): if message == 'fetch': del self.config_panel - def _init_controller(self): - self._controller = Controller(base_frame=self, build_spec=self.build_spec) - - def registerControllers(self): - for panel in self.panels: - pass - def GetOptions(self): return self.config_panel.GetOptions() @@ -115,7 +103,6 @@ class BaseWindow(wx.Frame): def GetOptionalArgs(self): return self.config_panel.GetOptionalArgs() - def _init_pages(self): def config(): @@ -138,9 +125,6 @@ class BaseWindow(wx.Frame): def load_view(self, view_name=None): self.layouts.get(view_name, lambda: None)() - def ManualStart(self): - self._controller.manual_restart() - def onResize(self, evt): evt.Skip() @@ -170,6 +154,12 @@ class BaseWindow(wx.Frame): pb.SetValue(value+1) pb.SetValue(value) + def show_dialog(self, title, content, style): + dlg = wx.MessageDialog(None, content, title, style) + result = dlg.ShowModal() + dlg.Destroy() + return result + if __name__ == '__main__': pass diff --git a/gooey/gui/windows/footer.py b/gooey/gui/windows/footer.py index d32c8d3..2b37754 100644 --- a/gooey/gui/windows/footer.py +++ b/gooey/gui/windows/footer.py @@ -22,8 +22,6 @@ class AbstractFooter(wx.Panel): wx.Panel.__init__(self, parent, **kwargs) self.SetMinSize((30, 53)) - self._controller = None - # components self.cancel_button = None self.start_button = None @@ -124,10 +122,6 @@ class AbstractFooter(wx.Panel): label=label, style=style) - def RegisterController(self, controller): - if self._controller is None: - self._controller = controller - def _load_image(self, img_path, height=70): return imageutil.resize_bitmap(self, imageutil._load_image(img_path), height) diff --git a/gooey/gui/windows/header.py b/gooey/gui/windows/header.py index e865660..3dbca02 100644 --- a/gooey/gui/windows/header.py +++ b/gooey/gui/windows/header.py @@ -19,7 +19,6 @@ class FrameHeader(wx.Panel): def __init__(self, heading, subheading, **kwargs): wx.Panel.__init__(self, **kwargs) self.SetDoubleBuffered(True) - self._controller = None self.heading_msg = heading self.subheading_msg = subheading @@ -82,10 +81,6 @@ class FrameHeader(wx.Panel): sizer.AddStretchSpacer(1) return sizer - def RegisterController(self, controller): - if self._controller is None: - self._controller = controller - def _init_pages(self): def config(): diff --git a/gooey/gui/windows/sidebar.py b/gooey/gui/windows/sidebar.py index b12a2be..47f00a1 100644 --- a/gooey/gui/windows/sidebar.py +++ b/gooey/gui/windows/sidebar.py @@ -14,8 +14,6 @@ class Sidebar(wx.Panel): self._parent = parent - self._controller = None - self._init_components() self._do_layout()