Commit 8834259f authored by Spencer Du's avatar Spencer Du

cameras ui config file issue fixed

parent 83069059
......@@ -164,21 +164,21 @@ class Ui_MainWindow(object):
self.pushButton_10.setChecked(True)
self.pushButton_10.setObjectName("pushButton_10")
self.gridLayout.addWidget(self.pushButton_10, 0, 0, 1, 1)
self.pushButton_10.clicked.connect(self.on)
self.pushButton_11 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_11.clicked.connect(self.stop)
self.pushButton_11.setObjectName("pushButton_11")
self.gridLayout.addWidget(self.pushButton_11, 0, 2, 1, 2)
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 exposureTime(self):
if not os.path.exists("cameras.ini"):
textboxValue = self.lineEdit.text()
if self.lineEdit.text() == "":
self.horizontalSlider.setValue(0)
else:
self.horizontalSlider.setValue(int(textboxValue))
client = device()
client.run()
......@@ -196,17 +196,13 @@ class Ui_MainWindow(object):
config = configparser.RawConfigParser()
f = open("cameras.ini", "w")
config.add_section("Cameras")
config.set("Cameras", "Exposure time", textboxValue + "ms")
f = open("cameras.ini")
config.add_section("Exposure")
config.set("Exposure", "time", textboxValue + "ms")
config.write(f)
else:
textboxValue = self.lineEdit.text()
if self.lineEdit.text() == "":
self.horizontalSlider.setValue(0)
else:
self.horizontalSlider.setValue(int(textboxValue))
client = device()
client.run()
......@@ -224,14 +220,15 @@ class Ui_MainWindow(object):
print("Exposure time: " + textboxValue + "ms")
config = configparser.RawConfigParser()
config.read("cameras.ini")
f = open("cameras.ini", "w")
try:
config.add_section("Cameras")
config.add_section("Exposure")
except Exception as e:
pass
try:
config.set("Cameras", "Exposure time", textboxValue + "ms")
config.set("Exposure", "time", textboxValue + "ms")
except Exception as e:
pass
config.write(f)
......@@ -258,8 +255,8 @@ class Ui_MainWindow(object):
config = configparser.RawConfigParser()
f = open("cameras.ini", "w")
config.add_section("Cameras")
config.set("Cameras", "delay", textboxValue + "ms")
config.add_section("Delay")
config.set("Delay", "time", textboxValue + "ms")
config.write(f)
else:
......@@ -278,15 +275,18 @@ class Ui_MainWindow(object):
time.sleep(1)
client.loop_stop()
print("Delay: " + textboxValue2 + "ms")
config = configparser.RawConfigParser()
config.read("cameras.ini")
f = open("cameras.ini", "w")
try:
config.add_section("Cameras")
config.add_section("Delay")
except Exception as e:
pass
try:
config.set("Cameras", "Delay", textboxValue2 + "ms")
config.set("Delay", "time", textboxValue2 + "ms")
except Exception as e:
pass
config.write(f)
......@@ -314,9 +314,9 @@ class Ui_MainWindow(object):
config = configparser.RawConfigParser()
f = open("cameras.ini", "w")
config.add_section("Cameras")
config.set("Cameras", "Left camera mode", leftMode)
config.set("Cameras", "Left camera lines", textboxValue3 + "px")
config.add_section("Left camera")
config.set("Left camera", "mode", leftMode)
config.set("Left camera", "lines", textboxValue3 + "px")
config.write(f)
else:
......@@ -339,18 +339,19 @@ class Ui_MainWindow(object):
print("Left camera lines: " + textboxValue3 + "px")
config = configparser.RawConfigParser()
config.read("cameras.ini")
f = open("cameras.ini", "w")
try:
config.add_section("Cameras")
config.add_section("Left camera")
except Exception as e:
pass
try:
config.set("Cameras", "Left camera mode", leftMode)
config.set("Left camera", "mode", leftMode)
except Exception as e:
pass
try:
config.set("Cameras", "Left camera lines", textboxValue3 + "px")
config.set("Left camera", "lines", textboxValue3 + "px")
except Exception as e:
pass
config.write(f)
......@@ -378,9 +379,9 @@ class Ui_MainWindow(object):
config = configparser.RawConfigParser()
f = open("cameras.ini", "w")
config.add_section("Cameras")
config.set("Cameras", "Right camera mode", rightMode)
config.set("Cameras", "Right camera lines", textboxValue4 + "px")
config.add_section("Right camera")
config.set("Right camera", "mode", rightMode)
config.set("Right camera", "lines", textboxValue4 + "px")
config.write(f)
else:
......@@ -396,25 +397,26 @@ class Ui_MainWindow(object):
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/cameras")
client.subscribe("microscope/light_sheet_microscope/UI/cameras")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/cameras")
client.publish("microscope/light_sheet_microscope/UI/cameras", json.dumps({"type": "device", "payload":{"name": "cameras", "left camera mode": leftMode, "left camera lines": textboxValue3 + "px", "cmd": "set left lines of left camera"}}, indent=2))
client.publish("microscope/light_sheet_microscope/UI/cameras", json.dumps({"type": "device", "payload":{"name": "cameras", "right camera mode": rightMode, "right camera lines": textboxValue4 + "px", "cmd": "set right camera mode and right camera lines"}}, indent=2))
time.sleep(1)
client.loop_stop()
print("Right camera mode: " + rightMode)
print("Right camera lines: " + textboxValue4 + "px")
config = configparser.RawConfigParser()
config.read("cameras.ini")
f = open("cameras.ini", "w")
try:
config.add_section("Cameras")
config.add_section("Right camera")
except Exception as e:
pass
try:
config.set("Cameras", "Right camera mode", rightMode)
config.set("Right camera", "Mode", rightMode)
except Exception as e:
pass
try:
config.set("Cameras", "Right camera lines", textboxValue4 + "px")
config.set("Right camera", "Lines", textboxValue4 + "px")
except Exception as e:
pass
config.write(f)
......@@ -440,8 +442,8 @@ class Ui_MainWindow(object):
config = configparser.RawConfigParser()
f = open("cameras.ini", "w")
config.add_section("Cameras")
config.set("Cameras", "Top ROI", textboxValue5 + "px")
config.add_section("Top ROI")
config.set("Top ROI", "ROI", textboxValue5 + "px")
config.write(f)
else:
......@@ -462,14 +464,15 @@ class Ui_MainWindow(object):
print("Top ROI: " + textboxValue5 + "px")
config = configparser.RawConfigParser()
config.read("cameras.ini")
f = open("cameras.ini", "w")
try:
config.add_section("Cameras")
config.add_section("Top ROI")
except Exception as e:
pass
try:
config.set("Cameras", "Top ROI", textboxValue5 + "px")
config.set("Top ROI", "ROI", textboxValue5 + "px")
except Exception as e:
pass
config.write(f)
......@@ -495,8 +498,8 @@ class Ui_MainWindow(object):
config = configparser.RawConfigParser()
f = open("cameras.ini", "w")
config.add_section("Cameras")
config.set("Cameras", "Left ROI", textboxValue6 + "px")
config.add_section("Left ROI")
config.set("Left ROI", "ROI", textboxValue6 + "px")
config.write(f)
else:
......@@ -517,14 +520,15 @@ class Ui_MainWindow(object):
print("Left ROI: " + textboxValue6 + "px")
config = configparser.RawConfigParser()
config.read("cameras.ini")
f = open("cameras.ini", "w")
try:
config.add_section("Cameras")
config.add_section("Left ROI")
except Exception as e:
pass
try:
config.set("Cameras", "Left ROI", textboxValue6 + "px")
config.set("Left ROI", "ROI", textboxValue6 + "px")
except Exception as e:
pass
config.write(f)
......@@ -550,8 +554,8 @@ class Ui_MainWindow(object):
config = configparser.RawConfigParser()
f = open("cameras.ini", "w")
config.add_section("Cameras")
config.set("Cameras", "Width ROI", textboxValue7 + "px")
config.add_section("Width ROI")
config.set("Width ROI", "ROI", textboxValue7 + "px")
config.write(f)
else:
......@@ -572,14 +576,15 @@ class Ui_MainWindow(object):
print("Width ROI: " + textboxValue7 + "px")
config = configparser.RawConfigParser()
config.read("cameras.ini")
f = open("cameras.ini", "w")
try:
config.add_section("Cameras")
config.add_section("Width ROI")
except Exception as e:
pass
try:
config.set("Cameras", "Width ROI", textboxValue7 + "px")
config.set("Width ROI", "ROI", textboxValue7 + "px")
except Exception as e:
pass
config.write(f)
......@@ -597,7 +602,7 @@ class Ui_MainWindow(object):
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/cameras")
client.subscribe("microscope/light_sheet_microscope/UI/cameras")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/cameras")
client.publish("microscope/light_sheet_microscope/UI/cameras", json.dumps({"type": "device", "payload":{"name": "cameras", "height ROI": textboxValue7 + "px", "cmd": "set height ROI"}}, indent=2))
client.publish("microscope/light_sheet_microscope/UI/cameras", json.dumps({"type": "device", "payload":{"name": "cameras", "height ROI": textboxValue8 + "px", "cmd": "set height ROI"}}, indent=2))
time.sleep(1)
client.loop_stop()
print("Height ROI: " + textboxValue8 + "px")
......@@ -606,7 +611,7 @@ class Ui_MainWindow(object):
f = open("cameras.ini", "w")
config.add_section("Cameras")
config.set("Cameras", "Height ROI", textboxValue8 + "px")
config.set("Height ROI", "ROI", textboxValue8 + "px")
config.write(f)
else:
......@@ -621,24 +626,91 @@ class Ui_MainWindow(object):
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/cameras")
client.subscribe("microscope/light_sheet_microscope/UI/cameras")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/cameras")
client.publish("microscope/light_sheet_microscope/UI/cameras", json.dumps({"type": "device", "payload":{"name": "cameras", "height ROI": textboxValue7 + "px", "cmd": "set height ROI"}}, indent=2))
client.publish("microscope/light_sheet_microscope/UI/cameras", json.dumps({"type": "device", "payload":{"name": "cameras", "height ROI": textboxValue8 + "px", "cmd": "set height ROI"}}, indent=2))
time.sleep(1)
client.loop_stop()
print("Height ROI: " + textboxValue8 + "px")
config = configparser.RawConfigParser()
config.read("cameras.ini")
f = open("cameras.ini", "w")
try:
config.add_section("Cameras")
config.add_section("Height ROI")
except Exception as e:
pass
try:
config.set("Cameras", "Height ROI", textboxValue8 + "px")
config.set("Height ROI", "ROI", textboxValue8 + "px")
except Exception as e:
pass
config.write(f)
def stop(self):
client = device()
client.run()
client.loop_start()
print("\n" + "Connected to broker")
time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/cameras")
client.subscribe("microscope/light_sheet_microscope/UI/cameras")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/cameras")
client.publish("microscope/light_sheet_microscope/UI/cameras", json.dumps({"type": "device", "payload":{"name": "cameras", "cmd": "device turning off"}}, indent=2))
time.sleep(1)
client.loop_stop()
print("Cameras turning off")
self.pushButton_11.clicked.disconnect(self.stop)
self.pushButton_10.setChecked(False)
self.lineEdit.clear()
self.lineEdit.returnPressed.disconnect(self.exposureTime)
self.lineEdit_8.clear()
self.lineEdit_8.returnPressed.disconnect(self.delay)
self.lineEdit_2.clear()
self.lineEdit_2.returnPressed.disconnect(self.leftCamera)
self.lineEdit_3.clear()
self.lineEdit_3.returnPressed.disconnect(self.rightCamera)
self.lineEdit_4.clear()
self.lineEdit_4.returnPressed.disconnect(self.topROI)
self.lineEdit_5.clear()
self.lineEdit_5.returnPressed.disconnect(self.widthROI)
self.lineEdit_6.clear()
self.lineEdit_6.returnPressed.disconnect(self.leftROI)
self.lineEdit_7.clear()
self.lineEdit_7.returnPressed.disconnect(self.heightROI)
def on(self):
if self.pushButton_10.isChecked():
if os.path.exists("cameras.ini"):
config = configparser.RawConfigParser()
config.read("cameras.ini")
client = device()
client.run()
client.loop_start()
print("\n" + "Connected to broker")
time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/cameras")
client.subscribe("microscope/light_sheet_microscope/UI/cameras")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/cameras")
client.publish("microscope/light_sheet_microscope/UI/cameras", json.dumps({"type": "device", "payload":{"name": "cameras", "cmd": "cameras turning on"}}, indent=2))
time.sleep(1)
client.loop_stop()
print("Cameras turned on")
self.pushButton_11.clicked.connect(self.stop)
self.pushButton_10.setCheckable(True)
self.lineEdit.returnPressed.connect(self.exposureTime)
self.lineEdit_8.returnPressed.connect(self.delay)
self.lineEdit_2.returnPressed.connect(self.leftCamera)
self.lineEdit_3.returnPressed.connect(self.rightCamera)
self.lineEdit_4.returnPressed.connect(self.topROI)
self.lineEdit_5.returnPressed.connect(self.widthROI)
self.lineEdit_6.returnPressed.connect(self.leftROI)
self.lineEdit_7.returnPressed.connect(self.heightROI)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
......@@ -671,6 +743,7 @@ class Ui_MainWindow(object):
self.label_8.setText(_translate("MainWindow", "Crop ROI"))
self.pushButton_9.setText(_translate("MainWindow", "ms"))
self.pushButton_10.setText(_translate("MainWindow", "ON"))
self.pushButton_11.setText(_translate("MainWindow", "OFF"))
if __name__ == "__main__":
import sys
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment