|
| 1 | +# Import StreamController modules |
| 2 | +from gi.repository import Gtk, Adw |
| 3 | +from src.backend.PluginManager.ActionCore import ActionCore |
| 4 | +from src.backend.DeckManagement.InputIdentifier import InputEvent, Input |
| 5 | +from src.backend.PluginManager.EventAssigner import EventAssigner |
| 6 | +from src.backend.PluginManager.PluginSettings.Asset import Color, Icon |
| 7 | +from GtkHelper.GenerativeUI.EntryRow import EntryRow |
| 8 | +from loguru import logger as log |
| 9 | + |
| 10 | +# Import python modules |
| 11 | +import os |
| 12 | + |
| 13 | +# Import gtk modules - used for the config rows |
| 14 | +import gi |
| 15 | +gi.require_version("Gtk", "4.0") |
| 16 | +gi.require_version("Adw", "1") |
| 17 | + |
| 18 | + |
| 19 | +class SimpleAction(ActionCore): |
| 20 | + def __init__(self, *args, **kwargs): |
| 21 | + super().__init__(*args, **kwargs) |
| 22 | + self.create_generative_ui() |
| 23 | + self.create_event_assigner() |
| 24 | + |
| 25 | + # Create events for the different supported functions. This allows users |
| 26 | + # to easily bind different key actions (like long-press) to your action |
| 27 | + def create_event_assigner(self): |
| 28 | + self.event_manager.add_event_assigner( |
| 29 | + EventAssigner( |
| 30 | + id="pressed", # A unique ID for the event |
| 31 | + ui_label="pressed", # The locales.csv key for the event name |
| 32 | + default_event=Input.Key.Events.DOWN, # The default action to trigger this event |
| 33 | + # The function that should get called when this event triggers |
| 34 | + callback=self._on_pressed |
| 35 | + ) |
| 36 | + ) |
| 37 | + self.event_manager.add_event_assigner( |
| 38 | + EventAssigner( |
| 39 | + id="released", # A unique ID for the event |
| 40 | + ui_label="released", # The locales.csv key for the event name |
| 41 | + default_event=Input.Key.Events.UP, # The default action to trigger this event |
| 42 | + # The function that should get called when this event triggers |
| 43 | + callback=self._on_released |
| 44 | + ) |
| 45 | + ) |
| 46 | + |
| 47 | + # This creates the UI. It doesn't have to be done in it's own function, |
| 48 | + # but should be done during __init__ of the plugin |
| 49 | + def create_generative_ui(self): |
| 50 | + self.text_row = EntryRow( |
| 51 | + action_core=self, # Should reference this action |
| 52 | + var_name="message_text", # The variable to store the value in |
| 53 | + default_value="Button Pressed", # Default text |
| 54 | + title="message-text", # The locales.csv key for the title |
| 55 | + auto_add=True, # If the UI field should be auto added without needing to manually implement |
| 56 | + # If set to true, will store the variable in a json dict. IE: "key.test = value" |
| 57 | + complex_var_name=False |
| 58 | + ) |
| 59 | + |
| 60 | + # on_ready gets called when the plugin is done initializing and is ready to |
| 61 | + # be interacted with on the deck |
| 62 | + def on_ready(self) -> None: |
| 63 | + icon_path = os.path.join(self.plugin_base.PATH, "assets", "info.png") |
| 64 | + # Sets the icon for the plugin |
| 65 | + self.set_media(media_path=icon_path, size=0.75) |
| 66 | + |
| 67 | + def _on_pressed(self, _) -> None: |
| 68 | + value = self.text_row.get_value() # Get the input value from the user |
| 69 | + # Use loguru instead of print() to help with debugging |
| 70 | + log.debug(value) |
| 71 | + |
| 72 | + def _on_released(self, _) -> None: |
| 73 | + # Use loguru instead of print() to help with debugging |
| 74 | + log.debug("Released") |
0 commit comments