From: Jakub Travnik Date: 2001-10-26T09:35:13+09:00 Subject: [ruby-talk:23385] Re: GUI / was [ANN] RubyInRubyParser 0.1-pre-alpha Eli Green wrote: > For example: > > window = Window.new > button = Button.new > def button.activate > print "Click!" > end > window.add(button) > window.run How to deal with multiple windows and positioning with this model? > Or something like that. The point is that Ruby has an event model already > written for us .. just redefine that instance's method! That's idea I use in JTTui (my text-mode user interface). I see a big similarity with example above and the way things are done in JTTui. JTTui now needs some fixies for bugs I am aware of. I plan to release it when they are fixed. > Another very cool thing this could lead to is something like this: > > PersonFactory = Struct.new("Person", :first_name, :last_name, :iq) > > window = Window.new > table = Table.new > table.header = ["First Name", "Last Name"] > table << PersonFactory.new("Joe", "Slopchuck", 210) > table << PersonFactory.new("Some", "Guy", 160) > table << PersonFactory.new("Eli", "Green", 10) > def table.data_for_row(row) > return [row.first_name, row.last_name] > end > window.add(table) > > So table would look something like: > > +------------+-----------+ > | First Name | Last Name | > +------------+-----------+ > | Joe | Slopchuck | > | Some | Guy | > | Eli | Green | > +------------+-----------+ > > Doing this: > > table.selected_object > > Would return the actual Person object that was inserted previously, giving the > entire environment a very OO feel. The same could be done for ComboBoxes and > Lists and such ... a reference to an object would be stored by the widget, but > the display would be determined by the re-defined format method call. Nice. Tables like this worth implementing in JTTui (with some modifications for more general use). JTTui have already almost general listbox/tree stuff done with same approach. Jakub Travnik ICQ: 66770334