From: Lyle J. <ly...@kn...> - 2004-04-03 03:30:24
|
On Mar 29, 2004, at 9:06 PM, Daniel Sheppard wrote: > I've been frustrated with the fact that you can't connect multiple > things to an FXObject. Ie. > > target = FXDataTarget.new() > target.connect(SEL_COMMAND) { puts "hello" } > target.connect(SEL_COMMAND) { puts "hello2" } > > The only thing that gets printed when the target is changed is > "hello2". Correct. Each object has exactly one message target, and the way that the connect() method is implemented is that it creates a target behind the scenes. > How do others normally deal with this? Do you have your code such that > all connectors must go through in intermediary? Do you only connect in > the one place? In a lot of cases, multiple "connections" for a command message (as in your example) are used to update the states of different objects based on some event. This is a natural choice for, say, Java programmers, who are used to Swing's model of having multiple listeners for a given event. FOX's approach to this is very different and emphasizes the use of GUI update to update the state of things. So for example instead of something like this: someButton.connect(SEL_COMMAND) { update_the_main_window_title() update_the_selected_text_color() update_the_button_font_size() } you would instead see code like this: main_window.connect(SEL_UPDATE) { update_my_title() } selected_text.connect(SEL_UPDATE) { update_my_color() } button.connect(SEL_UPDATE) { update_font_size() } For more about this, see the FOX documentation at: http://www.fox-toolkit.org. > I've thrown together a module to include in classes that I want to > multi-connect to. <snip> Yes, this looks fine too ;) |