gtk4 3.5.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/gtk4.gemspec +1 -5
  3. data/lib/gtk4/{menu-item.rb → application.rb} +11 -10
  4. data/lib/gtk4/box.rb +1 -1
  5. data/lib/gtk4/builder.rb +14 -61
  6. data/lib/gtk4/button.rb +1 -2
  7. data/lib/gtk4/combo-box.rb +1 -6
  8. data/lib/gtk4/deprecated.rb +234 -246
  9. data/lib/gtk4/dialog.rb +10 -21
  10. data/lib/gtk4/{action.rb → entry.rb} +11 -8
  11. data/lib/gtk4/{gdk-drag-context.rb → gdk-display.rb} +12 -10
  12. data/lib/gtk4/icon-theme.rb +9 -12
  13. data/lib/gtk4/image.rb +12 -56
  14. data/lib/gtk4/list-store.rb +8 -0
  15. data/lib/gtk4/loader.rb +153 -27
  16. data/lib/gtk4/message-dialog.rb +1 -1
  17. data/lib/gtk4/paned.rb +17 -11
  18. data/lib/gtk4/{clipboard.rb → response-type.rb} +11 -6
  19. data/lib/gtk4/ruby-builder-scope.rb +47 -0
  20. data/lib/gtk4/scale-button.rb +6 -13
  21. data/lib/gtk4/stack.rb +23 -27
  22. data/lib/gtk4/style-context.rb +20 -4
  23. data/lib/gtk4/text-buffer.rb +14 -10
  24. data/lib/gtk4/{style-properties.rb → tree-model-sort.rb} +7 -9
  25. data/lib/gtk4/tree-model.rb +21 -1
  26. data/lib/gtk4/{target-list.rb → tree-sortable.rb} +8 -11
  27. data/lib/gtk4/tree-view-column.rb +9 -1
  28. data/lib/gtk4/version.rb +2 -2
  29. data/lib/gtk4/widget.rb +44 -71
  30. data/lib/gtk4.rb +4 -35
  31. data/sample/demos/README.md +4 -0
  32. data/sample/examples/README.md +4 -0
  33. data/sample/{action-namespace.rb → examples/action-namespace.rb} +0 -0
  34. data/sample/{builder.rb → examples/builder.rb} +0 -0
  35. data/sample/{builder.ui → examples/builder.ui} +0 -0
  36. data/sample/{drawing.rb → examples/drawing.rb} +0 -0
  37. data/sample/{grid_packing.rb → examples/grid_packing.rb} +0 -0
  38. data/sample/{hello_world.rb → examples/hello_world.rb} +0 -0
  39. data/sample/{utils.rb → examples/utils.rb} +0 -0
  40. data/sample/getting-started/README.md +4 -0
  41. metadata +26 -92
  42. data/lib/gtk4/action-group.rb +0 -131
  43. data/lib/gtk4/calendar.rb +0 -30
  44. data/lib/gtk4/check-menu-item.rb +0 -34
  45. data/lib/gtk4/container.rb +0 -62
  46. data/lib/gtk4/icon-size.rb +0 -32
  47. data/lib/gtk4/image-menu-item.rb +0 -37
  48. data/lib/gtk4/radio-action.rb +0 -28
  49. data/lib/gtk4/radio-button.rb +0 -49
  50. data/lib/gtk4/recent-chooser-dialog.rb +0 -38
  51. data/lib/gtk4/selection-data.rb +0 -42
  52. data/lib/gtk4/stock-item.rb +0 -36
  53. data/lib/gtk4/stock.rb +0 -70
  54. data/lib/gtk4/table.rb +0 -43
  55. data/lib/gtk4/target-entry.rb +0 -27
  56. data/lib/gtk4/toggle-action.rb +0 -27
  57. data/lib/gtk4/tool-button.rb +0 -36
  58. data/lib/gtk4/ui-manager.rb +0 -35
  59. data/lib/gtk4/window.rb +0 -42
  60. data/test/fixture/gnome-logo-icon.png +0 -0
  61. data/test/gtk-test-utils.rb +0 -36
  62. data/test/run-test.rb +0 -42
  63. data/test/test-gtk-box.rb +0 -36
  64. data/test/test-gtk-button.rb +0 -46
  65. data/test/test-gtk-dialog.rb +0 -74
  66. data/test/test-gtk-menu-item.rb +0 -42
  67. data/test/test-gtk-message-dialog.rb +0 -62
  68. data/test/test-gtk-version.rb +0 -47
  69. data/test/test-gtk-window.rb +0 -34
