From 78769fb6669b30c15b50051f0e2adb315c3b3db5 Mon Sep 17 00:00:00 2001 From: Jared Wahlstrand Date: Sun, 28 May 2023 19:02:18 -0400 Subject: [PATCH] misc. methods to help dependent packages avoid using G_ --- gen/gen_gtk4.jl | 2 +- src/GLib/loop.jl | 8 +++++--- src/base.jl | 10 ++++++++++ src/buttons.jl | 15 ++++++++++++++- src/events.jl | 2 ++ src/gen/gtk4_structs | 10 ---------- src/input.jl | 3 +++ src/windows.jl | 11 +++++++++++ 8 files changed, 46 insertions(+), 15 deletions(-) diff --git a/gen/gen_gtk4.jl b/gen/gen_gtk4.jl index f3e0144e..9fbc9af2 100644 --- a/gen/gen_gtk4.jl +++ b/gen/gen_gtk4.jl @@ -40,7 +40,7 @@ GI.append_struc_docs!(exprs, "gtk4", d, c, ns) object_skiplist=[:CClosureExpression,:ClosureExpression,:ConstantExpression,:ObjectExpression,:PropertyExpression,:ParamSpecExpression,:PrintUnixDialog,:PageSetupUnixDialog] GI.all_interfaces!(exprs,exports,ns) -c = GI.all_objects!(exprs,exports,ns,skiplist=object_skiplist,constructor_skiplist=[:new_from_resource,:new_with_mnemonic,:new_with_text,:new_with_entry,:new_with_model_and_entry,:new_for_resource],output_cache_define=false,output_cache_init=false) +c = GI.all_objects!(exprs,exports,ns,skiplist=object_skiplist,constructor_skiplist=[:new_from_resource,:new_with_mnemonic,:new_with_text,:new_with_entry,:new_with_model_and_entry,:new_for_resource,:new_from_icon_name],output_cache_define=false,output_cache_init=false) GI.append_object_docs!(exprs, "gtk4", d, c, ns) push!(exprs,exports) diff --git a/src/GLib/loop.jl b/src/GLib/loop.jl index 4c7beffd..ea7d1a43 100644 --- a/src/GLib/loop.jl +++ b/src/GLib/loop.jl @@ -84,6 +84,8 @@ glib_main() = GLib.g_sigatom() do end end +is_loop_running() = (G_.main_depth() != 0) + """ start_main_loop() @@ -94,9 +96,9 @@ See also [`stop_main_loop`](@ref). """ function start_main_loop() @debug("Starting GLib main loop using g_main_context_iteration()") - # if g_main_depth > 0, a glib main-loop is already running, - # so we don't need to start a new one - if ccall((:g_main_depth, libglib), Cint, ()) == 0 + # if a glib main-loop is already running, we don't need to start a new one + if !is_loop_running() + g_main_running[] = true global glib_main_task = schedule(Task(glib_main)) end end diff --git a/src/base.jl b/src/base.jl index e0abc400..526251e2 100644 --- a/src/base.jl +++ b/src/base.jl @@ -47,6 +47,16 @@ Related GTK function: [`gtk_widget_get_allocated_height`()]($(gtkdoc_method_url( size(w::GtkWidget) = (width(w), height(w)) +""" + 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`()]($(gtkdoc_method_url("gtk4","Widget","set_size_request"))) +""" +size_request(w::GtkWidget, s) = G_.set_size_request(w,s[1],s[2]) +size_request(w::GtkWidget, width, height) = G_.set_size_request(w, width, height) + """ isvisible(w::GtkWidget) -> Bool diff --git a/src/buttons.jl b/src/buttons.jl index e18da0c0..07568fa7 100644 --- a/src/buttons.jl +++ b/src/buttons.jl @@ -1,11 +1,22 @@ ## GtkButton -GtkButton(title::AbstractString) = G_.Button_new_with_mnemonic(title) +GtkButton(title::AbstractString) = G_.Button_new_with_label(title) function GtkButton(w::GtkWidget) b = G_.Button_new() G_.set_child(b,w) b end +function GtkButton(s::Symbol,str::AbstractString) + if s === :mnemonic + G_.Button_new_with_mnemonic(str) + elseif s === :icon_name + G_.Button_new_from_icon_name(str) + elseif s === :label + G_.Button_new_with_label(str) + else + error("Symbol must be :mnemonic, :icon_name, or :label") + end +end setindex!(f::GtkButton, w::Union{Nothing,GtkWidget}) = G_.set_child(f,w) getindex(f::GtkButton) = G_.get_child(f) @@ -67,6 +78,8 @@ function GtkPopoverMenu(model::GMenu, nested = false) end end +popup(m::GtkPopover) = G_.popup(m) + GtkPopoverMenuBar(model::GMenu) = G_.PopoverMenuBar_new_from_model(model) menu_model(b::Union{GtkMenuButton,GtkPopoverMenu, GtkPopoverMenuBar}, model) = G_.set_menu_model(b, GMenuModel(model)) diff --git a/src/events.jl b/src/events.jl index 1b4fcaef..2e8a60dd 100644 --- a/src/events.jl +++ b/src/events.jl @@ -7,6 +7,8 @@ delete!(w::GtkWidget, c::GtkEventController) = (G_.remove_controller(w,c); w) Returns the widget associated with an event controller. """ widget +observe_controllers(w::GtkWidget) = GListModel(G_.observe_controllers(w)) + """ find_controller(w::GtkWidget, ::Type{T}) where T <: GtkEventController diff --git a/src/gen/gtk4_structs b/src/gen/gtk4_structs index 9adb2000..1099ad10 100644 --- a/src/gen/gtk4_structs +++ b/src/gen/gtk4_structs @@ -4084,11 +4084,6 @@ $(Expr(:toplevel, quote GLib.setproperties!(obj; kwargs...) obj end - function GtkButton(_icon_name::Maybe(Union{AbstractString, Symbol}); kwargs...) - obj = G_.Button_new_from_icon_name(_icon_name) - GLib.setproperties!(obj; kwargs...) - obj - end function GtkButton(_label::Union{AbstractString, Symbol}; kwargs...) obj = G_.Button_new_with_label(_label) GLib.setproperties!(obj; kwargs...) @@ -4533,11 +4528,6 @@ $(Expr(:toplevel, quote GLib.setproperties!(obj; kwargs...) obj end - function GtkImage(_icon_name::Maybe(Union{AbstractString, Symbol}); kwargs...) - obj = G_.Image_new_from_icon_name(_icon_name) - GLib.setproperties!(obj; kwargs...) - obj - end function GtkImage(_paintable::Maybe(GdkPaintable); kwargs...) obj = G_.Image_new_from_paintable(_paintable) GLib.setproperties!(obj; kwargs...) diff --git a/src/input.jl b/src/input.jl index decedfb9..4a20f341 100644 --- a/src/input.jl +++ b/src/input.jl @@ -10,6 +10,9 @@ function GtkEntryBuffer(initial_text = nothing) G_.EntryBuffer_new(initial_text, -1) end +setindex!(buffer::GtkEntryBuffer, content::String, ::Type{String}) = + G_.set_text(buffer, content, -1) + complete(completion::GtkEntryCompletion) = G_.complete(completion) ## GtkScale diff --git a/src/windows.jl b/src/windows.jl index 8ad80b75..12f8c3ca 100644 --- a/src/windows.jl +++ b/src/windows.jl @@ -66,6 +66,17 @@ Related GTK function: [`gtk_window_unfullscreen`()]($(gtkdoc_method_url("gtk4"," """ unfullscreen(win::GtkWindow) = G_.unfullscreen(win) +""" + isfullscreen(win::GtkWindow) + +Get whether `win` is in fullscreen mode. + +See also [`fullscreen`](@ref). + +Related GTK function: [`gtk_window_is_fullscreen`()]($(gtkdoc_method_url("gtk4","Window","is_fullscreen"))) +""" +isfullscreen(win::GtkWindow) = G_.is_fullscreen(win) + """ maximize(win::GtkWindow)