Browse Source

Merge 3fcb4f4e73 into 0945cf0c43

pull/491/merge
Pier CeccoPierangioliEugenio 6 months ago committed by GitHub
parent
commit
d8ad0f6102
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      libs/pyTermTk/TermTk/TTkCore/timer_pyodide.py
  2. 4
      libs/pyTermTk/TermTk/TTkCore/timer_unix.py
  3. 19
      libs/pyTermTk/TermTk/TTkCore/ttk.py
  4. 61
      tests/t.ui/test.ui.029.image.viewer.02.py
  5. 43
      tests/t.ui/test.ui.035.thread.01.py

2
libs/pyTermTk/TermTk/TTkCore/timer_pyodide.py

@ -37,7 +37,7 @@ class TTkTimer():
'_delay', '_delayLock', '_quit',
'_stopTime')
def __init__(self):
def __init__(self, name:str=''):
# Define Signals
self.timeout = pyTTkSignal()
self._running = True

4
libs/pyTermTk/TermTk/TTkCore/timer_unix.py

@ -31,13 +31,15 @@ class TTkTimer(threading.Thread):
__slots__ = (
'timeout', '_delay',
'_timer', '_quit', '_start')
def __init__(self):
def __init__(self, name:str=''):
self.timeout = pyTTkSignal()
self._delay = 0
self._quit = threading.Event()
self._start = threading.Event()
self._timer = threading.Event()
super().__init__()
if name:
self.name = name
TTkHelper.quitEvent.connect(self.quit)
def quit(self):

19
libs/pyTermTk/TermTk/TTkCore/ttk.py

@ -140,10 +140,10 @@ class TTk(TTkContainer):
self.time = curtime
def mainloop(self):
with ttk_capture_stderr():
self._mainloop_1()
self.ttk_init()
self.ttk_run()
def _mainloop_1(self):
def ttk_init(self):
try:
'''Enters the main event loop and waits until :meth:`~quit` is called or the main widget is destroyed.'''
TTkLog.debug( "" )
@ -166,8 +166,19 @@ class TTk(TTkContainer):
TTkLog.debug("Signal Event Registered")
TTkTerm.registerResizeCb(self._win_resize_cb)
except:
if platform.system() != 'Emscripten':
TTkSignalDriver.exit()
self.quit()
TTkTerm.exit()
def ttk_run(self) -> None:
with ttk_capture_stderr():
self.ttk_run_main()
self._timer = TTkTimer()
def ttk_run_main(self):
try:
self._timer = TTkTimer(name='TTk_Screen')
self._timer.timeout.connect(self._time_event)
self._timer.start(0.1)
self.show()

61
tests/t.ui/test.ui.029.image.viewer.02.py

@ -0,0 +1,61 @@
#!/usr/bin/env python3
# MIT License
#
# Copyright (c) 2023 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 os
import sys
import argparse
from PIL import Image
sys.path.append(os.path.join(sys.path[0],'../..'))
import TermTk as ttk
ttk.TTkTheme.loadTheme(ttk.TTkTheme.NERD)
def load_imageFile_to_TTkImage(file_name:str,ttkImage:ttk.TTkImage) -> None:
pilImage = Image.open(file_name)
pilImage = pilImage.convert('RGBA')
data = list(pilImage.getdata())
rgbList = [(r*a//255,g*a//255,b*a//255) for r,g,b,a in data]
width, height = pilImage.size
imageList = [rgbList[i:i+width] for i in range(0, len(rgbList), width)]
ttkImage.setData(imageList)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('filename', type=str,
help='the image to display')
args = parser.parse_args()
root = ttk.TTk()
window = ttk.TTkWindow(parent=root, size=(30,10), layout=ttk.TTkGridLayout())
image = ttk.TTkImage(parent=window)
load_imageFile_to_TTkImage(file_name=args.filename, ttkImage=image)
root.mainloop()
if __name__ == '__main__':
main()

43
tests/t.ui/test.ui.035.thread.01.py

@ -0,0 +1,43 @@
#!/usr/bin/env python3
# MIT License
#
# Copyright (c) 2025 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
from threading import Thread
from datetime import datetime
sys.path.append(os.path.join(sys.path[0],'../..'))
import TermTk as ttk
root = ttk.TTk()
win = ttk.TTkWindow(parent=root, size=(50,20), layout=ttk.TTkGridLayout())
ttk.TTkLogViewer(parent=win)
root.ttk_init()
def ttk_thread():
root.ttk_run()
app = Thread(target=ttk_thread)
app.start()
app.join()
Loading…
Cancel
Save