Tutorial Ruby Bagian 4

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

TUTORIAL RUBY DENGAN GUI SHOES

Oleh: SLAMET NURHADI

TEKNIK INFORMATIKA
UNIVERSITAS NASIONAL
Image

Shoes.app :title =>"Sample calc", :resizable =>


false, :width => 460, :height => 520 do
image 'd:/ruby.png'

end

Simple calc

Shoes.app :title =>"Sample calc", :resizable =>


false, :height => 250, :width => 200, :resizable =>
false do
def do_calc
@number = @previous.send(@op, @number) if @op
@op = nil
end

@previous, @number, @op = 0, 0, nil

background "#33ffff".."#333399", :curve => 5, :margin


=> 2

stack :margin => 2 do


stack :margin => 8 do
@number_field = para strong(@number)
end

flow :width => 218, :margin => 4 do


%w(7 8 9 / 4 5 6 * 1 2 3 - 0 Clr = +).each do |
btn|
button btn, :width => 46, :height => 46 do
case btn
when /[0-9]/
@number = @number.to_i * 10 + btn.to_i
when 'Clr'
@previous, @number, @op = 0, 0, nil
when '='
do_calc
else
do_calc
@previous, @number = @number, nil
@op = btn
end
@number_field.replace strong @number
end
end
end
end
end
Shoes.app :title =>"editbox", :resizable => false,
:width => 250, :height => 300 do

background "#666666".."#000000"

stack do
@msg = para 'Hello', :stroke =>white
@el = edit_line "We love Ruby."
button('ok'){ @msg.text = @el.text}
@eb = edit_box "We love Shoes."
button('ok'){ @msg.text = @eb.text}
end
end

Shoes.app :title =>"listbox", :resizable => false,


:width => 450, :height => 60 do

background "#666666".."#000000"
para "Pilih jurusan\n", :stroke =>white
button('OK'){@msg.text = @e.text}
@e = list_box :items => ['Teknik Informatika',
'Telekomunikasi', 'Sistem Informasi', 'Manajemen
Informatika'], :height => 30
@msg = para '', :stroke =>white

End

Shoes.app :title =>"animasi", :resizable => false,


:width => 300, :height => 300 do

background "#666666".."#000000"

def swap s1, s2


tmp = s2.style.to_a
s1.style.to_a.each{|k, v| s2.style k => v}
tmp.each{|k, v| s1.style k => v}
end

nostroke
r1 = rect 50, 50, 100, 100, :fill => mediumslateblue
r2 = rect 100, 100, 100, 100, :fill => sandybrown
r3 = rect 150, 150, 100, 100, :fill => orchid

button('swap 1-2'){swap r1, r2}


button('swap 2-3'){swap r2, r3}
button('swap 1-3'){swap r1, r3}
end
Shoes.app :width => 240, :height => 161, :resizable =>
false do
background "#666666".."#000000"
flow :width => 100, :height => 150, :left => 2, :top
=> 2, :scroll => true do
background bisque
30.times do |i|
color = COLORS.keys.map{|sym|
sym.to_s}.sort_by{rand}
para "colorful jellybeans", :stroke =>
send(color.first)
end
end
end
filename =ask_open_file
Shoes.app :title => "Open ", :width =>300, :height => 70
do
para File.read(filename)

end
Shoes.app :title => "Open ", :width =>300, :height => 70
do
button "Open File" do
filename =ask_open_file
para File.read(filename)
end
end

Shoes.app :title => "Open ", :width =>300, :height => 70


do
background "#666666".."#000000"
button "Open Folder" do
filename =ask_open_folder
para File.read(folder)
end
end
Shoes.app :title => "Save ", :width =>300, :height => 70
do
background "#FFCC00".."#000000"
button "save Folder" do
filename =ask_save_folder
para File.read(folder)
end
end

You might also like