62
Make GUI Apps with Shoes Brian Hogan

Make GUI Apps with Shoes

Embed Size (px)

Citation preview

Page 1: Make GUI Apps with Shoes

Make GUI Apps with ShoesBrian Hogan

Page 2: Make GUI Apps with Shoes

Shoes?

Page 3: Make GUI Apps with Shoes

simple GUI toolkit

Page 4: Make GUI Apps with Shoes

why ruby?• Highly dynamic

• Very high level

• 100% object oriented

• 100% open-source

• Really easy to learn

Page 5: Make GUI Apps with Shoes

simple code.

age = 42first_name = "Homer"start_date = Date.new 1980, 06, 05annual_salary = 100000.00

Page 6: Make GUI Apps with Shoes

Ruby is dynamically typed

Page 7: Make GUI Apps with Shoes

but strong-typed!

Page 8: Make GUI Apps with Shoes

so a string and a number can be

declared without a type...

Page 9: Make GUI Apps with Shoes

...but you can’t just add a number to a string without converting it.

age = 25"you are " + age.to_s + " years old!"

Page 10: Make GUI Apps with Shoes

there’s a shortcut for building strings though:

age = 25"you are #{age} years old."

Page 11: Make GUI Apps with Shoes

#{} embeds an expression in a string,

converting the result to a string!

Page 12: Make GUI Apps with Shoes

Ruby has simple logic.if on_probation(start_date) puts "Yes"else puts "no"end

Page 13: Make GUI Apps with Shoes

Methods (functions) are simple too.

# if start date + 6 months is > todaydef on_probation?(start_date) (start_date >> 6 > Date.today)end

Page 14: Make GUI Apps with Shoes

Classes can be boring...class Person @first_name @last_name def first_name=(f) @first_name = f end def first_name @first_name end def last_name=(l) @last_name = l end def last_name @last_name endend

Page 15: Make GUI Apps with Shoes

...or awesome!class User attr_accessor :first_name, :last_nameend

Page 16: Make GUI Apps with Shoes

Everything is an object... even integers

and strings!

Page 17: Make GUI Apps with Shoes

Arrays

colors = ["Red", "Green", "Blue"]

Page 18: Make GUI Apps with Shoes

Hashes (dictionaries)

attributes = {:age => 25, :first_name => "Homer", :last_name => "Simpson"}

Page 19: Make GUI Apps with Shoes

=>

Page 20: Make GUI Apps with Shoes

Hashes as parameters for methods are very

common.

Page 21: Make GUI Apps with Shoes

Blocks

some_method do some_code_you_wroteend

Page 22: Make GUI Apps with Shoes

Blocks can iterate...@colors = ["red", "green", "blue"]

@colors.each do |color| puts colorend

Page 23: Make GUI Apps with Shoes

and encapsulate codecreate_table :products do |t| t.string :name t.text :description t.boolean :visible t.integer :priceend

Page 24: Make GUI Apps with Shoes

You use them all the time in Ruby.

Page 25: Make GUI Apps with Shoes

in fact, every method can take a block.

5.times do puts "Hello!"end

Page 26: Make GUI Apps with Shoes

Blocks make it easy to write your own

language.

Page 27: Make GUI Apps with Shoes

DSL - Domain Specific Language

Page 28: Make GUI Apps with Shoes

Shoes is a DSL for making GUI apps.

Page 29: Make GUI Apps with Shoes

A Shoes app is an object.

Page 30: Make GUI Apps with Shoes

You use blocks to define the user

interface and trigger events,

Page 31: Make GUI Apps with Shoes

Shoes.app :title => "Hello World" do alert "Hello World"end

Page 32: Make GUI Apps with Shoes

Shoes.app :title => "Hello World" do button "Click me" do alert "Hello World" endend

Page 33: Make GUI Apps with Shoes

Shoes.app :title => "Hello World", :width => 320, :height => 240 do background red end

Page 34: Make GUI Apps with Shoes

Shoes.app :title => "Hello World", :width => 320, :height => 240 do background red..black end

Page 35: Make GUI Apps with Shoes

stacks

Page 36: Make GUI Apps with Shoes

Shoes.app :title => "Hello World", :width => 320, :height => 240 do stack do para "Hello" para "World" end end

Page 37: Make GUI Apps with Shoes

flows

Page 38: Make GUI Apps with Shoes

Shoes.app :title => "Hello World", :width => 320, :height => 240 do flow do para "Hello" para "World" end end

Page 39: Make GUI Apps with Shoes

Combine stacks and flows.

Page 40: Make GUI Apps with Shoes

Shoes.app :title => "Hello World", :width => 320, :height => 240 do stack :width => "100%" do background gray title "Hello World" end stack :width => "50%" do flow :width => "100%" do para "Left side has some text" end end stack :width => "50%" do background white para "Right side has some text" para "without an inner flow." end

end

Page 41: Make GUI Apps with Shoes

Shoes.app :title => "Hello World" do stack do banner "Hello there." title "The quick" subtitle "brown fox" tagline "jumped" caption "over" para "the" inscription "lazy dog" endend

Page 42: Make GUI Apps with Shoes

edit_lineShoes.app :title => "Hello World" do para "Enter your name" @name = edit_lineend

Page 43: Make GUI Apps with Shoes

Shoes.app :title => "text boxes" do para "Password" @pass = edit_line(:secret => true)end

edit_line

Page 44: Make GUI Apps with Shoes

edit_boxShoes.app :title => "text boxes" do para "About Me" @about = edit_boxend

Page 45: Make GUI Apps with Shoes

list_boxShoes.app :title => "text boxes" do para "Colors" @color = list_box :items => ["green", "red", "blue"]end

Page 46: Make GUI Apps with Shoes

Use .text to grab the values in the boxes.

Shoes.app :title => "Hello World" do para "Enter your name" @name = edit_line button "Go" do name = @name.text alert "Hello #{name}" endend

Page 47: Make GUI Apps with Shoes

Since everything is an object, you can work with it... even stacks

and flows!

Page 48: Make GUI Apps with Shoes

Shoes.app do para "add name" button "Add" do @names.append do para @name.text end @name.text = "" end @names = stackend

Page 49: Make GUI Apps with Shoes

Ooooh.. windows!Shoes.app do button "Open window" do window :title => "Child" do para "Hello!" end endend

Page 50: Make GUI Apps with Shoes

Shoes can load images, play music, and play

movies.

Page 51: Make GUI Apps with Shoes

You can use and embed almost every Ruby

library

Page 52: Make GUI Apps with Shoes
Page 53: Make GUI Apps with Shoes
Page 54: Make GUI Apps with Shoes

It can open browser windows...

Page 55: Make GUI Apps with Shoes

..and hook into the OS’s open, save, fonts,

and color pickers.

Page 56: Make GUI Apps with Shoes

Make games with Shoes!

Page 57: Make GUI Apps with Shoes

You can build installers for Windows, Linux, and

Mac.

Page 58: Make GUI Apps with Shoes

What makes Shoes so great?

Page 59: Make GUI Apps with Shoes

It lets you build things fast...

Page 60: Make GUI Apps with Shoes

...and have fun doing it.