Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

284 lines (203 sloc) 7.31 kb

Fancy Gallery 1-5

Gallery No.1

Listen - Ruby's top teacher, Satish Talim.

Original code was created by George and his grandson team. Cool!

# gallery1.rb
Shoes.setup do
  gem 'win32-sapi'
end

require 'win32/sapi5'

Shoes.app :width => 400, :height => 173 do
  background orange
  image '../images/rubytop10-teacher.gif', :top => 20
  inscription ins('Listen'), :align => 'right', :stroke => green
  words = "Ruby's top teacher, Satish Talim"
  click{Win32::SpVoice.new.speak words}
end

gallery1.png

gallery1.png

Ruby's Top Teacher in 2008 - Satish Talim

Massimiliano Giroldi sent me the following patch for Leopard and helpful information about Windows's platform detection. Thx. Cool!

# gallery1-1.rb
Shoes.setup do
  gem 'win32-sapi' if RUBY_PLATFORM =~ /win32/
end

Shoes.app :width => 400, :height => 173 do
  background orange
  image '../images/rubytop10-teacher.gif', :top => 20
  inscription ins('Listen'), :align => 'right', :stroke => green
  words = "Ruby's top teacher, Satish Talim"
  case RUBY_PLATFORM
    when /darwin/
      click{`osascript; say "#{words}"`}
    when /win32/
      require 'win32/sapi5'
      click{Win32::SpVoice.new.speak words}
    else
  end
end

Note:
If you've installed MinGW32 or cygwin32, look at this.

Gallery No.2

Simple custom edit box with background image.

Inspired the Eric Proctor's post in POIRPWSC101-2I

# gallery2.rb
Shoes.app :width => 200, :height => 200 do
  background mintcream, :width => 1.0, :height => 1.0
  @s = stack :margin => 5, :width => 1.0, :height => 1.0 do
    background '../images/shell.png', :curve => 5
    @line = para '', :stroke => white, :weight => 'bold'
    @line.cursor = -1
  end

  keypress do |k|
    case k
      when String, "\n"
        @line.text += k
      when :backspace
        @line.text = @line.text[0..-2]
      else
    end
  end
end

gallery2.png

gallery2.png


Another one.

  • select an input area by mouse click
  • String key and backspace key are available
  • if you press enter-key, Shoes alert window will be pop-up
  • cursor does not blink but appear at the end of input


# gallery2-1.rb
Shoes.app :width => 600, :height => 80 do
  msg0 = 'Customer Number'
  para msg0, :left => 10, :top=> 30

  s0 = stack :left => 150, :top=> 30, :width => 100 do
    background coral, :curve => 5
    @line0 = para '', :weight => 'bold'
    @line0.cursor = -1
  end

  msg1 = 'Customer Name'
  para msg1, :left => 280, :top=> 30

  s1 = stack :left =>410, :top=> 30, :width => 150 do
    background lightgreen, :curve => 5
    @line1 = para '', :weight => 'bold'
    @line1.cursor = -1
  end

  flag, @msg = 0, msg0
  s0.click{flag = 0; @msg = msg0}
  s1.click{flag = 1; @msg = msg1}

  keypress do |k|
    line = flag.zero? ? @line0 : @line1
    case k
      when "\n"
        alert @msg
      when String
        line.text += k
      when :backspace
        line.text = line.text[0..-2]
      else
    end
  end
end

gallery2-1.png

gallery2-1.png

Gallery No.3

Live code! Rewrite the code whatever you want! Change colors at once when you write correct code.

Inspired the George Thompson's post in POIRPWSC101-2I

# gallery3.rb
Shoes.app :title => "Live Code", :width => 500, :height => 240, :resizable => false do
  background purple..white

txt =<<-EOS
  def get_random_color
    send COLORS.keys.map{|sym|sym.to_s}[rand(COLORS.keys.size)]
  end
  get_random_color
EOS

  title 'Random Colors', :left => 10, :stroke => white
  para "Rewrite the code whatever you want!\nChange colors at once\nwhen you write correct code." ,
         :left => 10 , :top => 60, :width => 540

  code = edit_box txt , :left => 10 , :top => 140 , :width => 360 , :height => 70

  every(1){oval width - 130, 30, 100 , :stroke => eval(code.text), :strokewidth => 20, :fill => eval(code.text)}
end

gallery3.png

gallery3.png

Gallery No.4

Webcomic on Shoes! A simple app but quite convenient. Cool!

Original code was created by Michael Kohl.
His code uses Shoes.setup for requiring Mechanize and uses image with no arguments. The code works well on Mac. But unfortunately on Windows, Shoes 2 still has some problems. xx-P
So, I try to come up with a solution to get around the problems. Here we go. :)

# gallery4.rb
Shoes.app :title => "ManWithHat - An xkcd viewer" do

  def get_strip_details page
    system "ruby gallery4-1.rb #{page}"
    @strip.path, @funny.text, @title.text = IO.readlines('xkcd_tmp.viewer')
  end

  flow :margin => 10 do
    button 'Latest strip' do
      page = 'http://xkcd.org/'
      get_strip_details page
    end

    button 'Random strip' do
      page = 'http://dynamic.xkcd.com/comic/random/'
      get_strip_details page
    end

    stack do
      @title = caption
      @funny = para
      @strip = image '../images/space.png'
      @disclaimer = para em 'All cartoons and texts used in '\
                            'this application were made by xkcd.com.'
    end
  end
end

The following code is not a Shoes app, just a Ruby script to use Mechanize. ;-)

# gallery4-1.rb
require 'mechanize'

agent = WWW::Mechanize.new
page = ARGV[0]

page_content = agent.get(page)
image_regex = /<img src="(.*)" title="(.*)" alt="(.*)"/  # > : for BlueCloth

image_regex.match page_content.search("//img[contains(@src,'comics')]").to_s
open('xkcd_tmp.viewer', 'w'){|f| f.puts $1, $2, $3}

gallery4.png

gallery4.png

Gallery No.5

Do you know Para-Para Manga? That is called a flip book in English (from Wikipedia).

This is a very simple code. Just for fun. ;-)

The original gif animation is on this site:
Ultrahigh speed potato chopping - Japanese site.

# gallery5.rb
Shoes.app :width => 175, :height => 160 do
  background tan
  st = {:left => 10, :top => 10}

  @images = []
  1.upto 60 do |i|
    n = '00' + i.to_s
    n = n[-3..-1]
    @images << image("potato_chopping/1258_s#{n}.gif").hide
  end

  @images.each{|img| img.style st}

  def potacho
    @images[59].hide
    a = animate 12 do |i|
      @images[i].show
      @images[i-1].hide if i > 0
      a.stop if i > 58
    end
  end

  button 'start', :left => 10, :bottom => 0 do
    potacho
  end
end

gallery5.png

gallery5.png

Policeman

Gallery 2 and 3 worked well with Shoes-0.r1263. But Gallery 1 and 4 didn't... so far.

Jump to Line
Something went wrong with that request. Please try again.