6 changed files with 300 additions and 13 deletions
@ -0,0 +1,129 @@
|
||||
# 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 time, math |
||||
|
||||
from TermTk.TTkCore.signal import pyTTkSignal, pyTTkSlot |
||||
from TermTk.TTkCore.helper import TTkHelper |
||||
|
||||
class TTkEasingCurve(): |
||||
Linear = 0 |
||||
InQuad = 1 |
||||
OutQuad = 2 |
||||
InOutQuad = 3 |
||||
OutInQuad = 4 |
||||
InCubic = 5 |
||||
OutCubic = 6 |
||||
InOutCubic = 7 |
||||
OutInCubic = 8 |
||||
InQuart = 9 |
||||
OutQuart = 10 |
||||
InOutQuart = 11 |
||||
OutInQuart = 12 |
||||
InQuint = 13 |
||||
OutQuint = 14 |
||||
InOutQuint = 15 |
||||
OutInQuint = 16 |
||||
InSine = 17 |
||||
OutSine = 18 |
||||
InOutSine = 19 |
||||
OutInSine = 20 |
||||
InExpo = 21 |
||||
OutExpo = 22 |
||||
InOutExpo = 23 |
||||
OutInExpo = 24 |
||||
InCirc = 25 |
||||
OutCirc = 26 |
||||
InOutCirc = 27 |
||||
OutInCirc = 28 |
||||
InElastic = 29 |
||||
OutElastic = 30 |
||||
InOutElastic = 31 |
||||
OutInElastic = 32 |
||||
InBack = 33 |
||||
OutBack = 34 |
||||
InOutBack = 35 |
||||
OutInBack = 36 |
||||
InBounce = 37 |
||||
OutBounce = 38 |
||||
InOutBounce = 39 |
||||
OutInBounce = 40 |
||||
# BezierSpline = 45 |
||||
# TCBSpline = 46 |
||||
# Custom = 47 |
||||
|
||||
class TTkPropertyAnimation(): |
||||
__slots__ = ('_target', '_propertyName', '_parent', |
||||
'_duration', '_startValue', '_endValue', |
||||
'_easingCurve', '_baseTime') |
||||
def __init__(self, target, propertyName, parent=None): |
||||
self._target = target |
||||
self._propertyName = propertyName |
||||
self._parent = parent |
||||
self._duration = 0 |
||||
self._baseTime = 0 |
||||
self._startValue = None |
||||
self._endValue = None |
||||
|
||||
def setDuration(self, duration): |
||||
self._duration = duration |
||||
|
||||
def setStartValue(self, startValue): |
||||
self._startValue = startValue |
||||
|
||||
def setEndValue(self, endValue): |
||||
self._endValue = endValue |
||||
|
||||
def setEasingCurve(self, easingCurve): |
||||
self._easingCurve = easingCurve |
||||
|
||||
@pyTTkSlot() |
||||
def _refreshAnimation(self): |
||||
diff = time.time() - self._baseTime |
||||
if diff >= self._duration: |
||||
TTkHelper._rootWidget.paintExecuted.disconnect(self._refreshAnimation) |
||||
if type(self._endValue) in (list,tuple): |
||||
getattr(self._target,self._propertyName)(*self._endValue) |
||||
else: |
||||
getattr(self._target,self._propertyName)(self._endValue) |
||||
else: |
||||
def _processLinear(_s,_e,_v): |
||||
return int(_e*_v+_s*(1-_v)) |
||||
def _processQuad(_s,_e,_v): |
||||
return _processLinear(_s,_e,_v*_v) |
||||
def _processInQuad(_s,_e,_v): |
||||
return _processLinear(_s,_e,math.sqrt(math.sqrt(_v))) |
||||
_process = _processInQuad |
||||
v = diff/self._duration |
||||
if type(self._startValue) in (list,tuple): |
||||
newVal = [_process(s,e,v) for (s,e) in zip(self._startValue,self._endValue)] |
||||
getattr(self._target,self._propertyName)(*newVal) |
||||
else: |
||||
newVal = _process(self._startValue,self._endValue,v) |
||||
getattr(self._target,self._propertyName)(newVal) |
||||
|
||||
@pyTTkSlot() |
||||
def start(self): |
||||
self._baseTime = time.time() |
||||
if TTkHelper._rootWidget: |
||||
TTkHelper._rootWidget.paintExecuted.connect(self._refreshAnimation) |
||||
self._refreshAnimation() |
||||
@ -0,0 +1,141 @@
|
||||
#!/usr/bin/env python3 |
||||
|
||||
# MIT License |
||||
# |
||||
# Copyright (c) 2021 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 random |
||||
import 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 getUtfColoredSentence |
||||
|
||||
class superSimpleHorizontalLine(ttk.TTkWidget): |
||||
def paintEvent(self): |
||||
w,h = self.size() |
||||
self._canvas.drawText(pos=(0,h-1), text='┕'+('━'*(w-2))+'┙',color=ttk.TTkColor.fg("#888888")) |
||||
|
||||
|
||||
def demoTextEditRO(root=None): |
||||
frame = ttk.TTkFrame(parent=root, border=False) |
||||
|
||||
winTe = ttk.TTkWindow(parent=frame, title="Text Edit", pos=(20,3), size=(50,30), layout=ttk.TTkGridLayout()) |
||||
te = ttk.TTkTextEdit(parent=winTe, lineNumber=True) |
||||
|
||||
winAc = ttk.TTkWindow(parent=frame, title="Animation Controls", pos=(0,0), size=(50,30)) |
||||
animBtn = ttk.TTkButton(parent=winAc, text="Animate",border=True,pos=(0,0)) |
||||
|
||||
anim = ttk.TTkPropertyAnimation(te.viewport(),'viewMoveTo') |
||||
anim.setDuration(1) |
||||
anim.setStartValue((0, 0)) |
||||
anim.setEndValue(( 50, 120)) |
||||
# anim.setEasingCurve(QEasingCurve.OutBounce) |
||||
|
||||
animBtn.clicked.connect(anim.start) |
||||
|
||||
# Initialize the textedit with come text |
||||
|
||||
te.setText(ttk.TTkString("Text Edit DEMO\n",ttk.TTkColor.UNDERLINE+ttk.TTkColor.BOLD+ttk.TTkColor.ITALIC)) |
||||
|
||||
# Load ANSI input |
||||
te.append(ttk.TTkString("ANSI Input Test\n",ttk.TTkColor.UNDERLINE+ttk.TTkColor.BOLD)) |
||||
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)),'textedit.ANSI.txt')) as f: |
||||
te.append(f.read()) |
||||
|
||||
# Test Variable sized chars |
||||
te.append(ttk.TTkString("Test Variable sized chars\n",ttk.TTkColor.UNDERLINE+ttk.TTkColor.BOLD)) |
||||
te.append( "Emoticons: -😁😂😍😎----") |
||||
te.append( " --😐😁😂😍😎-") |
||||
te.append("") |
||||
|
||||
te.append( " UTF-8: £ @ £ ¬ ` 漢 _ _ あ _ _") |
||||
te.append( " |.|.|.|.|.||.|.|.||.|.|.") |
||||
te.append("") |
||||
|
||||
|
||||
zc1 = chr(0x07a6) |
||||
zc2 = chr(0x20D7) |
||||
zc3 = chr(0x065f) |
||||
te.append( " - | | | | | -") |
||||
te.append(f"Zero Size: - o{zc1} o{zc2} o{zc3} o{zc1}{zc2} o{zc1}{zc2}{zc3} -") |
||||
te.append( " - | | | | | -") |
||||
te.append("") |
||||
|
||||
te.append(f"Plus Tabs: -\t😁\t😍\to{zc1}{zc2}{zc3}\t😎\to{zc1}{zc2}{zc3}\t😂-") |
||||
te.append("") |
||||
|
||||
# Test Tabs |
||||
te.append(ttk.TTkString("Tabs Test\n",ttk.TTkColor.UNDERLINE+ttk.TTkColor.BOLD)) |
||||
te.append("Word\tAnother Word\tYet more words") |
||||
te.append("What a wonderful word\tOut of this word\tBattle of the words\tThe city of thousand words\tThe word is not enough\tJurassic word\n") |
||||
te.append("tab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab") |
||||
te.append("-tab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab") |
||||
te.append("--tab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab") |
||||
te.append("---tab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab") |
||||
te.append("----tab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab") |
||||
te.append("-----tab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab") |
||||
te.append("------tab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab") |
||||
te.append("-------tab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\ttab\n") |
||||
|
||||
te.append(ttk.TTkString("Random TTkString Input Test\n",ttk.TTkColor.UNDERLINE+ttk.TTkColor.BOLD)) |
||||
te.append(ttk.TTkString('\n').join([ getUtfColoredSentence(3,10) for _ in range(100)])) |
||||
|
||||
te.append(ttk.TTkString("-- The Very END --",ttk.TTkColor.UNDERLINE+ttk.TTkColor.BOLD)) |
||||
|
||||
# use the widget size to wrap |
||||
# te.setLineWrapMode(ttk.TTkK.WidgetWidth) |
||||
# te.setWordWrapMode(ttk.TTkK.WordWrap) |
||||
|
||||
# Use a fixed wrap size |
||||
# te.setLineWrapMode(ttk.TTkK.FixedWidth) |
||||
# te.setWrapWidth(100) |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return frame |
||||
|
||||
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') |
||||
args = parser.parse_args() |
||||
windowed = args.w |
||||
|
||||
ttk.TTkLog.use_default_file_logging() |
||||
|
||||
root = ttk.TTk() |
||||
if windowed: |
||||
rootTree = ttk.TTkWindow(parent=root,pos = (0,0), size=(70,40), title="Test Text Edit", layout=ttk.TTkGridLayout(), border=True) |
||||
else: |
||||
rootTree = root |
||||
root.setLayout(ttk.TTkGridLayout()) |
||||
demoTextEditRO(rootTree) |
||||
root.mainloop() |
||||
|
||||
if __name__ == "__main__": |
||||
main() |
||||
Loading…
Reference in new issue