wxruby 1.9.10-universal-darwin-9 → 2.0.0-universal-darwin-9

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -2,16 +2,22 @@
2
2
  # wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
3
3
  # Freely reusable code: see SAMPLES-LICENSE.TXT for details
4
4
 
5
- # RichTextCtrl sample by Chauk-Mean P
5
+ # RichTextCtrl sample by Chauk-Mean Proum
6
6
  #
7
- # RichTextCtrl is a sophisticated styled text editing component. This
8
- # short sample shows the basics, but RichTextCtrl supports numerous
9
- # other text characteristics (font, size, colour, super/subscript), as
10
- # well as paragraph alignment and spacing, and bullets. It permits named
11
- # text styles to be created and organised in stylesheets. It can output
12
- # to HTML and XML, and facilities are provided for printing.
7
+ # RichTextCtrl is a sophisticated styled text editing component.
8
+ # This sample illustrates a basic but functional rich editor featuring :
9
+ # - file loading/saving
10
+ # - text formatting
11
+ # - change undo/redo
12
+ # - selection copy/cut and clipboard paste
13
+ # - font preferences
14
+ # RichTextCtrl supports numerous other text characteristics (colour, super/subscript),
15
+ # as well as paragraph alignment and spacing, and bullets.
16
+ # It permits named text styles to be created and organised in stylesheets.
17
+ # Facilities are also provided for printing.
13
18
  #
14
19
  # Icons are taken from the Tango Icon Theme.
20
+ # Disabled icons are created at runtime as darkened grayscale versions.
15
21
 
16
22
  begin
17
23
  require 'rubygems'
@@ -22,69 +28,255 @@ require 'wx'
22
28
  class RichTextFrame < Wx::Frame
23
29
 
24
30
  def initialize
25
- super( nil, :title => "RichTextCtrl sample", :size => [800, 600] )
31
+ super( nil, :title => "RichTextCtrl Sample", :size => [900, 600] )
26
32
 
27
- toolbar = create_tool_bar( Wx::TB_HORIZONTAL|Wx::NO_BORDER|
28
- Wx::TB_FLAT|Wx::TB_TEXT )
29
- toolbar.tool_bitmap_size = [ 32, 32 ]
33
+ # Initialize the toolbar with standard actions
34
+ initialize_toolbar
30
35
 
31
- bold_bmp = bmp_from_png("format-text-bold.png")
32
- toolbar.add_check_tool( Wx::ID_BOLD, "Bold",
33
- bold_bmp, bold_bmp, "Apply bold")
34
-
35
- italic_bmp = bmp_from_png("format-text-italic.png")
36
- toolbar.add_check_tool( Wx::ID_ITALIC, "Italic",
37
- italic_bmp, italic_bmp, "Apply italic")
38
-
39
- underline_bmp = bmp_from_png("format-text-underline.png")
40
- toolbar.add_check_tool( Wx::ID_UNDERLINE, "Underline",
41
- underline_bmp, underline_bmp, "Apply underline")
42
- toolbar.realize
36
+ @editor = Wx::RichTextCtrl.new(self, :style => Wx::WANTS_CHARS)
37
+
38
+ # Add extra handlers (plain text is automatically added)
39
+ @editor.buffer.add_handler(Wx::RichTextXMLHandler.new)
40
+ @editor.buffer.add_handler(Wx::RichTextHTMLHandler.new)
41
+ file_wildcard = "Text File (*.txt)|*.txt|XML File (*.xml)|*.xml"
42
+ @file_open_wildcard = file_wildcard + "|All Supported File (*.*)|*.*"
43
+ @file_save_wildcard = file_wildcard + "|HTML File (*.html)|*.html"
44
+
45
+ @cur_dir = Dir.getwd
46
+ @cur_file = ""
47
+ @cur_filter_index = 1 # XML file
43
48
 
44
- editor = Wx::RichTextCtrl.new(self, :style => Wx::WANTS_CHARS)
45
- editor.begin_font_size(18)
49
+ # Use the system's standard sans-serif font at 18 point
50
+ @editor.font = Wx::Font.new( 18,
51
+ Wx::FONTFAMILY_SWISS,
52
+ Wx::FONTSTYLE_NORMAL,
53
+ Wx::FONTWEIGHT_NORMAL )
46
54
 
