Commit d032e28f authored by GUILLOU Perceval's avatar GUILLOU Perceval
Browse files

build BlissDialog

parent 46eb2072
......@@ -259,103 +259,125 @@ class AskInt(UserInput):
self.maxi = maxi
class _BaseWidget:
""" Dialog widget base class """
def __init__(self, label=""):
self.label = label
self.build()
class widget:
def build(self):
self.body = None
def display( user_input ):
dlg = None
title = user_input.title
text = user_input.label
def get_result(self):
return None
if isinstance( user_input, AskYesNo ):
dlg = yes_no_dialog(title, text, yes_text='Yes', no_text='No', style=None, async_=False)
#class DlgMsg(_BaseWidget):
# def __init__(self, label="This is a message"):
# super().__init__(self, label=label)
#
# def build(self):
# self.body = Label(text=self.label, dont_extend_height=True)
#
# def get_result(self):
# return True
elif isinstance( user_input, AskStr ):
class DlgInput(_BaseWidget):
def __init__(self, label="Please, enter a value"):
super().__init__(label)
self.label = label
self.build()
dlg = input_dialog(title, text, ok_text='OK', cancel_text='Cancel',
completer=None, password=False, style=None, async_=False)
def build(self):
elif isinstance( user_input, AskInt ):
wlabel = Label(text=self.label, dont_extend_height=True, dont_extend_width=True)
dlg = input_dialog(title, text, ok_text='OK', cancel_text='Cancel',
completer=None, password=False, style=None, async_=False)
self.textfield = TextArea(
multiline=False,
#password=password,
#completer=completer,
accept_handler=self.accept)
print(f"answer = {dlg}")
self.body = VSplit( [wlabel, self.textfield] )
def get_result(self):
return self.textfield.text
def multi_dialog( user_input_2d_list, title="", ok_text='OK', cancel_text='Cancel', style=None, async_=False ):
def accept(self, buf):
return True
#class dlg_result:
# def __init__(self, dlg):
def ok_handler():
ans = []
for r in results:
def get_dlg_widget(user_input):
if isinstance(user_input, ( AskStr, AskInt ) ):
return DlgInput(user_input.label)
else:
raise NotImplementedError
get_app().exit(result=results)
class BlissDialog(Dialog):
def __init__(self, user_input_2d_list, title="", ok_text="OK", cancel_text="Cancel", style=None):
self.user_input_2d_list = user_input_2d_list
self.style = style
#radio_list = RadioList(values)
buttons = [ Button(text=ok_text, handler=self.ok_handler), Button(text=cancel_text, handler=self.cancel_handler), ]
body = self.build()
results = []
super().__init__(title=title, body=body, buttons=buttons, with_background=True)
h_list = []
def ok_handler(self):
get_app().exit(result= [res() for res in self.results ] )
for user_input_list in user_input_2d_list:
v_list = []
for user_input in user_input_list:
def cancel_handler(self):
get_app().exit(result=False)
if isinstance( user_input, AskStr ):
def build(self):
self.results = []
y_list = []
textfield = TextArea(
multiline=False,
#password=password,
#completer=completer,
#accept_handler=accept
)
for user_inputs in self.user_input_2d_list:
x_list = []
for user_input in user_inputs:
text = user_input.label
v_list.append( Label(text=text, dont_extend_height=True) )
v_list.append(textfield)
results.append( textfield.text )
dlg_widget = get_dlg_widget( user_input )
x_list.append( dlg_widget.body )
self.results.append( dlg_widget.get_result )
xbody = VSplit( x_list, padding=1 )
y_list.append( xbody )
vbody = VSplit( v_list, padding=1 )
body = HSplit( y_list, padding=1 )
return body
h_list.append( vbody )
def show(self, async_=False):
return _run_dialog(self, self.style, async_=async_)
hbody = HSplit( h_list, padding=1 )
def display( user_input ):
dlg = None
title = user_input.title
text = user_input.label
dialog = Dialog(
title=title,
body=hbody,
#body=HSplit([
# Label(text=text, dont_extend_height=True),
# radio_list,
#], padding=1),
buttons=[
Button(text=ok_text, handler=ok_handler),
Button(text=cancel_text, handler=_return_none),
],
with_background=True)
if isinstance( user_input, AskYesNo ):
dlg = yes_no_dialog(title, text, yes_text='Yes', no_text='No', style=None, async_=False)
return _run_dialog(dialog, style, async_=async_)
elif isinstance( user_input, AskStr ):
dlg = input_dialog(title, text, ok_text='OK', cancel_text='Cancel',
completer=None, password=False, style=None, async_=False)
elif isinstance( user_input, AskInt ):
def test_multi_dialog( title="multi_dialog" ):
dlg = input_dialog(title, text, ok_text='OK', cancel_text='Cancel',
completer=None, password=False, style=None, async_=False)
dlg = multi_dialog( [ [AskStr(label="word1.1"), AskStr(label="word1.2")], [AskStr(label="word2.1"), AskStr(label="word2.2")] ] , title=title )
print(f"answer = {dlg}")
print(f"results = {dlg}")
return dlg
\ No newline at end of file
def test_multi_dialog( title="multi_dialog" ):
dlg = BlissDialog( [ [AskStr(label="word1.1"), AskStr(label="word1.2")], [AskStr(label="word2.1"), AskStr(label="word2.2")] ] , title=title )
ans = dlg.show()
print(f"results = {ans}")
return ans
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment