In article <A82143D5-8957-11D8-A64E-000A95CD7A8E / talbott.ws>, Nathaniel Talbott <nathaniel / talbott.ws> wrote: >On Apr 7, 2004, at 13:19, Hal Fulton wrote: > >> If I were you, I'd put together a working example (not too complex, >> not too simple) and write an article about it. Bet Dr Dobbs would >> go for it. > >Well, I'm not him, but I'll go ahead and do a little "show and tell" >here... I recently worked on an application with a Fox GUI, and in the >process I wrapped some code around Fox to make GUI creation easier. >Part of my thinking when I built it was that there are two things we do >when we set up a GUI, and it would be cleaner if we did them as two >steps instead of mashing them together. Those two steps are setting up >the components relationships to one another, and setting up the >component's properties, event handlers, etc. So I ended up with code >that looks like this: > > class LoginDialog > include FXUtil > > attr_reader :credentials > > def initialize(app) > super() > create(app) > end > > def create(app) > template(app) do > dialog("Login"){vertical{ > matrix{label(:please_log_in); empty > label("User name:"); text_field(:username) > label("Password:"); text_field(:password)} > horizontal(:buttons){button(:ok); button(:cancel)}}} > end > > setup :please_log_in do |w| > w.text = "Please log in" > w.bold = true > end > > setup :username do |w| > w.columns_visible = 20 > end > > setup :password do |w| > w.options |= TEXTFIELD_PASSWD > w.columns_visible = 20 > w.on_keypress do |source, selector, event| > if(event.text == "\r") > ok(source) > else > false > end > end > end > > setup :buttons do |w| > w.options = LAYOUT_CENTER_X > end > > setup :ok do |w| > w.text = "&OK" > w.options |= BUTTON_DEFAULT|BUTTON_INITIAL > w.on_click{|source, s, e| ok(source)} > end > > setup :cancel do |w| > w.text = "&Cancel" > w.on_click{|source, s, e| cancel(source)} > end > > build > end > > def ok(source) > @credentials = [widget(:username).text, widget(:password).text] > widget.handle(source, MKUINT(FXDialogBox::ID_ACCEPT, >SEL_COMMAND), nil) > end > > def cancel(source) > widget.handle(source, MKUINT(FXDialogBox::ID_CANCEL, >SEL_COMMAND), nil) > end > > def execute > widget(:username).setFocus > (widget.execute(PLACEMENT_SCREEN) == 1) ? true : false > end > end > >Currently 'FXUtil' is in no way ready for prime time, but hopefully >this code (which is presently live production code) illustrates one >better way that I found of building GUIs. > Interesting. I'd be interested in seeing your implementation of setup and template. Would that be possible? Wouldn't have to see everything. Phil