Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve various type errors and do some pythonic refactoring of the codebase #1179

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions picamera2/picamera2.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,12 @@ def __init__(self, camera_num=0, verbose_console=None, tuning=None, allocator=No
_log.debug(f"{self.camera_manager}")
# We deliberately make raw streams with no size so that it will be filled in
# later once the main stream size has been set.
self.preview_configuration = self.create_preview_configuration()
self.preview_configuration.enable_raw() # causes the size to be reset to None
self.still_configuration = self.create_still_configuration()
self.still_configuration.enable_raw() # ditto
self.video_configuration = self.create_video_configuration()
self.video_configuration.enable_raw() # ditto
self.preview_configuration_ = CameraConfiguration(self.create_preview_configuration(), self)
self.preview_configuration_.enable_raw() # causes the size to be reset to None
self.still_configuration_ = CameraConfiguration(self.create_still_configuration(), self)
self.still_configuration_.enable_raw() # ditto
self.video_configuration_ = CameraConfiguration(self.create_video_configuration(), self)
self.video_configuration_.enable_raw() # ditto
except Exception:
_log.error("Camera __init__ sequence did not complete.")
raise RuntimeError("Camera __init__ sequence did not complete.")
Expand Down Expand Up @@ -425,12 +425,10 @@ def _grab_camera(self, idx):
elif isinstance(idx, int):
return self.camera_manager.cameras[idx]

def _initialize_camera(self) -> bool:
def _initialize_camera(self) -> None:
"""Initialize camera

:raises RuntimeError: Failure to initialise camera
:return: True if success
:rtype: bool
"""
if not self.camera_manager.cameras:
_log.error("Camera(s) not found (Do not forget to disable legacy camera with raspi-config).")
Expand Down Expand Up @@ -458,7 +456,6 @@ def _initialize_camera(self) -> bool:
self.sensor_format = self._native_mode['format']

_log.info('Initialization successful.')
return True

def __identify_camera(self):
for idx, address in enumerate(self.camera_manager.cameras):
Expand All @@ -471,7 +468,9 @@ def _open_camera(self) -> None:

:raises RuntimeError: Failed to setup camera
"""
if not self._initialize_camera():
try:
self._initialize_camera()
except RuntimeError:
raise RuntimeError("Failed to initialize camera")

# This now throws an error if it can't open the camera.
Expand Down Expand Up @@ -628,12 +627,12 @@ def close(self) -> None:
self.streams = None
self.stream_map = None
self.camera = None
self.camera_ctrl_info = None
self.camera_ctrl_info = {}
self.camera_config = None
self.libcamera_config = None
self.preview_configuration_ = None
self.still_configuration_ = None
self.video_configuration_ = None
self.preview_configuration = {}
self.still_configuration = {}
self.video_configuration = {}
self.notifymeread.close()
os.close(self.notifyme_w)
# Clean up the allocator
Expand Down
Loading