data/lib/gtk4/stack.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014 Ruby-GNOME2 Project Team
1
+ # Copyright (C) 2014-2022 Ruby-GNOME Project Team
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -16,39 +16,35 @@
16
16
 
17
17
  module Gtk
18
18
  class Stack
19
- if method_defined?(:set_visible_child)
20
- alias_method :set_visible_child_raw, :set_visible_child
21
- def set_visible_child(widget_or_name, transition_type=nil)
22
- case widget_or_name
23
- when String
24
- name = widget_or_name
25
- else
26
- widget = widget_or_name
27
- end
19
+ alias_method :set_visible_child_raw, :set_visible_child
20
+ def set_visible_child(widget_or_name, transition_type=nil)
21
+ case widget_or_name
22
+ when String
23
+ name = widget_or_name
24
+ else
25
+ widget = widget_or_name
26
+ end
28
27
 
29
- if widget
30
- set_visible_child_raw(widget)
28
+ if widget
29
+ set_visible_child_raw(widget)
30
+ else
31
+ if transition_type
32
+ set_visible_child_full(name, transition_type)
31
33
  else
32
- if transition_type
33
- set_visible_child_full(name, transition_type)
34
- else
35
- set_visible_child_name(name)
36
- end
34
+ set_visible_child_name(name)
37
35
  end
38
36
  end
39
37
  end
40
38
 
41
- if method_defined?(:add_titled) and method_defined?(:add_named)
42
- def add(widget, name=nil, title=nil)
43
- if title
44
- add_titled(widget, name, title)
45
- elsif name
46
- add_named(widget, name)
47
- else
48
- super(widget)
49
- end
50
- self
39
+ def add(widget, name=nil, title=nil)
40
+ if title
41
+ add_titled(widget, name, title)
42
+ elsif name
43
+ add_named(widget, name)
44
+ else
45
+ add_child(widget)
51
46
  end
47
+ self
52
48
  end
53
49
  end
54
50
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2015 Ruby-GNOME2 Project Team
1
+ # Copyright (C) 2015-2022 Ruby-GNOME Project Team
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -17,10 +17,26 @@
17
17
  module Gtk
18
18
  class StyleContext
19
19
  class << self
20
- alias_method :reset_widgets_raw, :reset_widgets
21
- def reset_widgets(screen=nil)
22
- reset_widgets_raw(screen || Gdk::Screen.default)
20
+ def resolve_priority(priority)
21
+ case priority
22
+ when Symbol, String
23
+ StyleProvider.const_get("PRIORITY_#{priority.to_s.upcase}")
24
+ else
25
+ priority || StyleProvider::PRIORITY_APPLICATION
26
+ end
23
27
  end
28
+
29
+ alias_method :add_provider_for_display_raw, :add_provider_for_display
30
+ def add_provider_for_display(display, provider, priority=nil)
31
+ priority = resolve_priority(priority)
32
+ add_provider_for_display_raw(display, provider, priority)
33
+ end
34
+ end
35
+
36
+ alias_method :add_provider_raw, :add_provider
37
+ def add_provider(provider, priority=nil)
38
+ priority = self.class.resolve_priority(priority)
39
+ add_provider_raw(provider, priority)
24
40
  end
25
41
  end
26
42
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2017 Ruby-GNOME2 Project Team
1
+ # Copyright (C) 2014-20122 Ruby-GNOME Project Team
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -22,7 +22,8 @@ module Gtk
22
22
  return nil unless succeeded
23
23
 
24
24
  properties.each do |name, value|
25
- tag.__send__("#{name}=", value)
25
+ property_name = name.to_s.gsub(/-/, "_")
26
+ tag.__send__("#{property_name}=", value)
26
27
  end
27
28
 
28
29
  tag
@@ -94,7 +95,7 @@ module Gtk
94
95
  end
95
96
 
96
97
  alias_method :insert_raw, :insert
97
- alias_method :insert_pixbuf_raw, :insert_pixbuf
98
+ alias_method :insert_paintable_raw, :insert_paintable
98
99
  alias_method :insert_child_anchor_raw, :insert_child_anchor
99
100
  def insert(iter, target, *args)
100
101
  options = nil
@@ -129,8 +130,10 @@ module Gtk
129
130
  insert_interactive(iter, target, default_editable)
130
131
  else
131
132
  case target
133
+ when Gdk::Paintable
134
+ insert_paintable_raw(iter, target)
132
135
  when GdkPixbuf::Pixbuf
133
- insert_pixbuf_raw(iter, target)
136
+ insert_paintable_raw(iter, target)
134
137
  when TextChildAnchor
135
138
  insert_text_child_anchor_raw(iter, target)
136
139
  when GLib::Bytes
@@ -143,7 +146,13 @@ module Gtk
143
146
  if tags
144
147
  start_iter = get_iter_at(:offset => start_offset)
145
148
  tags.each do |tag|
146
- tag = tag_table.lookup(tag) if tag.is_a?(String)
149
+ if tag.is_a?(String)
150
+ resolved_tag = tag_table.lookup(tag)
151
+ if resolved_tag.nil?
152
+ raise ArgumentError "unknown tag: #{tag.inspect}"
153
+ end
154
+ tag = resolved_tag
155
+ end
147
156
  apply_tag(tag, start_iter, iter)
148
157
  end
149
158
  end
@@ -198,11 +207,6 @@ module Gtk
198
207
  end
199
208
  end
200
209
 
201
- alias_method :serialize_raw, :serialize
202
- def serialize(*arguments)
203
- serialize_raw(*arguments).pack("C*")
204
- end
205
-
206
210
  alias_method :selection_bounds_raw, :selection_bounds
207
211
  def selection_bounds
208
212
  selected, start_iter, end_iter = selection_bounds_raw
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2015 Ruby-GNOME2 Project Team
1
+ # Copyright (C) 2019 Ruby-GNOME Project Team
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -15,14 +15,12 @@
15
15
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
  module Gtk
18
- class StyleProperties
19
- alias_method :get_property_raw, :get_property
20
- def get_property(key, state)
21
- found, property = get_property_raw(key, state)
22
- if found
23
- property.value
24
- else
25
- nil
18
+ class TreeModelSort
19
+ if TreeModel.method_defined?(:sort_new_with_model)
20
+ class << self
21
+ def new(model)
22
+ model.sort_new_with_model
23
+ end
26
24
  end
27
25
  end
28
26
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 Ruby-GNOME2 Project Team
1
+ # Copyright (C) 2014-2022 Ruby-GNOME Project Team
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -107,6 +107,26 @@ module Gtk
107
107
 
108
108
  alias_method :create_filter, :filter_new
109
109
 
110
+ alias_method :each_raw, :each
111
+ def each
112
+ return to_enum(__method__) unless block_given?
113
+ exception = nil
114
+ each_raw do |model, path, iter|
115
+ stop = true
116
+ # TODO: This doesn't return 'stop' to GTK when caller uses 'break'.
117
+ begin
118
+ iter.model = model
119
+ yield(model, path, iter)
120
+ stop = false
121
+ rescue Exception => e
122
+ exception = e
123
+ end
124
+ stop
125
+ end
126
+ raise exception if exception
127
+ self
128
+ end
129
+
110
130
  private
111
131
  def setup_iter(iter)
112
132
  iter.model = self
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2015 Ruby-GNOME2 Project Team
1
+ # Copyright (C) 2022 Ruby-GNOME Project Team
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -15,16 +15,13 @@
15
15
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
  module Gtk
18
- class TargetList
19
- alias_method :find_raw, :find
20
- def find(target)
21
- target = Gdk::Atom.intern(target) if target.is_a?(String)
22
-
23
- found, info = find_raw(target)
24
- if found
25
- info
26
- else
27
- nil
18
+ module TreeSortable
19
+ alias_method :set_sort_func_raw, :set_sort_func
20
+ def set_sort_func(sort_column_id)
21
+ set_sort_func_raw(sort_column_id) do |model, iter1, iter2|
22
+ iter1.model = model
23
+ iter2.model = model
24
+ yield(model, iter1, iter2)
28
25
  end
