From 790bb55bdf1505b04502d2d523dbdd9da930081f Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Wed, 26 Apr 2023 17:49:34 +0200 Subject: [PATCH 1/5] Fixed the version attribute --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 3ab39fe7..7f815745 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = NodeGraphQt -version=attr: my_package.__version__ +version=attr: NodeGraphQt.VERSION author=Johnny Chan license = MIT License license_files = LICENSE.md From b2e0ee94f6e85a02af776e8d1f17c3299a830e2a Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Wed, 26 Apr 2023 17:59:40 +0200 Subject: [PATCH 2/5] changed the dependencies --- setup.cfg | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/setup.cfg b/setup.cfg index 7f815745..d59bd533 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,11 +6,11 @@ license = MIT License license_files = LICENSE.md long_description = file: README.md long_description_content_type = text/markdown -description = Node graph framework for PySide2/PyQt5 that can be +description = Node graph framework for PySide2/PyQt5/Pyside6/PyQt6 that can be implemented and re-purposed into applications. classifiers = Operating System :: OS Independent License :: OSI Approved :: MIT License - Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.8 url = https://github.com/jchanvfx/NodeGraphQt project_urls = Documentation = https://jchanvfx.github.io/NodeGraphQt/api/html/index.html @@ -20,12 +20,12 @@ project_urls = [options] packages = find: include_package_data = True -python_requires = >=3.6 +python_requires = >=3.8 install_requires = - Qt.py>=1.2.0 + qtpy>=2.3.1 [options.extras_require] -PySide2 = PySide2>=5.15 +PySide6 = PySide6>=6.5.0 [options.packages.find] exclude = examples From 41dc0411a70104ddfefd7db1001ddc35ccff2de7 Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Wed, 26 Apr 2023 21:20:35 +0200 Subject: [PATCH 3/5] Added a script to convert the Qt wrapper from Qt.py to qtpy --- dev/convert_qt_wrapper.py | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 dev/convert_qt_wrapper.py diff --git a/dev/convert_qt_wrapper.py b/dev/convert_qt_wrapper.py new file mode 100644 index 00000000..baea704c --- /dev/null +++ b/dev/convert_qt_wrapper.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python +import os +import logging +import tempfile +from typing import Iterator + + +def get_base_dir() -> str: + cur_path = os.path.dirname(__file__) + base_path = os.path.realpath(os.path.join(cur_path, "..")) + return base_path + +def replace_in_file(fpath: str, old_str: str, new_str: str) -> None: + _tfd, tpath = tempfile.mkstemp() + with open(fpath, "r") as fd, os.fdopen(_tfd, "w") as tfd: + for fline in fd: + tline = fline.replace(old_str, new_str) + tfd.write(tline) + os.unlink(fpath) + os.rename(tpath, fpath) + +def get_source_files(root: str) -> Iterator[str]: + cpath = os.path.realpath(__file__) + for dname, dirs, files in os.walk(root): + for fname in files: + fpath = os.path.realpath(os.path.join(dname, fname)) + valid_file = fpath.endswith(".py") + valid_file &= fpath != cpath + if not valid_file: + continue + yield fpath + + +if __name__ == "__main__": + base_dir = get_base_dir() + for src_dir in ["examples", "NodeGraphQt"]: + source_dir = os.path.join(base_dir, src_dir) + for source_file in get_source_files(source_dir): + logging.debug("Processing %s", source_file) + replace_in_file(source_file, "from Qt", "from qtpy") + replace_in_file(source_file, "import Qt,", "import qtpy,") + replace_in_file(source_file, "import Qt\n", "import qtpy\n") From f9e405e9c1788a3cf50d88c4716cede85b020a72 Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Wed, 26 Apr 2023 21:22:53 +0200 Subject: [PATCH 4/5] Ran the conversion script --- NodeGraphQt/base/commands.py | 2 +- NodeGraphQt/base/graph.py | 2 +- NodeGraphQt/base/menu.py | 2 +- NodeGraphQt/constants.py | 2 +- NodeGraphQt/custom_widgets/nodes_palette.py | 2 +- NodeGraphQt/custom_widgets/nodes_tree.py | 2 +- .../properties_bin/custom_widget_color_picker.py | 2 +- .../custom_widgets/properties_bin/custom_widget_file_paths.py | 2 +- .../custom_widgets/properties_bin/custom_widget_slider.py | 2 +- .../custom_widgets/properties_bin/custom_widget_value_edit.py | 2 +- .../custom_widgets/properties_bin/custom_widget_vectors.py | 2 +- .../custom_widgets/properties_bin/node_property_widgets.py | 2 +- .../custom_widgets/properties_bin/prop_widgets_abstract.py | 2 +- .../custom_widgets/properties_bin/prop_widgets_base.py | 2 +- NodeGraphQt/qgraphics/node_abstract.py | 2 +- NodeGraphQt/qgraphics/node_backdrop.py | 2 +- NodeGraphQt/qgraphics/node_base.py | 2 +- NodeGraphQt/qgraphics/node_circle.py | 2 +- NodeGraphQt/qgraphics/node_group.py | 2 +- NodeGraphQt/qgraphics/node_overlay_disabled.py | 2 +- NodeGraphQt/qgraphics/node_port_in.py | 2 +- NodeGraphQt/qgraphics/node_port_out.py | 2 +- NodeGraphQt/qgraphics/node_text_item.py | 2 +- NodeGraphQt/qgraphics/pipe.py | 2 +- NodeGraphQt/qgraphics/port.py | 2 +- NodeGraphQt/qgraphics/slicer.py | 2 +- NodeGraphQt/widgets/actions.py | 2 +- NodeGraphQt/widgets/dialogs.py | 2 +- NodeGraphQt/widgets/node_graph.py | 2 +- NodeGraphQt/widgets/node_widgets.py | 2 +- NodeGraphQt/widgets/scene.py | 2 +- NodeGraphQt/widgets/tab_search.py | 2 +- NodeGraphQt/widgets/viewer.py | 4 ++-- NodeGraphQt/widgets/viewer_nav.py | 2 +- examples/basic_example.py | 2 +- examples/nodes/custom_ports_node.py | 2 +- 36 files changed, 37 insertions(+), 37 deletions(-) diff --git a/NodeGraphQt/base/commands.py b/NodeGraphQt/base/commands.py index 360150d5..a82c9bc9 100644 --- a/NodeGraphQt/base/commands.py +++ b/NodeGraphQt/base/commands.py @@ -1,5 +1,5 @@ #!/usr/bin/python -from Qt import QtWidgets +from qtpy import QtWidgets from NodeGraphQt.constants import PortTypeEnum diff --git a/NodeGraphQt/base/graph.py b/NodeGraphQt/base/graph.py index b7a3faf5..94433c85 100644 --- a/NodeGraphQt/base/graph.py +++ b/NodeGraphQt/base/graph.py @@ -5,7 +5,7 @@ import os import re -from Qt import QtCore, QtWidgets +from qtpy import QtCore, QtWidgets from NodeGraphQt.base.commands import (NodeAddedCmd, NodeRemovedCmd, diff --git a/NodeGraphQt/base/menu.py b/NodeGraphQt/base/menu.py index d3a2f982..18d629dd 100644 --- a/NodeGraphQt/base/menu.py +++ b/NodeGraphQt/base/menu.py @@ -2,7 +2,7 @@ import re from distutils.version import LooseVersion -from Qt import QtGui, QtCore +from qtpy import QtGui, QtCore from NodeGraphQt.errors import NodeMenuError from NodeGraphQt.widgets.actions import BaseMenu, GraphAction, NodeAction diff --git a/NodeGraphQt/constants.py b/NodeGraphQt/constants.py index 781cfca1..e9e9d59a 100644 --- a/NodeGraphQt/constants.py +++ b/NodeGraphQt/constants.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- import os -from Qt import QtWidgets +from qtpy import QtWidgets from enum import Enum from .pkg_info import __version__ as _v diff --git a/NodeGraphQt/custom_widgets/nodes_palette.py b/NodeGraphQt/custom_widgets/nodes_palette.py index 91a94f28..870231ff 100644 --- a/NodeGraphQt/custom_widgets/nodes_palette.py +++ b/NodeGraphQt/custom_widgets/nodes_palette.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- from collections import defaultdict -from Qt import QtWidgets, QtCore, QtGui +from qtpy import QtWidgets, QtCore, QtGui from NodeGraphQt.constants import URN_SCHEME diff --git a/NodeGraphQt/custom_widgets/nodes_tree.py b/NodeGraphQt/custom_widgets/nodes_tree.py index 709e90a7..2a966269 100644 --- a/NodeGraphQt/custom_widgets/nodes_tree.py +++ b/NodeGraphQt/custom_widgets/nodes_tree.py @@ -1,6 +1,6 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -from Qt import QtWidgets, QtCore, QtGui +from qtpy import QtWidgets, QtCore, QtGui from NodeGraphQt.constants import URN_SCHEME diff --git a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_color_picker.py b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_color_picker.py index 79d0813b..a2549ad0 100644 --- a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_color_picker.py +++ b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_color_picker.py @@ -1,5 +1,5 @@ #!/usr/bin/python -from Qt import QtWidgets, QtCore, QtGui +from qtpy import QtWidgets, QtCore, QtGui from .custom_widget_vectors import PropVector3, PropVector4 from .prop_widgets_abstract import BaseProperty diff --git a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_file_paths.py b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_file_paths.py index 51b811ee..1a0c0e19 100644 --- a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_file_paths.py +++ b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_file_paths.py @@ -1,5 +1,5 @@ #!/usr/bin/python -from Qt import QtWidgets, QtCore +from qtpy import QtWidgets, QtCore from NodeGraphQt.widgets.dialogs import FileDialog from .prop_widgets_abstract import BaseProperty diff --git a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_slider.py b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_slider.py index 66193ed2..66ef5985 100644 --- a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_slider.py +++ b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_slider.py @@ -1,5 +1,5 @@ #!/usr/bin/python -from Qt import QtWidgets, QtCore +from qtpy import QtWidgets, QtCore from .prop_widgets_abstract import BaseProperty diff --git a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_value_edit.py b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_value_edit.py index 157c55d7..5dc27d34 100644 --- a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_value_edit.py +++ b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_value_edit.py @@ -1,5 +1,5 @@ #!/usr/bin/python -from Qt import QtWidgets, QtCore, QtGui +from qtpy import QtWidgets, QtCore, QtGui class _NumberValueMenu(QtWidgets.QMenu): diff --git a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_vectors.py b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_vectors.py index e29a6a5b..f0e1d6ff 100644 --- a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_vectors.py +++ b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_vectors.py @@ -1,5 +1,5 @@ #!/usr/bin/python -from Qt import QtWidgets +from qtpy import QtWidgets from .custom_widget_value_edit import _NumberValueEdit from .prop_widgets_abstract import BaseProperty diff --git a/NodeGraphQt/custom_widgets/properties_bin/node_property_widgets.py b/NodeGraphQt/custom_widgets/properties_bin/node_property_widgets.py index 2923e26b..a300f3e3 100644 --- a/NodeGraphQt/custom_widgets/properties_bin/node_property_widgets.py +++ b/NodeGraphQt/custom_widgets/properties_bin/node_property_widgets.py @@ -1,7 +1,7 @@ #!/usr/bin/python from collections import defaultdict -from Qt import QtWidgets, QtCore, QtGui, QtCompat +from qtpy import QtWidgets, QtCore, QtGui, QtCompat from .node_property_factory import NodePropertyWidgetFactory from .prop_widgets_base import PropLineEdit diff --git a/NodeGraphQt/custom_widgets/properties_bin/prop_widgets_abstract.py b/NodeGraphQt/custom_widgets/properties_bin/prop_widgets_abstract.py index 86974647..e35e469e 100644 --- a/NodeGraphQt/custom_widgets/properties_bin/prop_widgets_abstract.py +++ b/NodeGraphQt/custom_widgets/properties_bin/prop_widgets_abstract.py @@ -1,5 +1,5 @@ #!/usr/bin/python -from Qt import QtWidgets, QtCore +from qtpy import QtWidgets, QtCore class BaseProperty(QtWidgets.QWidget): diff --git a/NodeGraphQt/custom_widgets/properties_bin/prop_widgets_base.py b/NodeGraphQt/custom_widgets/properties_bin/prop_widgets_base.py index 040458c5..b57c00a5 100644 --- a/NodeGraphQt/custom_widgets/properties_bin/prop_widgets_base.py +++ b/NodeGraphQt/custom_widgets/properties_bin/prop_widgets_base.py @@ -1,5 +1,5 @@ #!/usr/bin/python -from Qt import QtWidgets, QtCore +from qtpy import QtWidgets, QtCore class PropLabel(QtWidgets.QLabel): diff --git a/NodeGraphQt/qgraphics/node_abstract.py b/NodeGraphQt/qgraphics/node_abstract.py index 29dfcf18..f764f60a 100644 --- a/NodeGraphQt/qgraphics/node_abstract.py +++ b/NodeGraphQt/qgraphics/node_abstract.py @@ -1,5 +1,5 @@ #!/usr/bin/python -from Qt import QtCore, QtWidgets +from qtpy import QtCore, QtWidgets from NodeGraphQt.constants import ( Z_VAL_NODE, diff --git a/NodeGraphQt/qgraphics/node_backdrop.py b/NodeGraphQt/qgraphics/node_backdrop.py index 4e806653..44c08a84 100644 --- a/NodeGraphQt/qgraphics/node_backdrop.py +++ b/NodeGraphQt/qgraphics/node_backdrop.py @@ -1,5 +1,5 @@ #!/usr/bin/python -from Qt import QtGui, QtCore, QtWidgets +from qtpy import QtGui, QtCore, QtWidgets from NodeGraphQt.constants import Z_VAL_PIPE, NodeEnum from NodeGraphQt.qgraphics.node_abstract import AbstractNodeItem diff --git a/NodeGraphQt/qgraphics/node_base.py b/NodeGraphQt/qgraphics/node_base.py index 9886f67f..ffb8661b 100644 --- a/NodeGraphQt/qgraphics/node_base.py +++ b/NodeGraphQt/qgraphics/node_base.py @@ -1,7 +1,7 @@ #!/usr/bin/python from collections import OrderedDict -from Qt import QtGui, QtCore, QtWidgets +from qtpy import QtGui, QtCore, QtWidgets from NodeGraphQt.constants import ( ITEM_CACHE_MODE, diff --git a/NodeGraphQt/qgraphics/node_circle.py b/NodeGraphQt/qgraphics/node_circle.py index 07bb0c7e..c0ab37db 100644 --- a/NodeGraphQt/qgraphics/node_circle.py +++ b/NodeGraphQt/qgraphics/node_circle.py @@ -1,5 +1,5 @@ #!/usr/bin/python -from Qt import QtCore, QtGui, QtWidgets +from qtpy import QtCore, QtGui, QtWidgets from NodeGraphQt.constants import NodeEnum, PortEnum from NodeGraphQt.qgraphics.node_base import NodeItem diff --git a/NodeGraphQt/qgraphics/node_group.py b/NodeGraphQt/qgraphics/node_group.py index 5b6a69e0..b4dd6674 100644 --- a/NodeGraphQt/qgraphics/node_group.py +++ b/NodeGraphQt/qgraphics/node_group.py @@ -1,5 +1,5 @@ #!/usr/bin/python -from Qt import QtCore, QtGui, QtWidgets +from qtpy import QtCore, QtGui, QtWidgets from NodeGraphQt.constants import NodeEnum, PortEnum from NodeGraphQt.qgraphics.node_base import NodeItem diff --git a/NodeGraphQt/qgraphics/node_overlay_disabled.py b/NodeGraphQt/qgraphics/node_overlay_disabled.py index da944b0e..2fe7bd0e 100644 --- a/NodeGraphQt/qgraphics/node_overlay_disabled.py +++ b/NodeGraphQt/qgraphics/node_overlay_disabled.py @@ -1,5 +1,5 @@ #!/usr/bin/python -from Qt import QtGui, QtCore, QtWidgets +from qtpy import QtGui, QtCore, QtWidgets from NodeGraphQt.constants import Z_VAL_NODE_WIDGET diff --git a/NodeGraphQt/qgraphics/node_port_in.py b/NodeGraphQt/qgraphics/node_port_in.py index b5c23618..56c156c5 100644 --- a/NodeGraphQt/qgraphics/node_port_in.py +++ b/NodeGraphQt/qgraphics/node_port_in.py @@ -1,5 +1,5 @@ #!/usr/bin/python -from Qt import QtCore, QtGui, QtWidgets +from qtpy import QtCore, QtGui, QtWidgets from NodeGraphQt.constants import NodeEnum from NodeGraphQt.qgraphics.node_base import NodeItem diff --git a/NodeGraphQt/qgraphics/node_port_out.py b/NodeGraphQt/qgraphics/node_port_out.py index 733b0043..808fe6bf 100644 --- a/NodeGraphQt/qgraphics/node_port_out.py +++ b/NodeGraphQt/qgraphics/node_port_out.py @@ -1,5 +1,5 @@ #!/usr/bin/python -from Qt import QtCore, QtGui, QtWidgets +from qtpy import QtCore, QtGui, QtWidgets from NodeGraphQt.constants import NodeEnum from NodeGraphQt.qgraphics.node_base import NodeItem diff --git a/NodeGraphQt/qgraphics/node_text_item.py b/NodeGraphQt/qgraphics/node_text_item.py index 4f02a242..bde3c125 100644 --- a/NodeGraphQt/qgraphics/node_text_item.py +++ b/NodeGraphQt/qgraphics/node_text_item.py @@ -1,4 +1,4 @@ -from Qt import QtWidgets, QtCore, QtGui +from qtpy import QtWidgets, QtCore, QtGui class NodeTextItem(QtWidgets.QGraphicsTextItem): diff --git a/NodeGraphQt/qgraphics/pipe.py b/NodeGraphQt/qgraphics/pipe.py index ec5e7b48..852c795f 100644 --- a/NodeGraphQt/qgraphics/pipe.py +++ b/NodeGraphQt/qgraphics/pipe.py @@ -1,7 +1,7 @@ #!/usr/bin/python import math -from Qt import QtCore, QtGui, QtWidgets +from qtpy import QtCore, QtGui, QtWidgets from NodeGraphQt.constants import ( LayoutDirectionEnum, diff --git a/NodeGraphQt/qgraphics/port.py b/NodeGraphQt/qgraphics/port.py index 78c8a0ad..64637d4f 100644 --- a/NodeGraphQt/qgraphics/port.py +++ b/NodeGraphQt/qgraphics/port.py @@ -1,5 +1,5 @@ #!/usr/bin/python -from Qt import QtGui, QtCore, QtWidgets +from qtpy import QtGui, QtCore, QtWidgets from NodeGraphQt.constants import ( PortTypeEnum, PortEnum, diff --git a/NodeGraphQt/qgraphics/slicer.py b/NodeGraphQt/qgraphics/slicer.py index 08282840..520925f4 100644 --- a/NodeGraphQt/qgraphics/slicer.py +++ b/NodeGraphQt/qgraphics/slicer.py @@ -1,7 +1,7 @@ #!/usr/bin/python import math -from Qt import QtCore, QtGui, QtWidgets +from qtpy import QtCore, QtGui, QtWidgets from NodeGraphQt.constants import Z_VAL_NODE_WIDGET, PipeSlicerEnum diff --git a/NodeGraphQt/widgets/actions.py b/NodeGraphQt/widgets/actions.py index 4af371eb..bf306c30 100644 --- a/NodeGraphQt/widgets/actions.py +++ b/NodeGraphQt/widgets/actions.py @@ -1,5 +1,5 @@ #!/usr/bin/python -from Qt import QtCore, QtWidgets +from qtpy import QtCore, QtWidgets from NodeGraphQt.constants import ViewerEnum diff --git a/NodeGraphQt/widgets/dialogs.py b/NodeGraphQt/widgets/dialogs.py index fd88d95a..42a11f56 100644 --- a/NodeGraphQt/widgets/dialogs.py +++ b/NodeGraphQt/widgets/dialogs.py @@ -1,6 +1,6 @@ import os -from Qt import QtWidgets +from qtpy import QtWidgets _current_user_directory = os.path.expanduser('~') diff --git a/NodeGraphQt/widgets/node_graph.py b/NodeGraphQt/widgets/node_graph.py index 435cb836..36c2a7a5 100644 --- a/NodeGraphQt/widgets/node_graph.py +++ b/NodeGraphQt/widgets/node_graph.py @@ -1,4 +1,4 @@ -from Qt import QtWidgets, QtGui +from qtpy import QtWidgets, QtGui from NodeGraphQt.constants import ( NodeEnum, ViewerEnum, ViewerNavEnum diff --git a/NodeGraphQt/widgets/node_widgets.py b/NodeGraphQt/widgets/node_widgets.py index a494bfaa..05f1ecde 100644 --- a/NodeGraphQt/widgets/node_widgets.py +++ b/NodeGraphQt/widgets/node_widgets.py @@ -1,5 +1,5 @@ #!/usr/bin/python -from Qt import QtCore, QtWidgets +from qtpy import QtCore, QtWidgets from NodeGraphQt.constants import ViewerEnum, Z_VAL_NODE_WIDGET from NodeGraphQt.errors import NodeWidgetError diff --git a/NodeGraphQt/widgets/scene.py b/NodeGraphQt/widgets/scene.py index 91e7ccfa..706a3582 100644 --- a/NodeGraphQt/widgets/scene.py +++ b/NodeGraphQt/widgets/scene.py @@ -1,5 +1,5 @@ #!/usr/bin/python -from Qt import QtGui, QtCore, QtWidgets +from qtpy import QtGui, QtCore, QtWidgets from NodeGraphQt.constants import ViewerEnum diff --git a/NodeGraphQt/widgets/tab_search.py b/NodeGraphQt/widgets/tab_search.py index 477342f8..662a6474 100644 --- a/NodeGraphQt/widgets/tab_search.py +++ b/NodeGraphQt/widgets/tab_search.py @@ -2,7 +2,7 @@ import re from collections import OrderedDict -from Qt import QtCore, QtWidgets, QtGui +from qtpy import QtCore, QtWidgets, QtGui from NodeGraphQt.constants import ViewerEnum, ViewerNavEnum diff --git a/NodeGraphQt/widgets/viewer.py b/NodeGraphQt/widgets/viewer.py index bd18d7f3..13e79fdc 100644 --- a/NodeGraphQt/widgets/viewer.py +++ b/NodeGraphQt/widgets/viewer.py @@ -3,7 +3,7 @@ import math from distutils.version import LooseVersion -from Qt import QtGui, QtCore, QtWidgets +from qtpy import QtGui, QtCore, QtWidgets from NodeGraphQt.base.menu import BaseMenu from NodeGraphQt.constants import ( @@ -1358,7 +1358,7 @@ def use_OpenGL(self): """ # use QOpenGLWidget instead of the deprecated QGLWidget to avoid # problems with Wayland. - import Qt + import qtpy if Qt.IsPySide2: from PySide2.QtWidgets import QOpenGLWidget elif Qt.IsPyQt5: diff --git a/NodeGraphQt/widgets/viewer_nav.py b/NodeGraphQt/widgets/viewer_nav.py index e308eb1c..2c9fe112 100644 --- a/NodeGraphQt/widgets/viewer_nav.py +++ b/NodeGraphQt/widgets/viewer_nav.py @@ -1,4 +1,4 @@ -from Qt import QtWidgets, QtCore, QtGui +from qtpy import QtWidgets, QtCore, QtGui from NodeGraphQt.constants import NodeEnum, ViewerNavEnum diff --git a/examples/basic_example.py b/examples/basic_example.py index 0a82d5ef..025d905e 100644 --- a/examples/basic_example.py +++ b/examples/basic_example.py @@ -3,7 +3,7 @@ import os import signal -from Qt import QtCore, QtWidgets +from qtpy import QtCore, QtWidgets from NodeGraphQt import ( NodeGraph, diff --git a/examples/nodes/custom_ports_node.py b/examples/nodes/custom_ports_node.py index 23befb01..a2c7b9e4 100644 --- a/examples/nodes/custom_ports_node.py +++ b/examples/nodes/custom_ports_node.py @@ -1,5 +1,5 @@ #!/usr/bin/python -from Qt import QtCore, QtGui +from qtpy import QtCore, QtGui from NodeGraphQt import BaseNode From 7af9c976d5d5a7feb8988396d7f9aebb1ebac676 Mon Sep 17 00:00:00 2001 From: Jorrit Wronski Date: Wed, 26 Apr 2023 23:27:05 +0200 Subject: [PATCH 5/5] Made some more manual changes for qtpy compatibility. some of them may not be backwards-compatible. the regular expression handling has also been modified and needs to be validated. --- NodeGraphQt/base/graph.py | 6 +- NodeGraphQt/base/menu.py | 4 +- NodeGraphQt/custom_widgets/nodes_palette.py | 22 +++--- NodeGraphQt/custom_widgets/nodes_tree.py | 6 +- .../custom_widget_color_picker.py | 8 +- .../custom_widget_file_paths.py | 2 +- .../properties_bin/custom_widget_slider.py | 10 +-- .../custom_widget_value_edit.py | 6 +- .../properties_bin/node_property_widgets.py | 26 +++---- .../properties_bin/prop_widgets_base.py | 6 +- NodeGraphQt/qgraphics/node_abstract.py | 2 +- NodeGraphQt/qgraphics/node_backdrop.py | 38 +++++----- NodeGraphQt/qgraphics/node_base.py | 26 +++---- NodeGraphQt/qgraphics/node_circle.py | 18 ++--- NodeGraphQt/qgraphics/node_group.py | 32 ++++---- .../qgraphics/node_overlay_disabled.py | 2 +- NodeGraphQt/qgraphics/node_port_in.py | 12 +-- NodeGraphQt/qgraphics/node_port_out.py | 12 +-- NodeGraphQt/qgraphics/node_text_item.py | 18 ++--- NodeGraphQt/qgraphics/pipe.py | 28 +++---- NodeGraphQt/qgraphics/port.py | 6 +- NodeGraphQt/qgraphics/slicer.py | 10 +-- NodeGraphQt/widgets/node_widgets.py | 4 +- NodeGraphQt/widgets/scene.py | 6 +- NodeGraphQt/widgets/tab_search.py | 21 +++--- NodeGraphQt/widgets/viewer.py | 75 ++++++++++--------- NodeGraphQt/widgets/viewer_nav.py | 12 +-- 27 files changed, 214 insertions(+), 204 deletions(-) diff --git a/NodeGraphQt/base/graph.py b/NodeGraphQt/base/graph.py index 94433c85..c0d415af 100644 --- a/NodeGraphQt/base/graph.py +++ b/NodeGraphQt/base/graph.py @@ -5,7 +5,7 @@ import os import re -from qtpy import QtCore, QtWidgets +from qtpy import QtCore, QtWidgets, QtGui from NodeGraphQt.base.commands import (NodeAddedCmd, NodeRemovedCmd, @@ -150,7 +150,7 @@ def __init__(self, parent=None, **kwargs): self._undo_view = None self._undo_stack = ( - kwargs.get('undo_stack') or QtWidgets.QUndoStack(self)) + kwargs.get('undo_stack') or QtGui.QUndoStack(self)) self._widget = None @@ -469,7 +469,7 @@ def widget(self): self._widget.addTab(self._viewer, 'Node Graph') # hide the close button on the first tab. tab_bar = self._widget.tabBar() - for btn_flag in [tab_bar.RightSide, tab_bar.LeftSide]: + for btn_flag in [tab_bar.ButtonPosition.RightSide, tab_bar.ButtonPosition.LeftSide]: tab_btn = tab_bar.tabButton(0, btn_flag) if tab_btn: tab_btn.deleteLater() diff --git a/NodeGraphQt/base/menu.py b/NodeGraphQt/base/menu.py index 18d629dd..70e041ec 100644 --- a/NodeGraphQt/base/menu.py +++ b/NodeGraphQt/base/menu.py @@ -135,10 +135,10 @@ def add_command(self, name, func=None, shortcut=None): shortcut = getattr(QtGui.QKeySequence, search.group(1)) elif all([i in ['Alt', 'Enter'] for i in shortcut.split('+')]): shortcut = QtGui.QKeySequence( - QtCore.Qt.ALT + QtCore.Qt.Key_Return + QtCore.Qt.Modifier.ALT | QtCore.Qt.Key.Key_Return ) elif all([i in ['Return', 'Enter'] for i in shortcut.split('+')]): - shortcut = QtCore.Qt.Key_Return + shortcut = QtCore.Qt.Key.Key_Return if shortcut: action.setShortcut(shortcut) diff --git a/NodeGraphQt/custom_widgets/nodes_palette.py b/NodeGraphQt/custom_widgets/nodes_palette.py index 870231ff..4a6c01f1 100644 --- a/NodeGraphQt/custom_widgets/nodes_palette.py +++ b/NodeGraphQt/custom_widgets/nodes_palette.py @@ -34,7 +34,7 @@ def paint(self, painter, option, index): ) painter.save() - painter.setRenderHint(QtGui.QPainter.Antialiasing, True) + painter.setRenderHint(QtGui.QPainter.RenderHint.Antialiasing, True) # background. bg_color = option.palette.window().color() @@ -44,21 +44,21 @@ def paint(self, painter, option, index): pen_color = pen_color.lighter(160) pen = QtGui.QPen(pen_color, 3.0) - pen.setCapStyle(QtCore.Qt.RoundCap) + pen.setCapStyle(QtCore.Qt.PenCapStyle.RoundCap) painter.setPen(pen) painter.setBrush(QtGui.QBrush(bg_color)) painter.drawRoundRect(base_rect, int(base_rect.height()/radius), int(base_rect.width()/radius)) - if option.state & QtWidgets.QStyle.State_Selected: + if option.state & QtWidgets.QStyle.StateFlag.State_Selected: pen_color = option.palette.highlight().color() else: pen_color = option.palette.midlight().color().darker(130) pen = QtGui.QPen(pen_color, 1.0) - pen.setCapStyle(QtCore.Qt.RoundCap) + pen.setCapStyle(QtCore.Qt.PenCapStyle.RoundCap) painter.setPen(pen) - painter.setBrush(QtCore.Qt.NoBrush) + painter.setBrush(QtCore.Qt.BrushStyle.NoBrush) sub_margin = 6 sub_rect = QtCore.QRectF( @@ -97,7 +97,7 @@ def paint(self, painter, option, index): # text pen_color = option.palette.text().color() pen = QtGui.QPen(pen_color, 0.5) - pen.setCapStyle(QtCore.Qt.RoundCap) + pen.setCapStyle(QtCore.Qt.PenCapStyle.RoundCap) painter.setPen(pen) font = painter.font() @@ -122,7 +122,7 @@ def __init__(self, parent=None): super(NodesGridProxyModel, self).__init__(parent) def mimeData(self, indexes): - node_ids = ['node:{}'.format(i.data(QtCore.Qt.ToolTipRole)) + node_ids = ['node:{}'.format(i.data(QtCore.Qt.ItemDataRole.ToolTipRole)) for i in indexes] node_urn = URN_SCHEME + ';'.join(node_ids) mime_data = super(NodesGridProxyModel, self).mimeData(indexes) @@ -134,11 +134,11 @@ class NodesGridView(QtWidgets.QListView): def __init__(self, parent=None): super(NodesGridView, self).__init__(parent) - self.setSelectionMode(self.ExtendedSelection) + self.setSelectionMode(self.SelectionMode.ExtendedSelection) self.setUniformItemSizes(True) - self.setResizeMode(self.Adjust) - self.setViewMode(self.IconMode) - self.setDragDropMode(self.DragOnly) + self.setResizeMode(self.ResizeMode.Adjust) + self.setViewMode(self.ViewMode.IconMode) + self.setDragDropMode(self.DragDropMode.DragOnly) self.setDragEnabled(True) self.setMinimumSize(300, 100) self.setSpacing(4) diff --git a/NodeGraphQt/custom_widgets/nodes_tree.py b/NodeGraphQt/custom_widgets/nodes_tree.py index 2a966269..0b23ec58 100644 --- a/NodeGraphQt/custom_widgets/nodes_tree.py +++ b/NodeGraphQt/custom_widgets/nodes_tree.py @@ -50,8 +50,8 @@ class NodesTreeWidget(QtWidgets.QTreeWidget): def __init__(self, parent=None, node_graph=None): super(NodesTreeWidget, self).__init__(parent) - self.setDragDropMode(QtWidgets.QAbstractItemView.DragOnly) - self.setSelectionMode(self.ExtendedSelection) + self.setDragDropMode(QtWidgets.QAbstractItemView.DragDropMode.DragOnly) + self.setSelectionMode(self.SelectionMode.ExtendedSelection) self.setHeaderHidden(True) self.setWindowTitle('Nodes') @@ -94,7 +94,7 @@ def _build_tree(self): label = '{}'.format(category) cat_item = BaseNodeTreeItem(self, [label], type=TYPE_CATEGORY) cat_item.setFirstColumnSpanned(True) - cat_item.setFlags(QtCore.Qt.ItemIsEnabled) + cat_item.setFlags(QtCore.Qt.ItemFlag.ItemIsEnabled) cat_item.setBackground(0, QtGui.QBrush(palette.midlight().color())) cat_item.setSizeHint(0, QtCore.QSize(100, 26)) self.addTopLevelItem(cat_item) diff --git a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_color_picker.py b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_color_picker.py index a2549ad0..7ad5846d 100644 --- a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_color_picker.py +++ b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_color_picker.py @@ -23,8 +23,8 @@ def __init__(self, parent=None): layout = QtWidgets.QHBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) - layout.addWidget(self._button, 0, QtCore.Qt.AlignLeft) - layout.addWidget(self._vector, 1, QtCore.Qt.AlignLeft) + layout.addWidget(self._button, 0, QtCore.Qt.AlignmentFlag.AlignLeft) + layout.addWidget(self._vector, 1, QtCore.Qt.AlignmentFlag.AlignLeft) def _on_vector_changed(self, _, value): self._color = tuple(value) @@ -82,8 +82,8 @@ def __init__(self, parent=None): layout = QtWidgets.QHBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) - layout.addWidget(self._button, 0, QtCore.Qt.AlignLeft) - layout.addWidget(self._vector, 1, QtCore.Qt.AlignLeft) + layout.addWidget(self._button, 0, QtCore.Qt.AlignmentFlag.AlignLeft) + layout.addWidget(self._vector, 1, QtCore.Qt.AlignmentFlag.AlignLeft) def _update_color(self): c = [int(max(min(i, 255), 0)) for i in self._color] diff --git a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_file_paths.py b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_file_paths.py index 1a0c0e19..d02fa210 100644 --- a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_file_paths.py +++ b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_file_paths.py @@ -14,7 +14,7 @@ class PropFilePath(BaseProperty): def __init__(self, parent=None): super(PropFilePath, self).__init__(parent) self._ledit = QtWidgets.QLineEdit() - self._ledit.setAlignment(QtCore.Qt.AlignLeft) + self._ledit.setAlignment(QtCore.Qt.AlignmentFlag.AlignLeft) self._ledit.editingFinished.connect(self._on_value_change) self._ledit.clearFocus() diff --git a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_slider.py b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_slider.py index 66ef5985..2a4ad9c9 100644 --- a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_slider.py +++ b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_slider.py @@ -21,11 +21,11 @@ def __init__(self, parent=None, disable_scroll=True, realtime_update=False): self._init_signal_connections() def _init(self): - self._slider.setOrientation(QtCore.Qt.Horizontal) - self._slider.setTickPosition(QtWidgets.QSlider.TicksBelow) - self._slider.setSizePolicy(QtWidgets.QSizePolicy.Expanding, - QtWidgets.QSizePolicy.Preferred) - self._spinbox.setButtonSymbols(QtWidgets.QAbstractSpinBox.NoButtons) + self._slider.setOrientation(QtCore.Qt.Orientation.Horizontal) + self._slider.setTickPosition(QtWidgets.QSlider.TickPosition.TicksBelow) + self._slider.setSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding, + QtWidgets.QSizePolicy.Policy.Preferred) + self._spinbox.setButtonSymbols(QtWidgets.QAbstractSpinBox.ButtonSymbols.NoButtons) layout = QtWidgets.QHBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self._spinbox) diff --git a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_value_edit.py b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_value_edit.py index 5dc27d34..197734d9 100644 --- a/NodeGraphQt/custom_widgets/properties_bin/custom_widget_value_edit.py +++ b/NodeGraphQt/custom_widgets/properties_bin/custom_widget_value_edit.py @@ -117,7 +117,7 @@ def mouseMoveEvent(self, event): super(_NumberValueEdit, self).mouseMoveEvent(event) def mousePressEvent(self, event): - if event.button() == QtCore.Qt.MiddleButton: + if event.button() == QtCore.Qt.MouseButton.MiddleButton: self._MMB_STATE = True self._reset_previous_x() self._menu.exec_(QtGui.QCursor.pos()) @@ -130,9 +130,9 @@ def mouseReleaseEvent(self, event): def keyPressEvent(self, event): super(_NumberValueEdit, self).keyPressEvent(event) - if event.key() == QtCore.Qt.Key_Up: + if event.key() == QtCore.Qt.Key.Key_Up: return - elif event.key() == QtCore.Qt.Key_Down: + elif event.key() == QtCore.Qt.Key.Key_Down: return # private diff --git a/NodeGraphQt/custom_widgets/properties_bin/node_property_widgets.py b/NodeGraphQt/custom_widgets/properties_bin/node_property_widgets.py index a300f3e3..6d191d69 100644 --- a/NodeGraphQt/custom_widgets/properties_bin/node_property_widgets.py +++ b/NodeGraphQt/custom_widgets/properties_bin/node_property_widgets.py @@ -1,7 +1,7 @@ #!/usr/bin/python from collections import defaultdict -from qtpy import QtWidgets, QtCore, QtGui, QtCompat +from qtpy import QtWidgets, QtCore, QtGui from .node_property_factory import NodePropertyWidgetFactory from .prop_widgets_base import PropLineEdit @@ -54,11 +54,11 @@ def __init__(self, parent=None): self.verticalHeader().hide() self.horizontalHeader().hide() - QtCompat.QHeaderView.setSectionResizeMode( - self.verticalHeader(), QtWidgets.QHeaderView.ResizeToContents) - QtCompat.QHeaderView.setSectionResizeMode( - self.horizontalHeader(), 0, QtWidgets.QHeaderView.Stretch) - self.setVerticalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel) + QtWidgets.QHeaderView.setSectionResizeMode( + self.verticalHeader(), QtWidgets.QHeaderView.ResizeMode.ResizeToContents) + QtWidgets.QHeaderView.setSectionResizeMode( + self.horizontalHeader(), 0, QtWidgets.QHeaderView.ResizeMode.Stretch) + self.setVerticalScrollMode(QtWidgets.QAbstractItemView.ScrollMode.ScrollPerPixel) def wheelEvent(self, event): """ @@ -110,9 +110,9 @@ def add_widget(self, name, widget, value, label=None): if row > 0: row += 1 - label_flags = QtCore.Qt.AlignCenter | QtCore.Qt.AlignRight + label_flags = QtCore.Qt.AlignmentFlag.AlignCenter | QtCore.Qt.AlignmentFlag.AlignRight if widget.__class__.__name__ == 'PropTextEdit': - label_flags = label_flags | QtCore.Qt.AlignTop + label_flags = label_flags | QtCore.Qt.AlignmentFlag.AlignTop self.__layout.addWidget(QtWidgets.QLabel(label), row, 0, label_flags) self.__layout.addWidget(widget, row, 1) @@ -154,7 +154,7 @@ def __init__(self, parent=None, node=None): close_btn = QtWidgets.QPushButton() close_btn.setIcon(QtGui.QIcon( - self.style().standardPixmap(QtWidgets.QStyle.SP_DialogCancelButton) + self.style().standardPixmap(QtWidgets.QStyle.StandardPixmap.SP_DialogCancelButton) )) close_btn.setMaximumWidth(40) close_btn.setToolTip('close property') @@ -166,7 +166,7 @@ def __init__(self, parent=None, node=None): self.name_wgt.value_changed.connect(self._on_property_changed) self.type_wgt = QtWidgets.QLabel(node.type_) - self.type_wgt.setAlignment(QtCore.Qt.AlignRight) + self.type_wgt.setAlignment(QtCore.Qt.AlignmentFlag.AlignRight) self.type_wgt.setToolTip('type_') font = self.type_wgt.font() font.setPointSize(10) @@ -407,7 +407,7 @@ def __repr__(self): return '<{} object at {}>'.format(self.__class__.__name__, hex(id(self))) def __on_prop_close(self, node_id): - items = self._prop_list.findItems(node_id, QtCore.Qt.MatchExactly) + items = self._prop_list.findItems(node_id, QtCore.Qt.MatchFlag.MatchExactly) [self._prop_list.removeRow(i.row()) for i in items] def __on_limit_changed(self, value): @@ -488,7 +488,7 @@ def add_node(self, node): if rows >= self.limit(): self._prop_list.removeRow(rows - 1) - itm_find = self._prop_list.findItems(node.id, QtCore.Qt.MatchExactly) + itm_find = self._prop_list.findItems(node.id, QtCore.Qt.MatchFlag.MatchExactly) if itm_find: self._prop_list.removeRow(itm_find[0].row()) @@ -539,7 +539,7 @@ def prop_widget(self, node): NodePropWidget: node property widget. """ node_id = node if isinstance(node, str) else node.id - itm_find = self._prop_list.findItems(node_id, QtCore.Qt.MatchExactly) + itm_find = self._prop_list.findItems(node_id, QtCore.Qt.MatchFlag.MatchExactly) if itm_find: item = itm_find[0] return self._prop_list.cellWidget(item.row(), 0) diff --git a/NodeGraphQt/custom_widgets/properties_bin/prop_widgets_base.py b/NodeGraphQt/custom_widgets/properties_bin/prop_widgets_base.py index b57c00a5..526e9151 100644 --- a/NodeGraphQt/custom_widgets/properties_bin/prop_widgets_base.py +++ b/NodeGraphQt/custom_widgets/properties_bin/prop_widgets_base.py @@ -130,7 +130,7 @@ def get_value(self): def set_value(self, value): if value != self.get_value(): - idx = self.findText(value, QtCore.Qt.MatchExactly) + idx = self.findText(value, QtCore.Qt.MatchFlag.MatchExactly) self.setCurrentIndex(idx) if idx >= 0: self.value_changed.emit(self.toolTip(), value) @@ -174,7 +174,7 @@ class PropSpinBox(QtWidgets.QSpinBox): def __init__(self, parent=None): super(PropSpinBox, self).__init__(parent) - self.setButtonSymbols(self.NoButtons) + self.setButtonSymbols(self.ButtonSymbols.NoButtons) self.valueChanged.connect(self._on_value_change) def __repr__(self): @@ -202,7 +202,7 @@ class PropDoubleSpinBox(QtWidgets.QDoubleSpinBox): def __init__(self, parent=None): super(PropDoubleSpinBox, self).__init__(parent) - self.setButtonSymbols(self.NoButtons) + self.setButtonSymbols(self.ButtonSymbols.NoButtons) self.valueChanged.connect(self._on_value_change) def __repr__(self): diff --git a/NodeGraphQt/qgraphics/node_abstract.py b/NodeGraphQt/qgraphics/node_abstract.py index f764f60a..6dc58f6a 100644 --- a/NodeGraphQt/qgraphics/node_abstract.py +++ b/NodeGraphQt/qgraphics/node_abstract.py @@ -16,7 +16,7 @@ class AbstractNodeItem(QtWidgets.QGraphicsItem): def __init__(self, name='node', parent=None): super(AbstractNodeItem, self).__init__(parent) - self.setFlags(self.ItemIsSelectable | self.ItemIsMovable) + self.setFlags(self.GraphicsItemFlag.ItemIsSelectable | self.GraphicsItemFlag.ItemIsMovable) self.setCacheMode(ITEM_CACHE_MODE) self.setZValue(Z_VAL_NODE) self._properties = { diff --git a/NodeGraphQt/qgraphics/node_backdrop.py b/NodeGraphQt/qgraphics/node_backdrop.py index 44c08a84..b8769137 100644 --- a/NodeGraphQt/qgraphics/node_backdrop.py +++ b/NodeGraphQt/qgraphics/node_backdrop.py @@ -18,10 +18,10 @@ class BackdropSizer(QtWidgets.QGraphicsItem): def __init__(self, parent=None, size=6.0): super(BackdropSizer, self).__init__(parent) - self.setFlag(self.ItemIsSelectable, True) - self.setFlag(self.ItemIsMovable, True) - self.setFlag(self.ItemSendsScenePositionChanges, True) - self.setCursor(QtGui.QCursor(QtCore.Qt.SizeFDiagCursor)) + self.setFlag(self.GraphicsItemFlag.ItemIsSelectable, True) + self.setFlag(self.GraphicsItemFlag.ItemIsMovable, True) + self.setFlag(self.GraphicsItemFlag.ItemSendsScenePositionChanges, True) + self.setCursor(QtGui.QCursor(QtCore.Qt.CursorShape.SizeFDiagCursor)) self.setToolTip('double-click auto resize') self._size = size @@ -38,7 +38,7 @@ def boundingRect(self): return QtCore.QRectF(0.5, 0.5, self._size, self._size) def itemChange(self, change, value): - if change == self.ItemPositionChange: + if change == self.GraphicsItemChange.ItemPositionChange: item = self.parentItem() mx, my = item.minimum_size x = mx if value.x() < mx else value.x() @@ -95,7 +95,7 @@ def paint(self, painter, option, widget): path.lineTo(rect.bottomRight()) path.lineTo(rect.bottomLeft()) painter.setBrush(color) - painter.setPen(QtCore.Qt.NoPen) + painter.setPen(QtCore.Qt.PenStyle.NoPen) painter.fillPath(path, painter.brush()) painter.restore() @@ -133,13 +133,13 @@ def mouseDoubleClickEvent(self, event): super(BackdropNodeItem, self).mouseDoubleClickEvent(event) def mousePressEvent(self, event): - if event.button() == QtCore.Qt.LeftButton: + if event.button() == QtCore.Qt.MouseButton.LeftButton: pos = event.scenePos() rect = QtCore.QRectF(pos.x() - 5, pos.y() - 5, 10, 10) item = self.scene().items(rect)[0] if isinstance(item, (PortItem, PipeItem)): - self.setFlag(self.ItemIsMovable, False) + self.setFlag(self.GraphicsItemFlag.ItemIsMovable, False) return if self.selected: return @@ -152,7 +152,7 @@ def mousePressEvent(self, event): def mouseReleaseEvent(self, event): super(BackdropNodeItem, self).mouseReleaseEvent(event) - self.setFlag(self.ItemIsMovable, True) + self.setFlag(self.GraphicsItemFlag.ItemIsMovable, True) [n.setSelected(True) for n in self._nodes] self._nodes = [self] @@ -184,8 +184,8 @@ def paint(self, painter, option, widget): widget (QtWidgets.QWidget): not used. """ painter.save() - painter.setPen(QtCore.Qt.NoPen) - painter.setBrush(QtCore.Qt.NoBrush) + painter.setPen(QtCore.Qt.PenStyle.NoPen) + painter.setBrush(QtCore.Qt.BrushStyle.NoBrush) margin = 1.0 rect = self.boundingRect() @@ -197,12 +197,12 @@ def paint(self, painter, option, widget): radius = 2.6 color = (self.color[0], self.color[1], self.color[2], 50) painter.setBrush(QtGui.QColor(*color)) - painter.setPen(QtCore.Qt.NoPen) + painter.setPen(QtCore.Qt.PenStyle.NoPen) painter.drawRoundedRect(rect, radius, radius) top_rect = QtCore.QRectF(rect.x(), rect.y(), rect.width(), 26.0) painter.setBrush(QtGui.QBrush(QtGui.QColor(*self.color))) - painter.setPen(QtCore.Qt.NoPen) + painter.setPen(QtCore.Qt.PenStyle.NoPen) painter.drawRoundedRect(top_rect, radius, radius) for pos in [top_rect.left(), top_rect.right() - 5.0]: painter.drawRect( @@ -215,35 +215,35 @@ def paint(self, painter, option, widget): rect.width() - 5.0, rect.height()) painter.setPen(QtGui.QColor(*self.text_color)) painter.drawText(txt_rect, - QtCore.Qt.AlignLeft | QtCore.Qt.TextWordWrap, + QtCore.Qt.AlignmentFlag.AlignLeft | QtCore.Qt.TextFlag.TextWordWrap, self.backdrop_text) if self.selected: sel_color = [x for x in NodeEnum.SELECTED_COLOR.value] sel_color[-1] = 15 painter.setBrush(QtGui.QColor(*sel_color)) - painter.setPen(QtCore.Qt.NoPen) + painter.setPen(QtCore.Qt.PenStyle.NoPen) painter.drawRoundedRect(rect, radius, radius) txt_rect = QtCore.QRectF(top_rect.x(), top_rect.y(), rect.width(), top_rect.height()) painter.setPen(QtGui.QColor(*self.text_color)) - painter.drawText(txt_rect, QtCore.Qt.AlignCenter, self.name) + painter.drawText(txt_rect, QtCore.Qt.AlignmentFlag.AlignCenter, self.name) border = 0.8 border_color = self.color if self.selected and NodeEnum.SELECTED_BORDER_COLOR.value: border = 1.0 border_color = NodeEnum.SELECTED_BORDER_COLOR.value - painter.setBrush(QtCore.Qt.NoBrush) + painter.setBrush(QtCore.Qt.BrushStyle.NoBrush) painter.setPen(QtGui.QPen(QtGui.QColor(*border_color), border)) painter.drawRoundedRect(rect, radius, radius) painter.restore() def get_nodes(self, inc_intersects=False): - mode = {True: QtCore.Qt.IntersectsItemShape, - False: QtCore.Qt.ContainsItemShape} + mode = {True: QtCore.Qt.ItemSelectionMode.IntersectsItemShape, + False: QtCore.Qt.ItemSelectionMode.ContainsItemShape} nodes = [] if self.scene(): polygon = self.mapToScene(self.boundingRect()) diff --git a/NodeGraphQt/qgraphics/node_base.py b/NodeGraphQt/qgraphics/node_base.py index ffb8661b..4e21dfde 100644 --- a/NodeGraphQt/qgraphics/node_base.py +++ b/NodeGraphQt/qgraphics/node_base.py @@ -34,11 +34,11 @@ def __init__(self, name='node', parent=None): if pixmap.size().height() > NodeEnum.ICON_SIZE.value: pixmap = pixmap.scaledToHeight( NodeEnum.ICON_SIZE.value, - QtCore.Qt.SmoothTransformation + QtCore.Qt.TransformationMode.SmoothTransformation ) self._properties['icon'] = ICON_NODE_BASE self._icon_item = QtWidgets.QGraphicsPixmapItem(pixmap, self) - self._icon_item.setTransformationMode(QtCore.Qt.SmoothTransformation) + self._icon_item.setTransformationMode(QtCore.Qt.TransformationMode.SmoothTransformation) self._text_item = NodeTextItem(self.name, self) self._x_item = XDisabledItem(self, 'DISABLED') self._input_items = OrderedDict() @@ -69,8 +69,8 @@ def post_init(self, viewer, pos=None): def _paint_horizontal(self, painter, option, widget): painter.save() - painter.setPen(QtCore.Qt.NoPen) - painter.setBrush(QtCore.Qt.NoBrush) + painter.setPen(QtCore.Qt.PenStyle.NoPen) + painter.setBrush(QtCore.Qt.BrushStyle.NoBrush) # base background. margin = 1.0 @@ -119,7 +119,7 @@ def _paint_horizontal(self, painter, option, widget): pen.setCosmetic(self.viewer().get_zoom() < 0.0) path = QtGui.QPainterPath() path.addRoundedRect(border_rect, radius, radius) - painter.setBrush(QtCore.Qt.NoBrush) + painter.setBrush(QtCore.Qt.BrushStyle.NoBrush) painter.setPen(pen) painter.drawPath(path) @@ -127,8 +127,8 @@ def _paint_horizontal(self, painter, option, widget): def _paint_vertical(self, painter, option, widget): painter.save() - painter.setPen(QtCore.Qt.NoPen) - painter.setBrush(QtCore.Qt.NoBrush) + painter.setPen(QtCore.Qt.PenStyle.NoPen) + painter.setBrush(QtCore.Qt.BrushStyle.NoBrush) # base background. margin = 1.0 @@ -174,7 +174,7 @@ def _paint_vertical(self, painter, option, widget): pen = QtGui.QPen(border_color, border_width) pen.setCosmetic(self.viewer().get_zoom() < 0.0) - painter.setBrush(QtCore.Qt.NoBrush) + painter.setBrush(QtCore.Qt.BrushStyle.NoBrush) painter.setPen(pen) painter.drawRoundedRect(border_rect, radius, radius) @@ -205,7 +205,7 @@ def mousePressEvent(self, event): Args: event (QtWidgets.QGraphicsSceneMouseEvent): mouse event. """ - if event.button() == QtCore.Qt.LeftButton: + if event.button() == QtCore.Qt.MouseButton.LeftButton: for p in self._input_items.keys(): if p.hovered: event.ignore() @@ -223,7 +223,7 @@ def mouseReleaseEvent(self, event): Args: event (QtWidgets.QGraphicsSceneMouseEvent): mouse event. """ - if event.modifiers() == QtCore.Qt.AltModifier: + if event.modifiers() == QtCore.Qt.KeyboardModifier.AltModifier: event.ignore() return super(NodeItem, self).mouseReleaseEvent(event) @@ -235,7 +235,7 @@ def mouseDoubleClickEvent(self, event): Args: event (QtWidgets.QGraphicsSceneMouseEvent): mouse event. """ - if event.button() == QtCore.Qt.LeftButton: + if event.button() == QtCore.Qt.MouseButton.LeftButton: if not self.disabled: # enable text item edit mode. items = self.scene().items(event.scenePos()) @@ -258,7 +258,7 @@ def itemChange(self, change, value): change: value: """ - if change == self.ItemSelectedChange and self.scene(): + if change == self.GraphicsItemChange.ItemSelectedChange and self.scene(): self.reset_pipes() if value: self.highlight_pipes() @@ -786,7 +786,7 @@ def icon(self, path=None): if pixmap.size().height() > NodeEnum.ICON_SIZE.value: pixmap = pixmap.scaledToHeight( NodeEnum.ICON_SIZE.value, - QtCore.Qt.SmoothTransformation + QtCore.Qt.TransformationMode.SmoothTransformation ) self._icon_item.setPixmap(pixmap) if self.scene(): diff --git a/NodeGraphQt/qgraphics/node_circle.py b/NodeGraphQt/qgraphics/node_circle.py index c0ab37db..81521a84 100644 --- a/NodeGraphQt/qgraphics/node_circle.py +++ b/NodeGraphQt/qgraphics/node_circle.py @@ -237,9 +237,9 @@ def _paint_horizontal(self, painter, option, widget): pen_color = QtGui.QColor(*self.border_color) pen_color.setAlpha(120) pen = QtGui.QPen(pen_color, 1.5) - pen.setCapStyle(QtCore.Qt.RoundCap) + pen.setCapStyle(QtCore.Qt.PenCapStyle.RoundCap) painter.setPen(pen) - painter.setBrush(QtCore.Qt.NoBrush) + painter.setBrush(QtCore.Qt.BrushStyle.NoBrush) for p in self.inputs: if p.isVisible(): p_text = self.get_input_text_item(p) @@ -276,7 +276,7 @@ def _paint_horizontal(self, painter, option, widget): # draw the base color. painter.setBrush(QtGui.QColor(*self.color)) - painter.setPen(QtCore.Qt.NoPen) + painter.setPen(QtCore.Qt.PenStyle.NoPen) painter.drawEllipse(rect) # draw outline. @@ -294,7 +294,7 @@ def _paint_horizontal(self, painter, option, widget): border_color = QtGui.QColor(*self.border_color) # draw the outlines. - painter.setBrush(QtCore.Qt.NoBrush) + painter.setBrush(QtCore.Qt.BrushStyle.NoBrush) painter.setPen(QtGui.QPen(border_color, border_width)) painter.drawEllipse(rect) @@ -310,7 +310,7 @@ def _paint_horizontal(self, painter, option, widget): painter.setBrush(QtGui.QColor(*NodeEnum.SELECTED_COLOR.value)) else: painter.setBrush(QtGui.QColor(0, 0, 0, 80)) - painter.setPen(QtCore.Qt.NoPen) + painter.setPen(QtCore.Qt.PenStyle.NoPen) painter.drawRoundedRect(text_rect, 8.0, 8.0) painter.restore() @@ -338,9 +338,9 @@ def _paint_vertical(self, painter, option, widget): pen_color = QtGui.QColor(*self.border_color) pen_color.setAlpha(120) pen = QtGui.QPen(pen_color, 1.5) - pen.setCapStyle(QtCore.Qt.RoundCap) + pen.setCapStyle(QtCore.Qt.PenCapStyle.RoundCap) painter.setPen(pen) - painter.setBrush(QtCore.Qt.NoBrush) + painter.setBrush(QtCore.Qt.BrushStyle.NoBrush) for p in self.inputs: if p.isVisible(): pt1 = QtCore.QPointF( @@ -367,7 +367,7 @@ def _paint_vertical(self, painter, option, widget): # draw the base color. painter.setBrush(QtGui.QColor(*self.color)) - painter.setPen(QtCore.Qt.NoPen) + painter.setPen(QtCore.Qt.PenStyle.NoPen) painter.drawEllipse(rect) # draw outline. @@ -385,7 +385,7 @@ def _paint_vertical(self, painter, option, widget): border_color = QtGui.QColor(*self.border_color) # draw the outlines. - painter.setBrush(QtCore.Qt.NoBrush) + painter.setBrush(QtCore.Qt.BrushStyle.NoBrush) painter.setPen(QtGui.QPen(border_color, border_width)) painter.drawEllipse(rect) diff --git a/NodeGraphQt/qgraphics/node_group.py b/NodeGraphQt/qgraphics/node_group.py index b4dd6674..4e320a2e 100644 --- a/NodeGraphQt/qgraphics/node_group.py +++ b/NodeGraphQt/qgraphics/node_group.py @@ -19,8 +19,8 @@ def __init__(self, name='group', parent=None): def _paint_horizontal(self, painter, option, widget): painter.save() - painter.setBrush(QtCore.Qt.NoBrush) - painter.setPen(QtCore.Qt.NoPen) + painter.setBrush(QtCore.Qt.BrushStyle.NoBrush) + painter.setPen(QtCore.Qt.PenStyle.NoPen) # base background. margin = 6.0 @@ -72,14 +72,14 @@ def _paint_horizontal(self, painter, option, widget): painter.setBrush(QtGui.QColor(*NodeEnum.SELECTED_COLOR.value)) else: painter.setBrush(QtGui.QColor(0, 0, 0, 80)) - painter.setPen(QtCore.Qt.NoPen) + painter.setPen(QtCore.Qt.PenStyle.NoPen) painter.drawRect(text_rect) # draw the outlines. pen = QtGui.QPen(border_color.darker(120), 0.8) - pen.setJoinStyle(QtCore.Qt.RoundJoin) - pen.setCapStyle(QtCore.Qt.RoundCap) - painter.setBrush(QtCore.Qt.NoBrush) + pen.setJoinStyle(QtCore.Qt.PenJoinStyle.RoundJoin) + pen.setCapStyle(QtCore.Qt.PenCapStyle.RoundCap) + painter.setBrush(QtCore.Qt.BrushStyle.NoBrush) painter.setPen(pen) painter.drawLines([rect_1.topRight(), rect_2.topRight(), rect_1.topRight(), rect_1.bottomRight(), @@ -88,8 +88,8 @@ def _paint_horizontal(self, painter, option, widget): painter.drawLine(rect_1.bottomRight(), rect_2.bottomRight()) pen = QtGui.QPen(border_color, 0.8) - pen.setJoinStyle(QtCore.Qt.MiterJoin) - pen.setCapStyle(QtCore.Qt.RoundCap) + pen.setJoinStyle(QtCore.Qt.PenJoinStyle.MiterJoin) + pen.setCapStyle(QtCore.Qt.PenCapStyle.RoundCap) painter.setPen(pen) painter.drawRect(rect_2) @@ -97,8 +97,8 @@ def _paint_horizontal(self, painter, option, widget): def _paint_vertical(self, painter, option, widget): painter.save() - painter.setBrush(QtCore.Qt.NoBrush) - painter.setPen(QtCore.Qt.NoPen) + painter.setBrush(QtCore.Qt.BrushStyle.NoBrush) + painter.setPen(QtCore.Qt.PenStyle.NoPen) # base background. margin = 6.0 @@ -146,7 +146,7 @@ def _paint_vertical(self, painter, option, widget): else: painter.setBrush(QtGui.QColor(0, 0, 0, 80)) - painter.setPen(QtCore.Qt.NoPen) + painter.setPen(QtCore.Qt.PenStyle.NoPen) for y in [rect_2.top() + padding, rect_2.bottom() - height - padding]: top_rect = QtCore.QRectF(rect.x() + padding - offset, y, rect.width() - (padding * 2), height) @@ -154,9 +154,9 @@ def _paint_vertical(self, painter, option, widget): # draw the outlines. pen = QtGui.QPen(border_color.darker(120), 0.8) - pen.setJoinStyle(QtCore.Qt.MiterJoin) - pen.setCapStyle(QtCore.Qt.RoundCap) - painter.setBrush(QtCore.Qt.NoBrush) + pen.setJoinStyle(QtCore.Qt.PenJoinStyle.MiterJoin) + pen.setCapStyle(QtCore.Qt.PenCapStyle.RoundCap) + painter.setBrush(QtCore.Qt.BrushStyle.NoBrush) painter.setPen(pen) painter.drawLines([rect_1.topRight(), rect_2.topRight(), rect_1.topRight(), rect_1.bottomRight(), @@ -165,8 +165,8 @@ def _paint_vertical(self, painter, option, widget): painter.drawLine(rect_1.bottomRight(), rect_2.bottomRight()) pen = QtGui.QPen(border_color, 0.8) - pen.setJoinStyle(QtCore.Qt.MiterJoin) - pen.setCapStyle(QtCore.Qt.RoundCap) + pen.setJoinStyle(QtCore.Qt.PenJoinStyle.MiterJoin) + pen.setCapStyle(QtCore.Qt.PenCapStyle.RoundCap) painter.setPen(pen) painter.drawRect(rect_2) diff --git a/NodeGraphQt/qgraphics/node_overlay_disabled.py b/NodeGraphQt/qgraphics/node_overlay_disabled.py index 2fe7bd0e..9d840114 100644 --- a/NodeGraphQt/qgraphics/node_overlay_disabled.py +++ b/NodeGraphQt/qgraphics/node_overlay_disabled.py @@ -44,7 +44,7 @@ def paint(self, painter, option, widget): rect.height() + margin) if not self.proxy_mode: pen = QtGui.QPen(QtGui.QColor(*self.color), 8) - pen.setCapStyle(QtCore.Qt.RoundCap) + pen.setCapStyle(QtCore.Qt.PenCapStyle.RoundCap) painter.setPen(pen) painter.drawLine(dis_rect.topLeft(), dis_rect.bottomRight()) painter.drawLine(dis_rect.topRight(), dis_rect.bottomLeft()) diff --git a/NodeGraphQt/qgraphics/node_port_in.py b/NodeGraphQt/qgraphics/node_port_in.py index 56c156c5..aa5981cb 100644 --- a/NodeGraphQt/qgraphics/node_port_in.py +++ b/NodeGraphQt/qgraphics/node_port_in.py @@ -29,8 +29,8 @@ def _paint_horizontal(self, painter, option, widget): self.auto_switch_mode() painter.save() - painter.setBrush(QtCore.Qt.NoBrush) - painter.setPen(QtCore.Qt.NoPen) + painter.setBrush(QtCore.Qt.BrushStyle.NoBrush) + painter.setPen(QtCore.Qt.PenStyle.NoPen) margin = 2.0 rect = self.boundingRect() @@ -73,7 +73,7 @@ def _paint_horizontal(self, painter, option, widget): pen = QtGui.QPen(QtGui.QColor(*self.border_color), 1.2) painter.setBrush(QtGui.QColor(0, 0, 0, 50)) - pen.setJoinStyle(QtCore.Qt.MiterJoin) + pen.setJoinStyle(QtCore.Qt.PenJoinStyle.MiterJoin) painter.setPen(pen) painter.drawPolygon(poly) @@ -89,8 +89,8 @@ def _paint_vertical(self, painter, option, widget): self.auto_switch_mode() painter.save() - painter.setBrush(QtCore.Qt.NoBrush) - painter.setPen(QtCore.Qt.NoPen) + painter.setBrush(QtCore.Qt.BrushStyle.NoBrush) + painter.setPen(QtCore.Qt.PenStyle.NoPen) margin = 2.0 rect = self.boundingRect() @@ -133,7 +133,7 @@ def _paint_vertical(self, painter, option, widget): pen = QtGui.QPen(QtGui.QColor(*self.border_color), 1.2) painter.setBrush(QtGui.QColor(0, 0, 0, 50)) - pen.setJoinStyle(QtCore.Qt.MiterJoin) + pen.setJoinStyle(QtCore.Qt.PenJoinStyle.MiterJoin) painter.setPen(pen) painter.drawPolygon(poly) diff --git a/NodeGraphQt/qgraphics/node_port_out.py b/NodeGraphQt/qgraphics/node_port_out.py index 808fe6bf..cce6d89d 100644 --- a/NodeGraphQt/qgraphics/node_port_out.py +++ b/NodeGraphQt/qgraphics/node_port_out.py @@ -29,8 +29,8 @@ def _paint_horizontal(self, painter, option, widget): self.auto_switch_mode() painter.save() - painter.setBrush(QtCore.Qt.NoBrush) - painter.setPen(QtCore.Qt.NoPen) + painter.setBrush(QtCore.Qt.BrushStyle.NoBrush) + painter.setPen(QtCore.Qt.PenStyle.NoPen) margin = 2.0 rect = self.boundingRect() @@ -73,7 +73,7 @@ def _paint_horizontal(self, painter, option, widget): pen = QtGui.QPen(QtGui.QColor(*self.border_color), 1.2) painter.setBrush(QtGui.QColor(0, 0, 0, 50)) - pen.setJoinStyle(QtCore.Qt.MiterJoin) + pen.setJoinStyle(QtCore.Qt.PenJoinStyle.MiterJoin) painter.setPen(pen) painter.drawPolygon(poly) @@ -89,8 +89,8 @@ def _paint_vertical(self, painter, option, widget): self.auto_switch_mode() painter.save() - painter.setBrush(QtCore.Qt.NoBrush) - painter.setPen(QtCore.Qt.NoPen) + painter.setBrush(QtCore.Qt.BrushStyle.NoBrush) + painter.setPen(QtCore.Qt.PenStyle.NoPen) margin = 2.0 rect = self.boundingRect() @@ -133,7 +133,7 @@ def _paint_vertical(self, painter, option, widget): pen = QtGui.QPen(QtGui.QColor(*self.border_color), 1.2) painter.setBrush(QtGui.QColor(0, 0, 0, 50)) - pen.setJoinStyle(QtCore.Qt.MiterJoin) + pen.setJoinStyle(QtCore.Qt.PenJoinStyle.MiterJoin) painter.setPen(pen) painter.drawPolygon(poly) diff --git a/NodeGraphQt/qgraphics/node_text_item.py b/NodeGraphQt/qgraphics/node_text_item.py index bde3c125..e8840dc1 100644 --- a/NodeGraphQt/qgraphics/node_text_item.py +++ b/NodeGraphQt/qgraphics/node_text_item.py @@ -20,7 +20,7 @@ def mouseDoubleClickEvent(self, event): event (QtWidgets.QGraphicsSceneMouseEvent): mouse event. """ if not self._locked: - if event.button() == QtCore.Qt.LeftButton: + if event.button() == QtCore.Qt.MouseButton.LeftButton: self.set_editable(True) event.ignore() return @@ -33,11 +33,11 @@ def keyPressEvent(self, event): Args: event (QtGui.QKeyEvent): key event. """ - if event.key() == QtCore.Qt.Key_Return: + if event.key() == QtCore.Qt.Key.Key_Return: current_text = self.toPlainText() self.set_node_name(current_text) self.set_editable(False) - elif event.key() == QtCore.Qt.Key_Escape: + elif event.key() == QtCore.Qt.Key.Key_Escape: self.setPlainText(self.node.name) self.set_editable(False) super(NodeTextItem, self).keyPressEvent(event) @@ -65,12 +65,12 @@ def set_editable(self, value=False): return if value: self.setTextInteractionFlags( - QtCore.Qt.TextEditable | - QtCore.Qt.TextSelectableByMouse | - QtCore.Qt.TextSelectableByKeyboard + QtCore.Qt.TextInteractionFlag.TextEditable | + QtCore.Qt.TextInteractionFlag.TextSelectableByMouse | + QtCore.Qt.TextInteractionFlag.TextSelectableByKeyboard ) else: - self.setTextInteractionFlags(QtCore.Qt.NoTextInteraction) + self.setTextInteractionFlags(QtCore.Qt.TextInteractionFlag.NoTextInteraction) cursor = self.textCursor() cursor.clearSelection() self.setTextCursor(cursor) @@ -99,12 +99,12 @@ def set_locked(self, state=False): self._locked = state if self._locked: self.setFlag(QtWidgets.QGraphicsItem.ItemIsFocusable, False) - self.setCursor(QtCore.Qt.ArrowCursor) + self.setCursor(QtCore.Qt.CursorShape.ArrowCursor) self.setToolTip('') else: self.setFlag(QtWidgets.QGraphicsItem.ItemIsFocusable, True) self.setToolTip('double-click to edit node name.') - self.setCursor(QtCore.Qt.IBeamCursor) + self.setCursor(QtCore.Qt.CursorShape.IBeamCursor) @property def node(self): diff --git a/NodeGraphQt/qgraphics/pipe.py b/NodeGraphQt/qgraphics/pipe.py index 852c795f..6ce73618 100644 --- a/NodeGraphQt/qgraphics/pipe.py +++ b/NodeGraphQt/qgraphics/pipe.py @@ -15,9 +15,9 @@ from NodeGraphQt.qgraphics.port import PortItem PIPE_STYLES = { - PipeEnum.DRAW_TYPE_DEFAULT.value: QtCore.Qt.SolidLine, - PipeEnum.DRAW_TYPE_DASHED.value: QtCore.Qt.DashLine, - PipeEnum.DRAW_TYPE_DOTTED.value: QtCore.Qt.DotLine + PipeEnum.DRAW_TYPE_DEFAULT.value: QtCore.Qt.PenStyle.SolidLine, + PipeEnum.DRAW_TYPE_DASHED.value: QtCore.Qt.PenStyle.DashLine, + PipeEnum.DRAW_TYPE_DOTTED.value: QtCore.Qt.PenStyle.DotLine } @@ -83,8 +83,8 @@ def paint(self, painter, option, widget): ]) if not is_visible: painter.save() - painter.setBrush(QtCore.Qt.NoBrush) - painter.setPen(QtCore.Qt.NoPen) + painter.setBrush(QtCore.Qt.BrushStyle.NoBrush) + painter.setPen(QtCore.Qt.PenStyle.NoPen) painter.restore() return @@ -93,7 +93,7 @@ def paint(self, painter, option, widget): pen_width = PipeEnum.WIDTH.value if self._active: color = QtGui.QColor(*PipeEnum.ACTIVE_COLOR.value) - if pen_style == QtCore.Qt.DashDotDotLine: + if pen_style == QtCore.Qt.PenStyle.DashDotDotLine: pen_width += 1 else: pen_width += 0.35 @@ -108,12 +108,12 @@ def paint(self, painter, option, widget): pen_style = PIPE_STYLES.get(PipeEnum.DRAW_TYPE_DOTTED.value) pen = QtGui.QPen(color, pen_width, pen_style) - pen.setCapStyle(QtCore.Qt.RoundCap) - pen.setJoinStyle(QtCore.Qt.MiterJoin) + pen.setCapStyle(QtCore.Qt.PenCapStyle.RoundCap) + pen.setJoinStyle(QtCore.Qt.PenJoinStyle.MiterJoin) painter.save() painter.setPen(pen) - painter.setRenderHint(painter.Antialiasing, True) + painter.setRenderHint(painter.RenderHint.Antialiasing, True) painter.drawPath(self.path()) # draw arrow @@ -141,8 +141,8 @@ def paint(self, painter, option, widget): pen_width *= (1.0 + dist) pen = QtGui.QPen(color, pen_width) - pen.setCapStyle(QtCore.Qt.RoundCap) - pen.setJoinStyle(QtCore.Qt.MiterJoin) + pen.setCapStyle(QtCore.Qt.PenCapStyle.RoundCap) + pen.setJoinStyle(QtCore.Qt.PenJoinStyle.MiterJoin) painter.setPen(pen) transform = QtGui.QTransform() @@ -362,7 +362,7 @@ def disabled(self): return False def itemChange(self, change, value): - if change == self.ItemSelectedChange and self.scene(): + if change == self.GraphicsItemChange.ItemSelectedChange and self.scene(): self.reset() if value: self.highlight() @@ -438,11 +438,11 @@ def paint(self, painter, option, widget): pen = QtGui.QPen(color, pen_width) pen.setStyle(pen_style) - pen.setCapStyle(QtCore.Qt.RoundCap) + pen.setCapStyle(QtCore.Qt.PenCapStyle.RoundCap) painter.save() painter.setPen(pen) - painter.setRenderHint(painter.Antialiasing, True) + painter.setRenderHint(painter.RenderHint.Antialiasing, True) painter.drawPath(self.path()) cen_x = self.path().pointAtPercent(0.5).x() diff --git a/NodeGraphQt/qgraphics/port.py b/NodeGraphQt/qgraphics/port.py index 64637d4f..3d43f788 100644 --- a/NodeGraphQt/qgraphics/port.py +++ b/NodeGraphQt/qgraphics/port.py @@ -16,8 +16,8 @@ def __init__(self, parent=None): super(PortItem, self).__init__(parent) self.setAcceptHoverEvents(True) self.setCacheMode(ITEM_CACHE_MODE) - self.setFlag(self.ItemIsSelectable, False) - self.setFlag(self.ItemSendsScenePositionChanges, True) + self.setFlag(self.GraphicsItemFlag.ItemIsSelectable, False) + self.setFlag(self.GraphicsItemFlag.ItemSendsScenePositionChanges, True) self.setZValue(Z_VAL_PORT) self._pipes = [] self._width = PortEnum.SIZE.value @@ -114,7 +114,7 @@ def paint(self, painter, option, widget): painter.restore() def itemChange(self, change, value): - if change == self.ItemScenePositionHasChanged: + if change == self.GraphicsItemChange.ItemScenePositionHasChanged: self.redraw_connected_pipes() return super(PortItem, self).itemChange(change, value) diff --git a/NodeGraphQt/qgraphics/slicer.py b/NodeGraphQt/qgraphics/slicer.py index 520925f4..e3713cf3 100644 --- a/NodeGraphQt/qgraphics/slicer.py +++ b/NodeGraphQt/qgraphics/slicer.py @@ -45,20 +45,20 @@ def paint(self, painter, option, widget): text_color = QtGui.QColor(*PipeSlicerEnum.COLOR.value) text_color.setAlpha(80) painter.setPen(QtGui.QPen( - text_color, PipeSlicerEnum.WIDTH.value, QtCore.Qt.SolidLine + text_color, PipeSlicerEnum.WIDTH.value, QtCore.Qt.PenStyle.SolidLine )) painter.drawText(text_pos, text) painter.setPen(QtGui.QPen( - color, PipeSlicerEnum.WIDTH.value, QtCore.Qt.DashDotLine + color, PipeSlicerEnum.WIDTH.value, QtCore.Qt.PenStyle.DashDotLine )) painter.drawPath(self.path()) pen = QtGui.QPen( - color, PipeSlicerEnum.WIDTH.value, QtCore.Qt.SolidLine + color, PipeSlicerEnum.WIDTH.value, QtCore.Qt.PenStyle.SolidLine ) - pen.setCapStyle(QtCore.Qt.RoundCap) - pen.setJoinStyle(QtCore.Qt.MiterJoin) + pen.setCapStyle(QtCore.Qt.PenCapStyle.RoundCap) + pen.setJoinStyle(QtCore.Qt.PenJoinStyle.MiterJoin) painter.setPen(pen) painter.setBrush(color) diff --git a/NodeGraphQt/widgets/node_widgets.py b/NodeGraphQt/widgets/node_widgets.py index 05f1ecde..1440c4e7 100644 --- a/NodeGraphQt/widgets/node_widgets.py +++ b/NodeGraphQt/widgets/node_widgets.py @@ -287,7 +287,7 @@ def set_value(self, text=''): combo_widget.addItems(text) return if text != self.get_value(): - index = combo_widget.findText(text, QtCore.Qt.MatchExactly) + index = combo_widget.findText(text, QtCore.Qt.MatchFlag.MatchExactly) combo_widget.setCurrentIndex(index) def add_item(self, item): @@ -353,7 +353,7 @@ def __init__(self, parent=None, name='', label='', text=''): ledit = QtWidgets.QLineEdit() ledit.setText(text) ledit.setStyleSheet(stylesheet) - ledit.setAlignment(QtCore.Qt.AlignCenter) + ledit.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter) ledit.editingFinished.connect(self.on_value_changed) ledit.clearFocus() self.set_custom_widget(ledit) diff --git a/NodeGraphQt/widgets/scene.py b/NodeGraphQt/widgets/scene.py index 706a3582..a2e503e3 100644 --- a/NodeGraphQt/widgets/scene.py +++ b/NodeGraphQt/widgets/scene.py @@ -122,9 +122,9 @@ def mousePressEvent(self, event): self.viewer().sceneMousePressEvent(event) super(NodeScene, self).mousePressEvent(event) keep_selection = any([ - event.button() == QtCore.Qt.MiddleButton, - event.button() == QtCore.Qt.RightButton, - event.modifiers() == QtCore.Qt.AltModifier + event.button() == QtCore.Qt.MouseButton.MiddleButton, + event.button() == QtCore.Qt.MouseButton.RightButton, + event.modifiers() == QtCore.Qt.KeyboardModifier.AltModifier ]) if keep_selection: for node in selected_nodes: diff --git a/NodeGraphQt/widgets/tab_search.py b/NodeGraphQt/widgets/tab_search.py index 662a6474..3e60a552 100644 --- a/NodeGraphQt/widgets/tab_search.py +++ b/NodeGraphQt/widgets/tab_search.py @@ -15,8 +15,8 @@ class TabSearchCompleter(QtWidgets.QCompleter): def __init__(self, nodes=None, parent=None): super(TabSearchCompleter, self).__init__(nodes, parent) - self.setCompletionMode(self.PopupCompletion) - self.setCaseSensitivity(QtCore.Qt.CaseInsensitive) + self.setCompletionMode(self.CompletionMode.PopupCompletion) + self.setCaseSensitivity(QtCore.Qt.CaseSensitivity.CaseInsensitive) self._local_completion_prefix = '' self._using_orig_model = False self._source_model = None @@ -35,11 +35,14 @@ def splitPath(self, path): def updateModel(self): if not self._using_orig_model: self._filter_model.setSourceModel(self._source_model) - - pattern = QtCore.QRegExp(self._local_completion_prefix, - QtCore.Qt.CaseInsensitive, - QtCore.QRegExp.FixedString) - self._filter_model.setFilterRegExp(pattern) + # # https://doc.qt.io/qtforpython-6/overviews/qtcore-changes-qt6.html#the-qregularexpression-class + # pattern = QtCore.QRegExp(self._local_completion_prefix, + # QtCore.Qt.CaseSensitivity.CaseInsensitive, + # QtCore.QRegExp.FixedString) + # self._filter_model.setFilterRegExp(pattern) + # TODO: review these changes + self._filter_model.setFilterCaseSensitivity(QtCore.Qt.CaseSensitivity.CaseInsensitive) + self._filter_model.setFilterFixedString(self._local_completion_prefix) def setModel(self, model): self._source_model = model @@ -55,7 +58,7 @@ class TabSearchLineEditWidget(QtWidgets.QLineEdit): def __init__(self, parent=None): super(TabSearchLineEditWidget, self).__init__(parent) - self.setAttribute(QtCore.Qt.WA_MacShowFocusRect, 0) + self.setAttribute(QtCore.Qt.WidgetAttribute.WA_MacShowFocusRect, 0) self.setMinimumSize(200, 22) # text_color = self.palette().text().color().getRgb() text_color = tuple(map(lambda i, j: i - j, (255, 255, 255), @@ -88,7 +91,7 @@ def __init__(self, parent=None): def keyPressEvent(self, event): super(TabSearchLineEditWidget, self).keyPressEvent(event) - if event.key() == QtCore.Qt.Key_Tab: + if event.key() == QtCore.Qt.Key.Key_Tab: self.tab_pressed.emit() diff --git a/NodeGraphQt/widgets/viewer.py b/NodeGraphQt/widgets/viewer.py index 13e79fdc..aa4244ad 100644 --- a/NodeGraphQt/widgets/viewer.py +++ b/NodeGraphQt/widgets/viewer.py @@ -51,19 +51,19 @@ def __init__(self, parent=None, undo_stack=None): """ Args: parent: - undo_stack (QtWidgets.QUndoStack): undo stack from the parent + undo_stack (QtGui.QUndoStack): undo stack from the parent graph controller. """ super(NodeViewer, self).__init__(parent) self.setScene(NodeScene(self)) - self.setRenderHint(QtGui.QPainter.Antialiasing, True) - self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) - self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) - self.setViewportUpdateMode(QtWidgets.QGraphicsView.FullViewportUpdate) - self.setCacheMode(QtWidgets.QGraphicsView.CacheBackground) + self.setRenderHint(QtGui.QPainter.RenderHint.Antialiasing, True) + self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarPolicy.ScrollBarAlwaysOff) + self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarPolicy.ScrollBarAlwaysOff) + self.setViewportUpdateMode(QtWidgets.QGraphicsView.ViewportUpdateMode.FullViewportUpdate) + self.setCacheMode(QtWidgets.QGraphicsView.CacheModeFlag.CacheBackground) self.setOptimizationFlag( - QtWidgets.QGraphicsView.DontAdjustForAntialiasing) + QtWidgets.QGraphicsView.OptimizationFlag.DontAdjustForAntialiasing) self.setAcceptDrops(True) self.resize(850, 800) @@ -85,7 +85,7 @@ def __init__(self, parent=None, undo_stack=None): self._prev_selection_pipes = [] self._node_positions = {} self._rubber_band = QtWidgets.QRubberBand( - QtWidgets.QRubberBand.Rectangle, self + QtWidgets.QRubberBand.Shape.Rectangle, self ) self._rubber_band.isActive = False @@ -173,8 +173,8 @@ def _build_context_menus(self): # setup the undo and redo actions. if self._undo_action and self._redo_action: - self._undo_action.setShortcuts(QtGui.QKeySequence.Undo) - self._redo_action.setShortcuts(QtGui.QKeySequence.Redo) + self._undo_action.setShortcuts(QtGui.QKeySequence.StandardKey.Undo) + self._redo_action.setShortcuts(QtGui.QKeySequence.StandardKey.Redo) if LooseVersion(QtCore.qVersion()) >= LooseVersion('5.10'): self._undo_action.setShortcutVisibleInContextMenu(True) self._redo_action.setShortcutVisibleInContextMenu(True) @@ -241,7 +241,7 @@ def _update_scene(self): Redraw the scene. """ self.setSceneRect(self._scene_range) - self.fitInView(self._scene_range, QtCore.Qt.KeepAspectRatio) + self.fitInView(self._scene_range, QtCore.Qt.AspectRatioMode.KeepAspectRatio) def _combined_rect(self, nodes): """ @@ -351,11 +351,11 @@ def contextMenuEvent(self, event): return super(NodeViewer, self).contextMenuEvent(event) def mousePressEvent(self, event): - if event.button() == QtCore.Qt.LeftButton: + if event.button() == QtCore.Qt.MouseButton.LeftButton: self.LMB_state = True - elif event.button() == QtCore.Qt.RightButton: + elif event.button() == QtCore.Qt.MouseButton.RightButton: self.RMB_state = True - elif event.button() == QtCore.Qt.MiddleButton: + elif event.button() == QtCore.Qt.MouseButton.MiddleButton: self.MMB_state = True self._origin_pos = event.pos() @@ -421,11 +421,11 @@ def mousePressEvent(self, event): super(NodeViewer, self).mousePressEvent(event) def mouseReleaseEvent(self, event): - if event.button() == QtCore.Qt.LeftButton: + if event.button() == QtCore.Qt.MouseButton.LeftButton: self.LMB_state = False - elif event.button() == QtCore.Qt.RightButton: + elif event.button() == QtCore.Qt.MouseButton.RightButton: self.RMB_state = False - elif event.button() == QtCore.Qt.MiddleButton: + elif event.button() == QtCore.Qt.MouseButton.MiddleButton: self.MMB_state = False # hide pipe slicer. @@ -522,7 +522,7 @@ def mouseMoveEvent(self, event): path.addRect(map_rect) self._rubber_band.setGeometry(rect) self.scene().setSelectionArea( - path, QtCore.Qt.IntersectsItemShape + path, QtCore.Qt.ItemSelectionMode.IntersectsItemShape ) self.scene().update(map_rect) @@ -577,7 +577,7 @@ def wheelEvent(self, event): def dropEvent(self, event): pos = self.mapToScene(event.pos()) - event.setDropAction(QtCore.Qt.CopyAction) + event.setDropAction(QtCore.Qt.DropAction.CopyAction) self.data_dropped.emit( event.mimeData(), QtCore.QPoint(pos.x(), pos.y())) @@ -606,12 +606,12 @@ def keyPressEvent(self, event): Args: event (QtGui.QKeyEvent): key event. """ - self.ALT_state = event.modifiers() == QtCore.Qt.AltModifier - self.CTRL_state = event.modifiers() == QtCore.Qt.ControlModifier - self.SHIFT_state = event.modifiers() == QtCore.Qt.ShiftModifier + self.ALT_state = event.modifiers() == QtCore.Qt.KeyboardModifier.AltModifier + self.CTRL_state = event.modifiers() == QtCore.Qt.KeyboardModifier.ControlModifier + self.SHIFT_state = event.modifiers() == QtCore.Qt.KeyboardModifier.ShiftModifier # Todo: find a better solution to catch modifier keys. - if event.modifiers() == (QtCore.Qt.AltModifier | QtCore.Qt.ShiftModifier): + if event.modifiers() == (QtCore.Qt.KeyboardModifier.AltModifier | QtCore.Qt.KeyboardModifier.ShiftModifier): self.ALT_state = True self.SHIFT_state = True @@ -627,9 +627,9 @@ def keyReleaseEvent(self, event): Args: event (QtGui.QKeyEvent): key event. """ - self.ALT_state = event.modifiers() == QtCore.Qt.AltModifier - self.CTRL_state = event.modifiers() == QtCore.Qt.ControlModifier - self.SHIFT_state = event.modifiers() == QtCore.Qt.ShiftModifier + self.ALT_state = event.modifiers() == QtCore.Qt.KeyboardModifier.AltModifier + self.CTRL_state = event.modifiers() == QtCore.Qt.KeyboardModifier.ControlModifier + self.SHIFT_state = event.modifiers() == QtCore.Qt.KeyboardModifier.ShiftModifier super(NodeViewer, self).keyReleaseEvent(event) # --- scene events --- @@ -716,7 +716,7 @@ def sceneMousePressEvent(self, event): self._node_positions[n] = n.xy_pos # emit selected node id with LMB. - if event.button() == QtCore.Qt.LeftButton: + if event.button() == QtCore.Qt.MouseButton.LeftButton: self.node_selected.emit(node.id) if not isinstance(node, BackdropNodeItem): @@ -755,7 +755,7 @@ def sceneMouseReleaseEvent(self, event): event (QtWidgets.QGraphicsSceneMouseEvent): The event handler from the QtWidgets.QGraphicsScene """ - if event.button() != QtCore.Qt.MiddleButton: + if event.button() != QtCore.Qt.MouseButton.MiddleButton: self.apply_live_connection(event) # --- port connections --- @@ -1358,9 +1358,16 @@ def use_OpenGL(self): """ # use QOpenGLWidget instead of the deprecated QGLWidget to avoid # problems with Wayland. - import qtpy - if Qt.IsPySide2: - from PySide2.QtWidgets import QOpenGLWidget - elif Qt.IsPyQt5: - from PyQt5.QtWidgets import QOpenGLWidget - self.setViewport(QOpenGLWidget()) + + # TODO: Review this part and make sure we do not break anything + # import qtpy + # if qtpy.PYSIDE2: + # from PySide2.QtWidgets import QOpenGLWidget + # elif qtpy.PYQT5: + # from PyQt5.QtWidgets import QOpenGLWidget + # elif qtpy.PYSIDE6: + # from PySide6.QtOpenGLWidgets import QOpenGLWidget + # elif qtpy.PYQT6: + # from PyQt6.QtOpenGLWidgets import QOpenGLWidget + + self.setViewport(QtWidgets.QOpenGLWidget()) diff --git a/NodeGraphQt/widgets/viewer_nav.py b/NodeGraphQt/widgets/viewer_nav.py index 2c9fe112..25f98a80 100644 --- a/NodeGraphQt/widgets/viewer_nav.py +++ b/NodeGraphQt/widgets/viewer_nav.py @@ -27,14 +27,14 @@ def paint(self, painter, option, index): ) painter.save() - painter.setPen(QtCore.Qt.NoPen) - painter.setBrush(QtCore.Qt.NoBrush) - painter.setRenderHint(QtGui.QPainter.Antialiasing, True) + painter.setPen(QtCore.Qt.PenStyle.NoPen) + painter.setBrush(QtCore.Qt.BrushStyle.NoBrush) + painter.setRenderHint(QtGui.QPainter.RenderHint.Antialiasing, True) # background. bg_color = QtGui.QColor(*ViewerNavEnum.ITEM_COLOR.value) itm_color = QtGui.QColor(80, 128, 123) - if option.state & QtWidgets.QStyle.State_Selected: + if option.state & QtWidgets.QStyle.StateFlag.State_Selected: bg_color = bg_color.lighter(120) itm_color = QtGui.QColor(*NodeEnum.SELECTED_BORDER_COLOR.value) @@ -70,7 +70,7 @@ def paint(self, painter, option, index): # text pen_color = option.palette.text().color() pen = QtGui.QPen(pen_color, 0.5) - pen.setCapStyle(QtCore.Qt.RoundCap) + pen.setCapStyle(QtCore.Qt.PenCapStyle.RoundCap) painter.setPen(pen) font = painter.font() @@ -148,7 +148,7 @@ def add_label_item(self, label, node_id): self.model().appendRow(item) self.selectionModel().setCurrentIndex( self.model().indexFromItem(item), - QtCore.QItemSelectionModel.ClearAndSelect) + QtCore.QItemSelectionModel.SelectionFlag.ClearAndSelect) def remove_label_item(self, node_id): rows = reversed(range(1, self.model().rowCount()))