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.
Files changed (220) hide show
  1. data/LICENSE +53 -0
  2. data/README +297 -0
  3. data/lib/wx.rb +2 -2
  4. data/lib/wx/accessors.rb +7 -1
  5. data/lib/wx/classes/app.rb +10 -4
  6. data/lib/wx/classes/bitmap.rb +29 -1
  7. data/lib/wx/classes/clipboard.rb +19 -3
  8. data/lib/wx/classes/colour.rb +6 -4
  9. data/lib/wx/classes/data_object.rb +14 -0
  10. data/lib/wx/classes/data_object_simple.rb +6 -0
  11. data/lib/wx/classes/dataformat.rb +23 -0
  12. data/lib/wx/classes/evthandler.rb +79 -4
  13. data/lib/wx/classes/genericdirctrl.rb +36 -0
  14. data/lib/wx/classes/grid.rb +8 -0
  15. data/lib/wx/classes/hboxsizer.rb +6 -0
  16. data/lib/wx/classes/icon.rb +12 -1
  17. data/lib/wx/classes/image.rb +13 -1
  18. data/lib/wx/classes/listctrl.rb +12 -0
  19. data/lib/wx/classes/point.rb +8 -0
  20. data/lib/wx/classes/rect.rb +10 -1
  21. data/lib/wx/classes/richtextctrl.rb +63 -0
  22. data/lib/wx/classes/size.rb +9 -0
  23. data/lib/wx/classes/sizer.rb +18 -3
  24. data/lib/wx/classes/standardpaths.rb +9 -0
  25. data/lib/wx/classes/texturlevent.rb +14 -2
  26. data/lib/wx/classes/toolbar.rb +4 -6
  27. data/lib/wx/classes/vboxsizer.rb +6 -0
  28. data/lib/wx/classes/window.rb +7 -0
  29. data/lib/wx/classes/xmlresource.rb +17 -0
  30. data/lib/wx/helpers.rb +16 -1
  31. data/lib/wx/keyword_ctors.rb +3 -2
  32. data/lib/wx/keyword_defs.rb +56 -5
  33. data/lib/wx/version.rb +1 -1
  34. data/lib/wxruby2.bundle +0 -0
  35. data/samples/SAMPLES-LICENSE.TXT +18 -0
  36. data/samples/aui/aui.rb +1356 -0
  37. data/samples/bigdemo/About.rbw +39 -0
  38. data/samples/bigdemo/ColorPanel.rbw +23 -0
  39. data/samples/bigdemo/GridSimple.rbw +78 -0
  40. data/samples/bigdemo/MDIDemo.rbw +57 -0
  41. data/samples/bigdemo/PopupMenu.rbw +149 -0
  42. data/samples/bigdemo/ShapedWindow.rbw +131 -0
  43. data/samples/bigdemo/Sizers.rbw +543 -0
  44. data/samples/bigdemo/bigdemo.rb +823 -0
  45. data/samples/bigdemo/demoTemplate.rbw +33 -0
  46. data/samples/bigdemo/helpfile.htb +0 -0
  47. data/samples/bigdemo/icons/Test 015.jpg +0 -0
  48. data/samples/bigdemo/icons/Test 015.png +0 -0
  49. data/samples/bigdemo/icons/choice.bmp +0 -0
  50. data/samples/bigdemo/icons/choice.xpm +27 -0
  51. data/samples/bigdemo/icons/combo.bmp +0 -0
  52. data/samples/bigdemo/icons/combo.xpm +27 -0
  53. data/samples/bigdemo/icons/copy.xpm +25 -0
  54. data/samples/bigdemo/icons/cut.xpm +24 -0
  55. data/samples/bigdemo/icons/gauge.bmp +0 -0
  56. data/samples/bigdemo/icons/gauge.xpm +27 -0
  57. data/samples/bigdemo/icons/help.xpm +25 -0
  58. data/samples/bigdemo/icons/list.bmp +0 -0
  59. data/samples/bigdemo/icons/list.xpm +27 -0
  60. data/samples/bigdemo/icons/mondrian.ico +0 -0
  61. data/samples/bigdemo/icons/mondrian.xpm +44 -0
  62. data/samples/bigdemo/icons/new.xpm +24 -0
  63. data/samples/bigdemo/icons/ogl.ico +0 -0
  64. data/samples/bigdemo/icons/ogl.xpm +45 -0
  65. data/samples/bigdemo/icons/open.xpm +26 -0
  66. data/samples/bigdemo/icons/paste.bmp +0 -0
  67. data/samples/bigdemo/icons/paste.xpm +38 -0
  68. data/samples/bigdemo/icons/pointy.png +0 -0
  69. data/samples/bigdemo/icons/preview.xpm +26 -0
  70. data/samples/bigdemo/icons/print.xpm +26 -0
  71. data/samples/bigdemo/icons/radio.bmp +0 -0
  72. data/samples/bigdemo/icons/radio.xpm +27 -0
  73. data/samples/bigdemo/icons/robert.xpm +415 -0
  74. data/samples/bigdemo/icons/ruby.png +0 -0
  75. data/samples/bigdemo/icons/sashtest.ico +0 -0
  76. data/samples/bigdemo/icons/save.xpm +25 -0
  77. data/samples/bigdemo/icons/smiles.bmp +0 -0
  78. data/samples/bigdemo/icons/smiles.xpm +39 -0
  79. data/samples/bigdemo/icons/smiley.ico +0 -0
  80. data/samples/bigdemo/icons/smiley.xpm +42 -0
  81. data/samples/bigdemo/icons/stattext.xpm +24 -0
  82. data/samples/bigdemo/icons/test2.bmp +0 -0
  83. data/samples/bigdemo/icons/test2.png +0 -0
  84. data/samples/bigdemo/icons/test2.xpm +79 -0
  85. data/samples/bigdemo/icons/text.bmp +0 -0
  86. data/samples/bigdemo/icons/text.xpm +27 -0
  87. data/samples/bigdemo/icons/tog1.bmp +0 -0
  88. data/samples/bigdemo/icons/tog1.xpm +38 -0
  89. data/samples/bigdemo/icons/tog2.bmp +0 -0
  90. data/samples/bigdemo/icons/tog2.xpm +38 -0
  91. data/samples/bigdemo/icons/wxwin.ico +0 -0
  92. data/samples/bigdemo/icons/wxwin16x16.png +0 -0
  93. data/samples/bigdemo/icons/wxwin16x16.xpm +25 -0
  94. data/samples/bigdemo/icons/wxwin32x32.png +0 -0
  95. data/samples/bigdemo/icons/wxwin48x48.png +0 -0
  96. data/samples/bigdemo/run.rb +90 -0
  97. data/samples/bigdemo/tips.txt +7 -0
  98. data/samples/bigdemo/utils.rb +12 -0
  99. data/samples/bigdemo/wxArtProvider.rbw +281 -0
  100. data/samples/bigdemo/wxBitmapButton.rbw +65 -0
  101. data/samples/bigdemo/wxButton.rbw +64 -0
  102. data/samples/bigdemo/wxCalendarCtrl.rbw +60 -0
  103. data/samples/bigdemo/wxCheckBox.rbw +50 -0
  104. data/samples/bigdemo/wxCheckListBox.rbw +65 -0
  105. data/samples/bigdemo/wxChoice.rbw +47 -0
  106. data/samples/bigdemo/wxChoicebook.rbw +78 -0
  107. data/samples/bigdemo/wxColourDialog.rbw +31 -0
  108. data/samples/bigdemo/wxComboBox.rbw +77 -0
  109. data/samples/bigdemo/wxCursor.rbw +136 -0
  110. data/samples/bigdemo/wxDialog.rbw +74 -0
  111. data/samples/bigdemo/wxDirDialog.rbw +29 -0
  112. data/samples/bigdemo/wxDragImage.rbw +70 -0
  113. data/samples/bigdemo/wxFileDialog.rbw +37 -0
  114. data/samples/bigdemo/wxFileDialog_Save.rbw +35 -0
  115. data/samples/bigdemo/wxFindReplaceDialog.rbw +82 -0
  116. data/samples/bigdemo/wxFontDialog.rbw +173 -0
  117. data/samples/bigdemo/wxFrame.rbw +53 -0
  118. data/samples/bigdemo/wxGauge.rbw +71 -0
  119. data/samples/bigdemo/wxGenericDirCtrl.rbw +74 -0
  120. data/samples/bigdemo/wxGrid.rbw +66 -0
  121. data/samples/bigdemo/wxHtmlHelpController.rbw +52 -0
  122. data/samples/bigdemo/wxListBox.rbw +140 -0
  123. data/samples/bigdemo/wxListCtrl_virtual.rbw +112 -0
  124. data/samples/bigdemo/wxMDIWindows.rbw +50 -0
  125. data/samples/bigdemo/wxMenu.rbw +236 -0
  126. data/samples/bigdemo/wxMessageDialog.rbw +27 -0
  127. data/samples/bigdemo/wxMiniFrame.rbw +70 -0
  128. data/samples/bigdemo/wxMultipleChoiceDialog.rbw +32 -0
  129. data/samples/bigdemo/wxNotebook.rbw +136 -0
  130. data/samples/bigdemo/wxProgressDialog.rbw +43 -0
  131. data/samples/bigdemo/wxRadioBox.rbw +72 -0
  132. data/samples/bigdemo/wxRadioButton.rbw +125 -0
  133. data/samples/bigdemo/wxSashWindow.rbw +141 -0
  134. data/samples/bigdemo/wxScrolledMessageDialog.rbw +57 -0
  135. data/samples/bigdemo/wxScrolledWindow.rbw +199 -0
  136. data/samples/bigdemo/wxSingleChoiceDialog.rbw +33 -0
  137. data/samples/bigdemo/wxSlider.rbw +42 -0
  138. data/samples/bigdemo/wxSpinButton.rbw +50 -0
  139. data/samples/bigdemo/wxSpinCtrl.rbw +51 -0
  140. data/samples/bigdemo/wxSplitterWindow.rbw +63 -0
  141. data/samples/bigdemo/wxStaticBitmap.rbw +51 -0
  142. data/samples/bigdemo/wxStaticText.rbw +55 -0
  143. data/samples/bigdemo/wxStatusBar.rbw +126 -0
  144. data/samples/bigdemo/wxTextCtrl.rbw +149 -0
  145. data/samples/bigdemo/wxTextEntryDialog.rbw +31 -0
  146. data/samples/bigdemo/wxToggleButton.rbw +49 -0
  147. data/samples/bigdemo/wxToolBar.rbw +131 -0
  148. data/samples/bigdemo/wxTreeCtrl.rbw +191 -0
  149. data/samples/calendar/calendar.rb +256 -0
  150. data/samples/caret/caret.rb +282 -0
  151. data/samples/caret/mondrian.xpm +44 -0
  152. data/samples/controls/controls.rb +1136 -0
  153. data/samples/controls/get_item_sample.rb +87 -0
  154. data/samples/controls/icons/choice.xpm +27 -0
  155. data/samples/controls/icons/combo.xpm +27 -0
  156. data/samples/controls/icons/gauge.xpm +27 -0
  157. data/samples/controls/icons/list.xpm +27 -0
  158. data/samples/controls/icons/radio.xpm +27 -0
  159. data/samples/controls/icons/stattext.xpm +24 -0
  160. data/samples/controls/icons/text.xpm +27 -0
  161. data/samples/controls/mondrian.ico +0 -0
  162. data/samples/controls/mondrian.xpm +44 -0
  163. data/samples/controls/test2.bmp +0 -0
  164. data/samples/dialogs/dialogs.rb +797 -0
  165. data/samples/dialogs/tips.txt +18 -0
  166. data/samples/dragdrop/dragdrop.rb +177 -0
  167. data/samples/drawing/graphics_drawing.rb +235 -0
  168. data/samples/drawing/images.rb +37 -0
  169. data/samples/drawing/paperclip.png +0 -0
  170. data/samples/etc/activation.rb +102 -0
  171. data/samples/etc/choice.rb +67 -0
  172. data/samples/etc/miniframe.rb +79 -0
  173. data/samples/etc/sash.rb +130 -0
  174. data/samples/etc/scrollwin.rb +110 -0
  175. data/samples/etc/system_settings.rb +252 -0
  176. data/samples/etc/threaded.rb +72 -0
  177. data/samples/etc/toolbar_sizer_additem.rb +55 -0
  178. data/samples/etc/wizard.rb +74 -0
  179. data/samples/event/event.rb +182 -0
  180. data/samples/event/update_ui_event.rb +70 -0
  181. data/samples/grid/grid.rb +198 -0
  182. data/samples/grid/gridtablebase.rb +148 -0
  183. data/samples/html/html.rb +262 -0
  184. data/samples/listbook/listbook.rb +174 -0
  185. data/samples/listbook/listbook.xrc +370 -0
  186. data/samples/mdi/mdi.rb +85 -0
  187. data/samples/media/mediactrl.rb +167 -0
  188. data/samples/minimal/minimal.rb +77 -0
  189. data/samples/minimal/mondrian.ico +0 -0
  190. data/samples/minimal/mondrian.png +0 -0
  191. data/samples/minimal/nothing.rb +16 -0
  192. data/samples/opengl/cube.rb +117 -0
  193. data/samples/printing/mondrian.ico +0 -0
  194. data/samples/printing/mondrian.xpm +44 -0
  195. data/samples/printing/printing.rb +487 -0
  196. data/samples/sockets/SocketPackets.rb +27 -0
  197. data/samples/sockets/res/message-new.png +0 -0
  198. data/samples/sockets/res/user.png +0 -0
  199. data/samples/sockets/wxClient.rb +395 -0
  200. data/samples/sockets/wxServer.rb +422 -0
  201. data/samples/sockets/wxSocketGUI.rb +97 -0
  202. data/samples/text/format-text-bold.png +0 -0
  203. data/samples/text/format-text-italic.png +0 -0
  204. data/samples/text/format-text-underline.png +0 -0
  205. data/samples/text/mondrian.ico +0 -0
  206. data/samples/text/mondrian.xpm +44 -0
  207. data/samples/text/rich_textctrl.rb +98 -0
  208. data/samples/text/scintilla.rb +169 -0
  209. data/samples/text/textctrl.rb +111 -0
  210. data/samples/text/unicode.rb +242 -0
  211. data/samples/text/utf8.txt +15 -0
  212. data/samples/treectrl/icon1.xpm +79 -0
  213. data/samples/treectrl/icon2.xpm +53 -0
  214. data/samples/treectrl/icon3.xpm +79 -0
  215. data/samples/treectrl/icon4.xpm +43 -0
  216. data/samples/treectrl/icon5.xpm +79 -0
  217. data/samples/treectrl/treectrl.rb +1166 -0
  218. data/samples/xrc/samples.xrc +46 -0
  219. data/samples/xrc/xrc_sample.rb +76 -0
  220. metadata +17 -3
