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
lease_log_in do |w|
w.text = "Please log in"
w.bold = true
end
setup :username do |w|
w.columns_visible = 20
end
setup
assword 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
k 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.