# Introduction to Qt - demonstrating Business - GUI communication
# 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    ex11_gui        import  GUI

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

class Controller:

    def __init__(self):
        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}'
                else              : msg = f'The current second is: {now.second}'
                self.gui.doCommand(dict(msg=msg))

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

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