2024-01-14 10:50:34 +00:00
|
|
|
# from ...OBSActionBase import OBSActionBase
|
2024-04-20 07:02:00 +00:00
|
|
|
import threading
|
2024-03-26 14:33:54 +00:00
|
|
|
from plugins.com_core447_OBSPlugin.OBSActionBase import OBSActionBase
|
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
|
2024-01-14 10:50:34 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
class ToggleRecord(OBSActionBase):
|
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-01-14 12:56:39 +00:00
|
|
|
self.current_state = -1
|
2024-01-14 10:50:34 +00:00
|
|
|
|
|
|
|
def on_ready(self):
|
2024-03-27 08:58:41 +00:00
|
|
|
self.current_state = -1
|
2024-01-14 10:50:34 +00:00
|
|
|
# Connect to obs if not connected
|
2024-03-26 18:08:18 +00:00
|
|
|
if self.plugin_base.backend is not None:
|
2024-04-20 07:02:00 +00:00
|
|
|
if not self.plugin_base.get_connected(): # self.plugin_base.obs.connect_to(host="localhost", port=4444, timeout=3, legacy=False)
|
2024-03-26 18:08:18 +00:00
|
|
|
self.reconnect_obs()
|
2024-01-14 10:50:34 +00:00
|
|
|
|
|
|
|
# Show current rec status
|
2024-04-20 07:02:00 +00:00
|
|
|
threading.Thread(target=self.show_current_rec_status, daemon=True, name="show_current_rec_status").start()
|
2024-01-14 10:50:34 +00:00
|
|
|
|
|
|
|
def show_current_rec_status(self, new_paused = False):
|
2024-03-27 08:58:41 +00:00
|
|
|
if self.plugin_base.backend is None:
|
|
|
|
self.current_state = -1
|
|
|
|
self.show_error()
|
|
|
|
return
|
2024-02-15 10:03:05 +00:00
|
|
|
if not self.plugin_base.backend.get_connected():
|
2024-03-27 08:58:41 +00:00
|
|
|
self.current_state = -1
|
|
|
|
self.show_error()
|
2024-01-14 10:50:34 +00:00
|
|
|
return
|
2024-02-15 10:03:05 +00:00
|
|
|
status = self.plugin_base.backend.get_record_status()
|
2024-01-14 10:50:34 +00:00
|
|
|
if status is None:
|
2024-03-27 08:58:41 +00:00
|
|
|
self.current_state = -1
|
|
|
|
self.show_error()
|
2024-01-14 10:50:34 +00:00
|
|
|
return
|
|
|
|
if status["paused"]:
|
|
|
|
self.show_for_state(2)
|
|
|
|
elif status["active"]:
|
|
|
|
self.show_for_state(1)
|
|
|
|
else:
|
|
|
|
self.show_for_state(0)
|
|
|
|
|
|
|
|
def show_for_state(self, state: int):
|
|
|
|
"""
|
|
|
|
0: Not Recording
|
|
|
|
1: Recording
|
|
|
|
2: Paused
|
|
|
|
3: Stopping in progress
|
|
|
|
"""
|
2024-03-27 09:21:57 +00:00
|
|
|
if state in [1, 2]:
|
|
|
|
self.show_rec_time()
|
|
|
|
|
2024-01-14 12:56:39 +00:00
|
|
|
if state == self.current_state:
|
|
|
|
return
|
2024-03-27 09:21:57 +00:00
|
|
|
|
2024-01-14 12:56:39 +00:00
|
|
|
self.current_state = state
|
2024-01-14 10:50:34 +00:00
|
|
|
image = "record_inactive.png"
|
|
|
|
if state == 0:
|
|
|
|
self.set_bottom_label(None)
|
|
|
|
image = "record_inactive.png"
|
|
|
|
elif state == 1:
|
|
|
|
image = "record_active.png"
|
|
|
|
elif state == 2:
|
|
|
|
image = "record_resume.png"
|
|
|
|
|
2024-03-12 18:48:56 +00:00
|
|
|
self.set_media(media_path=os.path.join(self.plugin_base.PATH, "assets", image))
|
2024-01-14 10:50:34 +00:00
|
|
|
|
|
|
|
def on_key_down(self):
|
2024-03-27 08:58:41 +00:00
|
|
|
if self.plugin_base.backend is None:
|
|
|
|
self.current_state = -1
|
|
|
|
self.show_error()
|
|
|
|
return
|
2024-02-15 10:03:05 +00:00
|
|
|
if not self.plugin_base.backend.get_connected():
|
2024-03-27 08:58:41 +00:00
|
|
|
self.current_state = -1
|
|
|
|
self.show_error()
|
2024-01-14 10:50:34 +00:00
|
|
|
return
|
2024-02-15 10:03:05 +00:00
|
|
|
self.plugin_base.backend.toggle_record()
|
2024-03-27 09:05:16 +00:00
|
|
|
self.on_tick()
|
2024-01-14 10:50:34 +00:00
|
|
|
|
|
|
|
def on_tick(self):
|
|
|
|
self.show_current_rec_status()
|
|
|
|
|
|
|
|
def show_rec_time(self):
|
2024-02-15 10:03:05 +00:00
|
|
|
if not self.plugin_base.backend.get_connected():
|
2024-03-12 18:48:56 +00:00
|
|
|
self.set_media(media_path=os.path.join(self.plugin_base.PATH, "assets", "error.png"))
|
2024-01-14 10:50:34 +00:00
|
|
|
return
|
2024-02-15 10:03:05 +00:00
|
|
|
status = self.plugin_base.backend.get_record_status()
|
2024-01-14 10:50:34 +00:00
|
|
|
if status is None:
|
2024-03-12 18:48:56 +00:00
|
|
|
self.set_media(media_path=os.path.join(self.plugin_base.PATH, "assets", "error.png"))
|
2024-01-14 10:50:34 +00:00
|
|
|
return
|
|
|
|
if not status["active"]:
|
|
|
|
self.set_bottom_label(None)
|
|
|
|
return
|
|
|
|
self.set_bottom_label(status["timecode"][:-4], font_size=16)
|