Hi all,
I’m working on a script to query some decisions from the user. So
there’s a loop iterating over pairs of alternatively possible choices.
Now, during querying the main program shouldn’t be available, thus some
kind of modal dialog box seems appropriate.
Up to now I wrote the following stuff, which is likely not the most
elegant way, but let’s follow the “Make it parse, make it work, make it
nice, make it fast (IF neccessary” maxime for a moment. (But then I’m
open for any improvements!)
class PriorizeDialog < FXDialogBox
attr_reader :result
include Responder
ID_ITEM1,
ID_ITEM2 = enum( FXMainWindow::ID_LAST , 2 )
def initialize( owner, item1, item2 )
@result = 0
FXMAPFUNC( SEL_COMMAND, PriorizeDialog::ID_ITEM1, "onItem1" )
FXMAPFUNC( SEL_COMMAND, PriorizeDialog::ID_ITEM2, "onItem2" )
# Invoke base class initialize function first
super(owner, "Priorize pair", DECOR_TITLE|DECOR_BORDER)
# Bottom buttons
buttons = FXHorizontalFrame.new(self, LAYOUT_SIDE_BOTTOM |
FRAME_NONE | LAYOUT_FILL_X|PACK_UNIFORM_WIDTH, 0, 0, 0, 0, 40,
40,
20, 20)
# Select item 2
FXButton.new(buttons, "&2. #{item2}", nil, self, ID_ITEM2,
FRAME_RAISED|FRAME_THICK|LAYOUT_RIGHT|LAYOUT_CENTER_Y)
# Select item 1
FXButton.new(buttons, "&1. #{item1}", nil, self, ID_ITEM1,
FRAME_RAISED|FRAME_THICK|LAYOUT_RIGHT|LAYOUT_CENTER_Y)
end
def onItem1( sender, sel, ptr )
@result = 1
end
def onItem2( sender, sel, ptr )
@result = 2
end
end
Now that doen’t work: The dialog will never quit.
My guess is that the script never runs into code that sends something
like ID_ACCEPT/ID_CANCEL to the appropriate object (which is self I think).
What’s the ruby way do accomplish this?
I have the stron feeling that my way of fiddling with @result may not be
too terribly rubyish - is there a better (Ruby) way to do this?
Thanks for any comments.
Stephan