gobject-introspection 1.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. data/Rakefile +50 -0
  2. data/ext/gobject-introspection/extconf.rb +97 -0
  3. data/ext/gobject-introspection/rb-gi-arg-info.c +151 -0
  4. data/ext/gobject-introspection/rb-gi-argument.c +223 -0
  5. data/ext/gobject-introspection/rb-gi-base-info.c +218 -0
  6. data/ext/gobject-introspection/rb-gi-boxed-info.c +48 -0
  7. data/ext/gobject-introspection/rb-gi-callable-info.c +124 -0
  8. data/ext/gobject-introspection/rb-gi-callback-info.c +48 -0
  9. data/ext/gobject-introspection/rb-gi-constant-info.c +77 -0
  10. data/ext/gobject-introspection/rb-gi-constructor-info.c +82 -0
  11. data/ext/gobject-introspection/rb-gi-conversions.h +95 -0
  12. data/ext/gobject-introspection/rb-gi-enum-info.c +145 -0
  13. data/ext/gobject-introspection/rb-gi-field-info.c +149 -0
  14. data/ext/gobject-introspection/rb-gi-flags-info.c +48 -0
  15. data/ext/gobject-introspection/rb-gi-function-info.c +199 -0
  16. data/ext/gobject-introspection/rb-gi-interface-info.c +222 -0
  17. data/ext/gobject-introspection/rb-gi-loader.c +61 -0
  18. data/ext/gobject-introspection/rb-gi-method-info.c +66 -0
  19. data/ext/gobject-introspection/rb-gi-object-info.c +345 -0
  20. data/ext/gobject-introspection/rb-gi-property-info.c +77 -0
  21. data/ext/gobject-introspection/rb-gi-registered-type-info.c +86 -0
  22. data/ext/gobject-introspection/rb-gi-repository.c +164 -0
  23. data/ext/gobject-introspection/rb-gi-signal-info.c +77 -0
  24. data/ext/gobject-introspection/rb-gi-struct-info.c +183 -0
  25. data/ext/gobject-introspection/rb-gi-type-info.c +143 -0
  26. data/ext/gobject-introspection/rb-gi-type-tag.c +43 -0
  27. data/ext/gobject-introspection/rb-gi-types.h +71 -0
  28. data/ext/gobject-introspection/rb-gi-union-info.c +206 -0
  29. data/ext/gobject-introspection/rb-gi-unresolved-info.c +48 -0
  30. data/ext/gobject-introspection/rb-gi-value-info.c +57 -0
  31. data/ext/gobject-introspection/rb-gi-vfunc-info.c +91 -0
  32. data/ext/gobject-introspection/rb-gobject-introspection.c +42 -0
  33. data/ext/gobject-introspection/rb-gobject-introspection.h +105 -0
  34. data/extconf.rb +71 -0
  35. data/lib/gobject-introspection.rb +39 -0
  36. data/lib/gobject-introspection/collection-reader.rb +34 -0
  37. data/lib/gobject-introspection/loader.rb +148 -0
  38. data/lib/gobject-introspection/object-info.rb +33 -0
  39. data/lib/gobject-introspection/repository.rb +32 -0
  40. data/lib/gobject-introspection/struct-info.rb +28 -0
  41. data/sample/clutter-basic-actor.rb +132 -0
  42. data/sample/clutter.rb +29 -0
  43. data/test/gobject-introspection-test-utils.rb +26 -0
  44. data/test/run-test.rb +45 -0
  45. data/test/test-arg-info.rb +68 -0
  46. data/test/test-base-info.rb +31 -0
  47. data/test/test-boxed-info.rb +21 -0
  48. data/test/test-callable-info.rb +49 -0
  49. data/test/test-callback-info.rb +29 -0
  50. data/test/test-constant-info.rb +24 -0
  51. data/test/test-enum-info.rb +56 -0
  52. data/test/test-field-type.rb +42 -0
  53. data/test/test-flags-info.rb +27 -0
  54. data/test/test-function-info.rb +37 -0
  55. data/test/test-interface-info.rb +97 -0
  56. data/test/test-loader.rb +30 -0
  57. data/test/test-object-info.rb +131 -0
  58. data/test/test-property-info.rb +38 -0
  59. data/test/test-registered-type-info.rb +35 -0
  60. data/test/test-repository.rb +59 -0
  61. data/test/test-signal-info.rb +37 -0
  62. data/test/test-struct-info.rb +57 -0
  63. data/test/test-type-info.rb +62 -0
  64. data/test/test-type-tag.rb +29 -0
  65. data/test/test-union-info.rb +21 -0
  66. data/test/test-value-info.rb +28 -0
  67. data/test/test-vfunc-info.rb +42 -0
  68. metadata +162 -0
