gir_ffi-gtk 0.13.1 → 0.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +26 -1
- data/lib/gir_ffi-gtk/base.rb +3 -3
- data/lib/gir_ffi-gtk/dialog.rb +31 -0
- data/lib/gir_ffi-gtk/file_chooser_dialog.rb +35 -0
- data/lib/gir_ffi-gtk/gtk2/menu.rb +26 -0
- data/lib/gir_ffi-gtk/message_dialog.rb +1 -1
- data/lib/gir_ffi-gtk/tree_path.rb +1 -1
- data/lib/gir_ffi-gtk/version.rb +5 -0
- data/lib/gir_ffi-gtk/widget.rb +25 -0
- data/lib/gir_ffi-gtk2.rb +22 -18
- data/lib/gir_ffi-gtk3.rb +18 -15
- metadata +98 -69
- data/Rakefile +0 -8
- data/examples/01_empty_window.rb +0 -12
- data/examples/02_hello_world.rb +0 -27
- data/examples/03_upgraded_hello_world.rb +0 -40
- data/examples/04_webkit.rb +0 -18
- data/examples/05_notification.rb +0 -33
- data/examples/06_treeview.rb +0 -51
- data/examples/07_simple_gtk_application.rb +0 -30
- data/examples/08_webkit_headless.rb +0 -21
- data/examples/09_webkit2_headless.rb +0 -24
- data/examples/10_completion_provider.rb +0 -62
- data/lib/gir_ffi-gtk/menu.rb +0 -19
- data/tasks/test.rake +0 -30
- data/test/callback_exceptions_test.rb +0 -58
- data/test/gir_ffi-gtk/action_test.rb +0 -17
- data/test/gir_ffi-gtk/base_test.rb +0 -47
- data/test/gir_ffi-gtk/builder_test.rb +0 -70
- data/test/gir_ffi-gtk/button_test.rb +0 -19
- data/test/gir_ffi-gtk/container_test.rb +0 -33
- data/test/gir_ffi-gtk/generated_gtk_test.rb +0 -58
- data/test/gir_ffi-gtk/image_test.rb +0 -43
- data/test/gir_ffi-gtk/list_store_test.rb +0 -38
- data/test/gir_ffi-gtk/menu_test.rb +0 -20
- data/test/gir_ffi-gtk/message_dialog_test.rb +0 -15
- data/test/gir_ffi-gtk/radio_action_test.rb +0 -28
- data/test/gir_ffi-gtk/radio_button_test.rb +0 -37
- data/test/gir_ffi-gtk/target_entry_test.rb +0 -19
- data/test/gir_ffi-gtk/tree_path_test.rb +0 -17
- data/test/gir_ffi-gtk/tree_store_test.rb +0 -38
- data/test/gir_ffi-gtk/tree_view_column_test.rb +0 -51
- data/test/test_helper.rb +0 -36
data/examples/04_webkit.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#
|
3
|
-
# Based on https://web.archive.org/web/20110228141616/http://www.idle-hacking.com/2010/02/webkit-ruby-and-gtk/
|
4
|
-
#
|
5
|
-
|
6
|
-
require 'gir_ffi-gtk3'
|
7
|
-
|
8
|
-
GirFFI.setup :WebKit2, '4.0'
|
9
|
-
|
10
|
-
Gtk.init
|
11
|
-
|
12
|
-
win = Gtk::Window.new :toplevel
|
13
|
-
wv = WebKit2::WebView.new
|
14
|
-
win.add(wv)
|
15
|
-
win.show_all
|
16
|
-
wv.load_uri('http://www.google.com/')
|
17
|
-
win.signal_connect('destroy') { Gtk.main_quit }
|
18
|
-
Gtk.main
|
data/examples/05_notification.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#
|
3
|
-
# Simple notification example.
|
4
|
-
require 'gir_ffi-gtk3'
|
5
|
-
|
6
|
-
GirFFI.setup :Notify
|
7
|
-
|
8
|
-
# Both Gtk and Notify need to be init'ed.
|
9
|
-
Gtk.init
|
10
|
-
Notify.init "notification test"
|
11
|
-
|
12
|
-
# Basic set up of the notification.
|
13
|
-
nf = Notify::Notification.new "Hello!", "Hi there.", "gtk-dialog-info"
|
14
|
-
nf.timeout = 3000
|
15
|
-
nf.urgency = :critical
|
16
|
-
|
17
|
-
# Show a button 'Test' in the notification, with a callback function.
|
18
|
-
nf.add_action("test", "Test") { |obj, action, user_data|
|
19
|
-
puts "Action #{action} clicked."
|
20
|
-
}
|
21
|
-
|
22
|
-
# In this case, we want the program to end once the notification is gone,
|
23
|
-
# but not before.
|
24
|
-
nf.signal_connect("closed") {
|
25
|
-
puts "Notification closed."
|
26
|
-
Gtk.main_quit
|
27
|
-
}
|
28
|
-
|
29
|
-
# Show the notification.
|
30
|
-
nf.show
|
31
|
-
|
32
|
-
# Start a main loop to wait for the notification to be closed.
|
33
|
-
Gtk.main
|
data/examples/06_treeview.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#
|
3
|
-
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
4
|
-
require 'gir_ffi-gtk3'
|
5
|
-
|
6
|
-
Gtk.init
|
7
|
-
|
8
|
-
|
9
|
-
#Add window.
|
10
|
-
win = Gtk::Window.new(:toplevel)
|
11
|
-
win.resize(640, 480)
|
12
|
-
win.signal_connect("destroy") { Gtk.main_quit }
|
13
|
-
|
14
|
-
|
15
|
-
#Add treeview.
|
16
|
-
tv = Gtk::TreeView.new
|
17
|
-
|
18
|
-
|
19
|
-
#Add store.
|
20
|
-
ls = Gtk::ListStore.new([GObject::TYPE_STRING])
|
21
|
-
tv.set_model(ls)
|
22
|
-
|
23
|
-
|
24
|
-
#Add column.
|
25
|
-
lab = Gtk::Label.new("Name")
|
26
|
-
rend = Gtk::CellRendererText.new
|
27
|
-
|
28
|
-
col = Gtk::TreeViewColumn.new
|
29
|
-
col.set_widget(lab)
|
30
|
-
col.pack_start(rend, true)
|
31
|
-
col.add_attribute(rend, "text", 0)
|
32
|
-
|
33
|
-
lab.show
|
34
|
-
|
35
|
-
tv.append_column(col)
|
36
|
-
|
37
|
-
|
38
|
-
#Add rows.
|
39
|
-
iter = ls.append
|
40
|
-
ls.set_value(iter, 0, "Kasper")
|
41
|
-
|
42
|
-
iter = ls.append
|
43
|
-
ls.set_value(iter, 0, "Christina")
|
44
|
-
|
45
|
-
|
46
|
-
win.add tv
|
47
|
-
tv.show
|
48
|
-
|
49
|
-
win.show
|
50
|
-
|
51
|
-
Gtk.main
|
@@ -1,30 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'gir_ffi-gtk3'
|
4
|
-
|
5
|
-
myapp = Gtk::Application.new('org.gtk.example', :handles_command_line)
|
6
|
-
|
7
|
-
myapp.signal_connect 'command-line' do |app, _command_line|
|
8
|
-
app.activate
|
9
|
-
0
|
10
|
-
end
|
11
|
-
|
12
|
-
myapp.signal_connect 'activate' do |app|
|
13
|
-
win = Gtk::ApplicationWindow.new(app)
|
14
|
-
win.set_title('Gtk Application example')
|
15
|
-
win.set_default_size(200, 200)
|
16
|
-
|
17
|
-
button_box = Gtk::ButtonBox.new(:horizontal)
|
18
|
-
win.add(button_box)
|
19
|
-
|
20
|
-
button = Gtk::Button.new_with_label('Hello world')
|
21
|
-
button.signal_connect 'clicked' do
|
22
|
-
puts 'Hello World'
|
23
|
-
app.quit
|
24
|
-
end
|
25
|
-
|
26
|
-
button_box.add(button)
|
27
|
-
win.show_all
|
28
|
-
end
|
29
|
-
|
30
|
-
exit(myapp.run([$PROGRAM_NAME] + ARGV))
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'gir_ffi-gtk3'
|
2
|
-
|
3
|
-
GirFFI.setup :WebKit, '3.0'
|
4
|
-
|
5
|
-
Gtk.init
|
6
|
-
|
7
|
-
win = Gtk::OffscreenWindow.new
|
8
|
-
web_view = WebKit::WebView.new
|
9
|
-
win.add(web_view)
|
10
|
-
|
11
|
-
web_view.signal_connect "load-finished" do
|
12
|
-
pixbuf = win.get_pixbuf
|
13
|
-
pixbuf.savev("google.png", "png", nil, nil)
|
14
|
-
puts web_view.get_title
|
15
|
-
Gtk.main_quit
|
16
|
-
end
|
17
|
-
|
18
|
-
web_view.load_uri('http://www.google.com/')
|
19
|
-
win.show_all
|
20
|
-
|
21
|
-
Gtk.main
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'gir_ffi-gtk3'
|
2
|
-
|
3
|
-
GirFFI.setup :WebKit2, '4.0'
|
4
|
-
|
5
|
-
Gtk.init
|
6
|
-
|
7
|
-
win = Gtk::OffscreenWindow.new
|
8
|
-
web_view = WebKit2::WebView.new
|
9
|
-
win.add(web_view)
|
10
|
-
|
11
|
-
web_view.signal_connect "load-changed" do |_, event, _|
|
12
|
-
case event
|
13
|
-
when :finished
|
14
|
-
pixbuf = win.get_pixbuf
|
15
|
-
pixbuf.savev("google.png", "png", nil, nil)
|
16
|
-
puts web_view.get_title
|
17
|
-
Gtk.main_quit
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
web_view.load_uri('http://www.google.com/')
|
22
|
-
win.show_all
|
23
|
-
|
24
|
-
Gtk.main
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'gir_ffi-gtk3'
|
2
|
-
|
3
|
-
# This is an example of creating a derived class with vfunc implementations.
|
4
|
-
|
5
|
-
GirFFI.setup :GtkSource
|
6
|
-
|
7
|
-
Gtk.init
|
8
|
-
|
9
|
-
class TestProvider < GObject::Object
|
10
|
-
include GtkSource::CompletionProvider
|
11
|
-
|
12
|
-
def get_name
|
13
|
-
'Test Provider'
|
14
|
-
end
|
15
|
-
|
16
|
-
def get_priority
|
17
|
-
1
|
18
|
-
end
|
19
|
-
|
20
|
-
def match(_context)
|
21
|
-
true
|
22
|
-
end
|
23
|
-
|
24
|
-
def populate(context)
|
25
|
-
icon = Gtk::IconTheme.get_default.load_icon(Gtk::STOCK_DIALOG_INFO, 16, 0)
|
26
|
-
|
27
|
-
proposals = [
|
28
|
-
GtkSource::CompletionItem.new("Proposal 1", "Proposal 1", icon, "blah 1"),
|
29
|
-
GtkSource::CompletionItem.new("Proposal 2", "Proposal 2", icon, "blah 2"),
|
30
|
-
GtkSource::CompletionItem.new("Proposal 3", "Proposal 3", icon, "blah 3"),
|
31
|
-
]
|
32
|
-
context.add_proposals(self, proposals, true)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
GirFFI.define_type TestProvider do |info|
|
37
|
-
info.install_vfunc_implementation :get_name
|
38
|
-
info.install_vfunc_implementation :get_priority
|
39
|
-
info.install_vfunc_implementation :match
|
40
|
-
info.install_vfunc_implementation :populate
|
41
|
-
end
|
42
|
-
|
43
|
-
win = Gtk::Window.new :toplevel
|
44
|
-
win.show
|
45
|
-
GObject.signal_connect(win, "destroy") { Gtk.main_quit }
|
46
|
-
|
47
|
-
vbox = Gtk::VBox.new(false, 0)
|
48
|
-
win.add vbox
|
49
|
-
|
50
|
-
lm = GtkSource::LanguageManager.get_default
|
51
|
-
lang = lm.get_language "ruby"
|
52
|
-
buffer = GtkSource::Buffer.new_with_language lang
|
53
|
-
@source = GtkSource::View.new_with_buffer buffer
|
54
|
-
|
55
|
-
test_provider = TestProvider.new
|
56
|
-
completion = @source.get_completion
|
57
|
-
completion.add_provider test_provider
|
58
|
-
|
59
|
-
vbox.pack_start @source, true, true, 0
|
60
|
-
|
61
|
-
win.show_all
|
62
|
-
Gtk.main
|
data/lib/gir_ffi-gtk/menu.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
Gtk.load_class :Menu
|
4
|
-
module Gtk
|
5
|
-
# Overrides for GtkMenu
|
6
|
-
class Menu
|
7
|
-
unless method_defined? :popup
|
8
|
-
# Smells of :reek:LongParameterList: due to the defined GtkMenu interface.
|
9
|
-
# rubocop:disable Metrics/ParameterLists
|
10
|
-
def popup(parent_menu_shell, parent_menu_item, func, data, button, activate_time)
|
11
|
-
popup_for_device(nil,
|
12
|
-
parent_menu_shell, parent_menu_item, func, data,
|
13
|
-
nil,
|
14
|
-
button, activate_time)
|
15
|
-
end
|
16
|
-
# rubocop:enable Metrics/ParameterLists
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/tasks/test.rake
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rake/testtask'
|
4
|
-
|
5
|
-
namespace :test do
|
6
|
-
Rake::TestTask.new(:gtk3) do |t|
|
7
|
-
t.libs = ['lib']
|
8
|
-
t.test_files = FileList['test/**/*_test.rb']
|
9
|
-
t.ruby_opts += ['-w', '-Itest']
|
10
|
-
end
|
11
|
-
|
12
|
-
Rake::TestTask.new(:gtk2) do |t|
|
13
|
-
t.libs = ['lib']
|
14
|
-
t.test_files = FileList['test/**/*_test.rb']
|
15
|
-
t.ruby_opts += ['-w', '-Itest']
|
16
|
-
end
|
17
|
-
|
18
|
-
task gtk2: :set_gtk_version_2
|
19
|
-
|
20
|
-
task :set_gtk_version_2 do
|
21
|
-
ENV['GTK_VERSION'] = '2'
|
22
|
-
end
|
23
|
-
|
24
|
-
task :sleep do
|
25
|
-
sleep 1
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
desc 'Run unit tests'
|
30
|
-
task test: ['test:gtk3', 'test:sleep', 'test:gtk2']
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class CallbackTestException < RuntimeError; end
|
4
|
-
|
5
|
-
describe 'An exception in a callback' do
|
6
|
-
describe 'for signals' do
|
7
|
-
let(:object) { Gtk::Window.new :toplevel }
|
8
|
-
|
9
|
-
before do
|
10
|
-
object.signal_connect 'destroy' do
|
11
|
-
raise CallbackTestException, 'Boom'
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'when the signal is emitted synchronously' do
|
16
|
-
it 'raises an error' do
|
17
|
-
-> { GObject.signal_emit object, 'destroy' }.must_raise CallbackTestException
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe 'when the signal is emitted during an event loop' do
|
22
|
-
it 'causes loop run to be terminated with an exception' do
|
23
|
-
GLib.timeout_add GLib::PRIORITY_DEFAULT, 1 do
|
24
|
-
GObject.signal_emit object, 'destroy'
|
25
|
-
false
|
26
|
-
end
|
27
|
-
# Guard against runaway loop
|
28
|
-
@guard = GLib.timeout_add(GLib::PRIORITY_DEFAULT, 1000) { Gtk.main_quit }
|
29
|
-
proc do
|
30
|
-
Gtk.main
|
31
|
-
end.must_raise CallbackTestException
|
32
|
-
end
|
33
|
-
|
34
|
-
after do
|
35
|
-
GLib.source_remove @guard
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe 'for other callbacks' do
|
41
|
-
describe 'when the callback occurs during an event loop' do
|
42
|
-
it 'causes loop run to be terminated with an exception' do
|
43
|
-
GLib.timeout_add GLib::PRIORITY_DEFAULT, 1 do
|
44
|
-
raise CallbackTestException, 'Boom'
|
45
|
-
end
|
46
|
-
# Guard against runaway loop
|
47
|
-
@guard = GLib.timeout_add(GLib::PRIORITY_DEFAULT, 1000) { Gtk.main_quit }
|
48
|
-
proc do
|
49
|
-
Gtk.main
|
50
|
-
end.must_raise CallbackTestException
|
51
|
-
end
|
52
|
-
|
53
|
-
after do
|
54
|
-
GLib.source_remove @guard
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
describe Gtk::Action do
|
4
|
-
let(:action) { Gtk::Action.new('hi', 'Hello', 'hey there', Gtk::STOCK_FILE) }
|
5
|
-
|
6
|
-
describe '#create_icon' do
|
7
|
-
it 'works when called with a symbol' do
|
8
|
-
result = action.create_icon :dialog
|
9
|
-
result.must_be_instance_of Gtk::Image
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'works when called with an integer' do
|
13
|
-
result = action.create_icon 4
|
14
|
-
result.must_be_instance_of Gtk::Image
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
describe Gtk do
|
4
|
-
describe '::init' do
|
5
|
-
before do
|
6
|
-
module DummyGtk
|
7
|
-
def self.init(_arr)
|
8
|
-
%w(baz qux zonk)
|
9
|
-
end
|
10
|
-
|
11
|
-
include GirFFIGtk::AutoArgv
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'does not take any arguments' do
|
16
|
-
assert_raises(ArgumentError) { DummyGtk.init 1, ['foo'] }
|
17
|
-
assert_raises(ArgumentError) { DummyGtk.init ['foo'] }
|
18
|
-
assert_nothing_raised { DummyGtk.init }
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'replaces ARGV with the tail of the result of the original init function' do
|
22
|
-
ARGV.replace %w(foo bar)
|
23
|
-
DummyGtk.init
|
24
|
-
assert_equal %w(qux zonk), ARGV.to_a
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '::main' do
|
29
|
-
it 'allows other threads to run' do
|
30
|
-
a = []
|
31
|
-
GLib.timeout_add(GLib::PRIORITY_DEFAULT, 150) { Gtk.main_quit }
|
32
|
-
|
33
|
-
slow_thread = Thread.new do
|
34
|
-
sleep 0.005
|
35
|
-
a << 'During run'
|
36
|
-
end
|
37
|
-
|
38
|
-
a << 'Before run'
|
39
|
-
Gtk.main
|
40
|
-
a << 'After run'
|
41
|
-
|
42
|
-
slow_thread.join
|
43
|
-
|
44
|
-
a.last.must_equal 'After run'
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
describe Gtk::Builder do
|
4
|
-
let(:builder) { Gtk::Builder.new }
|
5
|
-
let(:spec) do
|
6
|
-
<<-XML
|
7
|
-
<interface>
|
8
|
-
<object class="GtkButton" id="foo">
|
9
|
-
<signal handler="on_button_clicked" name="clicked"/>
|
10
|
-
</object>
|
11
|
-
</interface>
|
12
|
-
XML
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '#add_from_string' do
|
16
|
-
it 'takes one string as argument' do
|
17
|
-
builder.add_from_string spec
|
18
|
-
pass
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '#connect_signals' do
|
23
|
-
before do
|
24
|
-
builder.add_from_string spec
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'passes the handler name to the block' do
|
28
|
-
name = nil
|
29
|
-
builder.connect_signals do |handler_name|
|
30
|
-
name = handler_name
|
31
|
-
nil
|
32
|
-
end
|
33
|
-
|
34
|
-
name.must_equal 'on_button_clicked'
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'connects the signal to the proc returned by the block' do
|
38
|
-
name = nil
|
39
|
-
builder.connect_signals do |handler_name|
|
40
|
-
proc { name = handler_name }
|
41
|
-
end
|
42
|
-
button = builder.get_object('foo')
|
43
|
-
GObject.signal_emit button, 'clicked'
|
44
|
-
name.must_equal 'on_button_clicked'
|
45
|
-
end
|
46
|
-
|
47
|
-
describe 'with a signal with after flag' do
|
48
|
-
let(:spec) do
|
49
|
-
<<-XML
|
50
|
-
<interface>
|
51
|
-
<object class="GtkButton" id="foo">
|
52
|
-
<signal handler="handler_after" name="clicked" after="true"/>
|
53
|
-
<signal handler="handler_before" name="clicked"/>
|
54
|
-
</object>
|
55
|
-
</interface>
|
56
|
-
XML
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'connects the handlers in the right order' do
|
60
|
-
name = nil
|
61
|
-
builder.connect_signals do |handler_name|
|
62
|
-
proc { name = handler_name }
|
63
|
-
end
|
64
|
-
button = builder.get_object('foo')
|
65
|
-
GObject.signal_emit button, 'clicked'
|
66
|
-
name.must_equal 'handler_after'
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
describe Gtk::Button do
|
4
|
-
describe '.new_from_icon_name' do
|
5
|
-
before do
|
6
|
-
skip if Gtk::MAJOR_VERSION == 2 || Gtk::MAJOR_VERSION == 3 && Gtk::MINOR_VERSION < 10
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'works when called with a symbol' do
|
10
|
-
result = Gtk::Button.new_from_icon_name('hi', :dialog)
|
11
|
-
result.must_be_instance_of Gtk::Button
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'works when called with an integer' do
|
15
|
-
result = Gtk::Button.new_from_icon_name('hi', 4)
|
16
|
-
result.must_be_instance_of Gtk::Button
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
describe Gtk::Container do
|
4
|
-
let(:container) { Gtk::Table.new 1, 1, true }
|
5
|
-
let(:widget) { Gtk::Label.new 'foo' }
|
6
|
-
|
7
|
-
describe '#add_with_properties' do
|
8
|
-
before do
|
9
|
-
container.add_with_properties widget, 'left-attach': 1
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'adds the widget to the container' do
|
13
|
-
container.get_children.to_a.must_equal [widget]
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'sets the child properties for the widget' do
|
17
|
-
container.child_get_property(widget, 'left-attach').must_equal 1
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe '#child_get_property' do
|
22
|
-
it 'fetches the given child property' do
|
23
|
-
container.add widget
|
24
|
-
container.child_set_property(widget, 'left-attach', 1)
|
25
|
-
container.child_get_property(widget, 'left-attach').must_equal 1
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'raises an ArgumentError for unknown properties' do
|
29
|
-
container.add widget
|
30
|
-
proc { container.child_get_property(widget, 'foobar') }.must_raise ArgumentError
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
# Tests generated methods and functions in the Gtk namespace.
|
4
|
-
describe 'In the generated Gtk module' do
|
5
|
-
describe 'a Gtk::Builder instance' do
|
6
|
-
before do
|
7
|
-
@builder = Gtk::Builder.new
|
8
|
-
@spec = '
|
9
|
-
<interface>
|
10
|
-
<object class="GtkButton" id="foo">
|
11
|
-
<signal handler="on_button_clicked" name="clicked"/>
|
12
|
-
</object>
|
13
|
-
</interface>
|
14
|
-
'
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'loads the interface spec' do
|
18
|
-
assert_nothing_raised { @builder.add_from_string @spec }
|
19
|
-
end
|
20
|
-
|
21
|
-
describe 'its #get_object method' do
|
22
|
-
it 'returns objects of the proper class' do
|
23
|
-
@builder.add_from_string @spec
|
24
|
-
o = @builder.get_object 'foo'
|
25
|
-
assert_instance_of Gtk::Button, o
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe 'its #connect_signals_full method' do
|
30
|
-
before do
|
31
|
-
@builder.add_from_string @spec
|
32
|
-
end
|
33
|
-
it 'passes arguments correctly' do
|
34
|
-
aa = nil
|
35
|
-
@builder.connect_signals_full { |*args| aa = args }
|
36
|
-
b, o, sn, hn, co, f, ud = aa
|
37
|
-
assert_instance_of Gtk::Builder, b
|
38
|
-
assert_equal b.to_ptr, @builder.to_ptr
|
39
|
-
assert_instance_of Gtk::Button, o
|
40
|
-
assert_equal 'clicked', sn
|
41
|
-
assert_equal 'on_button_clicked', hn
|
42
|
-
co.must_be_nil
|
43
|
-
assert_equal 0, f
|
44
|
-
ud.wont_be_nil
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe 'a Gtk::Window instance' do
|
50
|
-
before do
|
51
|
-
@w = Gtk::Window.new :toplevel
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'starts with a refcount of 2 (one for us, one for GTK+)' do
|
55
|
-
assert_equal 2, ref_count(@w)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
describe Gtk::Image do
|
4
|
-
describe '.new_from_icon_name' do
|
5
|
-
it 'works when called with a symbol' do
|
6
|
-
result = Gtk::Image.new_from_icon_name('hi', :dialog)
|
7
|
-
result.must_be_instance_of Gtk::Image
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'works when called with an integer' do
|
11
|
-
result = Gtk::Image.new_from_icon_name('hi', 4)
|
12
|
-
result.must_be_instance_of Gtk::Image
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe '.new_from_gicon' do
|
17
|
-
let(:gicon) { Gio::ThemedIcon.new('hi') }
|
18
|
-
it 'works when called with a symbol' do
|
19
|
-
result = Gtk::Image.new_from_gicon(gicon, :dialog)
|
20
|
-
result.must_be_instance_of Gtk::Image
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'works when called with an integer' do
|
24
|
-
result = Gtk::Image.new_from_gicon(gicon, 4)
|
25
|
-
result.must_be_instance_of Gtk::Image
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe '#set_from_gicon' do
|
30
|
-
let(:gicon) { Gio::ThemedIcon.new('gnome') }
|
31
|
-
let(:image) { Gtk::Image.new }
|
32
|
-
|
33
|
-
it 'works when called with a symbol' do
|
34
|
-
image.set_from_gicon(gicon, :dialog)
|
35
|
-
image.get_gicon.must_equal [gicon, 6]
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'works when called with an integer' do
|
39
|
-
image.set_from_gicon(gicon, 4)
|
40
|
-
image.get_gicon.must_equal [gicon, 4]
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
describe Gtk::ListStore do
|
4
|
-
describe '.new' do
|
5
|
-
it 'takes an array of column types' do
|
6
|
-
store = Gtk::ListStore.new([GObject::TYPE_STRING, GObject::TYPE_INT])
|
7
|
-
store.must_be_instance_of Gtk::ListStore
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe '#insert_with_values' do
|
12
|
-
it 'inserts a row with the given values' do
|
13
|
-
store = Gtk::ListStore.new([GObject::TYPE_STRING, GObject::TYPE_INT])
|
14
|
-
row = store.insert_with_values(0, [0, 1], ['foo', 42])
|
15
|
-
store.get_value(row, 0).must_equal 'foo'
|
16
|
-
store.get_value(row, 1).must_equal 42
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '#set' do
|
21
|
-
it 'updates a row with the given values' do
|
22
|
-
store = Gtk::ListStore.new([GObject::TYPE_STRING, GObject::TYPE_INT])
|
23
|
-
row = store.insert_with_values(0, [0, 1], ['foo', 42])
|
24
|
-
store.set(row, [1, 0], [3, 'bar'])
|
25
|
-
store.get_value(row, 0).must_equal 'bar'
|
26
|
-
store.get_value(row, 1).must_equal 3
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe '#set_value' do
|
31
|
-
it 'allows setting a value to nil' do
|
32
|
-
store = Gtk::ListStore.new([GObject::TYPE_STRING, GObject::TYPE_INT])
|
33
|
-
row = store.insert_with_values(0, [0, 1], ['foo', 42])
|
34
|
-
store.set_value(row, 0, nil)
|
35
|
-
store.get_value(row, 0).must_be_nil
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|