Browse Source

Added WidgetTypes to allow file saving, opening, and miltifile select

pull/72/head
chriskiehl 9 years ago
parent
commit
15b1aa7c2e
5 changed files with 34 additions and 35 deletions
  1. 5
      gooey/__init__.py
  2. 5
      gooey/examples/widget_demo.py
  3. 17
      gooey/gui/widgets/components2.py
  4. 40
      gooey/gui/widgets/widget_pack.py
  5. 2
      gooey/python_bindings/argparse_to_json.py

5
gooey/__init__.py

@ -1,5 +1,8 @@
from gooey.python_bindings.gooey_decorator import Gooey
from gooey.python_bindings.gooey_parser import GooeyParser
__version__ = '0.1.2'
with open('version', 'r') as f:
version_num = f.read()
__version__ = version_num

5
gooey/examples/widget_demo.py

@ -17,7 +17,10 @@ def main():
desc = "Example application to show Gooey's various widgets"
file_help_msg = "Name of the file you want to process"
my_cool_parser = GooeyParser(description=desc)
my_cool_parser.add_argument("filename", help=file_help_msg, widget="FileChooser") # positional
my_cool_parser.add_argument("FileChooser", help=file_help_msg, widget="FileChooser") # positional
my_cool_parser.add_argument("DirectoryChooser", help=file_help_msg, widget="DirChooser") # positional
my_cool_parser.add_argument("FileSaver", help=file_help_msg, widget="FileSaver") # positional
my_cool_parser.add_argument("MultiFileSaver", help=file_help_msg, widget="MultiFileChooser") # positional
my_cool_parser.add_argument("directory", help="Directory to store output") # positional
my_cool_parser.add_argument('-c', '--countdown', default=2, type=int, help='sets the time to count down from you see its quite simple!')

17
gooey/gui/widgets/components2.py

@ -228,14 +228,15 @@ class RadioGroup(object):
FileChooser = lambda data: BaseGuiComponent(data=data, widget_pack=widget_pack.FileChooserPayload())
DirChooser = lambda data: BaseGuiComponent(data=data, widget_pack=widget_pack.DirChooserPayload())
DateChooser = lambda data: BaseGuiComponent(data=data, widget_pack=widget_pack.DateChooserPayload())
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
FileChooser = lambda data: BaseGuiComponent(data=data, widget_pack=widget_pack.FileChooserPayload())
MultiFileChooser = lambda data: BaseGuiComponent(data=data, widget_pack=widget_pack.MultiFileSaverPayload())
DirChooser = lambda data: BaseGuiComponent(data=data, widget_pack=widget_pack.DirChooserPayload())
FileSaver = lambda data: BaseGuiComponent(data=data, widget_pack=widget_pack.FileSaverPayload())
DateChooser = lambda data: BaseGuiComponent(data=data, widget_pack=widget_pack.DateChooserPayload())
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())

40
gooey/gui/widgets/widget_pack.py

@ -1,3 +1,4 @@
from functools import partial
from gooey.gui.util.filedrop import FileDrop
__author__ = 'Chris'
@ -65,13 +66,13 @@ class BaseChooser(WidgetPack):
def onButton(self, evt):
raise NotImplementedError
class FileChooserPayload(BaseChooser):
def __init__(self):
class BaseFileChooser(BaseChooser):
def __init__(self, dialog):
BaseChooser.__init__(self)
self.dialog = dialog
def onButton(self, evt):
dlg = wx.FileDialog(self.parent, style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
dlg = self.dialog(self.parent)
result = (dlg.GetPath()
if dlg.ShowModal() == wx.ID_OK
else None)
@ -80,29 +81,18 @@ class FileChooserPayload(BaseChooser):
# kinda hacky, but avoided a buncha boilerplate
self.text_box.SetLabelText(result)
def build_dialog(style, exist_constraint=True, **kwargs):
if exist_constraint:
return lambda panel: wx.FileDialog(panel, style=style | wx.FD_FILE_MUST_EXIST, **kwargs)
else:
return lambda panel: wx.FileDialog(panel, style=style, **kwargs)
class DirChooserPayload(BaseChooser):
def __init__(self):
BaseChooser.__init__(self)
def onButton(self, evt):
dlg = wx.DirDialog(self.parent, 'Select directory', style=wx.DD_DEFAULT_STYLE)
result = (dlg.GetPath()
if dlg.ShowModal() == wx.ID_OK
else None)
if result:
self.text_box.SetLabelText(result)
class DateChooserPayload(BaseChooser):
def __init__(self):
BaseChooser.__init__(self, button_text='Pick Date')
def onButton(self, evt):
dlg = CalendarDlg(self.parent)
dlg.ShowModal()
if dlg.GetPath():
self.text_box.SetLabelText(dlg.GetPath())
FileChooserPayload = partial(BaseFileChooser, dialog=build_dialog(wx.FD_OPEN))
FileSaverPayload = partial(BaseFileChooser, dialog=build_dialog(wx.FD_SAVE, False, defaultFile="Enter Filename"))
MultiFileSaverPayload = partial(BaseFileChooser, dialog=build_dialog(wx.FD_MULTIPLE, False))
DirChooserPayload = partial(BaseFileChooser, dialog=lambda parent: wx.DirDialog(parent, 'Select Directory', style=wx.DD_DEFAULT_STYLE))
DateChooserPayload = partial(BaseFileChooser, dialog=CalendarDlg)
class TextInputPayload(WidgetPack):

2
gooey/python_bindings/argparse_to_json.py

@ -15,6 +15,8 @@ import itertools
VALID_WIDGETS = (
'FileChooser',
'MultiFileChooser',
'FileSaver',
'DirChooser',
'DateChooser',
'TextField',

Loading…
Cancel
Save