clearable_textctrl
A TextCtrl with a button to clear its contents
Classes:
|
Text control used by |
|
Clear button for the |
|
TextCtrl with a button to clear its contents. |
Data:
XPM button icon for clearing the text control. |
-
class
CTCWidget
(parent, value, style, validator)[source] Bases:
TextCtrl
Text control used by
ClearableTextCtrl
.- Parameters
parent (
ClearableTextCtrl
) – The parent window.value (
str
) – The initial value of the text controlstyle (
int
) – The style of the text controlvalidator
Methods:
Returns the parent object.
OnText
(event)Event handler for text being entered in the control.
OnTextEnter
(_)Event handler for the enter / return ⏎ key being pressed
-
class
ClearButton
(parent, eventType, bmp)[source] Bases:
Control
Clear button for the
ClearableTextCtrl
.- Parameters
parent (
ClearableTextCtrl
) – The parent window.eventType (
PyEventBinder
)bmp (
Bitmap
)
Methods:
Always returns
False
.Returns the best size for the control.
Returns the parent object.
OnLeftUp
(_)Event Handler for left mouse button being released.
OnPaint
(_)Event Handler for widget being painted.
SetBitmapLabel
(label)Set bitmap for the button.
-
class
ClearableTextCtrl
(parent, id=-1, value='', pos=(-1, -1), size=(-1, -1), style=0, validator=<wx.Validator object>, name='ClearableTextCtrl')[source] Bases:
TextCtrlWrapper
,Panel
TextCtrl with a button to clear its contents.
- Parameters
parent (
Window
) – The parent window.id (
int
) – An identifier for the control.wx.ID_ANY
is taken to mean a default. Default-1
.value (
str
) – Default text value. Default''
.pos (
Point
) – The control position. The valuewx.DefaultPosition
indicates a default position, chosen by either the windowing system or wxWidgets, depending on platform. Default(-1, -1)
.size (
Size
) – The control size. The value wx.DefaultSize indicates a default size, chosen by either the windowing system or wxWidgets, depending on platform. Default(-1, -1)
.style (
int
) – The window style. Seewx.TextCtrl
. Default0
.validator (
Validator
) – Window validator. Default<wx.Validator object at 0x7f21e9c88f10>
.name (
str
) – Window name. Default'ClearableTextCtrl'
.
Methods:
AutoComplete
(completer)Enable auto-completion using the provided completer object.
Call this function to enable auto-completion of the text using the file system directories.
Call this function to enable auto-completion of the text typed in a single-line text control using all valid file system paths.
ChangeValue
(value)Sets the new text control value.
Resets the internal modified flag as if the current changes had been saved.
EmulateKeyPress
(event)Inserts into the control the character which would have been inserted if the given key event had occurred in the text control.
Returns the best size for the control.
Returns a list of
wx.Window
objects that make up this control.Returns the style currently used for new text.
Returns the insertion point, or cursor, position.
GetLineLength
(lineNo)Gets the length of the specified line, not including any trailing newline character(s).
GetLineText
(lineNo)Returns the contents of a given line in the text control, not including any trailing newline character(s).
Returns the number of lines in the text control buffer.
GetRange
(from_, to_)Returns the string containing the text starting in the positions from and up to to in the control.
GetStyle
(position, style)Returns the style at this position in the text control.
HitTest
(pt)Finds the row and column of the character at the specified point.
HitTestPos
(pt)Finds the position of the character at the specified point.
Returns the clear button’s visibility state.
Returns whether the text has been modified by user.
Returns whether this is a multi line control.
Returns whether this is a single line control.
Lays out the child controls.
Mark the control as modified (dirty).
OnClearButton
(event)Event handler for clear button being pressed
OnSize
(event)Event handler for the size of the control being changed.
PositionToXY
(pos)Converts given position to a zero-based column, line number pair.
SetBackgroundColour
(colour)Sets the background colour of the control
SetClearBitmap
(bitmap)Sets the bitmap for the clear button.
SetDefaultStyle
(style)Changes the default style to use for the new text which is going to be added to the control.
SetEditable
(editable)Makes the text item editable or read-only, overriding the
wx.TE_READONLY
flag.SetFont
(font)Sets the font for the control.
SetInsertionPoint
(pos)Sets the insertion point at the given position.
Sets the insertion point at the end of the text control.
SetMaxLength
(length)This function sets the maximum number of characters the user can enter into the control.
SetModified
(modified)Marks the control as being modified by the user or not.
SetStyle
(start, end, style)Changes the style of the given range.
- rtype
ShowPosition
(pos)Makes the line containing the given position visible.
XYToPosition
(x, y)Converts the given zero-based column and line number to a position.
Attributes:
Returns the default clear button bitmap for the control.
-
AutoComplete
(completer)[source] Enable auto-completion using the provided completer object.
The specified completer object will be used to retrieve the list of possible completions for the already entered text and will be deleted by
wx.TextEntry
itself when it’s not needed any longer.- Parameters
completer (
TextCompleter
) – The object to be used for generating completions if notNone
. If it isNone
, auto-completion is disabled. Thewx.TextEntry
object takes ownership of this pointer and will delete it in any case (i.e. even if this method returnFalse
).- Return type
- Returns
True
if the auto-completion was enabled orFalse
if the operation failed, typically because auto-completion is not supported by the current platform.
-
AutoCompleteDirectories
()[source] Call this function to enable auto-completion of the text using the file system directories.
Unlike
AutoCompleteFileNames()
, which completes both file names and directories, this function only completes the directory names.Note
This function is only implemented in wxMSW port and does nothing under the other platforms.
-
AutoCompleteFileNames
()[source] Call this function to enable auto-completion of the text typed in a single-line text control using all valid file system paths.
Note
This function is only implemented in wxMSW port and does nothing under the other platforms.
-
ChangeValue
(value)[source] Sets the new text control value.
It also marks the control as not-modified which means that
IsModified()
would returnFalse
immediately after the call toChangeValue()
.The insertion point is set to the start of the control (i.e. position 0) by this function.
This functions does not generate the
wx.wxEVT_TEXT
event but otherwise is identical toSetValue()
.- Parameters
value (
str
) – The new value to set. It may contain newline characters if the text control is multiline.
-
EmulateKeyPress
(event)[source] Inserts into the control the character which would have been inserted if the given key event had occurred in the text control.
The event object should be the same as the one passed to
wx.EVT_KEY_DOWN
handler previously by wxWidgets.Note
This function doesn’t currently work correctly for all keys under any platform but MSW.
-
GetInsertionPoint
()[source] Returns the insertion point, or cursor, position.
This is defined as the zero based index of the character position to the right of the insertion point. For example, if the insertion point is at the end of the single-line text control, it is equal to
GetLastPosition()
.- Return type
-
GetLineLength
(lineNo)[source] Gets the length of the specified line, not including any trailing newline character(s).
-
GetLineText
(lineNo)[source] Returns the contents of a given line in the text control, not including any trailing newline character(s).
-
GetRange
(from_, to_)[source] Returns the string containing the text starting in the positions from and up to to in the control.
The positions must have been returned by another
wx.TextCtrl
method.Note
The positions in a multiline
wx.TextCtrl
do not correspond to the indices in the string returned by GetValue because of the different new line representations (CR
orCR LF
) and so this method should be used to obtain the correct results instead of extracting parts of the entire value. It may also be more efficient, especially if the control contains a lot of data.
-
GetStyle
(position, style)[source] Returns the style at this position in the text control.
Not all platforms support this function.
-
HitTest
(pt)[source] Finds the row and column of the character at the specified point.
If the return code is not
wx.TE_HT_UNKNOWN
the row and column of the character closest to this position are returned, otherwise the output parameters are not modified.Note
This function is currently only implemented in Univ, wxMSW and wxGTK ports and always returns
wx.TE_HT_UNKNOWN
in the other ports.NB: pt is in device coords (not adjusted for the client area origin nor scrolling).
- Parameters
pt
- Return type
TextCtrlHitTestResult
-
HitTestPos
(pt)[source] Finds the position of the character at the specified point.
If the return code is not
wx.TE_HT_UNKNOWN
the position of the character closest to this position is returned, otherwise the output parameter is not modified.Note
This function is currently only implemented in Univ, wxMSW and wxGTK ports and always returns
wx.TE_HT_UNKNOWN
in the other ports.- Parameters
pt
- Return type
wxTextCtrlHitTestResult
-
IsModified
()[source] Returns whether the text has been modified by user.
Note
Calling
SetValue()
doesn’t make the control modified.- Return type
-
OnClearButton
(event)[source] Event handler for clear button being pressed
- Parameters
event (
CommandEvent
)
-
OnSize
(event)[source] Event handler for the size of the control being changed.
- Parameters
event (
SizeEvent
)
-
SetBackgroundColour
(colour)[source] Sets the background colour of the control
- Parameters
colour (
Colour
) – The colour to be used as the background colour; passwx.NullColour
. to reset to the default colour.
Note
You may want to use
wx.SystemSettings.GetColour
to retrieve a suitable colour to use rather than setting an hard-coded one.
-
SetDefaultStyle
(style)[source] Changes the default style to use for the new text which is going to be added to the control.
This applies both to the text added programmatically using
WriteText()
orAppendText()
and to the text entered by the user interactively.If either of the font, foreground, or background colour is not set in style, the values of the previous default style are used for them. If the previous default style didn’t set them either then the global font or colours of the text control itself are used as fall back.
However, if the style parameter is the default
wx.TextAttr
, then the default style is just reset (instead of being combined with the new style which wouldn’t change it at all).
-
SetEditable
(editable)[source] Makes the text item editable or read-only, overriding the
wx.TE_READONLY
flag.
-
SetInsertionPoint
(pos)[source] Sets the insertion point at the given position.
- Parameters
pos (
int
) – Position to set, in the range from 0 toGetLastPosition()
inclusive.
-
SetInsertionPointEnd
()[source] Sets the insertion point at the end of the text control.
This is equivalent to calling
SetInsertionPoint()
withGetLastPosition()
as the argument.
-
SetMaxLength
(length)[source] This function sets the maximum number of characters the user can enter into the control.
In other words, it allows limiting the text value length to len not counting the terminating
NUL
character.If len is 0, the previously set max length limit, if any, is discarded, and the user may enter as much text as the underlying native text control widget supports (typically at least 32Kb).
If the user tries to enter more characters into the text control when it is already filled up to the maximal length, a
wx.wxEVT_TEXT_MAXLEN
event is sent to notify the program about it (giving it the possibility to show an explanatory message, for example) and the extra input is discarded.Note that in wxGTK this function may only be used with single line text controls.
- Parameters
length (
int
)
-
SetModified
(modified)[source] Marks the control as being modified by the user or not.
- Parameters
modified (
bool
)
-
SetStyle
(start, end, style)[source] Changes the style of the given range.
If any attribute within style is not set, the corresponding attribute from GetDefaultStyle is used.
-
ShowPosition
(pos)[source] Makes the line containing the given position visible.
- Parameters
pos (
int
) – The position that should be visible.
-
property
default_clear_bitmap
Returns the default clear button bitmap for the control.
- Return type
-
clear_btn
= [b'25 19 2 1', b' c None', b'+ c #000000', b' ', b' ', b' ', b' ', b' ', b' ', b' +++++++++++++ ', b' ++ + ', b' ++ + + + ', b' ++ + + + ', b' ++ + + ', b' ++ + + + ', b' ++ + + + ', b' ++ + ', b' +++++++++++++ ', b' ', b' ', b' ', b' ', b' '] -
XPM button icon for clearing the text control.