From 8284b7224cfc615e8ddf8b9e8e388b55678f0372 Mon Sep 17 00:00:00 2001 From: chriskiehl Date: Sat, 22 Nov 2014 21:02:59 -0500 Subject: [PATCH] Added drag/drop support to plain text fields --- gooey/_tmp/mockapp.py | 2 +- gooey/gui/util/__init__.py | 1 + gooey/gui/util/filedrop.py | 10 ++++++++++ gooey/gui/widgets/widget_pack.py | 14 ++++---------- gooey/mockapplications/mockapp.py | 2 +- 5 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 gooey/gui/util/__init__.py create mode 100644 gooey/gui/util/filedrop.py diff --git a/gooey/_tmp/mockapp.py b/gooey/_tmp/mockapp.py index 61c07cf..af32804 100644 --- a/gooey/_tmp/mockapp.py +++ b/gooey/_tmp/mockapp.py @@ -24,7 +24,7 @@ def main(): file_help_msg = "Name of the file you want to process" my_cool_parser = GooeyParser(description=desc) my_cool_parser.add_argument("filename", help=file_help_msg, widget="FileChooser") # positional - my_cool_parser.add_argument("outfile", help="Name of the file where you'll save the output", widget="FileChooser") # positional + my_cool_parser.add_argument("outfile", help="Name of the file where you'll save the output") # positional my_cool_parser.add_argument('-c', '--countdown', default=10, type=int, help='sets the time to count down from you see its quite simple!', widget='DateChooser') # my_cool_parser.add_argument('-c', '--cron-schedule', default=10, type=int, help='Set the datetime when the cron should begin', widget='DateChooser') my_cool_parser.add_argument("-s", "--showtime", action="store_true", help="display the countdown timer") diff --git a/gooey/gui/util/__init__.py b/gooey/gui/util/__init__.py new file mode 100644 index 0000000..6bca6f6 --- /dev/null +++ b/gooey/gui/util/__init__.py @@ -0,0 +1 @@ +__author__ = 'Chris' diff --git a/gooey/gui/util/filedrop.py b/gooey/gui/util/filedrop.py new file mode 100644 index 0000000..460809d --- /dev/null +++ b/gooey/gui/util/filedrop.py @@ -0,0 +1,10 @@ +import wx + +class FileDrop(wx.FileDropTarget): + def __init__(self, window): + wx.FileDropTarget.__init__(self) + self.window = window + + def OnDropFiles(self, x, y, filenames): + for name in filenames: + self.window.WriteText(name) diff --git a/gooey/gui/widgets/widget_pack.py b/gooey/gui/widgets/widget_pack.py index 5837cb0..313b2f2 100644 --- a/gooey/gui/widgets/widget_pack.py +++ b/gooey/gui/widgets/widget_pack.py @@ -1,3 +1,5 @@ +from gooey.gui.util.filedrop import FileDrop + __author__ = 'Chris' from abc import ABCMeta, abstractmethod @@ -26,16 +28,6 @@ class WidgetPack(object): pass -class FileDrop(wx.FileDropTarget): - def __init__(self, window): - wx.FileDropTarget.__init__(self) - self.window = window - - def OnDropFiles(self, x, y, filenames): - - for name in filenames: - self.window.WriteText(name) - class BaseChooser(WidgetPack): @@ -121,6 +113,8 @@ class TextInputPayload(WidgetPack): def build(self, parent, data): self.option_string = data['commands'][0] if data['commands'] else '' self.widget = wx.TextCtrl(parent) + dt = FileDrop(self.widget) + self.widget.SetDropTarget(dt) self.widget.SetMinSize((0, -1)) self.widget.SetDoubleBuffered(True) return self.widget diff --git a/gooey/mockapplications/mockapp.py b/gooey/mockapplications/mockapp.py index fb44c28..839ef77 100644 --- a/gooey/mockapplications/mockapp.py +++ b/gooey/mockapplications/mockapp.py @@ -25,7 +25,7 @@ def main(): file_help_msg = "Name of the file you want to process" my_cool_parser = GooeyParser(description=desc) my_cool_parser.add_argument("filename", help=file_help_msg, widget="FileChooser") # positional - my_cool_parser.add_argument("outfile", help="Name of the file where you'll save the output", widget="FileChooser") # positional + my_cool_parser.add_argument("outfile", help="Name of the file where you'll save the output") # positional my_cool_parser.add_argument('-c', '--countdown', default=10, type=int, help='sets the time to count down from you see its quite simple!', widget='DateChooser') # my_cool_parser.add_argument('-c', '--cron-schedule', default=10, type=int, help='Set the datetime when the cron should begin', widget='DateChooser') my_cool_parser.add_argument("-s", "--showtime", action="store_true", help="display the countdown timer")