"""
This module contains the OpenCameras class, which is responsible for managing camera opening and settings.
"""
from MoildevUi.OpenCam import Ui_Dialog
import cv2
from PyQt5 import QtWidgets
[docs]
class OpenCameras(Ui_Dialog):
"""
A class to manage camera opening and settings.
Args:
MainWindow: The main window of the application.
recentWindow: The recent window of the application.
Attributes:
parent_win: Reference to the MainWindow object.
parent_dialog: Reference to the recentWindow object.
videoStreamURL: URL of the video stream.
"""
def __init__(self, MainWindow, recentWindow):
super().__init__(MainWindow)
'''
>> Main window is the the inheritance from the main UI this program
>> Recent window is the UI for this window.
this make it possible to communication between this two UI
'''
self.parent_win = MainWindow
self.parent_dialog = recentWindow
self.setupUi(self.parent_dialog)
self.videoStreamURL = None
self.lineEdit_14.setText('http://192.168.100.226:8000/stream.mjpg')
self.handleActivatedCombobox()
self.connectToButton()
[docs]
def handleActivatedCombobox(self):
"""
Handles the activation of the combo box to show/hide elements based on selection.
"""
if self.comboBox.currentText() == 'USB Camera':
self.label_59.hide()
self.lineEdit_14.hide()
self.framePortUsb.show()
# self.parent_win.stop_camera()
else:
# self.frame_2.show()
self.label_59.show()
self.lineEdit_14.show()
self.framePortUsb.hide()
# self.parent_win.stop_camera()
[docs]
def checkPortCamera(self):
"""
Checks available camera ports and displays them in a message box.
"""
all_camera_idx_available = []
for camera_idx in range(5):
cap = cv2.VideoCapture(camera_idx)
if cap.isOpened():
all_camera_idx_available.append(camera_idx)
cap.release()
msgbox = QtWidgets.QMessageBox()
msgbox.setWindowTitle("Camera Port Available")
msgbox.setText(
"Select the port camera from the number in list !! \n"
"Available Port = " + str(all_camera_idx_available))
msgbox.exec()
[docs]
def vidUrl(self):
"""
Get the video stream URL based on the current selection.
Returns:
str or int: The URL of the video stream or the port number of the USB camera.
"""
if self.comboBox.currentText() == 'USB Camera':
self.videoStreamURL = int(self.portCamera.currentText())
else:
self.videoStreamURL = self.lineEdit_14.text()
if self.videoStreamURL is None:
return None
else:
return self.videoStreamURL
[docs]
def ok(self):
"""
Handles the "OK" button click event to open the camera and close the dialog.
"""
self.parent_win.cameraOpen()
self.parent_dialog.close()
[docs]
def exit(self):
"""
Handles the "Exit" button click event to close the dialog.
"""
self.parent_dialog.close()