Browse Source

Adapted the tests to the new terminalhelper

pull/206/head
Eugenio Parodi 2 years ago
parent
commit
ba1f11b79e
  1. 9
      TermTk/TTkWidgets/TTkTerminal/terminalhelper.py
  2. 7
      tests/t.pty/test.pty.006.terminal.01.py
  3. 12
      tests/t.pty/test.pty.006.terminal.02.py
  4. 12
      tests/t.pty/test.pty.006.terminal.03.py
  5. 4
      tests/t.pty/test.pty.006.terminal.04.py
  6. 3
      tests/t.pty/test.pty.006.terminal.05.py
  7. 7
      tutorial/examples/TTkTerminal/TerminalTab.01.Basic.py
  8. 8
      tutorial/examples/TTkTerminal/TerminalTab.02.AddButton.py
  9. 8
      tutorial/examples/TTkTerminal/TerminalTab.03.KodeTab.py
  10. 53
      tutorial/examples/TTkTerminal/TerminalTab.04.KodeTab.close.py

9
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

7
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()

12
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])

12
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])

4
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)

3
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)

7
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()

8
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)

8
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)

53
tutorial/examples/TTkTerminal/TerminalTab.04.KodeTab.close.py

@ -0,0 +1,53 @@
#!/usr/bin/env python3
# MIT License
#
# Copyright (c) 2023 Eugenio Parodi <ceccopierangiolieugenio AT googlemail DOT com>
#
# 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()
Loading…
Cancel
Save