Howdy;
I’m using wxRuby to build menus for a Sketchup plug-in I’m working on.
(Specifically, I’m actually using wxSU, http://wxsu.sourceforge.net/,
which is basically wxRuby packaged up as a Sketchup plug-in).
I’m trying to create a custom dialog to gather information from the user
via text boxes (implemented with Wx::TextCtrl) and pull-down menus
(implemented with Wx::Choice). My problem is that I can’t figure out how
to get the information entered via these means out of the Wx::Dialog
object they live in when the “OK” button is clicked. Here is the
relevant code:
this is the WX code for an improved location dialog
class LocationDialog < Wx::Dialog
def initialize
## set dialog characteristics
title = "Location dialog"
size = Wx::Size.new(250, 305)
position = Wx::DEFAULT_POSITION
style = Wx::SYSTEM_MENU
name = "location dialog"
## create dialog
super(WxSU.app.sketchup_frame, -1, title, position, size, style,
name)
## fields and buttons
## city
citySTPos = Wx::Point.new(10,10)
citySTSize = Wx::Size.new(110,20)
cityST = Wx::StaticText.new(self, -1, 'city', citySTPos,
citySTSize, Wx::ALIGN_RIGHT)
cityTCPos = Wx::Point.new(130,10)
cityTCSize = Wx::Size.new(100,20)
@cityTC = Wx::TextCtrl.new(self, -1, '', cityTCPos, cityTCSize,
Wx::TE_LEFT)
## timezone offset
tzSTPos = Wx::Point.new(10,130)
tzSTSize = Wx::Size.new(110,20)
tzST = Wx::StaticText.new(self, -1, 'timezone offset', tzSTPos,
tzSTSize, Wx::ALIGN_RIGHT)
tzCPos = Wx::Point.new(130,130)
tzCSize = Wx::Size.new(70,20)
tzChoices = (-12..12).to_a.collect{ |e| e.to_s }
tzC = Wx::Choice.new(self, -1, tzCPos, tzCSize, tzChoices)
## a bunch more fields here that I've omitted for brevity
## okay button
okBPos = Wx::Point.new(130,255)
okBSize = Wx::Size.new(100,20)
okButton = Wx::Button.new(self, Wx::ID_OK, 'okay', okBPos,
okBSize, Wx::BU_BOTTOM)
self.set_affirmative_id(okButton.get_id()) ## identifies button
as dialog “OK” button
#evt_button(okButton.get_id()) {|e| on_okButton(e)} # attempt 1
#evt_button(okButton.get_id()) {|e| puts “test” } # attempt 2
## cancel button
canBPos = Wx::Point.new(20,255)
canBSize = Wx::Size.new(100,20)
canButton = Wx::Button.new(self, Wx::ID_CANCEL, 'cancel',
canBPos, canBSize, Wx::BU_BOTTOM)
self.set_escape_id(canButton.get_id()) ## identifies button as
dialog “cancel” button
end ## initilize
end ## LocationDialog
I tried using the button event handling block to point the button to
another method (“attempt 1” commented out above), but when I do it this
way, I can’t get the LocationDialog.show_modal method to return anything
but a Fixnum 0 when “OK” is clicked (it should be returning either a
Fixnum 5100, or a Wx::ID_OK), which is problematic because I need this
return value for logic elsewhere in my code.
I also tried simply putting the code I need right in the block (“attempt
2”, commented out above). When I do this the code in the block executes
as I would hope, but nothing else I need to happen happens – ie, the
dialog doesn’t close, and the LocationDialog.show_modal doesn’t return
the correct value.
So: I’m wondering how I can accomplish this. Any suggestions would be
very much appreciated.
Josh