wxruby 1.9.1-i386-mswin32 → 1.9.2-i386-mswin32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,35 +13,45 @@ rescue LoadError => no_wx_err
13
13
  end
14
14
  end
15
15
 
16
- # The frame or self-contained window for this application
16
+ # This sample shows a fairly minimal Wx::App using a Frame, with a
17
+ # MenuBar and StatusBar but no controls. For the absolute minimum app,
18
+ # see nothing.rb
19
+
20
+ # A Wx::Frame is a self-contained, top-level Window that can contain
21
+ # controls, menubars, and statusbars
17
22
  class MinimalFrame < Wx::Frame
18
23
  def initialize(title)
19
-
20
- # A main application frame has no parent (nil)
24
+ # The main application frame has no parent (nil)
21
25
  super(nil, :title => title, :size => [ 400, 300 ])
22
26
 
23
- # PNG is a good choice for cross-platofrm icons
24
- icon_file = File.join( File.dirname(__FILE__), 'mondrian.png')
25
- self.icon = Wx::Icon.new(icon_file)
27
+ icon_file = File.join( File.dirname(__FILE__), "mondrian.png")
28
+ # PNG can be used on all platforms, but icon type must be specified
29
+ # to work on Windows; OS X doesn't have "Frame" icons.
30
+ self.icon = Wx::Icon.new(icon_file, Wx::BITMAP_TYPE_PNG)
26
31
 
27
- menu_file = Wx::Menu.new()
28
- menu_help = Wx::Menu.new()
29
- # Using Wx::ID_ABOUT default id means the menu item will be placed
30
- # in the correct platform-specific place
31
- menu_help.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
32
+ menu_bar = Wx::MenuBar.new
33
+ # The "file" menu
34
+ menu_file = Wx::Menu.new
32
35
  menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
33
- menu_bar = Wx::MenuBar.new()
34
36
  menu_bar.append(menu_file, "&File")
37
+
38
+ # The "help" menu
39
+ menu_help = Wx::Menu.new
40
+ # Using Wx::ID_ABOUT default id means the menu item will be placed
41
+ # in the correct platform-specific place - eg on OS X
42
+ menu_help.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
35
43
  menu_bar.append(menu_help, "&Help")
36
- # Assign the menus to this frame
37
- set_menu_bar(menu_bar)
38
44
 
45
+ # Assign the menubar to this frame
46
+ self.menu_bar = menu_bar
47
+
48
+ # Create a status bar
39
49
  create_status_bar(2)
40
- set_status_text("Welcome to wxRuby!")
50
+ self.status_text = "Welcome to wxRuby!"
41
51
 
42
- # handle menu events
43
- evt_menu(Wx::ID_EXIT) { on_quit }
44
- evt_menu(Wx::ID_ABOUT) { on_about }
52
+ # Set it up to handle menu events using the relevant methods
53
+ evt_menu Wx::ID_EXIT, :on_quit
54
+ evt_menu Wx::ID_ABOUT, :on_about
45
55
  end
46
56
 
47
57
  # End the application; it should finish automatically when the last
@@ -58,26 +68,18 @@ class MinimalFrame < Wx::Frame
58
68
  # create a simple message dialog with OK button
59
69
  about_dlg = Wx::MessageDialog.new( self, msg, 'About Minimal',
60
70
  Wx::OK|Wx::ICON_INFORMATION )
71
+ # Display the dialog on top of and blocking other windows, until
72
+ # dismissed by clicking the 'OK' button
61
73
  about_dlg.show_modal
62
74
  end
63
75
  end
64
76
 
65
- # Wx::App is the container class for any wxruby app - only a single
66
- # instance is required
67
- class MinimalApp < Wx::App
68
- # This method is called when main_loop is entered; it should set up
69
- # the application's and display initial GUI windows.
70
- def on_init
71
- self.app_name = 'Minimal'
72
- frame = MinimalFrame.new("Minimal wxRuby App")
73
- # This is required,
74
- frame.show
75
- # on_init must return a true value else the app will not start
76
- true
77
- end
77
+ # Wx::App is the container class for any wxruby app. To start an
78
+ # application, either define a subclass of Wx::App, create an instance,
79
+ # and call its main_loop method, OR, simply call the Wx::App.run class
80
+ # method, as shown here.
81
+ Wx::App.run do
82
+ self.app_name = 'Minimal'
83
+ frame = MinimalFrame.new("Minimal wxRuby App")
84
+ frame.show
78
85
  end
79
-
80
- # Create an instance ...
81
- app = MinimalApp.new
82
- # ... and run the application
83
- app.main_loop()
Binary file
@@ -13,34 +13,9 @@ rescue LoadError => no_wx_err
13
13
  end
14
14
  end
15
15
 
16
- class MyFrame < Wx::Frame
17
- def initialize(title)
18
- super(nil, -1, title)
19
- end
16
+ # This is the minimum code to start a WxRuby app - create a Frame, and
17
+ # show it.
18
+ Wx::App.run do
19
+ frame = Wx::Frame.new(nil, :title => "Minimal wxRuby App")
20
+ frame.show
20
21
  end
21
-
22
- class NothingApp < Wx::App
23
- def on_init
24
- puts("in on_init")
25
- $frame = MyFrame.new("Minimal wxRuby App")
26
- puts("about to call show")
27
- $frame.show
28
- puts("returning from on_init")
29
- return true
30
- end
31
-
32
- def on_fatal_exception
33
- puts("on_fatal_exception")
34
- end
35
-
36
- def on_exit
37
- puts("on_exit")
38
- return super
39
- end
40
- end
41
-
42
- a = NothingApp.new
43
- a.main_loop()
44
- puts("back from main_loop...")
45
- GC.start
46
- puts("survived gc")