WxRuby

WxRuby

WxRuby est un toolkit graphique libre utilisant le langage de programmation Ruby. Il est basé sur le widget toolkit multiplate-forme wxWidgets, écrit en C++.

wxRuby permet d'utiliser Ruby pour la création d'applications graphiques sur Windows, Mac OS X, Linux GTK, etc. Les applications ainsi créées conservent l'apparence native du système sur lequel elles sont exécutées.

Sommaire

Licence

WxRuby est publié sous la licence WxRuby2[1].

Exemple

  1. #!/usr/bin/env ruby
    
  2.  
    
  3. begin
    
  4.   require 'rubygems' 
    
  5. rescue LoadError
    
  6. end
    
  7. require 'wx'
    
  8.  
    
  9. # A Wx::Frame is a self-contained, top-level Window that can contain
    
  10. # controls, menubars, and statusbars
    
  11. class MinimalFrame < Wx::Frame
    
  12.   def initialize(title)
    
  13.     # The main application frame has no parent (nil)
    
  14.     super(nil, :title => title, :size => [ 400, 300 ])
    
  15.  
    
  16.     menu_bar = Wx::MenuBar.new
    
  17.     # The "file" menu
    
  18.     menu_file = Wx::Menu.new
    
  19.     # Using Wx::ID_EXIT standard id means the menu item will be given
    
  20.     # the right label for the platform and language, and placed in the
    
  21.     # correct platform-specific menu - eg on OS X, in the Application's menu
    
  22.     menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
    
  23.     menu_bar.append(menu_file, "&File")
    
  24.  
    
  25.     # The "help" menu
    
  26.     menu_help = Wx::Menu.new
    
  27.     menu_help.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
    
  28.     menu_bar.append(menu_help, "&Help")
    
  29.  
    
  30.     # Assign the menubar to this frame
    
  31.     self.menu_bar = menu_bar
    
  32.  
    
  33.     # Create a status bar at the bottom of the frame
    
  34.     create_status_bar(2)
    
  35.     self.status_text = "Welcome to wxRuby!"
    
  36.  
    
  37.     # Set it up to handle menu events using the relevant methods. 
    
  38.     evt_menu Wx::ID_EXIT, :on_quit
    
  39.     evt_menu Wx::ID_ABOUT, :on_about
    
  40.   end
    
  41.  
    
  42.   # End the application; it should finish automatically when the last
    
  43.   # window is closed.
    
  44.   def on_quit
    
  45.     close()
    
  46.   end
    
  47.  
    
  48.   # show an 'About' dialog - WxRuby's about_box function will show a
    
  49.   # platform-native 'About' dialog, but you could also use an ordinary
    
  50.   # Wx::MessageDialog here.
    
  51.   def on_about
    
  52.     Wx::about_box(:name => self.title,
    
  53.                    :version     => Wx::WXRUBY_VERSION,
    
  54.                    :description => "This is the minimal sample",
    
  55.                    :developers  => ['The wxRuby Development Team'] )
    
  56.   end
    
  57. end
    
  58.  
    
  59. # Wx::App is the container class for any wxruby app. To start an
    
  60. # application, either define a subclass of Wx::App, create an instance,
    
  61. # and call its main_loop method, OR, simply call the Wx::App.run class
    
  62. # method, as shown here.
    
  63. Wx::App.run do 
    
  64.   self.app_name = 'Minimal'
    
  65.   frame = MinimalFrame.new("Minimal wxRuby App")
    
  66.   frame.show
    
  67. end
    

Références

Liens externes


Wikimedia Foundation. 2010.

Contenu soumis à la licence CC-BY-SA. Source : Article WxRuby de Wikipédia en français (auteurs)

Игры ⚽ Нужно решить контрольную?

Regardez d'autres dictionnaires:

  • WxWidgets — Тип библиотека элементов интерфейса (виджетов) Разработчик wxWidgets Developers and Contr …   Википедия

  • wxWidgets — Тип библиотека элементов интерфейса (виджетов) Разработчик …   Википедия

  • WxWidgets — Dieser Artikel wurde auf der Qualitätssicherungsseite des Portals Freie Software eingetragen. Beteilige dich an der Diskussion und hilf mit, den Artikel zu verbessern. wxWidgets …   Deutsch Wikipedia

  • WxWindows — Dieser Artikel wurde auf der Qualitätssicherungsseite des Portals Freie Software eingetragen. Beteilige dich an der Diskussion und hilf mit, den Artikel zu verbessern. wxWidgets …   Deutsch Wikipedia

  • Wxwidgets — Dieser Artikel wurde auf der Qualitätssicherungsseite des Portals Freie Software eingetragen. Beteilige dich an der Diskussion und hilf mit, den Artikel zu verbessern. wxWidgets …   Deutsch Wikipedia

  • Wxwindows — Dieser Artikel wurde auf der Qualitätssicherungsseite des Portals Freie Software eingetragen. Beteilige dich an der Diskussion und hilf mit, den Artikel zu verbessern. wxWidgets …   Deutsch Wikipedia

  • WxWindows — wxWidgets Тип библиотека элементов интерфейса (виджетов) Разработчик wxWidgets Developers and Contributers Написана на C++ …   Википедия

  • Руби IDE — Ruby Семантика: мультипарадигмальный Тип исполнения: интерпретатор Появился в: 1995 г. Автор(ы): Юкихиро Мацумото Последняя версия: 1.9.1 …   Википедия

  • Рубин (язык программирования) — Ruby Семантика: мультипарадигмальный Тип исполнения: интерпретатор Появился в: 1995 г. Автор(ы): Юкихиро Мацумото Последняя версия: 1.9.1 …   Википедия

  • Язык программирования Рубин — Ruby Семантика: мультипарадигмальный Тип исполнения: интерпретатор Появился в: 1995 г. Автор(ы): Юкихиро Мацумото Последняя версия: 1.9.1 …   Википедия

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”