Skip to content

Commit

Permalink
Unload camera widget correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanw-chartis committed Sep 14, 2020
1 parent 1d26417 commit 8a4edc3
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/roam/editorwidgets/camerawidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, parent=None):
self.capturebutton.pressed.connect(self.capture)

self.actionCancel = self.toolbar.addAction(QIcon(":/icons/cancel"), "Cancel")
self.actionCancel.triggered.connect(self.cancel.emit)
self.actionCancel.triggered.connect(self._cancel)

self.layout().setContentsMargins(0, 0, 0, 0)
self.layout().addWidget(self.toolbar)
Expand All @@ -47,6 +47,16 @@ def __init__(self, parent=None):

self.viewfinder.show()

def __del__(self):
if self.camera:
self.camera.unload()

def _cancel(self):
if self.camera:
self.camera.unload()

self.cancel.emit()

@property
def list_of_cameras(self):
return QCameraInfo.availableCameras()
Expand Down Expand Up @@ -77,11 +87,14 @@ def camera_res(self):
def imageCaptured(self, frameid, image):
# TODO Doing a pixmap convert here is a waste but downstream needs a qpixmap for now
# refactor later
if self.camera:
self.camera.unload()
self.imagecaptured.emit(QPixmap.fromImage(image))

def start(self, dev=1):
if self.camera:
self.camera.stop()
self.camera.unload()

cameras = QCameraInfo.availableCameras()
self.camera = QCamera(cameras[dev])
self.camera.setViewfinder(self.viewfinder)
Expand Down

0 comments on commit 8a4edc3

Please sign in to comment.