From ba1f11b79e4d29c9efa3797d54facf438210bd88 Mon Sep 17 00:00:00 2001 From: Eugenio Parodi Date: Tue, 21 Nov 2023 17:18:19 +0000 Subject: [PATCH] Adapted the tests to the new terminalhelper --- .../TTkWidgets/TTkTerminal/terminalhelper.py | 9 +++- tests/t.pty/test.pty.006.terminal.01.py | 7 +-- tests/t.pty/test.pty.006.terminal.02.py | 12 +++-- tests/t.pty/test.pty.006.terminal.03.py | 12 +++-- tests/t.pty/test.pty.006.terminal.04.py | 4 +- tests/t.pty/test.pty.006.terminal.05.py | 3 +- .../TTkTerminal/TerminalTab.01.Basic.py | 7 +-- .../TTkTerminal/TerminalTab.02.AddButton.py | 8 +-- .../TTkTerminal/TerminalTab.03.KodeTab.py | 8 +-- .../TerminalTab.04.KodeTab.close.py | 53 +++++++++++++++++++ 10 files changed, 100 insertions(+), 23 deletions(-) create mode 100755 tutorial/examples/TTkTerminal/TerminalTab.04.KodeTab.close.py diff --git a/TermTk/TTkWidgets/TTkTerminal/terminalhelper.py b/TermTk/TTkWidgets/TTkTerminal/terminalhelper.py index 9306256d..2e401973 100644 --- a/TermTk/TTkWidgets/TTkTerminal/terminalhelper.py +++ b/TermTk/TTkWidgets/TTkTerminal/terminalhelper.py @@ -33,7 +33,7 @@ class TTkTerminalHelper(): '_quit_pipe', '_size', #Signals 'dataOut') - def __init__(self) -> None: + def __init__(self, term=None) -> None: self.dataOut = pyTTkSignal(str) self._shell = os.environ.get('SHELL', 'sh') self._fd = None @@ -42,6 +42,13 @@ class TTkTerminalHelper(): self._quit_pipe = None self._size = (80,24) TTkHelper.quitEvent.connect(self._quit) + if term: + self.attachTTkTerminal(term) + + def attachTTkTerminal(self, term): + self.dataOut.connect(term.termWrite) + term.termData.connect(self.push) + term.termResized.connect(self.resize) def runShell(self, program=None): self._shell = program if program else self._shell diff --git a/tests/t.pty/test.pty.006.terminal.01.py b/tests/t.pty/test.pty.006.terminal.01.py index 030fb152..cb89cf8f 100755 --- a/tests/t.pty/test.pty.006.terminal.01.py +++ b/tests/t.pty/test.pty.006.terminal.01.py @@ -56,11 +56,12 @@ ttk.TTkLogViewer(parent=wlog, follow=False ) win1 = ttk.TTkWindow(parent=root, pos=(1,1), size=(70,15), title="Terminallo n.1", border=True, layout=ttk.TTkVBoxLayout(), flags = ttk.TTkK.WindowFlag.WindowMinMaxButtonsHint) term1 = ttk.TTkTerminal(parent=win1) -term1.runShell() +th1 = ttk.TTkTerminalHelper(term=term1) +th1.runShell() win2 = ttk.TTkWindow(parent=root, pos=(10,5), size=(70,15), title="Terminallo n.2", border=True, layout=ttk.TTkVBoxLayout(), flags = ttk.TTkK.WindowFlag.WindowMinMaxButtonsHint) term2 = ttk.TTkTerminal(parent=win2) -term2.runShell() - +th2 = ttk.TTkTerminalHelper(term=term2) +th2.runShell() root.mainloop() \ No newline at end of file diff --git a/tests/t.pty/test.pty.006.terminal.02.py b/tests/t.pty/test.pty.006.terminal.02.py index 68c37bce..91d245a4 100755 --- a/tests/t.pty/test.pty.006.terminal.02.py +++ b/tests/t.pty/test.pty.006.terminal.02.py @@ -66,19 +66,23 @@ quitBtn.clicked.connect(ttk.TTkHelper.quit) win1 = ttk.TTkWindow(pos=(90,5), size=(70,15), title="Terminallo n.1", border=True, layout=ttk.TTkVBoxLayout(), flags = ttk.TTkK.WindowFlag.WindowMinMaxButtonsHint) term1 = ttk.TTkTerminal(parent=win1) -term1.runShell() +th1 = ttk.TTkTerminalHelper(term=term1) +th1.runShell() win2 = ttk.TTkWindow(pos=(0,0), size=(150,30), title="Terminallo n.2", border=True, layout=ttk.TTkVBoxLayout(), flags = ttk.TTkK.WindowFlag.WindowMinMaxButtonsHint) term2 = ttk.TTkTerminal(parent=win2) -term2.runShell() +th2 = ttk.TTkTerminalHelper(term=term2) +th2.runShell() win3 = ttk.TTkWindow(pos=(92,8), size=(70,15), title="Terminallo n.3", border=True, layout=ttk.TTkVBoxLayout(), flags = ttk.TTkK.WindowFlag.WindowMinMaxButtonsHint) term3 = ttk.TTkTerminal(parent=win3) -term3.runShell() +th3 = ttk.TTkTerminalHelper(term=term3) +th3.runShell() win4 = ttk.TTkWindow(pos=(94,11), size=(70,15), title="Terminallo n.4", border=True, layout=ttk.TTkVBoxLayout(), flags = ttk.TTkK.WindowFlag.WindowMinMaxButtonsHint) term4 = ttk.TTkTerminal(parent=win4) -term4.runShell() +th4 = ttk.TTkTerminalHelper(term=term4) +th4.runShell() top.addWidgets([quitBtn, win1, win2, win3, win4]) diff --git a/tests/t.pty/test.pty.006.terminal.03.py b/tests/t.pty/test.pty.006.terminal.03.py index 85887128..63d7ce9c 100755 --- a/tests/t.pty/test.pty.006.terminal.03.py +++ b/tests/t.pty/test.pty.006.terminal.03.py @@ -76,21 +76,25 @@ cb_q.stateChanged.connect(lambda x: ttk.TTkTerm.setSigmask(ttk.TTkTerm.Sigmask.C win1 = ttk.TTkWindow(pos=(90,5), size=(70,15), title="Terminallo n.1", border=True, layout=ttk.TTkVBoxLayout(), flags = ttk.TTkK.WindowFlag.WindowMinMaxButtonsHint) term1 = ttk.TTkTerminal(parent=win1) -term1.runShell() +th1 = ttk.TTkTerminalHelper(term=term1) +th1.runShell() win2 = ttk.TTkWindow(pos=(10,0), size=(100,30), title="Terminallo n.2", border=True, layout=ttk.TTkVBoxLayout(), flags = ttk.TTkK.WindowFlag.WindowMinMaxButtonsHint) term2 = ttk.TTkTerminal(parent=win2) term2.bell.connect(lambda : ttk.TTkLog.debug("BELL!!! 🔔🔔🔔")) term2.titleChanged.connect(win2.setTitle) -term2.runShell() +th2 = ttk.TTkTerminalHelper(term=term2) +th2.runShell() win3 = ttk.TTkWindow(pos=(92,8), size=(70,15), title="Terminallo n.3", border=True, layout=ttk.TTkVBoxLayout(), flags = ttk.TTkK.WindowFlag.WindowMinMaxButtonsHint) term3 = ttk.TTkTerminal(parent=win3) -term3.runShell() +th3 = ttk.TTkTerminalHelper(term=term3) +th3.runShell() win4 = ttk.TTkWindow(pos=(94,11), size=(70,15), title="Terminallo n.4", border=True, layout=ttk.TTkVBoxLayout(), flags = ttk.TTkK.WindowFlag.WindowMinMaxButtonsHint) term4 = ttk.TTkTerminal(parent=win4) -term4.runShell() +th4 = ttk.TTkTerminalHelper(term=term4) +th4.runShell() top.addWidgets([quitBtn, cb_c, cb_s, cb_z, cb_q, win1, win2, win3, win4]) diff --git a/tests/t.pty/test.pty.006.terminal.04.py b/tests/t.pty/test.pty.006.terminal.04.py index 16e775c8..742e0442 100755 --- a/tests/t.pty/test.pty.006.terminal.04.py +++ b/tests/t.pty/test.pty.006.terminal.04.py @@ -78,7 +78,9 @@ win = ttk.TTkWindow(pos=(10,0), size=(100,30), title="Terminallo n.2", border=T term = ttk.TTkTerminal(parent=win) term.bell.connect(lambda : ttk.TTkLog.debug("BELL!!! 🔔🔔🔔")) term.titleChanged.connect(win.setTitle) -term.runShell() +th = ttk.TTkTerminalHelper(term=term) +th.runShell() + term.terminalClosed.connect(win.close) win.closed.connect(term.close) diff --git a/tests/t.pty/test.pty.006.terminal.05.py b/tests/t.pty/test.pty.006.terminal.05.py index 0be2b5f7..b3a42fb7 100755 --- a/tests/t.pty/test.pty.006.terminal.05.py +++ b/tests/t.pty/test.pty.006.terminal.05.py @@ -59,7 +59,8 @@ win = ttk.TTkWindow(pos=(10,0), size=(100,30), title="Terminallo n.2", border=T term = ttk.TTkTerminal(parent=win) term.bell.connect(lambda : ttk.TTkLog.debug("BELL!!! 🔔🔔🔔")) term.titleChanged.connect(win.setTitle) -term.runShell() +th = ttk.TTkTerminalHelper(term=term) +th.runShell() term.terminalClosed.connect(win.close) win.closed.connect(term.close) diff --git a/tutorial/examples/TTkTerminal/TerminalTab.01.Basic.py b/tutorial/examples/TTkTerminal/TerminalTab.01.Basic.py index 45992fec..bcd52783 100755 --- a/tutorial/examples/TTkTerminal/TerminalTab.01.Basic.py +++ b/tutorial/examples/TTkTerminal/TerminalTab.01.Basic.py @@ -38,10 +38,11 @@ root = ttk.TTk(layout=ttk.TTkGridLayout(), mouseTrack=True) tab = ttk.TTkTabWidget(parent=root) -terminal = ttk.TTkTerminal() +term = ttk.TTkTerminal() +th = ttk.TTkTerminalHelper(term=term) +th.runShell() -tab.addTab(terminal, "Terminal") +tab.addTab(term, "Terminal") -terminal.runShell() root.mainloop() diff --git a/tutorial/examples/TTkTerminal/TerminalTab.02.AddButton.py b/tutorial/examples/TTkTerminal/TerminalTab.02.AddButton.py index fd14c444..9126b7cf 100755 --- a/tutorial/examples/TTkTerminal/TerminalTab.02.AddButton.py +++ b/tutorial/examples/TTkTerminal/TerminalTab.02.AddButton.py @@ -42,9 +42,11 @@ menu = tab.addMenu("Add Terminal") def _addTerminal(): num = tab.count() + 1 - terminal = ttk.TTkTerminal() - tab.addTab(terminal, f"Terminal {num}") - terminal.runShell() + term = ttk.TTkTerminal() + th = ttk.TTkTerminalHelper(term=term) + tab.addTab(term, f"Terminal {num}") + tab.setCurrentWidget(term) + th.runShell() menu.menuButtonClicked.connect(_addTerminal) diff --git a/tutorial/examples/TTkTerminal/TerminalTab.03.KodeTab.py b/tutorial/examples/TTkTerminal/TerminalTab.03.KodeTab.py index 5b7d807a..d79dcfac 100755 --- a/tutorial/examples/TTkTerminal/TerminalTab.03.KodeTab.py +++ b/tutorial/examples/TTkTerminal/TerminalTab.03.KodeTab.py @@ -42,9 +42,11 @@ tab = ttk.TTkKodeTab(parent=root) menu = tab.addMenu("Add Terminal") def _addTerminal(): - terminal = ttk.TTkTerminal() - tab.addTab(terminal, "Terminal") - terminal.runShell() + term = ttk.TTkTerminal() + th = ttk.TTkTerminalHelper(term=term) + tab.addTab(term, f"Terminal") + tab.setCurrentWidget(term) + th.runShell() menu.menuButtonClicked.connect(_addTerminal) diff --git a/tutorial/examples/TTkTerminal/TerminalTab.04.KodeTab.close.py b/tutorial/examples/TTkTerminal/TerminalTab.04.KodeTab.close.py new file mode 100755 index 00000000..d79dcfac --- /dev/null +++ b/tutorial/examples/TTkTerminal/TerminalTab.04.KodeTab.close.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 + +# MIT License +# +# Copyright (c) 2023 Eugenio Parodi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +# Those 2 lines are required to use the TermTk library straight from the main folder +import sys, os +sys.path.append(os.path.join(sys.path[0],'../../..')) + +import TermTk as ttk + +# layout = GridLayout +# It is required to allow the tabWidget to be automatically resized to the "root" area +# mouseTrack = True (optional) +# It is required if we want to forward the mouse over events to the terminals +# i.e. the mouse over feature of pytermTk or Textual +root = ttk.TTk(layout=ttk.TTkGridLayout(), mouseTrack=True) + +# The KodeTab allow to split the screen dragging the tab at the corner of the widget +tab = ttk.TTkKodeTab(parent=root) + +menu = tab.addMenu("Add Terminal") + +def _addTerminal(): + term = ttk.TTkTerminal() + th = ttk.TTkTerminalHelper(term=term) + tab.addTab(term, f"Terminal") + tab.setCurrentWidget(term) + th.runShell() + +menu.menuButtonClicked.connect(_addTerminal) + +root.mainloop()