Make GUI Apps with Shoes

Preview:

Citation preview

Make GUI Apps with ShoesBrian Hogan

Shoes?

simple GUI toolkit

why ruby?• Highly dynamic

• Very high level

• 100% object oriented

• 100% open-source

• Really easy to learn

simple code.

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

Ruby is dynamically typed

but strong-typed!

so a string and a number can be

declared without a type...

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

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

there’s a shortcut for building strings though:

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

#{} embeds an expression in a string,

converting the result to a string!

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

Methods (functions) are simple too.

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

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

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

Everything is an object... even integers

and strings!

Arrays

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

Hashes (dictionaries)

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

=>

Hashes as parameters for methods are very

common.

Blocks

some_method do some_code_you_wroteend

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

@colors.each do |color| puts colorend

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

You use them all the time in Ruby.

in fact, every method can take a block.

5.times do puts "Hello!"end

Blocks make it easy to write your own

language.

DSL - Domain Specific Language

Shoes is a DSL for making GUI apps.

A Shoes app is an object.

You use blocks to define the user

interface and trigger events,

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

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

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

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

stacks

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

flows

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

Combine stacks and flows.

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

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

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

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

edit_line

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

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

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

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

and flows!

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

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

Shoes can load images, play music, and play

movies.

You can use and embed almost every Ruby

library

It can open browser windows...

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

and color pickers.

Make games with Shoes!

You can build installers for Windows, Linux, and

Mac.

What makes Shoes so great?

It lets you build things fast...

...and have fun doing it.

Recommended