wxruby 1.9.9-x86-mingw32 → 1.9.10-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +53 -53
- data/README +297 -297
- data/lib/wx.rb +53 -53
- data/lib/wx/classes/bitmap.rb +29 -1
- data/lib/wx/classes/clipboard.rb +19 -3
- data/lib/wx/classes/colour.rb +6 -4
- data/lib/wx/classes/data_object.rb +14 -0
- data/lib/wx/classes/data_object_simple.rb +6 -0
- data/lib/wx/classes/dataformat.rb +23 -0
- data/lib/wx/classes/evthandler.rb +31 -4
- data/lib/wx/classes/genericdirctrl.rb +36 -0
- data/lib/wx/classes/grid.rb +8 -0
- data/lib/wx/classes/hboxsizer.rb +6 -0
- data/lib/wx/classes/icon.rb +12 -1
- data/lib/wx/classes/image.rb +13 -1
- data/lib/wx/classes/listctrl.rb +12 -0
- data/lib/wx/classes/point.rb +8 -0
- data/lib/wx/classes/rect.rb +10 -1
- data/lib/wx/classes/richtextctrl.rb +22 -0
- data/lib/wx/classes/size.rb +9 -0
- data/lib/wx/classes/sizer.rb +18 -3
- data/lib/wx/classes/toolbar.rb +4 -6
- data/lib/wx/classes/vboxsizer.rb +6 -0
- data/lib/wx/classes/window.rb +7 -0
- data/lib/wx/classes/xmlresource.rb +17 -0
- data/lib/wx/helpers.rb +16 -1
- data/lib/wx/keyword_ctors.rb +3 -2
- data/lib/wx/keyword_defs.rb +27 -5
- data/lib/wx/version.rb +1 -1
- data/lib/wxruby2.so +0 -0
- data/samples/SAMPLES-LICENSE.TXT +17 -17
- data/samples/bigdemo/About.rbw +39 -39
- data/samples/bigdemo/ColorPanel.rbw +23 -23
- data/samples/bigdemo/GridSimple.rbw +78 -78
- data/samples/bigdemo/MDIDemo.rbw +57 -57
- data/samples/bigdemo/PopupMenu.rbw +149 -149
- data/samples/bigdemo/Sizers.rbw +543 -543
- data/samples/bigdemo/bigdemo.rb +823 -823
- data/samples/bigdemo/demoTemplate.rbw +33 -33
- data/samples/bigdemo/icons/choice.xpm +27 -27
- data/samples/bigdemo/icons/combo.xpm +27 -27
- data/samples/bigdemo/icons/copy.xpm +25 -25
- data/samples/bigdemo/icons/cut.xpm +24 -24
- data/samples/bigdemo/icons/gauge.xpm +27 -27
- data/samples/bigdemo/icons/help.xpm +25 -25
- data/samples/bigdemo/icons/list.xpm +27 -27
- data/samples/bigdemo/icons/mondrian.xpm +44 -44
- data/samples/bigdemo/icons/new.xpm +24 -24
- data/samples/bigdemo/icons/ogl.ico +0 -0
- data/samples/bigdemo/icons/ogl.xpm +45 -45
- data/samples/bigdemo/icons/open.xpm +26 -26
- data/samples/bigdemo/icons/paste.xpm +38 -38
- data/samples/bigdemo/icons/preview.xpm +26 -26
- data/samples/bigdemo/icons/print.xpm +26 -26
- data/samples/bigdemo/icons/radio.xpm +27 -27
- data/samples/bigdemo/icons/robert.xpm +415 -415
- data/samples/bigdemo/icons/save.xpm +25 -25
- data/samples/bigdemo/icons/smiles.xpm +39 -39
- data/samples/bigdemo/icons/smiley.xpm +42 -42
- data/samples/bigdemo/icons/stattext.xpm +24 -24
- data/samples/bigdemo/icons/test2.bmp +0 -0
- data/samples/bigdemo/icons/test2.xpm +79 -79
- data/samples/bigdemo/icons/text.xpm +27 -27
- data/samples/bigdemo/icons/tog1.xpm +38 -38
- data/samples/bigdemo/icons/tog2.xpm +38 -38
- data/samples/bigdemo/icons/wxwin16x16.xpm +25 -25
- data/samples/bigdemo/tips.txt +7 -7
- data/samples/bigdemo/utils.rb +11 -11
- data/samples/bigdemo/wxButton.rbw +64 -64
- data/samples/bigdemo/wxCalendarCtrl.rbw +60 -60
- data/samples/bigdemo/wxCheckBox.rbw +50 -50
- data/samples/bigdemo/wxCheckListBox.rbw +65 -75
- data/samples/bigdemo/wxChoice.rbw +47 -47
- data/samples/bigdemo/wxColourDialog.rbw +31 -31
- data/samples/bigdemo/wxComboBox.rbw +77 -77
- data/samples/bigdemo/wxDialog.rbw +74 -74
- data/samples/bigdemo/wxDirDialog.rbw +29 -29
- data/samples/bigdemo/wxFileDialog.rbw +37 -37
- data/samples/bigdemo/wxFileDialog_Save.rbw +35 -35
- data/samples/bigdemo/wxFindReplaceDialog.rbw +82 -82
- data/samples/bigdemo/wxFontDialog.rbw +173 -173
- data/samples/bigdemo/wxFrame.rbw +53 -53
- data/samples/bigdemo/wxGauge.rbw +71 -71
- data/samples/bigdemo/wxGrid.rbw +66 -66
- data/samples/bigdemo/wxListBox.rbw +140 -140
- data/samples/bigdemo/wxListCtrl_virtual.rbw +112 -107
- data/samples/bigdemo/wxMDIWindows.rbw +50 -50
- data/samples/bigdemo/wxMenu.rbw +236 -236
- data/samples/bigdemo/wxMessageDialog.rbw +27 -27
- data/samples/bigdemo/wxMultipleChoiceDialog.rbw +32 -32
- data/samples/bigdemo/wxNotebook.rbw +136 -136
- data/samples/bigdemo/wxProgressDialog.rbw +43 -43
- data/samples/bigdemo/wxRadioBox.rbw +72 -72
- data/samples/bigdemo/wxRadioButton.rbw +125 -125
- data/samples/bigdemo/wxSashWindow.rbw +2 -2
- data/samples/bigdemo/wxScrolledMessageDialog.rbw +57 -57
- data/samples/bigdemo/wxScrolledWindow.rbw +199 -199
- data/samples/bigdemo/wxSingleChoiceDialog.rbw +33 -33
- data/samples/bigdemo/wxSlider.rbw +42 -42
- data/samples/bigdemo/wxSpinButton.rbw +50 -50
- data/samples/bigdemo/wxSpinCtrl.rbw +51 -51
- data/samples/bigdemo/wxSplitterWindow.rbw +63 -63
- data/samples/bigdemo/wxStaticBitmap.rbw +51 -51
- data/samples/bigdemo/wxStaticText.rbw +55 -55
- data/samples/bigdemo/wxStatusBar.rbw +126 -126
- data/samples/bigdemo/wxTextCtrl.rbw +149 -149
- data/samples/bigdemo/wxTextEntryDialog.rbw +31 -31
- data/samples/bigdemo/wxToggleButton.rbw +49 -49
- data/samples/bigdemo/wxToolBar.rbw +131 -131
- data/samples/bigdemo/wxTreeCtrl.rbw +191 -190
- data/samples/calendar/calendar.rb +256 -271
- data/samples/caret/caret.rb +282 -282
- data/samples/caret/mondrian.xpm +44 -44
- data/samples/controls/controls.rb +1136 -1136
- data/samples/controls/get_item_sample.rb +87 -87
- data/samples/controls/icons/choice.xpm +27 -27
- data/samples/controls/icons/combo.xpm +27 -27
- data/samples/controls/icons/gauge.xpm +27 -27
- data/samples/controls/icons/list.xpm +27 -27
- data/samples/controls/icons/radio.xpm +27 -27
- data/samples/controls/icons/stattext.xpm +24 -24
- data/samples/controls/icons/text.xpm +27 -27
- data/samples/controls/mondrian.xpm +44 -44
- data/samples/dialogs/dialogs.rb +797 -723
- data/samples/dialogs/tips.txt +18 -18
- data/samples/drawing/images.rb +37 -37
- data/samples/etc/activation.rb +102 -102
- data/samples/etc/choice.rb +67 -67
- data/samples/etc/miniframe.rb +79 -79
- data/samples/etc/sash.rb +130 -130
- data/samples/etc/scrollwin.rb +110 -110
- data/samples/etc/system_settings.rb +252 -252
- data/samples/etc/toolbar_sizer_additem.rb +55 -0
- data/samples/etc/wizard.rb +74 -74
- data/samples/event/update_ui_event.rb +70 -0
- data/samples/grid/gridtablebase.rb +43 -29
- data/samples/listbook/listbook.rb +174 -174
- data/samples/listbook/listbook.xrc +370 -370
- data/samples/mdi/mdi.rb +85 -77
- data/samples/minimal/minimal.rb +77 -77
- data/samples/minimal/nothing.rb +16 -16
- data/samples/text/format-text-bold.png +0 -0
- data/samples/text/format-text-italic.png +0 -0
- data/samples/text/format-text-underline.png +0 -0
- data/samples/text/rich_textctrl.rb +98 -0
- data/samples/text/textctrl.rb +111 -113
- data/samples/text/unicode.rb +242 -242
- data/samples/text/utf8.txt +14 -14
- data/samples/treectrl/treectrl.rb +1166 -1174
- data/samples/xrc/samples.xrc +46 -46
- data/samples/xrc/xrc_sample.rb +76 -96
- metadata +15 -3
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
|
3
|
+
# Freely reusable code: see SAMPLES-LICENSE.TXT for details
|
4
|
+
|
5
|
+
require 'rubygems' rescue LoadError
|
6
|
+
|
7
|
+
require 'wx'
|
8
|
+
|
9
|
+
# Simple test application for keyword arguments to Sizer#add_item and
|
10
|
+
# ToolBar#add_item. Originally contributed by Chauk-Mean P
|
11
|
+
|
12
|
+
Wx::App.run do
|
13
|
+
frame = Wx::Frame.new( nil,
|
14
|
+
:title => 'ToolBar and Sizer API enhancements') do
|
15
|
+
|
16
|
+
sizer = Wx::BoxSizer.new(Wx::VERTICAL)
|
17
|
+
|
18
|
+
button1 = Wx::Button.new(self, :label => 'Button 1')
|
19
|
+
button2 = Wx::Button.new(self, :label => 'Button 2')
|
20
|
+
button3 = Wx::Button.new(self, :label => 'Button 3')
|
21
|
+
|
22
|
+
# Sizer#add_item usage
|
23
|
+
# use of positional arguments
|
24
|
+
sizer.add_item(button1, -1, 1, Wx::EXPAND)
|
25
|
+
# use of a spacer
|
26
|
+
sizer.add_item([20, 15])
|
27
|
+
# use of keyword arguments without index
|
28
|
+
sizer.add_item(button3, :proportion => 1, :flag => Wx::EXPAND)
|
29
|
+
# use of keyword arguments with index specified
|
30
|
+
sizer.add_item(button2, :index => 1, :proportion => 1, :flag => Wx::EXPAND)
|
31
|
+
self.sizer = sizer
|
32
|
+
|
33
|
+
# ToolBar#add_item usage
|
34
|
+
toolbar = create_tool_bar( Wx::TB_HORIZONTAL|Wx::TB_FLAT )
|
35
|
+
# provide only a bitmap
|
36
|
+
new_item_id = toolbar.add_item( Wx::ArtProvider.bitmap(Wx::ART_NEW) )
|
37
|
+
# use of keyword arguments without pos
|
38
|
+
save_item_id = toolbar.add_item( Wx::ArtProvider.bitmap(Wx::ART_FILE_SAVE),
|
39
|
+
:short_help => "Save")
|
40
|
+
# use of keyword arguments with pos
|
41
|
+
open_item_id = toolbar.add_item( Wx::ArtProvider.bitmap(Wx::ART_FILE_OPEN),
|
42
|
+
:position => 1,
|
43
|
+
:short_help => "Open")
|
44
|
+
toolbar.realize
|
45
|
+
|
46
|
+
# tool item event handling
|
47
|
+
evt_tool new_item_id do
|
48
|
+
Wx::message_box "New clicked"
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
frame.show
|
54
|
+
end
|
55
|
+
|
data/samples/etc/wizard.rb
CHANGED
@@ -1,74 +1,74 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
|
3
|
-
# Freely reusable code: see SAMPLES-LICENSE.TXT for details
|
4
|
-
begin
|
5
|
-
require 'rubygems'
|
6
|
-
rescue LoadError
|
7
|
-
end
|
8
|
-
require 'wx'
|
9
|
-
|
10
|
-
|
11
|
-
class MyFrame < Wx::Frame
|
12
|
-
def initialize(title, pos, size)
|
13
|
-
super(nil, :title => title, :position => pos, :size => size)
|
14
|
-
|
15
|
-
menuFile = Wx::Menu.new
|
16
|
-
helpMenu = Wx::Menu.new
|
17
|
-
helpMenu.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
|
18
|
-
menuFile.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
|
19
|
-
menuBar = Wx::MenuBar.new
|
20
|
-
menuBar.append(menuFile, "&File")
|
21
|
-
menuBar.append(helpMenu, "&Help")
|
22
|
-
self.menu_bar = menuBar
|
23
|
-
|
24
|
-
create_status_bar(1)
|
25
|
-
self.status_text = "Welcome to wxRuby!"
|
26
|
-
s = Wx::StaticText.new(self, :label => 'The Wizard has completed')
|
27
|
-
evt_menu Wx::ID_EXIT, :on_quit
|
28
|
-
evt_menu Wx::ID_ABOUT, :on_about
|
29
|
-
|
30
|
-
w = Wx::Wizard.new(self, :title => 'The WxRuby Wizard')
|
31
|
-
p1 = Wx::WizardPageSimple.new(w)
|
32
|
-
s = Wx::StaticText.new(p1, :label => 'This is the first page')
|
33
|
-
|
34
|
-
p2 = Wx::WizardPageSimple.new(w, p1)
|
35
|
-
p1.set_next(p2)
|
36
|
-
s = Wx::StaticText.new(p2, :label => 'This is the second page')
|
37
|
-
|
38
|
-
p3 = Wx::WizardPageSimple.new(w, p2)
|
39
|
-
p2.set_next(p3)
|
40
|
-
s = Wx::StaticText.new(p3, :label => 'This is the final page')
|
41
|
-
|
42
|
-
evt_wizard_page_changed(w) { p "page changed" }
|
43
|
-
evt_wizard_page_changing(w) { p "page changing" }
|
44
|
-
evt_wizard_help(w) { p "wizard help" }
|
45
|
-
evt_wizard_cancel(w) { p "wizard cancelled" }
|
46
|
-
evt_wizard_finished(w) { p "wizard finished" }
|
47
|
-
|
48
|
-
w.run_wizard(p1)
|
49
|
-
end
|
50
|
-
|
51
|
-
def on_quit
|
52
|
-
close(true)
|
53
|
-
end
|
54
|
-
|
55
|
-
def on_about
|
56
|
-
msg = sprintf("This is the About dialog of the wizard sample.\n" \
|
57
|
-
"Welcome to %s", Wx::VERSION_STRING)
|
58
|
-
Wx::message_box(msg, "About Wizard", Wx::OK|Wx::ICON_INFORMATION, self)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
class RbApp < Wx::App
|
63
|
-
def on_init
|
64
|
-
frame = MyFrame.new("Wizard wxRuby App",
|
65
|
-
Wx::Point.new(50, 50),
|
66
|
-
Wx::Size.new(450, 340))
|
67
|
-
frame.show(true)
|
68
|
-
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
app = RbApp.new
|
73
|
-
app.main_loop()
|
74
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
|
3
|
+
# Freely reusable code: see SAMPLES-LICENSE.TXT for details
|
4
|
+
begin
|
5
|
+
require 'rubygems'
|
6
|
+
rescue LoadError
|
7
|
+
end
|
8
|
+
require 'wx'
|
9
|
+
|
10
|
+
|
11
|
+
class MyFrame < Wx::Frame
|
12
|
+
def initialize(title, pos, size)
|
13
|
+
super(nil, :title => title, :position => pos, :size => size)
|
14
|
+
|
15
|
+
menuFile = Wx::Menu.new
|
16
|
+
helpMenu = Wx::Menu.new
|
17
|
+
helpMenu.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
|
18
|
+
menuFile.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
|
19
|
+
menuBar = Wx::MenuBar.new
|
20
|
+
menuBar.append(menuFile, "&File")
|
21
|
+
menuBar.append(helpMenu, "&Help")
|
22
|
+
self.menu_bar = menuBar
|
23
|
+
|
24
|
+
create_status_bar(1)
|
25
|
+
self.status_text = "Welcome to wxRuby!"
|
26
|
+
s = Wx::StaticText.new(self, :label => 'The Wizard has completed')
|
27
|
+
evt_menu Wx::ID_EXIT, :on_quit
|
28
|
+
evt_menu Wx::ID_ABOUT, :on_about
|
29
|
+
|
30
|
+
w = Wx::Wizard.new(self, :title => 'The WxRuby Wizard')
|
31
|
+
p1 = Wx::WizardPageSimple.new(w)
|
32
|
+
s = Wx::StaticText.new(p1, :label => 'This is the first page')
|
33
|
+
|
34
|
+
p2 = Wx::WizardPageSimple.new(w, p1)
|
35
|
+
p1.set_next(p2)
|
36
|
+
s = Wx::StaticText.new(p2, :label => 'This is the second page')
|
37
|
+
|
38
|
+
p3 = Wx::WizardPageSimple.new(w, p2)
|
39
|
+
p2.set_next(p3)
|
40
|
+
s = Wx::StaticText.new(p3, :label => 'This is the final page')
|
41
|
+
|
42
|
+
evt_wizard_page_changed(w) { p "page changed" }
|
43
|
+
evt_wizard_page_changing(w) { p "page changing" }
|
44
|
+
evt_wizard_help(w) { p "wizard help" }
|
45
|
+
evt_wizard_cancel(w) { p "wizard cancelled" }
|
46
|
+
evt_wizard_finished(w) { p "wizard finished" }
|
47
|
+
|
48
|
+
w.run_wizard(p1)
|
49
|
+
end
|
50
|
+
|
51
|
+
def on_quit
|
52
|
+
close(true)
|
53
|
+
end
|
54
|
+
|
55
|
+
def on_about
|
56
|
+
msg = sprintf("This is the About dialog of the wizard sample.\n" \
|
57
|
+
"Welcome to %s", Wx::VERSION_STRING)
|
58
|
+
Wx::message_box(msg, "About Wizard", Wx::OK|Wx::ICON_INFORMATION, self)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class RbApp < Wx::App
|
63
|
+
def on_init
|
64
|
+
frame = MyFrame.new("Wizard wxRuby App",
|
65
|
+
Wx::Point.new(50, 50),
|
66
|
+
Wx::Size.new(450, 340))
|
67
|
+
frame.show(true)
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
app = RbApp.new
|
73
|
+
app.main_loop()
|
74
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
begin
|
3
|
+
require 'rubygems'
|
4
|
+
rescue LoadError
|
5
|
+
end
|
6
|
+
require 'wx'
|
7
|
+
|
8
|
+
# Demonstrating the use of evt_update_ui to keep menu items and controls
|
9
|
+
# in sync in being enabled/disabled, checked/unchecked.
|
10
|
+
#
|
11
|
+
# evt_update_ui is called repeatedly whenever the item is (or is about
|
12
|
+
# to become) visible; by calling methods on the passed event object, the
|
13
|
+
# state of the control is updated. For complex applications, this can be
|
14
|
+
# a lot simpler (less code, more reliable) than having to remember to
|
15
|
+
# update all the relevant controls and items whenever the state changes.
|
16
|
+
#
|
17
|
+
# In the example below, the application is globally in edit mode. This
|
18
|
+
# mode can be changed either from a menu item, or via a
|
19
|
+
# checkbox. Whichever is used to change, the state of the other should
|
20
|
+
# be kept in sync
|
21
|
+
class UpdateUIFrame < Wx::Frame
|
22
|
+
def initialize
|
23
|
+
super(nil, :title => 'Update UI example', :size => [ 400, 300 ])
|
24
|
+
@edit_mode = false
|
25
|
+
|
26
|
+
# First, set up the menus
|
27
|
+
self.menu_bar = Wx::MenuBar.new
|
28
|
+
menu_edit = Wx::Menu.new
|
29
|
+
|
30
|
+
# Toggle case-change menu item
|
31
|
+
menu_edit.append_check_item(Wx::ID_EDIT, 'Allow case change')
|
32
|
+
# When the item is called, toggle edit mode
|
33
|
+
evt_menu(Wx::ID_EDIT) { @edit_mode = ! @edit_mode }
|
34
|
+
# Give the menu item a check or not, depending on mode
|
35
|
+
evt_update_ui(Wx::ID_EDIT) { | evt | evt.check(@edit_mode) }
|
36
|
+
|
37
|
+
# Upcase menu item
|
38
|
+
up_case = menu_edit.append('Upper case')
|
39
|
+
evt_menu(up_case) { @txt.value = @txt.value.upcase }
|
40
|
+
evt_update_ui(up_case) { | evt | evt.enable(@edit_mode) }
|
41
|
+
|
42
|
+
# Lowercase menu item
|
43
|
+
up_case = menu_edit.append('Lower case')
|
44
|
+
evt_menu(up_case) { @txt.value = @txt.value.downcase }
|
45
|
+
evt_update_ui(up_case) { | evt | evt.enable(@edit_mode) }
|
46
|
+
|
47
|
+
menu_bar.append(menu_edit, "&Edit")
|
48
|
+
|
49
|
+
# Second, the frame contents
|
50
|
+
self.sizer = Wx::BoxSizer.new(Wx::VERTICAL)
|
51
|
+
|
52
|
+
# A text control
|
53
|
+
@txt = Wx::TextCtrl.new( self,
|
54
|
+
:value => 'Welcome to wxRuby',
|
55
|
+
:style => Wx::TE_MULTILINE )
|
56
|
+
sizer.add(@txt, 1, Wx::GROW|Wx::ALL, 5)
|
57
|
+
|
58
|
+
# A checkbox, use the Wx::ID_EDIT id to share evt code with the
|
59
|
+
# corresponding menu item
|
60
|
+
@cbx = Wx::CheckBox.new( self,
|
61
|
+
:id => Wx::ID_EDIT,
|
62
|
+
:label => 'Allow case change')
|
63
|
+
evt_checkbox(@cbx) { @edit_mode = ! @edit_mode }
|
64
|
+
|
65
|
+
sizer.add(@cbx, 0, Wx::RIGHT|Wx::ALL, 5)
|
66
|
+
sizer.layout
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
Wx::App.run { UpdateUIFrame.new.show }
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# wxRuby2 Sample Code. Copyright (c) 2004-
|
2
|
+
# wxRuby2 Sample Code. Copyright (c) 2004-2009 wxRuby development team
|
3
3
|
# Freely reusable code: see SAMPLES-LICENSE.TXT for details
|
4
4
|
begin
|
5
5
|
require 'rubygems'
|
@@ -24,9 +24,12 @@ class MyGridTable < Wx::GridTableBase
|
|
24
24
|
super()
|
25
25
|
@rows = rows
|
26
26
|
@cols = cols
|
27
|
-
@
|
27
|
+
@number_col = 1
|
28
28
|
end
|
29
29
|
|
30
|
+
# Letter labels for columns
|
31
|
+
COLS = ('AA' .. 'ZZ').to_a
|
32
|
+
|
30
33
|
# Firstly, a GridTableBase must indicate the size of the grid in
|
31
34
|
# terms of rows ...
|
32
35
|
def get_number_rows
|
@@ -41,9 +44,25 @@ class MyGridTable < Wx::GridTableBase
|
|
41
44
|
# Most importantly, it should be able to return any given cell's
|
42
45
|
# contents, given its row and column reference
|
43
46
|
def get_value(row, col)
|
44
|
-
|
47
|
+
if col == @number_col
|
48
|
+
(row * 5).to_s
|
49
|
+
else
|
50
|
+
"#{row}:#{COLS[col]}"
|
51
|
+
end
|
45
52
|
end
|
46
53
|
|
54
|
+
# This is not needed if the cell contents are simply strings. However,
|
55
|
+
# if you wish to use custom GridCellRenderers and/or GridCellEditors,
|
56
|
+
# this should return a type name which has the correct renderer /
|
57
|
+
# editor defined for it in the Grid, using register_
|
58
|
+
def get_type_name(row, col)
|
59
|
+
if col == @number_col
|
60
|
+
"NUMBER"
|
61
|
+
else
|
62
|
+
"STRING"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
47
66
|
# It should also return the attributes that should apply to any given
|
48
67
|
# cell; this example give alternate rows red text letters
|
49
68
|
def get_attr(row, col, attr_kind)
|
@@ -61,7 +80,7 @@ class MyGridTable < Wx::GridTableBase
|
|
61
80
|
|
62
81
|
# It may also provide labels for the columns and rows
|
63
82
|
def get_col_label_value(col)
|
64
|
-
|
83
|
+
COLS[col]
|
65
84
|
end
|
66
85
|
|
67
86
|
# If the Grid is to support write as well as read operations,
|
@@ -73,23 +92,27 @@ class MyGridTable < Wx::GridTableBase
|
|
73
92
|
end
|
74
93
|
end
|
75
94
|
|
76
|
-
# A derivative class illustrating that it is possible to change
|
77
|
-
# parameters of the GridTable and have the main control update.
|
78
|
-
class MyMutableGridTable < MyGridTable
|
79
|
-
def increment_value
|
80
|
-
@val = @val.succ
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
|
85
95
|
class GridFrame < Wx::Frame
|
86
96
|
def initialize()
|
87
|
-
super(nil, :title => 'GridTableBase demo')
|
88
|
-
main_sizer = Wx::
|
97
|
+
super(nil, :title => 'GridTableBase demo', :size => [600, 300])
|
98
|
+
main_sizer = Wx::VBoxSizer.new
|
89
99
|
# Create a grid and associate an instance of the GridTable as the
|
90
100
|
# data provider for the grid
|
91
101
|
@grid = Wx::Grid.new(self)
|
92
|
-
|
102
|
+
|
103
|
+
# Define the renderers and editors used by the different data types
|
104
|
+
# displayed in this Grid. The type of a given cell is determined by
|
105
|
+
# calling the source's get_type_name method; see above.
|
106
|
+
@grid.register_data_type( "STRING",
|
107
|
+
Wx::GridCellStringRenderer.new,
|
108
|
+
Wx::GridCellTextEditor.new )
|
109
|
+
@grid.register_data_type( "NUMBER",
|
110
|
+
Wx::GridCellNumberRenderer.new,
|
111
|
+
Wx::GridCellNumberEditor.new(0, 500) )
|
112
|
+
|
113
|
+
# Set the data source
|
114
|
+
@grid.table = MyGridTable.new(10, 10)
|
115
|
+
|
93
116
|
|
94
117
|
main_sizer.add(@grid, 1, Wx::EXPAND|Wx::ALL, 5)
|
95
118
|
|
@@ -100,29 +123,20 @@ class GridFrame < Wx::Frame
|
|
100
123
|
# When resizing the grid to have a new number of rows or columns,
|
101
124
|
# need to allocate a new grid table source
|
102
125
|
evt_button(butt_1) do
|
103
|
-
@grid.table =
|
104
|
-
|
126
|
+
@grid.table = MyGridTable.new( @grid.table.rows + 1,
|
127
|
+
@grid.table.cols)
|
105
128
|
@grid.refresh
|
106
129
|
end
|
107
130
|
butt_sizer.add(butt_1)
|
108
131
|
|
109
132
|
butt_2 = Wx::Button.new(self, :label => "Add column")
|
110
133
|
evt_button(butt_2) do
|
111
|
-
@grid.table =
|
112
|
-
|
134
|
+
@grid.table = MyGridTable.new( @grid.table.rows,
|
135
|
+
@grid.table.cols + 1)
|
113
136
|
@grid.refresh
|
114
137
|
end
|
115
138
|
butt_sizer.add(butt_2)
|
116
139
|
|
117
|
-
# For other changes, can just change a value in the existing
|
118
|
-
# GridTable
|
119
|
-
butt_3 = Wx::Button.new(self, :label => "Increment letter")
|
120
|
-
evt_button(butt_3) do
|
121
|
-
@grid.table.increment_value
|
122
|
-
@grid.refresh
|
123
|
-
end
|
124
|
-
butt_sizer.add(butt_3)
|
125
|
-
|
126
140
|
main_sizer.add(butt_sizer, 0, Wx::EXPAND|Wx::ALL, 5)
|
127
141
|
self.sizer = main_sizer
|
128
142
|
end
|
@@ -1,174 +1,174 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
|
3
|
-
# Freely reusable code: see SAMPLES-LICENSE.TXT for details
|
4
|
-
begin
|
5
|
-
require 'rubygems'
|
6
|
-
rescue LoadError
|
7
|
-
end
|
8
|
-
require 'wx'
|
9
|
-
|
10
|
-
# Basic Frame Class. This creates the dialog window
|
11
|
-
#
|
12
|
-
class SimpleFrame < Wx::Frame
|
13
|
-
|
14
|
-
FILE_DIALOG, FILE_ABOUT, FILE_QUIT = [0,Wx::ID_ABOUT,Wx::ID_EXIT]
|
15
|
-
|
16
|
-
def initialize(parent)
|
17
|
-
# To load a layout defined in XRC into a Ruby subclass of Frame,
|
18
|
-
# first call the empty constructor. All the details of size,
|
19
|
-
# title, position and so on are loaded from the XRC by the call to
|
20
|
-
# load_frame_subclass. Using a non-empty constructor will cause
|
21
|
-
# errors on GTK.
|
22
|
-
super()
|
23
|
-
$xml.load_frame_subclass(self,nil,'ID_FRAME')
|
24
|
-
|
25
|
-
# Create a new menu
|
26
|
-
bar = Wx::MenuBar.new
|
27
|
-
menu = Wx::Menu.new
|
28
|
-
menu.append(FILE_ABOUT,"About...")
|
29
|
-
menu.append_separator
|
30
|
-
menu.append(FILE_QUIT,"Quit")
|
31
|
-
bar.append(menu,"File")
|
32
|
-
|
33
|
-
set_menu_bar(bar)
|
34
|
-
|
35
|
-
# Assign the menu events
|
36
|
-
evt_menu(FILE_ABOUT) do
|
37
|
-
Wx::message_box("wxRuby Listbook sample\nby Sean Long", "About Listbook", Wx::OK | Wx::ICON_INFORMATION, self)
|
38
|
-
end
|
39
|
-
evt_menu(FILE_QUIT) do
|
40
|
-
Wx::get_app.exit_main_loop()
|
41
|
-
end
|
42
|
-
evt_close() do
|
43
|
-
Wx::get_app.exit_main_loop()
|
44
|
-
end
|
45
|
-
|
46
|
-
# Variables not in tabs
|
47
|
-
@listbook = xrcid_to_window('ID_LISTBOOK')
|
48
|
-
@text_output = xrcid_to_window('ID_ORDER_TEXTCTRL')
|
49
|
-
|
50
|
-
# Variables for widgets in Pizza tab
|
51
|
-
@pizza_size = xrcid_to_window('ID_PIZZA_SIZE_CHOICE')
|
52
|
-
@pizza_crust = xrcid_to_window('ID_PIZZA_CRUST_CHOICE')
|
53
|
-
@pizza_sauce = xrcid_to_window('ID_PIZZA_SAUCE_CHOICE')
|
54
|
-
@pizza_cheese = xrcid_to_window('ID_PIZZA_CHEESE_CHOICE')
|
55
|
-
@pizza_toppings = []
|
56
|
-
3.times do |i|
|
57
|
-
@pizza_toppings << xrcid_to_window("ID_PIZZA_TOPPING_#{i+1}_CHOICE")
|
58
|
-
end
|
59
|
-
|
60
|
-
# fill in toppings
|
61
|
-
toppings = ['pepperoni','sausage','italian sausage','olives',
|
62
|
-
'mushrooms','artichoke','extra cheese','']
|
63
|
-
toppings.each do |top_name|
|
64
|
-
@pizza_toppings.each do |top_obj|
|
65
|
-
top_obj.append(top_name)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
index = 0
|
70
|
-
@pizza_toppings.each do |obj|
|
71
|
-
obj.set_selection(index)
|
72
|
-
index += 1
|
73
|
-
end
|
74
|
-
|
75
|
-
# Events for pizza tab
|
76
|
-
evt_button( Wx::xrcid('ID_PIZZA_BUTTON') ) do |event|
|
77
|
-
#get selections and add to order
|
78
|
-
order_string = @text_output.get_value
|
79
|
-
if order_string != "" then order_string << "\n" end
|
80
|
-
order_string << "One #{@pizza_size.get_string_selection} pizza with:\n"
|
81
|
-
order_string << @pizza_crust.get_string_selection + " crust" + "\n"
|
82
|
-
order_string << @pizza_sauce.get_string_selection + " sauce" +"\n"
|
83
|
-
order_string << @pizza_cheese.get_string_selection + " and" + "\n"
|
84
|
-
@pizza_toppings.each { |obj| order_string << obj.get_string_selection + "\n" }
|
85
|
-
|
86
|
-
@text_output.set_value(order_string)
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
# Variables for widgets in Drink tab
|
91
|
-
@drink_size = xrcid_to_window('ID_DRINK_SIZE_CHOICE')
|
92
|
-
@drink_type = xrcid_to_window('ID_DRINK_TYPE_CHOICE')
|
93
|
-
|
94
|
-
# Events for drink tab
|
95
|
-
evt_button(Wx::xrcid('ID_DRINK_BUTTON')) do |event|
|
96
|
-
#get selections and add to order
|
97
|
-
order_string = @text_output.get_value
|
98
|
-
if order_string != "" then order_string << "\n" end
|
99
|
-
|
100
|
-
order_string << "One #{@drink_size.get_string_selection} #{@drink_type.get_string_selection }.\n"
|
101
|
-
|
102
|
-
@text_output.set_value(order_string)
|
103
|
-
end
|
104
|
-
|
105
|
-
# Variables for widgets in Ice Cream tab
|
106
|
-
@ice_cream_size = xrcid_to_window('ID_ICE_CREAM_SIZE_CHOICE')
|
107
|
-
@ice_cream_type = xrcid_to_window('ID_ICE_CREAM_TYPE_CHOICE')
|
108
|
-
@ice_cream_toppings = []
|
109
|
-
4.times do |i|
|
110
|
-
@ice_cream_toppings <<
|
111
|
-
xrcid_to_window("ID_ICE_CREAM_TOPPING_#{i+1}_CHOICE")
|
112
|
-
end
|
113
|
-
|
114
|
-
toppings = ['','m&m\'s','chocolate chips','fudge','nuts','cherry','whip cream']
|
115
|
-
toppings.each do |top_name|
|
116
|
-
@ice_cream_toppings.each do |top_obj|
|
117
|
-
top_obj.append(top_name)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
@ice_cream_toppings.each { |obj| obj.set_selection(0) }
|
121
|
-
|
122
|
-
# Events for ice cream tab
|
123
|
-
evt_button(Wx::xrcid('ID_ICE_CREAM_BUTTON')) do |event|
|
124
|
-
#get selections and add to order
|
125
|
-
order_string = @text_output.get_value
|
126
|
-
if order_string != "" then order_string << "\n" end
|
127
|
-
|
128
|
-
order_string << "One #{@ice_cream_size.get_string_selection} #{@ice_cream_type.get_string_selection} ice cream:\n"
|
129
|
-
@ice_cream_toppings.each { |obj| order_string << obj.get_string_selection + "\n" }
|
130
|
-
|
131
|
-
@text_output.set_value(order_string)
|
132
|
-
end
|
133
|
-
|
134
|
-
evt_listbook_page_changed(Wx::xrcid('ID_LISTBOOK')) do |event|
|
135
|
-
tab_number = event.get_selection
|
136
|
-
order_string = @text_output.get_value
|
137
|
-
order_string << "moved to tab = #{@listbook.get_page_text(tab_number)} \n"
|
138
|
-
@text_output.set_value(order_string)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
# Converts a XRCID id - as used in wxWidget's XML format - into the
|
143
|
-
# correct ruby window
|
144
|
-
def xrcid_to_window(xrc_id)
|
145
|
-
Wx::Window.find_window_by_id(Wx::xrcid(xrc_id), self)
|
146
|
-
end
|
147
|
-
|
148
|
-
end
|
149
|
-
|
150
|
-
#
|
151
|
-
# Application class.
|
152
|
-
#
|
153
|
-
class XrcApp < Wx::App
|
154
|
-
|
155
|
-
def on_init
|
156
|
-
# Create a resource handler
|
157
|
-
$xml = Wx::XmlResource.get();
|
158
|
-
$xml.init_all_handlers();
|
159
|
-
|
160
|
-
# Load a resource file from the script's directory
|
161
|
-
xrc_file = File.join( File.dirname( __FILE__ ), 'listbook.xrc' )
|
162
|
-
|
163
|
-
$xml.load(xrc_file)
|
164
|
-
|
165
|
-
|
166
|
-
# Show the main frame.
|
167
|
-
$main = SimpleFrame.new(self)
|
168
|
-
$main.show(true)
|
169
|
-
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
|
174
|
-
XrcApp.new().main_loop()
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
|
3
|
+
# Freely reusable code: see SAMPLES-LICENSE.TXT for details
|
4
|
+
begin
|
5
|
+
require 'rubygems'
|
6
|
+
rescue LoadError
|
7
|
+
end
|
8
|
+
require 'wx'
|
9
|
+
|
10
|
+
# Basic Frame Class. This creates the dialog window
|
11
|
+
#
|
12
|
+
class SimpleFrame < Wx::Frame
|
13
|
+
|
14
|
+
FILE_DIALOG, FILE_ABOUT, FILE_QUIT = [0,Wx::ID_ABOUT,Wx::ID_EXIT]
|
15
|
+
|
16
|
+
def initialize(parent)
|
17
|
+
# To load a layout defined in XRC into a Ruby subclass of Frame,
|
18
|
+
# first call the empty constructor. All the details of size,
|
19
|
+
# title, position and so on are loaded from the XRC by the call to
|
20
|
+
# load_frame_subclass. Using a non-empty constructor will cause
|
21
|
+
# errors on GTK.
|
22
|
+
super()
|
23
|
+
$xml.load_frame_subclass(self,nil,'ID_FRAME')
|
24
|
+
|
25
|
+
# Create a new menu
|
26
|
+
bar = Wx::MenuBar.new
|
27
|
+
menu = Wx::Menu.new
|
28
|
+
menu.append(FILE_ABOUT,"About...")
|
29
|
+
menu.append_separator
|
30
|
+
menu.append(FILE_QUIT,"Quit")
|
31
|
+
bar.append(menu,"File")
|
32
|
+
|
33
|
+
set_menu_bar(bar)
|
34
|
+
|
35
|
+
# Assign the menu events
|
36
|
+
evt_menu(FILE_ABOUT) do
|
37
|
+
Wx::message_box("wxRuby Listbook sample\nby Sean Long", "About Listbook", Wx::OK | Wx::ICON_INFORMATION, self)
|
38
|
+
end
|
39
|
+
evt_menu(FILE_QUIT) do
|
40
|
+
Wx::get_app.exit_main_loop()
|
41
|
+
end
|
42
|
+
evt_close() do
|
43
|
+
Wx::get_app.exit_main_loop()
|
44
|
+
end
|
45
|
+
|
46
|
+
# Variables not in tabs
|
47
|
+
@listbook = xrcid_to_window('ID_LISTBOOK')
|
48
|
+
@text_output = xrcid_to_window('ID_ORDER_TEXTCTRL')
|
49
|
+
|
50
|
+
# Variables for widgets in Pizza tab
|
51
|
+
@pizza_size = xrcid_to_window('ID_PIZZA_SIZE_CHOICE')
|
52
|
+
@pizza_crust = xrcid_to_window('ID_PIZZA_CRUST_CHOICE')
|
53
|
+
@pizza_sauce = xrcid_to_window('ID_PIZZA_SAUCE_CHOICE')
|
54
|
+
@pizza_cheese = xrcid_to_window('ID_PIZZA_CHEESE_CHOICE')
|
55
|
+
@pizza_toppings = []
|
56
|
+
3.times do |i|
|
57
|
+
@pizza_toppings << xrcid_to_window("ID_PIZZA_TOPPING_#{i+1}_CHOICE")
|
58
|
+
end
|
59
|
+
|
60
|
+
# fill in toppings
|
61
|
+
toppings = ['pepperoni','sausage','italian sausage','olives',
|
62
|
+
'mushrooms','artichoke','extra cheese','']
|
63
|
+
toppings.each do |top_name|
|
64
|
+
@pizza_toppings.each do |top_obj|
|
65
|
+
top_obj.append(top_name)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
index = 0
|
70
|
+
@pizza_toppings.each do |obj|
|
71
|
+
obj.set_selection(index)
|
72
|
+
index += 1
|
73
|
+
end
|
74
|
+
|
75
|
+
# Events for pizza tab
|
76
|
+
evt_button( Wx::xrcid('ID_PIZZA_BUTTON') ) do |event|
|
77
|
+
#get selections and add to order
|
78
|
+
order_string = @text_output.get_value
|
79
|
+
if order_string != "" then order_string << "\n" end
|
80
|
+
order_string << "One #{@pizza_size.get_string_selection} pizza with:\n"
|
81
|
+
order_string << @pizza_crust.get_string_selection + " crust" + "\n"
|
82
|
+
order_string << @pizza_sauce.get_string_selection + " sauce" +"\n"
|
83
|
+
order_string << @pizza_cheese.get_string_selection + " and" + "\n"
|
84
|
+
@pizza_toppings.each { |obj| order_string << obj.get_string_selection + "\n" }
|
85
|
+
|
86
|
+
@text_output.set_value(order_string)
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
# Variables for widgets in Drink tab
|
91
|
+
@drink_size = xrcid_to_window('ID_DRINK_SIZE_CHOICE')
|
92
|
+
@drink_type = xrcid_to_window('ID_DRINK_TYPE_CHOICE')
|
93
|
+
|
94
|
+
# Events for drink tab
|
95
|
+
evt_button(Wx::xrcid('ID_DRINK_BUTTON')) do |event|
|
96
|
+
#get selections and add to order
|
97
|
+
order_string = @text_output.get_value
|
98
|
+
if order_string != "" then order_string << "\n" end
|
99
|
+
|
100
|
+
order_string << "One #{@drink_size.get_string_selection} #{@drink_type.get_string_selection }.\n"
|
101
|
+
|
102
|
+
@text_output.set_value(order_string)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Variables for widgets in Ice Cream tab
|
106
|
+
@ice_cream_size = xrcid_to_window('ID_ICE_CREAM_SIZE_CHOICE')
|
107
|
+
@ice_cream_type = xrcid_to_window('ID_ICE_CREAM_TYPE_CHOICE')
|
108
|
+
@ice_cream_toppings = []
|
109
|
+
4.times do |i|
|
110
|
+
@ice_cream_toppings <<
|
111
|
+
xrcid_to_window("ID_ICE_CREAM_TOPPING_#{i+1}_CHOICE")
|
112
|
+
end
|
113
|
+
|
114
|
+
toppings = ['','m&m\'s','chocolate chips','fudge','nuts','cherry','whip cream']
|
115
|
+
toppings.each do |top_name|
|
116
|
+
@ice_cream_toppings.each do |top_obj|
|
117
|
+
top_obj.append(top_name)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
@ice_cream_toppings.each { |obj| obj.set_selection(0) }
|
121
|
+
|
122
|
+
# Events for ice cream tab
|
123
|
+
evt_button(Wx::xrcid('ID_ICE_CREAM_BUTTON')) do |event|
|
124
|
+
#get selections and add to order
|
125
|
+
order_string = @text_output.get_value
|
126
|
+
if order_string != "" then order_string << "\n" end
|
127
|
+
|
128
|
+
order_string << "One #{@ice_cream_size.get_string_selection} #{@ice_cream_type.get_string_selection} ice cream:\n"
|
129
|
+
@ice_cream_toppings.each { |obj| order_string << obj.get_string_selection + "\n" }
|
130
|
+
|
131
|
+
@text_output.set_value(order_string)
|
132
|
+
end
|
133
|
+
|
134
|
+
evt_listbook_page_changed(Wx::xrcid('ID_LISTBOOK')) do |event|
|
135
|
+
tab_number = event.get_selection
|
136
|
+
order_string = @text_output.get_value
|
137
|
+
order_string << "moved to tab = #{@listbook.get_page_text(tab_number)} \n"
|
138
|
+
@text_output.set_value(order_string)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# Converts a XRCID id - as used in wxWidget's XML format - into the
|
143
|
+
# correct ruby window
|
144
|
+
def xrcid_to_window(xrc_id)
|
145
|
+
Wx::Window.find_window_by_id(Wx::xrcid(xrc_id), self)
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
#
|
151
|
+
# Application class.
|
152
|
+
#
|
153
|
+
class XrcApp < Wx::App
|
154
|
+
|
155
|
+
def on_init
|
156
|
+
# Create a resource handler
|
157
|
+
$xml = Wx::XmlResource.get();
|
158
|
+
$xml.init_all_handlers();
|
159
|
+
|
160
|
+
# Load a resource file from the script's directory
|
161
|
+
xrc_file = File.join( File.dirname( __FILE__ ), 'listbook.xrc' )
|
162
|
+
|
163
|
+
$xml.load(xrc_file)
|
164
|
+
|
165
|
+
|
166
|
+
# Show the main frame.
|
167
|
+
$main = SimpleFrame.new(self)
|
168
|
+
$main.show(true)
|
169
|
+
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
XrcApp.new().main_loop()
|