diff --git a/README.md b/README.md index 46ecfbe..b2b5a8e 100644 --- a/README.md +++ b/README.md @@ -48,12 +48,14 @@ Install on Linux/macOS: >>> recorder.stop_recording() ``` -> Take a look at the GUI screen recorder [here](examples/gui_recorder.py) for more information. +> Take a look at the example GUI screen recorder [here](examples/gui_recorder.py) for more information. Keep in mind that the `start_recording` method is non-blocking, it will start a thread in the background to capture the screenshots. -The `stop_recording` saves the video and deletes all screenshots used in the session. -So calling the `stop_recording` method is necessary when `start_recording` is called. + +The `stop_recording` saves the video. So calling the `stop_recording` method is necessary when `start_recording` is called. + +You'd ideally need some sort of a timeout or a callback to call the `stop_recording` function after `start_recording`, to give the program some time to capture the screen. If a screen recording session is already running, calling the `start_recording` and `resume_recording` methods raises a `ScreenRecodingInProgress` warning. diff --git a/examples/gui_recorder.py b/examples/gui_recorder.py index 99bbe6c..a9cc914 100644 --- a/examples/gui_recorder.py +++ b/examples/gui_recorder.py @@ -2,20 +2,26 @@ from tkinter import messagebox from warnings import filterwarnings -from pyscreenrec import ScreenRecorder, ScreenRecordingInProgress, NoScreenRecordingInProgress +from pyscreenrec import ( + ScreenRecorder, + ScreenRecordingInProgress, + NoScreenRecordingInProgress, +) +# to catch the warnings as error filterwarnings("error") COORDINATES = None + class RegionSelector(tk.Toplevel): def __init__(self, parent): super().__init__(parent) self.title("Select Recording Region") self.geometry("800x600") - self.attributes('-alpha', 0.3) - self.attributes('-fullscreen', True) - self.configure(background='grey') + self.attributes("-alpha", 0.3) + self.attributes("-fullscreen", True) + self.configure(background="grey") self.start_x = None self.start_y = None @@ -23,11 +29,11 @@ def __init__(self, parent): self.end_y = None self.canvas = tk.Canvas(self, highlightthickness=0) - self.canvas.pack(fill='both', expand=True) + self.canvas.pack(fill="both", expand=True) - self.canvas.bind('', self.start_selection) - self.canvas.bind('', self.update_selection) - self.canvas.bind('', self.end_selection) + self.canvas.bind("", self.start_selection) + self.canvas.bind("", self.update_selection) + self.canvas.bind("", self.end_selection) self.selection_rect = None @@ -41,7 +47,7 @@ def update_selection(self, event): if self.selection_rect: self.canvas.delete(self.selection_rect) self.selection_rect = self.canvas.create_rectangle( - self.start_x, self.start_y, event.x, event.y, outline='red' + self.start_x, self.start_y, event.x, event.y, outline="red" ) def end_selection(self, event): @@ -75,19 +81,29 @@ def __init__(self): self.recorder = ScreenRecorder() - self.start_button = tk.Button(self, text="Start Recording", command=self.start_recording) + self.start_button = tk.Button( + self, text="Start Recording", command=self.start_recording + ) self.start_button.pack(pady=10) - self.select_region_button = tk.Button(self, text="Select Region", command=self.select_recording_region) + self.select_region_button = tk.Button( + self, text="Select Region", command=self.select_recording_region + ) self.select_region_button.pack(pady=10) - self.pause_button = tk.Button(self, text="Pause Recording", command=self.pause_recording) + self.pause_button = tk.Button( + self, text="Pause Recording", command=self.pause_recording + ) self.pause_button.pack(pady=10) - self.resume_button = tk.Button(self, text="Resume Recording", command=self.resume_recording) + self.resume_button = tk.Button( + self, text="Resume Recording", command=self.resume_recording + ) self.resume_button.pack(pady=10) - self.stop_button = tk.Button(self, text="Stop Recording", command=self.stop_recording) + self.stop_button = tk.Button( + self, text="Stop Recording", command=self.stop_recording + ) self.stop_button.pack(pady=10) self.filename_entry = tk.Entry(self, width=40) @@ -109,9 +125,13 @@ def start_recording(self): self.recorder.start_recording(filename, fps, COORDINATES) messagebox.showinfo("Recording Started", "Screen recording has started.") except (ValueError, SyntaxError): - messagebox.showerror("Invalid Input", "Please enter valid values for the filename and FPS.") + messagebox.showerror( + "Invalid Input", "Please enter valid values for the filename and FPS." + ) except ScreenRecordingInProgress: - messagebox.showerror("Recording in Progress", "Screen recording is already in progress.") + messagebox.showerror( + "Recording in Progress", "Screen recording is already in progress." + ) def pause_recording(self): try: @@ -123,9 +143,13 @@ def pause_recording(self): def resume_recording(self): try: self.recorder.resume_recording() - messagebox.showinfo("Recording Resumed", "Screen recording has been resumed.") + messagebox.showinfo( + "Recording Resumed", "Screen recording has been resumed." + ) except ScreenRecordingInProgress: - messagebox.showerror("Recording in Progress", "Screen recording is already in progress.") + messagebox.showerror( + "Recording in Progress", "Screen recording is already in progress." + ) def stop_recording(self): try: