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.
Files changed (152) hide show
  1. data/LICENSE +53 -53
  2. data/README +297 -297
  3. data/lib/wx.rb +53 -53
  4. data/lib/wx/classes/bitmap.rb +29 -1
  5. data/lib/wx/classes/clipboard.rb +19 -3
  6. data/lib/wx/classes/colour.rb +6 -4
  7. data/lib/wx/classes/data_object.rb +14 -0
  8. data/lib/wx/classes/data_object_simple.rb +6 -0
  9. data/lib/wx/classes/dataformat.rb +23 -0
  10. data/lib/wx/classes/evthandler.rb +31 -4
  11. data/lib/wx/classes/genericdirctrl.rb +36 -0
  12. data/lib/wx/classes/grid.rb +8 -0
  13. data/lib/wx/classes/hboxsizer.rb +6 -0
  14. data/lib/wx/classes/icon.rb +12 -1
  15. data/lib/wx/classes/image.rb +13 -1
  16. data/lib/wx/classes/listctrl.rb +12 -0
  17. data/lib/wx/classes/point.rb +8 -0
  18. data/lib/wx/classes/rect.rb +10 -1
  19. data/lib/wx/classes/richtextctrl.rb +22 -0
  20. data/lib/wx/classes/size.rb +9 -0
  21. data/lib/wx/classes/sizer.rb +18 -3
  22. data/lib/wx/classes/toolbar.rb +4 -6
  23. data/lib/wx/classes/vboxsizer.rb +6 -0
  24. data/lib/wx/classes/window.rb +7 -0
  25. data/lib/wx/classes/xmlresource.rb +17 -0
  26. data/lib/wx/helpers.rb +16 -1
  27. data/lib/wx/keyword_ctors.rb +3 -2
  28. data/lib/wx/keyword_defs.rb +27 -5
  29. data/lib/wx/version.rb +1 -1
  30. data/lib/wxruby2.so +0 -0
  31. data/samples/SAMPLES-LICENSE.TXT +17 -17
  32. data/samples/bigdemo/About.rbw +39 -39
  33. data/samples/bigdemo/ColorPanel.rbw +23 -23
  34. data/samples/bigdemo/GridSimple.rbw +78 -78
  35. data/samples/bigdemo/MDIDemo.rbw +57 -57
  36. data/samples/bigdemo/PopupMenu.rbw +149 -149
  37. data/samples/bigdemo/Sizers.rbw +543 -543
  38. data/samples/bigdemo/bigdemo.rb +823 -823
  39. data/samples/bigdemo/demoTemplate.rbw +33 -33
  40. data/samples/bigdemo/icons/choice.xpm +27 -27
  41. data/samples/bigdemo/icons/combo.xpm +27 -27
  42. data/samples/bigdemo/icons/copy.xpm +25 -25
  43. data/samples/bigdemo/icons/cut.xpm +24 -24
  44. data/samples/bigdemo/icons/gauge.xpm +27 -27
  45. data/samples/bigdemo/icons/help.xpm +25 -25
  46. data/samples/bigdemo/icons/list.xpm +27 -27
  47. data/samples/bigdemo/icons/mondrian.xpm +44 -44
  48. data/samples/bigdemo/icons/new.xpm +24 -24
  49. data/samples/bigdemo/icons/ogl.ico +0 -0
  50. data/samples/bigdemo/icons/ogl.xpm +45 -45
  51. data/samples/bigdemo/icons/open.xpm +26 -26
  52. data/samples/bigdemo/icons/paste.xpm +38 -38
  53. data/samples/bigdemo/icons/preview.xpm +26 -26
  54. data/samples/bigdemo/icons/print.xpm +26 -26
  55. data/samples/bigdemo/icons/radio.xpm +27 -27
  56. data/samples/bigdemo/icons/robert.xpm +415 -415
  57. data/samples/bigdemo/icons/save.xpm +25 -25
  58. data/samples/bigdemo/icons/smiles.xpm +39 -39
  59. data/samples/bigdemo/icons/smiley.xpm +42 -42
  60. data/samples/bigdemo/icons/stattext.xpm +24 -24
  61. data/samples/bigdemo/icons/test2.bmp +0 -0
  62. data/samples/bigdemo/icons/test2.xpm +79 -79
  63. data/samples/bigdemo/icons/text.xpm +27 -27
  64. data/samples/bigdemo/icons/tog1.xpm +38 -38
  65. data/samples/bigdemo/icons/tog2.xpm +38 -38
  66. data/samples/bigdemo/icons/wxwin16x16.xpm +25 -25
  67. data/samples/bigdemo/tips.txt +7 -7
  68. data/samples/bigdemo/utils.rb +11 -11
  69. data/samples/bigdemo/wxButton.rbw +64 -64
  70. data/samples/bigdemo/wxCalendarCtrl.rbw +60 -60
  71. data/samples/bigdemo/wxCheckBox.rbw +50 -50
  72. data/samples/bigdemo/wxCheckListBox.rbw +65 -75
  73. data/samples/bigdemo/wxChoice.rbw +47 -47
  74. data/samples/bigdemo/wxColourDialog.rbw +31 -31
  75. data/samples/bigdemo/wxComboBox.rbw +77 -77
  76. data/samples/bigdemo/wxDialog.rbw +74 -74
  77. data/samples/bigdemo/wxDirDialog.rbw +29 -29
  78. data/samples/bigdemo/wxFileDialog.rbw +37 -37
  79. data/samples/bigdemo/wxFileDialog_Save.rbw +35 -35
  80. data/samples/bigdemo/wxFindReplaceDialog.rbw +82 -82
  81. data/samples/bigdemo/wxFontDialog.rbw +173 -173
  82. data/samples/bigdemo/wxFrame.rbw +53 -53
  83. data/samples/bigdemo/wxGauge.rbw +71 -71
  84. data/samples/bigdemo/wxGrid.rbw +66 -66
  85. data/samples/bigdemo/wxListBox.rbw +140 -140
  86. data/samples/bigdemo/wxListCtrl_virtual.rbw +112 -107
  87. data/samples/bigdemo/wxMDIWindows.rbw +50 -50
  88. data/samples/bigdemo/wxMenu.rbw +236 -236
  89. data/samples/bigdemo/wxMessageDialog.rbw +27 -27
  90. data/samples/bigdemo/wxMultipleChoiceDialog.rbw +32 -32
  91. data/samples/bigdemo/wxNotebook.rbw +136 -136
  92. data/samples/bigdemo/wxProgressDialog.rbw +43 -43
  93. data/samples/bigdemo/wxRadioBox.rbw +72 -72
  94. data/samples/bigdemo/wxRadioButton.rbw +125 -125
  95. data/samples/bigdemo/wxSashWindow.rbw +2 -2
  96. data/samples/bigdemo/wxScrolledMessageDialog.rbw +57 -57
  97. data/samples/bigdemo/wxScrolledWindow.rbw +199 -199
  98. data/samples/bigdemo/wxSingleChoiceDialog.rbw +33 -33
  99. data/samples/bigdemo/wxSlider.rbw +42 -42
  100. data/samples/bigdemo/wxSpinButton.rbw +50 -50
  101. data/samples/bigdemo/wxSpinCtrl.rbw +51 -51
  102. data/samples/bigdemo/wxSplitterWindow.rbw +63 -63
  103. data/samples/bigdemo/wxStaticBitmap.rbw +51 -51
  104. data/samples/bigdemo/wxStaticText.rbw +55 -55
  105. data/samples/bigdemo/wxStatusBar.rbw +126 -126
  106. data/samples/bigdemo/wxTextCtrl.rbw +149 -149
  107. data/samples/bigdemo/wxTextEntryDialog.rbw +31 -31
  108. data/samples/bigdemo/wxToggleButton.rbw +49 -49
  109. data/samples/bigdemo/wxToolBar.rbw +131 -131
  110. data/samples/bigdemo/wxTreeCtrl.rbw +191 -190
  111. data/samples/calendar/calendar.rb +256 -271
  112. data/samples/caret/caret.rb +282 -282
  113. data/samples/caret/mondrian.xpm +44 -44
  114. data/samples/controls/controls.rb +1136 -1136
  115. data/samples/controls/get_item_sample.rb +87 -87
  116. data/samples/controls/icons/choice.xpm +27 -27
  117. data/samples/controls/icons/combo.xpm +27 -27
  118. data/samples/controls/icons/gauge.xpm +27 -27
  119. data/samples/controls/icons/list.xpm +27 -27
  120. data/samples/controls/icons/radio.xpm +27 -27
  121. data/samples/controls/icons/stattext.xpm +24 -24
  122. data/samples/controls/icons/text.xpm +27 -27
  123. data/samples/controls/mondrian.xpm +44 -44
  124. data/samples/dialogs/dialogs.rb +797 -723
  125. data/samples/dialogs/tips.txt +18 -18
  126. data/samples/drawing/images.rb +37 -37
  127. data/samples/etc/activation.rb +102 -102
  128. data/samples/etc/choice.rb +67 -67
  129. data/samples/etc/miniframe.rb +79 -79
  130. data/samples/etc/sash.rb +130 -130
  131. data/samples/etc/scrollwin.rb +110 -110
  132. data/samples/etc/system_settings.rb +252 -252
  133. data/samples/etc/toolbar_sizer_additem.rb +55 -0
  134. data/samples/etc/wizard.rb +74 -74
  135. data/samples/event/update_ui_event.rb +70 -0
  136. data/samples/grid/gridtablebase.rb +43 -29
  137. data/samples/listbook/listbook.rb +174 -174
  138. data/samples/listbook/listbook.xrc +370 -370
  139. data/samples/mdi/mdi.rb +85 -77
  140. data/samples/minimal/minimal.rb +77 -77
  141. data/samples/minimal/nothing.rb +16 -16
  142. data/samples/text/format-text-bold.png +0 -0
  143. data/samples/text/format-text-italic.png +0 -0
  144. data/samples/text/format-text-underline.png +0 -0
  145. data/samples/text/rich_textctrl.rb +98 -0
  146. data/samples/text/textctrl.rb +111 -113
  147. data/samples/text/unicode.rb +242 -242
  148. data/samples/text/utf8.txt +14 -14
  149. data/samples/treectrl/treectrl.rb +1166 -1174
  150. data/samples/xrc/samples.xrc +46 -46
  151. data/samples/xrc/xrc_sample.rb +76 -96
  152. metadata +15 -3
