2003-08-02 01:04:30 -04:00
|
|
|
#
|
2001-05-06 11:06:00 -04:00
|
|
|
# tk.rb - Tk interface module using tcltklib
|
1999-08-13 01:37:52 -04:00
|
|
|
# $Date$
|
2001-05-06 11:06:00 -04:00
|
|
|
# by Yukihiro Matsumoto <matz@netlab.jp>
|
1999-08-13 01:37:52 -04:00
|
|
|
|
|
|
|
# use Shigehiro's tcltklib
|
|
|
|
require "tcltklib"
|
|
|
|
require "tkutil"
|
|
|
|
|
|
|
|
module TkComm
|
2003-09-07 03:10:44 -04:00
|
|
|
WidgetClassNames = {}.taint
|
1999-08-24 04:21:56 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
None = Object.new
|
|
|
|
def None.to_s
|
|
|
|
'None'
|
|
|
|
end
|
2003-08-29 04:34:14 -04:00
|
|
|
None.freeze
|
1999-08-13 01:37:52 -04:00
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
#Tk_CMDTBL = {}
|
|
|
|
#Tk_WINDOWS = {}
|
2003-09-07 03:10:44 -04:00
|
|
|
Tk_IDs = ["00000".taint, "00000".taint].freeze # [0]-cmdid, [1]-winid
|
2003-06-18 15:46:20 -04:00
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
# for backward compatibility
|
|
|
|
Tk_CMDTBL = Object.new
|
|
|
|
def Tk_CMDTBL.method_missing(id, *args)
|
|
|
|
TkCore::INTERP.tk_cmd_tbl.send(id, *args)
|
2003-06-18 15:46:20 -04:00
|
|
|
end
|
2003-08-29 04:34:14 -04:00
|
|
|
Tk_CMDTBL.freeze
|
2003-07-23 12:07:35 -04:00
|
|
|
Tk_WINDOWS = Object.new
|
|
|
|
def Tk_WINDOWS.method_missing(id, *args)
|
|
|
|
TkCore::INTERP.tk_windows.send(id, *args)
|
2003-06-21 04:47:22 -04:00
|
|
|
end
|
2003-08-29 04:34:14 -04:00
|
|
|
Tk_WINDOWS.freeze
|
|
|
|
|
|
|
|
self.instance_eval{
|
2003-09-07 03:10:44 -04:00
|
|
|
@cmdtbl = [].taint
|
2003-08-29 04:34:14 -04:00
|
|
|
}
|
2003-06-21 04:47:22 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def error_at
|
|
|
|
frames = caller()
|
|
|
|
frames.delete_if do |c|
|
|
|
|
c =~ %r!/tk(|core|thcore|canvas|text|entry|scrollbox)\.rb:\d+!
|
|
|
|
end
|
|
|
|
frames
|
|
|
|
end
|
|
|
|
private :error_at
|
|
|
|
|
|
|
|
def _genobj_for_tkwidget(path)
|
|
|
|
return TkRoot.new if path == '.'
|
|
|
|
|
|
|
|
begin
|
2003-06-18 15:46:20 -04:00
|
|
|
#tk_class = TkCore::INTERP._invoke('winfo', 'class', path)
|
2003-06-21 04:47:22 -04:00
|
|
|
tk_class = Tk.ip_invoke('winfo', 'class', path)
|
1999-08-13 01:37:52 -04:00
|
|
|
rescue
|
|
|
|
return path
|
|
|
|
end
|
|
|
|
|
2003-07-01 18:08:19 -04:00
|
|
|
if ruby_class = WidgetClassNames[tk_class]
|
|
|
|
ruby_class_name = ruby_class.name
|
2003-07-31 03:59:18 -04:00
|
|
|
# gen_class_name = ruby_class_name + 'GeneratedOnTk'
|
|
|
|
gen_class_name = ruby_class_name
|
2003-07-01 18:08:19 -04:00
|
|
|
classname_def = ''
|
|
|
|
elsif Object.const_defined?('Tk' + tk_class)
|
|
|
|
ruby_class_name = 'Tk' + tk_class
|
2003-07-31 03:59:18 -04:00
|
|
|
# gen_class_name = ruby_class_name + 'GeneratedOnTk'
|
|
|
|
gen_class_name = ruby_class_name
|
2003-07-01 18:08:19 -04:00
|
|
|
classname_def = ''
|
|
|
|
else
|
|
|
|
ruby_class_name = 'TkWindow'
|
2003-07-31 03:59:18 -04:00
|
|
|
# gen_class_name = ruby_class_name + tk_class + 'GeneratedOnTk'
|
|
|
|
gen_class_name = 'TkWidget_' + tk_class
|
2003-07-01 18:08:19 -04:00
|
|
|
classname_def = "WidgetClassName = '#{tk_class}'.freeze"
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
unless Object.const_defined? gen_class_name
|
2003-07-01 18:08:19 -04:00
|
|
|
Object.class_eval "class #{gen_class_name}<#{ruby_class_name}
|
|
|
|
#{classname_def}
|
|
|
|
end"
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-07-31 03:59:18 -04:00
|
|
|
Object.class_eval "#{gen_class_name}.new('widgetname'=>'#{path}',
|
|
|
|
'without_creating'=>true)"
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
private :_genobj_for_tkwidget
|
2003-07-01 18:08:19 -04:00
|
|
|
module_function :_genobj_for_tkwidget
|
1999-08-13 01:37:52 -04:00
|
|
|
|
|
|
|
def tk_tcl2ruby(val)
|
|
|
|
if val =~ /^rb_out (c\d+)/
|
2003-07-23 12:07:35 -04:00
|
|
|
#return Tk_CMDTBL[$1]
|
|
|
|
return TkCore::INTERP.tk_cmd_tbl[$1]
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
if val.include? ?\s
|
|
|
|
return val.split.collect{|v| tk_tcl2ruby(v)}
|
|
|
|
end
|
|
|
|
case val
|
|
|
|
when /^@font/
|
|
|
|
TkFont.get_obj(val)
|
|
|
|
when /^-?\d+$/
|
|
|
|
val.to_i
|
|
|
|
when /^\./
|
2003-07-23 12:07:35 -04:00
|
|
|
#Tk_WINDOWS[val] ? Tk_WINDOWS[val] : _genobj_for_tkwidget(val)
|
|
|
|
TkCore::INTERP.tk_windows[val]?
|
|
|
|
TkCore::INTERP.tk_windows[val] : _genobj_for_tkwidget(val)
|
2003-06-18 15:46:20 -04:00
|
|
|
when /^i\d+$/
|
|
|
|
TkImage::Tk_IMGTBL[val]? TkImage::Tk_IMGTBL[val] : val
|
1999-08-13 01:37:52 -04:00
|
|
|
when / /
|
|
|
|
val.split.collect{|elt|
|
|
|
|
tk_tcl2ruby(elt)
|
|
|
|
}
|
2003-06-18 15:46:20 -04:00
|
|
|
when /^-?\d+\.?\d*(e[-+]?\d+)?$/
|
1999-08-13 01:37:52 -04:00
|
|
|
val.to_f
|
|
|
|
else
|
|
|
|
val
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def tk_split_list(str)
|
|
|
|
return [] if str == ""
|
|
|
|
idx = str.index('{')
|
2001-10-29 00:07:26 -05:00
|
|
|
while idx and idx > 0 and str[idx-1] == ?\\
|
|
|
|
idx = str.index('{', idx+1)
|
|
|
|
end
|
2003-05-26 04:22:33 -04:00
|
|
|
unless idx
|
|
|
|
list = tk_tcl2ruby(str)
|
|
|
|
unless Array === list
|
|
|
|
list = [list]
|
|
|
|
end
|
|
|
|
return list
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
|
|
|
|
list = tk_tcl2ruby(str[0,idx])
|
|
|
|
list = [] if list == ""
|
|
|
|
str = str[idx+1..-1]
|
|
|
|
i = -1
|
|
|
|
brace = 1
|
|
|
|
str.each_byte {|c|
|
|
|
|
i += 1
|
|
|
|
brace += 1 if c == ?{
|
|
|
|
brace -= 1 if c == ?}
|
|
|
|
break if brace == 0
|
|
|
|
}
|
2003-05-26 04:22:33 -04:00
|
|
|
if str.size == i + 1
|
|
|
|
return tk_split_list(str[0, i])
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
if str[0, i] == ' '
|
|
|
|
list.push ' '
|
|
|
|
else
|
|
|
|
list.push tk_split_list(str[0, i])
|
|
|
|
end
|
|
|
|
list += tk_split_list(str[i+1..-1])
|
|
|
|
list
|
|
|
|
end
|
|
|
|
|
|
|
|
def tk_split_simplelist(str)
|
|
|
|
return [] if str == ""
|
|
|
|
idx = str.index('{')
|
2001-10-29 00:07:26 -05:00
|
|
|
while idx and idx > 0 and str[idx-1] == ?\\
|
|
|
|
idx = str.index('{', idx+1)
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
return str.split unless idx
|
|
|
|
|
|
|
|
list = str[0,idx].split
|
|
|
|
str = str[idx+1..-1]
|
|
|
|
i = -1
|
|
|
|
brace = 1
|
|
|
|
str.each_byte {|c|
|
|
|
|
i += 1
|
|
|
|
brace += 1 if c == ?{
|
|
|
|
brace -= 1 if c == ?}
|
|
|
|
break if brace == 0
|
|
|
|
}
|
|
|
|
if i == 0
|
|
|
|
list.push ''
|
|
|
|
elsif str[0, i] == ' '
|
|
|
|
list.push ' '
|
|
|
|
else
|
|
|
|
list.push str[0..i-1]
|
|
|
|
end
|
|
|
|
list += tk_split_simplelist(str[i+1..-1])
|
|
|
|
list
|
|
|
|
end
|
|
|
|
private :tk_tcl2ruby, :tk_split_list, :tk_split_simplelist
|
|
|
|
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
def _symbolkey2str(keys)
|
|
|
|
h = {}
|
|
|
|
keys.each{|key,value| h[key.to_s] = value}
|
|
|
|
h
|
|
|
|
end
|
|
|
|
private :_symbolkey2str
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def hash_kv(keys)
|
|
|
|
conf = []
|
|
|
|
if keys and keys != None
|
|
|
|
for k, v in keys
|
|
|
|
conf.push("-#{k}")
|
|
|
|
conf.push(v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
conf
|
|
|
|
end
|
|
|
|
private :hash_kv
|
2003-07-29 04:05:30 -04:00
|
|
|
module_function :hash_kv
|
1999-08-13 01:37:52 -04:00
|
|
|
|
|
|
|
def array2tk_list(ary)
|
|
|
|
ary.collect{|e|
|
|
|
|
if e.kind_of? Array
|
|
|
|
"{#{array2tk_list(e)}}"
|
|
|
|
elsif e.kind_of? Hash
|
|
|
|
"{#{e.to_a.collect{|ee| array2tk_list(ee)}.join(' ')}}"
|
|
|
|
else
|
|
|
|
s = _get_eval_string(e)
|
2003-11-30 03:41:15 -05:00
|
|
|
(s.index(/\s/) || s.size == 0)? "{#{s}}": s
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
}.join(" ")
|
|
|
|
end
|
|
|
|
private :array2tk_list
|
2003-07-29 04:05:30 -04:00
|
|
|
module_function :array2tk_list
|
1999-08-13 01:37:52 -04:00
|
|
|
|
|
|
|
def bool(val)
|
|
|
|
case val
|
|
|
|
when "1", 1, 'yes', 'true'
|
2003-06-18 15:46:20 -04:00
|
|
|
true
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
2003-06-18 15:46:20 -04:00
|
|
|
false
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
def number(val)
|
|
|
|
case val
|
|
|
|
when /^-?\d+$/
|
|
|
|
val.to_i
|
2003-06-18 15:46:20 -04:00
|
|
|
when /^-?\d+\.?\d*(e[-+]?\d+)?$/
|
1999-08-13 01:37:52 -04:00
|
|
|
val.to_f
|
|
|
|
else
|
2003-12-02 23:55:07 -05:00
|
|
|
fail(ArgumentError,
|
|
|
|
Kernel.format('invalid value for Number:"%s"', val.to_s))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
def string(val)
|
|
|
|
if val == "{}"
|
|
|
|
''
|
|
|
|
elsif val[0] == ?{
|
|
|
|
val[1..-2]
|
|
|
|
else
|
|
|
|
val
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def list(val)
|
2003-05-26 04:22:33 -04:00
|
|
|
tk_split_list(val)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def simplelist(val)
|
|
|
|
tk_split_simplelist(val)
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
def window(val)
|
2003-06-18 15:46:20 -04:00
|
|
|
if val =~ /^\./
|
2003-07-23 12:07:35 -04:00
|
|
|
#Tk_WINDOWS[val]? Tk_WINDOWS[val] : _genobj_for_tkwidget(val)
|
|
|
|
TkCore::INTERP.tk_windows[val]?
|
|
|
|
TkCore::INTERP.tk_windows[val] : _genobj_for_tkwidget(val)
|
2003-06-18 15:46:20 -04:00
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def procedure(val)
|
|
|
|
if val =~ /^rb_out (c\d+)/
|
2003-07-23 12:07:35 -04:00
|
|
|
#Tk_CMDTBL[$1]
|
2003-07-25 12:43:03 -04:00
|
|
|
#TkCore::INTERP.tk_cmd_tbl[$1]
|
|
|
|
TkCore::INTERP.tk_cmd_tbl[$1].cmd
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
2003-06-18 15:46:20 -04:00
|
|
|
#nil
|
|
|
|
val
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
private :bool, :number, :string, :list, :simplelist, :window, :procedure
|
|
|
|
module_function :bool, :number, :string, :list, :simplelist
|
|
|
|
module_function :window, :procedure
|
1999-08-13 01:37:52 -04:00
|
|
|
|
|
|
|
def _get_eval_string(str)
|
|
|
|
return nil if str == None
|
2000-01-31 22:12:21 -05:00
|
|
|
if str.kind_of?(String)
|
|
|
|
# do nothing
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
elsif str.kind_of?(Symbol)
|
|
|
|
str = str.id2name
|
2000-01-31 22:12:21 -05:00
|
|
|
elsif str.kind_of?(Hash)
|
1999-08-13 01:37:52 -04:00
|
|
|
str = hash_kv(str).join(" ")
|
|
|
|
elsif str.kind_of?(Array)
|
|
|
|
str = array2tk_list(str)
|
|
|
|
elsif str.kind_of?(Proc)
|
|
|
|
str = install_cmd(str)
|
|
|
|
elsif str == nil
|
|
|
|
str = ""
|
|
|
|
elsif str == false
|
|
|
|
str = "0"
|
|
|
|
elsif str == true
|
|
|
|
str = "1"
|
|
|
|
elsif (str.respond_to?(:to_eval))
|
|
|
|
str = str.to_eval()
|
|
|
|
else
|
2003-06-18 15:46:20 -04:00
|
|
|
str = str.to_s() || ''
|
|
|
|
unless str.kind_of? String
|
|
|
|
fail RuntimeError, "fail to convert the object to a string"
|
|
|
|
end
|
|
|
|
str
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
return str
|
|
|
|
end
|
|
|
|
private :_get_eval_string
|
2003-07-25 12:43:03 -04:00
|
|
|
module_function :_get_eval_string
|
1999-08-13 01:37:52 -04:00
|
|
|
|
2000-07-14 00:34:43 -04:00
|
|
|
def ruby2tcl(v)
|
|
|
|
if v.kind_of?(Hash)
|
|
|
|
v = hash_kv(v)
|
|
|
|
v.flatten!
|
|
|
|
v.collect{|e|ruby2tcl(e)}
|
|
|
|
else
|
|
|
|
_get_eval_string(v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
private :ruby2tcl
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def _curr_cmd_id
|
2003-07-23 12:07:35 -04:00
|
|
|
#id = format("c%.4d", Tk_IDs[0])
|
2003-07-29 04:05:30 -04:00
|
|
|
id = "c" + TkComm::Tk_IDs[0]
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def _next_cmd_id
|
|
|
|
id = _curr_cmd_id
|
2003-07-23 12:07:35 -04:00
|
|
|
#Tk_IDs[0] += 1
|
2003-07-29 04:05:30 -04:00
|
|
|
TkComm::Tk_IDs[0].succ!
|
1999-08-13 01:37:52 -04:00
|
|
|
id
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
private :_curr_cmd_id, :_next_cmd_id
|
2003-07-29 04:05:30 -04:00
|
|
|
module_function :_curr_cmd_id, :_next_cmd_id
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def install_cmd(cmd)
|
|
|
|
return '' if cmd == ''
|
|
|
|
id = _next_cmd_id
|
2003-07-23 12:07:35 -04:00
|
|
|
#Tk_CMDTBL[id] = cmd
|
2003-07-25 12:43:03 -04:00
|
|
|
TkCore::INTERP.tk_cmd_tbl[id] = TkCore::INTERP.get_cb_entry(cmd)
|
2003-07-17 01:23:54 -04:00
|
|
|
@cmdtbl = [] unless defined? @cmdtbl
|
2003-09-07 03:10:44 -04:00
|
|
|
@cmdtbl.taint unless @cmdtbl.tainted?
|
1999-08-13 01:37:52 -04:00
|
|
|
@cmdtbl.push id
|
2003-12-02 23:55:07 -05:00
|
|
|
return Kernel.format("rb_out %s", id);
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def uninstall_cmd(id)
|
2000-01-17 03:37:53 -05:00
|
|
|
id = $1 if /rb_out (c\d+)/ =~ id
|
2003-07-23 12:07:35 -04:00
|
|
|
#Tk_CMDTBL.delete(id)
|
|
|
|
TkCore::INTERP.tk_cmd_tbl.delete(id)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
private :install_cmd, :uninstall_cmd
|
2003-07-29 04:05:30 -04:00
|
|
|
module_function :install_cmd
|
1999-08-13 01:37:52 -04:00
|
|
|
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
def install_win(ppath,name=nil)
|
|
|
|
if !name or name == ''
|
2003-07-23 12:07:35 -04:00
|
|
|
#name = format("w%.4d", Tk_IDs[1])
|
|
|
|
#Tk_IDs[1] += 1
|
|
|
|
name = "w" + Tk_IDs[1]
|
|
|
|
Tk_IDs[1].succ!
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
end
|
2003-06-12 18:13:13 -04:00
|
|
|
if name[0] == ?.
|
|
|
|
@path = name.dup
|
|
|
|
elsif !ppath or ppath == "."
|
2003-12-02 23:55:07 -05:00
|
|
|
@path = Kernel.format(".%s", name);
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
2003-12-02 23:55:07 -05:00
|
|
|
@path = Kernel.format("%s.%s", ppath, name)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-07-23 12:07:35 -04:00
|
|
|
#Tk_WINDOWS[@path] = self
|
|
|
|
TkCore::INTERP.tk_windows[@path] = self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def uninstall_win()
|
2003-07-23 12:07:35 -04:00
|
|
|
#Tk_WINDOWS.delete(@path)
|
|
|
|
TkCore::INTERP.tk_windows.delete(@path)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
private :install_win, :uninstall_win
|
1999-08-13 01:37:52 -04:00
|
|
|
|
|
|
|
class Event
|
2003-06-18 15:46:20 -04:00
|
|
|
module TypeNum
|
|
|
|
KeyPress = 2
|
|
|
|
KeyRelease = 3
|
|
|
|
ButtonPress = 4
|
|
|
|
ButtonRelease = 5
|
|
|
|
MotionNotify = 6
|
|
|
|
EnterNotify = 7
|
|
|
|
LeaveNotify = 8
|
|
|
|
FocusIn = 9
|
|
|
|
FocusOut = 10
|
|
|
|
KeymapNotify = 11
|
|
|
|
Expose = 12
|
|
|
|
GraphicsExpose = 13
|
|
|
|
NoExpose = 14
|
|
|
|
VisibilityNotify = 15
|
|
|
|
CreateNotify = 16
|
|
|
|
DestroyNotify = 17
|
|
|
|
UnmapNotify = 18
|
|
|
|
MapNotify = 19
|
|
|
|
MapRequest = 20
|
|
|
|
ReparentNotify = 21
|
|
|
|
ConfigureNotify = 22
|
|
|
|
ConfigureRequest = 23
|
|
|
|
GravityNotify = 24
|
|
|
|
ResizeRequest = 25
|
|
|
|
CirculateNotify = 26
|
|
|
|
CirculateRequest = 27
|
|
|
|
PropertyNotify = 28
|
|
|
|
SelectionClear = 29
|
|
|
|
SelectionRequest = 30
|
|
|
|
SelectionNotify = 31
|
|
|
|
ColormapNotify = 32
|
|
|
|
ClientMessage = 33
|
|
|
|
MappingNotify = 34
|
|
|
|
end
|
|
|
|
|
|
|
|
EV_KEY = '#abcdfhikmopstwxyABDEKNRSTWXY'
|
|
|
|
EV_TYPE = 'nsnnsbnsnsbsxnnnnsnnbsnssnwnn'
|
|
|
|
|
|
|
|
def self.scan_args(arg_str, arg_val)
|
|
|
|
arg_cnv = []
|
|
|
|
arg_str.strip.split(/\s+/).each_with_index{|kwd,idx|
|
|
|
|
if kwd =~ /^%(.)$/
|
|
|
|
if num = EV_KEY.index($1)
|
|
|
|
case EV_TYPE[num]
|
|
|
|
when ?n
|
2003-07-31 16:52:40 -04:00
|
|
|
begin
|
|
|
|
val = TkComm::number(arg_val[idx])
|
|
|
|
rescue ArgumentError
|
|
|
|
# ignore --> no convert
|
|
|
|
val = TkComm::string(arg_val[idx])
|
|
|
|
end
|
|
|
|
arg_cnv << val
|
2003-06-18 15:46:20 -04:00
|
|
|
when ?s
|
|
|
|
arg_cnv << TkComm::string(arg_val[idx])
|
|
|
|
when ?b
|
|
|
|
arg_cnv << TkComm::bool(arg_val[idx])
|
|
|
|
when ?w
|
|
|
|
arg_cnv << TkComm::window(arg_val[idx])
|
|
|
|
when ?x
|
|
|
|
begin
|
|
|
|
arg_cnv << TkComm::number(arg_val[idx])
|
|
|
|
rescue ArgumentError
|
|
|
|
arg_cnv << arg_val[idx]
|
|
|
|
end
|
|
|
|
else
|
|
|
|
arg_cnv << arg_val[idx]
|
|
|
|
end
|
|
|
|
else
|
|
|
|
arg_cnv << arg_val[idx]
|
|
|
|
end
|
|
|
|
else
|
|
|
|
arg_cnv << arg_val[idx]
|
|
|
|
end
|
|
|
|
}
|
|
|
|
arg_cnv
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(seq,a,b,c,d,f,h,i,k,m,o,p,s,t,w,x,y,
|
2000-11-20 02:31:55 -05:00
|
|
|
aa,bb,dd,ee,kk,nn,rr,ss,tt,ww,xx,yy)
|
1999-08-13 01:37:52 -04:00
|
|
|
@serial = seq
|
2000-11-20 02:31:55 -05:00
|
|
|
@above = a
|
1999-08-13 01:37:52 -04:00
|
|
|
@num = b
|
2000-11-20 02:31:55 -05:00
|
|
|
@count = c
|
|
|
|
@detail = d
|
2003-06-18 15:46:20 -04:00
|
|
|
@focus = f
|
1999-08-13 01:37:52 -04:00
|
|
|
@height = h
|
2003-06-18 15:46:20 -04:00
|
|
|
@win_hex = i
|
1999-08-13 01:37:52 -04:00
|
|
|
@keycode = k
|
2000-11-20 02:31:55 -05:00
|
|
|
@mode = m
|
2003-06-18 15:46:20 -04:00
|
|
|
@override = o
|
2000-11-20 02:31:55 -05:00
|
|
|
@place = p
|
1999-08-13 01:37:52 -04:00
|
|
|
@state = s
|
|
|
|
@time = t
|
|
|
|
@width = w
|
|
|
|
@x = x
|
|
|
|
@y = y
|
|
|
|
@char = aa
|
2000-11-20 02:31:55 -05:00
|
|
|
@borderwidth = bb
|
|
|
|
@wheel_delta = dd
|
2003-06-18 15:46:20 -04:00
|
|
|
@send_event = ee
|
1999-08-13 01:37:52 -04:00
|
|
|
@keysym = kk
|
|
|
|
@keysym_num = nn
|
2000-11-20 02:31:55 -05:00
|
|
|
@rootwin_id = rr
|
|
|
|
@subwindow = ss
|
1999-08-13 01:37:52 -04:00
|
|
|
@type = tt
|
|
|
|
@widget = ww
|
|
|
|
@x_root = xx
|
|
|
|
@y_root = yy
|
|
|
|
end
|
|
|
|
attr :serial
|
2000-11-20 02:31:55 -05:00
|
|
|
attr :above
|
1999-08-13 01:37:52 -04:00
|
|
|
attr :num
|
2000-11-20 02:31:55 -05:00
|
|
|
attr :count
|
|
|
|
attr :detail
|
1999-08-13 01:37:52 -04:00
|
|
|
attr :focus
|
|
|
|
attr :height
|
2003-06-18 15:46:20 -04:00
|
|
|
attr :win_hex
|
1999-08-13 01:37:52 -04:00
|
|
|
attr :keycode
|
2000-11-20 02:31:55 -05:00
|
|
|
attr :mode
|
|
|
|
attr :override
|
|
|
|
attr :place
|
1999-08-13 01:37:52 -04:00
|
|
|
attr :state
|
|
|
|
attr :time
|
|
|
|
attr :width
|
|
|
|
attr :x
|
|
|
|
attr :y
|
|
|
|
attr :char
|
2000-11-20 02:31:55 -05:00
|
|
|
attr :borderwidth
|
|
|
|
attr :wheel_delta
|
1999-08-13 01:37:52 -04:00
|
|
|
attr :send_event
|
|
|
|
attr :keysym
|
|
|
|
attr :keysym_num
|
2000-11-20 02:31:55 -05:00
|
|
|
attr :rootwin_id
|
|
|
|
attr :subwindow
|
1999-08-13 01:37:52 -04:00
|
|
|
attr :type
|
|
|
|
attr :widget
|
|
|
|
attr :x_root
|
|
|
|
attr :y_root
|
|
|
|
end
|
|
|
|
|
|
|
|
def install_bind(cmd, args=nil)
|
|
|
|
if args
|
2000-08-02 00:54:21 -04:00
|
|
|
id = install_cmd(proc{|*arg|
|
2003-06-18 15:46:20 -04:00
|
|
|
TkUtil.eval_cmd(cmd, *Event.scan_args(args, arg))
|
1999-08-13 01:37:52 -04:00
|
|
|
})
|
|
|
|
id + " " + args
|
|
|
|
else
|
2003-06-18 15:46:20 -04:00
|
|
|
args = ' %# %a %b %c %d %f %h %i %k %m %o %p %s %t %w %x %y' +
|
|
|
|
' %A %B %D %E %K %N %R %S %T %W %X %Y'
|
2003-05-23 04:11:21 -04:00
|
|
|
id = install_cmd(proc{|*arg|
|
2003-06-18 15:46:20 -04:00
|
|
|
TkUtil.eval_cmd(cmd, Event.new(*Event.scan_args(args, arg)))
|
1999-08-13 01:37:52 -04:00
|
|
|
})
|
2003-06-18 15:46:20 -04:00
|
|
|
id + args
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def tk_event_sequence(context)
|
|
|
|
if context.kind_of? TkVirtualEvent
|
|
|
|
context = context.path
|
|
|
|
end
|
|
|
|
if context.kind_of? Array
|
|
|
|
context = context.collect{|ev|
|
2001-05-06 11:06:00 -04:00
|
|
|
if ev.kind_of? TkVirtualEvent
|
1999-08-13 01:37:52 -04:00
|
|
|
ev.path
|
|
|
|
else
|
|
|
|
ev
|
|
|
|
end
|
|
|
|
}.join("><")
|
|
|
|
end
|
|
|
|
if /,/ =~ context
|
|
|
|
context = context.split(/\s*,\s*/).join("><")
|
|
|
|
else
|
|
|
|
context
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
1999-08-24 04:21:56 -04:00
|
|
|
def _bind_core(mode, what, context, cmd, args=nil)
|
|
|
|
id = install_bind(cmd, args) if cmd
|
1999-08-13 01:37:52 -04:00
|
|
|
begin
|
1999-08-24 04:21:56 -04:00
|
|
|
tk_call(*(what + ["<#{tk_event_sequence(context)}>", mode + id]))
|
1999-08-13 01:37:52 -04:00
|
|
|
rescue
|
1999-08-24 04:21:56 -04:00
|
|
|
uninstall_cmd(id) if cmd
|
1999-08-13 01:37:52 -04:00
|
|
|
fail
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
1999-08-24 04:21:56 -04:00
|
|
|
def _bind(what, context, cmd, args=nil)
|
|
|
|
_bind_core('', what, context, cmd, args)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
1999-08-24 04:21:56 -04:00
|
|
|
def _bind_append(what, context, cmd, args=nil)
|
|
|
|
_bind_core('+', what, context, cmd, args)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2000-04-10 01:57:37 -04:00
|
|
|
def _bind_remove(what, context)
|
|
|
|
tk_call(*(what + ["<#{tk_event_sequence(context)}>", '']))
|
|
|
|
end
|
|
|
|
|
1999-08-24 04:21:56 -04:00
|
|
|
def _bindinfo(what, context=nil)
|
1999-08-13 01:37:52 -04:00
|
|
|
if context
|
1999-08-24 04:21:56 -04:00
|
|
|
tk_call(*what+["<#{tk_event_sequence(context)}>"]).collect {|cmdline|
|
1999-08-13 01:37:52 -04:00
|
|
|
if cmdline =~ /^rb_out (c\d+)\s+(.*)$/
|
2003-07-23 12:07:35 -04:00
|
|
|
#[Tk_CMDTBL[$1], $2]
|
|
|
|
[TkCore::INTERP.tk_cmd_tbl[$1], $2]
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
|
|
|
cmdline
|
|
|
|
end
|
|
|
|
}
|
|
|
|
else
|
2001-05-06 11:06:00 -04:00
|
|
|
tk_split_simplelist(tk_call(*what)).collect!{|seq|
|
|
|
|
l = seq.scan(/<*[^<>]+>*/).collect!{|subseq|
|
|
|
|
case (subseq)
|
|
|
|
when /^<<[^<>]+>>$/
|
|
|
|
TkVirtualEvent.getobj(subseq[1..-2])
|
|
|
|
when /^<[^<>]+>$/
|
|
|
|
subseq[1..-2]
|
|
|
|
else
|
|
|
|
subseq.split('')
|
|
|
|
end
|
|
|
|
}.flatten
|
|
|
|
(l.size == 1) ? l[0] : l
|
1999-08-13 01:37:52 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2000-01-17 03:37:53 -05:00
|
|
|
private :install_bind, :tk_event_sequence,
|
2000-04-10 02:05:19 -04:00
|
|
|
:_bind_core, :_bind, :_bind_append, :_bind_remove, :_bindinfo
|
2000-01-17 03:37:53 -05:00
|
|
|
|
2003-06-16 03:14:50 -04:00
|
|
|
def bind(tagOrClass, context, cmd=Proc.new, args=nil)
|
2000-01-17 03:37:53 -05:00
|
|
|
_bind(["bind", tagOrClass], context, cmd, args)
|
2003-06-18 15:46:20 -04:00
|
|
|
tagOrClass
|
2000-01-17 03:37:53 -05:00
|
|
|
end
|
|
|
|
|
2003-06-16 03:14:50 -04:00
|
|
|
def bind_append(tagOrClass, context, cmd=Proc.new, args=nil)
|
2000-01-17 03:37:53 -05:00
|
|
|
_bind_append(["bind", tagOrClass], context, cmd, args)
|
2003-06-18 15:46:20 -04:00
|
|
|
tagOrClass
|
2000-01-17 03:37:53 -05:00
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
|
2000-04-10 01:57:37 -04:00
|
|
|
def bind_remove(tagOrClass, context)
|
|
|
|
_bind_remove(['bind', tagOrClass], context)
|
2003-06-18 15:46:20 -04:00
|
|
|
tagOrClass
|
2000-04-10 01:57:37 -04:00
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def bindinfo(tagOrClass, context=nil)
|
1999-08-24 04:21:56 -04:00
|
|
|
_bindinfo(['bind', tagOrClass], context)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2003-06-16 03:14:50 -04:00
|
|
|
def bind_all(context, cmd=Proc.new, args=nil)
|
2000-01-17 03:37:53 -05:00
|
|
|
_bind(['bind', 'all'], context, cmd, args)
|
2003-06-18 15:46:20 -04:00
|
|
|
TkBindTag::ALL
|
2000-01-17 03:37:53 -05:00
|
|
|
end
|
|
|
|
|
2003-06-16 03:14:50 -04:00
|
|
|
def bind_append_all(context, cmd=Proc.new, args=nil)
|
2000-01-17 03:37:53 -05:00
|
|
|
_bind_append(['bind', 'all'], context, cmd, args)
|
2003-06-18 15:46:20 -04:00
|
|
|
TkBindTag::ALL
|
|
|
|
end
|
|
|
|
|
|
|
|
def bind_remove_all(context)
|
|
|
|
_bind_remove(['bind', 'all'], context)
|
|
|
|
TkBindTag::ALL
|
2000-01-17 03:37:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def bindinfo_all(context=nil)
|
|
|
|
_bindinfo(['bind', 'all'], context)
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def pack(*args)
|
2002-03-08 02:03:09 -05:00
|
|
|
TkPack.configure(*args)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def grid(*args)
|
2002-03-08 02:03:09 -05:00
|
|
|
TkGrid.configure(*args)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def update(idle=nil)
|
|
|
|
if idle
|
|
|
|
tk_call 'update', 'idletasks'
|
|
|
|
else
|
|
|
|
tk_call 'update'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
module TkCore
|
|
|
|
include TkComm
|
|
|
|
extend TkComm
|
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
unless self.const_defined? :INTERP
|
|
|
|
if self.const_defined? :IP_NAME
|
|
|
|
name = IP_NAME.to_s
|
|
|
|
else
|
|
|
|
name = nil
|
|
|
|
end
|
|
|
|
if self.const_defined? :IP_OPTS
|
|
|
|
if IP_OPTS.kind_of?(Hash)
|
|
|
|
opts = hash_kv(IP_OPTS).join(' ')
|
|
|
|
else
|
|
|
|
opts = IP_OPTS.to_s
|
|
|
|
end
|
|
|
|
else
|
|
|
|
opts = ''
|
|
|
|
end
|
|
|
|
|
|
|
|
INTERP = TclTkIp.new(name, opts)
|
|
|
|
|
2003-07-25 12:43:03 -04:00
|
|
|
def INTERP.__getip
|
|
|
|
self
|
2003-07-23 12:07:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
INTERP.instance_eval{
|
2003-09-07 03:10:44 -04:00
|
|
|
@tk_cmd_tbl = {}.taint
|
|
|
|
@tk_windows = {}.taint
|
2003-07-23 12:07:35 -04:00
|
|
|
|
2003-09-07 03:10:44 -04:00
|
|
|
@tk_table_list = [].taint
|
2003-07-23 12:07:35 -04:00
|
|
|
|
2003-09-07 03:10:44 -04:00
|
|
|
@init_ip_env = [].taint # table of Procs
|
|
|
|
@add_tk_procs = [].taint # table of [name, args, body]
|
2003-07-25 12:43:03 -04:00
|
|
|
|
|
|
|
@cb_entry_class = Class.new{|c|
|
|
|
|
def initialize(ip, cmd)
|
|
|
|
@ip = ip
|
|
|
|
@cmd = cmd
|
|
|
|
end
|
|
|
|
attr_reader :ip, :cmd
|
|
|
|
def call(*args)
|
|
|
|
@ip.cb_eval(@cmd, *args)
|
|
|
|
end
|
|
|
|
}
|
2003-07-23 12:07:35 -04:00
|
|
|
}
|
2003-07-25 12:43:03 -04:00
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
def INTERP.tk_cmd_tbl
|
|
|
|
@tk_cmd_tbl
|
|
|
|
end
|
|
|
|
def INTERP.tk_windows
|
|
|
|
@tk_windows
|
|
|
|
end
|
|
|
|
|
|
|
|
def INTERP.tk_object_table(id)
|
|
|
|
@tk_table_list[id]
|
|
|
|
end
|
|
|
|
def INTERP.create_table
|
|
|
|
id = @tk_table_list.size
|
2003-09-07 03:10:44 -04:00
|
|
|
(tbl = {}).tainted? || tbl.taint
|
|
|
|
@tk_table_list << tbl
|
2003-07-23 12:07:35 -04:00
|
|
|
obj = Object.new
|
|
|
|
obj.instance_eval <<-EOD
|
|
|
|
def self.method_missing(m, *args)
|
|
|
|
TkCore::INTERP.tk_object_table(#{id}).send(m, *args)
|
|
|
|
end
|
|
|
|
EOD
|
|
|
|
return obj
|
|
|
|
end
|
|
|
|
|
2003-07-25 12:43:03 -04:00
|
|
|
def INTERP.get_cb_entry(cmd)
|
|
|
|
@cb_entry_class.new(__getip, cmd).freeze
|
|
|
|
end
|
|
|
|
def INTERP.cb_eval(cmd, *args)
|
|
|
|
TkComm._get_eval_string(TkUtil.eval_cmd(cmd, *args))
|
|
|
|
end
|
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
def INTERP.init_ip_env(script = Proc.new)
|
|
|
|
@init_ip_env << script
|
|
|
|
script.call(self)
|
|
|
|
end
|
2003-07-25 12:43:03 -04:00
|
|
|
def INTERP.add_tk_procs(name, args = nil, body = nil)
|
2003-07-23 12:07:35 -04:00
|
|
|
@add_tk_procs << [name, args, body]
|
2003-07-25 12:43:03 -04:00
|
|
|
self._invoke('proc', name, args, body) if args && body
|
2003-07-23 12:07:35 -04:00
|
|
|
end
|
|
|
|
def INTERP.init_ip_internal
|
|
|
|
ip = self
|
|
|
|
@init_ip_env.each{|script| script.call(ip)}
|
|
|
|
@add_tk_procs.each{|name,args,body| ip._invoke('proc',name,args,body)}
|
|
|
|
end
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
INTERP.add_tk_procs('rb_out', 'args', <<-'EOL')
|
2001-10-29 00:07:26 -05:00
|
|
|
regsub -all {!} $args {\\!} args
|
|
|
|
regsub -all "{" $args "\\{" args
|
|
|
|
if {[set st [catch {ruby [format "TkCore.callback %%Q!%s!" $args]} ret]] != 0} {
|
|
|
|
return -code $st $ret
|
|
|
|
} {
|
|
|
|
return $ret
|
|
|
|
}
|
|
|
|
EOL
|
1999-08-13 01:37:52 -04:00
|
|
|
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
EventFlag = TclTkLib::EventFlag
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def callback_break
|
2000-01-31 22:12:21 -05:00
|
|
|
fail TkCallbackBreak, "Tk callback returns 'break' status"
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def callback_continue
|
2000-01-31 22:12:21 -05:00
|
|
|
fail TkCallbackContinue, "Tk callback returns 'continue' status"
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2003-07-25 12:43:03 -04:00
|
|
|
def TkCore.callback(arg)
|
|
|
|
# arg = tk_split_list(arg)
|
|
|
|
arg = tk_split_simplelist(arg)
|
|
|
|
#_get_eval_string(TkUtil.eval_cmd(Tk_CMDTBL[arg.shift], *arg))
|
|
|
|
#_get_eval_string(TkUtil.eval_cmd(TkCore::INTERP.tk_cmd_tbl[arg.shift],
|
|
|
|
# *arg))
|
|
|
|
cb_obj = TkCore::INTERP.tk_cmd_tbl[arg.shift]
|
2003-10-16 10:53:47 -04:00
|
|
|
unless $DEBUG
|
|
|
|
cb_obj.call(*arg)
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
raise 'check backtrace'
|
|
|
|
rescue
|
|
|
|
# ignore backtrace before 'callback'
|
|
|
|
pos = -($!.backtrace.size)
|
|
|
|
end
|
|
|
|
begin
|
|
|
|
cb_obj.call(*arg)
|
|
|
|
rescue
|
|
|
|
trace = $!.backtrace
|
|
|
|
raise $!, "\n#{trace[0]}: #{$!.message} (#{$!.class})\n" +
|
|
|
|
"\tfrom #{trace[1..pos].join("\n\tfrom ")}"
|
|
|
|
end
|
|
|
|
end
|
2003-07-25 12:43:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def load_cmd_on_ip(tk_cmd)
|
|
|
|
bool(tk_call('auto_load', tk_cmd))
|
|
|
|
end
|
|
|
|
|
2003-06-16 03:14:50 -04:00
|
|
|
def after(ms, cmd=Proc.new)
|
1999-08-13 01:37:52 -04:00
|
|
|
myid = _curr_cmd_id
|
|
|
|
cmdid = install_cmd(cmd)
|
|
|
|
tk_call("after",ms,cmdid)
|
2002-03-08 02:03:09 -05:00
|
|
|
# return
|
|
|
|
# if false #defined? Thread
|
|
|
|
# Thread.start do
|
|
|
|
# ms = Float(ms)/1000
|
|
|
|
# ms = 10 if ms == 0
|
|
|
|
# sleep ms/1000
|
|
|
|
# cmd.call
|
|
|
|
# end
|
|
|
|
# else
|
|
|
|
# cmdid = install_cmd(cmd)
|
|
|
|
# tk_call("after",ms,cmdid)
|
|
|
|
# end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2003-06-16 03:14:50 -04:00
|
|
|
def after_idle(cmd=Proc.new)
|
2000-11-27 04:23:38 -05:00
|
|
|
myid = _curr_cmd_id
|
|
|
|
cmdid = install_cmd(cmd)
|
|
|
|
tk_call('after','idle',cmdid)
|
|
|
|
end
|
|
|
|
|
|
|
|
def clock_clicks(ms=nil)
|
|
|
|
if ms
|
|
|
|
tk_call('clock','clicks','-milliseconds').to_i
|
|
|
|
else
|
|
|
|
tk_call('clock','clicks').to_i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def clock_format(clk, form=nil)
|
|
|
|
if form
|
|
|
|
tk_call('clock','format',clk,'-format',form).to_i
|
|
|
|
else
|
|
|
|
tk_call('clock','format',clk).to_i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def clock_formatGMT(clk, form=nil)
|
|
|
|
if form
|
|
|
|
tk_call('clock','format',clk,'-format',form,'-gmt','1').to_i
|
|
|
|
else
|
|
|
|
tk_call('clock','format',clk,'-gmt','1').to_i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def clock_scan(str, base=nil)
|
|
|
|
if base
|
|
|
|
tk_call('clock','scan',str,'-base',base).to_i
|
|
|
|
else
|
|
|
|
tk_call('clock','scan',str).to_i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def clock_scanGMT(str, base=nil)
|
|
|
|
if base
|
|
|
|
tk_call('clock','scan',str,'-base',base,'-gmt','1').to_i
|
|
|
|
else
|
|
|
|
tk_call('clock','scan',str,'-gmt','1').to_i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def clock_seconds
|
|
|
|
tk_call('clock','seconds').to_i
|
|
|
|
end
|
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
def windowingsystem
|
|
|
|
tk_call('tk', 'windowingsystem')
|
|
|
|
end
|
|
|
|
|
2000-06-12 03:48:31 -04:00
|
|
|
def scaling(scale=nil)
|
|
|
|
if scale
|
|
|
|
tk_call('tk', 'scaling', scale)
|
|
|
|
else
|
|
|
|
Float(number(tk_call('tk', 'scaling')))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def scaling_displayof(win, scale=nil)
|
|
|
|
if scale
|
|
|
|
tk_call('tk', 'scaling', '-displayof', win, scale)
|
|
|
|
else
|
|
|
|
Float(number(tk_call('tk', '-displayof', win, 'scaling')))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def appname(name=None)
|
|
|
|
tk_call('tk', 'appname', name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def appsend(interp, async, *args)
|
|
|
|
if async
|
|
|
|
tk_call('send', '-async', '--', interp, *args)
|
|
|
|
else
|
|
|
|
tk_call('send', '--', interp, *args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def rb_appsend(interp, async, *args)
|
2003-03-21 23:31:24 -05:00
|
|
|
args = args.collect!{|c| _get_eval_string(c).gsub(/[\[\]$"]/, '\\\\\&')}
|
1999-08-13 01:37:52 -04:00
|
|
|
args.push(').to_s"')
|
|
|
|
appsend(interp, async, 'ruby "(', *args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def appsend_displayof(interp, win, async, *args)
|
|
|
|
win = '.' if win == nil
|
|
|
|
if async
|
|
|
|
tk_call('send', '-async', '-displayof', win, '--', interp, *args)
|
|
|
|
else
|
|
|
|
tk_call('send', '-displayor', win, '--', interp, *args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def rb_appsend_displayof(interp, win, async, *args)
|
2003-03-21 23:31:24 -05:00
|
|
|
args = args.collect!{|c| _get_eval_string(c).gsub(/[\[\]$"]/, '\\\\\&')}
|
1999-08-13 01:37:52 -04:00
|
|
|
args.push(').to_s"')
|
|
|
|
appsend_displayof(interp, win, async, 'ruby "(', *args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def info(*args)
|
|
|
|
tk_call('info', *args)
|
|
|
|
end
|
|
|
|
|
2003-08-29 04:34:14 -04:00
|
|
|
def mainloop(check_root = true)
|
|
|
|
TclTkLib.mainloop(check_root)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
def mainloop_watchdog(check_root = true)
|
2003-07-31 03:59:18 -04:00
|
|
|
# watchdog restarts mainloop when mainloop is dead
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
TclTkLib.mainloop_watchdog(check_root)
|
|
|
|
end
|
|
|
|
|
2003-06-19 12:14:43 -04:00
|
|
|
def do_one_event(flag = TclTkLib::EventFlag::ALL)
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
TclTkLib.do_one_event(flag)
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_eventloop_tick(timer_tick)
|
|
|
|
TclTkLib.set_eventloop_tick(timer_tick)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_eventloop_tick()
|
|
|
|
TclTkLib.get_eventloop_tick
|
|
|
|
end
|
|
|
|
|
2003-06-19 12:14:43 -04:00
|
|
|
def set_no_event_wait(wait)
|
|
|
|
TclTkLib.set_no_even_wait(wait)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_no_event_wait()
|
|
|
|
TclTkLib.get_no_eventloop_wait
|
|
|
|
end
|
|
|
|
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
def set_eventloop_weight(loop_max, no_event_tick)
|
|
|
|
TclTkLib.set_eventloop_weight(loop_max, no_event_tick)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_eventloop_weight()
|
|
|
|
TclTkLib.get_eventloop_weight
|
|
|
|
end
|
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
def restart(app_name = nil, keys = {})
|
|
|
|
TkCore::INTERP.init_ip_internal
|
2003-06-18 15:46:20 -04:00
|
|
|
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
tk_call('set', 'argv0', app_name) if app_name
|
2003-07-25 12:43:03 -04:00
|
|
|
if keys.kind_of?(Hash)
|
2003-07-23 12:07:35 -04:00
|
|
|
# tk_call('set', 'argc', keys.size * 2)
|
|
|
|
tk_call('set', 'argv', hash_kv(keys).join(' '))
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
|
|
|
INTERP.restart
|
2002-03-08 02:03:09 -05:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def event_generate(window, context, keys=nil)
|
|
|
|
window = window.path if window.kind_of? TkObject
|
|
|
|
if keys
|
|
|
|
tk_call('event', 'generate', window,
|
|
|
|
"<#{tk_event_sequence(context)}>", *hash_kv(keys))
|
|
|
|
else
|
|
|
|
tk_call('event', 'generate', window, "<#{tk_event_sequence(context)}>")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def messageBox(keys)
|
|
|
|
tk_call 'tk_messageBox', *hash_kv(keys)
|
|
|
|
end
|
|
|
|
|
2000-07-06 03:21:26 -04:00
|
|
|
def getOpenFile(keys = nil)
|
1999-08-13 01:37:52 -04:00
|
|
|
tk_call 'tk_getOpenFile', *hash_kv(keys)
|
|
|
|
end
|
|
|
|
|
2000-07-06 03:21:26 -04:00
|
|
|
def getSaveFile(keys = nil)
|
1999-08-13 01:37:52 -04:00
|
|
|
tk_call 'tk_getSaveFile', *hash_kv(keys)
|
|
|
|
end
|
2003-07-17 02:40:28 -04:00
|
|
|
|
2000-07-06 03:21:26 -04:00
|
|
|
def chooseColor(keys = nil)
|
1999-08-13 01:37:52 -04:00
|
|
|
tk_call 'tk_chooseColor', *hash_kv(keys)
|
|
|
|
end
|
|
|
|
|
2003-07-26 01:27:42 -04:00
|
|
|
def chooseDirectory(keys = nil)
|
|
|
|
tk_call 'tk_chooseDirectory', *hash_kv(keys)
|
|
|
|
end
|
|
|
|
|
2003-06-21 04:47:22 -04:00
|
|
|
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
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def tk_call(*args)
|
2002-03-08 02:03:09 -05:00
|
|
|
puts args.inspect if $DEBUG
|
2000-07-14 00:34:43 -04:00
|
|
|
args.collect! {|x|ruby2tcl(x)}
|
1999-08-13 01:37:52 -04:00
|
|
|
args.compact!
|
|
|
|
args.flatten!
|
2002-03-08 02:03:09 -05:00
|
|
|
print "=> ", args.join(" ").inspect, "\n" if $DEBUG
|
1999-08-13 01:37:52 -04:00
|
|
|
begin
|
2003-06-20 10:52:45 -04:00
|
|
|
# res = INTERP._invoke(*args).taint
|
2003-08-29 04:34:14 -04:00
|
|
|
res = INTERP._invoke(*args) # _invoke returns a TAINTED string
|
|
|
|
rescue NameError => err
|
|
|
|
# err = $!
|
1999-08-13 01:37:52 -04:00
|
|
|
begin
|
|
|
|
args.unshift "unknown"
|
2003-06-20 10:52:45 -04:00
|
|
|
#res = INTERP._invoke(*args).taint
|
2003-08-29 04:34:14 -04:00
|
|
|
res = INTERP._invoke(*args) # _invoke returns a TAINTED string
|
|
|
|
rescue StandardError => err2
|
|
|
|
fail err2 unless /^invalid command/ =~ err2
|
2000-01-31 22:12:21 -05:00
|
|
|
fail err
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if INTERP._return_value() != 0
|
|
|
|
fail RuntimeError, res, error_at
|
|
|
|
end
|
2002-03-08 02:03:09 -05:00
|
|
|
print "==> ", res.inspect, "\n" if $DEBUG
|
1999-08-13 01:37:52 -04:00
|
|
|
return res
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2001-03-27 02:10:58 -05:00
|
|
|
module TkPackage
|
|
|
|
include TkCore
|
|
|
|
extend TkPackage
|
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['package'.freeze].freeze
|
|
|
|
|
2001-05-30 05:10:30 -04:00
|
|
|
def add_path(path)
|
|
|
|
Tk::AUTO_PATH.value = Tk::AUTO_PATH.to_a << path
|
|
|
|
end
|
|
|
|
|
2001-03-27 02:10:58 -05:00
|
|
|
def forget(package)
|
|
|
|
tk_call('package', 'forget', package)
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def names
|
|
|
|
tk_split_simplelist(tk_call('package', 'names'))
|
|
|
|
end
|
|
|
|
|
|
|
|
def provide(package, version=nil)
|
|
|
|
if version
|
|
|
|
tk_call('package', 'provide', package, version)
|
|
|
|
nil
|
|
|
|
else
|
|
|
|
tk_call('package', 'provide', package)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def present(package, version=None)
|
|
|
|
tk_call('package', 'present', package, version)
|
|
|
|
end
|
|
|
|
|
|
|
|
def present_exact(package, version)
|
|
|
|
tk_call('package', 'present', '-exact', package, version)
|
|
|
|
end
|
|
|
|
|
|
|
|
def require(package, version=None)
|
|
|
|
tk_call('package', 'require', package, version)
|
|
|
|
end
|
|
|
|
|
|
|
|
def require_exact(package, version)
|
|
|
|
tk_call('package', 'require', '-exact', package, version)
|
|
|
|
end
|
|
|
|
|
|
|
|
def versions(package)
|
|
|
|
tk_split_simplelist(tk_call('package', 'versions', package))
|
|
|
|
end
|
|
|
|
|
|
|
|
def vcompare(version1, version2)
|
|
|
|
Integer(tk_call('package', 'vcompare', version1, version2))
|
|
|
|
end
|
|
|
|
|
|
|
|
def vsatisfies(version1, version2)
|
|
|
|
bool(tk_call('package', 'vsatisfies', version1, version2))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
module Tk
|
|
|
|
include TkCore
|
|
|
|
extend Tk
|
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
TCL_VERSION = INTERP._invoke("info", "tclversion").freeze
|
|
|
|
TCL_PATCHLEVEL = INTERP._invoke("info", "patchlevel").freeze
|
2003-10-14 11:25:45 -04:00
|
|
|
|
|
|
|
TK_VERSION = INTERP._invoke("set", "tk_version").freeze
|
2003-06-18 15:46:20 -04:00
|
|
|
TK_PATCHLEVEL = INTERP._invoke("set", "tk_patchLevel").freeze
|
2001-03-27 02:10:58 -05:00
|
|
|
|
2003-10-14 11:25:45 -04:00
|
|
|
JAPANIZED_TK = (INTERP._invoke("info", "commands", "kanji") != "").freeze
|
2001-03-27 02:10:58 -05:00
|
|
|
|
2003-10-14 11:25:45 -04:00
|
|
|
def Tk.const_missing(sym)
|
|
|
|
case(sym)
|
|
|
|
when :TCL_LIBRARY
|
|
|
|
INTERP._invoke("set", "tcl_library").freeze
|
|
|
|
|
|
|
|
when :TK_LIBRARY
|
|
|
|
INTERP._invoke("set", "tk_library").freeze
|
|
|
|
|
|
|
|
when :LIBRARY
|
|
|
|
INTERP._invoke("info", "library").freeze
|
|
|
|
|
|
|
|
#when :PKG_PATH, :PACKAGE_PATH, :TCL_PACKAGE_PATH
|
|
|
|
# tk_split_simplelist(INTERP._invoke('set', 'tcl_pkgPath'))
|
|
|
|
|
|
|
|
#when :LIB_PATH, :LIBRARY_PATH, :TCL_LIBRARY_PATH
|
|
|
|
# tk_split_simplelist(INTERP._invoke('set', 'tcl_libPath'))
|
|
|
|
|
|
|
|
when :PLATFORM, :TCL_PLATFORM
|
|
|
|
Hash[*tk_split_simplelist(INTERP._invoke('array', 'get',
|
|
|
|
'tcl_platform'))]
|
|
|
|
|
|
|
|
when :ENV
|
|
|
|
Hash[*tk_split_simplelist(INTERP._invoke('array', 'get', 'env'))]
|
|
|
|
|
|
|
|
#when :AUTO_PATH #<===
|
|
|
|
# tk_split_simplelist(INTERP._invoke('set', 'auto_path'))
|
|
|
|
|
|
|
|
#when :AUTO_OLDPATH
|
|
|
|
# tk_split_simplelist(INTERP._invoke('set', 'auto_oldpath'))
|
|
|
|
|
|
|
|
when :AUTO_INDEX
|
|
|
|
Hash[*tk_split_simplelist(INTERP._invoke('array', 'get', 'auto_index'))]
|
|
|
|
|
|
|
|
when :PRIV, :PRIVATE, :TK_PRIV
|
|
|
|
priv = {}
|
|
|
|
if INTERP._invoke('info', 'vars', 'tk::Priv') != ""
|
|
|
|
var_nam = 'tk::Priv'
|
|
|
|
else
|
|
|
|
var_nam = 'tkPriv'
|
|
|
|
end
|
|
|
|
Hash[*tk_split_simplelist(INTERP._invoke('array', 'get',
|
|
|
|
var_nam))].each{|k,v|
|
|
|
|
k.freeze
|
|
|
|
case v
|
|
|
|
when /^-?\d+$/
|
|
|
|
priv[k] = v.to_i
|
|
|
|
when /^-?\d+\.?\d*(e[-+]?\d+)?$/
|
|
|
|
priv[k] = v.to_f
|
|
|
|
else
|
|
|
|
priv[k] = v.freeze
|
|
|
|
end
|
|
|
|
}
|
|
|
|
priv
|
2001-03-27 02:10:58 -05:00
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
else
|
2003-10-14 11:25:45 -04:00
|
|
|
raise NameError, 'uninitialized constant Tk::' + sym.id2name
|
2003-06-18 15:46:20 -04:00
|
|
|
end
|
2003-10-14 11:25:45 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def root
|
|
|
|
TkRoot.new
|
|
|
|
end
|
|
|
|
|
2003-08-29 04:34:14 -04:00
|
|
|
def Tk.bell(nice = false)
|
2003-06-18 15:46:20 -04:00
|
|
|
if nice
|
|
|
|
tk_call 'bell', '-nice'
|
|
|
|
else
|
|
|
|
tk_call 'bell'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-08-29 04:34:14 -04:00
|
|
|
def Tk.bell_on_display(win, nice = false)
|
2003-06-18 15:46:20 -04:00
|
|
|
if nice
|
|
|
|
tk_call('bell', '-displayof', win, '-nice')
|
|
|
|
else
|
|
|
|
tk_call('bell', '-displayof', win)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def Tk.destroy(*wins)
|
|
|
|
tk_call('destroy', *wins)
|
|
|
|
end
|
|
|
|
|
2003-06-19 12:14:43 -04:00
|
|
|
def Tk.exit
|
|
|
|
tk_call('destroy', '.')
|
|
|
|
end
|
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
def Tk.current_grabs
|
|
|
|
tk_split_list(tk_call('grab', 'current'))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def Tk.focus(display=nil)
|
|
|
|
if display == nil
|
2003-06-18 15:46:20 -04:00
|
|
|
window(tk_call('focus'))
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
2003-06-18 15:46:20 -04:00
|
|
|
window(tk_call('focus', '-displayof', display))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def Tk.focus_lastfor(win)
|
2003-06-18 15:46:20 -04:00
|
|
|
window(tk_call('focus', '-lastfor', win))
|
|
|
|
end
|
|
|
|
|
|
|
|
def Tk.focus_next(win)
|
|
|
|
TkManageFocus.next(win)
|
|
|
|
end
|
|
|
|
|
|
|
|
def Tk.focus_prev(win)
|
|
|
|
TkManageFocus.prev(win)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2001-03-27 02:10:58 -05:00
|
|
|
def Tk.strictMotif(bool=None)
|
|
|
|
bool(tk_call('set', 'tk_strictMotif', bool))
|
|
|
|
end
|
|
|
|
|
2000-06-13 05:57:40 -04:00
|
|
|
def Tk.show_kinsoku(mode='both')
|
|
|
|
begin
|
|
|
|
if /^8\.*/ === TK_VERSION && JAPANIZED_TK
|
|
|
|
tk_split_simplelist(tk_call('kinsoku', 'show', mode))
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def Tk.add_kinsoku(chars, mode='both')
|
|
|
|
begin
|
|
|
|
if /^8\.*/ === TK_VERSION && JAPANIZED_TK
|
|
|
|
tk_split_simplelist(tk_call('kinsoku', 'add', mode,
|
|
|
|
*(chars.split(''))))
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def Tk.delete_kinsoku(chars, mode='both')
|
|
|
|
begin
|
|
|
|
if /^8\.*/ === TK_VERSION && JAPANIZED_TK
|
|
|
|
tk_split_simplelist(tk_call('kinsoku', 'delete', mode,
|
|
|
|
*(chars.split(''))))
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2001-03-27 02:10:58 -05:00
|
|
|
def Tk.toUTF8(str,encoding)
|
1999-08-13 01:37:52 -04:00
|
|
|
INTERP._toUTF8(str,encoding)
|
|
|
|
end
|
|
|
|
|
2001-03-27 02:10:58 -05:00
|
|
|
def Tk.fromUTF8(str,encoding)
|
1999-08-13 01:37:52 -04:00
|
|
|
INTERP._fromUTF8(str,encoding)
|
|
|
|
end
|
|
|
|
|
|
|
|
module Scrollable
|
2003-06-16 03:14:50 -04:00
|
|
|
def xscrollcommand(cmd=Proc.new)
|
1999-08-13 01:37:52 -04:00
|
|
|
configure_cmd 'xscrollcommand', cmd
|
|
|
|
end
|
2003-06-16 03:14:50 -04:00
|
|
|
def yscrollcommand(cmd=Proc.new)
|
1999-08-13 01:37:52 -04:00
|
|
|
configure_cmd 'yscrollcommand', cmd
|
|
|
|
end
|
2000-01-31 22:12:21 -05:00
|
|
|
def xview(*index)
|
|
|
|
v = tk_send('xview', *index)
|
|
|
|
list(v) if index.size == 0
|
|
|
|
end
|
|
|
|
def yview(*index)
|
|
|
|
v = tk_send('yview', *index)
|
|
|
|
list(v) if index.size == 0
|
|
|
|
end
|
|
|
|
def xscrollbar(bar=nil)
|
|
|
|
if bar
|
|
|
|
@xscrollbar = bar
|
|
|
|
@xscrollbar.orient 'horizontal'
|
2003-07-29 04:05:30 -04:00
|
|
|
self.xscrollcommand {|*arg| @xscrollbar.set(*arg)}
|
|
|
|
@xscrollbar.command {|*arg| self.xview(*arg)}
|
2000-01-31 22:12:21 -05:00
|
|
|
end
|
|
|
|
@xscrollbar
|
|
|
|
end
|
|
|
|
def yscrollbar(bar=nil)
|
|
|
|
if bar
|
|
|
|
@yscrollbar = bar
|
|
|
|
@yscrollbar.orient 'vertical'
|
2003-07-29 04:05:30 -04:00
|
|
|
self.yscrollcommand {|*arg| @yscrollbar.set(*arg)}
|
|
|
|
@yscrollbar.command {|*arg| self.yview(*arg)}
|
2000-01-31 22:12:21 -05:00
|
|
|
end
|
|
|
|
@yscrollbar
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
module Wm
|
|
|
|
include TkComm
|
2003-07-23 12:07:35 -04:00
|
|
|
|
|
|
|
TkCommandNames = ['wm'.freeze].freeze
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def aspect(*args)
|
2000-01-17 03:37:53 -05:00
|
|
|
w = tk_call('wm', 'aspect', path, *args)
|
2003-06-18 15:46:20 -04:00
|
|
|
if args.length == 0
|
|
|
|
list(w)
|
|
|
|
else
|
|
|
|
self
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def attributes(slot=nil,value=None)
|
|
|
|
if slot == nil
|
|
|
|
lst = tk_split_list(tk_call('wm', 'attributes', path))
|
|
|
|
info = {}
|
|
|
|
while key = lst.shift
|
|
|
|
info[key[1..-1]] = lst.shift
|
|
|
|
end
|
|
|
|
info
|
|
|
|
elsif slot.kind_of? Hash
|
|
|
|
tk_call('wm', 'attributes', path, *hash_kv(slot))
|
|
|
|
self
|
|
|
|
elsif value == None
|
|
|
|
tk_call('wm', 'attributes', path, "-#{slot}")
|
|
|
|
else
|
|
|
|
tk_call('wm', 'attributes', path, "-#{slot}", value)
|
|
|
|
self
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def client(name=None)
|
2003-06-18 15:46:20 -04:00
|
|
|
if name == None
|
|
|
|
tk_call 'wm', 'client', path
|
|
|
|
else
|
|
|
|
name = '' if name == nil
|
|
|
|
tk_call 'wm', 'client', path, name
|
|
|
|
self
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def colormapwindows(*args)
|
2003-06-18 15:46:20 -04:00
|
|
|
r = tk_call('wm', 'colormapwindows', path, *args)
|
|
|
|
if args.size == 0
|
|
|
|
list(r)
|
|
|
|
else
|
|
|
|
self
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def wm_command(value=nil)
|
|
|
|
if value
|
|
|
|
tk_call('wm', 'command', path, value)
|
|
|
|
self
|
|
|
|
else
|
|
|
|
procedure(tk_call('wm', 'command', path))
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-23 10:22:44 -04:00
|
|
|
def deiconify(ex = true)
|
|
|
|
tk_call('wm', 'deiconify', path) if ex
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def focusmodel(mode = nil)
|
|
|
|
if mode
|
|
|
|
tk_call 'wm', 'focusmodel', path, mode
|
|
|
|
self
|
|
|
|
else
|
|
|
|
tk_call 'wm', 'focusmodel', path
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def frame
|
2000-01-17 03:37:53 -05:00
|
|
|
tk_call('wm', 'frame', path)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-09-01 05:02:43 -04:00
|
|
|
def geometry(geom=nil)
|
2003-06-18 15:46:20 -04:00
|
|
|
if geom
|
|
|
|
tk_call('wm', 'geometry', path, geom)
|
|
|
|
self
|
|
|
|
else
|
|
|
|
tk_call('wm', 'geometry', path)
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def grid(*args)
|
|
|
|
w = tk_call('wm', 'grid', path, *args)
|
2003-06-18 15:46:20 -04:00
|
|
|
if args.size == 0
|
|
|
|
list(w)
|
|
|
|
else
|
|
|
|
self
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def group(*args)
|
2003-10-16 13:47:19 -04:00
|
|
|
w = tk_call('wm', 'group', path, *args)
|
2003-06-18 15:46:20 -04:00
|
|
|
if args.size == 0
|
|
|
|
window(w)
|
|
|
|
else
|
|
|
|
self
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def iconbitmap(bmp=nil)
|
|
|
|
if bmp
|
|
|
|
tk_call 'wm', 'iconbitmap', path, bmp
|
|
|
|
self
|
|
|
|
else
|
|
|
|
tk_call 'wm', 'iconbitmap', path
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-23 10:22:44 -04:00
|
|
|
def iconify(ex = true)
|
|
|
|
tk_call('wm', 'iconify', path) if ex
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def iconmask(bmp=nil)
|
|
|
|
if bmp
|
|
|
|
tk_call 'wm', 'iconmask', path, bmp
|
|
|
|
self
|
|
|
|
else
|
|
|
|
tk_call 'wm', 'iconmask', path
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def iconname(name=nil)
|
|
|
|
if name
|
|
|
|
tk_call 'wm', 'iconname', path, name
|
|
|
|
self
|
|
|
|
else
|
|
|
|
tk_call 'wm', 'iconname', path
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def iconposition(*args)
|
|
|
|
w = tk_call('wm', 'iconposition', path, *args)
|
2003-06-18 15:46:20 -04:00
|
|
|
if args.size == 0
|
|
|
|
list(w)
|
|
|
|
else
|
|
|
|
self
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def iconwindow(*args)
|
|
|
|
w = tk_call('wm', 'iconwindow', path, *args)
|
2003-06-18 15:46:20 -04:00
|
|
|
if args.size == 0
|
|
|
|
window(w)
|
|
|
|
else
|
|
|
|
self
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def maxsize(*args)
|
|
|
|
w = tk_call('wm', 'maxsize', path, *args)
|
2003-06-18 15:46:20 -04:00
|
|
|
if args.size == 0
|
|
|
|
list(w)
|
|
|
|
else
|
|
|
|
self
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def minsize(*args)
|
|
|
|
w = tk_call('wm', 'minsize', path, *args)
|
2003-06-18 15:46:20 -04:00
|
|
|
if args.size == 0
|
|
|
|
list(w)
|
|
|
|
else
|
|
|
|
self
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def overrideredirect(bool=None)
|
|
|
|
if bool == None
|
|
|
|
bool(tk_call('wm', 'overrideredirect', path))
|
|
|
|
else
|
|
|
|
tk_call 'wm', 'overrideredirect', path, bool
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def positionfrom(who=None)
|
|
|
|
if who == None
|
|
|
|
r = tk_call('wm', 'positionfrom', path)
|
|
|
|
(r == "")? nil: r
|
|
|
|
else
|
|
|
|
tk_call('wm', 'positionfrom', path, who)
|
|
|
|
self
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def protocol(name=nil, cmd=nil)
|
|
|
|
if cmd
|
|
|
|
tk_call('wm', 'protocol', path, name, cmd)
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
elsif name
|
|
|
|
result = tk_call('wm', 'protocol', path, name)
|
|
|
|
(result == "")? nil : tk_tcl2ruby(result)
|
|
|
|
else
|
|
|
|
tk_split_simplelist(tk_call('wm', 'protocol', path))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def resizable(*args)
|
|
|
|
w = tk_call('wm', 'resizable', path, *args)
|
|
|
|
if args.length == 0
|
|
|
|
list(w).collect{|e| bool(e)}
|
2003-06-18 15:46:20 -04:00
|
|
|
else
|
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def sizefrom(who=None)
|
|
|
|
if who == None
|
|
|
|
r = tk_call('wm', 'sizefrom', path)
|
|
|
|
(r == "")? nil: r
|
|
|
|
else
|
|
|
|
tk_call('wm', 'sizefrom', path, who)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def stackorder
|
|
|
|
list(tk_call('wm', 'stackorder', path))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def stackorder_isabove(win)
|
|
|
|
bool(tk_call('wm', 'stackorder', path, 'isabove', win))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def stackorder_isbelow(win)
|
|
|
|
bool(tk_call('wm', 'stackorder', path, 'isbelow', win))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def state(state=nil)
|
|
|
|
if state
|
|
|
|
tk_call 'wm', 'state', path, state
|
|
|
|
self
|
|
|
|
else
|
|
|
|
tk_call 'wm', 'state', path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def title(str=nil)
|
|
|
|
if str
|
|
|
|
tk_call('wm', 'title', path, str)
|
|
|
|
self
|
|
|
|
else
|
|
|
|
tk_call('wm', 'title', path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def transient(master=nil)
|
|
|
|
if master
|
|
|
|
tk_call('wm', 'transient', path, master)
|
|
|
|
self
|
|
|
|
else
|
|
|
|
window(tk_call('wm', 'transient', path, master))
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-23 10:22:44 -04:00
|
|
|
def withdraw(ex = true)
|
|
|
|
tk_call('wm', 'withdraw', path) if ex
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-10-16 03:45:51 -04:00
|
|
|
###########################################
|
|
|
|
# string with Tcl's encoding
|
|
|
|
###########################################
|
|
|
|
module Tk
|
|
|
|
class EncodedString < String
|
|
|
|
@@enc_buf = '__rb_encoding_buffer__'
|
|
|
|
|
|
|
|
def self.tk_escape(str)
|
|
|
|
s = '"' + str.gsub(/[\[\]$"]/, '\\\\\&') + '"'
|
2003-12-02 23:55:07 -05:00
|
|
|
TkCore::INTERP.__eval(Kernel.format('global %s; set %s %s',
|
|
|
|
@@enc_buf, @@enc_buf, s))
|
2003-10-16 03:45:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.new(str, enc = Tk.encoding_system)
|
|
|
|
obj = super(self.tk_escape(str))
|
|
|
|
obj.instance_eval{@enc = enc}
|
|
|
|
obj
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.new_without_escape(str, enc = Tk.encoding_system)
|
|
|
|
obj = super(str)
|
|
|
|
obj.instance_eval{@enc = enc}
|
|
|
|
obj
|
|
|
|
end
|
|
|
|
|
|
|
|
def encoding
|
|
|
|
@enc
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def Tk.EncodedString(str, enc = Tk.encoding_system)
|
|
|
|
Tk::EncodedString.new(str, enc)
|
|
|
|
end
|
|
|
|
|
|
|
|
class UTF8_String < EncodedString
|
|
|
|
def self.new(str)
|
|
|
|
super(str, 'utf-8')
|
|
|
|
end
|
2003-10-17 03:59:32 -04:00
|
|
|
def self.new_without_escape(str)
|
|
|
|
super(str, 'utf-8')
|
|
|
|
end
|
2003-10-16 03:45:51 -04:00
|
|
|
end
|
|
|
|
def Tk.UTF8_String(str)
|
|
|
|
Tk::UTF8_String.new(str)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2000-08-02 00:54:21 -04:00
|
|
|
###########################################
|
|
|
|
# convert kanji string to/from utf-8
|
|
|
|
###########################################
|
|
|
|
if /^8\.[1-9]/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK
|
|
|
|
class TclTkIp
|
|
|
|
# from tkencoding.rb by ttate@jaist.ac.jp
|
|
|
|
alias __eval _eval
|
|
|
|
alias __invoke _invoke
|
|
|
|
|
|
|
|
attr_accessor :encoding
|
|
|
|
|
|
|
|
def _eval(cmd)
|
2003-07-17 01:23:54 -04:00
|
|
|
if defined? @encoding
|
2003-10-16 03:45:51 -04:00
|
|
|
if cmd.kind_of?(Tk::EncodedString)
|
|
|
|
_fromUTF8(__eval(_toUTF8(cmd, cmd.encoding)), @encoding)
|
|
|
|
else
|
|
|
|
_fromUTF8(__eval(_toUTF8(cmd, @encoding)), @encoding)
|
|
|
|
end
|
2000-08-02 00:54:21 -04:00
|
|
|
else
|
|
|
|
__eval(cmd)
|
|
|
|
end
|
|
|
|
end
|
2003-07-31 19:04:45 -04:00
|
|
|
|
2000-08-02 00:54:21 -04:00
|
|
|
def _invoke(*cmds)
|
2003-07-17 01:23:54 -04:00
|
|
|
if defined? @encoding
|
2003-10-16 03:45:51 -04:00
|
|
|
cmds = cmds.collect{|cmd|
|
|
|
|
if cmd.kind_of?(Tk::EncodedString)
|
|
|
|
_toUTF8(cmd, cmd.encoding)
|
|
|
|
else
|
|
|
|
_toUTF8(cmd, @encoding)
|
|
|
|
end
|
|
|
|
}
|
2000-08-02 00:54:21 -04:00
|
|
|
_fromUTF8(__invoke(*cmds), @encoding)
|
|
|
|
else
|
|
|
|
__invoke(*cmds)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module Tk
|
2003-07-23 12:07:35 -04:00
|
|
|
module Encoding
|
|
|
|
extend Encoding
|
2000-08-02 00:54:21 -04:00
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['encoding'.freeze].freeze
|
2000-08-02 00:54:21 -04:00
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
def encoding=(name)
|
2003-07-25 12:43:03 -04:00
|
|
|
TkCore::INTERP.encoding = name
|
2003-07-23 12:07:35 -04:00
|
|
|
end
|
2000-08-02 00:54:21 -04:00
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
def encoding
|
2003-07-25 12:43:03 -04:00
|
|
|
TkCore::INTERP.encoding
|
2003-07-23 12:07:35 -04:00
|
|
|
end
|
2000-08-02 00:54:21 -04:00
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
def encoding_names
|
|
|
|
tk_split_simplelist(tk_call('encoding', 'names'))
|
|
|
|
end
|
|
|
|
|
|
|
|
def encoding_system
|
|
|
|
tk_call('encoding', 'system')
|
|
|
|
end
|
|
|
|
|
|
|
|
def encoding_system=(enc)
|
|
|
|
tk_call('encoding', 'system', enc)
|
|
|
|
end
|
2003-07-31 19:04:45 -04:00
|
|
|
|
|
|
|
def encoding_convertfrom(str, enc=None)
|
|
|
|
TkCore::INTERP.__invoke('encoding', 'convertfrom', enc, str)
|
|
|
|
end
|
|
|
|
alias encoding_convert_from encoding_convertfrom
|
|
|
|
|
|
|
|
def encoding_convertto(str, enc=None)
|
|
|
|
TkCore::INTERP.__invoke('encoding', 'convertto', enc, str)
|
|
|
|
end
|
|
|
|
alias encoding_convert_to encoding_convertto
|
2000-08-02 00:54:21 -04:00
|
|
|
end
|
2003-07-23 12:07:35 -04:00
|
|
|
|
|
|
|
extend Encoding
|
2000-08-02 00:54:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# estimate encoding
|
|
|
|
case $KCODE
|
|
|
|
when /^e/i # EUC
|
|
|
|
Tk.encoding = 'euc-jp'
|
|
|
|
when /^s/i # SJIS
|
|
|
|
Tk.encoding = 'shiftjis'
|
|
|
|
when /^u/i # UTF8
|
|
|
|
Tk.encoding = 'utf-8'
|
|
|
|
else # NONE
|
|
|
|
begin
|
|
|
|
Tk.encoding = Tk.encoding_system
|
|
|
|
rescue StandardError, NameError
|
|
|
|
Tk.encoding = 'utf-8'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
# dummy methods
|
2003-07-31 19:04:45 -04:00
|
|
|
class TclTkIp
|
|
|
|
alias __eval _eval
|
|
|
|
alias __invoke _invoke
|
|
|
|
end
|
|
|
|
|
2000-08-02 00:54:21 -04:00
|
|
|
module Tk
|
2003-07-23 12:07:35 -04:00
|
|
|
module Encoding
|
|
|
|
extend Encoding
|
|
|
|
|
|
|
|
def encoding=(name)
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
def encoding
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
def encoding_names
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
def encoding_system
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
def encoding_system=(enc)
|
|
|
|
nil
|
|
|
|
end
|
2003-07-31 19:04:45 -04:00
|
|
|
|
|
|
|
def encoding_convertfrom(str, enc=None)
|
|
|
|
str
|
|
|
|
end
|
|
|
|
alias encoding_convert_from encoding_convertfrom
|
|
|
|
|
|
|
|
def encoding_convertto(str, enc=None)
|
|
|
|
str
|
|
|
|
end
|
|
|
|
alias encoding_convert_to encoding_convertto
|
2000-08-02 00:54:21 -04:00
|
|
|
end
|
2003-07-23 12:07:35 -04:00
|
|
|
|
|
|
|
extend Encoding
|
2000-08-02 00:54:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2000-01-17 03:37:53 -05:00
|
|
|
module TkBindCore
|
2003-06-16 03:14:50 -04:00
|
|
|
def bind(context, cmd=Proc.new, args=nil)
|
2003-06-18 15:46:20 -04:00
|
|
|
Tk.bind(self, context, cmd, args)
|
2000-01-17 03:37:53 -05:00
|
|
|
end
|
|
|
|
|
2003-06-16 03:14:50 -04:00
|
|
|
def bind_append(context, cmd=Proc.new, args=nil)
|
2003-06-18 15:46:20 -04:00
|
|
|
Tk.bind_append(self, context, cmd, args)
|
2000-01-17 03:37:53 -05:00
|
|
|
end
|
|
|
|
|
2000-04-10 01:57:37 -04:00
|
|
|
def bind_remove(context)
|
2003-06-18 15:46:20 -04:00
|
|
|
Tk.bind_remove(self, context)
|
2000-04-10 01:57:37 -04:00
|
|
|
end
|
|
|
|
|
2000-01-17 03:37:53 -05:00
|
|
|
def bindinfo(context=nil)
|
2003-06-18 15:46:20 -04:00
|
|
|
Tk.bindinfo(self, context)
|
2000-01-17 03:37:53 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TkBindTag
|
|
|
|
include TkBindCore
|
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
#BTagID_TBL = {}
|
|
|
|
BTagID_TBL = TkCore::INTERP.create_table
|
2003-09-07 03:10:44 -04:00
|
|
|
Tk_BINDTAG_ID = ["btag".freeze, "00000".taint].freeze
|
2003-06-18 15:46:20 -04:00
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCore::INTERP.init_ip_env{ BTagID_TBL.clear }
|
2003-06-18 15:46:20 -04:00
|
|
|
|
2000-01-17 03:37:53 -05:00
|
|
|
def TkBindTag.id2obj(id)
|
|
|
|
BTagID_TBL[id]? BTagID_TBL[id]: id
|
|
|
|
end
|
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
def TkBindTag.new_by_name(name, *args, &b)
|
|
|
|
return BTagID_TBL[name] if BTagID_TBL[name]
|
|
|
|
self.new(*args, &b).instance_eval{
|
|
|
|
BTagID_TBL.delete @id
|
|
|
|
@id = name
|
|
|
|
BTagID_TBL[@id] = self
|
|
|
|
}
|
|
|
|
end
|
2001-05-06 11:06:00 -04:00
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
def initialize(*args, &b)
|
2003-07-23 12:07:35 -04:00
|
|
|
@id = Tk_BINDTAG_ID.join
|
|
|
|
Tk_BINDTAG_ID[1].succ!
|
2000-01-17 03:37:53 -05:00
|
|
|
BTagID_TBL[@id] = self
|
2003-06-18 15:46:20 -04:00
|
|
|
bind(*args, &b) if args != []
|
2000-01-17 03:37:53 -05:00
|
|
|
end
|
|
|
|
|
2003-07-17 01:23:54 -04:00
|
|
|
ALL = self.new_by_name('all')
|
|
|
|
|
2003-06-25 10:40:32 -04:00
|
|
|
def name
|
|
|
|
@id
|
|
|
|
end
|
|
|
|
|
2000-01-17 03:37:53 -05:00
|
|
|
def to_eval
|
|
|
|
@id
|
|
|
|
end
|
|
|
|
|
|
|
|
def inspect
|
2003-12-02 23:55:07 -05:00
|
|
|
Kernel.format "#<TkBindTag: %s>", @id
|
2000-01-17 03:37:53 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2000-06-12 03:48:31 -04:00
|
|
|
class TkBindTagAll<TkBindTag
|
2003-06-18 15:46:20 -04:00
|
|
|
def TkBindTagAll.new(*args, &b)
|
2001-05-06 11:06:00 -04:00
|
|
|
$stderr.puts "Warning: TkBindTagALL is obsolete. Use TkBindTag::ALL\n"
|
2000-06-12 03:48:31 -04:00
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
TkBindTag::ALL.bind(*args, &b) if args != []
|
2001-05-06 11:06:00 -04:00
|
|
|
TkBindTag::ALL
|
2000-06-12 03:48:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
class TkDatabaseClass<TkBindTag
|
|
|
|
def self.new(name, *args, &b)
|
|
|
|
return BTagID_TBL[name] if BTagID_TBL[name]
|
|
|
|
super(name, *args, &b)
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(name, *args, &b)
|
|
|
|
@id = name
|
|
|
|
BTagID_TBL[@id] = self
|
|
|
|
bind(*args, &b) if args != []
|
|
|
|
end
|
|
|
|
|
|
|
|
def inspect
|
2003-12-02 23:55:07 -05:00
|
|
|
Kernel.format "#<TkDatabaseClass: %s>", @id
|
2003-06-18 15:46:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
class TkVariable
|
|
|
|
include Tk
|
|
|
|
extend TkCore
|
|
|
|
|
2003-08-29 04:34:14 -04:00
|
|
|
include Comparable
|
|
|
|
|
2003-10-14 11:25:45 -04:00
|
|
|
#TkCommandNames = ['tkwait'.freeze].freeze
|
|
|
|
TkCommandNames = ['vwait'.freeze].freeze
|
1999-08-13 01:37:52 -04:00
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
#TkVar_CB_TBL = {}
|
|
|
|
#TkVar_ID_TBL = {}
|
|
|
|
TkVar_CB_TBL = TkCore::INTERP.create_table
|
|
|
|
TkVar_ID_TBL = TkCore::INTERP.create_table
|
2003-09-07 03:10:44 -04:00
|
|
|
Tk_VARIABLE_ID = ["v".freeze, "00000".taint].freeze
|
2003-06-21 04:47:22 -04:00
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCore::INTERP.add_tk_procs('rb_var', 'args',
|
|
|
|
"ruby [format \"TkVariable.callback %%Q!%s!\" $args]")
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkVariable.callback(args)
|
|
|
|
name1,name2,op = tk_split_list(args)
|
|
|
|
if TkVar_CB_TBL[name1]
|
|
|
|
_get_eval_string(TkVar_CB_TBL[name1].trace_callback(name2,op))
|
|
|
|
else
|
|
|
|
''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(val="")
|
2003-07-23 12:07:35 -04:00
|
|
|
@id = Tk_VARIABLE_ID.join
|
|
|
|
Tk_VARIABLE_ID[1].succ!
|
2003-06-18 15:46:20 -04:00
|
|
|
TkVar_ID_TBL[@id] = self
|
2003-07-30 03:15:00 -04:00
|
|
|
|
|
|
|
@trace_var = nil
|
|
|
|
@trace_elem = nil
|
|
|
|
@trace_opts = nil
|
|
|
|
|
2003-08-29 04:34:14 -04:00
|
|
|
=begin
|
1999-08-13 01:37:52 -04:00
|
|
|
if val == []
|
2003-08-29 04:34:14 -04:00
|
|
|
# INTERP._eval(format('global %s; set %s(0) 0; unset %s(0)',
|
|
|
|
# @id, @id, @id))
|
1999-08-13 01:37:52 -04:00
|
|
|
elsif val.kind_of?(Array)
|
|
|
|
a = []
|
2003-08-29 04:34:14 -04:00
|
|
|
# val.each_with_index{|e,i| a.push(i); a.push(array2tk_list(e))}
|
|
|
|
# s = '"' + a.join(" ").gsub(/[\[\]$"]/, '\\\\\&') + '"'
|
|
|
|
val.each_with_index{|e,i| a.push(i); a.push(e)}
|
|
|
|
s = '"' + array2tk_list(a).gsub(/[\[\]$"]/, '\\\\\&') + '"'
|
1999-08-13 01:37:52 -04:00
|
|
|
INTERP._eval(format('global %s; array set %s %s', @id, @id, s))
|
|
|
|
elsif val.kind_of?(Hash)
|
|
|
|
s = '"' + val.to_a.collect{|e| array2tk_list(e)}.join(" ")\
|
2003-03-21 23:31:24 -05:00
|
|
|
.gsub(/[\[\]$"]/, '\\\\\&') + '"'
|
1999-08-13 01:37:52 -04:00
|
|
|
INTERP._eval(format('global %s; array set %s %s', @id, @id, s))
|
|
|
|
else
|
2003-03-21 23:31:24 -05:00
|
|
|
s = '"' + _get_eval_string(val).gsub(/[\[\]$"]/, '\\\\\&') + '"'
|
1999-08-13 01:37:52 -04:00
|
|
|
INTERP._eval(format('global %s; set %s %s', @id, @id, s))
|
|
|
|
end
|
2003-08-29 04:34:14 -04:00
|
|
|
=end
|
|
|
|
if val.kind_of?(Hash)
|
|
|
|
s = '"' + val.to_a.collect{|e| array2tk_list(e)}.join(" ")\
|
|
|
|
.gsub(/[\[\]$"]/, '\\\\\&') + '"'
|
2003-12-02 23:55:07 -05:00
|
|
|
INTERP._eval(Kernel.format('global %s; array set %s %s', @id, @id, s))
|
2003-08-29 04:34:14 -04:00
|
|
|
else
|
|
|
|
s = '"' + _get_eval_string(val).gsub(/[\[\]$"]/, '\\\\\&') + '"'
|
2003-12-02 23:55:07 -05:00
|
|
|
INTERP._eval(Kernel.format('global %s; set %s %s', @id, @id, s))
|
2003-08-29 04:34:14 -04:00
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2003-10-14 11:25:45 -04:00
|
|
|
def wait(on_thread = false, check_root = false)
|
|
|
|
if $SAFE >= 4
|
|
|
|
fail SecurityError, "can't wait variable at $SAFE >= 4"
|
|
|
|
end
|
|
|
|
if on_thread
|
|
|
|
if check_root
|
|
|
|
INTERP._thread_tkwait('variable', @id)
|
|
|
|
else
|
|
|
|
INTERP._thread_vwait(@id)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if check_root
|
|
|
|
INTERP._invoke('tkwait', 'variable', @id)
|
|
|
|
else
|
|
|
|
INTERP._invoke('vwait', @id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def eventloop_wait(check_root = false)
|
|
|
|
wait(false, check_root)
|
|
|
|
end
|
|
|
|
def thread_wait(check_root = false)
|
|
|
|
wait(true, check_root)
|
|
|
|
end
|
|
|
|
def tkwait(on_thread = true)
|
|
|
|
wait(on_thread, true)
|
|
|
|
end
|
|
|
|
def eventloop_tkwait
|
|
|
|
wait(false, true)
|
|
|
|
end
|
|
|
|
def thread_tkwait
|
|
|
|
wait(true, true)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def id
|
|
|
|
@id
|
|
|
|
end
|
|
|
|
|
|
|
|
def value
|
|
|
|
begin
|
2003-12-02 23:55:07 -05:00
|
|
|
INTERP._eval(Kernel.format('global %s; set %s', @id, @id))
|
1999-08-13 01:37:52 -04:00
|
|
|
rescue
|
2003-12-02 23:55:07 -05:00
|
|
|
if INTERP._eval(Kernel.format('global %s; array exists %s',
|
|
|
|
@id, @id)) != "1"
|
2000-01-31 22:12:21 -05:00
|
|
|
fail
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
2003-12-02 23:55:07 -05:00
|
|
|
Hash[*tk_split_simplelist(INTERP._eval(Kernel.format('global %s; array get %s', @id, @id)))]
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def value=(val)
|
|
|
|
begin
|
2003-03-21 23:31:24 -05:00
|
|
|
s = '"' + _get_eval_string(val).gsub(/[\[\]$"]/, '\\\\\&') + '"'
|
2003-12-02 23:55:07 -05:00
|
|
|
INTERP._eval(Kernel.format('global %s; set %s %s', @id, @id, s))
|
1999-08-13 01:37:52 -04:00
|
|
|
rescue
|
2003-12-02 23:55:07 -05:00
|
|
|
if INTERP._eval(Kernel.format('global %s; array exists %s',
|
|
|
|
@id, @id)) != "1"
|
2000-01-31 22:12:21 -05:00
|
|
|
fail
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
|
|
|
if val == []
|
2003-12-02 23:55:07 -05:00
|
|
|
INTERP._eval(Kernel.format('global %s; unset %s; set %s(0) 0; unset %s(0)', @id, @id, @id, @id))
|
1999-08-13 01:37:52 -04:00
|
|
|
elsif val.kind_of?(Array)
|
|
|
|
a = []
|
|
|
|
val.each_with_index{|e,i| a.push(i); a.push(array2tk_list(e))}
|
2003-03-21 23:31:24 -05:00
|
|
|
s = '"' + a.join(" ").gsub(/[\[\]$"]/, '\\\\\&') + '"'
|
2003-12-02 23:55:07 -05:00
|
|
|
INTERP._eval(Kernel.format('global %s; unset %s; array set %s %s',
|
|
|
|
@id, @id, @id, s))
|
1999-08-13 01:37:52 -04:00
|
|
|
elsif val.kind_of?(Hash)
|
|
|
|
s = '"' + val.to_a.collect{|e| array2tk_list(e)}.join(" ")\
|
2003-03-21 23:31:24 -05:00
|
|
|
.gsub(/[\[\]$"]/, '\\\\\&') + '"'
|
2003-12-02 23:55:07 -05:00
|
|
|
INTERP._eval(Kernel.format('global %s; unset %s; array set %s %s',
|
|
|
|
@id, @id, @id, s))
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
2000-01-31 22:12:21 -05:00
|
|
|
fail
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def [](index)
|
2003-12-02 23:55:07 -05:00
|
|
|
INTERP._eval(Kernel.format('global %s; set %s(%s)',
|
|
|
|
@id, @id, _get_eval_string(index)))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def []=(index,val)
|
2003-12-02 23:55:07 -05:00
|
|
|
INTERP._eval(Kernel.format('global %s; set %s(%s) %s', @id, @id,
|
|
|
|
_get_eval_string(index), _get_eval_string(val)))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2003-08-29 04:34:14 -04:00
|
|
|
def numeric
|
|
|
|
number(value)
|
|
|
|
end
|
|
|
|
def numeric=(val)
|
|
|
|
case val
|
|
|
|
when Numeric
|
|
|
|
self.value=(val)
|
|
|
|
when TkVariable
|
|
|
|
self.value=(val.numeric)
|
|
|
|
else
|
|
|
|
raise ArgumentError, "Numeric is expected"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def to_i
|
2001-06-01 02:47:32 -04:00
|
|
|
number(value).to_i
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_f
|
2001-06-01 02:47:32 -04:00
|
|
|
number(value).to_f
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
2001-06-01 02:47:32 -04:00
|
|
|
string(value).to_s
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2003-08-02 01:04:30 -04:00
|
|
|
def to_sym
|
|
|
|
value.intern
|
|
|
|
end
|
|
|
|
|
2003-08-29 04:34:14 -04:00
|
|
|
def list
|
|
|
|
tk_split_list(value)
|
|
|
|
end
|
|
|
|
alias to_a list
|
|
|
|
|
|
|
|
def list=(val)
|
|
|
|
case val
|
|
|
|
when Array
|
|
|
|
self.value=(val)
|
|
|
|
when TkVariable
|
|
|
|
self.value=(val.list)
|
|
|
|
else
|
|
|
|
raise ArgumentError, "Array is expected"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def inspect
|
2003-12-02 23:55:07 -05:00
|
|
|
Kernel.format "#<TkVariable: %s>", @id
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2003-08-29 04:34:14 -04:00
|
|
|
def coerce(other)
|
|
|
|
case other
|
|
|
|
when TkVariable
|
|
|
|
[other.value, self.value]
|
|
|
|
when String
|
|
|
|
[other, self.to_s]
|
|
|
|
when Symbol
|
|
|
|
[other, self.to_sym]
|
|
|
|
when Integer
|
|
|
|
[other, self.to_i]
|
|
|
|
when Float
|
|
|
|
[other, self.to_f]
|
|
|
|
when Array
|
|
|
|
[other, self.to_a]
|
|
|
|
else
|
|
|
|
[other, self.value]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def &(other)
|
|
|
|
if other.kind_of?(Array)
|
|
|
|
self.to_a & other.to_a
|
|
|
|
else
|
|
|
|
self.to_i & other.to_i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def |(other)
|
|
|
|
if other.kind_of?(Array)
|
|
|
|
self.to_a | other.to_a
|
|
|
|
else
|
|
|
|
self.to_i | other.to_i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def +(other)
|
|
|
|
case other
|
|
|
|
when Array
|
|
|
|
self.to_a + other
|
|
|
|
when String
|
|
|
|
self.value + other
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
number(self.value) + other
|
|
|
|
rescue
|
|
|
|
self.value + other.to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def -(other)
|
|
|
|
if other.kind_of?(Array)
|
|
|
|
self.to_a - other
|
|
|
|
else
|
|
|
|
number(self.value) - other
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def *(other)
|
|
|
|
begin
|
|
|
|
number(self.value) * other
|
|
|
|
rescue
|
|
|
|
self.value * other
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def /(other)
|
|
|
|
number(self.value) / other
|
|
|
|
end
|
|
|
|
def %(other)
|
|
|
|
begin
|
|
|
|
number(self.value) % other
|
|
|
|
rescue
|
|
|
|
self.value % other
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def **(other)
|
|
|
|
number(self.value) ** other
|
|
|
|
end
|
|
|
|
def =~(other)
|
|
|
|
self.value =~ other
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def ==(other)
|
|
|
|
case other
|
|
|
|
when TkVariable
|
2003-06-18 15:46:20 -04:00
|
|
|
self.equal?(other)
|
1999-08-13 01:37:52 -04:00
|
|
|
when String
|
|
|
|
self.to_s == other
|
2003-08-02 01:04:30 -04:00
|
|
|
when Symbol
|
|
|
|
self.to_sym == other
|
1999-08-13 01:37:52 -04:00
|
|
|
when Integer
|
|
|
|
self.to_i == other
|
|
|
|
when Float
|
|
|
|
self.to_f == other
|
|
|
|
when Array
|
|
|
|
self.to_a == other
|
2003-08-29 04:34:14 -04:00
|
|
|
when Hash
|
|
|
|
self.value == other
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-08-29 04:34:14 -04:00
|
|
|
def zero?
|
|
|
|
numeric.zero?
|
|
|
|
end
|
|
|
|
def nonzero?
|
|
|
|
!(numeric.zero?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def <=>(other)
|
|
|
|
if other.kind_of?(TkVariable)
|
|
|
|
begin
|
|
|
|
val = other.numeric
|
|
|
|
other = val
|
|
|
|
rescue
|
|
|
|
other = other.value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if other.kind_of?(Numeric)
|
|
|
|
begin
|
|
|
|
return self.numeric <=> other
|
|
|
|
rescue
|
|
|
|
return self.value <=> other.to_s
|
|
|
|
end
|
|
|
|
else
|
|
|
|
return self.value <=> other
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_eval
|
|
|
|
@id
|
|
|
|
end
|
|
|
|
|
|
|
|
def unset(elem=nil)
|
|
|
|
if elem
|
2003-12-02 23:55:07 -05:00
|
|
|
INTERP._eval(Kernel.format('global %s; unset %s(%s)',
|
|
|
|
@id, @id, tk_tcl2ruby(elem)))
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
2003-12-02 23:55:07 -05:00
|
|
|
INTERP._eval(Kernel.format('global %s; unset %s', @id, @id))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
alias remove unset
|
|
|
|
|
|
|
|
def trace_callback(elem, op)
|
|
|
|
if @trace_var.kind_of? Array
|
|
|
|
@trace_var.each{|m,e| e.call(self,elem,op) if m.index(op)}
|
|
|
|
end
|
|
|
|
if elem.kind_of? String
|
|
|
|
if @trace_elem[elem].kind_of? Array
|
|
|
|
@trace_elem[elem].each{|m,e| e.call(self,elem,op) if m.index(op)}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def trace(opts, cmd)
|
|
|
|
@trace_var = [] if @trace_var == nil
|
|
|
|
opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('')
|
|
|
|
@trace_var.unshift([opts,cmd])
|
|
|
|
if @trace_opts == nil
|
|
|
|
TkVar_CB_TBL[@id] = self
|
|
|
|
@trace_opts = opts
|
|
|
|
Tk.tk_call('trace', 'variable', @id, @trace_opts, 'rb_var')
|
|
|
|
else
|
|
|
|
newopts = @trace_opts.dup
|
|
|
|
opts.each_byte{|c| newopts += c.chr unless newopts.index(c)}
|
|
|
|
if newopts != @trace_opts
|
|
|
|
Tk.tk_call('trace', 'vdelete', @id, @trace_opts, 'rb_var')
|
|
|
|
@trace_opts.replace(newopts)
|
|
|
|
Tk.tk_call('trace', 'variable', @id, @trace_opts, 'rb_var')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def trace_element(elem, opts, cmd)
|
|
|
|
@trace_elem = {} if @trace_elem == nil
|
|
|
|
@trace_elem[elem] = [] if @trace_elem[elem] == nil
|
|
|
|
opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('')
|
|
|
|
@trace_elem[elem].unshift([opts,cmd])
|
|
|
|
if @trace_opts == nil
|
|
|
|
TkVar_CB_TBL[@id] = self
|
|
|
|
@trace_opts = opts
|
|
|
|
Tk.tk_call('trace', 'variable', @id, @trace_opts, 'rb_var')
|
|
|
|
else
|
|
|
|
newopts = @trace_opts.dup
|
|
|
|
opts.each_byte{|c| newopts += c.chr unless newopts.index(c)}
|
|
|
|
if newopts != @trace_opts
|
|
|
|
Tk.tk_call('trace', 'vdelete', @id, @trace_opts, 'rb_var')
|
|
|
|
@trace_opts.replace(newopts)
|
|
|
|
Tk.tk_call('trace', 'variable', @id, @trace_opts, 'rb_var')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def trace_vinfo
|
|
|
|
return [] unless @trace_var
|
|
|
|
@trace_var.dup
|
|
|
|
end
|
|
|
|
def trace_vinfo_for_element(elem)
|
|
|
|
return [] unless @trace_elem
|
|
|
|
return [] unless @trace_elem[elem]
|
|
|
|
@trace_elem[elem].dup
|
|
|
|
end
|
|
|
|
|
|
|
|
def trace_vdelete(opts,cmd)
|
|
|
|
return unless @trace_var.kind_of? Array
|
|
|
|
opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('')
|
|
|
|
idx = -1
|
|
|
|
newopts = ''
|
2002-01-28 03:44:45 -05:00
|
|
|
@trace_var.each_with_index{|e,i|
|
1999-08-13 01:37:52 -04:00
|
|
|
if idx < 0 && e[0] == opts && e[1] == cmd
|
|
|
|
idx = i
|
|
|
|
next
|
|
|
|
end
|
|
|
|
e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)}
|
|
|
|
}
|
|
|
|
if idx >= 0
|
|
|
|
@trace_var.delete_at(idx)
|
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
@trace_elem.each{|elem|
|
|
|
|
@trace_elem[elem].each{|e|
|
|
|
|
e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
newopts = ['r','w','u'].find_all{|c| newopts.index(c)}.join('')
|
|
|
|
if newopts != @trace_opts
|
|
|
|
Tk.tk_call('trace', 'vdelete', @id, @trace_opts, 'rb_var')
|
|
|
|
@trace_opts.replace(newopts)
|
|
|
|
if @trace_opts != ''
|
|
|
|
Tk.tk_call('trace', 'variable', @id, @trace_opts, 'rb_var')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def trace_vdelete_for_element(elem,opts,cmd)
|
|
|
|
return unless @trace_elem.kind_of? Hash
|
|
|
|
return unless @trace_elem[elem].kind_of? Array
|
|
|
|
opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('')
|
|
|
|
idx = -1
|
2002-01-28 03:44:45 -05:00
|
|
|
@trace_elem[elem].each_with_index{|e,i|
|
1999-08-13 01:37:52 -04:00
|
|
|
if idx < 0 && e[0] == opts && e[1] == cmd
|
|
|
|
idx = i
|
|
|
|
next
|
|
|
|
end
|
|
|
|
}
|
|
|
|
if idx >= 0
|
|
|
|
@trace_elem[elem].delete_at(idx)
|
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
newopts = ''
|
|
|
|
@trace_var.each{|e|
|
|
|
|
e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)}
|
|
|
|
}
|
|
|
|
@trace_elem.each{|elem|
|
|
|
|
@trace_elem[elem].each{|e|
|
|
|
|
e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
newopts = ['r','w','u'].find_all{|c| newopts.index(c)}.join('')
|
|
|
|
if newopts != @trace_opts
|
|
|
|
Tk.tk_call('trace', 'vdelete', @id, @trace_opts, 'rb_var')
|
|
|
|
@trace_opts.replace(newopts)
|
|
|
|
if @trace_opts != ''
|
|
|
|
Tk.tk_call('trace', 'variable', @id, @trace_opts, 'rb_var')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TkVarAccess<TkVariable
|
2003-06-18 15:46:20 -04:00
|
|
|
def self.new(name, *args)
|
|
|
|
return TkVar_ID_TBL[name] if TkVar_ID_TBL[name]
|
|
|
|
super(name, *args)
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def initialize(varname, val=nil)
|
|
|
|
@id = varname
|
2003-06-18 15:46:20 -04:00
|
|
|
TkVar_ID_TBL[@id] = self
|
1999-08-13 01:37:52 -04:00
|
|
|
if val
|
2003-03-21 23:31:24 -05:00
|
|
|
s = '"' + _get_eval_string(val).gsub(/[\[\]$"]/, '\\\\\&') + '"' #"
|
2003-12-02 23:55:07 -05:00
|
|
|
INTERP._eval(Kernel.format('global %s; set %s %s', @id, @id, s))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2001-05-30 05:10:30 -04:00
|
|
|
module Tk
|
|
|
|
begin
|
|
|
|
auto_path = INTERP._invoke('set', 'auto_path')
|
|
|
|
rescue
|
|
|
|
begin
|
|
|
|
auto_path = INTERP._invoke('set', 'env(TCLLIBPATH)')
|
|
|
|
rescue
|
|
|
|
auto_path = Tk::LIBRARY
|
|
|
|
end
|
|
|
|
end
|
2003-10-14 14:54:21 -04:00
|
|
|
|
2001-05-30 05:10:30 -04:00
|
|
|
AUTO_PATH = TkVarAccess.new('auto_path', auto_path)
|
2003-10-14 14:54:21 -04:00
|
|
|
|
|
|
|
=begin
|
|
|
|
AUTO_OLDPATH = tk_split_simplelist(INTERP._invoke('set', 'auto_oldpath'))
|
|
|
|
AUTO_OLDPATH.each{|s| s.freeze}
|
|
|
|
AUTO_OLDPATH.freeze
|
|
|
|
=end
|
2001-05-30 05:10:30 -04:00
|
|
|
|
|
|
|
TCL_PACKAGE_PATH = TkVarAccess.new('tcl_pkgPath')
|
2003-10-14 11:25:45 -04:00
|
|
|
PACKAGE_PATH = TCL_PACKAGE_PATH
|
|
|
|
|
|
|
|
TCL_LIBRARY_PATH = TkVarAccess.new('tcl_libPath')
|
|
|
|
LIBRARY_PATH = TCL_LIBRARY_PATH
|
2003-06-18 15:46:20 -04:00
|
|
|
|
|
|
|
TCL_PRECISION = TkVarAccess.new('tcl_precision')
|
2001-05-30 05:10:30 -04:00
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
module TkSelection
|
|
|
|
include Tk
|
|
|
|
extend Tk
|
2003-06-18 15:46:20 -04:00
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['selection'.freeze].freeze
|
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
def self.clear(sel=nil)
|
|
|
|
if sel
|
|
|
|
tk_call 'selection', 'clear', '-selection', sel
|
|
|
|
else
|
|
|
|
tk_call 'selection', 'clear'
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def self.clear_on_display(win, sel=nil)
|
|
|
|
if sel
|
|
|
|
tk_call 'selection', 'clear', '-displayof', win, '-selection', sel
|
|
|
|
else
|
|
|
|
tk_call 'selection', 'clear', '-displayof', win
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def clear(sel=nil)
|
|
|
|
TkSelection.clear_on_display(self, sel)
|
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
|
|
|
def self.get(keys=nil)
|
|
|
|
tk_call 'selection', 'get', *hash_kv(keys)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def self.get_on_display(win, keys=nil)
|
|
|
|
tk_call 'selection', 'get', '-displayof', win, *hash_kv(keys)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def get(keys=nil)
|
|
|
|
TkSelection.get_on_display(self, sel)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
def self.handle(win, func=Proc.new, keys=nil, &b)
|
|
|
|
if func.kind_of?(Hash) && keys == nil
|
|
|
|
keys = func
|
|
|
|
func = Proc.new(&b)
|
|
|
|
end
|
|
|
|
args = ['selection', 'handle']
|
|
|
|
args += hash_kv(keys)
|
|
|
|
args += [win, func]
|
|
|
|
tk_call(*args)
|
|
|
|
end
|
|
|
|
def handle(func=Proc.new, keys=nil, &b)
|
|
|
|
TkSelection.handle(self, func, keys, &b)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.get_owner(sel=nil)
|
|
|
|
if sel
|
|
|
|
window(tk_call('selection', 'own', '-selection', sel))
|
|
|
|
else
|
|
|
|
window(tk_call('selection', 'own'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def self.get_owner_on_display(win, sel=nil)
|
|
|
|
if sel
|
|
|
|
window(tk_call('selection', 'own', '-displayof', win, '-selection', sel))
|
|
|
|
else
|
|
|
|
window(tk_call('selection', 'own', '-displayof', win))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def get_owner(sel=nil)
|
|
|
|
TkSelection.get_owner_on_display(self, sel)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.set_owner(win, keys=nil)
|
|
|
|
tk_call('selection', 'own', *(hash_kv(keys) << win))
|
|
|
|
end
|
|
|
|
def set_owner(keys=nil)
|
|
|
|
TkSelection.set_owner(self, keys)
|
|
|
|
self
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
module TkKinput
|
|
|
|
include Tk
|
|
|
|
extend Tk
|
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = [
|
|
|
|
'kinput_start'.freeze,
|
|
|
|
'kinput_send_spot'.freeze,
|
|
|
|
'kanjiInput'.freeze
|
|
|
|
].freeze
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkKinput.start(window, style=None)
|
|
|
|
tk_call 'kinput_start', window.path, style
|
|
|
|
end
|
|
|
|
def kinput_start(style=None)
|
|
|
|
TkKinput.start(self, style)
|
|
|
|
end
|
|
|
|
|
|
|
|
def TkKinput.send_spot(window)
|
|
|
|
tk_call 'kinput_send_spot', window.path
|
|
|
|
end
|
|
|
|
def kinput_send_spot
|
|
|
|
TkKinput.send_spot(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
def TkKinput.input_start(window, keys=nil)
|
|
|
|
tk_call 'kanjiInput', 'start', window.path, *hash_kv(keys)
|
|
|
|
end
|
|
|
|
def kanji_input_start(keys=nil)
|
|
|
|
TkKinput.input_start(self, keys)
|
|
|
|
end
|
|
|
|
|
|
|
|
def TkKinput.attribute_config(window, slot, value=None)
|
|
|
|
if slot.kind_of? Hash
|
|
|
|
tk_call 'kanjiInput', 'attribute', window.path, *hash_kv(slot)
|
|
|
|
else
|
|
|
|
tk_call 'kanjiInput', 'attribute', window.path, "-#{slot}", value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def kinput_attribute_config(slot, value=None)
|
|
|
|
TkKinput.attribute_config(self, slot, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
def TkKinput.attribute_info(window, slot=nil)
|
|
|
|
if slot
|
|
|
|
conf = tk_split_list(tk_call('kanjiInput', 'attribute',
|
|
|
|
window.path, "-#{slot}"))
|
|
|
|
conf[0] = conf[0][1..-1]
|
|
|
|
conf
|
|
|
|
else
|
|
|
|
tk_split_list(tk_call('kanjiInput', 'attribute',
|
|
|
|
window.path)).collect{|conf|
|
|
|
|
conf[0] = conf[0][1..-1]
|
|
|
|
conf
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def kinput_attribute_info(slot=nil)
|
|
|
|
TkKinput.attribute_info(self, slot)
|
|
|
|
end
|
|
|
|
|
|
|
|
def TkKinput.input_end(window)
|
|
|
|
tk_call 'kanjiInput', 'end', window.path
|
|
|
|
end
|
|
|
|
def kanji_input_end
|
|
|
|
TkKinput.input_end(self)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2000-06-13 05:57:40 -04:00
|
|
|
module TkXIM
|
|
|
|
include Tk
|
|
|
|
extend Tk
|
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['imconfigure'.freeze].freeze
|
|
|
|
|
2000-06-13 05:57:40 -04:00
|
|
|
def TkXIM.useinputmethods(window=nil, value=nil)
|
|
|
|
if window
|
|
|
|
if value
|
|
|
|
tk_call 'tk', 'useinputmethods', '-displayof', window.path, value
|
|
|
|
else
|
|
|
|
tk_call 'tk', 'useinputmethods', '-displayof', window.path
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if value
|
|
|
|
tk_call 'tk', 'useinputmethods', value
|
|
|
|
else
|
|
|
|
tk_call 'tk', 'useinputmethods'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
def TkXIM.caret(window, keys=nil)
|
|
|
|
if keys
|
|
|
|
tk_call('tk', 'caret', window, *hash_kv(keys))
|
|
|
|
self
|
|
|
|
else
|
|
|
|
lst = tk_split_list(tk_call('tk', 'caret', window))
|
|
|
|
info = {}
|
|
|
|
while key = lst.shift
|
|
|
|
info[key[1..-1]] = lst.shift
|
|
|
|
end
|
|
|
|
info
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2000-06-13 05:57:40 -04:00
|
|
|
def TkXIM.configure(window, slot, value=None)
|
|
|
|
begin
|
|
|
|
if /^8\.*/ === Tk::TK_VERSION && JAPANIZED_TK
|
|
|
|
if slot.kind_of? Hash
|
|
|
|
tk_call 'imconfigure', window.path, *hash_kv(slot)
|
|
|
|
else
|
|
|
|
tk_call 'imconfigure', window.path, "-#{slot}", value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def TkXIM.configinfo(window, slot=nil)
|
|
|
|
begin
|
|
|
|
if /^8\.*/ === Tk::TK_VERSION && JAPANIZED_TK
|
|
|
|
if slot
|
|
|
|
conf = tk_split_list(tk_call('imconfigure', window.path, "-#{slot}"))
|
|
|
|
conf[0] = conf[0][1..-1]
|
|
|
|
conf
|
|
|
|
else
|
|
|
|
tk_split_list(tk_call('imconfigure', window.path)).collect{|conf|
|
|
|
|
conf[0] = conf[0][1..-1]
|
|
|
|
conf
|
|
|
|
}
|
|
|
|
end
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def useinputmethods(value=nil)
|
2001-03-27 02:10:58 -05:00
|
|
|
TkXIM.useinputmethods(self, value)
|
2000-06-13 05:57:40 -04:00
|
|
|
end
|
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
def caret(keys=nil)
|
|
|
|
TkXIM.caret(self, keys=nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
def imconfigure(slot, value=None)
|
|
|
|
TkXIM.configinfo(self, slot, value)
|
2000-06-13 05:57:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def imconfiginfo(slot=nil)
|
2003-06-18 15:46:20 -04:00
|
|
|
TkXIM.configinfo(self, slot)
|
2000-06-13 05:57:40 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
module TkWinfo
|
|
|
|
include Tk
|
|
|
|
extend Tk
|
2003-06-18 15:46:20 -04:00
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['winfo'.freeze].freeze
|
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
def TkWinfo.atom(name, win=nil)
|
|
|
|
if win
|
|
|
|
number(tk_call('winfo', 'atom', '-displayof', win, name))
|
|
|
|
else
|
|
|
|
number(tk_call('winfo', 'atom', name))
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def winfo_atom(name)
|
2003-06-18 15:46:20 -04:00
|
|
|
TkWinfo.atom(name, self)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
|
|
|
def TkWinfo.atomname(id, win=nil)
|
|
|
|
if win
|
|
|
|
tk_call('winfo', 'atomname', '-displayof', win, id)
|
|
|
|
else
|
|
|
|
tk_call('winfo', 'atomname', id)
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def winfo_atomname(id)
|
2003-06-18 15:46:20 -04:00
|
|
|
TkWinfo.atomname(id, self)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.cells(window)
|
2000-01-17 03:37:53 -05:00
|
|
|
number(tk_call('winfo', 'cells', window.path))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def winfo_cells
|
|
|
|
TkWinfo.cells self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.children(window)
|
|
|
|
c = tk_call('winfo', 'children', window.path)
|
|
|
|
list(c)
|
|
|
|
end
|
|
|
|
def winfo_children
|
|
|
|
TkWinfo.children self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.classname(window)
|
|
|
|
tk_call 'winfo', 'class', window.path
|
|
|
|
end
|
|
|
|
def winfo_classname
|
|
|
|
TkWinfo.classname self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
alias winfo_class winfo_classname
|
|
|
|
|
2000-01-17 03:37:53 -05:00
|
|
|
def TkWinfo.colormapfull(window)
|
|
|
|
bool(tk_call('winfo', 'colormapfull', window.path))
|
|
|
|
end
|
|
|
|
def winfo_colormapfull
|
|
|
|
TkWinfo.colormapfull self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
|
|
|
def TkWinfo.containing(rootX, rootY, win=nil)
|
|
|
|
if win
|
|
|
|
window(tk_call('winfo', 'containing', '-displayof', win, rootX, rootY))
|
|
|
|
else
|
|
|
|
window(tk_call('winfo', 'containing', rootX, rootY))
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def winfo_containing(x, y)
|
2003-06-18 15:46:20 -04:00
|
|
|
TkWinfo.containing(x, y, self)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.depth(window)
|
|
|
|
number(tk_call('winfo', 'depth', window.path))
|
|
|
|
end
|
|
|
|
def winfo_depth
|
|
|
|
TkWinfo.depth self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.exist?(window)
|
|
|
|
bool(tk_call('winfo', 'exists', window.path))
|
|
|
|
end
|
|
|
|
def winfo_exist?
|
|
|
|
TkWinfo.exist? self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
|
|
|
def TkWinfo.fpixels(window, dist)
|
|
|
|
number(tk_call('winfo', 'fpixels', window.path, dist))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def winfo_fpixels(dist)
|
|
|
|
TkWinfo.fpixels self, dist
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.geometry(window)
|
2000-01-17 03:37:53 -05:00
|
|
|
tk_call('winfo', 'geometry', window.path)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def winfo_geometry
|
|
|
|
TkWinfo.geometry self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.height(window)
|
|
|
|
number(tk_call('winfo', 'height', window.path))
|
|
|
|
end
|
|
|
|
def winfo_height
|
|
|
|
TkWinfo.height self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.id(window)
|
2000-01-17 03:37:53 -05:00
|
|
|
tk_call('winfo', 'id', window.path)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def winfo_id
|
|
|
|
TkWinfo.id self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.interps(window=nil)
|
|
|
|
if window
|
2000-01-17 03:37:53 -05:00
|
|
|
tk_split_simplelist(tk_call('winfo', 'interps',
|
|
|
|
'-displayof', window.path))
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
|
|
|
tk_split_simplelist(tk_call('winfo', 'interps'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def winfo_interps
|
|
|
|
TkWinfo.interps self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.mapped?(window)
|
|
|
|
bool(tk_call('winfo', 'ismapped', window.path))
|
|
|
|
end
|
|
|
|
def winfo_mapped?
|
|
|
|
TkWinfo.mapped? self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
2000-01-17 03:37:53 -05:00
|
|
|
def TkWinfo.manager(window)
|
|
|
|
tk_call('winfo', 'manager', window.path)
|
|
|
|
end
|
|
|
|
def winfo_manager
|
|
|
|
TkWinfo.manager self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.appname(window)
|
2000-01-17 03:37:53 -05:00
|
|
|
tk_call('winfo', 'name', window.path)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def winfo_appname
|
|
|
|
TkWinfo.appname self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.parent(window)
|
|
|
|
window(tk_call('winfo', 'parent', window.path))
|
|
|
|
end
|
|
|
|
def winfo_parent
|
|
|
|
TkWinfo.parent self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
|
|
|
def TkWinfo.widget(id, win=nil)
|
|
|
|
if win
|
|
|
|
window(tk_call('winfo', 'pathname', '-displayof', win, id))
|
|
|
|
else
|
|
|
|
window(tk_call('winfo', 'pathname', id))
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def winfo_widget(id)
|
2003-06-18 15:46:20 -04:00
|
|
|
TkWinfo.widget id, self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
|
|
|
def TkWinfo.pixels(window, dist)
|
|
|
|
number(tk_call('winfo', 'pixels', window.path, dist))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def winfo_pixels(dist)
|
|
|
|
TkWinfo.pixels self, dist
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.reqheight(window)
|
|
|
|
number(tk_call('winfo', 'reqheight', window.path))
|
|
|
|
end
|
|
|
|
def winfo_reqheight
|
|
|
|
TkWinfo.reqheight self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.reqwidth(window)
|
|
|
|
number(tk_call('winfo', 'reqwidth', window.path))
|
|
|
|
end
|
|
|
|
def winfo_reqwidth
|
|
|
|
TkWinfo.reqwidth self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.rgb(window, color)
|
|
|
|
list(tk_call('winfo', 'rgb', window.path, color))
|
|
|
|
end
|
|
|
|
def winfo_rgb(color)
|
|
|
|
TkWinfo.rgb self, color
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.rootx(window)
|
|
|
|
number(tk_call('winfo', 'rootx', window.path))
|
|
|
|
end
|
|
|
|
def winfo_rootx
|
|
|
|
TkWinfo.rootx self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.rooty(window)
|
|
|
|
number(tk_call('winfo', 'rooty', window.path))
|
|
|
|
end
|
|
|
|
def winfo_rooty
|
|
|
|
TkWinfo.rooty self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.screen(window)
|
|
|
|
tk_call 'winfo', 'screen', window.path
|
|
|
|
end
|
|
|
|
def winfo_screen
|
|
|
|
TkWinfo.screen self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.screencells(window)
|
|
|
|
number(tk_call('winfo', 'screencells', window.path))
|
|
|
|
end
|
|
|
|
def winfo_screencells
|
|
|
|
TkWinfo.screencells self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.screendepth(window)
|
|
|
|
number(tk_call('winfo', 'screendepth', window.path))
|
|
|
|
end
|
|
|
|
def winfo_screendepth
|
|
|
|
TkWinfo.screendepth self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.screenheight (window)
|
|
|
|
number(tk_call('winfo', 'screenheight', window.path))
|
|
|
|
end
|
|
|
|
def winfo_screenheight
|
|
|
|
TkWinfo.screenheight self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.screenmmheight(window)
|
|
|
|
number(tk_call('winfo', 'screenmmheight', window.path))
|
|
|
|
end
|
|
|
|
def winfo_screenmmheight
|
|
|
|
TkWinfo.screenmmheight self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.screenmmwidth(window)
|
|
|
|
number(tk_call('winfo', 'screenmmwidth', window.path))
|
|
|
|
end
|
|
|
|
def winfo_screenmmwidth
|
|
|
|
TkWinfo.screenmmwidth self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.screenvisual(window)
|
2003-06-18 15:46:20 -04:00
|
|
|
tk_call('winfo', 'screenvisual', window.path)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def winfo_screenvisual
|
|
|
|
TkWinfo.screenvisual self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.screenwidth(window)
|
|
|
|
number(tk_call('winfo', 'screenwidth', window.path))
|
|
|
|
end
|
|
|
|
def winfo_screenwidth
|
|
|
|
TkWinfo.screenwidth self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
2000-01-17 03:37:53 -05:00
|
|
|
def TkWinfo.server(window)
|
|
|
|
tk_call 'winfo', 'server', window.path
|
|
|
|
end
|
|
|
|
def winfo_server
|
|
|
|
TkWinfo.server self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.toplevel(window)
|
|
|
|
window(tk_call('winfo', 'toplevel', window.path))
|
|
|
|
end
|
|
|
|
def winfo_toplevel
|
|
|
|
TkWinfo.toplevel self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.visual(window)
|
2003-06-18 15:46:20 -04:00
|
|
|
tk_call('winfo', 'visual', window.path)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def winfo_visual
|
|
|
|
TkWinfo.visual self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
2000-01-17 03:37:53 -05:00
|
|
|
def TkWinfo.visualid(window)
|
2003-06-18 15:46:20 -04:00
|
|
|
tk_call('winfo', 'visualid', window.path)
|
2000-01-17 03:37:53 -05:00
|
|
|
end
|
|
|
|
def winfo_visualid
|
|
|
|
TkWinfo.visualid self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
2000-01-17 03:37:53 -05:00
|
|
|
def TkWinfo.visualsavailable(window, includeids=false)
|
|
|
|
if includeids
|
2003-06-18 15:46:20 -04:00
|
|
|
list(tk_call('winfo', 'visualsavailable', window.path, "includeids"))
|
2000-01-17 03:37:53 -05:00
|
|
|
else
|
2003-06-18 15:46:20 -04:00
|
|
|
list(tk_call('winfo', 'visualsavailable', window.path))
|
2000-01-17 03:37:53 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
def winfo_visualsavailable(includeids=false)
|
|
|
|
TkWinfo.visualsavailable self, includeids
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
2000-01-17 03:37:53 -05:00
|
|
|
def TkWinfo.vrootheight(window)
|
1999-08-13 01:37:52 -04:00
|
|
|
number(tk_call('winfo', 'vrootheight', window.path))
|
|
|
|
end
|
|
|
|
def winfo_vrootheight
|
|
|
|
TkWinfo.vrootheight self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.vrootwidth(window)
|
|
|
|
number(tk_call('winfo', 'vrootwidth', window.path))
|
|
|
|
end
|
|
|
|
def winfo_vrootwidth
|
|
|
|
TkWinfo.vrootwidth self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.vrootx(window)
|
|
|
|
number(tk_call('winfo', 'vrootx', window.path))
|
|
|
|
end
|
|
|
|
def winfo_vrootx
|
|
|
|
TkWinfo.vrootx self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.vrooty(window)
|
|
|
|
number(tk_call('winfo', 'vrooty', window.path))
|
|
|
|
end
|
|
|
|
def winfo_vrooty
|
|
|
|
TkWinfo.vrooty self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.width(window)
|
|
|
|
number(tk_call('winfo', 'width', window.path))
|
|
|
|
end
|
|
|
|
def winfo_width
|
|
|
|
TkWinfo.width self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.x(window)
|
|
|
|
number(tk_call('winfo', 'x', window.path))
|
|
|
|
end
|
|
|
|
def winfo_x
|
|
|
|
TkWinfo.x self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.y(window)
|
|
|
|
number(tk_call('winfo', 'y', window.path))
|
|
|
|
end
|
|
|
|
def winfo_y
|
|
|
|
TkWinfo.y self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.viewable(window)
|
2002-06-28 10:42:46 -04:00
|
|
|
bool(tk_call('winfo', 'viewable', window.path))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def winfo_viewable
|
|
|
|
TkWinfo.viewable self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.pointerx(window)
|
|
|
|
number(tk_call('winfo', 'pointerx', window.path))
|
|
|
|
end
|
|
|
|
def winfo_pointerx
|
|
|
|
TkWinfo.pointerx self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.pointery(window)
|
|
|
|
number(tk_call('winfo', 'pointery', window.path))
|
|
|
|
end
|
|
|
|
def winfo_pointery
|
|
|
|
TkWinfo.pointery self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def TkWinfo.pointerxy(window)
|
|
|
|
list(tk_call('winfo', 'pointerxy', window.path))
|
|
|
|
end
|
|
|
|
def winfo_pointerxy
|
|
|
|
TkWinfo.pointerxy self
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module TkPack
|
|
|
|
include Tk
|
|
|
|
extend Tk
|
2003-07-23 12:07:35 -04:00
|
|
|
|
|
|
|
TkCommandNames = ['pack'.freeze].freeze
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def configure(win, *args)
|
|
|
|
if args[-1].kind_of?(Hash)
|
|
|
|
keys = args.pop
|
|
|
|
end
|
|
|
|
wins = [win.epath]
|
|
|
|
for i in args
|
|
|
|
wins.push i.epath
|
|
|
|
end
|
|
|
|
tk_call "pack", 'configure', *(wins+hash_kv(keys))
|
|
|
|
end
|
|
|
|
|
|
|
|
def forget(*args)
|
|
|
|
tk_call 'pack', 'forget' *args
|
|
|
|
end
|
|
|
|
|
2000-11-27 04:23:38 -05:00
|
|
|
def info(slave)
|
|
|
|
ilist = list(tk_call('pack', 'info', slave.epath))
|
|
|
|
info = {}
|
|
|
|
while key = ilist.shift
|
|
|
|
info[key[1..-1]] = ilist.shift
|
|
|
|
end
|
|
|
|
return info
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def propagate(master, bool=None)
|
2000-11-27 04:23:38 -05:00
|
|
|
if bool == None
|
|
|
|
bool(tk_call('pack', 'propagate', master.epath))
|
|
|
|
else
|
|
|
|
tk_call('pack', 'propagate', master.epath, bool)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def slaves(master)
|
|
|
|
list(tk_call('pack', 'slaves', master.epath))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2000-11-27 04:23:38 -05:00
|
|
|
|
|
|
|
module_function :configure, :forget, :info, :propagate, :slaves
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
module TkGrid
|
|
|
|
include Tk
|
|
|
|
extend Tk
|
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['grid'.freeze].freeze
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def bbox(*args)
|
|
|
|
list(tk_call('grid', 'bbox', *args))
|
|
|
|
end
|
|
|
|
|
|
|
|
def configure(widget, *args)
|
|
|
|
if args[-1].kind_of?(Hash)
|
|
|
|
keys = args.pop
|
|
|
|
end
|
2003-08-02 17:39:23 -04:00
|
|
|
wins = []
|
|
|
|
args.unshift(widget)
|
1999-08-13 01:37:52 -04:00
|
|
|
for i in args
|
2003-08-02 17:39:23 -04:00
|
|
|
case i
|
|
|
|
when '-', 'x', '^' # RELATIVE PLACEMENT
|
|
|
|
wins.push(i)
|
|
|
|
else
|
|
|
|
wins.push(i.epath)
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
tk_call "grid", 'configure', *(wins+hash_kv(keys))
|
|
|
|
end
|
|
|
|
|
|
|
|
def columnconfigure(master, index, args)
|
|
|
|
tk_call "grid", 'columnconfigure', master, index, *hash_kv(args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def rowconfigure(master, index, args)
|
|
|
|
tk_call "grid", 'rowconfigure', master, index, *hash_kv(args)
|
|
|
|
end
|
|
|
|
|
2000-11-27 04:23:38 -05:00
|
|
|
def columnconfiginfo(master, index, slot=nil)
|
|
|
|
if slot
|
2003-06-18 15:46:20 -04:00
|
|
|
tk_call('grid', 'columnconfigure', master, index, "-#{slot}").to_i
|
2000-11-27 04:23:38 -05:00
|
|
|
else
|
|
|
|
ilist = list(tk_call('grid', 'columnconfigure', master, index))
|
|
|
|
info = {}
|
|
|
|
while key = ilist.shift
|
|
|
|
info[key[1..-1]] = ilist.shift
|
|
|
|
end
|
|
|
|
info
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def rowconfiginfo(master, index, slot=nil)
|
|
|
|
if slot
|
2003-06-18 15:46:20 -04:00
|
|
|
tk_call('grid', 'rowconfigure', master, index, "-#{slot}").to_i
|
2000-11-27 04:23:38 -05:00
|
|
|
else
|
|
|
|
ilist = list(tk_call('grid', 'rowconfigure', master, index))
|
|
|
|
info = {}
|
|
|
|
while key = ilist.shift
|
|
|
|
info[key[1..-1]] = ilist.shift
|
|
|
|
end
|
|
|
|
info
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def add(widget, *args)
|
|
|
|
configure(widget, *args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def forget(*args)
|
|
|
|
tk_call 'grid', 'forget', *args
|
|
|
|
end
|
|
|
|
|
|
|
|
def info(slave)
|
|
|
|
list(tk_call('grid', 'info', slave))
|
|
|
|
end
|
|
|
|
|
|
|
|
def location(master, x, y)
|
|
|
|
list(tk_call('grid', 'location', master, x, y))
|
|
|
|
end
|
|
|
|
|
|
|
|
def propagate(master, bool=None)
|
2000-11-27 04:23:38 -05:00
|
|
|
if bool == None
|
|
|
|
bool(tk_call('grid', 'propagate', master.epath))
|
|
|
|
else
|
|
|
|
tk_call('grid', 'propagate', master.epath, bool)
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def remove(*args)
|
|
|
|
tk_call 'grid', 'remove', *args
|
|
|
|
end
|
|
|
|
|
|
|
|
def size(master)
|
|
|
|
tk_call 'grid', 'size', master
|
|
|
|
end
|
|
|
|
|
2000-11-27 04:23:38 -05:00
|
|
|
def slaves(master, args)
|
|
|
|
list(tk_call('grid', 'slaves', master, *hash_kv(args)))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
module_function :bbox, :forget, :propagate, :info
|
|
|
|
module_function :remove, :size, :slaves, :location
|
|
|
|
module_function :configure, :columnconfigure, :rowconfigure
|
2000-11-27 04:23:38 -05:00
|
|
|
module_function :columnconfiginfo, :rowconfiginfo
|
|
|
|
end
|
|
|
|
|
|
|
|
module TkPlace
|
|
|
|
include Tk
|
|
|
|
extend Tk
|
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['place'.freeze].freeze
|
|
|
|
|
2000-11-27 04:23:38 -05:00
|
|
|
def configure(win, slot, value=None)
|
|
|
|
if slot.kind_of? Hash
|
|
|
|
tk_call 'place', 'configure', win.epath, *hash_kv(slot)
|
|
|
|
else
|
|
|
|
tk_call 'place', 'configure', win.epath, "-#{slot}", value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def configinfo(win, slot = nil)
|
|
|
|
# for >= Tk8.4a2 ?
|
|
|
|
if slot
|
|
|
|
conf = tk_split_list(tk_call('place', 'configure',
|
|
|
|
win.epath, "-#{slot}") )
|
|
|
|
conf[0] = conf[0][1..-1]
|
|
|
|
conf
|
|
|
|
else
|
|
|
|
tk_split_simplelist(tk_call('place', 'configure',
|
|
|
|
win.epath)).collect{|conflist|
|
|
|
|
conf = tk_split_simplelist(conflist)
|
|
|
|
conf[0] = conf[0][1..-1]
|
|
|
|
conf
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def forget(win)
|
|
|
|
tk_call 'place', 'forget', win
|
|
|
|
end
|
|
|
|
|
|
|
|
def info(win)
|
|
|
|
ilist = list(tk_call('place', 'info', win.epath))
|
|
|
|
info = {}
|
|
|
|
while key = ilist.shift
|
|
|
|
info[key[1..-1]] = ilist.shift
|
|
|
|
end
|
|
|
|
return info
|
|
|
|
end
|
|
|
|
|
|
|
|
def slaves(master)
|
|
|
|
list(tk_call('place', 'slaves', master.epath))
|
|
|
|
end
|
|
|
|
|
|
|
|
module_function :configure, :configinfo, :forget, :info, :slaves
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
module TkOptionDB
|
1999-08-13 01:37:52 -04:00
|
|
|
include Tk
|
|
|
|
extend Tk
|
2003-06-18 15:46:20 -04:00
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['option'.freeze].freeze
|
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
module Priority
|
|
|
|
WidgetDefault = 20
|
|
|
|
StartupFile = 40
|
|
|
|
UserDefault = 60
|
|
|
|
Interactive = 80
|
|
|
|
end
|
|
|
|
|
|
|
|
def add(pat, value, pri=None)
|
2003-09-07 03:10:44 -04:00
|
|
|
if $SAFE >= 4
|
|
|
|
fail SecurityError, "can't call 'TkOptionDB.add' at $SAFE >= 4"
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
tk_call 'option', 'add', pat, value, pri
|
|
|
|
end
|
|
|
|
def clear
|
2003-09-07 03:10:44 -04:00
|
|
|
if $SAFE >= 4
|
|
|
|
fail SecurityError, "can't call 'TkOptionDB.crear' at $SAFE >= 4"
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
tk_call 'option', 'clear'
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def get(win, name, klass)
|
2003-09-07 03:10:44 -04:00
|
|
|
tk_call('option', 'get', win ,name, klass)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def readfile(file, pri=None)
|
1999-08-13 01:37:52 -04:00
|
|
|
tk_call 'option', 'readfile', file, pri
|
|
|
|
end
|
|
|
|
module_function :add, :clear, :get, :readfile
|
2003-09-07 03:10:44 -04:00
|
|
|
|
|
|
|
def read_entries(file, f_enc=nil)
|
|
|
|
if TkCore::INTERP.safe?
|
|
|
|
fail SecurityError,
|
|
|
|
"can't call 'TkOptionDB.read_entries' on a safe interpreter"
|
|
|
|
end
|
|
|
|
|
|
|
|
i_enc = Tk.encoding()
|
|
|
|
|
|
|
|
unless f_enc
|
|
|
|
f_enc = i_enc
|
|
|
|
end
|
|
|
|
|
|
|
|
ent = []
|
|
|
|
cline = ''
|
|
|
|
open(file, 'r') {|f|
|
|
|
|
while line = f.gets
|
|
|
|
cline += line.chomp!
|
|
|
|
case cline
|
|
|
|
when /\\$/ # continue
|
|
|
|
cline.chop!
|
|
|
|
next
|
|
|
|
when /^!/ # coment
|
|
|
|
cline = ''
|
|
|
|
next
|
|
|
|
when /^([^:]+):\s(.*)$/
|
|
|
|
pat = $1
|
|
|
|
val = $2
|
|
|
|
p "ResourceDB: #{[pat, val].inspect}" if $DEBUG
|
|
|
|
pat = TkCore::INTERP._toUTF8(pat, f_enc)
|
|
|
|
pat = TkCore::INTERP._fromUTF8(pat, i_enc)
|
|
|
|
val = TkCore::INTERP._toUTF8(val, f_enc)
|
|
|
|
val = TkCore::INTERP._fromUTF8(val, i_enc)
|
|
|
|
ent << [pat, val]
|
|
|
|
cline = ''
|
|
|
|
else # unknown --> ignore
|
|
|
|
cline = ''
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
ent
|
|
|
|
end
|
|
|
|
module_function :read_entries
|
2003-07-31 19:04:45 -04:00
|
|
|
|
|
|
|
def read_with_encoding(file, f_enc=nil, pri=None)
|
2003-09-07 03:10:44 -04:00
|
|
|
# try to read the file as an OptionDB file
|
|
|
|
readfile(file, pri).each{|pat, val|
|
|
|
|
add(pat, val, pri)
|
|
|
|
}
|
|
|
|
|
|
|
|
=begin
|
2003-07-31 19:04:45 -04:00
|
|
|
i_enc = Tk.encoding()
|
|
|
|
|
|
|
|
unless f_enc
|
|
|
|
f_enc = i_enc
|
|
|
|
end
|
|
|
|
|
|
|
|
cline = ''
|
|
|
|
open(file, 'r') {|f|
|
|
|
|
while line = f.gets
|
|
|
|
cline += line.chomp!
|
|
|
|
case cline
|
|
|
|
when /\\$/ # continue
|
|
|
|
cline.chop!
|
|
|
|
next
|
|
|
|
when /^!/ # coment
|
|
|
|
cline = ''
|
|
|
|
next
|
|
|
|
when /^([^:]+):\s(.*)$/
|
|
|
|
pat = $1
|
|
|
|
val = $2
|
|
|
|
p "ResourceDB: #{[pat, val].inspect}" if $DEBUG
|
|
|
|
pat = TkCore::INTERP._toUTF8(pat, f_enc)
|
|
|
|
pat = TkCore::INTERP._fromUTF8(pat, i_enc)
|
|
|
|
val = TkCore::INTERP._toUTF8(val, f_enc)
|
|
|
|
val = TkCore::INTERP._fromUTF8(val, i_enc)
|
|
|
|
add(pat, val, pri)
|
|
|
|
cline = ''
|
|
|
|
else # unknown --> ignore
|
|
|
|
cline = ''
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
2003-09-07 03:10:44 -04:00
|
|
|
=end
|
2003-07-31 19:04:45 -04:00
|
|
|
end
|
|
|
|
module_function :read_with_encoding
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
|
|
|
|
# support procs on the resource database
|
|
|
|
@@resource_proc_class = Class.new
|
|
|
|
class << @@resource_proc_class
|
|
|
|
private :new
|
2003-06-24 12:46:07 -04:00
|
|
|
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
CARRIER = '.'.freeze
|
2003-07-23 12:07:35 -04:00
|
|
|
METHOD_TBL = TkCore::INTERP.create_table
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
ADD_METHOD = false
|
|
|
|
SAFE_MODE = 4
|
|
|
|
|
2003-06-24 12:46:07 -04:00
|
|
|
def __closed_block_check__(str)
|
|
|
|
depth = 0
|
|
|
|
str.scan(/[{}]/){|x|
|
|
|
|
if x == "{"
|
|
|
|
depth += 1
|
|
|
|
elsif x == "}"
|
|
|
|
depth -= 1
|
|
|
|
end
|
|
|
|
if depth <= 0 && !($' =~ /\A\s*\Z/)
|
|
|
|
fail RuntimeError, "bad string for procedure : #{str.inspect}"
|
|
|
|
end
|
|
|
|
}
|
|
|
|
str
|
|
|
|
end
|
|
|
|
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
def __check_proc_string__(str)
|
|
|
|
# If you want to check the proc_string, do it in this method.
|
2003-06-24 12:46:07 -04:00
|
|
|
# Please define this in the block given to 'new_proc_class' method.
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
str
|
|
|
|
end
|
|
|
|
|
|
|
|
def method_missing(id, *args)
|
|
|
|
res_proc = self::METHOD_TBL[id]
|
|
|
|
unless res_proc.kind_of? Proc
|
2003-06-24 12:46:07 -04:00
|
|
|
if id == :new || !(self::METHOD_TBL.has_key?(id) || self::ADD_METHOD)
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
raise NoMethodError,
|
|
|
|
"not support resource-proc '#{id.id2name}' for #{self.name}"
|
|
|
|
end
|
2003-06-24 12:46:07 -04:00
|
|
|
proc_str = TkOptionDB.get(self::CARRIER, id.id2name, '').strip
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
proc_str = '{' + proc_str + '}' unless /\A\{.*\}\Z/ =~ proc_str
|
2003-06-24 12:46:07 -04:00
|
|
|
proc_str = __closed_block_check__(proc_str)
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
proc_str = __check_proc_string__(proc_str)
|
2003-10-16 13:47:19 -04:00
|
|
|
res_proc = eval('Proc.new' + proc_str)
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
self::METHOD_TBL[id] = res_proc
|
|
|
|
end
|
|
|
|
proc{
|
|
|
|
$SAFE = self::SAFE_MODE
|
|
|
|
res_proc.call(*args)
|
|
|
|
}.call
|
|
|
|
end
|
|
|
|
|
2003-06-24 12:46:07 -04:00
|
|
|
private :__closed_block_check__, :__check_proc_string__, :method_missing
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
end
|
2003-06-24 12:46:07 -04:00
|
|
|
@@resource_proc_class.freeze
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
|
2003-06-24 12:46:07 -04:00
|
|
|
def __create_new_class(klass, func, safe = 4, add = false, parent = nil)
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
klass = klass.to_s if klass.kind_of? Symbol
|
|
|
|
unless (?A..?Z) === klass[0]
|
|
|
|
fail ArgumentError, "bad string '#{klass}' for class name"
|
|
|
|
end
|
|
|
|
unless func.kind_of? Array
|
|
|
|
fail ArgumentError, "method-list must be Array"
|
|
|
|
end
|
|
|
|
func_str = func.join(' ')
|
|
|
|
if parent == nil
|
|
|
|
install_win(parent)
|
|
|
|
elsif parent <= @@resource_proc_class
|
|
|
|
install_win(parent::CARRIER)
|
|
|
|
else
|
|
|
|
fail ArgumentError, "parent must be Resource-Proc class"
|
|
|
|
end
|
|
|
|
carrier = Tk.tk_call('frame', @path, '-class', klass)
|
|
|
|
|
|
|
|
body = <<-"EOD"
|
2003-06-18 15:46:20 -04:00
|
|
|
class #{klass} < TkOptionDB.module_eval('@@resource_proc_class')
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
CARRIER = '#{carrier}'.freeze
|
2003-07-23 12:07:35 -04:00
|
|
|
METHOD_TBL = TkCore::INTERP.create_table
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
ADD_METHOD = #{add}
|
|
|
|
SAFE_MODE = #{safe}
|
2003-06-24 12:46:07 -04:00
|
|
|
%w(#{func_str}).each{|f| METHOD_TBL[f.intern] = nil }
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
end
|
|
|
|
EOD
|
|
|
|
|
|
|
|
if parent.kind_of?(Class) && parent <= @@resource_proc_class
|
2003-06-24 12:46:07 -04:00
|
|
|
parent.class_eval(body)
|
|
|
|
eval(parent.name + '::' + klass)
|
|
|
|
else
|
|
|
|
eval(body)
|
|
|
|
eval('TkOptionDB::' + klass)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
module_function :__create_new_class
|
|
|
|
private_class_method :__create_new_class
|
|
|
|
|
|
|
|
def __remove_methods_of_proc_class(klass)
|
|
|
|
# for security, make these methods invalid
|
|
|
|
class << klass
|
|
|
|
attr_reader :class_eval, :name, :superclass,
|
|
|
|
:ancestors, :const_defined?, :const_get, :const_set,
|
|
|
|
:constants, :included_modules, :instance_methods,
|
|
|
|
:method_defined?, :module_eval, :private_instance_methods,
|
|
|
|
:protected_instance_methods, :public_instance_methods,
|
|
|
|
:remove_const, :remove_method, :undef_method,
|
|
|
|
:to_s, :inspect, :display, :method, :methods,
|
|
|
|
:instance_eval, :instance_variables, :kind_of?, :is_a?,
|
|
|
|
:private_methods, :protected_methods, :public_methods
|
|
|
|
end
|
|
|
|
end
|
|
|
|
module_function :__remove_methods_of_proc_class
|
|
|
|
private_class_method :__remove_methods_of_proc_class
|
|
|
|
|
|
|
|
RAND_BASE_CNT = [0]
|
|
|
|
RAND_BASE_HEAD = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
|
|
|
RAND_BASE_CHAR = RAND_BASE_HEAD + 'abcdefghijklmnopqrstuvwxyz0123456789_'
|
|
|
|
def __get_random_basename
|
|
|
|
name = '%s%03d' % [RAND_BASE_HEAD[rand(RAND_BASE_HEAD.size),1],
|
|
|
|
RAND_BASE_CNT[0]]
|
|
|
|
len = RAND_BASE_CHAR.size
|
|
|
|
(6+rand(10)).times{
|
|
|
|
name << RAND_BASE_CHAR[rand(len),1]
|
|
|
|
}
|
|
|
|
RAND_BASE_CNT[0] = RAND_BASE_CNT[0] + 1
|
|
|
|
name
|
|
|
|
end
|
|
|
|
module_function :__get_random_basename
|
|
|
|
private_class_method :__get_random_basename
|
|
|
|
|
|
|
|
# define new proc class :
|
|
|
|
# If you want to modify the new class or create a new subclass,
|
|
|
|
# you must do such operation in the block parameter.
|
|
|
|
# Because the created class is flozen after evaluating the block.
|
|
|
|
def new_proc_class(klass, func, safe = 4, add = false, parent = nil, &b)
|
|
|
|
new_klass = __create_new_class(klass, func, safe, add, parent)
|
|
|
|
new_klass.class_eval(&b) if block_given?
|
|
|
|
__remove_methods_of_proc_class(new_klass)
|
|
|
|
new_klass.freeze
|
|
|
|
new_klass
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
end
|
|
|
|
module_function :new_proc_class
|
2003-06-24 12:46:07 -04:00
|
|
|
|
|
|
|
def eval_under_random_base(parent = nil, &b)
|
|
|
|
new_klass = __create_new_class(__get_random_basename(),
|
|
|
|
[], 4, false, parent)
|
|
|
|
ret = new_klass.class_eval(&b) if block_given?
|
|
|
|
__remove_methods_of_proc_class(new_klass)
|
|
|
|
new_klass.freeze
|
|
|
|
ret
|
|
|
|
end
|
|
|
|
module_function :eval_under_random_base
|
|
|
|
|
|
|
|
def new_proc_class_random(klass, func, safe = 4, add = false, &b)
|
|
|
|
eval_under_random_base(){
|
|
|
|
TkOption.new_proc_class(klass, func, safe, add, self, &b)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
module_function :new_proc_class_random
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
TkOption = TkOptionDB
|
2003-06-24 12:46:07 -04:00
|
|
|
TkResourceDB = TkOptionDB
|
1999-08-13 01:37:52 -04:00
|
|
|
|
|
|
|
module TkTreatFont
|
2003-08-29 04:34:14 -04:00
|
|
|
def font_configinfo(name = nil)
|
1999-08-13 01:37:52 -04:00
|
|
|
ret = TkFont.used_on(self.path)
|
|
|
|
if ret == nil
|
2003-08-29 04:34:14 -04:00
|
|
|
=begin
|
|
|
|
if name
|
|
|
|
ret = name
|
|
|
|
else
|
|
|
|
ret = TkFont.init_widget_font(self.path, self.path, 'configure')
|
|
|
|
end
|
|
|
|
=end
|
1999-08-13 01:37:52 -04:00
|
|
|
ret = TkFont.init_widget_font(self.path, self.path, 'configure')
|
|
|
|
end
|
|
|
|
ret
|
|
|
|
end
|
|
|
|
alias fontobj font_configinfo
|
|
|
|
|
|
|
|
def font_configure(slot)
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
slot = _symbolkey2str(slot)
|
2003-09-02 01:04:30 -04:00
|
|
|
|
|
|
|
if slot.key?('font')
|
|
|
|
fnt = slot.delete('font')
|
1999-08-13 01:37:52 -04:00
|
|
|
if fnt.kind_of? TkFont
|
|
|
|
return fnt.call_font_configure(self.path, self.path,'configure',slot)
|
|
|
|
else
|
2003-09-02 01:04:30 -04:00
|
|
|
if fnt
|
|
|
|
if (slot.key?('kanjifont') ||
|
|
|
|
slot.key?('latinfont') ||
|
|
|
|
slot.key?('asciifont'))
|
|
|
|
fnt = TkFont.new(fnt)
|
|
|
|
|
|
|
|
lfnt = slot.delete('latinfont')
|
|
|
|
lfnt = slot.delete('asciifont') if slot.key?('asciifont')
|
|
|
|
kfnt = slot.delete('kanjifont')
|
|
|
|
|
|
|
|
fnt.latin_replace(lfnt) if lfnt
|
|
|
|
fnt.kanji_replace(kfnt) if kfnt
|
|
|
|
else
|
|
|
|
slot['font'] = fnt
|
|
|
|
tk_call(self.path, 'configure', *hash_kv(slot))
|
|
|
|
end
|
2003-08-29 04:34:14 -04:00
|
|
|
end
|
2003-09-02 01:04:30 -04:00
|
|
|
return self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
2003-09-02 01:04:30 -04:00
|
|
|
|
|
|
|
lfnt = slot.delete('latinfont')
|
|
|
|
lfnt = slot.delete('asciifont') if slot.key?('asciifont')
|
|
|
|
kfnt = slot.delete('kanjifont')
|
|
|
|
|
|
|
|
if lfnt && kfnt
|
|
|
|
return TkFont.new(lfnt, kfnt).call_font_configure(self.path, self.path,
|
|
|
|
'configure', slot)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2003-09-02 01:04:30 -04:00
|
|
|
latinfont_configure(lfnt) if lfnt
|
|
|
|
kanjifont_configure(kfnt) if kfnt
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
tk_call(self.path, 'configure', *hash_kv(slot)) if slot != {}
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def latinfont_configure(ltn, keys=nil)
|
2003-09-02 01:04:30 -04:00
|
|
|
if (fobj = TkFont.used_on(self.path))
|
|
|
|
fobj = TkFont.new(fobj) # create a new TkFont object
|
|
|
|
elsif Tk::JAPANIZED_TK
|
|
|
|
fobj = fontobj # create a new TkFont object
|
|
|
|
else
|
|
|
|
tk_call(self.path, 'configure', '-font', ltn)
|
|
|
|
return self
|
|
|
|
end
|
|
|
|
|
|
|
|
if fobj.kind_of?(TkFont)
|
|
|
|
if ltn.kind_of? TkFont
|
|
|
|
conf = {}
|
|
|
|
ltn.latin_configinfo.each{|key,val| conf[key] = val}
|
|
|
|
if keys
|
|
|
|
fobj.latin_configure(conf.update(keys))
|
|
|
|
else
|
|
|
|
fobj.latin_configure(conf)
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
2003-09-02 01:04:30 -04:00
|
|
|
fobj.latin_replace(ltn)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
2003-09-02 01:04:30 -04:00
|
|
|
|
|
|
|
return fobj.call_font_configure(self.path, self.path, 'configure', {})
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
alias asciifont_configure latinfont_configure
|
|
|
|
|
|
|
|
def kanjifont_configure(knj, keys=nil)
|
2003-09-02 01:04:30 -04:00
|
|
|
if (fobj = TkFont.used_on(self.path))
|
|
|
|
fobj = TkFont.new(fobj) # create a new TkFont object
|
|
|
|
elsif Tk::JAPANIZED_TK
|
|
|
|
fobj = fontobj # create a new TkFont object
|
|
|
|
else
|
|
|
|
tk_call(self.path, 'configure', '-font', knj)
|
|
|
|
return self
|
|
|
|
end
|
|
|
|
|
|
|
|
if fobj.kind_of?(TkFont)
|
|
|
|
if knj.kind_of? TkFont
|
|
|
|
conf = {}
|
|
|
|
knj.kanji_configinfo.each{|key,val| conf[key] = val}
|
|
|
|
if keys
|
|
|
|
fobj.kanji_configure(conf.update(keys))
|
|
|
|
else
|
|
|
|
fobj.kanji_configure(conf)
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
2003-09-02 01:04:30 -04:00
|
|
|
fobj.kanji_replace(knj)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
2003-09-02 01:04:30 -04:00
|
|
|
|
|
|
|
return fobj.call_font_configure(self.path, self.path, 'configure', {})
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def font_copy(window, tag=nil)
|
|
|
|
if tag
|
2003-09-02 01:04:30 -04:00
|
|
|
fnt = window.tagfontobj(tag).dup
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
2003-09-02 01:04:30 -04:00
|
|
|
fnt = window.fontobj.dup
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-09-02 01:04:30 -04:00
|
|
|
fnt.call_font_configure(self.path, self.path, 'configure', {})
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def latinfont_copy(window, tag=nil)
|
2003-09-02 01:04:30 -04:00
|
|
|
fontobj.dup.call_font_configure(self.path, self.path, 'configure', {})
|
1999-08-13 01:37:52 -04:00
|
|
|
if tag
|
2003-09-02 01:04:30 -04:00
|
|
|
fontobj.latin_replace(window.tagfontobj(tag).latin_font_id)
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
2003-09-02 01:04:30 -04:00
|
|
|
fontobj.latin_replace(window.fontobj.latin_font_id)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
alias asciifont_copy latinfont_copy
|
|
|
|
|
|
|
|
def kanjifont_copy(window, tag=nil)
|
2003-09-02 01:04:30 -04:00
|
|
|
fontobj.dup.call_font_configure(self.path, self.path, 'configure', {})
|
1999-08-13 01:37:52 -04:00
|
|
|
if tag
|
2003-09-02 01:04:30 -04:00
|
|
|
fontobj.kanji_replace(window.tagfontobj(tag).kanji_font_id)
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
2003-09-02 01:04:30 -04:00
|
|
|
fontobj.kanji_replace(window.fontobj.kanji_font_id)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2002-02-28 01:53:33 -05:00
|
|
|
module TkTreatItemFont
|
|
|
|
def __conf_cmd(idx)
|
2003-03-23 12:58:57 -05:00
|
|
|
raise NotImplementedError, "need to define `__conf_cmd'"
|
2002-02-28 01:53:33 -05:00
|
|
|
end
|
|
|
|
def __item_pathname(tagOrId)
|
2003-03-23 12:58:57 -05:00
|
|
|
raise NotImplementedError, "need to define `__item_pathname'"
|
2002-02-28 01:53:33 -05:00
|
|
|
end
|
|
|
|
private :__conf_cmd, :__item_pathname
|
|
|
|
|
2003-08-29 04:34:14 -04:00
|
|
|
def tagfont_configinfo(tagOrId, name = nil)
|
2002-02-28 01:53:33 -05:00
|
|
|
pathname = __item_pathname(tagOrId)
|
|
|
|
ret = TkFont.used_on(pathname)
|
|
|
|
if ret == nil
|
2003-08-29 04:34:14 -04:00
|
|
|
=begin
|
|
|
|
if name
|
|
|
|
ret = name
|
|
|
|
else
|
|
|
|
ret = TkFont.init_widget_font(pathname, self.path,
|
|
|
|
__conf_cmd(0), __conf_cmd(1), tagOrId)
|
|
|
|
end
|
|
|
|
=end
|
2002-02-28 01:53:33 -05:00
|
|
|
ret = TkFont.init_widget_font(pathname, self.path,
|
|
|
|
__conf_cmd(0), __conf_cmd(1), tagOrId)
|
|
|
|
end
|
|
|
|
ret
|
|
|
|
end
|
|
|
|
alias tagfontobj tagfont_configinfo
|
|
|
|
|
|
|
|
def tagfont_configure(tagOrId, slot)
|
|
|
|
pathname = __item_pathname(tagOrId)
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
slot = _symbolkey2str(slot)
|
2003-09-02 01:04:30 -04:00
|
|
|
|
|
|
|
if slot.key?('font')
|
|
|
|
fnt = slot.delete('font')
|
2002-02-28 01:53:33 -05:00
|
|
|
if fnt.kind_of? TkFont
|
2003-09-02 01:04:30 -04:00
|
|
|
return fnt.call_font_configure(pathname, self.path,
|
2002-02-28 01:53:33 -05:00
|
|
|
__conf_cmd(0), __conf_cmd(1),
|
|
|
|
tagOrId, slot)
|
|
|
|
else
|
2003-09-02 01:04:30 -04:00
|
|
|
if fnt
|
|
|
|
if (slot.key?('kanjifont') ||
|
|
|
|
slot.key?('latinfont') ||
|
|
|
|
slot.key?('asciifont'))
|
|
|
|
fnt = TkFont.new(fnt)
|
|
|
|
|
|
|
|
lfnt = slot.delete('latinfont')
|
|
|
|
lfnt = slot.delete('asciifont') if slot.key?('asciifont')
|
|
|
|
kfnt = slot.delete('kanjifont')
|
|
|
|
|
|
|
|
fnt.latin_replace(lfnt) if lfnt
|
|
|
|
fnt.kanji_replace(kfnt) if kfnt
|
|
|
|
end
|
|
|
|
|
|
|
|
slot['font'] = fnt
|
|
|
|
tk_call(self.path, __conf_cmd(0), __conf_cmd(1),
|
|
|
|
tagOrId, *hash_kv(slot))
|
2003-08-29 04:34:14 -04:00
|
|
|
end
|
2003-09-02 01:04:30 -04:00
|
|
|
return self
|
2002-02-28 01:53:33 -05:00
|
|
|
end
|
|
|
|
end
|
2003-09-02 01:04:30 -04:00
|
|
|
|
|
|
|
lfnt = slot.delete('latinfont')
|
|
|
|
lfnt = slot.delete('asciifont') if slot.key?('asciifont')
|
|
|
|
kfnt = slot.delete('kanjifont')
|
|
|
|
|
|
|
|
if lfnt && kfnt
|
|
|
|
return TkFont.new(lfnt, kfnt).call_font_configure(pathname, self.path,
|
|
|
|
__conf_cmd(0),
|
|
|
|
__conf_cmd(1),
|
|
|
|
tagOrId, slot)
|
2002-02-28 01:53:33 -05:00
|
|
|
end
|
|
|
|
|
2003-09-02 01:04:30 -04:00
|
|
|
latintagfont_configure(tagOrId, lfnt) if lfnt
|
|
|
|
kanjitagfont_configure(tagOrId, kfnt) if kfnt
|
|
|
|
|
2002-02-28 01:53:33 -05:00
|
|
|
tk_call(self.path, __conf_cmd(0), __conf_cmd(1),
|
|
|
|
tagOrId, *hash_kv(slot)) if slot != {}
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def latintagfont_configure(tagOrId, ltn, keys=nil)
|
2003-09-02 01:04:30 -04:00
|
|
|
pathname = __item_pathname(tagOrId)
|
|
|
|
if (fobj = TkFont.used_on(pathname))
|
|
|
|
fobj = TkFont.new(fobj) # create a new TkFont object
|
|
|
|
elsif Tk::JAPANIZED_TK
|
|
|
|
fobj = tagfontobj(tagOrId) # create a new TkFont object
|
|
|
|
else
|
|
|
|
tk_call(self.path, __conf_cmd(0), __conf_cmd(1), tagOrId, '-font', ltn)
|
|
|
|
return self
|
|
|
|
end
|
|
|
|
|
|
|
|
if fobj.kind_of?(TkFont)
|
|
|
|
if ltn.kind_of? TkFont
|
|
|
|
conf = {}
|
|
|
|
ltn.latin_configinfo.each{|key,val| conf[key] = val}
|
|
|
|
if keys
|
|
|
|
fobj.latin_configure(conf.update(keys))
|
|
|
|
else
|
|
|
|
fobj.latin_configure(conf)
|
|
|
|
end
|
2002-02-28 01:53:33 -05:00
|
|
|
else
|
2003-09-02 01:04:30 -04:00
|
|
|
fobj.latin_replace(ltn)
|
2002-02-28 01:53:33 -05:00
|
|
|
end
|
|
|
|
end
|
2003-09-02 01:04:30 -04:00
|
|
|
|
|
|
|
return fobj.call_font_configure(pathname, self.path,
|
|
|
|
__conf_cmd(0), __conf_cmd(1), tagOrId, {})
|
2002-02-28 01:53:33 -05:00
|
|
|
end
|
|
|
|
alias asciitagfont_configure latintagfont_configure
|
|
|
|
|
|
|
|
def kanjitagfont_configure(tagOrId, knj, keys=nil)
|
2003-09-02 01:04:30 -04:00
|
|
|
pathname = __item_pathname(tagOrId)
|
|
|
|
if (fobj = TkFont.used_on(pathname))
|
|
|
|
fobj = TkFont.new(fobj) # create a new TkFont object
|
|
|
|
elsif Tk::JAPANIZED_TK
|
|
|
|
fobj = tagfontobj(tagOrId) # create a new TkFont object
|
|
|
|
else
|
|
|
|
tk_call(self.path, __conf_cmd(0), __conf_cmd(1), tagOrId, '-font', knj)
|
|
|
|
return self
|
|
|
|
end
|
|
|
|
|
|
|
|
if fobj.kind_of?(TkFont)
|
|
|
|
if knj.kind_of? TkFont
|
|
|
|
conf = {}
|
|
|
|
knj.kanji_configinfo.each{|key,val| conf[key] = val}
|
|
|
|
if keys
|
|
|
|
fobj.kanji_configure(conf.update(keys))
|
|
|
|
else
|
|
|
|
fobj.kanji_configure(conf)
|
|
|
|
end
|
2002-02-28 01:53:33 -05:00
|
|
|
else
|
2003-09-02 01:04:30 -04:00
|
|
|
fobj.kanji_replace(knj)
|
2002-02-28 01:53:33 -05:00
|
|
|
end
|
|
|
|
end
|
2003-09-02 01:04:30 -04:00
|
|
|
|
|
|
|
return fobj.call_font_configure(pathname, self.path,
|
|
|
|
__conf_cmd(0), __conf_cmd(1), tagOrId, {})
|
2002-02-28 01:53:33 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def tagfont_copy(tagOrId, window, wintag=nil)
|
2003-09-02 01:04:30 -04:00
|
|
|
pathname = __item_pathname(tagOrId)
|
2002-02-28 01:53:33 -05:00
|
|
|
if wintag
|
2003-09-02 01:04:30 -04:00
|
|
|
fnt = window.tagfontobj(wintag).dup
|
2002-02-28 01:53:33 -05:00
|
|
|
else
|
2003-09-02 01:04:30 -04:00
|
|
|
fnt = window.fontobj.dup
|
2002-02-28 01:53:33 -05:00
|
|
|
end
|
2003-09-02 01:04:30 -04:00
|
|
|
fnt.call_font_configure(pathname, self.path,
|
|
|
|
__conf_cmd(0), __conf_cmd(1), tagOrId, {})
|
|
|
|
return self
|
2002-02-28 01:53:33 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def latintagfont_copy(tagOrId, window, wintag=nil)
|
2003-09-02 01:04:30 -04:00
|
|
|
pathname = __item_pathname(tagOrId)
|
|
|
|
tagfontobj(tagOrId).dup.call_font_configure(pathname, self.path,
|
|
|
|
__conf_cmd(0), __conf_cmd(1),
|
|
|
|
tagOrId, {})
|
2002-02-28 01:53:33 -05:00
|
|
|
if wintag
|
2003-09-02 01:04:30 -04:00
|
|
|
tagfontobj(tagOrId).
|
|
|
|
latin_replace(window.tagfontobj(wintag).latin_font_id)
|
2002-02-28 01:53:33 -05:00
|
|
|
else
|
2003-09-02 01:04:30 -04:00
|
|
|
tagfontobj(tagOrId).latin_replace(window.fontobj.latin_font_id)
|
2002-02-28 01:53:33 -05:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
2002-02-28 01:53:33 -05:00
|
|
|
end
|
|
|
|
alias asciitagfont_copy latintagfont_copy
|
|
|
|
|
|
|
|
def kanjitagfont_copy(tagOrId, window, wintag=nil)
|
2003-09-02 01:04:30 -04:00
|
|
|
pathname = __item_pathname(tagOrId)
|
|
|
|
tagfontobj(tagOrId).dup.call_font_configure(pathname, self.path,
|
|
|
|
__conf_cmd(0), __conf_cmd(1),
|
|
|
|
tagOrId, {})
|
2002-02-28 01:53:33 -05:00
|
|
|
if wintag
|
2003-09-02 01:04:30 -04:00
|
|
|
tagfontobj(tagOrId).
|
|
|
|
kanji_replace(window.tagfontobj(wintag).kanji_font_id)
|
2002-02-28 01:53:33 -05:00
|
|
|
else
|
2003-09-02 01:04:30 -04:00
|
|
|
tagfontobj(tagOrId).kanji_replace(window.fontobj.kanji_font_id)
|
2002-02-28 01:53:33 -05:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
2002-02-28 01:53:33 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
class TkObject<TkKernel
|
|
|
|
include Tk
|
|
|
|
include TkTreatFont
|
2000-01-17 03:37:53 -05:00
|
|
|
include TkBindCore
|
1999-08-13 01:37:52 -04:00
|
|
|
|
|
|
|
def path
|
|
|
|
return @path
|
|
|
|
end
|
|
|
|
|
|
|
|
def epath
|
|
|
|
return @path
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_eval
|
|
|
|
@path
|
|
|
|
end
|
|
|
|
|
|
|
|
def tk_send(cmd, *rest)
|
|
|
|
tk_call path, cmd, *rest
|
|
|
|
end
|
|
|
|
private :tk_send
|
|
|
|
|
|
|
|
def method_missing(id, *args)
|
|
|
|
name = id.id2name
|
|
|
|
case args.length
|
|
|
|
when 1
|
|
|
|
configure name, args[0]
|
|
|
|
when 0
|
|
|
|
begin
|
|
|
|
cget name
|
|
|
|
rescue
|
2003-06-25 01:49:10 -04:00
|
|
|
fail NameError,
|
|
|
|
"undefined local variable or method `#{name}' for #{self.to_s}",
|
|
|
|
error_at
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
else
|
|
|
|
fail NameError, "undefined method `#{name}' for #{self.to_s}", error_at
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def [](id)
|
|
|
|
cget id
|
|
|
|
end
|
|
|
|
|
|
|
|
def []=(id, val)
|
|
|
|
configure id, val
|
|
|
|
end
|
|
|
|
|
|
|
|
def cget(slot)
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
case slot.to_s
|
2001-09-05 02:54:57 -04:00
|
|
|
when 'text', 'label', 'show', 'data', 'file'
|
2000-11-27 04:23:38 -05:00
|
|
|
tk_call path, 'cget', "-#{slot}"
|
2003-08-29 04:34:14 -04:00
|
|
|
when 'font', 'kanjifont'
|
2003-09-02 01:04:30 -04:00
|
|
|
#fnt = tk_tcl2ruby(tk_call(path, 'cget', "-#{slot}"))
|
|
|
|
fnt = tk_tcl2ruby(tk_call(path, 'cget', "-font"))
|
2003-08-29 04:34:14 -04:00
|
|
|
unless fnt.kind_of?(TkFont)
|
|
|
|
fnt = fontobj(fnt)
|
|
|
|
end
|
2003-09-02 01:04:30 -04:00
|
|
|
if slot == 'kanjifont' && JAPANIZED_TK && TK_VERSION =~ /^4\.*/
|
|
|
|
# obsolete; just for compatibility
|
|
|
|
fnt.kanji_font
|
|
|
|
else
|
|
|
|
fnt
|
|
|
|
end
|
2000-11-27 04:23:38 -05:00
|
|
|
else
|
2002-06-28 10:42:46 -04:00
|
|
|
tk_tcl2ruby tk_call(path, 'cget', "-#{slot}")
|
2000-11-27 04:23:38 -05:00
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def configure(slot, value=None)
|
|
|
|
if slot.kind_of? Hash
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
if (slot['font'] || slot[:font] ||
|
|
|
|
slot['kanjifont'] || slot[:kanjifont] ||
|
|
|
|
slot['latinfont'] || slot[:latinfont] ||
|
|
|
|
slot['asciifont'] || slot[:asciifont] )
|
|
|
|
font_configure(slot)
|
2003-07-11 03:17:46 -04:00
|
|
|
elsif slot.size > 0
|
1999-08-13 01:37:52 -04:00
|
|
|
tk_call path, 'configure', *hash_kv(slot)
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
if (slot == 'font' || slot == :font ||
|
|
|
|
slot == 'kanjifont' || slot == :kanjifont ||
|
|
|
|
slot == 'latinfont' || slot == :latinfont ||
|
|
|
|
slot == 'asciifont' || slot == :asciifont )
|
1999-08-13 01:37:52 -04:00
|
|
|
if value == None
|
|
|
|
fontobj
|
|
|
|
else
|
|
|
|
font_configure({slot=>value})
|
|
|
|
end
|
|
|
|
else
|
|
|
|
tk_call path, 'configure', "-#{slot}", value
|
|
|
|
end
|
|
|
|
end
|
2003-06-12 17:14:11 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def configure_cmd(slot, value)
|
|
|
|
configure slot, install_cmd(value)
|
|
|
|
end
|
|
|
|
|
|
|
|
def configinfo(slot = nil)
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
if slot == 'font' || slot == :font ||
|
|
|
|
slot == 'kanjifont' || slot == :kanjifont
|
2003-08-29 04:34:14 -04:00
|
|
|
conf = tk_split_simplelist(tk_send('configure', "-#{slot}") )
|
|
|
|
conf[0] = conf[0][1..-1]
|
|
|
|
conf[4] = fontobj(conf[4])
|
|
|
|
conf
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
|
|
|
if slot
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
case slot.to_s
|
2001-09-05 02:54:57 -04:00
|
|
|
when 'text', 'label', 'show', 'data', 'file'
|
2000-11-27 04:23:38 -05:00
|
|
|
conf = tk_split_simplelist(tk_send('configure', "-#{slot}") )
|
|
|
|
else
|
|
|
|
conf = tk_split_list(tk_send('configure', "-#{slot}") )
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
conf[0] = conf[0][1..-1]
|
|
|
|
conf
|
|
|
|
else
|
2000-11-27 04:23:38 -05:00
|
|
|
ret = tk_split_simplelist(tk_send('configure') ).collect{|conflist|
|
|
|
|
conf = tk_split_simplelist(conflist)
|
1999-08-13 01:37:52 -04:00
|
|
|
conf[0] = conf[0][1..-1]
|
2000-11-27 04:23:38 -05:00
|
|
|
case conf[0]
|
2001-09-05 02:54:57 -04:00
|
|
|
when 'text', 'label', 'show', 'data', 'file'
|
2000-11-27 04:23:38 -05:00
|
|
|
else
|
|
|
|
if conf[3]
|
|
|
|
if conf[3].index('{')
|
|
|
|
conf[3] = tk_split_list(conf[3])
|
|
|
|
else
|
|
|
|
conf[3] = tk_tcl2ruby(conf[3])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if conf[4]
|
|
|
|
if conf[4].index('{')
|
|
|
|
conf[4] = tk_split_list(conf[4])
|
|
|
|
else
|
|
|
|
conf[4] = tk_tcl2ruby(conf[4])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
conf
|
|
|
|
}
|
2000-11-27 04:23:38 -05:00
|
|
|
fontconf = ret.assoc('font')
|
|
|
|
if fontconf
|
1999-08-13 01:37:52 -04:00
|
|
|
ret.delete_if{|item| item[0] == 'font' || item[0] == 'kanjifont'}
|
2003-08-29 04:34:14 -04:00
|
|
|
fontconf[4] = fontobj(fontconf[4])
|
2000-11-27 04:23:38 -05:00
|
|
|
ret.push(fontconf)
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
|
|
|
ret
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def event_generate(context, keys=nil)
|
|
|
|
if keys
|
|
|
|
tk_call('event', 'generate', path,
|
|
|
|
"<#{tk_event_sequence(context)}>", *hash_kv(keys))
|
|
|
|
else
|
|
|
|
tk_call('event', 'generate', path, "<#{tk_event_sequence(context)}>")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def tk_trace_variable(v)
|
|
|
|
unless v.kind_of?(TkVariable)
|
2003-12-02 23:55:07 -05:00
|
|
|
fail(ArgumentError,
|
|
|
|
Kernel.format("type error (%s); must be TkVariable object",
|
|
|
|
v.class))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
v
|
|
|
|
end
|
|
|
|
private :tk_trace_variable
|
|
|
|
|
|
|
|
def destroy
|
2003-07-30 00:36:29 -04:00
|
|
|
# tk_call 'trace', 'vdelete', @tk_vn, 'w', @var_id if @var_id
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TkWindow<TkObject
|
2003-07-01 18:08:19 -04:00
|
|
|
include TkWinfo
|
2000-01-17 03:37:53 -05:00
|
|
|
extend TkBindCore
|
1999-08-13 01:37:52 -04:00
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
WidgetClassName = ''.freeze
|
|
|
|
def self.to_eval
|
|
|
|
self::WidgetClassName
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def initialize(parent=nil, keys=nil)
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
if parent.kind_of? Hash
|
|
|
|
keys = _symbolkey2str(parent)
|
|
|
|
parent = keys.delete('parent')
|
|
|
|
widgetname = keys.delete('widgetname')
|
|
|
|
install_win(if parent then parent.path end, widgetname)
|
2003-06-18 15:46:20 -04:00
|
|
|
without_creating = keys.delete('without_creating')
|
|
|
|
if without_creating && !widgetname
|
2003-06-12 18:13:13 -04:00
|
|
|
fail ArgumentError,
|
2003-06-18 15:46:20 -04:00
|
|
|
"if set 'without_creating' to true, need to define 'widgetname'"
|
2003-06-12 18:13:13 -04:00
|
|
|
end
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
elsif keys
|
|
|
|
keys = _symbolkey2str(keys)
|
|
|
|
widgetname = keys.delete('widgetname')
|
|
|
|
install_win(if parent then parent.path end, widgetname)
|
2003-06-18 15:46:20 -04:00
|
|
|
without_creating = keys.delete('without_creating')
|
|
|
|
if without_creating && !widgetname
|
2003-06-12 18:13:13 -04:00
|
|
|
fail ArgumentError,
|
2003-06-18 15:46:20 -04:00
|
|
|
"if set 'without_creating' to true, need to define 'widgetname'"
|
2003-06-12 18:13:13 -04:00
|
|
|
end
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
else
|
|
|
|
install_win(if parent then parent.path end)
|
|
|
|
end
|
2002-02-28 01:53:33 -05:00
|
|
|
if self.method(:create_self).arity == 0
|
|
|
|
p 'create_self has no arg' if $DEBUG
|
2003-06-18 15:46:20 -04:00
|
|
|
create_self unless without_creating
|
2002-02-28 01:53:33 -05:00
|
|
|
if keys
|
2003-06-12 18:13:13 -04:00
|
|
|
# tk_call @path, 'configure', *hash_kv(keys)
|
|
|
|
configure(keys)
|
2002-02-28 01:53:33 -05:00
|
|
|
end
|
|
|
|
else
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
p 'create_self has args' if $DEBUG
|
2002-02-28 01:53:33 -05:00
|
|
|
fontkeys = {}
|
|
|
|
if keys
|
2003-06-12 18:13:13 -04:00
|
|
|
['font', 'kanjifont', 'latinfont', 'asciifont'].each{|key|
|
|
|
|
fontkeys[key] = keys.delete(key) if keys.key?(key)
|
|
|
|
}
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
if without_creating && keys
|
2003-06-12 18:13:13 -04:00
|
|
|
configure(keys)
|
|
|
|
else
|
|
|
|
create_self(keys)
|
2002-02-28 01:53:33 -05:00
|
|
|
end
|
|
|
|
font_configure(fontkeys) unless fontkeys.empty?
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_self
|
2003-11-10 20:45:06 -05:00
|
|
|
fail RuntimeError, "TkWindow is an abstract class"
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
private :create_self
|
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
def bind_class
|
|
|
|
@db_class || self.class()
|
|
|
|
end
|
|
|
|
|
2003-06-25 10:40:32 -04:00
|
|
|
def database_classname
|
2003-06-18 15:46:20 -04:00
|
|
|
TkWinfo.classname(self)
|
|
|
|
end
|
2003-06-25 10:40:32 -04:00
|
|
|
def database_class
|
|
|
|
name = database_classname()
|
|
|
|
if WidgetClassNames[name]
|
|
|
|
WidgetClassNames[name]
|
|
|
|
else
|
|
|
|
TkDatabaseClass.new(name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def self.database_classname
|
|
|
|
self::WidgetClassName
|
|
|
|
end
|
|
|
|
def self.database_class
|
|
|
|
WidgetClassNames[self::WidgetClassName]
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def pack(keys = nil)
|
|
|
|
tk_call 'pack', epath, *hash_kv(keys)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
def pack_in(target, keys = nil)
|
|
|
|
if keys
|
|
|
|
keys = keys.dup
|
|
|
|
keys['in'] = target
|
|
|
|
else
|
|
|
|
keys = {'in'=>target}
|
|
|
|
end
|
|
|
|
tk_call 'pack', epath, *hash_kv(keys)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2000-06-12 03:48:31 -04:00
|
|
|
def unpack
|
1999-08-13 01:37:52 -04:00
|
|
|
tk_call 'pack', 'forget', epath
|
|
|
|
self
|
|
|
|
end
|
2000-11-27 04:23:38 -05:00
|
|
|
alias pack_forget unpack
|
|
|
|
|
|
|
|
def pack_config(slot, value=None)
|
|
|
|
if slot.kind_of? Hash
|
|
|
|
tk_call 'pack', 'configure', epath, *hash_kv(slot)
|
|
|
|
else
|
|
|
|
tk_call 'pack', 'configure', epath, "-#{slot}", value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def pack_info()
|
|
|
|
ilist = list(tk_call('pack', 'info', epath))
|
|
|
|
info = {}
|
|
|
|
while key = ilist.shift
|
|
|
|
info[key[1..-1]] = ilist.shift
|
|
|
|
end
|
|
|
|
return info
|
|
|
|
end
|
|
|
|
|
2003-11-21 02:49:11 -05:00
|
|
|
def pack_propagate(mode=None)
|
|
|
|
if mode == None
|
2000-11-27 04:23:38 -05:00
|
|
|
tk_call('pack', 'propagate', epath, mode)
|
|
|
|
else
|
|
|
|
bool(tk_call('pack', 'propagate', epath))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def pack_slaves()
|
|
|
|
list(tk_call('pack', 'slaves', epath))
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
|
|
|
|
def grid(keys = nil)
|
|
|
|
tk_call 'grid', epath, *hash_kv(keys)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
def grid_in(target, keys = nil)
|
|
|
|
if keys
|
|
|
|
keys = keys.dup
|
|
|
|
keys['in'] = target
|
|
|
|
else
|
|
|
|
keys = {'in'=>target}
|
|
|
|
end
|
|
|
|
tk_call 'grid', epath, *hash_kv(keys)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2000-06-12 03:48:31 -04:00
|
|
|
def ungrid
|
1999-08-13 01:37:52 -04:00
|
|
|
tk_call 'grid', 'forget', epath
|
|
|
|
self
|
|
|
|
end
|
2000-11-27 04:23:38 -05:00
|
|
|
alias grid_forget ungrid
|
|
|
|
|
|
|
|
def grid_bbox(*args)
|
|
|
|
list(tk_call('grid', 'bbox', epath, *args))
|
|
|
|
end
|
|
|
|
|
|
|
|
def grid_config(slot, value=None)
|
|
|
|
if slot.kind_of? Hash
|
|
|
|
tk_call 'grid', 'configure', epath, *hash_kv(slot)
|
|
|
|
else
|
|
|
|
tk_call 'grid', 'configure', epath, "-#{slot}", value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def grid_columnconfig(index, keys)
|
2002-02-28 01:53:33 -05:00
|
|
|
tk_call('grid', 'columnconfigure', epath, index, *hash_kv(keys))
|
2000-11-27 04:23:38 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def grid_rowconfig(index, keys)
|
2002-02-28 01:53:33 -05:00
|
|
|
tk_call('grid', 'rowconfigure', epath, index, *hash_kv(keys))
|
2000-11-27 04:23:38 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def grid_columnconfiginfo(index, slot=nil)
|
|
|
|
if slot
|
2003-06-18 15:46:20 -04:00
|
|
|
tk_call('grid', 'columnconfigure', epath, index, "-#{slot}").to_i
|
2000-11-27 04:23:38 -05:00
|
|
|
else
|
|
|
|
ilist = list(tk_call('grid', 'columnconfigure', epath, index))
|
|
|
|
info = {}
|
|
|
|
while key = ilist.shift
|
|
|
|
info[key[1..-1]] = ilist.shift
|
|
|
|
end
|
|
|
|
info
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def grid_rowconfiginfo(index, slot=nil)
|
|
|
|
if slot
|
2003-06-18 15:46:20 -04:00
|
|
|
tk_call('grid', 'rowconfigure', epath, index, "-#{slot}").to_i
|
2000-11-27 04:23:38 -05:00
|
|
|
else
|
|
|
|
ilist = list(tk_call('grid', 'rowconfigure', epath, index))
|
|
|
|
info = {}
|
|
|
|
while key = ilist.shift
|
|
|
|
info[key[1..-1]] = ilist.shift
|
|
|
|
end
|
|
|
|
info
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def grid_info()
|
|
|
|
list(tk_call('grid', 'info', epath))
|
|
|
|
end
|
|
|
|
|
|
|
|
def grid_location(x, y)
|
|
|
|
list(tk_call('grid', 'location', epath, x, y))
|
|
|
|
end
|
|
|
|
|
2003-11-21 02:49:11 -05:00
|
|
|
def grid_propagate(mode=None)
|
|
|
|
if mode == None
|
2001-03-27 02:10:58 -05:00
|
|
|
tk_call('grid', 'propagate', epath, mode)
|
2000-11-27 04:23:38 -05:00
|
|
|
else
|
|
|
|
bool(tk_call('grid', 'propagate', epath))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def grid_remove()
|
|
|
|
tk_call 'grid', 'remove', epath
|
|
|
|
end
|
|
|
|
|
|
|
|
def grid_size()
|
|
|
|
tk_call 'grid', 'size', epath
|
|
|
|
end
|
|
|
|
|
|
|
|
def grid_slaves(args)
|
|
|
|
list(tk_call('grid', 'slaves', epath, *hash_kv(args)))
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
|
|
|
|
def place(keys = nil)
|
|
|
|
tk_call 'place', epath, *hash_kv(keys)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
def place_in(target, keys = nil)
|
|
|
|
if keys
|
|
|
|
keys = keys.dup
|
|
|
|
keys['in'] = target
|
|
|
|
else
|
|
|
|
keys = {'in'=>target}
|
|
|
|
end
|
|
|
|
tk_call 'place', epath, *hash_kv(keys)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2000-06-12 03:48:31 -04:00
|
|
|
def unplace
|
|
|
|
tk_call 'place', 'forget', epath
|
1999-08-13 01:37:52 -04:00
|
|
|
self
|
|
|
|
end
|
|
|
|
alias place_forget unplace
|
|
|
|
|
2000-11-27 04:23:38 -05:00
|
|
|
def place_config(slot, value=None)
|
|
|
|
if slot.kind_of? Hash
|
|
|
|
tk_call 'place', 'configure', epath, *hash_kv(slot)
|
|
|
|
else
|
|
|
|
tk_call 'place', 'configure', epath, "-#{slot}", value
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2000-11-27 04:23:38 -05:00
|
|
|
def place_configinfo(slot = nil)
|
|
|
|
# for >= Tk8.4a2 ?
|
|
|
|
if slot
|
|
|
|
conf = tk_split_list(tk_call('place', 'configure', epath, "-#{slot}") )
|
|
|
|
conf[0] = conf[0][1..-1]
|
|
|
|
conf
|
|
|
|
else
|
|
|
|
tk_split_simplelist(tk_call('place',
|
|
|
|
'configure', epath)).collect{|conflist|
|
|
|
|
conf = tk_split_simplelist(conflist)
|
|
|
|
conf[0] = conf[0][1..-1]
|
|
|
|
conf
|
|
|
|
}
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2000-11-27 04:23:38 -05:00
|
|
|
def place_info()
|
|
|
|
ilist = list(tk_call('place', 'info', epath))
|
1999-08-13 01:37:52 -04:00
|
|
|
info = {}
|
|
|
|
while key = ilist.shift
|
|
|
|
info[key[1..-1]] = ilist.shift
|
|
|
|
end
|
|
|
|
return info
|
|
|
|
end
|
|
|
|
|
|
|
|
def place_slaves()
|
|
|
|
list(tk_call('place', 'slaves', epath))
|
|
|
|
end
|
|
|
|
|
|
|
|
def focus(force=false)
|
|
|
|
if force
|
|
|
|
tk_call 'focus', '-force', path
|
|
|
|
else
|
|
|
|
tk_call 'focus', path
|
|
|
|
end
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def grab(*args)
|
|
|
|
if !args or args.length == 0
|
|
|
|
tk_call 'grab', 'set', path
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
elsif args.length == 1
|
|
|
|
case args[0]
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
when 'global', :global
|
2003-06-18 15:46:20 -04:00
|
|
|
#return(tk_call('grab', 'set', '-global', path))
|
|
|
|
tk_call('grab', 'set', '-global', path)
|
|
|
|
return self
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
when 'release', :release
|
2003-06-18 15:46:20 -04:00
|
|
|
#return tk_call('grab', 'release', path)
|
|
|
|
tk_call('grab', 'release', path)
|
|
|
|
return self
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
|
|
|
val = tk_call('grab', args[0], path)
|
|
|
|
end
|
|
|
|
case args[0]
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
when 'current', :current
|
1999-08-13 01:37:52 -04:00
|
|
|
return window(val)
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
when 'status', :status
|
1999-08-13 01:37:52 -04:00
|
|
|
return val
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
|
|
|
fail ArgumentError, 'wrong # of args'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
def grab_current
|
|
|
|
grab('current')
|
|
|
|
end
|
2003-11-22 08:52:48 -05:00
|
|
|
def grab_release
|
|
|
|
grab('release')
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def grab_set
|
|
|
|
grab('set')
|
|
|
|
end
|
|
|
|
def grab_set_global
|
|
|
|
grab('global')
|
|
|
|
end
|
|
|
|
def grab_status
|
|
|
|
grab('status')
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def lower(below=None)
|
2000-06-12 03:48:31 -04:00
|
|
|
tk_call 'lower', epath, below
|
1999-08-13 01:37:52 -04:00
|
|
|
self
|
|
|
|
end
|
|
|
|
def raise(above=None)
|
2000-06-12 03:48:31 -04:00
|
|
|
tk_call 'raise', epath, above
|
1999-08-13 01:37:52 -04:00
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2003-06-16 03:14:50 -04:00
|
|
|
def command(cmd=Proc.new)
|
1999-08-13 01:37:52 -04:00
|
|
|
configure_cmd 'command', cmd
|
|
|
|
end
|
|
|
|
|
|
|
|
def colormodel model=None
|
|
|
|
tk_call 'tk', 'colormodel', path, model
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2003-11-05 09:00:11 -05:00
|
|
|
def caret(keys=nil)
|
|
|
|
TkXIM.caret(path, keys)
|
|
|
|
end
|
|
|
|
|
2003-07-31 16:52:40 -04:00
|
|
|
def destroy
|
|
|
|
super
|
2003-07-30 00:36:29 -04:00
|
|
|
children = []
|
|
|
|
rexp = /^#{self.path}\.[^.]+$/
|
|
|
|
TkCore::INTERP.tk_windows.each{|path, obj|
|
2003-07-31 16:52:40 -04:00
|
|
|
children << [path, obj] if path =~ rexp
|
2003-07-30 00:36:29 -04:00
|
|
|
}
|
|
|
|
if defined?(@cmdtbl)
|
1999-08-13 01:37:52 -04:00
|
|
|
for id in @cmdtbl
|
|
|
|
uninstall_cmd id
|
|
|
|
end
|
|
|
|
end
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
children.each{|path, obj|
|
|
|
|
if defined?(@cmdtbl)
|
|
|
|
for id in @cmdtbl
|
|
|
|
uninstall_cmd id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
TkCore::INTERP.tk_windows.delete(path)
|
|
|
|
}
|
|
|
|
|
2003-09-07 03:10:44 -04:00
|
|
|
begin
|
|
|
|
tk_call 'destroy', epath
|
|
|
|
rescue
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
uninstall_win
|
|
|
|
end
|
|
|
|
|
2003-10-14 11:25:45 -04:00
|
|
|
def wait_visibility(on_thread = true)
|
|
|
|
if $SAFE >= 4
|
|
|
|
fail SecurityError, "can't wait visibility at $SAFE >= 4"
|
|
|
|
end
|
|
|
|
if on_thread
|
|
|
|
INTERP._thread_tkwait('visibility', path)
|
|
|
|
else
|
|
|
|
INTERP._invoke('tkwait', 'visibility', path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def eventloop_wait_visibility
|
|
|
|
wait_visibility(false)
|
|
|
|
end
|
|
|
|
def thread_wait_visibility
|
|
|
|
wait_visibility(true)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
alias wait wait_visibility
|
2003-10-14 11:25:45 -04:00
|
|
|
alias tkwait wait_visibility
|
|
|
|
alias eventloop_wait eventloop_wait_visibility
|
|
|
|
alias eventloop_tkwait eventloop_wait_visibility
|
|
|
|
alias eventloop_tkwait_visibility eventloop_wait_visibility
|
|
|
|
alias thread_wait thread_wait_visibility
|
|
|
|
alias thread_tkwait thread_wait_visibility
|
|
|
|
alias thread_tkwait_visibility thread_wait_visibility
|
|
|
|
|
|
|
|
def wait_destroy(on_thread = true)
|
|
|
|
if $SAFE >= 4
|
|
|
|
fail SecurityError, "can't wait destroy at $SAFE >= 4"
|
|
|
|
end
|
|
|
|
if on_thread
|
|
|
|
INTERP._thread_tkwait('window', epath)
|
|
|
|
else
|
|
|
|
INTERP._invoke('tkwait', 'window', epath)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def eventloop_wait_destroy
|
|
|
|
wait_destroy(false)
|
|
|
|
end
|
|
|
|
def thread_wait_destroy
|
|
|
|
wait_destroy(true)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-10-14 11:25:45 -04:00
|
|
|
alias tkwait_destroy wait_destroy
|
|
|
|
alias eventloop_tkwait_destroy eventloop_wait_destroy
|
|
|
|
alias thread_tkwait_destroy thread_wait_destroy
|
1999-08-13 01:37:52 -04:00
|
|
|
|
|
|
|
def bindtags(taglist=nil)
|
|
|
|
if taglist
|
2003-06-18 15:46:20 -04:00
|
|
|
fail ArgumentError, "taglist must be Array" unless taglist.kind_of? Array
|
1999-08-13 01:37:52 -04:00
|
|
|
tk_call('bindtags', path, taglist)
|
2003-06-18 15:46:20 -04:00
|
|
|
taglist
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
2000-01-17 03:37:53 -05:00
|
|
|
list(tk_call('bindtags', path)).collect{|tag|
|
|
|
|
if tag.kind_of?(String)
|
|
|
|
if cls = WidgetClassNames[tag]
|
|
|
|
cls
|
|
|
|
elsif btag = TkBindTag.id2obj(tag)
|
|
|
|
btag
|
|
|
|
else
|
|
|
|
tag
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
|
|
|
tag
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
|
|
|
def bindtags=(taglist)
|
|
|
|
bindtags(taglist)
|
|
|
|
end
|
|
|
|
|
|
|
|
def bindtags_shift
|
|
|
|
taglist = bindtags
|
|
|
|
tag = taglist.shift
|
|
|
|
bindtags(taglist)
|
|
|
|
tag
|
|
|
|
end
|
|
|
|
|
|
|
|
def bindtags_unshift(tag)
|
|
|
|
bindtags(bindtags().unshift(tag))
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class TkRoot<TkWindow
|
|
|
|
include Wm
|
2003-07-23 12:07:35 -04:00
|
|
|
|
|
|
|
=begin
|
1999-08-13 01:37:52 -04:00
|
|
|
ROOT = []
|
2003-06-21 08:55:17 -04:00
|
|
|
def TkRoot.new(keys=nil)
|
2003-06-18 15:46:20 -04:00
|
|
|
if ROOT[0]
|
|
|
|
Tk_WINDOWS["."] = ROOT[0]
|
|
|
|
return ROOT[0]
|
|
|
|
end
|
|
|
|
new = super(:without_creating=>true, :widgetname=>'.')
|
2003-06-23 10:22:44 -04:00
|
|
|
if keys # wm commands
|
|
|
|
keys.each{|k,v|
|
|
|
|
if v.kind_of? Array
|
|
|
|
new.send(k,*v)
|
|
|
|
else
|
|
|
|
new.send(k,v)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
ROOT[0] = new
|
|
|
|
Tk_WINDOWS["."] = new
|
|
|
|
end
|
2003-07-23 12:07:35 -04:00
|
|
|
=end
|
2003-07-31 23:53:38 -04:00
|
|
|
def TkRoot.new(keys=nil, &b)
|
2003-07-23 12:07:35 -04:00
|
|
|
unless TkCore::INTERP.tk_windows['.']
|
|
|
|
TkCore::INTERP.tk_windows['.'] =
|
|
|
|
super(:without_creating=>true, :widgetname=>'.')
|
|
|
|
end
|
|
|
|
root = TkCore::INTERP.tk_windows['.']
|
|
|
|
if keys # wm commands
|
|
|
|
keys.each{|k,v|
|
|
|
|
if v.kind_of? Array
|
|
|
|
root.send(k,*v)
|
|
|
|
else
|
|
|
|
root.send(k,v)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
2003-07-31 23:53:38 -04:00
|
|
|
root.instance_eval(&b) if block_given?
|
|
|
|
root
|
2003-07-23 12:07:35 -04:00
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
|
|
|
|
WidgetClassName = 'Tk'.freeze
|
1999-08-24 04:21:56 -04:00
|
|
|
WidgetClassNames[WidgetClassName] = self
|
1999-08-13 01:37:52 -04:00
|
|
|
|
|
|
|
def create_self
|
|
|
|
@path = '.'
|
|
|
|
end
|
|
|
|
def path
|
|
|
|
"."
|
|
|
|
end
|
2003-10-25 18:36:50 -04:00
|
|
|
|
|
|
|
def TkRoot.destroy
|
|
|
|
TkCore::INTERP._invoke('destroy', '.')
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class TkToplevel<TkWindow
|
|
|
|
include Wm
|
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['toplevel'.freeze].freeze
|
1999-08-13 01:37:52 -04:00
|
|
|
WidgetClassName = 'Toplevel'.freeze
|
1999-08-24 04:21:56 -04:00
|
|
|
WidgetClassNames[WidgetClassName] = self
|
1999-08-13 01:37:52 -04:00
|
|
|
|
2002-02-28 01:53:33 -05:00
|
|
|
################# old version
|
|
|
|
# def initialize(parent=nil, screen=nil, classname=nil, keys=nil)
|
|
|
|
# if screen.kind_of? Hash
|
|
|
|
# keys = screen.dup
|
|
|
|
# else
|
|
|
|
# @screen = screen
|
|
|
|
# end
|
|
|
|
# @classname = classname
|
|
|
|
# if keys.kind_of? Hash
|
|
|
|
# keys = keys.dup
|
|
|
|
# @classname = keys.delete('classname') if keys.key?('classname')
|
|
|
|
# @colormap = keys.delete('colormap') if keys.key?('colormap')
|
|
|
|
# @container = keys.delete('container') if keys.key?('container')
|
|
|
|
# @screen = keys.delete('screen') if keys.key?('screen')
|
|
|
|
# @use = keys.delete('use') if keys.key?('use')
|
|
|
|
# @visual = keys.delete('visual') if keys.key?('visual')
|
|
|
|
# end
|
|
|
|
# super(parent, keys)
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# def create_self
|
|
|
|
# s = []
|
|
|
|
# s << "-class" << @classname if @classname
|
|
|
|
# s << "-colormap" << @colormap if @colormap
|
|
|
|
# s << "-container" << @container if @container
|
|
|
|
# s << "-screen" << @screen if @screen
|
|
|
|
# s << "-use" << @use if @use
|
|
|
|
# s << "-visual" << @visual if @visual
|
|
|
|
# tk_call 'toplevel', @path, *s
|
|
|
|
# end
|
|
|
|
#################
|
|
|
|
|
2003-06-21 08:55:17 -04:00
|
|
|
def _wm_command_option_chk(keys)
|
2003-06-23 10:22:44 -04:00
|
|
|
keys = {} unless keys
|
2003-06-21 08:55:17 -04:00
|
|
|
new_keys = {}
|
|
|
|
wm_cmds = {}
|
|
|
|
keys.each{|k,v|
|
|
|
|
if Wm.method_defined?(k)
|
|
|
|
case k
|
2003-07-27 15:35:06 -04:00
|
|
|
when 'screen','class','colormap','container','use','visual'
|
2003-06-21 08:55:17 -04:00
|
|
|
new_keys[k] = v
|
|
|
|
else
|
|
|
|
case self.method(k).arity
|
|
|
|
when -1,1
|
|
|
|
wm_cmds[k] = v
|
|
|
|
else
|
|
|
|
new_keys[k] = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
new_keys[k] = v
|
|
|
|
end
|
|
|
|
}
|
|
|
|
[new_keys, wm_cmds]
|
|
|
|
end
|
|
|
|
private :_wm_command_option_chk
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def initialize(parent=nil, screen=nil, classname=nil, keys=nil)
|
2003-06-25 10:40:32 -04:00
|
|
|
my_class_name = nil
|
|
|
|
if self.class < WidgetClassNames[WidgetClassName]
|
|
|
|
my_class_name = self.class.name
|
|
|
|
my_class_name = nil if my_class_name == ''
|
|
|
|
end
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
if parent.kind_of? Hash
|
|
|
|
keys = _symbolkey2str(parent)
|
2003-06-21 08:55:17 -04:00
|
|
|
if keys.key?('classname')
|
|
|
|
keys['class'] = keys.delete('classname')
|
|
|
|
end
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
@classname = keys['class']
|
|
|
|
@colormap = keys['colormap']
|
|
|
|
@container = keys['container']
|
|
|
|
@screen = keys['screen']
|
|
|
|
@use = keys['use']
|
|
|
|
@visual = keys['visual']
|
2003-06-25 10:40:32 -04:00
|
|
|
if !@classname && my_class_name
|
|
|
|
keys['class'] = @classname = my_class_name
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
if @classname.kind_of? TkBindTag
|
|
|
|
@db_class = @classname
|
|
|
|
@classname = @classname.id
|
2003-06-24 12:46:07 -04:00
|
|
|
elsif @classname
|
2003-06-18 15:46:20 -04:00
|
|
|
@db_class = TkDatabaseClass.new(@classname)
|
2003-06-24 12:46:07 -04:00
|
|
|
else
|
|
|
|
@db_class = self.class
|
|
|
|
@classname = @db_class::WidgetClassName
|
2003-06-18 15:46:20 -04:00
|
|
|
end
|
2003-06-21 08:55:17 -04:00
|
|
|
keys, cmds = _wm_command_option_chk(keys)
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
super(keys)
|
2003-06-23 10:22:44 -04:00
|
|
|
cmds.each{|k,v|
|
|
|
|
if v.kind_of? Array
|
|
|
|
self.send(k,*v)
|
|
|
|
else
|
|
|
|
self.send(k,v)
|
|
|
|
end
|
|
|
|
}
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
return
|
|
|
|
end
|
2003-06-24 12:46:07 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
if screen.kind_of? Hash
|
2003-06-18 15:46:20 -04:00
|
|
|
keys = screen
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
|
|
|
@screen = screen
|
2003-06-24 12:46:07 -04:00
|
|
|
if classname.kind_of? Hash
|
|
|
|
keys = classname
|
|
|
|
else
|
|
|
|
@classname = classname
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
if keys.kind_of? Hash
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
keys = _symbolkey2str(keys)
|
2003-06-18 15:46:20 -04:00
|
|
|
if keys.key?('classname')
|
2002-02-28 01:53:33 -05:00
|
|
|
keys['class'] = keys.delete('classname')
|
|
|
|
end
|
2003-06-24 12:46:07 -04:00
|
|
|
@classname = keys['class'] unless @classname
|
2002-02-28 01:53:33 -05:00
|
|
|
@colormap = keys['colormap']
|
|
|
|
@container = keys['container']
|
2003-06-24 12:46:07 -04:00
|
|
|
@screen = keys['screen'] unless @screen
|
2002-02-28 01:53:33 -05:00
|
|
|
@use = keys['use']
|
|
|
|
@visual = keys['visual']
|
2003-06-25 10:40:32 -04:00
|
|
|
else
|
|
|
|
keys = {}
|
|
|
|
end
|
|
|
|
if !@classname && my_class_name
|
|
|
|
keys['class'] = @classname = my_class_name
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
if @classname.kind_of? TkBindTag
|
|
|
|
@db_class = @classname
|
|
|
|
@classname = @classname.id
|
2003-06-24 12:46:07 -04:00
|
|
|
elsif @classname
|
2003-06-18 15:46:20 -04:00
|
|
|
@db_class = TkDatabaseClass.new(@classname)
|
2003-06-24 12:46:07 -04:00
|
|
|
else
|
|
|
|
@db_class = self.class
|
|
|
|
@classname = @db_class::WidgetClassName
|
2003-06-18 15:46:20 -04:00
|
|
|
end
|
2003-06-21 08:55:17 -04:00
|
|
|
keys, cmds = _wm_command_option_chk(keys)
|
1999-08-13 01:37:52 -04:00
|
|
|
super(parent, keys)
|
2003-06-24 12:46:07 -04:00
|
|
|
cmds.each{|k,v|
|
|
|
|
if v.kind_of? Array
|
|
|
|
self.send(k,*v)
|
|
|
|
else
|
|
|
|
self.send(k,v)
|
|
|
|
end
|
|
|
|
}
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2002-02-28 01:53:33 -05:00
|
|
|
def create_self(keys)
|
|
|
|
if keys and keys != None
|
|
|
|
tk_call 'toplevel', @path, *hash_kv(keys)
|
|
|
|
else
|
|
|
|
tk_call 'toplevel', @path
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def specific_class
|
|
|
|
@classname
|
|
|
|
end
|
2003-06-25 10:40:32 -04:00
|
|
|
|
|
|
|
def self.database_class
|
|
|
|
if self == WidgetClassNames[WidgetClassName] || self.name == ''
|
|
|
|
self
|
|
|
|
else
|
|
|
|
TkDatabaseClass.new(self.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def self.database_classname
|
|
|
|
self.database_class.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.bind(*args)
|
|
|
|
if self == WidgetClassNames[WidgetClassName] || self.name == ''
|
|
|
|
super(*args)
|
|
|
|
else
|
|
|
|
TkDatabaseClass.new(self.name).bind(*args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def self.bind_append(*args)
|
|
|
|
if self == WidgetClassNames[WidgetClassName] || self.name == ''
|
|
|
|
super(*args)
|
|
|
|
else
|
|
|
|
TkDatabaseClass.new(self.name).bind_append(*args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def self.bind_remove(*args)
|
|
|
|
if self == WidgetClassNames[WidgetClassName] || self.name == ''
|
|
|
|
super(*args)
|
|
|
|
else
|
|
|
|
TkDatabaseClass.new(self.name).bind_remove(*args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def self.bindinfo(*args)
|
|
|
|
if self == WidgetClassNames[WidgetClassName] || self.name == ''
|
|
|
|
super(*args)
|
|
|
|
else
|
|
|
|
TkDatabaseClass.new(self.name).bindinfo(*args)
|
|
|
|
end
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class TkFrame<TkWindow
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['frame'.freeze].freeze
|
1999-08-13 01:37:52 -04:00
|
|
|
WidgetClassName = 'Frame'.freeze
|
1999-08-24 04:21:56 -04:00
|
|
|
WidgetClassNames[WidgetClassName] = self
|
1999-08-13 01:37:52 -04:00
|
|
|
|
2002-02-28 01:53:33 -05:00
|
|
|
################# old version
|
|
|
|
# def initialize(parent=nil, keys=nil)
|
|
|
|
# if keys.kind_of? Hash
|
|
|
|
# keys = keys.dup
|
|
|
|
# @classname = keys.delete('classname') if keys.key?('classname')
|
|
|
|
# @colormap = keys.delete('colormap') if keys.key?('colormap')
|
|
|
|
# @container = keys.delete('container') if keys.key?('container')
|
|
|
|
# @visual = keys.delete('visual') if keys.key?('visual')
|
|
|
|
# end
|
|
|
|
# super(parent, keys)
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# def create_self
|
|
|
|
# s = []
|
|
|
|
# s << "-class" << @classname if @classname
|
|
|
|
# s << "-colormap" << @colormap if @colormap
|
|
|
|
# s << "-container" << @container if @container
|
|
|
|
# s << "-visual" << @visual if @visual
|
|
|
|
# tk_call 'frame', @path, *s
|
|
|
|
# end
|
|
|
|
#################
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def initialize(parent=nil, keys=nil)
|
2003-06-25 10:40:32 -04:00
|
|
|
my_class_name = nil
|
|
|
|
if self.class < WidgetClassNames[WidgetClassName]
|
|
|
|
my_class_name = self.class.name
|
|
|
|
my_class_name = nil if my_class_name == ''
|
|
|
|
end
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
if parent.kind_of? Hash
|
|
|
|
keys = _symbolkey2str(parent)
|
|
|
|
else
|
|
|
|
if keys
|
|
|
|
keys = _symbolkey2str(keys)
|
|
|
|
keys['parent'] = parent
|
|
|
|
else
|
|
|
|
keys = {'parent'=>parent}
|
2002-02-28 01:53:33 -05:00
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
if keys.key?('classname')
|
|
|
|
keys['class'] = keys.delete('classname')
|
|
|
|
end
|
|
|
|
@classname = keys['class']
|
|
|
|
@colormap = keys['colormap']
|
|
|
|
@container = keys['container']
|
|
|
|
@visual = keys['visual']
|
2003-06-25 10:40:32 -04:00
|
|
|
if !@classname && my_class_name
|
|
|
|
keys['class'] = @classname = my_class_name
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
if @classname.kind_of? TkBindTag
|
|
|
|
@db_class = @classname
|
|
|
|
@classname = @classname.id
|
2003-06-24 12:46:07 -04:00
|
|
|
elsif @classname
|
2003-06-18 15:46:20 -04:00
|
|
|
@db_class = TkDatabaseClass.new(@classname)
|
2003-06-24 12:46:07 -04:00
|
|
|
else
|
|
|
|
@db_class = self.class
|
|
|
|
@classname = @db_class::WidgetClassName
|
2003-06-18 15:46:20 -04:00
|
|
|
end
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
super(keys)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2002-02-28 01:53:33 -05:00
|
|
|
def create_self(keys)
|
|
|
|
if keys and keys != None
|
|
|
|
tk_call 'frame', @path, *hash_kv(keys)
|
|
|
|
else
|
|
|
|
tk_call 'frame', @path
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
2003-06-25 10:40:32 -04:00
|
|
|
def database_classname
|
2003-06-18 15:46:20 -04:00
|
|
|
@classname
|
|
|
|
end
|
2003-06-25 10:40:32 -04:00
|
|
|
|
|
|
|
def self.database_class
|
|
|
|
if self == WidgetClassNames[WidgetClassName] || self.name == ''
|
|
|
|
self
|
|
|
|
else
|
|
|
|
TkDatabaseClass.new(self.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def self.database_classname
|
|
|
|
self.database_class.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.bind(*args)
|
|
|
|
if self == WidgetClassNames[WidgetClassName] || self.name == ''
|
|
|
|
super(*args)
|
|
|
|
else
|
|
|
|
TkDatabaseClass.new(self.name).bind(*args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def self.bind_append(*args)
|
|
|
|
if self == WidgetClassNames[WidgetClassName] || self.name == ''
|
|
|
|
super(*args)
|
|
|
|
else
|
|
|
|
TkDatabaseClass.new(self.name).bind_append(*args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def self.bind_remove(*args)
|
|
|
|
if self == WidgetClassNames[WidgetClassName] || self.name == ''
|
|
|
|
super(*args)
|
|
|
|
else
|
|
|
|
TkDatabaseClass.new(self.name).bind_remove(*args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def self.bindinfo(*args)
|
|
|
|
if self == WidgetClassNames[WidgetClassName] || self.name == ''
|
|
|
|
super(*args)
|
|
|
|
else
|
|
|
|
TkDatabaseClass.new(self.name).bindinfo(*args)
|
|
|
|
end
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class TkLabelFrame<TkFrame
|
2003-08-02 05:58:13 -04:00
|
|
|
TkCommandNames = ['labelframe'.freeze].freeze
|
|
|
|
WidgetClassName = 'Labelframe'.freeze
|
|
|
|
WidgetClassNames[WidgetClassName] = self
|
2003-06-18 15:46:20 -04:00
|
|
|
def create_self(keys)
|
|
|
|
if keys and keys != None
|
|
|
|
tk_call 'labelframe', @path, *hash_kv(keys)
|
|
|
|
else
|
|
|
|
tk_call 'labelframe', @path
|
|
|
|
end
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-08-02 05:58:13 -04:00
|
|
|
TkLabelframe = TkLabelFrame
|
1999-08-13 01:37:52 -04:00
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
class TkPanedWindow<TkWindow
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['panedwindow'.freeze].freeze
|
2003-06-18 15:46:20 -04:00
|
|
|
WidgetClassName = 'Panedwindow'.freeze
|
|
|
|
WidgetClassNames[WidgetClassName] = self
|
|
|
|
def create_self(keys)
|
|
|
|
if keys and keys != None
|
|
|
|
tk_call 'panedwindow', @path, *hash_kv(keys)
|
|
|
|
else
|
|
|
|
tk_call 'panedwindow', @path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def add(*args)
|
|
|
|
keys = args.pop
|
|
|
|
fail ArgumentError, "no window in arguments" unless keys
|
|
|
|
if keys && keys.kind_of?(Hash)
|
|
|
|
fail ArgumentError, "no window in arguments" if args == []
|
|
|
|
args += hash_kv(keys)
|
|
|
|
else
|
|
|
|
args.push(keys) if keys
|
|
|
|
end
|
|
|
|
tk_send('add', *args)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def forget(win, *wins)
|
|
|
|
tk_send('forget', win, *wins)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
alias del forget
|
|
|
|
alias delete forget
|
|
|
|
alias remove forget
|
|
|
|
|
|
|
|
def identify(x, y)
|
2003-06-24 12:46:07 -04:00
|
|
|
list(tk_send('identify', x, y))
|
2003-06-18 15:46:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def proxy_coord
|
|
|
|
list(tk_send('proxy', 'coord'))
|
|
|
|
end
|
|
|
|
def proxy_forget
|
|
|
|
tk_send('proxy', 'forget')
|
|
|
|
self
|
|
|
|
end
|
|
|
|
def proxy_place(x, y)
|
|
|
|
tk_send('proxy', 'place', x, y)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def sash_coord(index)
|
|
|
|
list(tk_send('sash', 'coord', index))
|
|
|
|
end
|
2003-06-24 12:46:07 -04:00
|
|
|
def sash_dragto(index)
|
|
|
|
tk_send('sash', 'dragto', index, x, y)
|
|
|
|
self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def sash_mark(index, x, y)
|
2003-06-24 12:46:07 -04:00
|
|
|
tk_send('sash', 'mark', index, x, y)
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
|
|
|
end
|
|
|
|
def sash_place(index, x, y)
|
2003-06-24 12:46:07 -04:00
|
|
|
tk_send('sash', 'place', index, x, y)
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def panecget(win, key)
|
|
|
|
tk_tcl2ruby(tk_send('panecget', win, "-#{key}"))
|
|
|
|
end
|
|
|
|
|
|
|
|
def paneconfigure(win, key, value=nil)
|
|
|
|
if key.kind_of? Hash
|
|
|
|
tk_send('paneconfigure', win, *hash_kv(key))
|
|
|
|
else
|
|
|
|
tk_send('paneconfigure', win, "-#{key}", value)
|
|
|
|
end
|
|
|
|
self
|
|
|
|
end
|
2003-08-29 04:34:14 -04:00
|
|
|
alias pane_config paneconfigure
|
2003-06-18 15:46:20 -04:00
|
|
|
|
|
|
|
def paneconfiginfo(win, key=nil)
|
|
|
|
if key
|
|
|
|
conf = tk_split_list(tk_send('paneconfigure', win, "-#{key}"))
|
|
|
|
conf[0] = conf[0][1..-1]
|
|
|
|
conf
|
|
|
|
else
|
|
|
|
tk_split_simplelist(tk_send('paneconfigure', win)).collect{|conflist|
|
|
|
|
conf = tk_split_simplelist(conflist)
|
|
|
|
conf[0] = conf[0][1..-1]
|
|
|
|
if conf[3]
|
|
|
|
if conf[3].index('{')
|
|
|
|
conf[3] = tk_split_list(conf[3])
|
|
|
|
else
|
|
|
|
conf[3] = tk_tcl2ruby(conf[3])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if conf[4]
|
|
|
|
if conf[4].index('{')
|
|
|
|
conf[4] = tk_split_list(conf[4])
|
|
|
|
else
|
|
|
|
conf[4] = tk_tcl2ruby(conf[4])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
conf
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2003-08-29 04:34:14 -04:00
|
|
|
alias pane_configinfo paneconfiginfo
|
2003-06-18 15:46:20 -04:00
|
|
|
|
|
|
|
def panes
|
|
|
|
list(tk_send('panes'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
TkPanedwindow = TkPanedWindow
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
class TkLabel<TkWindow
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['label'.freeze].freeze
|
1999-08-13 01:37:52 -04:00
|
|
|
WidgetClassName = 'Label'.freeze
|
1999-08-24 04:21:56 -04:00
|
|
|
WidgetClassNames[WidgetClassName] = self
|
2002-02-28 01:53:33 -05:00
|
|
|
def create_self(keys)
|
|
|
|
if keys and keys != None
|
|
|
|
tk_call 'label', @path, *hash_kv(keys)
|
|
|
|
else
|
|
|
|
tk_call 'label', @path
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def textvariable(v)
|
|
|
|
configure 'textvariable', tk_trace_variable(v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TkButton<TkLabel
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['button'.freeze].freeze
|
2003-06-18 15:46:20 -04:00
|
|
|
WidgetClassName = 'Button'.freeze
|
|
|
|
WidgetClassNames[WidgetClassName] = self
|
2002-02-28 01:53:33 -05:00
|
|
|
def create_self(keys)
|
|
|
|
if keys and keys != None
|
|
|
|
tk_call 'button', @path, *hash_kv(keys)
|
|
|
|
else
|
|
|
|
tk_call 'button', @path
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def invoke
|
|
|
|
tk_send 'invoke'
|
|
|
|
end
|
|
|
|
def flash
|
|
|
|
tk_send 'flash'
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2000-11-27 04:23:38 -05:00
|
|
|
class TkRadioButton<TkButton
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['radiobutton'.freeze].freeze
|
2003-06-18 15:46:20 -04:00
|
|
|
WidgetClassName = 'Radiobutton'.freeze
|
|
|
|
WidgetClassNames[WidgetClassName] = self
|
2002-02-28 01:53:33 -05:00
|
|
|
def create_self(keys)
|
|
|
|
if keys and keys != None
|
|
|
|
tk_call 'radiobutton', @path, *hash_kv(keys)
|
|
|
|
else
|
|
|
|
tk_call 'radiobutton', @path
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def deselect
|
|
|
|
tk_send 'deselect'
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def select
|
|
|
|
tk_send 'select'
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def variable(v)
|
|
|
|
configure 'variable', tk_trace_variable(v)
|
|
|
|
end
|
|
|
|
end
|
2000-11-27 04:23:38 -05:00
|
|
|
TkRadiobutton = TkRadioButton
|
1999-08-13 01:37:52 -04:00
|
|
|
|
2000-11-27 04:23:38 -05:00
|
|
|
class TkCheckButton<TkRadioButton
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['checkbutton'.freeze].freeze
|
2003-06-18 15:46:20 -04:00
|
|
|
WidgetClassName = 'Checkbutton'.freeze
|
|
|
|
WidgetClassNames[WidgetClassName] = self
|
2002-02-28 01:53:33 -05:00
|
|
|
def create_self(keys)
|
|
|
|
if keys and keys != None
|
|
|
|
tk_call 'checkbutton', @path, *hash_kv(keys)
|
|
|
|
else
|
|
|
|
tk_call 'checkbutton', @path
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def toggle
|
|
|
|
tk_send 'toggle'
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
2000-11-27 04:23:38 -05:00
|
|
|
TkCheckbutton = TkCheckButton
|
1999-08-13 01:37:52 -04:00
|
|
|
|
|
|
|
class TkMessage<TkLabel
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['message'.freeze].freeze
|
2003-06-18 15:46:20 -04:00
|
|
|
WidgetClassName = 'Message'.freeze
|
|
|
|
WidgetClassNames[WidgetClassName] = self
|
2002-02-28 01:53:33 -05:00
|
|
|
def create_self(keys)
|
|
|
|
if keys and keys != None
|
|
|
|
tk_call 'message', @path, *hash_kv(keys)
|
|
|
|
else
|
|
|
|
tk_call 'message', @path
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TkScale<TkWindow
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['scale'.freeze].freeze
|
1999-08-13 01:37:52 -04:00
|
|
|
WidgetClassName = 'Scale'.freeze
|
1999-08-24 04:21:56 -04:00
|
|
|
WidgetClassNames[WidgetClassName] = self
|
1999-08-13 01:37:52 -04:00
|
|
|
|
2002-02-28 01:53:33 -05:00
|
|
|
def create_self(keys)
|
|
|
|
if keys and keys != None
|
2003-07-31 03:59:18 -04:00
|
|
|
if keys.key?('command')
|
|
|
|
cmd = keys.delete('command')
|
|
|
|
keys['command'] = proc{|val| cmd.call(val.to_f)}
|
|
|
|
end
|
2002-02-28 01:53:33 -05:00
|
|
|
tk_call 'scale', @path, *hash_kv(keys)
|
|
|
|
else
|
|
|
|
tk_call 'scale', @path
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2003-07-31 03:59:18 -04:00
|
|
|
def _wrap_command_arg(cmd)
|
|
|
|
proc{|val|
|
|
|
|
if val.kind_of?(String)
|
|
|
|
cmd.call(number(val))
|
|
|
|
else
|
|
|
|
cmd.call(val)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
private :_wrap_command_arg
|
|
|
|
|
|
|
|
def configure_cmd(slot, value)
|
|
|
|
configure(slot=>value)
|
|
|
|
end
|
|
|
|
|
|
|
|
def configure(slot, value=None)
|
|
|
|
if (slot == 'command' || slot == :command)
|
|
|
|
configure('command'=>value)
|
|
|
|
elsif slot.kind_of?(Hash) &&
|
|
|
|
(slot.key?('command') || slot.key?(:command))
|
|
|
|
slot = _symbolkey2str(slot)
|
2003-08-03 06:53:09 -04:00
|
|
|
slot['command'] = _wrap_command_arg(slot.delete('command'))
|
2003-07-31 03:59:18 -04:00
|
|
|
end
|
|
|
|
super(slot, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
def command(cmd=Proc.new)
|
|
|
|
configure('command'=>cmd)
|
|
|
|
end
|
|
|
|
|
2001-03-27 02:10:58 -05:00
|
|
|
def get(x=None, y=None)
|
|
|
|
number(tk_send('get', x, y))
|
|
|
|
end
|
|
|
|
|
|
|
|
def coords(val=None)
|
|
|
|
tk_split_list(tk_send('coords', val))
|
|
|
|
end
|
|
|
|
|
|
|
|
def identify(x, y)
|
|
|
|
tk_send('identify', x, y)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def set(val)
|
2003-10-21 00:46:21 -04:00
|
|
|
tk_send("set", val)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def value
|
|
|
|
get
|
|
|
|
end
|
|
|
|
|
|
|
|
def value= (val)
|
2003-10-21 00:46:21 -04:00
|
|
|
set(val)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TkScrollbar<TkWindow
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['scrollbar'.freeze].freeze
|
1999-08-13 01:37:52 -04:00
|
|
|
WidgetClassName = 'Scrollbar'.freeze
|
1999-08-24 04:21:56 -04:00
|
|
|
WidgetClassNames[WidgetClassName] = self
|
1999-08-13 01:37:52 -04:00
|
|
|
|
2002-02-28 01:53:33 -05:00
|
|
|
def create_self(keys)
|
|
|
|
if keys and keys != None
|
|
|
|
tk_call 'scrollbar', @path, *hash_kv(keys)
|
|
|
|
else
|
|
|
|
tk_call 'scrollbar', @path
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def delta(deltax=None, deltay=None)
|
|
|
|
number(tk_send('delta', deltax, deltay))
|
|
|
|
end
|
|
|
|
|
|
|
|
def fraction(x=None, y=None)
|
|
|
|
number(tk_send('fraction', x, y))
|
|
|
|
end
|
|
|
|
|
2001-03-27 02:10:58 -05:00
|
|
|
def identify(x, y)
|
|
|
|
tk_send('identify', x, y)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def get
|
|
|
|
ary1 = tk_send('get').split
|
|
|
|
ary2 = []
|
|
|
|
for i in ary1
|
|
|
|
ary2.push number(i)
|
|
|
|
end
|
|
|
|
ary2
|
|
|
|
end
|
|
|
|
|
|
|
|
def set(first, last)
|
|
|
|
tk_send "set", first, last
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2001-03-27 02:10:58 -05:00
|
|
|
|
|
|
|
def activate(element=None)
|
|
|
|
tk_send('activate', element)
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class TkTextWin<TkWindow
|
|
|
|
def create_self
|
2003-11-10 20:45:06 -05:00
|
|
|
fail RuntimeError, "TkTextWin is an abstract class"
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def bbox(index)
|
2003-06-18 15:46:20 -04:00
|
|
|
list(tk_send('bbox', index))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def delete(first, last=None)
|
|
|
|
tk_send 'delete', first, last
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def get(*index)
|
|
|
|
tk_send 'get', *index
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def insert(index, *args)
|
|
|
|
tk_send 'insert', index, *args
|
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def scan_mark(x, y)
|
|
|
|
tk_send 'scan', 'mark', x, y
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def scan_dragto(x, y)
|
|
|
|
tk_send 'scan', 'dragto', x, y
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def see(index)
|
|
|
|
tk_send 'see', index
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2002-02-28 01:53:33 -05:00
|
|
|
module TkTreatListItemFont
|
|
|
|
include TkTreatItemFont
|
|
|
|
|
2003-08-02 01:04:30 -04:00
|
|
|
ItemCMD = ['itemconfigure'.freeze, TkComm::None].freeze
|
2002-02-28 01:53:33 -05:00
|
|
|
def __conf_cmd(idx)
|
|
|
|
ItemCMD[idx]
|
|
|
|
end
|
|
|
|
|
|
|
|
def __item_pathname(tagOrId)
|
|
|
|
self.path + ';' + tagOrId.to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
class TkListbox<TkTextWin
|
2002-02-28 01:53:33 -05:00
|
|
|
include TkTreatListItemFont
|
1999-12-06 04:04:03 -05:00
|
|
|
include Scrollable
|
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['listbox'.freeze].freeze
|
2003-06-18 15:46:20 -04:00
|
|
|
WidgetClassName = 'Listbox'.freeze
|
|
|
|
WidgetClassNames[WidgetClassName] = self
|
|
|
|
|
2002-02-28 01:53:33 -05:00
|
|
|
def create_self(keys)
|
|
|
|
if keys and keys != None
|
|
|
|
tk_call 'listbox', @path, *hash_kv(keys)
|
|
|
|
else
|
|
|
|
tk_call 'listbox', @path
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def activate(y)
|
|
|
|
tk_send 'activate', y
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def curselection
|
|
|
|
list(tk_send('curselection'))
|
|
|
|
end
|
2000-01-31 22:12:21 -05:00
|
|
|
def get(*index)
|
|
|
|
v = tk_send('get', *index)
|
|
|
|
if index.size == 1
|
|
|
|
v
|
|
|
|
else
|
|
|
|
tk_split_simplelist(v)
|
|
|
|
end
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
def nearest(y)
|
|
|
|
tk_send('nearest', y).to_i
|
|
|
|
end
|
1999-12-14 01:50:43 -05:00
|
|
|
def size
|
1999-08-13 01:37:52 -04:00
|
|
|
tk_send('size').to_i
|
|
|
|
end
|
|
|
|
def selection_anchor(index)
|
|
|
|
tk_send 'selection', 'anchor', index
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def selection_clear(first, last=None)
|
|
|
|
tk_send 'selection', 'clear', first, last
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
1999-12-14 01:50:43 -05:00
|
|
|
def selection_includes(index)
|
|
|
|
bool(tk_send('selection', 'includes', index))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def selection_set(first, last=None)
|
|
|
|
tk_send 'selection', 'set', first, last
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def index(index)
|
|
|
|
tk_send('index', index).to_i
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2000-06-12 03:48:31 -04:00
|
|
|
|
|
|
|
def itemcget(index, key)
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
case key.to_s
|
2000-11-27 04:23:38 -05:00
|
|
|
when 'text', 'label', 'show'
|
2003-06-18 15:46:20 -04:00
|
|
|
tk_send('itemcget', index, "-#{key}")
|
2003-08-29 04:34:14 -04:00
|
|
|
when 'font', 'kanjifont'
|
2003-09-02 01:04:30 -04:00
|
|
|
#fnt = tk_tcl2ruby(tk_send('itemcget', index, "-#{key}"))
|
|
|
|
fnt = tk_tcl2ruby(tk_send('itemcget', index, '-font'))
|
2003-08-29 04:34:14 -04:00
|
|
|
unless fnt.kind_of?(TkFont)
|
|
|
|
fnt = tagfontobj(index, fnt)
|
|
|
|
end
|
2003-09-02 01:04:30 -04:00
|
|
|
if key.to_s == 'kanjifont' && JAPANIZED_TK && TK_VERSION =~ /^4\.*/
|
|
|
|
# obsolete; just for compatibility
|
|
|
|
fnt.kanji_font
|
|
|
|
else
|
|
|
|
fnt
|
|
|
|
end
|
2000-11-27 04:23:38 -05:00
|
|
|
else
|
2003-06-18 15:46:20 -04:00
|
|
|
tk_tcl2ruby(tk_send('itemcget', index, "-#{key}"))
|
2000-11-27 04:23:38 -05:00
|
|
|
end
|
2000-06-12 03:48:31 -04:00
|
|
|
end
|
|
|
|
def itemconfigure(index, key, val=None)
|
|
|
|
if key.kind_of? Hash
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
if (key['font'] || key[:font] ||
|
|
|
|
key['kanjifont'] || key[:kanjifont] ||
|
|
|
|
key['latinfont'] || key[:latinfont] ||
|
|
|
|
key['asciifont'] || key[:asciifont] )
|
|
|
|
tagfont_configure(index, _symbolkey2str(key))
|
2000-06-12 03:48:31 -04:00
|
|
|
else
|
|
|
|
tk_send 'itemconfigure', index, *hash_kv(key)
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
if (key == 'font' || key == :font ||
|
|
|
|
key == 'kanjifont' || key == :kanjifont ||
|
|
|
|
key == 'latinfont' || key == :latinfont ||
|
|
|
|
key == 'asciifont' || key == :asciifont )
|
2003-09-02 01:04:30 -04:00
|
|
|
if val == None
|
|
|
|
tagfontobj(index)
|
|
|
|
else
|
|
|
|
tagfont_configure(index, {key=>val})
|
|
|
|
end
|
2000-06-12 03:48:31 -04:00
|
|
|
else
|
|
|
|
tk_call 'itemconfigure', index, "-#{key}", val
|
|
|
|
end
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
2000-06-12 03:48:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def itemconfiginfo(index, key=nil)
|
|
|
|
if key
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
case key.to_s
|
2000-11-27 04:23:38 -05:00
|
|
|
when 'text', 'label', 'show'
|
|
|
|
conf = tk_split_simplelist(tk_send('itemconfigure',index,"-#{key}"))
|
2003-08-29 04:34:14 -04:00
|
|
|
when 'font', 'kanjifont'
|
|
|
|
conf = tk_split_simplelist(tk_send('itemconfigure',index,"-#{key}") )
|
|
|
|
conf[4] = tagfont_configinfo(index, conf[4])
|
2000-11-27 04:23:38 -05:00
|
|
|
else
|
|
|
|
conf = tk_split_list(tk_send('itemconfigure',index,"-#{key}"))
|
|
|
|
end
|
2000-06-12 03:48:31 -04:00
|
|
|
conf[0] = conf[0][1..-1]
|
|
|
|
conf
|
|
|
|
else
|
2003-08-29 04:34:14 -04:00
|
|
|
ret = tk_split_simplelist(tk_send('itemconfigure',
|
|
|
|
index)).collect{|conflist|
|
2000-11-27 04:23:38 -05:00
|
|
|
conf = tk_split_simplelist(conflist)
|
2000-06-12 03:48:31 -04:00
|
|
|
conf[0] = conf[0][1..-1]
|
2000-11-27 04:23:38 -05:00
|
|
|
case conf[0]
|
|
|
|
when 'text', 'label', 'show'
|
|
|
|
else
|
|
|
|
if conf[3]
|
|
|
|
if conf[3].index('{')
|
|
|
|
conf[3] = tk_split_list(conf[3])
|
|
|
|
else
|
|
|
|
conf[3] = tk_tcl2ruby(conf[3])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if conf[4]
|
|
|
|
if conf[4].index('{')
|
|
|
|
conf[4] = tk_split_list(conf[4])
|
|
|
|
else
|
|
|
|
conf[4] = tk_tcl2ruby(conf[4])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2000-06-12 03:48:31 -04:00
|
|
|
conf
|
|
|
|
}
|
2003-08-29 04:34:14 -04:00
|
|
|
fontconf = ret.assoc('font')
|
|
|
|
if fontconf
|
|
|
|
ret.delete_if{|item| item[0] == 'font' || item[0] == 'kanjifont'}
|
|
|
|
fontconf[4] = tagfont_configinfo(index, fontconf[4])
|
|
|
|
ret.push(fontconf)
|
|
|
|
else
|
|
|
|
ret
|
|
|
|
end
|
2000-06-12 03:48:31 -04:00
|
|
|
end
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
module TkTreatMenuEntryFont
|
2002-02-28 01:53:33 -05:00
|
|
|
include TkTreatItemFont
|
1999-08-13 01:37:52 -04:00
|
|
|
|
2003-08-02 01:04:30 -04:00
|
|
|
ItemCMD = ['entryconfigure'.freeze, TkComm::None].freeze
|
2002-02-28 01:53:33 -05:00
|
|
|
def __conf_cmd(idx)
|
|
|
|
ItemCMD[idx]
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2002-02-28 01:53:33 -05:00
|
|
|
|
|
|
|
def __item_pathname(tagOrId)
|
|
|
|
self.path + ';' + tagOrId.to_s
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TkMenu<TkWindow
|
|
|
|
include TkTreatMenuEntryFont
|
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['menu'.freeze].freeze
|
1999-08-13 01:37:52 -04:00
|
|
|
WidgetClassName = 'Menu'.freeze
|
1999-08-24 04:21:56 -04:00
|
|
|
WidgetClassNames[WidgetClassName] = self
|
2003-06-18 15:46:20 -04:00
|
|
|
|
2002-02-28 01:53:33 -05:00
|
|
|
def create_self(keys)
|
|
|
|
if keys and keys != None
|
|
|
|
tk_call 'menu', @path, *hash_kv(keys)
|
|
|
|
else
|
|
|
|
tk_call 'menu', @path
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def activate(index)
|
|
|
|
tk_send 'activate', index
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def add(type, keys=nil)
|
|
|
|
tk_send 'add', type, *hash_kv(keys)
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-22 12:17:02 -04:00
|
|
|
def add_cascade(keys=nil)
|
|
|
|
add('cascade', keys)
|
|
|
|
end
|
|
|
|
def add_checkbutton(keys=nil)
|
|
|
|
add('checkbutton', keys)
|
|
|
|
end
|
|
|
|
def add_command(keys=nil)
|
|
|
|
add('command', keys)
|
|
|
|
end
|
|
|
|
def add_radiobutton(keys=nil)
|
|
|
|
add('radiobutton', keys)
|
|
|
|
end
|
|
|
|
def add_separator(keys=nil)
|
|
|
|
add('separator', keys)
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
def index(index)
|
2003-06-18 15:46:20 -04:00
|
|
|
ret = tk_send('index', index)
|
|
|
|
(ret == 'none')? nil: number(ret)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def invoke(index)
|
|
|
|
tk_send 'invoke', index
|
|
|
|
end
|
|
|
|
def insert(index, type, keys=nil)
|
2001-03-27 02:10:58 -05:00
|
|
|
tk_send 'insert', index, type, *hash_kv(keys)
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def delete(index, last=None)
|
|
|
|
tk_send 'delete', index, last
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2001-03-27 02:10:58 -05:00
|
|
|
def popup(x, y, index=None)
|
2003-06-18 15:46:20 -04:00
|
|
|
tk_call('tk_popup', path, x, y, index)
|
|
|
|
self
|
2000-06-12 03:48:31 -04:00
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
def post(x, y)
|
|
|
|
tk_send 'post', x, y
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def postcascade(index)
|
|
|
|
tk_send 'postcascade', index
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-16 03:14:50 -04:00
|
|
|
def postcommand(cmd=Proc.new)
|
1999-08-13 01:37:52 -04:00
|
|
|
configure_cmd 'postcommand', cmd
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-11-05 09:00:11 -05:00
|
|
|
def set_focus
|
|
|
|
tk_call('tk_menuSetFocus', path)
|
|
|
|
end
|
2003-06-16 03:14:50 -04:00
|
|
|
def tearoffcommand(cmd=Proc.new)
|
2000-11-20 02:31:55 -05:00
|
|
|
configure_cmd 'tearoffcommand', cmd
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
2000-11-20 02:31:55 -05:00
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
def menutype(index)
|
|
|
|
tk_send 'type', index
|
|
|
|
end
|
|
|
|
def unpost
|
|
|
|
tk_send 'unpost'
|
|
|
|
end
|
|
|
|
def yposition(index)
|
|
|
|
number(tk_send('yposition', index))
|
|
|
|
end
|
|
|
|
def entrycget(index, key)
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
case key.to_s
|
2000-11-27 04:23:38 -05:00
|
|
|
when 'text', 'label', 'show'
|
|
|
|
tk_send 'entrycget', index, "-#{key}"
|
2003-08-29 04:34:14 -04:00
|
|
|
when 'font', 'kanjifont'
|
2003-09-02 01:04:30 -04:00
|
|
|
#fnt = tk_tcl2ruby(tk_send('entrycget', index, "-#{key}"))
|
|
|
|
fnt = tk_tcl2ruby(tk_send('entrycget', index, '-font'))
|
2003-08-29 04:34:14 -04:00
|
|
|
unless fnt.kind_of?(TkFont)
|
|
|
|
fnt = tagfontobj(index, fnt)
|
|
|
|
end
|
2003-09-02 01:04:30 -04:00
|
|
|
if key.to_s == 'kanjifont' && JAPANIZED_TK && TK_VERSION =~ /^4\.*/
|
|
|
|
# obsolete; just for compatibility
|
|
|
|
fnt.kanji_font
|
|
|
|
else
|
|
|
|
fnt
|
|
|
|
end
|
2000-11-27 04:23:38 -05:00
|
|
|
else
|
2003-08-29 04:34:14 -04:00
|
|
|
tk_tcl2ruby(tk_send('entrycget', index, "-#{key}"))
|
2000-11-27 04:23:38 -05:00
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def entryconfigure(index, key, val=None)
|
|
|
|
if key.kind_of? Hash
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
if (key['font'] || key[:font] ||
|
|
|
|
key['kanjifont'] || key[:kanjifont] ||
|
|
|
|
key['latinfont'] || key[:latinfont] ||
|
|
|
|
key['asciifont'] || key[:asciifont])
|
|
|
|
tagfont_configure(index, _symbolkey2str(key))
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
|
|
|
tk_send 'entryconfigure', index, *hash_kv(key)
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
if (key == 'font' || key == :font ||
|
|
|
|
key == 'kanjifont' || key == :kanjifont ||
|
|
|
|
key == 'latinfont' || key == :latinfont ||
|
|
|
|
key == 'asciifont' || key == :asciifont )
|
2003-09-02 01:04:30 -04:00
|
|
|
if val == None
|
|
|
|
tagfontobj(index)
|
|
|
|
else
|
|
|
|
tagfont_configure(index, {key=>val})
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
|
|
|
tk_call 'entryconfigure', index, "-#{key}", val
|
|
|
|
end
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def entryconfiginfo(index, key=nil)
|
|
|
|
if key
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
case key.to_s
|
2000-11-27 04:23:38 -05:00
|
|
|
when 'text', 'label', 'show'
|
|
|
|
conf = tk_split_simplelist(tk_send('entryconfigure',index,"-#{key}"))
|
2003-08-29 04:34:14 -04:00
|
|
|
when 'font', 'kanjifont'
|
|
|
|
conf = tk_split_simplelist(tk_send('entryconfigure',index,"-#{key}"))
|
|
|
|
conf[4] = tagfont_configinfo(index, conf[4])
|
2000-11-27 04:23:38 -05:00
|
|
|
else
|
|
|
|
conf = tk_split_list(tk_send('entryconfigure',index,"-#{key}"))
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
conf[0] = conf[0][1..-1]
|
|
|
|
conf
|
|
|
|
else
|
2003-08-29 04:34:14 -04:00
|
|
|
ret = tk_split_simplelist(tk_send('entryconfigure',
|
|
|
|
index)).collect{|conflist|
|
2000-11-27 04:23:38 -05:00
|
|
|
conf = tk_split_simplelist(conflist)
|
1999-08-13 01:37:52 -04:00
|
|
|
conf[0] = conf[0][1..-1]
|
2000-11-27 04:23:38 -05:00
|
|
|
case conf[0]
|
|
|
|
when 'text', 'label', 'show'
|
|
|
|
else
|
|
|
|
if conf[3]
|
|
|
|
if conf[3].index('{')
|
|
|
|
conf[3] = tk_split_list(conf[3])
|
|
|
|
else
|
|
|
|
conf[3] = tk_tcl2ruby(conf[3])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if conf[4]
|
|
|
|
if conf[4].index('{')
|
|
|
|
conf[4] = tk_split_list(conf[4])
|
|
|
|
else
|
|
|
|
conf[4] = tk_tcl2ruby(conf[4])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
conf
|
|
|
|
}
|
2003-08-29 04:34:14 -04:00
|
|
|
if fontconf
|
|
|
|
ret.delete_if{|item| item[0] == 'font' || item[0] == 'kanjifont'}
|
|
|
|
fontconf[4] = tagfont_configinfo(index, fontconf[4])
|
|
|
|
ret.push(fontconf)
|
|
|
|
else
|
|
|
|
ret
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2000-11-20 02:31:55 -05:00
|
|
|
class TkMenuClone<TkMenu
|
2001-03-27 02:10:58 -05:00
|
|
|
def initialize(parent, type=None)
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
widgetname = nil
|
|
|
|
if parent.kind_of? Hash
|
|
|
|
keys = _symbolkey2str(parent)
|
|
|
|
parent = keys.delete('parent')
|
|
|
|
widgetname = keys.delete('widgetname')
|
|
|
|
type = keys.delete('type'); type = None unless type
|
|
|
|
end
|
2000-11-20 02:31:55 -05:00
|
|
|
unless parent.kind_of?(TkMenu)
|
|
|
|
fail ArgumentError, "parent must be TkMenu"
|
|
|
|
end
|
|
|
|
@parent = parent
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
install_win(@parent.path, widgetname)
|
2000-11-20 02:31:55 -05:00
|
|
|
tk_call @parent.path, 'clone', @path, type
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2000-06-12 03:48:31 -04:00
|
|
|
module TkSystemMenu
|
|
|
|
def initialize(parent, keys=nil)
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
if parent.kind_of? Hash
|
|
|
|
keys = _symbolkey2str(parent)
|
|
|
|
parent = keys.delete('parent')
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
unless parent.kind_of? TkMenu
|
|
|
|
fail ArgumentError, "parent must be a TkMenu object"
|
|
|
|
end
|
2003-12-02 23:55:07 -05:00
|
|
|
@path = Kernel.format("%s.%s", parent.path, self.class::SYSMENU_NAME)
|
2003-07-23 12:07:35 -04:00
|
|
|
#TkComm::Tk_WINDOWS[@path] = self
|
|
|
|
TkCore::INTERP.tk_windows[@path] = self
|
2002-02-28 01:53:33 -05:00
|
|
|
if self.method(:create_self).arity == 0
|
|
|
|
p 'create_self has no arg' if $DEBUG
|
|
|
|
create_self
|
|
|
|
configure(keys) if keys
|
|
|
|
else
|
|
|
|
p 'create_self has an arg' if $DEBUG
|
|
|
|
create_self(keys)
|
|
|
|
end
|
2000-06-12 03:48:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TkSysMenu_Help<TkMenu
|
|
|
|
# for all platform
|
|
|
|
include TkSystemMenu
|
|
|
|
SYSMENU_NAME = 'help'
|
|
|
|
end
|
|
|
|
|
|
|
|
class TkSysMenu_System<TkMenu
|
|
|
|
# for Windows
|
|
|
|
include TkSystemMenu
|
|
|
|
SYSMENU_NAME = 'system'
|
|
|
|
end
|
|
|
|
|
|
|
|
class TkSysMenu_Apple<TkMenu
|
|
|
|
# for Machintosh
|
|
|
|
include TkSystemMenu
|
|
|
|
SYSMENU_NAME = 'apple'
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
class TkMenubutton<TkLabel
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['menubutton'.freeze].freeze
|
2003-06-18 15:46:20 -04:00
|
|
|
WidgetClassName = 'Menubutton'.freeze
|
|
|
|
WidgetClassNames[WidgetClassName] = self
|
2002-02-28 01:53:33 -05:00
|
|
|
def create_self(keys)
|
|
|
|
if keys and keys != None
|
|
|
|
tk_call 'menubutton', @path, *hash_kv(keys)
|
|
|
|
else
|
|
|
|
tk_call 'menubutton', @path
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2000-06-12 03:48:31 -04:00
|
|
|
class TkOptionMenubutton<TkMenubutton
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['tk_optionMenu'.freeze].freeze
|
|
|
|
|
2000-06-12 03:48:31 -04:00
|
|
|
class OptionMenu<TkMenu
|
2003-06-22 12:17:02 -04:00
|
|
|
def initialize(path) #==> return value of tk_optionMenu
|
|
|
|
@path = path
|
2003-07-23 12:07:35 -04:00
|
|
|
#TkComm::Tk_WINDOWS[@path] = self
|
|
|
|
TkCore::INTERP.tk_windows[@path] = self
|
2000-06-12 03:48:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(parent=nil, var=TkVariable.new, firstval=nil, *vals)
|
2003-06-18 15:46:20 -04:00
|
|
|
if parent.kind_of? Hash
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
keys = _symbolkey2str(parent)
|
|
|
|
parent = keys['parent']
|
|
|
|
var = keys['variable'] if keys['variable']
|
|
|
|
firstval, *vals = keys['values']
|
|
|
|
end
|
2003-06-22 12:17:02 -04:00
|
|
|
fail 'variable option must be TkVariable' unless var.kind_of? TkVariable
|
2000-06-12 03:48:31 -04:00
|
|
|
@variable = var
|
|
|
|
firstval = @variable.value unless firstval
|
|
|
|
@variable.value = firstval
|
|
|
|
install_win(if parent then parent.path end)
|
2003-06-22 12:17:02 -04:00
|
|
|
@menu = OptionMenu.new(tk_call('tk_optionMenu', @path, @variable.id,
|
|
|
|
firstval, *vals))
|
2000-06-12 03:48:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def value
|
|
|
|
@variable.value
|
|
|
|
end
|
|
|
|
|
|
|
|
def activate(index)
|
|
|
|
@menu.activate(index)
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
2000-06-12 03:48:31 -04:00
|
|
|
end
|
|
|
|
def add(value)
|
|
|
|
@menu.add('radiobutton', 'variable'=>@variable,
|
|
|
|
'label'=>value, 'value'=>value)
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
2000-06-12 03:48:31 -04:00
|
|
|
end
|
|
|
|
def index(index)
|
|
|
|
@menu.index(index)
|
|
|
|
end
|
|
|
|
def invoke(index)
|
|
|
|
@menu.invoke(index)
|
|
|
|
end
|
|
|
|
def insert(index, value)
|
|
|
|
@menu.add(index, 'radiobutton', 'variable'=>@variable,
|
|
|
|
'label'=>value, 'value'=>value)
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
2000-06-12 03:48:31 -04:00
|
|
|
end
|
|
|
|
def delete(index, last=None)
|
|
|
|
@menu.delete(index, last)
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
2000-06-12 03:48:31 -04:00
|
|
|
end
|
|
|
|
def yposition(index)
|
|
|
|
@menu.yposition(index)
|
|
|
|
end
|
2003-06-22 12:17:02 -04:00
|
|
|
def menu
|
|
|
|
@menu
|
|
|
|
end
|
|
|
|
def menucget(key)
|
|
|
|
@menu.cget(key)
|
2000-06-12 03:48:31 -04:00
|
|
|
end
|
2003-06-22 12:17:02 -04:00
|
|
|
def menuconfigure(key, val=None)
|
|
|
|
@menu.configure(key, val)
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
2000-06-12 03:48:31 -04:00
|
|
|
end
|
2003-06-22 12:17:02 -04:00
|
|
|
def menuconfiginfo(key=nil)
|
|
|
|
@menu.configinfo(key)
|
2000-06-12 03:48:31 -04:00
|
|
|
end
|
|
|
|
def entrycget(index, key)
|
|
|
|
@menu.entrycget(index, key)
|
|
|
|
end
|
|
|
|
def entryconfigure(index, key, val=None)
|
|
|
|
@menu.entryconfigure(index, key, val)
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
2000-06-12 03:48:31 -04:00
|
|
|
end
|
|
|
|
def entryconfiginfo(index, key=nil)
|
|
|
|
@menu.entryconfiginfo(index, key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
module TkComposite
|
|
|
|
include Tk
|
|
|
|
extend Tk
|
|
|
|
|
|
|
|
def initialize(parent=nil, *args)
|
2003-07-31 16:52:40 -04:00
|
|
|
@delegates = {}
|
|
|
|
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
if parent.kind_of? Hash
|
|
|
|
keys = _symbolkey2str(parent)
|
2003-11-22 08:52:48 -05:00
|
|
|
parent = keys.delete('parent')
|
|
|
|
@frame = TkFrame.new(parent)
|
2003-10-16 11:14:41 -04:00
|
|
|
@delegates['DEFAULT'] = @frame
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
@path = @epath = @frame.path
|
|
|
|
initialize_composite(keys)
|
|
|
|
else
|
|
|
|
@frame = TkFrame.new(parent)
|
2003-10-16 11:14:41 -04:00
|
|
|
@delegates['DEFAULT'] = @frame
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
@path = @epath = @frame.path
|
|
|
|
initialize_composite(*args)
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def epath
|
|
|
|
@epath
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize_composite(*args) end
|
|
|
|
private :initialize_composite
|
|
|
|
|
|
|
|
def delegate(option, *wins)
|
|
|
|
if @delegates[option].kind_of?(Array)
|
|
|
|
for i in wins
|
|
|
|
@delegates[option].push(i)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
@delegates[option] = wins
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def configure(slot, value=None)
|
|
|
|
if slot.kind_of? Hash
|
|
|
|
slot.each{|slot,value| configure slot, value}
|
|
|
|
else
|
|
|
|
if @delegates and @delegates[slot]
|
|
|
|
for i in @delegates[slot]
|
|
|
|
if not i
|
|
|
|
i = @delegates['DEFALUT']
|
|
|
|
redo
|
|
|
|
else
|
|
|
|
last = i.configure(slot, value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
last
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module TkClipboard
|
|
|
|
include Tk
|
|
|
|
extend Tk
|
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['clipboard'.freeze].freeze
|
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
def self.clear(win=nil)
|
|
|
|
if win
|
|
|
|
tk_call 'clipboard', 'clear', '-displayof', win
|
|
|
|
else
|
|
|
|
tk_call 'clipboard', 'clear'
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def self.clear_on_display(win)
|
|
|
|
tk_call 'clipboard', 'clear', '-displayof', win
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.get(type=nil)
|
|
|
|
if type
|
|
|
|
tk_call 'clipboard', 'get', '-type', type
|
|
|
|
else
|
|
|
|
tk_call 'clipboard', 'get'
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def self.get_on_display(win, type=nil)
|
|
|
|
if type
|
|
|
|
tk_call 'clipboard', 'get', '-displayof', win, '-type', type
|
|
|
|
else
|
|
|
|
tk_call 'clipboard', 'get', '-displayof', win
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.set(data, keys=nil)
|
1999-08-13 01:37:52 -04:00
|
|
|
clear
|
2003-06-18 15:46:20 -04:00
|
|
|
append(data, keys)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
def self.set_on_display(win, data, keys=nil)
|
|
|
|
clear(win)
|
|
|
|
append_on_display(win, data, keys)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
def self.append(data, keys=nil)
|
|
|
|
args = ['clipboard', 'append']
|
|
|
|
args += hash_kv(keys)
|
|
|
|
args += ['--', data]
|
|
|
|
tk_call(*args)
|
|
|
|
end
|
|
|
|
def self.append_on_display(win, data, keys=nil)
|
|
|
|
args = ['clipboard', 'append', '-displayof', win]
|
|
|
|
args += hash_kv(keys)
|
|
|
|
args += ['--', data]
|
|
|
|
tk_call(*args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def clear
|
|
|
|
TkClipboard.clear_on_display(self)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
def get(type=nil)
|
|
|
|
TkClipboard.get_on_display(self, type)
|
|
|
|
end
|
|
|
|
def set(data, keys=nil)
|
|
|
|
TkClipboard.set_on_display(self, data, keys)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
def append(data, keys=nil)
|
|
|
|
TkClipboard.append_on_display(self, data, keys)
|
|
|
|
self
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2003-06-25 01:49:10 -04:00
|
|
|
# widget_destroy_hook
|
|
|
|
require 'tkvirtevent'
|
2003-07-31 16:52:40 -04:00
|
|
|
TkBindTag::ALL.bind(TkVirtualEvent.new('Destroy'), proc{|xpath|
|
|
|
|
path = xpath[1..-1]
|
|
|
|
if (widget = TkCore::INTERP.tk_windows[path])
|
|
|
|
if widget.respond_to?(:__destroy_hook__)
|
|
|
|
begin
|
2003-07-31 03:59:18 -04:00
|
|
|
widget.__destroy_hook__
|
2003-07-31 16:52:40 -04:00
|
|
|
rescue Exception
|
2003-07-31 03:59:18 -04:00
|
|
|
end
|
2003-07-27 15:35:06 -04:00
|
|
|
end
|
2003-06-25 01:49:10 -04:00
|
|
|
end
|
2003-07-31 16:52:40 -04:00
|
|
|
}, 'x%W')
|
2003-06-25 01:49:10 -04:00
|
|
|
|
2003-08-29 04:34:14 -04:00
|
|
|
# freeze core modules
|
2003-11-12 16:11:40 -05:00
|
|
|
#TclTkLib.freeze
|
|
|
|
#TclTkIp.freeze
|
|
|
|
#TkUtil.freeze
|
|
|
|
#TkKernel.freeze
|
|
|
|
#TkComm.freeze
|
|
|
|
#TkComm::Event.freeze
|
|
|
|
#TkCore.freeze
|
|
|
|
#Tk.freeze
|
2003-08-29 04:34:14 -04:00
|
|
|
|
2003-06-25 01:49:10 -04:00
|
|
|
# autoload
|
1999-08-13 01:37:52 -04:00
|
|
|
autoload :TkCanvas, 'tkcanvas'
|
|
|
|
autoload :TkImage, 'tkcanvas'
|
|
|
|
autoload :TkBitmapImage, 'tkcanvas'
|
|
|
|
autoload :TkPhotoImage, 'tkcanvas'
|
|
|
|
autoload :TkEntry, 'tkentry'
|
2000-11-20 02:31:55 -05:00
|
|
|
autoload :TkSpinbox, 'tkentry'
|
1999-08-13 01:37:52 -04:00
|
|
|
autoload :TkText, 'tktext'
|
|
|
|
autoload :TkDialog, 'tkdialog'
|
2003-06-18 15:46:20 -04:00
|
|
|
autoload :TkDialog2, 'tkdialog'
|
2000-11-27 04:23:38 -05:00
|
|
|
autoload :TkWarning, 'tkdialog'
|
2003-06-18 15:46:20 -04:00
|
|
|
autoload :TkWarning2, 'tkdialog'
|
1999-08-13 01:37:52 -04:00
|
|
|
autoload :TkMenubar, 'tkmenubar'
|
|
|
|
autoload :TkAfter, 'tkafter'
|
2003-06-18 15:46:20 -04:00
|
|
|
autoload :TkTimer, 'tkafter'
|
1999-08-13 01:37:52 -04:00
|
|
|
autoload :TkPalette, 'tkpalette'
|
|
|
|
autoload :TkFont, 'tkfont'
|
2000-11-27 04:23:38 -05:00
|
|
|
autoload :TkBgError, 'tkbgerror'
|
|
|
|
autoload :TkManageFocus, 'tkmngfocus'
|
|
|
|
autoload :TkPalette, 'tkpalette'
|
|
|
|
autoload :TkWinDDE, 'tkwinpkg'
|
|
|
|
autoload :TkWinRegistry, 'tkwinpkg'
|
|
|
|
autoload :TkMacResource, 'tkmacpkg'
|
2003-06-18 15:46:20 -04:00
|
|
|
autoload :TkConsole, 'tkconsole'
|