[Kde-bindings] branches/KDE/3.5/kdebindings/qtruby

Richard Dale Richard_Dale at tipitina.demon.co.uk
Thu Sep 14 10:34:57 UTC 2006


SVN commit 584205 by rdale:

* Added a new variant of connect, which takes a SIGNAL as an argument, along with
  a block. For example:

	quit.connect(SIGNAL(:clicked)) { puts 'quit pressed' }

  The block is called in the context of where the connect call was made, and 'self'
  needn't be a Qt::Object. It is similar to the signal_connect() method in
  ruby-gnome. This was suggested by rickdangerous on the #qtruby irc channel.

CCMAIL: kde-bindings at kde.org



 M  +11 -0     ChangeLog  
 M  +3 -1      rubylib/qtruby/Qt.cpp  
 M  +20 -0     rubylib/qtruby/lib/Qt/qtruby.rb  


--- branches/KDE/3.5/kdebindings/qtruby/ChangeLog #584204:584205
@@ -1,3 +1,14 @@
+2006-09-14  Richard Dale  <rdale at foton.es>
+
+	* Added a new variant of connect, which takes a SIGNAL as an argument, along with
+	  a block. For example:
+
+		quit.connect(SIGNAL(:clicked)) { puts 'quit pressed' }
+
+	  The block is called in the context of where the connect call was made, and 'self'
+	  needn't be a Qt::Object. It is similar to the signal_connect() method in
+	  ruby-gnome. This was suggested by rickdangerous on the #qtruby irc channel.
+
 2006-09-13  Richard Dale  <rdale at foton.es>
 
 	* Blocks can now be used as slots in Qt::Object.connect() calls. There are two
--- branches/KDE/3.5/kdebindings/qtruby/rubylib/qtruby/Qt.cpp #584204:584205
@@ -1857,7 +1857,9 @@
 qobject_connect(int argc, VALUE * argv, VALUE self)
 {
 	if (rb_block_given_p()) {
-		if (argc == 2) {
+		if (argc == 1) {
+			return rb_funcall(qt_internal_module, rb_intern("signal_connect"), 3, self, argv[0], rb_block_proc());
+		} else if (argc == 2) {
 			return rb_funcall(qt_internal_module, rb_intern("connect"), 4, argv[0], argv[1], self, rb_block_proc());
 		} else if (argc == 3) {
 			return rb_funcall(qt_internal_module, rb_intern("connect"), 4, argv[0], argv[1], argv[2], rb_block_proc());
--- branches/KDE/3.5/kdebindings/qtruby/rubylib/qtruby/lib/Qt/qtruby.rb #584204:584205
@@ -1205,6 +1205,18 @@
 		end
 	end
 
+	class SignalBlockInvocation < Qt::Object
+		def initialize(parent, block, args)
+			super(parent)
+			self.class.slots "invoke(#{args})"
+			@block = block
+		end
+
+		def invoke(*args)
+			@block.call(*args)
+		end
+	end
+
 	class BlockInvocation < Qt::Object
 		def initialize(target, block, args)
 			super(target)
@@ -1622,6 +1634,14 @@
 										Qt::BlockInvocation.new(target, block, signature),
 										SLOT("invoke(#{signature})") )
 		end
+
+		def Internal.signal_connect(src, signal, block)
+			signature = (signal =~ /\((.*)\)/) ? $1 : ""
+			return Qt::Object.connect(	src,
+										signal,
+										Qt::SignalBlockInvocation.new(src, block, signature),
+										SLOT("invoke(#{signature})") )
+		end
 	end # Qt::Internal
 
 	Meta = {}



More information about the Kde-bindings mailing list