Skip to content

backend.py

This is the backend for the BackendAction. It's gets called by the following code of the BackendAction:

BackendAction.py (partial)
backend_path = os.path.join(os.path.dirname(__file__), "backend.py")
self.launch_backend(backend_path=backend_path)

backend.py itself looks like this:

backend.py
from streamcontroller_plugin_tools import BackendBase

import Pyro5.api

import time
import random

@Pyro5.api.expose
class Backend(BackendBase):
    def __init__(self):
        super().__init__()

    def get_number(self):
        return str(random.randint(0, 42))

if __name__ == "__main__":
    backend = Backend()

Pyro5

If you are working with dedicated backends like this one it it important to understand that if will be executed in a completely dedicated python process. This means no normal communication or imports of any StreamController and action modules will be possible.
Instead the communication is done via Pyro5.

Read more in BackendAction#Pyro5.

Let's go over the code:

BackendBase

from streamcontroller_plugin_tools import BackendBase
This imports the BackendBase from streamcontroller_plugin_tools which is the base class for all backends. It will handle automatically connect to the action if launched from it.

get_number()

def get_number(self):
    return str(random.randint(0, 42))
This method returns a random number between 0 and 42 for testing purposes. It will be called by the action on the key_down_event.