Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simuDAtor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Computer Engineering
simuDAtor
Commits
869b0bdf
Commit
869b0bdf
authored
9 months ago
by
Johannes Kung
Browse files
Options
Downloads
Patches
Plain Diff
Added a signal viewer graphics item
parent
8eeffdd6
No related branches found
No related tags found
1 merge request
!44
Fixed flags
Pipeline
#133203
failed
9 months ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/simudator/gui/gui.py
+18
-2
18 additions, 2 deletions
src/simudator/gui/gui.py
src/simudator/gui/signal_viewer.py
+84
-0
84 additions, 0 deletions
src/simudator/gui/signal_viewer.py
with
102 additions
and
2 deletions
src/simudator/gui/gui.py
+
18
−
2
View file @
869b0bdf
...
@@ -24,16 +24,18 @@ from qtpy.QtWidgets import (
...
@@ -24,16 +24,18 @@ from qtpy.QtWidgets import (
)
)
from
simudator.core.processor
import
Processor
from
simudator.core.processor
import
Processor
from
simudator.core.signal
import
Signal
from
simudator.gui.breakpoint_window
import
BreakpointWindow
from
simudator.gui.breakpoint_window
import
BreakpointWindow
from
simudator.gui.cpu_graphics_scene
import
CpuGraphicsScene
from
simudator.gui.cpu_graphics_scene
import
CpuGraphicsScene
from
simudator.gui.custom_toolbar
import
CustomToolBar
from
simudator.gui.custom_toolbar
import
CustomToolBar
from
simudator.gui.dialogs.lambda_breakpoint_dialog
import
LambdaBreakpointDialog
from
simudator.gui.dialogs.lambda_breakpoint_dialog
import
LambdaBreakpointDialog
from
simudator.gui.module_graphics_item.module_graphics_item
import
ModuleGraphicsItem
from
simudator.gui.module_graphics_item.module_graphics_item
import
ModuleGraphicsItem
from
simudator.gui.orientation
import
Orientation
from
simudator.gui.orientation
import
Orientation
from
simudator.gui.pipeline
import
PipeLine
from
simudator.gui.port_graphics_item
import
PortGraphicsItem
from
simudator.gui.port_graphics_item
import
PortGraphicsItem
from
simudator.gui.run_continuously_thread
import
RunThread
from
simudator.gui.run_continuously_thread
import
RunThread
from
simudator.gui.signal_graphics_item
import
SignalGraphicsItem
from
simudator.gui.signal_graphics_item
import
SignalGraphicsItem
from
simudator.gui.
pipeline
import
PipeLine
from
simudator.gui.
signal_viewer
import
SignalViewer
class
View
(
QGraphicsView
):
class
View
(
QGraphicsView
):
...
@@ -363,7 +365,7 @@ class GUI(QMainWindow):
...
@@ -363,7 +365,7 @@ class GUI(QMainWindow):
signal
.
connect
(
self
.
updateCpuClockCycle
)
signal
.
connect
(
self
.
updateCpuClockCycle
)
def
init_pipeline
(
self
)
->
None
:
def
init_pipeline
(
self
)
->
None
:
"""
Initialize the pipeline diagram.
"""
Initialize the pipeline diagram.
Sets its height, width and instructions.
Sets its height, width and instructions.
"""
"""
...
@@ -987,6 +989,20 @@ class GUI(QMainWindow):
...
@@ -987,6 +989,20 @@ class GUI(QMainWindow):
"""
"""
self
.
cpu_graphics_scene
.
addAllSignals
()
self
.
cpu_graphics_scene
.
addAllSignals
()
def
add_signal_viewer
(
self
,
signal
:
Signal
,
label
:
str
|
None
=
None
)
->
None
:
"""
Add a signal viewer to the graphics scene.
Parameters
----------
signal : Signal
Processor signal to view.
label : str | None
Optional label of the signal viewer.
"""
viewer
=
SignalViewer
(
signal
,
label
)
self
.
cpu_graphics_scene
.
addItem
(
viewer
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
QtWidgets
.
QApplication
.
setAttribute
(
QtCore
.
Qt
.
AA_EnableHighDpiScaling
)
QtWidgets
.
QApplication
.
setAttribute
(
QtCore
.
Qt
.
AA_EnableHighDpiScaling
)
...
...
This diff is collapsed.
Click to expand it.
src/simudator/gui/signal_viewer.py
0 → 100644
+
84
−
0
View file @
869b0bdf
from
qtpy.QtCore
import
QPointF
,
QRectF
,
Qt
from
qtpy.QtCore
import
Signal
as
pyqtSignal
from
qtpy.QtCore
import
Slot
from
qtpy.QtGui
import
QPainter
,
QPainterPath
,
QPainterPathStroker
,
QPalette
,
QPen
from
qtpy.QtWidgets
import
(
QGraphicsItem
,
QGraphicsWidget
,
QStyleOptionGraphicsItem
,
QWidget
,
)
from
simudator.core.signal
import
Signal
class
SignalViewer
(
QGraphicsWidget
):
DEFAULT_WIDTH
=
50
DEFAULT_HEIGHT
=
50
def
__init__
(
self
,
signal
:
Signal
,
label
:
str
|
None
=
None
,
parent
:
QGraphicsItem
|
None
=
None
,
flags
:
Qt
.
WindowFlags
|
Qt
.
WindowType
=
Qt
.
WindowFlags
(),
)
->
None
:
super
().
__init__
(
parent
,
flags
)
self
.
_signal
=
signal
self
.
_label
=
label
self
.
_width
:
int
=
SignalViewer
.
DEFAULT_WIDTH
self
.
_height
:
int
=
SignalViewer
.
DEFAULT_HEIGHT
self
.
outline_width
:
float
=
1
self
.
setFlag
(
QGraphicsItem
.
ItemIsMovable
)
self
.
setFiltersChildEvents
(
False
)
def
paint
(
self
,
painter
:
QPainter
|
None
=
None
,
option
:
QStyleOptionGraphicsItem
|
None
=
None
,
widget
:
QWidget
|
None
=
None
,
)
->
None
:
painter
.
save
()
# Draw outline of the items shape with fill
palette
:
QPalette
=
option
.
palette
pen
=
QPen
(
palette
.
color
(
QPalette
.
ColorRole
.
Dark
))
brush
=
palette
.
brush
(
QPalette
.
ColorRole
.
Base
)
painter
.
setPen
(
pen
)
painter
.
setBrush
(
brush
)
painter
.
drawPath
(
self
.
shape
())
# Draw label if any
value_height_offset
=
self
.
_height
/
2
if
self
.
_label
is
not
None
:
# TODO: Proper positioning on the y-axis
x_pos
=
self
.
_width
/
2
-
len
(
self
.
_label
)
*
3
text_pos
=
QPointF
(
x_pos
,
self
.
_height
/
3
)
painter
.
setPen
(
palette
.
text
().
color
())
painter
.
setBrush
(
palette
.
text
())
painter
.
drawText
(
text_pos
,
self
.
_label
)
value_height_offset
=
self
.
_height
*
2
/
3
# Draw signal value
# TODO: Proper positioning on the y-axis
text_pos
=
QPointF
(
0
,
value_height_offset
)
painter
.
setPen
(
palette
.
text
().
color
())
painter
.
setBrush
(
palette
.
text
())
painter
.
drawText
(
text_pos
,
str
(
self
.
_signal
.
get_value
()))
painter
.
restore
()
@Slot
()
def
update
(
self
,
rect
:
QRectF
|
None
=
None
):
super
().
update
()
def
shape
(
self
)
->
QPainterPath
:
path
=
QPainterPath
()
path
.
addRect
(
0
,
0
,
self
.
_width
,
self
.
_height
)
# outline_painter = QPainterPathStroker()
# outline_painter.setWidth(self.outline_width)
# return outline_painter.createStroke(path)
return
path
def
boundingRect
(
self
)
->
QRectF
:
return
QRectF
(
0
,
0
,
self
.
_width
,
self
.
_height
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment