Browse Source

move multi Chooser logic from BaseFileChooser;

fix bug in parsing `action='count'`
pull/119/head
Alexander Gordeyev 9 years ago
parent
commit
f14eb000e5
2 changed files with 29 additions and 10 deletions
  1. 37
      gooey/gui/widgets/widget_pack.py
  2. 2
      gooey/python_bindings/argparse_to_json.py

37
gooey/gui/widgets/widget_pack.py

@ -86,11 +86,32 @@ class BaseFileChooser(BaseChooser):
self.dialog = dialog self.dialog = dialog
def getValue(self): def getValue(self):
value = ' '.join(quote(x) for x in self.text_box.GetValue().split(os.pathsep))
value = self.text_box.GetValue()
if self.option_string and value:
return '{} {}'.format(self.option_string, quote(value))
return quote(value) if value else ''
def onButton(self, evt):
dlg = self.dialog(self.parent)
result = (self.get_path(dlg)
if dlg.ShowModal() == wx.ID_OK
else None)
if result:
self.text_box.SetValue(result)
def get_path(self, dlg):
return dlg.GetPath()
class BaseMultiFileChooser(BaseFileChooser):
def __init__(self, dialog):
BaseFileChooser.__init__(self, dialog)
def getValue(self):
value = ' '.join(quote(x) for x in self.text_box.GetValue().split(os.pathsep) if x)
if self.option_string and value: if self.option_string and value:
return '{} {}'.format(self.option_string, value) return '{} {}'.format(self.option_string, value)
else:
return value or ''
return value or ''
def onButton(self, evt): def onButton(self, evt):
dlg = self.dialog(self.parent) dlg = self.dialog(self.parent)
@ -101,10 +122,8 @@ class BaseFileChooser(BaseChooser):
self.text_box.SetValue(result) self.text_box.SetValue(result)
def get_path(self, dlg): def get_path(self, dlg):
if isinstance(dlg, wx.DirDialog) or isinstance(dlg, CalendarDlg):
return dlg.GetPath()
else:
return os.pathsep.join(dlg.GetPaths())
return os.pathsep.join(dlg.GetPaths())
class MyMultiDirChooser(MDD.MultiDirDialog): class MyMultiDirChooser(MDD.MultiDirDialog):
def __init(self, *args, **kwargs): def __init(self, *args, **kwargs):
@ -122,10 +141,10 @@ def build_dialog(style, exist_constraint=True, **kwargs):
FileChooserPayload = partial(BaseFileChooser, dialog=build_dialog(wx.FD_OPEN)) FileChooserPayload = partial(BaseFileChooser, dialog=build_dialog(wx.FD_OPEN))
FileSaverPayload = partial(BaseFileChooser, dialog=build_dialog(wx.FD_SAVE, False, defaultFile="Enter Filename")) FileSaverPayload = partial(BaseFileChooser, dialog=build_dialog(wx.FD_SAVE, False, defaultFile="Enter Filename"))
MultiFileSaverPayload = partial(BaseFileChooser, dialog=build_dialog(wx.FD_MULTIPLE, False))
MultiFileSaverPayload = partial(BaseMultiFileChooser, dialog=build_dialog(wx.FD_MULTIPLE, False))
DirChooserPayload = partial(BaseFileChooser, dialog=lambda parent: wx.DirDialog(parent, 'Select Directory', style=wx.DD_DEFAULT_STYLE)) DirChooserPayload = partial(BaseFileChooser, dialog=lambda parent: wx.DirDialog(parent, 'Select Directory', style=wx.DD_DEFAULT_STYLE))
DateChooserPayload = partial(BaseFileChooser, dialog=CalendarDlg) DateChooserPayload = partial(BaseFileChooser, dialog=CalendarDlg)
MultiDirChooserPayload = partial(BaseFileChooser, dialog=lambda parent: MyMultiDirChooser(parent, title="Select Directories", defaultPath=os.getcwd(), agwStyle=MDD.DD_MULTIPLE|MDD.DD_DIR_MUST_EXIST))
MultiDirChooserPayload = partial(BaseMultiFileChooser, dialog=lambda parent: MyMultiDirChooser(parent, title="Select Directories", defaultPath=os.getcwd(), agwStyle=MDD.DD_MULTIPLE|MDD.DD_DIR_MUST_EXIST))
class TextInputPayload(WidgetPack): class TextInputPayload(WidgetPack):
def __init__(self, no_quoting=False): def __init__(self, no_quoting=False):

2
gooey/python_bindings/argparse_to_json.py

@ -85,7 +85,7 @@ def categorize(actions, widget_dict, required=False):
elif is_flag(action): elif is_flag(action):
yield as_json(action, _get_widget(action) or 'CheckBox', required) yield as_json(action, _get_widget(action) or 'CheckBox', required)
elif is_counter(action): elif is_counter(action):
_json = as_json(action, _get_widget(action) or 'Dropdown', required)
_json = as_json(action, _get_widget(action) or 'Counter', required)
# pre-fill the 'counter' dropdown # pre-fill the 'counter' dropdown
_json['data']['choices'] = map(str, range(1, 11)) _json['data']['choices'] = map(str, range(1, 11))
yield _json yield _json

Loading…
Cancel
Save