Python control v1.0


El código del primero código en Python, como siempre "no soy de desarrollo" asi que el código es "muy dummy", los que sean expertos de Python pueden mejorarlo y mandarlo.
Lo mejoraré con gusto. En breve publicaré los demás APPs.

Si alguien quiere el código fuente me manda un email.


#!/usr/bin/python
#
# Control Simple encendido y apagado
# 8 x 3 ON OFF
#
# 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 = 10
self.grid.setSpacing(10)
self.mainWidget.setLayout(self.grid)

self.setWindowTitle('Control Central - Uno a Uno')

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

# for i in range (1,9):
# for j in range (1,3):
# self.BTodo1 = QPushButton("i")
# self.grid.addWidget(self.BTodo1, j, i, 1, 1)
# self.connect(self.BTodo1, SIGNAL('clicked()'), self.dTodos)

self.B1on = QPushButton("1 UP ")
self.grid.addWidget(self.B1on, 1, 1, 1, 1)
self.connect(self.B1on, SIGNAL('clicked()'), self.dB1on)

self.B1off = QPushButton("1 OFF")
self.grid.addWidget(self.B1off, 2, 1, 1, 1)
self.connect(self.B1off, SIGNAL('clicked()'), self.dB1off)

self.B2on = QPushButton("2 UP ")
self.grid.addWidget(self.B2on, 1, 2, 1, 1)
self.connect(self.B2on, SIGNAL('clicked()'), self.dB2on)

self.B2off = QPushButton("2 OFF")
self.grid.addWidget(self.B2off, 2, 2, 1, 1)
self.connect(self.B2off, SIGNAL('clicked()'), self.dB2off)

self.B3on = QPushButton("3 ON ")
self.grid.addWidget(self.B3on, 1, 3, 1, 1)
self.connect(self.B3on, SIGNAL('clicked()'), self.dB3on)

self.B3off = QPushButton("3 OFF")
self.grid.addWidget(self.B3off, 2, 3, 1, 1)
self.connect(self.B3off, SIGNAL('clicked()'), self.dB3off)

self.B4on = QPushButton("4 UP ")
self.grid.addWidget(self.B4on, 1, 4, 1, 1)
self.connect(self.B4on, SIGNAL('clicked()'), self.dB4on)

self.B4off = QPushButton("4 OFF")
self.grid.addWidget(self.B4off, 2, 4, 1, 1)
self.connect(self.B4off, SIGNAL('clicked()'), self.dB4off)

self.B5on = QPushButton("5 UP ")
self.grid.addWidget(self.B5on, 1, 5, 1, 1)
self.connect(self.B5on, SIGNAL('clicked()'), self.dB5on)

self.B5off = QPushButton("5 OFF")
self.grid.addWidget(self.B5off, 2, 5, 1, 1)
self.connect(self.B5off, SIGNAL('clicked()'), self.dB5off)

self.B6on = QPushButton("6 ON ")
self.grid.addWidget(self.B6on, 1, 6, 1, 1)
self.connect(self.B6on, SIGNAL('clicked()'), self.dB6on)

self.B6off = QPushButton("6 OFF")
self.grid.addWidget(self.B6off, 2, 6, 1, 1)
self.connect(self.B6off, SIGNAL('clicked()'), self.dB6off)

self.B7on = QPushButton("7 ON ")
self.grid.addWidget(self.B7on, 1, 7, 1, 1)
self.connect(self.B7on, SIGNAL('clicked()'), self.dB7on)

self.B7off = QPushButton("7 OFF")
self.grid.addWidget(self.B7off, 2, 7, 1, 1)
self.connect(self.B7off, SIGNAL('clicked()'), self.dB7off)

self.B8on = QPushButton("8 ON ")
self.grid.addWidget(self.B8on, 1, 8, 1, 1)
self.connect(self.B8on, SIGNAL('clicked()'), self.dB8on)

self.B8off = QPushButton("8 OFF")
self.grid.addWidget(self.B8off, 2, 8, 1, 1)
self.connect(self.B8off, SIGNAL('clicked()'), self.dB8off)

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

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

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


# def lambda varx=1,vary=2: self.setear_bit(valor_de_posicion, valor_de_bit)


def dB1on(self) :
self.status[0] = 1
self.dSalida()
os.system("echo '1 on'")

def dB1off(self) :
self.status[0] = 0
self.dSalida()
os.system("echo '1 off'")

def dB2on(self) :
self.status[1] = 1
self.dSalida()
os.system("echo '2 on'")

def dB2off(self) :
self.status[1] = 0
self.dSalida()
os.system("echo '2 off'")

def dB3on(self) :
self.status[2] = 1
self.dSalida()
os.system("echo '3 on'")

def dB3off(self) :
self.status[2] = 0
self.dSalida()
os.system("echo '3 off'")

def dB4on(self) :
self.status[3] = 1
self.dSalida()
os.system("echo '4 on'")

def dB4off(self) :
self.status[3] = 0
self.dSalida()
os.system("echo '4 off'")

def dB5on(self) :
self.status[4] = 1
self.dSalida()
os.system("echo '5 on'")

def dB5off(self) :
self.status[4] = 0
self.dSalida()
os.system("echo '5 off'")

def dB6on(self) :
self.status[5] = 1
self.dSalida()
os.system("echo '6 on'")

def dB6off(self) :
self.status[5] = 0
self.dSalida()
os.system("echo '6 off'")

def dB7on(self) :
self.status[6] = 1
self.dSalida()
os.system("echo '7 on'")

def dB7off(self) :
self.status[6] = 0
self.dSalida()
os.system("echo '7 off'")

def dB8on(self) :
self.status[7] = 1
self.dSalida()
os.system("echo '8 on'")

def dB8off(self) :
self.status[7] = 0
self.dSalida()
os.system("echo '8 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

Entradas populares