From b5698dee630342fed5a55016d592b7227642c090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eugenio=20Parodi=20=F0=9F=8C=B6=EF=B8=8F?= Date: Thu, 23 Jan 2025 11:48:04 +0000 Subject: [PATCH] Added async test --- tests/t.ui/test.ui.034.async.01.py | 63 +++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 9 deletions(-) diff --git a/tests/t.ui/test.ui.034.async.01.py b/tests/t.ui/test.ui.034.async.01.py index d326ae88..8f0633ea 100755 --- a/tests/t.ui/test.ui.034.async.01.py +++ b/tests/t.ui/test.ui.034.async.01.py @@ -1,41 +1,81 @@ +#!/usr/bin/env python3 + +# MIT License +# +# Copyright (c) 2025 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 asyncio import inspect import sys, os import time -sys.path.append(os.path.join(sys.path[0],'..')) +sys.path.append(os.path.join(sys.path[0],'../..')) import TermTk as ttk -root = ttk.TTk(layout=ttk.TTkVBoxLayout()) -res = ttk.TTkLabel(parent=root) -num = ttk.TTkLabel(parent=root, text=1) -button_add = ttk.TTkButton(parent=root, text="+") +root = ttk.TTk(layout=(rgl:=ttk.TTkGridLayout())) + +rgl.addWidget(button_add := ttk.TTkButton(maxSize=(8,3), border=True, text="+") , 0, 0) +rgl.addWidget(button_call := ttk.TTkButton(maxSize=(8,3), border=True, text="Call") , 1, 0) +rgl.addWidget(button_call2 := ttk.TTkButton(maxSize=(8,3), border=True, text="Call2", checkable=True) , 2, 0) button_add.clicked.connect(lambda: num.setText(int(num.text()) + 1)) -button_call = ttk.TTkButton(parent=root, text="Call") -ttk.TTkButton(parent=root, text="Quit").clicked.connect(ttk.TTkHelper.quit) + +rgl.addWidget(res := ttk.TTkLabel(test='out...'), 0 , 1) +rgl.addWidget(num := ttk.TTkLabel(text='1') , 1 , 1) + +rgl.addWidget(qb := ttk.TTkButton(border=True, maxWidth=8, text="Quit"), 0,2,3,1) +qb.clicked.connect(ttk.TTkHelper.quit) + +rgl.addWidget(ttk.TTkLogViewer(), 3, 0, 1, 3) + @ttk.pyTTkSlot() def call0(): res.setText("0 Calling...") + ttk.TTkLog.info("0 Calling...") time.sleep(1) res.setText("0 Calling... - DONE") + ttk.TTkLog.info("0 Calling... - DONE") async def call1(): res.setText("1 Calling...") + ttk.TTkLog.info("1 Calling...") await asyncio.sleep(3) res.setText("1 Calling... - DONE") + ttk.TTkLog.info("1 Calling... - DONE") @ttk.pyTTkSlot() async def call2(): res.setText("2 Calling...") - await asyncio.sleep(5) + ttk.TTkLog.info("2 Calling...") + await asyncio.sleep(4) res.setText("2 Calling... - DONE") + ttk.TTkLog.info("2 Calling... - DONE") -@ttk.pyTTkSlot(int) +@ttk.pyTTkSlot(bool) async def call3(val): res.setText(f"3 Calling... {val}") + ttk.TTkLog.info(f"3 Calling... {val}") await asyncio.sleep(5) res.setText(f"3 Calling... {val} - DONE") + ttk.TTkLog.info(f"3 Calling... {val} - DONE") print(inspect.iscoroutinefunction(call0)) print(inspect.iscoroutinefunction(call1)) @@ -46,4 +86,9 @@ button_call.clicked.connect(call0) button_call.clicked.connect(call1) button_call.clicked.connect(call2) +# button_call2.toggled.connect(call0) +button_call2.toggled.connect(call1) +button_call2.toggled.connect(call2) +button_call2.toggled.connect(call3) + root.mainloop() \ No newline at end of file