Created
August 27, 2014 08:29
-
-
Save SylvainDe/0d4e7eec2ca223e1cf02 to your computer and use it in GitHub Desktop.
FilePickerPatch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 77cef5f99dbcbb5b0516e55e990cb8879cc366ba Mon Sep 17 00:00:00 2001 | |
From: Sylvain Desodt <sylvain.desodt+github@gmail.com> | |
Date: Wed, 27 Aug 2014 09:58:47 +0200 | |
Subject: [PATCH] [DEV] Support of file picker for text options | |
Changes have been made to be able to choose easily if text options will | |
be displayed as a text field or as a file picker (typing filename without | |
the autocompletion can be a bit tedious). | |
An idea would be to give the decorator an information that could be used | |
to determine for each text field the proper input to use. I don't have | |
much time to look at this but an example could be to feed a regex such that | |
if the option name (or option description) matches the regex, a file picker | |
is used, otherwise, a text field is used. (A default value could then be : | |
'.*file.*'). | |
Change-Id: I0f400bc93b6299066417f4302cfab33b0cb9dad4 | |
--- | |
gooey/gui/components.py | 51 +++++++++++++++++++++++++++---------------------- | |
1 file changed, 28 insertions(+), 23 deletions(-) | |
diff --git a/gooey/gui/components.py b/gooey/gui/components.py | |
index 0ff3cc4..ddb8eb1 100644 | |
--- a/gooey/gui/components.py | |
+++ b/gooey/gui/components.py | |
@@ -123,11 +123,10 @@ class AbstractComponent(object): | |
self._msg.Wrap(content_area) | |
-class Positional(AbstractComponent): | |
+class TextComponent(AbstractComponent): | |
""" | |
- Represents a positional argument in a program | |
- e.g. | |
- mypyfile.py param1 <-- this guy | |
+ Represents a text component (either optional | |
+ or mandatory). | |
""" | |
def __init__(self, action): | |
self._action = action | |
@@ -135,8 +134,24 @@ class Positional(AbstractComponent): | |
self.contents = None | |
def BuildInputWidget(self, parent, action): | |
+ return wx.FilePickerCtrl(parent) | |
return wx.TextCtrl(parent) | |
+ def GetValueFromWidget(self): | |
+ if hasattr(self._widget, 'GetValue'): | |
+ return self._widget.GetValue() | |
+ elif hasattr(self._widget, 'GetPath'): | |
+ return self._widget.GetPath() | |
+ assert False | |
+ return None | |
+ | |
+ | |
+class Positional(TextComponent): | |
+ """ | |
+ Represents a positional argument in a program | |
+ e.g. | |
+ mypyfile.py param1 <-- this guy | |
+ """ | |
def GetValue(self): | |
''' | |
Positionals have no associated options_string, | |
@@ -148,9 +163,8 @@ class Positional(AbstractComponent): | |
"argument_value" | |
''' | |
self.AssertInitialization('Positional') | |
- if str(self._widget.GetValue()) == EMPTY: | |
- return None | |
- return self._widget.GetValue() | |
+ val = self.GetValueFromWidget() | |
+ return val if val else None | |
class Choice(AbstractComponent): | |
@@ -169,11 +183,12 @@ class Choice(AbstractComponent): | |
"--option_name argument" | |
''' | |
self.AssertInitialization('Choice') | |
- if self._widget.GetValue() == self._DEFAULT_VALUE: | |
- return None | |
+ val = self._widget.GetValue() | |
+ if val == self._DEFAULT_VALUE: | |
+ return None | |
return ' '.join( | |
[self._action.option_strings[0], # get the verbose copy if available | |
- self._widget.GetValue()]) | |
+ val]) if val else None | |
def BuildInputWidget(self, parent, action): | |
return wx.ComboBox( | |
@@ -185,15 +200,7 @@ class Choice(AbstractComponent): | |
) | |
-class Optional(AbstractComponent): | |
- def __init__(self, action): | |
- self._action = action | |
- self._widget = None | |
- self.contents = None | |
- | |
- def BuildInputWidget(self, parent, action): | |
- return wx.TextCtrl(parent) | |
- | |
+class Optional(TextComponent): | |
def GetValue(self): | |
''' | |
General options are key/value style pairs (conceptually). | |
@@ -205,12 +212,10 @@ class Optional(AbstractComponent): | |
"--Option Value" | |
''' | |
self.AssertInitialization('Optional') | |
- value = self._widget.GetValue() | |
- if not value: | |
- return None | |
+ value = self.GetValueFromWidget() | |
return ' '.join( | |
[self._action.option_strings[0], # get the verbose copy if available | |
- value]) | |
+ value]) if value else None | |
class Flag(AbstractComponent): | |
-- | |
1.8.3.2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment