Commit 0b82e33e authored by Spencer Du's avatar Spencer Du

ui created for each device in Qt designer

parent 88dc23be
......@@ -4,25 +4,30 @@ from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5 import QtWidgets, uic
from mqtt import *
from cameras2 import *
import json
import time
class SubWindow(QWidget):
class SubWindow(QtWidgets.QMainWindow):
def __init__(self, parent = None):
super(SubWindow, self).__init__(parent)
self.setMinimumSize(QSize(300, 200))
label = QLabel("Laser", self)
self.Button = QtWidgets.QPushButton("ON",self)
# self.Button.clicked.connect(self.on)
self.Button.setGeometry(QtCore.QRect(10, 40, 81, 23))
self.setMinimumSize(QSize(379, 268))
self.Button2 = QtWidgets.QPushButton("OFF",self)
self.Button2.clicked.connect(self.off)
self.Button2.setGeometry(QtCore.QRect(10, 40, 81, 23))
self.Button2.move(120,40)
self.ui = Ui_Cameras()
self.ui.setupUi(self)
self.fileName_UI = "cameras"
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()
......@@ -37,7 +42,7 @@ class SubWindow(QWidget):
# 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")
# self.Button.setStyleSheet("background-color: green")
# listofdevices = []
# listofdevices.append(self.fileName_UI)
......@@ -55,39 +60,39 @@ class SubWindow(QWidget):
# print("No devices added yet")
# readFile("list_of_devices_currently_active.txt")
def off(self):
client = device()
client.run()
# 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:")
# 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", "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")
# 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 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()
\ No newline at end of file
# def closeEvent(self, event):
# self.close()
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>381</width>
<height>336</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QSlider" name="horizontalSlider">
<property name="geometry">
<rect>
<x>10</x>
<y>40</y>
<width>160</width>
<height>16</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit">
<property name="geometry">
<rect>
<x>190</x>
<y>40</y>
<width>113</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>301</x>
<y>40</y>
<width>71</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>ms</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>71</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Exposure Time</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>10</x>
<y>70</y>
<width>71</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Delay</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>10</x>
<y>120</y>
<width>39</width>
<height>11</height>
</rect>
</property>
<property name="text">
<string>Mode</string>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>40</x>
<y>100</y>
<width>39</width>
<height>11</height>
</rect>
</property>
<property name="text">
<string>Right</string>
</property>
</widget>
<widget class="QComboBox" name="comboBox">
<property name="geometry">
<rect>
<x>40</x>
<y>120</y>
<width>52</width>
<height>16</height>
</rect>
</property>
</widget>
<widget class="QCheckBox" name="checkBox">
<property name="geometry">
<rect>
<x>120</x>
<y>120</y>
<width>59</width>
<height>15</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="label_5">
<property name="geometry">
<rect>
<x>130</x>
<y>100</y>
<width>39</width>
<height>11</height>
</rect>
</property>
<property name="text">
<string>Link</string>
</property>
</widget>
<widget class="QComboBox" name="comboBox_2">
<property name="geometry">
<rect>
<x>160</x>
<y>120</y>
<width>52</width>
<height>16</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_6">
<property name="geometry">
<rect>
<x>160</x>
<y>100</y>
<width>39</width>
<height>11</height>
</rect>
</property>
<property name="text">
<string>Left</string>
</property>
</widget>
<widget class="QLabel" name="label_7">
<property name="geometry">
<rect>
<x>10</x>
<y>160</y>
<width>39</width>
<height>11</height>
</rect>
</property>
<property name="text">
<string>Lines</string>
</property>
</widget>
<widget class="QComboBox" name="comboBox_3">
<property name="geometry">
<rect>
<x>40</x>
<y>160</y>
<width>52</width>
<height>16</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>90</x>
<y>160</y>
<width>31</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>6</pointsize>
</font>
</property>
<property name="text">
<string>px</string>
</property>
</widget>
<widget class="QCheckBox" name="checkBox_2">
<property name="geometry">
<rect>
<x>130</x>
<y>160</y>
<width>16</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QComboBox" name="comboBox_4">
<property name="geometry">
<rect>
<x>160</x>
<y>160</y>
<width>52</width>
<height>16</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton_3">
<property name="geometry">
<rect>
<x>210</x>
<y>160</y>
<width>31</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>6</pointsize>
</font>
</property>
<property name="text">
<string>px</string>
</property>
</widget>
<widget class="QLabel" name="label_8">
<property name="geometry">
<rect>
<x>40</x>
<y>190</y>
<width>39</width>
<height>11</height>
</rect>
</property>
<property name="text">
<string>Crop ROI</string>
</property>
</widget>
<widget class="QLabel" name="label_9">
<property name="geometry">
<rect>
<x>10</x>
<y>210</y>
<width>39</width>
<height>11</height>
</rect>
</property>
<property name="text">
<string>Top</string>
</property>
</widget>
<widget class="QComboBox" name="comboBox_5">
<property name="geometry">
<rect>
<x>40</x>
<y>210</y>
<width>52</width>
<height>16</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton_4">
<property name="geometry">
<rect>
<x>90</x>
<y>210</y>
<width>31</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>6</pointsize>
</font>
</property>
<property name="text">
<string>px</string>
</property>
</widget>
<widget class="QLabel" name="label_10">
<property name="geometry">
<rect>
<x>10</x>
<y>240</y>
<width>39</width>
<height>11</height>
</rect>
</property>
<property name="text">
<string>Width</string>
</property>
</widget>
<widget class="QComboBox" name="comboBox_6">
<property name="geometry">
<rect>
<x>40</x>
<y>240</y>
<width>52</width>
<height>16</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton_5">
<property name="geometry">
<rect>
<x>90</x>
<y>240</y>
<width>31</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>6</pointsize>
</font>
</property>
<property name="text">
<string>px</string>
</property>
</widget>
<widget class="QLabel" name="label_11">
<property name="geometry">
<rect>
<x>130</x>
<y>210</y>
<width>39</width>
<height>11</height>
</rect>
</property>
<property name="text">
<string>Left</string>
</property>
</widget>
<widget class="QComboBox" name="comboBox_7">
<property name="geometry">
<rect>
<x>170</x>
<y>210</y>
<width>52</width>
<height>16</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton_6">
<property name="geometry">
<rect>
<x>220</x>
<y>210</y>
<width>31</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>6</pointsize>
</font>
</property>
<property name="text">
<string>px</string>
</property>
</widget>
<widget class="QLabel" name="label_12">
<property name="geometry">
<rect>
<x>130</x>
<y>240</y>
<width>39</width>
<height>11</height>
</rect>
</property>
<property name="text">
<string>Height</string>
</property>
</widget>
<widget class="QComboBox" name="comboBox_8">
<property name="geometry">
<rect>
<x>170</x>
<y>240</y>
<width>52</width>
<height>16</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton_7">
<property name="geometry">
<rect>
<x>220</x>
<y>240</y>
<width>31</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>6</pointsize>
</font>
</property>
<property name="text">
<string>px</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_8">
<property name="geometry">
<rect>
<x>10</x>
<y>280</y>
<width>71</width>
<height>19</height>
</rect>
</property>
<property name="text">
<string>Reset Crop ROI</string>
</property>
</widget>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'cameras.ui'
#
# Created by: PyQt5 UI code generator 5.13.0
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Cameras(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(381, 336)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.horizontalSlider = QtWidgets.QSlider(self.centralwidget)
self.horizontalSlider.setGeometry(QtCore.QRect(10, 40, 160, 16))
self.horizontalSlider.setOrientation(QtCore.Qt.Horizontal)
self.horizontalSlider.setObjectName("horizontalSlider")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(190, 40, 113, 20))
self.lineEdit.setObjectName("lineEdit")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(301, 40, 71, 20))
self.pushButton.setObjectName("pushButton")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(10, 20, 71, 16))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(10, 70, 71, 16))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(10, 120, 39, 11))
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(40, 100, 39, 11))
self.label_4.setObjectName("label_4")
self.comboBox = QtWidgets.QComboBox(self.centralwidget)
self.comboBox.setGeometry(QtCore.QRect(40, 120, 52, 16))
self.comboBox.setObjectName("comboBox")
self.checkBox = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox.setGeometry(QtCore.QRect(120, 120, 59, 15))
self.checkBox.setText("")
self.checkBox.setObjectName("checkBox")
self.label_5 = QtWidgets.QLabel(self.centralwidget)
self.label_5.setGeometry(QtCore.QRect(130, 100, 39, 11))
self.label_5.setObjectName("label_5")
self.comboBox_2 = QtWidgets.QComboBox(self.centralwidget)
self.comboBox_2.setGeometry(QtCore.QRect(160, 120, 52, 16))
self.comboBox_2.setObjectName("comboBox_2")
self.label_6 = QtWidgets.QLabel(self.centralwidget)
self.label_6.setGeometry(QtCore.QRect(160, 100, 39, 11))
self.label_6.setObjectName("label_6")
self.label_7 = QtWidgets.QLabel(self.centralwidget)
self.label_7.setGeometry(QtCore.QRect(10, 160, 39, 11))
self.label_7.setObjectName("label_7")
self.comboBox_3 = QtWidgets.QComboBox(self.centralwidget)
self.comboBox_3.setGeometry(QtCore.QRect(40, 160, 52, 16))
self.comboBox_3.setObjectName("comboBox_3")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(90, 160, 31, 16))
font = QtGui.QFont()
font.setPointSize(6)
self.pushButton_2.setFont(font)
self.pushButton_2.setObjectName("pushButton_2")
self.checkBox_2 = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_2.setGeometry(QtCore.QRect(130, 160, 16, 16))
self.checkBox_2.setText("")
self.checkBox_2.setObjectName("checkBox_2")
self.comboBox_4 = QtWidgets.QComboBox(self.centralwidget)
self.comboBox_4.setGeometry(QtCore.QRect(160, 160, 52, 16))
self.comboBox_4.setObjectName("comboBox_4")
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(QtCore.QRect(210, 160, 31, 16))
font = QtGui.QFont()
font.setPointSize(6)
self.pushButton_3.setFont(font)
self.pushButton_3.setObjectName("pushButton_3")
self.label_8 = QtWidgets.QLabel(self.centralwidget)
self.label_8.setGeometry(QtCore.QRect(40, 190, 39, 11))
self.label_8.setObjectName("label_8")
self.label_9 = QtWidgets.QLabel(self.centralwidget)
self.label_9.setGeometry(QtCore.QRect(10, 210, 39, 11))
self.label_9.setObjectName("label_9")
self.comboBox_5 = QtWidgets.QComboBox(self.centralwidget)
self.comboBox_5.setGeometry(QtCore.QRect(40, 210, 52, 16))
self.comboBox_5.setObjectName("comboBox_5")
self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_4.setGeometry(QtCore.QRect(90, 210, 31, 16))
font = QtGui.QFont()
font.setPointSize(6)
self.pushButton_4.setFont(font)
self.pushButton_4.setObjectName("pushButton_4")
self.label_10 = QtWidgets.QLabel(self.centralwidget)
self.label_10.setGeometry(QtCore.QRect(10, 240, 39, 11))
self.label_10.setObjectName("label_10")
self.comboBox_6 = QtWidgets.QComboBox(self.centralwidget)
self.comboBox_6.setGeometry(QtCore.QRect(40, 240, 52, 16))
self.comboBox_6.setObjectName("comboBox_6")
self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_5.setGeometry(QtCore.QRect(90, 240, 31, 16))
font = QtGui.QFont()
font.setPointSize(6)
self.pushButton_5.setFont(font)
self.pushButton_5.setObjectName("pushButton_5")
self.label_11 = QtWidgets.QLabel(self.centralwidget)
self.label_11.setGeometry(QtCore.QRect(130, 210, 39, 11))
self.label_11.setObjectName("label_11")
self.comboBox_7 = QtWidgets.QComboBox(self.centralwidget)
self.comboBox_7.setGeometry(QtCore.QRect(170, 210, 52, 16))
self.comboBox_7.setObjectName("comboBox_7")
self.pushButton_6 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_6.setGeometry(QtCore.QRect(220, 210, 31, 16))
font = QtGui.QFont()
font.setPointSize(6)
self.pushButton_6.setFont(font)
self.pushButton_6.setObjectName("pushButton_6")
self.label_12 = QtWidgets.QLabel(self.centralwidget)
self.label_12.setGeometry(QtCore.QRect(130, 240, 39, 11))
self.label_12.setObjectName("label_12")
self.comboBox_8 = QtWidgets.QComboBox(self.centralwidget)
self.comboBox_8.setGeometry(QtCore.QRect(170, 240, 52, 16))
self.comboBox_8.setObjectName("comboBox_8")
self.pushButton_7 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_7.setGeometry(QtCore.QRect(220, 240, 31, 16))
font = QtGui.QFont()
font.setPointSize(6)
self.pushButton_7.setFont(font)
self.pushButton_7.setObjectName("pushButton_7")
self.pushButton_8 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_8.setGeometry(QtCore.QRect(10, 280, 71, 19))
self.pushButton_8.setObjectName("pushButton_8")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate