Browse Source

Add support for wildcards, message, defualtFile, DefaultDir and DefaultPath for Choosers

pull/473/head
liranw 6 years ago
committed by Chris
parent
commit
c1a878700a
1 changed files with 25 additions and 8 deletions
  1. 33
      gooey/gui/components/widgets/core/chooser.py

33
gooey/gui/components/widgets/core/chooser.py

@ -64,13 +64,24 @@ class Chooser(wx.Panel):
class FileChooser(Chooser): class FileChooser(Chooser):
""" Retrieve an existing file from the system """ """ Retrieve an existing file from the system """
def getDialog(self): def getDialog(self):
return wx.FileDialog(self, _('open_file'), style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
options = self.Parent._options
return wx.FileDialog(self, message=options.get('message', _('open_file')),
style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST,
defaultFile=options.get('defaultFile', _("enter_filename")),
defaultDir=options.get('defaultDir', _('')),
wildcard=options.get('wildcard', wx.FileSelectorDefaultWildcardStr))
class MultiFileChooser(Chooser): class MultiFileChooser(Chooser):
""" Retrieve an multiple files from the system """ """ Retrieve an multiple files from the system """
def getDialog(self): def getDialog(self):
return wx.FileDialog(self, _('open_files'), style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST | wx.FD_MULTIPLE)
options = self.Parent._options
return wx.FileDialog(self, message=options.get('message', _('open_files')),
style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST | wx.FD_MULTIPLE,
defaultFile=options.get('defaultFile', _("enter_filename")),
defaultDir=options.get('defaultDir', _('')),
wildcard=options.get('wildcard', wx.FileSelectorDefaultWildcardStr))
def getResult(self, dialog): def getResult(self, dialog):
return os.pathsep.join(dialog.GetPaths()) return os.pathsep.join(dialog.GetPaths())
@ -78,26 +89,32 @@ class MultiFileChooser(Chooser):
class FileSaver(Chooser): class FileSaver(Chooser):
""" Specify the path to save a new file """ """ Specify the path to save a new file """
def getDialog(self): def getDialog(self):
options = self.Parent._options
return wx.FileDialog( return wx.FileDialog(
self, self,
style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT, style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT,
defaultFile=_("enter_filename"),
message=_('choose_file')
defaultFile=options.get('defaultFile', _("enter_filename")),
defaultDir=options.get('defaultDir', _('')),
message=options.get('message', _('choose_file')),
wildcard=options.get('wildcard', wx.FileSelectorDefaultWildcardStr)
) )
class DirChooser(Chooser): class DirChooser(Chooser):
""" Retrieve a path to the supplied directory """ """ Retrieve a path to the supplied directory """
def getDialog(self): def getDialog(self):
return wx.DirDialog(self, message=_('choose_folder'))
options = self.Parent._options
return wx.DirDialog(self, message=options.get('message', _('choose_folder')),
defaultPath=options.get('defaultPath', os.getcwd()))
class MultiDirChooser(Chooser): class MultiDirChooser(Chooser):
""" Retrieve an multiple directories from the system """ """ Retrieve an multiple directories from the system """
def getDialog(self): def getDialog(self):
options = self.Parent._options
return MDD.MultiDirDialog(self, return MDD.MultiDirDialog(self,
message=_('choose_folders_msg'),
message=options.get('message', _('choose_folders')),
title=_('choose_folders_title'), title=_('choose_folders_title'),
defaultPath=os.getcwd(),
defaultPath=options.get('defaultPath', os.getcwd()),
agwStyle=MDD.DD_MULTIPLE | MDD.DD_DIR_MUST_EXIST) agwStyle=MDD.DD_MULTIPLE | MDD.DD_DIR_MUST_EXIST)
def getResult(self, dialog): def getResult(self, dialog):
return os.pathsep.join(dialog.GetPaths()) return os.pathsep.join(dialog.GetPaths())

Loading…
Cancel
Save