Hi
Carlos Troncoso Phillips wrote:> Well, I''d like to have a dialog where you can choose from a list,
click
> ok and the dialog would return an answer
> i.e. hometown = mydlg.find_hometown(employee_array)
>
The class to start with is Wx::SingleChoiceDialog. Your message made me
look at this class for the first time and it needs a little developer
attention, but it should work fine for your purposes.
With dialogs the primary return value is whether or not the user chose
to proceed - ie did they click ''OK'' or
''Cancel'' (or shut the dialog, or
press <Escape>)? In deciding what to do next, an application should test
this before it thinks about acting upon what value was chosen.
Conventionally, wxRuby dialogs signal this by returning an integer
constant from show_modal. Your code should test this value, then proceed
accordingly.
> As in ruby, the last eval is what is returned, how can I self.distroy
> the dialog if the return value must be the LAST line of code in the
> function?
>
See the example code below as a starting point. It shows how, if you
want, you can provide a class method as a quick way to select something
from a list, or return ''nil'' if the user cancelled the action.
If you create a dialog with a parent window, then show it temporarily,
you don''t need to call #destroy on it. User code rarely need to call
#destroy (see the docs); in most normal cases wxRuby handles window
deletion and clean up automatically.
alex
__
require ''wx''
class EmployeeDialog < Wx::SingleChoiceDialog
EMPLOYEES = { ''Fred'' => ''London'',
''Brenda'' => ''Manchester'',
''Billy'' => ''Glasgow'' }
def self.find_hometown(parent)
dlg = new(parent, ''Select employee'', ''Choose
one'', EMPLOYEES.keys)
if dlg.show_modal == Wx::ID_OK
return dlg.hometown
else
return nil
end
end
def hometown
EMPLOYEES[string_selection]
end
end
Wx::App.run do
frame = Wx::Frame.new nil, :title => ''Employeees''
button = Wx::Button.new frame, :label => ''Select
employee''
evt_button(button) { puts EmployeeDialog.find_hometown(frame) }
frame.show
end