Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B-ASIC - Better ASIC Toolbox
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
B-ASIC - Better ASIC Toolbox
Commits
d48b4ebe
Commit
d48b4ebe
authored
2 years ago
by
Petter Källström
Committed by
Oscar Gustafsson
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
PlotWindow: Replaced PlotCanvas with FigureCanvas
parent
7185d1dd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!228
Update plot window
Pipeline
#90281
passed
2 years ago
Stage: test
Stage: deploy
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
b_asic/gui_utils/plot_window.py
+48
-42
48 additions, 42 deletions
b_asic/gui_utils/plot_window.py
with
48 additions
and
42 deletions
b_asic/gui_utils/plot_window.py
+
48
−
42
View file @
d48b4ebe
...
...
@@ -2,7 +2,7 @@
# TODO's:
# * Solve the legend update. That isn't working at all.
# *
Zoom etc. Might need to change FigureCanvas. Or just something very little
.
# *
Add a function to run this as a "stand-alone"
.
import
re
import
sys
...
...
@@ -12,49 +12,48 @@ from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as Navigatio
from
matplotlib.figure
import
Figure
from
matplotlib.ticker
import
MaxNLocator
from
qtpy.QtCore
import
Qt
from
qtpy.QtGui
import
QKeySequence
# Intereme imports for the Plot class:
from
qtpy.QtWidgets
import
(
# QFrame,; QScrollArea,; QLineEdit,; QSizePolicy,; QLabel,
from
qtpy.QtWidgets
import
(
# QFrame,; QScrollArea,; QLineEdit,; QSizePolicy,; QLabel,
; QFileDialog,; QShortcut,
QApplication
,
QCheckBox
,
QDialog
,
QFileDialog
,
QHBoxLayout
,
QListWidget
,
QListWidgetItem
,
QPushButton
,
QShortcut
,
QVBoxLayout
,
)
# from qtpy.QtGui import QKeySequence
class
PlotCanvas
(
FigureCanvas
):
"""
PlotCanvas is used as a part in the PlotWindow.
"""
def
__init__
(
self
,
logger
,
parent
=
None
,
width
=
5
,
height
=
4
,
dpi
=
100
):
fig
=
Figure
(
figsize
=
(
width
,
height
),
dpi
=
dpi
)
super
().
__init__
(
fig
)
self
.
axes
=
fig
.
add_subplot
(
111
)
self
.
axes
.
xaxis
.
set_major_locator
(
MaxNLocator
(
integer
=
True
))
self
.
legend
=
None
self
.
logger
=
logger
# class PlotCanvas(FigureCanvas):
# """PlotCanvas is used as a part in the PlotWindow."""
FigureCanvas
.
updateGeometry
(
self
)
self
.
save_figure
=
QShortcut
(
QKeySequence
(
"
Ctrl+S
"
),
self
)
self
.
save_figure
.
activated
.
connect
(
self
.
_save_plot_figure
)
# def __init__(self, logger, parent=None, width=5, height=4, dpi=100):
# fig = Figure(figsize=(width, height), dpi=dpi)
# super().__init__(fig)
# self.axes = fig.add_subplot(111)
# self.axes.xaxis.set_major_locator(MaxNLocator(integer=True))
# self.legend = None
# self.logger = logger
def
_save_plot_figure
(
self
):
self
.
logger
.
info
(
f
"
Saving plot of figure:
{
self
.
sfg
.
name
}
.
"
)
file_choices
=
"
PNG (*.png)|*.png
"
path
,
ext
=
QFileDialog
.
getSaveFileName
(
self
,
"
Save file
"
,
""
,
file_choices
)
path
=
path
.
encode
(
"
utf-8
"
)
if
not
path
[
-
4
:]
==
file_choices
[
-
4
:].
encode
(
"
utf-8
"
):
path
+=
file_choices
[
-
4
:].
encode
(
"
utf-8
"
)
# FigureCanvas.updateGeometry(self)
# self.save_figure = QShortcut(QKeySequence("Ctrl+S"), self)
# self.save_figure.activated.connect(self._save_plot_figure)
if
path
:
self
.
print_figure
(
path
.
decode
(),
dpi
=
self
.
dpi
)
self
.
logger
.
info
(
f
"
Saved plot:
{
self
.
sfg
.
name
}
to path:
{
path
}
.
"
)
# def _save_plot_figure(self):
# self.logger.info(f"Saving plot of figure: {self.sfg.name}.")
# file_choices = "PNG (*.png)|*.png"
# path, ext = QFileDialog.getSaveFileName(self, "Save file", "", file_choices)
# path = path.encode("utf-8")
# if not path[-4:] == file_choices[-4:].encode("utf-8"):
# path += file_choices[-4:].encode("utf-8")
# if path:
# self.print_figure(path.decode(), dpi=self.dpi)
# self.logger.info(f"Saved plot: {self.sfg.name} to path: {path}.")
class
PlotWindow
(
QDialog
):
...
...
@@ -101,7 +100,7 @@ class PlotWindow(QDialog):
sim_res_others
[
key
]
=
sim_result
[
key
]
# Layout: ############################################
# | list |
|
# | list |
icons
|
# | ... | plot |
# | misc | |
...
...
@@ -117,18 +116,25 @@ class PlotWindow(QDialog):
########### Plot: ##############
# Do this before the list layout, as the list layout will re/set visibility
# Note: The order is of importens. Interesting lines last, to be on top.
self
.
plotcanvas
=
PlotCanvas
(
logger
=
logger
,
parent
=
self
,
width
=
5
,
height
=
4
,
dpi
=
100
)
# self.plotcanvas = PlotCanvas(
# logger=logger, parent=self, width=5, height=4, dpi=100
# )
self
.
_plot_fig
=
Figure
(
figsize
=
(
5
,
4
),
dpi
=
100
)
self
.
_plot_axes
=
self
.
_plot_fig
.
add_subplot
(
111
)
self
.
_plot_axes
.
xaxis
.
set_major_locator
(
MaxNLocator
(
integer
=
True
))
self
.
_lines
=
{}
for
key
in
sim_res_others
|
sim_res_delays
|
sim_res_ins
|
sim_res_outs
:
line
=
self
.
plotcanvas
.
axes
.
plot
(
sim_result
[
key
],
visible
=
False
,
label
=
key
)
# line = self.plotcanvas.axes.plot(sim_result[key], visible=False, label=key)
line
=
self
.
_plot_axes
.
plot
(
sim_result
[
key
],
visible
=
False
,
label
=
key
)
self
.
_lines
[
key
]
=
line
self
.
plotcanvas
.
legend
=
self
.
plotcanvas
.
axes
.
legend
()
# self.plotcanvas.legend = self.plotcanvas.axes.legend()
self
.
_legend
=
self
.
_plot_axes
.
legend
()
self
.
_plot_canvas
=
FigureCanvas
(
self
.
_plot_fig
)
plotlayout
.
addWidget
(
NavigationToolbar
(
self
.
plotcanvas
,
self
))
plotlayout
.
addWidget
(
self
.
plotcanvas
)
plotlayout
.
addWidget
(
NavigationToolbar
(
self
.
_
plot
_
canvas
,
self
))
plotlayout
.
addWidget
(
self
.
_
plot
_
canvas
)
########### List layout: ##############
...
...
@@ -178,11 +184,11 @@ class PlotWindow(QDialog):
self
.
_auto_redraw
=
True
def
_legend_checkbox_change
(
self
,
checkState
):
self
.
plotcanvas
.
legend
.
set
(
visible
=
(
checkState
==
Qt
.
CheckState
.
Checked
))
self
.
_
legend
.
set
(
visible
=
(
checkState
==
Qt
.
CheckState
.
Checked
))
if
self
.
_auto_redraw
:
if
checkState
==
Qt
.
CheckState
.
Checked
:
self
.
plotcanvas
.
legend
=
self
.
plot
canvas
.
axes
.
legend
()
self
.
plotcanvas
.
draw
()
self
.
_
legend
=
self
.
_
plot
_
axes
.
legend
()
self
.
_
plot
_
canvas
.
draw
()
# def _ontop_checkbox_change(self, checkState):
# Bugg: It seems the window closes if you change the WindowStaysOnTopHint.
...
...
@@ -196,14 +202,14 @@ class PlotWindow(QDialog):
for
x
in
range
(
self
.
checklist
.
count
()):
self
.
checklist
.
item
(
x
).
setCheckState
(
Qt
.
CheckState
.
Checked
)
self
.
_auto_redraw
=
True
self
.
plotcanvas
.
draw
()
self
.
_
plot
_
canvas
.
draw
()
def
_button_none_click
(
self
,
event
):
self
.
_auto_redraw
=
False
for
x
in
range
(
self
.
checklist
.
count
()):
self
.
checklist
.
item
(
x
).
setCheckState
(
Qt
.
CheckState
.
Unchecked
)
self
.
_auto_redraw
=
True
self
.
plotcanvas
.
draw
()
self
.
_
plot
_
canvas
.
draw
()
def
_item_change
(
self
,
listitem
):
key
=
listitem
.
text
()
...
...
@@ -212,8 +218,8 @@ class PlotWindow(QDialog):
)
if
self
.
_auto_redraw
:
if
self
.
legend_checkbox
.
checkState
==
Qt
.
CheckState
.
Checked
:
self
.
plotcanvas
.
legend
=
self
.
plot
canvas
.
axes
.
legend
()
self
.
plotcanvas
.
draw
()
self
.
_
legend
=
self
.
_
plot
_
axes
.
legend
()
self
.
_
plot
_
canvas
.
draw
()
# Simple test of the dialog
...
...
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