Skip to content

Commit

Permalink
minor pyside6 compatibility changes
Browse files Browse the repository at this point in the history
  • Loading branch information
HeftyCoder authored and leon-thomm committed May 18, 2024
1 parent bf677ca commit bc6249b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion ryven-editor/ryven/example_nodes/std/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def rebuild_remove_actions(self):
{'method': self.remove_output, 'data': i}


class ButtonNode_MainWidget(QPushButton, NodeMainWidget):
class ButtonNode_MainWidget(NodeMainWidget, QPushButton):

def __init__(self, params):
NodeMainWidget.__init__(self, params)
Expand Down
6 changes: 4 additions & 2 deletions ryven-editor/ryven/gui/startup_dialog/StartupDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def minimumSizeHint(self):

def sizeHint(self):
hint = self.fontMetrics().boundingRect(self.text()).size()
l, t, r, b = self.getContentsMargins()
c_margins = self.contentsMargins()
l, t, r, b = c_margins.left(), c_margins.top(), c_margins.right(), c_margins.bottom()
margin = self.margin() * 2
return QSize(
min(100, hint.width()) + l + r + margin,
Expand All @@ -83,7 +84,8 @@ def paintEvent(self, event):
opt = QStyleOptionFrame()
self.initStyleOption(opt)
self.style().drawControl(QStyle.CE_ShapedFrame, opt, qp, self)
l, t, r, b = self.getContentsMargins()
c_margins = self.contentsMargins()
l, t, r, b = c_margins.left(), c_margins.top(), c_margins.right(), c_margins.bottom()
margin = self.margin()
try:
# since Qt >= 5.11
Expand Down
31 changes: 18 additions & 13 deletions ryvencore-qt/ryvencore_qt/src/flows/FlowView.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@
QShortcut,
QMenu,
QGraphicsItem,
QUndoStack,
QPushButton,
QHBoxLayout,
QWidget,
)

# for compatibility between qt5 and qt6
try:
from qtpy.QtGui import QUndoStack
except ImportError:
from qtpy.QtWidgets import QUndoStack

from ryvencore.Flow import Flow
from ryvencore.Node import Node
from ryvencore.NodePort import NodePort, NodeInput, NodeOutput
Expand Down Expand Up @@ -254,13 +259,11 @@ def init_proxy_widget(widget: QWidget, proxy: FlowViewProxyWidget):
menu_layout_widget.layout().addWidget(menu_button)

def menu_button_clicked():
point = self._menu_layout_proxy.scenePos()
view_pos = self.mapFromScene(point.toPoint())
# apply offset after
global_pos = self.viewport().mapToGlobal(
view_pos) + QPoint(8, self._menu_layout_proxy.widget().height()
)
self._menu.exec_(global_pos)
# prob not entirely correct, since menu is part of a layout
# but since it's the first item, it's the same
menu_pos = self._menu_button.pos()
menu_pos = self.mapToGlobal(menu_pos) + QPoint(8, self._menu_button.height() + 10)
self._menu.exec_(menu_pos)

menu_button.clicked.connect(menu_button_clicked)

Expand Down Expand Up @@ -506,13 +509,15 @@ def wheelEvent(self, event):
if event.modifiers() & Qt.ControlModifier:
event.accept()

self._zoom_data['viewport pos'] = event.posF()
self._zoom_data['scene pos'] = pointF_mapped(self.mapToScene(event.pos()), event.posF())
view_pos = event.position()
self._zoom_data['viewport pos'] = view_pos
self._zoom_data['scene pos'] = self.mapToScene(view_pos.toPoint())

self._zoom_data['delta'] += event.delta()
y_delta = event.angleDelta().y()
self._zoom_data['delta'] += y_delta

if self._zoom_data['delta'] * event.delta() < 0:
self._zoom_data['delta'] = event.delta()
if self._zoom_data['delta'] * y_delta < 0:
self._zoom_data['delta'] = y_delta()

anim = QTimeLine(100, self)
anim.setUpdateInterval(10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ def search_pkg_tree(self, search: str):
# removes whitespace and escapes all special regex chars
new_search = escape(search.strip())
# regex that enforces the text starts with <new_search>
self.pack_proxy_model.setFilterRegExp(f'^{new_search}')
self.pack_proxy_model.setFilterRegularExpression(f'^{new_search}')
self.pack_tree.expandAll()
else:
self.pack_proxy_model.setFilterRegExp('')
self.pack_proxy_model.setFilterRegularExpression('')
self.pack_tree.collapseAll()

def make_nodes_current(self, pack_nodes, pkg_name: str):
Expand Down

0 comments on commit bc6249b

Please sign in to comment.