# Introduction to Qt - demonstrating GUI with QPushButtons and QLabel
# 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, QLabel, QPushButton
from    PySide6.QtCore      import  Qt

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

class GUI(QWidget):

    def __init__(self):
        self.app = QApplication([])
        super().__init__()
        self.setWindowTitle('The Title')
        self.resize(650, 170)                       # size  window
        self.label = QLabel('label', self)
        self.label.setAlignment(Qt.AlignCenter)
        self.label.setStyleSheet("font-size: 20px; font-weight: bold; color: red")
        self.label.setGeometry(50, 30, 550, 50)
        btn = QPushButton('Date', self)
        btn.setGeometry(50, 100, 100, 35)
        btn.clicked.connect(self.onBtnDate)
        btn = QPushButton('Hour', self)
        btn.setGeometry(200, 100, 100, 35)
        btn.clicked.connect(self.onBtnHour)
        btn = QPushButton('Minute', self)
        btn.setGeometry(350, 100, 100, 35)
        btn.clicked.connect(self.onBtnMinute)
        btn = QPushButton('Second', self)
        btn.setGeometry(500, 100, 100, 35)
        btn.clicked.connect(self.onBtnSecond)
        self.show()


    def onBtnDate(self):
        self.label.setText(f'The date of today is {date.today()}')


    def onBtnHour(self):
        now = datetime.now()
        self.label.setText(f'The current hour is: {now.hour}')


    def onBtnMinute(self):
        now = datetime.now()
        self.label.setText(f'The current minute is: {now.minute}')


    def onBtnSecond(self):
        now = datetime.now()
        self.label.setText(f'The current second is: {now.second}')

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

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