wxruby 1.9.0-i386-mswin32 → 1.9.1-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. data/lib/wx.rb +42 -35
  2. data/lib/wx/accessors.rb +52 -0
  3. data/lib/wx/classes/evthandler.rb +36 -32
  4. data/lib/wx/classes/grid.rb +13 -13
  5. data/lib/wx/classes/point.rb +43 -0
  6. data/lib/wx/classes/size.rb +44 -0
  7. data/lib/wx/classes/styledtextctrl.rb +92 -0
  8. data/lib/wx/classes/textctrl.rb +14 -0
  9. data/lib/wx/classes/window.rb +4 -0
  10. data/lib/wx/keyword_ctors.rb +219 -0
  11. data/lib/wx/keyword_defs.rb +455 -0
  12. data/lib/wx/version.rb +1 -1
  13. data/lib/wxruby2.exp +0 -0
  14. data/lib/wxruby2.lib +0 -0
  15. data/lib/wxruby2.so +0 -0
  16. data/samples/SAMPLES-LICENSE.TXT +17 -17
  17. data/samples/aui/aui.rb +6 -5
  18. data/samples/bigdemo/About.rbw +39 -39
  19. data/samples/bigdemo/ColorPanel.rbw +25 -25
  20. data/samples/bigdemo/GridSimple.rbw +80 -80
  21. data/samples/bigdemo/MDIDemo.rbw +59 -59
  22. data/samples/bigdemo/PopupMenu.rbw +151 -151
  23. data/samples/bigdemo/Sizers.rbw +545 -545
  24. data/samples/bigdemo/bigdemo.rb +826 -826
  25. data/samples/bigdemo/demoTemplate.rbw +37 -37
  26. data/samples/bigdemo/icons/choice.xpm +27 -27
  27. data/samples/bigdemo/icons/combo.xpm +27 -27
  28. data/samples/bigdemo/icons/copy.xpm +25 -25
  29. data/samples/bigdemo/icons/cut.xpm +24 -24
  30. data/samples/bigdemo/icons/gauge.xpm +27 -27
  31. data/samples/bigdemo/icons/help.xpm +25 -25
  32. data/samples/bigdemo/icons/list.xpm +27 -27
  33. data/samples/bigdemo/icons/mondrian.xpm +44 -44
  34. data/samples/bigdemo/icons/new.xpm +24 -24
  35. data/samples/bigdemo/icons/ogl.ico +0 -0
  36. data/samples/bigdemo/icons/ogl.xpm +45 -45
  37. data/samples/bigdemo/icons/open.xpm +26 -26
  38. data/samples/bigdemo/icons/paste.xpm +38 -38
  39. data/samples/bigdemo/icons/preview.xpm +26 -26
  40. data/samples/bigdemo/icons/print.xpm +26 -26
  41. data/samples/bigdemo/icons/radio.xpm +27 -27
  42. data/samples/bigdemo/icons/robert.xpm +415 -415
  43. data/samples/bigdemo/icons/save.xpm +25 -25
  44. data/samples/bigdemo/icons/smiles.xpm +39 -39
  45. data/samples/bigdemo/icons/smiley.xpm +42 -42
  46. data/samples/bigdemo/icons/stattext.xpm +24 -24
  47. data/samples/bigdemo/icons/test2.bmp +0 -0
  48. data/samples/bigdemo/icons/test2.xpm +79 -79
  49. data/samples/bigdemo/icons/text.xpm +27 -27
  50. data/samples/bigdemo/icons/tog1.xpm +38 -38
  51. data/samples/bigdemo/icons/tog2.xpm +38 -38
  52. data/samples/bigdemo/icons/wxwin16x16.xpm +25 -25
  53. data/samples/bigdemo/tips.txt +7 -7
  54. data/samples/bigdemo/utils.rb +11 -11
  55. data/samples/bigdemo/wxButton.rbw +66 -66
  56. data/samples/bigdemo/wxCalendarCtrl.rbw +72 -72
  57. data/samples/bigdemo/wxCheckBox.rbw +52 -52
  58. data/samples/bigdemo/wxCheckListBox.rbw +77 -77
  59. data/samples/bigdemo/wxChoice.rbw +49 -49
  60. data/samples/bigdemo/wxColourDialog.rbw +34 -34
  61. data/samples/bigdemo/wxComboBox.rbw +79 -79
  62. data/samples/bigdemo/wxDialog.rbw +92 -92
  63. data/samples/bigdemo/wxDirDialog.rbw +32 -32
  64. data/samples/bigdemo/wxFileDialog.rbw +39 -39
  65. data/samples/bigdemo/wxFileDialog_Save.rbw +38 -38
  66. data/samples/bigdemo/wxFindReplaceDialog.rbw +85 -85
  67. data/samples/bigdemo/wxFontDialog.rbw +176 -176
  68. data/samples/bigdemo/wxFrame.rbw +55 -55
  69. data/samples/bigdemo/wxGauge.rbw +73 -73
  70. data/samples/bigdemo/wxGrid.rbw +68 -68
  71. data/samples/bigdemo/wxListBox.rbw +142 -142
  72. data/samples/bigdemo/wxListCtrl_virtual.rbw +109 -109
  73. data/samples/bigdemo/wxMDIWindows.rbw +52 -52
  74. data/samples/bigdemo/wxMenu.rbw +238 -238
  75. data/samples/bigdemo/wxMessageDialog.rbw +30 -30
  76. data/samples/bigdemo/wxMultipleChoiceDialog.rbw +34 -34
  77. data/samples/bigdemo/wxNotebook.rbw +138 -138
  78. data/samples/bigdemo/wxProgressDialog.rbw +45 -45
  79. data/samples/bigdemo/wxRadioBox.rbw +74 -74
  80. data/samples/bigdemo/wxRadioButton.rbw +127 -127
  81. data/samples/bigdemo/wxScrolledMessageDialog.rbw +59 -59
  82. data/samples/bigdemo/wxScrolledWindow.rbw +196 -196
  83. data/samples/bigdemo/wxSingleChoiceDialog.rbw +35 -35
  84. data/samples/bigdemo/wxSlider.rbw +44 -44
  85. data/samples/bigdemo/wxSpinButton.rbw +52 -52
  86. data/samples/bigdemo/wxSpinCtrl.rbw +53 -53
  87. data/samples/bigdemo/wxSplitterWindow.rbw +65 -65
  88. data/samples/bigdemo/wxStaticBitmap.rbw +53 -53
  89. data/samples/bigdemo/wxStaticText.rbw +57 -57
  90. data/samples/bigdemo/wxStatusBar.rbw +128 -128
  91. data/samples/bigdemo/wxTextCtrl.rbw +151 -151
  92. data/samples/bigdemo/wxTextEntryDialog.rbw +34 -34
  93. data/samples/bigdemo/wxToggleButton.rbw +51 -51
  94. data/samples/bigdemo/wxToolBar.rbw +133 -133
  95. data/samples/bigdemo/wxTreeCtrl.rbw +192 -192
  96. data/samples/calendar/calendar.rb +275 -275
  97. data/samples/caret/caret.rb +296 -296
  98. data/samples/caret/mondrian.xpm +44 -44
  99. data/samples/controls/controls.rb +1140 -1140
  100. data/samples/controls/get_item_sample.rb +87 -87
  101. data/samples/controls/icons/choice.xpm +27 -27
  102. data/samples/controls/icons/combo.xpm +27 -27
  103. data/samples/controls/icons/gauge.xpm +27 -27
  104. data/samples/controls/icons/list.xpm +27 -27
  105. data/samples/controls/icons/radio.xpm +27 -27
  106. data/samples/controls/icons/stattext.xpm +24 -24
  107. data/samples/controls/icons/text.xpm +27 -27
  108. data/samples/controls/mondrian.xpm +44 -44
  109. data/samples/dialogs/dialogs.rb +724 -724
  110. data/samples/dialogs/tips.txt +18 -18
  111. data/samples/etc/activation.rb +108 -108
  112. data/samples/etc/choice.rb +72 -72
  113. data/samples/etc/miniframe.rb +84 -84
  114. data/samples/etc/sash.rb +135 -135
  115. data/samples/etc/scrollwin.rb +116 -116
  116. data/samples/etc/system_settings.rb +258 -258
  117. data/samples/etc/wizard.rb +81 -81
  118. data/samples/event/event.rb +184 -0
  119. data/samples/images/images.rb +48 -48
  120. data/samples/listbook/listbook.rb +183 -183
  121. data/samples/listbook/listbook.xrc +370 -370
  122. data/samples/mdi/mdi.rb +87 -87
  123. data/samples/minimal/minimal.rb +83 -95
  124. data/samples/minimal/mondrian.png +0 -0
  125. data/samples/minimal/nothing.rb +46 -46
  126. data/samples/minimal/text.rb +35 -35
  127. data/samples/text/scintilla.rb +22 -28
  128. data/samples/text/textctrl.rb +124 -124
  129. data/samples/text/unicode.rb +238 -238
  130. data/samples/text/utf8.txt +14 -14
  131. data/samples/treectrl/treectrl.rb +1210 -1210
  132. data/samples/xrc/samples.xrc +46 -46
  133. data/samples/xrc/xrc_sample.rb +107 -107
  134. metadata +13 -5
  135. data/samples/minimal/mondrian.ico +0 -0
  136. data/samples/minimal/mondrian.xpm +0 -44