@@ -0,0 +1,34 @@
1
+ # Copyright (C) 2012 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ module GObjectIntrospection
18
+ module CollectionReader
19
+ def collection_reader(name)
20
+ n_getter = "n_#{name}"
21
+ if name.end_with?("ies")
22
+ singular = name.sub(/ies\z/, "y")
23
+ else
24
+ singular = name.sub(/s\z/, "")
25
+ end
26
+ getter = "get_#{singular}"
27
+ define_method(name) do
28
+ send(n_getter).times.collect do |i|
29
+ send(getter, i)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,148 @@
1
+ # Copyright (C) 2012 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ module GObjectIntrospection
18
+ class Loader
19
+ class << self
20
+ def load(namespace, base_module)
21
+ loader = new(base_module)
22
+ loader.load(namespace)
23
+ end
24
+ end
25
+
26
+ def initialize(base_module)
27
+ @base_module = base_module
28
+ end
29
+
30
+ def load(namespace)
31
+ repository = Repository.default
32
+ repository.require(namespace)
33
+ repository.each(namespace) do |info|
34
+ load_info(info)
35
+ end
36
+ end
37
+
38
+ private
39
+ def load_info(info)
40
+ case info
41
+ when FunctionInfo
42
+ load_function_info(info)
43
+ when StructInfo
44
+ load_struct_info(info)
45
+ when EnumInfo
46
+ load_enum_info(info)
47
+ when ObjectInfo
48
+ load_object_info(info)
49
+ when InterfaceInfo
50
+ load_interface_info(info)
51
+ when ConstantInfo
52
+ load_constant_info(info)
53
+ when UnionInfo
54
+ load_union_info(info)
55
+ end
56
+ end
57
+
58
+ def load_function_info(info)
59
+ @base_module.module_eval do
60
+ define_method(info.name) do |*arguments|
61
+ info.invoke(*arguments)
62
+ end
63
+ module_function(info.name)
64
+ end
65
+ end
66
+
67
+ def load_struct_info(info)
68
+ return if info.gtype_struct?
69
+ return if info.gtype == GLib::Type::NONE
70
+
71
+ klass = self.class.define_class(info.gtype, info.name, @base_module)
72
+ load_field_infos(info, klass)
73
+ info.methods.each do |method_info|
74
+ load_method_info(method_info, klass)
75
+ end
76
+ end
77
+
78
+ def load_enum_info(info)
79
+ self.class.define_class(info.gtype, info.name, @base_module)
80
+ end
81
+
82
+ def load_object_info(info)
83
+ klass = self.class.define_class(info.gtype, info.name, @base_module)
84
+ load_field_infos(info, klass)
85
+ info.methods.each do |method_info|
86
+ load_method_info(method_info, klass)
87
+ end
88
+ end
89
+
90
+ def load_field_infos(info, klass)
91
+ info.n_fields.times do |i|
92
+ field_info = info.get_field(i)
93
+ name = field_info.name
94
+ flags = field_info.flags
95
+
96
+ if flags.readable?
97
+ klass.__send__(:define_method, name) do
98
+ info.get_field_value(self, i)
99
+ end
100
+ end
101
+
102
+ if flags.writable?
103
+ klass.__send__(:define_method, "#{name}=") do |value|
104
+ info.set_field_value(self, i, value)
105
+ end
106
+ end
107
+ end
108
+ end
109
+
110
+ def load_method_info(info, klass)
111
+ name = info.name
112
+ case info
113
+ when ConstructorInfo
114
+ if name == "new"
115
+ klass.__send__(:define_method, "initialize") do |*arguments|
116
+ info.invoke(self, *arguments)
117
+ end
118
+ else
119
+ # TODO
120
+ end
121
+ when MethodInfo
122
+ klass.__send__(:define_method, name) do |*arguments|
123
+ info.invoke(self, *arguments)
124
+ end
125
+ else
126
+ return if name == "new"
127
+ return if name == "alloc"
128
+ singleton_class = (class << klass; self; end)
129
+ singleton_class.__send__(:define_method, name) do |*arguments|
130
+ info.invoke(*arguments)
131
+ end
132
+ end
133
+ end
134
+
135
+ def load_interface_info(info)
136
+ self.class.define_interface(info.gtype, info.name, @base_module)
137
+ end
138
+
139
+ def load_constant_info(info)
140
+ @base_module.const_set(info.name, info.value)
141
+ end
142
+
143
+ def load_union_info(info)
144
+ klass = self.class.define_class(info.gtype, info.name, @base_module)
145
+ load_field_infos(info, klass)
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,33 @@
1
+ # Copyright (C) 2012 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ require "gobject-introspection/collection-reader"
18
+
19
+ module GObjectIntrospection
20
+ class ObjectInfo
21
+ extend CollectionReader
22
+
23
+ alias_method :__methods__, :methods
24
+
25
+ collection_reader("interfaces")
26
+ collection_reader("fields")
27
+ collection_reader("properties")
28
+ collection_reader("methods")
29
+ collection_reader("signals")
30
+ collection_reader("vfuncs")
31
+ collection_reader("constants")
32
+ end
33
+ end
@@ -0,0 +1,32 @@
1
+ # Copyright (C) 2012 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ module GObjectIntrospection
18
+ class Repository
19
+ include Enumerable
20
+
21
+ def each(*namespaces)
22
+ if namespaces.empty?
23
+ namespaces = loaded_namespaces
24
+ end
25
+ namespaces.each do |namespace|
26
+ get_n_infos(namespace).times do |i|
27
+ yield(get_info(namespace, i))
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,28 @@
1
+ # Copyright (C) 2012 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ require "gobject-introspection/collection-reader"
18
+
19
+ module GObjectIntrospection
20
+ class StructInfo
21
+ extend CollectionReader
22
+
23
+ alias_method :__methods__, :methods
24
+
25
+ collection_reader("fields")
26
+ collection_reader("methods")
27
+ end
28
+ end
@@ -0,0 +1,132 @@
1
+ # This sample code is a port of clutter/examples/basic-actor.c.
2
+ # It is licensed under the terms of the GNU Lesser General Public
3
+ # License, version 2.1 or (at your option) later.
4
+ #
5
+ # Copyright (C) 2012 Ruby-GNOME2 Project Team
6
+ #
7
+ # This library is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation; either
10
+ # version 2.1 of the License, or (at your option) any later version.
11
+ #
12
+ # This library is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ # Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public
18
+ # License along with this library; if not, write to the Free Software
19
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+
21
+ require "clutter"
22
+
23
+ Clutter.init(ARGV.size, ARGV)
24
+
25
+ stage = Clutter::Stage.new
26
+ stage.signal_connect("destroy") do |*args|
27
+ Clutter.main_quit
28
+ end
29
+
30
+ vase = Clutter::Actor.new
31
+ vase.name = "vase"
32
+ vase.layout_manager = Clutter::BoxLayout.new
33
+ vase.background_color = Clutter::Color.get_static(:sky_blue_light)
34
+ vase.add_constraint(Clutter::AlignConstraint.new(stage, :both, 0.5))
35
+ stage.add_child(vase)
36
+
37
+ SIZE = 128
38
+
39
+ flowers = []
40
+
41
+ flower = Clutter::Actor.new
42
+ flowers << flower
43
+ flower.name = "flower.1"
44
+ flower.set_size(SIZE, SIZE)
45
+ flower.margin_left = 12
46
+ flower.background_color = Clutter::Color.get_static(:red)
47
+ flower.reactive = true
48
+ vase.add_child(flower)
49
+
50
+ toggled = true
51
+ flower.signal_connect("button-press-event") do |actor, event|
52
+ if toggled
53
+ end_color = Clutter::Color.get_static(:blue)
54
+ else
55
+ end_color = Clutter::Color.get_static(:red)
56
+ end
57
+
58
+ actor.save_easing_state
59
+ actor.set_easing_duration(500)
60
+ actor.set_easing_mode(:linear)
61
+ actor.background_color = end_color
62
+ actor.restore_easing_state
63
+
64
+ toggled = !toggled
65
+
66
+ stop = true
67
+ stop
68
+ end
69
+
70
+ flower = Clutter::Actor.new
71
+ flowers << flower
72
+ flower.set_name("flower.2")
73
+ flower.set_size(SIZE, SIZE)
74
+ flower.set_margin_top(12)
75
+ flower.set_margin_left(6)
76
+ flower.set_margin_right(6)
77
+ flower.set_margin_bottom(12)
78
+ flower.set_background_color(Clutter::Color.get_static(:yellow))
79
+ flower.set_reactive(flower, true)
80
+ vase.add_child(flower)
81
+
82
+ on_crossing = lambda do |actor, event|
83
+ if event.type == Clutter::EventType::ENTER
84
+ zpos = -250.0
85
+ else
86
+ zpos = 0.0
87
+ end
88
+
89
+ actor.save_easing_state
90
+ actor.set_easing_duration(500)
91
+ actor.set_easing_mode(:ease_out_bounce)
92
+ actor.set_z_position(zpos)
93
+ actor.restore_easing_state
94
+
95
+ stop = true
96
+ stop
97
+ end
98
+ flower.signal_connect("enter-event", &on_crossing)
99
+ flower.signal_connect("leave-event", &on_crossing)
100
+
101
+ flower = Clutter::Actor.new
102
+ flowers << flower
103
+ flower.set_name("flower.3")
104
+ flower.set_size(SIZE, SIZE)
105
+ flower.set_margin_right(12)
106
+ flower.set_background_color(Clutter::Color::get_static(:green))
107
+ flower.set_pivot_point(0.5, 0.0)
108
+ flower.set_reactive(true)
109
+ vase.add_child(flower);
110
+ flower.signal_connect("button-press-event") do |actor, event|
111
+ actor.save_easing_state
112
+ actor.set_easing_duration(1000)
113
+
114
+ actor.set_rotation_angle(:y_axis, 360.0)
115
+
116
+ actor.restore_easing_state
117
+
118
+ id = actor.signal_connect("transition-stopped::rotation-angle-y") do
119
+ actor.save_easing_state
120
+ actor.set_rotation_angle(:y_axis, 0.0)
121
+ actor.restore_easing_state
122
+
123
+ actor.signal_handler_disconnect(id)
124
+ end
125
+
126
+ stop = true
127
+ stop
128
+ end
129
+
130
+ stage.show
131
+
132
+ Clutter.main
data/sample/clutter.rb ADDED
@@ -0,0 +1,29 @@
1
+ # Copyright (C) 2012 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ require "gobject-introspection"
18
+
19
+ module Clutter
20
+ class Loader < GObjectIntrospection::Loader
21
+ private
22
+ def load_constant_info(info)
23
+ return unless /\A(?:KEY_|COLOR_)/ =~ info.name
24
+ super
25
+ end
26
+
27
+ load("Clutter", Clutter)
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ # Copyright (C) 2012 Ruby-GNOME2 Project Team
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ require "test-unit"
18
+ require "test/unit/notify"
19
+
20
+ module GObjectIntrospectionTestUtils
21
+ def require_version(major, minor, micro)
22
+ if (GObjectIntrospection::BUILD_VERSION <=> [major, minor, micro]) < 0
23
+ omit("require GObjectIntrospection #{major}.#{minor}.#{micro} or later.")
24
+ end
25
+ end
26
+ end