webcam.py 3.63 KB
Newer Older
Spencer Du's avatar
Spencer Du committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
from PyQt5 import QtCore, QtGui, QtWidgets, uic
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from webcam2 import *
from mqtt import *
import json
import time
import sys

class SubWindow(QtWidgets.QMainWindow):
    def __init__(self, parent = None):
        super(SubWindow, self).__init__(parent)
        self.setMinimumSize(QSize(300, 300))

        self.ui = Ui_Webcam()
        self.ui.setupUi(self)

def main():
    if hasattr(QtCore.Qt, 'AA_EnableHighDpiScaling'):
        QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
    if hasattr(QtCore.Qt, 'AA_UseHighDpiPixmaps'):
        QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)
    app = QtWidgets.QApplication(sys.argv)
    application = SubWindow()
    application.show()
    sys.exit(app.exec_())

if __name__ == "__main__":
    main()
    # def on(self):
    #     client = device()
    #     client.run()

    #     client.loop_start()
    #     print("Connected to broker")
    #     time.sleep(1)
    #     print("Subscribing to topic", "microscope/light_sheet_microscope/UI")
    #     client.subscribe("microscope/light_sheet_microscope/UI")        
    #     print("Publishing message to topic", "microscope/light_sheet_microscope/UI")
    #     client.publish("microscope/light_sheet_microscope/UI", json.dumps({"type": "device", "payload":{"name": self.fileName_UI, "cmd": "laser turning on"}}, indent=2))
    #     time.sleep(1)
    #     client.loop_stop()
        # self.Button.setStyleSheet("background-color: green")

        # listofdevices = []
        # listofdevices.append(self.fileName_UI)
        # with open("list_of_devices_currently_active.txt", "a+") as myfile:
        #     for item in listofdevices:
        #         myfile.write(item + "\n")
        # print("\n" + item + " added to device list" + "\n" + "\n" + "List of devices currently active:")

        # def readFile(fname):
        #     try:
        #         with open(fname, "r") as f:
        #             for item in f:
        #                 print(item)
        #     except:
        #         print("No devices added yet")
        # readFile("list_of_devices_currently_active.txt")

    # def off(self):
    #     client = device()
    #     client.run()

    #     client.loop_start()
    #     print("Connected to broker")
    #     time.sleep(1)
    #     print("Subscribing to topic", "microscope/light_sheet_microscope/UI/states")
    #     client.subscribe("microscope/light_sheet_microscope/UI/states")     
    #     print("Publishing message to topic", "microscope/light_sheet_microscope/UI/states")
    #     client.publish("microscope/light_sheet_microscope/UI/states", json.dumps({"type": "device", "payload":{"name": self.fileName_UI, "cmd": "cameras turning off"}}, indent=2))
    #     time.sleep(1)
    #     client.loop_stop()
    #     print("Device turned off")
    #     self.Button.setStyleSheet("background-color:")

    #     with open("list_of_devices_currently_active.txt", "r") as f:
    #         lines = f.readlines()

    #     with open("list_of_devices_currently_active.txt", "w") as f:
    #         for line in lines:
    #             if line.strip("\n") != "laser":
    #                 f.write(line)
    #     print("Laser removed from device list" + "\n\n" + "List of devices currently active")

    #     def readFile(fname):
    #         try:
    #             with open(fname, "r") as f:
    #                 for item in f:
    #                     print(item)
    #         except:
    #             print("No devices added yet")
    #     readFile("list_of_devices_currently_active.txt")

    # def closeEvent(self, event):
    #     self.close()