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

Moving to qtpy #327

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 3 additions & 3 deletions NodeGraphQt/base/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import re

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

from NodeGraphQt.base.commands import (NodeAddedCmd,
NodeRemovedCmd,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions NodeGraphQt/base/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
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 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.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(
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 @@ -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)
Expand All @@ -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)
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 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(self.ExtendedSelection)
self.setDragDropMode(QtWidgets.QAbstractItemView.DragDropMode.DragOnly)
self.setSelectionMode(self.SelectionMode.ExtendedSelection)
self.setHeaderHidden(True)
self.setWindowTitle('Nodes')

Expand Down Expand Up @@ -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)
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 All @@ -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)
Expand Down Expand Up @@ -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]
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,5 +1,5 @@
#!/usr/bin/python
from Qt import QtWidgets, QtCore, QtGui
from qtpy import QtWidgets, QtCore, QtGui


class _NumberValueMenu(QtWidgets.QMenu):
Expand Down Expand Up @@ -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())
Expand All @@ -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
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
26 changes: 13 additions & 13 deletions NodeGraphQt/custom_widgets/properties_bin/node_property_widgets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
from collections import defaultdict

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

from .node_property_factory import NodePropertyWidgetFactory
from .prop_widgets_base import PropLineEdit
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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)
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


class BaseProperty(QtWidgets.QWidget):
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


class PropLabel(QtWidgets.QLabel):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
Loading