@@ -24,12 +24,6 @@ class MyFrame < Frame
24
24
  def initialize(title,pos,size,style=DEFAULT_FRAME_STYLE)
25
25
  super(nil,-1,title,pos,size,style)
26
26
 
27
- if Wx::PLATFORM == "WXMSW"
28
- set_icon(Icon.new("mondrian.ico",BITMAP_TYPE_ICO))
29
- else
30
- set_icon(Icon.new("mondrian.xpm",BITMAP_TYPE_XPM))
31
- end
32
-
33
27
  menuFile = Menu.new()
34
28
  menuFile.append(Minimal_Quit, "E&xit\tAlt-X", "Quit this program")
35
29
 
@@ -51,23 +45,23 @@ class MyFrame < Frame
51
45
  create_status_bar(2)
52
46
  set_status_text("Welcome to wxRuby!")
53
47
 
54
- @sci = Wx::Scintilla.new(self)
48
+ @sci = Wx::StyledTextCtrl.new(self)
55
49
 
56
50
  font = Font.new(10, TELETYPE, NORMAL, NORMAL)
57
- @sci.style_set_font(SCI_STYLE_DEFAULT, font);
51
+ @sci.style_set_font(STC_STYLE_DEFAULT, font);
58
52
 
59
53
  @ws_visible = false
60
54
  @eol_visible = false
61
- @sci.set_edge_mode(SCI_EDGE_LINE)
55
+ @sci.set_edge_mode(STC_EDGE_LINE)
62
56
 
63
- line_num_margin = @sci.text_width(SCI_STYLE_LINENUMBER, "_99999")
57
+ line_num_margin = @sci.text_width(STC_STYLE_LINENUMBER, "_99999")
64
58
  @sci.set_margin_width(0, line_num_margin)
65
59
 