@@ -0,0 +1,148 @@
1
+ #!/usr/bin/env ruby
2
+ # wxRuby2 Sample Code. Copyright (c) 2004-2009 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
+ # GridTableBase is an alternative way to provide data to a Wx::Grid. A
11
+ # subclass of Wx::GridTableBase is created which is reqiured to provide
12
+ # methods to report the total size of the Grid in rows and columns, and
13
+ # the contents and style of individual cells.
14
+ #
15
+ # Then, when creating the Grid, instead of calling create_grid and
16
+ # set_value to populate it, the GridTableBase-derived class is
17
+ # associated with the Grid, and provides these functions (see below)
18
+ #
19
+ # This approach is typically useful for dealing with very large sets of
20
+ # data, as each cell's value is only requested as it becomes visible.v
21
+ class MyGridTable < Wx::GridTableBase
22
+ attr_reader :cols, :rows
23
+ def initialize(rows, cols)
24
+ super()
25
+ @rows = rows
26
+ @cols = cols
27
+ @number_col = 1
28
+ end
29
+
30
+ # Letter labels for columns
31
+ COLS = ('AA' .. 'ZZ').to_a
32
+
33
+ # Firstly, a GridTableBase must indicate the size of the grid in
34
+ # terms of rows ...
35
+ def get_number_rows
36
+ @rows
37
+ end
38
+
39
+ # ... and columns
40
+ def get_number_cols
41
+ @cols
42
+ end
43
+
44
+ # Most importantly, it should be able to return any given cell's
45
+ # contents, given its row and column reference
46
+ def get_value(row, col)
47
+ if col == @number_col
48
+ (row * 5).to_s
49
+ else
50
+ "#{row}:#{COLS[col]}"
51
+ end
52
+ end
53
+
54
+ # This is not needed if the cell contents are simply strings. However,
55
+ # if you wish to use custom GridCellRenderers and/or GridCellEditors,
56
+ # this should return a type name which has the correct renderer /
57
+ # editor defined for it in the Grid, using register_
58
+ def get_type_name(row, col)
59
+ if col == @number_col
60
+ "NUMBER"
61
+ else
62
+ "STRING"
63
+ end
64
+ end
65
+
66
+ # It should also return the attributes that should apply to any given
67
+ # cell; this example give alternate rows red text letters
68
+ def get_attr(row, col, attr_kind)
69
+ attr = Wx::GridCellAttr.new
70
+ if (row % 2).zero?
71
+ attr.text_colour = Wx::RED
72
+ end
73
+ attr
74
+ end
75
+
76
+ # It should indicate whether any given cell is empty
77
+ def is_empty_cell(row, col)
78
+ false
79
+ end
80
+
81
+ # It may also provide labels for the columns and rows
82
+ def get_col_label_value(col)
83
+ COLS[col]
84
+ end
85
+
86
+ # If the Grid is to support write as well as read operations,
87
+ # set_value should also be implemented. In this case, the change is
88
+ # merely echoed back and doesn't alter the underlying value; a real
89
+ # implementation could, for example, write back to a database
90
+ def set_value(x, y, val)
91
+ puts "Changing the value of cell (#{x}, #{y}) to '#{val}'"
92
+ end
93
+ end
94
+
95
+ class GridFrame < Wx::Frame
96
+ def initialize()
97
+ super(nil, :title => 'GridTableBase demo', :size => [600, 300])
98
+ main_sizer = Wx::VBoxSizer.new
99
+ # Create a grid and associate an instance of the GridTable as the
100
+ # data provider for the grid
101
+ @grid = Wx::Grid.new(self)
102
+
103
+ # Define the renderers and editors used by the different data types
104
+ # displayed in this Grid. The type of a given cell is determined by
105
+ # calling the source's get_type_name method; see above.
106
+ @grid.register_data_type( "STRING",
107
+ Wx::GridCellStringRenderer.new,
108
+ Wx::GridCellTextEditor.new )
109
+ @grid.register_data_type( "NUMBER",
110
+ Wx::GridCellNumberRenderer.new,
111
+ Wx::GridCellNumberEditor.new(0, 500) )
112
+
113
+ # Set the data source
114
+ @grid.table = MyGridTable.new(10, 10)
115
+
116
+
117
+ main_sizer.add(@grid, 1, Wx::EXPAND|Wx::ALL, 5)
118
+
119
+ # Add some buttons that can change the contents
120
+ butt_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL)
121
+
122
+ butt_1 = Wx::Button.new(self, :label => "Add row")
123
+ # When resizing the grid to have a new number of rows or columns,
124
+ # need to allocate a new grid table source
125
+ evt_button(butt_1) do
126
+ @grid.table = MyGridTable.new( @grid.table.rows + 1,
127
+ @grid.table.cols)
128
+ @grid.refresh
129
+ end
130
+ butt_sizer.add(butt_1)
131
+
132
+ butt_2 = Wx::Button.new(self, :label => "Add column")
133
+ evt_button(butt_2) do
134
+ @grid.table = MyGridTable.new( @grid.table.rows,
135
+ @grid.table.cols + 1)
136
+ @grid.refresh
137
+ end
138
+ butt_sizer.add(butt_2)
139
+
140
+ main_sizer.add(butt_sizer, 0, Wx::EXPAND|Wx::ALL, 5)
141
+ self.sizer = main_sizer
142
+ end
143
+ end
144
+
145
+ Wx::App.run do
146
+ GridFrame.new.show
147
+ end
148
+
@@ -0,0 +1,262 @@
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
+ require 'net/http'
11
+ require 'uri'
12
+
13
+ class MyHtmlWindow < Wx::HtmlWindow
14
+ attr_reader :html_src
15
+ def initialize(*args)
16
+ super
17
+ evt_html_link_clicked self, :on_link_clicked
18
+ evt_html_cell_hover self, :on_hover
19
+ end
20
+
21
+ def load_page_from_uri(uri)
22
+ case uri
23
+ when URI::HTTP
24
+ Wx::BusyCursor.busy do
25
+ begin
26
+ res = Net::HTTP.start(uri.host, uri.port) do | http |
27
+ http.get(uri.path)
28
+ end
29
+ @loaded_uri = uri
30
+ set_page(res.body)
31
+ rescue => err
32
+ msg = "Could not load page:\n#{err}"
33
+ Wx::MessageDialog.new(nil, msg, 'Error loading page',
34
+ Wx::OK|Wx::ICON_ERROR).show_modal
35
+ return ''
36
+ end
37
+ end
38
+ return @loaded_uri
39
+ when URI::Generic
40
+ if @loaded_uri and @loaded_uri.kind_of?(URI::HTTP)
41
+ return load_page_from_uri( @loaded_uri.merge(uri) )
42
+ elsif @loaded_uri # current viewing a file
43
+ if uri.to_s =~ /^\//
44
+ return load_file(uri.path)
45
+ elsif not uri.path.empty?
46
+ local_file = File.join( File.dirname(@loaded_uri.path), uri.path)
47
+ return load_file( local_file )
48
+ end
49
+ end
50
+ end
51
+
52
+ dlg = Wx::MessageDialog.new(nil, "Can't load link",
53
+ "Unable to load the link #{uri}",
54
+ Wx::ICON_ERROR)
55
+ dlg.show_modal
56
+ end
57
+
58
+ def load_file(file)
59
+ @loaded_uri = URI.parse("file:////" + file)
60
+ super file
61
+ @loaded_uri
62
+ end
63
+
64
+ def set_page(html)
65
+ super html
66
+ @html_src = html
67
+ related_frame.addr_bar.value = @loaded_uri.to_s
68
+ end
69
+
70
+ def on_link_clicked(event)
71
+ href = event.link_info.href
72
+ return if href =~ /^#/
73
+ link_uri = URI.parse(href)
74
+ @loaded_uri = load_page_from_uri(link_uri)
75
+ end
76
+
77
+ def on_hover(event)
78
+ if link = event.cell.link
79
+ related_frame.set_status_text(link.href)
80
+ else
81
+ related_frame.status_text = ''
82
+ end
83
+ end
84
+ end
85
+
86
+ # The frame or self-contained window for this application
87
+ class HtmlFrame < Wx::Frame
88
+ attr_reader :html_win, :addr_bar
89
+
90
+ def initialize(title, pos, size, style = Wx::DEFAULT_FRAME_STYLE)
91
+ # A main application frame has no parent (nil)
92
+ # -1 means this frame will be supplied a default id
93
+ super(nil, -1, title, pos, size, style)
94
+ setup_menus
95
+ setup_panel
96
+ create_status_bar
97
+ self.status_text = "Welcome to wxRuby!"
98
+ end
99
+
100
+ def setup_panel
101
+ panel = Wx::Panel.new(self, -1)
102
+
103
+ sizer = Wx::BoxSizer.new(Wx::VERTICAL)
104
+ top_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL)
105
+
106
+ @go_butt = Wx::StaticText.new(panel, -1, 'Location:')
107
+ top_sizer.add(@go_butt, 0, Wx::ALL, 4)
108
+ @addr_bar = Wx::TextCtrl.new(panel, -1, 'HOME', Wx::DEFAULT_POSITION,
109
+ Wx::DEFAULT_SIZE, Wx::TE_READONLY)
110
+ top_sizer.add(@addr_bar, 1, Wx::ALL, 4)
111
+ sizer.add(top_sizer, 0, Wx::EXPAND|Wx::TOP|Wx::BOTTOM, 4)
112
+
113
+ @html_win = MyHtmlWindow.new(panel, -1)
114
+ @html_win.set_related_frame(self, 'HTML Window: %s')
115
+
116
+ @html_win.set_page(DATA.read)
117
+ sizer.add(@html_win, 1, Wx::ALL|Wx::GROW, 4)
118
+ panel.set_sizer(sizer)
119
+ end
120
+
121
+ def setup_menus
122
+ menu_file = Wx::Menu.new()
123
+ menu_help = Wx::Menu.new()
124
+ # Using Wx::ID_ABOUT default id means the menu item will be placed
125
+ # in the correct platform-specific place
126
+ menu_help.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
127
+ menu_file.append(Wx::ID_OPEN, "&Open File...\tCtrl-O", "Open File")
128
+ menu_file.append(Wx::ID_HIGHEST + 1, "&Open URL...\tCtrl-U", "Open URL")
129
+ menu_file.append(Wx::ID_PRINT, "&Print...\tCtrl-P", "Print")
130
+
131
+ menu_file.append(Wx::ID_PREVIEW, "&Preview...\tCtrl-Shift-P",
132
+ "Print Preview")
133
+ menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
134
+
135
+ menu_bar = Wx::MenuBar.new()
136
+ menu_bar.append(menu_file, "&File")
137
+ menu_bar.append(menu_help, "&Help")
138
+ # Assign the menus to this frame
139
+ self.menu_bar = menu_bar
140
+ # handle menu events
141
+ evt_menu Wx::ID_OPEN, :on_open_file
142
+ evt_menu Wx::ID_HIGHEST + 1, :on_open_url
143
+ evt_menu Wx::ID_PRINT, :on_print
144
+ evt_menu Wx::ID_PREVIEW, :on_preview
145
+ evt_menu Wx::ID_EXIT, :on_quit
146
+ evt_menu Wx::ID_ABOUT, :on_about
147
+ end
148
+
149
+ # end the application
150
+ def on_quit
151
+ close
152
+ end
153
+
154
+ def on_open_file
155
+ f_dlg = Wx::FileDialog.new(self, "Open an HTML file", "", "",
156
+ "HTML files (*.html;*.htm)|*.html;*.htm)",
157
+ Wx::OPEN)
158
+ if not f_dlg.show_modal == Wx::ID_OK
159
+ return
160
+ end
161
+ html_file = f_dlg.get_path
162
+ if html_file.index("\\")
163
+ html_file = html_file.split("\\").join("/")
164
+ end
165
+ @html_win.load_file(html_file)
166
+ end
167
+
168
+ def on_open_url
169
+ url = Wx::get_text_from_user('Enter URL to open', 'Enter URL')
170
+ if not url.empty?
171
+ uri = URI.parse(url)
172
+ uri.path = '/' if uri.path.empty?
173
+ @html_win.load_page_from_uri(uri)
174
+ end
175
+ end
176
+
177
+ # show an 'About' dialog
178
+ def on_about
179
+ msg = sprintf("This is the About dialog of the HTML sample.\n" \
180
+ "Welcome to wxRuby, version %s", Wx::WXRUBY_VERSION)
181
+
182
+ # create a simple message dialog with OK button
183
+ about_dlg = Wx::MessageDialog.new( self, msg, 'About WxRuby HTML',
184
+ Wx::OK|Wx::ICON_INFORMATION )
185
+ about_dlg.show_modal()
186
+ about_dlg.destroy()
187
+ end
188
+
189
+ def on_preview
190
+ print = Wx::HtmlEasyPrinting.new('Print HTML', self)
191
+ print.preview_text(@html_win.html_src)
192
+ end
193
+
194
+ def on_print
195
+ print = Wx::HtmlEasyPrinting.new('Print HTML', self)
196
+ print.print_text(@html_win.html_src)
197
+ end
198
+
199
+ # utility function to find an icon relative to this ruby script
200
+ def local_icon_file(icon_name)
201
+ File.join( File.dirname(__FILE__), icon_name)
202
+ end
203
+ end
204
+
205
+ # Wx::App is the container class for any wxruby app - only a single
206
+ # instance is required
207
+ class HtmlApp < Wx::App
208
+ def on_init
209
+ frame = HtmlFrame.new("Minimal wxRuby App",
210
+ Wx::Point.new(50, 50),
211
+ Wx::Size.new(450, 340))
212
+ set_app_name('HtmlDemo')
213
+ # required
214
+ frame.show()
215
+ end
216
+ end
217
+
218
+ # Create an instance ...
219
+ app = HtmlApp.new
220
+ # ... and run the application
221
+ app.main_loop()
222
+
223
+ __END__
224
+ <html>
225
+ <head>
226
+ <title>WxRuby HTML Demo</title>
227
+ </head>
228
+
229
+ <body bgcolor="#ffffff">
230
+ <h1>The HtmlWindow widget</h1>
231
+ <p>This is a very simple demonstration of
232
+ <strong>Wx::HtmlWindow</strong>, a control for displaying hypertext. The
233
+ control understands most HTML tags, including links, tables, images,
234
+ lists and the venerable FONT tag. It does not know about CSS or
235
+ Javascript; it is not really intended for building a general-purpose
236
+ web browser.</p>
237
+ <h2>This demo</h2>
238
+ <p>In this demo you can open local files for viewing (by choosing the
239
+ File / Open). If you have an internet connection http:// links will be
240
+ downloaded as well. Its features are otherwise limited - for example,
241
+ this example doesn't know about HTML anchor targets, because it has
242
+ over-ridden default link handling to show how to subclass and
243
+ specialise HtmlWindow in Ruby.</a>
244
+ <h2>Html Easy Printing</h2>
245
+ <p>A useful feature included with WxRuby is a simple interface for
246
+ printing HTML. You can see this in action by choosing 'Print' or
247
+ 'Preview' from the File menu.</p>
248
+ <h3>Further information</h3>
249
+ <p>Here's a table with some links</p>
250
+ <table border="1">
251
+ <tr>
252
+ <td>WxRuby online documentation</td>
253
+ <td><a href="http://wxruby.rubyforge.org/doc/">http://wxruby.rubyforge.org/doc/</a></td>
254
+ </tr>
255
+ <tr>
256
+ <td>WxRuby Wiki</td>
257
+ <td><a href="http://wxruby.rubyforge.org/wiki/wiki.pl">http://wxruby.rubyforge.org/wiki/wiki.pl</a></td>
258
+ </tr>
259
+ </table>
260
+
261
+ </body>
262
+ </html>
@@ -0,0 +1,174 @@
1
+ #!/usr/bin/env ruby
2
+ # wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
3
+ # Freely reusable code: see SAMPLES-LICENSE.TXT for details
4
+ begin
5
+ require 'rubygems'
6
+ rescue LoadError
7
+ end
8
+ require 'wx'
9
+
10
+ # Basic Frame Class. This creates the dialog window
11
+ #
12
+ class SimpleFrame < Wx::Frame
13
+
14
+ FILE_DIALOG, FILE_ABOUT, FILE_QUIT = [0,Wx::ID_ABOUT,Wx::ID_EXIT]
15
+
16
+ def initialize(parent)
17
+ # To load a layout defined in XRC into a Ruby subclass of Frame,
18
+ # first call the empty constructor. All the details of size,
19
+ # title, position and so on are loaded from the XRC by the call to
20
+ # load_frame_subclass. Using a non-empty constructor will cause
21
+ # errors on GTK.
22
+ super()
23
+ $xml.load_frame_subclass(self,nil,'ID_FRAME')
24
+
25
+ # Create a new menu
26
+ bar = Wx::MenuBar.new
27
+ menu = Wx::Menu.new
28
+ menu.append(FILE_ABOUT,"About...")
29
+ menu.append_separator
30
+ menu.append(FILE_QUIT,"Quit")
31
+ bar.append(menu,"File")
32
+
33
+ set_menu_bar(bar)
34
+
35
+ # Assign the menu events
36
+ evt_menu(FILE_ABOUT) do
37
+ Wx::message_box("wxRuby Listbook sample\nby Sean Long", "About Listbook", Wx::OK | Wx::ICON_INFORMATION, self)
38
+ end
39
+ evt_menu(FILE_QUIT) do
40
+ Wx::get_app.exit_main_loop()
41
+ end
42
+ evt_close() do
43
+ Wx::get_app.exit_main_loop()
44
+ end
45
+
46
+ # Variables not in tabs
47
+ @listbook = xrcid_to_window('ID_LISTBOOK')
48
+ @text_output = xrcid_to_window('ID_ORDER_TEXTCTRL')
49
+
50
+ # Variables for widgets in Pizza tab
51
+ @pizza_size = xrcid_to_window('ID_PIZZA_SIZE_CHOICE')
52
+ @pizza_crust = xrcid_to_window('ID_PIZZA_CRUST_CHOICE')
53
+ @pizza_sauce = xrcid_to_window('ID_PIZZA_SAUCE_CHOICE')
54
+ @pizza_cheese = xrcid_to_window('ID_PIZZA_CHEESE_CHOICE')
55
+ @pizza_toppings = []
56
+ 3.times do |i|
57
+ @pizza_toppings << xrcid_to_window("ID_PIZZA_TOPPING_#{i+1}_CHOICE")
58
+ end
59
+
60
+ # fill in toppings
61
+ toppings = ['pepperoni','sausage','italian sausage','olives',
62
+ 'mushrooms','artichoke','extra cheese','']
63
+ toppings.each do |top_name|
64
+ @pizza_toppings.each do |top_obj|
65
+ top_obj.append(top_name)
66
+ end
67
+ end
68
+
69
+ index = 0
70
+ @pizza_toppings.each do |obj|
71
+ obj.set_selection(index)
72
+ index += 1
73
+ end
74
+
75
+ # Events for pizza tab
76
+ evt_button( Wx::xrcid('ID_PIZZA_BUTTON') ) do |event|
77
+ #get selections and add to order
78
+ order_string = @text_output.get_value
79
+ if order_string != "" then order_string << "\n" end
80
+ order_string << "One #{@pizza_size.get_string_selection} pizza with:\n"
81
+ order_string << @pizza_crust.get_string_selection + " crust" + "\n"
82
+ order_string << @pizza_sauce.get_string_selection + " sauce" +"\n"
83
+ order_string << @pizza_cheese.get_string_selection + " and" + "\n"
84
+ @pizza_toppings.each { |obj| order_string << obj.get_string_selection + "\n" }
85
+
86
+ @text_output.set_value(order_string)
87
+ end
88
+
89
+
90
+ # Variables for widgets in Drink tab
91
+ @drink_size = xrcid_to_window('ID_DRINK_SIZE_CHOICE')
92
+ @drink_type = xrcid_to_window('ID_DRINK_TYPE_CHOICE')
93
+
94
+ # Events for drink tab
95
+ evt_button(Wx::xrcid('ID_DRINK_BUTTON')) do |event|
96
+ #get selections and add to order
97
+ order_string = @text_output.get_value
98
+ if order_string != "" then order_string << "\n" end
99
+
100
+ order_string << "One #{@drink_size.get_string_selection} #{@drink_type.get_string_selection }.\n"
101
+
102
+ @text_output.set_value(order_string)
103
+ end
104
+
105
+ # Variables for widgets in Ice Cream tab
106
+ @ice_cream_size = xrcid_to_window('ID_ICE_CREAM_SIZE_CHOICE')
107
+ @ice_cream_type = xrcid_to_window('ID_ICE_CREAM_TYPE_CHOICE')
108
+ @ice_cream_toppings = []
109
+ 4.times do |i|
110
+ @ice_cream_toppings <<
111
+ xrcid_to_window("ID_ICE_CREAM_TOPPING_#{i+1}_CHOICE")
112
+ end
113
+
114
+ toppings = ['','m&m\'s','chocolate chips','fudge','nuts','cherry','whip cream']
115
+ toppings.each do |top_name|
116
+ @ice_cream_toppings.each do |top_obj|
117
+ top_obj.append(top_name)
118
+ end
119
+ end
120
+ @ice_cream_toppings.each { |obj| obj.set_selection(0) }
121
+
122
+ # Events for ice cream tab
123
+ evt_button(Wx::xrcid('ID_ICE_CREAM_BUTTON')) do |event|
124
+ #get selections and add to order
125
+ order_string = @text_output.get_value
126
+ if order_string != "" then order_string << "\n" end
127
+
128
+ order_string << "One #{@ice_cream_size.get_string_selection} #{@ice_cream_type.get_string_selection} ice cream:\n"
129
+ @ice_cream_toppings.each { |obj| order_string << obj.get_string_selection + "\n" }
130
+
131
+ @text_output.set_value(order_string)
132
+ end
133
+
134
+ evt_listbook_page_changed(Wx::xrcid('ID_LISTBOOK')) do |event|
135
+ tab_number = event.get_selection
136
+ order_string = @text_output.get_value
137
+ order_string << "moved to tab = #{@listbook.get_page_text(tab_number)} \n"
138
+ @text_output.set_value(order_string)
139
+ end
140
+ end
141
+
142
+ # Converts a XRCID id - as used in wxWidget's XML format - into the
143
+ # correct ruby window
144
+ def xrcid_to_window(xrc_id)
145
+ Wx::Window.find_window_by_id(Wx::xrcid(xrc_id), self)
146
+ end
147
+
148
+ end
149
+
150
+ #
151
+ # Application class.
152
+ #
153
+ class XrcApp < Wx::App
154
+
155
+ def on_init
156
+ # Create a resource handler
157
+ $xml = Wx::XmlResource.get();
158
+ $xml.init_all_handlers();
159
+
160
+ # Load a resource file from the script's directory
161
+ xrc_file = File.join( File.dirname( __FILE__ ), 'listbook.xrc' )
162
+
163
+ $xml.load(xrc_file)
164
+
165
+
166
+ # Show the main frame.
167
+ $main = SimpleFrame.new(self)
168
+ $main.show(true)
169
+
170
+ end
171
+ end
172
+
173
+
174
+ XrcApp.new().main_loop()