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
180d795e
Commit
180d795e
authored
Oct 31, 2019
by
Flavio TARSETTI
Browse files
[widgets][toolchaineditor] proper data load and dump
parent
411eb6a8
Changes
2
Hide whitespace changes
Inline
Side-by-side
beat/editor/test/test_toolchaineditor.py
View file @
180d795e
...
...
@@ -29,7 +29,7 @@ from ..backend.asset import Asset
from
..backend.asset
import
AssetType
from
..backend.assetmodel
import
AssetModel
from
..widgets.toolchaineditor
import
ToolchainEditor
#
from ..widgets.toolchaineditor import ToolchainEditor
from
.conftest
import
sync_prefix
from
.conftest
import
prefix
...
...
@@ -58,9 +58,14 @@ class TestToolchainEditor:
@
pytest
.
mark
.
parametrize
(
"toolchain"
,
get_valid_toolchains
(
prefix
))
def
test_load_and_dump
(
self
,
qtbot
,
test_prefix
,
toolchain
):
reference_json
=
get_toolchain_declaration
(
test_prefix
,
toolchain
)
editor
=
ToolchainEditor
()
pass
editor
.
load_json
(
reference_json
)
assert
editor
.
dump_json
()
==
reference_json
# reference_json = get_toolchain_declaration(test_prefix, toolchain)
# editor = ToolchainEditor()
#
# editor.load_json(reference_json)
#
# assert editor.dump_json() == reference_json
beat/editor/widgets/toolchaineditor.py
View file @
180d795e
...
...
@@ -217,10 +217,18 @@ class BlockType(Enum):
ANALYZERS
=
"analyzers"
DATASETS
=
"datasets"
@
classmethod
def
from_name
(
cls
,
name
):
try
:
return
cls
[
name
]
except
ValueError
:
raise
ValueError
(
"{} is not a valid block type"
.
format
(
name
))
class
Block
(
QGraphicsObject
):
"""Block item"""
dataChanged
=
pyqtSignal
()
blockMoved
=
pyqtSignal
()
def
__init__
(
self
,
block_details
,
block_type
,
style
):
...
...
@@ -239,9 +247,12 @@ class Block(QGraphicsObject):
if
"synchronized_channel"
in
block_details
:
self
.
synchronized_channel
=
block_details
[
"synchronized_channel"
]
else
:
self
.
synchronized_channel
=
None
self
.
type
=
block_type
self
.
style
=
style
self
.
position
=
QPointF
(
0
,
0
)
self
.
pins
=
dict
()
self
.
pins
[
"inputs"
]
=
dict
()
self
.
pins
[
"outputs"
]
=
dict
()
...
...
@@ -402,7 +413,10 @@ class Block(QGraphicsObject):
super
(
Block
,
self
).
mouseMoveEvent
(
event
)
self
.
position
=
self
.
scenePos
()
self
.
blockMoved
.
emit
()
self
.
dataChanged
.
emit
()
def
paint
(
self
,
painter
,
option
,
widget
):
"""Paint the block"""
...
...
@@ -451,6 +465,8 @@ class Block(QGraphicsObject):
class
Toolchain
(
QWidget
):
"""Toolchain designer"""
dataChanged
=
pyqtSignal
()
def
__init__
(
self
,
parent
=
None
):
super
().
__init__
(
parent
=
parent
)
...
...
@@ -473,18 +489,25 @@ class Toolchain(QWidget):
self
.
scene
.
clear
()
self
.
scene
.
items
().
clear
()
self
.
blocks
=
[]
self
.
connections
=
[]
def
load
(
self
,
json_object
):
"""Parse the json in parameter and generates a graph"""
self
.
json_object
=
json_object
if
"representation"
in
self
.
json_object
:
self
.
web_representation
=
self
.
json_object
[
"representation"
]
else
:
self
.
web_representation
=
None
self
.
clear_space
()
# Get datasets, blocks, analyzers
for
block_type
in
BlockType
:
for
block_item
in
self
.
json_object
[
block_type
.
value
]:
block
=
Block
(
block_item
,
block_type
.
name
,
self
.
block_config
)
block
.
dataChanged
.
connect
(
self
.
dataChanged
)
self
.
blocks
.
append
(
block
)
self
.
scene
.
addItem
(
block
)
...
...
@@ -492,12 +515,54 @@ class Toolchain(QWidget):
connections
=
self
.
json_object
[
"connections"
]
for
connection_item
in
connections
:
connection
=
Connection
(
self
,
connection_item
,
self
.
connection_config
)
self
.
connections
.
append
(
connection
)
self
.
scene
.
addItem
(
connection
)
def
dump
(
self
):
"""Returns the json used to load the widget"""
return
self
.
json_object
data
=
{}
if
self
.
web_representation
is
not
None
:
data
[
"representation"
]
=
self
.
web_representation
data
[
"editor_gui"
]
=
{}
for
block_type
in
BlockType
:
block_type_list
=
[]
for
block
in
self
.
blocks
:
block_data
=
{}
if
block_type
==
BlockType
.
from_name
(
block
.
type
):
block_data
[
"name"
]
=
block
.
name
if
block
.
synchronized_channel
is
not
None
:
block_data
[
"synchronized_channel"
]
=
block
.
synchronized_channel
if
block
.
inputs
is
not
None
:
block_data
[
"inputs"
]
=
block
.
inputs
if
block
.
outputs
is
not
None
:
block_data
[
"outputs"
]
=
block
.
outputs
block_type_list
.
append
(
block_data
)
data
[
"editor_gui"
][
block
.
name
]
=
{
"x"
:
block
.
position
.
x
(),
"y"
:
block
.
position
.
y
(),
}
data
[
block_type
.
value
]
=
block_type_list
connection_list
=
[]
for
connection
in
self
.
connections
:
connection_data
=
{}
connection_data
[
"channel"
]
=
connection
.
channel
connection_data
[
"from"
]
=
(
connection
.
start_block_name
+
"."
+
connection
.
start_pin_name
)
connection_data
[
"to"
]
=
(
connection
.
end_block_name
+
"."
+
connection
.
end_pin_name
)
connection_list
.
append
(
connection_data
)
data
[
"connections"
]
=
connection_list
return
data
@
frozen
...
...
@@ -514,6 +579,8 @@ class ToolchainEditor(AbstractAssetEditor):
self
.
layout
().
addWidget
(
self
.
toolchain
,
2
)
self
.
layout
().
addStretch
()
self
.
toolchain
.
dataChanged
.
connect
(
self
.
dataChanged
)
def
_load_json
(
self
,
json_object
):
"""Load the json object passed as parameter"""
...
...
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