From 0afa98cb2c6c244265dfdf9c845e595059f53224 Mon Sep 17 00:00:00 2001 From: ImLucasBrown <54835354+ImLucasBrown@users.noreply.github.com> Date: Tue, 9 Feb 2021 15:11:40 -0500 Subject: [PATCH] Py2 compatibility fixes Old Qt compatibility fixes --- nxt_editor/dockwidgets/widget_builder.py | 2 +- nxt_editor/node_graphics_item.py | 21 ++++++++++++++++----- nxt_editor/stage_view.py | 5 ++++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/nxt_editor/dockwidgets/widget_builder.py b/nxt_editor/dockwidgets/widget_builder.py index 0aaf128..79bde18 100644 --- a/nxt_editor/dockwidgets/widget_builder.py +++ b/nxt_editor/dockwidgets/widget_builder.py @@ -279,7 +279,7 @@ def update_window(self, changed_paths=None): return update = False if changed_paths else True - if not isinstance(changed_paths, collections.abc.Iterable): + if not isinstance(changed_paths, Iterable): changed_paths = [] for path in changed_paths: node_path, _ = nxt_path.path_attr_partition(path) diff --git a/nxt_editor/node_graphics_item.py b/nxt_editor/node_graphics_item.py index ca71eb3..58f160e 100644 --- a/nxt_editor/node_graphics_item.py +++ b/nxt_editor/node_graphics_item.py @@ -9,6 +9,7 @@ from Qt import QtWidgets from Qt import QtGui from Qt import QtCore +from PySide2 import __version_info__ as qt_version # Internal import nxt_editor @@ -24,8 +25,16 @@ MIN_LOD = user_prefs.get(USER_PREF.LOD, .4) +_pyside_version = qt_version -class NodeGraphicsItem(QtWidgets.QGraphicsObject): + +if _pyside_version[1] < 11: + graphic_type = QtWidgets.QGraphicsItem +else: + graphic_type = QtWidgets.QGraphicsObject + + +class NodeGraphicsItem(graphic_type): """The graphics item used to represent nodes in the graph. Contains instances of NodeGraphicsPlug for each attribute on the associated node. Contains functionality for arranging children into stacks. @@ -139,8 +148,9 @@ def anim_into_place(self, end_pos): if end_pos == self.pos(): return self.view._animating.append(self) - self.setup_in_anim() - if not self.view.do_animations: + if self.view.do_animations: + self.setup_in_anim() + else: self.setPos(end_pos) self.in_anim_group.finished.emit() return @@ -161,8 +171,9 @@ def anim_out(self): if self.get_is_animating(): return self.view._animating.append(self) - self.setup_out_anim() - if not self.view.do_animations: + if self.view.do_animations: + self.setup_out_anim() + else: self.out_anim_group.finished.emit() return self.setCacheMode(QtWidgets.QGraphicsItem.ItemCoordinateCache) diff --git a/nxt_editor/stage_view.py b/nxt_editor/stage_view.py index ce53622..b27b473 100644 --- a/nxt_editor/stage_view.py +++ b/nxt_editor/stage_view.py @@ -12,7 +12,8 @@ # Interal import nxt_editor from nxt import nxt_node, tokens -from nxt_editor.node_graphics_item import NodeGraphicsItem, NodeGraphicsPlug +from nxt_editor.node_graphics_item import (NodeGraphicsItem, NodeGraphicsPlug, + _pyside_version) from nxt_editor.connection_graphics_item import AttrConnectionGraphic from nxt_editor.commands import * from .user_dir import USER_PREF, user_prefs @@ -39,6 +40,8 @@ def __init__(self, model, parent=None): super(StageView, self).__init__(parent=parent) self.main_window = parent self._do_anim_pref = user_prefs.get(USER_PREF.ANIMATION, True) + if _pyside_version[1] < 11: + self._do_anim_pref = False self.do_animations = self._do_anim_pref self.once_sec_timer = QtCore.QTimer(self) self.once_sec_timer.timeout.connect(self.calculate_fps)