# Introduction to Qt - demonstrating task QTimer controlled
# by Anthony Vogelaar, Perth Scotland
# rev 0.10  2024-04-02  Initial release

import  os, signal;     os.system('clear')
from    datetime        import  date, datetime
from    ex13_gui        import  GUI

# =============================== Controller =========================================

class Controller:

    def __init__(self):
        self.counter = 0
        signal.signal(signal.SIGINT, signal.SIG_DFL)        # handle ctrl-c
        self.gui = GUI(self)                                # argument is owner
        self.gui.app.exec()


    # handle incoming commands
    def doCommand(self, d):
        for k, v in d.items():
            if k == 'btn_click':
                now = datetime.now()
                if   v == 'Date'  : msg = f'The date of today is {date.today()}'
                elif v == 'Hour'  : msg = f'The current hour is: {now.hour}'
                elif v == 'Minute': msg = f'The current minute is: {now.minute}'
                elif v == 'Second': msg = f'The current second is: {now.second}'
                else              : msg = f'The Counter value is: {self.counter}'
                self.gui.doCommand(dict(msg=msg))
            if k == 'timer': self.counter += 1

# ================================ Main ==========================================
        
Controller()

# ================================= End ==========================================
