From 58becd6b4f034e3e15c42a5779174c47109d47d6 Mon Sep 17 00:00:00 2001 From: Shravan Asati Date: Sun, 13 Oct 2024 22:54:36 +0530 Subject: [PATCH] raise warnings properly --- CHANGELOG | 2 +- pyscreenrec/__init__.py | 24 +++++++++++++----------- setup.py | 32 ++++++++++++++++---------------- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1ca2024..35cacde 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -20,7 +20,7 @@ Change Log - Minor bug fixes. -------------- -0.4 (13/10/24) +0.5 (13/10/24) -------------- - Remove the `HighFPSWarning` and `InvalidFPS` exception classes. - Raise frame count by almost 2 times. diff --git a/pyscreenrec/__init__.py b/pyscreenrec/__init__.py index af17b98..9fc489b 100644 --- a/pyscreenrec/__init__.py +++ b/pyscreenrec/__init__.py @@ -1,14 +1,11 @@ -# type: ignore -from pyscreeze import screenshot -from time import sleep - -# type: ignore -import cv2 import os from threading import Thread +from time import sleep +from warnings import warn -# type: ignore +import cv2 from natsort import natsorted +from pyscreeze import screenshot class InvalidCodec(Exception): @@ -75,7 +72,7 @@ def _start_recording(self, video_name: str, fps: int) -> None: # checking if screen is already being recorded if self.__running: - raise ScreenRecordingInProgress("Screen recording is already running.") + warn("Screen recording is already running.", ScreenRecordingInProgress) else: if self.__start_mode == "start": @@ -141,7 +138,8 @@ def stop_recording(self) -> None: Stops screen recording. """ if not self.__running: - raise NoScreenRecordingInProgress("No screen recording session is going on.") + warn("No screen recording session is going on.", NoScreenRecordingInProgress) + return self.__running = False @@ -154,7 +152,8 @@ def pause_recording(self) -> None: Pauses screen recording. """ if not self.__running: - raise NoScreenRecordingInProgress("No screen recording session is going on.") + warn("No screen recording session is going on.", NoScreenRecordingInProgress) + return self.__running = False @@ -163,7 +162,8 @@ def resume_recording(self) -> None: Resumes screen recording. """ if self.__running: - raise ScreenRecordingInProgress("Screen recording is already running.") + warn("Screen recording is already running.", ScreenRecordingInProgress) + return self.__start_mode = "resume" self.start_recording(self.video_name) @@ -215,6 +215,8 @@ def __repr__(self) -> str: rec = ScreenRecorder() print("recording started") rec.start_recording(fps=30) + rec.resume_recording() time.sleep(10) print("recording ended") rec.stop_recording() + rec.pause_recording() diff --git a/setup.py b/setup.py index 09dfbbd..bae1368 100644 --- a/setup.py +++ b/setup.py @@ -1,23 +1,23 @@ from setuptools import find_packages, setup -VERSION = 0.4 +VERSION = "0.5" with open("README.md") as f: README = f.read() setup( - name = "pyscreenrec", - version = VERSION, - description = "A small and cross-platform python library for recording screen.", - long_description_content_type = "text/markdown", - long_description = README, + name="pyscreenrec", + version=VERSION, + description="A small and cross-platform python library for recording screen.", + long_description_content_type="text/markdown", + long_description=README, url="https://github.com/shravanasati/pyscreenrec", - author = "Shravan Asati", - author_email = "dev.shravan@protonmail.com", - packages = find_packages(), - install_requires = ["pyscreeze", "opencv-python", "natsort"], - license = 'MIT', - keywords = ["python", "screen recording", "screen", "recording", "screenshots"], - classifiers = [ + author="Shravan Asati", + author_email="dev.shravan@protonmail.com", + packages=find_packages(), + install_requires=["pyscreeze", "opencv-python", "natsort"], + license="MIT", + keywords=["python", "screen recording", "screen", "recording", "screenshots"], + classifiers=[ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", @@ -28,6 +28,6 @@ "Operating System :: Unix", "Operating System :: MacOS :: MacOS X", "Operating System :: Microsoft :: Windows", - "Topic :: Software Development :: Libraries" - ] -) \ No newline at end of file + "Topic :: Software Development :: Libraries", + ], +)