Forum: Ruby-Gnome 2 signal_emit for other object

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
72b416125e0048f8279b1b57f973b66b?d=identicon&s=25 Cyrill Jakovlev (cyrill)
on 2008-10-26 03:30
my code:
http://pastie.org/300627
Why generated event, in same object, can not be heard in other?
Sorry for my english:)
07aaa2c67e8b41fa38f628356a2b163a?d=identicon&s=25 Roy Wright (royw)
on 2008-10-29 08:24
Cyrill Jakovlev wrote:
> my code:
> http://pastie.org/300627
> Why generated event, in same object, can not be heard in other?
> Sorry for my english:)

I think you are missing the "type_register" command.

Here's the pattern that I've used successfully:

class Foo < Gtk::Object
  type_register
  CHANGED = 'changed'
  signal_new(CHANGED,
             GLib::Signal::RUN_FIRST,    # flags
             nil,                        # accumulator (XXX: not
supported yet)
             nil,                        # return type (void == nil)
             Hash                        # parameter types: Hash
            )

  # needed to be able to emit the "changed" signal
  def signal_do_changed(params)
  end

  def something_useful
    ...
    params ||= {}
    signal_emit(CHANGED, params)
  end
end

class Bar
  ...
  foo = Foo.new
  foo.signal_connect(Foo::CHANGED) {|obj, params|
on_foo_changed(params)}
  ...
end

I've used this pattern for several widgets and EventBox objects.  Just
inherit from correct object.  For example:  class Foo < Gtk::EventBox

HTH,
Roy
72b416125e0048f8279b1b57f973b66b?d=identicon&s=25 Cyrill Jakovlev (cyrill)
on 2008-10-29 11:37
mm.. no
I don't make type_register, because I refined class GLib::Object. In
GLib::Object type_register called before..
Your example can hear signal only inside object. If I call
signal_emit('changed'), other instances of class Foo (and all other
objects) wouldn't know about it.
I want to all object (instance classes extends GLib::Object) can hear
signal, and I find solution: http://pastie.org/301012
signal_emit from button call method from window. How u like this?)
07aaa2c67e8b41fa38f628356a2b163a?d=identicon&s=25 Roy Wright (royw)
on 2008-10-29 21:23
Cyrill Jakovlev wrote:
> mm.. no
> I don't make type_register, because I refined class GLib::Object. In
> GLib::Object type_register called before..
> Your example can hear signal only inside object. If I call
> signal_emit('changed'), other instances of class Foo (and all other
> objects) wouldn't know about it.
> I want to all object (instance classes extends GLib::Object) can hear
> signal, and I find solution: http://pastie.org/301012
> signal_emit from button call method from window. How u like this?)

OK, you are wanting truly global signals.  First, I'd suggest removing
the instance signal_connect (line 15) and signal_emit (line 19) in your
example.  By removing them, GeneralWindow and ToolsPanel will each
receive only one signal via signal_connect_from_all_objects.  So you end
up with a pure global signal concept that is not blurred with normal
signal handling.

Also I'd suggest adding a signal_disconnect_from_all_objects method to
Glib::Object.  I'd suspect that you could run into problems deleting and
garbage collecting objects without it.

Part of me likes the global signal pattern, while another part of me has
concerns that the pattern can be abused leading to some difficult to
debug problems.

Thanks for sharing.

Have fun,
Roy
This topic is locked and can not be replied to.