# cPy qt_intro : image-button
# Copyright by Anthony Vogelaar, Perth Scotland
# rev 0.10  2026-01-25  initial release

from    PySide6.QtWidgets   import  QApplication, QWidget, QPushButton
from    PySide6.QtGui       import  QIcon
from    PySide6.QtCore      import  QSize

# ========================== demo 1 ==============================

# most simple usage of a QPushButton with icon
# a QIcon contais up to 8 images for states Normal, Disabled, Active and
#    Selected all in On and Off mode
class Gui1(QWidget):

    def __init__(self):
        app = QApplication()                            # Qt framework
        super().__init__()                              # instantiate QWidget = GUI
        self.resize(500, 300)
        icon     = QIcon('forth_bridge.jpg')
        btn = QPushButton(icon, '      Press Me', self) # space between icon and text
        btn.setGeometry(50, 50, 170, 80)
        # btn.setStyleSheet('background-color: Yellow')
        # btn.setIconSize(QSize(70, 70))
        btn.clicked.connect(self.onBtnClick)
        self.show()
        app.exec()


    def onBtnClick(self, sts):
        print('onBtnClick')

Gui1()

# ========================== demo 2 ==============================

# demonstrating enable / disable a button
class Gui2(QWidget):

    def __init__(self):
        app = QApplication()                            # Qt framework
        super().__init__()                              # instantiate QWidget = GUI
        self.resize(400, 150)
        icon     = QIcon('forth_bridge.jpg')
        self.btn1 = QPushButton(icon, 'Btn 1', self)
        self.btn1.setGeometry(50, 50, 100, 40)
        self.btn1.clicked.connect(self.onBtnClick)
        self.btn2 = QPushButton(icon, 'Btn 2', self)
        self.btn2.setGeometry(250, 50, 100, 40)
        self.btn2.clicked.connect(self.onBtnClick)
        self.btn2.setEnabled(False)
        self.show()
        app.exec()


    def onBtnClick(self, sts):
        left_button = self.sender().text() == 'Btn 1'
        self.btn1.setEnabled(not left_button)
        self.btn2.setEnabled(left_button)

#Gui2()

# ========================== demo 3 ==============================

# demonstrating a toglle button and adjusted icon size
class Gui3(QWidget):

    def __init__(self):
        app = QApplication()                            # Qt framework
        super().__init__()                              # instantiate QWidget = GUI
        self.resize(500, 300)
        icon     = QIcon('forth_bridge.jpg')
        btn = QPushButton(icon, '      Press Me', self) # space between icon and text
        btn.setGeometry(50, 50, 170, 80)
        btn.setIconSize(QSize(70, 70))
        btn.setCheckable(True)
        btn.setObjectName('b1')
        btn.setStyleSheet('#b1{background-color: Lime;} #b1:checked{background-color: Red}')
        btn.clicked.connect(self.onBtnClick)
        self.show()
        app.exec()


    def onBtnClick(self, sts):
        print('onBtnClick', sts)


#Gui3()

# ============================== end =============================
