SlideShare a Scribd company logo
1 of 23
Download to read offline
Intoduction to
  RubyCocoa
  (CocoaHead:Thinkboy)




  source: http://www.rubycocoa.com/
Aganda
• Problem?
• What?
• Why?
• How?
• Where?
• Demo?
Neither true or false,
just a matter of choice!
Problem?

• I love Mac OSX GUI (Aqua)
• I love Cocoa
• I love Xcode & Interface Builder
• But programming in Objective-C may be a
  bit of ‘curve’ to get started
From Objective-C
@interface Controller : NSObject
{
     IBOutlet NSWindow *itsWindow;
}
- (IBAction)changeTransparency:(id)sender;
@end
@implementation Controller
- (IBAction)changeTransparency:(id)sender
{	
     [itsWindow setAlphaValue:[sender floatValue]];
     [itsWindow display];
}
@end
To RubyCocoa
class Controller < OSX::NSObject
    ib_outlet :itsWindow
    def changeTransparency(sender)
        @itsWindow.setAlphaValue(sender.floatValue)
        @itsWindow.display
    end
end
Differences?
• ruby vs many other programming lang
• ruby vs objective-c vs java
• more comparison
• benchmark comparison
 Again, it is just a matter of choice
    and, perhaps, depending on
             requirement.
What is Ruby?
• Created by Yukihiro "Matz" Matsumoto in 1993
• PURE object-oriented             “if it walks like a duck,
                                   and talks like a duck,
                                   then it might as well be a duck.”



• Dynamic typing (duck typing)
                                   ~ Dave Thomas




• Interpreted language (scripting language)
• Designed for programmer productivity and fun
• Follow the principle of least surprise (POLS)
    in short, when u look at the
    syntax, u feel like home.
    that’s all.
Ruby Learning Trail

• quick tutorial
• interactive practice
• Programming Ruby by Dave Thomas
• Ruby Pocket Reference (O'Reilly 2007)
• more recommendation
When to use
        RubyCocoa?
Ruby           Ruby
                          Domain Specific
                           Application
JRuby       RubyCocoa      Runtime Bridge

Java        Objective-C   Core/ Framework

 C              C          System/Native
What is RubyCocoa?
• created by Hisakuni Fujimoto in 2001
• a bridge that makes it possible for Ruby
  scripts to access Objective-C objects
• like SWIG? but better!       Ruby and Objective C
                               share a common
                               ancestor in Smalltalk
                                                       tool like SWIG which
                                                       reads C and C++ source
                                                       files and automatically


• automatically create
                                                       writes the glue code that
                       Ruby proxy objects              wraps C functions for
                                                       other languages.
                                                       Objective-C uses for
  that are bridged to Objective-C classes.             dynamic message




• forwards Ruby messages to the instances of
  Objective-C classes.                                  by automatically
                                                        creating Ruby proxy
                                                        objects that are bridged


• so what? mixing Ruby and Objective-C in
                                                        to Objective-C classes.

                                                        for wards Ruby messages
                                                        to the instances of these

  the same source files.                                 Objective-C classes.
Why RubyCocoa?
• officially supported by Apple
• full support in Xcode3 (e.g. color syntax, auto
  complete, formatting)
• supports all important features of Cocoa, such as
  key-value coding, key-value observing, Core Data,
  the document architecture, notifications, and undo
  management.
• standard package in 10.5: ruby 1.8.6, rubycocoa,
  RubyGems, rake , Rails , Mongrel , Capistrano,
  Ferret, OpenID, sqlite3-ruby, libxml-ruby, dnssd,
  net-ssh and net-sftp
RubyCocoa How-To?
1. install RubyCocoa 0.13.0
2. create Cocoa-Ruby Application in Xcode3
3. add ScriptingBridge.framework
4. create new ruby controller by subclass
   NSObject
5. create label and button
6. connect controller to ib_outlet & ib_action
ITunesController.rb
require 'osx/cocoa'
include OSX

class ITunesController < NSObject
    ib_outlet :text_field
	
    def show_version(sender)
        iTunes =
SBApplication.applicationWithBundleIdentifier:'com.apple.iTunes'
        @text_field.setStringValue("iTunes version:
#{iTunes.version}")
		
    end
    ib_action :show_version
end
Quick Tutorial?
1. This (Shortest) Tutorial:
  http://cocoalocker.blogspot.com/2007/11/
  ruby-cocoa.html


2. Other Tutorial from YouTube
  http://www.youtube.com/watch?v=7q_DD-
  W6-oI&eurl=http://technorati.com/videos/
  youtube.com%2Fwatch%3Fv%3D7q_DD-
  W6-oI
RubyCocoa ri Doc?

• install rubycocoa-0.13.0.tar manually.
• ruby install config
• ruby install doc
• in the folder /RubyCocoa-0.13.0/
  framework/bridge-doc/
Where to Fish?
• Warn! apple official doc is not so accurate!!
 • doc example does not work on Xcode3
• lets learn by example:
 • /Developer/Examples/Ruby/RubyCocoa
 • Must Read: official RubyCocoa site
 • Mailing list: rubycocoa-talk
NXT Demo!
Demo Setup
• RubyCocoa that remote control NXT
• install Lego Mindstorms NXT 1.1 software
• setup bluetooth device from Mac to NXT
• gem install ruby-nxt 0.8.1
• download and compile ruby-serialport 0.6
• create a RubyCocoa apps in Xcode3
 source: www.bluetooth.com
                             +   +
Demo Architecture
    Ruby                       LabVIEW/C / Java


  Ruby-NXT                    NXT-G/RobotC/Lejos

                  Bluetooth
Ruby-SerialPort                 NXT Firmware
NxtController.rb
require 'osx/cocoa'
class NxtController < OSX::NSObject


      ib_outlet :command_mode

      ib_outlet :run_state

      ib_outlet :tacho_count

      ib_action :move_forward

      

      def initialize

      
      @nxt = NXTComm.new($DEV)

      end


       def move_forward

       
    @command_mode.setStringValue("Moving forward...")

       
    command = Commands::Move.new(@nxt)
 

       
    command.ports = :a, :b, :c

       
    command.duration = {:seconds => 1}

       
    command.next_action = :brake

       
    @run_state.setStringValue("Run State: #{command.message1.inspect}")

       
    @tacho_count.setStringValue("Tacho Count: #{command.message2.inspect}")

       

       
    command.duration = :unlimited

       
    command.start

       
    sleep(1)

       
    command.stop

       end
.....

* ported from the tk example of ruby-nxt
More About NXT
• NXT blog
  http://nxtasy.org/
• NXT programming Software
  http://www.teamhassenplug.org/NXT/
  NXTSoftware.html
• Interesting Projects
  http://www.youtube.com/watch?v=I8VvTENzPGI
  http://www.youtube.com/watch?v=0sl1Q6S3yuo
  http://www.youtube.com/watch?v=s0G35-xoRfA
Q &A
Email: manchi.leung@gmail.com

More Related Content

What's hot

Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Rubykim.mens
 
JavaScript as Development Platform
JavaScript as Development PlatformJavaScript as Development Platform
JavaScript as Development PlatformAlexei Skachykhin
 
An introduction and future of Ruby coverage library
An introduction and future of Ruby coverage libraryAn introduction and future of Ruby coverage library
An introduction and future of Ruby coverage librarymametter
 
LLVM Compiler - Link Time Optimization
LLVM Compiler - Link Time OptimizationLLVM Compiler - Link Time Optimization
LLVM Compiler - Link Time OptimizationVivek Pansara
 
Jfokus 2016 - A JVMs Journey into Polyglot Runtimes
Jfokus 2016 - A JVMs Journey into Polyglot RuntimesJfokus 2016 - A JVMs Journey into Polyglot Runtimes
Jfokus 2016 - A JVMs Journey into Polyglot RuntimesCharlie Gracie
 
Jit builder status and directions 2018 03-28
Jit builder status and directions 2018 03-28Jit builder status and directions 2018 03-28
Jit builder status and directions 2018 03-28Mark Stoodley
 
IronRuby for the .NET Developer
IronRuby for the .NET DeveloperIronRuby for the .NET Developer
IronRuby for the .NET DeveloperCory Foy
 
Rubinius - Ruby Implemented with Ruby
Rubinius - Ruby Implemented with RubyRubinius - Ruby Implemented with Ruby
Rubinius - Ruby Implemented with RubyAkanksha Agrawal
 
IronRuby for the Rubyist
IronRuby for the RubyistIronRuby for the Rubyist
IronRuby for the RubyistWill Green
 
A bridge between php and ruby
A bridge between php and ruby A bridge between php and ruby
A bridge between php and ruby do_aki
 
RJB - another choice for Ruby and Java interoperability
RJB - another choice for Ruby and Java interoperabilityRJB - another choice for Ruby and Java interoperability
RJB - another choice for Ruby and Java interoperabilityAkio Tajima
 
Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRubyelliando dias
 
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...Mickael Istria
 
Esoteric, Obfuscated, Artistic Programming in Ruby
Esoteric, Obfuscated, Artistic Programming in RubyEsoteric, Obfuscated, Artistic Programming in Ruby
Esoteric, Obfuscated, Artistic Programming in Rubymametter
 

What's hot (20)

Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
 
Ruby Presentation - Beamer
Ruby Presentation - BeamerRuby Presentation - Beamer
Ruby Presentation - Beamer
 
JavaScript as Development Platform
JavaScript as Development PlatformJavaScript as Development Platform
JavaScript as Development Platform
 
An introduction and future of Ruby coverage library
An introduction and future of Ruby coverage libraryAn introduction and future of Ruby coverage library
An introduction and future of Ruby coverage library
 
LLVM Compiler - Link Time Optimization
LLVM Compiler - Link Time OptimizationLLVM Compiler - Link Time Optimization
LLVM Compiler - Link Time Optimization
 
Jfokus 2016 - A JVMs Journey into Polyglot Runtimes
Jfokus 2016 - A JVMs Journey into Polyglot RuntimesJfokus 2016 - A JVMs Journey into Polyglot Runtimes
Jfokus 2016 - A JVMs Journey into Polyglot Runtimes
 
Jit builder status and directions 2018 03-28
Jit builder status and directions 2018 03-28Jit builder status and directions 2018 03-28
Jit builder status and directions 2018 03-28
 
IronRuby for the .NET Developer
IronRuby for the .NET DeveloperIronRuby for the .NET Developer
IronRuby for the .NET Developer
 
Rubinius - Ruby Implemented with Ruby
Rubinius - Ruby Implemented with RubyRubinius - Ruby Implemented with Ruby
Rubinius - Ruby Implemented with Ruby
 
IronRuby for the Rubyist
IronRuby for the RubyistIronRuby for the Rubyist
IronRuby for the Rubyist
 
Jaoo irony
Jaoo ironyJaoo irony
Jaoo irony
 
A bridge between php and ruby
A bridge between php and ruby A bridge between php and ruby
A bridge between php and ruby
 
IronRuby And The DLR
IronRuby And The DLRIronRuby And The DLR
IronRuby And The DLR
 
20140925 rails pacific
20140925 rails pacific20140925 rails pacific
20140925 rails pacific
 
Crystal
CrystalCrystal
Crystal
 
RJB - another choice for Ruby and Java interoperability
RJB - another choice for Ruby and Java interoperabilityRJB - another choice for Ruby and Java interoperability
RJB - another choice for Ruby and Java interoperability
 
Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRuby
 
LLVM
LLVMLLVM
LLVM
 
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
IDE as a Front-end and Fast time-to-market language support in Eclipse IDE re...
 
Esoteric, Obfuscated, Artistic Programming in Ruby
Esoteric, Obfuscated, Artistic Programming in RubyEsoteric, Obfuscated, Artistic Programming in Ruby
Esoteric, Obfuscated, Artistic Programming in Ruby
 

Similar to Introduction to RubyCocoa GUI Programming

MacRuby & HotCocoa
MacRuby & HotCocoaMacRuby & HotCocoa
MacRuby & HotCocoaThilo Utke
 
Ruby On Rails Overview
Ruby On Rails OverviewRuby On Rails Overview
Ruby On Rails Overviewjonkinney
 
MacRuby For Ruby Developers
MacRuby For Ruby DevelopersMacRuby For Ruby Developers
MacRuby For Ruby DevelopersRenzo Borgatti
 
RubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on RailsRubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on Railselliando dias
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLBarry Jones
 
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVMJung Kim
 
Ruby on Rails - An overview
Ruby on Rails -  An overviewRuby on Rails -  An overview
Ruby on Rails - An overviewThomas Asikis
 
Everything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventureEverything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventureQAware GmbH
 
Everything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPLEverything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPLMario-Leander Reimer
 
Mac ruby deployment
Mac ruby deploymentMac ruby deployment
Mac ruby deploymentThilo Utke
 
Programming iOS in Lua - A bridge story
Programming iOS in Lua - A bridge storyProgramming iOS in Lua - A bridge story
Programming iOS in Lua - A bridge storyjljumpertz
 
RubyMotion Introduction
RubyMotion IntroductionRubyMotion Introduction
RubyMotion IntroductionLori Olson
 
An introduction to the ruby ecosystem
An introduction to the ruby ecosystemAn introduction to the ruby ecosystem
An introduction to the ruby ecosystemGeison Goes
 
Ruby'izing iOS development
Ruby'izing iOS developmentRuby'izing iOS development
Ruby'izing iOS developmenttoamitkumar
 
Ruby on Rails : First Mile
Ruby on Rails : First MileRuby on Rails : First Mile
Ruby on Rails : First MileGourab Mitra
 
The story of language development
The story of language developmentThe story of language development
The story of language developmentHiroshi SHIBATA
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Nilesh Panchal
 

Similar to Introduction to RubyCocoa GUI Programming (20)

MacRuby & HotCocoa
MacRuby & HotCocoaMacRuby & HotCocoa
MacRuby & HotCocoa
 
Ruby On Rails Overview
Ruby On Rails OverviewRuby On Rails Overview
Ruby On Rails Overview
 
MacRuby For Ruby Developers
MacRuby For Ruby DevelopersMacRuby For Ruby Developers
MacRuby For Ruby Developers
 
RubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on RailsRubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on Rails
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
 
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
 
Ruby on Rails - An overview
Ruby on Rails -  An overviewRuby on Rails -  An overview
Ruby on Rails - An overview
 
Everything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventureEverything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventure
 
Everything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPLEverything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPL
 
Mac ruby deployment
Mac ruby deploymentMac ruby deployment
Mac ruby deployment
 
Programming iOS in Lua - A bridge story
Programming iOS in Lua - A bridge storyProgramming iOS in Lua - A bridge story
Programming iOS in Lua - A bridge story
 
RubyMotion Introduction
RubyMotion IntroductionRubyMotion Introduction
RubyMotion Introduction
 
Why ruby
Why rubyWhy ruby
Why ruby
 
An introduction to the ruby ecosystem
An introduction to the ruby ecosystemAn introduction to the ruby ecosystem
An introduction to the ruby ecosystem
 
Ruby'izing iOS development
Ruby'izing iOS developmentRuby'izing iOS development
Ruby'izing iOS development
 
Ruby on Rails : First Mile
Ruby on Rails : First MileRuby on Rails : First Mile
Ruby on Rails : First Mile
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
 
Athens Ruby Meetup #3: IronRuby
Athens Ruby Meetup #3: IronRubyAthens Ruby Meetup #3: IronRuby
Athens Ruby Meetup #3: IronRuby
 
The story of language development
The story of language developmentThe story of language development
The story of language development
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
 

More from tutorialsruby

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 

More from tutorialsruby (20)

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 

Recently uploaded

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 

Introduction to RubyCocoa GUI Programming

  • 1. Intoduction to RubyCocoa (CocoaHead:Thinkboy) source: http://www.rubycocoa.com/
  • 2. Aganda • Problem? • What? • Why? • How? • Where? • Demo?
  • 3. Neither true or false, just a matter of choice!
  • 4. Problem? • I love Mac OSX GUI (Aqua) • I love Cocoa • I love Xcode & Interface Builder • But programming in Objective-C may be a bit of ‘curve’ to get started
  • 5. From Objective-C @interface Controller : NSObject { IBOutlet NSWindow *itsWindow; } - (IBAction)changeTransparency:(id)sender; @end @implementation Controller - (IBAction)changeTransparency:(id)sender { [itsWindow setAlphaValue:[sender floatValue]]; [itsWindow display]; } @end
  • 6. To RubyCocoa class Controller < OSX::NSObject ib_outlet :itsWindow def changeTransparency(sender) @itsWindow.setAlphaValue(sender.floatValue) @itsWindow.display end end
  • 7. Differences? • ruby vs many other programming lang • ruby vs objective-c vs java • more comparison • benchmark comparison Again, it is just a matter of choice and, perhaps, depending on requirement.
  • 8. What is Ruby? • Created by Yukihiro "Matz" Matsumoto in 1993 • PURE object-oriented “if it walks like a duck, and talks like a duck, then it might as well be a duck.” • Dynamic typing (duck typing) ~ Dave Thomas • Interpreted language (scripting language) • Designed for programmer productivity and fun • Follow the principle of least surprise (POLS) in short, when u look at the syntax, u feel like home. that’s all.
  • 9. Ruby Learning Trail • quick tutorial • interactive practice • Programming Ruby by Dave Thomas • Ruby Pocket Reference (O'Reilly 2007) • more recommendation
  • 10. When to use RubyCocoa? Ruby Ruby Domain Specific Application JRuby RubyCocoa Runtime Bridge Java Objective-C Core/ Framework C C System/Native
  • 11. What is RubyCocoa? • created by Hisakuni Fujimoto in 2001 • a bridge that makes it possible for Ruby scripts to access Objective-C objects • like SWIG? but better! Ruby and Objective C share a common ancestor in Smalltalk tool like SWIG which reads C and C++ source files and automatically • automatically create writes the glue code that Ruby proxy objects wraps C functions for other languages. Objective-C uses for that are bridged to Objective-C classes. dynamic message • forwards Ruby messages to the instances of Objective-C classes. by automatically creating Ruby proxy objects that are bridged • so what? mixing Ruby and Objective-C in to Objective-C classes. for wards Ruby messages to the instances of these the same source files. Objective-C classes.
  • 12. Why RubyCocoa? • officially supported by Apple • full support in Xcode3 (e.g. color syntax, auto complete, formatting) • supports all important features of Cocoa, such as key-value coding, key-value observing, Core Data, the document architecture, notifications, and undo management. • standard package in 10.5: ruby 1.8.6, rubycocoa, RubyGems, rake , Rails , Mongrel , Capistrano, Ferret, OpenID, sqlite3-ruby, libxml-ruby, dnssd, net-ssh and net-sftp
  • 13. RubyCocoa How-To? 1. install RubyCocoa 0.13.0 2. create Cocoa-Ruby Application in Xcode3 3. add ScriptingBridge.framework 4. create new ruby controller by subclass NSObject 5. create label and button 6. connect controller to ib_outlet & ib_action
  • 14. ITunesController.rb require 'osx/cocoa' include OSX class ITunesController < NSObject ib_outlet :text_field def show_version(sender) iTunes = SBApplication.applicationWithBundleIdentifier:'com.apple.iTunes' @text_field.setStringValue("iTunes version: #{iTunes.version}") end ib_action :show_version end
  • 15. Quick Tutorial? 1. This (Shortest) Tutorial: http://cocoalocker.blogspot.com/2007/11/ ruby-cocoa.html 2. Other Tutorial from YouTube http://www.youtube.com/watch?v=7q_DD- W6-oI&eurl=http://technorati.com/videos/ youtube.com%2Fwatch%3Fv%3D7q_DD- W6-oI
  • 16. RubyCocoa ri Doc? • install rubycocoa-0.13.0.tar manually. • ruby install config • ruby install doc • in the folder /RubyCocoa-0.13.0/ framework/bridge-doc/
  • 17. Where to Fish? • Warn! apple official doc is not so accurate!! • doc example does not work on Xcode3 • lets learn by example: • /Developer/Examples/Ruby/RubyCocoa • Must Read: official RubyCocoa site • Mailing list: rubycocoa-talk
  • 19. Demo Setup • RubyCocoa that remote control NXT • install Lego Mindstorms NXT 1.1 software • setup bluetooth device from Mac to NXT • gem install ruby-nxt 0.8.1 • download and compile ruby-serialport 0.6 • create a RubyCocoa apps in Xcode3 source: www.bluetooth.com + +
  • 20. Demo Architecture Ruby LabVIEW/C / Java Ruby-NXT NXT-G/RobotC/Lejos Bluetooth Ruby-SerialPort NXT Firmware
  • 21. NxtController.rb require 'osx/cocoa' class NxtController < OSX::NSObject ib_outlet :command_mode ib_outlet :run_state ib_outlet :tacho_count ib_action :move_forward def initialize @nxt = NXTComm.new($DEV) end def move_forward @command_mode.setStringValue("Moving forward...") command = Commands::Move.new(@nxt) command.ports = :a, :b, :c command.duration = {:seconds => 1} command.next_action = :brake @run_state.setStringValue("Run State: #{command.message1.inspect}") @tacho_count.setStringValue("Tacho Count: #{command.message2.inspect}") command.duration = :unlimited command.start sleep(1) command.stop end ..... * ported from the tk example of ruby-nxt
  • 22. More About NXT • NXT blog http://nxtasy.org/ • NXT programming Software http://www.teamhassenplug.org/NXT/ NXTSoftware.html • Interesting Projects http://www.youtube.com/watch?v=I8VvTENzPGI http://www.youtube.com/watch?v=0sl1Q6S3yuo http://www.youtube.com/watch?v=s0G35-xoRfA