Skip to content

Commit

Permalink
edit readme
Browse files Browse the repository at this point in the history
  • Loading branch information
shravanasati committed Nov 9, 2024
1 parent 86f6133 commit 6b8a5a9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 21 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
60 changes: 42 additions & 18 deletions examples/gui_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,38 @@
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
self.end_x = None
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('<Button-1>', self.start_selection)
self.canvas.bind('<B1-Motion>', self.update_selection)
self.canvas.bind('<ButtonRelease-1>', self.end_selection)
self.canvas.bind("<Button-1>", self.start_selection)
self.canvas.bind("<B1-Motion>", self.update_selection)
self.canvas.bind("<ButtonRelease-1>", self.end_selection)

self.selection_rect = None

Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 6b8a5a9

Please sign in to comment.