def main(): D.P("Program started") relayCommand.closeAll() setButtons() alarm = Alarm() myInterface = Interface(buttons, alarm) myInterface.start() relayCommand.close() D.P("Main ended")
def addButtons(self): D.P("Adding buttons to interface") for i in self.buttons: but = Button(self.win, text=i.name, font=self.myFont, command=i.command, bg=i.color, activebackground=i.color) i.addReferences(self.win, but, self.alarm) self.blinkers.append(i.blinker) but.pack() but.place(x=i.x_poz, y=i.y_poz, height=i.height, width=i.width)
def run(): D.P("Draw rutine running") global win global status global buttons global alarm for i in buttons: i.run(status) if status == 1: status = 0 else: status = 1 alarm.run(status) win.after(TIME, run)
def __init__(self, buttons, alarm): D.P("Creating interface") self.win = Tk() self.myFont = tkFont.Font(family='Helvetica', size=10, weight='bold') self.win.title("First GUI") self.win.attributes('-fullscreen', True) #self.win.geometry('800x400') self.blinkers = [] self.buttons = buttons self.alarm = alarm self.alarm.draw(self.win, self.myFont) self.addButtons() self.addDefaultButtons() self.addClock() Synchronizer.init(self.win, self.blinkers, alarm.blinker)
def setButtons(): D.P("Setting buttons") buttons.append( WinButton(id=5, relayId=0, name="DORMITOR 1", width=120, height=120, x_poz=127, y_poz=355, color="green")) buttons.append( WinButton(id=6, relayId=1, name="DORMITOR 2", width=120, height=120, x_poz=5, y_poz=355, color="green")) buttons.append( WinButton(id=12, relayId=2, name="BAIE 1", width=80, height=60, x_poz=5, y_poz=290, color="green")) buttons.append( WinButton(id=13, relayId=3, name="BAIE D.3", width=80, height=60, x_poz=5, y_poz=225, color="green")) buttons.append( WinButton(id=16, relayId=3, name="DORMITOR 3", width=120, height=90, x_poz=5, y_poz=135, color="green")) buttons.append( WinButton(id=17, relayId=4, name="DORMITOR 4", width=120, height=120, x_poz=127, y_poz=60, color="green")) buttons.append( WinButton(id=18, relayId=5, name="DORMITOR 5", width=120, height=120, x_poz=248, y_poz=60, color="green")) buttons.append( WinButton(id=19, relayId=6, name="BAIE 2", width=70, height=70, x_poz=150, y_poz=220, color="green")) buttons.append( WinButton(id=20, relayId=7, name="BAIE 3", width=60, height=80, x_poz=370, y_poz=100, color="green")) buttons.append( WinButton(id=21, relayId=8, name="DORMITOR 6", width=120, height=120, x_poz=432, y_poz=60, color="green")) buttons.append( WinButton(id=22, relayId=9, name="DORMITOR 7", width=120, height=120, x_poz=553, y_poz=60, color="green")) buttons.append( WinButton(id=23, relayId=10, name="DORMITOR 8", width=120, height=90, x_poz=675, y_poz=135, color="green")) buttons.append( WinButton(id=24, relayId=10, name="BAIE D.8", width=80, height=60, x_poz=715, y_poz=225, color="green")) buttons.append( WinButton(id=25, relayId=11, name="BAIE 4", width=80, height=60, x_poz=715, y_poz=290, color="green")) buttons.append( WinButton(id=26, relayId=12, name="DORMITOR 9", width=120, height=120, x_poz=675, y_poz=355, color="green")) buttons.append( WinButton(id=27, relayId=13, name="DORMITOR 10", width=120, height=120, x_poz=553, y_poz=355, color="green")) buttons.append( WinButton(id=28, relayId=14, name="BAIE 5", width=70, height=70, x_poz=580, y_poz=220, color="green"))
def start(self): D.P("Starting win loop") self.win.mainloop()
def __del__(self): D.P("Deleting Interface") self.win.quit()
def close(): closeAll() D.P("Closing serial port") serPort.close()
def closeAll(): for id in range(0, 16): D.P("Closing relay " + str(id)) unsetRelay(id)
def unsetRelay(id): D.P("Setting relay " + str(id) + " OFF") msg = "relay off " + getId(id) + "\n\r" serPort.write(msg) D.P("Serial sent: " + msg)
def addEvent(self): D.P("Setting callback for button " + str(self.buttonID)) GPIO.add_event_detect(self.buttonID, GPIO.RISING, callback=self.activateSwitch)
def activateSwitch(self, pinReaded): D.P("Button" + str(self.buttonID) + " activated") self.activationCallback()