summaryrefslogtreecommitdiffstats
path: root/ext/tk/lib/tkextlib/ICONS
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-01 09:38:48 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-01 09:38:48 +0000
commitac8a1c931f18b7874453ea0db28c7c4e648371c2 (patch)
tree02232516faf0e1959ecb5d5b7aca25a52f9f87ca /ext/tk/lib/tkextlib/ICONS
parent6d1996039d9a66c604d363444799449f12c76d2b (diff)
* ext/tk/lib/tcltklib : bug fix
* ext/tk/lib/tk : bug fix and add Tcl/Tk extension support libraries git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@6559 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib/tkextlib/ICONS')
-rw-r--r--ext/tk/lib/tkextlib/ICONS/icons.rb84
-rw-r--r--ext/tk/lib/tkextlib/ICONS/setup.rb8
2 files changed, 92 insertions, 0 deletions
diff --git a/ext/tk/lib/tkextlib/ICONS/icons.rb b/ext/tk/lib/tkextlib/ICONS/icons.rb
new file mode 100644
index 000000000..fe8351fa5
--- /dev/null
+++ b/ext/tk/lib/tkextlib/ICONS/icons.rb
@@ -0,0 +1,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
diff --git a/ext/tk/lib/tkextlib/ICONS/setup.rb b/ext/tk/lib/tkextlib/ICONS/setup.rb
new file mode 100644
index 000000000..ce0f0bd4d
--- /dev/null
+++ b/ext/tk/lib/tkextlib/ICONS/setup.rb
@@ -0,0 +1,8 @@
+#
+# setup.rb -- setup script before calling TkPackage.require()
+#
+# If you need some setup operations (for example, add a library path
+# to the library search path) before using Tcl/Tk library packages
+# wrapped by Ruby scripts in this directory, please write the setup
+# operations in this file.
+#