TTkWidgetπΆοΈ
- class TTkWidget(parent: Self = None, x: int = 0, y: int = 0, width: int = 0, height: int = 0, pos: tuple = None, size: tuple = None, maxSize: tuple = None, maxWidth: int = 65536, maxHeight: int = 65536, minSize: tuple = None, minWidth: int = 0, minHeight: int = 0, name: str = None, visible: bool = True, enabled: bool = True, toolTip: TTkString = '', style: dict = None, addStyle: dict = None, **kwargs)[source]πΆοΈ
Bases:
TMouseEvents
,TKeyEvents
,TDragEvents
Widget sizes:
Terminal area (i.e. XTerm) = TTk βββββββββββββββββββββββββββββββββββββββββββ β β β TTkWidget width β β (x,y)βββββββββββββββββββββββββββ β β β β β β β β height β β β β β β β β β β β β β β βββββββββββββββββββββββββββ β βββββββββββββββββββββββββββββββββββββββββββ
The TTkWidget class is the base class of all user interface objects
- Parameters:
name (str, optional) β the name of the widget, defaults to ββ
parent (
TTkWidget
, optional) β the parent widget, defaults to Nonex (int, optional) β the x position, defaults to 0
y (int, optional) β the y position, defaults to 0
pos ((int,int), optional) β the [x,y] position (override the previously defined x, y), defaults to (x,y)
width (int, optional) β the width of the widget, defaults to 0
height (int, optional) β the height of the widget, defaults to 0
size ((int,int), optional) β the size [width, height] of the widget (override the previously defined sizes), defaults to (width,height)
maxWidth (int, optional) β the maxWidth of the widget, defaults to 0x10000
maxHeight (int, optional) β the maxHeight of the widget, defaults to 0x10000
maxSize ((int,int), optional) β the max [width,height] of the widget, optional, defaults to (maxWidth,maxHeight)
minWidth (int, optional) β the minWidth of the widget, defaults to 0
minHeight (int, optional) β the minHeight of the widget, defaults to 0
minSize ((int,int), optional) β the minSize [width,height] of the widget, optional, defaults to (minWidth,minHeight)
toolTip (
TTkString
, optional) β This property holds the widgetβs tooltip, defaults to ββstyle (dict, optional) β this field hold the custom style to be used by this widget
addStyle (dict, optional) β this field is required to override/merge the new style on top of the current one, useful if only few params need to be changed
visible (bool, optional) β the visibility, optional, defaults to True
enabled (bool, optional) β the ability to handle input events, optional, defaults to True
StyleπΆοΈ
classStyle = { 'default': {'color': TTkColor.RST, 'borderColor': TTkColor.RST}, 'disabled': {'color': TTkColor.fg('#888888'), 'borderColor': TTkColor.fg('#888888')}, # 'hover': {'color': TTkColor.fg('#00FF00')+TTkColor.bg('#0077FF')}, # 'checked': {'color': TTkColor.fg('#00FF00')+TTkColor.bg('#00FFFF')}, # 'clicked': {'color': TTkColor.fg('#FFFF00')}, # 'focus': {'color': TTkColor.fg('#FFFF88')}, }
SignalsπΆοΈ
This signal is emitted whenever the widget is closed
This signal is emitted whenever the widget stye change
This signal is emitted whenever the focus status change i.e. with the
setFocus()
orclearFocus()
methods.This signal is emitted whenever the widget size change
SlotsπΆοΈ
close
()Close (Destroy/Remove) the widget
hide
()hide the widget
Lower the Widget below its relatives
raiseWidget
([raiseParent])Raise the Widget above its relatives
setDisabled
([disabled])This property holds whether the widget is disnabled
setEnabled
([enabled])This property holds whether the widget is enabled
setFocus
()Focus the widget
setVisible
(visible)Set the visibility status of this widget
show
()show the widget
update
([repaint,Β updateLayout,Β updateParent])Notify the drawing routine that the widget changed and needs to draw its new content.
MembersπΆοΈ
- closed: pyTTkSignalπΆοΈ
This signal is emitted whenever the widget is closed
- Parameters:
widget (TTkWidget) β the widget closed (=self)
- currentStyleChanged: pyTTkSignalπΆοΈ
This signal is emitted whenever the widget stye change
- Parameters:
style (dict) β the new style applied
- focusChanged: pyTTkSignalπΆοΈ
This signal is emitted whenever the focus status change i.e. with the
setFocus()
orclearFocus()
methods- Parameters:
status (bool) β the curent focus status
- sizeChanged: pyTTkSignalπΆοΈ
This signal is emitted whenever the widget size change
- Parameters:
width (int) β the new widget width
height (int) β the new widget height
MethodsπΆοΈ
- focusPolicy() FocusPolicy [source]πΆοΈ
- getPixmap() TTkCanvas [source]πΆοΈ
Convenience function which return a pixmap representing the current widget status
- Returns:
- isEnabled() bool [source]πΆοΈ
This property holds whether the widget is enabled
use
setEnabled()
orsetDisabled()
to change this property- Returns:
bool
- move(x: int, y: int) None [source]πΆοΈ
Move the widget
- Parameters:
x (int) β the horizontal position
y (int) β the vertical position
- moveEvent(x: int, y: int) None [source]πΆοΈ
Convenience function, Event Callback triggered after a successful move
Note
Override this method to handle this event
- Parameters:
x (int) β the new horizontal position
y (int) β the new vertical position
- paintEvent(canvas: TTkCanvas) None [source]πΆοΈ
Paint Event callback, this need to be overridden in the widget.
Note
Override this method to handle this event
- Parameters:
canvas (
TTkCanvas
) β the canvas where the content need to be drawn
- pasteEvent(txt: str) None [source]πΆοΈ
Callback triggered when a paste event is forwarded to this widget.
Note
Reimplement this function to handle this event
- Parameters:
txt (str) β the paste object
- resize(width: int, height: int) None [source]πΆοΈ
Resize the widget
- Parameters:
width (int) β the new width
height (int) β the new height
- resizeEvent(width: int, height: int) None [source]πΆοΈ
Convenience function, Event Callback triggered after a successful resize
Note
Override this method to handle this event
- Parameters:
width (int) β the new width
height (int) β the new height
- setDisabled(disabled: bool = True) None [source]πΆοΈ
This property holds whether the widget is disnabled
This is a convenience function wrapped around
setEnabled()
where (not disabled) is used- Parameters:
disabled (bool) β the disabled status, defaults to True
- setEnabled(enabled: bool = True) None [source]πΆοΈ
This property holds whether the widget is enabled
In general an enabled widget handles keyboard and mouse events; a disabled widget does not.
Some widgets display themselves differently when they are disabled. For example a button might draw its label grayed out. If your widget needs to know when it becomes enabled or disabled.
Disabling a widget implicitly disables all its children. Enabling respectively enables all child widgets unless they have been explicitly disabled.
By default, this property is true.
- Parameters:
enabled (bool) β the enabled status, defaults to True
- setFocusPolicy(policy: FocusPolicy) None [source]πΆοΈ
This property holds the way the widget accepts keyboard focus
The policy is
TTkK.FocusPolicy.TabFocus
if the widget accepts keyboard focus by tabbing,TTkK.FocusPolicy.ClickFocus
if the widget accepts focus by clicking,TTkK.FocusPolicy.StrongFocus
if it accepts both, andTTkK.FocusPolicy.NoFocus
(the default) if it does not accept focus at all.You must enable keyboard focus for a widget if it processes keyboard events. This is normally done from the widgetβs constructor. For instance, the
TTkLineEdit
constructor callssetFocusPolicy()
withTTkK.FocusPolicy.StrongFocus
.If the widget has a focus proxy, then the focus policy will be propagated to it.
- Parameters:
policy (
TTkK.FocusPolicy
) β the focus policy
- setGeometry(x: int, y: int, width: int, height: int)[source]πΆοΈ
Resize and move the widget
- Parameters:
x (int) β the horizontal position
y (int) β the vertical position
width (int) β the new width
height (int) β the new height
- setName(name: str) None [source]πΆοΈ
Set the name of this Instance
- Parameters:
name (str) β the name to be set
- setVisible(visible: bool) None [source]πΆοΈ
Set the visibility status of this widget
- Parameters:
visible (bool:) β status
- update(repaint: bool = True, updateLayout: bool = False, updateParent: bool = False) None [source]πΆοΈ
Notify the drawing routine that the widget changed and needs to draw its new content.
It is important to call this method anytime a canvas update is required after a a status update.
Once
update()
is called, thepaintEvent()
is executed during the next screen refresh.i.e.
class NewLabel(TTkWidget): def __init__(self,**kwargs) -> None: self.text = "" super().__init__(**kwargs) def setText(self, text:str) -> None: self.text = text # Notify the runtime that un update # is required will trigger the paintEvent # at the next screen (terminal) refresh self.update() def paintEvent(self, canvas:TTkCanvas) -> None: canvas.drawText(pos=(0,0), text=self.text)
Methods Inherited from:
TMouseEvents
enterEvent
(evt)This event handler, can be reimplemented in a subclass to receive mouse enter events for the widget.
leaveEvent
(evt)This event handler, can be reimplemented in a subclass to receive mouse leave events for the widget.
mouseDoubleClickEvent
(evt)This event handler, can be reimplemented in a subclass to receive mouse click events for the widget.
mouseDragEvent
(evt)This event handler, can be reimplemented in a subclass to receive mouse drag events for the widget.
mouseMoveEvent
(evt)This event handler, can be reimplemented in a subclass to receive mouse move events for the widget.
mousePressEvent
(evt)This event handler, can be reimplemented in a subclass to receive mouse press events for the widget.
mouseReleaseEvent
(evt)This event handler, can be reimplemented in a subclass to receive mouse release events for the widget.
mouseTapEvent
(evt)This event handler, can be reimplemented in a subclass to receive mouse click events for the widget.
wheelEvent
(evt)This event handler, can be reimplemented in a subclass to receive mouse wheel events for the widget.
Methods Inherited from:
TKeyEvents
keyEvent
(evt)This event handler, can be reimplemented in a subclass to receive key events for the widget.
Methods Inherited from:
TDragEvents
dragEnterEvent
(evt)This event handler, can be reimplemented in a subclass to receive drag events for the widget.
dragLeaveEvent
(evt)This event handler, can be reimplemented in a subclass to receive drag events for the widget.
dragMoveEvent
(evt)This event handler, can be reimplemented in a subclass to receive drag events for the widget.
dropEvent
(evt)This event handler, can be reimplemented in a subclass to receive drag events for the widget.
TTkWidget AttributesπΆοΈ
|