66
- @sci.style_set_foreground(SCI_STYLE_DEFAULT, BLACK);
67
- @sci.style_set_background(SCI_STYLE_DEFAULT, WHITE);
68
- @sci.style_set_foreground(SCI_STYLE_LINENUMBER, LIGHT_GREY);
69
- @sci.style_set_background(SCI_STYLE_LINENUMBER, WHITE);
70
- @sci.style_set_foreground(SCI_STYLE_INDENTGUIDE, LIGHT_GREY);
60
+ @sci.style_set_foreground(STC_STYLE_DEFAULT, BLACK);
61
+ @sci.style_set_background(STC_STYLE_DEFAULT, WHITE);
62
+ @sci.style_set_foreground(STC_STYLE_LINENUMBER, LIGHT_GREY);
63
+ @sci.style_set_background(STC_STYLE_LINENUMBER, WHITE);
64
+ @sci.style_set_foreground(STC_STYLE_INDENTGUIDE, LIGHT_GREY);
71
65
 
72
66
  @sci.set_tab_width(4)
73
67
  @sci.set_use_tabs(false)
@@ -76,7 +70,7 @@ class MyFrame < Frame
76
70
  @sci.set_indent(4)
77
71
  @sci.set_edge_column(80)
78
72
 
79
- @sci.set_lexer(SCI_LEX_RUBY)
73
+ @sci.set_lexer(STC_LEX_RUBY)
80
74
  @sci.style_clear_all
81
75
  @sci.style_set_foreground(2, RED)
82
76
  @sci.style_set_foreground(3, GREEN)
@@ -91,17 +85,17 @@ class MyFrame < Frame
91
85
  @sci.set_property("fold.preprocessor", "1")
92
86
 
93
87
  @sci.set_margin_width(1, 0)
94
- @sci.set_margin_type(1, SCI_MARGIN_SYMBOL)
95
- @sci.set_margin_mask(1, SCI_MASK_FOLDERS)
88
+ @sci.set_margin_type(1, STC_MARGIN_SYMBOL)
89
+ @sci.set_margin_mask(1, STC_MASK_FOLDERS)
96
90
  @sci.set_margin_width(1, 20)
97
91
 
98
- @sci.marker_define(SCI_MARKNUM_FOLDER, SCI_MARK_PLUS)
99
- @sci.marker_define(SCI_MARKNUM_FOLDEROPEN, SCI_MARK_MINUS)
100
- @sci.marker_define(SCI_MARKNUM_FOLDEREND, SCI_MARK_EMPTY)
101
- @sci.marker_define(SCI_MARKNUM_FOLDERMIDTAIL, SCI_MARK_EMPTY)
102
- @sci.marker_define(SCI_MARKNUM_FOLDEROPENMID, SCI_MARK_EMPTY)
103
- @sci.marker_define(SCI_MARKNUM_FOLDERSUB, SCI_MARK_EMPTY)
104
- @sci.marker_define(SCI_MARKNUM_FOLDERTAIL, SCI_MARK_EMPTY)
92
+ @sci.marker_define(STC_MARKNUM_FOLDER, STC_MARK_PLUS)
93
+ @sci.marker_define(STC_MARKNUM_FOLDEROPEN, STC_MARK_MINUS)
94
+ @sci.marker_define(STC_MARKNUM_FOLDEREND, STC_MARK_EMPTY)
95
+ @sci.marker_define(STC_MARKNUM_FOLDERMIDTAIL, STC_MARK_EMPTY)
96
+ @sci.marker_define(STC_MARKNUM_FOLDEROPENMID, STC_MARK_EMPTY)
97
+ @sci.marker_define(STC_MARKNUM_FOLDERSUB, STC_MARK_EMPTY)
98
+ @sci.marker_define(STC_MARKNUM_FOLDERTAIL, STC_MARK_EMPTY)
105
99
  @sci.set_fold_flags(16)
106
100
 
107
101
  @sci.set_margin_sensitive(1,1)
@@ -110,8 +104,8 @@ class MyFrame < Frame
110
104
  evt_menu(Minimal_About) {onAbout}
111
105
  evt_menu(Toggle_Whitespace) {onWhitespace}
112
106
  evt_menu(Toggle_EOL) {onEOL}
113
- evt_sci_charadded {|evt| onCharadded(evt)}
114
- evt_sci_marginclick {|evt| onMarginClick(evt)}
107
+ evt_stc_charadded(@sci.get_id) {|evt| onCharadded(evt)}
108
+ evt_stc_marginclick(@sci.get_id) {|evt| onMarginClick(evt)}
115
109
 
116
110
  end
117
111
 
@@ -130,7 +124,7 @@ class MyFrame < Frame
130
124
 
131
125
  def onWhitespace
132
126
  @ws_visible = !@ws_visible
133
- @sci.set_view_white_space(@ws_visible ? SCI_WS_VISIBLEALWAYS : SCI_WS_INVISIBLE)
127
+ @sci.set_view_white_space(@ws_visible ? STC_WS_VISIBLEALWAYS : STC_WS_INVISIBLE)
134
128
  end
135
129
 
136
130
  def onEOL
