Browse Source

Linked variable cols lengths to build spec

pull/90/merge
chriskiehl 10 years ago
parent
commit
e7a141c66f
2 changed files with 38 additions and 40 deletions
  1. 49
      gooey/gui/application.py
  2. 29
      gooey/gui/windows/advanced_config.py

49
gooey/gui/application.py

@ -1,4 +1,8 @@
import itertools
'''
Main runner entry point for Gooey.
'''
import wx import wx
import os import os
import sys import sys
@ -12,26 +16,19 @@ from gooey.gui.windows.base_window import BaseWindow
from gooey.gui.windows.advanced_config import AdvancedConfigPanel from gooey.gui.windows.advanced_config import AdvancedConfigPanel
def run(build_spec=None):
if not build_spec:
if len(sys.argv) > 1:
parser = argparse.ArgumentParser(description='Gooey turns your command line programs into beautiful, user friendly GUIs')
parser.add_argument('file', help='Path to the configuration file for Gooey. We need this to run! :) ')
args = parser.parse_args()
gooey_config = args.file
else:
local_files = os.listdir(os.getcwd())
if 'gooey_config.json' not in local_files:
print "Bugger! gooey_config.json not found!"
sys.exit(1)
gooey_config = os.path.join(os.getcwd(), 'gooey_config.json')
def main():
gooey_config = pull_cmd_args() if has_arg_supplied() else read_local_dir()
if not os.path.exists(gooey_config):
raise IOError('Gooey Config not found')
if not os.path.exists(gooey_config):
raise IOError('Gooey Config not found')
with open(gooey_config, 'r') as f:
build_spec = json.load(f)
with open(gooey_config, 'r') as f:
build_spec = json.load(f)
run(build_spec)
def run(build_spec):
app = wx.App(False) app = wx.App(False)
i18n.load(build_spec['language']) i18n.load(build_spec['language'])
@ -44,11 +41,23 @@ def run(build_spec=None):
app.MainLoop() app.MainLoop()
def pull_cmd_args():
parser = argparse.ArgumentParser(description='Gooey turns your command line programs into beautiful, user friendly GUIs')
parser.add_argument('file', help='Path to the configuration file for Gooey. We need this to run! :) ')
args = parser.parse_args()
return args.file
def read_local_dir():
local_files = os.listdir(os.getcwd())
if 'gooey_config.json' not in local_files:
print "Bugger! gooey_config.json not found!"
sys.exit(1)
return os.path.join(os.getcwd(), 'gooey_config.json')
def has_arg_supplied():
return len(sys.argv) > 1
if __name__ == '__main__': if __name__ == '__main__':
run()
main()

29
gooey/gui/windows/advanced_config.py

@ -1,26 +1,26 @@
""" """
Created on Dec 28, 2013
Managed the internal layout for configuration options
@author: Chris @author: Chris
""" """
from itertools import chain
import itertools
import wx import wx
import itertools
from wx.lib.scrolledpanel import ScrolledPanel from wx.lib.scrolledpanel import ScrolledPanel
from gooey.gui import component_builder
from gooey.gui import styling
from gooey.gui.lang import i18n from gooey.gui.lang import i18n
from gooey.gui import component_builder
from gooey.gui.option_reader import OptionReader from gooey.gui.option_reader import OptionReader
from gooey.gui import styling
PADDING = 10 PADDING = 10
class AdvancedConfigPanel(ScrolledPanel, OptionReader): class AdvancedConfigPanel(ScrolledPanel, OptionReader):
"""
Abstract class for the Footer panels.
"""
def __init__(self, parent, build_spec=None, **kwargs): def __init__(self, parent, build_spec=None, **kwargs):
ScrolledPanel.__init__(self, parent, **kwargs) ScrolledPanel.__init__(self, parent, **kwargs)
@ -59,7 +59,7 @@ class AdvancedConfigPanel(ScrolledPanel, OptionReader):
container.Add(styling.HorizontalRule(self), *STD_LAYOUT) container.Add(styling.HorizontalRule(self), *STD_LAYOUT)
container.AddSpacer(20) container.AddSpacer(20)
self.AddWidgets(container, self.components.required_args, add_space=True)
self.CreateComponentGrid(container, self.components.required_args, cols=self._build_spec['requireds_cols'])
container.AddSpacer(10) container.AddSpacer(10)
@ -74,13 +74,6 @@ class AdvancedConfigPanel(ScrolledPanel, OptionReader):
self.SetSizer(container) self.SetSizer(container)
def AddWidgets(self, sizer, components, add_space=False, padding=PADDING):
for component in components:
widget_group = component.build(parent=self)
sizer.Add(widget_group, 0, wx.LEFT | wx.RIGHT | wx.EXPAND, padding)
if add_space:
sizer.AddSpacer(8)
def CreateComponentGrid(self, parent_sizer, components, cols=2): def CreateComponentGrid(self, parent_sizer, components, cols=2):
for row in self.chunk(components, cols): for row in self.chunk(components, cols):
hsizer = wx.BoxSizer(wx.HORIZONTAL) hsizer = wx.BoxSizer(wx.HORIZONTAL)
@ -114,10 +107,6 @@ class AdvancedConfigPanel(ScrolledPanel, OptionReader):
def GetRequiredArgs(self): def GetRequiredArgs(self):
return [arg.GetValue() for arg in self.components.required_args] return [arg.GetValue() for arg in self.components.required_args]
def GetOptionalArgs(self):
# Not used anywhere. Keep for debugging?
return filter(None, [arg.GetValue() for arg in chain(self.components.general_options, self.components.flags)])
def chunk(self, iterable, n, fillvalue=None): def chunk(self, iterable, n, fillvalue=None):
"Collect data into fixed-length chunks or blocks" "Collect data into fixed-length chunks or blocks"
# grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx

Loading…
Cancel
Save