ceccopierangiolieugenio / pyTermTk

Python Terminal Toolkit - a Spiced Up TUI Library 🌶️
https://ceccopierangiolieugenio.github.io/pyTermTk/
MIT License
585 stars 22 forks source link

How do I detect TTkTextEdit contents changed? #110

Closed nickandwolf closed 1 year ago

nickandwolf commented 1 year ago

Hello, I am trying to detect if the user has change the contents of a TextEdit widget but I am having a hard time figuring it out. Thank you again! I'll soon have something to show for all this effort.

self.te = ttk.TTkTextEdit(parent= (tef:=ttk.TTkFrame(parent=self.root,
                        pos=(0,6),size=(42,7),border=True)),
                        document=None,pos=(0,0),size=(41,5))
        self.te.setReadOnly(False)
        self.te.setLineWrapMode(ttk.TTkK.WidgetWidth)
        self.te.setWordWrapMode(ttk.TTkK.WordWrap)
        self.te.setText(self.lifepath.familyBackground)

        self.te.contentsChanged.connect(self.Unsaved) #here's where I fall flat.
ceccopierangiolieugenio commented 1 year ago

yes, the signal is missing, I will add it soon. I am keeping the textEdit a little on hold because I am slowly implementing some features that are needed if you want to use it in a proper codeEditor/Viewer (ttkode) you can workaround it using the textDocument signal:

self.te = ttk.TTkTextEdit(parent= (tef:=ttk.TTkFrame(parent=self.root,
                        pos=(0,6),size=(42,7),border=True)),
                        document=None,pos=(0,0),size=(41,5))
        self.te.setReadOnly(False)
        self.te.setLineWrapMode(ttk.TTkK.WidgetWidth)
        self.te.setWordWrapMode(ttk.TTkK.WordWrap)
        self.te.setText(self.lifepath.familyBackground)

        # the textChanged api will forward in the next release the document contentsChanged signal
        self.te.document().contentsChanged.connect(self.Unsaved) #here's where I fall flat.
ceccopierangiolieugenio commented 1 year ago

Here there is an example:

https://ceccopierangiolieugenio.github.io/pyTermTk/sandbox/sandbox.html?fileUri=https://gist.githubusercontent.com/ceccopierangiolieugenio/1be5eee2063d3e218e6e0eef65a8c33b/raw/d2a9ae991048d485a6913f211f198c2e91dac137/TextEditExample_001.py