Added parameter binding ability for Input
kwargs can now be set on init which allows for additional parameters on events. Will have to go over all the code to implement a standardised solution.
This commit is contained in:
parent
e2bfb79cdf
commit
6ae115a206
1 changed files with 19 additions and 2 deletions
|
@ -2,17 +2,34 @@ FUNCTION = type(lambda: 1)
|
||||||
|
|
||||||
class Input:
|
class Input:
|
||||||
def __init__(self, caption, initial_text="", on_done=None, on_change=None,
|
def __init__(self, caption, initial_text="", on_done=None, on_change=None,
|
||||||
on_cancel=None):
|
on_cancel=None, kwargs={}):
|
||||||
self.caption = caption
|
self.caption = caption
|
||||||
self.initial_text = initial_text
|
self.initial_text = initial_text
|
||||||
self.on_done = on_done
|
self.on_done = on_done
|
||||||
self.on_change = on_change
|
self.on_change = on_change
|
||||||
self.on_cancel = on_cancel
|
self.on_cancel = on_cancel
|
||||||
|
self.kwargs = kwargs
|
||||||
|
|
||||||
|
|
||||||
|
def wrapped_on_done(self, input_):
|
||||||
|
if not self.on_done == None:
|
||||||
|
self.on_done(input_, **self.kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def wrapped_on_change(self, input_):
|
||||||
|
if not self.on_change == None:
|
||||||
|
self.on_change(input_, **self.kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def wrapped_on_cancel(self):
|
||||||
|
if not self.on_cancel == None:
|
||||||
|
self.on_cancel(**self.kwargs)
|
||||||
|
|
||||||
|
|
||||||
def invoke(self, window):
|
def invoke(self, window):
|
||||||
window.show_input_panel(self.caption, self.initial_text,
|
window.show_input_panel(self.caption, self.initial_text,
|
||||||
self.on_done, self.on_change, self.on_cancel)
|
self.wrapped_on_done, self.wrapped_on_change,
|
||||||
|
self.wrapped_on_cancel)
|
||||||
|
|
||||||
|
|
||||||
class Entry:
|
class Entry:
|
||||||
|
|
Reference in a new issue