Python demo2
Segundo demo de interfaz para control.
Display de 7 segmentos.
#!/usr/bin/python
#
# Display 7 segmentos
# Encendido Apagado y nro directo
#
# 2013-10 V 1.
#
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
import subprocess
import os
class ControlWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.mainWidget = QWidget(self)
self.setCentralWidget(self.mainWidget)
self.grid = QGridLayout()
self.grid.columnCount = 6
self.grid.setSpacing(10)
self.mainWidget.setLayout(self.grid)
self.setWindowTitle('Control Central - Display 7 segmentos')
self.status = [0, 0, 0, 0, 0, 0, 0, 0]
self.font = QFont("", 0, QFont.Bold, False)
self.font.setPointSize(self.font.pointSize() * 2)
menubar = self.menuBar()
file = menubar.addMenu('&Acciones')
dealmenu = QAction('TODOS ON', self)
dealmenu.setShortcut('Ctrl+N')
dealmenu.setStatusTip('Todos los contactos ON')
self.connect(dealmenu, SIGNAL('triggered()'), self.dTodos)
file.addAction(dealmenu)
dealmenu = QAction('TODOS OFF', self)
dealmenu.setShortcut('Ctrl+F')
dealmenu.setStatusTip('Todos los contactos OFF')
self.connect(dealmenu, SIGNAL('triggered()'), self.dNada)
file.addAction(dealmenu)
exit = QAction('Exit', self)
exit.setShortcut('Ctrl+Q')
exit.setStatusTip('Exit application')
self.connect(exit, SIGNAL('triggered()'), SLOT('close()'))
file.addAction(exit)
self.labelEstado = QLabel('%s' % self.status)
self.grid.addWidget( self.labelEstado, 6, 2)
self.dSalida()
# Switches uno a uno
self.B1on = QPushButton("SEG 1")
# self.B1on.setCheckable(True)
self.grid.addWidget(self.B1on, 1, 2, 1, 1)
self.connect(self.B1on, SIGNAL('clicked()'), self.dB1on)
self.B2on = QPushButton("SEG 2")
# self.B2on.setCheckable(True)
self.grid.addWidget(self.B2on, 2, 1, 1, 1)
self.connect(self.B2on, SIGNAL('clicked()'), self.dB2on)
self.B3on = QPushButton("SEG 3")
# self.B3on.setCheckable(True)
self.grid.addWidget(self.B3on, 2, 3, 1, 1)
self.connect(self.B3on, SIGNAL('clicked()'), self.dB3on)
self.B4on = QPushButton("SEG 4")
# self.B4on.setCheckable(True)
self.grid.addWidget(self.B4on, 3, 2, 1, 1)
self.connect(self.B4on, SIGNAL('clicked()'), self.dB4on)
self.B5on = QPushButton("SEG 5")
# self.B5on.setCheckable(True)
self.grid.addWidget(self.B5on, 4, 1, 1, 1)
self.connect(self.B5on, SIGNAL('clicked()'), self.dB5on)
self.B6on = QPushButton("SEG 6")
# self.B6on.setCheckable(True)
self.grid.addWidget(self.B6on, 4, 3, 1, 1)
self.connect(self.B6on, SIGNAL('clicked()'), self.dB6on)
self.B7on = QPushButton("SEG 7")
# self.B7on.setCheckable(True)
self.grid.addWidget(self.B7on, 5, 2, 1, 1)
self.connect(self.B7on, SIGNAL('clicked()'), self.dB7on)
self.B8on = QPushButton("SEG 8")
# self.B8on.setCheckable(True)
self.grid.addWidget(self.B8on, 10, 2, 1, 1)
self.connect(self.B8on, SIGNAL('clicked()'), self.dB8on)
# Numeros digitales 7 segmentos
self.Bn0 = QPushButton("0")
self.grid.addWidget(self.Bn0, 1, 4, 1, 1)
self.connect(self.Bn0, SIGNAL('clicked()'), self.dBn0)
self.Bn1 = QPushButton("1")
self.grid.addWidget(self.Bn1, 2, 4, 1, 1)
self.connect(self.Bn1, SIGNAL('clicked()'), self.dBn1)
self.Bn2 = QPushButton("2")
self.grid.addWidget(self.Bn2, 3, 4, 1, 1)
self.connect(self.Bn2, SIGNAL('clicked()'), self.dBn2)
self.Bn3 = QPushButton("3")
self.grid.addWidget(self.Bn3, 4, 4, 1, 1)
self.connect(self.Bn3, SIGNAL('clicked()'), self.dBn3)
self.Bn4 = QPushButton("4")
self.grid.addWidget(self.Bn4, 5, 4, 1, 1)
self.connect(self.Bn4, SIGNAL('clicked()'), self.dBn4)
self.Bn5 = QPushButton("5")
self.grid.addWidget(self.Bn5, 6, 4, 1, 1)
self.connect(self.Bn5, SIGNAL('clicked()'), self.dBn5)
self.Bn6 = QPushButton("6")
self.grid.addWidget(self.Bn6, 7, 4, 1, 1)
self.connect(self.Bn6, SIGNAL('clicked()'), self.dBn6)
self.Bn7 = QPushButton("7")
self.grid.addWidget(self.Bn7, 8, 4, 1, 1)
self.connect(self.Bn7, SIGNAL('clicked()'), self.dBn7)
self.Bn8 = QPushButton("8")
self.grid.addWidget(self.Bn8, 9, 4, 1, 1)
self.connect(self.Bn8, SIGNAL('clicked()'), self.dBn8)
self.Bn9 = QPushButton("9")
self.grid.addWidget(self.Bn9, 10, 4, 1, 1)
self.connect(self.Bn9, SIGNAL('clicked()'), self.dBn9)
# for j in range (0,10):
# self.B1 = QPushButton("Nro "+str(j))
# self.grid.addWidget(self.B1, j, 4, 1, 1)
# self.connect(self.B1, SIGNAL('clicked()'), self.dTodos)
self.BTodo = QPushButton("TODOS")
self.grid.addWidget(self.BTodo, 1, 5, 1, 1)
self.connect(self.BTodo, SIGNAL('clicked()'), self.dTodos)
self.BNada = QPushButton("NINGUNO")
self.grid.addWidget(self.BNada, 2, 5, 1, 1)
self.connect(self.BNada, SIGNAL('clicked()'), self.dNada)
quitbutton = QPushButton("SALIR")
self.grid.addWidget(quitbutton, 10, 5)
self.connect(quitbutton, SIGNAL('clicked()'), self, SLOT('close()'))
# 0
def dB1on(self) :
if self.status[0] == 0:
self.status[0] = 1
self.dSalida()
os.system("echo '1 on'")
else:
self.status[0] = 0
self.dSalida()
os.system("echo '1 off'")
def dB2on(self) :
if self.status[1] == 0:
self.status[1] = 1
self.dSalida()
os.system("echo '2 on'")
else:
self.status[1] = 0
self.dSalida()
os.system("echo '2 off'")
def dB3on(self) :
if self.status[2] == 0:
self.status[2] = 1
self.dSalida()
os.system("echo '3 on'")
else:
self.status[2] = 0
self.dSalida()
os.system("echo '3 off'")
def dB4on(self) :
if self.status[3] == 0:
self.status[3] = 1
self.dSalida()
os.system("echo '4 on'")
else:
self.status[3] = 0
self.dSalida()
os.system("echo '4 off'")
def dB5on(self) :
if self.status[4] == 0:
self.status[4] = 1
self.dSalida()
os.system("echo '5 on'")
else:
self.status[4] = 0
self.dSalida()
os.system("echo '5 off'")
def dB6on(self) :
if self.status[5] == 0:
self.status[5] = 1
self.dSalida()
os.system("echo '6 on'")
else:
self.status[5] = 0
self.dSalida()
os.system("echo '6 off'")
def dB7on(self) :
if self.status[6] == 0:
self.status[6] = 1
self.dSalida()
os.system("echo '7 on'")
else:
self.status[6] = 0
self.dSalida()
os.system("echo '7 off'")
def dB8on(self) :
if self.status[7] == 0:
self.status[7] = 1
self.dSalida()
os.system("echo '8 on'")
else:
self.status[7] = 0
self.dSalida()
os.system("echo '8 off'")
# Numeros uno a uno
def dBn0(self) :
self.status = [1, 1, 1, 0, 1, 1, 1, 0]
self.dSalida()
os.system("echo '0 on' ")
os.system("echo '1 on' ")
os.system("echo '2 on' ")
os.system("echo '3 off' ")
os.system("echo '4 on' ")
os.system("echo '5 on' ")
os.system("echo '6 off' ")
os.system("echo '7 off' ")
def dBn1(self) :
self.status = [0, 0, 1, 0, 0, 1, 0, 0]
self.dSalida()
os.system("echo '0 off' ")
os.system("echo '1 off' ")
os.system("echo '2 on' ")
os.system("echo '3 off' ")
os.system("echo '4 off' ")
os.system("echo '5 on' ")
os.system("echo '6 off' ")
os.system("echo '7 off' ")
def dBn2(self) :
self.status = [1, 0, 1, 1, 1, 0, 1, 0]
self.dSalida()
os.system("echo '0 on' ")
os.system("echo '1 off' ")
os.system("echo '2 on' ")
os.system("echo '3 on' ")
os.system("echo '4 on' ")
os.system("echo '5 off' ")
os.system("echo '6 on' ")
os.system("echo '7 off' ")
def dBn3(self) :
self.status = [1, 0, 1, 1, 0, 1, 1, 0]
self.dSalida()
os.system("echo '0 on' ")
os.system("echo '1 off' ")
os.system("echo '2 on' ")
os.system("echo '3 on' ")
os.system("echo '4 off' ")
os.system("echo '5 on' ")
os.system("echo '6 on' ")
os.system("echo '7 off' ")
def dBn4(self) :
self.status = [0, 1, 1, 1, 0, 1, 0, 0]
self.dSalida()
os.system("echo '0 off' ")
os.system("echo '1 on' ")
os.system("echo '2 on' ")
os.system("echo '3 on' ")
os.system("echo '4 off' ")
os.system("echo '5 on' ")
os.system("echo '6 off' ")
os.system("echo '7 off' ")
def dBn5(self) :
self.status = [1, 1, 0, 1, 0, 1, 1, 0]
self.dSalida()
os.system("echo '0 on' ")
os.system("echo '1 on' ")
os.system("echo '2 off' ")
os.system("echo '3 on' ")
os.system("echo '4 off' ")
os.system("echo '5 on' ")
os.system("echo '6 on' ")
os.system("echo '7 off' ")
def dBn6(self) :
self.status = [1, 1, 0, 1, 1, 1, 1, 0]
self.dSalida()
os.system("echo '0 on' ")
os.system("echo '1 on' ")
os.system("echo '2 off' ")
os.system("echo '3 on' ")
os.system("echo '4 on' ")
os.system("echo '5 on' ")
os.system("echo '6 on' ")
os.system("echo '7 off' ")
def dBn7(self) :
self.status = [1, 0, 1, 0, 0, 1, 0, 0]
self.dSalida()
os.system("echo '0 on' ")
os.system("echo '1 off' ")
os.system("echo '2 on' ")
os.system("echo '3 off' ")
os.system("echo '4 off' ")
os.system("echo '5 on' ")
os.system("echo '6 off' ")
os.system("echo '7 off' ")
def dBn8(self) :
self.status = [1, 1, 1, 1, 1, 1, 1, 0]
self.dSalida()
os.system("echo '0 on' ")
os.system("echo '1 on' ")
os.system("echo '2 on' ")
os.system("echo '3 on' ")
os.system("echo '4 on' ")
os.system("echo '5 on' ")
os.system("echo '6 on' ")
os.system("echo '7 off'")
def dBn9(self) :
self.status = [1, 1, 1, 1, 0, 1, 1, 0]
self.dSalida()
os.system("echo '0 on' ")
os.system("echo '1 on' ")
os.system("echo '2 on' ")
os.system("echo '3 on' ")
os.system("echo '4 off'")
os.system("echo '5 on' ")
os.system("echo '6 on' ")
os.system("echo '7 off'")
def dTodos(self) :
for j in range (0,8):
if self.status[j] == 0:
self.status[j] = 1
os.system("echo " + str(j + 1) + " on")
self.dSalida()
def dNada(self) :
for j in range (0,8):
if self.status[j] == 1:
self.status[j] = 0
os.system("echo "+ str(j + 1) + " off")
self.dSalida()
def dSalida(self):
self.labelEstado.setText('%s' % self.status)
self.Textos = "echo `date` - "+ str(self.status) +" >> control.log"
os.system(self.Textos)
if __name__ == '__main__':
os.system("echo `date` 'Starting Control' >> control.log")
app = QApplication(sys.argv)
win = ControlWindow()
win.show()
app.exec_()
os.system("echo `date` 'Finishing Control' >> control.log")
#
# fin de codigo
#
Comentarios
Publicar un comentario