mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Ruby/Tk libraries except tk.rb :
* remove direct-accesses to a TkComm::INTERP * remove direct-accesses to a TkComm::INITIALIZE_TARGETS * use TkINTERP_SETUP_SCRIPTS constant for setting up the interpreter tcltklib.c : * support to create a safe interpreter with safe-Tk ( Tk8.x ) you can test it by the following --------------------------------------------- require 'tk' safeip = Tk::INTERP._eval('::safe::interpCreate') Tk::INTERP._eval('::safe::loadTk ' + safeip) Tk::INTERP._eval(safeip + ' eval button .b -text SlaveIP -command exit') Tk::INTERP._eval(safeip + ' eval pack .b') Tk.mainloop --------------------------------------------- git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
aa49df66ae
commit
e8ab40d239
8 changed files with 82 additions and 22 deletions
|
@ -470,11 +470,25 @@ lib_restart(self)
|
||||||
/* ignore ERROR */
|
/* ignore ERROR */
|
||||||
DUMP2("(TCL_Eval result) %d", ptr->return_value);
|
DUMP2("(TCL_Eval result) %d", ptr->return_value);
|
||||||
|
|
||||||
/* execute Tk_Init */
|
/* execute Tk_Init of Tk_SafeInit */
|
||||||
|
#if TCL_MAJOR_VERSION >= 8
|
||||||
|
if (Tcl_IsSafe(ptr->ip)) {
|
||||||
|
DUMP1("Tk_SafeInit");
|
||||||
|
if (Tk_SafeInit(ptr->ip) == TCL_ERROR) {
|
||||||
|
rb_raise(rb_eRuntimeError, "%s", ptr->ip->result);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
DUMP1("Tk_Init");
|
DUMP1("Tk_Init");
|
||||||
if (Tk_Init(ptr->ip) == TCL_ERROR) {
|
if (Tk_Init(ptr->ip) == TCL_ERROR) {
|
||||||
rb_raise(rb_eRuntimeError, "%s", ptr->ip->result);
|
rb_raise(rb_eRuntimeError, "%s", ptr->ip->result);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
DUMP1("Tk_Init");
|
||||||
|
if (Tk_Init(ptr->ip) == TCL_ERROR) {
|
||||||
|
rb_raise(rb_eRuntimeError, "%s", ptr->ip->result);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
@ -596,8 +610,12 @@ ip_init(self)
|
||||||
rb_raise(rb_eRuntimeError, "%s", ptr->ip->result);
|
rb_raise(rb_eRuntimeError, "%s", ptr->ip->result);
|
||||||
}
|
}
|
||||||
DUMP1("Tcl_StaticPackage(\"Tk\")");
|
DUMP1("Tcl_StaticPackage(\"Tk\")");
|
||||||
|
#if TCL_MAJOR_VERSION >= 8
|
||||||
|
Tcl_StaticPackage(ptr->ip, "Tk", Tk_Init, Tk_SafeInit);
|
||||||
|
#else
|
||||||
Tcl_StaticPackage(ptr->ip, "Tk", Tk_Init,
|
Tcl_StaticPackage(ptr->ip, "Tk", Tk_Init,
|
||||||
(Tcl_PackageInitProc *) NULL);
|
(Tcl_PackageInitProc *) NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* add ruby command to the interpreter */
|
/* add ruby command to the interpreter */
|
||||||
#if TCL_MAJOR_VERSION >= 8
|
#if TCL_MAJOR_VERSION >= 8
|
||||||
|
|
|
@ -25,6 +25,24 @@ module TkComm
|
||||||
Tk_WINDOWS.clear
|
Tk_WINDOWS.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.__add_target_for_init__(target)
|
||||||
|
INITIALIZE_TARGETS << target
|
||||||
|
|
||||||
|
if target.const_defined? :TkINTERP_SETUP_SCRIPTS
|
||||||
|
target::TkINTERP_SETUP_SCRIPTS.collect{|script|
|
||||||
|
if script.kind_of? Proc
|
||||||
|
script.call
|
||||||
|
elsif script.kind_of? Array
|
||||||
|
Tk.ip_invoke(*script)
|
||||||
|
else
|
||||||
|
Tk.ip_eval(script)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def error_at
|
def error_at
|
||||||
frames = caller()
|
frames = caller()
|
||||||
frames.delete_if do |c|
|
frames.delete_if do |c|
|
||||||
|
@ -39,7 +57,7 @@ module TkComm
|
||||||
|
|
||||||
begin
|
begin
|
||||||
#tk_class = TkCore::INTERP._invoke('winfo', 'class', path)
|
#tk_class = TkCore::INTERP._invoke('winfo', 'class', path)
|
||||||
tk_class = Tk.tk_call('winfo', 'class', path)
|
tk_class = Tk.ip_invoke('winfo', 'class', path)
|
||||||
rescue
|
rescue
|
||||||
return path
|
return path
|
||||||
end
|
end
|
||||||
|
@ -840,6 +858,22 @@ module TkCore
|
||||||
tk_call 'tk_chooseDirectory', *hash_kv(keys)
|
tk_call 'tk_chooseDirectory', *hash_kv(keys)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ip_eval(cmd_string)
|
||||||
|
res = INTERP._eval(cmd_string)
|
||||||
|
if INTERP._return_value() != 0
|
||||||
|
fail RuntimeError, res, error_at
|
||||||
|
end
|
||||||
|
return res
|
||||||
|
end
|
||||||
|
|
||||||
|
def ip_invoke(*args)
|
||||||
|
res = INTERP._invoke(*args)
|
||||||
|
if INTERP._return_value() != 0
|
||||||
|
fail RuntimeError, res, error_at
|
||||||
|
end
|
||||||
|
return res
|
||||||
|
end
|
||||||
|
|
||||||
def tk_call(*args)
|
def tk_call(*args)
|
||||||
puts args.inspect if $DEBUG
|
puts args.inspect if $DEBUG
|
||||||
args.collect! {|x|ruby2tcl(x)}
|
args.collect! {|x|ruby2tcl(x)}
|
||||||
|
@ -937,12 +971,13 @@ module Tk
|
||||||
TK_LIBRARY = INTERP._invoke("set", "tk_library").freeze
|
TK_LIBRARY = INTERP._invoke("set", "tk_library").freeze
|
||||||
LIBRARY = INTERP._invoke("info", "library").freeze
|
LIBRARY = INTERP._invoke("info", "library").freeze
|
||||||
|
|
||||||
PLATFORM = Hash[*tk_split_simplelist(INTERP._eval('array get tcl_platform'))]
|
PLATFORM = Hash[*tk_split_simplelist(INTERP._invoke('array', 'get',
|
||||||
|
'tcl_platform'))]
|
||||||
PLATFORM.each{|k, v| k.freeze; v.freeze}
|
PLATFORM.each{|k, v| k.freeze; v.freeze}
|
||||||
PLATFORM.freeze
|
PLATFORM.freeze
|
||||||
|
|
||||||
TK_PREV = {}
|
TK_PREV = {}
|
||||||
Hash[*tk_split_simplelist(INTERP._eval('array get tkPriv'))].each{|k,v|
|
Hash[*tk_split_simplelist(INTERP._invoke('array','get','tkPriv'))].each{|k,v|
|
||||||
k.freeze
|
k.freeze
|
||||||
case v
|
case v
|
||||||
when /^-?\d+$/
|
when /^-?\d+$/
|
||||||
|
@ -1437,7 +1472,7 @@ class TkBindTag
|
||||||
BTagID_TBL = {}
|
BTagID_TBL = {}
|
||||||
Tk_BINDTAG_ID = ["btag00000"]
|
Tk_BINDTAG_ID = ["btag00000"]
|
||||||
|
|
||||||
TkComm::INITIALIZE_TARGETS << self
|
TkComm.__add_target_for_init__(self)
|
||||||
|
|
||||||
def self.__init_tables__
|
def self.__init_tables__
|
||||||
BTagID_TBL.clear
|
BTagID_TBL.clear
|
||||||
|
@ -1509,16 +1544,19 @@ class TkVariable
|
||||||
TkVar_ID_TBL = {}
|
TkVar_ID_TBL = {}
|
||||||
Tk_VARIABLE_ID = ["v00000"]
|
Tk_VARIABLE_ID = ["v00000"]
|
||||||
|
|
||||||
TkComm::INITIALIZE_TARGETS << self
|
# this constant must be defined befor calling __add_target_for_init__
|
||||||
|
TkINTERP_SETUP_SCRIPTS = [
|
||||||
|
["proc", "rb_var", "args",
|
||||||
|
"ruby [format \"TkVariable.callback %%Q!%s!\" $args]"]
|
||||||
|
]
|
||||||
|
|
||||||
|
TkComm.__add_target_for_init__(self)
|
||||||
|
|
||||||
def self.__init_tables__
|
def self.__init_tables__
|
||||||
# cannot clear
|
# cannot clear
|
||||||
# Tcl interpreter may keeps callbacks
|
# Tcl interpreter may keeps callbacks
|
||||||
end
|
end
|
||||||
|
|
||||||
INTERP._invoke("proc", "rb_var", "args",
|
|
||||||
"ruby [format \"TkVariable.callback %%Q!%s!\" $args]")
|
|
||||||
|
|
||||||
def TkVariable.callback(args)
|
def TkVariable.callback(args)
|
||||||
name1,name2,op = tk_split_list(args)
|
name1,name2,op = tk_split_list(args)
|
||||||
if TkVar_CB_TBL[name1]
|
if TkVar_CB_TBL[name1]
|
||||||
|
|
|
@ -12,15 +12,19 @@ class TkTimer
|
||||||
Tk_CBID = [0]
|
Tk_CBID = [0]
|
||||||
Tk_CBTBL = {}
|
Tk_CBTBL = {}
|
||||||
|
|
||||||
TkComm::INITIALIZE_TARGETS << self
|
# this constant must be defined befor calling __add_target_for_init__
|
||||||
|
TkINTERP_SETUP_SCRIPTS = [
|
||||||
|
["proc", "rb_after", "id",
|
||||||
|
"ruby [format \"#{self.name}.callback %%Q!%s!\" $id]"]
|
||||||
|
]
|
||||||
|
|
||||||
|
TkComm.__add_target_for_init__(self)
|
||||||
|
|
||||||
def self.__init_tables__
|
def self.__init_tables__
|
||||||
# cannot clear
|
# cannot clear
|
||||||
# Tcl interpreter may keep callbacks
|
# Tcl interpreter may keep callbacks
|
||||||
end
|
end
|
||||||
|
|
||||||
INTERP._invoke("proc", "rb_after", "id",
|
|
||||||
"ruby [format \"#{self.name}.callback %%Q!%s!\" $id]")
|
|
||||||
|
|
||||||
###############################
|
###############################
|
||||||
# class methods
|
# class methods
|
||||||
|
|
|
@ -521,7 +521,7 @@ class TkcTag<TkObject
|
||||||
CTagID_TBL = {}
|
CTagID_TBL = {}
|
||||||
Tk_CanvasTag_ID = ['ctag0000']
|
Tk_CanvasTag_ID = ['ctag0000']
|
||||||
|
|
||||||
TkComm::INITIALIZE_TARGETS << self
|
TkComm.__add_target_for_init__(self)
|
||||||
|
|
||||||
def self.__init_tables__
|
def self.__init_tables__
|
||||||
CTagID_TBL.clear
|
CTagID_TBL.clear
|
||||||
|
@ -690,7 +690,7 @@ class TkcItem<TkObject
|
||||||
CItemTypeToClass = {}
|
CItemTypeToClass = {}
|
||||||
CItemID_TBL = {}
|
CItemID_TBL = {}
|
||||||
|
|
||||||
TkComm::INITIALIZE_TARGETS << self
|
TkComm.__add_target_for_init__(self)
|
||||||
|
|
||||||
def self.__init_tables__
|
def self.__init_tables__
|
||||||
CItemID_TBL.clear
|
CItemID_TBL.clear
|
||||||
|
@ -822,7 +822,7 @@ class TkImage<TkObject
|
||||||
Tk_IMGTBL = {}
|
Tk_IMGTBL = {}
|
||||||
Tk_Image_ID = ['i00000']
|
Tk_Image_ID = ['i00000']
|
||||||
|
|
||||||
TkComm::INITIALIZE_TARGETS << self
|
TkComm.__add_target_for_init__(self)
|
||||||
|
|
||||||
def self.__init_tables__
|
def self.__init_tables__
|
||||||
Tk_IMGTBL.clear
|
Tk_IMGTBL.clear
|
||||||
|
|
|
@ -143,7 +143,7 @@ class TkDialog2 < TkWindow
|
||||||
default_button = @default_button
|
default_button = @default_button
|
||||||
end
|
end
|
||||||
default_button = '{}' if default_button == nil
|
default_button = '{}' if default_button == nil
|
||||||
INTERP._eval('eval {global '+@var.id+';'+@config+
|
Tk.ip_eval('eval {global '+@var.id+';'+@config+
|
||||||
'set '+@var.id+' [tk_dialog '+
|
'set '+@var.id+' [tk_dialog '+
|
||||||
@path+" "+@title+" {#{@message}} "+@bitmap+" "+
|
@path+" "+@title+" {#{@message}} "+@bitmap+" "+
|
||||||
String(default_button)+" "+@buttons.join(' ')+']}')
|
String(default_button)+" "+@buttons.join(' ')+']}')
|
||||||
|
|
|
@ -13,7 +13,7 @@ class TkFont
|
||||||
Tk_FontNameTBL = {}
|
Tk_FontNameTBL = {}
|
||||||
Tk_FontUseTBL = {}
|
Tk_FontUseTBL = {}
|
||||||
|
|
||||||
TkComm::INITIALIZE_TARGETS << self
|
TkComm.__add_target_for_init__(self)
|
||||||
|
|
||||||
def self.__init_tables__
|
def self.__init_tables__
|
||||||
Tk_FontNameTBL.clear
|
Tk_FontNameTBL.clear
|
||||||
|
|
|
@ -728,7 +728,7 @@ class TkTextTag<TkObject
|
||||||
TTagID_TBL = {}
|
TTagID_TBL = {}
|
||||||
Tk_TextTag_ID = ['tag0000']
|
Tk_TextTag_ID = ['tag0000']
|
||||||
|
|
||||||
TkComm::INITIALIZE_TARGETS << self
|
TkComm.__add_target_for_init__(self)
|
||||||
|
|
||||||
def self.__init_tables__
|
def self.__init_tables__
|
||||||
TTagID_TBL.clear
|
TTagID_TBL.clear
|
||||||
|
|
|
@ -10,7 +10,7 @@ class TkVirtualEvent<TkObject
|
||||||
TkVirtualEventID = [0]
|
TkVirtualEventID = [0]
|
||||||
TkVirtualEventTBL = {}
|
TkVirtualEventTBL = {}
|
||||||
|
|
||||||
TkComm::INITIALIZE_TARGETS << self
|
TkComm.__add_target_for_init__(self)
|
||||||
|
|
||||||
def self.__init_tables__
|
def self.__init_tables__
|
||||||
TkVirtualEventTBL.clear
|
TkVirtualEventTBL.clear
|
||||||
|
|
Loading…
Reference in a new issue