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
beat
beat.editor
Commits
1a4d6458
Commit
1a4d6458
authored
Jun 13, 2019
by
Samuel GAIST
Browse files
[widgets][parameterwidget] Renamed ChoicesDialog to NumericalChoiceDialog
Also added test for the dialog itself
parent
1bac7a70
Changes
2
Hide whitespace changes
Inline
Side-by-side
beat/editor/test/test_parameterwidget.py
View file @
1a4d6458
...
...
@@ -28,6 +28,7 @@ import numpy as np
from
PyQt5
import
QtCore
from
PyQt5.QtWidgets
import
QDialogButtonBox
from
PyQt5.QtWidgets
import
QInputDialog
from
..backend.asset
import
Asset
...
...
@@ -37,7 +38,7 @@ from ..widgets.parameterwidget import StringSetupWidget
from
..widgets.parameterwidget
import
NumericalSetupWidget
from
..widgets.parameterwidget
import
ParameterWidget
from
..widgets.parameterwidget
import
InputType
from
..widgets.parameterwidget
import
Choice
s
Dialog
from
..widgets.parameterwidget
import
Numerical
ChoiceDialog
from
.conftest
import
prefix
from
.conftest
import
sync_prefix
...
...
@@ -125,6 +126,26 @@ class TestInputType:
input_type
.
numpy_info
class
TestNumericalChoiceDialog
:
"""Test the NumericalChoiceDialog class"""
def
test_dialog
(
self
,
qtbot
,
numerical_input_type
):
dialog
=
NumericalChoiceDialog
(
numerical_input_type
)
qtbot
.
addWidget
(
dialog
)
qtbot
.
mouseClick
(
dialog
.
buttons
.
button
(
QDialogButtonBox
.
Ok
),
QtCore
.
Qt
.
LeftButton
)
assert
dialog
.
value
()
==
0
@
pytest
.
mark
.
parametrize
(
"input_type"
,
[
item
for
item
in
InputType
if
item
not
in
InputType
.
numerical_types
()],
)
def
test_non_numerical_info
(
self
,
input_type
):
with
pytest
.
raises
(
RuntimeError
):
NumericalChoiceDialog
(
input_type
)
class
TestBoolSetupWidget
:
"""Test the BoolSetupWidget is set up and works correctly"""
...
...
@@ -468,7 +489,7 @@ class TestNumericalSetupWidget:
for
i
in
range
(
0
,
3
):
with
qtbot
.
waitSignal
(
numerical_setup_widget
.
dataChanged
):
monkeypatch
.
setattr
(
Choice
s
Dialog
,
Numerical
ChoiceDialog
,
"getChoiceValue"
,
classmethod
(
lambda
*
args
:
(
str
(
setup_choices
[
"choice"
][
i
]),
True
)),
)
...
...
@@ -522,7 +543,7 @@ class TestNumericalSetupWidget:
# add some choices
for
i
in
range
(
0
,
3
):
monkeypatch
.
setattr
(
Choice
s
Dialog
,
Numerical
ChoiceDialog
,
"getChoiceValue"
,
classmethod
(
lambda
*
args
:
(
str
(
wrong_setup_choices
[
"choice"
][
i
]),
True
)
...
...
@@ -570,19 +591,19 @@ class TestNumericalSetupWidget:
# add some choices
with
qtbot
.
waitSignal
(
numerical_setup_widget
.
dataChanged
):
monkeypatch
.
setattr
(
Choice
s
Dialog
,
Numerical
ChoiceDialog
,
"getChoiceValue"
,
classmethod
(
lambda
*
args
:
(
value1
,
True
)),
)
numerical_setup_widget
.
add_button
.
click
()
monkeypatch
.
setattr
(
Choice
s
Dialog
,
Numerical
ChoiceDialog
,
"getChoiceValue"
,
classmethod
(
lambda
*
args
:
(
value2
,
True
)),
)
numerical_setup_widget
.
add_button
.
click
()
monkeypatch
.
setattr
(
Choice
s
Dialog
,
Numerical
ChoiceDialog
,
"getChoiceValue"
,
classmethod
(
lambda
*
args
:
(
value3
,
True
)),
)
...
...
beat/editor/widgets/parameterwidget.py
View file @
1a4d6458
...
...
@@ -128,7 +128,7 @@ class StackedWidget(QStackedWidget):
return
size
class
Choice
s
Dialog
(
QDialog
):
class
Numerical
ChoiceDialog
(
QDialog
):
"""Dialog to retrieve a value to to add to a choice list"""
def
__init__
(
self
,
selected_type
,
parent
=
None
):
...
...
@@ -138,7 +138,7 @@ class ChoicesDialog(QDialog):
:param parent QWidget: parent widget
"""
super
(
Choice
s
Dialog
,
self
).
__init__
(
parent
)
super
(
Numerical
ChoiceDialog
,
self
).
__init__
(
parent
)
self
.
setWindowTitle
(
self
.
tr
(
"Input"
))
self
.
label
=
QLabel
(
self
.
tr
(
"New Choice:"
))
...
...
@@ -158,6 +158,11 @@ class ChoicesDialog(QDialog):
self
.
buttons
.
accepted
.
connect
(
self
.
accept
)
self
.
buttons
.
rejected
.
connect
(
self
.
reject
)
def
value
(
self
):
"""Returns the value selected"""
return
self
.
spinbox
.
value
()
@
staticmethod
def
getChoiceValue
(
selected_type
,
parent
=
None
):
"""Static method to create the dialog and return qdialog accepted/spinbox value
...
...
@@ -166,12 +171,12 @@ class ChoicesDialog(QDialog):
:param parent QWidget: parent widget
"""
dialog
=
Choice
s
Dialog
(
selected_type
,
parent
)
dialog
=
Numerical
ChoiceDialog
(
selected_type
,
parent
)
result
=
dialog
.
exec_
()
value
=
None
if
result
==
QDialog
.
Accepted
:
value
=
dialog
.
spinbox
.
value
()
value
=
dialog
.
value
()
return
(
value
,
result
)
...
...
@@ -706,7 +711,7 @@ class NumericalSetupWidget(QWidget):
input_value
=
None
ok
=
False
input_value
,
ok
=
Choice
s
Dialog
.
getChoiceValue
(
self
.
current_type
)
input_value
,
ok
=
Numerical
ChoiceDialog
.
getChoiceValue
(
self
.
current_type
)
if
ok
:
if
(
...
...
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