From 6db8a96214f092cbd4439b7133a40b6019b9a7dc Mon Sep 17 00:00:00 2001 From: Jared Wahlstrand Date: Sat, 20 Jan 2024 16:26:42 -0500 Subject: [PATCH 1/8] replace uses of GtkMessageDialog with GtkAlertDialog --- src/GLib/gio.jl | 15 +++++ src/deprecated.jl | 42 +++++++++++++- src/windows.jl | 140 ++++++++++++++++++++-------------------------- 3 files changed, 116 insertions(+), 81 deletions(-) diff --git a/src/GLib/gio.jl b/src/GLib/gio.jl index 897dff48..75150283 100644 --- a/src/GLib/gio.jl +++ b/src/GLib/gio.jl @@ -35,3 +35,18 @@ end cancel(c::GCancellable) = G_.cancel(c) iscancelled(c::GCancellable) = G_.is_cancelled(c) + +""" + cancel_after_delay(timeout) + +Creates and returns a `GCancellable` and after `timeout` seconds, cancels it. +""" +function cancel_after_delay(timeout) + cancellable = GCancellable() + if timeout > 0 + Timer(timeout) do timer + cancel(cancellable) + end + end + cancellable +end diff --git a/src/deprecated.jl b/src/deprecated.jl index c524cf60..80bec997 100644 --- a/src/deprecated.jl +++ b/src/deprecated.jl @@ -1,6 +1,42 @@ -GtkAdjustment(spinButton::GtkSpinButton) = G_.get_adjustment(spinButton) -GtkAdjustment(range::GtkRange) = G_.get_adjustment(range) -GtkAdjustment(scale::GtkScaleButton) = G_.get_adjustment(scale) +@deprecate GtkAdjustment(spinButton::GtkSpinButton) adjustment(spinButton::GtkSpinButton) +@deprecate GtkAdjustment(range::GtkRange) adjustment(range::GtkRange) +@deprecate GtkAdjustment(scale::GtkScaleButton) adjustment(scale::GtkScaleButton) setindex!(buffer::GtkEntryBuffer, content::String, ::Type{String}) = G_.set_text(buffer, content, -1) + +## GtkDialog + +function push!(d::GtkDialog, s::AbstractString, response) + G_.add_button(d, s, Int32(response)) + d +end + +function response(widget::GtkDialog, response_id) + G_.response(widget, Int32(response_id)) +end + +function GtkDialog(title::AbstractString, buttons, flags, parent = nothing; kwargs...) + parent = (parent === nothing ? C_NULL : parent) + w = GtkDialogLeaf(ccall((:gtk_dialog_new_with_buttons, libgtk4), Ptr{GObject}, + (Ptr{UInt8}, Ptr{GObject}, Cint, Ptr{Nothing}), + title, parent, flags, C_NULL)) + GLib.setproperties!(w; kwargs...) + for (k, v) in buttons + push!(w, k, v) + end + w +end + +function GtkMessageDialog(message::AbstractString, buttons, flags, typ, parent = nothing; kwargs...) + parent = (parent === nothing ? C_NULL : parent) + w = GtkMessageDialogLeaf(ccall((:gtk_message_dialog_new, libgtk4), Ptr{GObject}, + (Ptr{GObject}, Cuint, Cint, Cint, Ptr{UInt8}), + parent, flags, typ, ButtonsType_NONE, message)) + GLib.setproperties!(w; kwargs...) + for (k, v) in buttons + push!(w, k, v) + end + w +end + diff --git a/src/windows.jl b/src/windows.jl index 6bd83631..11fa1b51 100644 --- a/src/windows.jl +++ b/src/windows.jl @@ -183,41 +183,6 @@ push!(hb::GtkHeaderBar, w::GtkWidget) = (G_.pack_end(hb, w); hb) pushfirst!(hb::GtkHeaderBar, w::GtkWidget) = (G_.pack_start(hb, w); hb) delete!(hb::GtkHeaderBar, w::GtkWidget) = (G_.remove(hb, w); hb) -## GtkDialog - -function push!(d::GtkDialog, s::AbstractString, response) - G_.add_button(d, s, Int32(response)) - d -end - -function response(widget::GtkDialog, response_id) - G_.response(widget, Int32(response_id)) -end - -function GtkDialog(title::AbstractString, buttons, flags, parent = nothing; kwargs...) - parent = (parent === nothing ? C_NULL : parent) - w = GtkDialogLeaf(ccall((:gtk_dialog_new_with_buttons, libgtk4), Ptr{GObject}, - (Ptr{UInt8}, Ptr{GObject}, Cint, Ptr{Nothing}), - title, parent, flags, C_NULL)) - GLib.setproperties!(w; kwargs...) - for (k, v) in buttons - push!(w, k, v) - end - w -end - -function GtkMessageDialog(message::AbstractString, buttons, flags, typ, parent = nothing; kwargs...) - parent = (parent === nothing ? C_NULL : parent) - w = GtkMessageDialogLeaf(ccall((:gtk_message_dialog_new, libgtk4), Ptr{GObject}, - (Ptr{GObject}, Cuint, Cint, Cint, Ptr{UInt8}), - parent, flags, typ, ButtonsType_NONE, message)) - GLib.setproperties!(w; kwargs...) - for (k, v) in buttons - push!(w, k, v) - end - w -end - """ ask_dialog(question::AbstractString, parent = nothing; timeout = -1) @@ -242,21 +207,20 @@ function ask_dialog(message::AbstractString, no_text, yes_text, parent = nothing end function ask_dialog(callback::Function, message::AbstractString, no_text, yes_text, parent = nothing; timeout = -1) - dlg = GtkMessageDialog(message, ((no_text, ResponseType_NO), (yes_text, ResponseType_YES)), - DialogFlags_DESTROY_WITH_PARENT, MessageType_QUESTION, parent) - - function on_response(dlg, response_id) - callback(response_id == Int32(ResponseType_YES)) - G_.set_transient_for(dlg, nothing) - destroy(dlg) - end - - signal_connect(on_response, dlg, "response") - show(dlg) - - if timeout > 0 - emit(timer) = response(dlg, Gtk4.ResponseType_NO) - Timer(emit, timeout) + dlg = GtkAlertDialog(message) + G_.set_buttons(dlg, [no_text, yes_text]) + + cancellable = GLib.cancel_after_delay(timeout) + choose(dlg, parent, cancellable) do dlg, resobj + res = try + Gtk4.choose_finish(dlg, resobj) + catch e + if !isa(e, Gtk4.GLib.GErrorException) + rethrow(e) + end + 0 + end + callback(Bool(res)) end return dlg end @@ -266,8 +230,7 @@ end Create a dialog with an informational message `message`. Returns when the dialog (or its parent window `parent`) is closed. The optional input `timeout` (disabled by default) can be -used to set a time in seconds after which the dialog will close and `false` will be -returned. +used to set a time in seconds after which the dialog will close. """ info_dialog for (func, flag) in ( @@ -286,21 +249,21 @@ for (func, flag) in ( end @eval function $func(callback::Function, message::AbstractString, parent = nothing; timeout = -1) - dlg = GtkMessageDialog(message, (("Close",0),), DialogFlags_DESTROY_WITH_PARENT, $flag, parent) - - function destroy_dialog(dlg, response_id) + dlg = GtkAlertDialog(message) + + function cb(dlg, resobj) + try + Gtk4.choose_finish(dlg, resobj) + catch e + if !isa(e, Gtk4.GLib.GErrorException) + rethrow(e) + end + end callback() - G_.set_transient_for(dlg, nothing) - destroy(dlg) end - signal_connect(destroy_dialog, dlg, "response") - show(dlg) - - if timeout > 0 - emit(timer) = response(dlg, Gtk4.ResponseType_CANCEL) - Timer(emit, timeout) - end + cancellable = GLib.cancel_after_delay(timeout) + choose(cb, dlg, parent, cancellable) return dlg end @@ -329,29 +292,42 @@ end function input_dialog(callback::Function, message::AbstractString, entry_default::AbstractString, buttons = (("Cancel", 0), ("Accept", 1)), parent = nothing; timeout = -1) - dlg = GtkMessageDialog(message, buttons, DialogFlags_DESTROY_WITH_PARENT, MessageType_INFO, parent) - box = content_area(dlg) - entry = GtkEntry() + dlg = GtkWindow() + box = GtkBox(:v) + push!(box, GtkLabel(message)) + entry = GtkEntry(; activates_default = true) entry.text = entry_default push!(box, entry) - - function on_response(dlg, response_id) - if response_id == 1 - res = text(GtkEditable(entry)) - else - res = "" - end - callback(res) + boxb = GtkBox(:h) + push!(box, boxb) + accept = GtkButton("Accept"; hexpand = true) + default_widget(dlg, accept) + cancel = GtkButton("Cancel"; hexpand = true) + push!(boxb, cancel) + push!(boxb, accept) + isnothing(parent) && (G_.set_transient_for(dlg, parent); G_.set_modal(dlg, true)) + dlg[] = box + + signal_connect(cancel, "clicked") do b + callback(entry_default) + G_.set_transient_for(dlg, nothing) + destroy(dlg) + end + + signal_connect(accept, "clicked") do b + callback(text(GtkEditable(entry))) G_.set_transient_for(dlg, nothing) destroy(dlg) end - signal_connect(on_response, dlg, "response") show(dlg) if timeout > 0 - emit(timer) = response(dlg, 0) - Timer(emit, timeout) + Timer(timeout) do timer + callback(entry_default) + G_.set_transient_for(dlg, nothing) + destroy(dlg) + end end return dlg end @@ -584,6 +560,14 @@ function GtkAlertDialog(message::AbstractString) end show(dlg::GtkAlertDialog, parent=nothing) = G_.show(dlg, parent) +function choose(cb, dlg::GtkAlertDialog, parent = nothing, cancellable = nothing) + G_.choose(dlg, parent, cancellable, cb) +end +function choose_finish(dlg, resobj) + G_.choose_finish(dlg, GAsyncResult(resobj)) +end + +### New file dialogs function _path_finish(f, dlg, resobj) gfile = f(dlg, Gtk4.GLib.GAsyncResult(resobj)) From d2d31ed833892ee6ef0bc557f27d1c6d3d841af2 Mon Sep 17 00:00:00 2001 From: Jared Wahlstrand Date: Sun, 21 Jan 2024 08:32:24 -0500 Subject: [PATCH 2/8] reduce code duplication --- src/windows.jl | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/windows.jl b/src/windows.jl index 11fa1b51..3e103653 100644 --- a/src/windows.jl +++ b/src/windows.jl @@ -278,6 +278,7 @@ or its parent window `parent` is closed. The optional input `timeout` (disabled can be used to set a time in seconds after which the dialog will close and `entry_default` will be returned. """ +## TODO: remove buttons argument function input_dialog(message::AbstractString, entry_default::AbstractString, buttons = (("Cancel", 0), ("Accept", 1)), parent = nothing; timeout = -1) res = Ref{String}("") c = Condition() @@ -290,6 +291,12 @@ function input_dialog(message::AbstractString, entry_default::AbstractString, bu return res[] end +function _callback_and_destroy(dlg, callback, txt) + callback(txt) + G_.set_transient_for(dlg, nothing) + destroy(dlg) +end + function input_dialog(callback::Function, message::AbstractString, entry_default::AbstractString, buttons = (("Cancel", 0), ("Accept", 1)), parent = nothing; timeout = -1) dlg = GtkWindow() @@ -300,33 +307,27 @@ function input_dialog(callback::Function, message::AbstractString, entry_default push!(box, entry) boxb = GtkBox(:h) push!(box, boxb) - accept = GtkButton("Accept"; hexpand = true) + accept = GtkButton(buttons[2][1]; hexpand = true) default_widget(dlg, accept) - cancel = GtkButton("Cancel"; hexpand = true) + cancel = GtkButton(buttons[1][1]; hexpand = true) push!(boxb, cancel) push!(boxb, accept) isnothing(parent) && (G_.set_transient_for(dlg, parent); G_.set_modal(dlg, true)) dlg[] = box signal_connect(cancel, "clicked") do b - callback(entry_default) - G_.set_transient_for(dlg, nothing) - destroy(dlg) + _callback_and_destroy(dlg, callback, entry_default) end signal_connect(accept, "clicked") do b - callback(text(GtkEditable(entry))) - G_.set_transient_for(dlg, nothing) - destroy(dlg) + _callback_and_destroy(dlg, callback, text(GtkEditable(entry))) end show(dlg) if timeout > 0 Timer(timeout) do timer - callback(entry_default) - G_.set_transient_for(dlg, nothing) - destroy(dlg) + _callback_and_destroy(dlg, callback, entry_default) end end return dlg From 4a386d6410fe02aa2ca65c5d13a8df40e4c44e38 Mon Sep 17 00:00:00 2001 From: Jared Wahlstrand Date: Fri, 12 Apr 2024 19:15:51 -0400 Subject: [PATCH 3/8] remove warn_dialog and error_dialog These have never looked any different from info_dialog, as far as I know. --- docs/src/manual/dialogs.md | 3 +-- src/deprecated.jl | 5 ++++ src/windows.jl | 51 +++++++++++++++++--------------------- test/gui/dialogs.jl | 4 --- 4 files changed, 29 insertions(+), 34 deletions(-) diff --git a/docs/src/manual/dialogs.md b/docs/src/manual/dialogs.md index 99c73645..0e1fcb66 100644 --- a/docs/src/manual/dialogs.md +++ b/docs/src/manual/dialogs.md @@ -10,14 +10,13 @@ Dialogs are transient windows that show information or ask the user for informat ## Message dialogs -Gtk4.jl supports `GtkMessageDialog` and provides several convenience functions: `info_dialog`, `ask_dialog`, `warn_dialog`, and `error_dialog`. Each takes a string for a message to show and an optional parent container, and returns nothing, except for `ask_dialog` which returns `true` if the user clicks the button corresponding to yes. +Gtk4.jl supports `GtkMessageDialog` and provides several convenience functions: `info_dialog`, `ask_dialog`, and `input_dialog`. Each takes a string for a message to show and an optional parent container, and returns nothing, except for `ask_dialog` which returns `true` if the user clicks the button corresponding to yes. For all dialog convenience functions, there are two ways of using them. For use in the REPL or an interactive script, the following forms can be used: ```julia info_dialog("Julia rocks!") ask_dialog("Do you like chocolate ice cream?", "Not at all", "I like it") && println("That's my favorite too.") -warn_dialog("Oops!... I did it again") ``` These take an optional argument `timeout` (in seconds) that can be used to make the dialog disappear after a certain time. diff --git a/src/deprecated.jl b/src/deprecated.jl index 80bec997..cd5aace3 100644 --- a/src/deprecated.jl +++ b/src/deprecated.jl @@ -40,3 +40,8 @@ function GtkMessageDialog(message::AbstractString, buttons, flags, typ, parent = w end +warn_dialog(callback::Function, message::AbstractString, parent = nothing; timeout = -1) = info_dialog(callback, message, parent; timeout = -1) +error_dialog(callback::Function, message::AbstractString, parent = nothing; timeout = -1) = info_dialog(callback, message, parent; timeout = -1) + +@deprecate warn_dialog info_dialog +@deprecate error_dialog info_dialog diff --git a/src/windows.jl b/src/windows.jl index f7dd3105..c7a35588 100644 --- a/src/windows.jl +++ b/src/windows.jl @@ -247,39 +247,34 @@ parent window `parent`) is closed. The optional input `timeout` (disabled by def used to set a time in seconds after which the dialog will close. """ info_dialog -for (func, flag) in ( - (:info_dialog, :(MessageType_INFO)), - (:warn_dialog, :(MessageType_WARNING)), - (:error_dialog, :(MessageType_ERROR))) - @eval function $func(message::AbstractString, parent = nothing; timeout = -1) - c = Condition() - - $func(message, parent; timeout) do - notify(c) - end - wait(c) - return +function info_dialog(message::AbstractString, parent = nothing; timeout = -1) + c = Condition() + + info_dialog(message, parent; timeout) do + notify(c) end + wait(c) + return +end - @eval function $func(callback::Function, message::AbstractString, parent = nothing; timeout = -1) - dlg = GtkAlertDialog(message) - - function cb(dlg, resobj) - try - Gtk4.choose_finish(dlg, resobj) - catch e - if !isa(e, Gtk4.GLib.GErrorException) - rethrow(e) - end +function info_dialog(callback::Function, message::AbstractString, parent = nothing; timeout = -1) + dlg = GtkAlertDialog(message) + + function cb(dlg, resobj) + try + Gtk4.choose_finish(dlg, resobj) + catch e + if !isa(e, Gtk4.GLib.GErrorException) + rethrow(e) end - callback() end - - cancellable = GLib.cancel_after_delay(timeout) - choose(cb, dlg, parent, cancellable) - - return dlg + callback() end + + cancellable = GLib.cancel_after_delay(timeout) + choose(cb, dlg, parent, cancellable) + + return dlg end """ diff --git a/test/gui/dialogs.jl b/test/gui/dialogs.jl index b3af6eb2..9e2466ba 100644 --- a/test/gui/dialogs.jl +++ b/test/gui/dialogs.jl @@ -19,10 +19,6 @@ main_window = GtkWindow("Dialog example") info_dialog("Here's some information", main_window; timeout = 0.25) sleep(1.0) -warn_dialog("Here's some alarming information", main_window; timeout = 0.25) -sleep(1.0) -error_dialog("Here's an error", main_window; timeout = 0.25) -sleep(1.0) GC.gc() sleep(1.0) close(main_window) From 6d8eb85a20473076e2a282cee91ba2691a86a506 Mon Sep 17 00:00:00 2001 From: Jared Wahlstrand Date: Sat, 13 Apr 2024 14:39:47 -0400 Subject: [PATCH 4/8] switch color_dialog to use GtkColorDialog Also fix constructor for non-opaque structs --- GI/src/giimport.jl | 8 +- src/Gdk4.jl | 2 +- src/gen/cairo_structs | 26 ++-- src/gen/gdk4_structs | 37 +++-- src/gen/gdkpixbuf_structs | 24 +++- src/gen/gio_structs | 134 ++++++++++++----- src/gen/glib_structs | 79 +++++++--- src/gen/gobject_structs | 178 ++++++++++++++++------- src/gen/graphene_structs | 217 +++++++++++++++++++--------- src/gen/gsk4_structs | 33 +++-- src/gen/gtk4_structs | 96 +++++++++---- src/gen/pango_structs | 293 +++++++++++++++++++++++++++----------- src/windows.jl | 31 ++-- test/gui/input.jl | 6 +- 14 files changed, 819 insertions(+), 345 deletions(-) diff --git a/GI/src/giimport.jl b/GI/src/giimport.jl index 0f247c48..a890f34e 100644 --- a/GI/src/giimport.jl +++ b/GI/src/giimport.jl @@ -86,11 +86,14 @@ function decl(structinfo::GIStructInfo,force_opaque=false) gstructname = get_full_name(structinfo) gtype=get_g_type(structinfo) isboxed = GLib.g_isa(gtype,GLib.g_type(GBoxed)) + ustructname=get_struct_name(structinfo,force_opaque) + opaque = force_opaque || isopaque(structinfo) + ctypename = opaque ? :GBoxed : :(Union{GBoxed,$ustructname}) exprs=Expr[] if isboxed fin = quote $(unblock(typeinit_def(structinfo,gstructname))) - function $gstructname(ref::Ptr{T}, own::Bool = false) where {T <: GBoxed} + function $gstructname(ref::Ptr{T}, own::Bool = false) where {T <: $ctypename} #println("constructing ",$(QuoteNode(gstructname)), " ",own) x = new(ref) if own @@ -105,8 +108,6 @@ function decl(structinfo::GIStructInfo,force_opaque=false) end end conv=nothing - opaque = force_opaque || isopaque(structinfo) - ustructname=get_struct_name(structinfo,force_opaque) if !opaque fieldsexpr=Expr[] for field in get_fields(structinfo) @@ -123,6 +124,7 @@ function decl(structinfo::GIStructInfo,force_opaque=false) push!(exprs,ustruc) conv = quote unsafe_convert(::Type{Ptr{$ustructname}}, box::$gstructname) = convert(Ptr{$ustructname}, box.handle) + convert(::Type{$gstructname}, p::Ptr{$ustructname}, owns = false) = $gstructname(p, owns) end end decl = isboxed ? :($gstructname <: GBoxed) : gstructname diff --git a/src/Gdk4.jl b/src/Gdk4.jl index c4ba40bb..0a76491c 100644 --- a/src/Gdk4.jl +++ b/src/Gdk4.jl @@ -5,7 +5,7 @@ keyval(name::AbstractString) = G_.keyval_from_name(name) function GdkRGBA(r,g,b,a = 1.0) s=_GdkRGBA(r,g,b,a) - r=ccall((:gdk_rgba_copy, libgtk4), Ptr{GdkRGBA}, (Ptr{_GdkRGBA},), Ref(s)) + r=ccall((:gdk_rgba_copy, libgtk4), Ptr{_GdkRGBA}, (Ptr{_GdkRGBA},), Ref(s)) GdkRGBA(r) end diff --git a/src/gen/cairo_structs b/src/gen/cairo_structs index d9429e17..dc6ad72e 100644 --- a/src/gen/cairo_structs +++ b/src/gen/cairo_structs @@ -164,7 +164,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: cairoRectangle) = begin ccall(("cairo_gobject_rectangle_get_type", libcairo_gobject), GType, ()) end - function cairoRectangle(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function cairoRectangle(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _cairoRectangle} x = new(ref) if own finalizer(x) do x @@ -176,9 +176,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, cairoRectangle) end end - unsafe_convert(::Type{Ptr{_cairoRectangle}}, box::cairoRectangle) = begin - convert(Ptr{_cairoRectangle}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_cairoRectangle}}, box::cairoRectangle) = begin + convert(Ptr{_cairoRectangle}, box.handle) + end + convert(::Type{cairoRectangle}, p::Ptr{_cairoRectangle}, owns = false) = begin + cairoRectangle(p, owns) + end + end end begin struct _cairoRectangleInt @@ -193,7 +198,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: cairoRectangleInt) = begin ccall(("cairo_gobject_rectangle_int_get_type", libcairo_gobject), GType, ()) end - function cairoRectangleInt(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function cairoRectangleInt(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _cairoRectangleInt} x = new(ref) if own finalizer(x) do x @@ -205,9 +210,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, cairoRectangleInt) end end - unsafe_convert(::Type{Ptr{_cairoRectangleInt}}, box::cairoRectangleInt) = begin - convert(Ptr{_cairoRectangleInt}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_cairoRectangleInt}}, box::cairoRectangleInt) = begin + convert(Ptr{_cairoRectangleInt}, box.handle) + end + convert(::Type{cairoRectangleInt}, p::Ptr{_cairoRectangleInt}, owns = false) = begin + cairoRectangleInt(p, owns) + end + end end gboxed_cache_init() = begin append!(GLib.gboxed_types, gboxed_types) diff --git a/src/gen/gdk4_structs b/src/gen/gdk4_structs index b9fb0efc..ec591fd3 100644 --- a/src/gen/gdk4_structs +++ b/src/gen/gdk4_structs @@ -103,9 +103,14 @@ $(Expr(:toplevel, quote mutable struct GdkKeymapKey handle::Ptr{_GdkKeymapKey} end - unsafe_convert(::Type{Ptr{_GdkKeymapKey}}, box::GdkKeymapKey) = begin - convert(Ptr{_GdkKeymapKey}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GdkKeymapKey}}, box::GdkKeymapKey) = begin + convert(Ptr{_GdkKeymapKey}, box.handle) + end + convert(::Type{GdkKeymapKey}, p::Ptr{_GdkKeymapKey}, owns = false) = begin + GdkKeymapKey(p, owns) + end + end end mutable struct GdkPopupLayout <: GBoxed handle::Ptr{GdkPopupLayout} @@ -138,7 +143,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GdkRGBA) = begin ccall(("gdk_rgba_get_type", libgtk4), GType, ()) end - function GdkRGBA(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GdkRGBA(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GdkRGBA} x = new(ref) if own finalizer(x) do x @@ -150,9 +155,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GdkRGBA) end end - unsafe_convert(::Type{Ptr{_GdkRGBA}}, box::GdkRGBA) = begin - convert(Ptr{_GdkRGBA}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GdkRGBA}}, box::GdkRGBA) = begin + convert(Ptr{_GdkRGBA}, box.handle) + end + convert(::Type{GdkRGBA}, p::Ptr{_GdkRGBA}, owns = false) = begin + GdkRGBA(p, owns) + end + end end begin struct _GdkRectangle @@ -167,7 +177,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GdkRectangle) = begin ccall(("gdk_rectangle_get_type", libgtk4), GType, ()) end - function GdkRectangle(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GdkRectangle(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GdkRectangle} x = new(ref) if own finalizer(x) do x @@ -179,9 +189,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GdkRectangle) end end - unsafe_convert(::Type{Ptr{_GdkRectangle}}, box::GdkRectangle) = begin - convert(Ptr{_GdkRectangle}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GdkRectangle}}, box::GdkRectangle) = begin + convert(Ptr{_GdkRectangle}, box.handle) + end + convert(::Type{GdkRectangle}, p::Ptr{_GdkRectangle}, owns = false) = begin + GdkRectangle(p, owns) + end + end end begin mutable struct GdkTimeCoord diff --git a/src/gen/gdkpixbuf_structs b/src/gen/gdkpixbuf_structs index 21488347..3515dc04 100644 --- a/src/gen/gdkpixbuf_structs +++ b/src/gen/gdkpixbuf_structs @@ -10,9 +10,14 @@ $(Expr(:toplevel, quote mutable struct GdkPixbufModulePattern handle::Ptr{_GdkPixbufModulePattern} end - unsafe_convert(::Type{Ptr{_GdkPixbufModulePattern}}, box::GdkPixbufModulePattern) = begin - convert(Ptr{_GdkPixbufModulePattern}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GdkPixbufModulePattern}}, box::GdkPixbufModulePattern) = begin + convert(Ptr{_GdkPixbufModulePattern}, box.handle) + end + convert(::Type{GdkPixbufModulePattern}, p::Ptr{_GdkPixbufModulePattern}, owns = false) = begin + GdkPixbufModulePattern(p, owns) + end + end end begin struct _GdkPixbufFormat @@ -32,7 +37,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GdkPixbufFormat) = begin ccall(("gdk_pixbuf_format_get_type", libgdkpixbuf), GType, ()) end - function GdkPixbufFormat(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GdkPixbufFormat(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GdkPixbufFormat} x = new(ref) if own finalizer(x) do x @@ -44,9 +49,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GdkPixbufFormat) end end - unsafe_convert(::Type{Ptr{_GdkPixbufFormat}}, box::GdkPixbufFormat) = begin - convert(Ptr{_GdkPixbufFormat}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GdkPixbufFormat}}, box::GdkPixbufFormat) = begin + convert(Ptr{_GdkPixbufFormat}, box.handle) + end + convert(::Type{GdkPixbufFormat}, p::Ptr{_GdkPixbufFormat}, owns = false) = begin + GdkPixbufFormat(p, owns) + end + end end gboxed_cache_init() = begin append!(GLib.gboxed_types, gboxed_types) diff --git a/src/gen/gio_structs b/src/gen/gio_structs index b633ee13..f9b62b94 100644 --- a/src/gen/gio_structs +++ b/src/gen/gio_structs @@ -8,9 +8,14 @@ $(Expr(:toplevel, quote mutable struct GDBusErrorEntry handle::Ptr{_GDBusErrorEntry} end - unsafe_convert(::Type{Ptr{_GDBusErrorEntry}}, box::GDBusErrorEntry) = begin - convert(Ptr{_GDBusErrorEntry}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GDBusErrorEntry}}, box::GDBusErrorEntry) = begin + convert(Ptr{_GDBusErrorEntry}, box.handle) + end + convert(::Type{GDBusErrorEntry}, p::Ptr{_GDBusErrorEntry}, owns = false) = begin + GDBusErrorEntry(p, owns) + end + end end begin struct _GFileAttributeInfo @@ -21,9 +26,14 @@ $(Expr(:toplevel, quote mutable struct GFileAttributeInfo handle::Ptr{_GFileAttributeInfo} end - unsafe_convert(::Type{Ptr{_GFileAttributeInfo}}, box::GFileAttributeInfo) = begin - convert(Ptr{_GFileAttributeInfo}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GFileAttributeInfo}}, box::GFileAttributeInfo) = begin + convert(Ptr{_GFileAttributeInfo}, box.handle) + end + convert(::Type{GFileAttributeInfo}, p::Ptr{_GFileAttributeInfo}, owns = false) = begin + GFileAttributeInfo(p, owns) + end + end end begin struct _GFileAttributeInfoList @@ -36,7 +46,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GFileAttributeInfoList) = begin ccall(("g_file_attribute_info_list_get_type", libgio), GType, ()) end - function GFileAttributeInfoList(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GFileAttributeInfoList(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GFileAttributeInfoList} x = new(ref) if own finalizer(x) do x @@ -48,9 +58,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GFileAttributeInfoList) end end - unsafe_convert(::Type{Ptr{_GFileAttributeInfoList}}, box::GFileAttributeInfoList) = begin - convert(Ptr{_GFileAttributeInfoList}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GFileAttributeInfoList}}, box::GFileAttributeInfoList) = begin + convert(Ptr{_GFileAttributeInfoList}, box.handle) + end + convert(::Type{GFileAttributeInfoList}, p::Ptr{_GFileAttributeInfoList}, owns = false) = begin + GFileAttributeInfoList(p, owns) + end + end end mutable struct GFileAttributeMatcher <: GBoxed handle::Ptr{GFileAttributeMatcher} @@ -78,9 +93,14 @@ $(Expr(:toplevel, quote mutable struct GInputVector handle::Ptr{_GInputVector} end - unsafe_convert(::Type{Ptr{_GInputVector}}, box::GInputVector) = begin - convert(Ptr{_GInputVector}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GInputVector}}, box::GInputVector) = begin + convert(Ptr{_GInputVector}, box.handle) + end + convert(::Type{GInputVector}, p::Ptr{_GInputVector}, owns = false) = begin + GInputVector(p, owns) + end + end end begin struct _GOutputVector @@ -90,9 +110,14 @@ $(Expr(:toplevel, quote mutable struct GOutputVector handle::Ptr{_GOutputVector} end - unsafe_convert(::Type{Ptr{_GOutputVector}}, box::GOutputVector) = begin - convert(Ptr{_GOutputVector}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GOutputVector}}, box::GOutputVector) = begin + convert(Ptr{_GOutputVector}, box.handle) + end + convert(::Type{GOutputVector}, p::Ptr{_GOutputVector}, owns = false) = begin + GOutputVector(p, owns) + end + end end mutable struct GResource <: GBoxed handle::Ptr{GResource} @@ -203,9 +228,14 @@ $(Expr(:toplevel, quote mutable struct GXdpDocumentsIface handle::Ptr{_GXdpDocumentsIface} end - unsafe_convert(::Type{Ptr{_GXdpDocumentsIface}}, box::GXdpDocumentsIface) = begin - convert(Ptr{_GXdpDocumentsIface}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GXdpDocumentsIface}}, box::GXdpDocumentsIface) = begin + convert(Ptr{_GXdpDocumentsIface}, box.handle) + end + convert(::Type{GXdpDocumentsIface}, p::Ptr{_GXdpDocumentsIface}, owns = false) = begin + GXdpDocumentsIface(p, owns) + end + end end begin struct _GXdpOpenURIIface @@ -218,9 +248,14 @@ $(Expr(:toplevel, quote mutable struct GXdpOpenURIIface handle::Ptr{_GXdpOpenURIIface} end - unsafe_convert(::Type{Ptr{_GXdpOpenURIIface}}, box::GXdpOpenURIIface) = begin - convert(Ptr{_GXdpOpenURIIface}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GXdpOpenURIIface}}, box::GXdpOpenURIIface) = begin + convert(Ptr{_GXdpOpenURIIface}, box.handle) + end + convert(::Type{GXdpOpenURIIface}, p::Ptr{_GXdpOpenURIIface}, owns = false) = begin + GXdpOpenURIIface(p, owns) + end + end end begin struct _GXdpProxyResolverIface @@ -231,9 +266,14 @@ $(Expr(:toplevel, quote mutable struct GXdpProxyResolverIface handle::Ptr{_GXdpProxyResolverIface} end - unsafe_convert(::Type{Ptr{_GXdpProxyResolverIface}}, box::GXdpProxyResolverIface) = begin - convert(Ptr{_GXdpProxyResolverIface}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GXdpProxyResolverIface}}, box::GXdpProxyResolverIface) = begin + convert(Ptr{_GXdpProxyResolverIface}, box.handle) + end + convert(::Type{GXdpProxyResolverIface}, p::Ptr{_GXdpProxyResolverIface}, owns = false) = begin + GXdpProxyResolverIface(p, owns) + end + end end begin struct _GXdpTrashIface @@ -244,9 +284,14 @@ $(Expr(:toplevel, quote mutable struct GXdpTrashIface handle::Ptr{_GXdpTrashIface} end - unsafe_convert(::Type{Ptr{_GXdpTrashIface}}, box::GXdpTrashIface) = begin - convert(Ptr{_GXdpTrashIface}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GXdpTrashIface}}, box::GXdpTrashIface) = begin + convert(Ptr{_GXdpTrashIface}, box.handle) + end + convert(::Type{GXdpTrashIface}, p::Ptr{_GXdpTrashIface}, owns = false) = begin + GXdpTrashIface(p, owns) + end + end end begin struct _G_FreedesktopDBusIface @@ -275,9 +320,14 @@ $(Expr(:toplevel, quote mutable struct G_FreedesktopDBusIface handle::Ptr{_G_FreedesktopDBusIface} end - unsafe_convert(::Type{Ptr{_G_FreedesktopDBusIface}}, box::G_FreedesktopDBusIface) = begin - convert(Ptr{_G_FreedesktopDBusIface}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_G_FreedesktopDBusIface}}, box::G_FreedesktopDBusIface) = begin + convert(Ptr{_G_FreedesktopDBusIface}, box.handle) + end + convert(::Type{G_FreedesktopDBusIface}, p::Ptr{_G_FreedesktopDBusIface}, owns = false) = begin + G_FreedesktopDBusIface(p, owns) + end + end end begin struct _G_FreedesktopDBusProxy @@ -287,9 +337,14 @@ $(Expr(:toplevel, quote mutable struct G_FreedesktopDBusProxy handle::Ptr{_G_FreedesktopDBusProxy} end - unsafe_convert(::Type{Ptr{_G_FreedesktopDBusProxy}}, box::G_FreedesktopDBusProxy) = begin - convert(Ptr{_G_FreedesktopDBusProxy}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_G_FreedesktopDBusProxy}}, box::G_FreedesktopDBusProxy) = begin + convert(Ptr{_G_FreedesktopDBusProxy}, box.handle) + end + convert(::Type{G_FreedesktopDBusProxy}, p::Ptr{_G_FreedesktopDBusProxy}, owns = false) = begin + G_FreedesktopDBusProxy(p, owns) + end + end end begin struct _G_FreedesktopDBusSkeleton @@ -299,9 +354,14 @@ $(Expr(:toplevel, quote mutable struct G_FreedesktopDBusSkeleton handle::Ptr{_G_FreedesktopDBusSkeleton} end - unsafe_convert(::Type{Ptr{_G_FreedesktopDBusSkeleton}}, box::G_FreedesktopDBusSkeleton) = begin - convert(Ptr{_G_FreedesktopDBusSkeleton}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_G_FreedesktopDBusSkeleton}}, box::G_FreedesktopDBusSkeleton) = begin + convert(Ptr{_G_FreedesktopDBusSkeleton}, box.handle) + end + convert(::Type{G_FreedesktopDBusSkeleton}, p::Ptr{_G_FreedesktopDBusSkeleton}, owns = false) = begin + G_FreedesktopDBusSkeleton(p, owns) + end + end end function GFileAttributeInfoList() G_.FileAttributeInfoList_new() diff --git a/src/gen/glib_structs b/src/gen/glib_structs index d7532ab3..8e3e4181 100644 --- a/src/gen/glib_structs +++ b/src/gen/glib_structs @@ -101,9 +101,14 @@ $(Expr(:toplevel, quote mutable struct GDebugKey handle::Ptr{_GDebugKey} end - unsafe_convert(::Type{Ptr{_GDebugKey}}, box::GDebugKey) = begin - convert(Ptr{_GDebugKey}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GDebugKey}}, box::GDebugKey) = begin + convert(Ptr{_GDebugKey}, box.handle) + end + convert(::Type{GDebugKey}, p::Ptr{_GDebugKey}, owns = false) = begin + GDebugKey(p, owns) + end + end end mutable struct GKeyFile <: GBoxed handle::Ptr{GKeyFile} @@ -132,9 +137,14 @@ $(Expr(:toplevel, quote mutable struct GLogField handle::Ptr{_GLogField} end - unsafe_convert(::Type{Ptr{_GLogField}}, box::GLogField) = begin - convert(Ptr{_GLogField}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GLogField}}, box::GLogField) = begin + convert(Ptr{_GLogField}, box.handle) + end + convert(::Type{GLogField}, p::Ptr{_GLogField}, owns = false) = begin + GLogField(p, owns) + end + end end mutable struct GMainContext <: GBoxed handle::Ptr{GMainContext} @@ -239,9 +249,14 @@ $(Expr(:toplevel, quote mutable struct GOptionEntry handle::Ptr{_GOptionEntry} end - unsafe_convert(::Type{Ptr{_GOptionEntry}}, box::GOptionEntry) = begin - convert(Ptr{_GOptionEntry}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GOptionEntry}}, box::GOptionEntry) = begin + convert(Ptr{_GOptionEntry}, box.handle) + end + convert(::Type{GOptionEntry}, p::Ptr{_GOptionEntry}, owns = false) = begin + GOptionEntry(p, owns) + end + end end mutable struct GPatternSpec <: GBoxed handle::Ptr{GPatternSpec} @@ -312,9 +327,14 @@ $(Expr(:toplevel, quote mutable struct GScannerConfig handle::Ptr{_GScannerConfig} end - unsafe_convert(::Type{Ptr{_GScannerConfig}}, box::GScannerConfig) = begin - convert(Ptr{_GScannerConfig}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GScannerConfig}}, box::GScannerConfig) = begin + convert(Ptr{_GScannerConfig}, box.handle) + end + convert(::Type{GScannerConfig}, p::Ptr{_GScannerConfig}, owns = false) = begin + GScannerConfig(p, owns) + end + end end begin mutable struct GSource <: GBoxed @@ -346,9 +366,14 @@ $(Expr(:toplevel, quote mutable struct GSourceCallbackFuncs handle::Ptr{_GSourceCallbackFuncs} end - unsafe_convert(::Type{Ptr{_GSourceCallbackFuncs}}, box::GSourceCallbackFuncs) = begin - convert(Ptr{_GSourceCallbackFuncs}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GSourceCallbackFuncs}}, box::GSourceCallbackFuncs) = begin + convert(Ptr{_GSourceCallbackFuncs}, box.handle) + end + convert(::Type{GSourceCallbackFuncs}, p::Ptr{_GSourceCallbackFuncs}, owns = false) = begin + GSourceCallbackFuncs(p, owns) + end + end end begin struct _GString @@ -362,7 +387,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GString) = begin ccall(("g_gstring_get_type", libgobject), GType, ()) end - function GString(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GString(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GString} x = new(ref) if own finalizer(x) do x @@ -374,9 +399,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GString) end end - unsafe_convert(::Type{Ptr{_GString}}, box::GString) = begin - convert(Ptr{_GString}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GString}}, box::GString) = begin + convert(Ptr{_GString}, box.handle) + end + convert(::Type{GString}, p::Ptr{_GString}, owns = false) = begin + GString(p, owns) + end + end end begin struct _GTestConfig @@ -390,9 +420,14 @@ $(Expr(:toplevel, quote mutable struct GTestConfig handle::Ptr{_GTestConfig} end - unsafe_convert(::Type{Ptr{_GTestConfig}}, box::GTestConfig) = begin - convert(Ptr{_GTestConfig}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GTestConfig}}, box::GTestConfig) = begin + convert(Ptr{_GTestConfig}, box.handle) + end + convert(::Type{GTestConfig}, p::Ptr{_GTestConfig}, owns = false) = begin + GTestConfig(p, owns) + end + end end mutable struct GTimeZone <: GBoxed handle::Ptr{GTimeZone} diff --git a/src/gen/gobject_structs b/src/gen/gobject_structs index 33250194..2e21f3d7 100644 --- a/src/gen/gobject_structs +++ b/src/gen/gobject_structs @@ -9,9 +9,14 @@ $(Expr(:toplevel, quote mutable struct GEnumValue handle::Ptr{_GEnumValue} end - unsafe_convert(::Type{Ptr{_GEnumValue}}, box::GEnumValue) = begin - convert(Ptr{_GEnumValue}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GEnumValue}}, box::GEnumValue) = begin + convert(Ptr{_GEnumValue}, box.handle) + end + convert(::Type{GEnumValue}, p::Ptr{_GEnumValue}, owns = false) = begin + GEnumValue(p, owns) + end + end end begin struct _GTypeClass @@ -20,9 +25,14 @@ $(Expr(:toplevel, quote mutable struct GTypeClass handle::Ptr{_GTypeClass} end - unsafe_convert(::Type{Ptr{_GTypeClass}}, box::GTypeClass) = begin - convert(Ptr{_GTypeClass}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GTypeClass}}, box::GTypeClass) = begin + convert(Ptr{_GTypeClass}, box.handle) + end + convert(::Type{GTypeClass}, p::Ptr{_GTypeClass}, owns = false) = begin + GTypeClass(p, owns) + end + end end begin struct _GTypeInterface @@ -32,9 +42,14 @@ $(Expr(:toplevel, quote mutable struct GTypeInterface handle::Ptr{_GTypeInterface} end - unsafe_convert(::Type{Ptr{_GTypeInterface}}, box::GTypeInterface) = begin - convert(Ptr{_GTypeInterface}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GTypeInterface}}, box::GTypeInterface) = begin + convert(Ptr{_GTypeInterface}, box.handle) + end + convert(::Type{GTypeInterface}, p::Ptr{_GTypeInterface}, owns = false) = begin + GTypeInterface(p, owns) + end + end end begin struct _GFlagsValue @@ -45,9 +60,14 @@ $(Expr(:toplevel, quote mutable struct GFlagsValue handle::Ptr{_GFlagsValue} end - unsafe_convert(::Type{Ptr{_GFlagsValue}}, box::GFlagsValue) = begin - convert(Ptr{_GFlagsValue}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GFlagsValue}}, box::GFlagsValue) = begin + convert(Ptr{_GFlagsValue}, box.handle) + end + convert(::Type{GFlagsValue}, p::Ptr{_GFlagsValue}, owns = false) = begin + GFlagsValue(p, owns) + end + end end begin struct _GTypeValueTable @@ -63,9 +83,14 @@ $(Expr(:toplevel, quote mutable struct GTypeValueTable handle::Ptr{_GTypeValueTable} end - unsafe_convert(::Type{Ptr{_GTypeValueTable}}, box::GTypeValueTable) = begin - convert(Ptr{_GTypeValueTable}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GTypeValueTable}}, box::GTypeValueTable) = begin + convert(Ptr{_GTypeValueTable}, box.handle) + end + convert(::Type{GTypeValueTable}, p::Ptr{_GTypeValueTable}, owns = false) = begin + GTypeValueTable(p, owns) + end + end end begin struct _GEnumClass @@ -78,9 +103,14 @@ $(Expr(:toplevel, quote mutable struct GEnumClass handle::Ptr{_GEnumClass} end - unsafe_convert(::Type{Ptr{_GEnumClass}}, box::GEnumClass) = begin - convert(Ptr{_GEnumClass}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GEnumClass}}, box::GEnumClass) = begin + convert(Ptr{_GEnumClass}, box.handle) + end + convert(::Type{GEnumClass}, p::Ptr{_GEnumClass}, owns = false) = begin + GEnumClass(p, owns) + end + end end begin struct _GFlagsClass @@ -92,9 +122,14 @@ $(Expr(:toplevel, quote mutable struct GFlagsClass handle::Ptr{_GFlagsClass} end - unsafe_convert(::Type{Ptr{_GFlagsClass}}, box::GFlagsClass) = begin - convert(Ptr{_GFlagsClass}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GFlagsClass}}, box::GFlagsClass) = begin + convert(Ptr{_GFlagsClass}, box.handle) + end + convert(::Type{GFlagsClass}, p::Ptr{_GFlagsClass}, owns = false) = begin + GFlagsClass(p, owns) + end + end end begin struct _GInterfaceInfo @@ -105,9 +140,14 @@ $(Expr(:toplevel, quote mutable struct GInterfaceInfo handle::Ptr{_GInterfaceInfo} end - unsafe_convert(::Type{Ptr{_GInterfaceInfo}}, box::GInterfaceInfo) = begin - convert(Ptr{_GInterfaceInfo}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GInterfaceInfo}}, box::GInterfaceInfo) = begin + convert(Ptr{_GInterfaceInfo}, box.handle) + end + convert(::Type{GInterfaceInfo}, p::Ptr{_GInterfaceInfo}, owns = false) = begin + GInterfaceInfo(p, owns) + end + end end begin struct _GParamSpecTypeInfo @@ -123,9 +163,14 @@ $(Expr(:toplevel, quote mutable struct GParamSpecTypeInfo handle::Ptr{_GParamSpecTypeInfo} end - unsafe_convert(::Type{Ptr{_GParamSpecTypeInfo}}, box::GParamSpecTypeInfo) = begin - convert(Ptr{_GParamSpecTypeInfo}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GParamSpecTypeInfo}}, box::GParamSpecTypeInfo) = begin + convert(Ptr{_GParamSpecTypeInfo}, box.handle) + end + convert(::Type{GParamSpecTypeInfo}, p::Ptr{_GParamSpecTypeInfo}, owns = false) = begin + GParamSpecTypeInfo(p, owns) + end + end end begin struct _GSignalInvocationHint @@ -136,9 +181,14 @@ $(Expr(:toplevel, quote mutable struct GSignalInvocationHint handle::Ptr{_GSignalInvocationHint} end - unsafe_convert(::Type{Ptr{_GSignalInvocationHint}}, box::GSignalInvocationHint) = begin - convert(Ptr{_GSignalInvocationHint}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GSignalInvocationHint}}, box::GSignalInvocationHint) = begin + convert(Ptr{_GSignalInvocationHint}, box.handle) + end + convert(::Type{GSignalInvocationHint}, p::Ptr{_GSignalInvocationHint}, owns = false) = begin + GSignalInvocationHint(p, owns) + end + end end begin struct _GSignalQuery @@ -153,9 +203,14 @@ $(Expr(:toplevel, quote mutable struct GSignalQuery handle::Ptr{_GSignalQuery} end - unsafe_convert(::Type{Ptr{_GSignalQuery}}, box::GSignalQuery) = begin - convert(Ptr{_GSignalQuery}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GSignalQuery}}, box::GSignalQuery) = begin + convert(Ptr{_GSignalQuery}, box.handle) + end + convert(::Type{GSignalQuery}, p::Ptr{_GSignalQuery}, owns = false) = begin + GSignalQuery(p, owns) + end + end end begin struct _GTypeFundamentalInfo @@ -164,9 +219,14 @@ $(Expr(:toplevel, quote mutable struct GTypeFundamentalInfo handle::Ptr{_GTypeFundamentalInfo} end - unsafe_convert(::Type{Ptr{_GTypeFundamentalInfo}}, box::GTypeFundamentalInfo) = begin - convert(Ptr{_GTypeFundamentalInfo}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GTypeFundamentalInfo}}, box::GTypeFundamentalInfo) = begin + convert(Ptr{_GTypeFundamentalInfo}, box.handle) + end + convert(::Type{GTypeFundamentalInfo}, p::Ptr{_GTypeFundamentalInfo}, owns = false) = begin + GTypeFundamentalInfo(p, owns) + end + end end begin struct _GTypeInfo @@ -184,9 +244,14 @@ $(Expr(:toplevel, quote mutable struct GTypeInfo handle::Ptr{_GTypeInfo} end - unsafe_convert(::Type{Ptr{_GTypeInfo}}, box::GTypeInfo) = begin - convert(Ptr{_GTypeInfo}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GTypeInfo}}, box::GTypeInfo) = begin + convert(Ptr{_GTypeInfo}, box.handle) + end + convert(::Type{GTypeInfo}, p::Ptr{_GTypeInfo}, owns = false) = begin + GTypeInfo(p, owns) + end + end end begin struct _GTypePluginClass @@ -199,9 +264,14 @@ $(Expr(:toplevel, quote mutable struct GTypePluginClass handle::Ptr{_GTypePluginClass} end - unsafe_convert(::Type{Ptr{_GTypePluginClass}}, box::GTypePluginClass) = begin - convert(Ptr{_GTypePluginClass}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GTypePluginClass}}, box::GTypePluginClass) = begin + convert(Ptr{_GTypePluginClass}, box.handle) + end + convert(::Type{GTypePluginClass}, p::Ptr{_GTypePluginClass}, owns = false) = begin + GTypePluginClass(p, owns) + end + end end begin struct _GTypeQuery @@ -213,9 +283,14 @@ $(Expr(:toplevel, quote mutable struct GTypeQuery handle::Ptr{_GTypeQuery} end - unsafe_convert(::Type{Ptr{_GTypeQuery}}, box::GTypeQuery) = begin - convert(Ptr{_GTypeQuery}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GTypeQuery}}, box::GTypeQuery) = begin + convert(Ptr{_GTypeQuery}, box.handle) + end + convert(::Type{GTypeQuery}, p::Ptr{_GTypeQuery}, owns = false) = begin + GTypeQuery(p, owns) + end + end end begin struct _GValueArray @@ -229,7 +304,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GValueArray) = begin ccall(("g_value_array_get_type", libgobject), GType, ()) end - function GValueArray(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GValueArray(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GValueArray} x = new(ref) if own finalizer(x) do x @@ -241,9 +316,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GValueArray) end end - unsafe_convert(::Type{Ptr{_GValueArray}}, box::GValueArray) = begin - convert(Ptr{_GValueArray}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GValueArray}}, box::GValueArray) = begin + convert(Ptr{_GValueArray}, box.handle) + end + convert(::Type{GValueArray}, p::Ptr{_GValueArray}, owns = false) = begin + GValueArray(p, owns) + end + end end @doc "See the [GTK docs](https://docs.gtk.org/gobject/struct.EnumClass.html)." GEnumClass @doc "See the [GTK docs](https://docs.gtk.org/gobject/struct.FlagsClass.html)." GFlagsClass diff --git a/src/gen/graphene_structs b/src/gen/graphene_structs index 5885e1f9..255a26ca 100644 --- a/src/gen/graphene_structs +++ b/src/gen/graphene_structs @@ -11,9 +11,14 @@ $(Expr(:toplevel, quote mutable struct GrapheneSimd4F handle::Ptr{_GrapheneSimd4F} end - unsafe_convert(::Type{Ptr{_GrapheneSimd4F}}, box::GrapheneSimd4F) = begin - convert(Ptr{_GrapheneSimd4F}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GrapheneSimd4F}}, box::GrapheneSimd4F) = begin + convert(Ptr{_GrapheneSimd4F}, box.handle) + end + convert(::Type{GrapheneSimd4F}, p::Ptr{_GrapheneSimd4F}, owns = false) = begin + GrapheneSimd4F(p, owns) + end + end end begin struct _GrapheneVec3 @@ -25,7 +30,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GrapheneVec3) = begin ccall(("graphene_vec3_get_type", libgraphene), GType, ()) end - function GrapheneVec3(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GrapheneVec3(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GrapheneVec3} x = new(ref) if own finalizer(x) do x @@ -37,9 +42,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GrapheneVec3) end end - unsafe_convert(::Type{Ptr{_GrapheneVec3}}, box::GrapheneVec3) = begin - convert(Ptr{_GrapheneVec3}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GrapheneVec3}}, box::GrapheneVec3) = begin + convert(Ptr{_GrapheneVec3}, box.handle) + end + convert(::Type{GrapheneVec3}, p::Ptr{_GrapheneVec3}, owns = false) = begin + GrapheneVec3(p, owns) + end + end end begin struct _GrapheneSimd4X4F @@ -51,9 +61,14 @@ $(Expr(:toplevel, quote mutable struct GrapheneSimd4X4F handle::Ptr{_GrapheneSimd4X4F} end - unsafe_convert(::Type{Ptr{_GrapheneSimd4X4F}}, box::GrapheneSimd4X4F) = begin - convert(Ptr{_GrapheneSimd4X4F}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GrapheneSimd4X4F}}, box::GrapheneSimd4X4F) = begin + convert(Ptr{_GrapheneSimd4X4F}, box.handle) + end + convert(::Type{GrapheneSimd4X4F}, p::Ptr{_GrapheneSimd4X4F}, owns = false) = begin + GrapheneSimd4X4F(p, owns) + end + end end begin struct _GrapheneSize @@ -66,7 +81,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GrapheneSize) = begin ccall(("graphene_size_get_type", libgraphene), GType, ()) end - function GrapheneSize(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GrapheneSize(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GrapheneSize} x = new(ref) if own finalizer(x) do x @@ -78,9 +93,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GrapheneSize) end end - unsafe_convert(::Type{Ptr{_GrapheneSize}}, box::GrapheneSize) = begin - convert(Ptr{_GrapheneSize}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GrapheneSize}}, box::GrapheneSize) = begin + convert(Ptr{_GrapheneSize}, box.handle) + end + convert(::Type{GrapheneSize}, p::Ptr{_GrapheneSize}, owns = false) = begin + GrapheneSize(p, owns) + end + end end function GrapheneVec3() G_.Vec3_alloc() @@ -99,7 +119,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GrapheneBox) = begin ccall(("graphene_box_get_type", libgraphene), GType, ()) end - function GrapheneBox(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GrapheneBox(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GrapheneBox} x = new(ref) if own finalizer(x) do x @@ -111,9 +131,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GrapheneBox) end end - unsafe_convert(::Type{Ptr{_GrapheneBox}}, box::GrapheneBox) = begin - convert(Ptr{_GrapheneBox}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GrapheneBox}}, box::GrapheneBox) = begin + convert(Ptr{_GrapheneBox}, box.handle) + end + convert(::Type{GrapheneBox}, p::Ptr{_GrapheneBox}, owns = false) = begin + GrapheneBox(p, owns) + end + end end begin struct _GrapheneEuler @@ -126,7 +151,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GrapheneEuler) = begin ccall(("graphene_euler_get_type", libgraphene), GType, ()) end - function GrapheneEuler(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GrapheneEuler(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GrapheneEuler} x = new(ref) if own finalizer(x) do x @@ -138,9 +163,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GrapheneEuler) end end - unsafe_convert(::Type{Ptr{_GrapheneEuler}}, box::GrapheneEuler) = begin - convert(Ptr{_GrapheneEuler}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GrapheneEuler}}, box::GrapheneEuler) = begin + convert(Ptr{_GrapheneEuler}, box.handle) + end + convert(::Type{GrapheneEuler}, p::Ptr{_GrapheneEuler}, owns = false) = begin + GrapheneEuler(p, owns) + end + end end begin mutable struct GrapheneFrustum <: GBoxed @@ -173,7 +203,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GrapheneMatrix) = begin ccall(("graphene_matrix_get_type", libgraphene), GType, ()) end - function GrapheneMatrix(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GrapheneMatrix(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GrapheneMatrix} x = new(ref) if own finalizer(x) do x @@ -185,9 +215,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GrapheneMatrix) end end - unsafe_convert(::Type{Ptr{_GrapheneMatrix}}, box::GrapheneMatrix) = begin - convert(Ptr{_GrapheneMatrix}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GrapheneMatrix}}, box::GrapheneMatrix) = begin + convert(Ptr{_GrapheneMatrix}, box.handle) + end + convert(::Type{GrapheneMatrix}, p::Ptr{_GrapheneMatrix}, owns = false) = begin + GrapheneMatrix(p, owns) + end + end end begin struct _GraphenePlane @@ -200,7 +235,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GraphenePlane) = begin ccall(("graphene_plane_get_type", libgraphene), GType, ()) end - function GraphenePlane(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GraphenePlane(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GraphenePlane} x = new(ref) if own finalizer(x) do x @@ -212,9 +247,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GraphenePlane) end end - unsafe_convert(::Type{Ptr{_GraphenePlane}}, box::GraphenePlane) = begin - convert(Ptr{_GraphenePlane}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GraphenePlane}}, box::GraphenePlane) = begin + convert(Ptr{_GraphenePlane}, box.handle) + end + convert(::Type{GraphenePlane}, p::Ptr{_GraphenePlane}, owns = false) = begin + GraphenePlane(p, owns) + end + end end begin struct _GraphenePoint @@ -227,7 +267,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GraphenePoint) = begin ccall(("graphene_point_get_type", libgraphene), GType, ()) end - function GraphenePoint(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GraphenePoint(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GraphenePoint} x = new(ref) if own finalizer(x) do x @@ -239,9 +279,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GraphenePoint) end end - unsafe_convert(::Type{Ptr{_GraphenePoint}}, box::GraphenePoint) = begin - convert(Ptr{_GraphenePoint}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GraphenePoint}}, box::GraphenePoint) = begin + convert(Ptr{_GraphenePoint}, box.handle) + end + convert(::Type{GraphenePoint}, p::Ptr{_GraphenePoint}, owns = false) = begin + GraphenePoint(p, owns) + end + end end begin struct _GraphenePoint3D @@ -255,7 +300,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GraphenePoint3D) = begin ccall(("graphene_point3d_get_type", libgraphene), GType, ()) end - function GraphenePoint3D(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GraphenePoint3D(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GraphenePoint3D} x = new(ref) if own finalizer(x) do x @@ -267,9 +312,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GraphenePoint3D) end end - unsafe_convert(::Type{Ptr{_GraphenePoint3D}}, box::GraphenePoint3D) = begin - convert(Ptr{_GraphenePoint3D}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GraphenePoint3D}}, box::GraphenePoint3D) = begin + convert(Ptr{_GraphenePoint3D}, box.handle) + end + convert(::Type{GraphenePoint3D}, p::Ptr{_GraphenePoint3D}, owns = false) = begin + GraphenePoint3D(p, owns) + end + end end begin mutable struct GrapheneQuad <: GBoxed @@ -305,7 +355,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GrapheneQuaternion) = begin ccall(("graphene_quaternion_get_type", libgraphene), GType, ()) end - function GrapheneQuaternion(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GrapheneQuaternion(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GrapheneQuaternion} x = new(ref) if own finalizer(x) do x @@ -317,9 +367,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GrapheneQuaternion) end end - unsafe_convert(::Type{Ptr{_GrapheneQuaternion}}, box::GrapheneQuaternion) = begin - convert(Ptr{_GrapheneQuaternion}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GrapheneQuaternion}}, box::GrapheneQuaternion) = begin + convert(Ptr{_GrapheneQuaternion}, box.handle) + end + convert(::Type{GrapheneQuaternion}, p::Ptr{_GrapheneQuaternion}, owns = false) = begin + GrapheneQuaternion(p, owns) + end + end end begin struct _GrapheneRay @@ -332,7 +387,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GrapheneRay) = begin ccall(("graphene_ray_get_type", libgraphene), GType, ()) end - function GrapheneRay(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GrapheneRay(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GrapheneRay} x = new(ref) if own finalizer(x) do x @@ -344,9 +399,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GrapheneRay) end end - unsafe_convert(::Type{Ptr{_GrapheneRay}}, box::GrapheneRay) = begin - convert(Ptr{_GrapheneRay}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GrapheneRay}}, box::GrapheneRay) = begin + convert(Ptr{_GrapheneRay}, box.handle) + end + convert(::Type{GrapheneRay}, p::Ptr{_GrapheneRay}, owns = false) = begin + GrapheneRay(p, owns) + end + end end begin struct _GrapheneRect @@ -359,7 +419,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GrapheneRect) = begin ccall(("graphene_rect_get_type", libgraphene), GType, ()) end - function GrapheneRect(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GrapheneRect(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GrapheneRect} x = new(ref) if own finalizer(x) do x @@ -371,9 +431,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GrapheneRect) end end - unsafe_convert(::Type{Ptr{_GrapheneRect}}, box::GrapheneRect) = begin - convert(Ptr{_GrapheneRect}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GrapheneRect}}, box::GrapheneRect) = begin + convert(Ptr{_GrapheneRect}, box.handle) + end + convert(::Type{GrapheneRect}, p::Ptr{_GrapheneRect}, owns = false) = begin + GrapheneRect(p, owns) + end + end end begin struct _GrapheneSphere @@ -386,7 +451,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GrapheneSphere) = begin ccall(("graphene_sphere_get_type", libgraphene), GType, ()) end - function GrapheneSphere(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GrapheneSphere(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GrapheneSphere} x = new(ref) if own finalizer(x) do x @@ -398,9 +463,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GrapheneSphere) end end - unsafe_convert(::Type{Ptr{_GrapheneSphere}}, box::GrapheneSphere) = begin - convert(Ptr{_GrapheneSphere}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GrapheneSphere}}, box::GrapheneSphere) = begin + convert(Ptr{_GrapheneSphere}, box.handle) + end + convert(::Type{GrapheneSphere}, p::Ptr{_GrapheneSphere}, owns = false) = begin + GrapheneSphere(p, owns) + end + end end begin struct _GrapheneTriangle @@ -414,7 +484,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GrapheneTriangle) = begin ccall(("graphene_triangle_get_type", libgraphene), GType, ()) end - function GrapheneTriangle(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GrapheneTriangle(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GrapheneTriangle} x = new(ref) if own finalizer(x) do x @@ -426,9 +496,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GrapheneTriangle) end end - unsafe_convert(::Type{Ptr{_GrapheneTriangle}}, box::GrapheneTriangle) = begin - convert(Ptr{_GrapheneTriangle}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GrapheneTriangle}}, box::GrapheneTriangle) = begin + convert(Ptr{_GrapheneTriangle}, box.handle) + end + convert(::Type{GrapheneTriangle}, p::Ptr{_GrapheneTriangle}, owns = false) = begin + GrapheneTriangle(p, owns) + end + end end begin struct _GrapheneVec2 @@ -440,7 +515,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GrapheneVec2) = begin ccall(("graphene_vec2_get_type", libgraphene), GType, ()) end - function GrapheneVec2(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GrapheneVec2(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GrapheneVec2} x = new(ref) if own finalizer(x) do x @@ -452,9 +527,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GrapheneVec2) end end - unsafe_convert(::Type{Ptr{_GrapheneVec2}}, box::GrapheneVec2) = begin - convert(Ptr{_GrapheneVec2}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GrapheneVec2}}, box::GrapheneVec2) = begin + convert(Ptr{_GrapheneVec2}, box.handle) + end + convert(::Type{GrapheneVec2}, p::Ptr{_GrapheneVec2}, owns = false) = begin + GrapheneVec2(p, owns) + end + end end begin struct _GrapheneVec4 @@ -466,7 +546,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GrapheneVec4) = begin ccall(("graphene_vec4_get_type", libgraphene), GType, ()) end - function GrapheneVec4(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GrapheneVec4(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GrapheneVec4} x = new(ref) if own finalizer(x) do x @@ -478,9 +558,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GrapheneVec4) end end - unsafe_convert(::Type{Ptr{_GrapheneVec4}}, box::GrapheneVec4) = begin - convert(Ptr{_GrapheneVec4}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GrapheneVec4}}, box::GrapheneVec4) = begin + convert(Ptr{_GrapheneVec4}, box.handle) + end + convert(::Type{GrapheneVec4}, p::Ptr{_GrapheneVec4}, owns = false) = begin + GrapheneVec4(p, owns) + end + end end gboxed_cache_init() = begin append!(GLib.gboxed_types, gboxed_types) diff --git a/src/gen/gsk4_structs b/src/gen/gsk4_structs index 8ab863a2..8f777925 100644 --- a/src/gen/gsk4_structs +++ b/src/gen/gsk4_structs @@ -9,9 +9,14 @@ $(Expr(:toplevel, quote mutable struct GskColorStop handle::Ptr{_GskColorStop} end - unsafe_convert(::Type{Ptr{_GskColorStop}}, box::GskColorStop) = begin - convert(Ptr{_GskColorStop}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GskColorStop}}, box::GskColorStop) = begin + convert(Ptr{_GskColorStop}, box.handle) + end + convert(::Type{GskColorStop}, p::Ptr{_GskColorStop}, owns = false) = begin + GskColorStop(p, owns) + end + end end begin struct _GskParseLocation @@ -24,9 +29,14 @@ $(Expr(:toplevel, quote mutable struct GskParseLocation handle::Ptr{_GskParseLocation} end - unsafe_convert(::Type{Ptr{_GskParseLocation}}, box::GskParseLocation) = begin - convert(Ptr{_GskParseLocation}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GskParseLocation}}, box::GskParseLocation) = begin + convert(Ptr{_GskParseLocation}, box.handle) + end + convert(::Type{GskParseLocation}, p::Ptr{_GskParseLocation}, owns = false) = begin + GskParseLocation(p, owns) + end + end end begin mutable struct GskRoundedRect @@ -44,9 +54,14 @@ $(Expr(:toplevel, quote mutable struct GskShadow handle::Ptr{_GskShadow} end - unsafe_convert(::Type{Ptr{_GskShadow}}, box::GskShadow) = begin - convert(Ptr{_GskShadow}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GskShadow}}, box::GskShadow) = begin + convert(Ptr{_GskShadow}, box.handle) + end + convert(::Type{GskShadow}, p::Ptr{_GskShadow}, owns = false) = begin + GskShadow(p, owns) + end + end end mutable struct GskTransform <: GBoxed handle::Ptr{GskTransform} diff --git a/src/gen/gtk4_structs b/src/gen/gtk4_structs index 132cac2e..ccdccf5c 100644 --- a/src/gen/gtk4_structs +++ b/src/gen/gtk4_structs @@ -53,7 +53,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GtkBorder) = begin ccall(("gtk_border_get_type", libgtk4), GType, ()) end - function GtkBorder(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GtkBorder(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GtkBorder} x = new(ref) if own finalizer(x) do x @@ -65,9 +65,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GtkBorder) end end - unsafe_convert(::Type{Ptr{_GtkBorder}}, box::GtkBorder) = begin - convert(Ptr{_GtkBorder}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GtkBorder}}, box::GtkBorder) = begin + convert(Ptr{_GtkBorder}, box.handle) + end + convert(::Type{GtkBorder}, p::Ptr{_GtkBorder}, owns = false) = begin + GtkBorder(p, owns) + end + end end mutable struct GtkBuildableParseContext handle::Ptr{GtkBuildableParseContext} @@ -89,9 +94,14 @@ $(Expr(:toplevel, quote mutable struct GtkCssLocation handle::Ptr{_GtkCssLocation} end - unsafe_convert(::Type{Ptr{_GtkCssLocation}}, box::GtkCssLocation) = begin - convert(Ptr{_GtkCssLocation}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GtkCssLocation}}, box::GtkCssLocation) = begin + convert(Ptr{_GtkCssLocation}, box.handle) + end + convert(::Type{GtkCssLocation}, p::Ptr{_GtkCssLocation}, owns = false) = begin + GtkCssLocation(p, owns) + end + end end mutable struct GtkCssSection <: GBoxed handle::Ptr{GtkCssSection} @@ -143,9 +153,14 @@ $(Expr(:toplevel, quote mutable struct GtkPadActionEntry handle::Ptr{_GtkPadActionEntry} end - unsafe_convert(::Type{Ptr{_GtkPadActionEntry}}, box::GtkPadActionEntry) = begin - convert(Ptr{_GtkPadActionEntry}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GtkPadActionEntry}}, box::GtkPadActionEntry) = begin + convert(Ptr{_GtkPadActionEntry}, box.handle) + end + convert(::Type{GtkPadActionEntry}, p::Ptr{_GtkPadActionEntry}, owns = false) = begin + GtkPadActionEntry(p, owns) + end + end end mutable struct GtkPaperSize <: GBoxed handle::Ptr{GtkPaperSize} @@ -181,9 +196,14 @@ $(Expr(:toplevel, quote mutable struct GtkRecentData handle::Ptr{_GtkRecentData} end - unsafe_convert(::Type{Ptr{_GtkRecentData}}, box::GtkRecentData) = begin - convert(Ptr{_GtkRecentData}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GtkRecentData}}, box::GtkRecentData) = begin + convert(Ptr{_GtkRecentData}, box.handle) + end + convert(::Type{GtkRecentData}, p::Ptr{_GtkRecentData}, owns = false) = begin + GtkRecentData(p, owns) + end + end end mutable struct GtkRecentInfo <: GBoxed handle::Ptr{GtkRecentInfo} @@ -212,9 +232,14 @@ $(Expr(:toplevel, quote mutable struct GtkRequestedSize handle::Ptr{_GtkRequestedSize} end - unsafe_convert(::Type{Ptr{_GtkRequestedSize}}, box::GtkRequestedSize) = begin - convert(Ptr{_GtkRequestedSize}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GtkRequestedSize}}, box::GtkRequestedSize) = begin + convert(Ptr{_GtkRequestedSize}, box.handle) + end + convert(::Type{GtkRequestedSize}, p::Ptr{_GtkRequestedSize}, owns = false) = begin + GtkRequestedSize(p, owns) + end + end end begin struct _GtkRequisition @@ -227,7 +252,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GtkRequisition) = begin ccall(("gtk_requisition_get_type", libgtk4), GType, ()) end - function GtkRequisition(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GtkRequisition(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GtkRequisition} x = new(ref) if own finalizer(x) do x @@ -239,9 +264,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GtkRequisition) end end - unsafe_convert(::Type{Ptr{_GtkRequisition}}, box::GtkRequisition) = begin - convert(Ptr{_GtkRequisition}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GtkRequisition}}, box::GtkRequisition) = begin + convert(Ptr{_GtkRequisition}, box.handle) + end + convert(::Type{GtkRequisition}, p::Ptr{_GtkRequisition}, owns = false) = begin + GtkRequisition(p, owns) + end + end end mutable struct GtkScrollInfo <: GBoxed handle::Ptr{GtkScrollInfo} @@ -284,7 +314,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GtkTextIter) = begin ccall(("gtk_text_iter_get_type", libgtk4), GType, ()) end - function GtkTextIter(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GtkTextIter(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GtkTextIter} x = new(ref) if own finalizer(x) do x @@ -296,9 +326,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GtkTextIter) end end - unsafe_convert(::Type{Ptr{_GtkTextIter}}, box::GtkTextIter) = begin - convert(Ptr{_GtkTextIter}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GtkTextIter}}, box::GtkTextIter) = begin + convert(Ptr{_GtkTextIter}, box.handle) + end + convert(::Type{GtkTextIter}, p::Ptr{_GtkTextIter}, owns = false) = begin + GtkTextIter(p, owns) + end + end end begin struct _GtkTreeIter @@ -313,7 +348,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: GtkTreeIter) = begin ccall(("gtk_tree_iter_get_type", libgtk4), GType, ()) end - function GtkTreeIter(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function GtkTreeIter(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _GtkTreeIter} x = new(ref) if own finalizer(x) do x @@ -325,9 +360,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, GtkTreeIter) end end - unsafe_convert(::Type{Ptr{_GtkTreeIter}}, box::GtkTreeIter) = begin - convert(Ptr{_GtkTreeIter}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_GtkTreeIter}}, box::GtkTreeIter) = begin + convert(Ptr{_GtkTreeIter}, box.handle) + end + convert(::Type{GtkTreeIter}, p::Ptr{_GtkTreeIter}, owns = false) = begin + GtkTreeIter(p, owns) + end + end end mutable struct GtkTreePath <: GBoxed handle::Ptr{GtkTreePath} diff --git a/src/gen/pango_structs b/src/gen/pango_structs index ebb47ee3..198fda4e 100644 --- a/src/gen/pango_structs +++ b/src/gen/pango_structs @@ -31,7 +31,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: PangoColor) = begin ccall(("pango_color_get_type", libpango), GType, ()) end - function PangoColor(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function PangoColor(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _PangoColor} x = new(ref) if own finalizer(x) do x @@ -43,9 +43,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, PangoColor) end end - unsafe_convert(::Type{Ptr{_PangoColor}}, box::PangoColor) = begin - convert(Ptr{_PangoColor}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoColor}}, box::PangoColor) = begin + convert(Ptr{_PangoColor}, box.handle) + end + convert(::Type{PangoColor}, p::Ptr{_PangoColor}, owns = false) = begin + PangoColor(p, owns) + end + end end begin struct _PangoAttrClass @@ -57,9 +62,14 @@ $(Expr(:toplevel, quote mutable struct PangoAttrClass handle::Ptr{_PangoAttrClass} end - unsafe_convert(::Type{Ptr{_PangoAttrClass}}, box::PangoAttrClass) = begin - convert(Ptr{_PangoAttrClass}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoAttrClass}}, box::PangoAttrClass) = begin + convert(Ptr{_PangoAttrClass}, box.handle) + end + convert(::Type{PangoAttrClass}, p::Ptr{_PangoAttrClass}, owns = false) = begin + PangoAttrClass(p, owns) + end + end end begin struct _PangoRectangle @@ -71,9 +81,14 @@ $(Expr(:toplevel, quote mutable struct PangoRectangle handle::Ptr{_PangoRectangle} end - unsafe_convert(::Type{Ptr{_PangoRectangle}}, box::PangoRectangle) = begin - convert(Ptr{_PangoRectangle}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoRectangle}}, box::PangoRectangle) = begin + convert(Ptr{_PangoRectangle}, box.handle) + end + convert(::Type{PangoRectangle}, p::Ptr{_PangoRectangle}, owns = false) = begin + PangoRectangle(p, owns) + end + end end mutable struct PangoFontDescription <: GBoxed handle::Ptr{PangoFontDescription} @@ -105,7 +120,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: PangoAttribute) = begin ccall(("pango_attribute_get_type", libpango), GType, ()) end - function PangoAttribute(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function PangoAttribute(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _PangoAttribute} x = new(ref) if own finalizer(x) do x @@ -117,9 +132,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, PangoAttribute) end end - unsafe_convert(::Type{Ptr{_PangoAttribute}}, box::PangoAttribute) = begin - convert(Ptr{_PangoAttribute}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoAttribute}}, box::PangoAttribute) = begin + convert(Ptr{_PangoAttribute}, box.handle) + end + convert(::Type{PangoAttribute}, p::Ptr{_PangoAttribute}, owns = false) = begin + PangoAttribute(p, owns) + end + end end begin struct _PangoAnalysis @@ -136,9 +156,14 @@ $(Expr(:toplevel, quote mutable struct PangoAnalysis handle::Ptr{_PangoAnalysis} end - unsafe_convert(::Type{Ptr{_PangoAnalysis}}, box::PangoAnalysis) = begin - convert(Ptr{_PangoAnalysis}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoAnalysis}}, box::PangoAnalysis) = begin + convert(Ptr{_PangoAnalysis}, box.handle) + end + convert(::Type{PangoAnalysis}, p::Ptr{_PangoAnalysis}, owns = false) = begin + PangoAnalysis(p, owns) + end + end end begin struct _PangoItem @@ -153,7 +178,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: PangoItem) = begin ccall(("pango_item_get_type", libpango), GType, ()) end - function PangoItem(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function PangoItem(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _PangoItem} x = new(ref) if own finalizer(x) do x @@ -165,9 +190,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, PangoItem) end end - unsafe_convert(::Type{Ptr{_PangoItem}}, box::PangoItem) = begin - convert(Ptr{_PangoItem}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoItem}}, box::PangoItem) = begin + convert(Ptr{_PangoItem}, box.handle) + end + convert(::Type{PangoItem}, p::Ptr{_PangoItem}, owns = false) = begin + PangoItem(p, owns) + end + end end begin struct _PangoGlyphVisAttr @@ -177,9 +207,14 @@ $(Expr(:toplevel, quote mutable struct PangoGlyphVisAttr handle::Ptr{_PangoGlyphVisAttr} end - unsafe_convert(::Type{Ptr{_PangoGlyphVisAttr}}, box::PangoGlyphVisAttr) = begin - convert(Ptr{_PangoGlyphVisAttr}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoGlyphVisAttr}}, box::PangoGlyphVisAttr) = begin + convert(Ptr{_PangoGlyphVisAttr}, box.handle) + end + convert(::Type{PangoGlyphVisAttr}, p::Ptr{_PangoGlyphVisAttr}, owns = false) = begin + PangoGlyphVisAttr(p, owns) + end + end end begin struct _PangoGlyphGeometry @@ -190,9 +225,14 @@ $(Expr(:toplevel, quote mutable struct PangoGlyphGeometry handle::Ptr{_PangoGlyphGeometry} end - unsafe_convert(::Type{Ptr{_PangoGlyphGeometry}}, box::PangoGlyphGeometry) = begin - convert(Ptr{_PangoGlyphGeometry}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoGlyphGeometry}}, box::PangoGlyphGeometry) = begin + convert(Ptr{_PangoGlyphGeometry}, box.handle) + end + convert(::Type{PangoGlyphGeometry}, p::Ptr{_PangoGlyphGeometry}, owns = false) = begin + PangoGlyphGeometry(p, owns) + end + end end begin struct _PangoGlyphInfo @@ -203,9 +243,14 @@ $(Expr(:toplevel, quote mutable struct PangoGlyphInfo handle::Ptr{_PangoGlyphInfo} end - unsafe_convert(::Type{Ptr{_PangoGlyphInfo}}, box::PangoGlyphInfo) = begin - convert(Ptr{_PangoGlyphInfo}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoGlyphInfo}}, box::PangoGlyphInfo) = begin + convert(Ptr{_PangoGlyphInfo}, box.handle) + end + convert(::Type{PangoGlyphInfo}, p::Ptr{_PangoGlyphInfo}, owns = false) = begin + PangoGlyphInfo(p, owns) + end + end end begin struct _PangoGlyphString @@ -220,7 +265,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: PangoGlyphString) = begin ccall(("pango_glyph_string_get_type", libpango), GType, ()) end - function PangoGlyphString(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function PangoGlyphString(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _PangoGlyphString} x = new(ref) if own finalizer(x) do x @@ -232,9 +277,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, PangoGlyphString) end end - unsafe_convert(::Type{Ptr{_PangoGlyphString}}, box::PangoGlyphString) = begin - convert(Ptr{_PangoGlyphString}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoGlyphString}}, box::PangoGlyphString) = begin + convert(Ptr{_PangoGlyphString}, box.handle) + end + convert(::Type{PangoGlyphString}, p::Ptr{_PangoGlyphString}, owns = false) = begin + PangoGlyphString(p, owns) + end + end end begin struct _PangoGlyphItem @@ -250,7 +300,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: PangoGlyphItem) = begin ccall(("pango_glyph_item_get_type", libpango), GType, ()) end - function PangoGlyphItem(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function PangoGlyphItem(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _PangoGlyphItem} x = new(ref) if own finalizer(x) do x @@ -262,9 +312,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, PangoGlyphItem) end end - unsafe_convert(::Type{Ptr{_PangoGlyphItem}}, box::PangoGlyphItem) = begin - convert(Ptr{_PangoGlyphItem}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoGlyphItem}}, box::PangoGlyphItem) = begin + convert(Ptr{_PangoGlyphItem}, box.handle) + end + convert(::Type{PangoGlyphItem}, p::Ptr{_PangoGlyphItem}, owns = false) = begin + PangoGlyphItem(p, owns) + end + end end function PangoFontDescription() G_.FontDescription_new() @@ -283,9 +338,14 @@ $(Expr(:toplevel, quote mutable struct PangoAttrColor handle::Ptr{_PangoAttrColor} end - unsafe_convert(::Type{Ptr{_PangoAttrColor}}, box::PangoAttrColor) = begin - convert(Ptr{_PangoAttrColor}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoAttrColor}}, box::PangoAttrColor) = begin + convert(Ptr{_PangoAttrColor}, box.handle) + end + convert(::Type{PangoAttrColor}, p::Ptr{_PangoAttrColor}, owns = false) = begin + PangoAttrColor(p, owns) + end + end end begin struct _PangoAttrFloat @@ -295,9 +355,14 @@ $(Expr(:toplevel, quote mutable struct PangoAttrFloat handle::Ptr{_PangoAttrFloat} end - unsafe_convert(::Type{Ptr{_PangoAttrFloat}}, box::PangoAttrFloat) = begin - convert(Ptr{_PangoAttrFloat}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoAttrFloat}}, box::PangoAttrFloat) = begin + convert(Ptr{_PangoAttrFloat}, box.handle) + end + convert(::Type{PangoAttrFloat}, p::Ptr{_PangoAttrFloat}, owns = false) = begin + PangoAttrFloat(p, owns) + end + end end begin struct _PangoAttrFontDesc @@ -307,9 +372,14 @@ $(Expr(:toplevel, quote mutable struct PangoAttrFontDesc handle::Ptr{_PangoAttrFontDesc} end - unsafe_convert(::Type{Ptr{_PangoAttrFontDesc}}, box::PangoAttrFontDesc) = begin - convert(Ptr{_PangoAttrFontDesc}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoAttrFontDesc}}, box::PangoAttrFontDesc) = begin + convert(Ptr{_PangoAttrFontDesc}, box.handle) + end + convert(::Type{PangoAttrFontDesc}, p::Ptr{_PangoAttrFontDesc}, owns = false) = begin + PangoAttrFontDesc(p, owns) + end + end end begin struct _PangoAttrFontFeatures @@ -319,9 +389,14 @@ $(Expr(:toplevel, quote mutable struct PangoAttrFontFeatures handle::Ptr{_PangoAttrFontFeatures} end - unsafe_convert(::Type{Ptr{_PangoAttrFontFeatures}}, box::PangoAttrFontFeatures) = begin - convert(Ptr{_PangoAttrFontFeatures}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoAttrFontFeatures}}, box::PangoAttrFontFeatures) = begin + convert(Ptr{_PangoAttrFontFeatures}, box.handle) + end + convert(::Type{PangoAttrFontFeatures}, p::Ptr{_PangoAttrFontFeatures}, owns = false) = begin + PangoAttrFontFeatures(p, owns) + end + end end begin struct _PangoAttrInt @@ -331,9 +406,14 @@ $(Expr(:toplevel, quote mutable struct PangoAttrInt handle::Ptr{_PangoAttrInt} end - unsafe_convert(::Type{Ptr{_PangoAttrInt}}, box::PangoAttrInt) = begin - convert(Ptr{_PangoAttrInt}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoAttrInt}}, box::PangoAttrInt) = begin + convert(Ptr{_PangoAttrInt}, box.handle) + end + convert(::Type{PangoAttrInt}, p::Ptr{_PangoAttrInt}, owns = false) = begin + PangoAttrInt(p, owns) + end + end end mutable struct PangoAttrIterator <: GBoxed handle::Ptr{PangoAttrIterator} @@ -361,9 +441,14 @@ $(Expr(:toplevel, quote mutable struct PangoAttrLanguage handle::Ptr{_PangoAttrLanguage} end - unsafe_convert(::Type{Ptr{_PangoAttrLanguage}}, box::PangoAttrLanguage) = begin - convert(Ptr{_PangoAttrLanguage}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoAttrLanguage}}, box::PangoAttrLanguage) = begin + convert(Ptr{_PangoAttrLanguage}, box.handle) + end + convert(::Type{PangoAttrLanguage}, p::Ptr{_PangoAttrLanguage}, owns = false) = begin + PangoAttrLanguage(p, owns) + end + end end mutable struct PangoAttrList <: GBoxed handle::Ptr{PangoAttrList} @@ -395,9 +480,14 @@ $(Expr(:toplevel, quote mutable struct PangoAttrShape handle::Ptr{_PangoAttrShape} end - unsafe_convert(::Type{Ptr{_PangoAttrShape}}, box::PangoAttrShape) = begin - convert(Ptr{_PangoAttrShape}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoAttrShape}}, box::PangoAttrShape) = begin + convert(Ptr{_PangoAttrShape}, box.handle) + end + convert(::Type{PangoAttrShape}, p::Ptr{_PangoAttrShape}, owns = false) = begin + PangoAttrShape(p, owns) + end + end end begin struct _PangoAttrSize @@ -408,9 +498,14 @@ $(Expr(:toplevel, quote mutable struct PangoAttrSize handle::Ptr{_PangoAttrSize} end - unsafe_convert(::Type{Ptr{_PangoAttrSize}}, box::PangoAttrSize) = begin - convert(Ptr{_PangoAttrSize}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoAttrSize}}, box::PangoAttrSize) = begin + convert(Ptr{_PangoAttrSize}, box.handle) + end + convert(::Type{PangoAttrSize}, p::Ptr{_PangoAttrSize}, owns = false) = begin + PangoAttrSize(p, owns) + end + end end begin struct _PangoAttrString @@ -420,9 +515,14 @@ $(Expr(:toplevel, quote mutable struct PangoAttrString handle::Ptr{_PangoAttrString} end - unsafe_convert(::Type{Ptr{_PangoAttrString}}, box::PangoAttrString) = begin - convert(Ptr{_PangoAttrString}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoAttrString}}, box::PangoAttrString) = begin + convert(Ptr{_PangoAttrString}, box.handle) + end + convert(::Type{PangoAttrString}, p::Ptr{_PangoAttrString}, owns = false) = begin + PangoAttrString(p, owns) + end + end end begin struct _PangoFontMetrics @@ -443,7 +543,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: PangoFontMetrics) = begin ccall(("pango_font_metrics_get_type", libpango), GType, ()) end - function PangoFontMetrics(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function PangoFontMetrics(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _PangoFontMetrics} x = new(ref) if own finalizer(x) do x @@ -455,9 +555,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, PangoFontMetrics) end end - unsafe_convert(::Type{Ptr{_PangoFontMetrics}}, box::PangoFontMetrics) = begin - convert(Ptr{_PangoFontMetrics}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoFontMetrics}}, box::PangoFontMetrics) = begin + convert(Ptr{_PangoFontMetrics}, box.handle) + end + convert(::Type{PangoFontMetrics}, p::Ptr{_PangoFontMetrics}, owns = false) = begin + PangoFontMetrics(p, owns) + end + end end begin struct _PangoGlyphItemIter @@ -476,7 +581,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: PangoGlyphItemIter) = begin ccall(("pango_glyph_item_iter_get_type", libpango), GType, ()) end - function PangoGlyphItemIter(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function PangoGlyphItemIter(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _PangoGlyphItemIter} x = new(ref) if own finalizer(x) do x @@ -488,9 +593,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, PangoGlyphItemIter) end end - unsafe_convert(::Type{Ptr{_PangoGlyphItemIter}}, box::PangoGlyphItemIter) = begin - convert(Ptr{_PangoGlyphItemIter}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoGlyphItemIter}}, box::PangoGlyphItemIter) = begin + convert(Ptr{_PangoGlyphItemIter}, box.handle) + end + convert(::Type{PangoGlyphItemIter}, p::Ptr{_PangoGlyphItemIter}, owns = false) = begin + PangoGlyphItemIter(p, owns) + end + end end mutable struct PangoLayoutIter <: GBoxed handle::Ptr{PangoLayoutIter} @@ -525,7 +635,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: PangoLayoutLine) = begin ccall(("pango_layout_line_get_type", libpango), GType, ()) end - function PangoLayoutLine(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function PangoLayoutLine(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _PangoLayoutLine} x = new(ref) if own finalizer(x) do x @@ -537,9 +647,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, PangoLayoutLine) end end - unsafe_convert(::Type{Ptr{_PangoLayoutLine}}, box::PangoLayoutLine) = begin - convert(Ptr{_PangoLayoutLine}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoLayoutLine}}, box::PangoLayoutLine) = begin + convert(Ptr{_PangoLayoutLine}, box.handle) + end + convert(::Type{PangoLayoutLine}, p::Ptr{_PangoLayoutLine}, owns = false) = begin + PangoLayoutLine(p, owns) + end + end end begin struct _PangoLogAttr @@ -563,9 +678,14 @@ $(Expr(:toplevel, quote mutable struct PangoLogAttr handle::Ptr{_PangoLogAttr} end - unsafe_convert(::Type{Ptr{_PangoLogAttr}}, box::PangoLogAttr) = begin - convert(Ptr{_PangoLogAttr}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoLogAttr}}, box::PangoLogAttr) = begin + convert(Ptr{_PangoLogAttr}, box.handle) + end + convert(::Type{PangoLogAttr}, p::Ptr{_PangoLogAttr}, owns = false) = begin + PangoLogAttr(p, owns) + end + end end begin struct _PangoMatrix @@ -582,7 +702,7 @@ $(Expr(:toplevel, quote (GLib.g_type(::Type{T}) where T <: PangoMatrix) = begin ccall(("pango_matrix_get_type", libpango), GType, ()) end - function PangoMatrix(ref::Ptr{T}, own::Bool = false) where T <: GBoxed + function PangoMatrix(ref::Ptr{T}, own::Bool = false) where T <: Union{GBoxed, _PangoMatrix} x = new(ref) if own finalizer(x) do x @@ -594,9 +714,14 @@ $(Expr(:toplevel, quote push!(gboxed_types, PangoMatrix) end end - unsafe_convert(::Type{Ptr{_PangoMatrix}}, box::PangoMatrix) = begin - convert(Ptr{_PangoMatrix}, box.handle) - end + begin + unsafe_convert(::Type{Ptr{_PangoMatrix}}, box::PangoMatrix) = begin + convert(Ptr{_PangoMatrix}, box.handle) + end + convert(::Type{PangoMatrix}, p::Ptr{_PangoMatrix}, owns = false) = begin + PangoMatrix(p, owns) + end + end end mutable struct PangoScriptIter <: GBoxed handle::Ptr{PangoScriptIter} diff --git a/src/windows.jl b/src/windows.jl index c7a35588..03405035 100644 --- a/src/windows.jl +++ b/src/windows.jl @@ -536,28 +536,25 @@ function color_dialog(title::AbstractString, parent = nothing; timeout=-1) return color[] end -function color_dialog(callback::Function, title::AbstractString, parent = nothing; timeout=-1) - dlg = GtkColorChooserDialog(title, parent) +function color_dialog(callback::Function, title::AbstractString, parent = nothing; timeout=-1, initial_color = nothing) + dlg = GtkColorDialog() + G_.set_title(dlg, title) - function on_response(dlg, response_id) - dlgp = GtkColorChooser(dlg) - if unsafe_trunc(UInt16, response_id) == ResponseType_OK - res = G_.get_rgba(dlgp) - else - res = nothing + function cb(dlg, resobj) + rgba = try + Gtk4.G_.choose_rgba_finish(dlg, GAsyncResult(resobj)) + catch e + if !isa(e, Gtk4.GLib.GErrorException) + rethrow(e) + end + nothing end - callback(res) - G_.set_transient_for(dlg, nothing) - destroy(dlg) + callback(rgba) end - signal_connect(on_response, dlg, "response") - show(dlg) + cancellable = GLib.cancel_after_delay(timeout) + G_.choose_rgba(dlg, parent, initial_color, cancellable, cb) - if timeout > 0 - emit(timer) = response(dlg, Gtk4.ResponseType_CANCEL) - Timer(emit, timeout) - end return dlg end diff --git a/test/gui/input.jl b/test/gui/input.jl index 1530c307..f503df0a 100644 --- a/test/gui/input.jl +++ b/test/gui/input.jl @@ -7,7 +7,7 @@ Gtk4.value(sl, 3) push!(sl,π,:right,"pi") push!(sl,-3,:left) @test Gtk4.value(sl) == 3 -adj = GtkAdjustment(sl) +adj = adjustment(sl) @test get_gtk_property(adj,:value,Float64) == 3 set_gtk_property!(adj,:upper,11) empty!(sl) @@ -28,7 +28,7 @@ destroy(w) adj = GtkAdjustment(5.0,0.0,10.0,1.0,5.0,5.0) sp2 = GtkSpinButton(adj, 1.0, 2) -adj2 = GtkAdjustment(sp2) +adj2 = adjustment(sp2) @test adj == adj2 configure!(adj2; value = 2.0, lower = 1.0, upper = 20.0, step_increment = 2.0, page_increment = 10.0, page_size = 10.0) @@ -107,7 +107,7 @@ end @testset "ScaleButton" begin sb = GtkScaleButton(0.0:1.0:10.0) -adj = GtkAdjustment(sb) +adj = adjustment(sb) end From 77975fa46b5c1ba9e79aebd308fce111a8fba062 Mon Sep 17 00:00:00 2001 From: Jared Wahlstrand Date: Sun, 21 Apr 2024 14:56:25 -0400 Subject: [PATCH 5/8] docs fixes, remove button argument in input_dialog --- docs/src/manual/dialogs.md | 39 ++++++++++++++++++-------------------- src/windows.jl | 15 +++++++-------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/docs/src/manual/dialogs.md b/docs/src/manual/dialogs.md index 0e1fcb66..225710d5 100644 --- a/docs/src/manual/dialogs.md +++ b/docs/src/manual/dialogs.md @@ -1,16 +1,17 @@ # Dialogs -Dialogs are transient windows that show information or ask the user for information. +Dialogs are transient windows that show messages or ask the user for information. !!! note "Example" Some of the code on this page can be found in "dialogs.jl" in the "example" subdirectory. !!! tip "Creating dialogs in callbacks" - When creating dialogs in signal or action callbacks, you have to use the methods that take a function as the first argument (equivalently the `do` syntax). + When creating dialogs in signal or action callbacks, you must use the methods that take a function as the first argument (equivalently the `do` syntax). ## Message dialogs -Gtk4.jl supports `GtkMessageDialog` and provides several convenience functions: `info_dialog`, `ask_dialog`, and `input_dialog`. Each takes a string for a message to show and an optional parent container, and returns nothing, except for `ask_dialog` which returns `true` if the user clicks the button corresponding to yes. +Gtk4.jl supports `GtkAlertDialog` and wraps it in convenience functions `info_dialog` and `ask_dialog`. +Each takes a string for a message to show and an optional parent container. For all dialog convenience functions, there are two ways of using them. For use in the REPL or an interactive script, the following forms can be used: @@ -18,7 +19,7 @@ For all dialog convenience functions, there are two ways of using them. For use info_dialog("Julia rocks!") ask_dialog("Do you like chocolate ice cream?", "Not at all", "I like it") && println("That's my favorite too.") ``` -These take an optional argument `timeout` (in seconds) that can be used to make the dialog disappear after a certain time. +Note that `ask_dialog` returns `true` if the user clicks the button corresponding to yes. These functions take an optional argument `timeout` (in seconds) that can be used to make the dialog disappear after a certain time. In callbacks (for example when a user clicks a button in a GUI), you _must_ use a different form, which takes a callback as the first argument that will be called when the user closes the dialog. A full example: ```julia @@ -30,9 +31,9 @@ function on_click(b) end signal_connect(on_click, b, "clicked") ``` -If you are using these functions in the context of a GUI, you should set the third argument of `info_dialog`, `parent`, to be the top-level window. Otherwise, for standalone usage in scripts, do not set it. +If you are using these functions in the context of a GUI, you should set the third argument of `info_dialog`, `parent`, to be the top-level window. -The callback can alternatively be constructed using Julia's `do` syntax: +The callback function can alternatively be constructed using Julia's `do` syntax: ```julia info_dialog("Julia rocks!", win) do println("message received") @@ -75,18 +76,7 @@ open_dialog(f, "Pick a file to open", parent; start_folder = "/data") ``` The same syntax works for `save_dialog`. -### Filters -Filters can be used to limit the type of files that the user can pick. Filters can be specified as a Tuple or Vector. -A filter can be specified as a string, in which case it specifies a globbing pattern, for example `"*.png"`. -You can specify multiple match types for a single filter by separating the patterns with a comma, for example `"*.png,*.jpg"`. -You can alternatively specify MIME types, or if no specification is provided it defaults to types supported by `GdkPixbuf`. -The generic specification of a filter is -```julia -GtkFileFilter(pattern = "", mimetype = "") -``` -A human-readable name can optionally be provided using a keyword argument. - -If on the other hand you want to choose a folder instead of a file, use `select_folder = true` in `open_dialog`: +If you want to choose a folder instead of a file, use `select_folder = true` in `open_dialog`: ```julia dir=Ref{String}() open_dialog("Select Dataset Folder"; select_folder = true) do name @@ -98,6 +88,13 @@ if isdir(dir[]) end ``` -## Custom dialogs - -TODO +### Filters +Filters can be used to limit the type of files that the user can pick. Filters can be specified as a Tuple or Vector. +A filter can be specified as a string, in which case it specifies a globbing pattern, for example `"*.png"`. +You can specify multiple match types for a single filter by separating the patterns with a comma, for example `"*.png,*.jpg"`. +You can alternatively specify MIME types, or if no specification is provided it defaults to types supported by `GdkPixbuf`. +The generic specification of a filter is +```julia +GtkFileFilter(pattern = "", mimetype = "") +``` +A human-readable name can optionally be provided using a keyword argument. diff --git a/src/windows.jl b/src/windows.jl index 03405035..a0308fc5 100644 --- a/src/windows.jl +++ b/src/windows.jl @@ -278,7 +278,7 @@ function info_dialog(callback::Function, message::AbstractString, parent = nothi end """ - input_dialog(message::AbstractString, entry_default::AbstractString, buttons = (("Cancel", 0), ("Accept", 1)), parent = nothing; timeout = -1) + input_dialog(message::AbstractString, entry_default::AbstractString, parent = nothing; timeout = -1) Create a dialog with a message `message` and a text entry. Returns the string in the entry when the "Accept" button is pressed, or `entry_default` if "Cancel" is pressed or the dialog @@ -286,12 +286,11 @@ or its parent window `parent` is closed. The optional input `timeout` (disabled can be used to set a time in seconds after which the dialog will close and `entry_default` will be returned. """ -## TODO: remove buttons argument -function input_dialog(message::AbstractString, entry_default::AbstractString, buttons = (("Cancel", 0), ("Accept", 1)), parent = nothing; timeout = -1) +function input_dialog(message::AbstractString, entry_default::AbstractString, parent = nothing; timeout = -1) res = Ref{String}("") c = Condition() - input_dialog(message, entry_default, buttons, parent; timeout) do res_ + input_dialog(message, entry_default, parent; timeout) do res_ res[] = res_ notify(c) end @@ -306,7 +305,7 @@ function _callback_and_destroy(dlg, callback, txt) end function input_dialog(callback::Function, message::AbstractString, entry_default::AbstractString, - buttons = (("Cancel", 0), ("Accept", 1)), parent = nothing; timeout = -1) + parent = nothing; timeout = -1) dlg = GtkWindow() box = GtkBox(:v) push!(box, GtkLabel(message)) @@ -315,9 +314,9 @@ function input_dialog(callback::Function, message::AbstractString, entry_default push!(box, entry) boxb = GtkBox(:h) push!(box, boxb) - accept = GtkButton(buttons[2][1]; hexpand = true) + accept = GtkButton("Accept"; hexpand = true) default_widget(dlg, accept) - cancel = GtkButton(buttons[1][1]; hexpand = true) + cancel = GtkButton("Cancel"; hexpand = true) push!(boxb, cancel) push!(boxb, accept) isnothing(parent) && (G_.set_transient_for(dlg, parent); G_.set_modal(dlg, true)) @@ -525,7 +524,7 @@ end ## Other chooser dialogs function color_dialog(title::AbstractString, parent = nothing; timeout=-1) - color = Ref{Union{Nothing,_GdkRGBA}}() + color = Ref{Union{Nothing,GdkRGBA}}() c = Condition() color_dialog(title, parent; timeout) do col From 4e3be34198c5b76fc7aa9f0dd1bbea61161fe40b Mon Sep 17 00:00:00 2001 From: Jared Wahlstrand Date: Sun, 23 Jun 2024 14:05:25 -0400 Subject: [PATCH 6/8] work on dialog docstrings --- docs/src/doc/reference.md | 2 +- src/windows.jl | 67 +++++++++++++++++++++------------------ 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/docs/src/doc/reference.md b/docs/src/doc/reference.md index b9d7f2e8..9f040bfb 100644 --- a/docs/src/doc/reference.md +++ b/docs/src/doc/reference.md @@ -52,8 +52,8 @@ Gtk4.selected_string ## Dialogs ```@docs -Gtk4.ask_dialog Gtk4.info_dialog +Gtk4.ask_dialog Gtk4.input_dialog Gtk4.open_dialog Gtk4.save_dialog diff --git a/src/windows.jl b/src/windows.jl index a0308fc5..a754923d 100644 --- a/src/windows.jl +++ b/src/windows.jl @@ -198,21 +198,21 @@ pushfirst!(hb::GtkHeaderBar, w::GtkWidget) = (G_.pack_start(hb, w); hb) delete!(hb::GtkHeaderBar, w::GtkWidget) = (G_.remove(hb, w); hb) """ - ask_dialog(question::AbstractString, parent = nothing; timeout = -1) + ask_dialog(callback::Function, question::AbstractString, parent = nothing) + ask_dialog(question::AbstractString, parent = nothing) -Create a dialog with a message `question` and two buttons "No" and "Yes". Returns `true` if -"Yes" is selected and `false` if "No" is selected or the dialog (or its parent window -`parent`) is closed. The optional input `timeout` (disabled by default) can be used to set -a time in seconds after which the dialog will close and `false` will be returned. -""" -ask_dialog(question::AbstractString, parent = nothing; timeout = -1) = - ask_dialog(question, "No", "Yes", parent; timeout = timeout) +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. -function ask_dialog(message::AbstractString, no_text, yes_text, parent = nothing; timeout = -1) +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`. +""" +function ask_dialog(question::AbstractString, parent = nothing; timeout = -1, no_text = "No", yes_text = "Yes") res = Ref{Bool}(false) c = Condition() - ask_dialog(message, no_text, yes_text, parent; timeout) do res_ + ask_dialog(question, parent; timeout, no_text, yes_text) do res_ res[] = res_ notify(c) end @@ -220,8 +220,8 @@ function ask_dialog(message::AbstractString, no_text, yes_text, parent = nothing return res[] end -function ask_dialog(callback::Function, message::AbstractString, no_text, yes_text, parent = nothing; timeout = -1) - dlg = GtkAlertDialog(message) +function ask_dialog(callback::Function, question::AbstractString, parent = nothing; timeout = -1, no_text = "No", yes_text = "Yes") + dlg = GtkAlertDialog(question) G_.set_buttons(dlg, [no_text, yes_text]) cancellable = GLib.cancel_after_delay(timeout) @@ -240,11 +240,13 @@ function ask_dialog(callback::Function, message::AbstractString, no_text, yes_te end """ - info_dialog(message::AbstractString, parent = nothing; timeout = -1) + info_dialog(callback::Function, message::AbstractString, parent = nothing) + info_dialog(message::AbstractString, parent = nothing) -Create a dialog with an informational message `message`. Returns when the dialog (or its -parent window `parent`) is closed. The optional input `timeout` (disabled by default) can be -used to set a time in seconds after which the dialog will close. +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. + +Keyword arguments: +- `timeout = -1` to set a time in seconds after which the dialog will close and `false` will be returned. Disabled if negative. """ info_dialog function info_dialog(message::AbstractString, parent = nothing; timeout = -1) @@ -278,13 +280,13 @@ function info_dialog(callback::Function, message::AbstractString, parent = nothi end """ - input_dialog(message::AbstractString, entry_default::AbstractString, parent = nothing; timeout = -1) + 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 `message` and a text entry. Returns the string in the entry -when the "Accept" button is pressed, or `entry_default` if "Cancel" is pressed or the dialog -or its parent window `parent` is closed. The optional input `timeout` (disabled by default) -can be used to set a time in seconds after which the dialog will close and `entry_default` -will be returned. +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. + +Keyword arguments: +- `timeout = -1` to set a time in seconds after which the dialog will close and `false` will be returned. Disabled if negative. """ function input_dialog(message::AbstractString, entry_default::AbstractString, parent = nothing; timeout = -1) res = Ref{String}("") @@ -415,14 +417,16 @@ hide(d::GtkNativeDialog) = G_.hide(d) destroy(d::GtkNativeDialog) = G_.destroy(d) """ - open_dialog(title::AbstractString, parent = nothing, filters::Union{AbstractVector, Tuple} = String[]; timeout = -1, multiple = false, start_folder = "") + 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. Returns the path chosen by the user, or "" if "Cancel" is pressed or the dialog or its parent window `parent` is closed. The dialog title is set using `title`. The argument `filters` can be used to show only directory contents that match certain file extensions. +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`. The argument `filters` can be used to show only directory contents that match certain file extensions. Keyword arguments: -`timeout`: The optional input `timeout` (disabled by default) can be used to set a time in seconds after which the dialog will close and "" will be returned. -`multiple`: if `true`, multiple files can be selected, and a list of file paths is returned rather than a single path. -`start_folder`: if set, the dialog will start out browsing a particular folder. Otherwise GTK will decide. +- `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. """ function open_dialog(title::AbstractString, parent = nothing, filters::Union{AbstractVector, Tuple} = String[]; timeout = -1, multiple = false, select_folder = false, start_folder = "") res = Ref{String}("") @@ -468,13 +472,14 @@ function open_dialog(callback::Function, title::AbstractString, parent = nothing end """ - save_dialog(title::AbstractString, parent = nothing, filters::Union{AbstractVector, Tuple} = String[]; timeout = -1, start_folder = "") + 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. Returns the path chosen by the user, or "" if "Cancel" is pressed or the dialog or its parent window `parent` is closed. The window title is set using `title`. The argument `filters` can be used to show only directory contents that match certain file extensions. +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`. The argument `filters` can be used to show only directory contents that match certain file extensions. Keyword arguments: -`timeout`: The optional input `timeout` (disabled by default) can be used to set a time in seconds after which the dialog will close and "" will be returned. -`start_folder`: if set, the dialog will start out browsing a particular folder. Otherwise GTK will decide. +- `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. """ function save_dialog(title::AbstractString, parent = nothing, filters::Union{AbstractVector, Tuple} = String[]; timeout = -1, start_folder = "") res = Ref{String}("") From d44655cf229051edc945879d24258af63a1334ce Mon Sep 17 00:00:00 2001 From: Jared Wahlstrand Date: Sun, 23 Jun 2024 18:09:04 -0400 Subject: [PATCH 7/8] more work on docstrings and fix tests --- src/windows.jl | 105 ++++++++++++++++++++++++++++---------------- test/gui/dialogs.jl | 2 +- 2 files changed, 68 insertions(+), 39 deletions(-) diff --git a/src/windows.jl b/src/windows.jl index a754923d..84382b6f 100644 --- a/src/windows.jl +++ b/src/windows.jl @@ -1,10 +1,11 @@ @doc """ GtkWindow(title::Union{Nothing, AbstractString}, w::Real = -1, h::Real = -1, resizable::Bool = true, show_window::Bool = true) -Create an empty `GtkWindow` with a title. A default width and height can be -provided with `w` and `h`. If `resizable` is false, the window will have a -fixed size `w` and `h`. If `show_window` is false, the window will be initially -invisible. +Create an empty `GtkWindow` with a title. A default width and height can be provided with +`w` and `h`. If `resizable` is false, the window will have a fixed size `w` and `h`. If +`show_window` is false, the window will be initially invisible. + +GTK docs: [`GtkWindow`]($(gtkdoc_struc_url("gtk4","Window"))) """ function GtkWindow(title::Union{Nothing, AbstractString}, w::Real = -1, h::Real = -1, resizable::Bool = true, show_window::Bool = true) win = G_.Window_new() @@ -42,8 +43,10 @@ default_size(win::GtkWindow, w, h) = G_.set_default_size(win, w, h) """ isactive(win::GtkWindow) -Returns whether `win` is the currently active toplevel. This is the window that -receives keystrokes. +Returns whether `win` is the currently active toplevel. This is the window that receives +keystrokes. + +Related GTK function: [`gtk_window_is_active`()]($(gtkdoc_method_url("gtk4","Window","is_active"))) """ isactive(win::GtkWindow) = G_.is_active(win) @@ -61,34 +64,23 @@ end """ close(win::GtkWindow) -Request that `win` is closed. +Request that `win` be closed. Related GTK function: [`gtk_window_close`()]($(gtkdoc_method_url("gtk4","Window","close"))) """ close(w::GtkWindow) = G_.close(w) """ - fullscreen(win::GtkWindow) + fullscreen(win::GtkWindow [, mon::GdkMonitor]) -Set `win` to fullscreen mode. +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`](@ref). -Related GTK function: [`gtk_window_fullscreen`()]($(gtkdoc_method_url("gtk4","Window","fullscreen"))) +Related GTK functions: [`gtk_window_fullscreen`()]($(gtkdoc_method_url("gtk4","Window","fullscreen"))), [`gtk_window_fullscreen_on_monitor`()]($(gtkdoc_method_url("gtk4","Window","fullscreen_on_monitor"))) """ fullscreen(win::GtkWindow) = G_.fullscreen(win) - -""" - fullscreen(win::GtkWindow, mon::GdkMonitor) - -Set `win` to fullscreen mode 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`](@ref). - -Related GTK function: [`gtk_window_fullscreen_on_monitor`()]($(gtkdoc_method_url("gtk4","Window","fullscreen_on_monitor"))) -""" fullscreen(win::GtkWindow, mon::GdkMonitor) = G_.fullscreen_on_monitor(win, mon) """ @@ -136,12 +128,11 @@ Related GTK function: [`gtk_window_unmaximize`()]($(gtkdoc_method_url("gtk4","Wi unmaximize(win::GtkWindow) = G_.unmaximize(win) """ - present(win::GtkWindow) - present(win::GtkWindow, timestamp) + present(win::GtkWindow [, timestamp]) -Presents a window to the user. Usually means move it to the front. According to -the GTK docs, this function "should not be used" without including a timestamp -for the user's request. +Presents a window to the user. Usually means move it to the front. According to the GTK +docs, this function "should not be used" without including a timestamp for the user's +request. However, it's not clear from the GTK docs what the timestamp is exactly. Related GTK function: [`gtk_window_present`()]($(gtkdoc_method_url("gtk4","Window","present"))) Related GTK function: [`gtk_window_present_with_time`()]($(gtkdoc_method_url("gtk4","Window","present_with_time"))) @@ -181,6 +172,8 @@ end Create an empty `GtkApplicationWindow` for a `GtkApplication` app and a title. Keyword arguments can be used to set GObject properties. + +GTK docs: [`GtkApplicationWindow`]($(gtkdoc_struc_url("gtk4","ApplicationWindow"))) """ function GtkApplicationWindow(app::GtkApplication, title::AbstractString; kwargs...) win = GtkApplicationWindow(app; kwargs...) @@ -201,12 +194,18 @@ delete!(hb::GtkHeaderBar, w::GtkWidget) = (G_.remove(hb, w); hb) 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. +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) """ function ask_dialog(question::AbstractString, parent = nothing; timeout = -1, no_text = "No", yes_text = "Yes") res = Ref{Bool}(false) @@ -220,8 +219,8 @@ function ask_dialog(question::AbstractString, parent = nothing; timeout = -1, no return res[] end -function ask_dialog(callback::Function, question::AbstractString, parent = nothing; timeout = -1, no_text = "No", yes_text = "Yes") - dlg = GtkAlertDialog(question) +function ask_dialog(callback::Function, question::AbstractString, parent = nothing; timeout = -1, no_text = "No", yes_text = "Yes", modal = true) + dlg = GtkAlertDialog(question; modal = modal) G_.set_buttons(dlg, [no_text, yes_text]) cancellable = GLib.cancel_after_delay(timeout) @@ -243,10 +242,16 @@ end 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. +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) """ info_dialog function info_dialog(message::AbstractString, parent = nothing; timeout = -1) @@ -259,8 +264,8 @@ function info_dialog(message::AbstractString, parent = nothing; timeout = -1) return end -function info_dialog(callback::Function, message::AbstractString, parent = nothing; timeout = -1) - dlg = GtkAlertDialog(message) +function info_dialog(callback::Function, message::AbstractString, parent = nothing; timeout = -1, modal = true) + dlg = GtkAlertDialog(message; modal = modal) function cb(dlg, resobj) try @@ -283,7 +288,15 @@ end 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. +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. @@ -420,7 +433,14 @@ destroy(d::GtkNativeDialog) = G_.destroy(d) 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`. The argument `filters` can be used to show only directory contents that match certain file extensions. +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. @@ -475,7 +495,14 @@ end 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`. The argument `filters` can be used to show only directory contents that match certain file extensions. +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. @@ -564,9 +591,11 @@ end ## New dialogs (new in GTK 4.10) -function GtkAlertDialog(message::AbstractString) +function GtkAlertDialog(message::AbstractString; kwargs...) ptr = ccall((:gtk_alert_dialog_new, libgtk4), Ptr{GObject}, (Ptr{UInt8},), message) - GtkAlertDialogLeaf(ptr, true) + d = GtkAlertDialogLeaf(ptr, true) + GLib.setproperties!(d; kwargs...) + d end show(dlg::GtkAlertDialog, parent=nothing) = G_.show(dlg, parent) diff --git a/test/gui/dialogs.jl b/test/gui/dialogs.jl index 9e2466ba..df57abb6 100644 --- a/test/gui/dialogs.jl +++ b/test/gui/dialogs.jl @@ -42,7 +42,7 @@ color_dialog("What is your favorite color?", main_window; timeout = 0.25) sleep(1.0) -input_dialog("What is the meaning of life, the universe, and everything?", "42", (("Cancel", 0), ("Accept", 1)), main_window; timeout = 0.25) +input_dialog("Whadya know?", "Not much, you?", main_window; timeout = 0.25) sleep(1.0) From 4a4fd7ebffa8f6ff315becb643a91702e778e7e1 Mon Sep 17 00:00:00 2001 From: Jared Wahlstrand Date: Sun, 23 Jun 2024 19:13:26 -0400 Subject: [PATCH 8/8] don't test 1.6 --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2b769ff8..42483681 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,6 @@ jobs: fail-fast: false matrix: julia-version: - - "1.6" - "1" #- "nightly" os: