diff --git a/gooey/gui/application.py b/gooey/gui/application.py index e87acd0..60d448b 100644 --- a/gooey/gui/application.py +++ b/gooey/gui/application.py @@ -1,4 +1,8 @@ -import itertools +''' +Main runner entry point for Gooey. +''' + + import wx import os import sys @@ -12,26 +16,19 @@ from gooey.gui.windows.base_window import BaseWindow 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) i18n.load(build_spec['language']) @@ -44,11 +41,23 @@ def run(build_spec=None): 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__': - run() + main() diff --git a/gooey/gui/windows/advanced_config.py b/gooey/gui/windows/advanced_config.py index 4b8b17f..38f7946 100644 --- a/gooey/gui/windows/advanced_config.py +++ b/gooey/gui/windows/advanced_config.py @@ -1,26 +1,26 @@ """ -Created on Dec 28, 2013 +Managed the internal layout for configuration options @author: Chris """ -from itertools import chain -import itertools + + import wx +import itertools + 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 import component_builder from gooey.gui.option_reader import OptionReader -from gooey.gui import styling + PADDING = 10 class AdvancedConfigPanel(ScrolledPanel, OptionReader): - """ - Abstract class for the Footer panels. - """ def __init__(self, parent, build_spec=None, **kwargs): ScrolledPanel.__init__(self, parent, **kwargs) @@ -59,7 +59,7 @@ class AdvancedConfigPanel(ScrolledPanel, OptionReader): container.Add(styling.HorizontalRule(self), *STD_LAYOUT) 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) @@ -74,13 +74,6 @@ class AdvancedConfigPanel(ScrolledPanel, OptionReader): 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): for row in self.chunk(components, cols): hsizer = wx.BoxSizer(wx.HORIZONTAL) @@ -114,10 +107,6 @@ class AdvancedConfigPanel(ScrolledPanel, OptionReader): def GetRequiredArgs(self): 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): "Collect data into fixed-length chunks or blocks" # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx