Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions actions/SimpleAction.py
Original file line number Diff line number Diff line change
@@ -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")
28 changes: 0 additions & 28 deletions actions/SimpleAction/SimpleAction.py

This file was deleted.

4 changes: 4 additions & 0 deletions locales.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
key;en_US
message-text;Text to send
released;Released
pressed;Pressed
35 changes: 21 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
@@ -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"
)
# Register plugin using details from manifest.json
self.register()
12 changes: 7 additions & 5 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"version": "",
"thumbnail": "",
"id": "",
"name": ""
}
"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"
}