Browse Source

Removed dependency on argparse for building the GUI - now uses json. Fixed bugs in components resizing. Changed gooey_decorator to use the new json backed GUI builder

pull/61/head
chriskiehl 10 years ago
parent
commit
6a64e5e88d
15 changed files with 631 additions and 84 deletions
  1. 203
      gooey/argparse_to_json.py
  2. 73
      gooey/argparse_to_json_unittest.py
  3. 20
      gooey/dev_utils/ast_inspector.py
  4. 6
      gooey/gooey_decorator.py
  5. 39
      gooey/gui/advanced_config.py
  6. 14
      gooey/gui/base_window.py
  7. 79
      gooey/gui/build_spec_validator.py
  8. 87
      gooey/gui/componenets2_runner.py
  9. 38
      gooey/gui/component_builder.py
  10. 77
      gooey/gui/components2.py
  11. 1
      gooey/gui/display_main.py
  12. 3
      gooey/gui/runtime_display_panel.py
  13. 2
      gooey/gui/widget_pack.py
  14. 27
      gooey/mockapplications/mockapp.py
  15. 46
      gooey/mockapplications/qwindelzorf _example.py

203
gooey/argparse_to_json.py

@ -0,0 +1,203 @@
"""
Converts argparse parser actions into json "Build Specs"
"""
from argparse import (
_CountAction,
_HelpAction,
_StoreConstAction,
_StoreFalseAction,
_StoreTrueAction
)
import itertools
VALID_WIDGETS = (
'@FileChooser',
'@DirChooser',
'@DateChooser',
'@TextField',
'@Dropdown',
'@Counter',
'@RadioGroup'
)
def convert(argparser):
mutually_exclusive_group = [
mutex_action
for group_actions in argparser._mutually_exclusive_groups
for mutex_action in group_actions._group_actions]
base_actions = [action for action in argparser._actions
if action not in mutually_exclusive_group]
positional_args = get_required_and_positional_args(base_actions)
choice_args = get_optionals_with_choices(base_actions)
standard_args = get_optionals_without_choices(base_actions)
counter_args = get_counter_style_optionals(base_actions)
radio_args = get_mutually_exclusive_optionals(mutually_exclusive_group)
checkable_args = get_flag_style_optionals(base_actions)
return {
'required': positional_args,
'optional': list(itertools.chain(
get_optionals_with_choices(base_actions),
get_optionals_without_choices(base_actions),
get_counter_style_optionals(base_actions),
get_mutually_exclusive_optionals(mutually_exclusive_group),
get_flag_style_optionals(base_actions)
)),
}
def get_required_and_positional_args(actions):
"""
Extracts positional or required args from the actions list
In argparse, positionals are defined by either an empty option_strings
or by the option_strings parameters being sans a leading hyphen
"""
filtered_actions = [action for action in actions
if not action.option_strings
or action.required == True]
return [as_json(action, default_widget='TextField')
for action in filtered_actions]
def get_optionals_with_choices(actions):
"""
All optional arguments which are constrained
to specific choices.
"""
filtered_actions = [action
for action in actions
if action.choices]
return [as_json(action, default_widget='Dropdown')
for action in filtered_actions]
def get_optionals_without_choices(actions):
"""
All actions which are:
(a) Optional, but without required choices
(b) Not of a "boolean" type (storeTrue, etc..)
(c) Of type _AppendAction
e.g. anything which has an argument style like:
>>> -f myfilename.txt
"""
boolean_actions = (
_StoreConstAction, _StoreFalseAction,
_StoreTrueAction
)
filtered_actions = [
action
for action in actions
if action.option_strings
and not action.choices
and not isinstance(action, _CountAction)
and not isinstance(action, _HelpAction)
and type(action) not in boolean_actions
]
return [as_json(action, default_widget='TextField')
for action in filtered_actions]
def get_flag_style_optionals(actions):
"""
Gets all instances of "flag" type options.
i.e. options which either store a const, or
store boolean style options (e.g. StoreTrue).
Types:
_StoreTrueAction
_StoreFalseAction
_StoreConst
"""
filtered_actions = [
action
for action in actions
if isinstance(action, _StoreTrueAction)
or isinstance(action, _StoreFalseAction)
or isinstance(action, _StoreConstAction)
]
return [as_json(action, default_widget='CheckBox')
for action in filtered_actions]
def get_counter_style_optionals(actions):
"""
Returns all instances of type _CountAction
"""
filtered_actions = [action
for action in actions
if isinstance(action, _CountAction)]
_json_options = [as_json(action, default_widget='Dropdown')
for action in filtered_actions]
# Counter should show as Dropdowns, so pre-populare with numeric choices
for opt in _json_options:
opt['choices'] = range(10)
return _json_options
def get_mutually_exclusive_optionals(mutex_group):
if not mutex_group:
return []
options = [
{
'display_name': mutex_arg.dest,
'help': mutex_arg.help,
'nargs': mutex_arg.nargs or '',
'commands': mutex_arg.option_strings,
'choices': mutex_arg.choices,
} for mutex_arg in mutex_group
]
return [{
'type': 'RadioGroup',
'group_name': 'Choose Option',
'data': options
}]
def as_json(action, default_widget):
option_strings = action.option_strings
_type = option_strings[-1] if option_strings else None
return {
'type': widget_type(_type) if is_widget_spec(_type) else default_widget,
'data' : {
'display_name': action.dest,
'help': action.help,
'nargs': action.nargs or '',
'commands': action.option_strings,
'choices': action.choices or [],
}
}
def is_widget_spec(option_string):
return option_string and option_string in VALID_WIDGETS
def widget_type(option_string):
return option_string[1:]

