From 544fc1f7bff0b494e4e1ef1a0f1d3f0f99b71364 Mon Sep 17 00:00:00 2001 From: Hugh Sorby Date: Wed, 27 Sep 2023 17:20:06 +1300 Subject: [PATCH 1/2] Fix resizing of graphics scene for macOS. Addressed some of the Qt flags exact locations. --- src/mapclient/core/workflow/workflowscene.py | 2 +- .../view/workflow/workflowgraphicsitems.py | 77 ++++++++++--------- .../view/workflow/workflowgraphicsview.py | 60 +++++++++------ src/mapclient/view/workflow/workflowwidget.py | 24 +++--- src/setup.py | 2 +- 5 files changed, 89 insertions(+), 76 deletions(-) diff --git a/src/mapclient/core/workflow/workflowscene.py b/src/mapclient/core/workflow/workflowscene.py index a612ed27..cb763e0a 100644 --- a/src/mapclient/core/workflow/workflowscene.py +++ b/src/mapclient/core/workflow/workflowscene.py @@ -39,7 +39,7 @@ def __init__(self, manager): self._items = {} self._dependencyGraph = WorkflowDependencyGraph(self) self._main_window = None - self._view_parameters = None + self._view_parameters = {'rect': QtCore.QRectF(0, 0, 1024, 880)} def getViewParameters(self): return self._view_parameters diff --git a/src/mapclient/view/workflow/workflowgraphicsitems.py b/src/mapclient/view/workflow/workflowgraphicsitems.py index a437a6e1..24781509 100644 --- a/src/mapclient/view/workflow/workflowgraphicsitems.py +++ b/src/mapclient/view/workflow/workflowgraphicsitems.py @@ -46,7 +46,7 @@ def __init__(self, sourceNode, destNode): self._dest = weakref.ref(destNode) self._sourcePoint = QtCore.QPointF() self._destPoint = QtCore.QPointF() - self._pixmap = QtGui.QPixmap(':/workflow/images/cancel_256.png').scaled(16, 16, QtCore.Qt.KeepAspectRatio, QtCore.Qt.FastTransformation) + self._pixmap = QtGui.QPixmap(':/workflow/images/cancel_256.png').scaled(16, 16, QtCore.Qt.AspectRatioMode.KeepAspectRatio, QtCore.Qt.TransformationMode.FastTransformation) self._source().addArc(self) self._dest().addArc(self) self.setZValue(-1.5) @@ -91,7 +91,7 @@ def paint(self, painter, option, widget): if line.length() == 0.0: return - painter.setPen(QtGui.QPen(QtCore.Qt.black, 1, QtCore.Qt.DashLine, QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)) + painter.setPen(QtGui.QPen(QtCore.Qt.GlobalColor.black, 1, QtCore.Qt.PenStyle.DashLine, QtCore.Qt.PenCapStyle.RoundCap, QtCore.Qt.PenJoinStyle.RoundJoin)) painter.drawLine(line) painter.drawPixmap(midPoint.x() - 8, midPoint.y() - 8, self._pixmap) @@ -105,7 +105,7 @@ class Item(QtWidgets.QGraphicsItem): def __init__(self): QtWidgets.QGraphicsItem.__init__(self) - self.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable) + self.setFlag(QtWidgets.QGraphicsItem.GraphicsItemFlag.ItemIsSelectable) def setSelected(self, selected): QtWidgets.QGraphicsItem.setSelected(self, selected) @@ -158,9 +158,9 @@ def adjust(self): return sourceCentre = self._source().boundingRect().center() - destCentre = self._dest().boundingRect().center() + destinationCentre = self._dest().boundingRect().center() line = QtCore.QLineF(self.mapFromItem(self._source(), sourceCentre.x(), sourceCentre.y()), - self.mapFromItem(self._dest(), destCentre.x(), destCentre.y())) + self.mapFromItem(self._dest(), destinationCentre.x(), destinationCentre.y())) length = line.length() if length == 0.0: @@ -200,12 +200,13 @@ def paint(self, painter, option, widget): if line.length() == 0.0: return - brush = QtGui.QBrush(QtCore.Qt.black) - if option.state & QtWidgets.QStyle.State_Selected: # or self.selected: - painter.setBrush(QtCore.Qt.darkGray) + if option.state & QtWidgets.QStyle.StateFlag.State_Selected: # or self.selected: + painter.setBrush(QtCore.Qt.GlobalColor.darkGray) painter.drawRoundedRect(self.boundingRect(), 5, 5) # brush = QtGui.QBrush(QtCore.Qt.red) + brush_colour = QtCore.Qt.GlobalColor.black if QtGui.QStyleHints.colorScheme == QtCore.Qt.ColorScheme.Light else QtCore.Qt.GlobalColor.gray + brush = QtGui.QBrush(brush_colour) painter.setBrush(brush) angle = math.acos(line.dx() / line.length()) @@ -214,20 +215,20 @@ def paint(self, painter, option, widget): # Draw the arrows if there's enough room. if line.dy() * line.dy() + line.dx() * line.dx() > 200 * self._arrowSize: - midPoint = (self._destPoint + self._sourcePoint) / 2 + midPoint = QtCore.QPointF((self._destPoint + self._sourcePoint) / 2) - destArrowP1 = midPoint + QtCore.QPointF(math.sin(angle - Arc.Pi / 3) * self._arrowSize, - math.cos(angle - Arc.Pi / 3) * self._arrowSize) - destArrowP2 = midPoint + QtCore.QPointF(math.sin(angle - Arc.Pi + Arc.Pi / 3) * self._arrowSize, - math.cos(angle - Arc.Pi + Arc.Pi / 3) * self._arrowSize) + destination_arrow_p1 = midPoint + QtCore.QPointF(math.sin(angle - Arc.Pi / 3) * self._arrowSize, + math.cos(angle - Arc.Pi / 3) * self._arrowSize) + destination_arrow_p2 = midPoint + QtCore.QPointF(math.sin(angle - Arc.Pi + Arc.Pi / 3) * self._arrowSize, + math.cos(angle - Arc.Pi + Arc.Pi / 3) * self._arrowSize) self._arrow.clear() self._arrow.append(midPoint) - self._arrow.append(destArrowP1) - self._arrow.append(destArrowP2) + self._arrow.append(destination_arrow_p1) + self._arrow.append(destination_arrow_p2) painter.drawPolygon(self._arrow) - painter.setPen(QtGui.QPen(brush, 1, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)) + painter.setPen(QtGui.QPen(brush, 1, QtCore.Qt.PenStyle.SolidLine, QtCore.Qt.PenCapStyle.RoundCap, QtCore.Qt.PenJoinStyle.RoundJoin)) # painter.setPen(QtGui.QPen(QtCore.Qt.SolidLine)) painter.drawLine(line) @@ -248,7 +249,7 @@ def __init__(self, metastep): icon = QtGui.QImage(':/workflow/images/default_step_icon.png') self._pixmap = QtGui.QPixmap.fromImage(icon) \ - .scaled(self.Size, self.Size, QtCore.Qt.KeepAspectRatio, QtCore.Qt.FastTransformation) + .scaled(self.Size, self.Size, QtCore.Qt.AspectRatioMode.KeepAspectRatio, QtCore.Qt.TransformationMode.FastTransformation) self._step_port_items = [] self._text = StepText(metastep.getStep().getName(), self) @@ -256,8 +257,8 @@ def __init__(self, metastep): self._setToolTip() - self.setFlag(QtWidgets.QGraphicsItem.ItemIsMovable) - self.setFlag(QtWidgets.QGraphicsItem.ItemSendsGeometryChanges) + self.setFlag(QtWidgets.QGraphicsItem.GraphicsItemFlag.ItemIsMovable) + self.setFlag(QtWidgets.QGraphicsItem.GraphicsItemFlag.ItemSendsGeometryChanges) self.setCacheMode(self.CacheMode.DeviceCoordinateCache) self.setZValue(-1) @@ -430,7 +431,7 @@ def paint(self, painter, option, widget): # painter.drawPixmap(40, 40, self._configure_red) def itemChange(self, change, value): - if change == QtWidgets.QGraphicsItem.ItemPositionChange and self.scene(): + if change == QtWidgets.QGraphicsItem.GraphicsItemChange.ItemPositionChange and self.scene(): return self.scene().ensureItemInScene(self, value) elif change == QtWidgets.QGraphicsItem.ItemPositionHasChanged: for port_item in self._step_port_items: @@ -452,7 +453,7 @@ class StepPort(QtWidgets.QGraphicsEllipseItem): def __init__(self, port, parent): super(StepPort, self).__init__(0, 0, 11, 11, parent=parent) - self.setBrush(QtCore.Qt.black) + self.setBrush(QtCore.Qt.GlobalColor.black) self._port = port self._connections = [] self._pixmap = QtGui.QPixmap(':/workflow/images/icon-port.png') @@ -512,7 +513,7 @@ def removeArc(self, arc): self._connections = [weakarc for weakarc in self._connections if weakarc() != arc] def itemChange(self, change, value): - if change == QtWidgets.QGraphicsItem.ItemPositionHasChanged: + if change == QtWidgets.QGraphicsItem.GraphicsItemChange.ItemPositionHasChanged: self._removeDeadwood() for arc in self._connections: arc().adjust() @@ -525,7 +526,7 @@ class StepText(QtWidgets.QGraphicsTextItem): def __init__(self, *args): super().__init__(*args) - self._editable_flags = QtCore.Qt.TextEditable | QtCore.Qt.TextSelectableByMouse | QtCore.Qt.TextSelectableByKeyboard + self._editable_flags = QtCore.Qt.TextInteractionFlag.TextEditable | QtCore.Qt.TextInteractionFlag.TextSelectableByMouse | QtCore.Qt.TextInteractionFlag.TextSelectableByKeyboard self.setTextInteractionFlags(self._editable_flags) self._active_key = None self._make_connections() @@ -545,24 +546,24 @@ def focusOutEvent(self, event): def mousePressEvent(self, event): modifiers = QtWidgets.QApplication.keyboardModifiers() - if modifiers == QtCore.Qt.NoModifier: + if modifiers == QtCore.Qt.KeyboardModifier.NoModifier: self.setTextInteractionFlags(self._editable_flags) else: - self.setTextInteractionFlags(QtCore.Qt.NoTextInteraction) + self.setTextInteractionFlags(QtCore.Qt.TextInteractionFlag.NoTextInteraction) super().mousePressEvent(event) def keyPressEvent(self, event): self._active_key = event.key() - if self._active_key != QtCore.Qt.Key_Return and self._active_key != QtCore.Qt.Key_Enter: + if self._active_key != QtCore.Qt.Key.Key_Return and self._active_key != QtCore.Qt.Key.Key_Enter: super().keyPressEvent(event) def keyReleaseEvent(self, event): super().keyReleaseEvent(event) if self._active_key and self._active_key == event.key(): - if self._active_key == QtCore.Qt.Key_Return or self._active_key == QtCore.Qt.Key_Enter: + if self._active_key == QtCore.Qt.Key.Key_Return or self._active_key == QtCore.Qt.Key.Key_Enter: self._update_identifier() self.clearFocus() - self.setTextInteractionFlags(QtCore.Qt.NoTextInteraction) + self.setTextInteractionFlags(QtCore.Qt.TextInteractionFlag.NoTextInteraction) self._active_key = None @@ -586,7 +587,7 @@ class MercurialIcon(QtWidgets.QGraphicsItem): def __init__(self, *args, **kwargs): super(MercurialIcon, self).__init__(*args, **kwargs) self._hg_yellow = QtGui.QPixmap(':/workflow/images/modified_repo.png') \ - .scaled(24, 24, QtCore.Qt.KeepAspectRatio, QtCore.Qt.FastTransformation) + .scaled(24, 24, QtCore.Qt.AspectRatioMode.KeepAspectRatio, QtCore.Qt.TransformationMode.FastTransformation) self.setToolTip('The repository has been modified') def paint(self, painter, option, widget): @@ -608,8 +609,8 @@ class ConfigureIcon(QtWidgets.QGraphicsItem): def __init__(self, *args, **kwargs): super(ConfigureIcon, self).__init__(*args, **kwargs) self._configured = False - self._configure_green = QtGui.QPixmap(':/workflow/images/configure_green.png').scaled(24, 24, QtCore.Qt.KeepAspectRatio, QtCore.Qt.FastTransformation) - self._configure_red = QtGui.QPixmap(':/workflow/images/configure_red.png').scaled(24, 24, QtCore.Qt.KeepAspectRatio, QtCore.Qt.FastTransformation) + self._configure_green = QtGui.QPixmap(':/workflow/images/configure_green.png').scaled(24, 24, QtCore.Qt.AspectRatioMode.KeepAspectRatio, QtCore.Qt.TransformationMode.FastTransformation) + self._configure_red = QtGui.QPixmap(':/workflow/images/configure_red.png').scaled(24, 24, QtCore.Qt.AspectRatioMode.KeepAspectRatio, QtCore.Qt.TransformationMode.FastTransformation) self.setToolTip('Configure the step') def setConfigured(self, state): @@ -662,13 +663,13 @@ def paint(self, painter, option, widget): angle = Arc.TwoPi - angle # Draw the arrows if there's enough room. if line.dy() * line.dy() + line.dx() * line.dx() > 200 * self._arrowSize: - midPoint = (line.p1() + line.p2()) / 2 + midPoint = QtCore.QPointF((line.p1() + line.p2()) / 2) - destArrowP1 = midPoint + QtCore.QPointF(math.sin(angle - Arc.Pi / 3) * self._arrowSize, - math.cos(angle - Arc.Pi / 3) * self._arrowSize) - destArrowP2 = midPoint + QtCore.QPointF(math.sin(angle - Arc.Pi + Arc.Pi / 3) * self._arrowSize, - math.cos(angle - Arc.Pi + Arc.Pi / 3) * self._arrowSize) + destination_arrow_p1 = midPoint + QtCore.QPointF(math.sin(angle - Arc.Pi / 3) * self._arrowSize, + math.cos(angle - Arc.Pi / 3) * self._arrowSize) + destination_arrow_p2 = midPoint + QtCore.QPointF(math.sin(angle - Arc.Pi + Arc.Pi / 3) * self._arrowSize, + math.cos(angle - Arc.Pi + Arc.Pi / 3) * self._arrowSize) - painter.setBrush(QtCore.Qt.black) + painter.setBrush(QtCore.Qt.GlobalColor.black) # painter.drawPolygon(QtGui.QPolygonF([line.p1(), sourceArrowP1, sourceArrowP2])) - painter.drawPolygon(QtGui.QPolygonF([midPoint, destArrowP1, destArrowP2])) + painter.drawPolygon(QtGui.QPolygonF([midPoint, destination_arrow_p1, destination_arrow_p2])) diff --git a/src/mapclient/view/workflow/workflowgraphicsview.py b/src/mapclient/view/workflow/workflowgraphicsview.py index ac38ef28..fab496e6 100644 --- a/src/mapclient/view/workflow/workflowgraphicsview.py +++ b/src/mapclient/view/workflow/workflowgraphicsview.py @@ -55,11 +55,11 @@ def __init__(self, parent=None): self._selectionStartPos = None - self.setCacheMode(QtWidgets.QGraphicsView.CacheBackground) - self.setRenderHint(QtGui.QPainter.Antialiasing) + self.setCacheMode(QtWidgets.QGraphicsView.CacheModeFlag.CacheBackground) + self.setRenderHint(QtGui.QPainter.RenderHint.Antialiasing) - # self.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse) - # self.setResizeAnchor(QtGui.QGraphicsView.AnchorViewCenter) + # self.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse) + # self.setResizeAnchor(QtGui.QGraphicsView.AnchorViewCenter) self.setAcceptDrops(True) @@ -128,7 +128,7 @@ def nodeSelected(self, node, state): def keyPressEvent(self, event): QtWidgets.QGraphicsView.keyPressEvent(self, event) - if event.key() == QtCore.Qt.Key_Backspace or event.key() == QtCore.Qt.Key_Delete: + if event.key() == QtCore.Qt.Key.Key_Backspace or event.key() == QtCore.Qt.Key.Key_Delete: if self.scene().focusItem(): return @@ -136,14 +136,14 @@ def keyPressEvent(self, event): command = CommandRemove(self.scene(), self.scene().selectedItems()) self._undoStack.push(command) event.accept() - elif event.matches(QtGui.QKeySequence.Copy): + elif event.matches(QtGui.QKeySequence.StandardKey.Copy): mime_data = self.copy_steps() QtWidgets.QApplication.clipboard().setMimeData(mime_data) event.accept() - elif event.matches(QtGui.QKeySequence.Paste): + elif event.matches(QtGui.QKeySequence.StandardKey.Paste): if QtWidgets.QApplication.clipboard().mimeData().hasFormat('image/x-workflow-step(s)'): data = QtWidgets.QApplication.clipboard().mimeData().data("image/x-workflow-step(s)") - stream = QtCore.QDataStream(data, QtCore.QIODevice.ReadOnly) + stream = QtCore.QDataStream(data, QtCore.QIODevice.OpenModeFlag.ReadOnly) self.paste_steps(stream) event.accept() else: @@ -158,12 +158,12 @@ def copy_steps(self, start_pos=QtCore.QPoint(0, 0)): (or relevant) when copying items with the CTRL+C shortcut. """ data = QtCore.QByteArray() - data_stream = QtCore.QDataStream(data, QtCore.QIODevice.WriteOnly) + data_stream = QtCore.QDataStream(data, QtCore.QIODevice.OpenModeFlag.WriteOnly) # The first part of the data_stream now gives the number of steps to be copied/pasted. data_stream.writeUInt32(len(self.scene().selectedItems())) data_stream << start_pos - data_stream << QtCore.QPoint(0, 0) # Hotspot + data_stream << QtCore.QPoint(0, 0) # Hotspot for item in self.scene().selectedItems(): if item.type() == Node.Type: @@ -191,12 +191,12 @@ def copy_steps(self, start_pos=QtCore.QPoint(0, 0)): mime_data.setData('image/x-workflow-step(s)', data) return mime_data - # TODO: Paste the arrows aswell. + # TODO: Paste the arrows as well. def paste_steps(self, stream, event_position=None): """ This takes a stream of workflow items and pastes them to the workflow. See copy_steps for details on generating this stream. - The optional parameter (event_position) can be used to specify where to paste the copied steps. This argument is not relavant + The optional parameter (event_position) can be used to specify where to paste the copied steps. This argument is not relevant when pasting workflow items using the CRTL+V shortcut, as this event has no position. In the future we may want to update the CTRL+V action to consider the last workflow position the user clicked and use this to generate an event_position argument. """ @@ -214,6 +214,7 @@ def paste_steps(self, stream, event_position=None): stream >> start_pos stream >> hotspot + offset = None if event_position: offset = event_position - start_pos @@ -285,14 +286,14 @@ def setup_drag(self, start_pos): pixmap = QtGui.QPixmap() pixmap.convertFromImage(QtGui.QImage(':/workflow/images/default_step_icon.png')) - pixmap = pixmap.scaled(64, 64, QtCore.Qt.KeepAspectRatio, QtCore.Qt.FastTransformation) + pixmap = pixmap.scaled(64, 64, QtCore.Qt.AspectRatioMode.KeepAspectRatio, QtCore.Qt.TransformationMode.FastTransformation) hotspot = QtCore.QPoint(pixmap.width() / 2, pixmap.height() / 2) drag = QtGui.QDrag(self) drag.setMimeData(self.copy_steps(start_pos)) drag.setHotSpot(hotspot) drag.setPixmap(pixmap) - drag.exec(QtCore.Qt.MoveAction) + drag.exec(QtCore.Qt.DropAction.MoveAction) def contextMenuEvent(self, event): item = self.itemAt(event.pos()) @@ -302,7 +303,7 @@ def contextMenuEvent(self, event): def mousePressEvent(self, event): self._selectionStartPos = None item = self.scene().itemAt(self.mapToScene(event.pos()), QtGui.QTransform()) - if event.button() == QtCore.Qt.RightButton: + if event.button() == QtCore.Qt.MouseButton.RightButton: event.ignore() elif item and item.type() == StepPort.Type: centre = item.boundingRect().center() @@ -349,23 +350,27 @@ def _errorIconTimeout(self): del self._errorIcon def changeEvent(self, event): - if event.type() == QtCore.QEvent.EnabledChange: + if event.type() == QtCore.QEvent.Type.EnabledChange: self.invalidateScene(self.sceneRect()) def drawBackground(self, painter, rect): # Shadow. sceneRect = self.sceneRect() + shadow_colour = QtCore.Qt.GlobalColor.darkGray if QtGui.QStyleHints.colorScheme == QtCore.Qt.ColorScheme.Light else QtCore.Qt.GlobalColor.gray rightShadow = QtCore.QRectF(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height()) bottomShadow = QtCore.QRectF(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5) if rightShadow.intersects(rect) or rightShadow.contains(rect): - painter.fillRect(rightShadow, QtCore.Qt.darkGray) + painter.fillRect(rightShadow, shadow_colour) if bottomShadow.intersects(rect) or bottomShadow.contains(rect): - painter.fillRect(bottomShadow, QtCore.Qt.darkGray) + painter.fillRect(bottomShadow, shadow_colour) self._draw_grid(sceneRect, painter) def _draw_grid(self, scene_rect, painter): - self.grid_pen = QtGui.QPen(QtGui.QColor("lightblue")) + purple = '#3D2645' + french_blue = '#0075C4' + grid_colour = "lightblue" if QtGui.QStyleHints.colorScheme == QtCore.Qt.ColorScheme.Light else french_blue + self.grid_pen = QtGui.QPen(QtGui.QColor(grid_colour)) painter.setPen(self.grid_pen) top = int(scene_rect.y()) @@ -379,13 +384,14 @@ def _draw_grid(self, scene_rect, painter): for x in range(left, right, step): painter.drawLine(x, top, x, bottom) - painter.setPen(QtGui.QPen(QtGui.QColor("black"))) + rect_colour = QtGui.QColor("black") if QtGui.QStyleHints.colorScheme == QtCore.Qt.ColorScheme.Light else QtGui.QColor("white") + painter.setPen(QtGui.QPen(rect_colour)) painter.drawRect(scene_rect) def dropEvent(self, event): if event.mimeData().hasFormat("image/x-workflow-step(s)"): piece_data = event.mimeData().data("image/x-workflow-step(s)") - stream = QtCore.QDataStream(piece_data, QtCore.QIODevice.ReadOnly) + stream = QtCore.QDataStream(piece_data, QtCore.QIODevice.OpenModeFlag.ReadOnly) self.paste_steps(stream, event.pos()) event.accept() else: @@ -433,7 +439,7 @@ def set_default_id(self, step): def dragMoveEvent(self, event): QtWidgets.QGraphicsView.dragMoveEvent(self, event) if event.mimeData().hasFormat("image/x-workflow-step(s)"): - event.setDropAction(QtCore.Qt.MoveAction) + event.setDropAction(QtCore.Qt.DropAction.MoveAction) event.accept() else: event.ignore() @@ -461,7 +467,13 @@ def resizeEvent(self, event): scene.setReady() self._graphics_initialised = True - scene.setSceneRect(10, 10, (view_rect.width() - 20) / self._graphics_scale_factor, (view_rect.height() - 20) / self._graphics_scale_factor) + margin = 10 + scene.setSceneRect( + margin / self._graphics_scale_factor, + margin / self._graphics_scale_factor, + (view_rect.width() - 2 * margin) / self._graphics_scale_factor, + (view_rect.height() - 2 * margin) / self._graphics_scale_factor + ) self.reposition_steps() def _unscale_view(self, scale_factor): @@ -473,7 +485,7 @@ def _unscale_view(self, scale_factor): scene.setSceneRect(rect) def wheelEvent(self, event): - if event.modifiers() == QtCore.Qt.ControlModifier: + if event.modifiers() == QtCore.Qt.KeyboardModifier.ControlModifier: self.zoom(event.angleDelta().y()) else: super(WorkflowGraphicsView, self).wheelEvent(event) diff --git a/src/mapclient/view/workflow/workflowwidget.py b/src/mapclient/view/workflow/workflowwidget.py index 74ce04f8..849237c2 100644 --- a/src/mapclient/view/workflow/workflowwidget.py +++ b/src/mapclient/view/workflow/workflowwidget.py @@ -314,8 +314,8 @@ def open(self): filter=f"{primary_filter};;Any file (*.*)", selectedFilter=primary_filter, options=( - QtWidgets.QFileDialog.DontResolveSymlinks | - QtWidgets.QFileDialog.ReadOnly + QtWidgets.QFileDialog.Option.DontResolveSymlinks | + QtWidgets.QFileDialog.Option.ReadOnly ) )[0] @@ -323,17 +323,17 @@ def open(self): # Remove the filename to get the directory. workflow_dir = os.path.dirname(workflow_conf) - override = QtWidgets.QMessageBox.Yes + override = QtWidgets.QMessageBox.StandardButton.Yes if wm.is_restricted(workflow_dir): override = QtWidgets.QMessageBox.warning( self._main_window, 'Plugins Restricted', 'One or more of the plugins required for this workflow are already in use by another instance of the MAP Client. ' 'Unpredictable behavior may result if you attempt to run both workflows at the same time. ' 'Are you sure you want to open this workflow?', - QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, - QtWidgets.QMessageBox.No) + QtWidgets.QMessageBox.StandardButton.Yes | QtWidgets.QMessageBox.StandardButton.No, + QtWidgets.QMessageBox.StandardButton.No) - if override == QtWidgets.QMessageBox.Yes: + if override == QtWidgets.QMessageBox.StandardButton.Yes: err = self.openWorkflow(workflow_dir) if err: QtWidgets.QMessageBox.critical(self, 'Error Caught', 'Invalid Workflow. ' + err) @@ -367,8 +367,8 @@ def showDownloadableContent(self, plugins=None, dependencies=None): def installMissingPlugins(self, plugins): from mapclient.view.managers.plugins.pluginprogress import PluginProgress directory = QtWidgets.QFileDialog.getExistingDirectory(caption='Select Plugin Directory', dir='', - options=QtWidgets.QFileDialog.ShowDirsOnly | - QtWidgets.QFileDialog.DontResolveSymlinks) + options=QtWidgets.QFileDialog.Option.ShowDirsOnly | + QtWidgets.QFileDialog.Option.DontResolveSymlinks) if directory: pm = self._main_window.model().getPluginManager() pluginDirs = pm.directories() @@ -490,12 +490,12 @@ def _cloneFromPMR(self, workspace_url, workflowDir): def _load(self, workflow_dir): try: m = self._main_window.model().workflowManager() - self._ui.graphicsView.reset_zoom() - m.scene().setViewParameters(self._ui.graphicsView.getViewParameters()) + # self._ui.graphicsView.reset_zoom() + # m.scene().setViewParameters(self._ui.graphicsView.getViewParameters()) m.load(workflow_dir) m.setPreviousLocation(workflow_dir) - self._ui.graphicsView.setViewParameters(m.scene().getViewParameters()) - self._graphicsScene.setSceneRect(self._ui.graphicsView.rect()) + # self._ui.graphicsView.setViewParameters(m.scene().getViewParameters()) + # self._graphicsScene.setSceneRect(self._ui.graphicsView.rect()) self._graphicsScene.updateModel() self._ui.graphicsView.setLocation(workflow_dir) self._update_ui() diff --git a/src/setup.py b/src/setup.py index ac0fec66..4b6b3847 100644 --- a/src/setup.py +++ b/src/setup.py @@ -31,7 +31,7 @@ def find_version(*file_paths): # Define the list of requirements package_dependencies = [ - 'PySide6', + 'PySide6 >= 6.5', 'rdflib', 'virtualenv', 'requests', From 808bd06809b79a29e0f66b01edb8d9d2a9f3b277 Mon Sep 17 00:00:00 2001 From: Hugh Sorby Date: Wed, 27 Sep 2023 18:45:44 +1300 Subject: [PATCH 2/2] Add an is_light_mode helper function to detect applicaion light settings. --- src/mapclient/view/utils.py | 4 ++++ src/mapclient/view/workflow/workflowgraphicsitems.py | 3 ++- src/mapclient/view/workflow/workflowgraphicsview.py | 7 ++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/mapclient/view/utils.py b/src/mapclient/view/utils.py index 3f5687d2..8dee59e7 100644 --- a/src/mapclient/view/utils.py +++ b/src/mapclient/view/utils.py @@ -102,3 +102,7 @@ def do_runtime_error(self, *a, **kw): logger.error('{0}: {1}'.format(e.title, e.description)) ErrorDialog(e.title, e.description, self).exec() return do_runtime_error + + +def is_light_mode(): + return QtGui.QGuiApplication.styleHints().colorScheme() == QtCore.Qt.ColorScheme.Light diff --git a/src/mapclient/view/workflow/workflowgraphicsitems.py b/src/mapclient/view/workflow/workflowgraphicsitems.py index 24781509..20a83e91 100644 --- a/src/mapclient/view/workflow/workflowgraphicsitems.py +++ b/src/mapclient/view/workflow/workflowgraphicsitems.py @@ -27,6 +27,7 @@ from mapclient.core.workflow.workflowscene import Connection from mapclient.tools.annotation.annotationdialog import AnnotationDialog from mapclient.tools.pmr.pmrdvcshelper import repositoryIsUpToDate +from mapclient.view.utils import is_light_mode def _define_tooltip_for_triples(triples): @@ -205,7 +206,7 @@ def paint(self, painter, option, widget): painter.drawRoundedRect(self.boundingRect(), 5, 5) # brush = QtGui.QBrush(QtCore.Qt.red) - brush_colour = QtCore.Qt.GlobalColor.black if QtGui.QStyleHints.colorScheme == QtCore.Qt.ColorScheme.Light else QtCore.Qt.GlobalColor.gray + brush_colour = QtCore.Qt.GlobalColor.black if is_light_mode() else QtCore.Qt.GlobalColor.gray brush = QtGui.QBrush(brush_colour) painter.setBrush(brush) diff --git a/src/mapclient/view/workflow/workflowgraphicsview.py b/src/mapclient/view/workflow/workflowgraphicsview.py index fab496e6..7280e442 100644 --- a/src/mapclient/view/workflow/workflowgraphicsview.py +++ b/src/mapclient/view/workflow/workflowgraphicsview.py @@ -24,6 +24,7 @@ from mapclient.mountpoints.workflowstep import workflowStepFactory from mapclient.core.workflow.workflowscene import MetaStep +from mapclient.view.utils import is_light_mode from mapclient.view.workflow.workflowcommands import CommandSelection, CommandRemove, CommandAdd, CommandMove from mapclient.view.workflow.workflowgraphicsitems import Node, Arc, ErrorItem, ArrowLine, StepPort @@ -356,7 +357,7 @@ def changeEvent(self, event): def drawBackground(self, painter, rect): # Shadow. sceneRect = self.sceneRect() - shadow_colour = QtCore.Qt.GlobalColor.darkGray if QtGui.QStyleHints.colorScheme == QtCore.Qt.ColorScheme.Light else QtCore.Qt.GlobalColor.gray + shadow_colour = QtCore.Qt.GlobalColor.darkGray if is_light_mode() else QtCore.Qt.GlobalColor.gray rightShadow = QtCore.QRectF(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height()) bottomShadow = QtCore.QRectF(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5) if rightShadow.intersects(rect) or rightShadow.contains(rect): @@ -369,7 +370,7 @@ def drawBackground(self, painter, rect): def _draw_grid(self, scene_rect, painter): purple = '#3D2645' french_blue = '#0075C4' - grid_colour = "lightblue" if QtGui.QStyleHints.colorScheme == QtCore.Qt.ColorScheme.Light else french_blue + grid_colour = "lightblue" if is_light_mode() else french_blue self.grid_pen = QtGui.QPen(QtGui.QColor(grid_colour)) painter.setPen(self.grid_pen) @@ -384,7 +385,7 @@ def _draw_grid(self, scene_rect, painter): for x in range(left, right, step): painter.drawLine(x, top, x, bottom) - rect_colour = QtGui.QColor("black") if QtGui.QStyleHints.colorScheme == QtCore.Qt.ColorScheme.Light else QtGui.QColor("white") + rect_colour = QtGui.QColor("black") if is_light_mode() else QtGui.QColor("white") painter.setPen(QtGui.QPen(rect_colour)) painter.drawRect(scene_rect)