InputMethodContext
Added in version 2.28.
Superclasses: Object
Base class for input method contexts.
WebKitInputMethodContext defines the interface to implement WebKit input methods. The input methods are used by WebKit, when editable content is focused, to map from key events to Unicode character strings.
An input method may consume multiple key events in sequence and finally output the composed result. This is called preediting, and an input method may provide feedback about this process by displaying the intermediate composition states as preedit text.
Methods
- class InputMethodContext
- filter_key_event(key_event: Event) bool
Allow
key_event
to be handled by the input method.If
True
is returned, then no further processing should be done for the key event.Added in version 2.28.
- Parameters:
key_event – the key event to filter
- get_input_hints() InputHints
Get the value of the
InputMethodContext
:input-hints property.Added in version 2.28.
- get_input_purpose() InputPurpose
Get the value of the
InputMethodContext
:input-purpose property.Added in version 2.28.
- get_preedit() tuple[str, list[InputMethodUnderline], int]
Get the pre-edit string and a list of WebKitInputMethodUnderline.
Get the current pre-edit string for the
context
, and a list of WebKitInputMethodUnderline to apply to the string. The string will be displayed inserted atcursor_offset
.Added in version 2.28.
- notify_cursor_area(x: int, y: int, width: int, height: int) None
Notify
context
that cursor area changed in input associated.Added in version 2.28.
- Parameters:
x – the x coordinate of cursor location
y – the y coordinate of cursor location
width – the width of cursor area
height – the height of cursor area
- notify_focus_in() None
Notify
context
that input associated has gained focus.Added in version 2.28.
- notify_focus_out() None
Notify
context
that input associated has lost focus.Added in version 2.28.
- notify_surrounding(text: str, length: int, cursor_index: int, selection_index: int) None
Notify
context
that the context surrounding the cursor has changed.If there’s no selection
selection_index
is the same ascursor_index
.Added in version 2.28.
- Parameters:
text – text surrounding the insertion point
length – the length of
text
, or -1 iftext
is nul-terminatedcursor_index – the byte index of the insertion cursor within
text
.selection_index – the byte index of the selection cursor within
text
.
- reset() None
Reset the
context
.This will typically cause the input to clear the preedit state.
Added in version 2.28.
- set_enable_preedit(enabled: bool) None
Set whether
context
should enable preedit to display feedback.Added in version 2.28.
- Parameters:
enabled – whether to enable preedit
- set_input_hints(hints: InputHints) None
Set the value of the
InputMethodContext
:input-hints property.Added in version 2.28.
- Parameters:
hints – a
InputHints
- set_input_purpose(purpose: InputPurpose) None
Set the value of the
InputMethodContext
:input-purpose property.Added in version 2.28.
- Parameters:
purpose – a
InputPurpose
Properties
- class InputMethodContext
- props.input_hints: InputHints
The
InputHints
of the input associated with this context.Added in version 2.28.
- props.input_purpose: InputPurpose
The
InputPurpose
of the input associated with this context.Added in version 2.28.
Signals
- class InputMethodContext.signals
- committed(text: str) None
Emitted when a complete input sequence has been entered by the user. This can be a single character immediately after a key press or the final result of preediting.
Added in version 2.28.
- Parameters:
text – the string result
- delete_surrounding(offset: int, n_chars: int) None
Emitted when the input method wants to delete the context surrounding the cursor. If
offset
is a negative value, it means a position before the cursor.Added in version 2.28.
- Parameters:
offset – the character offset from the cursor position of the text to be deleted.
n_chars – the number of characters to be deleted
- preedit_changed() None
Emitted whenever the preedit sequence currently being entered has changed. It is also emitted at the end of a preedit sequence, in which case
get_preedit()
returns the empty string.Added in version 2.28.
Virtual Methods
- class InputMethodContext
-
- do_filter_key_event(key_event: Event) bool
Allow
key_event
to be handled by the input method.If
True
is returned, then no further processing should be done for the key event.Added in version 2.28.
- Parameters:
key_event – the key event to filter
- do_get_preedit() tuple[str, list[InputMethodUnderline], int]
Get the pre-edit string and a list of WebKitInputMethodUnderline.
Get the current pre-edit string for the
context
, and a list of WebKitInputMethodUnderline to apply to the string. The string will be displayed inserted atcursor_offset
.Added in version 2.28.
- do_notify_cursor_area(x: int, y: int, width: int, height: int) None
Notify
context
that cursor area changed in input associated.Added in version 2.28.
- Parameters:
x – the x coordinate of cursor location
y – the y coordinate of cursor location
width – the width of cursor area
height – the height of cursor area
- do_notify_focus_in() None
Notify
context
that input associated has gained focus.Added in version 2.28.
- do_notify_focus_out() None
Notify
context
that input associated has lost focus.Added in version 2.28.
- do_notify_surrounding(text: str, length: int, cursor_index: int, selection_index: int) None
Notify
context
that the context surrounding the cursor has changed.If there’s no selection
selection_index
is the same ascursor_index
.Added in version 2.28.
- Parameters:
text – text surrounding the insertion point
length – the length of
text
, or -1 iftext
is nul-terminatedcursor_index – the byte index of the insertion cursor within
text
.selection_index – the byte index of the selection cursor within
text
.