Developing cross platform desktop application with Ruby

16,333 views
15,618 views

Published on

A brief introduction and example of developing desktop application with Ruby programming language. JRuby and shoesrb is discussed as platform.
Prepared for and Presented on Ruby Conference Bangladesh 2003.

Published in: Technology
4 Comments
20 Likes
Statistics
Notes
  • Nice presentation helped me a lot thanks.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • @anisniit no worries mate, spreading the voice is pretty much all I can do to contribute to the ruby dev environment, but I try to do it good :) and that's already a good thing considering my pretty contorted english :D I'm glad you liked the solutions I advised though, take your time to experiment with them :)
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • @janfryslide, Thanks a lot for the great info! I'll take a look soon will share my views with you.
    Thanks again.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Thanks for your talk. I think you missed a more recent and powerful approach to developing a desktop app with jruby:

    jrubyfx wrapper for javafx gui library
    https://github.com/jruby/jrubyfx/wiki/Getting-Started

    other than being a more modern and good looking gui library (and not only that), with javafx can have presentation code in a separate FXML file and you can also take advantage of the wonderful javafx scenebuilder visual designer!

    A app is not necessarily a game but as a side note I'd also have mentioned the usage of the free and powerful JMonkeyEngine 3D game engine with JRuby which, I think, is the most mature way (if you consider the few and incomplete alternatives) to work with 3D graphics and multimedia content using ruby code, at the moment:

    https://github.com/blaix/jme3-jruby-template

    I'd like to know what you think :)
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
16,333
On SlideShare
0
From Embeds
0
Number of Embeds
106
Actions
Shares
0
Downloads
142
Comments
4
Likes
20
Embeds 0
No embeds

No notes for slide

Developing cross platform desktop application with Ruby

  1. 1. Desktop Application with Ruby Getting started with
  2. 2. I am... PHP ZEND KOHANA JSE JEE Ruby GWT JavaScript jQuery sinatra BackboneJS CSS3 HTML5 MySQL DrupalAnis Uddin Ahmad MongoDB PHPUNIT GroovyCTO & Co-Founder JRuby Symfony2 SWINGWNeeds Ltd. sqlite Doctrain solr Phing grails ...
  3. 3. !=
  4. 4. Ruby is not ONLY for web
  5. 5. Its a generic purpose language
  6. 6. generic purpose?● Web Application● Desktop Application● Mobile Application (Yes iPhone too!)● DSLs● Antyhing you can think*
  7. 7. So, Ruby can make Desktop App? Okay... But HOW?
  8. 8. Many Ways! Shoes Ruby-GNOME2 / GTKWxRuby Ruby-Tk Ruby Cocoa / MacRubyQtRuby JRuby + Swing FxRuby JRuby + SWT
  9. 9. Many Ways! Shoes Ruby-GNOME2 / GTKWxRuby Ruby-Tk Ruby Cocoa / MacRubyQtRuby JRuby + Swing FxRuby JRuby + SWT
  10. 10. Shoes cross-platform toolkit forwriting graphical apps easily and artfully using Ruby
  11. 11. Starting with Shoes● Download (http://shoesrb.com/downloads))● Run Shoes
  12. 12. Starting with Shoes● Download (http://shoesrb.com/downloads))● Run Shoes
  13. 13. Shoes exampleShoes.app :width => 300, :height => 200 do  button("Click me!") { alert("Good job.") }end
  14. 14. Shoes exampleShoes.app :width => 300, :height => 200 do  button("Click me!") { alert("Good job.") }end
  15. 15. Shoes example (Clock)Shoes.app do  @time = title "0:00"  every 1 do    @time.replace(Time.now.strftime("%I:%M %p"))  endend
  16. 16. Hackety Hack! http://hackety.com/
  17. 17. Packaging Shoes
  18. 18. JRubyThe Ruby Programming Language on the JVM
  19. 19. Ruby for desktop application? Yes we can!
  20. 20. The Redcar Editor http://redcareditor.com/
  21. 21. Why JRuby?● High performance
  22. 22. Why JRuby?● High performance● Real threading
  23. 23. Why JRuby?● High performance● Real threading● Vast array of libraries (gems + JARs)
  24. 24. Why JRuby?● High performance● Real threading● Vast array of libraries (gems + JARs)● Platform Independent
  25. 25. Why JRuby?● High performance● Real threading● Vast array of libraries (gems + JARs)● Platform Independent● Enterprise Acceptance
  26. 26. Why JRuby?● High performance● Real threading● Vast array of libraries (gems + JARs)● Platform Independent● Enterprise Acceptance The best of both worlds!
  27. 27. Lets make with JRuby!
  28. 28. Get JRuby● Download● Extract● Add bin subdirectory to your $PATH – (PATH=path/to/jruby/bin:$PATH)● Test it: jruby -v● Assuming you have jdk 1.7 installed● Can be installed with rvm too
  29. 29. Import Java Swing in .rbinclude Javaimport javax.swing.JFrameimport javax.swing.JComboBoximport javax.swing.JButtonimport javax.swing.JPanelimport javax.swing.JLabelimport javax.swing.JTextFieldimport java.awt.GridLayout
  30. 30. Make a Frame (JFrame)class NumberConverter < JFrame def initialize super(Number Format Converter) set_size(400,140); set_visible(true);       set_default_close_operation(JFrame::EXIT_ON_CLOSE); endendnum_converter = NumberConverter.new
  31. 31. Lets run it!$ cd go/to/source/dir$ jruby number_converter.rb
  32. 32. Place containersuper(Number Format Converter)main = JPanel.new;get_content_pane().add("Center", main);
  33. 33. Set Layoutsuper(Number Format Converter)main = JPanel.new;main.set_layout(GridLayout.new(3,3,2,2))get_content_pane().add("Center", main)
  34. 34. Add Componentsmain.set_layout(GridLayout.new(3,3,2,2))main.add(JLabel.new("Convert From : ", JLabel::RIGHT))main.add(@cmbFrom = JComboBox.new)main.add(@input = JTextField.new(15))
  35. 35. Where are they going?main.set_layout(GridLayout.new(3,3,2,2))main.add(JLabel.new("Convert From : ", JLabel::RIGHT))main.add(@cmbFrom = JComboBox.new)main.add(@input = JTextField.new(15)) 1 2 3 4 5 6 7 8 9
  36. 36. Add the rest ofmain.add(@input = JTextField.new(15))# Second rowmain.add(JLabel.new("Convert To : ", JLabel::RIGHT));main.add(@cmbTo = JComboBox.new);main.add(result = JTextField.new(15));# Third rowmain.add(JLabel.new(" ")); # Leave this cell blankmain.add(btn = JButton.new("CONVERT"));
  37. 37. Lets run again!$ cd go/to/source/dir$ jruby number_converter.rb
  38. 38. More with componentsmain.add(result = JTextField.new(15));result.set_editable(false);main.add(btn = Jbutton.new("CONVERT"));# Add options to comboBoxesnum_formats = ["Decimal", "Binary", "HexaDecimal", "Octal"]num_formats.each{|format| @cmbFrom.add_item format }num_formats.each{|format| @cmbTo.add_item format }
  39. 39. Set Event Handlermain.add(btn = Jbutton.new("CONVERT"));btn.add_action_listener do |evt| result.set_text(convert.upcase);end
  40. 40. Set Event Handler cont.main.add(btn = Jbutton.new("CONVERT"));btn.add_action_listener do |evt| result.set_text(convert.upcase);end def convert # Take the value of @input # Take formats form @cmbFrom and @cmbTo # Convert to required format endend # end of class NumFormat
  41. 41. Yep! Its Done!!https://github.com/ajaxray/jruby-swing
  42. 42. Java <=> JRuby Transformation
  43. 43. Java <=> JRuby Transformationnew Car(color, wheels)Car.new color, wheels
  44. 44. Java <=> JRuby TransformationJLabel.LEFTJLabel::LEFT
  45. 45. Java <=> JRuby TransformationObj.longFuncName();Obj.long_func_name
  46. 46. Java <=> JRuby TransformationString[] options = {"all", "any"};combo = new JcomboBox(options);options.each{ |format| combo.add_item format}
  47. 47. Java <=> JRuby Transformationbtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { doSomething(); }});btn.add_action_listener do |evt| do_somethingend
  48. 48. Deployment Warblerhttp://rawr.rubyforge.org/ https://github.com/jruby/warbler
  49. 49. BTW, JRuby is not ONLY for Desktop● Its just Ruby*● Rails just works *Here are differences- https://github.com/jruby/jruby/wiki/DifferencesBetweenMriAndJruby
  50. 50. JRuby Frameworks https://github.com/jruby/jruby/wiki/GUIFrameworks● Cheri::Swing● Limelight● Monkeybars● RSwing● Rubeus● Swiby
  51. 51. JRuby Frameworks https://github.com/jruby/jruby/wiki/GUIFrameworks● Cheri::Swing● Limelight● Monkeybars● RSwing● Rubeus● SwibyFrame.new("hello, world") do |frame| frame.default_close_operation = :exit_on_close frame.size = [200, 200] ...
  52. 52. Questions?

×