Gtk4 Reference
Widgets
Base.parent
— Functionparent(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
— Functionshow(w::GtkWidget)
Flag w
to be displayed and return w
.
Related GTK function: gtk_widget_set_visible
()
Graphics.height
— Functionheight(w::GtkWidget)
Returns the allocated height of w
in pixels.
Related GTK function: gtk_widget_get_allocated_height
()
Graphics.width
— Functionwidth(w::GtkWidget)
Returns the allocated width of w
in pixels.
Related GTK function: gtk_widget_get_allocated_width
()
Gtk4.GLib.activate
— Functionactivate(a::GAction, par = nothing)
Activates an action, optionally with a parameter par
, which if given should be a GVariant.
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
()
Gtk4.cursor
— FunctionGtk4.grab_focus
— Functiongrab_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
— FunctionGtk4.hide
— Functionhide(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
— Functionisvisible(w::GtkWidget) -> Bool
Returns whether w
and all of its parents are marked as visible.
Related GTK function: gtk_widget_is_visible
()
Gtk4.reveal
— Functionreveal(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
— Functiontoplevel(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
— Functionvisible(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
— Functiondisplay(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
— Functionmonitor(w::GtkWidget)
Gets the GdkMonitor
where w
is displayed, or nothing
if the widget is not part of a widget hierarchy.
Gtk4.size_request
— Functionsize_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
— Functionisrealized(w::GtkWidget)
Returns whether w
is realized (that is, whether it has been associated with a drawing surface).
Gtk4.add_css_class
— Functionadd_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
— Functionremove_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
— Functioncss_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
— TypeSee the GTK docs.
Base.close
— FunctionCairo.destroy
— FunctionGtk4.default_size
— Functiondefault_size(win::GtkWindow, w, h)
Set the default size of a GtkWindow
.
Related GTK function: gtk_window_default_size
()
Gtk4.fullscreen
— Functionfullscreen(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
— Functionunfullscreen(win::GtkWindow)
If win
is in fullscreen mode, return it to normal mode.
See also fullscreen
.
Related GTK function: gtk_window_unfullscreen
()
Gtk4.isfullscreen
— Functionisfullscreen(win::GtkWindow)
Get whether win
is in fullscreen mode.
See also fullscreen
.
Related GTK function: gtk_window_is_fullscreen
()
Gtk4.isactive
— Functionisactive(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
— Functionissuspended(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
— Functionmaximize(win::GtkWindow)
Request that the window win
be maximized.
See also unmaximize
.
Related GTK function: gtk_window_maximize
()
Gtk4.unmaximize
— Functionunmaximize(win::GtkWindow)
If win
is maximized, return it to its former size.
See also maximize
.
Related GTK function: gtk_window_unmaximize
()
Gtk4.present
— Functionpresent(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
— Functiontoplevels()
Returns a GListModel of all toplevel widgets (i.e. windows) known to GTK4.
Input widgets
Gtk4.configure!
— Functionconfigure!(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!
— Functionselected_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
— Functionselected_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.
Display widgets
Gtk4.start
— Functionstart(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
— Functionstop(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
— Functioninfo_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 andfalse
will be returned. Disabled if negative.modal = true
sets whether the dialog is modal (i.e. stays on top of its parent window)
Gtk4.ask_dialog
— Functionask_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 andfalse
will 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 = true
sets whether the dialog is modal (i.e. stays on top of its parent window)
Gtk4.input_dialog
— Functioninput_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 andfalse
will be returned. Disabled if negative.modal = true
sets whether the dialog is modal (i.e. stays on top of its parent window)
Gtk4.open_dialog
— Functionopen_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 andfalse
will 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 totrue
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.
Gtk4.save_dialog
— Functionsave_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 andfalse
will 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
— TypeGtkCanvas(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
— Functiondraw(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
.
Graphics.getgc
— Functiongetgc(c::GtkCanvas)
Return the CairoContext of the CairoSurface
backing store of a GtkCanvas
.
Gtk4.cairo_surface
— Functioncairo_surface(c::GtkCanvas)
Return the image CairoSurface
backing store for a GtkCanvas
.
GtkGLArea
Gtk4.get_error
— Functionget_error(w::GtkGLArea)
Gets the current error set on w
.
Related GTK function: gtk_gl_area_get_error
()
Gtk4.make_current
— Functionmake_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
— Functionqueue_render(w::GtkGLArea)
Queues a redraw of the widget.
Related GTK function: gtk_gl_area_queue_render
()
Event controllers
Gtk4.find_controller
— Functionfind_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
)
Gtk4.widget
— Functionwidget(c::GtkEventController)
Returns the widget associated with an event controller.
Gtk4.add_action_shortcut
— Functionadd_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!
— Functionundo!(buffer::GtkTextBuffer)
Implements gtk_text_buffer_undo
.
Gtk4.redo!
— Functionredo!(buffer::GtkTextBuffer)
Implements gtk_text_buffer_redo
.
Gtk4.create_mark
— Functioncreate_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
— Functionplace_cursor(buffer::GtkTextBuffer, it::_GtkTextIter)
place_cursor(buffer::GtkTextBuffer, pos::Int)
Place the cursor at indicated position.
Gtk4.scroll_to
— Functionscroll_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
— Functionsearch(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
— Functionselect_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
— Functionselection_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
— Functionskip(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
— Functionbackward_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
— Functionbuffer_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
— Functionchar_offset(iter::Union{Ref{_GtkTextIter}, GtkTextIter})
Returns the offset of iter
(one-based index).
Gtk4.forward_search
— Functionforward_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
— Functiontext_iter_at_position(view::GtkTextView, x::Integer, y::Integer)
Implements gtk_text_view_get_iter_at_position
.
Gtk4.window_to_buffer_coords
— Functionwindow_to_buffer_coords(view::GtkTextView, window_x::Integer, window_y::Integer, wintype::Integer = 2)
Implements gtk_text_view_window_to_buffer_coords
.