Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- # Form implementation generated from reading ui file 'arduinogui.ui'
- #
- # Created: Sun Aug 21 20:19:53 2011
- # by: PyQt4 UI code generator 4.7.3
- #
- # WARNING! All changes made in this file will be lost!
- import sys, time, threading, Queue, struct
- from PyQt4 import QtGui, QtCore
- from socket import *
- import guiClass
- netSocket = None
- serveradress = 'localhost'
- port = 32800
- bufsize = 2048
- class Dialog(QtGui.QDialog, guiClass.Ui_Dialog):
- def __init__(self, inputQ, outputQ, endcommand, connection, parent=None, f=QtCore.Qt.WindowFlags()):
- QtGui.QDialog.__init__(self, parent, f)
- self.inputQ = inputQ
- self.outputQ = outputQ
- self.manager = CommunicationManager
- self.endcommand = endcommand
- self.connection = connection
- self.dicoParam = {'mode':'#', 'abs':'#', 'vac':'#', 't_jour':'#', 't_nuit':'#', 't_abs':'#', 't_vac':'#', 'cal':'#', 'day_at':'#', 'night_at':'#'}
- self.listeParams = ()
- self.setupUi(self)
- def closeEvent(self, ev):
- self.endcommand()
- def processIncoming(self):
- """
- Handle all the messages currently in the queue (if any).
- """
- try:
- msg = self.inputQ.get(0)
- #msg = self.inputQ.get_nowait()
- print msg
- # Check contents of message and do what it says
- # As a test, we simply print it
- if msg[0:9] == "connected":
- self.label_connectStatus.setText("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:14pt; color:#ff0000;\">Connected</span></p></body></html>")
- if msg[0:5] == "relay":
- self.singleRs485color(msg[5], msg[7])
- if msg[0:4] == "data":
- lst = msg[1:].split(';') # 1:temp1, 2:temp2, 3:temp3, 4:temp4, 5:lightval, 6:lux, 7:mode, 8:Chauffe, 9:hour, 10:minute, 9:time_abs, 10:time_vac, 11:consigne_jour, 12:consigne_nuit, 13:consigne_abs, 14:consigne_vac, 15:calibrage, 16:day_at, 17:night_at
- if lst[7] == "1":
- self.label_modeEcran1.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:11pt; font-weight:600; color:#ff0000;\">Auto</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
- self.label_modeEcran2.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:11pt; font-weight:600; color:#ff0000;\">Auto</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
- if lst[7] == "2":
- self.label_modeEcran1.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:11pt; font-weight:600; color:#ff0000;\">Absent</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
- self.label_modeEcran2.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:11pt; font-weight:600; color:#ff0000;\">Absent</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
- if lst[7] == "3":
- self.label_modeEcran1.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:11pt; font-weight:600; color:#ff0000;\">Vacances</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
- self.label_modeEcran2.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:11pt; font-weight:600; color:#ff0000;\">Vacances</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
- if lst[7] == "4":
- self.label_modeEcran1.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:11pt; font-weight:600; color:#ff0000;\">Off</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
- self.label_modeEcran2.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:11pt; font-weight:600; color:#ff0000;\">Off</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
- self.label_tempRdc.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:11pt; color:#0000ff;\">%s</span></p></body></html>" %(lst[1]), None, QtGui.QApplication.UnicodeUTF8))
- self.label_tempE1.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:11pt; color:#0000ff;\">%s</span></p></body></html>" %(lst[2]), None, QtGui.QApplication.UnicodeUTF8))
- self.label_tempE2.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:11pt; color:#0000ff;\">%s</span></p></body></html>" %(lst[3]), None, QtGui.QApplication.UnicodeUTF8))
- self.label_tempExt.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:11pt; color:#0000ff;\">%s</span></p></body></html>" %(lst[4]), None, QtGui.QApplication.UnicodeUTF8))
- self.label_luxIn.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" color:#0000ff;\">%s</span></p></body></html>" %(lst[5]), None, QtGui.QApplication.UnicodeUTF8))
- self.label_luxOut.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:11pt; color:#0000ff;\">%s</span></p></body></html>" %(lst[6]), None, QtGui.QApplication.UnicodeUTF8))
- if lst[8] == "0":
- self.label_furnace.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:11pt; font-weight:600; color:#ff0000;\">OFF</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
- if lst[8] == "1":
- self.label_furnace.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:11pt; font-weight:600; color:#ff0000;\">ON</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
- self.label_clock.setText("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p align=\"right\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:11pt; color:#0000ff;\">%s:%s</span></p></body></html>" %(lst[9], lst[10]))
- self.label_showParamDay.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p align=\"right\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600;\">%s</span></p></body></html>" %(lst[13]), None, QtGui.QApplication.UnicodeUTF8))
- self.label_showParamNight.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p align=\"right\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600;\">%s</span></p></body></html>" %(lst[14]), None, QtGui.QApplication.UnicodeUTF8))
- self.label_showParamAbsence.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p align=\"right\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600;\">%s</span></p></body></html>" %(lst[15]), None, QtGui.QApplication.UnicodeUTF8))
- self.label_showParamHolidays.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p align=\"right\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600;\">%s</span></p></body></html>" %(lst[16]), None, QtGui.QApplication.UnicodeUTF8))
- self.label_showParamDayat.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p align=\"right\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600;\">%s</span></p></body></html>" %(lst[18]), None, QtGui.QApplication.UnicodeUTF8))
- self.label_showParamNightat.setText(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p align=\"right\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600;\">%s</span></p></body></html>" %(lst[19]), None, QtGui.QApplication.UnicodeUTF8))
- except Queue.Empty: pass
- def singleRs485switch(self, num, state) :
- self.outputQ.put("*RELAY;%s;%s!" %(num, state))
- def singleRs485color(self, relay, toggle) :
- if relay == "1":
- if toggle == "1" :
- self.label_relay1led.setPixmap(QtGui.QPixmap("./img/led_green.png"))
- if toggle == "0" :
- self.label_relay1led.setPixmap(QtGui.QPixmap("./img/led_red.png"))
- if relay == "2":
- if toggle == "1" :
- self.label_relay2led.setPixmap(QtGui.QPixmap("./img/led_green.png"))
- if toggle == "0" :
- self.label_relay2led.setPixmap(QtGui.QPixmap("./img/led_red.png"))
- if relay == "3":
- if toggle == "1" :
- self.label_relay3led.setPixmap(QtGui.QPixmap("./img/led_green.png"))
- if toggle == "0" :
- self.label_relay3led.setPixmap(QtGui.QPixmap("./img/led_red.png"))
- if relay == "4":
- if toggle == "1" :
- self.label_relay4led.setPixmap(QtGui.QPixmap("./img/led_green.png"))
- if toggle == "0" :
- self.label_relay4led.setPixmap(QtGui.QPixmap("./img/led_red.png"))
- if relay == "5":
- if toggle == "1" :
- self.label_relay5led.setPixmap(QtGui.QPixmap("./img/led_green.png"))
- if toggle == "0" :
- self.label_relay5led.setPixmap(QtGui.QPixmap("./img/led_red.png"))
- if relay == "6":
- if toggle == "1" :
- self.label_relay6led.setPixmap(QtGui.QPixmap("./img/led_green.png"))
- if toggle == "0" :
- self.label_relay6led.setPixmap(QtGui.QPixmap("./img/led_red.png"))
- if relay == "7":
- if toggle == "1" :
- self.label_relay7led.setPixmap(QtGui.QPixmap("./img/led_green.png"))
- if toggle == "0" :
- self.label_relay7led.setPixmap(QtGui.QPixmap("./img/led_red.png"))
- if relay == "8":
- if toggle == "1" :
- self.label_relay8led.setPixmap(QtGui.QPixmap("./img/led_green.png"))
- if toggle == "0" :
- self.label_relay8led.setPixmap(QtGui.QPixmap("./img/led_red.png"))
- def update_abs(self, value):
- # a = str(time.time() - time.timezone + time.daylight*3600)[0:10]
- a = str(time.time() + 3600)[0:10]
- b = int(value)*3600
- c = int(a) + b
- self.messageParam("abs", "%s" %c)
- def update_holidays(self, value):
- # value = "PyQt4.QtCore.QDateTime(2011, 9, 11, 12, 15)" time.mktime(tuple de 9 chiffres)
- a = "%s" %value
- b = a.split("(")
- c = b[1].replace(" ", "")
- d = c[:-1]
- liste = (a[:-1].split("(")[1].replace(" ", "")).split(',')
- self.messageParam("vac", "%s" %(str(time.mktime((int(liste[0]), int(liste[1]), int(liste[2]), int(liste[3]), int(liste[4]), 0, 0, 0, 0)))[0:10]))
- #self.messageParam("vac", "%s" %d) #liste = (a[:-1].split("(")[1].replace(" ", "")).split(',')
- # str(time.mktime((int(liste[0]), int(liste[1]), int(liste[2]), int(liste[3]), int(liste[4]), 0, 0, 0, 0)))[0:10]
- def update_dayT(self, value):
- self.messageParam("t_jour", "%s" %value.replace(",", "."))
- def update_nightT(self, value):
- self.messageParam("t_nuit", "%s" %value.replace(",", "."))
- def update_absT(self, value):
- self.messageParam("t_abs", "%s" %value.replace(",", "."))
- def update_vacT(self, value):
- self.messageParam("t_vac", "%s" %value.replace(",", "."))
- def update_factor(self, value):
- self.messageParam("cal", "%s" %value.replace(",", "."))
- def update_dayat(self, value):
- a = "%s" %value
- b = a.split("(")
- c = b[1].replace(" ", "")
- d = c[:-1].split(",") # liste = (a[:-1].split("(")[1].replace(" ", "")).split(",")
- e = (int(d[0])*60) + int(d[1]) # = int(liste[0])*60 + int(liste[1])
- self.messageParam("day_at", "%s" %e)
- def update_nightat(self, value):
- a = "%s" %value
- b = a.split("(")
- c = b[1].replace(" ", "")
- d = c[:-1].split(",") # liste = (a[:-1].split("(")[1].replace(" ", "")).split(",")
- e = (int(d[0])*60) + int(d[1]) # = int(liste[0])*60 + int(liste[1])
- self.messageParam("night_at", "%s" %e)
- def update_mode(self, index):
- if index == 0:
- self.groupBox_absence.setEnabled(False)
- self.groupBox_holidays.setEnabled(False)
- self.messageParam('mode', '1')
- #self.label_32.setText("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" color:#ff0000;\">AUTO</span></p></body></html>")
- if index == 1:
- self.groupBox_absence.setEnabled(True)
- self.groupBox_holidays.setEnabled(False)
- self.messageParam('mode', '2')
- #self.label_32.setText("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" color:#ff0000;\">ABSCENCE</span></p></body></html>")
- if index == 2:
- self.groupBox_absence.setEnabled(False)
- self.groupBox_holidays.setEnabled(True)
- self.messageParam('mode', '3')
- #self.label_32.setText("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" color:#ff0000;\">VACANCES</span></p></body></html>")
- if index == 3:
- self.groupBox_absence.setEnabled(False)
- self.groupBox_holidays.setEnabled(False)
- self.messageParam("mode", "4")
- #self.label_32.setText("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" color:#ff0000;\">OFF</span></p></body></html>")
- def messageParam(self, cle, data):
- #self.dicoParam = {'mode':'#', 'abs':'#', 'vac':'#', 't_jour':'#', 't_nuit':'#', 't_abs':'#', 't_vac':'#', 'cal':'#', 'day_at':'#', 'night_at':'#'}
- print cle, data
- self.dicoParam[cle] = '%s' %(data)
- self.listeParams = (self.dicoParam["mode"], self.dicoParam["abs"], self.dicoParam["vac"], self.dicoParam["t_jour"], self.dicoParam["t_nuit"], self.dicoParam["t_abs"], self.dicoParam["t_vac"], self.dicoParam["cal"], self.dicoParam["day_at"], self.dicoParam["night_at"])
- self.label_showParam.setText("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600; color:#ff0000;\">%s:%s</span></p></body></html>" %(cle, data))
- def resetParam(self):
- self.dicoParam = {'mode':'#', 'abs':'#', 'vac':'#', 't_jour':'#', 't_nuit':'#', 't_abs':'#', 't_vac':'#', 'cal':'#', 'day_at':'#', 'night_at':'#'}
- self.listeParams = ()
- self.label_showParam.setText("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n""<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n""p, li { white-space: pre-wrap; }\n""</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n""<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600; color:#ff0000;\">reset</span></p></body></html>")
- def connectAction(self, status):
- if status is True and self.lineEdit_pwd.text() == "abc":
- self.connection(self.lineEdit_ip.text(), port)
- else :
- self.endcommand()
- def sendParameters(self):
- if any (valeur != "#" for valeur in self.dicoParam.values()): print "dico modifié"
- self.outputQ.put("*PARAM;%s!" %(";".join(self.listeParams)))
- print "*PARAM;%s!" %(";".join(self.listeParams))
- self.resetParam()
- class CommunicationManager(object):
- """
- Launch the main part of the GUI and the worker thread. periodicCall and
- endApplication could reside in the GUI part, but putting them here
- means that you have all the thread controls in a single place.
- """
- def __init__(self, inputQ, outputQ):
- # Create the queue
- #self.queue = Queue.Queue()
- self.inputQ = inputQ
- self.outputQ = outputQ
- self.inputThread = None
- self.outputThread = None
- self.netSocket = netSocket
- self.endmarker = '\n'
- # Set up the GUI part
- self.gui = Dialog(self.inputQ, self.outputQ, self.endApplication, self.connection)
- self.gui.show()
- # A timer to periodically call periodicCall :-)
- self.timer = QtCore.QTimer()
- QtCore.QObject.connect(self.timer,
- QtCore.SIGNAL("timeout()"),
- self.periodicCall)
- # Start the timer -- this replaces the initial call to periodicCall
- self.timer.start(50)
- # Set up the thread to do asynchronous I/O
- # More can be made if necessary
- self.running = 1
- def periodicCall(self):
- """
- Check every 100 ms if there is something new in the queue.
- """
- self.gui.processIncoming()
- if not self.running:
- root.quit()
- sys.exit(1)
- def endApplication(self):
- self.outputQ.put("logout")
- time.sleep(1)
- self.running = 0
- self.netSocket.close()
- def runInput(self):
- while self.running:
- inputline = self.netSocket.recv(bufsize)
- if inputline:
- lines = inputline.split("\n")
- for line in lines :
- self.inputQ.put(line.rstrip())
- def runOutput(self):
- while self.running:
- try:
- outputline = self.outputQ.get()
- self.netSocket.send("%s\r\n"%outputline)
- except:
- pass
- def connection(self, serveradress, port):
- try :
- self.netSocket = socket(AF_INET,SOCK_STREAM)
- #self.netSocket.connect(('localhost',8080))
- self.netSocket.connect((serveradress, port))
- except : pass
- if not self.inputThread:
- self.inputThread = threading.Thread(target=self.runInput)
- self.inputThread.daemon=True
- self.inputThread.start()
- if not self.outputThread:
- self.outputThread = threading.Thread(target=self.runOutput)
- self.outputThread.daemon=True
- self.outputThread.start()
- if __name__ == "__main__":
- inputQ = Queue.Queue()
- outputQ = Queue.Queue()
- root = QtGui.QApplication(sys.argv)
- manager = CommunicationManager(inputQ,outputQ)
- #client = ThreadedClient()
- sys.exit(root.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement