Introduction © Jean-Pierre ANGHEL - 2004 FXRuby Par l’exemple Table des matières. 2 Introduction. 4 Chapitre 1. 6 Bref historique de Ruby. 6 Bref historique de Fox. 6 Où trouver Ruby ?. Avec quel éditeur de texte ?. Quelles connaissances faut-il avoir ?. Avantages divers. 7 Présentation des composants visuels. 7 Présentation des aménageurs d'espace. 8 Chapitre 2. 9 Les fenêtres et tout ce qui va avec. 9 Un peu de Ruby. 10 Particularités de FXRuby. 11 Chapitre 3. 12 Le bouton simple. 12 Un peu de ruby (1) : 15 Les commentaires et substitutions. 15 Exemple général sur les boutons. 16 Particularités de FXRuby : 20 Les cadres et séparateurs. 22 Les boîtes à grouper. 22 Les cases à cocher. 23 Les boutons-radio. 23 Les boutons-bascule. 23 Les boutons avec flèches incorporées. 23 Les bulles d'aide. 24 La barre de statut 24 Un peu de Ruby (2) : 24 Les variables. 24 Les opérateurs. 25 Les méthodes. 26 Chapitre 4. 28 Les canevas. 28 Un peu de Ruby. 32 Les blocs. 32 Les itérateurs. 33 Les boucles. 33 Les expressions conditionnelles. 34 Notes. 167 p1
Gosu : une bibliothèque pour faire des jeux avec Ruby Toutes les fonctions et les classes sont contenues dans le module Gosu. Lorsqu'un paramètre de type Gosu::Color est demandé, on peut mettre à la place un entier de la forme : 0xAARRGGBB (ici en hexadécimal). A = Code alpha (255 : aucune transparence, 0 : transparence totale) R = Code pour le rouge G = Code pour le vert B = Code pour le bleu On peut utiliser une couleur lors du dessin pour modifier la couleur originale de l'image. Pour les paramètres de mode pour les fonctions de dessins, les valeurs possibles sont : :default :additive Profondeur d'un dessin : lorsque deux dessins occupent la même place, il faut déterminer lequel écrase l'autre : pour cela certaines fonctions permettent de spécifier une profondeur : le dessin de profondeur la plus grande sera dessinée sur tous les autres. Paramètre facultatif : tous paramètres ayant une valeur par défaut (=valeur) peut être ignoré lors de l'appel : il aura alors sa valeur par défaut. Les angles dans Gosu:
Shoes (GUI toolkit) Shoes' philosophy is one of simplicity. It's designed to make applications as easy as possible. Here's an example Shoes app: Shoes.app :title => "Push Button" do @note = para "Nothing pushed so far" button "Push me" do @note.replace "Aha! The button was pushed!" endend Shoes isn't just for standard windowing widgets. _why releases:v1, "Curious"v2, "Raisins"Post-_why releases:v3, "Policeman" Current release is version 3.1. Ruby/TK Guide Introduction The standard graphical user interface (GUI) for Ruby is Tk. Tk started out as the GUI for the Tcl scripting language developed by John Ousterhout. Tk has the unique distinction of being the only cross-platform GUI. Tk runs on Windows, Mac, and Linux and provides a native look-and-feel on each operating system. The basic component of a Tk-based application is called a widget. Tk applications follow a widget hierarchy where any number of widgets may be placed within another widget, and those widgets within another widget, ad infinitum. Most Tk-based applications follow the same cycle: create the widgets, place them in the interface, and finally, bind the events associated with each widget to a method.There are three geometry managers; place, grid and pack that are responsible for controlling the size and location of each of the widgets in the interface. Installation The Ruby Tk bindings are distributed with Ruby but Tk is a separate installation. Simple Tk Application Get Started
GUI Frameworks Glimmer DSL for SWT (JRuby Desktop Development Cross-Platform Native GUI Framework) is a native-GUI cross-platform desktop development library written in JRuby, an OS-threaded faster JVM version of Ruby. It includes SWT 4.29 (released on September 3, 2023). Glimmer's main innovation is a declarative Ruby DSL that enables productive and efficient authoring of professional-grade desktop applications by relying on the robust Eclipse SWT library, with the familiar native look, feel, and behavior of GUI on Mac, Windows, and Linux. File (Ruby 2.2.0) absolute_path(file_name [, dir_string] ) → abs_file_name click to toggle source Converts a pathname to an absolute pathname. Relative paths are referenced from the current working directory of the process unless dir_string is given, in which case it will be used as the starting point. File.absolute_path("~oracle/bin") VALUE rb_file_s_absolute_path(int argc, const VALUE *argv) { VALUE fname, dname; if (argc == 1) { return rb_file_absolute_path(argv[0], Qnil); } rb_scan_args(argc, argv, "11", &fname, &dname); return rb_file_absolute_path(fname, dname); } atime(file_name) → time click to toggle source Returns the last access time for the named file as a Time object). file_name can be an IO object. File.atime("testfile") static VALUE rb_file_s_atime(VALUE klass, VALUE fname) { struct stat st; if (rb_stat(fname, &st) < 0) { FilePathValue(fname); rb_sys_fail_path(fname); } return stat_atime(&st); } basename(file_name [, suffix] ) → base_name click to toggle source File.birthtime("testfile") blockdev?
IO binread(name, [length [, offset]] ) → string click to toggle source Opens the file, optionally seeks to the given offset, then returns length bytes (defaulting to the rest of the file). binread ensures the file is closed before returning. The open mode would be “rb:ASCII-8BIT”. IO.binread("testfile") IO.binread("testfile", 20) IO.binread("testfile", 20, 10) binwrite(name, string, [offset] ) => fixnum click to toggle source Opens the file, optionally seeks to the given offset, writes string then returns the length written. binwrite ensures the file is closed before returning. IO.binwrite("testfile", "0123456789", 20) IO.binwrite("testfile", "0123456789") static VALUE rb_io_s_binwrite(int argc, VALUE *argv, VALUE io) { return io_s_write(argc, argv, 1); } copy_stream(src, dst) click to toggle source copy_stream(src, dst, copy_length) copy_stream(src, dst, copy_length, src_offset) ::copy_stream copies src to dst. src and dst is either a filename or an IO. Synonym for IO.new. produces: Parameters¶ ↑ fd
Graphical User Interfaces: Installing Tk The Tk GUI toolkit was originally written for the TCL scripting language, but has since been adopted by many other languages including Ruby. Though it's not the most modern of toolkits, it is free and cross-platform and is a good choice for simpler GUI applications. However, before you can begin writing GUI programs, you first have to install the Tk library and the Ruby "bindings." A binding is the Ruby code used to interface with the Tk library itself. Without bindings, a scripting language cannot access native libraries such as Tk. How you install Tk will vary depending on your operating system. Installing Tk on Windows There are numerous ways to install Tk on Windows, but the easiest is to install the ActiveTCL scripting language from Active State. continue reading below our video Loaded: 0% Progress: 0% While TCL is a completely different scripting language than Ruby, it's made by the same people who make Tk and the two projects are closely linked. Installing Tk on Ubuntu Linux Testing Tk #!
WxRubyWiki: WxRuby wxRuby is an open source GUI toolkit for the [Ruby] programming language. It allows native-looking desktop applications to be written for Windows, OS X, Linux GTK and other platforms using only Ruby. It's based on the cross-platform [wxWidgets] C++ GUI framework. Why wxRuby? wxRuby offers a combination of features that no other GUI library in Ruby can match: More about wxRuby features - why choose it as a GUI toolkit for Ruby? Development Status The current wxRuby version is [2.0.1], released on 9 Sep 2009. Developing with wxRuby StyleGuide - general advice on programming style and strategies for wxRuby wxRuby Tutorial - guides to using different features of wxRuby FAQS - frequently asked questions about wxRuby Real-life wxRuby applications and [online code samples] - where to find examples to learn from WxSugar - wxSugar; additional tools and syntax for wxRuby, from the core dev team [[RubyOnWindows]] - a good intro How to use this site Latest News Older news
Ruby Qt tutorial This is Ruby Qt tutorial. In this tutorial you will learn the basics of GUI programming in Qt with Ruby language. The tutorial is suitable for beginners and intermediate programmers. Table of contents Qt Qt is a cross-platform application development framework. Related tutorials There is a full Ruby tutorial on ZetCode. FrontPage - Ruby-GNOME2 Project Website
FXRuby tut-gtk-intro - Ruby-GNOME2 Project Website Obviously, you need to install Ruby-GNOME2 on your machine. Please consult one of our Install Guide. If your system is not yet covered, just download manually the latest package from SourceForge, decompress the tarball and read the README file for further instructions. (More recently, installation process has been significantly improved - see the Installation documentation). To begin our introduction to GTK, we'll start with the simplest program possible. This program will create a 200x200 pixel window and has no way of exiting except to be killed by using the shell: require 'gtk2' window = Gtk::Window.new window.show Gtk.main Save this program in a file named base.rb, and call it with: ruby base.rb We will comment now each step of the program. The first line links the Ruby/GTK2 library in the program. require 'gtk2' The second line uses Gtk::Window.new to create a new GTK window with default parameters, as follows: window = Gtk::Window.new window.show Gtk.main Note about the section Caveat
AllInOneRuby - A "Just-in-Time and Temporary Installation of Ruby" A "Just-in-Time and Temporary Installation of Ruby" Fri May 25 15:05:24 UTC 2007Erik Veenstra <allinoneruby@erikveen.dds.nl> PDF version (A4) 1. 2. 3. 4. 5. 6. 7. As you know, Ruby has to be installed, either by unzipping a ZIP-file, or by running an installer. AllInOneRuby creates a compressed executable for Windows, Linux or Mac OS X (Darwin) that includes both the Ruby interpreter and the runtime libraries. A "just-in-time and temporary installation of Ruby"... Because of the gathering of files from your own Ruby installation, AllInOneRuby creates an executable for the platform it's being run on. And when I say Windows, I mean both Windows (RubyInstaller, MinGW and MSWin32) and Cygwin. What's the difference between RubyScript2Exe and AllInOneRuby? AllInOneRuby runs in 3 phases: That's it. The files in Config::CONFIG["sitelibdir"] are completely ignored, because (strictly spoken) they are not part of Ruby. 3.1. If you use the original allinoneruby.rb, use this to create allinoneruby.exe: