TextEdit (hwx.gui)#
- class TextEdit(text='', **kwds)#
Bases:
Widget
A TextEdit Widget.
It is used to display and modify formatted and HTML text. It can be editable or not. Ctrl+Wheel zooms in/out.
# Name
Type
property
property
property
# Name
Description
Text
(self, *args) -> ‘uiString’onKeyPress
(self, event)Callback method when a key is pressed on the TextEdit widget.
onWheelHandler
(self, event)Callback method when the mouse wheel is rotated inside the TextEdit widget.
setStyleToSection
(self, paraFrom, indexFrom, paraTo, indexTo, color=None, size=None, bold=False, italic=False)Function to set style (color/bold/italic/size) to a particular section
Example
from hwx import gui # Create an html TextEdit area textEdit = gui.TextEdit(text=""" <h1>Heading1</h1> <h2>Heading2</h2> <p>This is a paragraph.</p>""", readonly=True, # Change this to make the text edit writable ) # Changing the style of 'Heading1'. textEdit.setStyleToSection(0,0,0,9,color="red", bold=True, italic=True) show(textEdit)
- property text: uiString#
The text to display.
- property html#
The HTML formatted text.
- property readonly#
Returns and sets whether text/value can be edited.
- setStyleToSection(paraFrom, indexFrom, paraTo, indexTo, color=None, size=None, bold=False, italic=False)#
Function to set style (color/bold/italic/size) to a particular section in text.
- Parameters:
paraFrom (int) – Starting paragraph number.
indexFrom (int) – Index in starting paragraph.
paraTo (int) – Ending paragraph number.
indexTo (int) – Index in ending paragraph.
color (string | tuple(int)) – Text color. It can be RGB values in form of tuple or color name.
size (int) – Text size.
bold (bool) – If True, text will be bold.
italic (bool) – If True, text will be italic.
- onWheelHandler(event)#
Callback method when the mouse wheel is rotated inside the TextEdit widget.
Ctrl+Wheel Zooms in/out.
- Parameters:
event (KeyEvent, MouseEvent) – The key event to capture the ctrl pressed and mouse wheel event to determine if is used zoom in or out.
- onKeyPress(event)#
Callback method when a key is pressed on the TextEdit widget.
<Ret> adds a new line, lets add <Shift+Ret> for onCommand.
- Parameters:
event (KeyEvent) – Event to get key pressed.