Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

134 lines (97 sloc) 3.532 kb

Open a new app window

We can use window method to open a new app window.

# sample46.rb
Shoes.app :title => 'parent', :width => 300, :height => 200 do
  def open_new_window
    window  :title => 'child', :width => 200, :height => 200 do
      button('parent'){owner.hello green}
      button('child'){owner.hello green, self}
    end
  end

  def hello color, win = nil
    win ||= self
    @n ||= 0
    @n += 1
    win.para strong("#{win}--#{@n}\n"), :stroke => color
  end

  button('parent'){hello red}
  button('child'){hello red, @w}
  para link('open a new window'){@w = open_new_window}
end

sample46.png

sample46.png

This screenshot shows the following.

  • open parent window.
  • in parent window, click parent button, output is --1
  • in parent window, click child button, output is --2
  • click 'open a new window' link, open a child window.
  • in child window, click parent button, output is --3
  • in child window, click child button, output is --4
  • in parent window, click parent button, output is --5
  • in parent window, click child button, output is --6

Another example.
We can use Shoes.app method to open a new app window.

# sample48.rb
@blk = class Trip < Shoes
  url "/", :index
  url "/japan", :japan
  url "/india", :india
  url "/tokyo", :tokyo
  url "/pune", :pune

  @@win = 0

  def index 
    case @@win
      when 0
        background coral
        para strong link("Go to Japan.", :click => "/japan")
        para strong link("Go to India.", :click => "/india")
      when 1
        background crimson
        para strong link("Go to Tokyo.", :click => "/tokyo")
      when 2
        background darkorange
        para strong link("Go to Pune.", :click => "/pune")
      else
    end
  end

  def japan
    @@win = 1
    Shoes.app :title => "Japan", :width => 200, :height => 100, &@blk
    @@win = 0
    visit "/"
  end

  def india
    @@win = 2
    Shoes.app :title => "India", :width => 200, :height => 100, &@blk
    @@win = 0
    visit "/"
  end

  def tokyo
    background gold
    para strong "Welcome to Tokyo!"
  end

  def pune
    background darksalmon
    para strong "Welcome to Pune!"
  end
end

Shoes.app :title => "World Trip", :width => 200, :height => 100, &@blk

Note:
Code Highlighter has a bug. It may replace &@ to &;@ in the code falsely. :(
So, please use sample48.rb under src directory instead of above code.

sample48.png

sample48.png

This screenshot shows the following.

  • open first window: title is World Trip
  • in first window, click 'Go to Japan', open second window: title is Japan
  • in first window, click 'Go to India', open third window: title is India
  • in second window, click 'Go to Tokyo', chang Shoes-URL on the same window, then shows the message "Welcome to Tokyo!"

The original idea was discussed in the Shoes ML.
links in ur windoze

Policeman

The sample46.rb worked with Shoes-0.r1263. The behavior was the same as Raisins. But showed slightly different messages like this:

sample46-1.png

sample46-1.png

The sample48.rb worked well with Shoes-0.r1263

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