summaryrefslogtreecommitdiff
path: root/src/main/python/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/python/utils')
-rw-r--r--src/main/python/utils/dialogs.py34
-rw-r--r--src/main/python/utils/fileWindow.py27
2 files changed, 56 insertions, 5 deletions
diff --git a/src/main/python/utils/dialogs.py b/src/main/python/utils/dialogs.py
index 4970468..8ab8f6f 100644
--- a/src/main/python/utils/dialogs.py
+++ b/src/main/python/utils/dialogs.py
@@ -59,7 +59,41 @@ class paperDims(QDialog):
self.deleteLater() #remove from memory
#if ok was pressed return value else return None
return (self._canvasSize, self._ppi) if self.result() else None
+
+class sideViewSwitchDialog(QDialog):
+
+ def __init__(self, parent=None, tabList = None, initial = None):
+ super(sideViewSwitchDialog, self).__init__(parent=parent)
+ self.tabList = tabList
+ self.returnVal = initial
+ self.initial = initial
+
+ dialogBoxLayout = QFormLayout(self)
+ tabListComboBox = QComboBox()
+ tabListComboBox.addItems(self.tabList)
+ tabListComboBox.activated[str].connect(lambda x: setattr(self, 'returnVal', self.tabList.index(x)))
+ tabLabel = QLabel("Change Side View")
+ tabLabel.setBuddy(tabListComboBox) # label for the above combo box
+ tabListComboBox.setCurrentIndex(self.returnVal)
+ dialogBoxLayout.setWidget(1, QFormLayout.LabelRole, tabLabel)
+ dialogBoxLayout.setWidget(1, QFormLayout.FieldRole, tabListComboBox)
+
+ # add ok and cancel buttons
+ buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, self)
+ buttonBox.accepted.connect(self.accept)
+ buttonBox.rejected.connect(self.reject)
+ dialogBoxLayout.addWidget(buttonBox)
+ self.setLayout(dialogBoxLayout)
+ self.resize(300,100) #resize to a certain size
+
+ def exec_(self):
+ #overload exec_ to add return values and delete itself(currently being tested)
+ super(sideViewSwitchDialog, self).exec_()
+ self.deleteLater() #remove from memory
+ #if ok was pressed return value else return None
+ return self.returnVal if self.result() else self.initial
+
def saveEvent(parent = None):
#utility function to generate a Qt alert window requesting the user to save the file, returns user intention on window close
alert = QMessageBox.question(parent, parent.objectName(), "All unsaved progress will be LOST!",
diff --git a/src/main/python/utils/fileWindow.py b/src/main/python/utils/fileWindow.py
index 2fb6abb..1c53c86 100644
--- a/src/main/python/utils/fileWindow.py
+++ b/src/main/python/utils/fileWindow.py
@@ -1,6 +1,6 @@
import pickle
-from PyQt5.QtCore import Qt, pyqtSignal
+from PyQt5.QtCore import Qt, pyqtSignal, QPoint
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import (QFileDialog, QHBoxLayout,
QMdiSubWindow, QMenu, QPushButton, QSizePolicy,
@@ -45,8 +45,8 @@ class fileWindow(QMdiSubWindow):
self.setWindowTitle(title)
#This is done so that a right click menu is shown on right click
- self.setContextMenuPolicy(Qt.CustomContextMenu)
- self.customContextMenuRequested.connect(self.contextMenu)
+ self.tabber.setContextMenuPolicy(Qt.CustomContextMenu)
+ self.tabber.customContextMenuRequested.connect(self.contextMenu)
# self.setAttribute(Qt.WA_DeleteOnClose, True)
self.setWindowFlag(Qt.CustomizeWindowHint, True)
@@ -79,6 +79,8 @@ class fileWindow(QMdiSubWindow):
self.sideViewCloseButton.clicked.connect(lambda: setattr(self, 'sideViewTab', None))
self.splitter.setVisible(False)
self.sideView.setVisible(False)
+ self.sideView.setContextMenuPolicy(Qt.CustomContextMenu)
+ self.sideView.customContextMenuRequested.connect(self.sideViewContextMenu)
def resizeHandler(self):
# resize Handler to handle resize cases.
@@ -110,7 +112,8 @@ class fileWindow(QMdiSubWindow):
menu.addAction("Adjust Canvas", self.adjustCanvasDialog)
menu.addAction("Remove Side View" if self.sideViewTab == self.tabber.currentWidget() else "View Side-By-Side",
self.sideViewMode)
- menu.exec_(self.mapToGlobal(point))
+ menu.addAction("Reset Zoom", lambda : setattr(self.tabber.currentWidget().view, 'zoom', 1))
+ menu.exec_(self.tabber.mapToGlobal(point))
def sideViewMode(self):
#helper context menu function to toggle side view
@@ -147,7 +150,21 @@ class fileWindow(QMdiSubWindow):
# x -= self.style().pixelMetric(QStyle.PM_ScrollBarExtent)
# self.sideViewCloseButton.move(x, 5)
self.sideViewCloseButton.move(5, 5)
-
+
+ def sideViewContextMenu(self, point):
+ menu = QMenu("Context Menu", self.sideView)
+ menu.addAction("Close Side View", lambda : setattr(self, 'sideViewTab', None))
+ menu.addAction("Switch side view tab", self.sideViewSwitchTab)
+ menu.addAction("Reset Zoom", lambda : setattr(self.sideView, 'zoom', 1))
+ menu.exec_(self.sideView.mapToGlobal(point))
+
+ def sideViewSwitchTab(self):
+ tabList = [f'{i}. {j.objectName()}' for i, j in enumerate(self.tabList)] + ['None (Remove)']
+ initial = self.tabList.index(self.sideViewTab)
+ result = dialogs.sideViewSwitchDialog(self.tabber, tabList, initial).exec_()
+ if result != initial:
+ self.sideViewTab = self.tabber.widget(result) if result<self.tabCount else None
+
@property
def sideViewTab(self):
#returns current active if sideViewTab otherwise None