2023-11-25 13:49:41 +00:00
|
|
|
from src.backend.PluginManager.ActionBase import ActionBase
|
|
|
|
from src.backend.PluginManager.PluginBase import PluginBase
|
2024-02-15 10:03:05 +00:00
|
|
|
from src.backend.DeckManagement.DeckController import DeckController
|
|
|
|
from src.backend.PageManagement.Page import Page
|
|
|
|
from src.backend.PluginManager.PluginBase import PluginBase
|
2023-11-25 13:49:41 +00:00
|
|
|
|
|
|
|
# Import gtk modules
|
|
|
|
import gi
|
|
|
|
gi.require_version("Gtk", "4.0")
|
|
|
|
gi.require_version("Adw", "1")
|
|
|
|
from gi.repository import Gtk, Adw
|
|
|
|
|
2024-04-20 07:02:00 +00:00
|
|
|
import threading
|
|
|
|
from loguru import logger as log
|
|
|
|
|
2023-11-25 13:49:41 +00:00
|
|
|
class OBSActionBase(ActionBase):
|
2024-02-15 10:03:05 +00:00
|
|
|
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)
|
2024-04-13 12:36:22 +00:00
|
|
|
|
|
|
|
self.HAS_CONFIGURATION = True
|
2023-11-25 13:49:41 +00:00
|
|
|
|
2024-02-15 10:03:05 +00:00
|
|
|
self.status_label = Gtk.Label(label=self.plugin_base.lm.get("actions.base.status.no-connection"), css_classes=["bold", "red"])
|
2023-11-25 13:49:41 +00:00
|
|
|
|
|
|
|
def get_config_rows(self) -> list:
|
2024-02-15 10:03:05 +00:00
|
|
|
self.ip_entry = Adw.EntryRow(title=self.plugin_base.lm.get("actions.base.ip.label"))
|
2023-11-25 13:49:41 +00:00
|
|
|
self.port_spinner = Adw.SpinRow.new_with_range(0, 65535, 1)
|
2024-02-15 10:03:05 +00:00
|
|
|
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"))
|
2023-11-25 13:49:41 +00:00
|
|
|
|
|
|
|
self.load_config_defaults()
|
|
|
|
|
|
|
|
# Connect signals
|
|
|
|
self.ip_entry.connect("notify::text", self.on_change_ip)
|
|
|
|
self.port_spinner.connect("notify::value", self.on_change_port)
|
|
|
|
self.password_entry.connect("notify::text", self.on_change_password)
|
|
|
|
|
|
|
|
return [self.ip_entry, self.port_spinner, self.password_entry]
|
|
|
|
|
|
|
|
def load_config_defaults(self):
|
2024-02-15 10:03:05 +00:00
|
|
|
settings = self.plugin_base.get_settings()
|
2023-11-25 13:49:41 +00:00
|
|
|
ip = settings.setdefault("ip", "localhost")
|
|
|
|
port = settings.setdefault("port", 4455)
|
|
|
|
password = settings.setdefault("password", "")
|
|
|
|
|
|
|
|
# Update ui
|
|
|
|
self.ip_entry.set_text(ip)
|
|
|
|
self.port_spinner.set_value(port)
|
|
|
|
self.password_entry.set_text(password)
|
|
|
|
|
2024-02-15 10:03:05 +00:00
|
|
|
self.plugin_base.set_settings(settings)
|
2023-11-25 13:49:41 +00:00
|
|
|
|
|
|
|
def on_change_ip(self, entry, *args):
|
2024-02-15 10:03:05 +00:00
|
|
|
settings = self.plugin_base.get_settings()
|
2023-11-25 13:49:41 +00:00
|
|
|
settings["ip"] = entry.get_text()
|
2024-02-15 10:03:05 +00:00
|
|
|
self.plugin_base.set_settings(settings)
|
2023-11-25 13:49:41 +00:00
|
|
|
|
|
|
|
self.reconnect_obs()
|
|
|
|
|
|
|
|
def on_change_port(self, spinner, *args):
|
2024-02-15 10:03:05 +00:00
|
|
|
settings = self.plugin_base.get_settings()
|
2023-11-25 13:49:41 +00:00
|
|
|
settings["port"] = int(spinner.get_value())
|
2024-02-15 10:03:05 +00:00
|
|
|
self.plugin_base.set_settings(settings)
|
2023-11-25 13:49:41 +00:00
|
|
|
|
|
|
|
self.reconnect_obs()
|
|
|
|
|
|
|
|
def on_change_password(self, entry, *args):
|
2024-02-15 10:03:05 +00:00
|
|
|
settings = self.plugin_base.get_settings()
|
2023-11-25 13:49:41 +00:00
|
|
|
settings["password"] = entry.get_text()
|
2024-02-15 10:03:05 +00:00
|
|
|
self.plugin_base.set_settings(settings)
|
2023-11-25 13:49:41 +00:00
|
|
|
|
|
|
|
self.reconnect_obs()
|
|
|
|
|
|
|
|
def reconnect_obs(self):
|
2024-04-20 07:02:00 +00:00
|
|
|
threading.Thread(target=self._reconnect_obs, daemon=True, name="reconnect_obs").start()
|
|
|
|
|
|
|
|
def _reconnect_obs(self):
|
|
|
|
try:
|
|
|
|
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)
|
|
|
|
except Exception as e:
|
|
|
|
log.error(e)
|
2024-03-26 14:29:08 +00:00
|
|
|
|
|
|
|
self.update_status_label()
|
|
|
|
|
|
|
|
def update_status_label(self) -> None:
|
2024-04-20 07:02:00 +00:00
|
|
|
threading.Thread(target=self._update_status_label, daemon=True, name="update_status_label").start()
|
|
|
|
|
|
|
|
def _update_status_label(self):
|
2024-02-15 10:03:05 +00:00
|
|
|
if self.plugin_base.backend.get_connected():
|
|
|
|
self.status_label.set_label(self.plugin_base.lm.get("actions.base.status.connected"))
|
2023-11-25 13:49:41 +00:00
|
|
|
self.status_label.remove_css_class("red")
|
|
|
|
self.status_label.add_css_class("green")
|
|
|
|
else:
|
2024-02-15 10:03:05 +00:00
|
|
|
self.status_label.set_label(self.plugin_base.lm.get("actions.base.status.no-connection"))
|
2023-11-25 13:49:41 +00:00
|
|
|
self.status_label.remove_css_class("green")
|
|
|
|
self.status_label.add_css_class("red")
|
|
|
|
|
|
|
|
def get_custom_config_area(self):
|
2024-03-26 14:29:08 +00:00
|
|
|
self.update_status_label()
|
2023-11-25 13:49:41 +00:00
|
|
|
return self.status_label
|