gtk4 4.1.2 → 4.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/sample/examples/application1/exampleapp.rb +2 -2
  3. data/sample/examples/application2/README.md +10 -0
  4. data/sample/examples/application2/exampleapp.rb +80 -0
  5. data/sample/examples/application3/README.md +1 -0
  6. data/sample/examples/application3/exampleapp.rb +108 -0
  7. data/sample/examples/application4/README.md +13 -0
  8. data/sample/examples/application4/exampleapp.rb +158 -0
  9. data/sample/examples/application5/README.md +30 -0
  10. data/sample/examples/application5/Rakefile +27 -0
  11. data/sample/examples/application5/exampleapp.rb +171 -0
  12. data/sample/examples/application5/org.gtk.exampleapp.gschema.xml +20 -0
  13. data/sample/examples/application6/README.md +15 -0
  14. data/sample/examples/application6/Rakefile +27 -0
  15. data/sample/examples/application6/exampleapp.rb +265 -0
  16. data/sample/examples/application6/org.gtk.exampleapp.gschema.xml +20 -0
  17. data/sample/examples/application7/README.md +15 -0
  18. data/sample/examples/application7/Rakefile +27 -0
  19. data/sample/examples/application7/exampleapp.rb +307 -0
  20. data/sample/examples/application7/org.gtk.exampleapp.gschema.xml +20 -0
  21. data/sample/examples/application8/README.md +15 -0
  22. data/sample/examples/application8/Rakefile +27 -0
  23. data/sample/examples/application8/exampleapp.rb +357 -0
  24. data/sample/examples/application8/org.gtk.exampleapp.gschema.xml +25 -0
  25. data/sample/examples/application9/README.md +15 -0
  26. data/sample/examples/application9/Rakefile +27 -0
  27. data/sample/examples/application9/exampleapp.rb +387 -0
  28. data/sample/examples/application9/org.gtk.exampleapp.gschema.xml +25 -0
  29. metadata +32 -6
