Module: RuGUI::SignalSupport::ClassMethods

Defined in:
lib/rugui/signal_support.rb

Instance Method Summary collapse

Instance Method Details

#on(widget_name, signal_name, receiver_method_name = nil, &block) ⇒ Object

Declares a signal handler for the given signal of the widget. The handler may be a method of this class or a block, which will be run with the instance of this class as context.

If the signal has arguments they are passed to the receiver method or the block.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rugui/signal_support.rb', line 10

def on(widget_name, signal_name, receiver_method_name = nil, &block)
  if receiver_method_name.nil? and not block_given?
    logger.warn "Either a block or a receiver_method_name must be given to on(#{widget_name}, #{signal_name}), ignoring call."
    return
  end

  signal_connection = RuGUI::SignalSupport::SignalConnection.new
  signal_connection.widget_name = widget_name
  signal_connection.signal_name = signal_name
  signal_connection.receiver_method_name = receiver_method_name
  signal_connection.receiver_block = block if block_given?
  signal_connection.receiver_class = self

  self.signal_connections << signal_connection
end