Skip to content

AppBridge

plantimager.controller.AppBridge Link

AppBridge Link

AppBridge(parent=None)

Bases: QObject

Singleton class which is the main bridge of the application.

AppBridge is a shared object accessible across the application. It initializes the zmq context and a device registry. When a new device is registered it creates the appropriate bridge for the application.

Attributes:

Name Type Description
context Context

Unique ZMQ context of the application.

registry DeviceRegistry

Device registry of the application.

device_list list[str]

List of device names.

device_bridges list[CameraBridge]

List of camera bridges.

Source code in plantimager/controller/AppBridge.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def __init__(self, parent=None):
    super().__init__(parent)
    self.context = zmq.Context()
    self.registry = deviceregistry.DeviceRegistry(context=self.context)
    # /!\ callback will be executed in registry thread
    # callback will only emit a signal
    # connection must be queued so that the slot is executed in the main thread
    self.registry.add_new_device_callback(self._new_device_callback)
    self.registry.add_device_removed_callback(self._remove_device_callback)
    self.registry.daemon = True
    self._registryNewDevice.connect(self._create_new_device, Qt.ConnectionType.QueuedConnection)
    self._registryRemoveDevice.connect(self._remove_device, Qt.ConnectionType.QueuedConnection)
    finalize(self, self._stop)
    self.device_list: list[str] = []
    self.device_bridges: list[CameraBridge] = []

    self._currentCamera = CameraBridge("", "", self.context)
    self._scanner = Scanner()

    self._controller_server = RPCControllerServer(self.context, "tcp://localhost:14567", self._scanner)
    self.scannerChanged.connect(self._controller_server.handle_scanner_changed)
    self._controller_thread = Thread(target=self._controller_server.serve_forever, name="RPCControllerServer")
    self._controller_thread.daemon = True
    self._controller_thread.start()

    self.registry.start()

getCameraBridgeAtIndex Link

getCameraBridgeAtIndex(index)

(Slot) Returns the camera bridge at a given index.

Parameters:

Name Type Description Default
index int

Index of the camera bridge.

required

Returns:

Type Description
CameraBridge
Source code in plantimager/controller/AppBridge.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
@Slot(int, result=CameraBridge)
def getCameraBridgeAtIndex(self, index: int) -> CameraBridge:
    """
    (Slot) Returns the camera bridge at a given index.
    Parameters
    ----------
    index: int
        Index of the camera bridge.

    Returns
    -------
    CameraBridge
    """
    return self.device_bridges[index]

reboot_host Link

reboot_host()

Reboots the host.

Source code in plantimager/controller/AppBridge.py
202
203
204
205
@Slot()
def reboot_host(self):
    """Reboots the host."""
    subprocess.run(["reboot"])

restart_app Link

restart_app()

Reboots the app.

Source code in plantimager/controller/AppBridge.py
207
208
209
210
@Slot()
def restart_app(self):
    """Reboots the app."""
    subprocess.run(["systemctl", "--user", "restart", "plant-imager-app.service"])

shutdown_host Link

shutdown_host()

Shuts down the host.

Source code in plantimager/controller/AppBridge.py
197
198
199
200
@Slot()
def shutdown_host(self):
    """Shuts down the host."""
    subprocess.run(["poweroff"])