2004-07-08 12:50:07 -04:00
|
|
|
#
|
|
|
|
# tkextlib/itk/incr_tk.rb
|
|
|
|
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
|
|
|
|
#
|
|
|
|
|
|
|
|
require 'tk'
|
|
|
|
require 'tk/menuspec'
|
|
|
|
require 'tkextlib/itcl.rb'
|
|
|
|
|
|
|
|
# call setup script
|
|
|
|
require 'tkextlib/itk.rb'
|
|
|
|
|
|
|
|
#TkPackage.require('Itk', '3.2')
|
|
|
|
TkPackage.require('Itk')
|
|
|
|
|
|
|
|
module Tk
|
|
|
|
module Itk
|
|
|
|
include Tk
|
|
|
|
extend Tk
|
|
|
|
|
|
|
|
LIBRARY = TkVarAccess.new('::itk::library')
|
|
|
|
|
|
|
|
def self.package_version
|
|
|
|
begin
|
2004-10-11 00:51:21 -04:00
|
|
|
TkPackage.require('Itk')
|
2004-07-08 12:50:07 -04:00
|
|
|
rescue
|
2004-10-11 00:51:21 -04:00
|
|
|
''
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.usual(arg, *args)
|
|
|
|
tk_call('::itk::usual', arg, *args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.usual_names
|
|
|
|
list(tk_call('::itk::usual'))
|
|
|
|
end
|
|
|
|
|
|
|
|
############################
|
|
|
|
|
|
|
|
class Archetype < TkWindow
|
|
|
|
TkCommandNames = [].freeze
|
|
|
|
# WidgetClassName = 'Archetype'.freeze
|
|
|
|
# WidgetClassNames[WidgetClassName] = self
|
|
|
|
|
|
|
|
def self.to_eval
|
2004-10-11 00:51:21 -04:00
|
|
|
'::itk::' << self::WidgetClassName
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
2004-07-14 21:18:57 -04:00
|
|
|
def __destroy_hook__
|
2004-10-11 00:51:21 -04:00
|
|
|
Tk::Itk::Component::ComponentID_TBL.delete(self.path)
|
2004-07-14 21:18:57 -04:00
|
|
|
end
|
|
|
|
|
2004-07-08 12:50:07 -04:00
|
|
|
#### [incr Tk] public methods
|
|
|
|
def component
|
2004-10-11 00:51:21 -04:00
|
|
|
simplelist(tk_send('component'))
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def component_path(name)
|
2004-10-11 00:51:21 -04:00
|
|
|
window(tk_send('component', name))
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
2004-07-09 15:29:29 -04:00
|
|
|
alias component_widget component_path
|
2004-07-08 12:50:07 -04:00
|
|
|
|
|
|
|
def component_invoke(name, cmd, *args)
|
2004-10-11 00:51:21 -04:00
|
|
|
window(tk_send('component', name, cmd, *args))
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def component_obj(*names)
|
2004-10-11 00:51:21 -04:00
|
|
|
names = component if names.empty?
|
|
|
|
names.collect{|name| Tk::Itk::Component.new(self.path, name) }
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
#### [incr Tk] protected methods
|
|
|
|
=begin
|
|
|
|
def itk_component_add(visibility, name, create_cmds, option_cmds=None)
|
2004-10-11 00:51:21 -04:00
|
|
|
args = []
|
|
|
|
visibility.each{|v| v = v.to_s; args << ( (v[0] == ?-)? v: "-#{v}" )}
|
|
|
|
args << '--' << name << create_cmd << option_cmds
|
|
|
|
tk_call('itk_component', 'add', *args)
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def itk_component_delete(*names)
|
2004-10-11 00:51:21 -04:00
|
|
|
tk_call('itk_component', 'delete', *names)
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def itk_initialize(keys={})
|
2004-10-11 00:51:21 -04:00
|
|
|
tk_call('itk_initialize', keys)
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def itk_option_add(*args)
|
2004-10-11 00:51:21 -04:00
|
|
|
tk_call('itk_option', 'add', *args)
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def itk_option_define(name, resource, klass, init, config=None)
|
2004-10-11 00:51:21 -04:00
|
|
|
tk_call('itk_option', 'define', name, resource, klass, init, config)
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def itk_option_remove(*args)
|
2004-10-11 00:51:21 -04:00
|
|
|
tk_call('itk_option', 'remove', *args)
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
=end
|
|
|
|
end
|
|
|
|
|
|
|
|
############################
|
|
|
|
|
|
|
|
class Toplevel < Archetype
|
|
|
|
TkCommandNames = ['::itk::Toplevel'].freeze
|
|
|
|
WidgetClassName = 'Toplevel'.freeze
|
|
|
|
WidgetClassNames[WidgetClassName] = self
|
|
|
|
|
|
|
|
include Wm
|
|
|
|
include TkMenuSpec
|
|
|
|
end
|
|
|
|
|
|
|
|
############################
|
|
|
|
|
|
|
|
class Widget < Archetype
|
|
|
|
TkCommandNames = ['::itk::Widget'].freeze
|
|
|
|
WidgetClassName = 'Widget'.freeze
|
|
|
|
WidgetClassNames[WidgetClassName] = self
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
############################
|
|
|
|
|
|
|
|
class Component < TkObject
|
|
|
|
def __cget_cmd
|
2004-10-11 00:51:21 -04:00
|
|
|
[self.master, 'component', self.name, 'cget']
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
2004-11-03 03:09:55 -05:00
|
|
|
private :__cget_cmd
|
2004-07-08 12:50:07 -04:00
|
|
|
|
|
|
|
def __config_cmd
|
2004-10-11 00:51:21 -04:00
|
|
|
[self.master, 'component', self.name, 'configure']
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
2004-11-03 03:09:55 -05:00
|
|
|
private :__config_cmd
|
2004-07-08 12:50:07 -04:00
|
|
|
|
|
|
|
ComponentID_TBL = TkCore::INTERP.create_table
|
2004-07-14 21:18:57 -04:00
|
|
|
Itk_Component_ID = ['itk:component'.freeze, '00000'.taint].freeze
|
2004-07-08 12:50:07 -04:00
|
|
|
|
|
|
|
TkCore::INTERP.init_ip_env{ ComponentID_TBL.clear }
|
|
|
|
|
|
|
|
def self.id2obj(master, id)
|
2004-10-11 00:51:21 -04:00
|
|
|
if master.kind_of?(TkObject)
|
|
|
|
master = master.path
|
|
|
|
else
|
|
|
|
master = master.to_s
|
|
|
|
end
|
|
|
|
return id unless ComponentID_TBL.key?(master)
|
|
|
|
(ComponentID_TBL.key?(id))? ComponentID_TBL[master][id]: id
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.new(master, component=nil)
|
2004-10-11 00:51:21 -04:00
|
|
|
if master.kind_of?(TkObject)
|
|
|
|
master = master.path
|
|
|
|
else
|
|
|
|
master = master.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
if component.kind_of?(Tk::Itk::Component)
|
|
|
|
component = component.name
|
|
|
|
elsif component
|
|
|
|
component = component.to_s
|
|
|
|
else
|
|
|
|
component = Itk_Component_ID.join(TkCore::INTERP._ip_id_)
|
|
|
|
Itk_Component_ID[1].succ!
|
|
|
|
end
|
|
|
|
|
|
|
|
if ComponentID_TBL.key?(master)
|
|
|
|
if ComponentID_TBL[master].key?(component)
|
|
|
|
return ComponentID_TBL[master][component]
|
|
|
|
end
|
|
|
|
else
|
|
|
|
ComponentID_TBL[master] = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
super(master, component)
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(master, component)
|
2004-10-11 00:51:21 -04:00
|
|
|
@master = master
|
|
|
|
@component = component
|
2004-07-08 12:50:07 -04:00
|
|
|
|
2004-10-11 00:51:21 -04:00
|
|
|
ComponentID_TBL[@master][@component] = self
|
2004-07-08 12:50:07 -04:00
|
|
|
|
2004-10-11 00:51:21 -04:00
|
|
|
begin
|
|
|
|
@widget = window(tk_call(@master, 'component', @component))
|
|
|
|
@path = @widget.path
|
|
|
|
rescue
|
|
|
|
@widget = nil
|
|
|
|
@path = nil
|
|
|
|
end
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def path
|
2004-10-11 00:51:21 -04:00
|
|
|
unless @path
|
|
|
|
begin
|
|
|
|
@widget = window(tk_call(@master, 'component', @component))
|
|
|
|
@path = @widget.path
|
|
|
|
rescue
|
|
|
|
fail RuntimeError, 'component is not assigned to a widget'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@path
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def epath
|
2004-10-11 00:51:21 -04:00
|
|
|
path()
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_eval
|
2004-10-11 00:51:21 -04:00
|
|
|
path()
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def master
|
2004-10-11 00:51:21 -04:00
|
|
|
@master
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def name
|
2004-10-11 00:51:21 -04:00
|
|
|
@component
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def widget
|
2004-10-11 00:51:21 -04:00
|
|
|
unless @widget
|
|
|
|
begin
|
|
|
|
@widget = window(tk_call(@master, 'component', @component))
|
|
|
|
@path = @widget.path
|
|
|
|
rescue
|
|
|
|
fail RuntimeError, 'component is not assigned to a widget'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@widget
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def widget_class
|
2004-10-11 00:51:21 -04:00
|
|
|
unless @widget
|
|
|
|
begin
|
|
|
|
@widget = window(tk_call(@master, 'component', @component))
|
|
|
|
@path = @widget.path
|
|
|
|
@widget.classname
|
|
|
|
rescue
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def method_missing(id, *args)
|
2004-10-11 00:51:21 -04:00
|
|
|
name = id.id2name
|
|
|
|
|
|
|
|
# try 1 : component command
|
|
|
|
begin
|
|
|
|
return tk_call(@master, 'component', @component, name, *args)
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
|
|
|
|
# try 2 : component configure
|
|
|
|
len = args.length
|
|
|
|
begin
|
|
|
|
case len
|
|
|
|
when 1
|
|
|
|
if name[-1] == ?=
|
|
|
|
return configure(name[0..-2], args[0])
|
|
|
|
else
|
|
|
|
return configure(name, args[0])
|
|
|
|
end
|
|
|
|
when 0
|
|
|
|
return cget(name)
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
|
|
|
|
# try 3 : widget method or widget configure
|
|
|
|
begin
|
|
|
|
unless @widget
|
|
|
|
@widget = window(tk_call(@master, 'component', @component))
|
|
|
|
@path = @widget.path
|
|
|
|
end
|
|
|
|
@widget.__send__(id, *args)
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
|
|
|
|
# unknown method
|
|
|
|
fail RuntimeError, "unknown method '#{name}' for #{self.inspect}"
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def tk_send(cmd, *rest)
|
2004-10-11 00:51:21 -04:00
|
|
|
begin
|
|
|
|
tk_call(@master, 'component', @component, cmd, *rest)
|
|
|
|
rescue
|
|
|
|
unless @path
|
|
|
|
begin
|
|
|
|
@widget = window(tk_call(@master, 'component', @component))
|
|
|
|
@path = @widget.path
|
|
|
|
rescue
|
|
|
|
fail RuntimeError, 'component is not assigned to a widget'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
tk_call(@path, cmd, *rest)
|
|
|
|
end
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def tk_send_without_enc(cmd, *rest)
|
2004-10-11 00:51:21 -04:00
|
|
|
begin
|
|
|
|
tk_call_without_enc(@master, 'component', @component, cmd, *rest)
|
|
|
|
rescue
|
|
|
|
unless @path
|
|
|
|
begin
|
|
|
|
@widget = window(tk_call(@master, 'component', @component))
|
|
|
|
@path = @widget.path
|
|
|
|
rescue
|
|
|
|
fail RuntimeError, 'component is not assigned to a widget'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
tk_call_without_enc(@path, cmd, *rest)
|
|
|
|
end
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def tk_send_with_enc(cmd, *rest)
|
2004-10-11 00:51:21 -04:00
|
|
|
begin
|
|
|
|
tk_call_with_enc(@master, 'component', @component, cmd, *rest)
|
|
|
|
rescue
|
|
|
|
unless @path
|
|
|
|
begin
|
|
|
|
@widget = window(tk_call(@master, 'component', @component))
|
|
|
|
@path = @widget.path
|
|
|
|
rescue
|
|
|
|
fail RuntimeError, 'component is not assigned to a widget'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
tk_call_with_enc(@path, cmd, *rest)
|
|
|
|
end
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
2004-12-08 13:14:15 -05:00
|
|
|
#def bind(*args)
|
|
|
|
# unless @widget
|
|
|
|
# begin
|
|
|
|
# @widget = window(tk_call(@master, 'component', @component))
|
|
|
|
# @path = @widget.path
|
|
|
|
# rescue
|
|
|
|
# fail RuntimeError, 'component is not assigned to a widget'
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# @widget.bind(*args)
|
|
|
|
#end
|
|
|
|
def bind(context, *args)
|
2004-10-11 00:51:21 -04:00
|
|
|
unless @widget
|
|
|
|
begin
|
|
|
|
@widget = window(tk_call(@master, 'component', @component))
|
|
|
|
@path = @widget.path
|
|
|
|
rescue
|
|
|
|
fail RuntimeError, 'component is not assigned to a widget'
|
|
|
|
end
|
|
|
|
end
|
2004-12-16 02:13:14 -05:00
|
|
|
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
|
2005-01-25 00:09:22 -05:00
|
|
|
if TkComm._callback_entry?(args[0]) || !block_given?
|
2004-12-08 13:14:15 -05:00
|
|
|
cmd = args.shift
|
|
|
|
else
|
|
|
|
cmd = Proc.new
|
|
|
|
end
|
|
|
|
@widget.bind(context, cmd, *args)
|
|
|
|
end
|
|
|
|
|
|
|
|
#def bind_append(*args)
|
|
|
|
# unless @widget
|
|
|
|
# begin
|
|
|
|
# @widget = window(tk_call(@master, 'component', @component))
|
|
|
|
# @path = @widget.path
|
|
|
|
# rescue
|
|
|
|
# fail RuntimeError, 'component is not assigned to a widget'
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# @widget.bind_append(*args)
|
|
|
|
#end
|
|
|
|
def bind_append(context, *args)
|
2004-10-11 00:51:21 -04:00
|
|
|
unless @widget
|
|
|
|
begin
|
|
|
|
@widget = window(tk_call(@master, 'component', @component))
|
|
|
|
@path = @widget.path
|
|
|
|
rescue
|
|
|
|
fail RuntimeError, 'component is not assigned to a widget'
|
|
|
|
end
|
|
|
|
end
|
2004-12-16 02:13:14 -05:00
|
|
|
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
|
2005-01-25 00:09:22 -05:00
|
|
|
if TkComm._callback_entry?(args[0]) || !block_given?
|
2004-12-08 13:14:15 -05:00
|
|
|
cmd = args.shift
|
|
|
|
else
|
|
|
|
cmd = Proc.new
|
|
|
|
end
|
|
|
|
@widget.bind_append(context, cmd, *args)
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def bind_remove(*args)
|
2004-10-11 00:51:21 -04:00
|
|
|
unless @widget
|
|
|
|
begin
|
|
|
|
@widget = window(tk_call(@master, 'component', @component))
|
|
|
|
@path = @widget.path
|
|
|
|
rescue
|
|
|
|
fail RuntimeError, 'component is not assigned to a widget'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@widget.bind_remove(*args)
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def bindinfo(*args)
|
2004-10-11 00:51:21 -04:00
|
|
|
unless @widget
|
|
|
|
begin
|
|
|
|
@widget = window(tk_call(@master, 'component', @component))
|
|
|
|
@path = @widget.path
|
|
|
|
rescue
|
|
|
|
fail RuntimeError, 'component is not assigned to a widget'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@widget.bindinfo(*args)
|
2004-07-08 12:50:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|