[fxruby-users] Connecting messages to methods

Jannis Pohlmann info at sten-net.de
Tue Apr 5 08:30:15 EDT 2005


Hi all.

I'm trying to write a subclass of FXMainWindow which has several methods to 
dispatch events. The class looks like this:

--

require "fox12"
require "fox12/responder"
include Fox

class Window < FXMainWindow

	include Responder

	ID_SELF,
	ID_BTN = enum(FXMainWindow::ID_LAST, 2) 

	def initialize(a, title)
		super(a, title, nil, nil, DECOR_ALL, 0, 0, 640, 480)
		self.setSelector(ID_SELF)
		self.setTarget(self)
		self.connect(SEL_CLOSE, method(:onClose))
		self.connect(SEL_COMMAND, method(:onCommand))
		FXButton.new(self, "Click me!", nil, self, ID_BTN)
	end

	def create
		super
		show(PLACEMENT_SCREEN)
	end

	def onClose(sender, sel, event)
		getApp.exit(0)
	end

	def onCommand(sender, sel, event)
		# ...
	end

end

--

I'd like to redirect all SEL_COMMAND events to Window::onCommand. As an example, if one
clicks the button, the message (SEL_COMMAND, ID_BTN) is sent to the Window class but is not
handled there (Window::onCommand is never called). When using 

	FXMAPFUNC(SEL_COMMAND, ID_BTN, "onCommand") 

or (better)

	FXMAPFUNCS(SEL_COMMAND, ID_SELF, ID_BTN, "onCommand")

this should work but I neither want to use this C-macro style nor do I want to add

	.connect(SEL_COMMAND, method(:onCommand))

to each widget I append to Window (this is one of the reasons why I'm not using GTK+).

Is there a way? Did I miss something?

Regards,
Jannis



More information about the fxruby-users mailing list