aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2024-01-26 13:39:41 +0100
committerShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2024-02-26 11:30:44 +0100
commit6b8ca656b9c41a8f247047fa24e6cdb028423354 (patch)
treed8c9ff32773772e77832e61b58097955d8817f03
parentb5140977291be15951b723ba58379b3d7c54df70 (diff)
Examples: adapt to consider permission API on macOS
- When Python is run in interpreter mode, we print and exist with a message. Pick-to: 6.5 6.6 Task-number: PYSIDE-2468 Change-Id: I79ce06eb2b96418fc2f84c11cccbd2e72207f3c1 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r--examples/bluetooth/heartrate_game/connectionhandler.py7
-rw-r--r--examples/bluetooth/heartrate_game/devicefinder.py8
-rw-r--r--examples/bluetooth/heartrate_game/heartrate_global.py13
-rw-r--r--examples/multimedia/audiosource/audiosource.py10
-rw-r--r--examples/multimedia/camera/camera.py14
5 files changed, 41 insertions, 11 deletions
diff --git a/examples/bluetooth/heartrate_game/connectionhandler.py b/examples/bluetooth/heartrate_game/connectionhandler.py
index 421446c8e..7bf60bbc5 100644
--- a/examples/bluetooth/heartrate_game/connectionhandler.py
+++ b/examples/bluetooth/heartrate_game/connectionhandler.py
@@ -7,9 +7,9 @@ from PySide6.QtBluetooth import QBluetoothLocalDevice
from PySide6.QtQml import QmlElement
from PySide6.QtCore import QObject, Property, Signal, Slot, Qt
-from heartrate_global import simulator, is_android
+from heartrate_global import simulator, is_android, error_not_nuitka
-if is_android:
+if is_android or sys.platform == "darwin":
from PySide6.QtCore import QBluetoothPermission
# To be used on the @QmlElement decorator
@@ -58,7 +58,8 @@ class ConnectionHandler(QObject):
self.deviceChanged.emit()
def initLocalDevice(self):
- if is_android:
+ if is_android or sys.platform == "darwin":
+ error_not_nuitka()
permission = QBluetoothPermission()
permission.setCommunicationModes(QBluetoothPermission.Access)
permission_status = qApp.checkPermission(permission) # noqa: F821
diff --git a/examples/bluetooth/heartrate_game/devicefinder.py b/examples/bluetooth/heartrate_game/devicefinder.py
index 5cabd1b5b..e581d12ec 100644
--- a/examples/bluetooth/heartrate_game/devicefinder.py
+++ b/examples/bluetooth/heartrate_game/devicefinder.py
@@ -1,5 +1,6 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+import sys
from PySide6.QtBluetooth import (QBluetoothDeviceDiscoveryAgent,
QBluetoothDeviceInfo)
@@ -8,9 +9,9 @@ from PySide6.QtCore import QTimer, Property, Signal, Slot, Qt
from bluetoothbaseclass import BluetoothBaseClass
from deviceinfo import DeviceInfo
-from heartrate_global import simulator, is_android
+from heartrate_global import simulator, is_android, error_not_nuitka
-if is_android:
+if is_android or sys.platform == "darwin":
from PySide6.QtCore import QBluetoothPermission
# To be used on the @QmlElement decorator
@@ -46,7 +47,8 @@ class DeviceFinder(BluetoothBaseClass):
@Slot()
def startSearch(self):
- if is_android:
+ if is_android or sys.platform == "darwin":
+ error_not_nuitka()
permission = QBluetoothPermission()
permission.setCommunicationModes(QBluetoothPermission.Access)
permission_status = qApp.checkPermission(permission) # noqa: F821
diff --git a/examples/bluetooth/heartrate_game/heartrate_global.py b/examples/bluetooth/heartrate_game/heartrate_global.py
index 584c44d21..de5c37ac3 100644
--- a/examples/bluetooth/heartrate_game/heartrate_global.py
+++ b/examples/bluetooth/heartrate_game/heartrate_global.py
@@ -1,7 +1,7 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import os
-
+import sys
_simulator = False
@@ -17,3 +17,14 @@ def set_simulator(s):
is_android = os.environ.get('ANDROID_ARGUMENT')
+
+
+def error_not_nuitka():
+ """Errors and exits for macOS if run in interpreted mode.
+ """
+ is_nuitka = "__compiled__" in globals()
+ if not is_nuitka and sys.platform == "darwin":
+ print("This example does not work on macOS when Python is run in interpreted mode."
+ "For this example to work on macOS, package the example using pyside6-deploy"
+ "For more information, read `Notes for Developer` in the documentation")
+ sys.exit(0)
diff --git a/examples/multimedia/audiosource/audiosource.py b/examples/multimedia/audiosource/audiosource.py
index bc2d606c0..a78beb584 100644
--- a/examples/multimedia/audiosource/audiosource.py
+++ b/examples/multimedia/audiosource/audiosource.py
@@ -25,7 +25,7 @@ from PySide6.QtWidgets import (QApplication, QComboBox, QPushButton, QSlider, QV
is_android = os.environ.get('ANDROID_ARGUMENT')
-if is_android:
+if is_android or sys.platform == "darwin":
from PySide6.QtCore import QMicrophonePermission
@@ -93,7 +93,13 @@ class InputTest(QWidget):
@Slot()
def initialize(self):
- if is_android:
+ if is_android or sys.platform == "darwin":
+ is_nuitka = "__compiled__" in globals()
+ if not is_nuitka and sys.platform == "darwin":
+ print("This example does not work on macOS when Python is run in interpreted mode."
+ "For this example to work on macOS, package the example using pyside6-deploy"
+ "For more information, read `Notes for Developer` in the documentation")
+ sys.exit(0)
permission = QMicrophonePermission()
permission_status = qApp.checkPermission(permission) # noqa: F821
if permission_status == Qt.PermissionStatus.Undetermined:
diff --git a/examples/multimedia/camera/camera.py b/examples/multimedia/camera/camera.py
index f66f28a21..fa379c807 100644
--- a/examples/multimedia/camera/camera.py
+++ b/examples/multimedia/camera/camera.py
@@ -2,6 +2,7 @@
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import os
+import sys
from pathlib import Path
from PySide6.QtMultimedia import (QAudioInput, QCamera, QCameraDevice,
@@ -16,8 +17,10 @@ from metadatadialog import MetaDataDialog
from imagesettings import ImageSettings
from videosettings import VideoSettings, is_android
-if is_android:
+if is_android or sys.platform == "darwin":
from PySide6.QtCore import QMicrophonePermission, QCameraPermission
+
+if is_android:
from ui_camera_mobile import Ui_Camera
else:
from ui_camera import Ui_Camera
@@ -60,7 +63,14 @@ class Camera(QMainWindow):
@Slot()
def initialize(self):
- if is_android:
+ if is_android or sys.platform == "darwin":
+ is_nuitka = "__compiled__" in globals()
+ if not is_nuitka and sys.platform == "darwin":
+ print("This example does not work on macOS when Python is run in interpreted mode."
+ "For this example to work on macOS, package the example using pyside6-deploy"
+ "For more information, read `Notes for Developer` in the documentation")
+ sys.exit(0)
+
# camera
cam_permission = QCameraPermission()
cam_permission_status = qApp.checkPermission(cam_permission) # noqa: F821