From c86cd6dbce6f88670a8f3abd24f7dcb9ae7383c1 Mon Sep 17 00:00:00 2001 From: liranw Date: Mon, 3 Jun 2019 12:05:19 +0300 Subject: [PATCH] Update options to snake_case instead of CamelCase and add it to documentation --- docs/Gooey-Options.md | 58 ++++++++++++++++++++ gooey/gui/components/widgets/core/chooser.py | 17 +++--- 2 files changed, 66 insertions(+), 9 deletions(-) diff --git a/docs/Gooey-Options.md b/docs/Gooey-Options.md index f538aea..1f8843c 100644 --- a/docs/Gooey-Options.md +++ b/docs/Gooey-Options.md @@ -131,4 +131,62 @@ parser.add_argument_group('MyGroup', desription='my cool group', gooey_options={ | margin_top | int | specifies the top margin in pixels for this group | ![image](https://user-images.githubusercontent.com/1408720/57576112-9c77bb00-740d-11e9-9dac-4e798699a35c.png) + + + +## File and Folder choosers + +File and Folder Choosers Groups take a number of `gooey_options` to help control default values. + +```python +parser.add_argument("FileChooser", widget="FileChooser", + gooey_options={ + 'wildcard': + "Comma separated file (*.csv)|*.csv|" + "All files (*.*)|*.*", + 'default_dir': "c:/batch", + 'default_file': "def_file.csv", + 'message': "pick me" + } + ) +parser.add_argument("DirectoryChooser", widget="DirChooser", + gooey_options={ + 'wildcard': + "Comma separated file (*.csv)|*.csv|" + "All files (*.*)|*.*", + 'message': "pick folder", + 'default_path': "c:/batch/stuff" + } + ) +parser.add_argument("FileSaver", widget="FileSaver", + gooey_options={ + 'wildcard': + "JPG (*.jpg)|*.jpg|" + "All files (*.*)|*.*", + 'message': "pick folder", + 'default_dir': "c:/projects", + 'default_file': "def_file.csv" + } + ) +parser.add_argument("MultiFileSaver", widget="MultiFileChooser", + gooey_options={ + 'wildcard': + "Comma separated file (*.csv)|*.csv|" + "All files (*.*)|*.*", + 'message': "pick folder", + 'default_dir': "c:/temp", + 'default_file': "def_file.csv" + } + ) +``` +| Keyword | Type | Description | +|---------|------|-------------| +| wildcard | string | Sets the wildcard, which can contain multiple file types, for example: "BMP files (.bmp)|.bmp|GIF files (.gif)|.gif" | +| message | string | Sets the message that will be displayed on the dialog. | +| default_dir | string | The default directory | +| default_file | string | The default filename | +| default_path | string | The default path | + + + \ No newline at end of file diff --git a/gooey/gui/components/widgets/core/chooser.py b/gooey/gui/components/widgets/core/chooser.py index e250201..e8a4c42 100644 --- a/gooey/gui/components/widgets/core/chooser.py +++ b/gooey/gui/components/widgets/core/chooser.py @@ -60,15 +60,14 @@ class Chooser(wx.Panel): return self.widget.getValue() - class FileChooser(Chooser): """ Retrieve an existing file from the system """ def getDialog(self): 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', _('')), + defaultFile=options.get('default_file', _("enter_filename")), + defaultDir=options.get('default_dir', _('')), wildcard=options.get('wildcard', wx.FileSelectorDefaultWildcardStr)) @@ -78,8 +77,8 @@ class MultiFileChooser(Chooser): 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', _('')), + defaultFile=options.get('default_file', _("enter_filename")), + defaultDir=options.get('default_dir', _('')), wildcard=options.get('wildcard', wx.FileSelectorDefaultWildcardStr)) def getResult(self, dialog): @@ -93,8 +92,8 @@ class FileSaver(Chooser): return wx.FileDialog( self, style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT, - defaultFile=options.get('defaultFile', _("enter_filename")), - defaultDir=options.get('defaultDir', _('')), + defaultFile=options.get('default_file', _("enter_filename")), + defaultDir=options.get('default_dir', _('')), message=options.get('message', _('choose_file')), wildcard=options.get('wildcard', wx.FileSelectorDefaultWildcardStr) ) @@ -105,7 +104,7 @@ class DirChooser(Chooser): def getDialog(self): options = self.Parent._options return wx.DirDialog(self, message=options.get('message', _('choose_folder')), - defaultPath=options.get('defaultPath', os.getcwd())) + defaultPath=options.get('default_path', os.getcwd())) class MultiDirChooser(Chooser): """ Retrieve an multiple directories from the system """ @@ -114,7 +113,7 @@ class MultiDirChooser(Chooser): return MDD.MultiDirDialog(self, message=options.get('message', _('choose_folders')), title=_('choose_folders_title'), - defaultPath=options.get('defaultPath', os.getcwd()), + defaultPath=options.get('default_path', os.getcwd()), agwStyle=MDD.DD_MULTIPLE | MDD.DD_DIR_MUST_EXIST) def getResult(self, dialog): return os.pathsep.join(dialog.GetPaths())