1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
| #! /usr/bin/env python3.5
# -*- coding: utf-8 -*-
#
import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import *
import serial
import time as time
# Create an PyQT4 application object.
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QSlider, QVBoxLayout, QMainWindow, QSpinBox, \
QListWidget, QComboBox
# from PyQt5.QtWidgets.QListWidget import QListWidget
from qtconsole.qt import QtGui
from requests.packages.urllib3.contrib.pyopenssl import orig_util_SSLContext
class App(QMainWindow):
def __init__(self):
super().__init__()
self.title = "Choosing color light"
self.left = 10
self.top = 30
self.width = 440
self.height = 280
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
connected = False
ser = serial.Serial("COM7", 38400, parity=serial.PARITY_NONE, timeout=1)
ser.xonxoff = True
time.sleep(0.5)
if connected: print("yes")
ser.write(b"raw")
a = ser.read(100)
while a[:10] == (b"raw\r\nERROR"):
ser.write(b"raw")
a = ser.read(100)
# print(a)
ser.write(b"0,0,0\r\n")
print(ser.read(100))
rspinner = QSpinBox(self)
gspinner = QSpinBox(self)
bspinner = QSpinBox(self)
rbtn = QtGui.QPushButton("RED", self)
rbtn.setStyleSheet(" padding: 15px 25px;"
"font-size: 24px;"
"text-align: center;"
"cursor: pointer;"
"outline: none;"
"color: #fff;"
"background-color: #B22222;"
"border: none;"
"border-radius: 15px;"
"box-shadow: 0 9px #999;"
)
rbtn.setStyleSheet("QPushButton:hover {background-color : #B22222}")
rbtn.setStyleSheet("QPushButton:active {background-color: #B22222;"
" box-shadow: 0 5px #666;"
" transform: translateY(4px);}")
rbtn.setToolTip('Couleur rouge')
rbtn.clicked.connect(lambda: self.color(ser, 255, 0, 0))
# rbtn.resize(rbtn.sizeHint())
rbtn.move(20, 40)
rspinner.setFocusPolicy(Qt.StrongFocus)
rspinner.setSingleStep(1)
rspinner.setRange(0, 255)
rspinner.move(20, 70)
rspinner.valueChanged.connect(lambda : self.color(ser, rspinner.value(), gspinner.value(), bspinner.value()))
#rspinner.mousePressEvent(self.color(ser, rspinner.value(), gspinner.value(), bspinner.value()))
gbtn = QPushButton("GREEN", self)
gbtn.setStyleSheet("QPushButton{ padding: 15px 25px;"
"font-size: 24px;"
"text-align: center;"
"cursor: pointer;"
"outline: none;"
"color: #fff;"
"background-color: #008000;"
"border: none;"
"border-radius: 15px;"
"box-shadow: 0 9px #999;}"
)
gbtn.setStyleSheet("QPushButton:hover {background-color : #008000}")
gbtn.setStyleSheet("QPushButton:active {background-color: #008000;"
" box-shadow: 0 5px #666;"
" transform: translateY(4px);}")
gbtn.setToolTip('Couleur verte')
gbtn.clicked.connect(lambda: self.color(ser, 0, 255, 0))
# gbtn.resize(rbtn.sizeHint())
gbtn.move(300, 40)
gspinner.setFocusPolicy(Qt.StrongFocus)
gspinner.setSingleStep(1)
gspinner.setRange(0, 255)
gspinner.move(300, 70)
#print(gspinner.value())
gspinner.valueChanged.connect(lambda: self.color(ser, rspinner.value(), gspinner.value(), bspinner.value()))
bbtn = QPushButton("BLUE", self)
bbtn.setStyleSheet("QPushButton{ padding: 15px 25px;"
"font-size: 24px;"
"text-align: center;"
"cursor: pointer;"
"outline: none;"
"color: #fff;"
"background-color: #0000FF;"
"border: none;"
"border-radius: 15px;"
"box-shadow: 0 9px #999;}"
)
bbtn.setStyleSheet("QPushButton:hover {background-color : #0000FF}")
bbtn.setStyleSheet("QPushButton:active {background-color: #0000FF;"
"box-shadow: 0 5px #666;"
"transform: translateY(4px);}")
bbtn.setToolTip('Couleur bleue')
bbtn.clicked.connect(lambda: self.color(ser, 0, 0, 255))
# bbtn.resize(bbtn.sizeHint())
bbtn.move(20, 200)
bspinner.setFocusPolicy(Qt.StrongFocus)
bspinner.setSingleStep(1)
bspinner.setRange(0, 255)
bspinner.move(20, 230)
bspinner.valueChanged.connect(lambda: self.color(ser, rspinner.value(), gspinner.value(), bspinner.value()))
bspinner.valueChanged.connect(lambda: print("DEDANS"))
wbtn = QPushButton("WHITE", self)
wbtn.setStyleSheet("QPushButton{ padding: 15px 25px;"
"font-size: 24px;"
"text-align: center;"
"cursor: pointer;"
"outline: none;"
"color: #fff;"
"background-color: #FFFFFF;"
"border: none;"
"border-radius: 15px;"
"box-shadow: 0 9px #999;}"
)
wbtn.setStyleSheet("QPushButton:hover {background-color : #FFFFFF}")
wbtn.setStyleSheet("QPushButton:active {background-color: #FFFFFF;"
" box-shadow: 0 5px #666;"
" transform: translateY(4px);}")
wbtn.setToolTip('White Light')
wbtn.clicked.connect(lambda: self.color(ser, 255, 255, 255))
# wbtn.resize(wbtn.sizeHint())
wbtn.move(300, 200)
# self.cb = QComboBox(self)
# self.cb.addItems(["1","2", "5", "10", "20"])
# self.cb.move(170,120)
# self.cb.currentIndexChanged.connect(self.cb.)
sp = QSpinBox(self)
sp.setFocusPolicy(Qt.StrongFocus)
sp.setSingleStep(1)
sp.setRange(0, 255)
sp.move(170, 120)
# print(sp.value())
#sp.valueChanged.connect(lambda: self.spinnerVal(self.rspinner, self.sp))
sp.valueChanged.connect(lambda : rspinner.setSingleStep(sp.value()))
sp.valueChanged.connect(lambda: gspinner.setSingleStep(sp.value()))
sp.valueChanged.connect(lambda: bspinner.setSingleStep(sp.value()))
#print("FAIIIT")
self.show()
def spinnerVal(self, rspinner1, sp1):
rspinner, sp = rspinner1, sp1
#print("VALEUR SPINNER ROUGE")
#print(self.rspinner.value)
# print("apres")
# rspinner.stepBy(sp.valueChanged())
# print("laaaaa")
return;
def color(self, ser1, r1, g1, b1):
print("APPPEL COLOR")
ser2, r2, g2, b2 = ser1, r1, g1, b1
ser2.write(b"raw")
a = ser2.read(100)
while a[:10] == (b"raw\r\nERROR"):
ser2.write(b"raw")
a = ser2.read(100)
s = "{0},{1},{2}\r\n".format(r2, g2, b2)
ser2.write(s.encode('utf-8'))
a = ser2.read(100)
print(a)
return;
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_()) |
Partager