Module TermTk.TTkTestWidgets.testwidget
Expand source code
#!/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.
from TermTk.TTkCore.log import TTkLog
from TermTk.TTkCore.color import TTkColor
from TermTk.TTkWidgets.widget import *
from TermTk.TTkWidgets.button import *
from TermTk.TTkWidgets.label import *
from TermTk.TTkWidgets.frame import *
class _TestContent(TTkWidget):
def paintEvent(self):
# TTkLog.debug(f"Test Paint - {self._name}")
y=0; self._canvas.drawText(pos=(0,y),color=TTkColor.fg("#ff0000"),text="Lorem ipsum dolor sit amet,")
y+=1; self._canvas.drawText(pos=(0,y),color=TTkColor.fg("#ff8800"),text="consectetur adipiscing elit,")
y+=1; self._canvas.drawText(pos=(0,y),color=TTkColor.fg("#ffff00"),text="sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
y+=1; self._canvas.drawText(pos=(0,y),color=TTkColor.fg("#00ff00"),text="Ut enim ad minim veniam,")
y+=1; self._canvas.drawText(pos=(0,y),color=TTkColor.fg("#00ffff"),text="quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.")
y+=1; self._canvas.drawText(pos=(0,y),color=TTkColor.fg("#0088ff"),text="Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.")
y+=1; self._canvas.drawText(pos=(0,y),color=TTkColor.fg("#0000ff"),text="Excepteur sint occaecat cupidatat non proident,")
y+=1; self._canvas.drawText(pos=(0,y),color=TTkColor.fg("#ff00ff"),text="sunt in culpa qui officia deserunt mollit anim id est laborum.")
y+=1; self._canvas.drawGrid(
pos=(0,y),size=(self._width,self._height-y),
hlines=(2,5,7), vlines=(4,7,15,30),
color=TTkColor.fg("#aaffaa"))
class TTkTestWidget(TTkFrame):
ID = 1
__slots__ = ('_name', '_l')
def __init__(self, *args, **kwargs):
TTkFrame.__init__(self, *args, **kwargs)
self._name = kwargs.get('name' , 'TTkTestWidget' )
#self.setLayout(TTkHBoxLayout())
self._name = f"TestWidget-{TTkTestWidget.ID}"
t,_,l,_ = self.getPadding()
TTkButton(parent=self, x=l, y=t, width=15, height=3, border=True, text=' Test Button')
self._l = [
TTkLabel(parent=self,pos=(l, t+3), size=(50,1), color=TTkColor.bg('#440099')+TTkColor.fg('#00ffff'), text="pippo"),
TTkLabel(parent=self,pos=(l, t+4), size=(50,1), color=TTkColor.bg('#440077')+TTkColor.fg('#00ccff')),
TTkLabel(parent=self,pos=(l, t+5), size=(50,1), color=TTkColor.bg('#440066')+TTkColor.fg('#0088ff')),
TTkLabel(parent=self,pos=(l, t+6), size=(50,1), color=TTkColor.bg('#440055')+TTkColor.fg('#0055ff')),
TTkLabel(parent=self,pos=(l, t+7), size=(50,1), color=TTkColor.bg('#440033')+TTkColor.fg('#0033ff')),
]
_TestContent(parent=self, x=l, y=t+8, width=50, height=50, name=f"content-{self._name}")
TTkTestWidget.ID+=1
def paintEvent(self):
TTkFrame.paintEvent(self)
self._l[0].text=f"Test Widget [{self._name}]"
self._l[1].text=f"x,y ({self._x},{self._y})"
self._l[2].text=f"w,h ({self._width},{self._height})"
self._l[3].text=f"max w,h ({self._maxw},{self._maxh})"
self._l[4].text=f"min w,h ({self._minw},{self._minh})"
def mousePressEvent(self, evt):
TTkLog.debug(f"{self._name} Test Mouse {evt}")
def mouseDragEvent(self, evt):
TTkLog.debug(f"{self._name} Test Mouse {evt}")
Classes
class TTkTestWidget (*args, **kwargs)-
Widget Layout sizes:
Terminal window ┌─────────────────────────────────────────┐ │ │ │ TTkWidget width │ │ (x,y)┌─────────────────────────┐ │ │ │ padt │ │ │ │ ┌───────────────┐ │ height │ │ │padl│ Layout/childs │padr│ │ │ │ └───────────────┘ │ │ │ │ padl │ │ │ └─────────────────────────┘ │ └─────────────────────────────────────────┘TTkWidget constructor
Args
name:str, optional- the name of the widget
parent:[TTkWidget], optional- the parent widget
x:int, optional, default=0- the x position
y:int, optional, default=0- the y position
pos:[int,int], optional, default=[0,0]- the [x,y] position (override the previously defined x, y)
width:int, optional, default=0- the width of the widget
height:int, optional, default=0- the height of the widget
size:[int,int], optional, default=[0,0]- the size [width, height] of the widget (override the previously defined sizes)
padding:int, optional, default=0- the padding (top, bottom, left, right) of the widget
paddingTop:int, optional, default=padding- the Top padding, override Top padding if already defined
paddingBottom:int, optional, default=padding- the Bottom padding, override Bottom padding if already defined
paddingLeft:int, optional, default=padding- the Left padding, override Left padding if already defined
paddingRight:int, optional, default=padding- the Right padding, override Right padding if already defined
maxWidth:int, optional, default=0x10000- the maxWidth of the widget
maxHeight:int, optional, default=0x10000- the maxHeight of the widget
maxSize:[int,int], optional- the max [width,height] of the widget
minWidth:int, optional, default=0- the minWidth of the widget
minHeight:int, optional, default=0- the minHeight of the widget
minSize:[int,int], optional- the minSize [width,height] of the widget
visible:bool, optional, default=True- the visibility
layout:[TermTk.TTkLayouts], optional, default=[TTkLayout]- the layout of this widget
Expand source code
class TTkTestWidget(TTkFrame): ID = 1 __slots__ = ('_name', '_l') def __init__(self, *args, **kwargs): TTkFrame.__init__(self, *args, **kwargs) self._name = kwargs.get('name' , 'TTkTestWidget' ) #self.setLayout(TTkHBoxLayout()) self._name = f"TestWidget-{TTkTestWidget.ID}" t,_,l,_ = self.getPadding() TTkButton(parent=self, x=l, y=t, width=15, height=3, border=True, text=' Test Button') self._l = [ TTkLabel(parent=self,pos=(l, t+3), size=(50,1), color=TTkColor.bg('#440099')+TTkColor.fg('#00ffff'), text="pippo"), TTkLabel(parent=self,pos=(l, t+4), size=(50,1), color=TTkColor.bg('#440077')+TTkColor.fg('#00ccff')), TTkLabel(parent=self,pos=(l, t+5), size=(50,1), color=TTkColor.bg('#440066')+TTkColor.fg('#0088ff')), TTkLabel(parent=self,pos=(l, t+6), size=(50,1), color=TTkColor.bg('#440055')+TTkColor.fg('#0055ff')), TTkLabel(parent=self,pos=(l, t+7), size=(50,1), color=TTkColor.bg('#440033')+TTkColor.fg('#0033ff')), ] _TestContent(parent=self, x=l, y=t+8, width=50, height=50, name=f"content-{self._name}") TTkTestWidget.ID+=1 def paintEvent(self): TTkFrame.paintEvent(self) self._l[0].text=f"Test Widget [{self._name}]" self._l[1].text=f"x,y ({self._x},{self._y})" self._l[2].text=f"w,h ({self._width},{self._height})" self._l[3].text=f"max w,h ({self._maxw},{self._maxh})" self._l[4].text=f"min w,h ({self._minw},{self._minh})" def mousePressEvent(self, evt): TTkLog.debug(f"{self._name} Test Mouse {evt}") def mouseDragEvent(self, evt): TTkLog.debug(f"{self._name} Test Mouse {evt}")Ancestors
Class variables
var ID
Inherited members
TTkFrame:addWidgetenterEventgetPaddingkeyEventkeyPressEventkeyReleaseEventleaveEventmouseDoubleClickEventmouseDragEventmouseEventmouseMoveEventmousePressEventmouseReleaseEventmovemoveEventpaintChildCanvaspaintEventpaintNotifyParentremoveWidgetresizeresizeEventsetGeometrysetPaddingwheelEvent