diff --git a/actions/SimpleAction.py b/actions/SimpleAction.py new file mode 100644 index 0000000..f368a18 --- /dev/null +++ b/actions/SimpleAction.py @@ -0,0 +1,74 @@ +# Import StreamController modules +from gi.repository import Gtk, Adw +from src.backend.PluginManager.ActionCore import ActionCore +from src.backend.DeckManagement.InputIdentifier import InputEvent, Input +from src.backend.PluginManager.EventAssigner import EventAssigner +from src.backend.PluginManager.PluginSettings.Asset import Color, Icon +from GtkHelper.GenerativeUI.EntryRow import EntryRow +from loguru import logger as log + +# Import python modules +import os + +# Import gtk modules - used for the config rows +import gi +gi.require_version("Gtk", "4.0") +gi.require_version("Adw", "1") + + +class SimpleAction(ActionCore): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.create_generative_ui() + self.create_event_assigner() + + # Create events for the different supported functions. This allows users + # to easily bind different key actions (like long-press) to your action + def create_event_assigner(self): + self.event_manager.add_event_assigner( + EventAssigner( + id="pressed", # A unique ID for the event + ui_label="pressed", # The locales.csv key for the event name + default_event=Input.Key.Events.DOWN, # The default action to trigger this event + # The function that should get called when this event triggers + callback=self._on_pressed + ) + ) + self.event_manager.add_event_assigner( + EventAssigner( + id="released", # A unique ID for the event + ui_label="released", # The locales.csv key for the event name + default_event=Input.Key.Events.UP, # The default action to trigger this event + # The function that should get called when this event triggers + callback=self._on_released + ) + ) + + # This creates the UI. It doesn't have to be done in it's own function, + # but should be done during __init__ of the plugin + def create_generative_ui(self): + self.text_row = EntryRow( + action_core=self, # Should reference this action + var_name="message_text", # The variable to store the value in + default_value="Button Pressed", # Default text + title="message-text", # The locales.csv key for the title + auto_add=True, # If the UI field should be auto added without needing to manually implement + # If set to true, will store the variable in a json dict. IE: "key.test = value" + complex_var_name=False + ) + + # on_ready gets called when the plugin is done initializing and is ready to + # be interacted with on the deck + def on_ready(self) -> None: + icon_path = os.path.join(self.plugin_base.PATH, "assets", "info.png") + # Sets the icon for the plugin + self.set_media(media_path=icon_path, size=0.75) + + def _on_pressed(self, _) -> None: + value = self.text_row.get_value() # Get the input value from the user + # Use loguru instead of print() to help with debugging + log.debug(value) + + def _on_released(self, _) -> None: + # Use loguru instead of print() to help with debugging + log.debug("Released") diff --git a/actions/SimpleAction/SimpleAction.py b/actions/SimpleAction/SimpleAction.py deleted file mode 100644 index a4deced..0000000 --- a/actions/SimpleAction/SimpleAction.py +++ /dev/null @@ -1,28 +0,0 @@ -# Import StreamController modules -from src.backend.PluginManager.ActionBase import ActionBase -from src.backend.DeckManagement.DeckController import DeckController -from src.backend.PageManagement.Page import Page -from src.backend.PluginManager.PluginBase import PluginBase - -# Import python modules -import os - -# Import gtk modules - used for the config rows -import gi -gi.require_version("Gtk", "4.0") -gi.require_version("Adw", "1") -from gi.repository import Gtk, Adw - -class SimpleAction(ActionBase): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - def on_ready(self) -> None: - icon_path = os.path.join(self.plugin_base.PATH, "assets", "info.png") - self.set_media(media_path=icon_path, size=0.75) - - def on_key_down(self) -> None: - print("Key down") - - def on_key_up(self) -> None: - print("Key up") \ No newline at end of file diff --git a/locales.csv b/locales.csv new file mode 100644 index 0000000..ebb2ec5 --- /dev/null +++ b/locales.csv @@ -0,0 +1,4 @@ +key;en_US +message-text;Text to send +released;Released +pressed;Pressed diff --git a/main.py b/main.py index 9f1be12..9b545fa 100644 --- a/main.py +++ b/main.py @@ -1,27 +1,34 @@ # Import StreamController modules from src.backend.PluginManager.PluginBase import PluginBase from src.backend.PluginManager.ActionHolder import ActionHolder +from src.backend.DeckManagement.InputIdentifier import Input +from src.backend.PluginManager.ActionInputSupport import ActionInputSupport # Import actions -from .actions.SimpleAction.SimpleAction import SimpleAction +from .actions.SimpleAction import SimpleAction + class PluginTemplate(PluginBase): def __init__(self): - super().__init__() + # Plugins should set use_legacy_locale to False + # for future proofing themselves + super().__init__(use_legacy_locale=False) - ## Register actions + # Register actions self.simple_action_holder = ActionHolder( - plugin_base = self, - action_base = SimpleAction, - action_id = "dev_core447_Template::SimpleAction", # Change this to your own plugin id - action_name = "Simple Action", + plugin_base=self, # Should always be set to self + action_base=SimpleAction, # References the actual created action + action_id_suffix="SimpleAction", # A unique name for the action in your plugin + action_name="Simple Action", # The display name for the action + action_support={ + # These should be set based on what inputs have been tested + Input.Key: ActionInputSupport.SUPPORTED, + Input.Dial: ActionInputSupport.UNTESTED, + Input.Touchscreen: ActionInputSupport.UNTESTED, + } ) + # Adds the action to the plugin self.add_action_holder(self.simple_action_holder) - # Register plugin - self.register( - plugin_name = "Template", - github_repo = "https://github.com/StreamController/PluginTemplate", - plugin_version = "1.0.0", - app_version = "1.1.1-alpha" - ) \ No newline at end of file + # Register plugin using details from manifest.json + self.register() diff --git a/manifest.json b/manifest.json index bb898a9..5bf7d46 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,8 @@ { - "version": "", - "thumbnail": "", - "id": "", - "name": "" -} \ No newline at end of file + "version": "0.0.1", + "id": "PluginTemplate", + "github": "https://github.com/StreamController/PluginTemplate", + "name": "PluginTemplate", + "minimum-app-version": "1.5.0-beta.10", + "app-version": "1.5.0-beta.10" +}