Python demo 3


Demo3, boometro....


#!/usr/bin/python
#
# Control de Nivel - llena de abajo hacia arriba
# 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 = 2
self.grid.setSpacing(10)
self.mainWidget.setLayout(self.grid)

self.setWindowTitle('Control Central - Nivel Altura')

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, 4, 2)
self.dSalida()




# Switches uno a uno

self.B1on = QPushButton("SEG 1")
# self.B1on.setCheckable(True)
self.grid.addWidget(self.B1on, 1, 1, 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, 3, 1, 1, 1)
self.connect(self.B3on, SIGNAL('clicked()'), self.dB3on)

self.B4on = QPushButton("SEG 4")
# self.B4on.setCheckable(True)
self.grid.addWidget(self.B4on, 4, 1, 1, 1)
self.connect(self.B4on, SIGNAL('clicked()'), self.dB4on)

self.B5on = QPushButton("SEG 5")
# self.B5on.setCheckable(True)
self.grid.addWidget(self.B5on, 5, 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, 6, 1, 1, 1)
self.connect(self.B6on, SIGNAL('clicked()'), self.dB6on)

self.B7on = QPushButton("SEG 7")
# self.B7on.setCheckable(True)
self.grid.addWidget(self.B7on, 7, 1, 1, 1)
self.connect(self.B7on, SIGNAL('clicked()'), self.dB7on)

self.B8on = QPushButton("SEG 8")
# self.B8on.setCheckable(True)
self.grid.addWidget(self.B8on, 8, 1, 1, 1)
self.connect(self.B8on, SIGNAL('clicked()'), self.dB8on)



self.BTodo = QPushButton("TODOS")
self.grid.addWidget(self.BTodo, 1, 2, 1, 1)
self.connect(self.BTodo, SIGNAL('clicked()'), self.dTodos)

self.BNada = QPushButton("NINGUNO")
self.grid.addWidget(self.BNada, 2, 2, 1, 1)
self.connect(self.BNada, SIGNAL('clicked()'), self.dNada)

quitbutton = QPushButton("SALIR")
self.grid.addWidget(quitbutton, 8, 2)
self.connect(quitbutton, SIGNAL('clicked()'), self, SLOT('close()'))





# 0
def dB1on(self) :
for j in range (0,8):
self.status[j] = 1
os.system("echo " + str(j + 1) + " on")
self.dSalida()


def dB2on(self) :
for j in range (0,8):
if j <= 0: self.status[j] = 0 os.system("echo " + str(j + 1) + " off") else: self.status[j] = 1 os.system("echo " + str(j + 1) + " on") self.dSalida() def dB3on(self) : for j in range (0,8): if j <= 1: self.status[j] = 0 os.system("echo " + str(j + 1) + " off") else: self.status[j] = 1 os.system("echo " + str(j + 1) + " on") self.dSalida() def dB4on(self) : for j in range (0,8): if j <= 2: self.status[j] = 0 os.system("echo " + str(j + 1) + " off") else: self.status[j] = 1 os.system("echo " + str(j + 1) + " on") self.dSalida() def dB5on(self) : for j in range (0,8): if j<= 3: self.status[j] = 0 os.system("echo " + str(j + 1) + " off") else: self.status[j] = 1 os.system("echo " + str(j + 1) + " on") self.dSalida() def dB6on(self) : for j in range (0,8): if j <= 4: self.status[j] = 0 os.system("echo " + str(j + 1) + " off") else: self.status[j] = 1 os.system("echo " + str(j + 1) + " on") self.dSalida() def dB7on(self) : for j in range (0,8): if j <= 5: self.status[j] = 0 os.system("echo " + str(j + 1) + " off") else: self.status[j] = 1 os.system("echo " + str(j + 1) + " on") self.dSalida() def dB8on(self) : for j in range (0,8): if j <= 6: self.status[j] = 0 os.system("echo " + str(j + 1) + " off") else: self.status[j] = 1 os.system("echo " + str(j + 1) + " on") self.dSalida() 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

Entradas populares