73
gooey/argparse_to_json_unittest.py

@ -0,0 +1,73 @@
import argparse
import unittest
import json
from argparse_to_json import *
class TestArgparseToJson(unittest.TestCase):
def setUp(self):
my_cool_parser = argparse.ArgumentParser(description='description')
my_cool_parser.add_argument("filename", help='filename help msg') # positional
my_cool_parser.add_argument("outfile", help="Name of the file where you'll save the output") # positional
my_cool_parser.add_argument('-c', '--countdown', default=10, type=int, help='sets the time to count down from')
my_cool_parser.add_argument("-s", "--showtime", action="store_true", help="display the countdown timer")
my_cool_parser.add_argument("-d", "--delay", action="store_true", help="Delay execution for a bit")
my_cool_parser.add_argument('--verbose', '-v', action='count')
my_cool_parser.add_argument("-o", "--obfuscate", action="store_true", help="obfuscate the countdown timer!")
my_cool_parser.add_argument('-r', '--recursive', choices=['yes', 'no'], help='Recurse into subfolders')
my_cool_parser.add_argument("-w", "--writelog", default="No, NOT whatevs", help="write log to some file or something")
my_cool_parser.add_argument("-e", "--expandAll", action="store_true", help="expand all processes")
verbosity = my_cool_parser.add_mutually_exclusive_group()
verbosity.add_argument('-t', '--verboze', dest='verboze', action="store_true", help="Show more details")
verbosity.add_argument('-q', '--quiet', dest='quiet', action="store_true", help="Only output on error")
self.parser = my_cool_parser
self.mutually_exclusive_group = [
mutex_action
for group_actions in self.parser._mutually_exclusive_groups
for mutex_action in group_actions._group_actions]
self.base_actions = [action for action in self.parser._actions
if action not in self.mutually_exclusive_group]
def test_get_optionals_with_choices(self):
target_arg = self.find_arg_by_option(self.base_actions, '--recursive')
json_result = get_optionals_with_choices(self.base_actions)
self._test_parser_to_json_mapping(target_arg, json_result[0], 'Dropdown')
def test_get_optionals_without_choices(self):
target_arg = self.find_arg_by_option(self.base_actions, '--showtime')
json_result = get_optionals_without_choices(self.base_actions)
self._test_parser_to_json_mapping(target_arg, json_result[0], 'TextField')
def test_get_counter_style_optionals(self):
target_arg = self.find_arg_by_option(self.base_actions, '--verbose')
json_result = get_counter_style_optionals(self.base_actions)
self._test_parser_to_json_mapping(target_arg, json_result[0], 'Dropdown')
def test_get_mutually_exclusive_optionals(self):
target_arg = self.find_arg_by_option(self.mutually_exclusive_group, '--verboze')
json_result = get_mutually_exclusive_optionals(self.mutually_exclusive_group)[0]
data = json_result['data'][0]
self.assertEqual('RadioGroup', json_result['type'])
self.assertEqual(target_arg.choices, data['choices'])
self.assertEqual(target_arg.help, data['help'])
self.assertEqual(target_arg.option_strings, data['commands'])
self.assertEqual(target_arg.dest, data['display_name'])
def _test_parser_to_json_mapping(self, target_arg, json_string, expected_type):
self.assertEqual(expected_type, json_string['type'])
self.assertEqual(target_arg.choices, json_string['data']['choices'])
self.assertEqual(target_arg.help, json_string['data']['help'])
self.assertEqual(target_arg.option_strings, json_string['data']['commands'])
self.assertEqual(target_arg.dest, json_string['data']['display_name'])
def find_arg_by_option(self, group, option_string):
for arg in group:
if option_string in arg.option_strings:
return arg

