clearable_textctrl

A TextCtrl with a button to clear its contents

Classes:

CTCWidget(parent, value, style, validator)

Text control used by ClearableTextCtrl.

ClearButton(parent, eventType, bmp)

Clear button for the ClearableTextCtrl.

ClearableTextCtrl(parent[, id, value, pos, …])

TextCtrl with a button to clear its contents.

Data:

clear_btn

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 control

  • style (int) – The style of the text control

  • validator

Methods:

GetMainWindowOfCompositeControl()

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

GetMainWindowOfCompositeControl()[source]

Returns the parent object.

Return type

ClearableTextCtrl

OnText(event)[source]

Event handler for text being entered in the control.

Parameters

event – The wxPython event.

OnTextEnter(_)[source]

Event handler for the enter / return key being pressed

Parameters

event – The wxPython event.

class ClearButton(parent, eventType, bmp)[source]

Bases: Control

Clear button for the ClearableTextCtrl.

Parameters

Methods:

AcceptsFocusFromKeyboard()

Always returns False.

GetBestSize()

Returns the best size for the control.

GetMainWindowOfCompositeControl()

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.

AcceptsFocusFromKeyboard()[source]

Always returns False.

Return type

bool

GetBestSize()[source]

Returns the best size for the control.

Return type

Size

GetMainWindowOfCompositeControl()[source]

Returns the parent object.

Return type

ClearableTextCtrl

OnLeftUp(_)[source]

Event Handler for left mouse button being released.

OnPaint(_)[source]

Event Handler for widget being painted.

SetBitmapLabel(label)[source]

Set bitmap for the button.

Parameters

label (Bitmap) – Bitmap to set 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 value wx.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. See wx.TextCtrl. Default 0.

  • 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.

AutoCompleteDirectories()

Call this function to enable auto-completion of the text using the file system directories.

AutoCompleteFileNames()

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.

DiscardEdits()

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.

GetBestClientSize()

Returns the best size for the control.

GetCompositeWindowParts()

Returns a list of wx.Window objects that make up this control.

GetDefaultStyle()

Returns the style currently used for new text.

GetInsertionPoint()

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).

GetNumberOfLines()

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.

IsClearButtonVisible()

Returns the clear button’s visibility state.

IsModified()

Returns whether the text has been modified by user.

IsMultiLine()

Returns whether this is a multi line control.

IsSingleLine()

Returns whether this is a single line control.

LayoutControls()

Lays out the child controls.

MarkDirty()

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.

SetInsertionPointEnd()

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.

ShouldInheritColours()

rtype

bool

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:

default_clear_bitmap

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 not None. If it is None, auto-completion is disabled. The wx.TextEntry object takes ownership of this pointer and will delete it in any case (i.e. even if this method return False).

Return type

bool

Returns

True if the auto-completion was enabled or False 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.

Return type

bool

Returns

True if the auto-completion was enabled or False if the operation failed, typically because auto-completion is not supported by the current platform.

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.

Return type

bool

Returns

True if the auto-completion was enabled or False if the operation failed, typically because auto-completion is not supported by the current platform.

ChangeValue(value)[source]

Sets the new text control value.

It also marks the control as not-modified which means that IsModified() would return False immediately after the call to ChangeValue().

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 to SetValue().

Parameters

value (str) – The new value to set. It may contain newline characters if the text control is multiline.

DiscardEdits()[source]

Resets the internal modified flag as if the current changes had been saved.

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.

Parameters

event (KeyEvent)

Return type

bool

Returns

True if the event resulted in a change to the control, False otherwise.

GetBestClientSize()[source]

Returns the best size for the control.

Return type

Size

GetCompositeWindowParts()[source]

Returns a list of wx.Window objects that make up this control.

Return type

List[Window]

GetDefaultStyle()[source]

Returns the style currently used for new text.

Return type

TextAttr

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

int

GetLineLength(lineNo)[source]

Gets the length of the specified line, not including any trailing newline character(s).

Parameters

lineNo (int) – Line number (starting from zero).

Return type

int

Returns

The length of the line, or -1 if lineNo was invalid.

GetLineText(lineNo)[source]

Returns the contents of a given line in the text control, not including any trailing newline character(s).

Parameters

lineNo (int) – Line number (starting from zero).

Return type

str

GetNumberOfLines()[source]

Returns the number of lines in the text control buffer.

Return type

int

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 or CR 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.

Parameters
Return type

str

GetStyle(position, style)[source]

Returns the style at this position in the text control.

Not all platforms support this function.

Parameters
Return type

bool

Returns

True on success, False if an error occurred (this may also mean that the styles are not supported under this platform).

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

IsClearButtonVisible()[source]

Returns the clear button’s visibility state.

Return type

bool

IsModified()[source]

Returns whether the text has been modified by user.

Note

Calling SetValue() doesn’t make the control modified.

Return type

bool

IsMultiLine()[source]

Returns whether this is a multi line control.

Return type

bool

IsSingleLine()[source]

Returns whether this is a single line control.

Return type

bool

LayoutControls()[source]

Lays out the child controls.

MarkDirty()[source]

Mark the control as modified (dirty).

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)

PositionToXY(pos)[source]

Converts given position to a zero-based column, line number pair.

Parameters

pos (int) – Position

Return type

Tuple[int, int]

SetBackgroundColour(colour)[source]

Sets the background colour of the control

Parameters

colour (Colour) – The colour to be used as the background colour; pass wx.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.

Return type

bool

Returns

True if the operation completes successfully, False otherwise.

SetClearBitmap(bitmap)[source]

Sets the bitmap for the clear button.

Parameters

bitmap (Bitmap)

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() or AppendText() 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).

Parameters

style (TextAttr) – The style for the new text

Return type

bool

Returns

True on success, False if an error occurred (this may also mean that the styles are not supported under this platform).

SetEditable(editable)[source]

Makes the text item editable or read-only, overriding the wx.TE_READONLY flag.

Parameters

editable (bool) – If True, the control should be editable. If False, the control should be read-only.

SetFont(font)[source]

Sets the font for the control.

Parameters

font (Font) – Font to associate with this control. Pass wx.NullFont to reset to the default font.

Return type

bool

Returns

True if the operation completes successfully, False otherwise.

SetInsertionPoint(pos)[source]

Sets the insertion point at the given position.

Parameters

pos (int) – Position to set, in the range from 0 to GetLastPosition() inclusive.

SetInsertionPointEnd()[source]

Sets the insertion point at the end of the text control.

This is equivalent to calling SetInsertionPoint() with GetLastPosition() 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.

Parameters
  • start (int) – The start of the range to change.

  • end (int) – The end of the range to change.

  • style (TextAttr) – The new style for the range.

Return type

bool

Returns

True on success, False if an error occurred (this may also mean the styles are not supported under this platform).

ShouldInheritColours()[source]
Return type

bool

ShowPosition(pos)[source]

Makes the line containing the given position visible.

Parameters

pos (int) – The position that should be visible.

XYToPosition(x, y)[source]

Converts the given zero-based column and line number to a position.

Parameters
  • x (int) – The column number

  • y (int) – The line number

Return type

int

property default_clear_bitmap

Returns the default clear button bitmap for the control.

Return type

Bitmap

textctrl

Type:    TextCtrl

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'                         ']

Type:    List[bytes]

XPM button icon for clearing the text control.