Browse Source

Moved GooeyParser into its own module and added it to __init__ imports; Fixed bug in widget_pack that was feeding incorrect value

pull/61/head
chriskiehl 10 years ago
parent
commit
c7e65bd1c0
6 changed files with 51 additions and 42 deletions
  1. 1
      gooey/__init__.py
  2. 6
      gooey/_tmp/mockapp.py
  3. 5
      gooey/gui/widgets/widget_pack.py
  4. 6
      gooey/mockapplications/mockapp.py
  5. 35
      gooey/python_bindings/gooey_decorator.py
  6. 40
      gooey/python_bindings/gooey_parser.py

1
gooey/__init__.py

@ -1 +1,2 @@
from gooey.python_bindings.gooey_decorator import Gooey from gooey.python_bindings.gooey_decorator import Gooey
from gooey.python_bindings.gooey_parser import GooeyParser

6
gooey/_tmp/mockapp.py

@ -13,7 +13,7 @@ import argparse as ap
from argparse import ArgumentParser as AP from argparse import ArgumentParser as AP
from gooey import Gooey from gooey import Gooey
from gooey.python_bindings.gooey_decorator import GooeyParser
from gooey import GooeyParser
def main(): def main():
@ -25,8 +25,8 @@ def main():
my_cool_parser = GooeyParser(description=desc) my_cool_parser = GooeyParser(description=desc)
my_cool_parser.add_argument("filename", help=file_help_msg, widget="FileChooser") # positional my_cool_parser.add_argument("filename", help=file_help_msg, widget="FileChooser") # positional
my_cool_parser.add_argument("outfile", help="Name of the file where you'll save the output", widget="FileChooser") # positional my_cool_parser.add_argument("outfile", help="Name of the file where you'll save the output", widget="FileChooser") # positional
# my_cool_parser.add_argument('-c', '--countdown', default=10, type=int, help='sets the time to count down from you see its quite simple!', widget='DateChooser')
my_cool_parser.add_argument('-c', '--cron-schedule', default=10, type=int, help='Set the datetime when the cron should begin', widget='DateChooser')
my_cool_parser.add_argument('-c', '--countdown', default=10, type=int, help='sets the time to count down from you see its quite simple!', widget='DateChooser')
# my_cool_parser.add_argument('-c', '--cron-schedule', default=10, type=int, help='Set the datetime when the cron should begin', widget='DateChooser')
my_cool_parser.add_argument("-s", "--showtime", action="store_true", help="display the countdown timer") 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("-d", "--delay", action="store_true", help="Delay execution for a bit")
my_cool_parser.add_argument('-v', '--verbose', action='count') my_cool_parser.add_argument('-v', '--verbose', action='count')

5
gooey/gui/widgets/widget_pack.py

@ -54,7 +54,10 @@ class BaseChooser(WidgetPack):
return widget_sizer return widget_sizer
def getValue(self): def getValue(self):
return self.text_box.GetValue()
if self.option_string:
return '{0} {1}'.format(self.option_string, self.text_box.GetValue())
else:
return self.text_box.GetValue()
def onButton(self, evt): def onButton(self, evt):
raise NotImplementedError raise NotImplementedError

6
gooey/mockapplications/mockapp.py

@ -13,7 +13,7 @@ import argparse as ap
from argparse import ArgumentParser as AP from argparse import ArgumentParser as AP
from gooey import Gooey from gooey import Gooey
from gooey.python_bindings.gooey_decorator import GooeyParser
from gooey import GooeyParser
@Gooey @Gooey
@ -26,8 +26,8 @@ def main():
my_cool_parser = GooeyParser(description=desc) my_cool_parser = GooeyParser(description=desc)
my_cool_parser.add_argument("filename", help=file_help_msg, widget="FileChooser") # positional my_cool_parser.add_argument("filename", help=file_help_msg, widget="FileChooser") # positional
my_cool_parser.add_argument("outfile", help="Name of the file where you'll save the output", widget="FileChooser") # positional my_cool_parser.add_argument("outfile", help="Name of the file where you'll save the output", widget="FileChooser") # positional
# my_cool_parser.add_argument('-c', '--countdown', default=10, type=int, help='sets the time to count down from you see its quite simple!', widget='DateChooser')
my_cool_parser.add_argument('-c', '--cron-schedule', default=10, type=int, help='Set the datetime when the cron should begin', widget='DateChooser')
my_cool_parser.add_argument('-c', '--countdown', default=10, type=int, help='sets the time to count down from you see its quite simple!', widget='DateChooser')
# my_cool_parser.add_argument('-c', '--cron-schedule', default=10, type=int, help='Set the datetime when the cron should begin', widget='DateChooser')
my_cool_parser.add_argument("-s", "--showtime", action="store_true", help="display the countdown timer") 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("-d", "--delay", action="store_true", help="Delay execution for a bit")
my_cool_parser.add_argument('-v', '--verbose', action='count') my_cool_parser.add_argument('-v', '--verbose', action='count')

35
gooey/python_bindings/gooey_decorator.py

@ -154,42 +154,7 @@ def get_caller_path():
return tmp_sys.argv[0] return tmp_sys.argv[0]
class GooeyParser(object):
def __init__(self, **kwargs):
self.__dict__['parser'] = ArgumentParser(**kwargs)
self.widgets = {}
@property
def _mutually_exclusive_groups(self):
return self.parser._mutually_exclusive_groups
@property
def _actions(self):
return self.parser._actions
@property
def description(self):
return self.parser.description
def add_argument(self, *args, **kwargs):
widget = kwargs.pop('widget', None)
self.parser.add_argument(*args, **kwargs)
self.widgets[self.parser._actions[-1].dest] = widget
def add_mutually_exclusive_group(self, **kwargs):
return self.parser.add_mutually_exclusive_group(**kwargs)
def add_argument_group(self, *args, **kwargs):
return self.parser.add_argument_group(*args, **kwargs)
def parse_args(self, args=None, namespace=None):
return self.parser.parse_args(args, namespace)
def __getattr__(self, item):
return getattr(self.parser, item)
def __setattr__(self, key, value):
return setattr(self.parser, key, value)
if __name__ == '__main__': if __name__ == '__main__':
pass pass

40
gooey/python_bindings/gooey_parser.py

@ -0,0 +1,40 @@
from argparse import ArgumentParser
class GooeyParser(object):
def __init__(self, **kwargs):
self.__dict__['parser'] = ArgumentParser(**kwargs)
self.widgets = {}
@property
def _mutually_exclusive_groups(self):
return self.parser._mutually_exclusive_groups
@property
def _actions(self):
return self.parser._actions
@property
def description(self):
return self.parser.description
def add_argument(self, *args, **kwargs):
widget = kwargs.pop('widget', None)
self.parser.add_argument(*args, **kwargs)
self.widgets[self.parser._actions[-1].dest] = widget
def add_mutually_exclusive_group(self, **kwargs):
return self.parser.add_mutually_exclusive_group(**kwargs)
def add_argument_group(self, *args, **kwargs):
return self.parser.add_argument_group(*args, **kwargs)
def parse_args(self, args=None, namespace=None):
return self.parser.parse_args(args, namespace)
def __getattr__(self, item):
return getattr(self.parser, item)
def __setattr__(self, key, value):
return setattr(self.parser, key, value)
Loading…
Cancel
Save