|
@ -8,24 +8,44 @@ from gooey.gui.components.widgets.dialogs.calender_dialog import CalendarDlg |
|
|
from gooey.gui.components.widgets.dialogs.time_dialog import TimeDlg |
|
|
from gooey.gui.components.widgets.dialogs.time_dialog import TimeDlg |
|
|
from gooey.gui.lang.i18n import _ |
|
|
from gooey.gui.lang.i18n import _ |
|
|
from gooey.util.functional import merge |
|
|
from gooey.util.functional import merge |
|
|
|
|
|
from gui.util.filedrop import FileDrop |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Chooser(wx.Panel): |
|
|
class Chooser(wx.Panel): |
|
|
""" |
|
|
""" |
|
|
|
|
|
TODO: Tests! |
|
|
|
|
|
TODO: Document GooeyOptions! |
|
|
Base 'Chooser' type. |
|
|
Base 'Chooser' type. |
|
|
|
|
|
|
|
|
Launches a Dialog box that allows the user to pick files, directories, |
|
|
Launches a Dialog box that allows the user to pick files, directories, |
|
|
dates, etc.. and places the result into a TextInput in the UI |
|
|
dates, etc.. and places the result into a TextInput in the UI |
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TODO: oh, young me. DRY != Good Abstraction |
|
|
|
|
|
TODO: this is another weird inheritance hierarchy that's hard |
|
|
|
|
|
to follow. Why do subclasses rather into, not their parent |
|
|
|
|
|
class, but their _physical_ UI parent to grab the Gooey Options? |
|
|
|
|
|
All this could be simplified to make the data flow |
|
|
|
|
|
more apparent. |
|
|
|
|
|
""" |
|
|
|
|
|
_gooey_options = { |
|
|
|
|
|
'pathsep': str |
|
|
|
|
|
} |
|
|
def __init__(self, parent, *args, **kwargs): |
|
|
def __init__(self, parent, *args, **kwargs): |
|
|
super(Chooser, self).__init__(parent) |
|
|
super(Chooser, self).__init__(parent) |
|
|
|
|
|
self.options = parent._options |
|
|
buttonLabel = kwargs.pop('label', _('browse')) |
|
|
buttonLabel = kwargs.pop('label', _('browse')) |
|
|
self.widget = TextInput(self, *args, **kwargs) |
|
|
self.widget = TextInput(self, *args, **kwargs) |
|
|
self.button = wx.Button(self, label=buttonLabel) |
|
|
self.button = wx.Button(self, label=buttonLabel) |
|
|
self.button.Bind(wx.EVT_BUTTON, self.spawnDialog) |
|
|
self.button.Bind(wx.EVT_BUTTON, self.spawnDialog) |
|
|
|
|
|
self.dropTarget = FileDrop(self.widget, self.dropHandler) |
|
|
|
|
|
self.SetDropTarget(self.dropTarget) |
|
|
|
|
|
self.widget.SetDropTarget(self.dropTarget) |
|
|
self.layout() |
|
|
self.layout() |
|
|
|
|
|
|
|
|
|
|
|
def dropHandler(self, x, y, filenames): |
|
|
|
|
|
sep = self.options.get('pathsep', os.pathsep) |
|
|
|
|
|
self.widget.setValue(sep.join(filenames)) |
|
|
|
|
|
return True |
|
|
|
|
|
|
|
|
def layout(self): |
|
|
def layout(self): |
|
|
layout = wx.BoxSizer(wx.HORIZONTAL) |
|
|
layout = wx.BoxSizer(wx.HORIZONTAL) |
|
@ -36,25 +56,21 @@ class Chooser(wx.Panel): |
|
|
v.Add(layout, 1, wx.EXPAND, wx.TOP, 1) |
|
|
v.Add(layout, 1, wx.EXPAND, wx.TOP, 1) |
|
|
self.SetSizer(v) |
|
|
self.SetSizer(v) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def spawnDialog(self, event): |
|
|
def spawnDialog(self, event): |
|
|
fd = self.getDialog() |
|
|
fd = self.getDialog() |
|
|
if fd.ShowModal() == wx.ID_CANCEL: |
|
|
if fd.ShowModal() == wx.ID_CANCEL: |
|
|
return |
|
|
return |
|
|
self.processResult(self.getResult(fd)) |
|
|
self.processResult(self.getResult(fd)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getDialog(self): |
|
|
def getDialog(self): |
|
|
return wx.FileDialog(self, _('open_file')) |
|
|
return wx.FileDialog(self, _('open_file')) |
|
|
|
|
|
|
|
|
def getResult(self, dialog): |
|
|
def getResult(self, dialog): |
|
|
return dialog.GetPath() |
|
|
return dialog.GetPath() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def processResult(self, result): |
|
|
def processResult(self, result): |
|
|
self.setValue(result) |
|
|
self.setValue(result) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def setValue(self, value): |
|
|
def setValue(self, value): |
|
|
self.widget.setValue(value) |
|
|
self.widget.setValue(value) |
|
|
|
|
|
|
|
@ -137,17 +153,16 @@ class DateChooser(Chooser): |
|
|
defaults = {'label': _('choose_date')} |
|
|
defaults = {'label': _('choose_date')} |
|
|
super(DateChooser, self).__init__(*args, **merge(kwargs, defaults)) |
|
|
super(DateChooser, self).__init__(*args, **merge(kwargs, defaults)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getDialog(self): |
|
|
def getDialog(self): |
|
|
return CalendarDlg(self) |
|
|
return CalendarDlg(self) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TimeChooser(Chooser): |
|
|
class TimeChooser(Chooser): |
|
|
""" Launches a time picker which returns and ISO Time """ |
|
|
""" Launches a time picker which returns and ISO Time """ |
|
|
def __init__(self, *args, **kwargs): |
|
|
def __init__(self, *args, **kwargs): |
|
|
defaults = {'label': _('choose_time')} |
|
|
defaults = {'label': _('choose_time')} |
|
|
super(TimeChooser, self).__init__(*args, **merge(kwargs, defaults)) |
|
|
super(TimeChooser, self).__init__(*args, **merge(kwargs, defaults)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getDialog(self): |
|
|
def getDialog(self): |
|
|
return TimeDlg(self) |
|
|
return TimeDlg(self) |
|
|
|
|
|
|
|
|