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
78
79
80
81
82
83
84
|
#
# tkextlib/ICONS/icons.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
# call setup script for general 'tkextlib' libraries
require 'tkextlib/setup.rb'
# call setup script
require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb')
# TkPackage.require('icons', '1.0')
TkPackage.require('icons')
module Tk
class ICONS < TkImage
def self.create(*args) # icon, icon, ..., keys
if args[-1].kind_of?(Hash)
keys = args.pop
icons = simplelist(tk_call('::icons::icons', 'create',
*(hash_kv(keys).concat(args.flatten))))
else
icons = simplelist(tk_call('::icons::icons', 'create',
*(args.flatten)))
end
icons.collect{|icon| self.new(icon, :without_creating=>true)}
end
def self.delete(*icons)
return if icons.empty?
tk_call('::icons::icons', 'delete', icons)
end
def self.query(*args)
if args[-1].kind_of?(Hash)
keys = args.pop
list(tk_call('::icons::icons', 'query',
*(hash_kv(keys).concat(args.flatten))))
else
list(tk_call('::icons::icons', 'query', *(args.flatten)))
end
end
##########################################
def self.new(name, keys=nil)
Tk_IMGTBL["::icon::#{name}"] || super
end
def initialize(name, keys=nil)
if name.kind_of?(String) && name =~ /^::icon::(.+)$/
@name = $1
@path = name
else
@name = name.to_s
@path = "::icon::#{@name}"
end
keys = _symbolkey2str(keys)
unless keys.delete('without_creating')
tk_call('::icons::icons', 'create', *(hash_kv(keys) << @name))
end
Tk_IMGTBL[@path] = self
end
def name
@name
end
def delete
Tk_IMGTBL.delete(@path)
tk_call('::icons::icons', 'delete', @name)
self
end
def query(keys)
list(simplelist(tk_call('::icons::icons', 'query',
*(hash_kv(keys) << @name))
)[0])
end
end
end
|