TTkTerminalHelper🌢️

class TTkTerminalHelper(*, term: TTkTerminal = None)[source]🌢️

Bases: object

TTkTerminalHelper is a convenience class that simplify the initilization and the handling of a pty terminal session

Note

This helper is available only on Linux and Mac

Quickstart:

import TermTk as ttk

root = ttk.TTk(mouseTrack=True)

win = ttk.TTkWindow(parent=root, title="Terminal", size=(80+2,24+4), layout=ttk.TTkGridLayout())

term = ttk.TTkTerminal(parent=win)

th = ttk.TTkTerminalHelper(term=term)
th.runShell()

root.mainloop()
Parameters:

term (TTkTerminal) – The terminal handled by this helper.

Signals🌢️

dataOut

This signal is emitted when some data is available in the pty interface

terminalClosed

This signal is emitted when the pty session ends

Slots🌢️

push(data)

Send the data to the pty session

resize(width,Β height)

Send a resize "TIOCSWINSZ" ioctl to the pty session

Members🌢️

dataOut: pyTTkSignal🌢️

This signal is emitted when some data is available in the pty interface

Parameters:

data (str) – the pty data

terminalClosed: pyTTkSignal🌢️

This signal is emitted when the pty session ends

Methods🌢️

attachTTkTerminal(term: TTkTerminal) None[source]🌢️

Attach a TTkTerminal to this helper.

Parameters:

term (TTkTerminal) – The terminal handled by this helper.

loop() None[source]🌢️

This is the main loop routine responsible of handling the pty and terminal events, for example, forwarding the input codes to the pty session and the pty output to the terminal emulator.

TTkTerminal
╔═══════╗                                                       pty
β•‘ C:\   β•‘ --[ KeyPresses, MouseEvents, ResizeSignal, ... ]--> β”Œβ”€β”€β”€β”€ ── ─  ─
β•‘       β•‘ <---------[ Output, Ansi escape codes, ... ]------- β”‚ bash, sh, ...
β•šβ•β•β•β•β•β•β•β•                                                     └──── ── ─  ─

Caution

Do not touch this! (unless you know what you are doing)

push(data: str) None[source]🌢️

Send the data to the pty session

Parameters:

data (str) – the data

resize(width: int, height: int) None[source]🌢️

Send a resize β€œTIOCSWINSZ” ioctl to the pty session

Parameters:
  • width (int) – the new width

  • height (int) – the new height

runShell(program: str = None) None[source]🌢️

Run a β€œprogram” attaching it the the pty session linked to this terminal.

Parameters:

program (str, optional) – The program required to run, defaults to the cmd defined bu the β€œSHELL” env variable or β€œsh” if missing