Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Benoit Rousselle
bliss
Commits
ea5eb65d
Commit
ea5eb65d
authored
May 21, 2019
by
GUILLOU Perceval
Browse files
add choices
parent
d032e28f
Changes
1
Hide whitespace changes
Inline
Side-by-side
bliss/shell/cli/user_input_dialog.py
View file @
ea5eb65d
...
...
@@ -245,21 +245,26 @@ class UserInput:
class
AskYesNo
(
UserInput
):
def
__init__
(
self
,
title
=
"Question"
,
label
=
""
,
defval
=
False
,
validator
=
None
):
super
(
AskYesNo
,
self
).
__init__
(
title
,
label
,
defval
,
validator
)
super
().
__init__
(
title
,
label
,
defval
,
validator
)
class
AskStr
(
UserInput
):
def
__init__
(
self
,
title
=
"Enter a string"
,
label
=
"word"
,
defval
=
""
,
validator
=
None
):
super
(
AskStr
,
self
).
__init__
(
title
,
label
,
defval
,
validator
)
super
().
__init__
(
title
,
label
,
defval
,
validator
)
class
AskInt
(
UserInput
):
def
__init__
(
self
,
title
=
"Enter a integer"
,
label
=
"value"
,
defval
=
0
,
mini
=
None
,
maxi
=
None
,
validator
=
None
):
super
(
AskInt
,
self
).
__init__
(
title
,
label
,
defval
,
validator
)
super
().
__init__
(
title
,
label
,
defval
,
validator
)
self
.
mini
=
mini
self
.
maxi
=
maxi
class
AskChoice
(
UserInput
):
def
__init__
(
self
,
title
=
"Select one value"
,
label
=
"select"
,
choices
=
[],
defval
=
0
,
validator
=
None
):
super
().
__init__
(
title
,
label
,
defval
,
validator
)
self
.
choices
=
choices
class
_BaseWidget
:
class
DlgWidget
:
""" Dialog widget base class """
def
__init__
(
self
,
label
=
""
):
self
.
label
=
label
...
...
@@ -271,44 +276,68 @@ class _BaseWidget:
def
get_result
(
self
):
return
None
#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
class
Dlg
Input
(
_Base
Widget
):
class
Input
Widget
(
Dlg
Widget
):
def
__init__
(
self
,
label
=
"Please, enter a value"
):
super
().
__init__
(
label
)
if
not
isinstance
(
label
,(
tuple
,
list
)):
label
=
[
label
,]
self
.
label
=
label
self
.
build
()
super
().
__init__
(
label
)
def
build
(
self
):
self
.
textfields
=
[]
hlist
=
[]
for
label
in
self
.
label
:
wlabel
=
Label
(
text
=
label
+
" "
,
dont_extend_height
=
True
,
dont_extend_width
=
True
)
textfield
=
TextArea
(
multiline
=
False
,
#password=password,
#completer=completer,
accept_handler
=
self
.
accept
)
self
.
textfields
.
append
(
textfield
)
hlist
.
append
(
VSplit
(
[
wlabel
,
textfield
]
))
wlabel
=
Label
(
text
=
self
.
label
,
dont_extend_height
=
True
,
dont_extend_width
=
True
)
self
.
body
=
HSplit
(
hlist
)
self
.
textfield
=
TextArea
(
multiline
=
False
,
#password=password,
#completer=completer,
accept_handler
=
self
.
accept
)
def
get_result
(
self
):
return
[
textfield
.
text
for
textfield
in
self
.
textfields
]
def
accept
(
self
,
buf
):
return
True
self
.
body
=
VSplit
(
[
wlabel
,
self
.
textfield
]
)
class
ChoiceWidget
(
DlgWidget
):
def
__init__
(
self
,
choices
=
[],
label
=
"Please, select one value"
):
self
.
label
=
label
self
.
choices
=
choices
super
().
__init__
(
label
)
def
get_result
(
self
):
return
self
.
textfield
.
text
def
build
(
self
):
wlabel
=
Label
(
text
=
self
.
label
+
" "
,
dont_extend_height
=
True
,
dont_extend_width
=
True
)
self
.
radio_list
=
RadioList
(
self
.
choices
)
self
.
body
=
HSplit
(
[
wlabel
,
self
.
radio_list
]
)
def
get_result
(
self
):
return
self
.
radio_list
.
current_value
def
accept
(
self
,
buf
):
return
True
def
get_dlg_widget
(
user_input
):
if
isinstance
(
user_input
,
(
AskStr
,
AskInt
)
):
return
DlgInput
(
user_input
.
label
)
return
InputWidget
(
user_input
.
label
)
elif
isinstance
(
user_input
,
AskChoice
):
return
ChoiceWidget
(
user_input
.
choices
,
user_input
.
label
)
else
:
raise
NotImplementedError
...
...
@@ -377,7 +406,7 @@ def display( user_input ):
def
test_multi_dialog
(
title
=
"multi_dialog"
):
dlg
=
BlissDialog
(
[
[
AskStr
(
label
=
"word1.1
"
),
AskStr
(
label
=
"
word
1.2"
)],
[
AskStr
(
label
=
"word2.1"
),
AskStr
(
label
=
"word2.2"
)]
]
,
title
=
title
)
dlg
=
BlissDialog
(
[
[
AskStr
(
label
=
[
"word1.1
.1"
,
"word1.1.2"
,
"word1.1.3"
]),
AskChoice
(
choices
=
[(
"A"
,
"A"
),(
"B"
,
"B"
),(
"C"
,
"C"
)],
label
=
"
choice
1.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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment