diff --git a/gooey/gui/controller.py b/gooey/gui/controller.py index ce6ae45..c31841c 100644 --- a/gooey/gui/controller.py +++ b/gooey/gui/controller.py @@ -3,9 +3,6 @@ from gooey.gui.presenter import Presenter from gooey.gui.windows.base_window import BaseWindow -YES = 5103 -NO = 5104 - class Controller(object): def __init__(self, build_spec): diff --git a/gooey/gui/message_event.py b/gooey/gui/message_event.py deleted file mode 100644 index 46493c0..0000000 --- a/gooey/gui/message_event.py +++ /dev/null @@ -1,5 +0,0 @@ -import wx -import wx.lib.newevent - -MessageEvent, EVT_MSG = wx.lib.newevent.NewEvent() - diff --git a/gooey/gui/widgets/components.py b/gooey/gui/widgets/components.py index f7bcbf7..251d35c 100644 --- a/gooey/gui/widgets/components.py +++ b/gooey/gui/widgets/components.py @@ -105,13 +105,6 @@ class BaseGuiComponent(object): if val: self.widget_pack.widget.SetValue(str(val)) - # def HasOptionString(self): - # return bool(self.widget_pack.option_string) - # - # def _GetWidget(self): - # # used only for unittesting - # return self.widget_pack.widget - def __repr__(self): return self.__class__.__name__ @@ -162,22 +155,10 @@ class CheckBox(BaseGuiComponent): self.widget.SetValue(val) - # def GetValue(self): - # return self.option_strings if self.widget.GetValue() else '' - # - # def HasOptionString(self): - # return bool(self.option_strings) - # - # def _GetWidget(self): - # return self.widget - - class RadioGroup(object): def __init__(self, parent, title, msg): self.panel = None - # self.data = data - self.radio_buttons = [] self.option_strings = [] self.help_msgs = [] @@ -207,7 +188,6 @@ class RadioGroup(object): vertical_container.Add(help, 1, wx.EXPAND | wx.LEFT, 25) vertical_container.AddSpacer(5) - # self.panel.Bind(wx.EVT_RADIOBUTTON, self.onSetter, button) self.panel.SetSizer(vertical_container) self.panel.Bind(wx.EVT_SIZE, self.onResize) @@ -235,18 +215,6 @@ class RadioGroup(object): def set_value(self, val): pass - # def GetValue(self): - # vals = [button.GetValue() for button in self.radio_buttons] - # try: - # return self.option_strings[vals.index(True)][0] - # except: - # return '' - - def HasOptionString(self): - return bool(self.option_strings) - - def _GetWidget(self): - return self.radio_buttons def build_subclass(name, widget_class): @@ -265,7 +233,3 @@ Dropdown = build_subclass('Dropdown', widget_pack.DropdownPayload) Counter = build_subclass('Counter', widget_pack.CounterPayload) MultiDirChooser = build_subclass('MultiDirChooser', widget_pack.MultiDirChooserPayload) -if __name__ == '__main__': - - DirChooser = type('DirChooser', (BaseGuiComponent,), {'widget_pack': widget_pack.DirChooserPayload }) - d = DirChooser() diff --git a/gooey/gui/widgets/widget_pack.py b/gooey/gui/widgets/widget_pack.py index d5d07a0..b5d2bfb 100644 --- a/gooey/gui/widgets/widget_pack.py +++ b/gooey/gui/widgets/widget_pack.py @@ -1,16 +1,11 @@ -from functools import partial -from gooey.gui.lang import i18n -from gooey.gui.util.filedrop import FileDrop -from gooey.gui.util.quoting import quote - -__author__ = 'Chris' - -from abc import ABCMeta, abstractmethod - import os import wx + import wx.lib.agw.multidirdialog as MDD +from abc import ABCMeta, abstractmethod +from gooey.gui.lang import i18n +from gooey.gui.util.filedrop import FileDrop from gooey.gui.widgets.calender_dialog import CalendarDlg @@ -63,22 +58,11 @@ class BaseChooser(WidgetPack): widget_sizer.AddSpacer(10) widget_sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL) - parent.Bind(wx.EVT_BUTTON, self.onButton, self.button) return widget_sizer def get_value(self): return self.widget.GetValue() - # def getValue(self): - # value = self.widget.GetValue() - # if self.option_string and value: - # return '{0} {1}'.format(self.option_string, quote(value)) - # else: - # return quote(value) if value else '' - # - # def onButton(self, evt): - # raise NotImplementedError - def __repr__(self): return self.__class__.__name__ @@ -105,12 +89,6 @@ class BaseMultiFileChooser(BaseFileChooser): BaseFileChooser.__init__(self) self.dialog = dialog - # def getValue(self): - # value = ' '.join(quote(x) for x in self.widget.GetValue().split(os.pathsep) if x) - # if self.option_string and value: - # return '{} {}'.format(self.option_string, value) - # return value or '' - def get_path(self, dlg): return os.pathsep.join(dlg.GetPaths()) @@ -135,7 +113,6 @@ class MultiDirChooserPayload(BaseMultiFileChooser): BaseMultiFileChooser.__init__(self, MultiDirChooserPayload.MyMultiDirChooser) - class TextInputPayload(WidgetPack): def __init__(self, no_quoting=False): self.widget = None @@ -157,22 +134,6 @@ class TextInputPayload(WidgetPack): def get_value(self): return self.widget.GetValue() - # def getValue(self): - # if self.no_quoting: - # _quote = lambda value: value - # else: - # _quote = quote - # value = self.widget.GetValue() - # if value and self.option_string: - # return '{} {}'.format(self.option_string, _quote(value)) - # else: - # return _quote(value) if value else '' - # - # def _SetValue(self, text): - # # used for testing - # self.widget.SetLabelText(text) - - class DropdownPayload(WidgetPack): default_value = 'Select Option' @@ -197,22 +158,9 @@ class DropdownPayload(WidgetPack): def get_value(self): return self.widget.GetValue() - # def getValue(self): - # if self.no_quoting: - # _quote = lambda value: value - # else: - # _quote = quote - # value = self.widget.GetValue() - # if value == self.default_value: - # return '' - # elif value and self.option_string: - # return '{} {}'.format(self.option_string, _quote(value)) - # else: - # return _quote(value) if value else '' - - def _SetValue(self, text): - # used for testing - self.widget.SetLabelText(text) + def set_value(self, text): + # TODO: can we set dropdowns this way? + self.widget.SetValue(text) class CounterPayload(WidgetPack): @@ -234,41 +182,12 @@ class CounterPayload(WidgetPack): def get_value(self): return self.widget.GetValue() - # def getValue(self): - # ''' - # Returns - # str(option_string * DropDown Value) - # e.g. - # -vvvvv - # ''' - # return self.widget.GetValue() - # if not str(dropdown_value).isdigit(): - # return '' - # arg = str(self.option_string).replace('-', '') - # repeated_args = arg * int(dropdown_value) - # return '-' + repeated_args - - # def getValue(self): - # ''' - # Returns - # str(option_string * DropDown Value) - # e.g. - # -vvvvv - # ''' - # dropdown_value = self.widget.GetValue() - # if not str(dropdown_value).isdigit(): - # return '' - # arg = str(self.option_string).replace('-', '') - # repeated_args = arg * int(dropdown_value) - # return '-' + repeated_args - class DirDialog(wx.DirDialog): def __init__(self, parent, *args, **kwargs): wx.DirDialog.__init__(self, parent, 'Select Directory', style=wx.DD_DEFAULT_STYLE) + def safe_default(data, default): - # str(None) is 'None'!? Whaaaaat...? - # return str(data['default']) if data['default'] else default return '' def build_dialog(style, exist_constraint=True, **kwargs): @@ -277,10 +196,10 @@ def build_dialog(style, exist_constraint=True, **kwargs): else: return lambda panel: wx.FileDialog(panel, style=style, **kwargs) - def build_subclass(subclass, dialog): return type(subclass, (BaseFileChooser,), {'dialog': dialog}) + FileSaverPayload = build_subclass('FileSaverPayload', staticmethod(build_dialog(wx.FD_SAVE, False, defaultFile="Enter Filename"))) FileChooserPayload = build_subclass('FileChooserPayload', staticmethod(build_dialog(wx.FD_OPEN))) DirChooserPayload = build_subclass('DirChooserPayload', DirDialog) diff --git a/gooey/gui/windows/advanced_config.py b/gooey/gui/windows/advanced_config.py index ef354d3..c5b831e 100644 --- a/gooey/gui/windows/advanced_config.py +++ b/gooey/gui/windows/advanced_config.py @@ -17,6 +17,9 @@ PADDING = 10 class WidgetContainer(wx.Panel): + ''' + Collection of widgets + ''' def __init__(self, parent, section_name, *args, **kwargs): wx.Panel.__init__(self, parent, *args, **kwargs) self.section_name = section_name @@ -30,13 +33,9 @@ class WidgetContainer(wx.Panel): for index, widget in enumerate(widgets): widget_class = getattr(components, widget.type) widget_instance = widget_class(self, widget.title, widget.help) - # widget_instance.bind(wx.EVT_TEXT, self.publish_change) self.widgets.append(widget_instance) self.layout() - def publish_change(self, evt): - evt.Skip() - def get_values(self): return [x.get_value() for x in self.widgets] @@ -65,7 +64,6 @@ class WidgetContainer(wx.Panel): def chunk(self, iterable, n, fillvalue=None): "itertools recipe: Collect data into fixed-length chunks or blocks" - # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx args = [iter(iterable)] * n return izip_longest(fillvalue=fillvalue, *args) @@ -78,19 +76,15 @@ class ConfigPanel(ScrolledPanel): def __init__(self, parent, req_cols=1, opt_cols=3, title=None, **kwargs): ScrolledPanel.__init__(self, parent, **kwargs) self.SetupScrolling(scroll_x=False, scrollToTop=False) - self.SetDoubleBuffered(True) self.title = title - self._num_req_cols = req_cols self._num_opt_cols = opt_cols - self.required_section = WidgetContainer(self, i18n._("required_args_msg")) self.optional_section = WidgetContainer(self, i18n._("optional_args_msg")) self._do_layout() - self.Bind(wx.EVT_SIZE, self.OnResize) @@ -101,26 +95,9 @@ class ConfigPanel(ScrolledPanel): container.AddSpacer(15) container.Add(self.required_section, *STD_LAYOUT) container.Add(self.optional_section, *STD_LAYOUT) - self.SetSizer(container) def OnResize(self, evt): self.SetupScrolling(scroll_x=False, scrollToTop=False) evt.Skip() - def GetOptions(self): - """ - returns the collective values from all of the - widgets contained in the panel""" - _f = lambda lst: [x for x in lst if x is not None] - optional_args = _f([c.GetValue() for c in self.widgets.optional_args]) - required_args = _f([c.GetValue() for c in self.widgets.required_args if c.HasOptionString()]) - position_args = _f([c.GetValue() for c in self.widgets.required_args if not c.HasOptionString()]) - if position_args: position_args.insert(0, "--") - return ' '.join(chain(required_args, optional_args, position_args)) - - def GetRequiredArgs(self): - return [arg.GetValue() for arg in self.widgets.required_args] - -if __name__ == '__main__': - pass diff --git a/gooey/gui/windows/base_window.py b/gooey/gui/windows/base_window.py index 41a3872..62529e1 100644 --- a/gooey/gui/windows/base_window.py +++ b/gooey/gui/windows/base_window.py @@ -4,23 +4,24 @@ Created on Jan 19, 2014 ''' import sys -from distutils import config import wx -from gooey.gui.pubsub import pub -from gooey.gui.lang.i18n import _ -from gooey.gui.windows.advanced_config import ConfigPanel -from gooey.gui.windows.runtime_display_panel import RuntimeDisplay from gooey.gui import image_repository, events +from gooey.gui.lang.i18n import _ +from gooey.gui.pubsub import pub from gooey.gui.util import wx_util from gooey.gui.windows import footer, header, layouts - +from gooey.gui.windows.runtime_display_panel import RuntimeDisplay YES = 5103 NO = 5104 class BaseWindow(wx.Frame): + ''' + Primary Frame under which all sub-Panels are organized. + ''' + def __init__(self, layout_type): wx.Frame.__init__(self, parent=None, id=-1) @@ -40,11 +41,10 @@ class BaseWindow(wx.Frame): self._init_properties() self._init_components() self._do_layout() - # self._init_pages() + self.Bind(wx.EVT_SIZE, self.onResize) self.Bind(wx.EVT_CLOSE, self.onClose) - @property def window_size(self): return self.GetSize() @@ -90,22 +90,11 @@ class BaseWindow(wx.Frame): return self.foot_panel.progress_bar def set_display_font_style(self, style): - ''' - wx.FONTFAMILY_DEFAULT Chooses a default font. - wx.FONTFAMILY_DECORATIVE A decorative font. - wx.FONTFAMILY_ROMAN A formal, serif font. - wx.FONTFAMILY_SCRIPT A handwriting font. - wx.FONTFAMILY_SWISS A sans-serif font. - wx.FONTFAMILY_MODERN Usually a fixed pitch font. - wx.FONTFAMILY_TELETYPE A teletype font. - ''' # TODO: make this not stupid # TODO: _actual_ font support self.runtime_display.set_font_style( wx.MODERN if style == 'monospace' else wx.DEFAULT) - - def _init_properties(self): # self.SetTitle(self.build_spec['program_name']) # self.SetSize(self.build_spec['default_size']) @@ -113,6 +102,33 @@ class BaseWindow(wx.Frame): self.icon = wx.Icon(image_repository.program_icon, wx.BITMAP_TYPE_ICO) self.SetIcon(self.icon) + def _init_components(self): + self.runtime_display = RuntimeDisplay(self) + self.head_panel = header.FrameHeader(parent=self) + self.foot_panel = footer.Footer(self) + self.panels = [self.head_panel, self.config_panel, self.foot_panel] + + def _do_layout(self): + sizer = wx.BoxSizer(wx.VERTICAL) + sizer.Add(self.head_panel, 0, wx.EXPAND) + sizer.Add(wx_util.horizontal_rule(self), 0, wx.EXPAND) + + if self.layout_type == layouts.COLUMN: + self.config_panel = layouts.ColumnLayout(self) + else: + self.config_panel = layouts.FlatLayout(self) + + sizer.Add(self.config_panel, 1, wx.EXPAND) + + sizer.Add(self.runtime_display, 1, wx.EXPAND) + + self.runtime_display.Hide() + sizer.Add(wx_util.horizontal_rule(self), 0, wx.EXPAND) + sizer.Add(self.foot_panel, 0, wx.EXPAND) + self.SetSizer(sizer) + + self.sizer = sizer + def enable_stop_button(self): self.foot_panel.stop_button.Enable() @@ -150,84 +166,12 @@ class BaseWindow(wx.Frame): def hide_all_buttons(self): self.foot_panel.hide_all_buttons() - def _init_components(self): - # init gui - # _desc = self.build_spec['program_description'] - # self.head_panel = header.FrameHeader( - # heading=_("settings_title"), - # subheading=_desc or '', - # parent=self) - self.runtime_display = RuntimeDisplay(self) - self.head_panel = header.FrameHeader(parent=self) - self.foot_panel = footer.Footer(self) - - # if self.build_spec['disable_stop_button']: - # self.foot_panel.stop_button.Disable() - # else: - # self.foot_panel.stop_button.Enable() - - self.panels = [self.head_panel, self.config_panel, self.foot_panel] - - def _do_layout(self): - sizer = wx.BoxSizer(wx.VERTICAL) - sizer.Add(self.head_panel, 0, wx.EXPAND) - sizer.Add(wx_util.horizontal_rule(self), 0, wx.EXPAND) - - if self.layout_type == layouts.COLUMN: - self.config_panel = layouts.ColumnLayout(self) - else: - self.config_panel = layouts.FlatLayout(self) - - sizer.Add(self.config_panel, 1, wx.EXPAND) - - sizer.Add(self.runtime_display, 1, wx.EXPAND) - - self.runtime_display.Hide() - sizer.Add(wx_util.horizontal_rule(self), 0, wx.EXPAND) - sizer.Add(self.foot_panel, 0, wx.EXPAND) - self.SetSizer(sizer) - - self.sizer = sizer - - def GetOptions(self): - return self.config_panel.GetOptions() - - def GetRequiredArgs(self): - return self.config_panel.GetRequiredArgs() - - def GetOptionalArgs(self): - return self.config_panel.GetOptionalArgs() - - def update_console_async(self, msg): - wx.CallAfter(self.PublishConsoleMsg, msg) + wx.CallAfter(self.runtime_display.append_text, msg) def update_progress_aync(self, progress): wx.CallAfter(self.UpdateProgressBar, progress) - - # 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 onResize(self, evt): evt.Skip() @@ -236,9 +180,6 @@ class BaseWindow(wx.Frame): evt.Veto() pub.send_message(str(events.WINDOW_CLOSE)) - def PublishConsoleMsg(self, text): - self.runtime_display.append_text(text) - def UpdateProgressBar(self, value): pb = self.foot_panel.progress_bar if value < 0: diff --git a/gooey/gui/windows/footer.py b/gooey/gui/windows/footer.py index 463b8ac..9f2d239 100644 --- a/gooey/gui/windows/footer.py +++ b/gooey/gui/windows/footer.py @@ -39,11 +39,8 @@ class Footer(wx.Panel): self.layouts = {} self._init_components() - # self._init_pages() self._do_layout() - # pub.subscribe(self.load_view, events.WINDOW_CHANGE) - for button in self.buttons: self.Bind(wx.EVT_BUTTON, self.dispatch_click, button) @@ -62,44 +59,6 @@ class Footer(wx.Panel): self.stop_button, self.close_button, self.restart_button, self.edit_button] - def dispatch_click(self, event): - pub.send_message(str(event.GetId())) - event.Skip() - - # def _init_pages(self): - # def config(): - # self.hide_all_buttons() - # self.cancel_button.Show() - # self.start_button.Show() - # self.Layout() - # - # def running(): - # self.hide_all_buttons() - # self.stop_button.Show() - # self.progress_bar.Show() - # self.progress_bar.Pulse() - # self.Layout() - # - # def success(): - # self.hide_all_buttons() - # self.progress_bar.Hide() - # self.edit_button.Show() - # self.restart_button.Show() - # self.close_button.Show() - # self.Layout() - # - # 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() self.restart_button.Hide() @@ -136,6 +95,14 @@ class Footer(wx.Panel): label=label, style=style) + def dispatch_click(self, event): + pub.send_message(str(event.GetId())) + event.Skip() + + def hide_all_buttons(self): + for button in self.buttons: + button.Hide() + 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 eeae22f..fa17e2d 100644 --- a/gooey/gui/windows/header.py +++ b/gooey/gui/windows/header.py @@ -5,11 +5,9 @@ Created on Dec 23, 2013 ''' import wx -from gooey.gui.pubsub import pub -from gooey.gui import imageutil, image_repository, events +from gooey.gui import imageutil, image_repository from gooey.gui.util import wx_util -from gooey.gui.lang import i18n PAD_SIZE = 10 @@ -27,16 +25,10 @@ class FrameHeader(wx.Panel): self.check_mark = None self.error_symbol = None - # self.layouts = {} - self._init_properties() - # self._init_components(heading, subheading) self._init_components() - # self._init_pages() self._do_layout() - # pub.subscribe(self.load_view, events.WINDOW_CHANGE) - @property def title(self): return self._header.GetLabel() @@ -94,42 +86,3 @@ class FrameHeader(wx.Panel): sizer.AddStretchSpacer(1) return sizer - # def _init_pages(self): - # - # 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.error_symbol.Hide() - # self.Layout() - # - # def running(): - # self._header.SetLabel(i18n._("running_title")) - # self._subheader.SetLabel(i18n._('running_msg')) - # self.check_mark.Hide() - # self.settings_img.Hide() - # self.running_img.Show() - # self.error_symbol.Hide() - # self.Layout() - # - # def success(): - # self._header.SetLabel(i18n._('finished_title')) - # self._subheader.SetLabel(i18n._('finished_msg')) - # self.running_img.Hide() - # self.check_mark.Show() - # self.Layout() - # - # def error(): - # self._header.SetLabel(i18n._('finished_title')) - # self._subheader.SetLabel(i18n._('finished_error')) - # self.running_img.Hide() - # self.error_symbol.Show() - # self.Layout() - # - # self.layouts = locals() - # - # def load_view(self, view_name=None): - # self.layouts.get(view_name, lambda: None)() - diff --git a/gooey/python_bindings/config_generator.py b/gooey/python_bindings/config_generator.py index ab6a3cb..c03098b 100644 --- a/gooey/python_bindings/config_generator.py +++ b/gooey/python_bindings/config_generator.py @@ -6,7 +6,7 @@ from gooey.gui.util.quoting import quote def create_from_parser(parser, source_path, **kwargs): - show_config = kwargs.get('show_config', False) + auto_start = kwargs.get('auto_start', False) if hasattr(sys, 'frozen'): run_cmd = quote(source_path) @@ -35,13 +35,10 @@ def create_from_parser(parser, source_path, **kwargs): 'group_by_type': kwargs.get('group_by_type', True) } - if show_config: + if not auto_start: build_spec['program_description'] = parser.description or build_spec['program_description'] layout_data = argparse_to_json.convert(parser) if build_spec['show_advanced'] else layouts.basic_config.items() build_spec.update(layout_data) - else: - build_spec['manual_start'] = True - return build_spec