Browse Source

More pubsub changes. Added title section to subparser configs. New layout options

pull/90/merge
chriskiehl 10 years ago
parent
commit
11aa02aa1c
10 changed files with 86 additions and 40 deletions
  1. 4
      gooey/gui/chooser_runner.py
  2. 4
      gooey/gui/component_builder.py
  3. 7
      gooey/gui/controller.py
  4. 3
      gooey/gui/events.py
  5. 7
      gooey/gui/util/wx_util.py
  6. 11
      gooey/gui/widgets/widget_pack.py
  7. 31
      gooey/gui/windows/advanced_config.py
  8. 11
      gooey/gui/windows/base_window.py
  9. 42
      gooey/gui/windows/layouts.py
  10. 6
      gooey/gui/windows/sidebar.py

4
gooey/gui/chooser_runner.py

@ -11,8 +11,8 @@ class MyFrame(wx.Frame):
self.SetBackgroundColour('#ffffff')
sizer = wx.BoxSizer(wx.VERTICAL)
f = CalendarChooser({'title':'cool title', 'help_msg':'cool help msg that is super long and intense andd has lots of words!', 'nargs': '+'})
sizer.Add(f.build(self), 0, wx.EXPAND)
f = wx.FileDialog(self, style=wx.FD_MULTIPLE | wx.FD_FILE_MUST_EXIST)
sizer.Add(f, 0, wx.EXPAND)
self.SetSizer(sizer)
if __name__ == '__main__':

4
gooey/gui/component_builder.py