47
- editor.begin_bold
48
- editor.write_text "Simple RichTextCtrl sample"
49
- editor.end_bold
50
- editor.newline
51
- editor.begin_italic
52
- editor.write_text "Use the formatting buttons then type some text or "
53
- editor.write_text "select some text and use the buttons to apply the formatting.\n"
54
- editor.end_italic
55
+ initialize_text
56
+
57
+ # -- For complex event handling, use of a method call --
58
+ evt_tool Wx::ID_OPEN, :open_file
59
+ evt_tool Wx::ID_SAVE, :save_file
60
+ evt_tool Wx::ID_PREFERENCES, :select_font
61
+
62
+ # -- For simple event handling, use of a code block --
55
63
 
56
64
  # Apply / unapply bold to selection
57
65
  evt_tool(Wx::ID_BOLD) do
58
- editor.apply_bold_to_selection
66
+ @editor.apply_bold_to_selection
59
67
  end
60
68
 
61
69
  # Keep the pressed / unpressed state of the button in sync with the
62
70
  # current selection in the text ctrl
63
71
  evt_update_ui(Wx::ID_BOLD) do |evt|
64
- evt.check(editor.selection_bold?)
72
+ evt.check(@editor.selection_bold?)
65
73
  end
66
74
 
67
75
  evt_tool(Wx::ID_ITALIC) do
68
- editor.apply_italic_to_selection
76
+ @editor.apply_italic_to_selection
69
77
  end
70
78
 
71
79
  evt_update_ui(Wx::ID_ITALIC) do |evt|
72
- evt.check(editor.selection_italics?)
80
+ evt.check(@editor.selection_italics?)
73
81
  end
74
82
 
75
83
  evt_tool(Wx::ID_UNDERLINE) do
76
- editor.apply_underline_to_selection
84
+ @editor.apply_underline_to_selection
77
85
  end
78
86
 
79
87
  evt_update_ui(Wx::ID_UNDERLINE) do |evt|
80
- evt.check(editor.selection_underlined?)
88
+ evt.check(@editor.selection_underlined?)
89
+ end
90
+
91
+ evt_tool(Wx::ID_UNDO) do
92
+ @editor.undo
81
93
  end
94
+
95
+ evt_update_ui(Wx::ID_UNDO) do |evt|
96
+ evt.enable(@editor.can_undo?)
97
+ end
98
+
99
+ evt_tool(Wx::ID_REDO) do
100
+ @editor.redo
101
+ end
102
+
103
+ evt_update_ui(Wx::ID_REDO) do |evt|
104
+ evt.enable(@editor.can_redo?)
105
+ end
106
+
107
+ evt_tool(Wx::ID_COPY) do
108
+ @editor.copy
109
+ end
110
+
111
+ evt_update_ui(Wx::ID_COPY) do |evt|
112
+ evt.enable(@editor.can_copy?)
113
+ end
114
+
115
+ evt_tool(Wx::ID_CUT) do
116
+ @editor.cut
117
+ end
118
+
119
+ evt_update_ui(Wx::ID_CUT) do |evt|
120
+ evt.enable(@editor.can_cut?)
121
+ end
122
+
123
+ evt_tool(Wx::ID_PASTE) do
124
+ # @editor.apply_bold_to_selection if @editor.selection_bold?
125
+ # @editor.apply_italic_to_selection if @editor.selection_italics?
126
+ # @editor.apply_underline_to_selection if @editor.selection_underlined?
127
+ @editor.paste
128
+ end
129
+
130
+ evt_update_ui(Wx::ID_PASTE) do |evt|
131
+ evt.enable(@editor.can_paste?)
132
+ end
133
+ # Shortcut keys for the editor
134
+ accel_keys = { "Z" => Wx::ID_UNDO,
135
+ "Y" => Wx::ID_REDO,
136
+ "C" => Wx::ID_COPY,
137
+ "X" => Wx::ID_CUT,
138
+ "V" => Wx::ID_PASTE }
139
+ accel_table = accel_keys.keys.map do | key |
140
+ [ Wx::MOD_CMD, key, accel_keys[key] ]
141
+ end
142
+
143
+ @editor.accelerator_table = Wx::AcceleratorTable[ *accel_table ]
82
144
  end
83
145
 
84
- # Return a new bitmap corresponding to the specified PNG filename
85
- def bmp_from_png(filename)
146
+
147
+ # Return bitmaps corresponding to the specified PNG filename :
148
+ # - the first one is the original version (e.g. for an enabled icon)
149
+ # - the second one is a darkened grayscale version (e.g. for a disabled icon)
150
+ def bitmaps_from_png(filename, greyscale = true)
86
151
  img_file = File.join( File.dirname(__FILE__), filename)
