mirror of
https://github.com/onyx-and-iris/simple-recorder.git
synced 2025-06-27 18:00:23 +01:00
add tabgroup to mainframe
add pause, split and add chapter buttons to Recorder tab - they are not implemented yet add timeouts on requests + handle them add obs connected status message on GUI load
This commit is contained in:
parent
0814678278
commit
1d6fbd0bda
@ -1,6 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import FreeSimpleGUI as fsg
|
import FreeSimpleGUI as fsg
|
||||||
|
import obsws_python as obsws
|
||||||
|
|
||||||
from .errors import SimpleRecorderError
|
from .errors import SimpleRecorderError
|
||||||
from .start import Start
|
from .start import Start
|
||||||
@ -17,17 +18,75 @@ class SimpleRecorderWindow(fsg.Window):
|
|||||||
self.password = password
|
self.password = password
|
||||||
fsg.theme(theme)
|
fsg.theme(theme)
|
||||||
|
|
||||||
layout = [
|
try:
|
||||||
[fsg.Text("Enter recording filename:")],
|
with obsws.ReqClient(
|
||||||
[fsg.InputText("", key="-FILENAME-")],
|
host=self.host, port=self.port, password=self.password, timeout=3
|
||||||
[fsg.Button("Start Recording"), fsg.Button("Stop Recording")],
|
) as client:
|
||||||
[fsg.Text("Status: Not started", key="-OUTPUT-")],
|
resp = client.get_version()
|
||||||
|
status_message = f"Connected to OBS {resp.obs_version} ✓"
|
||||||
|
except (ConnectionRefusedError, TimeoutError):
|
||||||
|
status_message = "Failed to connect to OBS. Is it running?"
|
||||||
|
|
||||||
|
recorder_layout = [
|
||||||
|
[fsg.Text("Enter recording filename:", key="-PROMPT-")],
|
||||||
|
[fsg.InputText("default_name", key="-FILENAME-", focus=True, size=(45, 1))],
|
||||||
|
[
|
||||||
|
fsg.Button("Start", key="Start Recording", size=(10, 1)),
|
||||||
|
fsg.Button("Stop", key="Stop Recording", size=(10, 1)),
|
||||||
|
fsg.Button("Pause", key="Pause Recording", size=(10, 1)),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
fsg.Button("Split", key="Split Recording", size=(10, 1)),
|
||||||
|
fsg.Button("Add Chapter", key="Add Chapter", size=(10, 1)),
|
||||||
|
],
|
||||||
]
|
]
|
||||||
super().__init__("Simple Recorder", layout, finalize=True)
|
|
||||||
|
frame = fsg.Frame(
|
||||||
|
"",
|
||||||
|
recorder_layout,
|
||||||
|
relief=fsg.RELIEF_SUNKEN,
|
||||||
|
)
|
||||||
|
|
||||||
|
recorder_tab = fsg.Tab(
|
||||||
|
"Recorder",
|
||||||
|
[
|
||||||
|
[frame],
|
||||||
|
[
|
||||||
|
fsg.Text(
|
||||||
|
f"Status: {status_message}",
|
||||||
|
key="-OUTPUT-",
|
||||||
|
text_color="white"
|
||||||
|
if status_message.startswith("Connected")
|
||||||
|
else "red",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
settings_layout = [
|
||||||
|
[fsg.Text("Enter the filepath for the recording:")],
|
||||||
|
[fsg.InputText("", key="-FILEPATH-", size=(45, 1))],
|
||||||
|
]
|
||||||
|
|
||||||
|
settings_tab = fsg.Tab("Settings", settings_layout)
|
||||||
|
|
||||||
|
mainframe = [
|
||||||
|
[fsg.TabGroup([[recorder_tab, settings_tab]])],
|
||||||
|
]
|
||||||
|
|
||||||
|
super().__init__("Simple Recorder", mainframe, finalize=True)
|
||||||
self["-FILENAME-"].bind("<Return>", " || RETURN")
|
self["-FILENAME-"].bind("<Return>", " || RETURN")
|
||||||
self["Start Recording"].bind("<Return>", " || RETURN")
|
self["Start Recording"].bind("<Return>", " || RETURN")
|
||||||
self["Stop Recording"].bind("<Return>", " || RETURN")
|
self["Stop Recording"].bind("<Return>", " || RETURN")
|
||||||
|
|
||||||
|
self["-FILENAME-"].bind("<KeyPress>", " || KEYPRESS")
|
||||||
|
self["-FILENAME-"].update(select=True)
|
||||||
|
self["Add Chapter"].bind("<FocusIn>", " || FOCUS")
|
||||||
|
self["Add Chapter"].bind("<Enter>", " || FOCUS")
|
||||||
|
self["Add Chapter"].bind("<FocusOut>", " || LEAVE")
|
||||||
|
self["Add Chapter"].bind("<Leave>", " || LEAVE")
|
||||||
|
self["Add Chapter"].bind("<Button-3>", " || RIGHT_CLICK")
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
while True:
|
while True:
|
||||||
event, values = self.read()
|
event, values = self.read()
|
||||||
@ -65,7 +124,27 @@ class SimpleRecorderWindow(fsg.Window):
|
|||||||
f"Error: {e.raw_message}", text_color="red"
|
f"Error: {e.raw_message}", text_color="red"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
case ["Add Chapter", "FOCUS" | "LEAVE" as focus_event]:
|
||||||
|
if focus_event == "FOCUS":
|
||||||
|
self["-OUTPUT-"].update(
|
||||||
|
"Right-click to set a chapter name", text_color="white"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self["-OUTPUT-"].update("", text_color="white")
|
||||||
|
|
||||||
|
case ["Add Chapter", "RIGHT_CLICK"]:
|
||||||
|
_ = fsg.popup_get_text(
|
||||||
|
"Enter chapter name:",
|
||||||
|
"Add Chapter",
|
||||||
|
default_text="unnamed",
|
||||||
|
)
|
||||||
|
|
||||||
|
case ["Pause Recording" | "Split Recording" | "Add Chapter"]:
|
||||||
|
self["-OUTPUT-"].update(
|
||||||
|
"This feature is not implemented yet", text_color="orange"
|
||||||
|
)
|
||||||
|
|
||||||
case _:
|
case _:
|
||||||
self.logger.warning(f"Unhandled event: {e}")
|
self.logger.debug(f"Unhandled event: {e}")
|
||||||
|
|
||||||
self.close()
|
self.close()
|
||||||
|
@ -29,8 +29,9 @@ class Start(Command):
|
|||||||
if not self.filename:
|
if not self.filename:
|
||||||
raise SimpleRecorderError("Recording name cannot be empty.")
|
raise SimpleRecorderError("Recording name cannot be empty.")
|
||||||
|
|
||||||
|
try:
|
||||||
with obsws.ReqClient(
|
with obsws.ReqClient(
|
||||||
host=self.host, port=self.port, password=self.password
|
host=self.host, port=self.port, password=self.password, timeout=3
|
||||||
) as client:
|
) as client:
|
||||||
resp = client.get_record_status()
|
resp = client.get_record_status()
|
||||||
if resp.output_active:
|
if resp.output_active:
|
||||||
@ -44,3 +45,5 @@ class Start(Command):
|
|||||||
)
|
)
|
||||||
client.start_record()
|
client.start_record()
|
||||||
print(f"Recording started with filename: {highlight(filename)}")
|
print(f"Recording started with filename: {highlight(filename)}")
|
||||||
|
except TimeoutError:
|
||||||
|
raise SimpleRecorderError("Failed to connect to OBS. Is it running?")
|
||||||
|
@ -15,8 +15,9 @@ class Stop(Command):
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
async def run(self):
|
async def run(self):
|
||||||
|
try:
|
||||||
with obsws.ReqClient(
|
with obsws.ReqClient(
|
||||||
host=self.host, port=self.port, password=self.password
|
host=self.host, port=self.port, password=self.password, timeout=3
|
||||||
) as client:
|
) as client:
|
||||||
resp = client.get_record_status()
|
resp = client.get_record_status()
|
||||||
if not resp.output_active:
|
if not resp.output_active:
|
||||||
@ -24,3 +25,5 @@ class Stop(Command):
|
|||||||
|
|
||||||
client.stop_record()
|
client.stop_record()
|
||||||
print(highlight("Recording stopped successfully."))
|
print(highlight("Recording stopped successfully."))
|
||||||
|
except TimeoutError:
|
||||||
|
raise SimpleRecorderError("Failed to connect to OBS. Is it running?")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user