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
683e97e7
Commit
683e97e7
authored
4 years ago
by
Felix Goding
Committed by
Adam Jakobsson
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Implemented a GUI framework
parent
dd68a74d
No related branches found
Branches containing commit
No related tags found
2 merge requests
!67
WIP: B-ASIC version 1.0.0 hotfix
,
!65
B-ASIC version 1.0.0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
GUI/main_window.py
+200
-0
200 additions, 0 deletions
GUI/main_window.py
small_logo.png
+0
-0
0 additions, 0 deletions
small_logo.png
with
200 additions
and
0 deletions
GUI/main_window.py
0 → 100644
+
200
−
0
View file @
683e97e7
"""
@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_
()
This diff is collapsed.
Click to expand it.
small_logo.png
0 → 100644
+
0
−
0
View file @
683e97e7
39.5 KiB
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