Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • da/B-ASIC
  • lukja239/B-ASIC
  • robal695/B-ASIC
3 results
Show changes
Commits on Source (101)
Showing
with 1820 additions and 35 deletions
.vs/
.vscode/
build*/
bin*/
logs/
dist/
CMakeLists.txt.user*
*.autosave
*.creator
*.creator.user*
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*
*~
.fuse_hudden*
.directory
.Trash-*
.nfs*
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
$RECYCLE.BIN/
*.stackdump
[Dd]esktop.ini
*.egg-info
__pycache__/
env/
.vs/
.vscode/
build*/
bin*/
logs/
dist/
CMakeLists.txt.user*
*.autosave
*.creator
*.creator.user*
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*
*~
.fuse_hudden*
.directory
.Trash-*
.nfs*
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
$RECYCLE.BIN/
*.stackdump
[Dd]esktop.ini
*.egg-info
__pycache__/
env/
venv/
\ No newline at end of file
......@@ -8,17 +8,27 @@ How to build and debug the library during development.
### Prerequisites
The following packages are required in order to build the library:
* cmake 3.8+
* C++:
* cmake 3.8+
* gcc 7+/clang 7+/msvc 16+
* fmtlib 5.2.1+
* pybind11 2.3.0+
* python 3.6+
* Python:
* python 3.6+
* setuptools
* wheel
* pybind11
* numpy
* pyside2/pyqt5
To build a binary distribution, the following additional packages are required:
* Python:
* wheel
To run the test suite, the following additional packages are required:
* Python:
* pytest
* pytest-cov (for testing with coverage)
### Using CMake directly
How to build using CMake.
......
"""TODO"""
from drag_button import *
from improved_main_window import *
from gui_interface import *
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QLabel, QAction,\
QStatusBar, QMenuBar, QLineEdit, QPushButton, QSlider, QScrollArea, QVBoxLayout,\
QHBoxLayout, QDockWidget, QToolBar, QMenu, QLayout, QSizePolicy, QListWidget, QListWidgetItem,\
QGraphicsLineItem, QGraphicsWidget
from PyQt5.QtCore import Qt, QSize, QLineF, QPoint, QRectF
from PyQt5.QtGui import QIcon, QFont, QPainter, QPen
class Arrow(QGraphicsLineItem):
def __init__(self, source, destination, window, parent=None):
super(Arrow, self).__init__(parent)
self.source = source
self.destination = destination
self._window = window
self.moveLine()
self.source.moved.connect(self.moveLine)
self.destination.moved.connect(self.moveLine)
def contextMenuEvent(self, event):
menu = QMenu()
menu.addAction("Delete", self.remove)
menu.exec_(self.cursor().pos())
def remove(self):
self._window.scene.removeItem(self)
self._window.signalList.remove(self)
def moveLine(self):
self.setPen(QPen(Qt.black, 3))
self.setLine(QLineF(self.source.operation.x()+self.source.x()+14,\
self.source.operation.y()+self.source.y()+7.5,\
self.destination.operation.x()+self.destination.x(),\
self.destination.operation.y()+self.destination.y()+7.5))
"""@package docstring
Drag button class.
This class creates a dragbutton which can be clicked, dragged and dropped.
"""
import os.path
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtCore import Qt, QSize
from PyQt5.QtGui import QIcon
from utils import decorate_class, handle_error
@decorate_class(handle_error)
class DragButton(QPushButton):
def __init__(self, name, operation, operation_path_name, window, parent = None):
self.name = name
self._window = window
self.operation = operation
self.operation_path_name = operation_path_name
self.clicked = 0
self.pressed = False
super(DragButton, self).__init__(self._window)
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()
for signal in self._window.signalList:
signal.update()
self.clicked += 1
if self.clicked == 1:
self.pressed = True
self.setStyleSheet("background-color: grey; border-style: solid;\
border-color: black; border-width: 2px; border-radius: 10px")
path_to_image = os.path.join('operation_icons', self.operation_path_name + '_grey.png')
self.setIcon(QIcon(path_to_image))
self.setIconSize(QSize(50, 50))
self._window.pressed_button.append(self)
elif self.clicked == 2:
self.clicked = 0
self.pressed = False
self.setStyleSheet("background-color: white; border-style: solid;\
border-color: black; border-width: 2px; border-radius: 10px")
path_to_image = os.path.join('operation_icons', self.operation_path_name + '.png')
self.setIcon(QIcon(path_to_image))
self.setIconSize(QSize(50, 50))
self._window.pressed_button.remove(self)
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
self._window.update()
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)
def remove(self):
self.deleteLater()
\ No newline at end of file
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'gui_interface.ui'
#
# Created by: PyQt5 UI code generator 5.14.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_main_window(object):
def setupUi(self, main_window):
main_window.setObjectName("main_window")
main_window.setEnabled(True)
main_window.resize(897, 633)
self.centralwidget = QtWidgets.QWidget(main_window)
self.centralwidget.setObjectName("centralwidget")
self.operation_box = QtWidgets.QGroupBox(self.centralwidget)
self.operation_box.setGeometry(QtCore.QRect(10, 10, 201, 531))
self.operation_box.setLayoutDirection(QtCore.Qt.LeftToRight)
self.operation_box.setAutoFillBackground(False)
self.operation_box.setStyleSheet("QGroupBox { \n"
" border: 2px solid gray; \n"
" border-radius: 3px;\n"
" margin-top: 0.5em; \n"
" } \n"
"\n"
"QGroupBox::title {\n"
" subcontrol-origin: margin;\n"
" left: 10px;\n"
" padding: 0 3px 0 3px;\n"
"}")
self.operation_box.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter)
self.operation_box.setFlat(False)
self.operation_box.setCheckable(False)
self.operation_box.setObjectName("operation_box")
self.operation_list = QtWidgets.QToolBox(self.operation_box)
self.operation_list.setGeometry(QtCore.QRect(10, 20, 171, 271))
self.operation_list.setAutoFillBackground(False)
self.operation_list.setObjectName("operation_list")
self.core_operations_page = QtWidgets.QWidget()
self.core_operations_page.setGeometry(QtCore.QRect(0, 0, 171, 217))
self.core_operations_page.setObjectName("core_operations_page")
self.core_operations_list = QtWidgets.QListWidget(self.core_operations_page)
self.core_operations_list.setGeometry(QtCore.QRect(10, 0, 141, 211))
self.core_operations_list.setMinimumSize(QtCore.QSize(141, 0))
self.core_operations_list.setEditTriggers(QtWidgets.QAbstractItemView.DoubleClicked|QtWidgets.QAbstractItemView.EditKeyPressed)
self.core_operations_list.setDragEnabled(False)
self.core_operations_list.setDragDropMode(QtWidgets.QAbstractItemView.NoDragDrop)
self.core_operations_list.setMovement(QtWidgets.QListView.Static)
self.core_operations_list.setFlow(QtWidgets.QListView.TopToBottom)
self.core_operations_list.setProperty("isWrapping", False)
self.core_operations_list.setResizeMode(QtWidgets.QListView.Adjust)
self.core_operations_list.setLayoutMode(QtWidgets.QListView.SinglePass)
self.core_operations_list.setViewMode(QtWidgets.QListView.ListMode)
self.core_operations_list.setUniformItemSizes(False)
self.core_operations_list.setWordWrap(False)
self.core_operations_list.setSelectionRectVisible(False)
self.core_operations_list.setObjectName("core_operations_list")
self.operation_list.addItem(self.core_operations_page, "")
self.special_operations_page = QtWidgets.QWidget()
self.special_operations_page.setGeometry(QtCore.QRect(0, 0, 171, 217))
self.special_operations_page.setObjectName("special_operations_page")
self.special_operations_list = QtWidgets.QListWidget(self.special_operations_page)
self.special_operations_list.setGeometry(QtCore.QRect(10, 0, 141, 81))
self.special_operations_list.setObjectName("special_operations_list")
self.operation_list.addItem(self.special_operations_page, "")
main_window.setCentralWidget(self.centralwidget)
self.menu_bar = QtWidgets.QMenuBar(main_window)
self.menu_bar.setGeometry(QtCore.QRect(0, 0, 897, 21))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 255, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Light, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Midlight, brush)
brush = QtGui.QBrush(QtGui.QColor(127, 127, 127))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Dark, brush)
brush = QtGui.QBrush(QtGui.QColor(170, 170, 170))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Mid, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.BrightText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Shadow, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.AlternateBase, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 220))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ToolTipBase, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ToolTipText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 128))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.PlaceholderText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 255, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Light, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Midlight, brush)
brush = QtGui.QBrush(QtGui.QColor(127, 127, 127))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Dark, brush)
brush = QtGui.QBrush(QtGui.QColor(170, 170, 170))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Mid, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.BrightText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Shadow, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.AlternateBase, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 220))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ToolTipBase, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ToolTipText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 128))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.PlaceholderText, brush)
brush = QtGui.QBrush(QtGui.QColor(127, 127, 127))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 255, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Light, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Midlight, brush)
brush = QtGui.QBrush(QtGui.QColor(127, 127, 127))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Dark, brush)
brush = QtGui.QBrush(QtGui.QColor(170, 170, 170))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Mid, brush)
brush = QtGui.QBrush(QtGui.QColor(127, 127, 127))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.BrightText, brush)
brush = QtGui.QBrush(QtGui.QColor(127, 127, 127))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Shadow, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.AlternateBase, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 220))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ToolTipBase, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ToolTipText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 128))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.PlaceholderText, brush)
self.menu_bar.setPalette(palette)
self.menu_bar.setObjectName("menu_bar")
self.file_menu = QtWidgets.QMenu(self.menu_bar)
self.file_menu.setObjectName("file_menu")
self.edit_menu = QtWidgets.QMenu(self.menu_bar)
self.edit_menu.setObjectName("edit_menu")
self.view_menu = QtWidgets.QMenu(self.menu_bar)
self.view_menu.setObjectName("view_menu")
main_window.setMenuBar(self.menu_bar)
self.status_bar = QtWidgets.QStatusBar(main_window)
self.status_bar.setObjectName("status_bar")
main_window.setStatusBar(self.status_bar)
self.save_menu = QtWidgets.QAction(main_window)
self.save_menu.setObjectName("save_menu")
self.exit_menu = QtWidgets.QAction(main_window)
self.exit_menu.setObjectName("exit_menu")
self.actionUndo = QtWidgets.QAction(main_window)
self.actionUndo.setObjectName("actionUndo")
self.actionRedo = QtWidgets.QAction(main_window)
self.actionRedo.setObjectName("actionRedo")
self.actionToolbar = QtWidgets.QAction(main_window)
self.actionToolbar.setCheckable(True)
self.actionToolbar.setObjectName("actionToolbar")
self.file_menu.addAction(self.save_menu)
self.file_menu.addSeparator()
self.file_menu.addAction(self.exit_menu)
self.edit_menu.addAction(self.actionUndo)
self.edit_menu.addAction(self.actionRedo)
self.view_menu.addAction(self.actionToolbar)
self.menu_bar.addAction(self.file_menu.menuAction())
self.menu_bar.addAction(self.edit_menu.menuAction())
self.menu_bar.addAction(self.view_menu.menuAction())
self.retranslateUi(main_window)
self.operation_list.setCurrentIndex(1)
self.core_operations_list.setCurrentRow(-1)
QtCore.QMetaObject.connectSlotsByName(main_window)
def retranslateUi(self, main_window):
_translate = QtCore.QCoreApplication.translate
main_window.setWindowTitle(_translate("main_window", "MainWindow"))
self.operation_box.setTitle(_translate("main_window", "Operations"))
self.core_operations_list.setSortingEnabled(False)
__sortingEnabled = self.core_operations_list.isSortingEnabled()
self.core_operations_list.setSortingEnabled(False)
self.core_operations_list.setSortingEnabled(__sortingEnabled)
self.operation_list.setItemText(self.operation_list.indexOf(self.core_operations_page), _translate("main_window", "Core operations"))
__sortingEnabled = self.special_operations_list.isSortingEnabled()
self.special_operations_list.setSortingEnabled(False)
self.special_operations_list.setSortingEnabled(__sortingEnabled)
self.operation_list.setItemText(self.operation_list.indexOf(self.special_operations_page), _translate("main_window", "Special operations"))
self.file_menu.setTitle(_translate("main_window", "File"))
self.edit_menu.setTitle(_translate("main_window", "Edit"))
self.view_menu.setTitle(_translate("main_window", "View"))
self.save_menu.setText(_translate("main_window", "Save"))
self.exit_menu.setText(_translate("main_window", "Exit"))
self.exit_menu.setShortcut(_translate("main_window", "Ctrl+Q"))
self.actionUndo.setText(_translate("main_window", "Undo"))
self.actionRedo.setText(_translate("main_window", "Redo"))
self.actionToolbar.setText(_translate("main_window", "Toolbar"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
main_window = QtWidgets.QMainWindow()
ui = Ui_main_window()
ui.setupUi(main_window)
main_window.show()
sys.exit(app.exec_())
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>main_window</class>
<widget class="QMainWindow" name="main_window">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>897</width>
<height>633</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QGroupBox" name="operation_box">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>201</width>
<height>531</height>
</rect>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">QGroupBox {
border: 2px solid gray;
border-radius: 3px;
margin-top: 0.5em;
}
QGroupBox::title {
subcontrol-origin: margin;
left: 10px;
padding: 0 3px 0 3px;
}</string>
</property>
<property name="title">
<string>Operations</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="flat">
<bool>false</bool>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<widget class="QToolBox" name="operation_list">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>171</width>
<height>271</height>
</rect>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="core_operations_page">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>171</width>
<height>217</height>
</rect>
</property>
<attribute name="label">
<string>Core operations</string>
</attribute>
<widget class="QListWidget" name="core_operations_list">
<property name="geometry">
<rect>
<x>10</x>
<y>0</y>
<width>141</width>
<height>211</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>141</width>
<height>0</height>
</size>
</property>
<property name="editTriggers">
<set>QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed</set>
</property>
<property name="dragEnabled">
<bool>false</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::NoDragDrop</enum>
</property>
<property name="movement">
<enum>QListView::Static</enum>
</property>
<property name="flow">
<enum>QListView::TopToBottom</enum>
</property>
<property name="isWrapping" stdset="0">
<bool>false</bool>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="layoutMode">
<enum>QListView::SinglePass</enum>
</property>
<property name="viewMode">
<enum>QListView::ListMode</enum>
</property>
<property name="uniformItemSizes">
<bool>false</bool>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
<property name="selectionRectVisible">
<bool>false</bool>
</property>
<property name="currentRow">
<number>-1</number>
</property>
<property name="sortingEnabled">
<bool>false</bool>
</property>
<item>
<property name="text">
<string>Addition</string>
</property>
</item>
<item>
<property name="text">
<string>Subtraction</string>
</property>
</item>
<item>
<property name="text">
<string>Multiplication</string>
</property>
</item>
<item>
<property name="text">
<string>Division</string>
</property>
</item>
<item>
<property name="text">
<string>Constant</string>
</property>
</item>
<item>
<property name="text">
<string>Constant multiplication</string>
</property>
</item>
<item>
<property name="text">
<string>Square root</string>
</property>
</item>
<item>
<property name="text">
<string>Complex conjugate</string>
</property>
</item>
<item>
<property name="text">
<string>Absolute</string>
</property>
</item>
<item>
<property name="text">
<string>Max</string>
</property>
</item>
<item>
<property name="text">
<string>Min</string>
</property>
</item>
<item>
<property name="text">
<string>Butterfly</string>
</property>
</item>
</widget>
</widget>
<widget class="QWidget" name="special_operations_page">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>171</width>
<height>217</height>
</rect>
</property>
<attribute name="label">
<string>Special operations</string>
</attribute>
<widget class="QListWidget" name="special_operations_list">
<property name="geometry">
<rect>
<x>10</x>
<y>0</y>
<width>141</width>
<height>81</height>
</rect>
</property>
<item>
<property name="text">
<string>Input</string>
</property>
</item>
<item>
<property name="text">
<string>Output</string>
</property>
</item>
<item>
<property name="text">
<string>Register</string>
</property>
</item>
<item>
<property name="text">
<string>Custom</string>
</property>
</item>
</widget>
</widget>
</widget>
</widget>
</widget>
<widget class="QMenuBar" name="menu_bar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>897</width>
<height>21</height>
</rect>
</property>
<property name="palette">
<palette>
<active>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>255</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Light">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Midlight">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Dark">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>127</red>
<green>127</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Mid">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>170</red>
<green>170</green>
<blue>170</blue>
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="BrightText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Shadow">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="AlternateBase">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="ToolTipBase">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>220</blue>
</color>
</brush>
</colorrole>
<colorrole role="ToolTipText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="PlaceholderText">
<brush brushstyle="SolidPattern">
<color alpha="128">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>255</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Light">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Midlight">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Dark">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>127</red>
<green>127</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Mid">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>170</red>
<green>170</green>
<blue>170</blue>
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="BrightText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Shadow">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="AlternateBase">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="ToolTipBase">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>220</blue>
</color>
</brush>
</colorrole>
<colorrole role="ToolTipText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="PlaceholderText">
<brush brushstyle="SolidPattern">
<color alpha="128">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>127</red>
<green>127</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>255</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Light">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Midlight">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Dark">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>127</red>
<green>127</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Mid">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>170</red>
<green>170</green>
<blue>170</blue>
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>127</red>
<green>127</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="BrightText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>127</red>
<green>127</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Shadow">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="AlternateBase">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="ToolTipBase">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>220</blue>
</color>
</brush>
</colorrole>
<colorrole role="ToolTipText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="PlaceholderText">
<brush brushstyle="SolidPattern">
<color alpha="128">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<widget class="QMenu" name="file_menu">
<property name="title">
<string>File</string>
</property>
<addaction name="save_menu"/>
<addaction name="separator"/>
<addaction name="exit_menu"/>
</widget>
<widget class="QMenu" name="edit_menu">
<property name="title">
<string>Edit</string>
</property>
<addaction name="actionUndo"/>
<addaction name="actionRedo"/>
</widget>
<widget class="QMenu" name="view_menu">
<property name="title">
<string>View</string>
</property>
<addaction name="actionToolbar"/>
</widget>
<addaction name="file_menu"/>
<addaction name="edit_menu"/>
<addaction name="view_menu"/>
</widget>
<widget class="QStatusBar" name="status_bar"/>
<action name="save_menu">
<property name="text">
<string>Save</string>
</property>
</action>
<action name="exit_menu">
<property name="text">
<string>Exit</string>
</property>
<property name="shortcut">
<string>Ctrl+Q</string>
</property>
</action>
<action name="actionUndo">
<property name="text">
<string>Undo</string>
</property>
</action>
<action name="actionRedo">
<property name="text">
<string>Redo</string>
</property>
</action>
<action name="actionToolbar">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Toolbar</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>
"""@package docstring
B-ASIC GUI Module.
This python file is the main window of the GUI for B-ASIC.
"""
from os import getcwd, path
import sys
from drag_button import DragButton
from gui_interface import Ui_main_window
from arrow import Arrow
from port_button import PortButton
from b_asic import Operation
import b_asic.core_operations as c_oper
import b_asic.special_operations as s_oper
from utils import decorate_class, handle_error
from numpy import linspace
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QLabel, QAction,\
QStatusBar, QMenuBar, QLineEdit, QPushButton, QSlider, QScrollArea, QVBoxLayout,\
QHBoxLayout, QDockWidget, QToolBar, QMenu, QLayout, QSizePolicy, QListWidget,\
QListWidgetItem, QGraphicsView, QGraphicsScene, QShortcut
from PyQt5.QtCore import Qt, QSize
from PyQt5.QtGui import QIcon, QFont, QPainter, QPen, QBrush, QKeySequence
@decorate_class(handle_error)
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.ui = Ui_main_window()
self.ui.setupUi(self)
self.setWindowTitle(" ")
self.setWindowIcon(QIcon('small_logo.png'))
self.scene = None
self._operations_from_name = dict()
self.zoom = 1
self.operationList = []
self.signalList = []
self.pressed_button = []
self.portList = []
self.pressed_ports = []
self.source = None
self._window = self
self.init_ui()
self.add_operations_from_namespace(c_oper, self.ui.core_operations_list)
self.add_operations_from_namespace(s_oper, self.ui.special_operations_list)
self.shortcut_core = QShortcut(QKeySequence("Ctrl+R"), self.ui.operation_box)
self.shortcut_core.activated.connect(self._refresh_operations_list_from_namespace)
def init_ui(self):
self.ui.core_operations_list.itemClicked.connect(self.on_list_widget_item_clicked)
self.ui.special_operations_list.itemClicked.connect(self.on_list_widget_item_clicked)
self.ui.exit_menu.triggered.connect(self.exit_app)
self.create_graphics_view()
def create_graphics_view(self):
self.scene = QGraphicsScene()
self.graphic_view = QGraphicsView(self.scene, self)
self.graphic_view.setRenderHint(QPainter.Antialiasing)
self.graphic_view.setGeometry(250, 40, 600, 520)
self.graphic_view.setDragMode(QGraphicsView.ScrollHandDrag)
def wheelEvent(self, event):
old_zoom = self.zoom
self.zoom += event.angleDelta().y()/2500
self.graphic_view.scale(self.zoom, self.zoom)
self.zoom = old_zoom
def exit_app(self, checked):
QApplication.quit()
def _determine_port_distance(self, length, 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 [length / 2] if ports == 1 else linspace(0, length, ports)
def _create_port(self, operation, output_port=True):
text = ">" if output_port else "<"
button = PortButton(text, operation, self)
button.setStyleSheet("background-color: white")
button.connectionRequested.connect(self.connectButton)
return button
def add_ports(self, operation):
_output_ports_dist = self._determine_port_distance(50 - 15, operation.operation.output_count)
_input_ports_dist = self._determine_port_distance(50 - 15, operation.operation.input_count)
for dist in _input_ports_dist:
port = self._create_port(operation)
port.move(0, dist)
port.show()
for dist in _output_ports_dist:
port = self._create_port(operation)
port.move(50 - 15, dist)
port.show()
def get_operations_from_namespace(self, namespace):
return [comp for comp in dir(namespace) if hasattr(getattr(namespace, comp), "type_name")]
def add_operations_from_namespace(self, namespace, _list):
for attr_name in self.get_operations_from_namespace(namespace):
attr = getattr(namespace, attr_name)
try:
attr.type_name()
item = QListWidgetItem(attr_name)
_list.addItem(item)
self._operations_from_name[attr_name] = attr
except NotImplementedError:
pass
def _create_operation(self, item):
try:
attr_oper = self._operations_from_name[item.text()]()
attr_button = DragButton(attr_oper.graph_id, attr_oper, attr_oper.type_name().lower(), self)
attr_button.move(250, 100)
attr_button.setFixedSize(50, 50)
attr_button.setStyleSheet("background-color: white; border-style: solid;\
border-color: black; border-width: 2px; border-radius: 10px")
self.add_ports(attr_button)
icon_path = path.join("operation_icons", f"{attr_oper.type_name().lower()}.png")
if not path.exists(icon_path):
icon_path = path.join("operation_icons", f"custom_operation.png")
attr_button.setIcon(QIcon(icon_path))
attr_button.setIconSize(QSize(50, 50))
attr_button.setParent(None)
self.scene.addWidget(attr_button)
self.operationList.append(attr_button)
except Exception as e:
print("Unexpected error occured: ", e)
def _refresh_operations_list_from_namespace(self):
self.ui.core_operations_list.clear()
self.ui.special_operations_list.clear()
self.add_operations_from_namespace(c_oper, self.ui.core_operations_list)
self.add_operations_from_namespace(s_oper, self.ui.special_operations_list)
def print_input_port_1(self):
print("Input port 1")
def print_input_port_2(self):
print("Input port 2")
def print_output_port_1(self):
print("Output port 1")
def print_output_port_2(self):
print("Output port 2")
def on_list_widget_item_clicked(self, item):
self._create_operation(item)
def keyPressEvent(self, event):
pressed_buttons = []
for op in self.operationList:
if op.pressed:
pressed_buttons.append(op)
if event.key() == Qt.Key_Delete:
for pressed_op in pressed_buttons:
self.operationList.remove(pressed_op)
pressed_op.remove()
super().keyPressEvent(event)
def connectButton(self, button):
if len(self.pressed_ports) < 2:
return
for i in range(len(self.pressed_ports) - 1):
line = Arrow(self.pressed_ports[i], self.pressed_ports[i + 1], self)
self.scene.addItem(line)
self.signalList.append(line)
self.update()
def paintEvent(self, event):
for signal in self.signalList:
signal.moveLine()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
"""@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, QSlider, QScrollArea, QVBoxLayout,\
QHBoxLayout, QDockWidget, QToolBar, QMenu
from PyQt5.QtCore import Qt, QSize, pyqtSlot
from PyQt5.QtGui import QIcon, QFont, QPainter, QPen, QColor
from b_asic.core_operations import Addition
class DragButton(QPushButton):
def __init__(self, name, window, parent = None):
self.name = name
self.__menu = None
self.__window = window
self.counter = 0
self.clicked = 0
self.pressed = False
print("Constructor" + self.name)
super(DragButton, self).__init__(self.__window)
self.__window.setContextMenuPolicy(Qt.CustomContextMenu)
self.__window.customContextMenuRequested.connect(self.create_menu)
@pyqtSlot(QAction)
def actionClicked(self, action):
print("Triggern "+ self.name, self.__menu.name)
#self.__window.check_for_remove_op(self.name)
#def show_context_menu(self, point):
# show context menu
def create_menu(self, point):
self.counter += 1
# create context menu
popMenu = MyMenu('Menu' + str(self.counter))
popMenu.addAction(QAction('Add a signal', self))
popMenu.addAction(QAction('Remove a signal', self))
#action = QAction('Remove operation', self)
popMenu.addAction('Remove operation', lambda:self.removeAction(self))
popMenu.addSeparator()
popMenu.addAction(QAction('Remove all signals', self))
self.__window.menuList.append(popMenu)
#self.__window.actionList.append(action)
self.__menu = popMenu
self.pressed = False
self.__menu.exec_(self.__window.sender().mapToGlobal(point))
self.__menu.triggered.connect(self.actionClicked)
def removeAction(self, op):
print(op.__menu.name, op.name)
op.remove()
"""This class is made to create a draggable button"""
def mousePressEvent(self, event):
self._mouse_press_pos = None
self._mouse_move_pos = None
self.clicked += 1
if self.clicked == 1:
self.pressed = True
self.setStyleSheet("background-color: grey; border-style: solid;\
border-color: black; border-width: 2px; border-radius: 10px")
elif self.clicked == 2:
self.clicked = 0
self.presseed = False
self.setStyleSheet("background-color: white; border-style: solid;\
border-color: black; border-width: 2px; border-radius: 10px")
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.pressed = False
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)
def remove(self):
self.deleteLater()
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 MyMenu(QMenu):
def __init__(self, name, parent = None):
self.name = name
super(MyMenu, self).__init__()
class MainWindow(QMainWindow):
"""Main window for the program"""
# pylint: disable=too-many-instance-attributes
# Eight is reasonable in this case.
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.init_ui()
self.counter = 0
self.operations = []
self.menuList = []
self.actionList = []
def init_ui(self):
self.setWindowTitle(" ")
self.setWindowIcon(QIcon('small_logo.png'))
self.create_operation_menu()
self.create_menu_bar()
self.setStatusBar(QStatusBar(self))
def create_operation_menu(self):
self.operation_box = QDockWidget("Operation Box", self)
self.operation_box.setAllowedAreas(Qt.LeftDockWidgetArea)
self.test = QToolBar(self)
self.operation_list = QMenuBar(self)
self.test.addWidget(self.operation_list)
self.test.setOrientation(Qt.Vertical)
self.operation_list.setStyleSheet("background-color:rgb(222,222,222); vertical")
basic_operations = self.operation_list.addMenu('Basic operations')
special_operations = self.operation_list.addMenu('Special operations')
self.addition_menu_item = QAction('&Addition', self)
self.addition_menu_item.setStatusTip("Add addition operation to workspace")
self.addition_menu_item.triggered.connect(self.create_addition_operation)
basic_operations.addAction(self.addition_menu_item)
self.subtraction_menu_item = QAction('&Subtraction', self)
self.subtraction_menu_item.setStatusTip("Add subtraction operation to workspace")
self.subtraction_menu_item.triggered.connect(self.create_subtraction_operation)
basic_operations.addAction(self.subtraction_menu_item)
self.multiplication_menu_item = QAction('&Multiplication', self)
self.multiplication_menu_item.setStatusTip("Add multiplication operation to workspace")
self.multiplication_menu_item.triggered.connect(self.create_multiplication_operation)
basic_operations.addAction(self.multiplication_menu_item)
self.division_menu_item = QAction('&Division', self)
self.division_menu_item.setStatusTip("Add division operation to workspace")
#self.division_menu_item.triggered.connect(self.create_division_operation)
basic_operations.addAction(self.division_menu_item)
self.constant_menu_item = QAction('&Constant', self)
self.constant_menu_item.setStatusTip("Add constant operation to workspace")
#self.constant_menu_item.triggered.connect(self.create_constant_operation)
basic_operations.addAction(self.constant_menu_item)
self.square_root_menu_item = QAction('&Square root', self)
self.square_root_menu_item.setStatusTip("Add square root operation to workspace")
#self.square_root_menu_item.triggered.connect(self.create_square_root_operation)
basic_operations.addAction(self.square_root_menu_item)
self.complex_conjugate_menu_item = QAction('&Complex conjugate', self)
self.complex_conjugate_menu_item.setStatusTip("Add complex conjugate operation to workspace")
#self.complex_conjugate_menu_item.triggered.connect(self.create_complex_conjugate_operation)
basic_operations.addAction(self.complex_conjugate_menu_item)
self.max_menu_item = QAction('&Max', self)
self.max_menu_item.setStatusTip("Add max operation to workspace")
#self.max_menu_item.triggered.connect(self.create_max_operation)
basic_operations.addAction(self.max_menu_item)
self.min_menu_item = QAction('&Min', self)
self.min_menu_item.setStatusTip("Add min operation to workspace")
#self.min_menu_item.triggered.connect(self.create_min_operation)
basic_operations.addAction(self.min_menu_item)
self.absolute_menu_item = QAction('&Absolute', self)
self.absolute_menu_item.setStatusTip("Add absolute operation to workspace")
#self.absolute_menu_item.triggered.connect(self.create_absolute_operation)
basic_operations.addAction(self.absolute_menu_item)
self.constant_addition_menu_item = QAction('&Constant addition', self)
self.constant_addition_menu_item.setStatusTip("Add constant addition operation to workspace")
#self.constant_addition_menu_item.triggered.connect(self.create_constant_addition_operation)
basic_operations.addAction(self.constant_addition_menu_item)
self.constant_subtraction_menu_item = QAction('&Constant subtraction', self)
self.constant_subtraction_menu_item.setStatusTip("Add constant subtraction operation to workspace")
#self.constant_subtraction_menu_item.triggered.connect(self.create_constant_subtraction_operation)
basic_operations.addAction(self.constant_subtraction_menu_item)
self.constant_multiplication_menu_item = QAction('&Constant multiplication', self)
self.constant_multiplication_menu_item.setStatusTip("Add constant multiplication operation to workspace")
#self.constant_multiplication_menu_item.triggered.connect(self.create_constant_multiplication_operation)
basic_operations.addAction(self.constant_multiplication_menu_item)
self.constant_division_menu_item = QAction('&Constant division', self)
self.constant_division_menu_item.setStatusTip("Add constant division operation to workspace")
#self.constant_division_menu_item.triggered.connect(self.create_constant_division_operation)
basic_operations.addAction(self.constant_division_menu_item)
self.butterfly_menu_item = QAction('&Butterfly', self)
self.butterfly_menu_item.setStatusTip("Add butterfly operation to workspace")
#self.butterfly_menu_item.triggered.connect(self.create_butterfly_operation)
basic_operations.addAction(self.butterfly_menu_item)
self.operation_box.setWidget(self.operation_list)
self.operation_box.setMaximumSize(240, 400)
self.operation_box.setFeatures(QDockWidget.NoDockWidgetFeatures)
self.operation_box.setFixedSize(300, 500)
self.operation_box.setStyleSheet("background-color: white; border-style: solid;\
border-color: black; border-width: 2px")
self.addDockWidget(Qt.LeftDockWidgetArea, self.operation_box)
def create_addition_operation(self):
self.counter += 1
# Create drag button
addition_operation = DragButton("OP" + str(self.counter), self)
addition_operation.move(250, 100)
addition_operation.setFixedSize(50, 50)
addition_operation.setStyleSheet("background-color: white; border-style: solid;\
border-color: black; border-width: 2px; border-radius: 10px")
addition_operation.clicked.connect(self.create_sub_window)
#self.addition_operation.setIcon(QIcon("GUI'\'operation_icons'\'plus.png"))
addition_operation.setText("OP" + str(self.counter))
addition_operation.setIconSize(QSize(50, 50))
addition_operation.show()
self.operations.append(addition_operation)
# set context menu policies
#self.addition_operation.setContextMenuPolicy(Qt.CustomContextMenu)
#self.addition_operation.customContextMenuRequested.connect(self.show_context_menu)
#self.action.triggered.connect(lambda checked: self.remove(self.addition_operation.name))
def check_for_remove_op(self, name):
self.remove(name)
def remove(self, name):
for op in self.operations:
print(name, op.name)
if op.name == name:
self.operations.remove(op)
op.remove()
def create_subtraction_operation(self):
self.subtraction_operation = DragButton("sub" + str(self.counter), self)
self.subtraction_operation.move(250, 100)
self.subtraction_operation.setFixedSize(50, 50)
self.subtraction_operation.setStyleSheet("background-color: white; border-style: solid;\
border-color: black; border-width: 2px; border-radius: 10px")
self.subtraction_operation.setIcon(QIcon("GUI'\'operation_icons'\'minus.png"))
self.subtraction_operation.setIconSize(QSize(50, 50))
self.subtraction_operation.clicked.connect(self.create_sub_window)
self.subtraction_operation.show()
# set context menu policies
self.subtraction_operation.setContextMenuPolicy(Qt.CustomContextMenu)
self.subtraction_operation.customContextMenuRequested.connect(self.show_context_menu)
# create context menu
self.button_context_menu = QMenu(self)
self.button_context_menu.addAction(QAction('Add a signal', self))
self.button_context_menu.addAction(QAction('Remove a signal', self))
self.button_context_menu.addSeparator()
self.button_context_menu.addAction(QAction('Remove all signals', self))
def create_multiplication_operation(self):
self.multiplication_operation = DragButton(self)
self.multiplication_operation.move(250, 100)
self.multiplication_operation.setFixedSize(50, 50)
self.multiplication_operation.setStyleSheet("background-color: white; border-style: solid;\
border-color: black; border-width: 2px; border-radius: 10px")
self.multiplication_operation.clicked.connect(self.create_sub_window)
self.multiplication_operation.setIcon(QIcon(r"GUI\operation_icons\plus.png"))
self.multiplication_operation.setIconSize(QSize(50, 50))
self.multiplication_operation.show()
# set context menu policies
self.multiplication_operation.setContextMenuPolicy(Qt.CustomContextMenu)
self.multiplication_operation.customContextMenuRequested.connect(self.show_context_menu)
# create context menu
self.button_context_menu = QMenu(self)
self.button_context_menu.addAction(QAction('Add a signal', self))
self.button_context_menu.addAction(QAction('Remove a signal', self))
self.button_context_menu.addSeparator()
self.button_context_menu.addAction(QAction('Remove all signals', self))
def create_menu_bar(self):
# Menu buttons
load_button = QAction("Load", self)
save_button = QAction("Save", 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(save_button)
file_menu.addSeparator()
file_menu.addAction(exit_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)
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()
def keyPressEvent(self, event):
for op in self.operations:
if event.key() == Qt.Key_Delete and op.pressed:
self.operations.remove(op)
op.remove()
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")
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.resize(960, 720)
window.show()
app.exec_()
b_asic/GUI/operation_icons/abs.png

1.22 KiB

b_asic/GUI/operation_icons/abs_grey.png

1.34 KiB

b_asic/GUI/operation_icons/add.png

1.18 KiB

b_asic/GUI/operation_icons/add_grey.png

1.27 KiB

b_asic/GUI/operation_icons/bfly.png

5.23 KiB

b_asic/GUI/operation_icons/bfly_grey.png

5.02 KiB

b_asic/GUI/operation_icons/c.png

5.08 KiB

b_asic/GUI/operation_icons/c_grey.png

4.9 KiB

b_asic/GUI/operation_icons/cmul.png

3.52 KiB

b_asic/GUI/operation_icons/cmul_grey.png

3.76 KiB

b_asic/GUI/operation_icons/conj.png

3.9 KiB