Commit 0119c5a7 authored by Spencer Du's avatar Spencer Du

update code

parent c4a1450d
import sys
from PyQt5 import QtCore, QtGui, QtWidgets, uic
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from mqtt import *
from cameras2 import *
from mqtt import *
import json
import time
import sys
class SubWindow(QtWidgets.QMainWindow):
def __init__(self, parent = None):
......@@ -24,7 +27,6 @@ def main():
if __name__ == "__main__":
main()
# def on(self):
# client = device()
# client.run()
......
......@@ -15,12 +15,11 @@ import time
import json
from mqtt import *
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(468, 336)
self.centralwidget = QtWidgets.QWidget(MainWindow)
class Ui_Cameras(object):
def setupUi(self, Cameras):
Cameras.setObjectName("Cameras")
Cameras.resize(468, 336)
self.centralwidget = QtWidgets.QWidget(Cameras)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName("gridLayout")
......@@ -166,15 +165,15 @@ class Ui_MainWindow(object):
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.clicked.connect(self.off)
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)
Cameras.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(Cameras)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
Cameras.setStatusBar(self.statusbar)
self.retranslateUi(Cameras)
QtCore.QMetaObject.connectSlotsByName(Cameras)
def exposureTime(self):
if not os.path.exists("cameras.ini"):
......@@ -645,7 +644,7 @@ class Ui_MainWindow(object):
pass
config.write(f)
def stop(self):
def off(self):
client = device()
client.run()
......@@ -661,7 +660,7 @@ class Ui_MainWindow(object):
print("Cameras turning off")
self.pushButton_11.clicked.disconnect(self.stop)
self.pushButton_11.clicked.disconnect(self.off)
self.pushButton_10.setChecked(False)
self.lineEdit.clear()
self.lineEdit.returnPressed.disconnect(self.exposureTime)
......@@ -699,7 +698,7 @@ class Ui_MainWindow(object):
time.sleep(1)
client.loop_stop()
print("Cameras turned on")
self.pushButton_11.clicked.connect(self.stop)
self.pushButton_11.clicked.connect(self.off)
self.pushButton_10.setCheckable(True)
self.lineEdit.returnPressed.connect(self.exposureTime)
......@@ -710,7 +709,6 @@ class Ui_MainWindow(object):
self.lineEdit_5.returnPressed.connect(self.widthROI)
self.lineEdit_6.returnPressed.connect(self.leftROI)
self.lineEdit_7.returnPressed.connect(self.heightROI)
else:
config = configparser.RawConfigParser()
config.read("cameras.ini")
......@@ -728,7 +726,7 @@ class Ui_MainWindow(object):
time.sleep(1)
client.loop_stop()
print("Cameras turned on")
self.pushButton_11.clicked.connect(self.stop)
self.pushButton_11.clicked.connect(self.off)
self.pushButton_10.setCheckable(True)
self.lineEdit.returnPressed.connect(self.exposureTime)
......@@ -740,46 +738,45 @@ class Ui_MainWindow(object):
self.lineEdit_6.returnPressed.connect(self.leftROI)
self.lineEdit_7.returnPressed.connect(self.heightROI)
def retranslateUi(self, MainWindow):
def retranslateUi(self, Cameras):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton_2.setText(_translate("MainWindow", "px"))
self.comboBox.setItemText(0, _translate("MainWindow", "Program"))
self.comboBox.setItemText(1, _translate("MainWindow", "Shutter Priority"))
self.comboBox.setItemText(2, _translate("MainWindow", "Aperture Priority"))
self.comboBox.setItemText(3, _translate("MainWindow", "Manual"))
self.comboBox_2.setItemText(0, _translate("MainWindow", "Program"))
self.comboBox_2.setItemText(1, _translate("MainWindow", "Shutter Priority"))
self.comboBox_2.setItemText(2, _translate("MainWindow", "Aperture Priority"))
self.comboBox_2.setItemText(3, _translate("MainWindow", "Manual"))
self.pushButton.setText(_translate("MainWindow", "ms"))
self.pushButton_3.setText(_translate("MainWindow", "px"))
self.pushButton_7.setText(_translate("MainWindow", "px"))
self.pushButton_4.setText(_translate("MainWindow", "px"))
self.label_7.setText(_translate("MainWindow", "Lines"))
self.label_10.setText(_translate("MainWindow", "Width"))
self.label_3.setText(_translate("MainWindow", "Mode"))
self.label_12.setText(_translate("MainWindow", "Height"))
self.pushButton_6.setText(_translate("MainWindow", "px"))
self.label_4.setText(_translate("MainWindow", "Left"))
self.label_6.setText(_translate("MainWindow", "Right"))
self.label.setText(_translate("MainWindow", "Exposure Time"))
self.label_11.setText(_translate("MainWindow", "Left"))
self.pushButton_8.setText(_translate("MainWindow", "Reset Crop ROI"))
self.label_9.setText(_translate("MainWindow", "Top"))
self.pushButton_5.setText(_translate("MainWindow", "px"))
self.label_2.setText(_translate("MainWindow", "Delay"))
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"))
Cameras.setWindowTitle(_translate("Cameras", "MainWindow"))
self.pushButton_2.setText(_translate("Cameras", "px"))
self.comboBox.setItemText(0, _translate("Cameras", "Program"))
self.comboBox.setItemText(1, _translate("Cameras", "Shutter Priority"))
self.comboBox.setItemText(2, _translate("Cameras", "Aperture Priority"))
self.comboBox.setItemText(3, _translate("Cameras", "Manual"))
self.comboBox_2.setItemText(0, _translate("Cameras", "Program"))
self.comboBox_2.setItemText(1, _translate("Cameras", "Shutter Priority"))
self.comboBox_2.setItemText(2, _translate("Cameras", "Aperture Priority"))
self.comboBox_2.setItemText(3, _translate("Cameras", "Manual"))
self.pushButton.setText(_translate("Cameras", "ms"))
self.pushButton_3.setText(_translate("Cameras", "px"))
self.pushButton_7.setText(_translate("Cameras", "px"))
self.pushButton_4.setText(_translate("Cameras", "px"))
self.label_7.setText(_translate("Cameras", "Lines"))
self.label_10.setText(_translate("Cameras", "Width"))
self.label_3.setText(_translate("Cameras", "Mode"))
self.label_12.setText(_translate("Cameras", "Height"))
self.pushButton_6.setText(_translate("Cameras", "px"))
self.label_4.setText(_translate("Cameras", "Left"))
self.label_6.setText(_translate("Cameras", "Right"))
self.label.setText(_translate("Cameras", "Exposure Time"))
self.label_11.setText(_translate("Cameras", "Left"))
self.pushButton_8.setText(_translate("Cameras", "Reset Crop ROI"))
self.label_9.setText(_translate("Cameras", "Top"))
self.pushButton_5.setText(_translate("Cameras", "px"))
self.label_2.setText(_translate("Cameras", "Delay"))
self.label_8.setText(_translate("Cameras", "Crop ROI"))
self.pushButton_9.setText(_translate("Cameras", "ms"))
self.pushButton_10.setText(_translate("Cameras", "ON"))
self.pushButton_11.setText(_translate("Cameras", "OFF"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
Cameras = QtWidgets.QMainWindow()
ui = Ui_Cameras()
ui.setupUi(Cameras)
Cameras.show()
sys.exit(app.exec_())
\ No newline at end of file
......@@ -9,7 +9,7 @@ class SubWindow(QtWidgets.QMainWindow):
super(SubWindow, self).__init__(parent)
self.setMinimumSize(QSize(379, 268))
self.ui = Ui_Filterwheel()
self.ui = Ui_FilterWheel()
self.ui.setupUi(self)
def main():
......
......@@ -15,11 +15,11 @@ import time
import json
from mqtt import *
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(322, 161)
self.centralwidget = QtWidgets.QWidget(MainWindow)
class Ui_FilterWheel(object):
def setupUi(self, FilterWheel):
FilterWheel.setObjectName("MainWindow")
FilterWheel.resize(322, 161)
self.centralwidget = QtWidgets.QWidget(FilterWheel)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName("gridLayout")
......@@ -62,7 +62,7 @@ class Ui_MainWindow(object):
self.pushButton2.setObjectName("pushButton2")
self.gridLayout.addWidget(self.pushButton2, 0, 2, 1, 2)
self.pushButton2.setChecked(True)
self.pushButton2.clicked.connect(self.stop)
self.pushButton2.clicked.connect(self.off)
self.checkBox_2 = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_2.setText("")
self.checkBox_2.setObjectName("checkBox_2")
......@@ -92,13 +92,12 @@ class Ui_MainWindow(object):
self.comboBox_2.addItem("")
self.comboBox_2.setItemText(6, "")
self.gridLayout.addWidget(self.comboBox_2, 2, 2, 2, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
FilterWheel.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(FilterWheel)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
FilterWheel.setStatusBar(self.statusbar)
self.retranslateUi(FilterWheel)
QtCore.QMetaObject.connectSlotsByName(FilterWheel)
def link(self):
if not os.path.exists("filter wheel.ini"):
......@@ -230,7 +229,7 @@ class Ui_MainWindow(object):
pass
config.write(f)
def stop(self):
def off(self):
client = device()
client.run()
......@@ -245,7 +244,7 @@ class Ui_MainWindow(object):
client.loop_stop()
print("Filter wheel turning off")
self.pushButton2.clicked.disconnect(self.stop)
self.pushButton2.clicked.disconnect(self.off)
self.pushButton.setChecked(False)
self.checkBox.setChecked(False)
self.checkBox.setCheckable(False)
......@@ -273,7 +272,7 @@ class Ui_MainWindow(object):
client.loop_stop()
print("Filter wheel turning on")
self.pushButton2.clicked.connect(self.stop)
self.pushButton2.clicked.connect(self.off)
self.pushButton.setChecked(True)
self.checkBox.setChecked(True)
self.checkBox.setCheckable(True)
......@@ -297,7 +296,7 @@ class Ui_MainWindow(object):
client.loop_stop()
print("Filter wheel turning on")
self.pushButton2.clicked.connect(self.stop)
self.pushButton2.clicked.connect(self.off)
self.pushButton.setChecked(True)
self.checkBox.setChecked(True)
self.checkBox.setCheckable(True)
......@@ -306,37 +305,37 @@ class Ui_MainWindow(object):
self.checkBox_2.setCheckable(True)
self.checkBox_2.clicked.connect(self.link2)
def retranslateUi(self, MainWindow):
def retranslateUi(self, FilterWheel):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.comboBox.setItemText(0, _translate("MainWindow", "1"))
self.comboBox.setItemText(1, _translate("MainWindow", "2"))
self.comboBox.setItemText(2, _translate("MainWindow", "3"))
self.comboBox.setItemText(3, _translate("MainWindow", "4"))
self.comboBox.setItemText(4, _translate("MainWindow", "5"))
self.comboBox.setItemText(5, _translate("MainWindow", "6"))
self.label_3.setText(_translate("MainWindow", "Left magnification changer"))
self.label_2.setText(_translate("MainWindow", "Right filter wheel"))
self.comboBox_3.setItemText(0, _translate("MainWindow", "22.2x"))
self.comboBox_4.setItemText(0, _translate("MainWindow", "22.2x"))
self.label_4.setText(_translate("MainWindow", "Right magnification changer"))
self.label.setText(_translate("MainWindow", "Left filter wheel"))
self.pushButton.setText(_translate("MainWindow", "ON"))
self.pushButton2.setText(_translate("MainWindow", "OFF"))
self.label_5.setText(_translate("MainWindow", "link"))
self.label_6.setText(_translate("MainWindow", "link"))
self.comboBox_2.setItemText(0, _translate("MainWindow", "1"))
self.comboBox_2.setItemText(1, _translate("MainWindow", "2"))
self.comboBox_2.setItemText(2, _translate("MainWindow", "3"))
self.comboBox_2.setItemText(3, _translate("MainWindow", "4"))
self.comboBox_2.setItemText(4, _translate("MainWindow", "5"))
self.comboBox_2.setItemText(5, _translate("MainWindow", "6"))
FilterWheel.setWindowTitle(_translate("FilterWheel", "MainWindow"))
self.comboBox.setItemText(0, _translate("FilterWheel", "1"))
self.comboBox.setItemText(1, _translate("FilterWheel", "2"))
self.comboBox.setItemText(2, _translate("FilterWheel", "3"))
self.comboBox.setItemText(3, _translate("FilterWheel", "4"))
self.comboBox.setItemText(4, _translate("FilterWheel", "5"))
self.comboBox.setItemText(5, _translate("FilterWheel", "6"))
self.label_3.setText(_translate("FilterWheel", "Left magnification changer"))
self.label_2.setText(_translate("FilterWheel", "Right filter wheel"))
self.comboBox_3.setItemText(0, _translate("FilterWheel", "22.2x"))
self.comboBox_4.setItemText(0, _translate("FilterWheel", "22.2x"))
self.label_4.setText(_translate("FilterWheel", "Right magnification changer"))
self.label.setText(_translate("FilterWheel", "Left filter wheel"))
self.pushButton.setText(_translate("FilterWheel", "ON"))
self.pushButton2.setText(_translate("FilterWheel", "OFF"))
self.label_5.setText(_translate("FilterWheel", "link"))
self.label_6.setText(_translate("FilterWheel", "link"))
self.comboBox_2.setItemText(0, _translate("FilterWheel", "1"))
self.comboBox_2.setItemText(1, _translate("FilterWheel", "2"))
self.comboBox_2.setItemText(2, _translate("FilterWheel", "3"))
self.comboBox_2.setItemText(3, _translate("FilterWheel", "4"))
self.comboBox_2.setItemText(4, _translate("FilterWheel", "5"))
self.comboBox_2.setItemText(5, _translate("FilterWheel", "6"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
FilterWheel = QtWidgets.QMainWindow()
ui = Ui_FilterWheel()
ui.setupUi(FilterWheel)
FilterWheel.show()
sys.exit(app.exec_())
\ No newline at end of file
......@@ -200,7 +200,7 @@ class Ui_Laser(object):
self.gridLayout.addWidget(self.pushButton_8, 1, 0, 1, 2)
self.pushButton_7 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_7.setChecked(True)
self.pushButton_7.clicked.connect(self.stop)
self.pushButton_7.clicked.connect(self.off)
self.pushButton_7.setObjectName("pushButton_7")
self.gridLayout.addWidget(self.pushButton_7, 1, 2, 1, 2)
self.label_8 = QtWidgets.QLabel(self.centralwidget)
......@@ -1145,7 +1145,7 @@ class Ui_Laser(object):
time.sleep(1)
client.loop_stop()
print("Laser turned on")
self.pushButton_7.clicked.connect(self.stop)
self.pushButton_7.clicked.connect(self.off)
self.pushButton.setCheckable(True)
self.pushButton.clicked.connect(self.btnstate)
self.pushButton_2.setCheckable(True)
......@@ -1187,11 +1187,11 @@ class Ui_Laser(object):
self.pushButton_5.clicked.connect(self.btnstate5)
self.pushButton_6.setCheckable(True)
self.pushButton_6.clicked.connect(self.btnstate6)
self.pushButton_7.clicked.connect(self.stop)
self.pushButton_7.clicked.connect(self.off)
else:
pass
def stop(self):
def off(self):
client = device()
client.run()
......@@ -1204,7 +1204,7 @@ class Ui_Laser(object):
client.publish("microscope/light_sheet_microscope/UI/laser", json.dumps({"type": "device", "payload":{"name": "laser", "cmd": "device turning off"}}, indent=2))
time.sleep(1)
client.loop_stop()
self.pushButton_7.clicked.disconnect(self.stop)
self.pushButton_7.clicked.disconnect(self.off)
self.pushButton_8.setChecked(False)
try:
self.pushButton.setChecked(False)
......
import random
import sys
from PyQt5.QtWidgets import (QWidget, QLabel, QHBoxLayout,QCheckBox, QApplication)
from PyQt5 import QtCore
class basicWindow(QWidget):
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
class MovableWidget(QWidget):
def __init__(self):
super().__init__()
layout = QHBoxLayout()
self.setLayout(layout)
self.checkBoxA = QCheckBox("Select This.")
self.labelA = QLabel("Not slected.")
self.checkBoxA.stateChanged.connect(self.checkBoxChangedAction)
layout.addWidget(self.checkBoxA)
layout.addWidget(self.labelA)
self.setGeometry(200, 200, 300, 200)
self.setWindowTitle('CheckBox Example')
def checkBoxChangedAction(self, state):
if (QtCore.Qt.Checked == state):
print("selected")
else:
print("Not Selected.")
if __name__ == '__main__':
super(MovableWidget, self).__init__()
#remove the frame
self.setWindowFlags(Qt.CustomizeWindowHint)
self.pressing = False
# overriding the three next methods is a way to customize your Widgets
# not just in terms of appearance but also behavioral.
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)
windowExample = basicWindow()
windowExample.show()
custom_dialog = CustomDialog()
custom_widget = ABitMoreCustomizedWidget()
custom_dialog.show()
custom_widget.show()
sys.exit(app.exec_())
\ No newline at end of file
import aiohttp
from aiohttp import web
from actorio import Actor, EndMainLoop
import asyncio
class Client(Actor):
def __init__(self, websocket: web.WebSocketResponse):
self.websocket = websocket
super().__init__()
# Here we define an input task handler,
# It will be called each time its registered event happens.
# The resulting `asyncio.Task` object will be passed as argument,
# this way, the handler can deal with any exception raised during event collection
async def handle_websocket_event(self, task: asyncio.Task):
try:
msg = task.result()
except Exception as e:
# In case of any exception, we just stop the Actor
self.logger.exception(e)
raise EndMainLoop()
if msg.type == aiohttp.WSMsgType.TEXT:
# if we receive text, we just send it back
# We could also just send a message to our inbox
await self.websocket.send_str(msg.data)
else:
# any other request just stops the Actor
raise EndMainLoop()
async def mainloop_setup(self):
self.register_input_task(self.websocket.receive, self.handle_websocket_event)
await super().mainloop_setup()
async def websocket_handler(request):
ws = web.WebSocketResponse()
await ws.prepare(request)
client_actor = Client(websocket=ws)
async with client_actor:
# We until the client's mainloop ends
await client_actor
return ws
app = web.Application()
app.add_routes([web.get('/', websocket_handler)])
web.run_app(app)
\ No newline at end of file
button = 5
print(button + 6 + str")
\ No newline at end of file
import numpy as np
import cv2
class Camera:
def __init__(self, cam_num):
self.cam_num = cam_num
self.cap = None
self.last_frame = np.zeros((1,1))
def initialize(self):
self.cap = cv2.VideoCapture(self.cam_num)
def get_frame(self):
ret, self.last_frame = self.cap.read()
return self.last_frame
def acquire_movie(self, num_frames):
movie = []
for _ in range(num_frames):
movie.append(self.get_frame())
return movie
def set_brightness(self, value):
self.cap.set(cv2.CAP_PROP_BRIGHTNESS, value)
def get_brightness(self):
return self.cap.get(cv2.CAP_PROP_BRIGHTNESS)
def close_camera(self):
self.cap.release()
def __str__(self):
return 'OpenCV Camera {}'.format(self.cam_num)
if __name__ == '__main__':
cam = Camera(0)
cam.initialize()
print(cam)
frame = cam.get_frame()
print(frame)
cam.set_brightness(1)
print(cam.get_brightness())
cam.set_brightness(0.5)
print(cam.get_brightness())
cam.close_camera()
\ No newline at end of file
[X]
position = 2um