gir_ffi-gtk 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9db12a11ec0be6f650fa77d62a76e2f987b2e99a
4
- data.tar.gz: d3a2f90bb11881d3b4f0fe12beda7e1791e2ad55
3
+ metadata.gz: 44dcee9edb2115e16f8d3db797a6c84bca61e6b6
4
+ data.tar.gz: b5f54fc463e5a501e5d603815114348248a734fa
5
5
  SHA512:
6
- metadata.gz: 215691511a0bb591c5342ad9842d637b29f06f1112e4b29ead2033833bc64ed430e19de97c7283a0fbbe9558d55a4d4d84308d7c4d4056c525c93ef0b8a3d6de
7
- data.tar.gz: 0e695e5a0d1a17f29d58d97a1ed4a7a4258d4f5243014f848bc029467d0bc525f26a0ee43766f752bd80f8431e91e5014d2e4ee1b78e1aec44c76e4213bfa574
6
+ metadata.gz: cc76784425a3bdaf0f83b37e1f8915a86fa900f907d5bd20222d6bacf3450c3cad55269f946d649742c6e798116fc61b1f6770060acc4aba5bec650a97c5aa8d
7
+ data.tar.gz: 3007b00f4ecc6492ab2198480c2a76e49844b9901da87a90d4d1ae2c8bfb33ed4f41f689fa4f1a7fe8310c698d04584a98095954d74a28bb74acd08050b54186
@@ -3,6 +3,21 @@
3
3
  All notable changes to this project will be documented in this file. See the
4
4
  Git log for all changes.
5
5
 
6
+ ## 0.9.0 / 2016-01-21
7
+
8
+ * Propagate exceptions from callbacks during event loops
9
+ * Add new overrides:
10
+ * for Gtk::Container
11
+ * for Gtk::TreeViewColumn
12
+ * for Gtk::TreeStore
13
+ * for Gtk::ListStore
14
+ * for Gtk::TargetEntry.new
15
+ * for GtkBuilder#connect_signals
16
+ * Depend on GirFFI 0.9.0
17
+ * Use GirFFI's new way of handling callback parameters and user data and
18
+ destroy notifier handling
19
+
20
+
6
21
  ## 0.8.1 / 2015-12-02
7
22
 
8
23
  * Add override for Gtk::RadioAction#set_group
data/README.md CHANGED
@@ -46,7 +46,7 @@ and for Gtk+ 2:
46
46
 
47
47
  ## License
48
48
 
