Skip to content

Commit

Permalink
misc. methods to help dependent packages avoid using G_
Browse files Browse the repository at this point in the history
  • Loading branch information
jwahlstrand committed May 28, 2023
1 parent 5cbe708 commit 78769fb
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 15 deletions.
2 changes: 1 addition & 1 deletion gen/gen_gtk4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions src/GLib/loop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ glib_main() = GLib.g_sigatom() do
end
end

is_loop_running() = (G_.main_depth() != 0)

"""
start_main_loop()
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion src/buttons.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions src/events.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions src/gen/gtk4_structs
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down Expand Up @@ -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...)
Expand Down
3 changes: 3 additions & 0 deletions src/input.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/windows.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 78769fb

Please sign in to comment.