87
- Wx::Bitmap.new(img_file, Wx::BITMAP_TYPE_PNG)
152
+ normal_bmp = Wx::Bitmap.new(img_file, Wx::BITMAP_TYPE_PNG)
153
+ if greyscale
154
+ greyscale_img = normal_bmp.convert_to_image.convert_to_greyscale(0.2, 0.2, 0.2)
155
+ greyscale_bmp = Wx::Bitmap.from_image(greyscale_img)
156
+ return normal_bmp, greyscale_bmp
157
+ else
158
+ normal_bmp
159
+ end
160
+ end
161
+
162
+
163
+ # Return a new bitmap corresponding to the specified PNG filename
164
+ def bitmap_from_png(filename)
165
+ bitmaps_from_png(filename, false)
166
+ end
167
+
168
+
169
+ # Initialize the toolbar
170
+ #
171
+ # As the toolbar contains only standard actions, use of stock/builtin IDs
172
+ # to avoid keeping references to each tool item.
173
+ def initialize_toolbar
174
+ toolbar = create_tool_bar( Wx::TB_HORIZONTAL|Wx::NO_BORDER|
175
+ Wx::TB_FLAT|Wx::TB_TEXT )
176
+ toolbar.tool_bitmap_size = [ 32, 32 ]
177
+
178
+ open_bmp = bitmap_from_png("document-open.png")
179
+ toolbar.add_item(open_bmp, :id => Wx::ID_OPEN,
180
+ :label => "Open", :short_help => "Open file")
181
+
182
+ save_bmp = bitmap_from_png("document-save.png")
183
+ toolbar.add_item(save_bmp, :id => Wx::ID_SAVE,
184
+ :label => "Save", :short_help => "Save file")
185
+
186
+ font_bmp = bitmap_from_png("preferences-desktop-font.png")
187
+ toolbar.add_item(font_bmp, :id => Wx::ID_PREFERENCES,
188
+ :label => "Font", :short_help => "Select font preferences")
189
+
190
+ toolbar.add_separator
191
+
192
+ copy_bmp, copy_disabled_bmp = bitmaps_from_png("edit-copy.png")
193
+ toolbar.add_item(copy_bmp, copy_disabled_bmp, :id => Wx::ID_COPY,
194
+ :label => "Copy", :short_help => "Copy selection (CMD+C)")
195
+
196
+ cut_bmp, cut_disabled_bmp = bitmaps_from_png("edit-cut.png")
197
+ toolbar.add_item(cut_bmp, cut_disabled_bmp, :id => Wx::ID_CUT,
198
+ :label => "Cut", :short_help => "Cut selection (CMD+X)")
199
+
200
+ paste_bmp, paste_disabled_bmp = bitmaps_from_png("edit-paste.png")
201
+ toolbar.add_item(paste_bmp, paste_disabled_bmp, :id => Wx::ID_PASTE,
202
+ :label => "Paste", :short_help => "Paste clipboard (CMD+V)")
203
+
204
+ undo_bmp, undo_disabled_bmp = bitmaps_from_png("edit-undo.png")
205
+ toolbar.add_item(undo_bmp, undo_disabled_bmp, :id => Wx::ID_UNDO,
206
+ :label => "Undo", :short_help => "Undo change (CMD+Z)")
207
+
208
+ redo_bmp, redo_disabled_bmp = bitmaps_from_png("edit-redo.png")
209
+ toolbar.add_item(redo_bmp, redo_disabled_bmp, :id => Wx::ID_REDO,
210
+ :label => "Redo", :short_help => "Redo change (CMD+Y)")
211
+
212
+ toolbar.add_separator
213
+
214
+ bold_bmp = bitmap_from_png("format-text-bold.png")
215
+ toolbar.add_item(bold_bmp, :id => Wx::ID_BOLD, :kind => Wx::ITEM_CHECK,
216
+ :label => "Bold", :short_help => "Apply bold")
217
+
218
+ italic_bmp = bitmap_from_png("format-text-italic.png")
219
+ toolbar.add_item(italic_bmp, :id => Wx::ID_ITALIC, :kind => Wx::ITEM_CHECK,
220
+ :label => "Italic", :short_help => "Apply italic")
221
+
222
+ underline_bmp = bitmap_from_png("format-text-underline.png")
223
+ toolbar.add_item(underline_bmp, :id => Wx::ID_UNDERLINE, :kind => Wx::ITEM_CHECK,
224
+ :label => "Underline", :short_help => "Apply underline")
225
+
226
+ toolbar.realize
227
+ end
228
+
229
+ def initialize_text
230
+ @editor.begin_suppress_undo
231
+ @editor.begin_bold
232
+ @editor.write_text "Simple RichTextCtrl sample"
233
+ @editor.end_bold
234
+ @editor.newline
235
+ @editor.begin_italic
236
+ @editor.write_text "Use the formatting buttons then type some text or "
237
+ @editor.write_text "select some text and use the buttons to apply the formatting.\n"
238
+ @editor.write_text "Save as an XML file in order to keep the text formatting.\n"
239
+ @editor.end_italic
240
+ @editor.newline
241
+ @editor.end_suppress_undo
242
+ end
243
+
244
+ def select_font
245
+ data = Wx::FontData.new
246
+ data.initial_font = @editor.font
247
+ # data.enable_effects(false)
248
+
249
+ dlg = Wx::FontDialog.new(self, data)
250
+ if dlg.show_modal() == Wx::ID_OK
251
+ data = dlg.font_data
252
+ @editor.font = data.chosen_font
253
+ end
254
+ end
255
+
256
+ def open_file
257
+ dlg = Wx::FileDialog.new(self, "Open file", @cur_dir, @cur_file, @file_open_wildcard, Wx::OPEN)
258
+ dlg.filter_index = @cur_filter_index
259
+ if dlg.show_modal() == Wx::ID_OK
260
+ @editor.load_file(dlg.path, Wx::RICHTEXT_TYPE_ANY)
261
+ update_from_file dlg
262
+ end
263
+ end
264
+
265
+ def save_file
266
+ dlg = Wx::FileDialog.new(self, "Save file as...", @cur_dir, @cur_file, @file_save_wildcard, Wx::SAVE)
267
+ dlg.filter_index = @cur_filter_index
268
+ if dlg.show_modal() == Wx::ID_OK
269
+ @editor.save_file(dlg.path, Wx::RICHTEXT_TYPE_ANY)
270
+ update_from_file dlg
271
+ end
272
+ end
273
+
274
+ # Update current file parameters
275
+ def update_from_file dlg
276
+ @cur_dir = dlg.directory
277
+ @cur_file = dlg.filename
278
+ @cur_filter_index = dlg.filter_index
279
+ self.title = "RichTextCtrl Sample - #{@cur_file}"
88
280
  end
