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

PySide6 support #189

Merged
merged 3 commits into from
May 20, 2024
Merged
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 .github/workflows/type-checking.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: python -m pip install . --user && python -m pip uninstall ryven --yes
working-directory: ./ryven-editor
- name: Install type-checking dependencies
run: python -m pip install mypy pyside2 types-Pygments --user
run: python -m pip install mypy pyside2 pyside6 PySide6-stubs types-Pygments --user
- name: Typecheck
run: mypy
working-directory: .
2 changes: 1 addition & 1 deletion debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
f"{RYVEN_PATH}/ryven/example_nodes/std",
f"{RYVEN_PATH}/ryven/example_nodes/linalg",
],
qt_api='pyside2',
qt_api='pyside6',
show_dialog=False,
)
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 @@ -209,7 +209,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
2 changes: 1 addition & 1 deletion ryven-editor/ryven/gui/flow_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(self, main_window, flow: Flow, flow_view: FlowView):
self.ui.inspector_dock.setWidget(self.inspector_widget)

#undo history widget
self.undo_widget = QUndoView(stack=self.flow_view._undo_stack)
self.undo_widget = QUndoView(stack=self.flow_view._undo_stack) # type: ignore
self.ui.undo_history_dock.setWidget(self.undo_widget)
# logs
self.ui.logs_scrollArea.setWidget(self.create_loggers_widget())
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
27 changes: 27 additions & 0 deletions ryven-editor/ryven/main/Ryven.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,32 @@
from ryven.main.args_parser import process_args


def check_pyside_available(qt_api: str):
if qt_api == 'pyside2':
try:
import PySide2
except ImportError:
sys.exit(
'You are trying to use PySide2 as the Qt API, but it is not available. '
'please install it, or use pyside6 as the Qt API. Either of those can '
'installed through pip, e.g. `pip install pyside2` or `pip install \'pyside6<6.7\'`. '
)
elif qt_api == 'pyside6':
try:
import PySide6
except ImportError:
sys.exit(
'You are trying to use PySide6 as the Qt API, but it is not available. '
'please install it, or use pyside2 as the Qt API. Either of those can '
'installed through pip, e.g. `pip install pyside2` or `pip install \'pyside6<6.7\'`. '
)
else:
sys.exit(
f'Error: Illegal Qt API: "{qt_api}". '
f'Use either "pyside2" or "pyside6". '
)


def run(*args_,
qt_app=None, gui_parent=None, use_sysargs: bool = True,
**kwargs):
Expand Down Expand Up @@ -72,6 +98,7 @@ def run(*args_,
#

# Init environment
check_pyside_available(conf.qt_api)
os.environ['RYVEN_MODE'] = 'gui'
os.environ['QT_API'] = conf.qt_api
from ryven.node_env import init_node_env
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 @@ -39,12 +39,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 # type: ignore

from ryvencore.Flow import Flow
from ryvencore.Node import Node
from ryvencore.NodePort import NodePort, NodeInput, NodeOutput
Expand Down Expand Up @@ -262,13 +267,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 @@ -514,13 +517,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
1 change: 0 additions & 1 deletion ryvencore-qt/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ include_package_data = True
python_requires = >=3.6, <3.11
install_requires =
ryvencore ==0.4.*
PySide2
QtPy
waiting
textdistance
Loading