20
gooey/dev_utils/ast_inspector.py

@ -68,13 +68,23 @@ def main():
nodes = ast.parse(git_example)
assign = source_parser.get_nodes_by_instance_type(nodes, Assign)
assignment = source_parser.get_nodes_by_containing_attr(assign, "ArgumentParser")
print assignment
print assignment[0].__dict__
p = source_parser.convert_to_python(assignment)[0]
print p
varname, instruction = code_prep.split_line(source_parser.convert_to_python(assignment)[0])
updated_code = git_example.replace(varname, "jello_maker")
all_code_leading_up_to_parseargs = '\n'.join(itertools.takewhile(lambda line: 'parse_args()' not in line, updated_code.split('\n')))
code = compile(all_code_leading_up_to_parseargs, '', 'exec')
exec(code)
parser = main()
print parser._actions
print 'Fusdo:', updated_code.split('\n')[8]
# all_code_leading_up_to_parseargs = '\n'.join(itertools.takewhile(lambda line: 'parse_args()' not in line, updated_code.split('\n')))
# code = compile(all_code_leading_up_to_parseargs, '', 'exec')
# exec(code)
# parser = main()
# print parser._actions

6
gooey/gooey_decorator.py

@ -45,6 +45,7 @@ done.
from functools import partial
import wx
from gooey import argparse_to_json
from gooey.gui.component_factory import ComponentFactory
import i18n
@ -84,8 +85,11 @@ def Gooey(f=None, advanced=True,
if config:
parser = get_parser(module_path)
client_app = ClientApp(parser, payload)
build_spec = argparse_to_json.convert(parser)
if advanced:
BodyPanel = partial(AdvancedConfigPanel, action_groups=client_app.action_groups)
BodyPanel = partial(AdvancedConfigPanel, build_spec=build_spec)
else:
BodyPanel = BasicConfigPanel
# User doesn't want to display configuration screen

39
gooey/gui/advanced_config.py

@ -8,26 +8,25 @@ import wx
from wx.lib.scrolledpanel import ScrolledPanel
from gooey import i18n
from gooey.gui import component_builder
from gooey.gui.component_factory import ComponentFactory
from gooey.gui.option_reader import OptionReader
import styling
PADDING = 10
class AdvancedConfigPanel(ScrolledPanel, OptionReader):
"""
Abstract class for the Footer panels.
"""
def __init__(self, parent, action_groups=None, **kwargs):
def __init__(self, parent, build_spec=None, **kwargs):
ScrolledPanel.__init__(self, parent, **kwargs)
self.SetupScrolling()
self._action_groups = action_groups
self._positionals = len(action_groups._positionals) > 0
self.components = ComponentFactory(action_groups)
self._action_groups = build_spec
self._positionals = build_spec.get('required', None)
self.components = component_builder.ComponentBuilder(build_spec)
self._msg_req_args = None
self._msg_opt_args = None
@ -66,29 +65,35 @@ class AdvancedConfigPanel(ScrolledPanel, OptionReader):
container.Add(styling.HorizontalRule(self), *STD_LAYOUT)
container.AddSpacer(20)
flag_grids = self.CreateComponentGrid(self.components.flags, cols=3, vgap=15)
general_opts_grid = self.CreateComponentGrid(self.components.general_options)
container.Add(general_opts_grid, *STD_LAYOUT)
container.AddSpacer(30)
container.Add(flag_grids, *STD_LAYOUT)
# self.CreateComponentGrid(container, self.components.flags, cols=3)
self.CreateComponentGrid(container, self.components.general_options, cols=2)
# container.Add(general_opts_grid, *STD_LAYOUT)
# container.AddSpacer(30)
# container.Add(flag_grids, 0, wx.LEFT | wx.RIGHT | wx.EXPAND, PADDING)
self.SetSizer(container)
def AddWidgets(self, sizer, components, add_space=False, padding=PADDING):
for component in components:
widget_group = component.Build(parent=self)
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, components, cols=2, vgap=10):
gridsizer = wx.GridSizer(rows=0, cols=cols, vgap=vgap, hgap=4)
self.AddWidgets(gridsizer, components)
return gridsizer
def CreateComponentGrid(self, parent_sizer, components, cols=2):
rows = [components[i:i+cols] for i in range(0, len(components), cols)]
for row in rows:
hsizer = wx.BoxSizer(wx.HORIZONTAL)
for widget in row:
hsizer.Add(widget.build(self), 1, wx.EXPAND | wx.LEFT | wx.RIGHT, 10)
# hsizer.FitInside(parent_sizer)
parent_sizer.Add(hsizer, 0, wx.EXPAND)
parent_sizer.AddSpacer(20)
def OnResize(self, evt):
for component in self.components:
component.Update(evt.m_size)
component.onResize(evt)
self.SetupScrolling()
evt.Skip()
def RegisterController(self, controller):

