Browse Source

Added layout manager shell for subparsers. Converted core gui components to work with new data schema

subparsing
chriskiehl 9 years ago
parent
commit
b00ba13c44
8 changed files with 180 additions and 42 deletions
  1. 6
      gooey/gui/application.py
  2. 30
      gooey/gui/commands.py
  3. 6
      gooey/gui/routes.py
  4. 45
      gooey/gui/windows/advanced_config.py
  5. 41
      gooey/gui/windows/base_window.py
  6. 47
      gooey/gui/windows/layouts.py
  7. 2
      gooey/gui/windows/runtime_display_panel.py
  8. 45
      gooey/gui/windows/sidebar.py

6
gooey/gui/application.py

@ -14,7 +14,6 @@ from gooey.gui.lang import i18n
from gooey.gui.windows.base_window import BaseWindow
from gooey.gui.windows.advanced_config import AdvancedConfigPanel
# C:\Users\Chris\Dropbox\pretty_gui\Gooey\gooey\gui\application.py
from gooey.python_bindings import config_generator, source_parser
@ -75,10 +74,7 @@ def run(build_spec):
i18n.load(build_spec['language'])
BodyPanel = partial(AdvancedConfigPanel, build_spec=build_spec)
frame = BaseWindow(BodyPanel, build_spec)
frame = BaseWindow(build_spec)
frame.Show(True)
app.MainLoop()

30
gooey/gui/commands.py

@ -0,0 +1,30 @@
import itertools
import docopt
from gooey.python_bindings import argparse_to_json
class Required(object):
def __init__(self, id):
class Optional(object):
pass
parser = []
command_list = CommandList(argparse_to_json.convert(parser))
print command_list.required_args
command_list['filter'].value = 123
command_list['compress'].value = True
if not command_list.is_valid():
raise "invalid"

6
gooey/gui/routes.py

@ -0,0 +1,6 @@
import wx
config = lambda self: self.Bind(wx.EVT_BUTTON, 'handler', id=wx.NewId())

45
gooey/gui/windows/advanced_config.py

@ -4,11 +4,9 @@ Managed the internal layout for configuration options
@author: Chris
"""
import wx
import itertools
from itertools import chain
from wx.lib.scrolledpanel import ScrolledPanel
from gooey.gui import styling
@ -29,23 +27,17 @@ class AdvancedConfigPanel(ScrolledPanel, OptionReader):
self.SetDoubleBuffered(True)
self._build_spec = build_spec
self._positionals = build_spec.get('required', None)
self.components = component_builder.ComponentBuilder(build_spec)
self.widgets = component_builder.build_components(build_spec['widgets'])
self._msg_req_args = None
self._msg_opt_args = None
self._controller = None
self._init_components()
self._do_layout()
self.Bind(wx.EVT_SIZE, self.OnResize)
self.Bind(wx.EVT_SIZE, self.OnResize)
def _init_components(self):
self._msg_req_args = (styling.H1(self, i18n.translate("required_args_msg"))
if self._positionals else None)
self._msg_opt_args = styling.H1(self, i18n.translate("optional_args_msg"))
def _do_layout(self):
STD_LAYOUT = (0, wx.LEFT | wx.RIGHT | wx.EXPAND, PADDING)
@ -53,24 +45,25 @@ class AdvancedConfigPanel(ScrolledPanel, OptionReader):
container = wx.BoxSizer(wx.VERTICAL)
container.AddSpacer(15)
if self._positionals:
container.Add(self._msg_req_args, 0, wx.LEFT | wx.RIGHT, PADDING)
if self.widgets.required_args:
container.Add(styling.H1(self, i18n.translate("required_args_msg")), 0, wx.LEFT | wx.RIGHT, PADDING)
container.AddSpacer(5)
container.Add(styling.HorizontalRule(self), *STD_LAYOUT)
container.AddSpacer(20)
self.CreateComponentGrid(container, self.components.required_args, cols=self._build_spec['requireds_cols'])
self.CreateComponentGrid(container, self.widgets.required_args, cols=self._build_spec['requireds_cols'])
container.AddSpacer(10)
container.AddSpacer(10)
container.Add(self._msg_opt_args, 0, wx.LEFT | wx.RIGHT, PADDING)
container.AddSpacer(5)
container.Add(styling.HorizontalRule(self), *STD_LAYOUT)
container.AddSpacer(20)
self.CreateComponentGrid(container, self.components.general_options, cols=self._build_spec['optionals_cols'])
self.CreateComponentGrid(container, self.components.flags, cols=self._build_spec['optionals_cols'])
if self.widgets.optional_args:
container.AddSpacer(10)
container.Add(styling.H1(self, i18n.translate("optional_args_msg")), 0, wx.LEFT | wx.RIGHT, PADDING)
container.AddSpacer(5)
container.Add(styling.HorizontalRule(self), *STD_LAYOUT)
container.AddSpacer(20)
self.CreateComponentGrid(container, self.widgets.optional_args, cols=self._build_spec['optionals_cols'])
self.SetSizer(container)
@ -84,12 +77,8 @@ class AdvancedConfigPanel(ScrolledPanel, OptionReader):
parent_sizer.AddSpacer(20)
def OnResize(self, evt):
self.Freeze()
for component in self.components:
component.onResize(evt)
self.SetupScrolling(scroll_x=False, scrollToTop=False)
evt.Skip()
self.Thaw()
def RegisterController(self, controller):
if self._controller is None:
@ -100,15 +89,15 @@ class AdvancedConfigPanel(ScrolledPanel, OptionReader):
returns the collective values from all of the
widgets contained in the panel"""
values = [c.GetValue()
for c in self.components
for c in chain(*self.widgets)
if c.GetValue() is not None]
return ' '.join(values)
def GetRequiredArgs(self):
return [arg.GetValue() for arg in self.components.required_args]
return [arg.GetValue() for arg in self.widgets.required_args]
def chunk(self, iterable, n, fillvalue=None):
"Collect data into fixed-length chunks or blocks"
"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)

