From 7cd7df8c75969b81b94cc8c11714b62668490b44 Mon Sep 17 00:00:00 2001 From: Roshgar Date: Fri, 12 Jun 2015 19:03:27 +0200 Subject: [PATCH] Added MDD to widget_pack --- gooey/gui/widgets/widget_pack.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/gooey/gui/widgets/widget_pack.py b/gooey/gui/widgets/widget_pack.py index 8d2812a..37d09a3 100644 --- a/gooey/gui/widgets/widget_pack.py +++ b/gooey/gui/widgets/widget_pack.py @@ -7,6 +7,7 @@ __author__ = 'Chris' from abc import ABCMeta, abstractmethod import wx +import wx.lib.agw.multidirdialog as MDD from gooey.gui.widgets.calender_dialog import CalendarDlg @@ -96,7 +97,6 @@ class BaseFileChooser(BaseChooser): paths = dlg.GetPaths() return paths[0] if len(paths) < 2 else ' '.join(paths) - 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) @@ -104,12 +104,36 @@ def build_dialog(style, exist_constraint=True, **kwargs): return lambda panel: wx.FileDialog(panel, style=style, **kwargs) +class multiDirChooser(BaseChooser): + def __init__(self, dialog): + BaseChooser.__init__(self) + self.dialog = dialog + + 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): + paths = dlg.dirCtrl.GetPaths() + return paths[0] if len(paths) < 2 else ' '.join(paths) + + +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) + 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) - +MultiDirChooserPayload = partial(multiDirChooser, dialog=lambda parent: MDD.MultiDirDialog(None, title="Select Directories", defaultPath=os.getcwd(), agwStyle=MDD.DD_MULTIPLE|MDD.DD_DIR_MUST_EXIST)) class TextInputPayload(WidgetPack): def __init__(self): @@ -198,4 +222,3 @@ class CounterPayload(WidgetPack): repeated_args = arg * int(dropdown_value) return '-' + repeated_args -