1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/ext/tk/lib/tkextlib/itcl/incr_tcl.rb
nagai ed6ce8b43b * ext/tk/extconf.rb: New strategy for searching Tcl/Tk libraries.
* ext/tk/*: Support new features of Tcl/Tk8.6b1 and minor bug fixes.
     ( [KNOWN BUG] Ruby/Tk on Ruby 1.9 will not work on Cygwin. )
* ext/tk/*: Unify sources between Ruby 1.8 & 1.9.
            Improve default_widget_set handling.
* ext/tk/*: Multi-TkInterpreter (multi-tk.rb) works on Ruby 1.8 & 1.9.
     ( [KNOWN BUG] On Ruby 1.8, join to a long term Thread on Tk
       callbacks may freeze. On Ruby 1.9, cannot create a second 
       master interpreter (creating slaves are OK); supported master
       interpreter is the default master interpreter only. )
* ext/tk/lib/tkextlib/*: Update supported versions of Tk extensions.
         Tcllib 1.8/Tklib 0.4.1  ==>  Tcllib 1.11.1/Tklib 0.5
         BWidgets 1.7            ==>  BWidgets 1.8
         TkTable 2.9             ==>  TkTable 2.10
         TkTreeCtrl 2005-12-02   ==>  TkTreeCtrl 2.2.9
         Tile 0.8.0/8.5.1        ==>  Tile 0.8.3/8.6b1
         IncrTcl 2005-02-14      ==>  IncrTcl 2008-12-15
         TclX 2005-02-07         ==>  TclX 2008-12-15
         Trofs 0.4.3             ==>  Trofs 0.4.4


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24063 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-07-12 23:08:32 +00:00

178 lines
4.3 KiB
Ruby

#
# tkextlib/itk/incr_tcl.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
# call setup script
require 'tkextlib/itcl.rb'
# TkPackage.require('Itcl', '3.2')
TkPackage.require('Itcl')
module Tk
module Itcl
include Tk
extend Tk
LIBRARY = TkVarAccess.new('::itcl::library')
PURIST = TkVarAccess.new('::itcl::purist')
VERSION = TkCore::INTERP._invoke("set", "::itcl::version").freeze
PATCHLEVEL = TkCore::INTERP._invoke("set", "::itcl::patchLevel").freeze
PACKAGE_NAME = 'Itcl'.freeze
def self.package_name
PACKAGE_NAME
end
def self.package_version
begin
TkPackage.require('Itcl')
rescue
''
end
end
##############################################
class ItclObject < TkObject
ITCL_CLASSNAME = ''.freeze
(ITCL_OBJ_ID = ['itclobj'.freeze, TkUtil.untrust('00000')]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
ITCL_OBJ_TBL = TkUtil.untrust({})
def initialize(*args)
if (@klass = self.class::ITCL_CLASSNAME).empty?
fail RuntimeError, 'unknown itcl class (abstract class?)'
end
Tk::Itcl::ItclObject::ITCL_OBJ_ID.mutex.synchronize{
@id = Tk::Itcl::ItclObject::TCL_OBJ_ID.join(TkCore::INTERP._ip_id_)
Tk::Itcl::ItclObject::ITCL_OBJ_ID[1].succ!
}
@path = @id
end
def self.call_proc(name, *args)
tk_call("#{ITCL_CLASSNAME}::#{cmd}", *args)
end
def call_method(name, *args)
tk_call(@path, name, *args)
end
def isa(klass)
bool(tk_call(@path, 'isa', klass))
end
alias itcl_kind_of? isa
def info_class
tk_call(@path, 'info', 'class')
end
def info_inherit
simplelist(tk_call(@path, 'info', 'inherit'))
end
def info_heritage
list(tk_call(@path, 'info', 'heritage'))
end
def info_function(*args)
if args[-1].kind_of?(Array)
params = args.pop
params.each{|param|
param = param.to_s
args << ( (param[0] == ?-)? param: "-#{param}" )
}
end
list(tk_call(@path, 'info', 'function', *args))
end
def info_variable(*args)
if args[-1].kind_of?(Array)
params = args.pop
params.each{|param|
param = param.to_s
args << ( (param[0] == ?-)? param: "-#{param}" )
}
end
list(tk_call(@path, 'info', 'variable', *args))
end
end
##############################################
def self.body(klass, func, args, body)
tk_call('::itcl::body', "#{klass}::#{func}", args, body)
end
def self.code(cmd, *args)
tk_call('::itcl::code', cmd, *args)
end
def self.code_in_namespace(namespace, cmd, *args)
tk_call('::itcl::code', '-namespace', namespace, cmd, *args)
end
def self.configbody(klass, var, body)
tk_call('::itcl::configbody', "#{klass}::#{var}", body)
end
def self.create_itcl_class(name, body)
TkCore::INTERP._invoke('::itcl::class', name, body)
klass = Class.new(Tk::Itcl::ItclObject)
klass.const_set('ITCL_CLASSNAME', name.dup.freeze)
klass
end
def self.delete_itcl_class(*names)
tk_call('::itcl::delete', 'class', *names)
end
def self.delete_itcl_object(*names)
tk_call('::itcl::delete', 'object', *names)
end
def self.delete_namespace(*names)
tk_call('::itcl::delete', 'namespace', *names)
end
def self.ensemble(name, *args)
tk_call('::itcl::ensemble', name, *args)
end
def self.find_classes(pat=None)
simplelist(tk_call('::itcl::find', 'classes', pat))
end
def self.find_objects(*args)
simplelist(tk_call('::itcl::find', 'objects', *args))
end
def self.is_itcl_class(target)
bool(tk_call('::itcl::is', 'class', target))
end
def self.is_itcl_object(target)
bool(tk_call('::itcl::is', 'object', target))
end
def self.create_local_obj(klass, name, *args)
tk_call('::itcl::local', klass, name, *args)
end
def self.is_itcl_instance(klass, target)
bool(tk_call('::itcl::is', 'object', '-class', klass, target))
end
def self.scope(var)
tk_call('::itcl::scope', var)
end
end
end