OBSPlugin/actions/RecPlayPause/RecPlayPause.py

68 lines
2.3 KiB
Python
Raw Permalink Normal View History

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
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 RecPlayPause(OBSActionBase):
2024-05-10 15:33:23 +00:00
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.current_state = -1
2024-01-14 10:50:34 +00:00
def on_ready(self):
self.current_state = -1
2024-01-14 10:50:34 +00:00
# Connect to obs if not connected
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)
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-04-20 07:02:00 +00:00
if not self.plugin_base.get_connected():
self.show_error()
2024-01-14 10:50:34 +00:00
return
status = self.plugin_base.backend.get_record_status()
2024-01-14 10:50:34 +00:00
if status is None:
self.show_error()
2024-01-14 10:50:34 +00:00
return
if status["active"] and not status["paused"]:
self.show_for_state(1)
elif status["paused"]:
self.show_for_state(2)
else:
self.show_for_state(0)
def show_for_state(self, state: int):
"""
0: Not Recording
1: Recording
2: Paused
3: Stopping in progress
"""
self.hide_error()
if state == self.current_state:
return
self.current_state = state
2024-01-14 10:50:34 +00:00
image = "record_inactive.png"
if state == 1:
self.set_bottom_label("Pause", font_size=16)
image = "record_pause.png"
if state == 2:
self.set_bottom_label("Resume", font_size=16)
image = "record_resume.png"
else:
self.set_bottom_label(None)
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):
if not self.plugin_base.backend.get_connected():
2024-01-14 10:50:34 +00:00
return
self.plugin_base.backend.toggle_record_pause()
2024-01-14 10:50:34 +00:00
def on_tick(self):
self.show_current_rec_status()