From d5a58a7f28ebece56a7286036626aa83cbd9168b Mon Sep 17 00:00:00 2001 From: Eugenio Parodi Date: Tue, 15 Oct 2024 22:56:56 +0100 Subject: [PATCH] Added recording test 003 --- .github/workflows/testing.yml | 1 + Makefile | 12 ++++--- TermTk/TTkCore/string.py | 2 +- demo/demo.py | 2 ++ demo/showcase/table.py | 67 +++++++++++++++++++++++++++++++++++ tests/pytest/test_001_demo.py | 13 ++++++- 6 files changed, 91 insertions(+), 6 deletions(-) create mode 100755 demo/showcase/table.py diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index c2f53156..d47f6f48 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -54,6 +54,7 @@ jobs: mkdir -p tmp wget -O tmp/test.input.001.bin https://github.com/ceccopierangiolieugenio/binaryRepo/raw/master/pyTermTk/tests/test.input.001.bin wget -O tmp/test.input.002.bin https://github.com/ceccopierangiolieugenio/binaryRepo/raw/master/pyTermTk/tests/test.input.002.bin + wget -O tmp/test.input.003.bin https://github.com/ceccopierangiolieugenio/binaryRepo/raw/master/pyTermTk/tests/test.input.003.bin pytest ${DDDD}/tests/pytest/test_003_string.py pytest ${DDDD}/tests/pytest/test_002_textedit.py pytest ${DDDD}/tests/pytest/test_001_demo.py diff --git a/Makefile b/Makefile index 3ce53e19..c0547f19 100644 --- a/Makefile +++ b/Makefile @@ -134,10 +134,14 @@ test: .venv mkdir -p tmp wget -O tmp/test.input.001.bin https://github.com/ceccopierangiolieugenio/binaryRepo/raw/master/pyTermTk/tests/test.input.001.bin wget -O tmp/test.input.002.bin https://github.com/ceccopierangiolieugenio/binaryRepo/raw/master/pyTermTk/tests/test.input.002.bin + wget -O tmp/test.input.003.bin https://github.com/ceccopierangiolieugenio/binaryRepo/raw/master/pyTermTk/tests/test.input.003.bin tools/check.import.sh . .venv/bin/activate ; \ - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude .venv,build,tmp ; \ - pytest tests/pytest/test_003_string.py ; \ - pytest tests/pytest/test_002_textedit.py ; \ - pytest -v tests/pytest/test_001_demo.py ; + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude .venv,build,tmp,experiments ; + . .venv/bin/activate ; \ + pytest tests/pytest/test_003_string.py ; + . .venv/bin/activate ; \ + pytest tests/pytest/test_002_textedit.py ; + . .venv/bin/activate ; \ + pytest -v tests/pytest/test_001_demo.py ; diff --git a/TermTk/TTkCore/string.py b/TermTk/TTkCore/string.py index 60be45f7..06a81d5a 100644 --- a/TermTk/TTkCore/string.py +++ b/TermTk/TTkCore/string.py @@ -506,7 +506,7 @@ class TTkString(): ret._colors += self._colors start=0 lenMatch = len(match) - while pos := self._text.index(match, start) if match in self._text[start:] else None: + while None != (pos := self._text.index(match, start) if match in self._text[start:] else None): start = pos+lenMatch ret._colors[pos: pos+lenMatch] = [color]*lenMatch elif posFrom == posTo == None: diff --git a/demo/demo.py b/demo/demo.py index 9f7f859c..ab5254f7 100755 --- a/demo/demo.py +++ b/demo/demo.py @@ -46,6 +46,7 @@ from showcase.menubar import demoMenuBar from showcase.filepicker import demoFilePicker from showcase.colorpicker import demoColorPicker from showcase.tree import demoTree +from showcase.table import demoTTkTable from showcase.fancytable import demoFancyTable from showcase.fancytree import demoFancyTree from showcase.textedit import demoTextEdit @@ -172,6 +173,7 @@ def demoShowcase(root=None, border=True): tabWidgets.addTab(demoTextEdit(), " Text Edit ", 'showcase/textedit.py') tabWidgets.addTab(demoList(), " List Test ", 'showcase/list.py') tabWidgets.addTab(demoTree(), " Tree Test", 'showcase/tree.py') + tabWidgets.addTab(demoTTkTable(), " Table Test", 'showcase/table.py') tabWidgets.addTab(demoTab(), " Tab Test ", 'showcase/tab.py') tabWidgets.addTab(demoFancyTable(), " Old Table ", 'showcase/fancytable.py') tabWidgets.addTab(demoFancyTree(), " Old Tree ", 'showcase/fancytree.py') diff --git a/demo/showcase/table.py b/demo/showcase/table.py new file mode 100755 index 00000000..0c2da8a5 --- /dev/null +++ b/demo/showcase/table.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 + +# MIT License +# +# Copyright (c) 2024 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. + +import sys, os, argparse + +sys.path.append(os.path.join(sys.path[0],'../..')) +import TermTk as ttk + +sys.path.append(os.path.join(sys.path[0],'..')) +from showcase._showcasehelper import getUtfWord + +def demoTTkTable(root= None): + # Basic Table Demo + + # Setup a model using a 2d list of random values + dataList = [[f"0x{i:04X}"] + [int(i*100),float(i*100),ttk.TTkString(getUtfWord(),ttk.TTkColor.YELLOW)] + [getUtfWord() for _ in range(10)] for i in range(101)] + tableModel = ttk.TTkTableModelList(data=dataList) + + # Init the table with the model defilned + retTable = ttk.TTkTable(parent=root, tableModel=tableModel) + retTable.resizeRowsToContents() + retTable.resizeColumnsToContents() + + return retTable + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('-f', help='Full Screen (default)', action='store_true') + parser.add_argument('-w', help='Windowed', action='store_true') + parser.add_argument('-t', help='Track Mouse', action='store_true') + args = parser.parse_args() + windowed = args.w + mouseTrack = args.t + + root = ttk.TTk(title="pyTermTk List Demo", mouseTrack=mouseTrack) + if windowed: + rootTab = ttk.TTkWindow(parent=root,pos=(1,1), size=(100,40), title="Test Tab", border=True, layout=ttk.TTkGridLayout()) + else: + rootTab = root + root.setLayout(ttk.TTkGridLayout()) + demoTTkTable(rootTab) + root.mainloop() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/tests/pytest/test_001_demo.py b/tests/pytest/test_001_demo.py index 70573aa5..c9c065a7 100755 --- a/tests/pytest/test_001_demo.py +++ b/tests/pytest/test_001_demo.py @@ -128,12 +128,14 @@ if __name__ == "__main__": parser.add_argument('-p', '--play', help='Play input from File', type=argparse.FileType('br')) parser.add_argument('-f', help='Full Screen (default)', action='store_true') parser.add_argument('-w', help='Windowed', action='store_true') + parser.add_argument('-t', help='Track Mouse', action='store_true') args = parser.parse_args() + mouseTrack = args.t print(args) if args.record: - root = TTkRecord(title="pyTermTk Demo Record", record=True) + root = TTkRecord(title="pyTermTk Demo Record", record=True, mouseTrack=mouseTrack) winTabbed1 = demo.ttk.TTkWindow(parent=root,pos=(0,0), size=(80,24), title="pyTermTk Showcase", border=True, layout=demo.ttk.TTkGridLayout()) demo.demoShowcase(winTabbed1, True) root.mainloop() @@ -178,4 +180,13 @@ def test_recording2(): root.loadQueue(open('tmp/test.input.002.bin', 'rb')) winTabbed1 = demo.ttk.TTkWindow(parent=root,pos=(0,0), size=(80,24), title="pyTermTk Showcase", border=True, layout=demo.ttk.TTkGridLayout()) demo.demoShowcase(winTabbed1, True) + root.mainloop() + +def test_recording3(): + # demo.ttk.TTkLog.use_default_file_logging() + demo.ttk.TTkLog.installMessageHandler(message_handler) + root = TTkRecord(title="pyTermTk Demo Record", record=False) + root.loadQueue(open('tmp/test.input.003.bin', 'rb')) + winTabbed1 = demo.ttk.TTkWindow(parent=root,pos=(0,0), size=(80,24), title="pyTermTk Showcase", border=True, layout=demo.ttk.TTkGridLayout()) + demo.demoShowcase(winTabbed1, True) root.mainloop() \ No newline at end of file