Gtk4 Reference

Widgets

Base.parentFunction
parent(w::GtkWidget)

Returns the parent widget of w, or nothing if the widget has not been set as the child of another widget (or is a toplevel widget, like a GtkWindow).

See also toplevel.

Related GTK function: gtk_widget_get_parent()

source
Gtk4.GLib.activateFunction
activate(a::GAction, par = nothing)

Activates an action, optionally with a parameter par, which if given should be a GVariant.

source
activate(w::GtkWidget)

Activates widgets like buttons, menu items, etc. that support being activated. Returns false if the widget is not activatable.

Related GTK function: gtk_widget_activate()

source
Gtk4.monitorFunction
monitor(w::GtkWidget)

Gets the GdkMonitor where w is displayed, or nothing if the widget is not part of a widget hierarchy.

source
Gtk4.isrealizedFunction
isrealized(w::GtkWidget)

Returns whether w is realized (that is, whether it has been associated with a drawing surface).

source

Windows

Gtk4.isactiveFunction
isactive(win::GtkWindow)

Returns whether win is the currently active toplevel. This is the window that receives keystrokes.

source
Gtk4.presentFunction
present(win::GtkWindow)
present(win::GtkWindow, timestamp)

Presents a window to the user. Usually means move it to the front. According to the GTK docs, this function "should not be used" without including a timestamp for the user's request.

Related GTK function: gtk_window_present() Related GTK function: gtk_window_present_with_time()

source
Gtk4.toplevelsFunction
toplevels()

Returns a GListModel of all toplevel widgets (i.e. windows) known to GTK4.

source

Input widgets

Gtk4.configure!Function
configure!(adj::GtkAdjustment; value = nothing, lower = nothing, upper = nothing, step_increment = nothing, page_increment = nothing, page_size = nothing)

Sets all properties of an adjustment, while only resulting in one emission of the changed signal. If an argument is nothing, it is not changed.

Related GTK function: gtk_adjustment_configure()

source
configure!(sb::GtkSpinButton; adj = nothing, climb_rate = nothing, digits = nothing)

Sets the adjustment adj, the climb_rate, and the number of digits of a GtkSpinButton. If an argument is nothing, it is not changed.

Related GTK function: gtk_spin_button_configure()

source
Gtk4.selected_string!Function
selected_string!(d::GtkDropDown, s::AbstractString)

Set the selected item in a dropdown widget. This method assumes that the widget's model is a GtkStringList.

source
Gtk4.selected_stringFunction
selected_string(d::GtkDropDown)

Get the currently selected item in a dropdown widget. This method assumes that the widget's model is a GtkStringList or that items in the model have a "string" property.

source

Dialogs

Gtk4.ask_dialogFunction
ask_dialog(question::AbstractString, parent = nothing; timeout = -1)

Create a dialog with a message question and two buttons "No" and "Yes". Returns true if "Yes" is selected and false if "No" is selected or the dialog (or its parent window parent) is closed. The optional input timeout (disabled by default) can be used to set a time in seconds after which the dialog will close and false will be returned.

source
Gtk4.info_dialogFunction
info_dialog(message::AbstractString, parent = nothing; timeout = -1)

Create a dialog with an informational message message. Returns when the dialog (or its parent window parent) is closed. The optional input timeout (disabled by default) can be used to set a time in seconds after which the dialog will close and false will be returned.

source
Gtk4.input_dialogFunction
input_dialog(message::AbstractString, entry_default::AbstractString, buttons = (("Cancel", 0), ("Accept", 1)), parent = nothing; timeout = -1)

Create a dialog with a message message and a text entry. Returns the string in the entry when the "Accept" button is pressed, or entry_default if "Cancel" is pressed or the dialog or its parent window parent is closed. The optional input timeout (disabled by default) can be used to set a time in seconds after which the dialog will close and entry_default will be returned.

source
Gtk4.open_dialogFunction
open_dialog(title::AbstractString, parent = nothing, filters::Union{AbstractVector, Tuple} = String[]; timeout = -1, multiple = false, start_folder = "")

Create a dialog for choosing a file or folder to be opened. Returns the path chosen by the user, or "" if "Cancel" is pressed or the dialog or its parent window parent is closed. The dialog title is set using title. The argument filters can be used to show only directory contents that match certain file extensions.

