diff --git a/gooey/gui/controller.py b/gooey/gui/controller.py index 912f958..68afae8 100644 --- a/gooey/gui/controller.py +++ b/gooey/gui/controller.py @@ -13,7 +13,7 @@ from wx.lib.pubsub import pub from multiprocessing.dummy import Pool from gooey.gui import events from gooey.gui.lang import i18n - +from gooey.gui.windows import views YES = 5103 NO = 5104 @@ -40,6 +40,10 @@ class Controller(object): pub.subscribe(self.on_start, events.WINDOW_START) pub.subscribe(self.on_restart, events.WINDOW_RESTART) pub.subscribe(self.on_close, events.WINDOW_CLOSE) + pub.subscribe(self.on_edit, events.WINDOW_EDIT) + + def on_edit(self): + pub.sendMessage(events.WINDOW_CHANGE, view_name=views.CONFIG_SCREEN) def on_close(self): self.core_gui.Destroy() @@ -67,8 +71,7 @@ class Controller(object): cmd_line_args = self.core_gui.GetOptions() command = '{0} {1}'.format(self.build_spec['target'], cmd_line_args) - print command - self.core_gui.NextPage() + pub.sendMessage(events.WINDOW_CHANGE, view_name=views.RUNNING_SCREEN) self.run_client_code(command) def run_client_code(self, command): @@ -87,10 +90,10 @@ class Controller(object): def process_result(self, process): _stdout, _stderr = process.communicate() if process.returncode == 0: - self.core_gui.NextPage() + pub.sendMessage(events.WINDOW_CHANGE, view_name=views.SUCCESS_SCREEN) self.success_dialog() else: - self.core_gui.NextPage() + pub.sendMessage(events.WINDOW_CHANGE, view_name=views.ERROR_SCREEN) self.error_dialog(_stderr) def skipping_config(self): diff --git a/gooey/gui/events.py b/gooey/gui/events.py index 0c7cefd..7d21ec1 100644 --- a/gooey/gui/events.py +++ b/gooey/gui/events.py @@ -13,5 +13,7 @@ WINDOW_CANCEL = new_id() WINDOW_CLOSE = new_id() WINDOW_START = new_id() WINDOW_RESTART = new_id() +WINDOW_EDIT = new_id() +WINDOW_CHANGE = new_id() PANEL_CHANGE = new_id() diff --git a/gooey/gui/windows/base_window.py b/gooey/gui/windows/base_window.py index 6ca8cad..2d21b3e 100644 --- a/gooey/gui/windows/base_window.py +++ b/gooey/gui/windows/base_window.py @@ -10,7 +10,7 @@ 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 -from gooey.gui import image_repository +from gooey.gui import image_repository, events from gooey.gui.util import wx_util from gooey.gui.windows import footer, header, layouts @@ -36,6 +36,7 @@ class BaseWindow(wx.Frame): self._init_properties() self._init_components() self._do_layout() + self._init_pages() self._init_controller() self.registerControllers() self.Bind(wx.EVT_SIZE, self.onResize) @@ -55,8 +56,6 @@ class BaseWindow(wx.Frame): subheading=_desc or '', parent=self) - # self.config_panel = AdvancedConfigPanel(self, self.build_spec) - self.runtime_display = RuntimeDisplay(self) self.foot_panel = footer.Footer(self) self.panels = [self.head_panel, self.config_panel, self.foot_panel] @@ -83,6 +82,9 @@ class BaseWindow(wx.Frame): self.sizer = sizer pub.subscribe(self.myListener, "panelListener") + pub.subscribe(self.load_view, events.WINDOW_CHANGE) + + def myListener(self, message): print message @@ -90,9 +92,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) @@ -110,12 +109,27 @@ class BaseWindow(wx.Frame): return self.config_panel.GetOptionalArgs() - def NextPage(self): - self.head_panel.NextPage() - self.foot_panel.NextPage() - self.config_panel.Hide() - self.runtime_display.Show() - self.Layout() + def _init_pages(self): + + def config(): + self.config_panel.Show() + self.runtime_display.Hide() + + def running(): + self.config_panel.Hide() + self.runtime_display.Show() + self.Layout() + + def success(): + running() + + def error(): + running() + + self.layouts = locals() + + def load_view(self, view_name=None): + self.layouts.get(view_name, lambda: None)() def ManualStart(self): self._controller.manual_restart() diff --git a/gooey/gui/windows/footer.py b/gooey/gui/windows/footer.py index 2af1bc9..c821ea6 100644 --- a/gooey/gui/windows/footer.py +++ b/gooey/gui/windows/footer.py @@ -33,10 +33,14 @@ class AbstractFooter(wx.Panel): self.restart_button = None self.buttons = None + self.layouts = {} + self._init_components() self._init_pages() self._do_layout() + pub.subscribe(self.load_view, events.WINDOW_CHANGE) + def _init_components(self): self.cancel_button = self.button(i18n._('cancel'), wx.ID_CANCEL, event_id=int(events.WINDOW_CANCEL)) @@ -44,31 +48,46 @@ class AbstractFooter(wx.Panel): self.start_button = self.button(i18n._('start'), wx.ID_OK, event_id=int(events.WINDOW_START)) self.close_button = self.button(i18n._("close"), wx.ID_OK, event_id=int(events.WINDOW_CLOSE)) self.restart_button = self.button(i18n._('restart'), wx.ID_OK, event_id=int(events.WINDOW_RESTART)) + self.edit_button = self.button(i18n._('edit'), wx.ID_OK, event_id=int(events.WINDOW_EDIT)) + self.running_animation = wx.animate.GIFAnimationCtrl(self, -1, image_repository.loader) - self.buttons = [self.cancel_button, self.start_button, self.stop_button, self.close_button, self.restart_button] + self.buttons = [self.cancel_button, self.start_button, self.stop_button, self.close_button, self.restart_button, self.edit_button] def _init_pages(self): - if self.restart_button.IsShown(): self.restart_button.Hide() - if self.close_button.IsShown(): self.close_button.Hide() + def config(): + self.hide_all_buttons() + self.cancel_button.Show() + self.start_button.Show() + self.running_animation.Stop() + self.Layout() - def PageOne(): - self.cancel_button.Hide() - self.start_button.Hide() + def running(): + self.hide_all_buttons() self.running_animation.Show() self.running_animation.Play() self.Layout() - def PageTwo(): + def success(): + self.hide_all_buttons() self.running_animation.Stop() self.running_animation.Hide() + self.edit_button.Show() self.restart_button.Show() self.close_button.Show() - self.restart_button.Show() self.Layout() - self._pages = iter([PageOne, PageTwo]) + def error(): + success() + + self.layouts = locals() + def load_view(self, view_name=None): + self.layouts.get(view_name, lambda: None)() + + def hide_all_buttons(self): + for button in self.buttons: + button.Hide() def _do_layout(self): self.stop_button.Hide() @@ -86,8 +105,10 @@ class AbstractFooter(wx.Panel): v_sizer.Add(self.running_animation, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.RIGHT, 20) self.running_animation.Hide() - v_sizer.Add(self.restart_button, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.RIGHT, 20) - v_sizer.Add(self.close_button, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.RIGHT, 20) + h_sizer.Add(self.edit_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 10) + h_sizer.Add(self.restart_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 10) + h_sizer.Add(self.close_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20) + self.edit_button.Hide() self.restart_button.Hide() self.close_button.Hide() @@ -106,13 +127,6 @@ class AbstractFooter(wx.Panel): if self._controller is None: self._controller = controller - def NextPage(self): - try: - next(self._pages)() - except: - self._init_pages() - next(self._pages)() - 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 7dd0c87..8a3b5bb 100644 --- a/gooey/gui/windows/header.py +++ b/gooey/gui/windows/header.py @@ -5,8 +5,9 @@ Created on Dec 23, 2013 ''' import wx +from wx.lib.pubsub import pub -from gooey.gui import imageutil, image_repository +from gooey.gui import imageutil, image_repository, events from gooey.gui.util import wx_util from gooey.gui.lang import i18n @@ -16,22 +17,27 @@ PAD_SIZE = 10 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 + self._header = None self._subheader = None self._settings_img = None self._running_img = None self._check_mark = None + self.layouts = {} + self._init_properties() self._init_components(heading, subheading) self._init_pages() self._do_layout() + pub.subscribe(self.load_view, events.WINDOW_CHANGE) def _init_properties(self): self.SetBackgroundColour('#ffffff') @@ -78,7 +84,15 @@ class FrameHeader(wx.Panel): def _init_pages(self): - def PageOne(): + def config(): + self._header.SetLabel(self.heading_msg) + self._subheader.SetLabel(self.subheading_msg) + self._settings_img.Show() + self._check_mark.Hide() + self._running_img.Hide() + self.Layout() + + def running(): self._header.SetLabel(i18n._("running_title")) self._subheader.SetLabel(i18n._('running_msg')) self._check_mark.Hide() @@ -86,18 +100,18 @@ class FrameHeader(wx.Panel): self._running_img.Show() self.Layout() - def PageTwo(): + def success(): self._header.SetLabel(i18n._('finished_title')) self._subheader.SetLabel(i18n._('finished_msg')) self._running_img.Hide() self._check_mark.Show() self.Layout() - self._pages = iter([PageOne, PageTwo]) + def error(): + success() + + self.layouts = locals() + + def load_view(self, view_name=None): + self.layouts.get(view_name, lambda: None)() - def NextPage(self): - try: - next(self._pages)() - except: - self._init_pages() - next(self._pages)() diff --git a/gooey/gui/windows/views.py b/gooey/gui/windows/views.py new file mode 100644 index 0000000..941e5ce --- /dev/null +++ b/gooey/gui/windows/views.py @@ -0,0 +1,6 @@ + + +CONFIG_SCREEN = 'config' +RUNNING_SCREEN = 'running' +SUCCESS_SCREEN = 'success' +ERROR_SCREEN = 'error' diff --git a/gooey/languages/english.json b/gooey/languages/english.json index 4c0d41a..3b1dc48 100644 --- a/gooey/languages/english.json +++ b/gooey/languages/english.json @@ -17,6 +17,7 @@ "stop": "Stop", "status": "Status", "restart": "Restart", + "edit": "Edit", "success_message": "Program completed Sucessfully!\nPress the OK button to exit", "sure_you_want_to_exit": "Are you sure you want to exit?", "uh_oh": "\nUh oh! Looks like there was a problem. \nCopy the below error to let your developer know what went wrong.\n\n{} \t\t\n\t\t"