29
26
  end
30
27
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2016 Ruby-GNOME2 Project Team
1
+ # Copyright (C) 2014-2022 Ruby-GNOME Project Team
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -57,5 +57,13 @@ module Gtk
57
57
  key = key.to_s if key.is_a?(Symbol)
58
58
  add_attribute_raw(renderer, key, value)
59
59
  end
60
+
61
+ alias_method :set_cell_data_func_raw, :set_cell_data_func
62
+ def set_cell_data_func(cell)
63
+ set_cell_data_func_raw(cell) do |column, cell, model, iter|
64
+ iter.model = model
65
+ yield(column, cell, model, iter)
66
+ end
67
+ end
60
68
  end
61
69
  end
data/lib/gtk4/version.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2018 Ruby-GNOME2 Project Team
1
+ # Copyright (C) 2014-2015 Ruby-GNOME2 Project Team
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -20,7 +20,7 @@ module Gtk
20
20
 
21
21
  class << self
22
22
  def or_later?(major, minor, micro=nil)
23
- error_message = Gtk.check_version(major, minor, micro)
23
+ error_message = Gtk.check_version(major, minor, micro || 0)
24
24
  error_message.nil?
25
25
  end
26
26
  end
data/lib/gtk4/widget.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2015-2016 Ruby-GNOME2 Project Team
1
+ # Copyright (C) 2015-2022 Ruby-GNOME Project Team
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -17,9 +17,6 @@
17
17
  module Gtk
18
18
  class Widget
19
19
  class << self
20
- def init
21
- end
22
-
23
20
  def have_template?
24
21
  @have_template ||= false
25
22
  end
@@ -38,6 +35,8 @@ module Gtk
38
35
  else
39
36
  set_template_raw(data)
40
37
  end
38
+ @scope = Gtk::RubyBuilderScope.new
39
+ set_template_scope(@scope)
41
40
  @have_template = true
42
41
  end
43
42
 
@@ -49,63 +48,24 @@ module Gtk
49
48
  attr_reader(name)
50
49
  end
51
50
  end
52
-
53
- alias_method :set_connect_func_raw, :set_connect_func
54
- def set_connect_func(&block)
55
- set_connect_func_raw do |*args|
56
- Builder.connect_signal(*args, &block)
57
- end
58
- end
59
51
  end
60
52
 
61
- alias_method :events_raw, :events
62
- def events
63
- Gdk::EventMask.new(events_raw)
64
- end
65
-
66
- alias_method :add_events_raw, :add_events
67
- def add_events(new_events)
68
- unless new_events.is_a?(Gdk::EventMask)
69
- new_events = Gdk::EventMask.new(new_events)
70
- end
71
- add_events_raw(new_events.to_i)
72
- end
73
-
74
- alias_method :set_events_raw, :set_events
75
- def set_events(new_events)
76
- unless new_events.is_a?(Gdk::EventMask)
77
- new_events = Gdk::EventMask.new(new_events)
53
+ alias_method :set_size_request_raw, :set_size_request
54
+ def set_size_request(*args)
55
+ case args.size
56
+ when 1
57
+ options = args[0]
58
+ raise ArgumentError, ":width is missing" unless options.key?(:width)
59
+ width = options[:width]
60
+ raise ArgumentError, ":height is missing" unless options.key?(:height)
61
+ height = options[:height]
62
+ when 2
63
+ width, height = args
64
+ else
65
+ message = "wrong number of arguments (given #{args.size}, expected 1..2)"
66
+ raise ArgumentError, message
78
67
  end