14
gooey/gui/base_window.py

@ -1,12 +1,5 @@
'''
Created on Jan 19, 2014
New plan:
fuck the multi-component thing.
Bind and unbind the buttons on the panels.
@author: Chris
'''
@ -45,6 +38,7 @@ class BaseWindow(wx.Frame):
self._do_layout()
self._init_controller()
self.registerControllers()
self.Bind(wx.EVT_SIZE, self.onResize)
def _init_properties(self):
@ -54,7 +48,7 @@ class BaseWindow(wx.Frame):
title = self._params['program_name']
self.SetTitle(title)
self.SetSize((610, 530))
self.SetMinSize((400, 300))
# self.SetMinSize((400, 300))
self.icon = wx.Icon(image_repository.icon, wx.BITMAP_TYPE_ICO)
self.SetIcon(self.icon)
@ -106,6 +100,10 @@ class BaseWindow(wx.Frame):
def ManualStart(self):
self._controller.ManualStart()
def onResize(self, evt):
print self.Size
evt.Skip()
if __name__ == '__main__':
pass

79
gooey/gui/build_spec_validator.py

@ -0,0 +1,79 @@
'''
Validates that the json has meaningful keys
'''
import itertools
a = {
'required' : [
{
'component': 'TextField',
'data': {
'display_name': 'filename',
'help_text': 'path to file you want to process',
'command_args': ['-f', '--infile']
}
},
{
'component': 'FileChooser',
'data': {
'display_name': 'Output Location',
'help_text': 'Where to save the file',
'command_args': ['-o', '--outfile']
}
}
],
'optional' : [
{
'component': 'RadioGroup',
'data': [
{
'display_name': 'Output Location',
'help_text': 'Where to save the file',
'command_args': ['-o', '--outfile']
}, {
'display_name': 'Output Location',
'help_text': 'Where to save the file',
'command_args': ['-o', '--outfile']
}
]
}
]
}
VALID_WIDGETS = (
'FileChooser',
'DirChooser',
'DateChooser',
'TextField',
'Dropdown',
'Counter',
'RadioGroup'
)
class MalformedBuildSpecException(Exception):
pass
def validate(json_string):
required = json_string.get('required')
optional = json_string.get('optional')
if not required or not optional:
raise MalformedBuildSpecException("All objects must be children of 'required,' or 'optional'")
objects = [item for key in json_string for item in json_string[key]]
for obj in objects:
if obj['component'] not in VALID_WIDGETS:
raise MalformedBuildSpecException("Invalid Component name: {0}".format(obj['component']))
if __name__ == '__main__':
validate(a)

