# cPy qt_intro : text edit
# Copyright by Anthony Vogelaar, Perth Scotland
# rev 0.10  2026-01-26  initial release

from    PySide6.QtWidgets   import  (QApplication, QWidget, QPushButton, 
                                     QLineEdit, QTextEdit)
from    PySide6.QtGui       import  QTextCursor

# ========================== demo ==============================

# demonstrating QLineEdit
class Gui1(QWidget):

    def __init__(self):
        app = QApplication()                            # Qt framework
        super().__init__()                              # instantiate QWidget = GUI
        self.resize(550, 200)
        self.ed = QLineEdit('Enter text', self)
        self.ed.setGeometry(50, 40, 180, 30)
        self.ed.textChanged.connect(self.onChanged)
        btn = QPushButton('Add', self)
        btn.setGeometry(250, 40, 50, 30)
        btn.clicked.connect(self.onBtnAddClick)
        btn = QPushButton('Clear', self)
        btn.setGeometry(250, 90, 50, 30)
        btn.clicked.connect(self.onBtnClearClick)
        self.memo = QTextEdit(self)
        self.memo.setGeometry(320, 40, 180, 120)
        self.memo.setReadOnly(True)
        self.memo.setStyleSheet('background-color: MediumAquamarine')
        self.show()
        app.exec()


    def onChanged(self):
        self.ed.setStyleSheet('background-color: Yellow')


    def onBtnAddClick(self, sts):
        if s := self.ed.text():
           txt = self.memo.toPlainText()
           if txt: txt += '\n'
           self.memo.setText(txt + s)
           self.memo.moveCursor(QTextCursor.End)
        self.ed.clear()
        self.ed.setStyleSheet('background-color: White')


    def onBtnClearClick(self, sts):
        self.memo.clear()

# ============================= main =============================

Gui1()

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