:right-sidebar: True Widget =================================================================== .. currentmodule:: gi.repository.Gtk .. class:: Widget(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.InitiallyUnowned`, :class:`~gi.repository.GObject.Object` Subclasses: :class:`~gi.repository.Gtk.ActionBar`, :class:`~gi.repository.Gtk.AppChooserButton`, :class:`~gi.repository.Gtk.AppChooserWidget`, :class:`~gi.repository.Gtk.AspectFrame`, :class:`~gi.repository.Gtk.Box`, :class:`~gi.repository.Gtk.Button`, :class:`~gi.repository.Gtk.Calendar`, :class:`~gi.repository.Gtk.CellView`, :class:`~gi.repository.Gtk.CenterBox`, :class:`~gi.repository.Gtk.CheckButton`, :class:`~gi.repository.Gtk.ColorButton`, :class:`~gi.repository.Gtk.ColorChooserWidget`, :class:`~gi.repository.Gtk.ColorDialogButton`, :class:`~gi.repository.Gtk.ColumnView`, :class:`~gi.repository.Gtk.ComboBox`, :class:`~gi.repository.Gtk.DragIcon`, :class:`~gi.repository.Gtk.DrawingArea`, :class:`~gi.repository.Gtk.DropDown`, :class:`~gi.repository.Gtk.EditableLabel`, :class:`~gi.repository.Gtk.Entry`, :class:`~gi.repository.Gtk.Expander`, :class:`~gi.repository.Gtk.FileChooserWidget`, :class:`~gi.repository.Gtk.Fixed`, :class:`~gi.repository.Gtk.FlowBox`, :class:`~gi.repository.Gtk.FlowBoxChild`, :class:`~gi.repository.Gtk.FontButton`, :class:`~gi.repository.Gtk.FontChooserWidget`, :class:`~gi.repository.Gtk.FontDialogButton`, :class:`~gi.repository.Gtk.Frame`, :class:`~gi.repository.Gtk.GLArea`, :class:`~gi.repository.Gtk.GraphicsOffload`, :class:`~gi.repository.Gtk.Grid`, :class:`~gi.repository.Gtk.HeaderBar`, :class:`~gi.repository.Gtk.IconView`, :class:`~gi.repository.Gtk.Image`, :class:`~gi.repository.Gtk.InfoBar`, :class:`~gi.repository.Gtk.Inscription`, :class:`~gi.repository.Gtk.Label`, :class:`~gi.repository.Gtk.LevelBar`, :class:`~gi.repository.Gtk.ListBase`, :class:`~gi.repository.Gtk.ListBox`, :class:`~gi.repository.Gtk.ListBoxRow`, :class:`~gi.repository.Gtk.MediaControls`, :class:`~gi.repository.Gtk.MenuButton`, :class:`~gi.repository.Gtk.Notebook`, :class:`~gi.repository.Gtk.Overlay`, :class:`~gi.repository.Gtk.Paned`, :class:`~gi.repository.Gtk.PasswordEntry`, :class:`~gi.repository.Gtk.Picture`, :class:`~gi.repository.Gtk.Popover`, :class:`~gi.repository.Gtk.PopoverMenuBar`, :class:`~gi.repository.Gtk.ProgressBar`, :class:`~gi.repository.Gtk.Range`, :class:`~gi.repository.Gtk.Revealer`, :class:`~gi.repository.Gtk.ScaleButton`, :class:`~gi.repository.Gtk.Scrollbar`, :class:`~gi.repository.Gtk.ScrolledWindow`, :class:`~gi.repository.Gtk.SearchBar`, :class:`~gi.repository.Gtk.SearchEntry`, :class:`~gi.repository.Gtk.Separator`, :class:`~gi.repository.Gtk.ShortcutLabel`, :class:`~gi.repository.Gtk.ShortcutsShortcut`, :class:`~gi.repository.Gtk.SpinButton`, :class:`~gi.repository.Gtk.Spinner`, :class:`~gi.repository.Gtk.Stack`, :class:`~gi.repository.Gtk.StackSidebar`, :class:`~gi.repository.Gtk.StackSwitcher`, :class:`~gi.repository.Gtk.Statusbar`, :class:`~gi.repository.Gtk.Switch`, :class:`~gi.repository.Gtk.Text`, :class:`~gi.repository.Gtk.TextView`, :class:`~gi.repository.Gtk.TreeExpander`, :class:`~gi.repository.Gtk.TreeView`, :class:`~gi.repository.Gtk.Video`, :class:`~gi.repository.Gtk.Viewport`, :class:`~gi.repository.Gtk.Window`, :class:`~gi.repository.Gtk.WindowControls`, :class:`~gi.repository.Gtk.WindowHandle` Implemented Interfaces: :class:`~gi.repository.Gtk.Accessible`, :class:`~gi.repository.Gtk.Buildable`, :class:`~gi.repository.Gtk.ConstraintTarget` :Constructors: :: Widget(**properties) Methods ------- .. rst-class:: interim-class .. class:: Widget :no-index: .. method:: action_set_enabled(action_name: str, enabled: bool) -> None Enable or disable an action installed with :func:`~gi.repository.Gtk.WidgetClass.install_action`. :param action_name: action name, such as "clipboard.paste" :param enabled: whether the action is now enabled .. method:: activate() -> bool For widgets that can be “activated” (buttons, menu items, etc.), this function activates them. The activation will emit the signal set using :obj:`~gi.repository.Gtk.WidgetClass.set_activate_signal` during class initialization. Activation is what happens when you press :kbd:`Enter` on a widget during key navigation. If you wish to handle the activation keybinding yourself, it is recommended to use :obj:`~gi.repository.Gtk.WidgetClass.add_shortcut` with an action created with :obj:`~gi.repository.Gtk.SignalAction.new`. If ``widget`` isn't activatable, the function returns :const:`False`. .. method:: activate_action(name: str, args: ~gi.repository.GLib.Variant | None = None) -> bool Looks up the action in the action groups associated with ``widget`` and its ancestors, and activates it. This is a wrapper around :obj:`~gi.repository.Gtk.Widget.activate_action_variant` that constructs the ``args`` variant according to ``format_string``. :param name: the name of the action to activate :param args: .. method:: activate_default() -> None Activates the ``default.activate`` action from ``widget``. .. method:: add_controller(controller: ~gi.repository.Gtk.EventController) -> None Adds ``controller`` to ``widget`` so that it will receive events. You will usually want to call this function right after creating any kind of :obj:`~gi.repository.Gtk.EventController`. :param controller: a ``GtkEventController`` that hasn't been added to a widget yet .. method:: add_css_class(css_class: str) -> None Adds a style class to ``widget``. After calling this function, the widget’s style will match for ``css_class``, according to CSS matching rules. Use :obj:`~gi.repository.Gtk.Widget.remove_css_class` to remove the style again. :param css_class: The style class to add to ``widget``, without the leading '.' used for notation of style classes .. method:: add_mnemonic_label(label: ~gi.repository.Gtk.Widget) -> None Adds a widget to the list of mnemonic labels for this widget. See :obj:`~gi.repository.Gtk.Widget.list_mnemonic_labels`. Note the list of mnemonic labels for the widget is cleared when the widget is destroyed, so the caller must make sure to update its internal state at this point as well. :param label: a ``GtkWidget`` that acts as a mnemonic label for ``widget`` .. classmethod:: add_shortcut(shortcut: ~gi.repository.Gtk.Shortcut) -> None :param shortcut: .. method:: add_tick_callback(callback: ~typing.Callable[[...], bool], *user_data: ~typing.Any) -> int Queues an animation frame update and adds a callback to be called before each frame. Until the tick callback is removed, it will be called frequently (usually at the frame rate of the output device or as quickly as the application can be repainted, whichever is slower). For this reason, is most suitable for handling graphics that change every frame or every few frames. The tick callback does not automatically imply a relayout or repaint. If you want a repaint or relayout, and aren’t changing widget properties that would trigger that (for example, changing the text of a ``GtkLabel``), then you will have to call :obj:`~gi.repository.Gtk.Widget.queue_resize` or :obj:`~gi.repository.Gtk.Widget.queue_draw` yourself. :obj:`~gi.repository.Gdk.FrameClock.get_frame_time` should generally be used for timing continuous animations and :obj:`~gi.repository.Gdk.FrameTimings.get_predicted_presentation_time` if you are trying to display isolated frames at particular times. This is a more convenient alternative to connecting directly to the :obj:`~gi.repository.Gdk.FrameClock.signals.update` signal of ``GdkFrameClock``, since you don't have to worry about when a ``GdkFrameClock`` is assigned to a widget. :param callback: function to call for updating animations :param user_data: data to pass to ``callback`` .. method:: allocate(width: int, height: int, baseline: int, transform: ~gi.repository.Gsk.Transform | None = None) -> None This function is only used by ``GtkWidget`` subclasses, to assign a size, position and (optionally) baseline to their child widgets. In this function, the allocation and baseline may be adjusted. The given allocation will be forced to be bigger than the widget's minimum size, as well as at least 0×0 in size. For a version that does not take a transform, see :obj:`~gi.repository.Gtk.Widget.size_allocate`. :param width: New width of ``widget`` :param height: New height of ``widget`` :param baseline: New baseline of ``widget``, or -1 :param transform: Transformation to be applied to ``widget`` .. classmethod:: bind_template_callback_full(callback_name: str, callback_symbol: ~typing.Callable[[], None]) -> None :param callback_name: :param callback_symbol: .. classmethod:: bind_template_child_full(name: str, internal_child: bool, struct_offset: int) -> None :param name: :param internal_child: :param struct_offset: .. method:: child_focus(direction: ~gi.repository.Gtk.DirectionType) -> bool Called by widgets as the user moves around the window using keyboard shortcuts. The ``direction`` argument indicates what kind of motion is taking place (up, down, left, right, tab forward, tab backward). This function calls the :obj:`~gi.repository.Gtk.Widget.focus` virtual function; widgets can override the virtual function in order to implement appropriate focus behavior. The default ``focus()`` virtual function for a widget should return ``TRUE`` if moving in ``direction`` left the focus on a focusable location inside that widget, and ``FALSE`` if moving in ``direction`` moved the focus outside the widget. When returning ``TRUE``, widgets normally call :obj:`~gi.repository.Gtk.Widget.grab_focus` to place the focus accordingly; when returning ``FALSE``, they don’t modify the current focus location. This function is used by custom widget implementations; if you're writing an app, you’d use :obj:`~gi.repository.Gtk.Widget.grab_focus` to move the focus to a particular widget. :param direction: direction of focus movement .. method:: compute_bounds(target: ~gi.repository.Gtk.Widget) -> tuple[bool, ~gi.repository.Graphene.Rect] Computes the bounds for ``widget`` in the coordinate space of ``target``. The bounds of widget are (the bounding box of) the region that it is expected to draw in. See the `coordinate system `_ overview to learn more. If the operation is successful, :const:`True` is returned. If ``widget`` has no bounds or the bounds cannot be expressed in ``target``'s coordinate space (for example if both widgets are in different windows), :const:`False` is returned and ``bounds`` is set to the zero rectangle. It is valid for ``widget`` and ``target`` to be the same widget. :param target: the ``GtkWidget`` .. method:: compute_expand(orientation: ~gi.repository.Gtk.Orientation) -> bool Computes whether a container should give this widget extra space when possible. Containers should check this, rather than looking at :obj:`~gi.repository.Gtk.Widget.get_hexpand` or :obj:`~gi.repository.Gtk.Widget.get_vexpand`. This function already checks whether the widget is visible, so visibility does not need to be checked separately. Non-visible widgets are not expanded. The computed expand value uses either the expand setting explicitly set on the widget itself, or, if none has been explicitly set, the widget may expand if some of its children do. :param orientation: expand direction .. method:: compute_point(target: ~gi.repository.Gtk.Widget, point: ~gi.repository.Graphene.Point) -> tuple[bool, ~gi.repository.Graphene.Point] Translates the given ``point`` in ``widget``'s coordinates to coordinates relative to ``target``’s coordinate system. In order to perform this operation, both widgets must share a common ancestor. :param target: the ``GtkWidget`` to transform into :param point: a point in ``widget``'s coordinate system .. method:: compute_transform(target: ~gi.repository.Gtk.Widget) -> tuple[bool, ~gi.repository.Graphene.Matrix] Computes a matrix suitable to describe a transformation from ``widget``'s coordinate system into ``target``'s coordinate system. The transform can not be computed in certain cases, for example when ``widget`` and ``target`` do not share a common ancestor. In that case ``out_transform`` gets set to the identity matrix. To learn more about widget coordinate systems, see the coordinate system `overview `_. :param target: the target widget that the matrix will transform to .. method:: contains(x: float, y: float) -> bool Tests if the point at (``x``, ``y``) is contained in ``widget``. The coordinates for (``x``, ``y``) must be in widget coordinates, so (0, 0) is assumed to be the top left of ``widget``'s content area. :param x: X coordinate to test, relative to ``widget``'s origin :param y: Y coordinate to test, relative to ``widget``'s origin .. method:: create_pango_context() -> ~gi.repository.Pango.Context Creates a new ``PangoContext`` with the appropriate font map, font options, font description, and base direction for drawing text for this widget. See also :obj:`~gi.repository.Gtk.Widget.get_pango_context`. .. method:: create_pango_layout(text: str | None = None) -> ~gi.repository.Pango.Layout Creates a new ``PangoLayout`` with the appropriate font map, font description, and base direction for drawing text for this widget. If you keep a ``PangoLayout`` created in this way around, you need to re-create it when the widget ``PangoContext`` is replaced. This can be tracked by listening to changes of the :obj:`~gi.repository.Gtk.Widget.props.root` property on the widget. :param text: text to set on the layout .. method:: dispose_template(widget_type: type) -> None Clears the template children for the given widget. This function is the opposite of :obj:`~gi.repository.Gtk.Widget.init_template`, and it is used to clear all the template children from a widget instance. If you bound a template child to a field in the instance structure, or in the instance private data structure, the field will be set to ``NULL`` after this function returns. You should call this function inside the ``GObjectClass.dispose()`` implementation of any widget that called ``:func:`~gi.repository.Gtk.Widget.init_template```. Typically, you will want to call this function last, right before chaining up to the parent type's dispose implementation, e.g. .. code-block:: c :dedent: static void some_widget_dispose (GObject *gobject) { SomeWidget *self = SOME_WIDGET (gobject); // Clear the template data for SomeWidget gtk_widget_dispose_template (GTK_WIDGET (self), SOME_TYPE_WIDGET); G_OBJECT_CLASS (some_widget_parent_class)->dispose (gobject); } .. versionadded:: 4.8 :param widget_type: the type of the widget to finalize the template for .. method:: drag_check_threshold(start_x: int, start_y: int, current_x: int, current_y: int) -> bool Checks to see if a drag movement has passed the GTK drag threshold. :param start_x: X coordinate of start of drag :param start_y: Y coordinate of start of drag :param current_x: current X coordinate :param current_y: current Y coordinate .. method:: error_bell() -> None Notifies the user about an input-related error on this widget. If the :obj:`~gi.repository.Gtk.Settings.props.gtk_error_bell` setting is :const:`True`, it calls :obj:`~gi.repository.Gdk.Surface.beep`, otherwise it does nothing. Note that the effect of :obj:`~gi.repository.Gdk.Surface.beep` can be configured in many ways, depending on the windowing backend and the desktop environment or window manager that is used. .. classmethod:: get_activate_signal() -> int .. method:: get_allocated_baseline() -> int Returns the baseline that has currently been allocated to ``widget``. This function is intended to be used when implementing handlers for the ``GtkWidget``Class.snapshot() function, and when allocating child widgets in ``GtkWidget``Class.size_allocate(). .. deprecated:: 4.12 Use :obj:`~gi.repository.Gtk.Widget.get_baseline` instead .. method:: get_allocated_height() -> int Returns the height that has currently been allocated to ``widget``. To learn more about widget sizes, see the coordinate system `overview `_. .. deprecated:: 4.12 Use :obj:`~gi.repository.Gtk.Widget.get_height` instead .. method:: get_allocated_width() -> int Returns the width that has currently been allocated to ``widget``. To learn more about widget sizes, see the coordinate system `overview `_. .. deprecated:: 4.12 Use :obj:`~gi.repository.Gtk.Widget.get_width` instead .. method:: get_allocation() -> ~gi.repository.Gdk.Rectangle Retrieves the widget’s allocation. Note, when implementing a layout container: a widget’s allocation will be its “adjusted” allocation, that is, the widget’s parent typically calls :obj:`~gi.repository.Gtk.Widget.size_allocate` with an allocation, and that allocation is then adjusted (to handle margin and alignment for example) before assignment to the widget. :obj:`~gi.repository.Gtk.Widget.get_allocation` returns the adjusted allocation that was actually assigned to the widget. The adjusted allocation is guaranteed to be completely contained within the :obj:`~gi.repository.Gtk.Widget.size_allocate` allocation, however. So a layout container is guaranteed that its children stay inside the assigned bounds, but not that they have exactly the bounds the container assigned. .. deprecated:: 4.12 Use :obj:`~gi.repository.Gtk.Widget.compute_bounds`, :obj:`~gi.repository.Gtk.Widget.get_width` or :obj:`~gi.repository.Gtk.Widget.get_height` instead. .. method:: get_ancestor(widget_type: type) -> ~gi.repository.Gtk.Widget | None Gets the first ancestor of ``widget`` with type ``widget_type``. For example, `gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)` gets the first ``GtkBox`` that’s an ancestor of ``widget``. No reference will be added to the returned widget; it should not be unreferenced. Note that unlike :obj:`~gi.repository.Gtk.Widget.is_ancestor`, this function considers ``widget`` to be an ancestor of itself. :param widget_type: ancestor type .. method:: get_baseline() -> int Returns the baseline that has currently been allocated to ``widget``. This function is intended to be used when implementing handlers for the ``GtkWidget``Class.snapshot() function, and when allocating child widgets in ``GtkWidget``Class.size_allocate(). .. versionadded:: 4.12 .. method:: get_can_focus() -> bool Determines whether the input focus can enter ``widget`` or any of its children. See :obj:`~gi.repository.Gtk.Widget.set_focusable`. .. method:: get_can_target() -> bool Queries whether ``widget`` can be the target of pointer events. .. method:: get_child_visible() -> bool Gets the value set with :func:`~gi.repository.Gtk.Widget.set_child_visible`. If you feel a need to use this function, your code probably needs reorganization. This function is only useful for container implementations and should never be called by an application. .. method:: get_clipboard() -> ~gi.repository.Gdk.Clipboard Gets the clipboard object for ``widget``. This is a utility function to get the clipboard object for the ``GdkDisplay`` that ``widget`` is using. Note that this function always works, even when ``widget`` is not realized yet. .. method:: get_color() -> ~gi.repository.Gdk.RGBA Gets the current foreground color for the widget’s CSS style. This function should only be used in snapshot implementations that need to do custom drawing with the foreground color. .. versionadded:: 4.10 .. method:: get_css_classes() -> list[str] Returns the list of style classes applied to ``widget``. .. method:: get_css_name() -> str Returns the CSS name that is used for ``self``. .. method:: get_cursor() -> ~gi.repository.Gdk.Cursor | None Queries the cursor set on ``widget``. See :obj:`~gi.repository.Gtk.Widget.set_cursor` for details. .. method:: get_default_direction() -> ~gi.repository.Gtk.TextDirection Obtains the current default reading direction. See :obj:`~gi.repository.Gtk.Widget.set_default_direction`. .. method:: get_direction() -> ~gi.repository.Gtk.TextDirection Gets the reading direction for a particular widget. See :obj:`~gi.repository.Gtk.Widget.set_direction`. .. method:: get_display() -> ~gi.repository.Gdk.Display Get the ``GdkDisplay`` for the toplevel window associated with this widget. This function can only be called after the widget has been added to a widget hierarchy with a ``GtkWindow`` at the top. In general, you should only create display specific resources when a widget has been realized, and you should free those resources when the widget is unrealized. .. method:: get_first_child() -> ~gi.repository.Gtk.Widget | None Returns the widget’s first child. This API is primarily meant for widget implementations. .. method:: get_focus_child() -> ~gi.repository.Gtk.Widget | None Returns the current focus child of ``widget``. .. method:: get_focus_on_click() -> bool Returns whether the widget should grab focus when it is clicked with the mouse. See :obj:`~gi.repository.Gtk.Widget.set_focus_on_click`. .. method:: get_focusable() -> bool Determines whether ``widget`` can own the input focus. See :obj:`~gi.repository.Gtk.Widget.set_focusable`. .. method:: get_font_map() -> ~gi.repository.Pango.FontMap | None Gets the font map of ``widget``. See :obj:`~gi.repository.Gtk.Widget.set_font_map`. .. method:: get_font_options() -> ~gi.repository.cairo.FontOptions | None Returns the ``cairo_font_options_t`` of widget. Seee :obj:`~gi.repository.Gtk.Widget.set_font_options`. .. method:: get_frame_clock() -> ~gi.repository.Gdk.FrameClock | None Obtains the frame clock for a widget. The frame clock is a global “ticker” that can be used to drive animations and repaints. The most common reason to get the frame clock is to call :obj:`~gi.repository.Gdk.FrameClock.get_frame_time`, in order to get a time to use for animating. For example you might record the start of the animation with an initial value from :obj:`~gi.repository.Gdk.FrameClock.get_frame_time`, and then update the animation by calling :obj:`~gi.repository.Gdk.FrameClock.get_frame_time` again during each repaint. :obj:`~gi.repository.Gdk.FrameClock.request_phase` will result in a new frame on the clock, but won’t necessarily repaint any widgets. To repaint a widget, you have to use :obj:`~gi.repository.Gtk.Widget.queue_draw` which invalidates the widget (thus scheduling it to receive a draw on the next frame). :func:`~gi.repository.Gtk.Widget.queue_draw` will also end up requesting a frame on the appropriate frame clock. A widget’s frame clock will not change while the widget is mapped. Reparenting a widget (which implies a temporary unmap) can change the widget’s frame clock. Unrealized widgets do not have a frame clock. .. method:: get_halign() -> ~gi.repository.Gtk.Align Gets the horizontal alignment of ``widget``. For backwards compatibility reasons this method will never return one of the baseline alignments, but instead it will convert it to ``GTK_ALIGN_FILL`` or ``GTK_ALIGN_CENTER``. Baselines are not supported for horizontal alignment. .. method:: get_has_tooltip() -> bool Returns the current value of the ``has-tooltip`` property. .. method:: get_height() -> int Returns the content height of the widget. This function returns the height passed to its size-allocate implementation, which is the height you should be using in :obj:`~gi.repository.Gtk.Widget.snapshot`. For pointer events, see :obj:`~gi.repository.Gtk.Widget.contains`. To learn more about widget sizes, see the coordinate system `overview `_. .. method:: get_hexpand() -> bool Gets whether the widget would like any available extra horizontal space. When a user resizes a ``GtkWindow``, widgets with expand=TRUE generally receive the extra space. For example, a list or scrollable area or document in your window would often be set to expand. Containers should use :obj:`~gi.repository.Gtk.Widget.compute_expand` rather than this function, to see whether a widget, or any of its children, has the expand flag set. If any child of a widget wants to expand, the parent may ask to expand also. This function only looks at the widget’s own hexpand flag, rather than computing whether the entire widget tree rooted at this widget wants to expand. .. method:: get_hexpand_set() -> bool Gets whether :func:`~gi.repository.Gtk.Widget.set_hexpand` has been used to explicitly set the expand flag on this widget. If :obj:`~gi.repository.Gtk.Widget.props.hexpand` property is set, then it overrides any computed expand value based on child widgets. If ``hexpand`` is not set, then the expand value depends on whether any children of the widget would like to expand. There are few reasons to use this function, but it’s here for completeness and consistency. .. method:: get_last_child() -> ~gi.repository.Gtk.Widget | None Returns the widget’s last child. This API is primarily meant for widget implementations. .. method:: get_layout_manager() -> ~gi.repository.Gtk.LayoutManager | None Retrieves the layout manager used by ``widget``. See :obj:`~gi.repository.Gtk.Widget.set_layout_manager`. .. classmethod:: get_layout_manager_type() -> type .. method:: get_mapped() -> bool Whether the widget is mapped. .. method:: get_margin_bottom() -> int Gets the bottom margin of ``widget``. .. method:: get_margin_end() -> int Gets the end margin of ``widget``. .. method:: get_margin_start() -> int Gets the start margin of ``widget``. .. method:: get_margin_top() -> int Gets the top margin of ``widget``. .. method:: get_name() -> str Retrieves the name of a widget. See :obj:`~gi.repository.Gtk.Widget.set_name` for the significance of widget names. .. method:: get_native() -> ~gi.repository.Gtk.Native | None Returns the nearest ``GtkNative`` ancestor of ``widget``. This function will return :const:`None` if the widget is not contained inside a widget tree with a native ancestor. ``GtkNative`` widgets will return themselves here. .. method:: get_next_sibling() -> ~gi.repository.Gtk.Widget | None Returns the widget’s next sibling. This API is primarily meant for widget implementations. .. method:: get_opacity() -> float ``Fetches`` the requested opacity for this widget. See :obj:`~gi.repository.Gtk.Widget.set_opacity`. .. method:: get_overflow() -> ~gi.repository.Gtk.Overflow Returns the widget’s overflow value. .. method:: get_pango_context() -> ~gi.repository.Pango.Context Gets a ``PangoContext`` with the appropriate font map, font description, and base direction for this widget. Unlike the context returned by :obj:`~gi.repository.Gtk.Widget.create_pango_context`, this context is owned by the widget (it can be used until the screen for the widget changes or the widget is removed from its toplevel), and will be updated to match any changes to the widget’s attributes. This can be tracked by listening to changes of the :obj:`~gi.repository.Gtk.Widget.props.root` property on the widget. .. method:: get_parent() -> ~gi.repository.Gtk.Widget | None Returns the parent widget of ``widget``. .. method:: get_preferred_size() -> tuple[~gi.repository.Gtk.Requisition, ~gi.repository.Gtk.Requisition] Retrieves the minimum and natural size of a widget, taking into account the widget’s preference for height-for-width management. This is used to retrieve a suitable size by container widgets which do not impose any restrictions on the child placement. It can be used to deduce toplevel window and menu sizes as well as child widgets in free-form containers such as ``GtkFixed``. Handle with care. Note that the natural height of a height-for-width widget will generally be a smaller size than the minimum height, since the required height for the natural width is generally smaller than the required height for the minimum width. Use :obj:`~gi.repository.Gtk.Widget.measure` if you want to support baseline alignment. .. method:: get_prev_sibling() -> ~gi.repository.Gtk.Widget | None Returns the widget’s previous sibling. This API is primarily meant for widget implementations. .. method:: get_primary_clipboard() -> ~gi.repository.Gdk.Clipboard Gets the primary clipboard of ``widget``. This is a utility function to get the primary clipboard object for the ``GdkDisplay`` that ``widget`` is using. Note that this function always works, even when ``widget`` is not realized yet. .. method:: get_realized() -> bool Determines whether ``widget`` is realized. .. method:: get_receives_default() -> bool Determines whether ``widget`` is always treated as the default widget within its toplevel when it has the focus, even if another widget is the default. See :obj:`~gi.repository.Gtk.Widget.set_receives_default`. .. method:: get_request_mode() -> ~gi.repository.Gtk.SizeRequestMode Gets whether the widget prefers a height-for-width layout or a width-for-height layout. Single-child widgets generally propagate the preference of their child, more complex widgets need to request something either in context of their children or in context of their allocation capabilities. .. method:: get_root() -> ~gi.repository.Gtk.Root | None Returns the ``GtkRoot`` widget of ``widget``. This function will return :const:`None` if the widget is not contained inside a widget tree with a root widget. ``GtkRoot`` widgets will return themselves here. .. method:: get_scale_factor() -> int Retrieves the internal scale factor that maps from window coordinates to the actual device pixels. On traditional systems this is 1, on high density outputs, it can be a higher value (typically 2). See :obj:`~gi.repository.Gdk.Surface.get_scale_factor`. .. method:: get_sensitive() -> bool Returns the widget’s sensitivity. This function returns the value that has been set using :obj:`~gi.repository.Gtk.Widget.set_sensitive`). The effective sensitivity of a widget is however determined by both its own and its parent widget’s sensitivity. See :obj:`~gi.repository.Gtk.Widget.is_sensitive`. .. method:: get_settings() -> ~gi.repository.Gtk.Settings Gets the settings object holding the settings used for this widget. Note that this function can only be called when the ``GtkWidget`` is attached to a toplevel, since the settings object is specific to a particular ``GdkDisplay``. If you want to monitor the widget for changes in its settings, connect to the ``notify::display`` signal. .. method:: get_size(orientation: ~gi.repository.Gtk.Orientation) -> int Returns the content width or height of the widget. Which dimension is returned depends on ``orientation``. This is equivalent to calling :obj:`~gi.repository.Gtk.Widget.get_width` for :const:`~gi.repository.Gtk.Orientation.HORIZONTAL` or :obj:`~gi.repository.Gtk.Widget.get_height` for :const:`~gi.repository.Gtk.Orientation.VERTICAL`, but can be used when writing orientation-independent code, such as when implementing :obj:`~gi.repository.Gtk.Orientable` widgets. To learn more about widget sizes, see the coordinate system `overview `_. :param orientation: the orientation to query .. method:: get_size_request() -> tuple[int, int] Gets the size request that was explicitly set for the widget using :func:`~gi.repository.Gtk.Widget.set_size_request`. A value of -1 stored in ``width`` or ``height`` indicates that that dimension has not been set explicitly and the natural requisition of the widget will be used instead. See :obj:`~gi.repository.Gtk.Widget.set_size_request`. To get the size a widget will actually request, call :obj:`~gi.repository.Gtk.Widget.measure` instead of this function. .. method:: get_state_flags() -> ~gi.repository.Gtk.StateFlags Returns the widget state as a flag set. It is worth mentioning that the effective :const:`~gi.repository.Gtk.StateFlags.INSENSITIVE` state will be returned, that is, also based on parent insensitivity, even if ``widget`` itself is sensitive. Also note that if you are looking for a way to obtain the :obj:`~gi.repository.Gtk.StateFlags` to pass to a :obj:`~gi.repository.Gtk.StyleContext` method, you should look at :obj:`~gi.repository.Gtk.StyleContext.get_state`. .. method:: get_style_context() -> ~gi.repository.Gtk.StyleContext Returns the style context associated to ``widget``. The returned object is guaranteed to be the same for the lifetime of ``widget``. .. deprecated:: 4.10 Style contexts will be removed in GTK 5 .. method:: get_template_child(widget_type: type, name: str) -> ~gi.repository.GObject.Object Fetch an object build from the template XML for ``widget_type`` in this ``widget`` instance. This will only report children which were previously declared with :obj:`~gi.repository.Gtk.WidgetClass.bind_template_child_full` or one of its variants. This function is only meant to be called for code which is private to the ``widget_type`` which declared the child and is meant for language bindings which cannot easily make use of the GObject structure offsets. :param widget_type: The ``GType`` to get a template child for :param name: The “id” of the child defined in the template XML .. method:: get_tooltip_markup() -> str | None Gets the contents of the tooltip for ``widget``. If the tooltip has not been set using :obj:`~gi.repository.Gtk.Widget.set_tooltip_markup`, this function returns :const:`None`. .. method:: get_tooltip_text() -> str | None Gets the contents of the tooltip for ``widget``. If the ``widget``'s tooltip was set using :obj:`~gi.repository.Gtk.Widget.set_tooltip_markup`, this function will return the escaped text. .. method:: get_valign() -> ~gi.repository.Gtk.Align Gets the vertical alignment of ``widget``. .. method:: get_vexpand() -> bool Gets whether the widget would like any available extra vertical space. See :obj:`~gi.repository.Gtk.Widget.get_hexpand` for more detail. .. method:: get_vexpand_set() -> bool Gets whether :func:`~gi.repository.Gtk.Widget.set_vexpand` has been used to explicitly set the expand flag on this widget. See :obj:`~gi.repository.Gtk.Widget.get_hexpand_set` for more detail. .. method:: get_visible() -> bool Determines whether the widget is visible. If you want to take into account whether the widget’s parent is also marked as visible, use :obj:`~gi.repository.Gtk.Widget.is_visible` instead. This function does not check if the widget is obscured in any way. See :obj:`~gi.repository.Gtk.Widget.set_visible`. .. method:: get_width() -> int Returns the content width of the widget. This function returns the width passed to its size-allocate implementation, which is the width you should be using in :obj:`~gi.repository.Gtk.Widget.snapshot`. For pointer events, see :obj:`~gi.repository.Gtk.Widget.contains`. To learn more about widget sizes, see the coordinate system `overview `_. .. method:: grab_focus() -> bool Causes ``widget`` to have the keyboard focus for the ``GtkWindow`` it's inside. If ``widget`` is not focusable, or its :obj:`~gi.repository.Gtk.Widget.grab_focus` implementation cannot transfer the focus to a descendant of ``widget`` that is focusable, it will not take focus and :const:`False` will be returned. Calling :obj:`~gi.repository.Gtk.Widget.grab_focus` on an already focused widget is allowed, should not have an effect, and return :const:`True`. .. method:: has_css_class(css_class: str) -> bool Returns whether ``css_class`` is currently applied to ``widget``. :param css_class: A style class, without the leading '.' used for notation of style classes .. method:: has_default() -> bool Determines whether ``widget`` is the current default widget within its toplevel. .. method:: has_focus() -> bool Determines if the widget has the global input focus. See :obj:`~gi.repository.Gtk.Widget.is_focus` for the difference between having the global input focus, and only having the focus within a toplevel. .. method:: has_visible_focus() -> bool Determines if the widget should show a visible indication that it has the global input focus. This is a convenience function that takes into account whether focus indication should currently be shown in the toplevel window of ``widget``. See :obj:`~gi.repository.Gtk.Window.get_focus_visible` for more information about focus indication. To find out if the widget has the global input focus, use :obj:`~gi.repository.Gtk.Widget.has_focus`. .. method:: hide() -> None Reverses the effects of :func:`~gi.repository.Gtk.Widget.show`. This is causing the widget to be hidden (invisible to the user). .. deprecated:: 4.10 Use :obj:`~gi.repository.Gtk.Widget.set_visible` instead .. method:: in_destruction() -> bool Returns whether the widget is currently being destroyed. This information can sometimes be used to avoid doing unnecessary work. .. method:: init_template() -> None Creates and initializes child widgets defined in templates. This function must be called in the instance initializer for any class which assigned itself a template using :obj:`~gi.repository.Gtk.WidgetClass.set_template`. It is important to call this function in the instance initializer of a ``GtkWidget`` subclass and not in ``GObject.constructed()`` or ``GObject.constructor()`` for two reasons: - derived widgets will assume that the composite widgets defined by its parent classes have been created in their relative instance initializers - when calling ``:func:`~gi.repository.GObject.GObject.Object.new``` on a widget with composite templates, it’s important to build the composite widgets before the construct properties are set. Properties passed to ``:func:`~gi.repository.GObject.GObject.Object.new``` should take precedence over properties set in the private template XML A good rule of thumb is to call this function as the first thing in an instance initialization function. .. method:: insert_action_group(name: str, group: ~gi.repository.Gio.ActionGroup | None = None) -> None Inserts ``group`` into ``widget``. Children of ``widget`` that implement :obj:`~gi.repository.Gtk.Actionable` can then be associated with actions in ``group`` by setting their “action-name” to ``prefix``.``action-name``. Note that inheritance is defined for individual actions. I.e. even if you insert a group with prefix ``prefix``, actions with the same prefix will still be inherited from the parent, unless the group contains an action with the same name. If ``group`` is :const:`None`, a previously inserted group for ``name`` is removed from ``widget``. :param name: the prefix for actions in ``group`` :param group: a ``GActionGroup``, or :const:`None` to remove the previously inserted group for ``name`` .. method:: insert_after(parent: ~gi.repository.Gtk.Widget, previous_sibling: ~gi.repository.Gtk.Widget | None = None) -> None Inserts ``widget`` into the child widget list of ``parent``. It will be placed after ``previous_sibling``, or at the beginning if ``previous_sibling`` is :const:`None`. After calling this function, ``gtk_widget_get_prev_sibling(widget)`` will return ``previous_sibling``. If ``parent`` is already set as the parent widget of ``widget``, this function can also be used to reorder ``widget`` in the child widget list of ``parent``. This API is primarily meant for widget implementations; if you are just using a widget, you *must* use its own API for adding children. :param parent: the parent ``GtkWidget`` to insert ``widget`` into :param previous_sibling: the new previous sibling of ``widget`` .. method:: insert_before(parent: ~gi.repository.Gtk.Widget, next_sibling: ~gi.repository.Gtk.Widget | None = None) -> None Inserts ``widget`` into the child widget list of ``parent``. It will be placed before ``next_sibling``, or at the end if ``next_sibling`` is :const:`None`. After calling this function, ``gtk_widget_get_next_sibling(widget)`` will return ``next_sibling``. If ``parent`` is already set as the parent widget of ``widget``, this function can also be used to reorder ``widget`` in the child widget list of ``parent``. This API is primarily meant for widget implementations; if you are just using a widget, you *must* use its own API for adding children. :param parent: the parent ``GtkWidget`` to insert ``widget`` into :param next_sibling: the new next sibling of ``widget`` .. classmethod:: install_action(action_name: str, parameter_type: str | None, activate: ~typing.Callable[[~gi.repository.Gtk.Widget, str, ~gi.repository.GLib.Variant | None], None]) -> None :param action_name: :param parameter_type: :param activate: .. classmethod:: install_property_action(action_name: str, property_name: str) -> None :param action_name: :param property_name: .. method:: is_ancestor(ancestor: ~gi.repository.Gtk.Widget) -> bool Determines whether ``widget`` is somewhere inside ``ancestor``, possibly with intermediate containers. :param ancestor: another ``GtkWidget`` .. method:: is_drawable() -> bool Determines whether ``widget`` can be drawn to. A widget can be drawn if it is mapped and visible. .. method:: is_focus() -> bool Determines if the widget is the focus widget within its toplevel. This does not mean that the :obj:`~gi.repository.Gtk.Widget.props.has_focus` property is necessarily set; :obj:`~gi.repository.Gtk.Widget.props.has_focus` will only be set if the toplevel widget additionally has the global input focus. .. method:: is_sensitive() -> bool Returns the widget’s effective sensitivity. This means it is sensitive itself and also its parent widget is sensitive. .. method:: is_visible() -> bool Determines whether the widget and all its parents are marked as visible. This function does not check if the widget is obscured in any way. See also :obj:`~gi.repository.Gtk.Widget.get_visible` and :obj:`~gi.repository.Gtk.Widget.set_visible`. .. method:: keynav_failed(direction: ~gi.repository.Gtk.DirectionType) -> bool Emits the ``::keynav-failed`` signal on the widget. This function should be called whenever keyboard navigation within a single widget hits a boundary. The return value of this function should be interpreted in a way similar to the return value of :obj:`~gi.repository.Gtk.Widget.child_focus`. When :const:`True` is returned, stay in the widget, the failed keyboard navigation is OK and/or there is nowhere we can/should move the focus to. When :const:`False` is returned, the caller should continue with keyboard navigation outside the widget, e.g. by calling :obj:`~gi.repository.Gtk.Widget.child_focus` on the widget’s toplevel. The default :obj:`~gi.repository.Gtk.Widget.signals.keynav_failed` handler returns :const:`False` for :const:`~gi.repository.Gtk.DirectionType.TAB_FORWARD` and :const:`~gi.repository.Gtk.DirectionType.TAB_BACKWARD`. For the other values of ``GtkDirectionType`` it returns :const:`True`. Whenever the default handler returns :const:`True`, it also calls :obj:`~gi.repository.Gtk.Widget.error_bell` to notify the user of the failed keyboard navigation. A use case for providing an own implementation of ::keynav-failed (either by connecting to it or by overriding it) would be a row of :obj:`~gi.repository.Gtk.Entry` widgets where the user should be able to navigate the entire row with the cursor keys, as e.g. known from user interfaces that require entering license keys. :param direction: direction of focus movement .. method:: list_mnemonic_labels() -> list[~gi.repository.Gtk.Widget] Returns the widgets for which this widget is the target of a mnemonic. Typically, these widgets will be labels. See, for example, :obj:`~gi.repository.Gtk.Label.set_mnemonic_widget`. The widgets in the list are not individually referenced. If you want to iterate through the list and perform actions involving callbacks that might destroy the widgets, you must call `g_list_foreach (result, (GFunc)g_object_ref, NULL)` first, and then unref all the widgets afterwards. .. method:: map() -> None Causes a widget to be mapped if it isn’t already. This function is only for use in widget implementations. .. method:: measure(orientation: ~gi.repository.Gtk.Orientation, for_size: int) -> tuple[int, int, int, int] Measures ``widget`` in the orientation ``orientation`` and for the given ``for_size``. As an example, if ``orientation`` is :const:`~gi.repository.Gtk.Orientation.HORIZONTAL` and ``for_size`` is 300, this functions will compute the minimum and natural width of ``widget`` if it is allocated at a height of 300 pixels. See `GtkWidget’s geometry management section `_ for a more details on implementing ``GtkWidgetClass.measure()``. :param orientation: the orientation to measure :param for_size: Size for the opposite of ``orientation``, i.e. if ``orientation`` is :const:`~gi.repository.Gtk.Orientation.HORIZONTAL`, this is the height the widget should be measured with. The :const:`~gi.repository.Gtk.Orientation.VERTICAL` case is analogous. This way, both height-for-width and width-for-height requests can be implemented. If no size is known, -1 can be passed. .. method:: mnemonic_activate(group_cycling: bool) -> bool Emits the ::mnemonic-activate signal. See :obj:`~gi.repository.Gtk.Widget.signals.mnemonic_activate`. :param group_cycling: :const:`True` if there are other widgets with the same mnemonic .. method:: observe_children() -> ~gi.repository.Gio.ListModel Returns a ``GListModel`` to track the children of ``widget``. Calling this function will enable extra internal bookkeeping to track children and emit signals on the returned listmodel. It may slow down operations a lot. Applications should try hard to avoid calling this function because of the slowdowns. .. method:: observe_controllers() -> ~gi.repository.Gio.ListModel Returns a ``GListModel`` to track the :obj:`~gi.repository.Gtk.EventController`'s of ``widget``. Calling this function will enable extra internal bookkeeping to track controllers and emit signals on the returned listmodel. It may slow down operations a lot. Applications should try hard to avoid calling this function because of the slowdowns. .. method:: pick(x: float, y: float, flags: ~gi.repository.Gtk.PickFlags) -> ~gi.repository.Gtk.Widget | None Finds the descendant of ``widget`` closest to the point (``x``, ``y``). The point must be given in widget coordinates, so (0, 0) is assumed to be the top left of ``widget``'s content area. Usually widgets will return :const:`None` if the given coordinate is not contained in ``widget`` checked via :obj:`~gi.repository.Gtk.Widget.contains`. Otherwise they will recursively try to find a child that does not return :const:`None`. Widgets are however free to customize their picking algorithm. This function is used on the toplevel to determine the widget below the mouse cursor for purposes of hover highlighting and delivering events. :param x: X coordinate to test, relative to ``widget``'s origin :param y: Y coordinate to test, relative to ``widget``'s origin :param flags: Flags to influence what is picked .. classmethod:: query_action(index_: int) -> tuple[bool, type, str, ~gi.repository.GLib.VariantType, str] :param index_: .. method:: queue_allocate() -> None Flags the widget for a rerun of the :obj:`~gi.repository.Gtk.Widget.size_allocate` function. Use this function instead of :obj:`~gi.repository.Gtk.Widget.queue_resize` when the ``widget``'s size request didn't change but it wants to reposition its contents. An example user of this function is :obj:`~gi.repository.Gtk.Widget.set_halign`. This function is only for use in widget implementations. .. method:: queue_draw() -> None Schedules this widget to be redrawn in the paint phase of the current or the next frame. This means ``widget``'s :obj:`~gi.repository.Gtk.Widget.snapshot` implementation will be called. .. method:: queue_resize() -> None Flags a widget to have its size renegotiated. This should be called when a widget for some reason has a new size request. For example, when you change the text in a :obj:`~gi.repository.Gtk.Label`, the label queues a resize to ensure there’s enough space for the new text. Note that you cannot call :func:`~gi.repository.Gtk.Widget.queue_resize` on a widget from inside its implementation of the :obj:`~gi.repository.Gtk.Widget.size_allocate` virtual method. Calls to :func:`~gi.repository.Gtk.Widget.queue_resize` from inside :obj:`~gi.repository.Gtk.Widget.size_allocate` will be silently ignored. This function is only for use in widget implementations. .. method:: realize() -> None Creates the GDK resources associated with a widget. Normally realization happens implicitly; if you show a widget and all its parent containers, then the widget will be realized and mapped automatically. Realizing a widget requires all the widget’s parent widgets to be realized; calling this function realizes the widget’s parents in addition to ``widget`` itself. If a widget is not yet inside a toplevel window when you realize it, bad things will happen. This function is primarily used in widget implementations, and isn’t very useful otherwise. Many times when you think you might need it, a better approach is to connect to a signal that will be called after the widget is realized automatically, such as :obj:`~gi.repository.Gtk.Widget.signals.realize`. .. method:: remove_controller(controller: ~gi.repository.Gtk.EventController) -> None Removes ``controller`` from ``widget``, so that it doesn't process events anymore. It should not be used again. Widgets will remove all event controllers automatically when they are destroyed, there is normally no need to call this function. :param controller: a ``GtkEventController`` .. method:: remove_css_class(css_class: str) -> None Removes a style from ``widget``. After this, the style of ``widget`` will stop matching for ``css_class``. :param css_class: The style class to remove from ``widget``, without the leading '.' used for notation of style classes .. method:: remove_mnemonic_label(label: ~gi.repository.Gtk.Widget) -> None Removes a widget from the list of mnemonic labels for this widget. See :obj:`~gi.repository.Gtk.Widget.list_mnemonic_labels`. The widget must have previously been added to the list with :obj:`~gi.repository.Gtk.Widget.add_mnemonic_label`. :param label: a ``GtkWidget`` that was previously set as a mnemonic label for ``widget`` with :obj:`~gi.repository.Gtk.Widget.add_mnemonic_label` .. method:: remove_tick_callback(id: int) -> None Removes a tick callback previously registered with :func:`~gi.repository.Gtk.Widget.add_tick_callback`. :param id: an id returned by :obj:`~gi.repository.Gtk.Widget.add_tick_callback` .. classmethod:: set_accessible_role(accessible_role: ~gi.repository.Gtk.AccessibleRole) -> None :param accessible_role: .. classmethod:: set_activate_signal(signal_id: int) -> None :param signal_id: .. classmethod:: set_activate_signal_from_name(signal_name: str) -> None :param signal_name: .. method:: set_can_focus(can_focus: bool) -> None Specifies whether the input focus can enter the widget or any of its children. Applications should set ``can_focus`` to :const:`False` to mark a widget as for pointer/touch use only. Note that having ``can_focus`` be :const:`True` is only one of the necessary conditions for being focusable. A widget must also be sensitive and focusable and not have an ancestor that is marked as not can-focus in order to receive input focus. See :obj:`~gi.repository.Gtk.Widget.grab_focus` for actually setting the input focus on a widget. :param can_focus: whether or not the input focus can enter the widget or any of its children .. method:: set_can_target(can_target: bool) -> None Sets whether ``widget`` can be the target of pointer events. :param can_target: whether this widget should be able to receive pointer events .. method:: set_child_visible(child_visible: bool) -> None Sets whether ``widget`` should be mapped along with its parent. The child visibility can be set for widget before it is added to a container with :obj:`~gi.repository.Gtk.Widget.set_parent`, to avoid mapping children unnecessary before immediately unmapping them. However it will be reset to its default state of :const:`True` when the widget is removed from a container. Note that changing the child visibility of a widget does not queue a resize on the widget. Most of the time, the size of a widget is computed from all visible children, whether or not they are mapped. If this is not the case, the container can queue a resize itself. This function is only useful for container implementations and should never be called by an application. :param child_visible: if :const:`True`, ``widget`` should be mapped along with its parent. .. method:: set_css_classes(classes: ~typing.Sequence[str]) -> None Clear all style classes applied to ``widget`` and replace them with ``classes``. :param classes: :const:`None`-terminated list of style classes to apply to ``widget``. .. classmethod:: set_css_name(name: str) -> None :param name: .. method:: set_cursor(cursor: ~gi.repository.Gdk.Cursor | None = None) -> None Sets the cursor to be shown when pointer devices point towards ``widget``. If the ``cursor`` is NULL, ``widget`` will use the cursor inherited from the parent widget. :param cursor: the new cursor .. method:: set_cursor_from_name(name: str | None = None) -> None Sets a named cursor to be shown when pointer devices point towards ``widget``. This is a utility function that creates a cursor via :obj:`~gi.repository.Gdk.Cursor.new_from_name` and then sets it on ``widget`` with :obj:`~gi.repository.Gtk.Widget.set_cursor`. See those functions for details. On top of that, this function allows ``name`` to be :const:`None`, which will do the same as calling :obj:`~gi.repository.Gtk.Widget.set_cursor` with a :const:`None` cursor. :param name: The name of the cursor .. method:: set_default_direction(dir: ~gi.repository.Gtk.TextDirection) -> None Sets the default reading direction for widgets. See :obj:`~gi.repository.Gtk.Widget.set_direction`. :param dir: the new default direction. This cannot be :const:`~gi.repository.Gtk.TextDirection.NONE`. .. method:: set_direction(dir: ~gi.repository.Gtk.TextDirection) -> None Sets the reading direction on a particular widget. This direction controls the primary direction for widgets containing text, and also the direction in which the children of a container are packed. The ability to set the direction is present in order so that correct localization into languages with right-to-left reading directions can be done. Generally, applications will let the default reading direction present, except for containers where the containers are arranged in an order that is explicitly visual rather than logical (such as buttons for text justification). If the direction is set to :const:`~gi.repository.Gtk.TextDirection.NONE`, then the value set by :obj:`~gi.repository.Gtk.Widget.set_default_direction` will be used. :param dir: the new direction .. method:: set_focus_child(child: ~gi.repository.Gtk.Widget | None = None) -> None Set ``child`` as the current focus child of ``widget``. This function is only suitable for widget implementations. If you want a certain widget to get the input focus, call :obj:`~gi.repository.Gtk.Widget.grab_focus` on it. :param child: a direct child widget of ``widget`` or :const:`None` to unset the focus child of ``widget`` .. method:: set_focus_on_click(focus_on_click: bool) -> None Sets whether the widget should grab focus when it is clicked with the mouse. Making mouse clicks not grab focus is useful in places like toolbars where you don’t want the keyboard focus removed from the main area of the application. :param focus_on_click: whether the widget should grab focus when clicked with the mouse .. method:: set_focusable(focusable: bool) -> None Specifies whether ``widget`` can own the input focus. Widget implementations should set ``focusable`` to :const:`True` in their init() function if they want to receive keyboard input. Note that having ``focusable`` be :const:`True` is only one of the necessary conditions for being focusable. A widget must also be sensitive and can-focus and not have an ancestor that is marked as not can-focus in order to receive input focus. See :obj:`~gi.repository.Gtk.Widget.grab_focus` for actually setting the input focus on a widget. :param focusable: whether or not ``widget`` can own the input focus .. method:: set_font_map(font_map: ~gi.repository.Pango.FontMap | None = None) -> None Sets the font map to use for Pango rendering. The font map is the object that is used to look up fonts. Setting a custom font map can be useful in special situations, e.g. when you need to add application-specific fonts to the set of available fonts. When not set, the widget will inherit the font map from its parent. :param font_map: a ``PangoFontMap``, or :const:`None` to unset any previously set font map .. method:: set_font_options(options: ~gi.repository.cairo.FontOptions | None = None) -> None Sets the ``cairo_font_options_t`` used for Pango rendering in this widget. When not set, the default font options for the ``GdkDisplay`` will be used. :param options: a ``cairo_font_options_t`` to unset any previously set default font options .. method:: set_halign(align: ~gi.repository.Gtk.Align) -> None Sets the horizontal alignment of ``widget``. :param align: the horizontal alignment .. method:: set_has_tooltip(has_tooltip: bool) -> None Sets the ``has-tooltip`` property on ``widget`` to ``has_tooltip``. :param has_tooltip: whether or not ``widget`` has a tooltip. .. method:: set_hexpand(expand: bool) -> None Sets whether the widget would like any available extra horizontal space. When a user resizes a ``GtkWindow``, widgets with expand=TRUE generally receive the extra space. For example, a list or scrollable area or document in your window would often be set to expand. Call this function to set the expand flag if you would like your widget to become larger horizontally when the window has extra room. By default, widgets automatically expand if any of their children want to expand. (To see if a widget will automatically expand given its current children and state, call :obj:`~gi.repository.Gtk.Widget.compute_expand`. A container can decide how the expandability of children affects the expansion of the container by overriding the compute_expand virtual method on ``GtkWidget``.). Setting hexpand explicitly with this function will override the automatic expand behavior. This function forces the widget to expand or not to expand, regardless of children. The override occurs because :obj:`~gi.repository.Gtk.Widget.set_hexpand` sets the hexpand-set property (see :obj:`~gi.repository.Gtk.Widget.set_hexpand_set`) which causes the widget’s hexpand value to be used, rather than looking at children and widget state. :param expand: whether to expand .. method:: set_hexpand_set(set: bool) -> None Sets whether the hexpand flag will be used. The :obj:`~gi.repository.Gtk.Widget.props.hexpand_set` property will be set automatically when you call :obj:`~gi.repository.Gtk.Widget.set_hexpand` to set hexpand, so the most likely reason to use this function would be to unset an explicit expand flag. If hexpand is set, then it overrides any computed expand value based on child widgets. If hexpand is not set, then the expand value depends on whether any children of the widget would like to expand. There are few reasons to use this function, but it’s here for completeness and consistency. :param set: value for hexpand-set property .. method:: set_layout_manager(layout_manager: ~gi.repository.Gtk.LayoutManager | None = None) -> None Sets the layout manager delegate instance that provides an implementation for measuring and allocating the children of ``widget``. :param layout_manager: a ``GtkLayoutManager`` .. classmethod:: set_layout_manager_type(type: type) -> None :param type: .. method:: set_margin_bottom(margin: int) -> None Sets the bottom margin of ``widget``. :param margin: the bottom margin .. method:: set_margin_end(margin: int) -> None Sets the end margin of ``widget``. :param margin: the end margin .. method:: set_margin_start(margin: int) -> None Sets the start margin of ``widget``. :param margin: the start margin .. method:: set_margin_top(margin: int) -> None Sets the top margin of ``widget``. :param margin: the top margin .. method:: set_name(name: str) -> None Sets a widgets name. Setting a name allows you to refer to the widget from a CSS file. You can apply a style to widgets with a particular name in the CSS file. See the documentation for the CSS syntax (on the same page as the docs for :obj:`~gi.repository.Gtk.StyleContext`. Note that the CSS syntax has certain special characters to delimit and represent elements in a selector (period, #, >, *...), so using these will make your widget impossible to match by name. Any combination of alphanumeric symbols, dashes and underscores will suffice. :param name: name for the widget .. method:: set_opacity(opacity: float) -> None Request the ``widget`` to be rendered partially transparent. An opacity of 0 is fully transparent and an opacity of 1 is fully opaque. Opacity works on both toplevel widgets and child widgets, although there are some limitations: For toplevel widgets, applying opacity depends on the capabilities of the windowing system. On X11, this has any effect only on X displays with a compositing manager, see :func:`~gi.repository.Gdk.Display.is_composited`. On Windows and Wayland it should always work, although setting a window’s opacity after the window has been shown may cause some flicker. Note that the opacity is inherited through inclusion — if you set a toplevel to be partially translucent, all of its content will appear translucent, since it is ultimatively rendered on that toplevel. The opacity value itself is not inherited by child widgets (since that would make widgets deeper in the hierarchy progressively more translucent). As a consequence, :obj:`~gi.repository.Gtk.Popover`'s and other :obj:`~gi.repository.Gtk.Native` widgets with their own surface will use their own opacity value, and thus by default appear non-translucent, even if they are attached to a toplevel that is translucent. :param opacity: desired opacity, between 0 and 1 .. method:: set_overflow(overflow: ~gi.repository.Gtk.Overflow) -> None Sets how ``widget`` treats content that is drawn outside the widget's content area. See the definition of :obj:`~gi.repository.Gtk.Overflow` for details. This setting is provided for widget implementations and should not be used by application code. The default value is :const:`~gi.repository.Gtk.Overflow.VISIBLE`. :param overflow: desired overflow .. method:: set_parent(parent: ~gi.repository.Gtk.Widget) -> None Sets ``parent`` as the parent widget of ``widget``. This takes care of details such as updating the state and style of the child to reflect its new location and resizing the parent. The opposite function is :obj:`~gi.repository.Gtk.Widget.unparent`. This function is useful only when implementing subclasses of ``GtkWidget``. :param parent: parent widget .. method:: set_receives_default(receives_default: bool) -> None Specifies whether ``widget`` will be treated as the default widget within its toplevel when it has the focus, even if another widget is the default. :param receives_default: whether or not ``widget`` can be a default widget. .. method:: set_sensitive(sensitive: bool) -> None Sets the sensitivity of a widget. A widget is sensitive if the user can interact with it. Insensitive widgets are “grayed out” and the user can’t interact with them. Insensitive widgets are known as “inactive”, “disabled”, or “ghosted” in some other toolkits. :param sensitive: :const:`True` to make the widget sensitive .. method:: set_size_request(width: int, height: int) -> None Sets the minimum size of a widget. That is, the widget’s size request will be at least ``width`` by ``height``. You can use this function to force a widget to be larger than it normally would be. In most cases, :obj:`~gi.repository.Gtk.Window.set_default_size` is a better choice for toplevel windows than this function; setting the default size will still allow users to shrink the window. Setting the size request will force them to leave the window at least as large as the size request. Note the inherent danger of setting any fixed size - themes, translations into other languages, different fonts, and user action can all change the appropriate size for a given widget. So, it's basically impossible to hardcode a size that will always be correct. The size request of a widget is the smallest size a widget can accept while still functioning well and drawing itself correctly. However in some strange cases a widget may be allocated less than its requested size, and in many cases a widget may be allocated more space than it requested. If the size request in a given direction is -1 (unset), then the “natural” size request of the widget will be used instead. The size request set here does not include any margin from the properties :obj:`~gi.repository.Gtk.Widget.props.margin_start`, :obj:`~gi.repository.Gtk.Widget.props.margin_end`, :obj:`~gi.repository.Gtk.Widget.props.margin_top`, and :obj:`~gi.repository.Gtk.Widget.props.margin_bottom`, but it does include pretty much all other padding or border properties set by any subclass of ``GtkWidget``. :param width: width ``widget`` should request, or -1 to unset :param height: height ``widget`` should request, or -1 to unset .. method:: set_state_flags(flags: ~gi.repository.Gtk.StateFlags, clear: bool) -> None Turns on flag values in the current widget state. Typical widget states are insensitive, prelighted, etc. This function accepts the values :const:`~gi.repository.Gtk.StateFlags.DIR_LTR` and :const:`~gi.repository.Gtk.StateFlags.DIR_RTL` but ignores them. If you want to set the widget's direction, use :obj:`~gi.repository.Gtk.Widget.set_direction`. This function is for use in widget implementations. :param flags: State flags to turn on :param clear: Whether to clear state before turning on ``flags`` .. classmethod:: set_template(template_bytes: ~gi.repository.GLib.Bytes) -> None :param template_bytes: .. classmethod:: set_template_from_resource(resource_name: str) -> None :param resource_name: .. classmethod:: set_template_scope(scope: ~gi.repository.Gtk.BuilderScope) -> None :param scope: .. method:: set_tooltip_markup(markup: str | None = None) -> None Sets ``markup`` as the contents of the tooltip, which is marked up with Pango markup. This function will take care of setting the :obj:`~gi.repository.Gtk.Widget.props.has_tooltip` as a side effect, and of the default handler for the :obj:`~gi.repository.Gtk.Widget.signals.query_tooltip` signal. See also :obj:`~gi.repository.Gtk.Tooltip.set_markup`. :param markup: the contents of the tooltip for ``widget`` .. method:: set_tooltip_text(text: str | None = None) -> None Sets ``text`` as the contents of the tooltip. If ``text`` contains any markup, it will be escaped. This function will take care of setting :obj:`~gi.repository.Gtk.Widget.props.has_tooltip` as a side effect, and of the default handler for the :obj:`~gi.repository.Gtk.Widget.signals.query_tooltip` signal. See also :obj:`~gi.repository.Gtk.Tooltip.set_text`. :param text: the contents of the tooltip for ``widget`` .. method:: set_valign(align: ~gi.repository.Gtk.Align) -> None Sets the vertical alignment of ``widget``. :param align: the vertical alignment .. method:: set_vexpand(expand: bool) -> None Sets whether the widget would like any available extra vertical space. See :obj:`~gi.repository.Gtk.Widget.set_hexpand` for more detail. :param expand: whether to expand .. method:: set_vexpand_set(set: bool) -> None Sets whether the vexpand flag will be used. See :obj:`~gi.repository.Gtk.Widget.set_hexpand_set` for more detail. :param set: value for vexpand-set property .. method:: set_visible(visible: bool) -> None Sets the visibility state of ``widget``. Note that setting this to :const:`True` doesn’t mean the widget is actually viewable, see :obj:`~gi.repository.Gtk.Widget.get_visible`. :param visible: whether the widget should be shown or not .. method:: should_layout() -> bool Returns whether ``widget`` should contribute to the measuring and allocation of its parent. This is :const:`False` for invisible children, but also for children that have their own surface. .. method:: show() -> None Flags a widget to be displayed. Any widget that isn’t shown will not appear on the screen. Remember that you have to show the containers containing a widget, in addition to the widget itself, before it will appear onscreen. When a toplevel container is shown, it is immediately realized and mapped; other shown widgets are realized and mapped when their toplevel container is realized and mapped. .. deprecated:: 4.10 Use :obj:`~gi.repository.Gtk.Widget.set_visible` instead .. method:: size_allocate(allocation: ~gi.repository.Gdk.Rectangle, baseline: int) -> None Allocates widget with a transformation that translates the origin to the position in ``allocation``. This is a simple form of :obj:`~gi.repository.Gtk.Widget.allocate`. :param allocation: position and size to be allocated to ``widget`` :param baseline: The baseline of the child, or -1 .. method:: snapshot_child(child: ~gi.repository.Gtk.Widget, snapshot: ~gi.repository.Gtk.Snapshot) -> None Snapshot the a child of ``widget``. When a widget receives a call to the snapshot function, it must send synthetic :obj:`~gi.repository.Gtk.Widget.snapshot` calls to all children. This function provides a convenient way of doing this. A widget, when it receives a call to its :obj:`~gi.repository.Gtk.Widget.snapshot` function, calls :func:`~gi.repository.Gtk.Widget.snapshot_child` once for each child, passing in the ``snapshot`` the widget received. :func:`~gi.repository.Gtk.Widget.snapshot_child` takes care of translating the origin of ``snapshot``, and deciding whether the child needs to be snapshot. This function does nothing for children that implement ``GtkNative``. :param child: a child of ``widget`` :param snapshot: ``GtkSnapshot`` as passed to the widget. In particular, no calls to :func:`~gi.repository.Gtk.Snapshot.translate` or other transform calls should have been made. .. method:: translate_coordinates(dest_widget: ~gi.repository.Gtk.Widget, src_x: float, src_y: float) -> tuple[bool, float, float] Translate coordinates relative to ``src_widget``’s allocation to coordinates relative to ``dest_widget``’s allocations. In order to perform this operation, both widget must share a common ancestor. .. deprecated:: 4.12 Use :func:`~gi.repository.Gtk.Widget.compute_point` instead :param dest_widget: a ``GtkWidget`` :param src_x: X position relative to ``src_widget`` :param src_y: Y position relative to ``src_widget`` .. method:: trigger_tooltip_query() -> None Triggers a tooltip query on the display where the toplevel of ``widget`` is located. .. method:: unmap() -> None Causes a widget to be unmapped if it’s currently mapped. This function is only for use in widget implementations. .. method:: unparent() -> None Dissociate ``widget`` from its parent. This function is only for use in widget implementations, typically in dispose. .. method:: unrealize() -> None Causes a widget to be unrealized (frees all GDK resources associated with the widget). This function is only useful in widget implementations. .. method:: unset_state_flags(flags: ~gi.repository.Gtk.StateFlags) -> None Turns off flag values for the current widget state. See :obj:`~gi.repository.Gtk.Widget.set_state_flags`. This function is for use in widget implementations. :param flags: State flags to turn off Properties ---------- .. rst-class:: interim-class .. class:: Widget :no-index: .. attribute:: props.can_focus :type: bool Whether the widget or any of its descendents can accept the input focus. This property is meant to be set by widget implementations, typically in their instance init function. .. attribute:: props.can_target :type: bool Whether the widget can receive pointer events. .. attribute:: props.css_classes :type: ~typing.Sequence[str] A list of css classes applied to this widget. .. attribute:: props.css_name :type: str The name of this widget in the CSS tree. This property is meant to be set by widget implementations, typically in their instance init function. .. attribute:: props.cursor :type: ~gi.repository.Gdk.Cursor The cursor used by ``widget``. .. attribute:: props.focus_on_click :type: bool Whether the widget should grab focus when it is clicked with the mouse. This property is only relevant for widgets that can take focus. .. attribute:: props.focusable :type: bool Whether this widget itself will accept the input focus. .. attribute:: props.halign :type: ~gi.repository.Gtk.Align How to distribute horizontal space if widget gets extra space. .. attribute:: props.has_default :type: bool Whether the widget is the default widget. .. attribute:: props.has_focus :type: bool Whether the widget has the input focus. .. attribute:: props.has_tooltip :type: bool Enables or disables the emission of the ::query-tooltip signal on ``widget``. A value of :const:`True` indicates that ``widget`` can have a tooltip, in this case the widget will be queried using :obj:`~gi.repository.Gtk.Widget.signals.query_tooltip` to determine whether it will provide a tooltip or not. .. attribute:: props.height_request :type: int Override for height request of the widget. If this is -1, the natural request will be used. .. attribute:: props.hexpand :type: bool Whether to expand horizontally. .. attribute:: props.hexpand_set :type: bool Whether to use the ``hexpand`` property. .. attribute:: props.layout_manager :type: ~gi.repository.Gtk.LayoutManager The ``GtkLayoutManager`` instance to use to compute the preferred size of the widget, and allocate its children. This property is meant to be set by widget implementations, typically in their instance init function. .. attribute:: props.margin_bottom :type: int Margin on bottom side of widget. This property adds margin outside of the widget's normal size request, the margin will be added in addition to the size from :obj:`~gi.repository.Gtk.Widget.set_size_request` for example. .. attribute:: props.margin_end :type: int Margin on end of widget, horizontally. This property supports left-to-right and right-to-left text directions. This property adds margin outside of the widget's normal size request, the margin will be added in addition to the size from :obj:`~gi.repository.Gtk.Widget.set_size_request` for example. .. attribute:: props.margin_start :type: int Margin on start of widget, horizontally. This property supports left-to-right and right-to-left text directions. This property adds margin outside of the widget's normal size request, the margin will be added in addition to the size from :obj:`~gi.repository.Gtk.Widget.set_size_request` for example. .. attribute:: props.margin_top :type: int Margin on top side of widget. This property adds margin outside of the widget's normal size request, the margin will be added in addition to the size from :obj:`~gi.repository.Gtk.Widget.set_size_request` for example. .. attribute:: props.name :type: str The name of the widget. .. attribute:: props.opacity :type: float The requested opacity of the widget. .. attribute:: props.overflow :type: ~gi.repository.Gtk.Overflow How content outside the widget's content area is treated. This property is meant to be set by widget implementations, typically in their instance init function. .. attribute:: props.parent :type: ~gi.repository.Gtk.Widget The parent widget of this widget. .. attribute:: props.receives_default :type: bool Whether the widget will receive the default action when it is focused. .. attribute:: props.root :type: ~gi.repository.Gtk.Root The ``GtkRoot`` widget of the widget tree containing this widget. This will be :const:`None` if the widget is not contained in a root widget. .. attribute:: props.scale_factor :type: int The scale factor of the widget. .. attribute:: props.sensitive :type: bool Whether the widget responds to input. .. attribute:: props.tooltip_markup :type: str Sets the text of tooltip to be the given string, which is marked up with Pango markup. Also see :obj:`~gi.repository.Gtk.Tooltip.set_markup`. This is a convenience property which will take care of getting the tooltip shown if the given string is not :const:`None`: :obj:`~gi.repository.Gtk.Widget.props.has_tooltip` will automatically be set to :const:`True` and there will be taken care of :obj:`~gi.repository.Gtk.Widget.signals.query_tooltip` in the default signal handler. Note that if both :obj:`~gi.repository.Gtk.Widget.props.tooltip_text` and :obj:`~gi.repository.Gtk.Widget.props.tooltip_markup` are set, the last one wins. .. attribute:: props.tooltip_text :type: str Sets the text of tooltip to be the given string. Also see :obj:`~gi.repository.Gtk.Tooltip.set_text`. This is a convenience property which will take care of getting the tooltip shown if the given string is not :const:`None`: :obj:`~gi.repository.Gtk.Widget.props.has_tooltip` will automatically be set to :const:`True` and there will be taken care of :obj:`~gi.repository.Gtk.Widget.signals.query_tooltip` in the default signal handler. Note that if both :obj:`~gi.repository.Gtk.Widget.props.tooltip_text` and :obj:`~gi.repository.Gtk.Widget.props.tooltip_markup` are set, the last one wins. .. attribute:: props.valign :type: ~gi.repository.Gtk.Align How to distribute vertical space if widget gets extra space. .. attribute:: props.vexpand :type: bool Whether to expand vertically. .. attribute:: props.vexpand_set :type: bool Whether to use the ``vexpand`` property. .. attribute:: props.visible :type: bool Whether the widget is visible. .. attribute:: props.width_request :type: int Override for width request of the widget. If this is -1, the natural request will be used. Signals ------- .. rst-class:: interim-class .. class:: Widget.signals :no-index: .. method:: destroy() -> None Signals that all holders of a reference to the widget should release the reference that they hold. May result in finalization of the widget if all references are released. This signal is not suitable for saving widget state. .. method:: direction_changed(previous_direction: ~gi.repository.Gtk.TextDirection) -> None Emitted when the text direction of a widget changes. :param previous_direction: the previous text direction of ``widget`` .. method:: hide() -> None Emitted when ``widget`` is hidden. .. method:: keynav_failed(direction: ~gi.repository.Gtk.DirectionType) -> bool Emitted if keyboard navigation fails. See :obj:`~gi.repository.Gtk.Widget.keynav_failed` for details. :param direction: the direction of movement .. method:: map() -> None Emitted when ``widget`` is going to be mapped. A widget is mapped when the widget is visible (which is controlled with :obj:`~gi.repository.Gtk.Widget.props.visible`) and all its parents up to the toplevel widget are also visible. The ::map signal can be used to determine whether a widget will be drawn, for instance it can resume an animation that was stopped during the emission of :obj:`~gi.repository.Gtk.Widget.signals.unmap`. .. method:: mnemonic_activate(group_cycling: bool) -> bool Emitted when a widget is activated via a mnemonic. The default handler for this signal activates ``widget`` if ``group_cycling`` is :const:`False`, or just makes ``widget`` grab focus if ``group_cycling`` is :const:`True`. :param group_cycling: :const:`True` if there are other widgets with the same mnemonic .. method:: move_focus(direction: ~gi.repository.Gtk.DirectionType) -> None Emitted when the focus is moved. The ::move-focus signal is a `keybinding signal `_. The default bindings for this signal are :kbd:`Tab` to move forward, and :kbd:`Shift`+:kbd:`Tab` to move backward. :param direction: the direction of the focus move .. method:: query_tooltip(x: int, y: int, keyboard_mode: bool, tooltip: ~gi.repository.Gtk.Tooltip) -> bool Emitted when the widget’s tooltip is about to be shown. This happens when the :obj:`~gi.repository.Gtk.Widget.props.has_tooltip` property is :const:`True` and the hover timeout has expired with the cursor hovering "above" ``widget``; or emitted when ``widget`` got focus in keyboard mode. Using the given coordinates, the signal handler should determine whether a tooltip should be shown for ``widget``. If this is the case :const:`True` should be returned, :const:`False` otherwise. Note that if ``keyboard_mode`` is :const:`True`, the values of ``x`` and ``y`` are undefined and should not be used. The signal handler is free to manipulate ``tooltip`` with the therefore destined function calls. :param x: the x coordinate of the cursor position where the request has been emitted, relative to ``widget``'s left side :param y: the y coordinate of the cursor position where the request has been emitted, relative to ``widget``'s top :param keyboard_mode: :const:`True` if the tooltip was triggered using the keyboard :param tooltip: a ``GtkTooltip`` .. method:: realize() -> None Emitted when ``widget`` is associated with a ``GdkSurface``. This means that :obj:`~gi.repository.Gtk.Widget.realize` has been called or the widget has been mapped (that is, it is going to be drawn). .. method:: show() -> None Emitted when ``widget`` is shown. .. method:: state_flags_changed(flags: ~gi.repository.Gtk.StateFlags) -> None Emitted when the widget state changes. See :obj:`~gi.repository.Gtk.Widget.get_state_flags`. :param flags: The previous state flags. .. method:: unmap() -> None Emitted when ``widget`` is going to be unmapped. A widget is unmapped when either it or any of its parents up to the toplevel widget have been set as hidden. As ::unmap indicates that a widget will not be shown any longer, it can be used to, for example, stop an animation on the widget. .. method:: unrealize() -> None Emitted when the ``GdkSurface`` associated with ``widget`` is destroyed. This means that :obj:`~gi.repository.Gtk.Widget.unrealize` has been called or the widget has been unmapped (that is, it is going to be hidden). Virtual Methods --------------- .. rst-class:: interim-class .. class:: Widget :no-index: .. method:: do_compute_expand(hexpand_p: bool, vexpand_p: bool) -> None Computes whether a container should give this widget extra space when possible. :param hexpand_p: :param vexpand_p: .. method:: do_contains(x: float, y: float) -> bool Tests if the point at (``x``, ``y``) is contained in ``widget``. The coordinates for (``x``, ``y``) must be in widget coordinates, so (0, 0) is assumed to be the top left of ``widget``'s content area. :param x: X coordinate to test, relative to ``widget``'s origin :param y: Y coordinate to test, relative to ``widget``'s origin .. method:: do_css_changed(change: ~gi.repository.Gtk.CssStyleChange) -> None Vfunc called when the CSS used by widget was changed. Widgets should then discard their caches that depend on CSS and queue resizes or redraws accordingly. The default implementation will take care of this for all the default CSS properties, so implementations must chain up. :param change: .. method:: do_direction_changed(previous_direction: ~gi.repository.Gtk.TextDirection) -> None Signal emitted when the text direction of a widget changes. :param previous_direction: .. method:: do_focus(direction: ~gi.repository.Gtk.DirectionType) -> bool Vfunc for :func:`~gi.repository.Gtk.Widget.child_focus` :param direction: .. method:: do_get_request_mode() -> ~gi.repository.Gtk.SizeRequestMode Gets whether the widget prefers a height-for-width layout or a width-for-height layout. Single-child widgets generally propagate the preference of their child, more complex widgets need to request something either in context of their children or in context of their allocation capabilities. .. method:: do_grab_focus() -> bool Causes ``widget`` to have the keyboard focus for the ``GtkWindow`` it's inside. If ``widget`` is not focusable, or its :obj:`~gi.repository.Gtk.Widget.grab_focus` implementation cannot transfer the focus to a descendant of ``widget`` that is focusable, it will not take focus and :const:`False` will be returned. Calling :obj:`~gi.repository.Gtk.Widget.grab_focus` on an already focused widget is allowed, should not have an effect, and return :const:`True`. .. method:: do_hide() -> None Reverses the effects of :func:`~gi.repository.Gtk.Widget.show`. This is causing the widget to be hidden (invisible to the user). .. deprecated:: 4.10 Use :obj:`~gi.repository.Gtk.Widget.set_visible` instead .. method:: do_keynav_failed(direction: ~gi.repository.Gtk.DirectionType) -> bool Emits the ``::keynav-failed`` signal on the widget. This function should be called whenever keyboard navigation within a single widget hits a boundary. The return value of this function should be interpreted in a way similar to the return value of :obj:`~gi.repository.Gtk.Widget.child_focus`. When :const:`True` is returned, stay in the widget, the failed keyboard navigation is OK and/or there is nowhere we can/should move the focus to. When :const:`False` is returned, the caller should continue with keyboard navigation outside the widget, e.g. by calling :obj:`~gi.repository.Gtk.Widget.child_focus` on the widget’s toplevel. The default :obj:`~gi.repository.Gtk.Widget.signals.keynav_failed` handler returns :const:`False` for :const:`~gi.repository.Gtk.DirectionType.TAB_FORWARD` and :const:`~gi.repository.Gtk.DirectionType.TAB_BACKWARD`. For the other values of ``GtkDirectionType`` it returns :const:`True`. Whenever the default handler returns :const:`True`, it also calls :obj:`~gi.repository.Gtk.Widget.error_bell` to notify the user of the failed keyboard navigation. A use case for providing an own implementation of ::keynav-failed (either by connecting to it or by overriding it) would be a row of :obj:`~gi.repository.Gtk.Entry` widgets where the user should be able to navigate the entire row with the cursor keys, as e.g. known from user interfaces that require entering license keys. :param direction: direction of focus movement .. method:: do_map() -> None Causes a widget to be mapped if it isn’t already. This function is only for use in widget implementations. .. method:: do_measure(orientation: ~gi.repository.Gtk.Orientation, for_size: int) -> tuple[int, int, int, int] Measures ``widget`` in the orientation ``orientation`` and for the given ``for_size``. As an example, if ``orientation`` is :const:`~gi.repository.Gtk.Orientation.HORIZONTAL` and ``for_size`` is 300, this functions will compute the minimum and natural width of ``widget`` if it is allocated at a height of 300 pixels. See `GtkWidget’s geometry management section `_ for a more details on implementing ``GtkWidgetClass.measure()``. :param orientation: the orientation to measure :param for_size: Size for the opposite of ``orientation``, i.e. if ``orientation`` is :const:`~gi.repository.Gtk.Orientation.HORIZONTAL`, this is the height the widget should be measured with. The :const:`~gi.repository.Gtk.Orientation.VERTICAL` case is analogous. This way, both height-for-width and width-for-height requests can be implemented. If no size is known, -1 can be passed. .. method:: do_mnemonic_activate(group_cycling: bool) -> bool Emits the ::mnemonic-activate signal. See :obj:`~gi.repository.Gtk.Widget.signals.mnemonic_activate`. :param group_cycling: :const:`True` if there are other widgets with the same mnemonic .. method:: do_move_focus(direction: ~gi.repository.Gtk.DirectionType) -> None Signal emitted when a change of focus is requested :param direction: .. method:: do_query_tooltip(x: int, y: int, keyboard_tooltip: bool, tooltip: ~gi.repository.Gtk.Tooltip) -> bool Signal emitted when “has-tooltip” is :const:`True` and the hover timeout has expired with the cursor hovering “above” widget; or emitted when widget got focus in keyboard mode. :param x: :param y: :param keyboard_tooltip: :param tooltip: .. method:: do_realize() -> None Creates the GDK resources associated with a widget. Normally realization happens implicitly; if you show a widget and all its parent containers, then the widget will be realized and mapped automatically. Realizing a widget requires all the widget’s parent widgets to be realized; calling this function realizes the widget’s parents in addition to ``widget`` itself. If a widget is not yet inside a toplevel window when you realize it, bad things will happen. This function is primarily used in widget implementations, and isn’t very useful otherwise. Many times when you think you might need it, a better approach is to connect to a signal that will be called after the widget is realized automatically, such as :obj:`~gi.repository.Gtk.Widget.signals.realize`. .. method:: do_root() -> None Called when the widget gets added to a ``GtkRoot`` widget. Must chain up .. method:: do_set_focus_child(child: ~gi.repository.Gtk.Widget | None = None) -> None Set ``child`` as the current focus child of ``widget``. This function is only suitable for widget implementations. If you want a certain widget to get the input focus, call :obj:`~gi.repository.Gtk.Widget.grab_focus` on it. :param child: a direct child widget of ``widget`` or :const:`None` to unset the focus child of ``widget`` .. method:: do_show() -> None Flags a widget to be displayed. Any widget that isn’t shown will not appear on the screen. Remember that you have to show the containers containing a widget, in addition to the widget itself, before it will appear onscreen. When a toplevel container is shown, it is immediately realized and mapped; other shown widgets are realized and mapped when their toplevel container is realized and mapped. .. deprecated:: 4.10 Use :obj:`~gi.repository.Gtk.Widget.set_visible` instead .. method:: do_size_allocate(width: int, height: int, baseline: int) -> None Called to set the allocation, if the widget does not have a layout manager. :param width: :param height: :param baseline: .. method:: do_snapshot(snapshot: ~gi.repository.Gtk.Snapshot) -> None Vfunc called when a new snapshot of the widget has to be taken. :param snapshot: .. method:: do_state_flags_changed(previous_state_flags: ~gi.repository.Gtk.StateFlags) -> None Signal emitted when the widget state changes, see :func:`~gi.repository.Gtk.Widget.get_state_flags`. :param previous_state_flags: .. method:: do_system_setting_changed(settings: ~gi.repository.Gtk.SystemSetting) -> None Emitted when a system setting was changed. Must chain up. :param settings: .. method:: do_unmap() -> None Causes a widget to be unmapped if it’s currently mapped. This function is only for use in widget implementations. .. method:: do_unrealize() -> None Causes a widget to be unrealized (frees all GDK resources associated with the widget). This function is only useful in widget implementations. .. method:: do_unroot() -> None Called when the widget is about to be removed from its ``GtkRoot`` widget. Must chain up Fields ------ .. rst-class:: interim-class .. class:: Widget :no-index: .. attribute:: parent_instance .. attribute:: priv