Browse Source

closes #523 - added ColourChooser widget

1.0.4-release-candidate
conradhilley 4 years ago
committed by Chris
parent
commit
3307f8b04b
6 changed files with 39 additions and 6 deletions
  1. 7
      gooey/gui/components/widgets/choosers.py
  2. 2
      gooey/gui/components/widgets/core/__init__.py
  3. 25
      gooey/gui/components/widgets/core/chooser.py
  4. 1
      gooey/languages/english.json
  5. 4
      gooey/tests/all_widgets.py
  6. 6
      gooey/tests/all_widgets_subparser.py

7
gooey/gui/components/widgets/choosers.py

@ -7,7 +7,8 @@ __ALL__ = [
'FileSaver',
'DirChooser',
'MultiDirChooser',
'DateChooser'
'DateChooser',
'ColourChooser'
]
class FileChooser(BaseChooser):
@ -29,6 +30,7 @@ class DirChooser(BaseChooser):
# todo: allow wildcard
widget_class = core.DirChooser
class MultiDirChooser(BaseChooser):
# todo: allow wildcard
widget_class = core.MultiDirChooser
@ -38,3 +40,6 @@ class DateChooser(BaseChooser):
# todo: allow wildcard
widget_class = core.DateChooser
class ColourChooser(BaseChooser):
widget_class = core.ColourChooser

2
gooey/gui/components/widgets/core/__init__.py

@ -1,2 +1,2 @@
from . chooser import Chooser, FileChooser, FileSaver, DirChooser, DateChooser, MultiFileChooser, MultiDirChooser
from . chooser import Chooser, FileChooser, FileSaver, DirChooser, DateChooser, MultiFileChooser, MultiDirChooser, ColourChooser
from . text_input import PasswordInput, MultilineTextInput, TextInput

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

@ -120,7 +120,7 @@ class MultiDirChooser(Chooser):
class DateChooser(Chooser):
""" Launches a date picker which returns and ISO Date """
""" Launches a date picker which returns an ISO Date """
def __init__(self, *args, **kwargs):
defaults = {'label': _('choose_date')}
super(DateChooser, self).__init__(*args, **merge(kwargs, defaults))
@ -130,6 +130,29 @@ class DateChooser(Chooser):
return CalendarDlg(self)
class ColourChooser(Chooser):
""" Launches a color picker which returns a hex color code"""
def __init__(self, *args, **kwargs):
defaults = {'label': _('choose_colour'),
'style': wx.TE_RICH}
super(ColourChooser, self).__init__(*args, **merge(kwargs, defaults))
def setValue(self, value):
colour = wx.Colour(value)
self.widget.widget.SetForegroundColour(colour)
self.widget.widget.SetBackgroundColour(colour)
self.widget.setValue(value)
def getResult(self, dialog):
colour = dialog.GetColourData().GetColour()
# Set text box back/foreground to selected colour
self.widget.widget.SetForegroundColour(colour)
self.widget.widget.SetBackgroundColour(colour)
return colour.GetAsString(wx.C2S_HTML_SYNTAX)
def getDialog(self):
return wx.ColourDialog(self)

1
gooey/languages/english.json

@ -2,6 +2,7 @@
"browse": "Browse",
"cancel": "Cancel",
"checkbox_label": "Enable",
"choose_colour": "Choose Colour",
"choose_date": "Choose Date",
"choose_file": "Choose File",
"choose_folder": "Choose Folder",

4
gooey/tests/all_widgets.py

@ -68,6 +68,7 @@ def main():
parser.add_argument("--filesaver", default="fs-value", widget='FileSaver')
parser.add_argument("--dirchooser", default="dc-value", widget='DirChooser')
parser.add_argument("--datechooser", default="2015-01-01", widget='DateChooser')
parser.add_argument("--colourchooser", default="#000000", widget='ColourChooser')
dest_vars = [
'textfield',
@ -82,7 +83,8 @@ def main():
'filechooser',
'filesaver',
'dirchooser',
'datechooser'
'datechooser',
'colourchooser'
]

6
gooey/tests/all_widgets_subparser.py

@ -67,6 +67,7 @@ def main():
parser_one.add_argument("--filesaver", default="fs-value", widget='FileSaver')
parser_one.add_argument("--dirchooser", default="dc-value", widget='DirChooser')
parser_one.add_argument("--datechooser", default="2015-01-01", widget='DateChooser')
parser_one.add_argument("--colourchooser", default="#000000", widget='ColourChooser')
parser_two = subs.add_parser('parser2', prog="parser 2")
parser_two.add_argument('--textfield', default=2, widget="TextField")
@ -120,6 +121,7 @@ def main():
parser_two.add_argument("--filesaver", default="fs-value", widget='FileSaver')
parser_two.add_argument("--dirchooser", default="dc-value", widget='DirChooser')
parser_two.add_argument("--datechooser", default="2015-01-01",widget='DateChooser')
parser_two.add_argument("--colourchooser", default="#000000", widget='ColourChooser')
dest_vars = [
'textfield',
@ -134,7 +136,8 @@ def main():
'filechooser',
'filesaver',
'dirchooser',
'datechooser'
'datechooser',
'colourchooser'
]
parser.parse_args()
@ -147,6 +150,5 @@ def main():
print("Success")
if __name__ == '__main__':
main()
Loading…
Cancel
Save