diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/python/utils/dialogs.py | 27 | ||||
-rw-r--r-- | src/main/python/utils/fileWindow.py | 20 | ||||
-rw-r--r-- | src/main/python/utils/graphics.py | 21 |
3 files changed, 36 insertions, 32 deletions
diff --git a/src/main/python/utils/dialogs.py b/src/main/python/utils/dialogs.py index 8ab8f6f..4351f16 100644 --- a/src/main/python/utils/dialogs.py +++ b/src/main/python/utils/dialogs.py @@ -10,8 +10,8 @@ class paperDims(QDialog): super(paperDims, self).__init__(parent) #store initial values to show currently set value, also updated when changed. these are returned at EOL - self._canvasSize = size - self._ppi = ppi + self.returnCanvasSize = size + self.returnCanvasPPI = ppi self.setWindowTitle(name+" :Canvas Size") #Set Window Title #init layout @@ -20,19 +20,19 @@ class paperDims(QDialog): sizeComboBox = QComboBox() #combo box for paper sizes sizeComboBox.addItems(sheetDimensionList) sizeComboBox.setCurrentIndex(4) - sizeComboBox.activated[str].connect(self.setCanvasSize) + sizeComboBox.activated[str].connect(lambda size: setattr(self, "returnCanvasSize", size)) sizeLabel = QLabel("Canvas Size") sizeLabel.setBuddy(sizeComboBox) # label for the above combo box - sizeComboBox.setCurrentIndex(sheetDimensionList.index(self._canvasSize)) #set index to current value of canvas + sizeComboBox.setCurrentIndex(sheetDimensionList.index(self.returnCanvasSize)) #set index to current value of canvas dialogBoxLayout.setWidget(0, QFormLayout.LabelRole, sizeLabel) dialogBoxLayout.setWidget(0, QFormLayout.FieldRole, sizeComboBox) ppiComboBox = QComboBox() #combo box for ppis ppiComboBox.addItems(ppiList) - ppiComboBox.activated[str].connect(self.setCanvasPPI) + ppiComboBox.activated[str].connect(lambda ppi: setattr(self, "returnCanvasPPI", ppi)) ppiLabel = QLabel("Canvas ppi") ppiLabel.setBuddy(ppiComboBox) # label for the above combo box - ppiComboBox.setCurrentIndex(ppiList.index(self._ppi)) #set index to current value of canvas + ppiComboBox.setCurrentIndex(ppiList.index(self.returnCanvasPPI)) #set index to current value of canvas dialogBoxLayout.setWidget(1, QFormLayout.LabelRole, ppiLabel) dialogBoxLayout.setWidget(1, QFormLayout.FieldRole, ppiComboBox) @@ -44,24 +44,19 @@ class paperDims(QDialog): dialogBoxLayout.addWidget(buttonBox) self.setLayout(dialogBoxLayout) self.resize(300,100) #resize to a certain size - - def setCanvasSize(self, size): - #for standard combo box behaviour - self._canvasSize = size - - def setCanvasPPI(self, ppi): - #for standard combo box behaviour - self._ppi = ppi def exec_(self): #overload exec_ to add return values and delete itself(currently being tested) super(paperDims, self).exec_() self.deleteLater() #remove from memory #if ok was pressed return value else return None - return (self._canvasSize, self._ppi) if self.result() else None + return (self.returnCanvasSize, self.returnCanvasPPI) if self.result() else None class sideViewSwitchDialog(QDialog): - + """ + Custom dialog box to show, all available tabs to set the side view to. + Also has accept reject events. Structure is similar to paperDims dialog box. + """ def __init__(self, parent=None, tabList = None, initial = None): super(sideViewSwitchDialog, self).__init__(parent=parent) self.tabList = tabList diff --git a/src/main/python/utils/fileWindow.py b/src/main/python/utils/fileWindow.py index 0230cd2..e549568 100644 --- a/src/main/python/utils/fileWindow.py +++ b/src/main/python/utils/fileWindow.py @@ -145,35 +145,37 @@ class fileWindow(QMdiSubWindow): return False def moveSideViewCloseButton(self): - # x = self.rect().width()//2 - 5 - # if self.sideView.verticalScrollBar().isVisible(): - # x -= self.style().pixelMetric(QStyle.PM_ScrollBarExtent) - # self.sideViewCloseButton.move(x, 5) + # used to place side view close button at appropriate position self.sideViewCloseButton.move(5, 5) def sideViewContextMenu(self, point): + # context menu for side view menu = QMenu("Context Menu", self.sideView) menu.addAction("Reset Zoom", lambda : setattr(self.sideView, 'zoom', 1)) menu.addSection('Change Side View Tab') if self.tabCount > 5: + # just show switch dialog box, if there are 6 or more tabs open menu.addAction("Show switch menu", self.sideViewSwitchTab) else: + # enumerate all tabs from side view. for i in range(self.tabCount): j = self.tabber.widget(i) - if j == self.sideViewTab: + if j == self.sideViewTab: continue + # evaluate i as index, weird lambda behaviour + #see https://stackoverflow.com/a/33984811/7799568 menu.addAction(f'{i}. {j.objectName()}', lambda index=i: self.sideViewSwitchCMenu(index)) menu.addAction("Remove side view", lambda : setattr(self, 'sideViewTab', None)) menu.exec_(self.sideView.mapToGlobal(point)) def sideViewSwitchCMenu(self, index): - print(index) self.sideViewTab = self.tabber.widget(index) def sideViewSwitchTab(self): - tabList = [f'{i}. {j.objectName()}' for i, j in enumerate(self.tabList)] - initial = self.tabList.index(self.sideViewTab) - result = dialogs.sideViewSwitchDialog(self.tabber, tabList, initial).exec_() + # displays a side view switch dialog box + tabList = [f'{i}. {j.objectName()}' for i, j in enumerate(self.tabList)] #names and index of all tabs + initial = self.tabList.index(self.sideViewTab) # current side view tab + result = dialogs.sideViewSwitchDialog(self.tabber, tabList, initial).exec_() #call dialog box if result != initial: self.sideViewTab = self.tabber.widget(result) if result<self.tabCount else None diff --git a/src/main/python/utils/graphics.py b/src/main/python/utils/graphics.py index 8c87b96..4d754b5 100644 --- a/src/main/python/utils/graphics.py +++ b/src/main/python/utils/graphics.py @@ -2,9 +2,11 @@ from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QGraphicsView class customView(QGraphicsView): - + """ + Defines custom QGraphicsView with zoom features, overriding wheel event + """ def __init__(self, scene = None, parent=None): - if scene is not None: + if scene is not None: #overloaded constructor super(customView, self).__init__(scene, parent) else: super(customView, self).__init__(parent) @@ -12,23 +14,28 @@ class customView(QGraphicsView): self.setDragMode(True) def wheelEvent(self, QWheelEvent): - if Qt.ControlModifier: - if QWheelEvent.source() == Qt.MouseEventNotSynthesized: - if self.zoom + QWheelEvent.angleDelta().y()/2880 > 0.1: + #overload wheelevent, to zoom if control is pressed, else scroll normally + if Qt.ControlModifier: #check if control is pressed + if QWheelEvent.source() == Qt.MouseEventNotSynthesized: #check if precision mouse(mac) + # angle delta is 1/8th of a degree per scroll unit + if self.zoom + QWheelEvent.angleDelta().y()/2880 > 0.1: # hit and trial value (2880) self.zoom += QWheelEvent.angleDelta().y()/2880 else: + # precision delta is exactly equal to amount to scroll if self.zoom + QWheelEvent.pixelDelta().y() > 0.1: self.zoom += QWheelEvent.angleDelta().y() - QWheelEvent.accept() + QWheelEvent.accept() # accept event so that scrolling doesnt happen simultaneously else: - return super().wheelEvent(self, QWheelEvent) + return super().wheelEvent(self, QWheelEvent) # scroll if ctrl not pressed @property def zoom(self): + # property for zoom return self._zoom @zoom.setter def zoom(self, value): + # set scale according to zoom value being set temp = self.zoom self._zoom = value self.scale(self.zoom / temp, self.zoom / temp)
\ No newline at end of file |