File: tkdialog.rb

package info (click to toggle)
ruby 1.4.3-6
  • links: PTS
  • area: main
  • in suites: potato
  • size: 4,068 kB
  • ctags: 7,509
  • sloc: ansic: 60,668; ruby: 23,106; yacc: 4,122; sh: 1,753; lisp: 997; makefile: 597; sed: 68; awk: 36; tcl: 31; perl: 17; python: 6
file content (62 lines) | stat: -rw-r--r-- 1,491 bytes parent folder | download
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
#! /usr/local/bin/ruby
require "tk"

root = TkFrame.new
top = TkFrame.new(root) {
  relief 'raised'
  border 1
}
msg = TkMessage.new(top) {
  text "File main.c hasn't been saved to disk since \
it was last modified.  What should I do?" 
  justify 'center'
  aspect 200
  font '-Adobe-helvetica-medium-r-normal--*-240*'
  pack('padx'=>5, 'pady'=>5, 'expand'=>'yes')
}
top.pack('fill'=>'both')
root.pack

bot = TkFrame.new(root) {
  relief 'raised'
  border 1
}

TkFrame.new(bot) { |left|
  relief 'sunken'
  border 1
  pack('side'=>'left', 'expand'=>'yes', 'padx'=>10, 'pady'=> 10)
  TkButton.new(left) {
    text "Save File"
    command "quit 'save'"
    pack('expand'=>'yes','padx'=>6,'pady'=> 6)
    top.bind "Enter", proc{state 'active'}
    msg.bind "Enter", proc{state 'active'}
    bot.bind "Enter", proc{state 'active'}
    top.bind "Leave", proc{state 'normal'}
    msg.bind "Leave", proc{state 'normal'}
    bot.bind "Leave", proc{state 'normal'}
    Tk.root.bind "ButtonRelease-1", proc{quit 'save'}
    Tk.root.bind "Return", proc{quit 'save'}
  }
}
TkButton.new(bot) {
  text "Quit Anyway"
  command "quit 'quit'"
  pack('side'=>'left', 'expand'=>'yes', 'padx'=>10)
}
TkButton.new(bot) {
  text "Return To Editor"
  command "quit 'return'"
  pack('side'=>'left', 'expand'=>'yes', 'padx'=>10)
}
bot.pack
root.pack('side'=>'top', 'fill'=>'both', 'expand'=>'yes')

def quit(button)
  print "aaa\n"
  print "You pressed the \"#{button}\" button;  bye-bye!\n"
  exit
end

Tk.mainloop