Skip to content

Commit c498284

Browse files
committed
Switch to ActionCore
1 parent cb4f505 commit c498284

File tree

4 files changed

+103
-40
lines changed

4 files changed

+103
-40
lines changed

actions/SimpleAction.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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")

actions/SimpleAction/SimpleAction.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

locales.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
key;en_US
2+
message-text;Text to send
3+
released;Released
4+
pressed;Pressed

main.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
11
# Import StreamController modules
22
from src.backend.PluginManager.PluginBase import PluginBase
33
from src.backend.PluginManager.ActionHolder import ActionHolder
4+
from src.backend.DeckManagement.InputIdentifier import Input
5+
from src.backend.PluginManager.ActionInputSupport import ActionInputSupport
46

57
# Import actions
6-
from .actions.SimpleAction.SimpleAction import SimpleAction
8+
from .actions.SimpleAction import SimpleAction
9+
710

811
class PluginTemplate(PluginBase):
912
def __init__(self):
10-
super().__init__()
13+
# Plugins should set use_legacy_locale to False
14+
# for future proofing themselves
15+
super().__init__(use_legacy_locale=False)
1116

12-
## Register actions
17+
# Register actions
1318
self.simple_action_holder = ActionHolder(
14-
plugin_base = self,
15-
action_base = SimpleAction,
16-
action_id = "dev_core447_Template::SimpleAction", # Change this to your own plugin id
17-
action_name = "Simple Action",
19+
plugin_base=self, # Should always be set to self
20+
action_base=SimpleAction, # References the actual created action
21+
action_id_suffix="SimpleAction", # A unique name for the action in your plugin
22+
action_name="Simple Action", # The display name for the action
23+
action_support={
24+
# These should be set based on what inputs have been tested
25+
Input.Key: ActionInputSupport.SUPPORTED,
26+
Input.Dial: ActionInputSupport.UNTESTED,
27+
Input.Touchscreen: ActionInputSupport.UNTESTED,
28+
}
1829
)
30+
# Adds the action to the plugin
1931
self.add_action_holder(self.simple_action_holder)
2032

2133
# Register plugin
2234
self.register(
23-
plugin_name = "Template",
24-
github_repo = "https://github.com/StreamController/PluginTemplate",
25-
plugin_version = "1.0.0",
26-
app_version = "1.1.1-alpha"
27-
)
35+
plugin_name="Template", # Should be a unique name for your plugin
36+
# The GitHub repository for your plugin
37+
github_repo="https://github.com/StreamController/PluginTemplate",
38+
plugin_version="1.0.0", # The plugin version, will be used to check updates
39+
app_version="1.1.1-alpha" # The support application version
40+
)

0 commit comments

Comments
 (0)