TTkString๐ถ๏ธ
- class TTkString(text: str = '', color: TTkColor = None)[source]๐ถ๏ธ
Bases:
object
TermTk String Helper
The TTkString constructor creates a terminal String object.
- Parameters:
text (str, optional) โ text of the string, defaults to โโ
color (
TTkColor
, optional) โ the color of the string, defaults toTTkColor.RST
Example:
# No params Constructor str1 = TTkString() + "test 1" str2 = TTkString() + TTkColor.BOLD + "test 2" # Indexed params constructor str3 = TTkString("test 3") str4 = TTkString("test 4", TTkColor.ITALIC) # Named params constructor str5 = TTkString(text="test 5") str6 = TTkString(text="test 6", color=TTkColor.ITALIC+TTkColor.bg("000044")) # Combination of constructors (Highly Unrecommended) str7 = TTkString("test 7", color=TTkColor.fg('#FF0000'))
Methods๐ถ๏ธ
- align(width=None, color=<TermTk.TTkCore.color._TTkColor object>, alignment=0) Self [source]๐ถ๏ธ
Align the string
- Parameters:
width (int, optional) โ the new width
color (
TTkColor
, optional) โ the color of the padding, defaults toTTkColor.RST
alignment (
TTkConstant.Alignment
, optional) โ the alignment of the text to the full widthNONE
- completeColor(color, match=None, posFrom=None, posTo=None) Self [source]๐ถ๏ธ
Complete the color of the entire string or a slice of it
The Fg and/or Bg of the string is replaced with the selected Fg/Bg color only if missing
If only the color is specified, the entire string is colorized
- Parameters:
color (
TTkColor
) โ the color to be used, defaults toTTkColor.RST
match (str, optional) โ the match to colorize
posFrom (int, optional) โ the initial position of the color
posTo (int, optional) โ the final position of the color
- findall(regexp, ignoreCase=False)[source]๐ถ๏ธ
FindAll the regexp matches in the string
- Parameters:
regexp (str) โ the regular expression to be matched
ignoreCase (bool) โ Ignore case, defaults to False
- isPlainText() bool [source]๐ถ๏ธ
Return True if the string does not include colors or modifications
- join(strings: list[Self]) Self [source]๐ถ๏ธ
Join the input strings using the current as separator
- Parameters:
strings (list) โ the list of strings to be joined
- replace(*args, **kwargs) Self [source]๐ถ๏ธ
replace (old, new, count)
Replace โoldโ match with โnewโ string for โcountโ times
- Parameters:
old (str) โ the match to be placed
new (str, optional) โ the match to replace
count (int, optional) โ the number of occurrences
- search(regexp, ignoreCase=False)[source]๐ถ๏ธ
Return the re.match of the regexp
- Parameters:
regexp (str) โ the regular expression to be matched
ignoreCase (bool) โ Ignore case, defaults to False
- setColor(color, match=None, posFrom=None, posTo=None) Self [source]๐ถ๏ธ
Set the color of the entire string or a slice of it
If only the color is specified, the entire string is colorized
- Parameters:
color (
TTkColor
) โ the color to be used, defaults toTTkColor.RST
match (str, optional) โ the match to colorize
posFrom (int, optional) โ the initial position of the color
posTo (int, optional) โ the final position of the color
- split(separator) list[Self] [source]๐ถ๏ธ
Split the string using a separator
Note
Only a one char separator is currently supported
- Parameters:
separator (str) โ the โcharโ separator to be used
- substring(fr=None, to=None) Self [source]๐ถ๏ธ
Return the substring
- Parameters:
fr (int, optional) โ the starting of the slice, defaults to 0
to (int, optional) โ the ending of the slice, defaults to the end of the string
- tab2spaces(tabSpaces=4) Self [source]๐ถ๏ธ
Return the string representation with the tabs (converted in spaces) trimmed and aligned
- tabCharPos(pos, tabSpaces=4, alignTabRight=False) int [source]๐ถ๏ธ
Return the char position in the string from the position in its representation with the tab and variable char sizes are solved
i.e.
pos X = 11 tab2Spaces |----------|---------------------| Tabs |-| | |-| |-| | _text L๐rem ipsum dolor sit amet, chars .. ...t .....t .....t ...t..... ret x = 7 (tab is a char)
TTkString Attributes๐ถ๏ธ
|