41
gooey/gui/windows/base_window.py

@ -7,22 +7,27 @@ import os
import sys
import wx
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.runtime_display_panel import RuntimeDisplay
from gooey.gui import styling, image_repository
from gooey.gui.windows import footer, header
from gooey.gui.windows import footer, header, layouts
from gooey.gui.windows.sidebar import Sidebar
class BaseWindow(wx.Frame):
def __init__(self, BodyPanel, build_spec):
def __init__(self, build_spec):
wx.Frame.__init__(self, parent=None, id=-1)
self.build_spec = build_spec
self._controller = None
self.SetDoubleBuffered(True)
# Components
self.icon = None
self.head_panel = None
@ -32,7 +37,7 @@ class BaseWindow(wx.Frame):
self.panels = None
self._init_properties()
self._init_components(BodyPanel)
self._init_components()
self._do_layout()
self._init_controller()
self.registerControllers()
@ -45,14 +50,14 @@ class BaseWindow(wx.Frame):
self.icon = wx.Icon(image_repository.icon, wx.BITMAP_TYPE_ICO)
self.SetIcon(self.icon)
def _init_components(self, BodyPanel):
def _init_components(self):
# init gui
_desc = self.build_spec['program_description']
self.head_panel = header.FrameHeader(
heading=i18n.translate("settings_title"),
subheading=_desc or '',
parent=self)
self.config_panel = BodyPanel(self)
self.config_panel = AdvancedConfigPanel(self, self.build_spec)
self.runtime_display = RuntimeDisplay(self)
self.foot_panel = footer.Footer(self, self._controller)
self.panels = [self.head_panel, self.config_panel, self.foot_panel]
@ -61,13 +66,35 @@ class BaseWindow(wx.Frame):
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.head_panel, 0, wx.EXPAND)
sizer.Add(styling.HorizontalRule(self), 0, wx.EXPAND)
sizer.Add(self.config_panel, 1, wx.EXPAND)
self.runtime_display.Hide()
if self.build_spec['layout_type'] == 'column':
print 'hello!'
self.config_panel = layouts.ColumnLayout(self)
sizer.Add(self.config_panel, 1, wx.EXPAND)
else:
self.config_panel = layouts.FlatLayout(self, build_spec=self.build_spec)
sizer.Add(self.config_panel, 1, wx.EXPAND)
sizer.Add(self.runtime_display, 1, wx.EXPAND)
self.runtime_display.Hide()
sizer.Add(styling.HorizontalRule(self), 0, wx.EXPAND)
sizer.Add(self.foot_panel, 0, wx.EXPAND)
self.SetSizer(sizer)
self.sizer = sizer
pub.subscribe(self.myListener, "panelListener")
def myListener(self, message):
print message
print message == 'fetch'
if message == 'fetch':
del self.config_panel
def _init_controller(self):
self._controller = Controller(base_frame=self, build_spec=self.build_spec)

