Commit cb138566 authored by Spencer Du's avatar Spencer Du

update

parent 6f445e86
import paho.mqtt.client as mqtt
import os
import sys
import PyQt5
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5 import QtWidgets, uic, QtCore
from mqtt import *
import json
import time
if hasattr(QtCore.Qt, 'AA_EnableHighDpiScaling'):
PyQt5.QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
if hasattr(QtCore.Qt, 'AA_UseHighDpiPixmaps'):
PyQt5.QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)
class MainWindow(QtWidgets.QMainWindow):
def __init__(self,parent = None):
QMainWindow.__init__(self)
super(MainWindow, self).__init__(parent)
self.mdi = QMdiArea()
self.setCentralWidget(self.mdi)
self.setMinimumSize(QSize(800, 600))
self.setWindowTitle("PyQt button example - pythonprogramminglanguage.com")
client = device()
client.run()
client.loop_start()
print("Connected to broker")
time.sleep(1)
print("Subscribing to topic", "microscope/light_sheet_microscope/UI/devices")
client.subscribe("microscope/light_sheet_microscope/UI/devices")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/devices")
client.publish("microscope/light_sheet_microscope/UI/devices", json.dumps({"type": "system", "payload":{"cmd": "get all devices"}}, indent=2))
time.sleep(1)
pybutton = QPushButton('Add device', self)
pybutton.clicked.connect(self.importbutton)
pybutton.move(100, 400)
pybutton.resize(150, 32)
self.combo = QComboBox(self)
self.combo.move(100,350)
self.combo.resize(100, 32)
menubar = self.menuBar()
devicesMenu = menubar.addMenu("Devices")
def readFile(fname):
try:
with open(fname, "r") as f:
for item in f:
self.combo.addItem(item, self.importbutton)
except:
print("No devices active")
readFile("list_of_device(s)_currently_active.txt")
def importbutton(self):
if not os.path.exists("laser.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/add device")
client.subscribe("microscope/light_sheet_microscope/UI/add device")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/add device")
client.publish("microscope/light_sheet_microscope/UI/add device", json.dumps({"type": "system", "payload":{"cmd": "init device panel"}}, indent=2))
time.sleep(1)
client.loop_stop()
self.fileName_UI = self.combo.currentText()
self.loadGUI()
print("Device panel initialised" + "\n")
else:
if os.path.exists("laser.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/laser")
client.subscribe("microscope/light_sheet_microscope/UI/laser")
print("Publishing message to topic", "microscope/light_sheet_microscope/UI/laser")
client.publish("microscope/light_sheet_microscope/UI/laser", json.dumps({"type": "device", "payload":{"name": "laser", "cmd": "set config"}}, indent=2))
time.sleep(1)
client.loop_stop()
self.fileName_UI = self.combo.currentText()
self.loadGUI()
print("Laser config set" + "\n")
def loadGUI(self):
module = __import__(self.fileName_UI.rstrip("\n"))
my_class = getattr(module, "SubWindow")
sub = QMdiSubWindow()
sub.setWidget(my_class())
sub.setWindowTitle(self.fileName_UI)
self.mdi.addSubWindow(sub)
sub.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
mainWin = MainWindow()
mainWin.show()
# publishedMessage = mainWin.getGUIFilename()
sys.exit(app.exec_())
\ No newline at end of file
import random
import asyncio
from actorio import Actor, Message, DataMessage, ask, EndMainLoop, Reference
class Cameras:
async def Cameras():
print("Camera")
class Cameras(Actor):
async def handle_message(self, message: Message):
print("Cameras")
await asyncio.sleep(2)
print("Unitialised")
await asyncio.sleep(2)
......@@ -14,5 +16,11 @@ class Cameras:
await asyncio.sleep(2)
print("Configured")
await asyncio.sleep(2)
print("Hello World Im a camera!" + "\n")
asyncio.run(Cameras())
\ No newline at end of file
await message.sender.tell(DataMessage(data="Hello World Im a camera!" + "\n", sender=self))
async def main():
# Let's create an instance of a Greeter actor and start it.
async with Cameras() as cameras:
# Then we'll just send it an empty message and wait for a response
reply : DataMessage = await ask(cameras, Message())
print(reply.data)
asyncio.get_event_loop().run_until_complete(main())
\ No newline at end of file
import random
import asyncio
from actorio import Actor, Message, DataMessage, ask, EndMainLoop, Reference
class FW:
async def FW():
class FW(Actor):
async def handle_message(self, message: Message):
print("Filter wheel")
await asyncio.sleep(2)
print("Unitialised")
......@@ -14,5 +16,11 @@ class FW:
await asyncio.sleep(2)
print("Configured")
await asyncio.sleep(2)
print("Hello World Im a filter wheel!" + "\n")
asyncio.run(FW())
\ No newline at end of file
await message.sender.tell(DataMessage(data="Hello World Im a filter wheel!" + "\n", sender=self))
async def main():
# Let's create an instance of a Greeter actor and start it.
async with FW() as fw:
# Then we'll just send it an empty message and wait for a response
reply : DataMessage = await ask(fw, Message())
print(reply.data)
asyncio.get_event_loop().run_until_complete(main())
\ No newline at end of file
import random
import asyncio
from actorio import Actor, Message, DataMessage, ask, EndMainLoop, Reference
from mqtt2 import *
class Laser:
async def Laser():
class Laser(Actor):
async def handle_message(self, message: Message):
print("Laser")
await asyncio.sleep(2)
print("Unitialised")
......@@ -15,8 +17,14 @@ class Laser:
await asyncio.sleep(2)
print("Configured")
await asyncio.sleep(2)
print("Hello World Im a laser!" + "\n")
asyncio.run(Laser())
await message.sender.tell(DataMessage(data="Hello World Im a laser!" + "\n", sender=self))
async def main():
# Let's create an instance of a Greeter actor and start it.
async with Laser() as laser:
# Then we'll just send it an empty message and wait for a response
reply : DataMessage = await ask(laser, Message())
print(reply.data)
asyncio.get_event_loop().run_until_complete(main())
def subscribe():
client = embedded()
......
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