Commit c403ff41 authored by Spencer Du's avatar Spencer Du

made improvements to UIs

parent 024ba0c1
......@@ -38,8 +38,6 @@ class MainWindow(QtWidgets.QMainWindow):
menubar = self.menuBar()
fileMenu = menubar.addMenu("Devices")
startMenu = menubar.addMenu("Start")
stopMenu = menubar.addMenu("Stop")
# startMenu.triggered.connect(self.start)
......@@ -96,7 +94,6 @@ class MainWindow(QtWidgets.QMainWindow):
sender = self.sender()
self.fileName_UI = sender.text()
self.loadGUI()
print("Laser config set" + "\n")
def loadGUI(self):
module = __import__(self.fileName_UI.rstrip("\n"))
......@@ -109,6 +106,21 @@ class MainWindow(QtWidgets.QMainWindow):
self.mdi.addSubWindow(sub)
sub.show()
def closeEvent(self, event):
client = device()
client.run()
client.loop_start()
print("\n" + "Connected to broker")
time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope")
client.subscribe("microscope/light_sheet_microscope")
print("Publishing message to topic", "microscope/light_sheet_microscope")
client.publish("microscope/light_sheet_microscope", json.dumps({"cmd": "Microscope shutting down"}, indent=2))
time.sleep(1)
client.loop_stop()
print("Microscope shut down")
if __name__ == "__main__":
app = QApplication(sys.argv)
mainWin = MainWindow()
......
......@@ -14,6 +14,8 @@ import configparser
import time
import json
from mqtt import *
from pynq.overlays.base import BaseOverlay
from pynq.lib import LED, Switch, Button
class Ui_Cameras(object):
def setupUi(self, Cameras):
......@@ -779,4 +781,8 @@ if __name__ == "__main__":
ui = Ui_Cameras()
ui.setupUi(Cameras)
Cameras.show()
print("LED 0 turning on")
base = BaseOverlay("base.bit")
led0 = base.leds[0]
led0.on()
sys.exit(app.exec_())
\ No newline at end of file
......@@ -2,12 +2,12 @@ import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from mqtt import *
from filterwheel2 import *
from filter_wheel2 import *
class SubWindow(QtWidgets.QMainWindow):
def __init__(self, parent = None):
super(SubWindow, self).__init__(parent)
self.setMinimumSize(QSize(379, 268))
self.setMinimumSize(379, 268)
self.ui = Ui_FilterWheel()
self.ui.setupUi(self)
......
......@@ -14,6 +14,8 @@ import configparser
import time
import json
from mqtt import *
from pynq.overlays.base import BaseOverlay
from pynq.lib import LED, Switch, Button
class Ui_FilterWheel(object):
def setupUi(self, FilterWheel):
......@@ -338,4 +340,8 @@ if __name__ == "__main__":
ui = Ui_FilterWheel()
ui.setupUi(FilterWheel)
FilterWheel.show()
print("LED 0 turning on")
base = BaseOverlay("base.bit")
led0 = base.leds[0]
led0.on()
sys.exit(app.exec_())
\ No newline at end of file
This diff is collapsed.
......@@ -19,60 +19,108 @@ class embedded(mqtt.Client):
print("message qos=", message.qos)
print("message retain flag=", message.retain)
m_in = json.loads(m_decode)
if message.topic == "microscope/light_sheet_microscope/UI/laser/445nm":
print("LED 0 flashing")
base = BaseOverlay("base.bit")
led0 = base.leds[0]
for i in range(20):
led0.toggle()
time.sleep(.1)
if message.topic == "microscope/light_sheet_microscope/UI/laser/488nm":
print("LED 0 flashing")
base = BaseOverlay("base.bit")
led0 = base.leds[0]
for i in range(20):
led0.toggle()
time.sleep(.1)
if message.topic == "microscope/light_sheet_microscope/UI/laser/515nm":
print("LED 0 flashing")
base = BaseOverlay("base.bit")
led0 = base.leds[0]
for i in range(20):
led0.toggle()
time.sleep(.1)
if message.topic == "microscope/light_sheet_microscope/UI/laser/561nm":
if message.topic == "microscope/light_sheet_microscope/UI/laser/445nm" and m_in["payload"]["cmd"] == "turning on laser":
print("Laser LED turning on")
base = BaseOverlay("base.bit")
led0 = base.leds[0]
led0.on()
if message.topic == "microscope/light_sheet_microscope/UI/laser/445nm" and m_in["payload"]["cmd"] == "turning off laser":
print("Laser LED turning off")
base = BaseOverlay("base.bit")
led0 = base.leds[0]
led0.off()
if message.topic == "microscope/light_sheet_microscope/UI/laser/488nm" and m_in["payload"]["cmd"] == "turning on laser":
print("Laser LED turning on")
base = BaseOverlay("base.bit")
led0 = base.leds[0]
for i in range(20):
led0.toggle()
time.sleep(.1)
led0.on()
if message.topic == "microscope/light_sheet_microscope/UI/laser/594nm":
print("LED 0 flashing")
if message.topic == "microscope/light_sheet_microscope/UI/laser/488nm" and m_in["payload"]["cmd"] == "turning off laser":
print("Laser LED turning off")
base = BaseOverlay("base.bit")
led0 = base.leds[0]
for i in range(20):
led0.toggle()
time.sleep(.1)
led0.off()
if message.topic == "microscope/light_sheet_microscope/UI/laser/638nm":
print("LED 0 flashing")
if message.topic == "microscope/light_sheet_microscope/UI/laser/515nm" and m_in["payload"]["cmd"] == "turning on laser":
print("Laser LED turning on")
base = BaseOverlay("base.bit")
led0 = base.leds[0]
for i in range(20):
led0.toggle()
time.sleep(.1)
led0.on()
if message.topic == "microscope/light_sheet_microscope/UI/laser" and m_in["payload"]["cmd"] == "device turning off":
print("Laser turning off")
client.loop_stop()
if message.topic == "microscope/light_sheet_microscope/UI/laser/515nm" and m_in["payload"]["cmd"] == "turning off laser":
print("Laser LED turning off")
base = BaseOverlay("base.bit")
led0 = base.leds[0]
led0.off()
if message.topic == "microscope/light_sheet_microscope/UI/laser/561nm" and m_in["payload"]["cmd"] == "turning on laser":
print("Laser LED turning on")
base = BaseOverlay("base.bit")
led0 = base.leds[0]
led0.on()
if message.topic == "microscope/light_sheet_microscope/UI/laser/561nm" and m_in["payload"]["cmd"] == "turning off laser":
print("Laser LED turning off")
base = BaseOverlay("base.bit")
led0 = base.leds[0]
led0.off()
if message.topic == "microscope/light_sheet_microscope/UI/laser/594nm" and m_in["payload"]["cmd"] == "turning on laser":
print("Laser LED turning on")
base = BaseOverlay("base.bit")
led0 = base.leds[0]
led0.on()
if message.topic == "microscope/light_sheet_microscope/UI/laser/594nm" and m_in["payload"]["cmd"] == "turning off laser":
print("Laser LED turning off")
base = BaseOverlay("base.bit")
led0 = base.leds[0]
led0.off()
if message.topic == "microscope/light_sheet_microscope/UI/laser/638nm" and m_in["payload"]["cmd"] == "turning on laser":
print("Laser LED turning on")
base = BaseOverlay("base.bit")
led0 = base.leds[0]
led0.on()
if message.topic == "microscope/light_sheet_microscope/UI/laser/638nm" and m_in["payload"]["cmd"] == "turning off laser":
print("Laser LED turning off")
base = BaseOverlay("base.bit")
led0 = base.leds[0]
led0.off()
if message.topic == "microscope/light_sheet_microscope/UI/laser/445nm" and m_in["payload"]["cmd"] == "set intensity of laser":
print(m_in["payload"]["voltage"])
dac = Pmod_DAC(base.PMODA)
dac.write(m_in["payload"]["voltage"])
if message.topic == "microscope/light_sheet_microscope/UI/laser/488nm" and m_in["payload"]["cmd"] == "set intensity of laser":
print(m_in["payload"]["voltage"])
dac = Pmod_DAC(base.PMODA)
dac.write(m_in["payload"]["voltage"])
if message.topic == "microscope/light_sheet_microscope/UI/laser/515nm" and m_in["payload"]["cmd"] == "set intensity of laser":
print(m_in["payload"]["voltage"])
dac = Pmod_DAC(base.PMODA)
dac.write(m_in["payload"]["voltage"])
if message.topic == "microscope/light_sheet_microscope/UI/laser/561nm" and m_in["payload"]["cmd"] == "set intensity of laser":
print(m_in["payload"]["voltage"])
dac = Pmod_DAC(base.PMODA)
dac.write(m_in["payload"]["voltage"])
if message.topic == "microscope/light_sheet_microscope/UI/laser/594nm" and m_in["payload"]["cmd"] == "set intensity of laser":
print(m_in["payload"]["voltage"])
dac = Pmod_DAC(base.PMODA)
dac.write(m_in["payload"]["voltage"])
if message.topic == "microscope/light_sheet_microscope/UI/laser/638nm" and m_in["payload"]["cmd"] == "set intensity of laser":
print(m_in["payload"]["voltage"])
dac = Pmod_DAC(base.PMODA)
dac.write(0.6)
dac.write(m_in["payload"]["voltage"])
def run(self):
self.connect("broker.hivemq.com", 1883, 60)
\ No newline at end of file
self.connect("broker.hivemq.com", 1883, 60)
import random
import sys
# class TestClass(object):
# def testFunc(self):
# hi = "in Test Func"
# print(hi)
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QDialog
from PyQt5.QtWidgets import QHBoxLayout
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtWidgets import QVBoxLayout
from PyQt5.QtWidgets import QWidget
# testInstance = TestClass()
# testInstance.testFunc()
# class TestClass(object):
# def f(self):
# global s
# s = "Look for Geeksforgeeks Python Section"
# global d
# d = "hi"
# Testc
class MovableWidget(QWidget):
def __init__(self):
super(MovableWidget, self).__init__()
# class Ui_Laser(object):
# def pizzais(self):
# return "yummy"
#remove the frame
self.setWindowFlags(Qt.CustomizeWindowHint)
self.pressing = False
# pizza = Ui_Laser()
# print(pizza.pizzais)
# overriding the three next methods is a way to customize your Widgets
# not just in terms of appearance but also behavioral.
class Samochod(object):
def test(self):
global hi
hi = "something"
def mousePressEvent(self, QMouseEvent):
#the pos of the widget when you first pressed it.
self.start = QMouseEvent.pos()
#to make sure you are holding mouse button down
self.pressing = True
def mouseMoveEvent(self, QMouseEvent):
# You can Verify if it's also the left button and some other things
# you need.
if self.pressing : #and QMouseEvent.type() == Qt.LeftButton
self.end = QMouseEvent.pos()
self.delta = self.mapToGlobal(self.end-self.start)
self.move(self.delta)
self.end = self.start
def mouseReleaseEvent(self, QMouseEvent):
self.pressing = False
# inherits from QDialog and from MovableWidget so we can have its properties.
class CustomDialog(QDialog, MovableWidget):
def __init__(self):
super(CustomDialog, self).__init__()
#Make the Dialog transparent
self.setAttribute(Qt.WA_TranslucentBackground)
# the widget will dispose itself according to the layout rules he's
# inserted into.
self.inner_widget = QWidget()
self.inner_widget.setFixedSize(300,300)
self.inner_layout = QHBoxLayout()
self.inner_widget.setLayout(self.inner_layout)
self.btn_change_color = QPushButton("Roll Color")
self.btn_change_color.setStyleSheet("""
background-color: green;
""")
# will connect to a function to be executed when the button is clicked.
self.btn_change_color.clicked.connect(self.change_color)
self.inner_layout.addWidget(self.btn_change_color)
# Choose among many layouts according to your needs, QVBoxLayout,
# QHBoxLayout, QStackedLayout, ... you can set its orientation
# you can set its policies, spacing, margins. That's one of the main
# concepts you have to learn to customize your Widget in the way
# you want.
self.layout = QVBoxLayout()
# stylesheet have basically CSS syntax can call it QSS.
# it can be used only on objects that come from Widgets
# Also one of the main things to learn about customizing Widgets.
# Note: The stylesheet you set in the "father" will be applied to its
# children. Unless you tell it to be applied only to it and/or specify
# each children's style.
# The point I used inside the StyleSheet before the QDialog
# e.g .QDialog and .QWidget says it'll be applied only to that
# instance.
self.setStyleSheet("""
.QDialog{
border-radius: 10px;
}
""")
self.inner_widget.setStyleSheet("""
.QWidget{
background-color: red;
}
""")
self.layout.addWidget(self.inner_widget)
self.setLayout(self.layout)
def change_color(self):
red = random.choice(range(0,256))
green = random.choice(range(0,256))
blue = random.choice(range(0,256))
self.inner_widget.setStyleSheet(
"""
background-color: rgb({},{},{});
""".format(red,green,blue)
)
# since MovableWidget inherits from QWidget it also have QWidget properties.
class ABitMoreCustomizedWidget(MovableWidget):
def __init__(self):
super(ABitMoreCustomizedWidget, self).__init__()
self.layout = QHBoxLayout()
self.setLayout(self.layout)
self.custom_button1 = CustomButton("Button 1")
self.custom_button1.clicked.connect(self.btn_1_pressed)
self.custom_button2 = CustomButton("Button 2")
self.custom_button2.clicked.connect(self.btn_2_pressed)
self.layout.addWidget(self.custom_button1)
self.layout.addWidget(self.custom_button2)
def btn_1_pressed(self):
self.custom_button1.hide()
self.custom_button2.show()
def btn_2_pressed(self):
self.custom_button2.hide()
self.custom_button1.show()
class CustomButton(QPushButton):
# it could receive args and keys** so all the QPushButton initializer
# would work for here too.
def __init__(self, txt):
super(CustomButton, self).__init__()
self.setText(txt)
self.setStyleSheet("""
QPushButton{
background-color: black;
border-radius: 5px;
color: white;
}
QPushButton::pressed{
background-color: blue;
}
QPushButton::released{
background-color: gray;
}
""")
if __name__ == "__main__":
app = QApplication(sys.argv)
custom_dialog = CustomDialog()
custom_widget = ABitMoreCustomizedWidget()
custom_dialog.show()
custom_widget.show()
sys.exit(app.exec_())
\ No newline at end of file
global no
no = "no"
ss = Samochod()
ss.test()
\ No newline at end of file
from asdsad import *
print(hi)
print(no)
\ No newline at end of file
[X]
position = 2um
[Y]
position = 2um
[Z]
position = 2um
[R]
degrees = 2deg
......@@ -12,6 +12,8 @@ import os
import configparser
import time
import json
from pynq.overlays.base import BaseOverlay
from pynq.lib import LED, Switch, Button
class Ui_Stage(object):
def setupUi(self, Stage):
......@@ -565,4 +567,8 @@ if __name__ == "__main__":
ui = Ui_Stage()
ui.setupUi(Stage)
Stage.show()
print("LED 0 turning on")
base = BaseOverlay("base.bit")
led0 = base.leds[0]
led0.on()
sys.exit(app.exec_())
\ No newline at end of file
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