87
gooey/gui/componenets2_runner.py

@ -1,41 +1,76 @@
__author__ = 'Chris'
import wx
import components2
from wx.lib.scrolledpanel import ScrolledPanel
class MyFrame(wx.Frame):
class TestPanel(ScrolledPanel):
def __init__(self, parent):
wx.Frame.__init__(self, parent, title="test", size=(320, 240))
self.SetBackgroundColour('#ffffff')
ScrolledPanel.__init__(self, parent)
self.SetupScrolling(scroll_x=False)
self.textctrls = [wx.TextCtrl(self) for _ in range(4)]
sizer = wx.BoxSizer(wx.VERTICAL)
# f = components2.RadioGroup({
# 'title': 'cool title',
# 'help_msg': 'cool help msg that is super long and intense andd has lots of words!', 'nargs': '+',
# 'option_strings': ['-f', '--fudger'],
# 'choices': ['choice 1', 'choice 2', 'choice 3']
# })
f = components2.RadioGroup(data={
'group_name': 'My Options',
'buttons': [
{'name': 'verbose',
'help': "cool help msg that is super long and intense and has lots of words!",
'option': '-v'
},{
'name': 'quiet',
'help': "Only output on error",
'option': '-q'
}
]
})
sizer.Add(f.build(self), 0, wx.EXPAND)
hsizer = wx.BoxSizer(wx.HORIZONTAL)
for textctrl in self.textctrls:
hsizer.Add(textctrl, 1, wx.EXPAND)
sizer.Add(hsizer, 0, wx.EXPAND)
self.SetSizer(sizer)
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, title="test", size=(320, 240))
self.SetBackgroundColour('#ffffff')
self.panel = TestPanel(self)
self.Show()
if __name__ == '__main__':
app = wx.App(False)
frame = MyFrame(None)
frame.Show(True)
MyFrame(None)
app.MainLoop()
# a = {
# 'required' : [
# {
# 'component': 'TextField',
# 'data': {
# 'display_name': 'filename',
# 'help_text': 'path to file you want to process',
# 'command_args': ['-f', '--infile']
# }
# },
# {
# 'component': 'FileChooser',
# 'data': {
# 'display_name': 'Output Location',
# 'help_text': 'Where to save the file',
# 'command_args': ['-o', '--outfile']
# }
# }
# ],
# 'optional' : [
# {
# 'component': 'RadioGroup',
# 'data': [
# {
# 'display_name': 'Output Location',
# 'help_text': 'Where to save the file',
# 'command_args': ['-o', '--outfile']
# }, {
# 'display_name': 'Output Location',
# 'help_text': 'Where to save the file',
# 'command_args': ['-o', '--outfile']
# }
# ]
# }
# ]
# }
#
# ]
# }

38
gooey/gui/component_builder.py