@@ -1,113 +1,111 @@
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 InformativeTextCtrl < Wx::TextCtrl
11
- NEWLINE_CORRECTION_FACTOR = 0
12
-
13
- # These text controls are multiline, and may have rich (coloured,
14
- # styled) text in them
15
- STYLE = Wx::TE_MULTILINE|Wx::TE_RICH|Wx::TE_RICH2
16
- def initialize(parent, text = '')
17
- super(parent, :value => text, :style => STYLE)
18
- end
19
-
20
- # more ruby-ish
21
- alias :<< :append_text
22
-
23
- # run through a few useful methods of textctrl and report the results
24
- # as a string
25
- def report()
26
- report = ''
27
- report << 'Insertion Point: ' << get_insertion_point.to_s() << "\n"
28
- report << 'First Line Text: ' << get_line_text(0) << "\n"
29
- report << 'Final Position: ' << get_last_position().to_s() << "\n"
30
- report << 'Selection: ' << get_selection().inspect() << "\n"
31
- report << 'String Selection: ' << get_string_selection().inspect << "\n"
32
- report << 'Position to X, Y: ' <<
33
- position_to_xy( get_insertion_point ).inspect
34
- return report
35
- end
36
- end
37
-
38
- # A read-only text ctrl useful for displaying output
39
- class LogTextCtrl < Wx::TextCtrl
40
- STYLE = Wx::TE_READONLY|Wx::TE_MULTILINE
41
- def initialize(parent)
42
- super(parent, :style => STYLE)
43
- end
44
- end
45
-
46
- class TextCtrlFrame < Wx::Frame
47
- def initialize(*args)
48
- super(nil, *args)
49
-
50
- panel = Wx::Panel.new(self)
51
- sizer = Wx::BoxSizer.new(Wx::VERTICAL)
52
-
53
- @textctrl = InformativeTextCtrl.new(panel)
54
- populate_textctrl()
55
- sizer.add(@textctrl, 2, Wx::GROW|Wx::ALL, 2)
56
-
57
- button = Wx::Button.new(panel, :label => 'Get Info')
58
- sizer.add(button, 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2 )
59
- evt_button button, :on_click
60
-
61
- @log = LogTextCtrl.new(panel)
62
- sizer.add(@log, 1, Wx::GROW|Wx::ALL, 2)
63
- panel.sizer = sizer
64
- end
65
-
66
- def populate_textctrl()
67
- @textctrl << "This is some plain text\n"
68
- @textctrl << "Text with green letters and yellow background\n"
69
- @textctrl << "This is some more plain text"
70
- # create a new rich text style
71
- attr = Wx::TextAttr.new(Wx::GREEN, Wx::Colour.new(255, 255, 0) )
72
- # apply the style from character 26 to character 76
73
- @textctrl.set_style(24, 69, attr)
74
- end
75
-
76
- def construct_menus()
77
- menu_bar = Wx::MenuBar.new()
78
-
79
- menu_file = Wx::Menu.new()
80
- menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
81
- menu_bar.append(menu_file, "&File")
82
- evt_menu Wx::ID_EXIT, :on_quit
83
-
84
- menu_help = Wx::Menu.new()
85
- menu_help.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
86
- evt_menu Wx::ID_ABOUT, :on_about
87
- menu_bar.append(menu_help, "&Help")
88
-
89
- self.menu_bar = menu_bar
90
- end
91
-
92
- def on_click
93
- @log.value = @textctrl.report
94
- end
95
-
96
- def on_quit
97
- close
98
- end
99
-
100
- def on_about
101
- msg = sprintf("This is the About dialog of the textctrl sample.\n" \
102
- "Welcome to %s", Wx::VERSION_STRING)
103
- message_box(msg, "About Minimal", Wx::OK|Wx::ICON_INFORMATION, self)
104
- end
105
- end
106
-
107
- Wx::App.run do
108
- frame = TextCtrlFrame.new( :title => "TextCtrl demonstration",
109
- :pos => [ 50, 50 ],
110
- :size => [ 450, 340 ] )
111
- frame.show
112
- end
113
-
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 InformativeTextCtrl < Wx::TextCtrl
11
+ # These text controls are multiline, and may have rich (coloured,
12
+ # styled) text in them
13
+ STYLE = Wx::TE_MULTILINE|Wx::TE_RICH|Wx::TE_RICH2
14
+ def initialize(parent, text = '')
15
+ super(parent, :value => text, :style => STYLE)
16
+ end
17
+
18
+ # more ruby-ish
19
+ alias :<< :append_text
20
+
21
+ # run through a few useful methods of textctrl and report the results
22
+ # as a string
23
+ def report()
24
+ report = ''
25
+ report << 'Insertion Point: ' << get_insertion_point.to_s() << "\n"
26
+ report << 'First Line Text: ' << get_line_text(0) << "\n"
27
+ report << 'Final Position: ' << get_last_position().to_s() << "\n"
28
+ report << 'Selection: ' << get_selection().inspect() << "\n"
29
+ report << 'String Selection: ' << get_string_selection().inspect << "\n"
30
+ report << 'Position to X, Y: ' <<
31
+ position_to_xy( get_insertion_point ).inspect
32
+ return report
33
+ end
34
+ end
35
+
36
+ # A read-only text ctrl useful for displaying output
37
+ class LogTextCtrl < Wx::TextCtrl
38
+ STYLE = Wx::TE_READONLY|Wx::TE_MULTILINE
39
+ def initialize(parent)
40
+ super(parent, :style => STYLE)
41
+ end
42
+ end
43
+
44
+ class TextCtrlFrame < Wx::Frame
45
+ def initialize(*args)
46
+ super(nil, *args)
47
+
48
+ panel = Wx::Panel.new(self)
49
+ sizer = Wx::BoxSizer.new(Wx::VERTICAL)
50
+
51
+ @textctrl = InformativeTextCtrl.new(panel)
52
+ populate_textctrl()
53
+ sizer.add(@textctrl, 2, Wx::GROW|Wx::ALL, 2)
54
+
55
+ button = Wx::Button.new(panel, :label => 'Get Info')
56
+ sizer.add(button, 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2 )
57
+ evt_button button, :on_click
58
+
59
+ @log = LogTextCtrl.new(panel)
60
+ sizer.add(@log, 1, Wx::GROW|Wx::ALL, 2)
61
+ panel.sizer = sizer
62
+ end
63
+
64
+ def populate_textctrl()
65
+ @textctrl << "This is some plain text\n"
66
+ @textctrl << "Text with green letters and yellow background\n"
67
+ @textctrl << "This is some more plain text"
68
+ # create a new rich text style
69
+ attr = Wx::TextAttr.new(Wx::GREEN, Wx::Colour.new(255, 255, 0) )
70
+ # apply the style from character 26 to character 76
71
+ @textctrl.set_style(24, 69, attr)
72
+ end
73
+
74
+ def construct_menus()
75
+ menu_bar = Wx::MenuBar.new()
76
+
77
+ menu_file = Wx::Menu.new()
78
+ menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
79
+ menu_bar.append(menu_file, "&File")
80
+ evt_menu Wx::ID_EXIT, :on_quit
81
+
82
+ menu_help = Wx::Menu.new()
83
+ menu_help.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
84
+ evt_menu Wx::ID_ABOUT, :on_about
85
+ menu_bar.append(menu_help, "&Help")
86
+
87
+ self.menu_bar = menu_bar
88
+ end
89
+
90
+ def on_click
91
+ @log.value = @textctrl.report
92
+ end
93
+
94
+ def on_quit
95
+ close
96
+ end
97
+
98
+ def on_about
99
+ msg = sprintf("This is the About dialog of the textctrl sample.\n" \
100
+ "Welcome to %s", Wx::VERSION_STRING)
101
+ message_box(msg, "About Minimal", Wx::OK|Wx::ICON_INFORMATION, self)
102
+ end
103
+ end
104
+
105
+ Wx::App.run do
106
+ frame = TextCtrlFrame.new( :title => "TextCtrl demonstration",
107
+ :pos => [ 50, 50 ],
108
+ :size => [ 450, 340 ] )
109
+ frame.show
110
+ end
111
+
@@ -1,242 +1,242 @@
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
- # Tell ruby this script is written in UTF-8 encoded text.
9
- $KCODE = 'u'
10
-
11
- # Library to get character lengths (as opposed to byte lengths) from
12
- # Ruby strings.
13
- require 'jcode'
14
-
15
- require 'wx'
16
-
17
- $utf8_file = File.join( File.dirname(__FILE__), 'utf8.txt')
18
-
19
- class UnicodeDemoTextCtrl < Wx::TextCtrl
20
- NEWLINE_CORRECTION_FACTOR = 0
21
-
22
- DEFAULT_TEXT = "If you have a unicode version of wxruby, you should be able to see a range of characters from different languages displayed, and be able to type multilingual strings in the text area. Note that some scripts may only be displayed if you are using a suitable font; otherwise characters will appear as blank boxes.
23
-
24
- " << File.read( $utf8_file )
25
-
26
- def initialize(parent, text = DEFAULT_TEXT)
27
- super(parent, -1, text,
28
- Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, Wx::TE_MULTILINE)
29
- end
30
-
31
- # run through a few useful methods of textctrl and report the results
32
- # as a string
33
- def report()
34
- report = ''
35
- sel = get_string_selection()
36
- report << 'Selected string byte length: ' << sel.length.to_s << "\n"
37
- report << 'Selected string character length: ' << sel.jlength.to_s << "\n"
38
- report << 'Selected string:: ' << sel.inspect << "\n"
39
- return report
40
- end
41
- end
42
-
43
- # A read-only text ctrl useful for displaying output
44
- class LogTextCtrl < Wx::TextCtrl
45
- STYLE = Wx::TE_READONLY|Wx::TE_MULTILINE
46
- def initialize(parent)
47
- super(parent, -1, '', Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, STYLE)
48
- end
49
- end
50
-
51
- class IConvFrame < Wx::Frame
52
- # Ruby stdlib for converting strings between encodings
53
- begin
54
- require 'iconv'
55
- ICONV_LOADED = 1
56
- rescue LoadError
57
- end
58
-
59
- # The encodings we're going to make importable and exportable in this
60
- # application - see construct_import_export_menus below
61
- ENCODINGS = { 'US ASCII' => 'ASCII',
62
- 'UTF-8' => 'UTF-8',
63
- 'UTF-16' => 'UTF-16',
64
- 'Windows Latin CP1252' => 'CP1252',
65
- 'Latin ISO-8859-1' => 'ISO-8859-1',
66
- 'Japanese SHIFT-JIS' => 'SHIFT-JIS' }
67
-
68
- def initialize(title, pos, size)
69
- super(nil, -1, title, pos, size)
70
- panel = Wx::Panel.new(self)
71
- sizer = Wx::BoxSizer.new(Wx::VERTICAL)
72
-
73
- sys_lang = Wx::Locale.get_system_language_name
74
- text = Wx::StaticText.new(panel, -1, "System language: #{sys_lang}")
75
- sizer.add(text, 0, Wx::ALL, 5)
76
-
77
- sys_enc = Wx::Locale.get_system_encoding_name
78
- text = Wx::StaticText.new(panel, -1, "System default encoding: #{sys_enc}")
79
- sizer.add(text, 0, Wx::ALL, 5)
80
-
81
- # The text input and display
82
- @textctrl = UnicodeDemoTextCtrl.new(panel)
83
- sizer.add(@textctrl, 3, Wx::GROW|Wx::ALL, 2)
84
-
85
- # The button to show what's selected
86
- button = Wx::Button.new(panel, -1, 'Describe text selection')
87
- sizer.add(button, 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2 )
88
- evt_button(button.get_id) { | e | on_click(e) }
89
-
90
- @log = LogTextCtrl.new(panel)
91
- sizer.add(@log, 1, Wx::GROW|Wx::ALL, 2)
92
- sizer.add( Wx::StaticText.new(panel, -1, 'Some controls with unicode'),
93
- 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2 )
94
- ctrl_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL)
95
-
96
- test_button = Wx::Button.new(panel, -1, '万')
97
- ctrl_sizer.add(test_button, 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2)
98
- choice = Wx::Choice.new(panel, -1, Wx::DEFAULT_POSITION,
99
- Wx::DEFAULT_SIZE, [])
100
- File.readlines($utf8_file).each do | line |
101
- next if line.chomp.empty?
102
- choice.append(line.chomp)
103
- end
104
- choice.set_selection(0)
105
- ctrl_sizer.add(choice, 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2)
106
-
107
- sizer.add(ctrl_sizer, 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2)
108
- construct_menus()
109
- panel.set_sizer_and_fit( sizer )
110
- end
111
-
112
- # Prompt the user to specify a file whose contents should be loaded
113
- # into the text ctrl. The file should be encoded in +encoding+
114
- def on_import_file(encoding)
115
- fd = Wx::FileDialog.new( nil, 'Import file', "", "",
116
- "*.*", Wx::OPEN|Wx::FILE_MUST_EXIST )
117
- return unless fd.show_modal() == Wx::ID_OK
118
- File.open( fd.get_path ) do | file |
119
- import_file( file, encoding )
120
- end
121
- rescue Iconv::IllegalSequence
122
- message = "The file %s does not seem to be in %s encoding " %
123
- [ fd.get_filename, encoding ]
124
- Wx::MessageDialog.new(self, message, 'Wrong encoding',
125
- Wx::OK|Wx::ICON_EXCLAMATION).show_modal()
126
- end
127
-
128
- # Read +io+, which should be text file encoding in +source_encoding+,
129
- # and display the contents in the textctrl.
130
- def import_file(io, source_encoding = 'UTF-8')
131
- case source_encoding
132
- when /UTF-?8/
133
- @textctrl.set_value( io.read() )
134
- else
135
- output = ''
136
- Iconv.open('UTF-8', source_encoding) do | converter |
137
- output << converter.iconv( io.read() )
138
- output << converter.iconv(nil)
139
- end
140
- @textctrl.set_value( output )
141
- end
142
- end
143
-
144
- # Ask the user for a file path, and then export the content of the
145
- # textctrl to it in the encoding +encoding+
146
- def on_export_file(encoding)
147
- fd = Wx::FileDialog.new( nil, 'Export file', "", "",
148
- "*.*", Wx::SAVE|Wx::OVERWRITE_PROMPT )
149
- return unless fd.show_modal() == Wx::ID_OK
150
- File.open( fd.get_path, 'w' ) do | file |
151
- export_file( file, encoding )
152
- end
153
- rescue Iconv::IllegalSequence
154
- message = "The text content containts characters that " <<
155
- "cannot be encoded using %s" % encoding
156
- Wx::MessageDialog.new(self, message, 'Invalid encoding',
157
- Wx::OK|Wx::ICON_EXCLAMATION).show_modal()
158
- end
159
-
160
- # Write the content of the textctrl to the file or io +io+, encoding
161
- # the text in encoding +target_encoding+
162
- def export_file(io, target_encoding = 'utf-8')
163
- case target_encoding
164
- when /UTF-?8/
165
- io.write( @textctrl.get_value )
166
- else
167
- Iconv.open(target_encoding, 'UTF-8') do | converter |
168
- io << converter.iconv( @textctrl.get_value )
169
- io << converter.iconv(nil)
170
- end
171
- end
172
- end
173
-
174
- def construct_menus()
175
- menu_bar = Wx::MenuBar.new()
176
-
177
- menu_file = Wx::Menu.new()
178
- menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
179
- evt_menu(Wx::ID_EXIT) { on_quit() }
180
- menu_bar.append(menu_file, "&File")
181
- if self.class.const_defined?(:ICONV_LOADED)
182
- construct_import_export_menus(menu_bar)
183
- end
184
-
185
- menu_help = Wx::Menu.new()
186
- menu_help.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
187
- evt_menu(Wx::ID_ABOUT) { on_about() }
188
- menu_bar.append(menu_help, "&Help")
189
-
190
- set_menu_bar(menu_bar)
191
- end
192
-
193
- def construct_import_export_menus(menu_bar)
194
- id_counter = 0
195
- menu_import = Wx::Menu.new()
196
-
197
- ENCODINGS.each do | desc, enc |
198
- id_counter += 1
199
- menu_import.append(id_counter, "Import (#{desc})",
200
- "Import a file in #{desc} encoding")
201
-
202
- evt_menu(id_counter) { on_import_file(enc) }
203
- end
204
- menu_bar.append(menu_import, '&Import')
205
-
206
- menu_export = Wx::Menu.new()
207
- ENCODINGS.each do | desc, enc |
208
- id_counter += 1
209
- menu_export.append(id_counter, "Export (#{desc})",
210
- "Export a file in #{desc} encoding")
211
-
212
- evt_menu(id_counter) { on_export_file(enc) }
213
- end
214
- menu_bar.append(menu_export, '&Export')
215
- end
216
-
217
- def on_click(e)
218
- @log.set_value( @textctrl.report() )
219
- end
220
-
221
- def on_quit()
222
- close(TRUE)
223
- end
224
-
225
- def on_about()
226
- msg = sprintf("This is the About dialog of the Unicode sample.\n" \
227
- "Welcome to %s", Wx::VERSION_STRING)
228
- Wx::message_box(msg, "About Minimal", Wx::OK|Wx::ICON_INFORMATION, self)
229
- end
230
- end
231
-
232
- class IConvApp < Wx::App
233
- def on_init()
234
- frame = IConvFrame.new("Unicode demonstration - ",
235
- Wx::Point.new(50, 50),
236
- Wx::Size.new(450, 450) )
237
-
238
- frame.show(true)
239
- end
240
- end
241
-
242
- IConvApp.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
+ # Tell ruby this script is written in UTF-8 encoded text.
9
+ $KCODE = 'u'
10
+
11
+ # Library to get character lengths (as opposed to byte lengths) from
12
+ # Ruby strings.
13
+ require 'jcode'
14
+
15
+ require 'wx'
16
+
17
+ $utf8_file = File.join( File.dirname(__FILE__), 'utf8.txt')
18
+
19
+ class UnicodeDemoTextCtrl < Wx::TextCtrl
20
+ NEWLINE_CORRECTION_FACTOR = 0
21
+
22
+ DEFAULT_TEXT = "If you have a unicode version of wxruby, you should be able to see a range of characters from different languages displayed, and be able to type multilingual strings in the text area. Note that some scripts may only be displayed if you are using a suitable font; otherwise characters will appear as blank boxes.
23
+
24
+ " << File.read( $utf8_file )
25
+
26
+ def initialize(parent, text = DEFAULT_TEXT)
27
+ super(parent, -1, text,
28
+ Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, Wx::TE_MULTILINE)
29
+ end
30
+
31
+ # run through a few useful methods of textctrl and report the results
32
+ # as a string
33
+ def report()
34
+ report = ''
35
+ sel = get_string_selection()
36
+ report << 'Selected string byte length: ' << sel.length.to_s << "\n"
37
+ report << 'Selected string character length: ' << sel.jlength.to_s << "\n"
38
+ report << 'Selected string:: ' << sel.inspect << "\n"
39
+ return report
40
+ end
41
+ end
42
+
43
+ # A read-only text ctrl useful for displaying output
44
+ class LogTextCtrl < Wx::TextCtrl
45
+ STYLE = Wx::TE_READONLY|Wx::TE_MULTILINE
46
+ def initialize(parent)
47
+ super(parent, -1, '', Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, STYLE)
48
+ end
49
+ end
50
+
51
+ class IConvFrame < Wx::Frame
52
+ # Ruby stdlib for converting strings between encodings
53
+ begin
54
+ require 'iconv'
55
+ ICONV_LOADED = 1
56
+ rescue LoadError
57
+ end
58
+
59
+ # The encodings we're going to make importable and exportable in this
60
+ # application - see construct_import_export_menus below
61
+ ENCODINGS = { 'US ASCII' => 'ASCII',
62
+ 'UTF-8' => 'UTF-8',
63
+ 'UTF-16' => 'UTF-16',
64
+ 'Windows Latin CP1252' => 'CP1252',
65
+ 'Latin ISO-8859-1' => 'ISO-8859-1',
66
+ 'Japanese SHIFT-JIS' => 'SHIFT-JIS' }
67
+
68
+ def initialize(title, pos, size)
69
+ super(nil, -1, title, pos, size)
70
+ panel = Wx::Panel.new(self)
71
+ sizer = Wx::BoxSizer.new(Wx::VERTICAL)
72
+
73
+ sys_lang = Wx::Locale.get_system_language_name
74
+ text = Wx::StaticText.new(panel, -1, "System language: #{sys_lang}")
75
+ sizer.add(text, 0, Wx::ALL, 5)
76
+
77
+ sys_enc = Wx::Locale.get_system_encoding_name
78
+ text = Wx::StaticText.new(panel, -1, "System default encoding: #{sys_enc}")
79
+ sizer.add(text, 0, Wx::ALL, 5)
80
+
81
+ # The text input and display
82
+ @textctrl = UnicodeDemoTextCtrl.new(panel)
83
+ sizer.add(@textctrl, 3, Wx::GROW|Wx::ALL, 2)
84
+
85
+ # The button to show what's selected
86
+ button = Wx::Button.new(panel, -1, 'Describe text selection')
87
+ sizer.add(button, 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2 )
88
+ evt_button(button.get_id) { | e | on_click(e) }
89
+
90
+ @log = LogTextCtrl.new(panel)
91
+ sizer.add(@log, 1, Wx::GROW|Wx::ALL, 2)
92
+ sizer.add( Wx::StaticText.new(panel, -1, 'Some controls with unicode'),
93
+ 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2 )
94
+ ctrl_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL)
95
+
96
+ test_button = Wx::Button.new(panel, -1, '万')
97
+ ctrl_sizer.add(test_button, 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2)
98
+ choice = Wx::Choice.new(panel, -1, Wx::DEFAULT_POSITION,
99
+ Wx::DEFAULT_SIZE, [])
100
+ File.readlines($utf8_file).each do | line |
101
+ next if line.chomp.empty?
102
+ choice.append(line.chomp)
103
+ end
104
+ choice.set_selection(0)
105
+ ctrl_sizer.add(choice, 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2)
106
+
107
+ sizer.add(ctrl_sizer, 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2)
108
+ construct_menus()
109
+ panel.set_sizer_and_fit( sizer )
110
+ end
111
+
112
+ # Prompt the user to specify a file whose contents should be loaded
113
+ # into the text ctrl. The file should be encoded in +encoding+
114
+ def on_import_file(encoding)
115
+ fd = Wx::FileDialog.new( nil, 'Import file', "", "",
116
+ "*.*", Wx::OPEN|Wx::FILE_MUST_EXIST )
117
+ return unless fd.show_modal() == Wx::ID_OK
118
+ File.open( fd.get_path ) do | file |
119
+ import_file( file, encoding )
120
+ end
121
+ rescue Iconv::IllegalSequence
122
+ message = "The file %s does not seem to be in %s encoding " %
123
+ [ fd.get_filename, encoding ]
124
+ Wx::MessageDialog.new(self, message, 'Wrong encoding',
125
+ Wx::OK|Wx::ICON_EXCLAMATION).show_modal()
126
+ end
127
+
128
+ # Read +io+, which should be text file encoding in +source_encoding+,
129
+ # and display the contents in the textctrl.
130
+ def import_file(io, source_encoding = 'UTF-8')
131
+ case source_encoding
132
+ when /UTF-?8/
133
+ @textctrl.set_value( io.read() )
134
+ else
135
+ output = ''
136
+ Iconv.open('UTF-8', source_encoding) do | converter |
137
+ output << converter.iconv( io.read() )
138
+ output << converter.iconv(nil)
139
+ end
140
+ @textctrl.set_value( output )
141
+ end
142
+ end
143
+
144
+ # Ask the user for a file path, and then export the content of the
145
+ # textctrl to it in the encoding +encoding+
146
+ def on_export_file(encoding)
147
+ fd = Wx::FileDialog.new( nil, 'Export file', "", "",
148
+ "*.*", Wx::SAVE|Wx::OVERWRITE_PROMPT )
149
+ return unless fd.show_modal() == Wx::ID_OK
150
+ File.open( fd.get_path, 'w' ) do | file |
151
+ export_file( file, encoding )
152
+ end
153
+ rescue Iconv::IllegalSequence
154
+ message = "The text content containts characters that " <<
155
+ "cannot be encoded using %s" % encoding
156
+ Wx::MessageDialog.new(self, message, 'Invalid encoding',
157
+ Wx::OK|Wx::ICON_EXCLAMATION).show_modal()
158
+ end
159
+
160
+ # Write the content of the textctrl to the file or io +io+, encoding
161
+ # the text in encoding +target_encoding+
162
+ def export_file(io, target_encoding = 'utf-8')
163
+ case target_encoding
164
+ when /UTF-?8/
165
+ io.write( @textctrl.get_value )
166
+ else
167
+ Iconv.open(target_encoding, 'UTF-8') do | converter |
168
+ io << converter.iconv( @textctrl.get_value )
169
+ io << converter.iconv(nil)
170
+ end
171
+ end
172
+ end
173
+
174
+ def construct_menus()
175
+ menu_bar = Wx::MenuBar.new()
176
+
177
+ menu_file = Wx::Menu.new()
178
+ menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
179
+ evt_menu(Wx::ID_EXIT) { on_quit() }
180
+ menu_bar.append(menu_file, "&File")
181
+ if self.class.const_defined?(:ICONV_LOADED)
182
+ construct_import_export_menus(menu_bar)
183
+ end
184
+
185
+ menu_help = Wx::Menu.new()
186
+ menu_help.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
187
+ evt_menu(Wx::ID_ABOUT) { on_about() }
188
+ menu_bar.append(menu_help, "&Help")
189
+
190
+ set_menu_bar(menu_bar)
191
+ end
192
+
193
+ def construct_import_export_menus(menu_bar)
194
+ id_counter = 0
195
+ menu_import = Wx::Menu.new()
196
+
197
+ ENCODINGS.each do | desc, enc |
198
+ id_counter += 1
199
+ menu_import.append(id_counter, "Import (#{desc})",
200
+ "Import a file in #{desc} encoding")
201
+
202
+ evt_menu(id_counter) { on_import_file(enc) }
203
+ end
204
+ menu_bar.append(menu_import, '&Import')
205
+
206
+ menu_export = Wx::Menu.new()
207
+ ENCODINGS.each do | desc, enc |
208
+ id_counter += 1
209
+ menu_export.append(id_counter, "Export (#{desc})",
210
+ "Export a file in #{desc} encoding")
211
+
212
+ evt_menu(id_counter) { on_export_file(enc) }
213
+ end
214
+ menu_bar.append(menu_export, '&Export')
215
+ end
216
+
217
+ def on_click(e)
218
+ @log.set_value( @textctrl.report() )
219
+ end
220
+
221
+ def on_quit()
222
+ close(TRUE)
223
+ end
224
+
225
+ def on_about()
226
+ msg = sprintf("This is the About dialog of the Unicode sample.\n" \
227
+ "Welcome to %s", Wx::VERSION_STRING)
228
+ Wx::message_box(msg, "About Minimal", Wx::OK|Wx::ICON_INFORMATION, self)
229
+ end
230
+ end
231
+
232
+ class IConvApp < Wx::App
233
+ def on_init()
234
+ frame = IConvFrame.new("Unicode demonstration - ",
235
+ Wx::Point.new(50, 50),
236
+ Wx::Size.new(450, 450) )
237
+
238
+ frame.show(true)
239
+ end
240
+ end
241
+
242
+ IConvApp.new().main_loop()