From: Alex Fenton Date: 2008-01-21T08:54:59+09:00 Subject: Re: wxRuby 1.9.4 Dominik Honnef wrote: > In my opinion, a binding to wxWidgets is a great chance for GUIs with ruby, but I'm wondering, if its very ruby-like. > Lets take the following extract of the tutorial (frames, part 1) As the tutorial front page warns, some of that material is dated. Much more ruby-like syntax is permitted now. The API docs and many of the bundled samples are more current. > [code] > btn = Wx::Button.new(panel, -1, name + " (Close me)", Wx::Point.new(45,55)) > evt_button(btn.get_id()) {|event| destroy()} > [/code] could be written: btn = Wx::Button.new(panel, :label => "#{name} (Close me)", :pos => [45, 55]) evt_button(btn) { close } > In my opinion, the button itself should handle its events and not the frame. Both are valid programming strategies: you might want to encapsulate a set of behaviours in a ruby subclass of a widget like a button, or have a coherent group of interactions managed by a particular frame or dialog. Anyway, either is possible. CommandEvents from controls like Button bubble upwards to their containing windows. The event handling page in the docs discusses this in detail: http://wxruby.rubyforge.org/doc/eventhandlingoverview.html > And even if the frame has to handle it, why does evt_button await an ID and not simply the button instance itself? Event handlers have for numerous versions accepted IDs or just the instance itself. > Maybe there are good reasons for this behaviour, but I cant see them. In most cases, like you say, using an object is preferable. You'd normally only use an ID now with "special" identifiers like Wx::ID_EXIT or Wx::ID_ABOUT. The great advantage of using these special ids to identify, for example, menu items is that they will get all the OS-standard behaviour on different platforms. A Wx::ID_EXIT menu item will be labelled "Exit" on Windows and GTK, and will get the desktop-standard menu icon on the latter. But on OS X it will be called "Quit" and will be located in the Application-name menu, not the File menu. This kind of attention to GUI platform standards is one of wxRuby/wxWidget's strengths, along with accessibility. GTK apps, for example, feel clumsy and look foreign on OS X in particular. I'm not picking on GTK - it's an excellent toolkit too, and wxRuby uses it on Linux - but it's a matter of choosing the right GUI library given the target platforms and user group for any given project. cheers alex