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

Display widgets

Gtk4.startFunction
start(spinner::GtkSpinner)

Start a GtkSpinner widget spinning. The purpose of this widget is to show that some operation is in process.

Related GTK function: gtk_spinner_start()

source
Gtk4.stopFunction
stop(spinner::GtkSpinner)

Stop a GtkSpinner. The purpose of this widget is to show that some operation is in process.

Related GTK function: gtk_spinner_stop()

source

Dialogs

Gtk4.info_dialogFunction
info_dialog(callback::Function, message::AbstractString, parent = nothing)
info_dialog(message::AbstractString, parent = nothing)

Create a dialog that displays an informational message. The form with a callback function argument is intended for use in GUI callbacks, while the form without callback is only useful in interactive scripts. If callback is provided, it should take no arguments. This function is called when the user closes the dialog. If callback is not provided, this function returns when the dialog is closed. Passing in a parent window is strongly recommended. The dialog will appear in front of the parent window by default.

Keyword arguments:

  • timeout = -1 to set a time in seconds after which the dialog will close and false will be returned. Disabled if negative.
  • modal = true sets whether the dialog is modal (i.e. stays on top of its parent window)
source
Gtk4.ask_dialogFunction
ask_dialog(callback::Function, question::AbstractString, parent = nothing)
ask_dialog(question::AbstractString, parent = nothing)

Create a dialog with a question and two buttons "No" and "Yes". The form with a callback function argument is intended for use in GUI callbacks, while the form without callback is only useful in interactive scripts. If callback is provided, it should take a single boolean argument. This function is called with true if "Yes" is selected and false if "No" is selected or the dialog is closed. Passing in a parent window is strongly recommended. The dialog will appear in front of the parent window by default.

Keyword arguments:

  • timeout = -1 to set a time in seconds after which the dialog will close and false will be returned. Disabled if negative.
  • no_text = "No" to change the text for the response that produces false.
  • yes_text = "Yes" to change the text for the response that produces true.
  • modal = true sets whether the dialog is modal (i.e. stays on top of its parent window)
source
Gtk4.input_dialogFunction
input_dialog(callback::Function, message::AbstractString, entry_default::AbstractString, parent = nothing)
input_dialog(message::AbstractString, entry_default::AbstractString, parent = nothing)

Create a dialog with a message and a text entry. The form with a callback function argument is intended for use in GUI callbacks, while the form without callback is only useful in interactive scripts. If callback is provided, it should be a function that takes a single String argument. When the "Accept" button is pressed, the callback function is called with the user's input text. If "Cancel" is pressed (or the dialog or its parent window parent is closed), entry_default will be passed to the callback. If no callback function is provided, the string from the dialog is returned. Passing in a parent window is strongly recommended. The dialog will appear in front of the parent window by default.

Keyword arguments:

  • timeout = -1 to set a time in seconds after which the dialog will close and false will be returned. Disabled if negative.
  • modal = true sets whether the dialog is modal (i.e. stays on top of its parent window)
source
Gtk4.open_dialogFunction
open_dialog(callback::Function, title::AbstractString, parent = nothing, filters::Union{AbstractVector, Tuple} = String[])
open_dialog(title::AbstractString, parent = nothing, filters::Union{AbstractVector, Tuple} = String[])

Create a dialog for choosing a file or folder to be opened. The form with a callback function argument is intended for use in GUI callbacks, while the form without callback is only useful in interactive scripts. If callback is provided, it should be a function that takes a single String argument (or a vector of strings if multiple is set to true). The callback is called with the file path chosen by the user or "" if "Cancel" is pressed. The dialog title is set using title. Passing in a parent window is strongly recommended. The dialog will appear in front of the parent window by default. The argument filters can be used to show only directory contents that match certain file extensions.

Keyword arguments:

  • timeout = -1 to set a time in seconds after which the dialog will close and false will be returned. Disabled if negative.
  • multiple = false: if true, multiple files can be selected, and an array of file paths is returned rather than a single path.
  • select_folder = false: set to true to allow the user to select a folder rather than a file.
  • start_folder = "": if set to a path, the dialog will start out browsing a particular folder. Otherwise GTK will decide.
source
Gtk4.save_dialogFunction
save_dialog(callback::Function, title::AbstractString, parent = nothing, filters::Union{AbstractVector, Tuple} = String[])
save_dialog(title::AbstractString, parent = nothing, filters::Union{AbstractVector, Tuple} = String[])

Create a dialog for choosing a file to be saved to. The form with a callback function argument is intended for use in GUI callbacks, while the form without callback is only useful in interactive scripts. If callback is provided, it should be a function that takes a single String argument. The callback is called with the file path chosen by the user or "" if "Cancel" is pressed. The window title is set using title. Passing in a parent window is strongly recommended. The dialog will appear in front of the parent window by default. The argument filters can be used to show only directory contents that match certain file extensions.

Keyword arguments:

  • timeout = -1 to set a time in seconds after which the dialog will close and false will be returned. Disabled if negative.
  • 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.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 = TextSearchFlags_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 according 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