79
- set_events_raw(new_events.to_i)
80
- end
81
-
82
- alias_method :events_raw=, :events=
83
- alias_method :events=, :set_events
84
-
85
- alias_method :drag_source_set_raw, :drag_source_set
86
- def drag_source_set(flags, targets, actions)
87
- targets = ensure_drag_targets(targets)
88
- drag_source_set_raw(flags, targets, actions)
89
- end
90
-
91
- alias_method :drag_dest_set_raw, :drag_dest_set
92
- def drag_dest_set(flags, targets, actions)
93
- targets = ensure_drag_targets(targets)
94
- drag_dest_set_raw(flags, targets, actions)
95
- end
96
-
97
- alias_method :style_get_property_raw, :style_get_property
98
- def style_get_property(name)
99
- property = self.class.find_style_property(name)
100
- value = GLib::Value.new(property.value_type)
101
- style_get_property_raw(name, value)
102
- value.value
103
- end
104
-
105
- alias_method :render_icon_pixbuf_raw, :render_icon_pixbuf
106
- def render_icon_pixbuf(stock_id, size)
107
- size = IconSize.new(size) unless size.is_a?(IconSize)
108
- render_icon_pixbuf_raw(stock_id, size)
68
+ set_size_request_raw(width, height)
109
69
  end
110
70
 
111
71
  alias_method :translate_coordinates_raw, :translate_coordinates
@@ -118,6 +78,32 @@ module Gtk
118
78
  end
119
79
  end
120
80
 
81
+ alias_method :style_context_raw, :style_context
82
+ def style_context
83
+ @style_context ||= style_context_raw
84
+ end
85
+
86
+ alias_method :insert_action_group_raw, :insert_action_group
87
+ def insert_action_group(name, group)
88
+ insert_action_group_raw(name, group)
89
+ @action_groups ||= {}
90
+ if group.nil?
91
+ @action_groups.delete(name)
92
+ else
93
+ @action_groups[name] = group
94
+ end
95
+ end
96
+
97
+ def children
98
+ _children = []
99
+ child = first_child
100
+ while child
101
+ _children << child
102
+ child = child.next_sibling
103
+ end
104
+ _children
105
+ end
106
+
121
107
  private
122
108
  def initialize_post
123
109
  klass = self.class
@@ -130,18 +116,5 @@ module Gtk
130
116
  instance_variable_set("@#{name}", get_template_child(gtype, name))
131
117
  end
132
118
  end
133
-
134
- def ensure_drag_targets(targets)
135
- return targets unless targets.is_a?(Array)
136
-
137
- targets.collect do |target|
138
- case target
139
- when Array
140
- TargetEntry.new(*target)
141
- else
142
- target
143
- end
144
- end
145
- end
146
119
  end
147
120
  end
data/lib/gtk4.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2006-2018 Ruby-GNOME2 Project Team
1
+ # Copyright (C) 2006-2022 Ruby-GNOME Project Team
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -14,12 +14,9 @@
14
14
  # License along with this library; if not, write to the Free Software
15
15
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
- require "gobject-introspection"
18
- require "atk"
19
17
  require "gdk4"
20
- require "gio2"
21
18
 
22
- require "gtk4/loader"
19
+ require_relative "gtk4/loader"
23
20
 
24
21
  module Gtk
25
22
  LOG_DOMAIN = "Gtk"
@@ -31,34 +28,6 @@ module Gtk
31
28
  class InitError < Error
32
29
  end
33
30
 
34
- class << self
35
- def const_missing(name)
36
- init()
37
- if const_defined?(name)
38
- const_get(name)
39
- else
40
- super
41
- end
42
- end
43
-
44
- def method_missing(name, *args, &block)
45
- init()
46
- if respond_to?(name)
47
- __send__(name, *args, &block)
48
- else
49
- super
50
- end
51
- end
52
-
53
- def init(*argv)
54
- class << self
55
- remove_method(:init)
56
- remove_method(:const_missing)
57
- remove_method(:method_missing)
58
- end
59
- Gdk.init if Gdk.respond_to?(:init)
60
- loader = Loader.new(self, argv)
61
- loader.load
62
- end
63
- end
31
+ loader = Loader.new(self)
32
+ loader.load
64
33
  end
@@ -0,0 +1,4 @@
1
+ # Ruby/GTK4 demos
2
+
3
+ There are scripts ported from
4
+ https://gitlab.gnome.org/GNOME/gtk/-/tree/main/demos .
@@ -0,0 +1,4 @@
1
+ # Ruby/GTK4 examples
2
+
3
+ There are scripts ported from
4
+ https://gitlab.gnome.org/GNOME/gtk/-/tree/main/examples .
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,4 @@
1
+ # Ruby/GTK4 getting started
2
+
3
+ There are scripts ported from
4
+ https://docs.gtk.org/gtk4/getting_started.html .