Skip to content
Snippets Groups Projects
Commit f87dfe46 authored by Jacob Wahlman's avatar Jacob Wahlman :ok_hand:
Browse files

merged w/ latest develop

parents 1733040e a99172b8
No related branches found
No related tags found
1 merge request!46Resolve "Resize GUI Window"
Pipeline #14953 passed
......@@ -5,8 +5,10 @@ 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 properties_window import PropertiesWindow
from PyQt5.QtWidgets import QPushButton, QMenu, QAction
from PyQt5.QtCore import Qt, QSize, pyqtSignal
from PyQt5.QtGui import QIcon
from utils import decorate_class, handle_error
......@@ -14,8 +16,11 @@ 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):
connectionRequested = pyqtSignal(QPushButton)
moved = pyqtSignal()
def __init__(self, name, operation, operation_path_name, is_show_name, window, parent = None):
self.name = name
self.is_show_name = is_show_name
self._window = window
self.operation = operation
self.operation_path_name = operation_path_name
......@@ -25,6 +30,20 @@ class DragButton(QPushButton):
self._mouse_move_pos = None
super(DragButton, self).__init__(self._window)
def contextMenuEvent(self, event):
menu = QMenu()
properties = QAction("Properties")
menu.addAction(properties)
properties.triggered.connect(self.show_properties_window)
menu.exec_(self.cursor().pos())
def show_properties_window(self, event):
self.properties_window = PropertiesWindow(self, self._window)
self.properties_window.show()
def add_label(self, label):
self.label = label
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
......@@ -38,20 +57,20 @@ class DragButton(QPushButton):
if self.clicked == 1:
self.pressed = True
self.setStyleSheet("background-color: grey; border-style: solid;\
border-color: black; border-width: 2px; border-radius: 10px")
border-color: black; border-width: 2px")
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.setIconSize(QSize(55, 55))
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")
border-color: black; border-width: 2px")
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.setIconSize(QSize(55, 55))
self._window.pressed_button.remove(self)
super(DragButton, self).mousePressEvent(event)
......
This diff is collapsed.
from PyQt5.QtWidgets import QDialog, QLineEdit, QPushButton, QVBoxLayout, QHBoxLayout,\
QLabel, QCheckBox
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIntValidator
class PropertiesWindow(QDialog):
def __init__(self, operation, main_window):
super(PropertiesWindow, self).__init__()
self.operation = operation
self.main_window = main_window
self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint)
self.setWindowTitle("Properties")
self.name_layout = QHBoxLayout()
self.name_layout.setSpacing(50)
self.name_label = QLabel("Name:")
self.edit_name = QLineEdit(self.operation.operation_path_name)
self.name_layout.addWidget(self.name_label)
self.name_layout.addWidget(self.edit_name)
self.vertical_layout = QVBoxLayout()
self.vertical_layout.addLayout(self.name_layout)
if self.operation.operation_path_name == "c":
self.constant_layout = QHBoxLayout()
self.constant_layout.setSpacing(50)
self.constant_value = QLabel("Constant:")
self.edit_constant = QLineEdit(str(self.operation.operation.value))
self.only_accept_int = QIntValidator()
self.edit_constant.setValidator(self.only_accept_int)
self.constant_layout.addWidget(self.constant_value)
self.constant_layout.addWidget(self.edit_constant)
self.vertical_layout.addLayout(self.constant_layout)
self.show_name_layout = QHBoxLayout()
self.check_show_name = QCheckBox("Show name?")
if self.operation.is_show_name:
self.check_show_name.setChecked(1)
else:
self.check_show_name.setChecked(0)
self.check_show_name.setLayoutDirection(Qt.RightToLeft)
self.check_show_name.setStyleSheet("spacing: 170px")
self.show_name_layout.addWidget(self.check_show_name)
self.vertical_layout.addLayout(self.show_name_layout)
self.ok = QPushButton("OK")
self.ok.clicked.connect(self.save_properties)
self.vertical_layout.addWidget(self.ok)
self.setLayout(self.vertical_layout)
def save_properties(self):
self.operation.name = self.edit_name.text()
self.operation.label.setPlainText(self.operation.name)
if self.operation.operation_path_name == "c":
self.operation.operation.value = self.edit_constant.text()
if self.check_show_name.isChecked():
self.operation.label.setOpacity(1)
self.operation.is_show_name = True
else:
self.operation.label.setOpacity(0)
self.operation.is_show_name = False
self.reject()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment