Skip to content

Commit ba1f11b

Browse files
Adapted the tests to the new terminalhelper
1 parent 60a3720 commit ba1f11b

10 files changed

+100
-23
lines changed

TermTk/TTkWidgets/TTkTerminal/terminalhelper.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class TTkTerminalHelper():
3333
'_quit_pipe', '_size',
3434
#Signals
3535
'dataOut')
36-
def __init__(self) -> None:
36+
def __init__(self, term=None) -> None:
3737
self.dataOut = pyTTkSignal(str)
3838
self._shell = os.environ.get('SHELL', 'sh')
3939
self._fd = None
@@ -42,6 +42,13 @@ def __init__(self) -> None:
4242
self._quit_pipe = None
4343
self._size = (80,24)
4444
TTkHelper.quitEvent.connect(self._quit)
45+
if term:
46+
self.attachTTkTerminal(term)
47+
48+
def attachTTkTerminal(self, term):
49+
self.dataOut.connect(term.termWrite)
50+
term.termData.connect(self.push)
51+
term.termResized.connect(self.resize)
4552

4653
def runShell(self, program=None):
4754
self._shell = program if program else self._shell

tests/t.pty/test.pty.006.terminal.01.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@
5656

5757
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)
5858
term1 = ttk.TTkTerminal(parent=win1)
59-
term1.runShell()
59+
th1 = ttk.TTkTerminalHelper(term=term1)
60+
th1.runShell()
6061

6162
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)
6263
term2 = ttk.TTkTerminal(parent=win2)
63-
term2.runShell()
64-
64+
th2 = ttk.TTkTerminalHelper(term=term2)
65+
th2.runShell()
6566

6667
root.mainloop()

tests/t.pty/test.pty.006.terminal.02.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,23 @@
6666

6767
win1 = ttk.TTkWindow(pos=(90,5), size=(70,15), title="Terminallo n.1", border=True, layout=ttk.TTkVBoxLayout(), flags = ttk.TTkK.WindowFlag.WindowMinMaxButtonsHint)
6868
term1 = ttk.TTkTerminal(parent=win1)
69-
term1.runShell()
69+
th1 = ttk.TTkTerminalHelper(term=term1)
70+
th1.runShell()
7071

7172
win2 = ttk.TTkWindow(pos=(0,0), size=(150,30), title="Terminallo n.2", border=True, layout=ttk.TTkVBoxLayout(), flags = ttk.TTkK.WindowFlag.WindowMinMaxButtonsHint)
7273
term2 = ttk.TTkTerminal(parent=win2)
73-
term2.runShell()
74+
th2 = ttk.TTkTerminalHelper(term=term2)
75+
th2.runShell()
7476

7577
win3 = ttk.TTkWindow(pos=(92,8), size=(70,15), title="Terminallo n.3", border=True, layout=ttk.TTkVBoxLayout(), flags = ttk.TTkK.WindowFlag.WindowMinMaxButtonsHint)
7678
term3 = ttk.TTkTerminal(parent=win3)
77-
term3.runShell()
79+
th3 = ttk.TTkTerminalHelper(term=term3)
80+
th3.runShell()
7881

7982
win4 = ttk.TTkWindow(pos=(94,11), size=(70,15), title="Terminallo n.4", border=True, layout=ttk.TTkVBoxLayout(), flags = ttk.TTkK.WindowFlag.WindowMinMaxButtonsHint)
8083
term4 = ttk.TTkTerminal(parent=win4)
81-
term4.runShell()
84+
th4 = ttk.TTkTerminalHelper(term=term4)
85+
th4.runShell()
8286

8387
top.addWidgets([quitBtn, win1, win2, win3, win4])
8488

tests/t.pty/test.pty.006.terminal.03.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,25 @@
7676

7777
win1 = ttk.TTkWindow(pos=(90,5), size=(70,15), title="Terminallo n.1", border=True, layout=ttk.TTkVBoxLayout(), flags = ttk.TTkK.WindowFlag.WindowMinMaxButtonsHint)
7878
term1 = ttk.TTkTerminal(parent=win1)
79-
term1.runShell()
79+
th1 = ttk.TTkTerminalHelper(term=term1)
80+
th1.runShell()
8081

8182
win2 = ttk.TTkWindow(pos=(10,0), size=(100,30), title="Terminallo n.2", border=True, layout=ttk.TTkVBoxLayout(), flags = ttk.TTkK.WindowFlag.WindowMinMaxButtonsHint)
8283
term2 = ttk.TTkTerminal(parent=win2)
8384
term2.bell.connect(lambda : ttk.TTkLog.debug("BELL!!! 🔔🔔🔔"))
8485
term2.titleChanged.connect(win2.setTitle)
85-
term2.runShell()
86+
th2 = ttk.TTkTerminalHelper(term=term2)
87+
th2.runShell()
8688

8789
win3 = ttk.TTkWindow(pos=(92,8), size=(70,15), title="Terminallo n.3", border=True, layout=ttk.TTkVBoxLayout(), flags = ttk.TTkK.WindowFlag.WindowMinMaxButtonsHint)
8890
term3 = ttk.TTkTerminal(parent=win3)
89-
term3.runShell()
91+
th3 = ttk.TTkTerminalHelper(term=term3)
92+
th3.runShell()
9093

9194
win4 = ttk.TTkWindow(pos=(94,11), size=(70,15), title="Terminallo n.4", border=True, layout=ttk.TTkVBoxLayout(), flags = ttk.TTkK.WindowFlag.WindowMinMaxButtonsHint)
9295
term4 = ttk.TTkTerminal(parent=win4)
93-
term4.runShell()
96+
th4 = ttk.TTkTerminalHelper(term=term4)
97+
th4.runShell()
9498

9599
top.addWidgets([quitBtn, cb_c, cb_s, cb_z, cb_q, win1, win2, win3, win4])
96100

tests/t.pty/test.pty.006.terminal.04.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@
7878
term = ttk.TTkTerminal(parent=win)
7979
term.bell.connect(lambda : ttk.TTkLog.debug("BELL!!! 🔔🔔🔔"))
8080
term.titleChanged.connect(win.setTitle)
81-
term.runShell()
81+
th = ttk.TTkTerminalHelper(term=term)
82+
th.runShell()
83+
8284
term.terminalClosed.connect(win.close)
8385
win.closed.connect(term.close)
8486

tests/t.pty/test.pty.006.terminal.05.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
term = ttk.TTkTerminal(parent=win)
6060
term.bell.connect(lambda : ttk.TTkLog.debug("BELL!!! 🔔🔔🔔"))
6161
term.titleChanged.connect(win.setTitle)
62-
term.runShell()
62+
th = ttk.TTkTerminalHelper(term=term)
63+
th.runShell()
6364
term.terminalClosed.connect(win.close)
6465
win.closed.connect(term.close)
6566

tutorial/examples/TTkTerminal/TerminalTab.01.Basic.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@
3838

3939
tab = ttk.TTkTabWidget(parent=root)
4040

41-
terminal = ttk.TTkTerminal()
41+
term = ttk.TTkTerminal()
42+
th = ttk.TTkTerminalHelper(term=term)
43+
th.runShell()
4244

43-
tab.addTab(terminal, "Terminal")
45+
tab.addTab(term, "Terminal")
4446

45-
terminal.runShell()
4647

4748
root.mainloop()

tutorial/examples/TTkTerminal/TerminalTab.02.AddButton.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@
4242

4343
def _addTerminal():
4444
num = tab.count() + 1
45-
terminal = ttk.TTkTerminal()
46-
tab.addTab(terminal, f"Terminal {num}")
47-
terminal.runShell()
45+
term = ttk.TTkTerminal()
46+
th = ttk.TTkTerminalHelper(term=term)
47+
tab.addTab(term, f"Terminal {num}")
48+
tab.setCurrentWidget(term)
49+
th.runShell()
4850

4951
menu.menuButtonClicked.connect(_addTerminal)
5052

tutorial/examples/TTkTerminal/TerminalTab.03.KodeTab.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@
4242
menu = tab.addMenu("Add Terminal")
4343

4444
def _addTerminal():
45-
terminal = ttk.TTkTerminal()
46-
tab.addTab(terminal, "Terminal")
47-
terminal.runShell()
45+
term = ttk.TTkTerminal()
46+
th = ttk.TTkTerminalHelper(term=term)
47+
tab.addTab(term, f"Terminal")
48+
tab.setCurrentWidget(term)
49+
th.runShell()
4850

4951
menu.menuButtonClicked.connect(_addTerminal)
5052

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python3
2+
3+
# MIT License
4+
#
5+
# Copyright (c) 2023 Eugenio Parodi <ceccopierangiolieugenio AT googlemail DOT com>
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
25+
26+
# Those 2 lines are required to use the TermTk library straight from the main folder
27+
import sys, os
28+
sys.path.append(os.path.join(sys.path[0],'../../..'))
29+
30+
import TermTk as ttk
31+
32+
# layout = GridLayout
33+
# It is required to allow the tabWidget to be automatically resized to the "root" area
34+
# mouseTrack = True (optional)
35+
# It is required if we want to forward the mouse over events to the terminals
36+
# i.e. the mouse over feature of pytermTk or Textual
37+
root = ttk.TTk(layout=ttk.TTkGridLayout(), mouseTrack=True)
38+
39+
# The KodeTab allow to split the screen dragging the tab at the corner of the widget
40+
tab = ttk.TTkKodeTab(parent=root)
41+
42+
menu = tab.addMenu("Add Terminal")
43+
44+
def _addTerminal():
45+
term = ttk.TTkTerminal()
46+
th = ttk.TTkTerminalHelper(term=term)
47+
tab.addTab(term, f"Terminal")
48+
tab.setCurrentWidget(term)
49+
th.runShell()
50+
51+
menu.menuButtonClicked.connect(_addTerminal)
52+
53+
root.mainloop()

0 commit comments

Comments
 (0)