@@ -1,124 +1,124 @@
1
- #!/usr/bin/env ruby
2
- # wxRuby2 Sample Code. Copyright (c) 2004-2006 Kevin B. Smith
3
- # Freely reusable code: see SAMPLES-LICENSE.TXT for details
4
-
5
- begin
6
- require 'wx'
7
- rescue LoadError => no_wx_err
8
- begin
9
- require 'rubygems'
10
- require 'wx'
11
- rescue LoadError
12
- raise no_wx_err
13
- end
14
- end
15
-
16
- class InformativeTextCtrl < Wx::TextCtrl
17
- NEWLINE_CORRECTION_FACTOR = 0
18
-
19
- # These text controls are multiline, and may have rich (coloured,
20
- # styled) text in them
21
- STYLE = Wx::TE_MULTILINE|Wx::TE_RICH|Wx::TE_RICH2
22
- def initialize(parent, text)
23
- super(parent, -1, text, Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, STYLE)
24
- end
25
-
26
- # more ruby-ish
27
- alias :<< :append_text
28
-
29
- # run through a few useful methods of textctrl and report the results
30
- # as a string
31
- def report()
32
- report = ''
33
- report << 'Insertion Point: ' << get_insertion_point.to_s() << "\n"
34
- report << 'First Line Text: ' << get_line_text(0) << "\n"
35
- report << 'Final Position: ' << get_last_position().to_s() << "\n"
36
- report << 'Selection: ' << get_selection().inspect() << "\n"
37
- report << 'String Selection: ' << get_string_selection().inspect << "\n"
38
- report << 'Position to X, Y: ' <<
39
- position_to_xy( get_insertion_point ).inspect
40
- return report
41
- end
42
- end
43
-
44
- # A read-only text ctrl useful for displaying output
45
- class LogTextCtrl < Wx::TextCtrl
46
- STYLE = Wx::TE_READONLY|Wx::TE_MULTILINE
47
- def initialize(parent)
48
- super(parent, -1, '', Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, STYLE)
49
- end
50
- end
51
-
52
- class TextCtrlFrame < Wx::Frame
53
- def initialize(title, pos, size)
54
- super(nil, -1, title, pos, size)
55
-
56
- panel = Wx::Panel.new(self, -1)
57
- sizer = Wx::BoxSizer.new(Wx::VERTICAL)
58
-
59
- @textctrl = InformativeTextCtrl.new(panel, '')
60
- populate_textctrl()
61
- sizer.add(@textctrl, 2, Wx::GROW|Wx::ALL, 2)
62
-
63
- button = Wx::Button.new(panel, -1, 'Get Info')
64
- sizer.add(button, 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2 )
65
- evt_button(button.get_id) { | e | on_click(e) }
66
-
67
- @log = LogTextCtrl.new(panel)
68
- sizer.add(@log, 1, Wx::GROW|Wx::ALL, 2)
69
-
70
- panel.set_sizer( sizer )
71
- end
72
-
73
- def populate_textctrl()
74
- @textctrl << "This is some plain text\n"
75
- @textctrl << "Text with green letters and yellow background\n"
76
- @textctrl << "This is some more plain text"
77
- # create a new rich text style
78
- attr = Wx::TextAttr.new(Wx::GREEN, Wx::Colour.new(255, 255, 0) )
79
- # apply the style from character 26 to character 76
80
- @textctrl.set_style(24, 69, attr)
81
- end
82
-
83
- def construct_menus()
84
- menu_bar = Wx::MenuBar.new()
85
-
86
- menu_file = Wx::Menu.new()
87
- menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
88
- menu_bar.append(menu_file, "&File")
89
- evt_menu(Wx::ID_EXIT) { on_quit() }
90
-
91
- menu_help = Wx::Menu.new()
92
- menu_help.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
93
- evt_menu(Wx::ID_ABOUT) { on_about() }
94
- menu_bar.append(menu_help, "&Help")
95
-
96
- set_menu_bar(menu_bar)
97
- end
98
-
99
- def on_click(e)
100
- @log.set_value( @textctrl.report() )
101
- end
102
-
103
- def on_quit()
104
- close(TRUE)
105
- end
106
-
107
- def on_about()
108
- msg = sprintf("This is the About dialog of the textctrl sample.\n" \
109
- "Welcome to %s", Wx::VERSION_STRING)
110
- message_box(msg, "About Minimal", Wx::OK|Wx::ICON_INFORMATION, self)
111
- end
112
- end
113
-
114
- class RbApp < Wx::App
115
- def on_init()
116
- frame = TextCtrlFrame.new("TextCtrl demonstration",
117
- Wx::Point.new(50, 50),
118
- Wx::Size.new(450, 340) )
119
-
120
- frame.show(true)
121
- end
122
- end
123
-
124
- RbApp.new().main_loop()
1
+ #!/usr/bin/env ruby
2
+ # wxRuby2 Sample Code. Copyright (c) 2004-2006 Kevin B. Smith
3
+ # Freely reusable code: see SAMPLES-LICENSE.TXT for details
4
+
5
+ begin
6
+ require 'wx'
7
+ rescue LoadError => no_wx_err
8
+ begin
9
+ require 'rubygems'
10
+ require 'wx'
11
+ rescue LoadError
12
+ raise no_wx_err
13
+ end
14
+ end
15
+
16
+ class InformativeTextCtrl < Wx::TextCtrl
17
+ NEWLINE_CORRECTION_FACTOR = 0
18
+
19
+ # These text controls are multiline, and may have rich (coloured,
20
+ # styled) text in them
21
+ STYLE = Wx::TE_MULTILINE|Wx::TE_RICH|Wx::TE_RICH2
22
+ def initialize(parent, text)
23
+ super(parent, -1, text, Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, STYLE)
24
+ end
25
+
26
+ # more ruby-ish
27
+ alias :<< :append_text
28
+
29
+ # run through a few useful methods of textctrl and report the results
30
+ # as a string
31
+ def report()
32
+ report = ''
33
+ report << 'Insertion Point: ' << get_insertion_point.to_s() << "\n"
34
+ report << 'First Line Text: ' << get_line_text(0) << "\n"
35
+ report << 'Final Position: ' << get_last_position().to_s() << "\n"
36
+ report << 'Selection: ' << get_selection().inspect() << "\n"
37
+ report << 'String Selection: ' << get_string_selection().inspect << "\n"
38
+ report << 'Position to X, Y: ' <<
39
+ position_to_xy( get_insertion_point ).inspect
40
+ return report
41
+ end
42
+ end
43
+
44
+ # A read-only text ctrl useful for displaying output
45
+ class LogTextCtrl < Wx::TextCtrl
46
+ STYLE = Wx::TE_READONLY|Wx::TE_MULTILINE
47
+ def initialize(parent)
48
+ super(parent, -1, '', Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, STYLE)
49
+ end
50
+ end
51
+
52
+ class TextCtrlFrame < Wx::Frame
53
+ def initialize(title, pos, size)
54
+ super(nil, -1, title, pos, size)
55
+
56
+ panel = Wx::Panel.new(self, -1)
57
+ sizer = Wx::BoxSizer.new(Wx::VERTICAL)
58
+
59
+ @textctrl = InformativeTextCtrl.new(panel, '')
60
+ populate_textctrl()
61
+ sizer.add(@textctrl, 2, Wx::GROW|Wx::ALL, 2)
62
+
63
+ button = Wx::Button.new(panel, -1, 'Get Info')
64
+ sizer.add(button, 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2 )
65
+ evt_button(button.get_id) { | e | on_click(e) }
66
+
67
+ @log = LogTextCtrl.new(panel)
68
+ sizer.add(@log, 1, Wx::GROW|Wx::ALL, 2)
69
+
70
+ panel.set_sizer( sizer )
71
+ end
72
+
73
+ def populate_textctrl()
74
+ @textctrl << "This is some plain text\n"
75
+ @textctrl << "Text with green letters and yellow background\n"
76
+ @textctrl << "This is some more plain text"
77
+ # create a new rich text style
78
+ attr = Wx::TextAttr.new(Wx::GREEN, Wx::Colour.new(255, 255, 0) )
79
+ # apply the style from character 26 to character 76
80
+ @textctrl.set_style(24, 69, attr)
81
+ end
82
+
83
+ def construct_menus()
84
+ menu_bar = Wx::MenuBar.new()
85
+
86
+ menu_file = Wx::Menu.new()
87
+ menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
88
+ menu_bar.append(menu_file, "&File")
89
+ evt_menu(Wx::ID_EXIT) { on_quit() }
90
+
91
+ menu_help = Wx::Menu.new()
92
+ menu_help.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
93
+ evt_menu(Wx::ID_ABOUT) { on_about() }
94
+ menu_bar.append(menu_help, "&Help")
95
+
96
+ set_menu_bar(menu_bar)
97
+ end
98
+
99
+ def on_click(e)
100
+ @log.set_value( @textctrl.report() )
101
+ end
102
+
103
+ def on_quit()
104
+ close(TRUE)
105
+ end
106
+
107
+ def on_about()
108
+ msg = sprintf("This is the About dialog of the textctrl sample.\n" \
109
+ "Welcome to %s", Wx::VERSION_STRING)
110
+ message_box(msg, "About Minimal", Wx::OK|Wx::ICON_INFORMATION, self)
111
+ end
112
+ end
113
+
114
+ class RbApp < Wx::App
115
+ def on_init()
116
+ frame = TextCtrlFrame.new("TextCtrl demonstration",
117
+ Wx::Point.new(50, 50),
118
+ Wx::Size.new(450, 340) )
119
+
120
+ frame.show(true)
121
+ end
122
+ end
123
+
124
+ RbApp.new().main_loop()
@@ -1,238 +1,238 @@
1
- # wxRuby2 Sample Code. Copyright (c) 2004-2006 Kevin B. Smith
2
- # Freely reusable code: see SAMPLES-LICENSE.TXT for details
3
-
4
- # Tell ruby this script is written in UTF-8 encoded text.
5
- $KCODE = 'u'
6
-
7
- # Library to get character lengths (as opposed to byte lengths) from
8
- # Ruby strings.
9
- require 'jcode'
10
-
11
- require 'wx'
12
-
13
- $utf8_file = File.join( File.dirname(__FILE__), 'utf8.txt')
14
-
15
- class UnicodeDemoTextCtrl < Wx::TextCtrl
16
- NEWLINE_CORRECTION_FACTOR = 0
17
-
18
- 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.
19
-
20
- " << File.read( $utf8_file )
21
-
22
- def initialize(parent, text = DEFAULT_TEXT)
23
- super(parent, -1, text,
24
- Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, Wx::TE_MULTILINE)
25
- end
26
-
27
- # run through a few useful methods of textctrl and report the results
28
- # as a string
29
- def report()
30
- report = ''
31
- sel = get_string_selection()
32
- report << 'Selected string byte length: ' << sel.length.to_s << "\n"
33
- report << 'Selected string character length: ' << sel.jlength.to_s << "\n"
34
- report << 'Selected string:: ' << sel.inspect << "\n"
35
- return report
36
- end
37
- end
38
-
39
- # A read-only text ctrl useful for displaying output
40
- class LogTextCtrl < Wx::TextCtrl
41
- STYLE = Wx::TE_READONLY|Wx::TE_MULTILINE
42
- def initialize(parent)
43
- super(parent, -1, '', Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, STYLE)
44
- end
45
- end
46
-
47
- class IConvFrame < Wx::Frame
48
- # Ruby stdlib for converting strings between encodings
49
- begin
50
- require 'iconv'
51
- ICONV_LOADED = 1
52
- rescue LoadError
53
- end
54
-
55
- # The encodings we're going to make importable and exportable in this
56
- # application - see construct_import_export_menus below
57
- ENCODINGS = { 'US ASCII' => 'ASCII',
58
- 'UTF-8' => 'UTF-8',
59
- 'UTF-16' => 'UTF-16',
60
- 'Windows Latin CP1252' => 'CP1252',
61
- 'Latin ISO-8859-1' => 'ISO-8859-1',
62
- 'Japanese SHIFT-JIS' => 'SHIFT-JIS' }
63
-
64
- def initialize(title, pos, size)
65
- super(nil, -1, title, pos, size)
66
- panel = Wx::Panel.new(self)
67
- sizer = Wx::BoxSizer.new(Wx::VERTICAL)
68
-
69
- sys_lang = Wx::Locale.get_system_language_name
70
- text = Wx::StaticText.new(panel, -1, "System language: #{sys_lang}")
71
- sizer.add(text, 0, Wx::ALL, 5)
72
-
73
- sys_enc = Wx::Locale.get_system_encoding_name
74
- text = Wx::StaticText.new(panel, -1, "System default encoding: #{sys_enc}")
75
- sizer.add(text, 0, Wx::ALL, 5)
76
-
77
- # The text input and display
78
- @textctrl = UnicodeDemoTextCtrl.new(panel)
79
- sizer.add(@textctrl, 3, Wx::GROW|Wx::ALL, 2)
80
-
81
- # The button to show what's selected
82
- button = Wx::Button.new(panel, -1, 'Describe text selection')
83
- sizer.add(button, 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2 )
84
- evt_button(button.get_id) { | e | on_click(e) }
85
-
86
- @log = LogTextCtrl.new(panel)
87
- sizer.add(@log, 1, Wx::GROW|Wx::ALL, 2)
88
- sizer.add( Wx::StaticText.new(panel, -1, 'Some controls with unicode'),
89
- 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2 )
90
- ctrl_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL)
91
-
92
- test_button = Wx::Button.new(panel, -1, '万')
93
- ctrl_sizer.add(test_button, 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2)
94
- choice = Wx::Choice.new(panel, -1, Wx::DEFAULT_POSITION,
95
- Wx::DEFAULT_SIZE, [])
96
- File.readlines($utf8_file).each do | line |
97
- next if line.chomp.empty?
98
- choice.append(line.chomp)
99
- end
100
- choice.set_selection(0)
101
- ctrl_sizer.add(choice, 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2)
102
-
103
- sizer.add(ctrl_sizer, 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2)
104
- construct_menus()
105
- panel.set_sizer( sizer )
106
- end
107
-
108
- # Prompt the user to specify a file whose contents should be loaded
109
- # into the text ctrl. The file should be encoded in +encoding+
110
- def on_import_file(encoding)
111
- fd = Wx::FileDialog.new( nil, 'Import file', "", "",
112
- "*.*", Wx::OPEN|Wx::FILE_MUST_EXIST )
113
- return unless fd.show_modal() == Wx::ID_OK
114
- File.open( fd.get_path ) do | file |
115
- import_file( file, encoding )
116
- end
117
- rescue Iconv::IllegalSequence
118
- message = "The file %s does not seem to be in %s encoding " %
119
- [ fd.get_filename, encoding ]
120
- Wx::MessageDialog.new(self, message, 'Wrong encoding',
121
- Wx::OK|Wx::ICON_EXCLAMATION).show_modal()
122
- end
123
-
124
- # Read +io+, which should be text file encoding in +source_encoding+,
125
- # and display the contents in the textctrl.
126
- def import_file(io, source_encoding = 'UTF-8')
127
- case source_encoding
128
- when /UTF-?8/
129
- @textctrl.set_value( io.read() )
130
- else
131
- output = ''
132
- Iconv.open('UTF-8', source_encoding) do | converter |
133
- output << converter.iconv( io.read() )
134
- output << converter.iconv(nil)
135
- end
136
- @textctrl.set_value( output )
137
- end
138
- end
139
-
140
- # Ask the user for a file path, and then export the content of the
141
- # textctrl to it in the encoding +encoding+
142
- def on_export_file(encoding)
143
- fd = Wx::FileDialog.new( nil, 'Export file', "", "",
144
- "*.*", Wx::SAVE|Wx::OVERWRITE_PROMPT )
145
- return unless fd.show_modal() == Wx::ID_OK
146
- File.open( fd.get_path, 'w' ) do | file |
147
- export_file( file, encoding )
148
- end
149
- rescue Iconv::IllegalSequence
150
- message = "The text content containts characters that " <<
151
- "cannot be encoded using %s" % encoding
152
- Wx::MessageDialog.new(self, message, 'Invalid encoding',
153
- Wx::OK|Wx::ICON_EXCLAMATION).show_modal()
154
- end
155
-
156
- # Write the content of the textctrl to the file or io +io+, encoding
157
- # the text in encoding +target_encoding+
158
- def export_file(io, target_encoding = 'utf-8')
159
- case target_encoding
160
- when /UTF-?8/
161
- io.write( @textctrl.get_value )
162
- else
163
- Iconv.open(target_encoding, 'UTF-8') do | converter |
164
- io << converter.iconv( @textctrl.get_value )
165
- io << converter.iconv(nil)
166
- end
167
- end
168
- end
169
-
170
- def construct_menus()
171
- menu_bar = Wx::MenuBar.new()
172
-
173
- menu_file = Wx::Menu.new()
174
- menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
175
- evt_menu(Wx::ID_EXIT) { on_quit() }
176
- menu_bar.append(menu_file, "&File")
177
- if self.class.const_defined?(:ICONV_LOADED)
178
- construct_import_export_menus(menu_bar)
179
- end
180
-
181
- menu_help = Wx::Menu.new()
182
- menu_help.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
183
- evt_menu(Wx::ID_ABOUT) { on_about() }
184
- menu_bar.append(menu_help, "&Help")
185
-
186
- set_menu_bar(menu_bar)
187
- end
188
-
189
- def construct_import_export_menus(menu_bar)
190
- id_counter = 0
191
- menu_import = Wx::Menu.new()
192
-
193
- ENCODINGS.each do | desc, enc |
194
- id_counter += 1
195
- menu_import.append(id_counter, "Import (#{desc})",
196
- "Import a file in #{desc} encoding")
197
-
198
- evt_menu(id_counter) { on_import_file(enc) }
199
- end
200
- menu_bar.append(menu_import, '&Import')
201
-
202
- menu_export = Wx::Menu.new()
203
- ENCODINGS.each do | desc, enc |
204
- id_counter += 1
205
- menu_export.append(id_counter, "Export (#{desc})",
206
- "Export a file in #{desc} encoding")
207
-
208
- evt_menu(id_counter) { on_export_file(enc) }
209
- end
210
- menu_bar.append(menu_export, '&Export')
211
- end
212
-
213
- def on_click(e)
214
- @log.set_value( @textctrl.report() )
215
- end
216
-
217
- def on_quit()
218
- close(TRUE)
219
- end
220
-
221
- def on_about()
222
- msg = sprintf("This is the About dialog of the Unicode sample.\n" \
223
- "Welcome to %s", Wx::VERSION_STRING)
224
- Wx::message_box(msg, "About Minimal", Wx::OK|Wx::ICON_INFORMATION, self)
225
- end
226
- end
227
-
228
- class IConvApp < Wx::App
229
- def on_init()
230
- frame = IConvFrame.new("Unicode demonstration - ",
231
- Wx::Point.new(50, 50),
232
- Wx::Size.new(450, 450) )
233
-
234
- frame.show(true)
235
- end
236
- end
237
-
238
- IConvApp.new().main_loop()
1
+ # wxRuby2 Sample Code. Copyright (c) 2004-2006 Kevin B. Smith
2
+ # Freely reusable code: see SAMPLES-LICENSE.TXT for details
3
+
4
+ # Tell ruby this script is written in UTF-8 encoded text.
5
+ $KCODE = 'u'
6
+
7
+ # Library to get character lengths (as opposed to byte lengths) from
8
+ # Ruby strings.
9
+ require 'jcode'
10
+
11
+ require 'wx'
12
+
13
+ $utf8_file = File.join( File.dirname(__FILE__), 'utf8.txt')
14
+
15
+ class UnicodeDemoTextCtrl < Wx::TextCtrl
16
+ NEWLINE_CORRECTION_FACTOR = 0
17
+
18
+ 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.
19
+
20
+ " << File.read( $utf8_file )
21
+
22
+ def initialize(parent, text = DEFAULT_TEXT)
23
+ super(parent, -1, text,
24
+ Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, Wx::TE_MULTILINE)
25
+ end
26
+
27
+ # run through a few useful methods of textctrl and report the results
28
+ # as a string
29
+ def report()
30
+ report = ''
31
+ sel = get_string_selection()
32
+ report << 'Selected string byte length: ' << sel.length.to_s << "\n"
33
+ report << 'Selected string character length: ' << sel.jlength.to_s << "\n"
34
+ report << 'Selected string:: ' << sel.inspect << "\n"
35
+ return report
36
+ end
37
+ end
38
+
39
+ # A read-only text ctrl useful for displaying output
40
+ class LogTextCtrl < Wx::TextCtrl
41
+ STYLE = Wx::TE_READONLY|Wx::TE_MULTILINE
42
+ def initialize(parent)
43
+ super(parent, -1, '', Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, STYLE)
44
+ end
45
+ end
46
+
47
+ class IConvFrame < Wx::Frame
48
+ # Ruby stdlib for converting strings between encodings
49
+ begin
50
+ require 'iconv'
51
+ ICONV_LOADED = 1
52
+ rescue LoadError
53
+ end
54
+
55
+ # The encodings we're going to make importable and exportable in this
56
+ # application - see construct_import_export_menus below
57
+ ENCODINGS = { 'US ASCII' => 'ASCII',
58
+ 'UTF-8' => 'UTF-8',
59
+ 'UTF-16' => 'UTF-16',
60
+ 'Windows Latin CP1252' => 'CP1252',
61
+ 'Latin ISO-8859-1' => 'ISO-8859-1',
62
+ 'Japanese SHIFT-JIS' => 'SHIFT-JIS' }
63
+
64
+ def initialize(title, pos, size)
65
+ super(nil, -1, title, pos, size)
66
+ panel = Wx::Panel.new(self)
67
+ sizer = Wx::BoxSizer.new(Wx::VERTICAL)
68
+
69
+ sys_lang = Wx::Locale.get_system_language_name
70
+ text = Wx::StaticText.new(panel, -1, "System language: #{sys_lang}")
71
+ sizer.add(text, 0, Wx::ALL, 5)
72
+
73
+ sys_enc = Wx::Locale.get_system_encoding_name
74
+ text = Wx::StaticText.new(panel, -1, "System default encoding: #{sys_enc}")
75
+ sizer.add(text, 0, Wx::ALL, 5)
76
+
77
+ # The text input and display
78
+ @textctrl = UnicodeDemoTextCtrl.new(panel)
79
+ sizer.add(@textctrl, 3, Wx::GROW|Wx::ALL, 2)
80
+
81
+ # The button to show what's selected
82
+ button = Wx::Button.new(panel, -1, 'Describe text selection')
83
+ sizer.add(button, 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2 )
84
+ evt_button(button.get_id) { | e | on_click(e) }
85
+
86
+ @log = LogTextCtrl.new(panel)
87
+ sizer.add(@log, 1, Wx::GROW|Wx::ALL, 2)
88
+ sizer.add( Wx::StaticText.new(panel, -1, 'Some controls with unicode'),
89
+ 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2 )
90
+ ctrl_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL)
91
+
92
+ test_button = Wx::Button.new(panel, -1, '万')
93
+ ctrl_sizer.add(test_button, 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2)
94
+ choice = Wx::Choice.new(panel, -1, Wx::DEFAULT_POSITION,
95
+ Wx::DEFAULT_SIZE, [])
96
+ File.readlines($utf8_file).each do | line |
97
+ next if line.chomp.empty?
98
+ choice.append(line.chomp)
99
+ end
100
+ choice.set_selection(0)
101
+ ctrl_sizer.add(choice, 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2)
102
+
103
+ sizer.add(ctrl_sizer, 0, Wx::ADJUST_MINSIZE|Wx::ALL, 2)
104
+ construct_menus()
105
+ panel.set_sizer_and_fit( sizer )
106
+ end
107
+
108
+ # Prompt the user to specify a file whose contents should be loaded
109
+ # into the text ctrl. The file should be encoded in +encoding+
110
+ def on_import_file(encoding)
111
+ fd = Wx::FileDialog.new( nil, 'Import file', "", "",
112
+ "*.*", Wx::OPEN|Wx::FILE_MUST_EXIST )
113
+ return unless fd.show_modal() == Wx::ID_OK
114
+ File.open( fd.get_path ) do | file |
115
+ import_file( file, encoding )
116
+ end
117
+ rescue Iconv::IllegalSequence
118
+ message = "The file %s does not seem to be in %s encoding " %
119
+ [ fd.get_filename, encoding ]
120
+ Wx::MessageDialog.new(self, message, 'Wrong encoding',
121
+ Wx::OK|Wx::ICON_EXCLAMATION).show_modal()
122
+ end
123
+
124
+ # Read +io+, which should be text file encoding in +source_encoding+,
125
+ # and display the contents in the textctrl.
126
+ def import_file(io, source_encoding = 'UTF-8')
127
+ case source_encoding
128
+ when /UTF-?8/
129
+ @textctrl.set_value( io.read() )
130
+ else
131
+ output = ''
132
+ Iconv.open('UTF-8', source_encoding) do | converter |
133
+ output << converter.iconv( io.read() )
134
+ output << converter.iconv(nil)
135
+ end
136
+ @textctrl.set_value( output )
137
+ end
138
+ end
139
+
140
+ # Ask the user for a file path, and then export the content of the
141
+ # textctrl to it in the encoding +encoding+
142
+ def on_export_file(encoding)
143
+ fd = Wx::FileDialog.new( nil, 'Export file', "", "",
144
+ "*.*", Wx::SAVE|Wx::OVERWRITE_PROMPT )
145
+ return unless fd.show_modal() == Wx::ID_OK
146
+ File.open( fd.get_path, 'w' ) do | file |
147
+ export_file( file, encoding )
148
+ end
149
+ rescue Iconv::IllegalSequence
150
+ message = "The text content containts characters that " <<
151
+ "cannot be encoded using %s" % encoding
152
+ Wx::MessageDialog.new(self, message, 'Invalid encoding',
153
+ Wx::OK|Wx::ICON_EXCLAMATION).show_modal()
154
+ end
155
+
156
+ # Write the content of the textctrl to the file or io +io+, encoding
157
+ # the text in encoding +target_encoding+
158
+ def export_file(io, target_encoding = 'utf-8')
159
+ case target_encoding
160
+ when /UTF-?8/
161
+ io.write( @textctrl.get_value )
162
+ else
163
+ Iconv.open(target_encoding, 'UTF-8') do | converter |
164
+ io << converter.iconv( @textctrl.get_value )
165
+ io << converter.iconv(nil)
166
+ end
167
+ end
168
+ end
169
+
170
+ def construct_menus()
171
+ menu_bar = Wx::MenuBar.new()
172
+
173
+ menu_file = Wx::Menu.new()
174
+ menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
175
+ evt_menu(Wx::ID_EXIT) { on_quit() }
176
+ menu_bar.append(menu_file, "&File")
177
+ if self.class.const_defined?(:ICONV_LOADED)
178
+ construct_import_export_menus(menu_bar)
179
+ end
180
+
181
+ menu_help = Wx::Menu.new()
182
+ menu_help.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
183
+ evt_menu(Wx::ID_ABOUT) { on_about() }
184
+ menu_bar.append(menu_help, "&Help")
185
+
186
+ set_menu_bar(menu_bar)
187
+ end
188
+
189
+ def construct_import_export_menus(menu_bar)
190
+ id_counter = 0
191
+ menu_import = Wx::Menu.new()
192
+
193
+ ENCODINGS.each do | desc, enc |
194
+ id_counter += 1
195
+ menu_import.append(id_counter, "Import (#{desc})",
196
+ "Import a file in #{desc} encoding")
197
+
198
+ evt_menu(id_counter) { on_import_file(enc) }
199
+ end
200
+ menu_bar.append(menu_import, '&Import')
201
+
202
+ menu_export = Wx::Menu.new()
203
+ ENCODINGS.each do | desc, enc |
204
+ id_counter += 1
205
+ menu_export.append(id_counter, "Export (#{desc})",
206
+ "Export a file in #{desc} encoding")
207
+
208
+ evt_menu(id_counter) { on_export_file(enc) }
209
+ end
210
+ menu_bar.append(menu_export, '&Export')
211
+ end
212
+
213
+ def on_click(e)
214
+ @log.set_value( @textctrl.report() )
215
+ end
216
+
217
+ def on_quit()
218
+ close(TRUE)
219
+ end
220
+
221
+ def on_about()
222
+ msg = sprintf("This is the About dialog of the Unicode sample.\n" \
223
+ "Welcome to %s", Wx::VERSION_STRING)
224
+ Wx::message_box(msg, "About Minimal", Wx::OK|Wx::ICON_INFORMATION, self)
225
+ end
226
+ end
227
+
228
+ class IConvApp < Wx::App
229
+ def on_init()
230
+ frame = IConvFrame.new("Unicode demonstration - ",
231
+ Wx::Point.new(50, 50),
232
+ Wx::Size.new(450, 450) )
233
+
234
+ frame.show(true)
235
+ end
236
+ end
237
+
238
+ IConvApp.new().main_loop()