Skip to content

Commit

Permalink
SG-30534: First step to supporting PySide6 (#898)
Browse files Browse the repository at this point in the history
* First step to supporting PySide6.

* Provide a patch for PySide6 to work using the PySide (Qt4) interface
* Create a new qt6 module to import PySide6 directly (unpatched)
* Next step, deprecate PySide/Qt4 and make PySide6/Qt6 the default base

* Black style
  • Loading branch information
staceyoue committed Jul 6, 2023
1 parent 9a3cf8f commit 07e0d88
Show file tree
Hide file tree
Showing 4 changed files with 615 additions and 7 deletions.
28 changes: 28 additions & 0 deletions python/tank/platform/engine.py
Expand Up @@ -49,6 +49,7 @@
from . import events
from . import qt
from . import qt5
from . import qt6
from .bundle import TankBundle
from .framework import setup_frameworks
from .engine_logging import ToolkitEngineHandler, ToolkitEngineLegacyHandler
Expand Down Expand Up @@ -92,6 +93,7 @@ def __init__(self, tk, context, engine_instance_name, env):
self.__created_qt_dialogs = []
self.__qt_debug_info = {}
self.__has_qt5 = False
self.__has_qt6 = False

self.__commands_that_need_prefixing = []

Expand Down Expand Up @@ -179,6 +181,11 @@ def __init__(self, tk, context, engine_instance_name, env):
for name, value in qt5_base.items():
setattr(qt5, name, value)

qt6_base = self.__define_qt6_base()
self.__has_qt6 = len(qt6_base) > 0
for name, value in qt6_base.items():
setattr(qt6, name, value)

# Update the authentication module to use the engine's Qt.
# @todo: can this import be untangled? Code references internal part of the auth module
from ..authentication.ui import qt_abstraction
Expand Down Expand Up @@ -623,6 +630,16 @@ def has_qt5(self):
"""
return self.__has_qt5

@property
def has_qt6(self):
"""
Indicates that the host application has access to Qt 6 and that the ``sgtk.platform.qt6`` module
has been populated with the Qt 6 modules and information.
:returns bool: boolean value indicating if Qt 6 is available.
"""
return self.__has_qt6

@property
def has_qt4(self):
"""
Expand Down Expand Up @@ -2167,6 +2184,17 @@ def __define_qt5_base(self):
"""
return QtImporter(interface_version_requested=QtImporter.QT5).base

def __define_qt6_base(self):
"""
This will be called at initialization to discover every PySide6 module. It should provide
every Qt modules available as well as two extra attributes, ``__name__`` and
``__version__``, which refer to the name of the binding and it's version, e.g.
PySide6 and 6.2.7
:returns: A dictionary with all the modules, __version__ and __name__.
"""
return QtImporter(interface_version_requested=QtImporter.QT6).base

def _initialize_dark_look_and_feel(self):
"""
Initializes a standard toolkit look and feel using a combination of
Expand Down
12 changes: 12 additions & 0 deletions python/tank/platform/qt6/__init__.py
@@ -0,0 +1,12 @@
# Copyright (c) 2016 Shotgun Software Inc.
#
# CONFIDENTIAL AND PROPRIETARY
#
# This work is provided "AS IS" and subject to the Shotgun Pipeline Toolkit
# Source Code License included in this distribution package. See LICENSE.
# By accessing, using, copying or modifying this work you indicate your
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.

# This module will be populated during engine initialization with modules available for Qt 6 if
# PySide6 is accessible.

1 comment on commit 07e0d88

@halil3d
Copy link

@halil3d halil3d commented on 07e0d88 Jul 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance to also integrate #815 for PyQt5?

Please sign in to comment.