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

initial changes

parent 08eaa299
Branches
No related tags found
1 merge request!46Resolve "Resize GUI Window"
Pipeline #14914 passed
...@@ -21,11 +21,11 @@ class DragButton(QPushButton): ...@@ -21,11 +21,11 @@ class DragButton(QPushButton):
self.operation_path_name = operation_path_name self.operation_path_name = operation_path_name
self.clicked = 0 self.clicked = 0
self.pressed = False self.pressed = False
self._mouse_press_pos = None
self._mouse_move_pos = None
super(DragButton, self).__init__(self._window) super(DragButton, self).__init__(self._window)
def mousePressEvent(self, event): def mousePressEvent(self, event):
self._mouse_press_pos = None
self._mouse_move_pos = None
if event.button() == Qt.LeftButton: if event.button() == Qt.LeftButton:
self._mouse_press_pos = event.globalPos() self._mouse_press_pos = event.globalPos()
...@@ -60,6 +60,9 @@ class DragButton(QPushButton): ...@@ -60,6 +60,9 @@ class DragButton(QPushButton):
if event.buttons() == Qt.LeftButton: if event.buttons() == Qt.LeftButton:
cur_pos = self.mapToGlobal(self.pos()) cur_pos = self.mapToGlobal(self.pos())
global_pos = event.globalPos() global_pos = event.globalPos()
if self._mouse_move_pos is None:
self._mouse_move_pos = global_pos
diff = global_pos - self._mouse_move_pos diff = global_pos - self._mouse_move_pos
new_pos = self.mapFromGlobal(cur_pos + diff) new_pos = self.mapFromGlobal(cur_pos + diff)
self.move(new_pos) self.move(new_pos)
......
...@@ -22,10 +22,13 @@ from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QLabel, QAction, ...@@ -22,10 +22,13 @@ from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QLabel, QAction,
QStatusBar, QMenuBar, QLineEdit, QPushButton, QSlider, QScrollArea, QVBoxLayout,\ QStatusBar, QMenuBar, QLineEdit, QPushButton, QSlider, QScrollArea, QVBoxLayout,\
QHBoxLayout, QDockWidget, QToolBar, QMenu, QLayout, QSizePolicy, QListWidget,\ QHBoxLayout, QDockWidget, QToolBar, QMenu, QLayout, QSizePolicy, QListWidget,\
QListWidgetItem, QGraphicsView, QGraphicsScene, QShortcut QListWidgetItem, QGraphicsView, QGraphicsScene, QShortcut
from PyQt5.QtCore import Qt, QSize from PyQt5.QtCore import Qt, QSize, QSize
from PyQt5.QtGui import QIcon, QFont, QPainter, QPen, QBrush, QKeySequence from PyQt5.QtGui import QIcon, QFont, QPainter, QPen, QBrush, QKeySequence
MIN_WIDTH_SCENE = 600
MIN_HEIGHT_SCENE = 520
@decorate_class(handle_error) @decorate_class(handle_error)
class MainWindow(QMainWindow): class MainWindow(QMainWindow):
def __init__(self): def __init__(self):
...@@ -58,11 +61,21 @@ class MainWindow(QMainWindow): ...@@ -58,11 +61,21 @@ class MainWindow(QMainWindow):
self.ui.exit_menu.triggered.connect(self.exit_app) self.ui.exit_menu.triggered.connect(self.exit_app)
self.create_graphics_view() self.create_graphics_view()
def resizeEvent(self, event):
oldSize = event.oldSize()
if event.oldSize() == QSize(-1, -1):
oldSize = event.size()
newWidth = oldSize.width() * (oldSize.width() / event.size().width())
newHeight = oldSize.height() * (oldSize.height() / event.size().height())
self.graphic_view.setGeometry(250, 40, newWidth - 300, newHeight - 100)
super(MainWindow, self).resizeEvent(event)
def create_graphics_view(self): def create_graphics_view(self):
self.scene = QGraphicsScene() 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(250, 40, 600, 520) self.graphic_view.setGeometry(0, 0, self.width(), self.height())
self.graphic_view.setDragMode(QGraphicsView.ScrollHandDrag) self.graphic_view.setDragMode(QGraphicsView.ScrollHandDrag)
def wheelEvent(self, event): def wheelEvent(self, event):
...@@ -187,5 +200,6 @@ class MainWindow(QMainWindow): ...@@ -187,5 +200,6 @@ class MainWindow(QMainWindow):
if __name__ == "__main__": if __name__ == "__main__":
app = QApplication(sys.argv) app = QApplication(sys.argv)
window = MainWindow() window = MainWindow()
window.setMinimumSize(MIN_WIDTH_SCENE, MIN_HEIGHT_SCENE)
window.show() window.show()
sys.exit(app.exec_()) sys.exit(app.exec_())
...@@ -20,7 +20,6 @@ class PortButton(QPushButton): ...@@ -20,7 +20,6 @@ class PortButton(QPushButton):
menu.exec_(self.cursor().pos()) menu.exec_(self.cursor().pos())
def mousePressEvent(self, event): def mousePressEvent(self, event):
if event.button() == Qt.LeftButton: if event.button() == Qt.LeftButton:
self.clicked += 1 self.clicked += 1
if self.clicked == 1: if self.clicked == 1:
...@@ -29,11 +28,11 @@ class PortButton(QPushButton): ...@@ -29,11 +28,11 @@ class PortButton(QPushButton):
self.window.pressed_ports.append(self) self.window.pressed_ports.append(self)
elif self.clicked == 2: elif self.clicked == 2:
self.setStyleSheet("background-color: white") self.setStyleSheet("background-color: white")
self.pressed = False self.pressed = False
self.clicked = 0 self.clicked = 0
self.window.pressed_ports.remove(self) self.window.pressed_ports.remove(self)
super(PortButton, self).mousePressEvent(event) super(PortButton, self).mousePressEvent(event)
def mouseReleaseEvent(self, event): def mouseReleaseEvent(self, event):
super(PortButton, self).mouseReleaseEvent(event) super(PortButton, self).mouseReleaseEvent(event)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment