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
4c588606
Commit
4c588606
authored
2 years ago
by
Oscar Gustafsson
Browse files
Options
Downloads
Patches
Plain Diff
Move add_ports logic to drag_button
parent
5e253f97
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!106
Move add_ports logic to drag_button
Pipeline
#88158
passed
2 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
b_asic/GUI/drag_button.py
+42
-9
42 additions, 9 deletions
b_asic/GUI/drag_button.py
b_asic/GUI/main_window.py
+18
-59
18 additions, 59 deletions
b_asic/GUI/main_window.py
with
60 additions
and
68 deletions
b_asic/GUI/drag_button.py
+
42
−
9
View file @
4c588606
...
@@ -10,9 +10,16 @@ from qtpy.QtCore import QSize, Qt, Signal
...
@@ -10,9 +10,16 @@ from qtpy.QtCore import QSize, Qt, Signal
from
qtpy.QtGui
import
QIcon
from
qtpy.QtGui
import
QIcon
from
qtpy.QtWidgets
import
QAction
,
QMenu
,
QPushButton
from
qtpy.QtWidgets
import
QAction
,
QMenu
,
QPushButton
from
b_asic.GUI.port_button
import
PortButton
from
b_asic.GUI.properties_window
import
PropertiesWindow
from
b_asic.GUI.properties_window
import
PropertiesWindow
from
b_asic.GUI.utils
import
decorate_class
,
handle_error
from
b_asic.GUI.utils
import
decorate_class
,
handle_error
from
b_asic.GUI._preferences
import
GRID
,
MINBUTTONSIZE
,
PORTWIDTH
from
b_asic.GUI._preferences
import
(
GAP
,
GRID
,
MINBUTTONSIZE
,
PORTHEIGHT
,
PORTWIDTH
,
)
from
b_asic.port
import
InputPort
from
b_asic.port
import
InputPort
...
@@ -49,6 +56,8 @@ class DragButton(QPushButton):
...
@@ -49,6 +56,8 @@ class DragButton(QPushButton):
self
.
_mouse_press_pos
=
None
self
.
_mouse_press_pos
=
None
self
.
_mouse_move_pos
=
None
self
.
_mouse_move_pos
=
None
self
.
_flipped
=
False
self
.
_flipped
=
False
self
.
_properties_window
=
None
self
.
label
=
None
super
().
__init__
(
parent
)
super
().
__init__
(
parent
)
def
contextMenuEvent
(
self
,
event
):
def
contextMenuEvent
(
self
,
event
):
...
@@ -67,8 +76,8 @@ class DragButton(QPushButton):
...
@@ -67,8 +76,8 @@ class DragButton(QPushButton):
menu
.
exec_
(
self
.
cursor
().
pos
())
menu
.
exec_
(
self
.
cursor
().
pos
())
def
show_properties_window
(
self
,
event
):
def
show_properties_window
(
self
,
event
):
self
.
properties_window
=
PropertiesWindow
(
self
,
self
.
_window
)
self
.
_
properties_window
=
PropertiesWindow
(
self
,
self
.
_window
)
self
.
properties_window
.
show
()
self
.
_
properties_window
.
show
()
def
add_label
(
self
,
label
):
def
add_label
(
self
,
label
):
self
.
label
=
label
self
.
label
=
label
...
@@ -146,9 +155,7 @@ class DragButton(QPushButton):
...
@@ -146,9 +155,7 @@ class DragButton(QPushButton):
path_to_image
=
os
.
path
.
join
(
path_to_image
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
os
.
path
.
dirname
(
__file__
),
"
operation_icons
"
,
"
operation_icons
"
,
(
f
"
{
self
.
operation_path_name
}{
'
_grey.png
'
if
self
.
pressed
else
'
.png
'
}
"
,
f
"
{
self
.
operation_path_name
}{
'
_grey.png
'
if
self
.
pressed
else
'
.png
'
}
"
),
)
)
self
.
setIcon
(
QIcon
(
path_to_image
))
self
.
setIcon
(
QIcon
(
path_to_image
))
self
.
setIconSize
(
QSize
(
MINBUTTONSIZE
,
MINBUTTONSIZE
))
self
.
setIconSize
(
QSize
(
MINBUTTONSIZE
,
MINBUTTONSIZE
))
...
@@ -188,9 +195,7 @@ class DragButton(QPushButton):
...
@@ -188,9 +195,7 @@ class DragButton(QPushButton):
for
signal
,
ports
in
self
.
_window
.
signalPortDict
.
items
():
for
signal
,
ports
in
self
.
_window
.
signalPortDict
.
items
():
if
any
(
if
any
(
map
(
map
(
lambda
port
:
set
(
port
).
intersection
(
lambda
port
:
set
(
port
).
intersection
(
set
(
self
.
ports
)),
set
(
self
.
_window
.
portDict
[
self
])
),
ports
,
ports
,
)
)
):
):
...
@@ -227,3 +232,31 @@ class DragButton(QPushButton):
...
@@ -227,3 +232,31 @@ class DragButton(QPushButton):
if
self
.
operation
in
self
.
_window
.
operationDragDict
:
if
self
.
operation
in
self
.
_window
.
operationDragDict
:
del
self
.
_window
.
operationDragDict
[
self
.
operation
]
del
self
.
_window
.
operationDragDict
[
self
.
operation
]
def
add_ports
(
self
):
def
_determine_port_distance
(
opheight
,
ports
):
"""
Determine the distance between each port on the side of an operation.
The method returns the distance that each port should have from 0.
"""
return
(
[(
opheight
-
PORTHEIGHT
)
//
2
]
if
ports
==
1
else
[(
PORTHEIGHT
+
GAP
)
*
no
for
no
in
range
(
ports
)]
)
op
=
self
.
operation
height
=
self
.
height
()
output_ports_dist
=
_determine_port_distance
(
height
,
op
.
output_count
)
input_ports_dist
=
_determine_port_distance
(
height
,
op
.
input_count
)
for
i
,
dist
in
enumerate
(
input_ports_dist
):
port
=
PortButton
(
"
>
"
,
self
,
op
.
input
(
i
),
self
.
_window
)
self
.
ports
.
append
(
port
)
port
.
move
(
0
,
dist
)
port
.
show
()
for
i
,
dist
in
enumerate
(
output_ports_dist
):
port
=
PortButton
(
"
>
"
,
self
,
op
.
output
(
i
),
self
.
_window
)
self
.
ports
.
append
(
port
)
port
.
move
(
MINBUTTONSIZE
-
PORTWIDTH
,
dist
)
port
.
show
()
This diff is collapsed.
Click to expand it.
b_asic/GUI/main_window.py
+
18
−
59
View file @
4c588606
...
@@ -26,22 +26,18 @@ from qtpy.QtWidgets import (
...
@@ -26,22 +26,18 @@ from qtpy.QtWidgets import (
QShortcut
,
QShortcut
,
)
)
import
b_asic.core_operations
as
c_oper
import
b_asic.core_operations
import
b_asic.special_operations
as
s_oper
import
b_asic.special_operations
from
b_asic.GUI.about_window
import
AboutWindow
,
FaqWindow
,
KeybindsWindow
from
b_asic.GUI.about_window
import
AboutWindow
,
FaqWindow
,
KeybindsWindow
from
b_asic.GUI.arrow
import
Arrow
from
b_asic.GUI.arrow
import
Arrow
from
b_asic.GUI.drag_button
import
DragButton
from
b_asic.GUI.drag_button
import
DragButton
from
b_asic.GUI.gui_interface
import
Ui_main_window
from
b_asic.GUI.gui_interface
import
Ui_main_window
from
b_asic.GUI.port_button
import
PortButton
from
b_asic.GUI.select_sfg_window
import
SelectSFGWindow
from
b_asic.GUI.select_sfg_window
import
SelectSFGWindow
from
b_asic.GUI._preferences
import
(
from
b_asic.GUI._preferences
import
(
GAP
,
GAP
,
GRID
,
GRID
,
MINBUTTONSIZE
,
MINBUTTONSIZE
,
PORTHEIGHT
,
PORTHEIGHT
,
PORTWIDTH
,
MIN_HEIGHT_SCENE
,
MIN_WIDTH_SCENE
,
)
)
from
b_asic.GUI.show_pc_window
import
ShowPCWindow
from
b_asic.GUI.show_pc_window
import
ShowPCWindow
from
b_asic.GUI.simulate_sfg_window
import
Plot
,
SimulateSFGWindow
from
b_asic.GUI.simulate_sfg_window
import
Plot
,
SimulateSFGWindow
...
@@ -64,7 +60,7 @@ class MainWindow(QMainWindow):
...
@@ -64,7 +60,7 @@ class MainWindow(QMainWindow):
self
.
ui
=
Ui_main_window
()
self
.
ui
=
Ui_main_window
()
self
.
ui
.
setupUi
(
self
)
self
.
ui
.
setupUi
(
self
)
self
.
setWindowIcon
(
QIcon
(
"
small_logo.png
"
))
self
.
setWindowIcon
(
QIcon
(
"
small_logo.png
"
))
self
.
scene
=
None
self
.
scene
=
QGraphicsScene
(
self
)
self
.
_operations_from_name
=
{}
self
.
_operations_from_name
=
{}
self
.
zoom
=
1
self
.
zoom
=
1
self
.
sfg_name_i
=
0
self
.
sfg_name_i
=
0
...
@@ -82,10 +78,10 @@ class MainWindow(QMainWindow):
...
@@ -82,10 +78,10 @@ class MainWindow(QMainWindow):
self
.
logger
=
logging
.
getLogger
(
__name__
)
self
.
logger
=
logging
.
getLogger
(
__name__
)
self
.
init_ui
()
self
.
init_ui
()
self
.
add_operations_from_namespace
(
self
.
add_operations_from_namespace
(
c_oper
,
self
.
ui
.
core_operations_list
b_asic
.
core_operations
,
self
.
ui
.
core_operations_list
)
)
self
.
add_operations_from_namespace
(
self
.
add_operations_from_namespace
(
s_oper
,
self
.
ui
.
special_operations_list
b_asic
.
special_operations
,
self
.
ui
.
special_operations_list
)
)
self
.
shortcut_core
=
QShortcut
(
self
.
shortcut_core
=
QShortcut
(
...
@@ -143,7 +139,6 @@ class MainWindow(QMainWindow):
...
@@ -143,7 +139,6 @@ class MainWindow(QMainWindow):
self
.
create_graphics_view
()
self
.
create_graphics_view
()
def
create_graphics_view
(
self
):
def
create_graphics_view
(
self
):
self
.
scene
=
QGraphicsScene
(
self
)
self
.
graphic_view
=
QGraphicsView
(
self
.
scene
,
self
)
self
.
graphic_view
=
QGraphicsView
(
self
.
scene
,
self
)
self
.
graphic_view
.
setRenderHint
(
QPainter
.
Antialiasing
)
self
.
graphic_view
.
setRenderHint
(
QPainter
.
Antialiasing
)
self
.
graphic_view
.
setGeometry
(
self
.
graphic_view
.
setGeometry
(
...
@@ -334,7 +329,7 @@ class MainWindow(QMainWindow):
...
@@ -334,7 +329,7 @@ class MainWindow(QMainWindow):
if
not
accepted
:
if
not
accepted
:
return
return
if
n
ame
==
""
:
if
n
ot
name
:
self
.
logger
.
warning
(
"
Failed to initialize SFG with empty name.
"
)
self
.
logger
.
warning
(
"
Failed to initialize SFG with empty name.
"
)
return
return
...
@@ -452,40 +447,6 @@ class MainWindow(QMainWindow):
...
@@ -452,40 +447,6 @@ class MainWindow(QMainWindow):
self
.
dialog
.
add_sfg_to_dialog
()
self
.
dialog
.
add_sfg_to_dialog
()
self
.
dialog
.
show
()
self
.
dialog
.
show
()
def
_determine_port_distance
(
self
,
height
,
ports
):
"""
Determine the distance between each port on the side of an operation.
The method returns the distance that each port should have from 0.
"""
return
(
[(
height
-
PORTHEIGHT
)
//
2
]
if
ports
==
1
else
[(
PORTHEIGHT
+
GAP
)
*
i
for
i
in
range
(
ports
)]
)
def
add_ports
(
self
,
operation
):
op
=
operation
.
operation
height
=
self
.
_get_button_height
(
op
)
_output_ports_dist
=
self
.
_determine_port_distance
(
height
,
op
.
output_count
)
_input_ports_dist
=
self
.
_determine_port_distance
(
height
,
op
.
input_count
)
self
.
portDict
[
operation
]
=
[]
for
i
,
dist
in
enumerate
(
_input_ports_dist
):
port
=
PortButton
(
"
>
"
,
operation
,
op
.
input
(
i
),
self
)
self
.
portDict
[
operation
].
append
(
port
)
operation
.
ports
.
append
(
port
)
port
.
move
(
0
,
dist
)
port
.
show
()
for
i
,
dist
in
enumerate
(
_output_ports_dist
):
port
=
PortButton
(
"
>
"
,
operation
,
op
.
output
(
i
),
self
)
self
.
portDict
[
operation
].
append
(
port
)
operation
.
ports
.
append
(
port
)
port
.
move
(
MINBUTTONSIZE
-
PORTWIDTH
,
dist
)
port
.
show
()
def
get_operations_from_namespace
(
self
,
namespace
):
def
get_operations_from_namespace
(
self
,
namespace
):
self
.
logger
.
info
(
self
.
logger
.
info
(
f
"
Fetching operations from namespace:
{
namespace
.
__name__
}
.
"
f
"
Fetching operations from namespace:
{
namespace
.
__name__
}
.
"
...
@@ -511,7 +472,7 @@ class MainWindow(QMainWindow):
...
@@ -511,7 +472,7 @@ class MainWindow(QMainWindow):
f
"
Added operations from namespace:
{
namespace
.
__name__
}
.
"
f
"
Added operations from namespace:
{
namespace
.
__name__
}
.
"
)
)
def
add_namespace
(
self
):
def
add_namespace
(
self
,
event
=
None
):
module
,
accepted
=
QFileDialog
().
getOpenFileName
()
module
,
accepted
=
QFileDialog
().
getOpenFileName
()
if
not
accepted
:
if
not
accepted
:
return
return
...
@@ -526,12 +487,6 @@ class MainWindow(QMainWindow):
...
@@ -526,12 +487,6 @@ class MainWindow(QMainWindow):
namespace
,
self
.
ui
.
custom_operations_list
namespace
,
self
.
ui
.
custom_operations_list
)
)
def
_get_button_height
(
self
,
op
):
max_ports
=
max
(
op
.
input_count
,
op
.
output_count
)
return
max
(
MINBUTTONSIZE
,
max_ports
*
PORTHEIGHT
+
(
max_ports
-
1
)
*
GAP
)
def
create_operation
(
self
,
op
,
position
=
None
):
def
create_operation
(
self
,
op
,
position
=
None
):
try
:
try
:
attr_button
=
DragButton
(
attr_button
=
DragButton
(
...
@@ -542,14 +497,18 @@ class MainWindow(QMainWindow):
...
@@ -542,14 +497,18 @@ class MainWindow(QMainWindow):
else
:
else
:
attr_button
.
move
(
*
position
)
attr_button
.
move
(
*
position
)
attr_button
.
setFixedSize
(
max_ports
=
max
(
op
.
input_count
,
op
.
output_count
)
MINBUTTONSIZE
,
self
.
_get_button_height
(
op
)
button_height
=
max
(
MINBUTTONSIZE
,
max_ports
*
PORTHEIGHT
+
(
max_ports
-
1
)
*
GAP
)
)
attr_button
.
setFixedSize
(
MINBUTTONSIZE
,
button_height
)
attr_button
.
setStyleSheet
(
attr_button
.
setStyleSheet
(
"
background-color: white; border-style: solid;
"
"
background-color: white; border-style: solid;
"
"
border-color: black; border-width: 2px
"
"
border-color: black; border-width: 2px
"
)
)
self
.
add_ports
(
attr_button
)
attr_button
.
add_ports
()
self
.
portDict
[
attr_button
]
=
attr_button
.
ports
icon_path
=
os
.
path
.
join
(
icon_path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
os
.
path
.
dirname
(
__file__
),
...
@@ -588,7 +547,7 @@ class MainWindow(QMainWindow):
...
@@ -588,7 +547,7 @@ class MainWindow(QMainWindow):
self
.
dragOperationSceneDict
[
attr_button
]
=
attr_button_scene
self
.
dragOperationSceneDict
[
attr_button
]
=
attr_button_scene
except
Exception
as
e
:
except
Exception
as
e
:
self
.
logger
.
error
(
self
.
logger
.
error
(
f
"
Unexpected error occured while creating operation:
{
e
}
.
"
f
"
Unexpected error occur
r
ed while creating operation:
{
e
}
.
"
)
)
def
_create_operation_item
(
self
,
item
):
def
_create_operation_item
(
self
,
item
):
...
@@ -598,7 +557,7 @@ class MainWindow(QMainWindow):
...
@@ -598,7 +557,7 @@ class MainWindow(QMainWindow):
self
.
create_operation
(
attr_oper
)
self
.
create_operation
(
attr_oper
)
except
Exception
as
e
:
except
Exception
as
e
:
self
.
logger
.
error
(
self
.
logger
.
error
(
f
"
Unexpected error occured while creating operation:
{
e
}
.
"
f
"
Unexpected error occur
r
ed while creating operation:
{
e
}
.
"
)
)
def
_refresh_operations_list_from_namespace
(
self
):
def
_refresh_operations_list_from_namespace
(
self
):
...
@@ -607,10 +566,10 @@ class MainWindow(QMainWindow):
...
@@ -607,10 +566,10 @@ class MainWindow(QMainWindow):
self
.
ui
.
special_operations_list
.
clear
()
self
.
ui
.
special_operations_list
.
clear
()
self
.
add_operations_from_namespace
(
self
.
add_operations_from_namespace
(
c_oper
,
self
.
ui
.
core_operations_list
b_asic
.
core_operations
,
self
.
ui
.
core_operations_list
)
)
self
.
add_operations_from_namespace
(
self
.
add_operations_from_namespace
(
s_oper
,
self
.
ui
.
special_operations_list
b_asic
.
special_operations
,
self
.
ui
.
special_operations_list
)
)
self
.
logger
.
info
(
"
Finished refreshing operation list.
"
)
self
.
logger
.
info
(
"
Finished refreshing operation list.
"
)
...
...
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