Skip to content

Commit 56117e7

Browse files
committed
small improvements in GI mostly
1 parent 8babe53 commit 56117e7

11 files changed

+124
-27
lines changed

GI/Project.toml

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ EzXML = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615"
99
Glib_jll = "7746bdde-850d-59dc-9ae8-88ece973131d"
1010
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
1111
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
12-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1312
gobject_introspection_jll = "6306888c-5478-5f78-9aeb-34cb5688c579"
1413

1514
[compat]
1615
julia = "1.6"
16+
BitFlags = "0.1.5"
17+
CEnum = "0.4, 0.5"
18+
EzXML = "1"
19+
Glib_jll = "2.74.0"
20+
Libdl = "1.6"
21+
MacroTools = "0.5"
22+
gobject_introspection_jll = "1.74"

GI/src/GI.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ module GI
1616
import Base: convert, cconvert, show, length, getindex, setindex!, uppercase, unsafe_convert
1717
using Libdl
1818

19-
uppercase(s::Symbol) = Symbol(uppercase(string(s)))
19+
symuppercase(s::Symbol) = Symbol(uppercase(string(s)))
20+
symuppercase(s::AbstractString) = Symbol(uppercase(s))
2021

2122
export GINamespace
2223
export const_expr

GI/src/GLibBase/GLibBase.jl

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ import Base: convert, size, length, getindex, setindex!, get,
1212
getindex, setindex!
1313

1414
export GInterface, GType, GObject, GBoxed, GTypeInstance
15-
export GEnum, GError, GValue, gvalue, g_type
15+
export GEnum, GError, GValue, g_type
1616
export GHashTable, GByteArray, GArray, GPtrArray
17-
export GList, glist_iter, _GSList, _GList
18-
export GConnectFlags
17+
export GList, _GSList, _GList
1918
export cfunction_
2019

2120

GI/src/giimport.jl

+18-5
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ function enum_decl(enum)
1111
if match(r"^[a-zA-Z_]",string(name)) === nothing
1212
name = Symbol("_$name")
1313
end
14-
push!(body.args, :(const $(uppercase(name)) = $val) )
14+
push!(body.args, :(const $(symuppercase(name)) = $val) )
1515
end
1616
Expr(:toplevel, Expr(:module, false, Symbol(enumname), body))
1717
end
1818

19-
enum_fullname(enumname,name) = Symbol(enumname,"_",uppercase(name))
19+
enum_fullname(enumname,name) = Symbol(enumname,"_",symuppercase(name))
2020
enum_name(enum) = Symbol(string(get_namespace(enum),get_name(enum)))
2121

2222
function find_symbol(l,id)
@@ -710,7 +710,6 @@ function convert_from_c(name::Symbol, arginfo::ArgInfo, typeinfo::TypeDesc{T}) w
710710
return nothing
711711
end
712712
end
713-
println("$owns")
714713
throw(NotImplementedError("Unknown array type"))
715714
end
716715

@@ -948,7 +947,21 @@ function convert_from_c(name::Symbol, arginfo::ArgInfo, typeinfo::TypeDesc{T}) w
948947
end
949948
end
950949

951-
function extract_type(typeinfo::TypeInfo, info::ObjectLike)
950+
# avoid method ambiguity
951+
function extract_type(typeinfo::GITypeInfo, info::ObjectLike)
952+
if is_pointer(typeinfo)
953+
if typename(info)===:GParam # GParamSpec is a GTypeInstance but we handle it differently
954+
throw(NotImplementedError("ObjectLike but not a GObject"))
955+
#return TypeDesc(info,:GParamSpec,:(Ptr{GParamSpec}))
956+
end
957+
t = get_toplevel(info)
958+
TypeDesc(info,typename(info),typename(info),:(Ptr{$t}))
959+
else
960+
# a GList has implicitly pointers to all elements
961+
TypeDesc(info,:INVALID,:INVALID,:GObject)
962+
end
963+
end
964+
function extract_type(typeinfo::Type{InstanceType}, info::ObjectLike)
952965
if is_pointer(typeinfo)
953966
if typename(info)===:GParam # GParamSpec is a GTypeInstance but we handle it differently
954967
throw(NotImplementedError("ObjectLike but not a GObject"))
@@ -1010,7 +1023,7 @@ function jparams(args::Array{Arg})
10101023
end
10111024

