Newer
Older
1
2
3
4
5
6
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#
# 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