Class: Shoes

Inherits:
Object
  • Object
show all
Defined in:
lib/shoes/HttpResponse.rb,
lib/shoes/pack.rb,
lib/shoes/image.rb,
lib/shoes/version.rb,
lib/shoes/download.rb,
lib/shoes/deprecated.rb,
lib/shoes/shybuilder.rb,
lib/shoes.rb

Overview

fun - need this in several places.

Defined Under Namespace

Modules: Basic, Debugger, LogWindow, Manual, Pack, Types Classes: Download, HttpResponse, SettingUp, Setup, VideoVlc

Constant Summary collapse

I_NET =
"No, download Shoes if it's absent."
I_YES =
"Yes, I want Shoes included."
I_NOV =
"Yes, include Shoes, but without video support."
PackMake =
proc do
  background "#DDD"

  @page1 = stack do
    stack do
      background white
      background "#FFF".."#EEE", :height => 50, :bottom => 50
      border "#CCC", :height => 2, :bottom => 0
      stack :margin => 20 do
        selt = proc { @sel1.toggle; @sel2.toggle }
        @path = ""
        @shy_path = nil
        @sel1 =
          flow do
            para "File to package:"
            inscription " (or a ", link("directory", &selt), ")"
            edit1 = edit_line :width => -120
            @bb = button "Browse...", :width => 100 do
              @path = edit1.text = ask_open_file
              #est_recount
            end
          end
        @sel2 =
          flow :hidden => true do
            para "Directory:"
            inscription " (or a ", link("single file", &selt), ")"
            edit2 = edit_line :width => -120
            @bf = button "Folder...", :width => 100 do
              @path = edit2.text = ask_open_folder
              #est_recount
            end
          end

        para "Packaging options"
        para "Should Shoes be included with your script or should the script \
download Shoes when the user runs it? Not all options are available on all \
systems. The defaults work."
        flow :margin_left => 20 do
          @shy = check
          para "Shoes (.shy) for users who have Shoes already", :margin_right => 20
        end
        items = [Shoes::I_NET, Shoes::I_YES, Shoes::I_NOV]
        items.shift unless ::RUBY_PLATFORM =~ /mswin|mingw/
        flow :margin_left => 20 do
          flow :width => 0.25 do
            @exe = check 
            para "Windows"
          end
          @incWin = list_box :items => items, :width => 0.6, :height => 30 do
            @downOpt = @incWin.text
            est_recount 
          end
          @incWin.choose items[0]
        end
        flow :margin_left => 20 do
          flow :width => 0.25 do
            @dmg = check
            para "OS X", :margin_right => 47
          end
          osxop = [Shoes::I_NET, Shoes::I_NOV]
          @incOSX = list_box :items => osxop, :width => 0.6, :height => 30 do
            @downOpt = @incOSX.text
            est_recount
          end
          @incOSX.choose(Shoes::I_NOV)
        end 
        flow :margin_left => 20 do
          flow :width => 0.25 do
            @run = check
            para "Linux", :margin_right => 49 
          end
          @incLinux = list_box :items => [Shoes::I_NET], :width => 0.6,
              :height => 30 do
            est_recount
          end
          @incLinux.choose(Shoes::I_NET)
        end
      end
    end

    stack :margin => 20 do
      @est = para "Estimated size of your choice: ", strong("0k"), :margin => 0, :margin_bottom => 4
      def est_recount 
        base = 
          case  @downOpt
          when Shoes::I_NET; 98
          when Shoes::I_YES; 11600
          when Shoes::I_NOV; 7000
        end
        base += ((File.directory?(@path) ? Shy.du(@path) : File.size(@path)) rescue 0) / 1024
        @est.replace "Estimated size of each app: ", strong(base > 1024 ?
          "%0.1fM" % [base / 1024.0] : "#{base}K")
      end
      def build_thread
        @shy_path = nil
        if File.directory? @path
          @shy_path = @path.gsub(%r![\\/]+$!, '') + ".shy"
        elsif @shy.style[:checked]
          @shy_path = @path.gsub(/\.\w+$/, '') + ".shy"
        end
        if @shy_path and not @shy_meta
          @page_shy.show
          @shy_para.text = File.basename(@shy_path)
          @shy_launch.items = Shy.launchable(@path)
          return
        end
        @page2.show 
        @path2.replace File.basename(@path)
         inc_win_text, inc_osx_text, inc_linux_text = @incWin.text, 
@incOSX.text, @incLinux.text
        Thread.start do
          begin
            sofar, stage = 0.0, 1.0 / [@shy.style[:checked], @exe.style[:checked], @dmg.style[:checked], @run.style[:checked]].
              select { |x| x }.size
            blk = proc do |frac|
              @prog.style(:width => sofar + (frac * stage))
            end

            if @shy_path
              @status.replace "Compressing the script's folder."
              pblk = Shy.progress(Shy.du(@path)) do |name, perc, left|
                blk[perc]
              end
              Shy.c(@shy_path, @shy_meta, @path, &pblk)
              @path = @shy_path
              @prog.style(:width => sofar += stage)
            end
            if @exe.style[:checked]
              @status.replace "Working on an .exe for Windows."
              Shoes::Pack.exe(@path, inc_win_text, &blk)
              @prog.style(:width => sofar += stage)
            end
            if @dmg.style[:checked]
              @status.replace "Working on a .dmg for Mac OS X."
              Shoes::Pack.dmg(@path, inc_osx_text, &blk)
              @prog.style(:width => sofar += stage)
            end
            if @run.style[:checked]
              @status.replace "Working on a .run for Linux."
              Shoes::Pack.linux(@path, inc_linux_text, &blk)
              @prog.style(:width => sofar += stage)
            end
            if @shy_path and not @shy.style[:checked]
              FileUtils.rm_rf(@shy_path)
            end

            every do
              if @prog.style[:width] == 1.0
                @page2.hide
                @page3.show 
                @path3.replace File.basename(@path)
              end
            end
          rescue => e
            @packErrMsg = e
            # weirdness begins
            @page2.hide
            @path3.style  :font => 'italic', :size => 12
            @page3.show
            @path3.replace @packErrMsg
          end
        end
      end
      
      inscription "Using the latest Shoes build (0.r#{Shoes::REVISION})", :margin => 0
      flow :margin_top => 10, :margin_left => 310 do
        button "OK", :margin_right => 4 do
          @page1.hide; @bb.hide; @bf.hide
          @packErrMsg = nil
          build_thread
        end
        button "Cancel" do
          close
        end
      end
    end
  end

  @page_shy = stack :hidden => true do
    stack do
      background white
      border "#DDD", :height => 2, :bottom => 0
      stack :margin => 20 do
        para "Details for:", :margin => 4
        @shy_para = para "", :size => 20, :margin => 4
        flow do
          stack :margin => 10, :width => 0.4 do
            para "Name of app:"
            @shy_name = edit_line :width => 1.0
          end
          stack :margin => 10, :width => 0.4 do
            para "Version:"
            @shy_version = edit_line :width => 120
          end
          stack :margin => 10, :width => 0.4 do
            para "Creator"
            @shy_creator = edit_line :width => 1.0
          end
          stack :margin => 10, :width => 0.5 do
            para "Launch"
            @shy_launch = list_box :height => 30
          end
        end
      end
    end

    stack :margin => 20 do
      flow :margin_top => 10, :margin_left => 310 do
        button "OK", :margin_right => 4 do
          @shy_meta = Shy.new
          @shy_meta.name = @shy_name.text
          @shy_meta.creator = @shy_creator.text
          @shy_meta.version = @shy_version.text
          @shy_meta.launch =  @shy_launch.text
          @page_shy.hide
          build_thread
        end
        button "Cancel" do
          close
        end
      end
    end
  end

  @page2 = stack :hidden => true do
    stack do
      background white
      border "#DDD", :height => 2, :bottom => 0
      stack :margin => 20 do
        para "Packaging:", :margin => 4
        @path2 = para "", :size => 20, :margin => 4
        @status = para "", :margin => 4
      end
    end

    stack :margin => 20 do
      stack :width => -20, :height => 24 do
        @prog = background "#{DIR}/static/stripe.png", :curve => 7
        background "rgb(0, 0, 0, 100)".."rgb(120, 120, 120, 0)", :curve => 6, :height => 16
        background "rgb(120, 120, 120, 0)".."rgb(0, 0, 0, 100)", :curve => 6, 
          :height => 16, :top => 8
        border "rgb(60, 60, 60, 80)", :curve => 7, :strokewidth => 2
      end
    end
  end

  @page3 = stack :hidden => true do
    stack do
      background white
      border "#DDD", :height => 2, :bottom => 0
      stack :margin => 20 do
        para "Completed:", :margin => 4
        @path3 = para "", :size => 20, :margin => 4
        para "Your files are done, you may close this window.", :margin => 4
        button "Quit" do
          exit
        end
      end
    end
  end

  start do
    @exe.checked = false
    @dmg.checked = false
    @run.checked = false
    @shy.checked = true
    #@inc.choose( ::RUBY_PLATFORM =~ /mswin|mingw/ ? Shoes::I_NET : Shoes::I_NOV )
  end
end
VERSION =
"3.0.1"
Help =
Shoes.make_help_page
RELEASES =
%w(Curious Raisins Policeman Federales Walkabout)
NotFound =
proc do
  para '404 NOT FOUND, GUYS!'
end
SHOES_CMD_OPTS =
{}
OPTS =
OptionParser.new do |opts|
  opts.banner = "Usage: shoes [options] (app.rb or app.shy)"

  opts.on("-m", "--manual",
          "Open the built-in manual.") do
    show_manual
  end

  opts.on("-w", "--console", "show terminal") do
    Shoes.terminal
  end

  #opts.on("--old-package",
  #        "(Obsolete) Package a Shoes app for Windows, OS X and Linux.") do |s|
  #  make_pack
  #end

  opts.on("-c", "--cobbler",
          "Maintain Shoes installation") do |c|
    cobbler
  end
  
  # display for -h - it's not in ARGV when used.
  opts.on("-d [shoes args]", "Debug Shoes - must be first argument")

  opts.on("-p", "--package",
          "Package Shoes App (new)") do |c|
    app_package
  end
  
  opts.on("-e", "--profile [Script]", "Profile app") do |c|
    SHOES_CMD_OPTS['profile'] = c
  end
  
  opts.on('-g', '--gem',
          'Passes commands to RubyGems.') do
    require 'shoes/setup'
    require 'rubygems/gem_runner'
    Gem::GemRunner.new.run(ARGV)
    fail SystemExit, ''
  end
  
 opts.on('-f', '--file', 'path to script [OSX packaging uses this]') do
    #puts "-f ARGV: #{ARGV}"
  end
  
  opts.on_tail('-v', '--version', 'Display the version info.') do
    fail SystemExit, "Shoes #{Shoes::VERSION_NAME} #{Shoes::VERSION_NUMBER} r#{Shoes::VERSION_REVISION} #{RUBY_PLATFORM} #{RUBY_VERSION}"
  end

  opts.on_tail('-h', '--help', 'Show this message') do
    fail SystemExit, opts.to_s
  end
end
SHOES_URL_RE =

SHOES_URL_RE = %r!^@(+)(.*)$!

%r{^@([^/]+)(.*)$}
BASIC_S =

complete list of styles

[:left, :top, :right, :bottom, :width, :height, :attach, :hidden,
:displace_left, :displace_top, :margin, :margin_left, :margin_top,
:margin_right, :margin_bottom]
TEXT_S =
[:strikecolor, :undercolor, :font, :size, :family, :weight,
:rise, :kerning, :emphasis, :strikethrough, :stretch, :underline,
:variant]
MOUSE_S =
[:click, :motion, :release, :hover, :leave]
KEY_S =
[:keydown, :keypress, :keyup]
COLOR_S =
[:stroke, :fill]

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.languageObject

Returns the value of attribute language



61
62
63
# File 'lib/shoes.rb', line 61

def language
  @language
end

.localeObject

Returns the value of attribute locale



61
62
63
# File 'lib/shoes.rb', line 61

def locale
  @locale
end

Class Method Details

.app_packageObject



185
186
187
# File 'lib/shoes.rb', line 185

def self.app_package
  require 'shoes/app_package'
end

.args!(osx_launch = nil) ⇒ Object

This is the real entry point for shows. It's called from the C startup code



268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/shoes.rb', line 268

