Gtk4 Reference
Widgets
Base.parent — Function
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()
Base.show — Function
show(w::GtkWidget)Flag w to be displayed and return w.
Related GTK function: gtk_widget_set_visible()
Graphics.height — Function
height(w::GtkWidget)Returns the allocated height of w in pixels.
Related GTK function: gtk_widget_get_height()
Graphics.width — Function
width(w::GtkWidget)Returns the allocated width of w in pixels.
Related GTK function: gtk_widget_get_width()
Gtk4.GLib.activate — Function
activate(a::GAction, par = nothing)Activates an action, optionally with a parameter par, which if given should be a GVariant.
Related GLib function: g_action_activate()
activate(g::GActionGroup, name [, parameter])Activate an action name in a GActionGroup, optionally with a parameter.
Related GLib function: g_action_group_activate_action()
activate(w::GtkWidget)Activates widgets that support being activated, such as buttons and menu items. Returns false if the widget is not activatable.
Related GTK function: gtk_widget_activate()
Gtk4.cursor — Function
Gtk4.grab_focus — Function
grab_focus(w::GtkWidget)Gives w the keyboard focus for the window it is in. Returns false if this fails.
Related GTK function: gtk_widget_grab_focus()
Gtk4.hasparent — Function
Gtk4.hide — Function
hide(w::GtkWidget)Flag w to be hidden and return w. This is the opposite of show.
Related GTK function: gtk_widget_set_visible()
Gtk4.isvisible — Function
isvisible(w::GtkWidget) -> BoolReturns whether w and all of its parents are marked as visible.
Related GTK function: gtk_widget_is_visible()
Gtk4.reveal — Function
reveal(w::GtkWidget)Triggers a redraw of a widget by calling GTK's gtk_widget_queue_draw.
Related GTK function: gtk_widget_queue_draw())
reveal(w::GtkGLArea)Triggers a redraw of a widget by calling GTK's gtk_glarea_queue_render.
Related GTK function: gtk_gl_area_queue_render()
Gtk4.toplevel — Function
toplevel(w::GtkWidget)Returns the topmost ancestor of w, which in most cases will be a GtkWindow.
See also parent.
Related GTK function: gtk_widget_get_root()
Gtk4.visible — Function
visible(w::GtkWidget, state::Bool)Control visibility of w. Note that w will not be visible unless its parent is also visible.
Related GTK function: gtk_widget_set_visible()
Gtk4.display — Function
display(w::GtkWidget)Gets the GdkDisplay for w. Should only be called if w has been added to a widget hierarchy.
Related GTK function: gtk_widget_get_display()
Gtk4.monitor — Function
monitor(w::GtkWidget)Gets the GdkMonitor where w is displayed, or nothing if the widget is not part of a widget hierarchy.
Gtk4.size_request — Function
size_request(w::GtkWidget, s)Set the minimum size w to s, which should be a tuple (width, height).
Related GTK function: gtk_widget_set_size_request()
Gtk4.isrealized — Function
isrealized(w::GtkWidget)Returns whether w is realized (that is, whether it has been associated with a drawing surface).
Gtk4.add_css_class — Function
add_css_class(w::GtkWidget, c::AbstractString)Add a CSS class to a widget.
See also remove_css_class.
Related GTK function: gtk_widget_add_css_class()
Gtk4.remove_css_class — Function
remove_css_class(w::GtkWidget, c::AbstractString)Remove a CSS class from a widget.
See also add_css_class.
Related GTK function: gtk_widget_add_css_class()
Gtk4.css_classes — Function
css_classes(w::GtkWidget, c::Vector{AbstractString})Sets the CSS style classes for a widget, replacing the previously set classes.
Related GTK function: gtk_widget_set_css_classes()
Windows
Gtk4.GtkWindow — Type
See the GTK docs.
Base.close — Function
Cairo.destroy — Function
Gtk4.default_size — Function
default_size(win::GtkWindow, w, h)Set the default size of a GtkWindow.
Related GTK function: gtk_window_default_size()
Gtk4.fullscreen — Function
fullscreen(win::GtkWindow [, mon::GdkMonitor])Set win to fullscreen mode, optionally on a particular monitor mon. The windowing system (outside GTK's control) may not allow this, so it may not work on some platforms.
See also unfullscreen.
Related GTK functions: gtk_window_fullscreen(), gtk_window_fullscreen_on_monitor()
Gtk4.unfullscreen — Function
unfullscreen(win::GtkWindow)If win is in fullscreen mode, return it to normal mode.
See also fullscreen.
Related GTK function: gtk_window_unfullscreen()
Gtk4.isfullscreen — Function
isfullscreen(win::GtkWindow)Get whether win is in fullscreen mode.
See also fullscreen.
Related GTK function: gtk_window_is_fullscreen()
Gtk4.isactive — Function
isactive(win::GtkWindow)Returns whether win is the currently active toplevel. This is the window that receives keystrokes.
Related GTK function: gtk_window_is_active()
Gtk4.issuspended — Function
issuspended(win::GtkWindow)Get whether win is in a state where it's invisible to the user.
Related GTK function: gtk_window_is_suspended()
Gtk4.maximize — Function
maximize(win::GtkWindow)Request that the window win be maximized.
See also unmaximize.
Related GTK function: gtk_window_maximize()
Gtk4.unmaximize — Function
unmaximize(win::GtkWindow)If win is maximized, return it to its former size.
See also maximize.
Related GTK function: gtk_window_unmaximize()
Gtk4.present — Function
present(win::GtkWindow [, timestamp])Presents a window to the user. Usually means move it to the front.
Related GTK function: gtk_window_present() Related GTK function: gtk_window_present_with_time()
Gtk4.toplevels — Function
toplevels()Returns a GListModel of all toplevel widgets (i.e. windows) known to GTK4.
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()
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()
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.
Gtk4.selected_string — Function
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.
Gtk4.selected — Function
selected(d::GtkDropDown)Get the (one based) index of the currently selected item of a dropdown widget. Returns nothing if there is no item selected.
Related GTK functions: gtk_drop_down_get_selected()
selected(d::GtkSingleSelection)Get the (one based) index of the currently selected item in a list widget corresponding to a GtkSingleSelection object. Returns nothing if there is no item currently selected.
Related GTK function: gtk_single_selection_get_selected()
Gtk4.selected! — Function
selected!(d::GtkDropDown, i)Set the (one based) index of the currently selected item of a dropdown widget.
Related GTK functions: gtk_drop_down_set_selected()
selected!(d::GtkSingleSelection, i)Set the (one based) index of the currently selected item in a list widget corresponding to a GtkSingleSelection object. Pass in nothing to clear the selection.
Related GTK function: gtk_single_selection_set_selected()
Display widgets
Gtk4.start — Function
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()
Gtk4.stop — Function
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()
Dialogs
Gtk4.info_dialog — Function
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 = -1to set a time in seconds after which the dialog will close andfalsewill be returned. Disabled if negative.modal = truesets whether the dialog is modal (i.e. stays on top of its parent window)
Gtk4.ask_dialog — Function
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 = -1to set a time in seconds after which the dialog will close andfalsewill be returned. Disabled if negative.no_text = "No"to change the text for the response that producesfalse.yes_text = "Yes"to change the text for the response that producestrue.modal = truesets whether the dialog is modal (i.e. stays on top of its parent window)
Gtk4.input_dialog — Function
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 = -1to set a time in seconds after which the dialog will close andfalsewill be returned. Disabled if negative.modal = truesets whether the dialog is modal (i.e. stays on top of its parent window)
Gtk4.open_dialog — Function
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 = -1to set a time in seconds after which the dialog will close andfalsewill be returned. Disabled if negative.multiple = false: iftrue, multiple files can be selected, and an array of file paths is returned rather than a single path.select_folder = false: set totrueto 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.
Gtk4.save_dialog — Function
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 = -1to set a time in seconds after which the dialog will close andfalsewill be returned. Disabled if negative.start_folder = "": if set, the dialog will start out browsing a particular folder. Otherwise GTK will decide.
GtkCanvas (for Cairo drawing)
Gtk4.GtkCanvas — Type
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.
Gtk4.draw — Function
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.
draw(widget::GtkCanvas)Triggers a redraw of the canvas using a previously set redraw function.
Graphics.getgc — Function
getgc(c::GtkCanvas)Return the CairoContext of the CairoSurface backing store of a GtkCanvas.
Gtk4.cairo_surface — Function
cairo_surface(c::GtkCanvas)Return the image CairoSurface backing store for a GtkCanvas.
GtkGLArea
Gtk4.get_error — Function
get_error(w::GtkGLArea)Gets the current error set on w.
Related GTK function: gtk_gl_area_get_error()
Gtk4.make_current — Function
make_current(w::GtkGLArea)Ensures that the GdkGLContext used by area is associated with the GtkGLArea.
Related GTK function: gtk_gl_area_make_current()
Gtk4.queue_render — Function
queue_render(w::GtkGLArea)Queues a redraw of the widget.
Related GTK function: gtk_gl_area_queue_render()
Event controllers
Gtk4.find_controller — Function
find_controller(w::GtkWidget, ::Type{T}) where T <: GtkEventControllerReturns 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)
Gtk4.widget — Function
widget(c::GtkEventController)Returns the widget associated with an event controller.
Gtk4.add_action_shortcut — Function
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.
GtkTextView
Gtk4.undo! — Function
undo!(buffer::GtkTextBuffer)Implements gtk_text_buffer_undo.
Gtk4.redo! — Function
redo!(buffer::GtkTextBuffer)Implements gtk_text_buffer_redo.
Gtk4.create_mark — Function
create_mark(buffer::GtkTextBuffer, mark_name, it::TI, left_gravity::Bool)
create_mark(buffer::GtkTextBuffer, it::TI)Implements gtk_text_buffer_create_mark.
Gtk4.place_cursor — Function
place_cursor(buffer::GtkTextBuffer, it::_GtkTextIter)
place_cursor(buffer::GtkTextBuffer, pos::Int)Place the cursor at indicated position.
Gtk4.scroll_to — Function
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.
Gtk4.search — Function
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.
Gtk4.select_range — Function
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.
Gtk4.selection_bounds — Function
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.
Base.skip — Function
skip(iter::Ref{_GtkTextIter}, count::Integer)Moves iter count characters. Returns a Bool indicating if the move was successful.
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)
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)
Gtk4.backward_search — Function
backward_search(iter::Ref{_GtkTextIter},
str::AbstractString, start::Ref{_GtkTextIter},
stop::Ref{_GtkTextIter}, limit::Ref{_GtkTextIter}, flag::Int32)Implements gtk_text_iter_backward_search.
Gtk4.buffer_to_window_coords — Function
buffer_to_window_coords(view::GtkTextView, buffer_x::Integer, buffer_y::Integer, wintype::Integer = 0)Implements gtk_text_view_buffer_to_window_coords.
Gtk4.char_offset — Function
char_offset(iter::Union{Ref{_GtkTextIter}, GtkTextIter})Returns the offset of iter (one-based index).
Gtk4.forward_search — Function
forward_search(iter::Ref{_GtkTextIter},
str::AbstractString, start::Ref{_GtkTextIter},
stop::Ref{_GtkTextIter}, limit::Ref{_GtkTextIter}, flag::Int32)Implements gtk_text_iter_forward_search.
Gtk4.text_iter_at_position — Function
text_iter_at_position(view::GtkTextView, x::Integer, y::Integer)Implements gtk_text_view_get_iter_at_position.
Gtk4.window_to_buffer_coords — Function
window_to_buffer_coords(view::GtkTextView, window_x::Integer, window_y::Integer, wintype::Integer = 2)Implements gtk_text_view_window_to_buffer_coords.