Keyword arguments: timeout: The optional input timeout (disabled by default) can be used to set a time in seconds after which the dialog will close and "" will be returned. multiple: if true, multiple files can be selected, and a list of file paths is returned rather than a single path. start_folder: if set, the dialog will start out browsing a particular folder. Otherwise GTK will decide.

source
Gtk4.save_dialogFunction
save_dialog(title::AbstractString, parent = nothing, filters::Union{AbstractVector, Tuple} = String[]; timeout = -1, start_folder = "")

Create a dialog for choosing a file to be saved to. Returns the path chosen by the user, or "" if "Cancel" is pressed or the dialog or its parent window parent is closed. The window title is set using title. The argument filters can be used to show only directory contents that match certain file extensions.

Keyword arguments: timeout: The optional input timeout (disabled by default) can be used to set a time in seconds after which the dialog will close and "" will be returned. start_folder: if set, the dialog will start out browsing a particular folder. Otherwise GTK will decide.

source

GtkCanvas (for Cairo drawing)

Gtk4.GtkCanvasType
GtkCanvas(w = -1, h = -1, init_back = false; kwargs...)

Create a GtkCanvas widget for drawing using Cairo (based on GtkDrawingArea). Optional arguments w and h can be used to set the minimum width and height of the drawing area in pixels. If init_back is set to true, the canvas's image CairoSurface will be initialized immediately, which is useful for precompilation.

Keyword arguments can be used to set properties of the GtkDrawingArea widget.

source
Gtk4.drawFunction
draw(redraw::Function, widget::GtkCanvas)

Set a function redraw to be called whenever the GtkCanvas's CairoSurface needs to be redrawn. The function should have a single argument, the GtkCanvas, from which the CairoSurface can be retrieved using getgc.

source
Graphics.getgcFunction
getgc(c::GtkCanvas)

Return the CairoContext of the CairoSurface backing store of a GtkCanvas.

source
Gtk4.cairo_surfaceFunction
cairo_surface(c::GtkCanvas)

Return the image CairoSurface backing store for a GtkCanvas.

source

GtkGLArea

Event controllers

Gtk4.find_controllerFunction
find_controller(w::GtkWidget, ::Type{T}) where T <: GtkEventController

Returns an event controller of type T connected to a widget, or nothing if one doesn't exist. This function is intended for testing purposes (to simulate events) and is not recommended otherwise, as there is a performance penalty for creating a list of a widget's event controllers.

Related GTK function: gtk_widget_observe_controllers)

source
Gtk4.widgetFunction
widget(c::GtkEventController)

Returns the widget associated with an event controller.

source
Gtk4.add_action_shortcutFunction
add_action_shortcut(scc::GtkShortcutController,trigger::AbstractString,action::AbstractString)

Adds a shortcut specified by a string like "<Control>S" for an action (such as "app.save") to a GtkShortcutController.

source

GtkTextView

Gtk4.bufferFunction
buffer(iter::Union{Ref{_GtkTextIter}, _GtkTextIter})

Returns the buffer associated with iter.

source
Gtk4.undo!Function
undo!(buffer::GtkTextBuffer)

Implements gtk_text_buffer_undo.

source
Gtk4.redo!Function
redo!(buffer::GtkTextBuffer)

Implements gtk_text_buffer_redo.

source
Gtk4.create_markFunction
create_mark(buffer::GtkTextBuffer, mark_name, it::TI, left_gravity::Bool)
create_mark(buffer::GtkTextBuffer, it::TI)

Implements gtk_text_buffer_create_mark.

source
Gtk4.place_cursorFunction
place_cursor(buffer::GtkTextBuffer, it::_GtkTextIter)
place_cursor(buffer::GtkTextBuffer, pos::Int)

Place the cursor at indicated position.

source
Gtk4.scroll_toFunction
scroll_to(view::GtkTextView, mark::GtkTextMark, within_margin::Real,
               use_align::Bool, xalign::Real, yalign::Real)

scroll_to(view::GtkTextView, iter::TI, within_margin::Real,
          use_align::Bool, xalign::Real, yalign::Real)