49
- Copyright © 2012–2015 [Matijs van Zuijlen](http://www.matijs.net)
49
+ Copyright © 2012–2016 [Matijs van Zuijlen](http://www.matijs.net)
50
50
 
51
51
  GirFFI-Gtk is free software, distributed under the terms of the GNU Lesser
52
52
  General Public License, version 2.1 or later. See the file COPYING.LIB for
@@ -20,26 +20,37 @@ module GirFFIGtk
20
20
  end
21
21
 
22
22
  # Override main to start an idle thread to allow Ruby threads to run during
23
- # the main loop.
24
- module ThreadEnabler
23
+ # the main loop, and to handle exceptions
24
+ module MainLoopOverride
25
+ class DummyLoop
26
+ def quit
27
+ Gtk.main_quit
28
+ end
29
+ end
30
+
25
31
  def self.included(base)
26
32
  base.extend ClassMethods
27
33
  class << base
28
- alias_method :main_without_thread_enabler, :main
29
- alias_method :main, :main_with_thread_enabler
34
+ alias_method :main_without_override, :main
35
+ alias_method :main, :main_with_override
30
36
  end
31
37
  end
32
38
 
33
- # Implementation of class methods for ThreadEnabler
39
+ # Implementation of class methods for MainLoopOverride
34
40
  module ClassMethods
35
- def main_with_thread_enabler
41
+ def main_with_override
36
42
  case RUBY_ENGINE
37
43
  when 'jruby'
38
44
  when 'rbx'
39
45
  else # 'ruby' most likely
40
46
  GLib::MainLoop::ThreadEnabler.instance.setup_idle_handler
41
47
  end
42
- main_without_thread_enabler
48
+ GLib::MainLoop::RUNNING_LOOPS << DummyLoop.new
49
+ result = main_without_override
50
+ ex = GLib::MainLoop::EXCEPTIONS.shift
51
+ GLib::MainLoop::RUNNING_LOOPS.pop
52
+ raise ex if ex
53
+ result
43
54
  end
44
55
  end
45
56
  end
@@ -51,5 +62,5 @@ module Gtk
51
62
  setup_method 'main'
52
63
 
53
64
  include GirFFIGtk::AutoArgv
54
- include GirFFIGtk::ThreadEnabler
65
+ include GirFFIGtk::MainLoopOverride
55
66
  end
@@ -0,0 +1,32 @@
1
+ Gtk.load_class :Builder
2
+ module Gtk
3
+ # Overrides for GtkBuilder
4
+ class Builder
5
+ setup_instance_method :add_from_string
6
+
7
+ def add_from_string_with_auto_length(buffer)
8
+ add_from_string_without_auto_length buffer, buffer.length
9
+ end
10
+
11
+ alias_method :add_from_string_without_auto_length, :add_from_string
12
+ alias_method :add_from_string, :add_from_string_with_auto_length
13
+
14
+ setup_instance_method :connect_signals_full
15
+ remove_method :connect_signals
16
+
17
+ AFTER_FLAG = GObject::ConnectFlags[:after]
18
+
19
+ def connect_signals
20
+ connect_signals_full do |_builder, object, signal_name, handler_name, _connect_object, flags, _user_data|
21
+ handler = yield handler_name
22
+ return unless handler
23
+
24
+ if flags & AFTER_FLAG == AFTER_FLAG
25
+ object.signal_connect_after signal_name, &handler
26
+ else
27
+ object.signal_connect signal_name, &handler
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ Gtk.load_class :Container
2
+ module Gtk
3
+ # Overrides for GtkContainer
4
+ class Container
5
+ def add_with_properties(widget, properties)
6
+ add widget
7
+ properties.each do |property_name, value|
8
+ child_set_property widget, property_name.to_s, value
9
+ end
10
+ end
11
+
12
+ setup_instance_method :child_get_property
13
+
14
+ def child_get_property_with_override(widget, property_name)
15
+ param_spec = object_class.find_child_property property_name
16
+ unless param_spec
17
+ raise ArgumentError,
18
+ "child property named '#{property_name}' not found in #{self.class}"
19
+ end
20
+ gtype = param_spec.value_type
21
+ gvalue = GObject::Value.for_gtype gtype
22
+
23
+ child_get_property_without_override widget, property_name, gvalue
24
+ gvalue.get_value
25
+ end
26
+
27
+ alias_method :child_get_property_without_override, :child_get_property
28
+ alias_method :child_get_property, :child_get_property_with_override
29
+ end
30
+ end
@@ -0,0 +1,14 @@
1
+ Gtk.load_class :ListStore
2
+ module Gtk
3
+ # Overrides for GtkListStore
4
+ class ListStore
5
+ setup_method :newv
6
+ setup_instance_method :set_valuesv
7
+
8
+ alias_method :old_initialize, :initialize
9
+ alias_method :initialize, :initializev
10
+ remove_method :old_initialize
11
+
12
+ alias_method :set, :set_valuesv
13
+ end
14
+ end
@@ -8,24 +8,22 @@ module Gtk
8
8
 
9
9
  # Overrides for GtkRadioButton
10
10
  class RadioButton
11
- def self.new(*args)
12
- obj = allocate
13
- obj.send :initialize, *args
14
- obj
15
- end
16
-
17
11
  def self.new_from_widget(*args)
18
12
  obj = allocate
19
13
  obj.send :initialize_from_widget, *args
20
14
  obj
21
15
  end
22
16
 
17
+ alias_method :old_initialize, :initialize
18
+
23
19
  def initialize(group)
24
20
  list = GLib::SList.from(Gtk::RadioButton, group)
25
21
  ptr = Gtk::Lib.gtk_radio_button_new(list)
26
22
  store_pointer(ptr)
27
23
  end
28
24
 
25
+ remove_method :old_initialize
26
+
29
27
  def initialize_from_widget(radio_group_member)
30
28
  widget = Gtk::RadioButton.from(radio_group_member)
31
29
  ptr = Gtk::Lib.gtk_radio_button_new_from_widget(widget)
@@ -0,0 +1,12 @@
1
+ Gtk.load_class :TargetEntry
2
+ module Gtk
3
+ # Overrides for GtkTargetEntry
4
+ class TargetEntry
5
+ def initialize(target, flags, info)
6
+ super()
7
+ self.target = target
8
+ self.flags = Gtk::TargetFlags.to_native flags, nil
9
+ self.info = info
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ Gtk.load_class :TreeStore
2
+ module Gtk
3
+ # Overrides for GtkTreeStore
4
+ class TreeStore
5
+ setup_method :newv
6
+ setup_instance_method :set_valuesv
7
+ setup_instance_method :insert_with_valuesv
8
+
9
+ alias_method :old_initialize, :initialize
10
+ alias_method :initialize, :initializev
11
+ remove_method :old_initialize
12
+
13
+ alias_method :insert_with_values, :insert_with_valuesv
14
+ alias_method :set, :set_valuesv
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ Gtk.load_class :TargetEntry
2
+ module Gtk
3
+ # Overrides for GtkTargetEntry
4
+ class TargetEntry
5
+ setup_method :new
6
+
7
+ def initialize_with_flags_conversion(target, flags, info)
8
+ native_flags = Gtk::TargetFlags.to_native flags, nil
9
+ initialize_without_flags_conversion target, native_flags, info
10
+ end
11
+
12
+ alias_method :initialize_without_flags_conversion, :initialize
13
+ alias_method :initialize, :initialize_with_flags_conversion
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ Gtk.load_class :ListStore
2
+ module Gtk
3
+ # Overrides for GtkListStore
4
+ class ListStore
5
+ setup_instance_method :insert_with_valuesv
6
+
7
+ alias_method :insert_with_values, :insert_with_valuesv
8
+
9
+ setup_instance_method :set_value
10
+
11
+ def set_value_with_value_conversion(iter, column, value)
12
+ if value.nil?
13
+ value = GObject::Value.for_gtype get_column_type(column)
14
+ end
15
+ set_value_without_value_conversion iter, column, value
16
+ end
17
+
18
+ alias_method :set_value_without_value_conversion, :set_value
19
+ alias_method :set_value, :set_value_with_value_conversion
20
+ end
21
+ end
@@ -13,11 +13,7 @@ module Gtk
13
13
 
14
14
  # Overrides for GtkMessageDialog
15
15
  class MessageDialog
16
- def self.new(*args)
17
- obj = allocate
18
- obj.send :initialize, *args
19
- obj
20
- end
16
+ alias_method :old_initialize, :initialize
21
17
 
22
18
  def initialize(parent, flags, type, buttons, message)
23
19
  ptr = Gtk::Lib.gtk_message_dialog_new(parent, flags, type, buttons,
@@ -25,5 +21,7 @@ module Gtk
25
21
  :string, message)
26
22
  store_pointer(ptr)
27
23
  end
24
+
25
+ remove_method :old_initialize
28
26
  end
29
27
  end
@@ -0,0 +1,15 @@
1
+ Gtk.load_class :TreeStore
2
+ module Gtk
3
+ # Overrides for GtkTreeStore
4
+ class TreeStore
5
+ def set_value_with_value_conversion(iter, column, value)
6
+ if value.nil?
7
+ value = GObject::Value.for_gtype get_column_type(column)
8
+ end
9
+ set_value_without_value_conversion iter, column, value
10
+ end
11
+
12
+ alias_method :set_value_without_value_conversion, :set_value
13
+ alias_method :set_value, :set_value_with_value_conversion
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ Gtk.load_class :TreeViewColumn
2
+ module Gtk
3
+ # Overrides for Gtk::TreeViewColumn
4
+ class TreeViewColumn
5
+ def self.new_with_attributes(*args)
6
+ obj = allocate
7
+ obj.send :initialize_with_attributes, *args
8
+ obj
9
+ end
10
+
11
+ def set_attributes(renderer, attributes)
12
+ attributes.each do |attribute, column|
13
+ add_attribute renderer, attribute.to_s, column
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def initialize_with_attributes(title, renderer, attributes = {})
20
+ initialize
21
+ set_title title
22
+ pack_start(renderer, false)
23
+ set_attributes(renderer, attributes)
24
+ end
25
+ end
26
+ end
@@ -3,8 +3,17 @@ require 'gir_ffi'
3
3
  GirFFI.setup :Gtk, '2.0'
4
4
 
5
5
  require 'gir_ffi-gtk/base'
6
+ require 'gir_ffi-gtk/builder'
7
+ require 'gir_ffi-gtk/container'
8
+ require 'gir_ffi-gtk/list_store'
6
9
  require 'gir_ffi-gtk/menu'
7
10
  require 'gir_ffi-gtk/message_dialog'
8
- require 'gir_ffi-gtk/radio_action'
9
- require 'gir_ffi-gtk/radio_button'
10
11
  require 'gir_ffi-gtk/tree_path'
12
+ require 'gir_ffi-gtk/tree_store'
13
+ require 'gir_ffi-gtk/tree_view_column'
14
+
15
+ require 'gir_ffi-gtk/gtk2/list_store'
16
+ require 'gir_ffi-gtk/gtk2/radio_action'
17
+ require 'gir_ffi-gtk/gtk2/radio_button'
18
+ require 'gir_ffi-gtk/gtk2/target_entry'
19
+ require 'gir_ffi-gtk/gtk2/tree_store'
@@ -3,6 +3,13 @@ require 'gir_ffi'
3
3
  GirFFI.setup :Gtk, '3.0'
4
4
 
5
5
  require 'gir_ffi-gtk/base'
6
+ require 'gir_ffi-gtk/builder'
7
+ require 'gir_ffi-gtk/container'
8
+ require 'gir_ffi-gtk/list_store'
6
9
  require 'gir_ffi-gtk/menu'
7
10
  require 'gir_ffi-gtk/message_dialog'
8
11
  require 'gir_ffi-gtk/tree_path'
12
+ require 'gir_ffi-gtk/tree_store'
13
+ require 'gir_ffi-gtk/tree_view_column'
14
+
15
+ require 'gir_ffi-gtk/gtk3/target_entry'
@@ -10,7 +10,13 @@ namespace :test do
10
10
  Rake::TestTask.new(:gtk2) do |t|
11
11
  t.libs = ['lib']
12
12
  t.test_files = FileList['test/**/*_test.rb']
13
- t.ruby_opts += ['-rgir_ffi-gtk2', '-w', '-Itest']
13
+ t.ruby_opts += ['-w', '-Itest']
14
+ end
15
+
16
+ task gtk2: :set_gtk_version_2
17
+
18
+ task :set_gtk_version_2 do
19
+ ENV['GTK_VERSION'] = '2'
14
20
  end
15
21
  end
16
22
 
@@ -0,0 +1,59 @@
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
+ lambda { 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
59
+
@@ -28,9 +28,7 @@ describe Gtk do
28
28
  describe "::main" do
29
29
  it "allows other threads to run" do
30
30
  a = []
31
- GLib.timeout_add(GLib::PRIORITY_DEFAULT, 150,
32
- proc { Gtk.main_quit },
33
- nil, nil)
31
+ GLib.timeout_add(GLib::PRIORITY_DEFAULT, 150) { Gtk.main_quit }
34
32
 
35
33
  slow_thread = Thread.new do
36
34
  sleep 0.005
@@ -0,0 +1,70 @@
1
+ require 'test_helper'
2
+
3
+ describe Gtk::Builder do
4
+ let(:builder) { Gtk::Builder.new }
5
+ let(:spec) do
6
+ <<-EOS
7
+ <interface>
8
+ <object class="GtkButton" id="foo">
9
+ <signal handler="on_button_clicked" name="clicked"/>
10
+ </object>
11
+ </interface>
12
+ EOS
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
+ <<-EOS
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
+ EOS
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
@@ -0,0 +1,33 @@
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
@@ -17,12 +17,12 @@ describe "In the generated Gtk module" do
17
17
  end
18
18
 
19
19
  it "loads the interface spec" do
20
- assert_nothing_raised { @builder.add_from_string @spec, @spec.length }
20
+ assert_nothing_raised { @builder.add_from_string @spec }
21
21
  end
22
22
 
23
23
  describe "its #get_object method" do
24
24
  it "returns objects of the proper class" do
25
- @builder.add_from_string @spec, @spec.length
25
+ @builder.add_from_string @spec
26
26
  o = @builder.get_object "foo"
27
27
  assert_instance_of Gtk::Button, o
28
28
  end
@@ -30,11 +30,11 @@ describe "In the generated Gtk module" do
30
30
 
31
31
  describe "its #connect_signals_full method" do
32
32
  before do
33
- @builder.add_from_string @spec, @spec.length
33
+ @builder.add_from_string @spec
34
34
  end
35
35
  it "passes arguments correctly" do
36
36
  aa = nil
37
- @builder.connect_signals_full Proc.new {|*args| aa = args}, nil
37
+ @builder.connect_signals_full {|*args| aa = args}
38
38
  b, o, sn, hn, co, f, ud = aa
39
39
  assert_instance_of Gtk::Builder, b
40
40
  assert_equal b.to_ptr, @builder.to_ptr
@@ -43,7 +43,7 @@ describe "In the generated Gtk module" do
43
43
  assert_equal "on_button_clicked", hn
44
44
  assert_equal nil, co
45
45
  assert_equal 0, f
46
- assert_equal nil, ud
46
+ ud.wont_be_nil
47
47
  end
48
48
  end
49
49
  end
@@ -0,0 +1,38 @@
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_equal nil
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+
3
+ describe Gtk::TargetEntry do
4
+ describe '.new' do
5
+ it 'takes and uses three arguments' do
6
+ entry = Gtk::TargetEntry.new('foo', 3, 42)
7
+ entry.target.must_equal 'foo'
8
+ entry.flags.must_equal 3
9
+ entry.info.must_equal 42
10
+ end
11
+
12
+ it 'allows symbol values for the second argument' do
13
+ entry = Gtk::TargetEntry.new('foo', :same_app, 42)
14
+ entry.target.must_equal 'foo'
15
+ entry.flags.must_equal 1
16
+ entry.info.must_equal 42
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,38 @@
1
+ require 'test_helper'
2
+
3
+ describe Gtk::TreeStore do
4
+ describe '.new' do
5
+ it 'takes an array of column types' do
6
+ store = Gtk::TreeStore.new([GObject::TYPE_STRING, GObject::TYPE_INT])
7
+ store.must_be_instance_of Gtk::TreeStore
8
+ end
9
+ end
10
+
11
+ describe '#insert_with_values' do
12
+ it 'inserts a row with the given values' do
13
+ store = Gtk::TreeStore.new([GObject::TYPE_STRING, GObject::TYPE_INT])
14
+ row = store.insert_with_values(nil, 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::TreeStore.new([GObject::TYPE_STRING, GObject::TYPE_INT])
23
+ row = store.insert_with_values(nil, 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::TreeStore.new([GObject::TYPE_STRING, GObject::TYPE_INT])
33
+ row = store.insert_with_values(nil, 0, [0, 1], ['foo', 42])
34
+ store.set_value(row, 0, nil)
35
+ store.get_value(row, 0).must_equal nil
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+
3
+ describe Gtk::TreeViewColumn do
4
+ describe '.new_with_attributes' do
5
+ let(:renderer) { Gtk::CellRendererText.new }
6
+ let(:column) { Gtk::TreeViewColumn.new_with_attributes('foo-title',
7
+ renderer,
8
+ text: 1) }
9
+ let(:list_store) { Gtk::ListStore.new([GObject::TYPE_INT, GObject::TYPE_STRING]) }
10
+
11
+ it "sets the column's title" do
12
+ column.title.must_equal 'foo-title'
13
+ end
14
+
15
+ it 'packs the renderer into the column' do
16
+ column.get_cells.to_a.must_equal [renderer]
17
+ end
18
+
19
+ it "adds the attribute mapping for the renderer" do
20
+ row = list_store.append
21
+ list_store.set_value(row, 1, 'foo-value')
22
+ column.cell_set_cell_data(list_store, row, false, false)
23
+ renderer.text.must_equal 'foo-value'
24
+ end
25
+
26
+ it 'allows not specifying any attributes' do
27
+ col = Gtk::TreeViewColumn.new_with_attributes('foo-title', renderer)
28
+ col.must_be_instance_of Gtk::TreeViewColumn
29
+ end
30
+ end
31
+
32
+ describe '#set_attributes' do
33
+ let(:renderer) { Gtk::CellRendererText.new }
34
+ let(:column) { Gtk::TreeViewColumn.new }
35
+ let(:list_store) { Gtk::ListStore.new([GObject::TYPE_INT, GObject::TYPE_STRING]) }
36
+
37
+ before do
38
+ column.pack_start(renderer, false)
39
+ column.set_attributes(renderer, text: 1)
40
+ end
41
+
42
+ it "adds the attribute mapping for the renderer" do
43
+ row = list_store.append
44
+ list_store.set_value(row, 1, 'foo-value')
45
+ column.cell_set_cell_data(list_store, row, false, false)
46
+ renderer.text.must_equal 'foo-value'
47
+ end
48
+ end
49
+ end
@@ -15,7 +15,9 @@ require 'rr'
15
15
 
16
16
  Thread.abort_on_exception = true
17
17
 
18
- unless Object.const_defined? :Gtk
18
+ if ENV['GTK_VERSION'] == '2'
19
+ require 'gir_ffi-gtk2'
20
+ else
19
21
  require 'gir_ffi-gtk3'
20
22
  end
21
23
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gir_ffi-gtk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matijs van Zuijlen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-02 00:00:00.000000000 Z
11
+ date: 2016-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gir_ffi
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.8.0
19
+ version: 0.9.0
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: 0.8.0
26
+ version: 0.9.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -87,21 +87,37 @@ files:
87
87
  - examples/08_webkit_headless.rb
88
88
  - examples/09_webkit2_headless.rb
89
89
  - lib/gir_ffi-gtk/base.rb
90
+ - lib/gir_ffi-gtk/builder.rb
91
+ - lib/gir_ffi-gtk/container.rb
92
+ - lib/gir_ffi-gtk/gtk2/list_store.rb
93
+ - lib/gir_ffi-gtk/gtk2/radio_action.rb
94
+ - lib/gir_ffi-gtk/gtk2/radio_button.rb
95
+ - lib/gir_ffi-gtk/gtk2/target_entry.rb
96
+ - lib/gir_ffi-gtk/gtk2/tree_store.rb
97
+ - lib/gir_ffi-gtk/gtk3/target_entry.rb
98
+ - lib/gir_ffi-gtk/list_store.rb
90
99
  - lib/gir_ffi-gtk/menu.rb
91
100
  - lib/gir_ffi-gtk/message_dialog.rb
92
- - lib/gir_ffi-gtk/radio_action.rb
93
- - lib/gir_ffi-gtk/radio_button.rb
94
101
  - lib/gir_ffi-gtk/tree_path.rb
102
+ - lib/gir_ffi-gtk/tree_store.rb
103
+ - lib/gir_ffi-gtk/tree_view_column.rb
95
104
  - lib/gir_ffi-gtk2.rb
96
105
  - lib/gir_ffi-gtk3.rb
97
106
  - tasks/test.rake
107
+ - test/callback_exceptions_test.rb
98
108
  - test/gir_ffi-gtk/base_test.rb
109
+ - test/gir_ffi-gtk/builder_test.rb
110
+ - test/gir_ffi-gtk/container_test.rb
99
111
  - test/gir_ffi-gtk/generated_gtk_test.rb
112
+ - test/gir_ffi-gtk/list_store_test.rb
100
113
  - test/gir_ffi-gtk/menu_test.rb
101
114
  - test/gir_ffi-gtk/message_dialog_test.rb
102
115
  - test/gir_ffi-gtk/radio_action_test.rb
103
116
  - test/gir_ffi-gtk/radio_button_test.rb
117
+ - test/gir_ffi-gtk/target_entry_test.rb
104
118
  - test/gir_ffi-gtk/tree_path_test.rb
119
+ - test/gir_ffi-gtk/tree_store_test.rb
120
+ - test/gir_ffi-gtk/tree_view_column_test.rb
105
121
  - test/test_helper.rb
106
122
  homepage: http://www.github.com/mvz/gir_ffi-gtk
107
123
  licenses:
@@ -115,7 +131,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
131
  requirements:
116
132
  - - ">="
117
133
  - !ruby/object:Gem::Version
118
- version: 1.9.3
134
+ version: 2.0.0
119
135
  required_rubygems_version: !ruby/object:Gem::Requirement
120
136
  requirements:
121
137
  - - ">="
@@ -128,11 +144,18 @@ signing_key:
128
144
  specification_version: 4
129
145
  summary: GirFFI-based Ruby bindings for Gtk+ 2 and 3
130
146
  test_files:
147
+ - test/callback_exceptions_test.rb
131
148
  - test/gir_ffi-gtk/base_test.rb
149
+ - test/gir_ffi-gtk/builder_test.rb
150
+ - test/gir_ffi-gtk/container_test.rb
132
151
  - test/gir_ffi-gtk/generated_gtk_test.rb
152
+ - test/gir_ffi-gtk/list_store_test.rb
133
153
  - test/gir_ffi-gtk/menu_test.rb
134
154
  - test/gir_ffi-gtk/message_dialog_test.rb
135
155
  - test/gir_ffi-gtk/radio_action_test.rb
136
156
  - test/gir_ffi-gtk/radio_button_test.rb
157
+ - test/gir_ffi-gtk/target_entry_test.rb
137
158
  - test/gir_ffi-gtk/tree_path_test.rb
159
+ - test/gir_ffi-gtk/tree_store_test.rb
160
+ - test/gir_ffi-gtk/tree_view_column_test.rb
138
161
  - test/test_helper.rb