Advertisement
zoroastre74

Client.py

Nov 8th, 2011
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 30.50 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. # Form implementation generated from reading ui file 'arduinogui.ui'
  4. #
  5. # Created: Sun Aug 21 20:19:53 2011
  6. #      by: PyQt4 UI code generator 4.7.3
  7. #
  8. # WARNING! All changes made in this file will be lost!
  9.  
  10. import sys, time, threading, Queue, struct
  11. from PyQt4 import QtGui, QtCore
  12. from socket import *
  13. import guiClass
  14.  
  15. netSocket = None
  16. serveradress = 'localhost'
  17. port = 32800
  18.  
  19. bufsize = 2048
  20.  
  21. class Dialog(QtGui.QDialog, guiClass.Ui_Dialog):
  22.     def __init__(self, inputQ, outputQ, endcommand, connection, parent=None, f=QtCore.Qt.WindowFlags()):
  23.         QtGui.QDialog.__init__(self, parent, f)
  24.        
  25.         self.inputQ = inputQ
  26.         self.outputQ = outputQ
  27.         self.manager = CommunicationManager
  28.         self.endcommand = endcommand
  29.         self.connection = connection
  30.         self.dicoParam = {'mode':'#', 'abs':'#', 'vac':'#', 't_jour':'#', 't_nuit':'#', 't_abs':'#', 't_vac':'#', 'cal':'#', 'day_at':'#', 'night_at':'#'}
  31.         self.listeParams = ()
  32.        
  33.         self.setupUi(self)
  34.        
  35.     def closeEvent(self, ev):
  36.         self.endcommand()
  37.  
  38.     def processIncoming(self):
  39.         """
  40.        Handle all the messages currently in the queue (if any).
  41.        """
  42.         try:
  43.             msg = self.inputQ.get(0)
  44.             #msg = self.inputQ.get_nowait()
  45.             print msg
  46.             # Check contents of message and do what it says
  47.             # As a test, we simply print it
  48.             if msg[0:9] == "connected":
  49.                 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>")
  50.            
  51.             if msg[0:5] == "relay":
  52.                 self.singleRs485color(msg[5], msg[7])
  53.                
  54.             if msg[0:4] == "data":
  55.                 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
  56.                 if lst[7] == "1":
  57.                     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))
  58.                     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))
  59.                 if lst[7] == "2":
  60.                     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))
  61.                     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))
  62.                 if lst[7] == "3":
  63.                     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))
  64.                     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))
  65.                 if lst[7] == "4":
  66.                     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))
  67.                     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))
  68.    
  69.                 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))
  70.                 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))
  71.                 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))
  72.                 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))
  73.  
  74.                 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))
  75.                 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))
  76.  
  77.                 if lst[8] == "0":
  78.                     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))
  79.                 if lst[8] == "1":
  80.                     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))
  81.  
  82.                 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]))
  83.  
  84.                 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))
  85.                 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))
  86.                 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))
  87.                 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))
  88.  
  89.                 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))
  90.                 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))
  91.  
  92.    
  93.         except Queue.Empty: pass
  94.  
  95.     def singleRs485switch(self, num, state) :
  96.         self.outputQ.put("*RELAY;%s;%s!" %(num, state))
  97.  
  98.     def singleRs485color(self, relay, toggle) :
  99.         if relay == "1":
  100.             if toggle == "1" :
  101.                 self.label_relay1led.setPixmap(QtGui.QPixmap("./img/led_green.png"))
  102.             if toggle == "0" :
  103.                 self.label_relay1led.setPixmap(QtGui.QPixmap("./img/led_red.png"))
  104.         if relay == "2":
  105.             if toggle == "1" :
  106.                 self.label_relay2led.setPixmap(QtGui.QPixmap("./img/led_green.png"))
  107.             if toggle == "0" :
  108.                 self.label_relay2led.setPixmap(QtGui.QPixmap("./img/led_red.png"))
  109.         if relay == "3":
  110.             if toggle == "1" :
  111.                 self.label_relay3led.setPixmap(QtGui.QPixmap("./img/led_green.png"))
  112.             if toggle == "0" :
  113.                 self.label_relay3led.setPixmap(QtGui.QPixmap("./img/led_red.png"))        
  114.         if relay == "4":
  115.             if toggle == "1" :
  116.                 self.label_relay4led.setPixmap(QtGui.QPixmap("./img/led_green.png"))
  117.             if toggle == "0" :
  118.                 self.label_relay4led.setPixmap(QtGui.QPixmap("./img/led_red.png"))
  119.         if relay == "5":
  120.             if toggle == "1" :
  121.                 self.label_relay5led.setPixmap(QtGui.QPixmap("./img/led_green.png"))
  122.             if toggle == "0" :
  123.                 self.label_relay5led.setPixmap(QtGui.QPixmap("./img/led_red.png"))
  124.         if relay == "6":
  125.             if toggle == "1" :
  126.                 self.label_relay6led.setPixmap(QtGui.QPixmap("./img/led_green.png"))
  127.             if toggle == "0" :
  128.                 self.label_relay6led.setPixmap(QtGui.QPixmap("./img/led_red.png"))
  129.         if relay == "7":
  130.             if toggle == "1" :
  131.                 self.label_relay7led.setPixmap(QtGui.QPixmap("./img/led_green.png"))
  132.             if toggle == "0" :
  133.                 self.label_relay7led.setPixmap(QtGui.QPixmap("./img/led_red.png"))
  134.         if relay == "8":
  135.             if toggle == "1" :
  136.                 self.label_relay8led.setPixmap(QtGui.QPixmap("./img/led_green.png"))
  137.             if toggle == "0" :
  138.                 self.label_relay8led.setPixmap(QtGui.QPixmap("./img/led_red.png"))
  139.                
  140.     def update_abs(self, value):
  141. #        a = str(time.time() - time.timezone + time.daylight*3600)[0:10]
  142.         a = str(time.time() + 3600)[0:10]
  143.         b = int(value)*3600
  144.         c = int(a) + b
  145.         self.messageParam("abs", "%s" %c)
  146.        
  147.     def update_holidays(self, value):
  148.         # value = "PyQt4.QtCore.QDateTime(2011, 9, 11, 12, 15)" time.mktime(tuple de 9 chiffres)
  149.         a = "%s" %value
  150.         b = a.split("(")
  151.         c = b[1].replace(" ", "")
  152.         d = c[:-1]
  153.         liste = (a[:-1].split("(")[1].replace(" ", "")).split(',')
  154.         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]))
  155.         #self.messageParam("vac", "%s" %d) #liste = (a[:-1].split("(")[1].replace(" ", "")).split(',')
  156.         # str(time.mktime((int(liste[0]), int(liste[1]), int(liste[2]), int(liste[3]), int(liste[4]), 0, 0, 0, 0)))[0:10]
  157.        
  158.        
  159.     def update_dayT(self, value):
  160.         self.messageParam("t_jour", "%s" %value.replace(",", "."))
  161.  
  162.     def update_nightT(self, value):
  163.         self.messageParam("t_nuit", "%s" %value.replace(",", "."))
  164.        
  165.     def update_absT(self, value):
  166.         self.messageParam("t_abs", "%s" %value.replace(",", "."))
  167.  
  168.     def update_vacT(self, value):
  169.         self.messageParam("t_vac", "%s" %value.replace(",", "."))
  170.  
  171.     def update_factor(self, value):
  172.         self.messageParam("cal", "%s" %value.replace(",", "."))
  173.  
  174.     def update_dayat(self, value):
  175.         a = "%s" %value
  176.         b = a.split("(")
  177.         c = b[1].replace(" ", "")
  178.         d = c[:-1].split(",") # liste = (a[:-1].split("(")[1].replace(" ", "")).split(",")
  179.         e = (int(d[0])*60) + int(d[1]) # = int(liste[0])*60 + int(liste[1])
  180.         self.messageParam("day_at", "%s" %e)
  181.        
  182.     def update_nightat(self, value):
  183.         a = "%s" %value
  184.         b = a.split("(")
  185.         c = b[1].replace(" ", "")
  186.         d = c[:-1].split(",") # liste = (a[:-1].split("(")[1].replace(" ", "")).split(",")
  187.         e = (int(d[0])*60) + int(d[1]) # = int(liste[0])*60 + int(liste[1])
  188.         self.messageParam("night_at", "%s" %e)
  189.  
  190.     def update_mode(self, index):
  191.         if index == 0:
  192.             self.groupBox_absence.setEnabled(False)
  193.             self.groupBox_holidays.setEnabled(False)
  194.             self.messageParam('mode', '1')
  195.             #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>")
  196.         if index == 1:
  197.             self.groupBox_absence.setEnabled(True)
  198.             self.groupBox_holidays.setEnabled(False)
  199.             self.messageParam('mode', '2')
  200.             #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>")
  201.         if index == 2:
  202.             self.groupBox_absence.setEnabled(False)
  203.             self.groupBox_holidays.setEnabled(True)
  204.             self.messageParam('mode', '3')
  205.             #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>")
  206.         if index == 3:
  207.             self.groupBox_absence.setEnabled(False)
  208.             self.groupBox_holidays.setEnabled(False)
  209.             self.messageParam("mode", "4")
  210.             #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>")
  211.  
  212.     def messageParam(self, cle, data):
  213.         #self.dicoParam = {'mode':'#', 'abs':'#', 'vac':'#', 't_jour':'#', 't_nuit':'#', 't_abs':'#', 't_vac':'#', 'cal':'#', 'day_at':'#', 'night_at':'#'}
  214.         print cle, data
  215.         self.dicoParam[cle] = '%s' %(data)
  216.         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"])
  217.         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))
  218.  
  219.     def resetParam(self):
  220.         self.dicoParam = {'mode':'#', 'abs':'#', 'vac':'#', 't_jour':'#', 't_nuit':'#', 't_abs':'#', 't_vac':'#', 'cal':'#', 'day_at':'#', 'night_at':'#'}
  221.         self.listeParams = ()
  222.         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>")
  223.  
  224.     def connectAction(self, status):
  225.         if status is True and self.lineEdit_pwd.text() == "abc":
  226.             self.connection(self.lineEdit_ip.text(), port)
  227.         else :
  228.             self.endcommand()
  229.            
  230.     def sendParameters(self):
  231.         if any (valeur != "#" for valeur in self.dicoParam.values()): print "dico modifié"
  232.         self.outputQ.put("*PARAM;%s!" %(";".join(self.listeParams)))
  233.         print "*PARAM;%s!" %(";".join(self.listeParams))
  234.         self.resetParam()
  235.  
  236. class CommunicationManager(object):
  237.     """
  238.    Launch the main part of the GUI and the worker thread. periodicCall and
  239.    endApplication could reside in the GUI part, but putting them here
  240.    means that you have all the thread controls in a single place.
  241.    """
  242.     def __init__(self, inputQ, outputQ):
  243.         # Create the queue
  244.         #self.queue = Queue.Queue()
  245.         self.inputQ = inputQ
  246.         self.outputQ = outputQ
  247.        
  248.         self.inputThread = None
  249.         self.outputThread = None
  250.        
  251.         self.netSocket = netSocket
  252.         self.endmarker = '\n'
  253.  
  254.         # Set up the GUI part
  255.         self.gui = Dialog(self.inputQ, self.outputQ, self.endApplication, self.connection)
  256.         self.gui.show()
  257.  
  258.         # A timer to periodically call periodicCall :-)
  259.         self.timer = QtCore.QTimer()
  260.         QtCore.QObject.connect(self.timer,
  261.                            QtCore.SIGNAL("timeout()"),
  262.                            self.periodicCall)
  263.         # Start the timer -- this replaces the initial call to periodicCall
  264.         self.timer.start(50)
  265.  
  266.         # Set up the thread to do asynchronous I/O
  267.         # More can be made if necessary
  268.         self.running = 1
  269.  
  270.     def periodicCall(self):
  271.         """
  272.        Check every 100 ms if there is something new in the queue.
  273.        """
  274.         self.gui.processIncoming()
  275.         if not self.running:
  276.             root.quit()
  277.             sys.exit(1)
  278.  
  279.     def endApplication(self):
  280.         self.outputQ.put("logout")
  281.         time.sleep(1)
  282.         self.running = 0
  283.         self.netSocket.close()
  284.  
  285.     def runInput(self):
  286.         while self.running:
  287.             inputline = self.netSocket.recv(bufsize)
  288.             if inputline:
  289.                 lines = inputline.split("\n")
  290.                 for line in lines :
  291.                     self.inputQ.put(line.rstrip())
  292.    
  293.     def runOutput(self):
  294.         while self.running:
  295.             try:
  296.                 outputline = self.outputQ.get()
  297.                 self.netSocket.send("%s\r\n"%outputline)
  298.             except:
  299.                 pass
  300.  
  301.     def connection(self, serveradress, port):
  302.         try :
  303.             self.netSocket = socket(AF_INET,SOCK_STREAM)
  304.             #self.netSocket.connect(('localhost',8080))
  305.             self.netSocket.connect((serveradress, port))
  306.            
  307.         except : pass
  308.         if not self.inputThread:
  309.             self.inputThread = threading.Thread(target=self.runInput)
  310.             self.inputThread.daemon=True
  311.             self.inputThread.start()
  312.         if not self.outputThread:
  313.             self.outputThread = threading.Thread(target=self.runOutput)
  314.             self.outputThread.daemon=True
  315.             self.outputThread.start()
  316.        
  317. if __name__ == "__main__":
  318.  
  319.     inputQ = Queue.Queue()
  320.     outputQ = Queue.Queue()
  321.    
  322.     root = QtGui.QApplication(sys.argv)
  323.     manager = CommunicationManager(inputQ,outputQ)
  324.     #client = ThreadedClient()
  325.     sys.exit(root.exec_())
  326.  
  327.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement