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
Merge requests
!23
Resolve "Simulate SFG"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Simulate SFG"
24-simulate-sfg
into
develop
Overview
2
Commits
37
Pipelines
3
Changes
5
Merged
Ivar Härnqvist
requested to merge
24-simulate-sfg
into
develop
4 years ago
Overview
2
Commits
37
Pipelines
3
Changes
5
Expand
Closes
#22 (closed)
and
#24 (closed)
. This merge will:
add some important test cases
implement deep copying of SFG
implement Simulation
add Register operation
refactor operation evaluation to allow for simulation of registers/delays with loops and nested SFGs
refactor neighbors/parameter/traverse interface by moving it to GraphComponent
add some convenience functions to Operation
tidy up the method signatures of some interfaces to be more general
move bit length specification from InputPort to Signal
add customization point for specifying input truncation behavior for user operations
0
0
Merge request reports
Viewing commit
356caa76
Prev
Next
Show latest version
5 files
+
292
−
2
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
356caa76
Merge remote-tracking branch 'origin/develop' into 24-simulate-sfg
· 356caa76
Ivar Härnqvist
authored
4 years ago
GUI/main_window.py
0 → 100644
+
200
−
0
Options
"""
@package docstring
B-ASIC GUI Module.
This python file is an example of how a GUI can be implemented
using buttons and textboxes.
"""
import
sys
from
PyQt5.QtWidgets
import
QApplication
,
QWidget
,
QMainWindow
,
QLabel
,
QAction
,
\
QStatusBar
,
QMenuBar
,
QLineEdit
,
QPushButton
from
PyQt5.QtCore
import
Qt
from
PyQt5.QtGui
import
QIcon
,
QFont
,
QPainter
,
QPen
class
DragButton
(
QPushButton
):
"""
How to create a dragbutton
"""
def
mousePressEvent
(
self
,
event
):
self
.
_mouse_press_pos
=
None
self
.
_mouse_move_pos
=
None
if
event
.
button
()
==
Qt
.
LeftButton
:
self
.
_mouse_press_pos
=
event
.
globalPos
()
self
.
_mouse_move_pos
=
event
.
globalPos
()
super
(
DragButton
,
self
).
mousePressEvent
(
event
)
def
mouseMoveEvent
(
self
,
event
):
if
event
.
buttons
()
==
Qt
.
LeftButton
:
cur_pos
=
self
.
mapToGlobal
(
self
.
pos
())
global_pos
=
event
.
globalPos
()
diff
=
global_pos
-
self
.
_mouse_move_pos
new_pos
=
self
.
mapFromGlobal
(
cur_pos
+
diff
)
self
.
move
(
new_pos
)
self
.
_mouse_move_pos
=
global_pos
super
(
DragButton
,
self
).
mouseMoveEvent
(
event
)
def
mouseReleaseEvent
(
self
,
event
):
if
self
.
_mouse_press_pos
is
not
None
:
moved
=
event
.
globalPos
()
-
self
.
_mouse_press_pos
if
moved
.
manhattanLength
()
>
3
:
event
.
ignore
()
return
super
(
DragButton
,
self
).
mouseReleaseEvent
(
event
)
class
SubWindow
(
QWidget
):
"""
Creates a sub window
"""
def
create_window
(
self
,
window_width
,
window_height
):
"""
Creates a window
"""
parent
=
None
super
(
SubWindow
,
self
).
__init__
(
parent
)
self
.
setWindowFlags
(
Qt
.
WindowStaysOnTopHint
)
self
.
resize
(
window_width
,
window_height
)
class
MainWindow
(
QMainWindow
):
"""
Main window for the program
"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
MainWindow
,
self
).
__init__
(
*
args
,
**
kwargs
)
self
.
setWindowTitle
(
"
"
)
self
.
setWindowIcon
(
QIcon
(
'
small_logo.png
'
))
# Menu buttons
test_button
=
QAction
(
"
Test
"
,
self
)
exit_button
=
QAction
(
"
Exit
"
,
self
)
exit_button
.
setShortcut
(
"
Ctrl+Q
"
)
exit_button
.
triggered
.
connect
(
self
.
exit_app
)
edit_button
=
QAction
(
"
Edit
"
,
self
)
edit_button
.
setStatusTip
(
"
Open edit menu
"
)
edit_button
.
triggered
.
connect
(
self
.
on_edit_button_click
)
view_button
=
QAction
(
"
View
"
,
self
)
view_button
.
setStatusTip
(
"
Open view menu
"
)
view_button
.
triggered
.
connect
(
self
.
on_view_button_click
)
menu_bar
=
QMenuBar
()
menu_bar
.
setStyleSheet
(
"
background-color:rgb(222, 222, 222)
"
)
self
.
setMenuBar
(
menu_bar
)
file_menu
=
menu_bar
.
addMenu
(
"
&File
"
)
file_menu
.
addAction
(
exit_button
)
file_menu
.
addSeparator
()
file_menu
.
addAction
(
test_button
)
edit_menu
=
menu_bar
.
addMenu
(
"
&Edit
"
)
edit_menu
.
addAction
(
edit_button
)
edit_menu
.
addSeparator
()
view_menu
=
menu_bar
.
addMenu
(
"
&View
"
)
view_menu
.
addAction
(
view_button
)
self
.
setStatusBar
(
QStatusBar
(
self
))
def
on_file_button_click
(
self
):
print
(
"
File
"
)
def
on_edit_button_click
(
self
):
print
(
"
Edit
"
)
def
on_view_button_click
(
self
):
print
(
"
View
"
)
def
exit_app
(
self
,
checked
):
QApplication
.
quit
()
def
clicked
(
self
):
print
(
"
Drag button clicked
"
)
def
add_drag_buttons
(
self
):
"""
Adds draggable buttons
"""
addition_button
=
DragButton
(
"
Addition
"
,
self
)
addition_button
.
move
(
10
,
130
)
addition_button
.
setFixedSize
(
70
,
20
)
addition_button
.
clicked
.
connect
(
self
.
create_sub_window
)
addition_button2
=
DragButton
(
"
Addition
"
,
self
)
addition_button2
.
move
(
10
,
130
)
addition_button2
.
setFixedSize
(
70
,
20
)
addition_button2
.
clicked
.
connect
(
self
.
create_sub_window
)
subtraction_button
=
DragButton
(
"
Subtraction
"
,
self
)
subtraction_button
.
move
(
10
,
170
)
subtraction_button
.
setFixedSize
(
70
,
20
)
subtraction_button
.
clicked
.
connect
(
self
.
create_sub_window
)
subtraction_button2
=
DragButton
(
"
Subtraction
"
,
self
)
subtraction_button2
.
move
(
10
,
170
)
subtraction_button2
.
setFixedSize
(
70
,
20
)
subtraction_button2
.
clicked
.
connect
(
self
.
create_sub_window
)
multiplication_button
=
DragButton
(
"
Multiplication
"
,
self
)
multiplication_button
.
move
(
10
,
210
)
multiplication_button
.
setFixedSize
(
70
,
20
)
multiplication_button
.
clicked
.
connect
(
self
.
create_sub_window
)
multiplication_button2
=
DragButton
(
"
Multiplication
"
,
self
)
multiplication_button2
.
move
(
10
,
210
)
multiplication_button2
.
setFixedSize
(
70
,
20
)
multiplication_button2
.
clicked
.
connect
(
self
.
create_sub_window
)
def
paintEvent
(
self
,
e
):
# Temporary black box for operations
painter
=
QPainter
(
self
)
painter
.
setPen
(
QPen
(
Qt
.
black
,
5
,
Qt
.
SolidLine
))
painter
.
drawRect
(
0
,
110
,
100
,
400
)
# Temporary arrow resembling a signal
painter
.
setRenderHint
(
QPainter
.
Antialiasing
)
painter
.
setPen
(
Qt
.
black
)
painter
.
setBrush
(
Qt
.
white
)
painter
.
drawLine
(
300
,
200
,
400
,
200
)
painter
.
drawLine
(
400
,
200
,
395
,
195
)
painter
.
drawLine
(
400
,
200
,
395
,
205
)
def
create_sub_window
(
self
):
"""
Example of how to create a sub window
"""
self
.
sub_window
=
SubWindow
()
self
.
sub_window
.
create_window
(
400
,
300
)
self
.
sub_window
.
setWindowTitle
(
"
Properties
"
)
self
.
sub_window
.
properties_label
=
QLabel
(
self
.
sub_window
)
self
.
sub_window
.
properties_label
.
setText
(
'
Properties
'
)
self
.
sub_window
.
properties_label
.
setFixedWidth
(
400
)
self
.
sub_window
.
properties_label
.
setFont
(
QFont
(
'
SansSerif
'
,
14
,
QFont
.
Bold
))
self
.
sub_window
.
properties_label
.
setAlignment
(
Qt
.
AlignCenter
)
self
.
sub_window
.
name_label
=
QLabel
(
self
.
sub_window
)
self
.
sub_window
.
name_label
.
setText
(
'
Name:
'
)
self
.
sub_window
.
name_label
.
move
(
20
,
40
)
self
.
sub_window
.
name_line
=
QLineEdit
(
self
.
sub_window
)
self
.
sub_window
.
name_line
.
setPlaceholderText
(
"
Write a name here
"
)
self
.
sub_window
.
name_line
.
move
(
70
,
40
)
self
.
sub_window
.
name_line
.
resize
(
100
,
20
)
self
.
sub_window
.
id_label
=
QLabel
(
self
.
sub_window
)
self
.
sub_window
.
id_label
.
setText
(
'
Id:
'
)
self
.
sub_window
.
id_label
.
move
(
20
,
70
)
self
.
sub_window
.
id_line
=
QLineEdit
(
self
.
sub_window
)
self
.
sub_window
.
id_line
.
setPlaceholderText
(
"
Write an id here
"
)
self
.
sub_window
.
id_line
.
move
(
70
,
70
)
self
.
sub_window
.
id_line
.
resize
(
100
,
20
)
self
.
sub_window
.
show
()
if
__name__
==
"
__main__
"
:
app
=
QApplication
(
sys
.
argv
)
window
=
MainWindow
()
window
.
add_drag_buttons
()
window
.
resize
(
960
,
720
)
window
.
show
()
app
.
exec_
()
Loading