aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-05-05 16:44:38 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-05-09 18:01:17 +0000
commit69830ed595bfe50686a3d6934e2df69ba4ea4989 (patch)
treed280a21581ac71629e9bb9915403ca0cd7cfd43f
parent44993bcaca283ce6896f7c7cdb97a2e0176368be (diff)
Bluetooth/Heartrate game example: Fix the simulator CLI option
For some reason, a global variable from the heartrate_global module does not work. Replace it by functions. Task-number: PYSIDE-2206 Change-Id: I3ae587a912ab33ab8c88785bed759bcf8bb79261 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> (cherry picked from commit 721c944f649ac8e3e94fcc028035a35c6dd5ff8c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--examples/bluetooth/heartrate_game/connectionhandler.py2
-rw-r--r--examples/bluetooth/heartrate_game/devicefinder.py8
-rw-r--r--examples/bluetooth/heartrate_game/devicehandler.py6
-rw-r--r--examples/bluetooth/heartrate_game/deviceinfo.py4
-rw-r--r--examples/bluetooth/heartrate_game/heartrate_global.py13
-rw-r--r--examples/bluetooth/heartrate_game/main.py4
6 files changed, 24 insertions, 13 deletions
diff --git a/examples/bluetooth/heartrate_game/connectionhandler.py b/examples/bluetooth/heartrate_game/connectionhandler.py
index f631ecdb3..e8734153e 100644
--- a/examples/bluetooth/heartrate_game/connectionhandler.py
+++ b/examples/bluetooth/heartrate_game/connectionhandler.py
@@ -29,7 +29,7 @@ class ConnectionHandler(QObject):
def alive(self):
if sys.platform == "darwin":
return True
- if simulator:
+ if simulator():
return True
return (self.m_localDevice.isValid()
and self.m_localDevice.hostMode() != QBluetoothLocalDevice.HostPoweredOff)
diff --git a/examples/bluetooth/heartrate_game/devicefinder.py b/examples/bluetooth/heartrate_game/devicefinder.py
index 7bb9cb20b..283897f28 100644
--- a/examples/bluetooth/heartrate_game/devicefinder.py
+++ b/examples/bluetooth/heartrate_game/devicefinder.py
@@ -36,7 +36,7 @@ class DeviceFinder(BluetoothBaseClass):
self.m_deviceDiscoveryAgent.finished.connect(self.scanFinished)
self.m_deviceDiscoveryAgent.canceled.connect(self.scanFinished)
#! [devicediscovery-1]
- if simulator:
+ if simulator():
self.m_demoTimer.setSingleShot(True)
self.m_demoTimer.setInterval(2000)
self.m_demoTimer.timeout.connect(self.scanFinished)
@@ -49,7 +49,7 @@ class DeviceFinder(BluetoothBaseClass):
self.devicesChanged.emit()
- if simulator:
+ if simulator():
self.m_demoTimer.start()
else:
#! [devicediscovery-2]
@@ -82,7 +82,7 @@ class DeviceFinder(BluetoothBaseClass):
@Slot()
def scanFinished(self):
- if simulator:
+ if simulator():
# Only for testing
for i in range(5):
self.m_devices.append(DeviceInfo(QBluetoothDeviceInfo()))
@@ -113,7 +113,7 @@ class DeviceFinder(BluetoothBaseClass):
@Property(bool, notify=scanningChanged)
def scanning(self):
- if simulator:
+ if simulator():
return self.m_demoTimer.isActive()
return self.m_deviceDiscoveryAgent.isActive()
diff --git a/examples/bluetooth/heartrate_game/devicehandler.py b/examples/bluetooth/heartrate_game/devicehandler.py
index 31f31a1bf..aa8f96b16 100644
--- a/examples/bluetooth/heartrate_game/devicehandler.py
+++ b/examples/bluetooth/heartrate_game/devicehandler.py
@@ -62,7 +62,7 @@ class DeviceHandler(BluetoothBaseClass):
self.m_demoTimer = QTimer()
- if simulator:
+ if simulator():
self.m_demoTimer.setSingleShot(False)
self.m_demoTimer.setInterval(2000)
self.m_demoTimer.timeout.connect(self.updateDemoHR)
@@ -99,7 +99,7 @@ class DeviceHandler(BluetoothBaseClass):
self.clearMessages()
self.m_currentDevice = device
- if simulator:
+ if simulator():
self.info = "Demo device connected."
return
@@ -259,7 +259,7 @@ class DeviceHandler(BluetoothBaseClass):
@Property(bool, notify=aliveChanged)
def alive(self):
- if simulator:
+ if simulator():
return True
if self.m_service:
return self.m_service.state() == QLowEnergyService.RemoteServiceDiscovered
diff --git a/examples/bluetooth/heartrate_game/deviceinfo.py b/examples/bluetooth/heartrate_game/deviceinfo.py
index 4ea08628f..5fd5c3270 100644
--- a/examples/bluetooth/heartrate_game/deviceinfo.py
+++ b/examples/bluetooth/heartrate_game/deviceinfo.py
@@ -25,13 +25,13 @@ class DeviceInfo(QObject):
@Property(str, notify=deviceChanged)
def deviceName(self):
- if simulator:
+ if simulator():
return "Demo device"
return self.m_device.name()
@Property(str, notify=deviceChanged)
def deviceAddress(self):
- if simulator:
+ if simulator():
return "00:11:22:33:44:55"
if sys.platform == "Darwin": # workaround for Core Bluetooth:
return self.m_device.deviceUuid().toString()
diff --git a/examples/bluetooth/heartrate_game/heartrate_global.py b/examples/bluetooth/heartrate_game/heartrate_global.py
index 7d95f1299..ada5d5cb1 100644
--- a/examples/bluetooth/heartrate_game/heartrate_global.py
+++ b/examples/bluetooth/heartrate_game/heartrate_global.py
@@ -3,4 +3,15 @@
import sys
-simulator = sys.platform == "win32"
+
+_simulator = sys.platform == "win32"
+
+
+def simulator():
+ global _simulator
+ return _simulator
+
+
+def set_simulator(s):
+ global _simulator
+ _simulator = s
diff --git a/examples/bluetooth/heartrate_game/main.py b/examples/bluetooth/heartrate_game/main.py
index 684d7dbca..fb135d8dc 100644
--- a/examples/bluetooth/heartrate_game/main.py
+++ b/examples/bluetooth/heartrate_game/main.py
@@ -14,7 +14,7 @@ from PySide6.QtCore import QCoreApplication, QLoggingCategory
from connectionhandler import ConnectionHandler
from devicefinder import DeviceFinder
from devicehandler import DeviceHandler
-from heartrate_global import simulator
+from heartrate_global import set_simulator
if __name__ == '__main__':
@@ -26,7 +26,7 @@ if __name__ == '__main__':
parser.add_argument("-s", "--simulator", action="store_true",
help="Use Simulator")
options = parser.parse_args()
- simulator = options.simulator
+ set_simulator(options.simulator)
if options.verbose:
QLoggingCategory.setFilterRules("qt.bluetooth* = true")