@@ -0,0 +1,387 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (C) 2023 Ruby-GNOME Project Team
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ #
19
+ # Example from:
20
+ # * https://gitlab.gnome.org/GNOME/gtk/-/blob/main/examples/application9/exampleapp.c
21
+ # * https://gitlab.gnome.org/GNOME/gtk/-/blob/main/examples/application9/exampleappwin.c
22
+ # * https://gitlab.gnome.org/GNOME/gtk/-/blob/main/examples/application9/exampleappprefs.c
23
+ # * https://gitlab.gnome.org/GNOME/gtk/-/blob/main/examples/application9/window.ui
24
+ # * https://gitlab.gnome.org/GNOME/gtk/-/blob/main/examples/application9/gears-menu.ui
25
+ # * https://gitlab.gnome.org/GNOME/gtk/-/blob/main/examples/application9/prefs.ui
26
+ # License: LGPL2.1-or-later
27
+
28
+ # GSETTINGS_SCHEMA_DIR must be set before requiring "gtk4" gem because it is used in the GIO initialization.
29
+
30
+ if File.exist?(File.join(__dir__, "gschemas.compiled"))
31
+ ENV["GSETTINGS_SCHEMA_DIR"] = __dir__
32
+ else
33
+ raise %{gschemas.compiled doesn't exist. Run "rake" to generate it.}
34
+ end
35
+
36
+ require "gtk4"
37
+
38
+ class ExampleAppPrefs < Gtk::Dialog
39
+ type_register
40
+ class << self
41
+ def init
42
+ template = <<~TEMPLATE
43
+ <?xml version="1.0" encoding="UTF-8"?>
44
+ <interface>
45
+ <template class="ExampleAppPrefs" parent="GtkDialog">
46
+ <property name="title" translatable="yes">Preferences</property>
47
+ <property name="resizable">0</property>
48
+ <property name="modal">1</property>
49
+ <child internal-child="content_area">
50
+ <object class="GtkBox" id="content_area">
51
+ <child>
52
+ <object class="GtkGrid" id="grid">
53
+ <property name="margin-start">12</property>
54
+ <property name="margin-end">12</property>
55
+ <property name="margin-top">12</property>
56
+ <property name="margin-bottom">12</property>
57
+ <property name="row-spacing">12</property>
58
+ <property name="column-spacing">12</property>
59
+ <child>
60
+ <object class="GtkLabel" id="fontlabel">
61
+ <property name="label">_Font:</property>
62
+ <property name="use-underline">1</property>
63
+ <property name="mnemonic-widget">font</property>
64
+ <property name="xalign">1</property>
65
+ <layout>
66
+ <property name="column">0</property>
67
+ <property name="row">0</property>
68
+ </layout>
69
+ </object>
70
+ </child>
71
+ <child>
72
+ <object class="GtkFontButton" id="font">
73
+ <layout>
74
+ <property name="column">1</property>
75
+ <property name="row">0</property>
76
+ </layout>
77
+ </object>
78
+ </child>
79
+ <child>
80
+ <object class="GtkLabel" id="transitionlabel">
81
+ <property name="label">_Transition:</property>
82
+ <property name="use-underline">1</property>
83
+ <property name="mnemonic-widget">transition</property>
84
+ <property name="xalign">1</property>
85
+ <layout>
86
+ <property name="column">0</property>
87
+ <property name="row">1</property>
88
+ </layout>
89
+ </object>
90
+ </child>
91
+ <child>
92
+ <object class="GtkComboBoxText" id="transition">
93
+ <items>
94
+ <item translatable="yes" id="none">None</item>
95
+ <item translatable="yes" id="crossfade">Fade</item>
96
+ <item translatable="yes" id="slide-left-right">Slide</item>
97
+ </items>
98
+ <layout>
99
+ <property name="column">1</property>
100
+ <property name="row">1</property>
101
+ </layout>
102
+ </object>
103
+ </child>
104
+ </object>
105
+ </child>
106
+ </object>
107
+ </child>
108
+ </template>
109
+ </interface>
110
+ TEMPLATE
111
+ set_template(data: template)
112
+ bind_template_child("font")
113
+ bind_template_child("transition")
114
+ end
115
+ end
116
+
117
+ def initialize(win)
118
+ # The original C program sets use-header-bar property to TRUE instead of 1.
119
+ # But the property type is int, not gboolean.
120
+ # Therefore, the property value must be 1, not `true` here.
121
+ super('transient-for': win, 'use-header-bar': 1)
122
+ settings = Gio::Settings.new("org.gtk.exampleapp")
123
+ settings.bind("font", font, "font", :default)
124
+ settings.bind("transition", transition, "active-id", :default)
125
+ end
126
+ end
127
+
128
+ class ExampleAppWindow < Gtk::ApplicationWindow
129
+ type_register
130
+ class << self
131
+ def init
132
+ template = <<~TEMPLATE
133
+ <?xml version="1.0" encoding="UTF-8"?>
134
+ <interface>
135
+ <template class="ExampleAppWindow" parent="GtkApplicationWindow">
136
+ <property name="title" translatable="yes">Example Application</property>
137
+ <property name="default-width">600</property>
138
+ <property name="default-height">400</property>
139
+ <child type="titlebar">
140
+ <object class="GtkHeaderBar" id="header">
141
+ <child>
142
+ <object class="GtkLabel" id="lines_label">
143
+ <property name="visible">0</property>
144
+ <property name="label" translatable="yes">Lines:</property>
145
+ </object>
146
+ </child>
147
+ <child>
148
+ <object class="GtkLabel" id="lines">
149
+ <property name="visible">0</property>
150
+ </object>
151
+ </child>
152
+ <child type="title">
153
+ <object class="GtkStackSwitcher" id="tabs">
154
+ <property name="stack">stack</property>
155
+ </object>
156
+ </child>
157
+ <child type="end">
158
+ <object class="GtkToggleButton" id="search">
159
+ <property name="sensitive">0</property>
160
+ <property name="icon-name">edit-find-symbolic</property>
161
+ </object>
162
+ </child>
163
+ <child type="end">
164
+ <object class="GtkMenuButton" id="gears">
165
+ <property name="direction">none</property>
166
+ </object>
167
+ </child>
168
+ </object>
169
+ </child>
170
+ <child>
171
+ <object class="GtkBox" id="content_box">
172
+ <property name="orientation">vertical</property>
173
+ <child>
174
+ <object class="GtkSearchBar" id="searchbar">
175
+ <child>
176
+ <object class="GtkSearchEntry" id="searchentry">
177
+ <signal name="search-changed" handler="search_text_changed"/>
178
+ </object>
179
+ </child>
180
+ </object>
181
+ </child>
182
+ <child>
183
+ <object class="GtkBox" id="hbox">
184
+ <child>
185
+ <object class="GtkRevealer" id="sidebar">
186
+ <property name="transition-type">slide-right</property>
187
+ <child>
188
+ <object class="GtkScrolledWindow" id="sidebar-sw">
189
+ <property name="hscrollbar-policy">never</property>
190
+ <child>
191
+ <object class="GtkListBox" id="words">
192
+ <property name="selection-mode">none</property>
193
+ </object>
194
+ </child>
195
+ </object>
196
+ </child>
197
+ </object>
198
+ </child>
199
+ <child>
200
+ <object class="GtkStack" id="stack">
201
+ <signal name="notify::visible-child" handler="visible_child_changed"/>
202
+ </object>
203
+ </child>
204
+ </object>
205
+ </child>
206
+ </object>
207
+ </child>
208
+ </template>
209
+ </interface>
210
+ TEMPLATE
211
+ set_template(data: template)
212
+ bind_template_child("stack")
213
+ bind_template_child("gears")
214
+ bind_template_child("search")
215
+ bind_template_child("searchbar")
216
+ bind_template_child("searchentry")
217
+ bind_template_child("words")
218
+ bind_template_child("sidebar")
219
+ bind_template_child("lines")
220
+ bind_template_child("lines_label")
221
+ bind_template_callback_full("search_text_changed")
222
+ bind_template_callback_full("visible_child_changed")
223
+ end
224
+ end
225
+
226
+ def initialize(application)
227
+ menu_ui = <<~MENU
228
+ <?xml version="1.0" encoding="UTF-8"?>
229
+ <interface>
230
+ <menu id="menu">
231
+ <section>
232
+ <item>
233
+ <attribute name="label" translatable="yes">_Words</attribute>
234
+ <attribute name="action">win.show-words</attribute>
235
+ </item>
236
+ <item>
237
+ <attribute name="label" translatable="yes">_Lines</attribute>
238
+ <attribute name="action">win.show-lines</attribute>
239
+ </item>
240
+ <item>
241
+ <attribute name="label" translatable="yes">_Preferences</attribute>
242
+ <attribute name="action">app.preferences</attribute>
243
+ </item>
244
+ </section>
245
+ <section>
246
+ <item>
247
+ <attribute name="label" translatable="yes">_Quit</attribute>
248
+ <attribute name="action">app.quit</attribute>
249
+ </item>
250
+ </section>
251
+ </menu>
252
+ </interface>
253
+ MENU
254
+ super(application: application)
255
+ builder = Gtk::Builder.new(string: menu_ui)
256
+ gears.menu_model = builder["menu"]
257
+ @settings = Gio::Settings.new("org.gtk.exampleapp")
258
+ @settings.bind("transition", stack, "transition-type", :default)
259
+ @settings.bind("show-words", sidebar, "reveal-child", :default)
260
+ search.bind_property("active", searchbar, "search-mode-enabled", :bidirectional)
261
+ sidebar.signal_connect "notify::reveal-child" do |_sidebar, _pspec|
262
+ update_words
263
+ end
264
+ action = @settings.create_action("show-words")
265
+ add_action(action)
266
+ action = Gio::PropertyAction.new("show-lines", lines, "visible")
267
+ add_action(action)
268
+ lines.bind_property("visible", lines_label, "visible", :default)
269
+ end
270
+
271
+ def open(file)
272
+ basename = file.basename
273
+ scrolled = Gtk::ScrolledWindow.new
274
+ scrolled.hexpand = true
275
+ scrolled.vexpand = true
276
+ view = Gtk::TextView.new
277
+ view.editable = false
278
+ view.cursor_visible = false
279
+ scrolled.child = view
280
+ stack.add_titled(scrolled, basename, basename)
281
+ buffer = view.buffer
282
+ file.read do |stream|
283
+ buffer.text = stream.read.force_encoding(Encoding::UTF_8)
284
+ end
285
+ tag = buffer.create_tag
286
+ @settings.bind("font", tag, "font", :default)
287
+ buffer.apply_tag(tag, buffer.start_iter, buffer.end_iter)
288
+ search.sensitive = true
289
+ update_words
290
+ update_lines
291
+ end
292
+
293
+ private
294
+
295
+ def search_text_changed(search_entry)
296
+ text = search_entry.text
297
+ return if text.empty?
298
+ tab = stack.visible_child
299
+ view = tab.child
300
+ buffer = view.buffer
301
+ range = buffer.start_iter.forward_search(text, :case_insensitive)
302
+ return unless range
303
+ buffer.select_range(range[0], range[1])
304
+ view.scroll_to_iter(range[0], 0.0, false, 0.0, 0.0)
305
+ end
306
+
307
+ def update_words
308
+ tab = stack.visible_child
309
+ return unless tab
310
+ view = tab.child
311
+ buffer = view.buffer
312
+ strings = buffer.text.downcase.scan(/[[:word:]]+/).uniq
313
+ while (child = words.first_child)
314
+ words.remove(child)
315
+ end
316
+ strings.each do |s|
317
+ row = Gtk::Button.new(label: s)
318
+ row.signal_connect("clicked") {searchentry.text = s}
319
+ words.insert(row, -1)
320
+ end
321
+ end
322
+
323
+ def update_lines
324
+ tab = stack.visible_child
325
+ return unless tab
326
+ view = tab.child
327
+ buffer = view.buffer
328
+ lines.text = buffer.line_count.to_s
329
+ end
330
+
331
+ def visible_child_changed(stack, params)
332
+ return if stack.in_destruction?
333
+ searchbar.search_mode = false
334
+ update_words
335
+ update_lines
336
+ end
337
+ end
338
+
339
+ class ExampleApp < Gtk::Application
340
+ def initialize
341
+ super("org.gtk.exampleapp", :handles_open)
342
+
343
+ signal_connect "startup" do |application|
344
+ [
345
+ "preferences",
346
+ "quit"
347
+ ].each do |action_name|
348
+ action = Gio::SimpleAction.new(action_name)
349
+ action.signal_connect("activate") do |_action, _parameter|
350
+ __send__("#{action_name}_activated")
351
+ end
352
+ application.add_action(action)
353
+ end
354
+ application.set_accels_for_action("app.quit", ["<Control>Q"])
355
+ end
356
+ signal_connect "activate" do |application|
357
+ window = ExampleAppWindow.new(application)
358
+ window.present
359
+ end
360
+ signal_connect "open" do |application, files, hint|
361
+ window = application.windows[0] || ExampleAppWindow.new(application)
362
+ files.each do |file|
363
+ window.open(file)
364
+ end
365
+ window.present
366
+ end
367
+ end
368
+
369
+ private
370
+
371
+ def preferences_activated
372
+ prefs = ExampleAppPrefs.new(active_window)
373
+ prefs.present
374
+ end
375
+
376
+ def quit_activated
377
+ quit
378
+ end
379
+ end
380
+
381
+ app = ExampleApp.new
382
+
383
+ # Gtk::Application#run needs C style argv ([prog, arg1, arg2, ...,argn]).
384
+ # The ARGV ruby variable only contains the arguments ([arg1, arg2, ...,argb])
385
+ # and not the program name. We have to add it explicitly.
386
+
387
+ app.run([$PROGRAM_NAME] + ARGV)
@@ -0,0 +1,25 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <schemalist>
3
+ <schema path="/org/gtk/exampleapp/" id="org.gtk.exampleapp">
4
+ <key name="font" type="s">
5
+ <default>'Monospace 12'</default>
6
+ <summary>Font</summary>
7
+ <description>The font to be used for content.</description>
8
+ </key>
9
+ <key name="transition" type="s">
10
+ <choices>
11
+ <choice value='none'/>
12
+ <choice value='crossfade'/>
13
+ <choice value='slide-left-right'/>
14
+ </choices>
15
+ <default>'none'</default>
16
+ <summary>Transition</summary>
17
+ <description>The transition to use when switching tabs.</description>
18
+ </key>
19
+ <key name="show-words" type="b">
20
+ <default>false</default>
21
+ <summary>Show words</summary>
22
+ <description>Whether to show a word list in the sidebar</description>
23
+ </key>
24
+ </schema>
25
+ </schemalist>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gtk4
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.2
4
+ version: 4.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Ruby-GNOME Project Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-24 00:00:00.000000000 Z
11
+ date: 2023-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: atk
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 4.1.2
19
+ version: 4.1.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 4.1.2
26
+ version: 4.1.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: gdk4
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 4.1.2
33
+ version: 4.1.3
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 4.1.2
40
+ version: 4.1.3
41
41
  description: Ruby/GTK4 is a Ruby binding of GTK+-4.x.
42
42
  email: ruby-gnome2-devel-en@lists.sourceforge.net
43
43
  executables: []
@@ -121,6 +121,32 @@ files:
121
121
  - sample/examples/application1/exampleapp.png
122
122
  - sample/examples/application1/exampleapp.rb
123
123
  - sample/examples/application1/org.gtk.exampleapp.desktop
124
+ - sample/examples/application2/README.md
125
+ - sample/examples/application2/exampleapp.rb
126
+ - sample/examples/application3/README.md
127
+ - sample/examples/application3/exampleapp.rb
128
+ - sample/examples/application4/README.md
129
+ - sample/examples/application4/exampleapp.rb
130
+ - sample/examples/application5/README.md
131
+ - sample/examples/application5/Rakefile
132
+ - sample/examples/application5/exampleapp.rb
133
+ - sample/examples/application5/org.gtk.exampleapp.gschema.xml
134
+ - sample/examples/application6/README.md
135
+ - sample/examples/application6/Rakefile
136
+ - sample/examples/application6/exampleapp.rb
137
+ - sample/examples/application6/org.gtk.exampleapp.gschema.xml
138
+ - sample/examples/application7/README.md
139
+ - sample/examples/application7/Rakefile
140
+ - sample/examples/application7/exampleapp.rb
141
+ - sample/examples/application7/org.gtk.exampleapp.gschema.xml
142
+ - sample/examples/application8/README.md
143
+ - sample/examples/application8/Rakefile
144
+ - sample/examples/application8/exampleapp.rb
145
+ - sample/examples/application8/org.gtk.exampleapp.gschema.xml
146
+ - sample/examples/application9/README.md
147
+ - sample/examples/application9/Rakefile
148
+ - sample/examples/application9/exampleapp.rb
149
+ - sample/examples/application9/org.gtk.exampleapp.gschema.xml
124
150
  - sample/examples/builder.rb
125
151
  - sample/examples/builder.ui
126
152
  - sample/examples/drawing.rb