コード例 #1
0
class ConditionalRunner:
    def __init__(self, template):
        template_str = "".join(template)
        self._template = env.from_string(template_str)
        self._ae = GlobalStorage().aircraft_events
        self._aq = GlobalStorage().aircraft_requests

    def get_simvar_value(self, name: str):
        value = self._aq.get(name)
        return value

    def set_simvar_value(self, name: str, value):
        self._aq.set(name, value)

    def trigger_event(self, name: str, value):
        self._ae.find(name)(int(value))

    @staticmethod
    def trigger_encoder_alternate(index: int, value: bool):
        GlobalStorage().encoders[index - 1].on_alternate(value)

    def execute(self):
        self._template.render(data=self)

    def __call__(self, *args, **kwargs):
        self.execute()
コード例 #2
0
class ConditionalRunner:
    def __init__(self, template):
        self._template_str = "".join(template)
        self._template = env.from_string(self._template_str)
        self._ae = GlobalStorage().aircraft_events
        self._aq = GlobalStorage().aircraft_requests

    def get_simvar_value(self, name: str):
        value = self._aq.get(name)
        return value

    def set_simvar_value(self, name: str, value):
        self._aq.set(name, value)

    def trigger_event(self, name: str, value):
        self._ae.find(name)(int(value))

    @staticmethod
    def trigger_encoder_alternate(index: int, value: bool):
        GlobalStorage().encoders[index - 1].on_alternate(value)

    @staticmethod
    def set_global_variable(key: str, value):
        GlobalStorage().set_global_variable(key, value)

    @staticmethod
    def get_global_variable(key: str):
        return GlobalStorage().get_global_variable(key)

    @staticmethod
    def print(data):
        print(data)

    @staticmethod
    def set_button_led(index: int, on: bool, blink=False):
        GlobalStorage().buttons[index - 1].set_led_on_off(on, blink)

    @staticmethod
    def set_encoder_led(index: int, on: bool, blink=False):
        GlobalStorage().encoders[index - 1].set_led_ring_on_off(on, blink)

    @staticmethod
    def set_encoder_led_value(index: int, value: int, blink=False):
        GlobalStorage().encoders[index - 1].set_led_ring_value(
            int(value), blink)

    def execute(self):
        try:
            self._template.render(data=self)
        except Exception as e:
            print('Exception during execution of template:', e)
            print('For template:', self._template_str)

    def __call__(self, *args, **kwargs):
        self.execute()
コード例 #3
0
class SingleEvent:
    def __init__(self, event_name, event_type="auto", value=0):
        self._event_name = event_name
        self._event_type = event_type
        self._value = value
        self._ae = GlobalStorage().aircraft_events
        self._aq = GlobalStorage().aircraft_requests
        self._event = None

        if event_type == "manual":
            self._event = Event(event_name.encode(),
                                self._ae.sm)  # manual event with forced value
        elif event_type == "condition":
            self._event = ConditionalRunner(event_name)
        elif event_type == "condition-file":
            self._event = ConditionalRunner("", event_name)
        else:
            self._event = self._ae.find(event_name)  # auto find event
            if self._event is None:
                print(
                    f"WARNING: Event {event_name}, was not found in simconnect list. Using a manual binding"
                )
                self._event = Event(event_name.encode(), self._ae.sm)

    def __call__(self, value=0):
        if self._event_type == "manual":
            self._event(self._value)
        else:
            self._event(value)
コード例 #4
0
class SingleEvent:
    def __init__(self, event_name, event_type="auto", value=0):
        self._event_name = event_name
        self._event_type = event_type
        self._value = value
        self._ae = GlobalStorage().aircraft_events
        self._aq = GlobalStorage().aircraft_requests
        self._event = None

        if event_type == "manual":
            self._event = Event(event_name.encode(), self._ae.sm)  # manual event with forced value
        elif event_type == "condition":
            self._event = ConditionalRunner(event_name)
        else:
            self._event = self._ae.find(event_name)  # auto find event

    def __call__(self, value=0):
        if self._event_type == "manual":
            self._event(self._value)
        else:
            self._event(value)