47
gooey/gui/windows/layouts.py

@ -1,4 +1,10 @@
import wx
from gooey.gui.windows.advanced_config import AdvancedConfigPanel
from gooey.gui.windows.sidebar import Sidebar
from gooey.gui import styling
basic_config = {
'required': [{
@ -13,3 +19,44 @@ basic_config = {
}],
'optional': []
}
class FlatLayout(wx.Panel):
def __init__(self, *args, **kwargs):
self._build_spec = kwargs.pop('build_spec')
super(FlatLayout, self).__init__(*args, **kwargs)
self.SetDoubleBuffered(True)
self.main_content = AdvancedConfigPanel(self, build_spec=self._build_spec)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(self.main_content, 3, wx.EXPAND)
self.SetSizer(sizer)
def GetOptions(self):
return self.main_content.GetOptions()
def GetRequiredArgs(self):
return self.main_content.GetRequiredArgs()
class ColumnLayout(wx.Panel):
def __init__(self, *args, **kwargs):
super(ColumnLayout, self).__init__(*args, **kwargs)
self.SetDoubleBuffered(True)
self.sidebar = Sidebar(self, contents=['one', 'two', 'three', 'four', 'five'])
self.main_content = AdvancedConfigPanel(self)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(self.sidebar, 1, wx.EXPAND)
sizer.Add(styling.vertical_rule(self), 0, wx.EXPAND)
sizer.Add(self.main_content, 3, wx.EXPAND)
self.SetSizer(sizer)
def get_layout_builder(layout_type):
if layout_type == 'column':
return

2
gooey/gui/windows/runtime_display_panel.py

@ -67,5 +67,3 @@ class RuntimeDisplay(wx.Panel):
def OnMsg(self, evt):
pass
# print 'It workded!!'
# print locals()

45
gooey/gui/windows/sidebar.py

@ -0,0 +1,45 @@
import wx
from wx.lib.pubsub import pub
from gooey.gui import styling
class Sidebar(wx.Panel):
def __init__(self, parent, *args, **kwargs):
self.contents = kwargs.pop('contents', [])
super(Sidebar, self).__init__(parent, *args, **kwargs)
self.SetDoubleBuffered(True)
self._parent = parent
self._controller = None
self._init_components()
self._do_layout()
def _init_components(self):
pass
def _do_layout(self):
self.SetDoubleBuffered(True)
self.SetBackgroundColour('#f2f2f2')
self.SetSize((180, 0))
self.SetMinSize((180, 0))
STD_LAYOUT = (0, wx.LEFT | wx.RIGHT | wx.EXPAND, 10)
container = wx.BoxSizer(wx.VERTICAL)
container.AddSpacer(15)
container.Add(styling.H1(self, 'Actions'), *STD_LAYOUT)
container.AddSpacer(5)
thing = wx.ListBox(self, -1, choices=['Connect', 'process', 'commit', 'fetch'])
container.Add(thing, 1, wx.LEFT | wx.RIGHT | wx.EXPAND, 10)
container.AddSpacer(20)
self.SetSizer(container)
self.Bind(wx.EVT_LISTBOX, self.onClick, thing)
def onClick(self, evt):
pub.sendMessage("panelListener", message=evt.GetString())
evt.Skip()
Loading…
Cancel
Save