Skip to content
Browse files

test qt integration - builder

  • Loading branch information...
1 parent 8ee3782 commit 3f615c52aecd1c88a90402868a207263ea5bd989 andrea@SONGOKU committed Nov 11, 2009
View
2 Rakefile
@@ -9,7 +9,7 @@ require 'rake/testtask'
spec = Gem::Specification.new do |s|
s.name = 'freightrain'
- s.version = '0.2.6'
+ s.version = '0.3.0'
s.has_rdoc = false
s.summary = 'ruby desktop development made easy'
s.description = s.summary
View
2 lib/freightrain.rb
@@ -5,7 +5,7 @@
require 'require_all'
require 'tmpdir'
-require_all File.dirname(__FILE__) + '/freightrain' #thanks Tony!
+require_all File.dirname(__FILE__) + '/freightrain'
module Freightrain
View
2 lib/freightrain/gtk_builder_helper.rb
@@ -2,7 +2,7 @@
module Freightrain
module GtkBuilderHelper
- def load_from_file(file_path,builder = Gtk::Builder.new)
+ def load_from_file(file_path,builder = GtkInterfaceBuilder.new)
if File.exists?(file_path)
builder.add_from_file(file_path)
builder.objects.each do |widget|
View
30 lib/freightrain/toolkit_extensions/gtk/gtk_interface_builder.rb
@@ -0,0 +1,30 @@
+
+module Freightrain
+
+ class GtkInterfaceBuilder
+
+ def initialize
+ @builder = Gtk::Builder.new
+ end
+
+ def add_from_file(file_path)
+ @builder.add_from_file(file_path)
+ end
+
+ def objects
+ return @builder.objects
+ end
+
+ def get_object(name)
+ return @builder.get_object(name)
+ end
+
+ def connect_signals
+ raise "You must provide a block to connect_signals" unless block_given?
+ @builder.connect_signals do |signal|
+ yield(signal)
+ end
+ end
+
+ end
+end
View
39 lib/freightrain/toolkit_extensions/qt/qt_interface_builder.rb
@@ -0,0 +1,39 @@
+
+module Freightrain
+
+ class QtInterfaceBuilder
+
+ def initialize
+ @builder = Qt::UiLoader.new
+ end
+
+ def add_from_file(file_path)
+ file = Qt::File.new(file_path)
+ file.open(Qt::File::ReadOnly)
+ @toplevel = @builder.load(file)
+ file.close
+ end
+
+ def objects
+ return get_all_objects(@toplevel)
+ end
+
+ def get_object(name)
+ return get_all_objects(@toplevel).select { |widget| widget.objectName == name}.first
+ end
+
+ def connect_signals
+ p "not yet implemented"
+ end
+
+ private
+ def get_all_objects(parent, objects = [])
+ objects << parent
+ parent.children.each do |child|
+ get_all_objects(child, objects)
+ end
+ return objects
+ end
+
+ end
+end
View
4 spec/freightrain/ioc/container_hookable_spec.rb
@@ -9,6 +9,10 @@
describe "subclasses" do
+ before :each do
+ ContainerHookable.classes.clear
+ end
+
it "should return an empty array if never extended" do
ContainerHookable.classes.length.should == 0
end

0 comments on commit 3f615c5

Please sign in to comment.
Something went wrong with that request. Please try again.