|
11 | 11 | from PyQt6.QtCore import Qt, QTimer
|
12 | 12 | from PyQt6.QtGui import QCloseEvent, QIcon, QImage, QKeyEvent, QPixmap, QColor, QPainter, QFont, QFontDatabase
|
13 | 13 | from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel, QVBoxLayout, QWidget, QComboBox, QPushButton, QFrame
|
14 |
| -if sys.platform == 'win32': |
| 14 | +if sys.platform == 'win32' or sys.platform == 'darwin': |
15 | 15 | import qdarktheme
|
16 | 16 |
|
17 | 17 | class CameraApp(QMainWindow):
|
@@ -100,24 +100,24 @@ def get_available_cameras(self):
|
100 | 100 |
|
101 | 101 |
|
102 | 102 | def get_cameras_mac(self):
|
103 |
| - # print("entre dans get_cameras_mac()") |
104 | 103 | try:
|
105 |
| - import Quartz |
| 104 | + from AVFoundation import AVCaptureDevice |
| 105 | + |
106 | 106 | except ImportError:
|
107 |
| - self.label.setText("Installez pyobjc avec 'pip install pyobjc'") |
| 107 | + print("Installez pyobjc avec 'pip install pyobjc'") |
108 | 108 | return {}
|
109 | 109 |
|
110 | 110 | camera_indices = []
|
111 | 111 | camera_names = []
|
112 | 112 |
|
113 |
| - for index, device in enumerate(Quartz.IORegistryIteratorCreateForMatchingService(Quartz.kIOMasterPortDefault, Quartz.CFDictionaryCreate(None, (Quartz.kIOUSBDeviceClassName,), (True,), 1))): |
114 |
| - camera_name = Quartz.IORegistryEntryGetName(device) |
115 |
| - if "infrared" in camera_name.lower() or "ir" in camera_name.lower(): |
116 |
| - continue # Ignore the infrared camera |
| 113 | + devices = AVCaptureDevice.devicesWithMediaType_('vide') |
| 114 | + for device_index, device_name in enumerate(devices): |
| 115 | + camera_name = device_name.localizedName().cString() |
117 | 116 | camera_names.append(camera_name)
|
118 |
| - camera_indices.append(index) |
119 |
| - return camera_names, camera_indices |
| 117 | + camera_indices.append(device_index) |
120 | 118 |
|
| 119 | + return camera_names, camera_indices |
| 120 | + |
121 | 121 | def get_cameras_windows(self):
|
122 | 122 | # print("entre dans get_cameras_windows()")
|
123 | 123 | try:
|
@@ -243,7 +243,17 @@ def run(self, virtual_frame):
|
243 | 243 | except Exception as e:
|
244 | 244 | print(f"Erreur dans virtual_camera.create_virtual_camera: {e}")
|
245 | 245 | pass
|
246 |
| - self.old_frame = virtual_frame_resized |
| 246 | + elif sys.platform.startswith("darwin"): |
| 247 | + with pyvirtualcam.Camera(width=1280, height=720, fps=30) as cam: |
| 248 | + try: |
| 249 | + virtual_frame = self.virtual_frame |
| 250 | + virtual_frame_resized = self.resize_image(virtual_frame, 1280, 720) |
| 251 | + cam.send(virtual_frame_resized) |
| 252 | + cam.sleep_until_next_frame() |
| 253 | + except Exception as e: |
| 254 | + print(f"Erreur dans virtual_camera.create_virtual_camera: {e}") |
| 255 | + pass |
| 256 | + self.old_frame = virtual_frame_resized |
247 | 257 | def resize_image(self, image, width, height):
|
248 | 258 | resized_image = cv2.resize(image, (width, height))
|
249 | 259 | return resized_image
|
@@ -535,11 +545,11 @@ def __init__(self):
|
535 | 545 | except (ImportError, AttributeError, OSError):
|
536 | 546 | pass
|
537 | 547 |
|
538 |
| - self.counter = 0 |
539 |
| - self.timer_counter = QTimer(self) |
540 |
| - self.image_label = QLabel() |
541 |
| - self.timer_counter.timeout.connect(self.update_counter) |
542 |
| - self.timer_counter.start(1000) |
| 548 | + # self.counter = 0 |
| 549 | + # self.timer_counter = QTimer(self) |
| 550 | + # self.image_label = QLabel() |
| 551 | + # self.timer_counter.timeout.connect(self.update_counter) |
| 552 | + # self.timer_counter.start(1000) |
543 | 553 |
|
544 | 554 | self.cap = None
|
545 | 555 | self.timer_capture = QTimer()
|
@@ -608,67 +618,67 @@ def update_image_label(self, virtual_frame):
|
608 | 618 | print(f"Erreur dans matrix.update_virtual_frame: {e}")
|
609 | 619 | message = False
|
610 | 620 |
|
611 |
| - def update_counter(self): |
612 |
| - # print("entre dans matrix.update_counter()\n") |
613 |
| - self.counter += 1 |
614 |
| - self.counter_string = str(self.counter) |
| 621 | + # def update_counter(self): |
| 622 | + # # print("entre dans matrix.update_counter()\n") |
| 623 | + # self.counter += 1 |
| 624 | + # self.counter_string = str(self.counter) |
615 | 625 |
|
616 |
| - if random.randint(0, 9) % 2 == 0: |
617 |
| - self.counter_string = self.counter_string.replace("0", "¦") |
618 |
| - if random.randint(0, 9) % 2 == 0: |
619 |
| - self.counter_string = self.counter_string.replace("1","§") |
620 |
| - if random.randint(0, 9) % 2 == 0: |
621 |
| - self.counter_string = self.counter_string.replace("2", "¨") |
622 |
| - if random.randint(0, 9) % 2 == 0: |
623 |
| - self.counter_string = self.counter_string.replace("3", "©") |
624 |
| - if random.randint(0, 9) % 2 == 0: |
625 |
| - self.counter_string = self.counter_string.replace("4", "ª") |
626 |
| - if random.randint(0, 9) % 2 == 0: |
627 |
| - self.counter_string = self.counter_string.replace("5", "«") |
628 |
| - if random.randint(0, 9) % 2 == 0: |
629 |
| - self.counter_string = self.counter_string.replace("6", "¬") |
630 |
| - if random.randint(0, 9) % 2 == 0: |
631 |
| - self.counter_string = self.counter_string.replace("8", "®") |
632 |
| - if random.randint(0, 9) % 2 == 0: |
633 |
| - self.counter_string = self.counter_string.replace("9", "¯") |
| 626 | + # if random.randint(0, 9) % 2 == 0: |
| 627 | + # self.counter_string = self.counter_string.replace("0", "¦") |
| 628 | + # if random.randint(0, 9) % 2 == 0: |
| 629 | + # self.counter_string = self.counter_string.replace("1","§") |
| 630 | + # if random.randint(0, 9) % 2 == 0: |
| 631 | + # self.counter_string = self.counter_string.replace("2", "¨") |
| 632 | + # if random.randint(0, 9) % 2 == 0: |
| 633 | + # self.counter_string = self.counter_string.replace("3", "©") |
| 634 | + # if random.randint(0, 9) % 2 == 0: |
| 635 | + # self.counter_string = self.counter_string.replace("4", "ª") |
| 636 | + # if random.randint(0, 9) % 2 == 0: |
| 637 | + # self.counter_string = self.counter_string.replace("5", "«") |
| 638 | + # if random.randint(0, 9) % 2 == 0: |
| 639 | + # self.counter_string = self.counter_string.replace("6", "¬") |
| 640 | + # if random.randint(0, 9) % 2 == 0: |
| 641 | + # self.counter_string = self.counter_string.replace("8", "®") |
| 642 | + # if random.randint(0, 9) % 2 == 0: |
| 643 | + # self.counter_string = self.counter_string.replace("9", "¯") |
634 | 644 |
|
635 | 645 |
|
636 |
| - pixmap = QPixmap(1280, 720) # Créez un QPixmap de la taille souhaitée |
637 |
| - pixmap.fill(QColor(0,0,0)) # Remplissez-le avec une couleur transparente |
| 646 | + # pixmap = QPixmap(1280, 720) # Créez un QPixmap de la taille souhaitée |
| 647 | + # pixmap.fill(QColor(0,0,0)) # Remplissez-le avec une couleur transparente |
638 | 648 |
|
639 |
| - painter = QPainter(pixmap) |
| 649 | + # painter = QPainter(pixmap) |
640 | 650 |
|
641 |
| - font_id = QFontDatabase.addApplicationFont(self.font_path) |
642 |
| - if font_id < 0: print("Error") |
643 |
| - families = QFontDatabase.applicationFontFamilies(font_id) |
644 |
| - painter.setFont(QFont(families[0], 40)) |
645 |
| - painter.setPen(QColor("#008800")) |
| 651 | + # font_id = QFontDatabase.addApplicationFont(self.font_path) |
| 652 | + # if font_id < 0: print("Error") |
| 653 | + # families = QFontDatabase.applicationFontFamilies(font_id) |
| 654 | + # painter.setFont(QFont(families[0], 40)) |
| 655 | + # painter.setPen(QColor("#008800")) |
646 | 656 |
|
647 |
| - self.counter_txt = "C O M P T E U R : " |
| 657 | + # self.counter_txt = "C O M P T E U R : " |
648 | 658 |
|
649 |
| - if random.randint(0, 9) % 2 == 0: |
650 |
| - self.counter_txt = self.counter_txt.replace("C", "Ý") |
651 |
| - if random.randint(0, 9) % 2 == 0: |
652 |
| - self.counter_txt = self.counter_txt.replace("M", "ç") |
653 |
| - if random.randint(0, 9) % 2 == 0: |
654 |
| - self.counter_txt = self.counter_txt.replace("P", "ê") |
655 |
| - if random.randint(0, 9) % 2 == 0: |
656 |
| - self.counter_txt = self.counter_txt.replace("T", "î") |
657 |
| - if random.randint(0, 9) % 2 == 0: |
658 |
| - self.counter_txt = self.counter_txt.replace("E", "ß") |
659 |
| - if random.randint(0, 9) % 2 == 0: |
660 |
| - self.counter_txt = self.counter_txt.replace("U", "ï") |
661 |
| - if random.randint(0, 9) % 2 == 0: |
662 |
| - self.counter_txt = self.counter_txt.replace("R", "ì") |
| 659 | + # if random.randint(0, 9) % 2 == 0: |
| 660 | + # self.counter_txt = self.counter_txt.replace("C", "Ý") |
| 661 | + # if random.randint(0, 9) % 2 == 0: |
| 662 | + # self.counter_txt = self.counter_txt.replace("M", "ç") |
| 663 | + # if random.randint(0, 9) % 2 == 0: |
| 664 | + # self.counter_txt = self.counter_txt.replace("P", "ê") |
| 665 | + # if random.randint(0, 9) % 2 == 0: |
| 666 | + # self.counter_txt = self.counter_txt.replace("T", "î") |
| 667 | + # if random.randint(0, 9) % 2 == 0: |
| 668 | + # self.counter_txt = self.counter_txt.replace("E", "ß") |
| 669 | + # if random.randint(0, 9) % 2 == 0: |
| 670 | + # self.counter_txt = self.counter_txt.replace("U", "ï") |
| 671 | + # if random.randint(0, 9) % 2 == 0: |
| 672 | + # self.counter_txt = self.counter_txt.replace("R", "ì") |
663 | 673 |
|
664 | 674 |
|
665 |
| - # print(self.counter_txt + self.counter_string) |
| 675 | + # # print(self.counter_txt + self.counter_string) |
666 | 676 |
|
667 |
| - painter.drawText(pixmap.rect(), Qt.AlignmentFlag.AlignCenter, self.counter_txt + self.counter_string) |
| 677 | + # painter.drawText(pixmap.rect(), Qt.AlignmentFlag.AlignCenter, self.counter_txt + self.counter_string) |
668 | 678 |
|
669 |
| - painter.end() |
670 |
| - # if random.randint(0, 9) % 3 == 0: |
671 |
| - # self.image_label.setPixmap(pixmap) |
| 679 | + # painter.end() |
| 680 | + # if random.randint(0, 9) % 3 == 0: |
| 681 | + # self.image_label.setPixmap(pixmap) |
672 | 682 |
|
673 | 683 |
|
674 | 684 | def setCameraIndex(self, index):
|
@@ -793,6 +803,8 @@ def capture_frame(self):
|
793 | 803 | app = QApplication([])
|
794 | 804 | if sys.platform == 'win32':
|
795 | 805 | qdarktheme.setup_theme("auto", custom_colors={"primary": "#00B294"})
|
| 806 | + if sys.platform == 'darwin': |
| 807 | + qdarktheme.setup_theme("auto") |
796 | 808 | matrix = Matrix()
|
797 | 809 | camera_app = CameraApp(matrix)
|
798 | 810 | matrix.hide()
|
|
0 commit comments