Modal Dialog + Ruby — Sample program

Modal Dialog + Ruby — Sample program

Installation

1. ruby 1.8.6

2. comamnd prompt

C:> gem install wxruby

Code:

require ‘wx’
include Wx

class MyFrame < Frame
def initialize()
super(nil, -1, ‘Jazzez’)
# First create the controls
@my_panel = Panel.new(self)
@my_label = StaticText.new(@my_panel, -1, ‘URL’, DEFAULT_POSITION, DEFAULT_SIZE, ALIGN_CENTER)
@my_textbox = TextCtrl.new(@my_panel, -1, ‘Default Textbox Value’)
#@my_combo = ComboBox.new(@my_panel, -1, ‘Default Combo Text’, DEFAULT_POSITION, DEFAULT_SIZE, [‘Item 1’, ‘Item 2’, ‘Item 3’])
@my_button = Button.new(@my_panel, -1, ‘My Button Text’)
# Bind controls to functions
evt_button(@my_button.get_id()) { |event| my_button_click(event)}
# Now do the layout
@my_panel_sizer = BoxSizer.new(VERTICAL)
@my_panel.set_sizer(@my_panel_sizer)
@my_panel_sizer.add(@my_label, 0, GROW|ALL, 2)
@my_panel_sizer.add(@my_textbox, 0, GROW|ALL, 2)
#@my_panel_sizer.add(@my_combo, 0, GROW|ALL, 2)
@my_panel_sizer.add(@my_button, 0, GROW|ALL, 2)
show()
end

def my_button_click(event)
a= @my_textbox.get_value
b=a.to_i+1
@new= StaticText.new(@my_panel, -1, “#{b}”, DEFAULT_POSITION, DEFAULT_SIZE, ALIGN_CENTER)
@my_panel_sizer.add(@new, 0, GROW|ALL, 2)
end

end

class MyApp < App
def on_init
MyFrame.new
end
end

MyApp.new.main_loop()

Comments are always welcome

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s