# Introduction to Qt - demonstrating buttuns within a layout manager
# by Anthony Vogelaar, Perth Scotland
# rev 0.10  2024-03-31  Initial release

import  os, sys, signal;    os.system('clear')
from    datetime            import  date, datetime
from    PySide6.QtWidgets   import  QApplication, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton
from    PySide6.QtCore      import  Qt

# ================================== GUI =========================================

class GUI(QWidget):

    def __init__(self):
        self.app = QApplication([])
        super().__init__()
        self.setWindowTitle('The Title')

        lo_main = QVBoxLayout()
        self.label = QLabel('label')
        self.label.setAlignment(Qt.AlignCenter)
        self.label.setStyleSheet("font-size: 20px; font-weight: bold; color: red")
        lo_main.addWidget(self.label)

        lo_buttons = QHBoxLayout()
        for caption in ('Date', 'Hour', 'Minute', 'Second'):
            btn = QPushButton(caption)
            btn.clicked.connect(self.onBtnClick)
            lo_buttons.addWidget(btn)

        lo_main.addLayout(lo_buttons)
        self.setLayout(lo_main)
        self.show()


    def onBtnClick(self):
        now = datetime.now()
        id  = self.sender().text()
        if   id == 'Date'  : msg = f'The date of today is {date.today()}'
        elif id == 'Hour'  : msg = f'The current hour is: {now.hour}'
        elif id == 'Minute': msg = f'The current minute is: {now.minute}'
        else               : msg = f'The current second is: {now.second}'
        self.label.setText(msg)

# ================================ Main ==========================================
        
signal.signal(signal.SIGINT, signal.SIG_DFL)        # handle ctrl-c
gui     = GUI()
sys.exit(gui.app.exec())

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