Gtk.IMContext¶
- Subclasses:
Methods¶
- Inherited:
- Structs:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Properties¶
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/en |
|||
r/w/en |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent_instance |
r |
Class Details¶
- class Gtk.IMContext(**kwargs)¶
- Bases:
- Abstract:
Yes
- Structure:
GtkIMContext
defines the interface for GTK input methods.GtkIMContext
is used by GTK text input widgets likeGtkText
to map from key events to Unicode character strings.An input method may consume multiple key events in sequence before finally outputting 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. To do so, the
GtkIMContext
will emit [signal`Gtk`.IMContext::preedit-start], [signal`Gtk`.IMContext::preedit-changed] and [signal`Gtk`.IMContext::preedit-end] signals.For instance, the built-in GTK input method [class`Gtk`.IMContextSimple] implements the input of arbitrary Unicode code points by holding down the <kbd>Control</kbd> and <kbd>Shift</kbd> keys and then typing <kbd>u</kbd> followed by the hexadecimal digits of the code point. When releasing the <kbd>Control</kbd> and <kbd>Shift</kbd> keys, preediting ends and the character is inserted as text. For example,
Ctrl+Shift+u 2 0 A C
results in the € sign.
Additional input methods can be made available for use by GTK widgets as loadable modules. An input method module is a small shared library which provides a
GIOExtension
for the extension point named “gtk-im-module”.To connect a widget to the users preferred input method, you should use [class`Gtk`.IMMulticontext].
- delete_surrounding(offset, n_chars)[source]¶
- Parameters:
- Returns:
True
if the signal was handled.- Return type:
Asks the widget that the input context is attached to delete characters around the cursor position by emitting the
::delete_surrounding
signal.Note that offset and n_chars are in characters not in bytes which differs from the usage other places in
GtkIMContext
.In order to use this function, you should first call [method`Gtk`.IMContext.get_surrounding] to get the current context, and call this function immediately afterwards to make sure that you know what you are deleting. You should also account for the fact that even if the signal was handled, the input context might not have deleted all the characters that were requested to be deleted.
This function is used by an input method that wants to make substitutions in the existing text in response to new input. It is not useful for applications.
- filter_key(press, surface, device, time, keycode, state, group)[source]¶
- Parameters:
press (
bool
) – whether to forward a key press or release eventsurface (
Gdk.Surface
) – the surface the event is fordevice (
Gdk.Device
) – the device that the event is fortime (
int
) – the timestamp for the eventkeycode (
int
) – the keycode for the eventstate (
Gdk.ModifierType
) – modifier state for the eventgroup (
int
) – the active keyboard group for the event
- Returns:
True
if the input method handled the key event.- Return type:
Allow an input method to forward key press and release events to another input method without necessarily having a
GdkEvent
available.
- filter_keypress(event)[source]¶
- Parameters:
event (
Gdk.Event
) – the key event- Returns:
True
if the input method handled the key event.- Return type:
Allow an input method to internally handle key press and release events.
If this function returns
True
, then no further processing should be done for this key event.
- focus_in()[source]¶
Notify the input method that the widget to which this input context corresponds has gained focus.
The input method may, for example, change the displayed feedback to reflect this change.
- focus_out()[source]¶
Notify the input method that the widget to which this input context corresponds has lost focus.
The input method may, for example, change the displayed feedback or reset the contexts state to reflect this change.
- get_preedit_string()[source]¶
- Returns:
- str:
location to store the retrieved string. The string retrieved must be freed with
GLib.free
().- attrs:
location to store the retrieved attribute list. When you are done with this list, you must unreference it with [method`Pango`.AttrList.unref].
- cursor_pos:
location to store position of cursor (in characters) within the preedit string.
- Return type:
(str:
str
, attrs:Pango.AttrList
, cursor_pos:int
)
Retrieve the current preedit string for the input context, and a list of attributes to apply to the string.
This string should be displayed inserted at the insertion point.
- get_surrounding()[source]¶
- Returns:
None
if no surrounding text was provided; otherwise a tuple containing:- text:
text holding context around the insertion point.
- cursor_index:
byte index of the insertion cursor within text
- Return type:
Retrieves context around the insertion point.
Input methods typically want context in order to constrain input text based on existing text; this is important for languages such as Thai where only some sequences of characters are allowed.
This function is implemented by emitting the [signal`Gtk`.IMContext::retrieve-surrounding] signal on the input method; in response to this signal, a widget should provide as much context as is available, up to an entire paragraph, by calling [method`Gtk`.IMContext.set_surrounding].
Note that there is no obligation for a widget to respond to the
::retrieve-surrounding
signal, so input methods must be prepared to function without context.Deprecated since version 4.2: Use [method`Gtk`.IMContext.get_surrounding_with_selection] instead.
- get_surrounding_with_selection()[source]¶
- Returns:
TRUE
if surrounding text was provided; in this case you must free the result stored intext
.- text:
location to store a UTF-8 encoded string of text holding context around the insertion point. If the function returns
True
, then you must free the result stored in this location withGLib.free
().- cursor_index:
location to store byte index of the insertion cursor within text.
- anchor_index:
location to store byte index of the selection bound within text
- Return type:
Retrieves context around the insertion point.
Input methods typically want context in order to constrain input text based on existing text; this is important for languages such as Thai where only some sequences of characters are allowed.
This function is implemented by emitting the [signal`Gtk`.IMContext::retrieve-surrounding] signal on the input method; in response to this signal, a widget should provide as much context as is available, up to an entire paragraph, by calling [method`Gtk`.IMContext.set_surrounding_with_selection].
Note that there is no obligation for a widget to respond to the
::retrieve-surrounding
signal, so input methods must be prepared to function without context.New in version 4.2.
- reset()[source]¶
Notify the input method that a change such as a change in cursor position has been made.
This will typically cause the input method to clear the preedit state.
- set_client_widget(widget)[source]¶
- Parameters:
widget (
Gtk.Widget
orNone
) – the client widget. This may beNone
to indicate that the previous client widget no longer exists.
Set the client widget for the input context.
This is the
GtkWidget
holding the input focus. This widget is used in order to correctly position status windows, and may also be used for purposes internal to the input method.
- set_cursor_location(area)[source]¶
- Parameters:
area (
Gdk.Rectangle
) – new location
Notify the input method that a change in cursor position has been made.
The location is relative to the client widget.
- set_surrounding(text, len, cursor_index)[source]¶
- Parameters:
Sets surrounding context around the insertion point and preedit string.
This function is expected to be called in response to the [signal`Gtk`.IMContext::retrieve-surrounding] signal, and will likely have no effect if called at other times.
Deprecated since version 4.2: Use [method`Gtk`.IMContext.set_surrounding_with_selection] instead
- set_surrounding_with_selection(text, len, cursor_index, anchor_index)[source]¶
- Parameters:
text (
str
) – text surrounding the insertion point, as UTF-8. the preedit string should not be included within textlen (
int
) – the length of text, or -1 if text is nul-terminatedcursor_index (
int
) – the byte index of the insertion cursor within textanchor_index (
int
) – the byte index of the selection bound within text
Sets surrounding context around the insertion point and preedit string. This function is expected to be called in response to the [signal`Gtk`.IMContext::retrieve_surrounding] signal, and will likely have no effect if called at other times.
New in version 4.2.
- set_use_preedit(use_preedit)[source]¶
- Parameters:
use_preedit (
bool
) – whether the IM context should use the preedit string.
Sets whether the IM context should use the preedit string to display feedback.
If use_preedit is
False
(default isTrue
), then the IM context may use some other method to display feedback, such as displaying it in a child of the root window.
- do_activate_osk() virtual¶
- do_commit(str) virtual¶
- Parameters:
str (
str
) –
Default handler of the [signal`Gtk`.IMContext::commit] signal.
- do_delete_surrounding(offset, n_chars) virtual¶
- Parameters:
- Returns:
True
if the signal was handled.- Return type:
Asks the widget that the input context is attached to delete characters around the cursor position by emitting the
::delete_surrounding
signal.Note that offset and n_chars are in characters not in bytes which differs from the usage other places in
GtkIMContext
.In order to use this function, you should first call [method`Gtk`.IMContext.get_surrounding] to get the current context, and call this function immediately afterwards to make sure that you know what you are deleting. You should also account for the fact that even if the signal was handled, the input context might not have deleted all the characters that were requested to be deleted.
This function is used by an input method that wants to make substitutions in the existing text in response to new input. It is not useful for applications.
- do_filter_keypress(event) virtual¶
- Parameters:
event (
Gdk.Event
) – the key event- Returns:
True
if the input method handled the key event.- Return type:
Allow an input method to internally handle key press and release events.
If this function returns
True
, then no further processing should be done for this key event.
- do_focus_in() virtual¶
Notify the input method that the widget to which this input context corresponds has gained focus.
The input method may, for example, change the displayed feedback to reflect this change.
- do_focus_out() virtual¶
Notify the input method that the widget to which this input context corresponds has lost focus.
The input method may, for example, change the displayed feedback or reset the contexts state to reflect this change.
- do_get_preedit_string() virtual¶
- Returns:
- str:
location to store the retrieved string. The string retrieved must be freed with
GLib.free
().- attrs:
location to store the retrieved attribute list. When you are done with this list, you must unreference it with [method`Pango`.AttrList.unref].
- cursor_pos:
location to store position of cursor (in characters) within the preedit string.
- Return type:
(str:
str
, attrs:Pango.AttrList
, cursor_pos:int
)
Retrieve the current preedit string for the input context, and a list of attributes to apply to the string.
This string should be displayed inserted at the insertion point.
- do_get_surrounding() virtual¶
- Returns:
TRUE
if surrounding text was provided; in this case you must free the result stored intext
.- Return type:
Retrieves context around the insertion point.
Input methods typically want context in order to constrain input text based on existing text; this is important for languages such as Thai where only some sequences of characters are allowed.
This function is implemented by emitting the [signal`Gtk`.IMContext::retrieve-surrounding] signal on the input method; in response to this signal, a widget should provide as much context as is available, up to an entire paragraph, by calling [method`Gtk`.IMContext.set_surrounding].
Note that there is no obligation for a widget to respond to the
::retrieve-surrounding
signal, so input methods must be prepared to function without context.Deprecated since version 4.2: Use [method`Gtk`.IMContext.get_surrounding_with_selection] instead.
- do_get_surrounding_with_selection() virtual¶
- Returns:
TRUE
if surrounding text was provided; in this case you must free the result stored intext
.- text:
location to store a UTF-8 encoded string of text holding context around the insertion point. If the function returns
True
, then you must free the result stored in this location withGLib.free
().- cursor_index:
location to store byte index of the insertion cursor within text.
- anchor_index:
location to store byte index of the selection bound within text
- Return type:
Retrieves context around the insertion point.
Input methods typically want context in order to constrain input text based on existing text; this is important for languages such as Thai where only some sequences of characters are allowed.
This function is implemented by emitting the [signal`Gtk`.IMContext::retrieve-surrounding] signal on the input method; in response to this signal, a widget should provide as much context as is available, up to an entire paragraph, by calling [method`Gtk`.IMContext.set_surrounding_with_selection].
Note that there is no obligation for a widget to respond to the
::retrieve-surrounding
signal, so input methods must be prepared to function without context.New in version 4.2.
- do_preedit_changed() virtual¶
Default handler of the [signal`Gtk`.IMContext::preedit-changed] signal.
- do_preedit_end() virtual¶
Default handler of the [signal`Gtk`.IMContext::preedit-end] signal.
- do_preedit_start() virtual¶
Default handler of the [signal`Gtk`.IMContext::preedit-start] signal.
- do_reset() virtual¶
Notify the input method that a change such as a change in cursor position has been made.
This will typically cause the input method to clear the preedit state.
- do_retrieve_surrounding() virtual¶
- Return type:
Default handler of the [signal`Gtk`.IMContext::retrieve-surrounding] signal.
- do_set_client_widget(widget) virtual¶
- Parameters:
widget (
Gtk.Widget
orNone
) – the client widget. This may beNone
to indicate that the previous client widget no longer exists.
Set the client widget for the input context.
This is the
GtkWidget
holding the input focus. This widget is used in order to correctly position status windows, and may also be used for purposes internal to the input method.
- do_set_cursor_location(area) virtual¶
- Parameters:
area (
Gdk.Rectangle
) – new location
Notify the input method that a change in cursor position has been made.
The location is relative to the client widget.
- do_set_surrounding(text, len, cursor_index) virtual¶
- Parameters:
Sets surrounding context around the insertion point and preedit string.
This function is expected to be called in response to the [signal`Gtk`.IMContext::retrieve-surrounding] signal, and will likely have no effect if called at other times.
Deprecated since version 4.2: Use [method`Gtk`.IMContext.set_surrounding_with_selection] instead
- do_set_surrounding_with_selection(text, len, cursor_index, anchor_index) virtual¶
- Parameters:
text (
str
) – text surrounding the insertion point, as UTF-8. the preedit string should not be included within textlen (
int
) – the length of text, or -1 if text is nul-terminatedcursor_index (
int
) – the byte index of the insertion cursor within textanchor_index (
int
) – the byte index of the selection bound within text
Sets surrounding context around the insertion point and preedit string. This function is expected to be called in response to the [signal`Gtk`.IMContext::retrieve_surrounding] signal, and will likely have no effect if called at other times.
New in version 4.2.
- do_set_use_preedit(use_preedit) virtual¶
- Parameters:
use_preedit (
bool
) – whether the IM context should use the preedit string.
Sets whether the IM context should use the preedit string to display feedback.
If use_preedit is
False
(default isTrue
), then the IM context may use some other method to display feedback, such as displaying it in a child of the root window.
Signal Details¶
- Gtk.IMContext.signals.commit(i_m_context, str)¶
- Signal Name:
commit
- Flags:
- Parameters:
i_m_context (
Gtk.IMContext
) – The object which received the signalstr (
str
) – the completed character(s) entered by the user
The
::commit
signal is emitted when a complete input sequence has been entered by the user.If the commit comes after a preediting sequence, the
::commit
signal is emitted after::preedit-end
.This can be a single character immediately after a key press or the final result of preediting.
- Gtk.IMContext.signals.delete_surrounding(i_m_context, offset, n_chars)¶
- Signal Name:
delete-surrounding
- Flags:
- Parameters:
i_m_context (
Gtk.IMContext
) – The object which received the signaloffset (
int
) – the character offset from the cursor position of the text to be deleted. A negative value indicates a position before the cursor.n_chars (
int
) – the number of characters to be deleted
- Returns:
True
if the signal was handled.- Return type:
The
::delete-surrounding
signal is emitted when the input method needs to delete all or part of the context surrounding the cursor.
- Gtk.IMContext.signals.preedit_changed(i_m_context)¶
- Signal Name:
preedit-changed
- Flags:
- Parameters:
i_m_context (
Gtk.IMContext
) – The object which received the signal
The
::preedit-changed
signal is emitted whenever the preedit sequence currently being entered has changed.It is also emitted at the end of a preedit sequence, in which case [method`Gtk`.IMContext.get_preedit_string] returns the empty string.
- Gtk.IMContext.signals.preedit_end(i_m_context)¶
- Signal Name:
preedit-end
- Flags:
- Parameters:
i_m_context (
Gtk.IMContext
) – The object which received the signal
The
::preedit-end
signal is emitted when a preediting sequence has been completed or canceled.
- Gtk.IMContext.signals.preedit_start(i_m_context)¶
- Signal Name:
preedit-start
- Flags:
- Parameters:
i_m_context (
Gtk.IMContext
) – The object which received the signal
The
::preedit-start
signal is emitted when a new preediting sequence starts.
- Gtk.IMContext.signals.retrieve_surrounding(i_m_context)¶
- Signal Name:
retrieve-surrounding
- Flags:
- Parameters:
i_m_context (
Gtk.IMContext
) – The object which received the signal- Returns:
True
if the signal was handled.- Return type:
The
::retrieve-surrounding
signal is emitted when the input method requires the context surrounding the cursor.The callback should set the input method surrounding context by calling the [method`Gtk`.IMContext.set_surrounding] method.
Property Details¶
- Gtk.IMContext.props.input_hints¶
- Name:
input-hints
- Type:
- Default Value:
- Flags:
Additional hints that allow input methods to fine-tune their behaviour.
- Gtk.IMContext.props.input_purpose¶
- Name:
input-purpose
- Type:
- Default Value:
- Flags:
The purpose of the text field that the `:obj:Gtk.IMContext is connected to.
This property can be used by on-screen keyboards and other input methods to adjust their behaviour.