mirror of
https://github.com/cyberboy666/r_e_c_u_r.git
synced 2025-12-05 16:00:06 +01:00
ensuring camera is connected before trying to capture
This commit is contained in:
@@ -165,8 +165,8 @@ class Actions(object):
|
||||
if self.video_driver.current_player.status == 'PAUSED':
|
||||
self.toggle_pause_on_player()
|
||||
else:
|
||||
self.capture.start_preview()
|
||||
if self.video_driver.current_player.status != 'PAUSED':
|
||||
is_successful = self.capture.start_preview()
|
||||
if is_successful and self.video_driver.current_player.status != 'PAUSED':
|
||||
self.toggle_pause_on_player()
|
||||
|
||||
def toggle_capture_recording(self):
|
||||
|
||||
@@ -167,7 +167,9 @@ class Display(object):
|
||||
def _generate_capture_status(self):
|
||||
is_previewing = self.capture.is_previewing
|
||||
is_recording = self.capture.is_recording
|
||||
rec_time = self.capture.get_recording_time()
|
||||
rec_time = -1
|
||||
if is_recording == True:
|
||||
rec_time = self.capture.get_recording_time()
|
||||
capture_status = ''
|
||||
if is_previewing and is_recording == True:
|
||||
capture_status = '<{}>'.format('REC'+ self.format_time_value(rec_time))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
import subprocess
|
||||
import datetime
|
||||
from picamera import PiCamera
|
||||
import picamera
|
||||
|
||||
class Capture(object):
|
||||
def __init__(self, root, message_handler, data):
|
||||
@@ -17,14 +17,23 @@ class Capture(object):
|
||||
|
||||
def create_capture_device(self):
|
||||
if self.use_capture:
|
||||
self.device = PiCamera()
|
||||
try:
|
||||
self.device = picamera.PiCamera()
|
||||
except picamera.exc.PiCameraError as e:
|
||||
self.use_capture = False
|
||||
print('camera exception is {}'.format(e))
|
||||
self.message_handler.set_message('INFO', 'no capture device attached')
|
||||
|
||||
def start_preview(self):
|
||||
if self.use_capture == False:
|
||||
self.message_handler.set_message('INFO', 'capture not enabled')
|
||||
return False
|
||||
if self.device.closed:
|
||||
self.create_capture_device()
|
||||
self.is_previewing = True
|
||||
self.device.start_preview()
|
||||
self.set_preview_screen_size()
|
||||
self.set_preview_screen_size()
|
||||
return True
|
||||
|
||||
def set_preview_screen_size(self):
|
||||
if self.data.get_screen_size_setting() == 'dev_mode':
|
||||
@@ -40,6 +49,9 @@ class Capture(object):
|
||||
self.device.close()
|
||||
|
||||
def start_recording(self):
|
||||
if self.use_capture == False:
|
||||
self.message_handler.set_message('INFO', 'capture not enabled')
|
||||
return
|
||||
if self.device.closed:
|
||||
self.create_capture_device()
|
||||
# need to check the space in destination (or check in a main loop somewhere ?)
|
||||
@@ -98,7 +110,7 @@ class Capture(object):
|
||||
return '{}/{}'.format(rec_dir,name), name
|
||||
|
||||
def get_recording_time(self):
|
||||
if not self.device.recording or self.device.frame.timestamp == None:
|
||||
if not self.device or not self.device.recording or self.device.frame.timestamp == None:
|
||||
return -1
|
||||
else:
|
||||
return self.device.frame.timestamp / 1000000
|
||||
|
||||
Reference in New Issue
Block a user