10121025
# Map library names onto exports of *_jll
1013-
libnames = Dict("libglib"=>:libglib, "libgobject"=>:libgobject,
1026+
const libnames = Dict("libglib"=>:libglib, "libgobject"=>:libgobject,
10141027
"libgio"=>:libgio, "libcairo-gobject"=>:libcairo_gobject,
10151028
"libpangocairo"=>:libpangocairo, "libpangoft"=>:libpangoft,
10161029
"libpango"=>:libpango, "libatk"=>:libatk,

GI/src/girepo.jl

+28-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Julia wrapper for libgirepository
22

3-
abstract type GIRepository end
3+
# https://gi.readthedocs.io/en/latest/
4+
# https://gnome.pages.gitlab.gnome.org/gobject-introspection/girepository/
45

6+
abstract type GIRepository end
57
abstract type GITypelib end
6-
78
abstract type GIBaseInfo end
9+
810
# a GIBaseInfo we own a reference to
911
mutable struct GIInfo{Typeid}
1012
handle::Ptr{GIBaseInfo}
@@ -104,7 +106,7 @@ function show(io::IO, info::GICallbackInfo)
104106
show(io, get_return_type(info))
105107
end
106108

107-
109+
"""Represents a C library namespace, like "gtk" or "pango"."""
108110
struct GINamespace
109111
name::Symbol
110112
function GINamespace(namespace::Symbol, version = nothing)
@@ -149,10 +151,22 @@ Base.eltype(::Type{GINamespace}) = GIInfo
149151

150152
getindex(ns::GINamespace, name::Symbol) = gi_find_by_name(ns, name)
151153

154+
"""
155+
prepend_search_path(s::AbstractString)
156+
157+
Add a directory that contains *.typelib files to libgirepository's search
158+
path.
159+
"""
152160
function prepend_search_path(s::AbstractString)
153161
ccall((:g_irepository_prepend_search_path, libgi), Cvoid, (Cstring,), s)
154162
end
155163

164+
"""
165+
prepend_search_path(s::Module)
166+
167+
For a JLL module that includes GObject introspection data, add the directory
168+
that contains *.typelib files to libgirepository's search path.
169+
"""
156170
function prepend_search_path(mod::Module)
157171
d = mod.find_artifact_dir()*"/lib/girepository-1.0"
158172
d === Missing && error("Artifact directory not found")
@@ -163,6 +177,12 @@ function get_all(ns::GINamespace, t::Type{T},exclude_deprecated=true) where {T<:
163177
[info for info=ns if isa(info,t) && (exclude_deprecated ? !is_deprecated(info) : true)]
164178
end
165179

180+
"""
181+
get_c_prefix(ns)
182+
183+
Get the C prefix for a namespace, which, for example, is "G" for GLib and "Gtk"
184+
for GTK.
185+
"""
166186
function get_c_prefix(ns)
167187
ret = ccall((:g_irepository_get_c_prefix, libgi), Ptr{UInt8}, (Ptr{GIRepository}, Cstring), C_NULL, ns)
168188
if ret != C_NULL
@@ -498,12 +518,10 @@ function show(io::IO,info::GITypeInfo)
498518
end
499519
end
500520

501-
function get_constant_value(typ,info)
502-
eval(quote
503-
x = Ref{$typ}(0)
504-
siz = ccall((:g_constant_info_get_value,libgi),Cint,(Ptr{GIBaseInfo}, Ref{$typ}), $info, x)
505-
x[]
506-
end)
521+
function get_constant_value(::Type{T}, info) where T
522+
x=Ref{T}(0)
523+
siz = ccall((:g_constant_info_get_value,libgi),Cint,(Ptr{GIBaseInfo}, Ref{T}), info, x)
524+
x[]
507525
end
508526

509527
function get_value(info::GIConstantInfo)
@@ -522,7 +540,7 @@ function get_value(info::GIConstantInfo)
522540
ccall((:g_constant_info_free_value,libgi), Nothing, (Ptr{GIBaseInfo}, Ptr{Nothing}), info, x)
523541
val
524542
else
525-
nothing#unimplemented
543+
throw(NotImplementedError("Constant with type $typ not supported"))
526544
end
527545
end
528546

gen/gen_gobject.jl

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ disguised = GI.read_disguised(d)
1616
special = [:Value]
1717
import_as_opaque = [:ObjectClass]
1818
struct_skiplist=vcat(disguised, special, [:CClosure,:Closure,:ClosureNotifyData,
19-
:InterfaceInfo,:ObjectConstructParam,:ParamSpecTypeInfo,:TypeInstance,
20-
:TypeInterface,:WeakRef])
19+
:ObjectConstructParam,:TypeInstance,:TypeInterface,:WeakRef])
2120

2221
# these struct types are members in other structs, so we export them first
23-
first_list=[:EnumValue,:TypeClass,:FlagsValue,:TypeValueTable]
22+
first_list=[:EnumValue,:TypeClass,:TypeInterface,:FlagsValue,:TypeValueTable]
2423
GI.struct_exprs!(exprs,exports,ns,first_list)
2524

2625
struct_skiplist=vcat(struct_skiplist,first_list)
@@ -76,7 +75,7 @@ skiplist=vcat(handled_list,[:enum_complete_type_info,:enum_register_static,:flag
7675
:signal_accumulator_true_handled,:signal_connect_closure,:signal_connect_closure_by_id,
7776
:signal_handler_find,:signal_handlers_block_matched,:signal_handlers_disconnect_matched,
7877
:signal_handlers_unblock_matched,:signal_override_class_closure,
79-
:source_set_closure,:source_set_dummy_callback,:type_add_interface_static,
78+
:source_set_closure,:source_set_dummy_callback,
8079
:type_check_instance,:type_check_instance_is_a,:type_check_instance_is_fundamentally_a,
8180
:type_default_interface_unref,:type_free_instance,
8281
:type_name_from_instance,:type_register_fundamental,

src/GLib/gio.jl

+1
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ end
3535

3636
cancel(c::GCancellable) = G_.cancel(c)
3737
iscancelled(c::GCancellable) = G_.is_cancelled(c)
38+

src/GLib/gtype.jl

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
abstract type GTypeInstance end
22
abstract type GObject <: GTypeInstance end
3-
abstract type GTypeInterface end
4-
abstract type _GTypeInterface end
53
abstract type GInterface <: GObject end
64
abstract type GBoxed end
75

src/events.jl

+13
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ function GtkShortcutController(widget::GtkWidget)
4646
g
4747
end
4848

49+
"""
50+
add_action_shortcut(scc::GtkShortcutController,trigger::AbstractString,action::AbstractString)
51+
52+
Adds a shortcut specified by a string like "<Control>S" for an action (such as
53+
"app.save") to a `GtkShortcutController`.
54+
"""
55+
function add_action_shortcut(scc::GtkShortcutController,trigger::AbstractString,action::AbstractString)
56+
t = GtkShortcutTrigger(trigger)
57+
a = GtkShortcutAction("action($action)")
58+
sc = GtkShortcut(t,a)
59+
Gtk4.G_.add_shortcut(scc,sc)
60+
end
61+
4962
push!(sc::GtkShortcutController, s::GtkShortcut) = (G_.add_shortcut(sc,s);sc)
5063

5164
function GtkGestureClick(widget::GtkWidget,button=1)

src/gen/gobject_functions

+4
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ $(Expr(:toplevel, quote
172172
ret = ccall(("g_type_add_interface_dynamic", libgobject), Nothing, (UInt64, UInt64, Ptr{GObject}), _instance_type, _interface_type, _plugin)
173173
nothing
174174
end
175+
function type_add_interface_static(_instance_type::Integer, _interface_type::Integer, _info::Union{GInterfaceInfo, Ref{_GInterfaceInfo}})
176+
ret = ccall(("g_type_add_interface_static", libgobject), Nothing, (UInt64, UInt64, Ptr{_GInterfaceInfo}), _instance_type, _interface_type, _info)
177+
nothing
178+
end
175179
function type_check_class_is_a(_g_class::Union{GTypeClass, Ref{_GTypeClass}}, _is_a_type::Integer)
176180
ret = ccall(("g_type_check_class_is_a", libgobject), Cint, (Ptr{_GTypeClass}, UInt64), _g_class, _is_a_type)
177181
ret2 = convert(Bool, ret)

src/gen/gobject_structs

+46-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ $(Expr(:toplevel, quote
2424
convert(Ptr{_GTypeClass}, box.handle)
2525
end
2626
end
27+
begin
28+
struct _GTypeInterface
29+
g_type::UInt64
30+
g_instance_type::UInt64
31+
end
32+
mutable struct GTypeInterface
33+
handle::Ptr{_GTypeInterface}
34+
end
35+
unsafe_convert(::Type{Ptr{_GTypeInterface}}, box::GTypeInterface) = begin
36+
convert(Ptr{_GTypeInterface}, box.handle)
37+
end
38+
end
2739
begin
2840
struct _GFlagsValue
2941
value::UInt32
@@ -84,6 +96,37 @@ $(Expr(:toplevel, quote
8496
convert(Ptr{_GFlagsClass}, box.handle)
8597
end
8698
end
99+
begin
100+
struct _GInterfaceInfo
101+
interface_init::Ptr{Cvoid}
102+
interface_finalize::Ptr{Cvoid}
103+
interface_data::Ptr{Nothing}
104+
end
105+
mutable struct GInterfaceInfo
106+
handle::Ptr{_GInterfaceInfo}
107+
end
108+
unsafe_convert(::Type{Ptr{_GInterfaceInfo}}, box::GInterfaceInfo) = begin
109+
convert(Ptr{_GInterfaceInfo}, box.handle)
110+
end
111+
end
112+
begin
113+
struct _GParamSpecTypeInfo
114+
instance_size::UInt16
115+
n_preallocs::UInt16
116+
instance_init::Ptr{Cvoid}
117+
value_type::UInt64
118+
finalize::Ptr{Cvoid}
119+
value_set_default::Ptr{Cvoid}
120+
value_validate::Ptr{Cvoid}
121+
values_cmp::Ptr{Cvoid}
122+
end
123+
mutable struct GParamSpecTypeInfo
124+
handle::Ptr{_GParamSpecTypeInfo}
125+
end
126+
unsafe_convert(::Type{Ptr{_GParamSpecTypeInfo}}, box::GParamSpecTypeInfo) = begin
127+
convert(Ptr{_GParamSpecTypeInfo}, box.handle)
128+
end
129+
end
87130
begin
88131
struct _GSignalInvocationHint
89132
signal_id::UInt32
@@ -204,6 +247,8 @@ $(Expr(:toplevel, quote
204247
end
205248
@doc "See the [GTK docs](https://docs.gtk.org/gobject/struct.EnumClass.html)." GEnumClass
206249
@doc "See the [GTK docs](https://docs.gtk.org/gobject/struct.FlagsClass.html)." GFlagsClass
250+
@doc "See the [GTK docs](https://docs.gtk.org/gobject/struct.InterfaceInfo.html)." GInterfaceInfo
251+
@doc "See the [GTK docs](https://docs.gtk.org/gobject/struct.ParamSpecTypeInfo.html)." GParamSpecTypeInfo
207252
@doc "See the [GTK docs](https://docs.gtk.org/gobject/struct.SignalInvocationHint.html)." GSignalInvocationHint
208253
@doc "See the [GTK docs](https://docs.gtk.org/gobject/struct.SignalQuery.html)." GSignalQuery
209254
@doc "See the [GTK docs](https://docs.gtk.org/gobject/struct.TypeFundamentalInfo.html)." GTypeFundamentalInfo
@@ -378,6 +423,6 @@ $(Expr(:toplevel, quote
378423
ret = f(ihint, n_param_values, param_values)
379424
convert(Cint, ret)
380425
end
381-
export GEnumValue, _GEnumValue, GTypeClass, _GTypeClass, GFlagsValue, _GFlagsValue, GTypeValueTable, _GTypeValueTable, GEnumClass, _GEnumClass, GFlagsClass, _GFlagsClass, GSignalInvocationHint, _GSignalInvocationHint, GSignalQuery, _GSignalQuery, GTypeFundamentalInfo, _GTypeFundamentalInfo, GTypeInfo, _GTypeInfo, GTypePluginClass, _GTypePluginClass, GTypeQuery, _GTypeQuery, GValueArray, _GValueArray, GBinding, GBindingLeaf, GBindingGroup, GBindingGroupLeaf, GInitiallyUnowned, GInitiallyUnownedLeaf, GTypeModule, GTypePlugin, GBindingTransformFunc, GClassFinalizeFunc, GClassInitFunc, GClosureMarshal, GInterfaceFinalizeFunc, GInterfaceInitFunc, GSignalAccumulator, GSignalEmissionHook
426+
export GEnumValue, _GEnumValue, GTypeClass, _GTypeClass, GTypeInterface, _GTypeInterface, GFlagsValue, _GFlagsValue, GTypeValueTable, _GTypeValueTable, GEnumClass, _GEnumClass, GFlagsClass, _GFlagsClass, GInterfaceInfo, _GInterfaceInfo, GParamSpecTypeInfo, _GParamSpecTypeInfo, GSignalInvocationHint, _GSignalInvocationHint, GSignalQuery, _GSignalQuery, GTypeFundamentalInfo, _GTypeFundamentalInfo, GTypeInfo, _GTypeInfo, GTypePluginClass, _GTypePluginClass, GTypeQuery, _GTypeQuery, GValueArray, _GValueArray, GBinding, GBindingLeaf, GBindingGroup, GBindingGroupLeaf, GInitiallyUnowned, GInitiallyUnownedLeaf, GTypeModule, GTypePlugin, GBindingTransformFunc, GClassFinalizeFunc, GClassInitFunc, GClosureMarshal, GInterfaceFinalizeFunc, GInterfaceInitFunc, GSignalAccumulator, GSignalEmissionHook
382427
end))
383428
end

0 commit comments

Comments
 (0)