def self.args!(osx_launch = nil)
  require_relative "shoes/deprecated"
  
  if (ARGV.empty?)
    Shoes.splash if  !osx_launch || osx_launch == '0'
    return true
  else
    OPTS.parse! ARGV 
    if SHOES_CMD_OPTS['profile']
      require 'shoes/profiler'
      Shoes.profile SHOES_CMD_OPTS['profile']
    elsif SHOES_DEBUG && ARGV[0]
      # clear ARGV so byebug/irb won't get confused
      script = ARGV.delete_at(0)
      return script
    else
      return ARGV[0] || true
    end
  end
end

.cleanObject



360
361
362
363
364
365
# File 'lib/shoes.rb', line 360

def self.clean
  if @shy
    Dir.chdir() # do it from HOME 
    FileUtils.rm_rf(@tmpdir, secure: true)
  end
end

.cobblerObject



181
182
183
# File 'lib/shoes.rb', line 181

def self.cobbler
  require 'shoes/cobbler'
end

.hookObject



32
# File 'lib/shoes.rb', line 32

def Shoes.hook; end

.image_cache_path(hash, ext) ⇒ Object



11
12
13
14
15
# File 'lib/shoes/image.rb', line 11

def self.image_cache_path hash, ext
  dir = File.join(CACHE_DIR, hash[0,2])
  Dir.mkdir(dir) unless File.exists?(dir)
  File.join(dir, hash[2..-1]) + ext.downcase
end

.image_download_sync(url, opts) ⇒ Object

Synchronous download - no threading. called from the bowels of image.c -> rbload.c -> here. Returns something that rbload.c can deal with assumes HttpResponse from download.rb has been require'd and with magic of duck typing, it looks like cResponse.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/shoes/image.rb', line 22

def self.image_download_sync url, opts
  # puts "image_download_sync called"
  #require 'open-uri'
  tmpf = File.open(opts[:save],'wb')
  result = HttpResponse.new
  begin
    uri_opts = {}
    uri_opts[:redirect_to_https] = true
    #uri_opts[:ssl_verify_mode] = OpenSSL::SSL::VERIFY_NONE
    uri_opts[:ssl_verify_mode] = OpenSSL::SSL::VERIFY_PEER
    if RUBY_PLATFORM =~ /mingw|darwin/
      $stderr.puts "fixing ssl"
      uri_opts[:ssl_ca_cert]  = File.join(DIR, "lib/shoes/cacert.pem")
    end
    open url, uri_opts do |f|
      # everything has been downloaded at this point.
      # f is a tempfile like creature
      result.status = f.status[0].to_i # 200, 404, etc
      result.body = f.read
      tmpf.write(result.body)
      result.headers = f.meta
      tmpf.close
     end
  rescue => e
    raise "Image download failed for #{url} because: #{e}"
  end
  puts "image_download_sync finished"
  return result
end

.image_temp_path(uri, uext) ⇒ Object



7
8
9
# File 'lib/shoes/image.rb', line 7

def self.image_temp_path uri, uext
  File.join(Dir::tmpdir, "#{uri.host}-#{Time.now.usec}" + uext)
end

.make_help_pageObject



451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
# File 'lib/shoes/help.rb', line 451

def Shoes.make_help_page
  font "#{DIR}/fonts/Coolvetica.ttf" unless Shoes::FONTS.include? "Coolvetica"
  proc do
    extend Shoes::Manual
    docs = load_docs Shoes::Manual.path

    style(Shoes::Image, :margin => 8, :margin_left => 100)
    style(Shoes::Code, :stroke => "#C30")
    style(Shoes::LinkHover, :stroke => green, :fill => nil)
    style(Shoes::Para, :size => 12, :stroke => "#332")
    style(Shoes::Tagline, :size => 12, :weight => "bold", :stroke => "#eee", :margin => 6)
    style(Shoes::Caption, :size => 24)
    background "#ddd".."#fff", :angle => 90
    
    [Shoes::LinkHover, Shoes::Para, Shoes::Tagline, Shoes::Caption].each do |type|
      style(type, :font => "MS UI Gothic")
    end if Shoes.language == 'ja'

    @visited = { :back => ["Hello!"], :forward => [], :clicked => false }
    click { |n|
      if 4 == n
         visit_back
      elsif 5 == n
         visit_forward
      end
    }
    keypress { |n|
      if n.eql?(:alt_left)
         visit_back
      elsif n.eql?(:alt_right)
         visit_forward
      elsif n.eql?(:alt_f)
         open_link("Search")
      elsif n.eql?(:page_down)
         app.slot.scroll_top += app.slot.height
      elsif n.eql?(:page_up)
         app.slot.scroll_top -= app.slot.height
      elsif n.eql?(:down)
         app.slot.scroll_top += 20
      elsif n.eql?(:up)
         app.slot.scroll_top -= 20
      end
    }
    
    stack do
      background black
      stack :margin_left => 118 do
        para "The Shoes Manual", :stroke => "#eee", :margin_top => 8, :margin_left => 17, 
          :margin_bottom => 0
        @title = title docs[0][0], :stroke => white, :margin => 4, :margin_left => 14,
          :margin_top => 0, :font => "Coolvetica"
      end
      background "rgb(66, 66, 66, 180)".."rgb(0, 0, 0, 0)", :height => 0.7
      background "rgb(66, 66, 66, 100)".."rgb(255, 255, 255, 0)", :height => 20, :bottom => 0
    end
    @doc =
      stack :margin_left => 130, :margin_top => 20, :margin_bottom => 50, :margin_right => 50 + gutter,
        &dewikify(docs[0][-1]['description'], true)
    add_next_link(0, -1)
    stack :top => 84, :left => 0, :attach => Shoes::Window do
      #flow :width => 94, :margin_left => 12, :margin_right => 12, :margin_top => 25 do ## fix for #100
      flow :width => 118, :margin_left => 12, :margin_right => 12, :margin_top => 25 do
         stack :width => 38 do
            background "#8A7", :margin => [0, 2, 0, 2], :curve => 4 
            para link("back", :stroke => "#eee", :underline => "none") {
               visit_back
            }, :margin => 4, :align => 'center', :weight => 'bold', :size => 9
         end
         stack :width => 54, :right => 0 do
            background "#8A7", :margin => [0, 2, 0, 2], :curve => 4 
            para link("forward", :stroke => "#eee", :underline => "none") {
               visit_forward
            }, :margin => 4, :align => 'center', :weight => 'bold', :size => 9
         end
      end
      @toc = {}
      stack :margin => 12, :width => 130, :margin_top => 20 do
        docs.each do |sect_s, sect_h|
          sect_cls = sect_h['class']
          para strong(link(sect_s, :stroke => black) { open_section(sect_s) }),
            :size => 11, :margin => 4, :margin_top => 0
          @toc[sect_cls] =
            stack :hidden => @toc.empty? ? false : true do
              links = sect_h['sections'].map do |meth_s, meth_h|
                [link(meth_s) { open_methods(meth_s) }, "\n"]
              end.flatten
              links[-1] = {:size => 9, :margin => 4, :margin_left => 10}
              para *links
            end
        end
      end
      #stack :margin => 12, :width => 94, :margin_top => 6 do ## fix for #100
      stack :margin => 12, :width => 118, :margin_top => 6 do
        background "#330", :curve => 4
        para "Not finding it? Try ", strong(link("Search", :stroke => white) { show_search }), "!", :stroke => "#ddd", :size => 9, :align => "center", :margin => 6
      end
      stack :margin => 12, :width => 118 do
        inscription "Shoes #{Shoes::RELEASE_NAME}\nRevision: #{Shoes::REVISION}",
          :size => 7, :align => "center", :stroke => "#999"
      end
    end
    image :width => 120, :height => 120, :top => -18, :left => 6 do
      #image "#{DIR}/static/shoes-icon.png", :width => 100, :height => 100, :top => 10, :left => 10 
      image "#{DIR}/static/shoes-icon.png", :width => 80, :height => 80, :top => 22, :left => 10 
     glow 2
    end
  end
rescue => e
  p e.message
  p e.class
end

def self.make_pack

  require 'shoes/packgui'
  Shoes.app(:width => 500, :height => 480, :resizable => true, &Packshow)
  require 'shoes/pack'
  Shoes.app(width: 500, height: 480, resizable: true, &PackMake)
end


206
207
# File 'lib/shoes.rb', line 206

def self.manual_link(_sect)
end

.mount(path, meth, &blk) ⇒ Object



236
237
238
239
240
241
242
# File 'lib/shoes.rb', line 236

def self.mount(path, meth, &blk)
  unless @mounts.empty?
    # checking if app changed
    @mounts.clear if meth[0] != @mounts[0][1][0]
  end
  @mounts << [path, meth || blk]
end

.package_appObject



142
143
144
145
146
147
# File 'lib/shoes.rb', line 142

def self.package_app
  require_relative 'shoes/shybuilder'
  fname = ask_open_file
  return false unless fname
  start_shy_builder fname
end

.profile(file = nil) ⇒ Object



385
386
387
388
389
390
# File 'lib/shoes/profiler.rb', line 385

def Shoes.profile(file = nil)
  $shoes_profiler = ProfilerDB.new()
  $shoes_profiler.file = file # passed on the commandline with '-e file' or nil

  Shoes.app width: 600, height: 400, resizeable: true, title: "Profiler"
end

.profilerObject

from the splash screen



194
195
196
197
# File 'lib/shoes.rb', line 194

def self.profiler
  require 'shoes/profiler'
  Shoes.profile(nil)
end

.rdbObject

remote debugger



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/shoes/remote_debugger.rb', line 2

def Shoes.rdb
  Shoes.app height: 120, title: "Remote Debug" do 
    para "In a new terminal or console, run 'byebug -R localhost:8989'\n"
    para "Then use the spash screen to load the program that has the 'byebug'"
    para "command where you want to start the debugging from. Or"
    para "otherwise cause a 'byebug' to be invoked."
    require 'byebug/core'
    bye_thr = Thread.new {
      Byebug.wait_connection = true
      Byebug.start_server('localhost', 8989)
    }
  end
end

.read_file(path) ⇒ Object



367
368
369
370
371
372
373
374
375
376
# File 'lib/shoes.rb', line 367

def self.read_file(path)
  if RUBY_VERSION =~ /^1\.9/ && !@shy
    # File.open(path, 'r:utf-8') { |f| f.read }
    IO.read(path).force_encoding('UTF-8')
  elsif RUBY_VERSION =~ /^2\.0/ && !@shy
    IO.read(path).force_encoding('UTF-8')
  else
    File.read(path)
  end
end

.remote_debugObject



221
222
223
224
# File 'lib/shoes.rb', line 221

def self.remote_debug
  require "shoes/remote_debugger.rb"
  Shoes.rdb
end

.remote_debuggerObject



189
190
191
# File 'lib/shoes.rb', line 189

def self.remote_debugger
  alert "Launching debuger is not implmented yet"
end

.run(path) ⇒ Object



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/shoes.rb', line 247

def self.run(path)
  uri = URI(path)
  @mounts.each do |mpath, rout|
    m, *args = *path.match(/^#{mpath}$/)
    if m
      rout = rout[0].instance_method(rout[1]) unless rout.is_a? Proc
      # return [rout, args]
      return [rout, args, rout.owner] # requires change in app.c
    end
  end
  case uri.path 
  when '/'
    [nil]
  when SHOES_URL_RE
    [proc { eval(URI("http://#{Regexp.last_match(1)}:53045#{Regexp.last_match(2)}").read) }]
  else
    [NotFound]
  end
end

.setup(&blk) ⇒ Object



127
128
129
130
131
132
133
134
135
# File 'lib/shoes.rb', line 127

def self.setup(&blk)
  require 'shoes/setup'
  line = caller[0]
  return if @setups[line]
  script = line[/^(.+?):/, 1]
  set = Shoes::Setup.new(script, &blk)
  @setups[line] = true
  fail SettingUp unless set.no_steps?
end

.shoes_irbObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/shoes/shoes_irb.rb', line 97

def Shoes.shoes_irb
   Shoes.app do
     irbalike = MimickIRB.new
     @history = { :cmd => irbalike.history, :pointer => 0 }
     @str, @cmd = [CURSOR + " "], ""
     stack :width => 1.0, :height => 1.0 do
       background "#555"
       stack :width => 1.0, :height => 30 do
         background white
         para "Interactive Ruby ready.", :stroke => red
       end
       @scroll =
         stack :width => 1.0, :height => -50, :scroll => true do
           background "#555"
           @console = para @str, :font => "Monospace 12px", :stroke => "#dfa", :wrap => "char"
           @console.cursor = -1
         end
     end
     keypress do |k|
       case k
       when "\n"
         begin
           @history[:cmd] << @cmd
           @history[:pointer] = @history[:cmd].size
           out, obj = irbalike.run(@cmd)
           @str += ["#@cmd\n",
             irbalike.echo ? 
               span("#{out}=> #{obj.inspect}\n", :stroke => "#fda") :
               span("#{out}", :stroke => "#fda"),
             "#{CURSOR} "]
           @cmd = ""
           @console.cursor = -1
         rescue MimickIRB::Empty
         rescue MimickIRB::Continue
           @str += ["#@cmd\n.. "]
           @cmd = ""
         rescue Object => e
           @str += ["#@cmd\n", span("#{e.class}: #{e.message}\n", :stroke => "#fcf"),
             "#{CURSOR} "]
           @cmd = ""
         end
       when String
         @cmd.insert(@console.cursor, k)
       when :backspace
         @cmd.slice!(@console.cursor)
       when :delete
         @cmd.slice!(@console.cursor += 1) if @console.cursor < -1
       when :tab
         @cmd += "  "
       when :alt_q
         quit
       when :alt_c
         self.clipboard = @cmd
       when :alt_v
         @cmd += self.clipboard
       when :left
         @console.cursor -= 1 unless @cmd.length < -@console.cursor
       when :right
         @console.cursor += 1 if @console.cursor < -1
       when :up
         if @history[:pointer] > 0
            @history[:pointer] -= 1
            @cmd = @history[:cmd][@history[:pointer]].dup
         end
       when :down
         if @history[:pointer] < @history[:cmd].size
            @history[:pointer] += 1
            @cmd = @history[:cmd][@history[:pointer]].dup
         end
       end
       @console.replace *(@str + [@cmd])
       @scroll.scroll_top = @scroll.scroll_max
     end
   end
end

.show_irbObject

called with alt-= keystroke.



216
217
218
219
# File 'lib/shoes.rb', line 216

def self.show_irb
  require "shoes/shoes_irb.rb"
  Shoes.shoes_irb
end

.show_logObject



226
227
228
229
230
231
232
233
234
# File 'lib/shoes.rb', line 226

def self.show_log
  require 'shoes/log'
  return if @log_app && Shoes.APPS.include?(@log_app)
  @log_app =
    Shoes.app do
      extend Shoes::LogWindow
      setup
    end
end

.show_manualObject



209
210
211
212
213
# File 'lib/shoes.rb', line 209

def self.show_manual
  require 'shoes/search'
  require 'shoes/help'
  Shoes.app(width: 720, height: 640, &Shoes::Help)
end

.show_selector(debug = false) ⇒ Object



137
138
139
140
# File 'lib/shoes.rb', line 137

def self.show_selector (debug = false)
  fname = ask_open_file
  Shoes.visit(fname, debug) if fname
end

.splashObject



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/shoes.rb', line 149

def self.splash
  font "#{DIR}/fonts/Lacuna.ttf" unless Shoes::FONTS.include? "Lacuna"
  Shoes.app width: 598, height: 520, resizable: false do
    background "#{DIR}/static/splash.png"
    style(Para, align: 'center', weight: 'bold', font: 'Lacuna Regular', size: 13)
    style(Link, stroke: khaki, underline: nil)
    style(LinkHover, stroke: yellow, fill: nil)

    require 'shoes/search'
    require 'shoes/help'

    stack margin: 18 do
      para 'Welcome to', stroke: ivory, size: 18, margin: 0
      para 'SHOES', size: 24, stroke: ivory, margin: 0
      para Shoes::VERSION_NAME, stroke: ivory, size: 14, margin: 0, weight: 'bold'
      para "build #{Shoes::VERSION_NUMBER} r#{Shoes::VERSION_REVISION}", size: 14, stroke: ivory, margin_top: 0
      stack do
        background black(0.3), :curve => 8
        para link(strong("Run an App")) { Shoes.show_selector and close }, :margin => 10, :margin_bottom => 4
        para link(strong("Read the Manual")) { Shoes.show_manual and close }, :margin => 10, :margin_bottom => 4
        para link(strong("Maintain Shoes")) {Shoes.cobbler and close}, :margin => 10, :margin_bottom => 4
        #para link(strong("Debug an App (remote)")) {Shoes.remote_debug and close}, :margin => 10, :margin_bottom => 4
        #para link(strong("Profile an App")) {Shoes.profiler and close}, :margin => 10, :margin_bottom => 4
        para link(strong("Bundle an App (shy)")) { Shoes.package_app and close }, :margin => 10, :margin_bottom => 4
        para link(strong("Package an App with Shoes")) {Shoes.app_package and close }, :margin => 10, :margin_bottom => 4
        #para link("Obsolete: Package") { Shoes.make_pack and close }, :margin => 10, :margin_bottom => 4
      end
      para 'Alt-Slash opens the console', stroke: '#00', align: 'center'
    end
  end
end

.start_shy_builder(launch_script) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/shoes/shybuilder.rb', line 7

def self.start_shy_builder(launch_script)
  launch_script = File.expand_path(launch_script)
  top_dir = File.dirname(launch_script)
  launch_script = File.basename(launch_script)
  shy_name = "#{top_dir}.shy" 
  Shoes.app do
    background white
    stack do
      para "Almost ready to make #{shy_name}"
      fields = {}
      for label, name in [["Project Name", "name"],
                          ["Version", "version"],
                          ["Your Name", "creator"]]
        flow :width => 1.0 do
          para "#{label}: "
          fields[name] = edit_line ''
        end
      end
      button "Build .shy" do
        shy_desc = Shy.new
        for name in fields.keys
          shy_desc.send("#{name}=".intern, fields[name].text)
        end
        shy_desc.launch = launch_script
        Shy.c(shy_name, shy_desc, top_dir)
        clear
        background white
        stack do
          para "Built #{shy_name}"
          button "Ok" do
            close
          end
        end
      end
    end
  end
end

.uri(str) ⇒ Object



289
290
291
292
293
294
295
# File 'lib/shoes.rb', line 289

def self.uri(str)
  if str =~ SHOES_URL_RE
    URI("http://#{Regexp.last_match(1)}:53045#{Regexp.last_match(2)}")
  else
    URI(str) rescue nil
  end
end

.url(path, meth) ⇒ Object



378
379
380
# File 'lib/shoes.rb', line 378

def self.url(path, meth)
  Shoes.mount(path, [self, meth])
end

.visit(path, debug = false) ⇒ Object



297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/shoes.rb', line 297

def self.visit(path, debug=false)
  uri = Shoes.uri(path)
  case uri
  when URI::HTTP
    str = uri.read
    if str !~ /Shoes\.app/
      Shoes.app do
        eval(uri.read)
      end
    else
      eval(uri.read)
    end
  else
    path = File.expand_path(path.gsub(/\\/, '/'))
    if path =~ /\.shy$/
      @shy = true
      require 'shoes/shy'
      base = File.basename(path, '.shy')
      #@tmpdir = tmpdir = '%s/shoes-%s.%d' % [Dir.tmpdir, base, $PROCESS_ID]
      @tmpdir = tmpdir = "%s/shoes-%s.%d" % [Dir.tmpdir, base, $$]
      shy = Shy.x(path, tmpdir)
      Dir.chdir(tmpdir)
      # Shoes.debug "Loaded SHY: #{shy.name} #{shy.version} by #{shy.creator}"
      path = shy.launch
    else
      @shy = false
      Dir.chdir(File.dirname(path))
      path = File.basename(path)
    end
    if debug
      require 'byebug'
      require 'byebug/runner'
      puts "debugging script  #{path}"
      # Danger Ahead! At this point in Shoes startup, we haven't really
      # initialized the complete GUI. On Linux, there's only one thread
      # (for ruby). None of the three methods work!
      #thr_list = Thread.list
      #thr_list.each {|t| puts t.inspect }
      #  Method 1
      ARGV.unshift(path)
      ARGV.unshift('-shoes-debug')
      ARGV.unshift(path)
      puts "before #{ARGV}"
      Byebug::Runner.new.run
      #  Method 2
      #code = "ARGV.unshift(\"#{path}\"); Byebug::Runner.new.run"
      #puts code
      #eval(code, TOPLEVEL_BINDING)
      #  Method 3 (older times)
      #$PROGRAM_NAME = path
      #Byebug.debug_load($PROGRAM_NAME, true) # this starts byebug loop
    else
      $0.replace path
      code = read_file(path)
      eval(code, TOPLEVEL_BINDING, path)
    end
  end
rescue SettingUp
rescue Object => e
  error(e)
  show_log
end