89
281
  end
90
282
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wxruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.10
4
+ version: 2.0.0
5
5
  platform: universal-darwin-9
6
6
  authors:
7
7
  - wxRuby development team
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-04 00:00:00 +00:00
12
+ date: 2009-02-27 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -86,6 +86,7 @@ files:
86
86
  - lib/wx/classes/toolbar.rb
87
87
  - lib/wx/classes/toolbartool.rb
88
88
  - lib/wx/classes/treectrl.rb
89
+ - lib/wx/classes/validator.rb
89
90
  - lib/wx/classes/vboxsizer.rb
90
91
  - lib/wx/classes/window.rb
91
92
  - lib/wx/classes/xmlresource.rb
@@ -236,9 +237,12 @@ files:
236
237
  - samples/dragdrop
237
238
  - samples/dragdrop/dragdrop.rb
238
239
  - samples/drawing
240
+ - samples/drawing/bitmap.rb
241
+ - samples/drawing/bitmap_image.rb
239
242
  - samples/drawing/graphics_drawing.rb
240
- - samples/drawing/images.rb
241
- - samples/drawing/paperclip.png
243
+ - samples/drawing/maths_images.rb
244
+ - samples/drawing/ruby-logo.jpg
245
+ - samples/drawing/wxruby-logo.png
242
246
  - samples/etc
243
247
  - samples/etc/activation.rb
244
248
  - samples/etc/choice.rb
@@ -285,11 +289,19 @@ files:
285
289
  - samples/sockets/wxServer.rb
286
290
  - samples/sockets/wxSocketGUI.rb
287
291
  - samples/text
292
+ - samples/text/document-open.png
293
+ - samples/text/document-save.png
294
+ - samples/text/edit-copy.png
295
+ - samples/text/edit-cut.png
296
+ - samples/text/edit-paste.png
297
+ - samples/text/edit-redo.png
298
+ - samples/text/edit-undo.png
288
299
  - samples/text/format-text-bold.png
289
300
  - samples/text/format-text-italic.png
290
301
  - samples/text/format-text-underline.png
291
302
  - samples/text/mondrian.ico
292
303
  - samples/text/mondrian.xpm
304
+ - samples/text/preferences-desktop-font.png
293
305
  - samples/text/rich_textctrl.rb
294
306
  - samples/text/scintilla.rb
295
307
  - samples/text/textctrl.rb
@@ -306,6 +318,7 @@ files:
306
318
  - samples/xrc/samples.xrc
307
319
  - samples/xrc/xrc_sample.rb
308
320
  - README
321
+ - INSTALL
309
322
  - LICENSE
310
323
  has_rdoc: false
311
324
  homepage: http://wxruby.org/