wxruby-ruby19 1.9.8-x86-darwin-9 → 1.9.10-x86-darwin-9
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +53 -0
- data/README +297 -0
- data/lib/wx.rb +2 -2
- data/lib/wx/accessors.rb +7 -1
- data/lib/wx/classes/app.rb +10 -4
- 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 +79 -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 +63 -0
- data/lib/wx/classes/size.rb +9 -0
- data/lib/wx/classes/sizer.rb +18 -3
- data/lib/wx/classes/standardpaths.rb +9 -0
- data/lib/wx/classes/texturlevent.rb +14 -2
- 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 +56 -5
- data/lib/wx/version.rb +1 -1
- data/lib/wxruby2.bundle +0 -0
- data/samples/SAMPLES-LICENSE.TXT +18 -0
- data/samples/aui/aui.rb +1356 -0
- data/samples/bigdemo/About.rbw +39 -0
- data/samples/bigdemo/ColorPanel.rbw +23 -0
- data/samples/bigdemo/GridSimple.rbw +78 -0
- data/samples/bigdemo/MDIDemo.rbw +57 -0
- data/samples/bigdemo/PopupMenu.rbw +149 -0
- data/samples/bigdemo/ShapedWindow.rbw +131 -0
- data/samples/bigdemo/Sizers.rbw +543 -0
- data/samples/bigdemo/bigdemo.rb +823 -0
- data/samples/bigdemo/demoTemplate.rbw +33 -0
- data/samples/bigdemo/helpfile.htb +0 -0
- data/samples/bigdemo/icons/Test 015.jpg +0 -0
- data/samples/bigdemo/icons/Test 015.png +0 -0
- data/samples/bigdemo/icons/choice.bmp +0 -0
- data/samples/bigdemo/icons/choice.xpm +27 -0
- data/samples/bigdemo/icons/combo.bmp +0 -0
- data/samples/bigdemo/icons/combo.xpm +27 -0
- data/samples/bigdemo/icons/copy.xpm +25 -0
- data/samples/bigdemo/icons/cut.xpm +24 -0
- data/samples/bigdemo/icons/gauge.bmp +0 -0
- data/samples/bigdemo/icons/gauge.xpm +27 -0
- data/samples/bigdemo/icons/help.xpm +25 -0
- data/samples/bigdemo/icons/list.bmp +0 -0
- data/samples/bigdemo/icons/list.xpm +27 -0
- data/samples/bigdemo/icons/mondrian.ico +0 -0
- data/samples/bigdemo/icons/mondrian.xpm +44 -0
- data/samples/bigdemo/icons/new.xpm +24 -0
- data/samples/bigdemo/icons/ogl.ico +0 -0
- data/samples/bigdemo/icons/ogl.xpm +45 -0
- data/samples/bigdemo/icons/open.xpm +26 -0
- data/samples/bigdemo/icons/paste.bmp +0 -0
- data/samples/bigdemo/icons/paste.xpm +38 -0
- data/samples/bigdemo/icons/pointy.png +0 -0
- data/samples/bigdemo/icons/preview.xpm +26 -0
- data/samples/bigdemo/icons/print.xpm +26 -0
- data/samples/bigdemo/icons/radio.bmp +0 -0
- data/samples/bigdemo/icons/radio.xpm +27 -0
- data/samples/bigdemo/icons/robert.xpm +415 -0
- data/samples/bigdemo/icons/ruby.png +0 -0
- data/samples/bigdemo/icons/sashtest.ico +0 -0
- data/samples/bigdemo/icons/save.xpm +25 -0
- data/samples/bigdemo/icons/smiles.bmp +0 -0
- data/samples/bigdemo/icons/smiles.xpm +39 -0
- data/samples/bigdemo/icons/smiley.ico +0 -0
- data/samples/bigdemo/icons/smiley.xpm +42 -0
- data/samples/bigdemo/icons/stattext.xpm +24 -0
- data/samples/bigdemo/icons/test2.bmp +0 -0
- data/samples/bigdemo/icons/test2.png +0 -0
- data/samples/bigdemo/icons/test2.xpm +79 -0
- data/samples/bigdemo/icons/text.bmp +0 -0
- data/samples/bigdemo/icons/text.xpm +27 -0
- data/samples/bigdemo/icons/tog1.bmp +0 -0
- data/samples/bigdemo/icons/tog1.xpm +38 -0
- data/samples/bigdemo/icons/tog2.bmp +0 -0
- data/samples/bigdemo/icons/tog2.xpm +38 -0
- data/samples/bigdemo/icons/wxwin.ico +0 -0
- data/samples/bigdemo/icons/wxwin16x16.png +0 -0
- data/samples/bigdemo/icons/wxwin16x16.xpm +25 -0
- data/samples/bigdemo/icons/wxwin32x32.png +0 -0
- data/samples/bigdemo/icons/wxwin48x48.png +0 -0
- data/samples/bigdemo/run.rb +90 -0
- data/samples/bigdemo/tips.txt +7 -0
- data/samples/bigdemo/utils.rb +12 -0
- data/samples/bigdemo/wxArtProvider.rbw +281 -0
- data/samples/bigdemo/wxBitmapButton.rbw +65 -0
- data/samples/bigdemo/wxButton.rbw +64 -0
- data/samples/bigdemo/wxCalendarCtrl.rbw +60 -0
- data/samples/bigdemo/wxCheckBox.rbw +50 -0
- data/samples/bigdemo/wxCheckListBox.rbw +65 -0
- data/samples/bigdemo/wxChoice.rbw +47 -0
- data/samples/bigdemo/wxChoicebook.rbw +78 -0
- data/samples/bigdemo/wxColourDialog.rbw +31 -0
- data/samples/bigdemo/wxComboBox.rbw +77 -0
- data/samples/bigdemo/wxCursor.rbw +136 -0
- data/samples/bigdemo/wxDialog.rbw +74 -0
- data/samples/bigdemo/wxDirDialog.rbw +29 -0
- data/samples/bigdemo/wxDragImage.rbw +70 -0
- data/samples/bigdemo/wxFileDialog.rbw +37 -0
- data/samples/bigdemo/wxFileDialog_Save.rbw +35 -0
- data/samples/bigdemo/wxFindReplaceDialog.rbw +82 -0
- data/samples/bigdemo/wxFontDialog.rbw +173 -0
- data/samples/bigdemo/wxFrame.rbw +53 -0
- data/samples/bigdemo/wxGauge.rbw +71 -0
- data/samples/bigdemo/wxGenericDirCtrl.rbw +74 -0
- data/samples/bigdemo/wxGrid.rbw +66 -0
- data/samples/bigdemo/wxHtmlHelpController.rbw +52 -0
- data/samples/bigdemo/wxListBox.rbw +140 -0
- data/samples/bigdemo/wxListCtrl_virtual.rbw +112 -0
- data/samples/bigdemo/wxMDIWindows.rbw +50 -0
- data/samples/bigdemo/wxMenu.rbw +236 -0
- data/samples/bigdemo/wxMessageDialog.rbw +27 -0
- data/samples/bigdemo/wxMiniFrame.rbw +70 -0
- data/samples/bigdemo/wxMultipleChoiceDialog.rbw +32 -0
- data/samples/bigdemo/wxNotebook.rbw +136 -0
- data/samples/bigdemo/wxProgressDialog.rbw +43 -0
- data/samples/bigdemo/wxRadioBox.rbw +72 -0
- data/samples/bigdemo/wxRadioButton.rbw +125 -0
- data/samples/bigdemo/wxSashWindow.rbw +141 -0
- data/samples/bigdemo/wxScrolledMessageDialog.rbw +57 -0
- data/samples/bigdemo/wxScrolledWindow.rbw +199 -0
- data/samples/bigdemo/wxSingleChoiceDialog.rbw +33 -0
- data/samples/bigdemo/wxSlider.rbw +42 -0
- data/samples/bigdemo/wxSpinButton.rbw +50 -0
- data/samples/bigdemo/wxSpinCtrl.rbw +51 -0
- data/samples/bigdemo/wxSplitterWindow.rbw +63 -0
- data/samples/bigdemo/wxStaticBitmap.rbw +51 -0
- data/samples/bigdemo/wxStaticText.rbw +55 -0
- data/samples/bigdemo/wxStatusBar.rbw +126 -0
- data/samples/bigdemo/wxTextCtrl.rbw +149 -0
- data/samples/bigdemo/wxTextEntryDialog.rbw +31 -0
- data/samples/bigdemo/wxToggleButton.rbw +49 -0
- data/samples/bigdemo/wxToolBar.rbw +131 -0
- data/samples/bigdemo/wxTreeCtrl.rbw +191 -0
- data/samples/calendar/calendar.rb +256 -0
- data/samples/caret/caret.rb +282 -0
- data/samples/caret/mondrian.xpm +44 -0
- data/samples/controls/controls.rb +1136 -0
- data/samples/controls/get_item_sample.rb +87 -0
- data/samples/controls/icons/choice.xpm +27 -0
- data/samples/controls/icons/combo.xpm +27 -0
- data/samples/controls/icons/gauge.xpm +27 -0
- data/samples/controls/icons/list.xpm +27 -0
- data/samples/controls/icons/radio.xpm +27 -0
- data/samples/controls/icons/stattext.xpm +24 -0
- data/samples/controls/icons/text.xpm +27 -0
- data/samples/controls/mondrian.ico +0 -0
- data/samples/controls/mondrian.xpm +44 -0
- data/samples/controls/test2.bmp +0 -0
- data/samples/dialogs/dialogs.rb +797 -0
- data/samples/dialogs/tips.txt +18 -0
- data/samples/dragdrop/dragdrop.rb +177 -0
- data/samples/drawing/graphics_drawing.rb +235 -0
- data/samples/drawing/images.rb +37 -0
- data/samples/drawing/paperclip.png +0 -0
- data/samples/etc/activation.rb +102 -0
- data/samples/etc/choice.rb +67 -0
- data/samples/etc/miniframe.rb +79 -0
- data/samples/etc/sash.rb +130 -0
- data/samples/etc/scrollwin.rb +110 -0
- data/samples/etc/system_settings.rb +252 -0
- data/samples/etc/threaded.rb +72 -0
- data/samples/etc/toolbar_sizer_additem.rb +55 -0
- data/samples/etc/wizard.rb +74 -0
- data/samples/event/event.rb +182 -0
- data/samples/event/update_ui_event.rb +70 -0
- data/samples/grid/grid.rb +198 -0
- data/samples/grid/gridtablebase.rb +148 -0
- data/samples/html/html.rb +262 -0
- data/samples/listbook/listbook.rb +174 -0
- data/samples/listbook/listbook.xrc +370 -0
- data/samples/mdi/mdi.rb +85 -0
- data/samples/media/mediactrl.rb +167 -0
- data/samples/minimal/minimal.rb +77 -0
- data/samples/minimal/mondrian.ico +0 -0
- data/samples/minimal/mondrian.png +0 -0
- data/samples/minimal/nothing.rb +16 -0
- data/samples/opengl/cube.rb +117 -0
- data/samples/printing/mondrian.ico +0 -0
- data/samples/printing/mondrian.xpm +44 -0
- data/samples/printing/printing.rb +487 -0
- data/samples/sockets/SocketPackets.rb +27 -0
- data/samples/sockets/res/message-new.png +0 -0
- data/samples/sockets/res/user.png +0 -0
- data/samples/sockets/wxClient.rb +395 -0
- data/samples/sockets/wxServer.rb +422 -0
- data/samples/sockets/wxSocketGUI.rb +97 -0
- 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/mondrian.ico +0 -0
- data/samples/text/mondrian.xpm +44 -0
- data/samples/text/rich_textctrl.rb +98 -0
- data/samples/text/scintilla.rb +169 -0
- data/samples/text/textctrl.rb +111 -0
- data/samples/text/unicode.rb +242 -0
- data/samples/text/utf8.txt +15 -0
- data/samples/treectrl/icon1.xpm +79 -0
- data/samples/treectrl/icon2.xpm +53 -0
- data/samples/treectrl/icon3.xpm +79 -0
- data/samples/treectrl/icon4.xpm +43 -0
- data/samples/treectrl/icon5.xpm +79 -0
- data/samples/treectrl/treectrl.rb +1166 -0
- data/samples/xrc/samples.xrc +46 -0
- data/samples/xrc/xrc_sample.rb +76 -0
- metadata +17 -3
@@ -0,0 +1,182 @@
|
|
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
|
+
# This sample demonstrates how to dynamically connect and disconnect
|
11
|
+
# event handlers, and how to create custom event types and listeners
|
12
|
+
# associated with user-defined control classes.
|
13
|
+
|
14
|
+
# A custom type of event associated with a target control. Note that for
|
15
|
+
# user-defined controls, the associated event should inherit from
|
16
|
+
# Wx::CommandEvent rather than Wx::Event.
|
17
|
+
class TargetHitEvent < Wx::CommandEvent
|
18
|
+
# Create a new unique constant identifier, associate this class
|
19
|
+
# with events of that identifier, and create a shortcut 'evt_target'
|
20
|
+
# method for setting up this handler.
|
21
|
+
EVT_HIT_TARGET = Wx::EvtHandler.register_class(self, nil, 'evt_target', 1)
|
22
|
+
|
23
|
+
def initialize(target, score, distance)
|
24
|
+
# The constant id is the arg to super
|
25
|
+
super(EVT_HIT_TARGET)
|
26
|
+
# client_data should be used to store any information associated
|
27
|
+
# with the event.
|
28
|
+
self.client_data = { :score => score, :distance => distance }
|
29
|
+
self.id = target.get_id
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns the points score associated with this event
|
33
|
+
def score
|
34
|
+
client_data[:score]
|
35
|
+
end
|
36
|
+
|
37
|
+
# Returns the distance (in pixels) from the centre of the target
|
38
|
+
def distance
|
39
|
+
client_data[:distance]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# An example of a simple user-written control, which displays a
|
44
|
+
# "bulls-eye" like target, and sends events with a score and distance
|
45
|
+
class TargetControl < Wx::Window
|
46
|
+
TargetCircle = Struct.new(:radius, :score, :brush)
|
47
|
+
|
48
|
+
def initialize(parent, *args)
|
49
|
+
super(parent, *args)
|
50
|
+
|
51
|
+
# Set up the scores and sizes of the rings
|
52
|
+
@radii = [
|
53
|
+
TargetCircle[ 0.1, 20, Wx::RED_BRUSH ],
|
54
|
+
TargetCircle[ 0.25, 10, Wx::BLUE_BRUSH ],
|
55
|
+
TargetCircle[ 0.4, 5, Wx::GREEN_BRUSH ] ]
|
56
|
+
evt_paint { | e | on_paint(e) }
|
57
|
+
evt_left_down { | e | on_left_down(e) }
|
58
|
+
end
|
59
|
+
|
60
|
+
# What point is at the centre (assuming this control is always square)
|
61
|
+
def centre_point
|
62
|
+
size.width / 2
|
63
|
+
end
|
64
|
+
|
65
|
+
# Called whenever the target is repainted, draws a series of
|
66
|
+
# concentric circles
|
67
|
+
def on_paint(evt)
|
68
|
+
paint do | dc |
|
69
|
+
dc.clear
|
70
|
+
@radii.reverse_each do | circ |
|
71
|
+
dc.brush = circ.brush
|
72
|
+
dc.draw_circle(centre_point, centre_point,
|
73
|
+
( size.width * circ.radius).to_i )
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Test if the target was hit, and generate a TargetHitEvent if so
|
79
|
+
def on_left_down(evt)
|
80
|
+
# quick bit of pythagoras...
|
81
|
+
distance = Math.sqrt( ( evt.x - centre_point ) ** 2 +
|
82
|
+
( evt.y - centre_point ) ** 2 )
|
83
|
+
# See which target ring, if any, was hit by the event
|
84
|
+
@radii.each do | circ |
|
85
|
+
if distance < ( size.width * circ.radius)
|
86
|
+
# Create an instance of the event
|
87
|
+
evt = TargetHitEvent.new(self, circ.score, distance)
|
88
|
+
# This sends the event for processing by listeners
|
89
|
+
event_handler.process_event(evt)
|
90
|
+
break
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Container frame for the target control
|
97
|
+
class TargetFrame < Wx::Frame
|
98
|
+
def initialize(title)
|
99
|
+
super(nil, :title => title, :size => [300, 300])
|
100
|
+
@tgt = TargetControl.new(self)
|
101
|
+
# This user-defined event handling method was set up by
|
102
|
+
# EvtHandler.register_class, above
|
103
|
+
evt_target(@tgt.get_id) { | e | on_target(e) }
|
104
|
+
@listening = true
|
105
|
+
evt_size { | e | on_size(e) }
|
106
|
+
setup_menus
|
107
|
+
create_status_bar
|
108
|
+
end
|
109
|
+
|
110
|
+
# What's done when the target is hit
|
111
|
+
def on_target(evt)
|
112
|
+
msg = "Target hit for score %i, %.2f pixels from centre" %
|
113
|
+
[ evt.score, evt.distance ]
|
114
|
+
self.status_text = msg
|
115
|
+
end
|
116
|
+
|
117
|
+
# Keep the target centred and square
|
118
|
+
def on_size(evt)
|
119
|
+
smaller = [ evt.size.width, evt.size.height ].min
|
120
|
+
@tgt.centre
|
121
|
+
@tgt.size = Wx::Size.new(smaller, smaller)
|
122
|
+
@tgt.refresh
|
123
|
+
end
|
124
|
+
|
125
|
+
# Toggle whether or not we are listening for events from the bulls-eye
|
126
|
+
# target
|
127
|
+
def on_toggle_connect
|
128
|
+
if @listening
|
129
|
+
# Remove :evt_target event handler for the @tgt
|
130
|
+
disconnect(@tgt.get_id, Wx::ID_ANY, :evt_target)
|
131
|
+
menu_bar.check(TOGGLE_LISTEN, false)
|
132
|
+
self.status_text = "Ignoring target events"
|
133
|
+
@listening = false
|
134
|
+
else
|
135
|
+
# Restore evt_target event handler for the @tgt
|
136
|
+
evt_target(@tgt.get_id) { | e | on_target(e) }
|
137
|
+
menu_bar.check(TOGGLE_LISTEN, true)
|
138
|
+
self.status_text = ''
|
139
|
+
@listening = true
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def on_about
|
144
|
+
msg = sprintf("This is the About dialog of the event handling sample.\n" \
|
145
|
+
"Welcome to wxRuby, version %s", Wx::WXRUBY_VERSION)
|
146
|
+
|
147
|
+
about_dlg = Wx::MessageDialog.new( self, msg, 'About Event Handling',
|
148
|
+
Wx::OK|Wx::ICON_INFORMATION )
|
149
|
+
about_dlg.show_modal
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
TOGGLE_LISTEN = 1001
|
154
|
+
def setup_menus
|
155
|
+
menu_file = Wx::Menu.new
|
156
|
+
menu_help = Wx::Menu.new
|
157
|
+
menu_help.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
|
158
|
+
evt_menu(Wx::ID_ABOUT) { on_about }
|
159
|
+
menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
|
160
|
+
evt_menu(Wx::ID_EXIT) { self.close }
|
161
|
+
menu_file.append_check_item(TOGGLE_LISTEN, "L&isten for events",
|
162
|
+
"Toggle listening for target events")
|
163
|
+
evt_menu(TOGGLE_LISTEN) { on_toggle_connect }
|
164
|
+
|
165
|
+
menu_bar = Wx::MenuBar.new
|
166
|
+
menu_bar.append(menu_file, "&File")
|
167
|
+
menu_bar.append(menu_help, "&Help")
|
168
|
+
|
169
|
+
self.menu_bar = menu_bar
|
170
|
+
menu_bar.check(TOGGLE_LISTEN, true)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
class TargetApp < Wx::App
|
175
|
+
def on_init
|
176
|
+
TargetFrame.new("Event Handling Sample").show
|
177
|
+
return true
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
a = TargetApp.new
|
182
|
+
a.main_loop()
|
@@ -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 }
|
@@ -0,0 +1,198 @@
|
|
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
|
+
class GridFrame < Wx::Frame
|
11
|
+
|
12
|
+
def initialize(parent, id = -1, title = "MyFrame",
|
13
|
+
pos = Wx::DEFAULT_POSITION,
|
14
|
+
size = Wx::DEFAULT_SIZE,
|
15
|
+
style = Wx::DEFAULT_FRAME_STYLE)
|
16
|
+
|
17
|
+
super(parent, id, title, pos, size, style)
|
18
|
+
sizer = Wx::BoxSizer.new(Wx::VERTICAL)
|
19
|
+
create_status_bar()
|
20
|
+
set_status_text(Wx::VERSION_STRING)
|
21
|
+
|
22
|
+
# panel = Wx::Panel.new(self)
|
23
|
+
sel_menu = Wx::Menu.new
|
24
|
+
sel_menu.append(1002, 'Select all', 'Select all')
|
25
|
+
evt_menu(1002) { @grid.select_all }
|
26
|
+
sel_menu.append(1003, 'Select row 2', 'Select row 2')
|
27
|
+
evt_menu(1003) { @grid.select_row(1) }
|
28
|
+
sel_menu.append(1004, 'Select column 4', 'Select col 4')
|
29
|
+
evt_menu(1004) { @grid.select_col(3) }
|
30
|
+
sel_menu.append(1005, 'Select block', 'Select block')
|
31
|
+
evt_menu(1005) { @grid.select_block(1, 1, 6, 3) }
|
32
|
+
menu_bar = Wx::MenuBar.new
|
33
|
+
menu_bar.append(sel_menu, 'Select')
|
34
|
+
set_menu_bar(menu_bar)
|
35
|
+
|
36
|
+
make_grid(self)
|
37
|
+
sizer.add(@grid, 1, Wx::ALL|Wx::GROW, 4)
|
38
|
+
set_sizer(sizer)
|
39
|
+
|
40
|
+
evt_grid_cell_left_click() do |evt|
|
41
|
+
set_status_text("#{evt.get_row} x #{evt.get_col} is clicked")
|
42
|
+
evt.skip
|
43
|
+
end
|
44
|
+
|
45
|
+
evt_grid_cell_right_click() do |evt|
|
46
|
+
set_status_text("#{evt.get_row} x #{evt.get_col} is right clicked")
|
47
|
+
evt.skip
|
48
|
+
end
|
49
|
+
|
50
|
+
evt_grid_cell_left_dclick() do |evt|
|
51
|
+
set_status_text("#{evt.get_row} x #{evt.get_col} is double clicked")
|
52
|
+
evt.skip
|
53
|
+
end
|
54
|
+
|
55
|
+
evt_grid_cell_right_dclick() do |evt|
|
56
|
+
set_status_text("#{evt.get_row} x #{evt.get_col} is right double clicked")
|
57
|
+
evt.skip
|
58
|
+
end
|
59
|
+
|
60
|
+
evt_grid_label_left_click() do |evt|
|
61
|
+
set_status_text("#{evt.get_row} x #{evt.get_col} label is clicked")
|
62
|
+
evt.skip
|
63
|
+
end
|
64
|
+
|
65
|
+
evt_grid_label_right_click() do |evt|
|
66
|
+
set_status_text("#{evt.get_row} x #{evt.get_col} label is right clicked")
|
67
|
+
evt.skip
|
68
|
+
end
|
69
|
+
|
70
|
+
evt_grid_label_left_dclick() do |evt|
|
71
|
+
set_status_text("#{evt.get_row} x #{evt.get_col} labelis double clicked")
|
72
|
+
evt.skip
|
73
|
+
end
|
74
|
+
|
75
|
+
evt_grid_label_right_dclick() do |evt|
|
76
|
+
set_status_text("#{evt.get_row} x #{evt.get_col} label is right double clicked")
|
77
|
+
evt.skip
|
78
|
+
end
|
79
|
+
|
80
|
+
evt_grid_select_cell() do |evt|
|
81
|
+
set_status_text("#{evt.get_row} x #{evt.get_col} cell is selected")
|
82
|
+
evt.skip
|
83
|
+
end
|
84
|
+
|
85
|
+
evt_grid_row_size do |evt|
|
86
|
+
set_status_text("Row #{evt.get_row_or_col} size changed")
|
87
|
+
evt.skip
|
88
|
+
end
|
89
|
+
|
90
|
+
evt_grid_col_size do |evt|
|
91
|
+
set_status_text("Column #{evt.get_row_or_col} size changed")
|
92
|
+
evt.skip
|
93
|
+
end
|
94
|
+
|
95
|
+
evt_grid_editor_shown do |evt|
|
96
|
+
set_status_text("Begin editing")
|
97
|
+
evt.skip
|
98
|
+
end
|
99
|
+
|
100
|
+
evt_grid_editor_hidden do |evt|
|
101
|
+
set_status_text("End editing")
|
102
|
+
evt.skip
|
103
|
+
end
|
104
|
+
|
105
|
+
evt_grid_range_select do |evt|
|
106
|
+
top = evt.get_top_left_coords
|
107
|
+
bottom = evt.get_bottom_right_coords
|
108
|
+
set_status_text("[ #{top[0].to_s} x #{top[1].to_s} ] to [ #{bottom[0].to_s} x #{bottom[1].to_s} ] is selected")
|
109
|
+
end
|
110
|
+
|
111
|
+
evt_grid_editor_created do |evt|
|
112
|
+
set_status_text("Control #{evt.get_control} created")
|
113
|
+
evt.skip
|
114
|
+
end
|
115
|
+
|
116
|
+
evt_grid_cell_change() do |evt|
|
117
|
+
set_status_text("Cell #{evt.get_row} x #{evt.get_col} has changed")
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# Create a wxGrid object
|
122
|
+
def make_grid(panel)
|
123
|
+
@grid = Wx::Grid.new(panel, -1)
|
124
|
+
|
125
|
+
# Then we call CreateGrid to set the dimensions of the grid
|
126
|
+
# (11 rows and 12 columns in this example)
|
127
|
+
@grid.create_grid( 20, 12 )
|
128
|
+
@grid.set_default_cell_background_colour(Wx::WHITE)
|
129
|
+
# We can set the sizes of individual rows and columns
|
130
|
+
# in pixels, and the label value string
|
131
|
+
@grid.set_row_size( 0, 60 )
|
132
|
+
@grid.set_row_label_value( 0, "Row1" )
|
133
|
+
@grid.set_row_label_alignment(Wx::ALIGN_CENTRE, Wx::ALIGN_CENTRE)
|
134
|
+
|
135
|
+
@grid.set_col_size( 0, 120 )
|
136
|
+
@grid.set_col_label_value( 0, "Col1" )
|
137
|
+
@grid.set_col_label_alignment(Wx::ALIGN_CENTRE, Wx::ALIGN_CENTRE)
|
138
|
+
|
139
|
+
# And set grid cell contents as strings
|
140
|
+
@grid.set_cell_value( 0, 0, "wxGrid is good" )
|
141
|
+
|
142
|
+
# We can specify that some cells are read-only
|
143
|
+
@grid.set_cell_value( 0, 2, "Read-only" )
|
144
|
+
@grid.set_read_only( 0, 2 )
|
145
|
+
|
146
|
+
# Colours can be specified for grid cell contents
|
147
|
+
@grid.set_cell_value(1, 1, "white on red")
|
148
|
+
@grid.set_cell_text_colour(1, 1, Wx::WHITE)
|
149
|
+
@grid.set_cell_background_colour(1, 1, Wx::RED)
|
150
|
+
|
151
|
+
# We can specify the some cells will store numeric
|
152
|
+
# values rather than strings. Here we set grid column 6
|
153
|
+
# to hold floating point values displayed with width
|
154
|
+
# of 2 and precision of 2. The column is highlighted in light grey
|
155
|
+
cell_attr = Wx::GridCellAttr.new
|
156
|
+
cell_attr.set_background_colour( Wx::LIGHT_GREY )
|
157
|
+
cell_attr.set_renderer( Wx::GridCellFloatRenderer.new(2, 2) )
|
158
|
+
|
159
|
+
@grid.set_col_attr(5, cell_attr)
|
160
|
+
@grid.set_cell_value(0, 5, "3.1415")
|
161
|
+
@grid.set_cell_value(0, 6,
|
162
|
+
"The whole column to the left uses float format")
|
163
|
+
|
164
|
+
# Custom Editors Can be used
|
165
|
+
editor = Wx::GridCellNumberEditor.new(5, 20)
|
166
|
+
@grid.set_cell_value(3, 1, 'Number editor below')
|
167
|
+
@grid.set_cell_editor(4, 1, editor)
|
168
|
+
|
169
|
+
editor = Wx::GridCellFloatEditor.new(4, 2)
|
170
|
+
@grid.set_cell_value(3, 2, 'Float editor below')
|
171
|
+
@grid.set_cell_editor(4, 2, editor)
|
172
|
+
|
173
|
+
editor = Wx::GridCellChoiceEditor.new(['foo', 'bar', 'baz'])
|
174
|
+
@grid.set_cell_value(3, 3, 'Choice editor below')
|
175
|
+
@grid.set_cell_editor(4, 3, editor)
|
176
|
+
|
177
|
+
@grid.auto_size_row(3, true)
|
178
|
+
|
179
|
+
# Display of cells can be customised
|
180
|
+
@grid.set_cell_editor(6, 0, Wx::GridCellBoolEditor.new)
|
181
|
+
@grid.set_cell_renderer(6, 0, Wx::GridCellBoolRenderer.new)
|
182
|
+
@grid.set_cell_value(6, 1, 'Cell to the left displayed as boolean')
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
class GridApp < Wx::App
|
188
|
+
def on_init
|
189
|
+
frame = GridFrame.new(nil, -1, "Grid Sample",
|
190
|
+
Wx::Point.new(10, 100),
|
191
|
+
Wx::Size.new(630,400))
|
192
|
+
|
193
|
+
set_top_window(frame)
|
194
|
+
frame.show()
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
GridApp.new.main_loop()
|