@ -15,10 +15,10 @@ def build_components(widget_list):
Converts the Json widget information into concrete wx Widget types
'''
required_args, optional_args = partition(widget_list, is_required)
checkbox_args, general_args = partition(optional_args, is_checkbox)
checkbox_args, general_args = partition(map(build_widget, optional_args), is_checkbox)
required_args = map(build_widget, required_args)
optional_args = map(build_widget, general_args) + map(build_widget, checkbox_args)
optional_args = general_args + checkbox_args
return ComponentList(required_args, optional_args)

7
gooey/gui/controller.py

@ -67,6 +67,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()
self.run_client_code(command)
@ -96,8 +97,10 @@ class Controller(object):
return self.build_spec['manual_start']
def required_section_complete(self):
_required = self.core_gui.GetRequiredArgs()
return _required and not any(req == '' for req in _required)
required_section = self.core_gui.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)

3
gooey/gui/events.py

@ -14,5 +14,4 @@ WINDOW_CLOSE = new_id()
WINDOW_START = new_id()
WINDOW_RESTART = new_id()
PANEL_CHANGE = new_id()

7
gooey/gui/util/wx_util.py

@ -15,6 +15,13 @@ def dark_grey(statictext):
darkgray = (54, 54, 54)
statictext.SetForegroundColour(darkgray)
def h0(parent, label):
text = wx.StaticText(parent, label=label)
font_size = text.GetFont().GetPointSize()
font = wx.Font(font_size * 1.4, *(wx.FONTFAMILY_DEFAULT, wx.FONTWEIGHT_NORMAL, wx.FONTWEIGHT_BOLD, False))
text.SetFont(font)
return text
def h1(parent, label):
return _header(parent, label, (wx.FONTFAMILY_DEFAULT, wx.FONTWEIGHT_NORMAL, wx.FONTWEIGHT_BOLD, False))

11
gooey/gui/widgets/widget_pack.py

@ -65,7 +65,7 @@ class BaseChooser(WidgetPack):
if self.option_string and value:
return '{0} "{1}"'.format(self.option_string, value)
else:
return '"{}"'.format(value) if value else None
return '"{}"'.format(value) if value else ''
def onButton(self, evt):
raise NotImplementedError
@ -86,8 +86,6 @@ class BaseFileChooser(BaseChooser):
if dlg.ShowModal() == wx.ID_OK
else None)
if result:
# self.text_box references a field on the class this is passed into
# kinda hacky, but avoided a buncha boilerplate
self.text_box.SetValue(result)
@ -120,10 +118,11 @@ class TextInputPayload(WidgetPack):
return self.widget
def getValue(self):
if self.widget.GetValue() and self.option_string:
return '{} {}'.format(self.option_string, self.widget.GetValue())
value = self.widget.GetValue()
if value and self.option_string:
return '{} {}'.format(self.option_string, value)
else:
return self.widget.GetValue()
return '"{}"'.format(value) if value else ''
def _SetValue(self, text):
# used for testing

31
gooey/gui/windows/advanced_config.py

@ -4,33 +4,35 @@ Managed the internal layout for configuration options
@author: Chris
"""
import itertools
from itertools import chain
import wx
from wx.lib.scrolledpanel import ScrolledPanel
from itertools import chain, izip_longest
from gooey.gui.util import wx_util
from gooey.gui.lang import i18n
from gooey.gui import component_builder
from gooey.gui.option_reader import OptionReader
PADDING = 10
class AdvancedConfigPanel(ScrolledPanel, OptionReader):
class ConfigPanel(ScrolledPanel, OptionReader):
def __init__(self, parent, build_spec=None, **kwargs):
def __init__(self, parent, widgets=None, 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._build_spec = build_spec
self.widgets = component_builder.build_components(build_spec['widgets'])
self.title = title
self.widgets = component_builder.build_components(widgets)
self._msg_req_args = None
self._msg_opt_args = None
self._num_req_cols = req_cols
self._num_opt_cols = opt_cols
self._controller = None
@ -45,25 +47,28 @@ class AdvancedConfigPanel(ScrolledPanel, OptionReader):
container = wx.BoxSizer(wx.VERTICAL)
container.AddSpacer(15)
if self.title:
container.Add(wx_util.h0(self, self.title), 0, wx.LEFT | wx.RIGHT, PADDING)
container.AddSpacer(30)
if self.widgets.required_args:
container.Add(wx_util.h1(self, i18n._("required_args_msg")), 0, wx.LEFT | wx.RIGHT, PADDING)
container.AddSpacer(5)
container.Add(wx_util.horizontal_rule(self), *STD_LAYOUT)
container.AddSpacer(20)
self.CreateComponentGrid(container, self.widgets.required_args, cols=self._build_spec['requireds_cols'])
self.CreateComponentGrid(container, self.widgets.required_args, cols=self._num_req_cols)
container.AddSpacer(10)
if self.widgets.optional_args:
container.AddSpacer(10)
# container.AddSpacer(10)
container.Add(wx_util.h1(self, i18n._("optional_args_msg")), 0, wx.LEFT | wx.RIGHT, PADDING)
container.AddSpacer(5)
container.Add(wx_util.horizontal_rule(self), *STD_LAYOUT)
container.AddSpacer(20)
self.CreateComponentGrid(container, self.widgets.optional_args, cols=self._build_spec['optionals_cols'])
self.CreateComponentGrid(container, self.widgets.optional_args, cols=self._num_opt_cols)
self.SetSizer(container)
@ -100,7 +105,7 @@ class AdvancedConfigPanel(ScrolledPanel, OptionReader):
"itertools recipe: Collect data into fixed-length chunks or blocks"
# grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx
args = [iter(iterable)] * n
return itertools.izip_longest(fillvalue=fillvalue, *args)
return izip_longest(fillvalue=fillvalue, *args)
if __name__ == '__main__':
pass

11
gooey/gui/windows/base_window.py

@ -8,7 +8,7 @@ from wx.lib.pubsub import pub
from gooey.gui.controller import Controller
from gooey.gui.lang import i18n
from gooey.gui.windows.advanced_config import AdvancedConfigPanel
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.util import wx_util
@ -54,7 +54,9 @@ class BaseWindow(wx.Frame):
heading=i18n._("settings_title"),
subheading=_desc or '',
parent=self)
self.config_panel = AdvancedConfigPanel(self, self.build_spec)
# 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]
@ -65,8 +67,7 @@ class BaseWindow(wx.Frame):
sizer.Add(wx_util.horizontal_rule(self), 0, wx.EXPAND)
if self.build_spec['layout_type'] == 'column':
print 'hello!'
self.config_panel = layouts.ColumnLayout(self)
self.config_panel = layouts.ColumnLayout(self, build_spec=self.build_spec)
sizer.Add(self.config_panel, 1, wx.EXPAND)
else:
self.config_panel = layouts.FlatLayout(self, build_spec=self.build_spec)
@ -97,7 +98,7 @@ class BaseWindow(wx.Frame):
def registerControllers(self):
for panel in self.panels:
panel.RegisterController(self._controller)
pass
def GetOptions(self):
return self.config_panel.GetOptions()

42
gooey/gui/windows/layouts.py

@ -1,6 +1,9 @@
from collections import OrderedDict
import wx
from wx.lib.pubsub import pub
from gooey.gui.windows.advanced_config import AdvancedConfigPanel
from gooey.gui import events
from gooey.gui.windows.advanced_config import ConfigPanel
from gooey.gui.windows.sidebar import Sidebar
from gooey.gui.util import wx_util
@ -25,7 +28,7 @@ class FlatLayout(wx.Panel):
super(FlatLayout, self).__init__(*args, **kwargs)
self.SetDoubleBuffered(True)
self.main_content = AdvancedConfigPanel(self, build_spec=self._build_spec)
self.main_content = ConfigPanel(self, widgets=self._build_spec['widgets'], opt_cols=self._build_spec['num_optional_cols'])
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(self.main_content, 3, wx.EXPAND)
@ -40,19 +43,46 @@ class FlatLayout(wx.Panel):
class ColumnLayout(wx.Panel):
def __init__(self, *args, **kwargs):
self._build_spec = kwargs.pop('build_spec')
super(ColumnLayout, self).__init__(*args, **kwargs)
self.SetDoubleBuffered(True)
self.sidebar = Sidebar(self, contents=['one', 'two', 'three', 'four', 'five'])
self.main_content = AdvancedConfigPanel(self)
self.sidebar = Sidebar(self, contents=self._build_spec['widgets'].keys())
sizer = wx.BoxSizer(wx.HORIZONTAL)
self.config_panels = self.build_panels(self._build_spec)
self.active_panel = self.config_panels.keys()[0]
self.config_panels[self.active_panel].Show()
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(self.sidebar, 1, wx.EXPAND)
sizer.Add(wx_util.vertical_rule(self), 0, wx.EXPAND)
sizer.Add(self.main_content, 3, wx.EXPAND)
for panel in self.config_panels.values():
sizer.Add(panel, 3, wx.EXPAND)
self.SetSizer(sizer)
pub.subscribe(self.load_view, events.PANEL_CHANGE)
def load_view(self, view_name):
self.config_panels[self.active_panel].Hide()
self.config_panels[view_name].Show()
self.active_panel = view_name
self.Layout()
def build_panels(self, build_spec):
panels = OrderedDict()
for panel_name in self._build_spec['widgets'].keys():
panel = ConfigPanel(self, widgets=self._build_spec['widgets'][panel_name], opt_cols=self._build_spec['num_optional_cols'], title=panel_name.upper())
panels[panel_name] = panel
panel.Hide()
return panels
def GetOptions(self):
return '{} {}'.format(self.active_panel, self.config_panels[self.active_panel].GetOptions())
def GetRequiredArgs(self):
return self.config_panels[self.active_panel].GetRequiredArgs()
def get_layout_builder(layout_type):
if layout_type == 'column':

6
gooey/gui/windows/sidebar.py

@ -1,5 +1,6 @@
import wx
from wx.lib.pubsub import pub
from gooey.gui import events
from gooey.gui.util import wx_util
@ -33,13 +34,14 @@ class Sidebar(wx.Panel):
container.AddSpacer(15)
container.Add(wx_util.h1(self, 'Actions'), *STD_LAYOUT)
container.AddSpacer(5)
thing = wx.ListBox(self, -1, choices=['Connect', 'process', 'commit', 'fetch'])
thing = wx.ListBox(self, -1, choices=self.contents)
container.Add(thing, 1, wx.LEFT | wx.RIGHT | wx.EXPAND, 10)
container.AddSpacer(20)
self.SetSizer(container)
thing.SetSelection(0)
self.Bind(wx.EVT_LISTBOX, self.onClick, thing)
def onClick(self, evt):
pub.sendMessage("panelListener", message=evt.GetString())
pub.sendMessage(events.PANEL_CHANGE, view_name=evt.GetString())
evt.Skip()
Loading…
Cancel
Save