-1

I am struggling with my GTK GUI...

I made a GUI for lights and etc and so far "everything" works but I can't figur it out for a timer that will start the lights on a given time and end it. The left spinbutton is for the "start Hour" and the right one is for the "End Hour". every object has a checkbox for enabeling/disabeling of the timer, and everytime you put in or edit the time, you need to push on the ok button. can someone help me please?

import datetime
import gi
import time

gi.require_version('Gtk', '3.0')
from gi.repository import Gtk as gtk, GObject, GLib





class Main:
    def __init__(self):
        gladeFile = "main.glade"
        self.builder = gtk.Builder()
        self.builder.add_from_file(gladeFile)
        self.builder.connect_signals(self)

        self.window        = self.builder.get_object("Main")
        self.window.connect("delete-event", gtk.main_quit)
        self.window.show_all()
        self.window.set_decorated(False)
        self.labelClock  = self.builder.get_object("Time")
        self.labelDate   = self.builder.get_object("Date")
        self.Uur_LED_Aan = self.builder.get_object("Uur_LED_Aan")
        self.Uur_LED_Uit = self.builder.get_object("Uur_LED_Uit")
        self.Uur_Licht_Aan = self.builder.get_object("Uur_Licht_Aan")
        self.Uur_Licht_Uit = self.builder.get_object("Uur_Licht_Uit")
        self.Uur_Luik_Open = self.builder.get_object("Uur_Luik_Open")
        self.Uur_Luik_Dicht = self.builder.get_object("Uur_Luik_Dicht")

    def compare(self):
        ULA = self.OK()
        ULU = self.OK()
        start_hour = ULA
        start_minute = '00'
        end_hour = ULU
        end_minute = '00'

        start_time = int(start_hour) * 60 + int(start_minute)
        end_time = int(end_hour) * 60 + int(end_minute)
        current_time = datetime.datetime.now().hour * 60 + datetime.datetime.now().minute
        if start_time == current_time:
            print("LED ON")

        elif end_time == current_time:
            print("LED OFF")
        return True

    def ULED_Update(self):
        GLib.timeout_add(100, self.compare, True)





    def OK(self, button):
        ULA  = self.Uur_LED_Aan.get_value()
        ULU  = self.Uur_LED_Uit.get_value()
        ULIA = self.Uur_Licht_Aan.get_value()
        ULIU = self.Uur_Licht_Uit.get_value()
        ULO  = self.Uur_Luik_Open.get_value()
        ULD  = self.Uur_Luik_Dicht.get_value()

        print(ULA, ULU, ULIA, ULIU, ULO, ULD)
        return ULA, ULU, ULIA, ULIU, ULO, ULD


    def displayDate(self, state):
        Time_now = str(datetime.datetime.now().strftime("%d-%m-%Y"))
        self.labelDate.set_label(Time_now)
        return state,


    def displayclock(self, state):
        #  putting our datetime into a var and setting our label to the result.
        #  we need to return "True" to ensure the timer continues to run, otherwise it will only run once.
        Time_now = str(datetime.datetime.now().strftime("%H:%M:%S"))
        self.labelClock.set_label(Time_now)
        return state, Time_now

    # Initialize Timer
    def startclocktimer(self):
        #  this takes 2 args: (how often to update in millisec, the method to run)
        GLib.timeout_add(100, self.displayclock, True)

    def startDate(self):
        #  this takes 2 args: (how often to update in millisec, the method to run)
        GLib.timeout_add(100, self.displayDate, True)


    def Switch_LED(self, switch, gparam):
        if switch.get_active():
            state = "Led_On"
        else:
            state = "Led_Off"
        print("Led_Switch was", state)


    def Switch_Licht(self, switch, gparam):
        if switch.get_active():
            state = "Licht_on"
        else:
            state = "Licht_off"
        print("Licht_Switch was", state)

    def Luik_Open(self, button):
        state = "Rolluik_open"
        print(state)

    def Luik_Dicht(self, button):
        state = "Rolluik_dicht"
        print(state)

if __name__ == '__main__':
    main = Main()
    main.startclocktimer()
    main.startDate()
    main.ULED_Update()
    gtk.main()
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
kevekop
  • 3
  • 2
  • I'm not sure that I understand what your actual question is. Could you describe what happens when you run the code you posted, and how that differs from what you expect to happen? – JHixson Jun 03 '20 at 19:07
  • i changed my code back how i was trying. I try to compare the live current time, for example : now it's 22H and my LED needs to go ON at 22H30 and needs to go OFF at 23H. I made a def called "compare" etc... . sorry for the bad explaind question and english.. i'm a bit tired too, was working on this GUI till 5H this morning – kevekop Jun 03 '20 at 20:13

1 Answers1

0

start a separated thread for updating the timer showing the time in a label in the GUI. I see an example there https://github.com/f4iteightiz/UWR_scoreboard

floppy_molly
  • 175
  • 1
  • 10