diff --git a/OBSActionBase.py b/OBSActionBase.py index 2d04f10..64dee0b 100644 --- a/OBSActionBase.py +++ b/OBSActionBase.py @@ -1,5 +1,8 @@ from src.backend.PluginManager.ActionBase import ActionBase from src.backend.PluginManager.PluginBase import PluginBase +from src.backend.DeckManagement.DeckController import DeckController +from src.backend.PageManagement.Page import Page +from src.backend.PluginManager.PluginBase import PluginBase # Import gtk modules import gi @@ -8,16 +11,18 @@ gi.require_version("Adw", "1") from gi.repository import Gtk, Adw class OBSActionBase(ActionBase): - def __init__(self, deck_controller, page, coords): - super().__init__(deck_controller=deck_controller, page=page, coords=coords) + def __init__(self, action_id: str, action_name: str, + deck_controller: "DeckController", page: Page, coords: str, plugin_base: PluginBase): + super().__init__(action_id=action_id, action_name=action_name, + deck_controller=deck_controller, page=page, coords=coords, plugin_base=plugin_base) - self.status_label = Gtk.Label(label="Couldn't connect to OBS", css_classes=["bold", "red"]) + self.status_label = Gtk.Label(label=self.plugin_base.lm.get("actions.base.status.no-connection"), css_classes=["bold", "red"]) def get_config_rows(self) -> list: - self.ip_entry = Adw.EntryRow(title="IP Address") + self.ip_entry = Adw.EntryRow(title=self.plugin_base.lm.get("actions.base.ip.label")) self.port_spinner = Adw.SpinRow.new_with_range(0, 65535, 1) - self.port_spinner.set_title("Port:") - self.password_entry = Adw.PasswordEntryRow(title="Password") + self.port_spinner.set_title(self.plugin_base.lm.get("actions.base.port.label")) + self.password_entry = Adw.PasswordEntryRow(title=self.plugin_base.lm.get("actions.base.password.label")) self.load_config_defaults() @@ -29,7 +34,7 @@ class OBSActionBase(ActionBase): return [self.ip_entry, self.port_spinner, self.password_entry] def load_config_defaults(self): - settings = self.PLUGIN_BASE.get_settings() + settings = self.plugin_base.get_settings() ip = settings.setdefault("ip", "localhost") port = settings.setdefault("port", 4455) password = settings.setdefault("password", "") @@ -39,39 +44,43 @@ class OBSActionBase(ActionBase): self.port_spinner.set_value(port) self.password_entry.set_text(password) - self.PLUGIN_BASE.set_settings(settings) + self.plugin_base.set_settings(settings) def on_change_ip(self, entry, *args): - settings = self.PLUGIN_BASE.get_settings() + settings = self.plugin_base.get_settings() settings["ip"] = entry.get_text() - self.PLUGIN_BASE.set_settings(settings) + self.plugin_base.set_settings(settings) self.reconnect_obs() def on_change_port(self, spinner, *args): - settings = self.PLUGIN_BASE.get_settings() + settings = self.plugin_base.get_settings() settings["port"] = int(spinner.get_value()) - self.PLUGIN_BASE.set_settings(settings) + self.plugin_base.set_settings(settings) self.reconnect_obs() def on_change_password(self, entry, *args): - settings = self.PLUGIN_BASE.get_settings() + settings = self.plugin_base.get_settings() settings["password"] = entry.get_text() - self.PLUGIN_BASE.set_settings(settings) + self.plugin_base.set_settings(settings) self.reconnect_obs() def reconnect_obs(self): print("reconnecing obs") - self.PLUGIN_BASE.backend.connect_to(host=self.PLUGIN_BASE.get_settings()["ip"], port=self.PLUGIN_BASE.get_settings()["port"], password=self.PLUGIN_BASE.get_settings()["password"], timeout=3, legacy=False) + self.plugin_base.backend.connect_to( + host=self.plugin_base.get_settings().get("ip"), + port=self.plugin_base.get_settings().get("port"), + password=self.plugin_base.get_settings().get("password"), + timeout=3, legacy=False) - if self.PLUGIN_BASE.backend.get_connected(): - self.status_label.set_label("Successfully connected to OBS") + if self.plugin_base.backend.get_connected(): + self.status_label.set_label(self.plugin_base.lm.get("actions.base.status.connected")) self.status_label.remove_css_class("red") self.status_label.add_css_class("green") else: - self.status_label.set_label("Couldn't connect to OBS") + self.status_label.set_label(self.plugin_base.lm.get("actions.base.status.no-connection")) self.status_label.remove_css_class("green") self.status_label.add_css_class("red") diff --git a/__install__.py b/__install__.py index 966842c..957c4b5 100644 --- a/__install__.py +++ b/__install__.py @@ -3,4 +3,4 @@ from os.path import join, abspath, dirname print("installing") toplevel = dirname(abspath(__file__)) -create_venv(join(toplevel, ".venv"), join(toplevel, "backend/requirements.txt")) \ No newline at end of file +create_venv(join(toplevel, ".venv"), join(toplevel, "backend", "requirements.txt")) \ No newline at end of file diff --git a/actions/RecPlayPause/RecPlayPause.py b/actions/RecPlayPause/RecPlayPause.py index aaceeeb..d2248e4 100644 --- a/actions/RecPlayPause/RecPlayPause.py +++ b/actions/RecPlayPause/RecPlayPause.py @@ -1,29 +1,32 @@ from plugins.dev_core447_OBSPlugin.OBSActionBase import OBSActionBase +from src.backend.DeckManagement.DeckController import DeckController +from src.backend.PageManagement.Page import Page +from src.backend.PluginManager.PluginBase import PluginBase import os class RecPlayPause(OBSActionBase): - ACTION_NAME = "Recording Play/Pause" - CONTROLS_KEY_IMAGE = True - def __init__(self, deck_controller, page, coords): + def __init__(self, action_id: str, action_name: str, + deck_controller: "DeckController", page: Page, coords: str, plugin_base: PluginBase): + super().__init__(action_id=action_id, action_name=action_name, + deck_controller=deck_controller, page=page, coords=coords, plugin_base=plugin_base) self.current_state = -1 - super().__init__(deck_controller=deck_controller, page=page, coords=coords) def on_ready(self): # Connect to obs if not connected - if not self.PLUGIN_BASE.backend.get_connected(): - # self.PLUGIN_BASE.obs.connect_to(host="localhost", port=4444, timeout=3, legacy=False) + if not self.plugin_base.backend.get_connected(): + # self.plugin_base.obs.connect_to(host="localhost", port=4444, timeout=3, legacy=False) self.reconnect_obs() # Show current rec status self.show_current_rec_status() def show_current_rec_status(self, new_paused = False): - if not self.PLUGIN_BASE.backend.get_connected(): - self.set_key(media_path=os.path.join(self.PLUGIN_BASE.PATH, "assets", "error.png")) + if not self.plugin_base.backend.get_connected(): + self.set_key(media_path=os.path.join(self.plugin_base.PATH, "assets", "error.png")) return - status = self.PLUGIN_BASE.backend.get_record_status() + status = self.plugin_base.backend.get_record_status() if status is None: - self.set_key(media_path=os.path.join(self.PLUGIN_BASE.PATH, "assets", "error.png")) + self.set_key(media_path=os.path.join(self.plugin_base.PATH, "assets", "error.png")) return if status["active"] and not status["paused"]: self.show_for_state(1) @@ -52,12 +55,12 @@ class RecPlayPause(OBSActionBase): else: self.set_bottom_label(None) - self.set_key(media_path=os.path.join(self.PLUGIN_BASE.PATH, "assets", image)) + self.set_key(media_path=os.path.join(self.plugin_base.PATH, "assets", image)) def on_key_down(self): - if not self.PLUGIN_BASE.backend.get_connected(): + if not self.plugin_base.backend.get_connected(): return - self.PLUGIN_BASE.backend.toggle_record_pause() + self.plugin_base.backend.toggle_record_pause() def on_tick(self): self.show_current_rec_status() \ No newline at end of file diff --git a/actions/ToggleRecord/ToggleRecord.py b/actions/ToggleRecord/ToggleRecord.py index 1fac12f..acff83b 100644 --- a/actions/ToggleRecord/ToggleRecord.py +++ b/actions/ToggleRecord/ToggleRecord.py @@ -1,29 +1,32 @@ # from ...OBSActionBase import OBSActionBase from plugins.dev_core447_OBSPlugin.OBSActionBase import OBSActionBase +from src.backend.DeckManagement.DeckController import DeckController +from src.backend.PageManagement.Page import Page +from src.backend.PluginManager.PluginBase import PluginBase import os class ToggleRecord(OBSActionBase): - ACTION_NAME = "Toggle Record" - CONTROLS_KEY_IMAGE = True - def __init__(self, deck_controller, page, coords): + def __init__(self, action_id: str, action_name: str, + deck_controller: "DeckController", page: Page, coords: str, plugin_base: PluginBase): + super().__init__(action_id=action_id, action_name=action_name, + deck_controller=deck_controller, page=page, coords=coords, plugin_base=plugin_base) self.current_state = -1 - super().__init__(deck_controller=deck_controller, page=page, coords=coords) def on_ready(self): # Connect to obs if not connected - if not self.PLUGIN_BASE.backend.get_connected(): # self.PLUGIN_BASE.obs.connect_to(host="localhost", port=4444, timeout=3, legacy=False) + if not self.plugin_base.backend.get_connected(): # self.plugin_base.obs.connect_to(host="localhost", port=4444, timeout=3, legacy=False) self.reconnect_obs() # Show current rec status self.show_current_rec_status() def show_current_rec_status(self, new_paused = False): - if not self.PLUGIN_BASE.backend.get_connected(): - self.set_key(media_path=os.path.join(self.PLUGIN_BASE.PATH, "assets", "error.png")) + if not self.plugin_base.backend.get_connected(): + self.set_key(media_path=os.path.join(self.plugin_base.PATH, "assets", "error.png")) return - status = self.PLUGIN_BASE.backend.get_record_status() + status = self.plugin_base.backend.get_record_status() if status is None: - self.set_key(media_path=os.path.join(self.PLUGIN_BASE.PATH, "assets", "error.png")) + self.set_key(media_path=os.path.join(self.plugin_base.PATH, "assets", "error.png")) return if status["paused"]: self.show_for_state(2) @@ -54,23 +57,23 @@ class ToggleRecord(OBSActionBase): self.show_rec_time() image = "record_resume.png" - self.set_key(media_path=os.path.join(self.PLUGIN_BASE.PATH, "assets", image)) + self.set_key(media_path=os.path.join(self.plugin_base.PATH, "assets", image)) def on_key_down(self): - if not self.PLUGIN_BASE.backend.get_connected(): + if not self.plugin_base.backend.get_connected(): return - self.PLUGIN_BASE.backend.toggle_record() + self.plugin_base.backend.toggle_record() def on_tick(self): self.show_current_rec_status() def show_rec_time(self): - if not self.PLUGIN_BASE.backend.get_connected(): - self.set_key(media_path=os.path.join(self.PLUGIN_BASE.PATH, "assets", "error.png")) + if not self.plugin_base.backend.get_connected(): + self.set_key(media_path=os.path.join(self.plugin_base.PATH, "assets", "error.png")) return - status = self.PLUGIN_BASE.backend.get_record_status() + status = self.plugin_base.backend.get_record_status() if status is None: - self.set_key(media_path=os.path.join(self.PLUGIN_BASE.PATH, "assets", "error.png")) + self.set_key(media_path=os.path.join(self.plugin_base.PATH, "assets", "error.png")) return if not status["active"]: self.set_bottom_label(None) diff --git a/locales/de_DE.json b/locales/de_DE.json new file mode 100644 index 0000000..e7233d9 --- /dev/null +++ b/locales/de_DE.json @@ -0,0 +1,9 @@ +{ + "plugin.name": "OBS", + "actions.toggle-record.name": "Aufnahme pausieren", + "actions.rec-play-pause.name": "Play/Pause Aufnahme", + "actions.base.status.no-connection": "Es konnte keine Verbindung zu OBS hergestellt werden.", + "actions.base.ip.label": "IP:", + "actions.base.port.label": "Port:", + "actions.base.password.label": "Passwort:" +} \ No newline at end of file diff --git a/locales/en_US.json b/locales/en_US.json new file mode 100644 index 0000000..60dd084 --- /dev/null +++ b/locales/en_US.json @@ -0,0 +1,10 @@ +{ + "plugin.name": "OBS", + "actions.toggle-record.name": "Toggle Recording", + "actions.rec-play-pause.name": "Play/Pause Recording", + "actions.base.status.no-connection": "Could not connect to OBS.", + "actions.base.status.connected": "Successfully connected to OBS.", + "actions.base.ip.label": "IP:", + "actions.base.port.label": "Port:", + "actions.base.password.label": "Password:" +} \ No newline at end of file diff --git a/main.py b/main.py index d5d38fd..cd2ef74 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,6 @@ from src.backend.PluginManager.ActionBase import ActionBase from src.backend.PluginManager.PluginBase import PluginBase +from src.backend.PluginManager.ActionHolder import ActionHolder # Import gtk modules import gi @@ -23,15 +24,40 @@ from actions.RecPlayPause.RecPlayPause import RecPlayPause class OBS(PluginBase): def __init__(self): - self.PLUGIN_NAME = "OBS" - self.GITHUB_REPO = "https://github.com/your-github-repo" super().__init__() # Launch backend + print("launch backend") self.launch_backend(os.path.join(self.PATH, "backend", "backend.py"), os.path.join(self.PATH, ".venv")) + print("backend launched") - self.add_action(ToggleRecord) - self.add_action(RecPlayPause) + self.lm = self.locale_manager + self.lm.set_to_os_default() + + + self.register( + plugin_name=self.lm.get("plugin.name"), + github_repo="https://github.com/Core447/OBSPlugin", + plugin_version="0.1", + app_version="0.1.1-alpha", + ) + + + toggle_record_action_holder = ActionHolder( + plugin_base=self, + action_base=ToggleRecord, + action_id="dev_core447_OBSPlugin::ToggleRecord", + action_name=self.lm.get("actions.toggle-record.name") + ) + self.add_action_holder(toggle_record_action_holder) + + rec_play_pause_action_holder = ActionHolder( + plugin_base=self, + action_base=RecPlayPause, + action_id="dev_core447_OBSPlugin::RecPlayPause", + action_name=self.lm.get("actions.rec-play-pause.name") + ) + self.add_action_holder(rec_play_pause_action_holder) # Load custom css self.add_css_stylesheet(os.path.join(self.PATH, "style.css")) \ No newline at end of file