Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebase #327 and continue migration to PySide6/PyQt6 using qtpy compat layer #420

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# virtual enviroment
env/*
venv/*
venv/
.venv*/

# sphinx documentation
docs/_build/
Expand Down
2 changes: 1 addition & 1 deletion NodeGraphQt/base/commands.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python
from Qt import QtWidgets
from qtpy import QtWidgets

from NodeGraphQt.constants import PortTypeEnum

Expand Down
8 changes: 4 additions & 4 deletions NodeGraphQt/base/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re
from pathlib import Path

from Qt import QtCore, QtWidgets
from qtpy import QtCore, QtWidgets, QtGui

from NodeGraphQt.base.commands import (NodeAddedCmd,
NodesRemovedCmd,
Expand Down Expand Up @@ -151,7 +151,7 @@ def __init__(self, parent=None, **kwargs):
kwargs.get('node_factory') or NodeFactory())
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
self._sub_graphs = {}
Expand Down Expand Up @@ -521,8 +521,8 @@ def widget(self):
# hide the close button on the first tab.
tab_bar = self._widget.tabBar()
tab_flags = [
QtWidgets.QTabBar.RightSide,
QtWidgets.QTabBar.LeftSide
QtWidgets.QTabBar.ButtonPosition.RightSide,
QtWidgets.QTabBar.ButtonPosition.LeftSide
]
for btn_flag in tab_flags:
tab_btn = tab_bar.tabButton(0, btn_flag)
Expand Down
12 changes: 4 additions & 8 deletions NodeGraphQt/base/menu.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/python
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
Expand Down Expand Up @@ -120,10 +119,10 @@ def _set_shortcut(action, shortcut):
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)

Expand All @@ -141,8 +140,7 @@ def add_command(self, name, func=None, shortcut=None):
"""
action = GraphAction(name, self._graph.viewer())
action.graph = self._graph
if LooseVersion(QtCore.qVersion()) >= LooseVersion('5.10'):
action.setShortcutVisibleInContextMenu(True)
action.setShortcutVisibleInContextMenu(True)

if shortcut:
self._set_shortcut(action, shortcut)
Expand Down Expand Up @@ -218,8 +216,6 @@ def add_command(self, name, func=None, node_type=None, node_class=None,

action = NodeAction(name, self._graph.viewer())
action.graph = self._graph
if LooseVersion(QtCore.qVersion()) >= LooseVersion('5.10'):
action.setShortcutVisibleInContextMenu(True)

if shortcut:
self._set_shortcut(action, shortcut)
Expand Down
2 changes: 1 addition & 1 deletion NodeGraphQt/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions NodeGraphQt/custom_widgets/nodes_palette.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 MIME_TYPE, URN_SCHEME

Expand Down Expand Up @@ -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()
Expand All @@ -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.drawRoundedRect(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(
Expand Down Expand Up @@ -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()
Expand All @@ -123,7 +123,7 @@ def __init__(self, parent=None):

def mimeData(self, indexes, p_int=None):
node_ids = [
'node:{}'.format(i.data(QtCore.Qt.ToolTipRole))
'node:{}'.format(i.data(QtCore.Qt.ItemDataRole.ToolTipRole))
for i in indexes
]
node_urn = URN_SCHEME + ';'.join(node_ids)
Expand All @@ -136,11 +136,11 @@ class NodesGridView(QtWidgets.QListView):

def __init__(self, parent=None):
super(NodesGridView, self).__init__(parent)
self.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
self.setSelectionMode(QtWidgets.QAbstractItemView.SelectionMode.ExtendedSelection)
self.setUniformItemSizes(True)
self.setResizeMode(QtWidgets.QListView.Adjust)
self.setViewMode(QtWidgets.QListView.IconMode)
self.setDragDropMode(QtWidgets.QListView.DragOnly)
self.setResizeMode(QtWidgets.QListView.ResizeMode.Adjust)
self.setViewMode(QtWidgets.QListView.ViewMode.IconMode)
self.setDragDropMode(QtWidgets.QListView.DragDropMode.DragOnly)
self.setDragEnabled(True)
self.setMinimumSize(300, 100)
self.setSpacing(4)
Expand Down
8 changes: 4 additions & 4 deletions NodeGraphQt/custom_widgets/nodes_tree.py
Original file line number Diff line number Diff line change
@@ -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 MIME_TYPE, URN_SCHEME

Expand Down Expand Up @@ -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(QtWidgets.QAbstractItemView.ExtendedSelection)
self.setDragDropMode(QtWidgets.QAbstractItemView.DragDropMode.DragOnly)
self.setSelectionMode(QtWidgets.QAbstractItemView.SelectionMode.ExtendedSelection)
self.setHeaderHidden(True)
self.setWindowTitle('Nodes')

Expand Down Expand Up @@ -93,7 +93,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.setSizeHint(0, QtCore.QSize(100, 26))
self.addTopLevelItem(cat_item)
cat_item.setExpanded(True)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -27,8 +27,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)
Expand Down Expand Up @@ -99,8 +99,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]
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python
from Qt import QtWidgets, QtCore
from qtpy import QtWidgets, QtCore

from .prop_widgets_abstract import BaseProperty

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
import re

from Qt import QtWidgets, QtCore, QtGui
from qtpy import QtWidgets, QtCore, QtGui

_NUMB_REGEX = re.compile(r'^((?:\-)*\d+)*([\.,])*(\d+(?:[eE](?:[\-\+])*\d+)*)*')

Expand Down Expand Up @@ -122,7 +122,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())
Expand All @@ -135,9 +135,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
Expand Down Expand Up @@ -192,14 +192,14 @@ def set_data_type(self, data_type):
"""
self._data_type = data_type
if data_type is int:
regexp = QtCore.QRegExp(r'\d+')
validator = QtGui.QRegExpValidator(regexp, self)
regexp = QtCore.QRegularExpression(r'\d+')
validator = QtGui.QRegularExpressionValidator(regexp, self)
steps = [1, 10, 100, 1000]
self._min = None if self._min is None else int(self._min)
self._max = None if self._max is None else int(self._max)
elif data_type is float:
regexp = QtCore.QRegExp(r'\d+[\.,]\d+(?:[eE](?:[\-\+]|)\d+)*')
validator = QtGui.QRegExpValidator(regexp, self)
regexp = QtCore.QRegularExpression(r'\d+[\.,]\d+(?:[eE](?:[\-\+]|)\d+)*')
validator = QtGui.QRegularExpressionValidator(regexp, self)
steps = [0.001, 0.01, 0.1, 1]
self._min = None if self._min is None else float(self._min)
self._max = None if self._max is None else float(self._max)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading