Sha256: 21b87d386201ae93b9c34c2d626c28c103f5c1d44154e120670270d2b08ec2dc

Contents?: true

Size: 1.62 KB

Versions: 40

Compression:

Stored size: 1.62 KB

Contents

#
# This is a FOX version of Thomas and Hunt's timeless classic,
# the Pig It! example (from the "Ruby/Tk" chapter of "Programming
# Ruby".
#

require 'fox16'

include Fox

class PigBox < FXMainWindow
  def pig(word)
    leadingCap = word =~ /^A-Z/
    word.downcase!
    res = case word
      when /^aeiouy/
        word+"way"
      when /^([^aeiouy]+)(.*)/
        $2+$1+"ay"
      else
        word
    end
    leadingCap ? res.capitalize : res
  end

  def showPig
    @text.value = @text.value.split.collect{|w| pig(w)}.join(" ")
  end

  def initialize(app)
    # Initialize base class
    super(app, "Pig")
    
    @text = FXDataTarget.new("")
    
    top = FXVerticalFrame.new(self, LAYOUT_FILL_X|LAYOUT_FILL_Y) do |theFrame|
      theFrame.padLeft = 10
      theFrame.padRight = 10
      theFrame.padBottom = 10
      theFrame.padTop = 10
      theFrame.vSpacing = 20
    end
    
    p = proc { showPig }
    
    FXLabel.new(top, 'Enter Text:') do |theLabel|
      theLabel.layoutHints = LAYOUT_FILL_X
    end
    
    FXTextField.new(top, 20, @text, FXDataTarget::ID_VALUE) do |theTextField|
      theTextField.layoutHints = LAYOUT_FILL_X
      theTextField.setFocus()
    end
    
    FXButton.new(top, 'Pig It') do |pigButton|
      pigButton.connect(SEL_COMMAND, p)
      pigButton.layoutHints = LAYOUT_CENTER_X
    end
    
    FXButton.new(top, 'Exit') do |exitButton|
      exitButton.connect(SEL_COMMAND) { exit }
      exitButton.layoutHints = LAYOUT_CENTER_X
    end
  end
  
  def create
    super
    show(PLACEMENT_SCREEN)
  end
end

if __FILE__ == $0
  app = FXApp.new("Pig It", "FXRuby")
  PigBox.new(app)
  app.create
  app.run
end

Version data entries

40 entries across 40 versions & 2 rubygems

Version Path
fxruby-1.6.22.pre2-x86-mingw32 examples/pig.rb
fxruby-1.6.22.pre2 examples/pig.rb
fxrubi-1.6.22.pre1-x86-mingw32 examples/pig.rb
fxrubi-1.6.22.pre1 examples/pig.rb
fxruby-1.6.20-x86-mingw32 examples/pig.rb
fxruby-1.6.20-x86-linux examples/pig.rb
fxruby-1.6.20 examples/pig.rb
fxruby-1.6.20-universal-darwin-10 examples/pig.rb
fxruby-1.6.19-x86-mingw32 examples/pig.rb
fxruby-1.6.14-mswin32 examples/pig.rb
fxruby-1.6.13-mswin32 examples/pig.rb
fxruby-1.6.0 examples/pig.rb
fxruby-1.6.1 examples/pig.rb
fxruby-1.6.11 examples/pig.rb
fxruby-1.6.10 examples/pig.rb
fxruby-1.6.12 examples/pig.rb
fxruby-1.6.13 examples/pig.rb
fxruby-1.6.14-universal-darwin-9 examples/pig.rb
fxruby-1.6.15-universal-darwin-9 examples/pig.rb
fxruby-1.6.14 examples/pig.rb