@ -0,0 +1,38 @@
import itertools
from gooey.gui import components2
class ComponentBuilder(object):
def __init__(self, build_spec):
self.build_spec = build_spec
_required_specs = self.build_spec.get('required', None)
_optional_specs = self.build_spec.get('optional', None)
self.required_args = self.build_widget(_required_specs) if _required_specs else None
optionals = self.build_widget(_optional_specs) if _optional_specs else None
if _optional_specs:
self.flags = [widget for widget in optionals if isinstance(widget, components2.CheckBox)]
self.general_options = [widget for widget in optionals if not isinstance(widget, components2.CheckBox)]
else:
self.flags = []
self.general_options = []
def build_widget(self, build_spec):
assembled_widgets = []
for spec in build_spec:
widget_type = spec['type']
properties = spec['data']
Component = getattr(components2, widget_type)
assembled_widgets.append(Component(data=properties))
return assembled_widgets
def __iter__(self):
'''
return an iterator for all of the contained gui
'''
return itertools.chain(self.required_args,
self.flags,
self.general_options)

77
gooey/gui/components2.py

@ -49,13 +49,13 @@ class BaseGuiComponent(object):
def createHelpMsgWidget(self, parent):
label_text = (self.formatExtendedHelpMsg(self.data)
if self.data['nargs']
else self.data['help_msg'])
base_text = wx.StaticText(parent, label=label_text)
else self.data['help'])
base_text = wx.StaticText(parent, label=label_text or '')
styling.MakeDarkGrey(base_text)
return base_text
def createTitle(self, parent):
text = wx.StaticText(parent, label=self.data['title'].title())
text = wx.StaticText(parent, label=self.data['display_name'].title())
styling.MakeBold(text)
return text
@ -76,19 +76,74 @@ class BaseGuiComponent(object):
evt.Skip()
def _onResize(self, evt):
if self.help_msg is None:
if not self.help_msg:
return
self.panel.Size = evt.GetSize()
print 'Component Panel Size:', self.panel.Size
container_width, _ = self.panel.Size
# if 'filename' in self.data['display_name']:
# print 'Container Width:', container_width, '-', self.data['display_name']
text_width, _ = self.help_msg.Size
print 'container width:', container_width
print 'text width', text_width
if text_width != container_width:
self.help_msg.SetLabel(self.help_msg.GetLabelText().replace('\n', ' '))
self.help_msg.Wrap(container_width)
evt.Skip()
def getValue(self):
return self.widget_pack.getValue()
class CheckBox(BaseGuiComponent):
def __init__(self, data, widget_pack=None):
BaseGuiComponent.__init__(self, data, widget_pack)
self.widget = None
print data
self.option_strings = data['commands'][0]
def build(self, parent):
return self.do_layout(parent)
def do_layout(self, parent):
self.panel = wx.Panel(parent)
self.widget = wx.CheckBox(self.panel)
self.title = self.createTitle(self.panel)
self.help_msg = self.createHelpMsgWidget(self.panel)
vertical_container = wx.BoxSizer(wx.VERTICAL)
vertical_container.Add(self.title)
horizontal_sizer = wx.BoxSizer(wx.HORIZONTAL)
horizontal_sizer.Add(self.widget, 0, wx.EXPAND | wx.RIGHT, 10)
horizontal_sizer.Add(self.help_msg, 1, wx.EXPAND)
vertical_container.Add(horizontal_sizer, 0, wx.EXPAND)
self.panel.SetSizer(vertical_container)
self.panel.Bind(wx.EVT_SIZE, self.onResize)
return self.panel
def onSetter(self, evt):
self.getValue()
def onResize(self, evt):
msg = self.help_msg
print 'thing:', self.data['display_name']
container_width, _ = self.panel.Size
text_width, _ = msg.Size
if text_width != container_width:
msg.SetLabel(msg.GetLabelText().replace('\n', ' '))
msg.Wrap(container_width)
evt.Skip()
def getValue(self):
return
class RadioGroup(object):
def __init__(self, data):
@ -107,13 +162,14 @@ class RadioGroup(object):
def do_layout(self, parent):
self.panel = wx.Panel(parent)
self.radio_buttons = [wx.RadioButton(self.panel, -1) for _ in self.data['buttons']]
self.btn_names = [wx.StaticText(self.panel, label=btn['name'].title()) for btn in self.data['buttons']]
self.help_msgs = [wx.StaticText(self.panel, label=btn['help'].title()) for btn in self.data['buttons']]
self.option_stings = [btn['option'] for btn in self.data['buttons']]
self.radio_buttons = [wx.RadioButton(self.panel, -1) for _ in self.data]
self.btn_names = [wx.StaticText(self.panel, label=btn_data['display_name'].title()) for btn_data in self.data]
self.help_msgs = [wx.StaticText(self.panel, label=btn_data['help'].title()) for btn_data in self.data]
self.option_stings = [btn_data['commands'] for btn_data in self.data]
# box = wx.StaticBox(self.panel, -1, label=self.data['group_name'])
vertical_container = wx.BoxSizer(wx.VERTICAL)
box = wx.StaticBox(self.panel, -1, label='Set Verbosity Level')
vertical_container = wx.StaticBoxSizer(box, wx.VERTICAL)
for button, name, help in zip(self.radio_buttons, self.btn_names, self.help_msgs):
@ -158,7 +214,8 @@ DateChooser = lambda data: BaseGuiComponent(data=data, widget_pack=widget_pack.D
TextField = lambda data: BaseGuiComponent(data=data, widget_pack=widget_pack.TextInputPayload())
Dropdown = lambda data: BaseGuiComponent(data=data, widget_pack=widget_pack.DropdownPayload())
Counter = lambda data: BaseGuiComponent(data=data, widget_pack=widget_pack.CounterPayload())
# RadioGroup
# CheckBox

1
gooey/gui/display_main.py

@ -108,4 +108,3 @@ class MainWindow(wx.Frame):

3
gooey/gui/runtime_display_panel.py

@ -27,7 +27,7 @@ class RuntimeDisplay(wx.Panel):
self._init_properties()
self._init_components()
self._do_layout()
self._HookStdout()
# self._HookStdout()
def _init_properties(self):
self.SetBackgroundColour('#F0F0F0')
@ -62,4 +62,3 @@ class RuntimeDisplay(wx.Panel):
self.AppendText(txt)

2
gooey/gui/widget_pack.py

@ -113,7 +113,7 @@ class DropdownPayload(WidgetPack):
self.widget = None
def build(self, parent, data):
self.option_string = data['option_strings'][0]
self.option_string = data['commands'][0]
self.widget = wx.ComboBox(
parent=parent,
id=-1,

27
gooey/mockapplications/mockapp.py

@ -15,18 +15,21 @@ from gooey import Gooey
@Gooey
def main():
desc = "Mock application to test Gooey's functionality"
file_help_msg = "Name of the file you want to read"
file_help_msg = "Name of the file you want to process"
my_cool_parser = ArgumentParser(description=desc)
my_cool_parser.add_argument("filename", help=file_help_msg) # positional
my_cool_parser.add_argument("outfile", help="Name of the file where you'll save the output") # positional
my_cool_parser.add_argument('-c', '--countdown', default=10, type=int, help='sets the time to count down from')
my_cool_parser.add_argument("-s", "--showtime", action="store_true", help="display the countdown timer")
my_cool_parser.add_argument("-d", "--delay", action="store_true", help="Delay execution for a bit")
# my_cool_parser.add_argument("-s", "--showtime", action="store_true", help="display the countdown timer")
# my_cool_parser.add_argument("-d", "--delay", action="store_true", help="Delay execution for a bit")
my_cool_parser.add_argument('--verbose', '-v', action='count')
my_cool_parser.add_argument("-o", "--obfuscate", action="store_true", help="obfuscate the countdown timer!")
# my_cool_parser.add_argument("-o", "--obfuscate", action="store_true", help="obfuscate the countdown timer!")
my_cool_parser.add_argument('-r', '--recursive', choices=['yes', 'no'], help='Recurse into subfolders')
my_cool_parser.add_argument("-w", "--writelog", default="No, NOT whatevs", help="write log to some file or something")
my_cool_parser.add_argument("-e", "--expandAll", action="store_true", help="expand all processes")
# my_cool_parser.add_argument("-w", "--writelog", default="No, NOT whatevs", help="write log to some file or something")
# my_cool_parser.add_argument("-e", "--expandAll", action="store_true", help="expand all processes")
# verbosity = my_cool_parser.add_mutually_exclusive_group()
# verbosity.add_argument('-t', '--verbozze', dest='verbose', action="store_true", help="Show more details")
# verbosity.add_argument('-q', '--quiet', dest='quiet', action="store_true", help="Only output on error")
print 'inside of main(), my_cool_parser =', my_cool_parser
args = my_cool_parser.parse_args()
@ -48,6 +51,14 @@ def main():
# raise ValueError("Something has gone wrong! AHHHHHHHHHHH")
if __name__ == '__main__':
# sys.argv.extend('asdf -c 5 -s'.split())
# print sys.argv
sys.argv.extend('asdf -c 5 -s'.split())
print sys.argv
main()
# import inspect
# import dis
# # print dir(main.__code__)
# # for i in dir(main.__code__):
# # print i, getattr(main.__code__, i)
# print dis.dis(main.__code__)
# # for i in inspect.getmembers(main):
# # print i

46
gooey/mockapplications/qwindelzorf _example.py

@ -1,6 +1,7 @@
"""inline"""
import argparse
from __builtin__ import getattr
from gooey import Gooey
x = '''random line'''
@ -14,16 +15,45 @@ and here
# @Gooey
def main():
"""This is my main module"""
"""
This is my main module
example:
args = parser.parse_args()
"""
parser = argparse.ArgumentParser('Get my users')
verbosity = parser.add_mutually_exclusive_group()
verbosity.add_argument('-v', '--verbose', dest='verbose', action="store_true", help="Show more details")
verbosity.add_argument('-q', '--quiet', dest='quiet', action="store_true", help="Only output on error")
parser.add_argument("filename", help="yo yo yo") # positional
parser.add_argument("outfile", help="Name of the file where you'll save the output") # positional
slervocity = parser.add_mutually_exclusive_group()
slervocity.add_argument('-c', '--countdown', action="store_true", help='sets the time to count down from')
slervocity.add_argument("-s", "--showtime", action="store_true", help="display the countdown timer")
parser.add_argument("-d", "--delay", action="store_true", help="Delay execution for a bit")
parser.add_argument("-o", "--obfuscate", action="store_true", help="obfuscate the countdown timer!")
parser.add_argument('-r', '--recursive', choices=['yes', 'no'], help='Recurse into subfolders')
parser.add_argument("-w", "--writelog", default="No, NOT whatevs", help="write log to some file or something")
parser.add_argument("-e", "--expandAll", action="store_true", help="expand all processes")
mutually_exclusive_group = [mutex_action
for group_actions in parser._mutually_exclusive_groups
for mutex_action in group_actions._group_actions]
base_actions = [action for action in parser._actions
if action not in mutually_exclusive_group]
for i in base_actions:
print 'Base Action:', i.option_strings
#
# print
for mutex_group in parser._mutually_exclusive_groups:
group_actions = mutex_group._group_actions
for i, mutex_action in enumerate(mutex_group._group_actions):
print mutex_action
for i in mutually_exclusive_group:
print 'Mute Action:', i
# for i in base_actions:
# print dir(i)
# print i.nargs
# break
def moo(asdf):
@ -49,5 +79,11 @@ def baz():
a = 1
def foo():
parser = argparse.ArgumentParser()
bar = 1
baz = 2
if __name__ == '__main__':
main()
Loading…
Cancel
Save