Implements gtk_text_view_scroll_to_mark and gtk_text_view_scroll_to_iter.

source
Gtk4.searchFunction
search(buffer::GtkTextBuffer, str::AbstractString, direction = :forward,
    flag = GtkTextSearchFlags.GTK_TEXT_SEARCH_TEXT_ONLY)

Search text str in buffer in direction :forward or :backward starting from the cursor position in the buffer.

Returns a tuple (found, start, stop) where found indicates whether the search was successful and start and stop are _GtkTextIters containing the location of the match.

source
Gtk4.select_rangeFunction
select_range(buffer::GtkTextBuffer, ins::TI, bound::TI)
select_range(buffer::GtkTextBuffer, range::GtkTextRange)

Select the text in buffer accorind to _GtkTextIter ins and bound.

Implements gtk_text_buffer_select_range.

source
Gtk4.selection_boundsFunction
selection_bounds(buffer::GtkTextBuffer)

Returns a tuple (selected, start, stop) indicating if text is selected in the buffer, and if so sets the _GtkTextIter start and stop to point to the selected text.

Implements gtk_text_buffer_get_selection_bounds.

source
Base.skipFunction
skip(iter::Ref{_GtkTextIter}, count::Integer)

Moves iter count characters. Returns a Bool indicating if the move was successful.

source
skip(iter::Ref{_GtkTextIter}, what::Symbol)

Moves iter according to the operation specified by what. Operations are :

  • :forward_line (gtk_text_iter_forward_line)
  • :backward_line (gtk_text_iter_backward_line)
  • :forward_to_line_end (gtk_text_iter_forward_to_line_end)
  • :backward_word_start (gtk_text_iter_forward_word_end)
  • :forward_word_end (gtk_text_iter_backward_word_start)
  • :backward_sentence_start (gtk_text_iter_backward_sentence_start)
  • :forward_sentence_end (gtk_text_iter_forward_sentence_end)
source
skip(iter::Ref{_GtkTextIter}, count::Integer, what::Symbol)

Moves iter according to the operation specified by what and count. Operations are :

  • :chars (gtk_text_iter_forward_chars)
  • :lines (gtk_text_iter_forward_lines)
  • :words (gtk_text_iter_forward_word_ends)
  • :word_cursor_positions (gtk_text_iter_forward_cursor_positions)
  • :sentences (gtk_text_iter_forward_sentence_ends)
  • :visible_words (gtk_text_iter_forward_visible_word_ends)
  • :visible_cursor_positions (gtk_text_iter_forward_visible_cursor_positions)
  • :visible_lines (gtk_text_iter_forward_visible_lines)
  • :line_ends (gtk_text_iter_forward_visible_lines)
source
Gtk4.backward_searchFunction
backward_search(iter::Ref{_GtkTextIter},
    str::AbstractString, start::Ref{_GtkTextIter},
    stop::Ref{_GtkTextIter}, limit::Ref{_GtkTextIter}, flag::Int32)

Implements gtk_text_iter_backward_search.

source
Gtk4.buffer_to_window_coordsFunction
buffer_to_window_coords(view::GtkTextView, buffer_x::Integer, buffer_y::Integer, wintype::Integer = 0)

Implements gtk_text_view_buffer_to_window_coords.

source
Gtk4.char_offsetFunction
char_offset(iter::Union{Ref{_GtkTextIter}, _GtkTextIter})

Returns the offset of iter (one-based index).

source
Gtk4.forward_searchFunction
forward_search(iter::Ref{_GtkTextIter},
    str::AbstractString, start::Ref{_GtkTextIter},
    stop::Ref{_GtkTextIter}, limit::Ref{_GtkTextIter}, flag::Int32)

Implements gtk_text_iter_forward_search.

source
Gtk4.window_to_buffer_coordsFunction
window_to_buffer_coords(view::GtkTextView, window_x::Integer, window_y::Integer, wintype::Integer = 2)

Implements gtk_text_view_window_to_buffer_coords.

source
Gtk4._GtkTextIterType
_GtkTextIter(text::GtkTextBuffer, char_offset::Integer)

Creates a _GtkTextIter with offset char_offset (one-based index).

source