1#!/usr/bin/env ruby
2require "tk"
3
4root = TkFrame.new
5top = TkFrame.new(root) {
6  relief 'raised'
7  border 1
8}
9msg = TkMessage.new(top) {
10  text "File main.c hasn't been saved to disk since \
11it was last modified.  What should I do?"
12  justify 'center'
13  aspect 200
14  font '-Adobe-helvetica-medium-r-normal--*-240*'
15  pack('padx'=>5, 'pady'=>5, 'expand'=>'yes')
16}
17top.pack('fill'=>'both')
18root.pack
19
20bot = TkFrame.new(root) {
21  relief 'raised'
22  border 1
23}
24
25TkFrame.new(bot) { |left|
26  relief 'sunken'
27  border 1
28  pack('side'=>'left', 'expand'=>'yes', 'padx'=>10, 'pady'=> 10)
29  TkButton.new(left) {
30    text "Save File"
31    command "quit 'save'"
32    pack('expand'=>'yes','padx'=>6,'pady'=> 6)
33    top.bind "Enter", proc{state 'active'}
34    msg.bind "Enter", proc{state 'active'}
35    bot.bind "Enter", proc{state 'active'}
36    top.bind "Leave", proc{state 'normal'}
37    msg.bind "Leave", proc{state 'normal'}
38    bot.bind "Leave", proc{state 'normal'}
39    Tk.root.bind "ButtonRelease-1", proc{quit 'save'}
40    Tk.root.bind "Return", proc{quit 'save'}
41  }
42}
43TkButton.new(bot) {
44  text "Quit Anyway"
45  command "quit 'quit'"
46  pack('side'=>'left', 'expand'=>'yes', 'padx'=>10)
47}
48TkButton.new(bot) {
49  text "Return To Editor"
50  command "quit 'return'"
51  pack('side'=>'left', 'expand'=>'yes', 'padx'=>10)
52}
53bot.pack
54root.pack('side'=>'top', 'fill'=>'both', 'expand'=>'yes')
55
56def quit(button)
57  print "You pressed the \"#{button}\" button;  bye-bye!\n"
58  exit
59end
60
61Tk.mainloop
62