Browse Source

Added recording test 003

pull/272/head
Eugenio Parodi 1 year ago
parent
commit
d5a58a7f28
  1. 1
      .github/workflows/testing.yml
  2. 12
      Makefile
  3. 2
      TermTk/TTkCore/string.py
  4. 2
      demo/demo.py
  5. 67
      demo/showcase/table.py
  6. 13
      tests/pytest/test_001_demo.py

1
.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

12
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 ;

2
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:

2
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')

67
demo/showcase/table.py

@ -0,0 +1,67 @@
#!/usr/bin/env python3
# MIT License
#
# Copyright (c) 2024 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.
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()

13
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()
Loading…
Cancel
Save