1 #
2 # tk/palette.rb : methods for Tcl/Tk standard library 'palette.tcl'
3 # 1998/06/21 by Hidetoshi Nagai <nagai@ai.kyutech.ac.jp>
4 #
5 require 'tk'
6
7 module TkPalette
8 include Tk
9 extend Tk
10
11 TkCommandNames = [
12 'tk_setPalette'.freeze,
13 'tk_bisque'.freeze,
14 'tkDarken'.freeze
15 ].freeze
16
17 def TkPalette.set(*args)
18 args = args[0].to_a.flatten if args[0].kind_of? Hash
19 tk_call('tk_setPalette', *args)
20 end
21 def TkPalette.setPalette(*args)
22 TkPalette.set(*args)
23 end
24
25 def TkPalette.bisque
26 tk_call('tk_bisque')
27 end
28
29 def TkPalette.darken(color, percent)
30 tk_call('tkDarken', color, percent)
31 end
32
33 def TkPalette.recolorTree(win, colors)
34 if not colors.kind_of?(Hash)
35 fail "2nd arg need to be Hash"
36 end
37
38 tk_call('global', "tkPalette")
39 colors.each{|key, value|
40 begin
41 if win.cget(key) == tk_call('set', "tkPalette(#{key})")
42 win[key] = colors[key]
43 end
44 rescue
45 # ignore
46 end
47 }
48
49 TkWinfo.children(win).each{|w| TkPalette.recolorTree(w, colors)}
50 end
51
52 def recolorTree(colors)
53 TkPalette.recolorTree(self, colors)
54 end
55 end