* ext/tk/lib/tk/image.rb: bug fix
* ext/tk/lib/tk/optiondb.rb: support definition of command resources on widgets git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6993 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6e8ae612ba
commit
581ca6097e
@ -1,3 +1,10 @@
|
|||||||
|
Mon Oct 4 12:53:45 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
||||||
|
|
||||||
|
* ext/tk/lib/tk/optiondb.rb: support definition of command
|
||||||
|
resources on widgets
|
||||||
|
|
||||||
|
* ext/tk/lib/tk/image.rb: bug fix
|
||||||
|
|
||||||
Sun Oct 3 21:16:05 2004 Shugo Maeda <shugo@ruby-lang.org>
|
Sun Oct 3 21:16:05 2004 Shugo Maeda <shugo@ruby-lang.org>
|
||||||
|
|
||||||
* lib/net/imap.rb (TEXT_REGEXP): allow 8-bit characters for the german
|
* lib/net/imap.rb (TEXT_REGEXP): allow 8-bit characters for the german
|
||||||
|
@ -263,6 +263,8 @@ sample/binding_sample.rb
|
|||||||
sample/bindtag_sample.rb
|
sample/bindtag_sample.rb
|
||||||
sample/binstr_usage.rb
|
sample/binstr_usage.rb
|
||||||
sample/btn_with_frame.rb
|
sample/btn_with_frame.rb
|
||||||
|
sample/cmd_res_test.rb
|
||||||
|
sample/cmd_resource
|
||||||
sample/encstr_usage.rb
|
sample/encstr_usage.rb
|
||||||
sample/iso2022-kr.txt
|
sample/iso2022-kr.txt
|
||||||
sample/menubar1.rb
|
sample/menubar1.rb
|
||||||
|
@ -107,7 +107,7 @@ class TkPhotoImage<TkImage
|
|||||||
term
|
term
|
||||||
end
|
end
|
||||||
}.flatten
|
}.flatten
|
||||||
tk_send('copy', source, *args)
|
tk_send('copy', src, *args)
|
||||||
end
|
end
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
@ -8,6 +8,7 @@ module TkOptionDB
|
|||||||
extend Tk
|
extend Tk
|
||||||
|
|
||||||
TkCommandNames = ['option'.freeze].freeze
|
TkCommandNames = ['option'.freeze].freeze
|
||||||
|
CmdClassID = ['CMD_CLASS'.freeze, '00000'.taint].freeze
|
||||||
|
|
||||||
module Priority
|
module Priority
|
||||||
WidgetDefault = 20
|
WidgetDefault = 20
|
||||||
@ -193,6 +194,7 @@ module TkOptionDB
|
|||||||
end
|
end
|
||||||
@@resource_proc_class.freeze
|
@@resource_proc_class.freeze
|
||||||
|
|
||||||
|
=begin
|
||||||
def __create_new_class(klass, func, safe = 4, add = false, parent = nil)
|
def __create_new_class(klass, func, safe = 4, add = false, parent = nil)
|
||||||
klass = klass.to_s if klass.kind_of? Symbol
|
klass = klass.to_s if klass.kind_of? Symbol
|
||||||
unless (?A..?Z) === klass[0]
|
unless (?A..?Z) === klass[0]
|
||||||
@ -229,12 +231,55 @@ module TkOptionDB
|
|||||||
eval('TkOptionDB::' + klass)
|
eval('TkOptionDB::' + klass)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
=end
|
||||||
|
def __create_new_class(klass, func, safe = 4, add = false, parent = nil)
|
||||||
|
if klass.kind_of?(TkWindow)
|
||||||
|
carrier = klass.path
|
||||||
|
klass = CmdClassID.join(TkCore::INTERP._ip_id_)
|
||||||
|
CmdClassID[1].succ!
|
||||||
|
parent = nil # ignore parent
|
||||||
|
else
|
||||||
|
klass = klass.to_s if klass.kind_of? Symbol
|
||||||
|
unless (?A..?Z) === klass[0]
|
||||||
|
fail ArgumentError, "bad string '#{klass}' for class name"
|
||||||
|
end
|
||||||
|
if parent == nil
|
||||||
|
install_win(nil)
|
||||||
|
elsif parent.kind_of?(TkWindow)
|
||||||
|
install_win(parent.path)
|
||||||
|
elsif parent <= @@resource_proc_class
|
||||||
|
install_win(parent::CARRIER)
|
||||||
|
else
|
||||||
|
fail ArgumentError, "parent must be Resource-Proc class"
|
||||||
|
end
|
||||||
|
carrier = Tk.tk_call_without_enc('frame', @path, '-class', klass)
|
||||||
|
end
|
||||||
|
|
||||||
|
unless func.kind_of? Array
|
||||||
|
fail ArgumentError, "method-list must be Array"
|
||||||
|
end
|
||||||
|
func_str = func.join(' ')
|
||||||
|
|
||||||
|
if parent.kind_of?(Class) && parent <= @@resource_proc_class
|
||||||
|
cmd_klass = Class.new(parent)
|
||||||
|
else
|
||||||
|
cmd_klass = Class.new(TkOptionDB.module_eval('@@resource_proc_class'))
|
||||||
|
end
|
||||||
|
cmd_klass.const_set(:CARRIER, carrier.dup.freeze)
|
||||||
|
cmd_klass.const_set(:METHOD_TBL, TkCore::INTERP.create_table)
|
||||||
|
cmd_klass.const_set(:ADD_METHOD, add)
|
||||||
|
cmd_klass.const_set(:SAFE_MODE, safe)
|
||||||
|
func.each{|f| cmd_klass::METHOD_TBL[f.to_s.intern] = nil }
|
||||||
|
|
||||||
|
cmd_klass
|
||||||
|
end
|
||||||
module_function :__create_new_class
|
module_function :__create_new_class
|
||||||
private_class_method :__create_new_class
|
private_class_method :__create_new_class
|
||||||
|
|
||||||
def __remove_methods_of_proc_class(klass)
|
def __remove_methods_of_proc_class(klass)
|
||||||
# for security, make these methods invalid
|
# for security, make these methods invalid
|
||||||
class << klass
|
class << klass
|
||||||
|
=begin
|
||||||
attr_reader :class_eval, :name, :superclass,
|
attr_reader :class_eval, :name, :superclass,
|
||||||
:ancestors, :const_defined?, :const_get, :const_set,
|
:ancestors, :const_defined?, :const_get, :const_set,
|
||||||
:constants, :included_modules, :instance_methods,
|
:constants, :included_modules, :instance_methods,
|
||||||
@ -244,6 +289,19 @@ module TkOptionDB
|
|||||||
:to_s, :inspect, :display, :method, :methods,
|
:to_s, :inspect, :display, :method, :methods,
|
||||||
:instance_eval, :instance_variables, :kind_of?, :is_a?,
|
:instance_eval, :instance_variables, :kind_of?, :is_a?,
|
||||||
:private_methods, :protected_methods, :public_methods
|
:private_methods, :protected_methods, :public_methods
|
||||||
|
=end
|
||||||
|
def __null_method(*args); nil; end
|
||||||
|
[ :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 ].each{|m|
|
||||||
|
alias_method(m, :__null_method)
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
module_function :__remove_methods_of_proc_class
|
module_function :__remove_methods_of_proc_class
|
||||||
|
17
ext/tk/sample/cmd_res_test.rb
Normal file
17
ext/tk/sample/cmd_res_test.rb
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
require 'tk'
|
||||||
|
TkOptionDB.readfile(File.expand_path('cmd_resource',
|
||||||
|
File.dirname(__FILE__)))
|
||||||
|
f = TkFrame.new(:class=>'BtnFrame').pack
|
||||||
|
b = TkButton.new(:parent=>f, :widgetname=>'hello').pack
|
||||||
|
cmd1 = TkOptionDB.new_proc_class(b, [:show_msg, :bye_msg], 3)
|
||||||
|
cmd2 = TkOptionDB.new_proc_class(:ZZZ, [:show_msg, :bye_msg], 3, false, cmd1)
|
||||||
|
cmd3 = TkOptionDB.new_proc_class(:ZZZ, [:show_msg, :bye_msg], 3, false, b)
|
||||||
|
cmd4 = TkOptionDB.new_proc_class(:BTN_CMD, [:show_msg, :bye_msg], 3){
|
||||||
|
def self.__check_proc_string__(str)
|
||||||
|
"{|arg| print [arg, $SAFE].inspect, ': '; Proc.new#{str}.call(arg)}"
|
||||||
|
end
|
||||||
|
}
|
||||||
|
cmd1.show_msg('cmd1')
|
||||||
|
cmd2.show_msg('cmd2')
|
||||||
|
cmd3.show_msg('cmd3')
|
||||||
|
cmd4.show_msg('cmd4')
|
5
ext/tk/sample/cmd_resource
Normal file
5
ext/tk/sample/cmd_resource
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
*BtnFrame.hello.text: HELLO
|
||||||
|
*BtnFrame.hello.command: ruby {puts "Hello World!!"}
|
||||||
|
*BTN_CMD.show_msg: {|arg| print "Hello, #{arg}!!\n"}
|
||||||
|
*hello.show_msg: {|arg| print "Hello, Hello, #{arg}!!\n"}
|
||||||
|
*hello.ZZZ.show_msg: {|arg| print "Hello, Hello, ZZZ:#{arg}!!\n"}
|
Loading…
x
Reference in New Issue
Block a user