summaryrefslogtreecommitdiffstats
path: root/ext
diff options
context:
space:
mode:
authorocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-08-06 03:44:00 +0000
committerocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-08-06 03:44:00 +0000
commit8734312ea6b2960de1a6fbeeeb04e686342c962e (patch)
treef85db3e7d924e7892c5221dc7e56d6330eb22034 /ext
parentd9a5fc6a5d1e7edb2e2fe0bab1dc37ae8b68df7c (diff)
downloadruby-8734312ea6b2960de1a6fbeeeb04e686342c962e.tar.gz
ruby-8734312ea6b2960de1a6fbeeeb04e686342c962e.tar.xz
ruby-8734312ea6b2960de1a6fbeeeb04e686342c962e.zip
* ext/tk/lib/{tk.rb,tk/itemconfig.rb}: configure creates
TkVariable if key name is 'variable' or 'textvariable' by default. [ruby-dev:26749] * ext/tk/lib/tk/{label,radiobutton}.rb: removed its own {variable,textvariable} function. * ext/tk/lib/tk/variable.rb: retains backward conpatibility. (written by Hidetoshi NAGAI) git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@8933 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/tk/ChangeLog.tkextlib4
-rw-r--r--ext/tk/lib/tk.rb101
-rw-r--r--ext/tk/lib/tk/itemconfig.rb89
-rw-r--r--ext/tk/lib/tk/label.rb4
-rw-r--r--ext/tk/lib/tk/radiobutton.rb3
-rw-r--r--ext/tk/lib/tk/variable.rb28
-rw-r--r--ext/tk/sample/tkextlib/tile/demo.rb4
7 files changed, 219 insertions, 14 deletions
diff --git a/ext/tk/ChangeLog.tkextlib b/ext/tk/ChangeLog.tkextlib
index 51561be86..d7c3a9687 100644
--- a/ext/tk/ChangeLog.tkextlib
+++ b/ext/tk/ChangeLog.tkextlib
@@ -1,3 +1,7 @@
+2005-08-06 ocean <ocean@ruby-lang.org>
+
+ * sample/tkextlib/tile/demo.rb: use Tk::Tile::Scale#variable.
+
2005-08-04 ocean <ocean@ruby-lang.org>
* sample/tkextlib/tile/demo.rb: followed previous changes.
diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb
index 74fa4f38d..f0f027104 100644
--- a/ext/tk/lib/tk.rb
+++ b/ext/tk/lib/tk.rb
@@ -2233,10 +2233,13 @@ if (/^(8\.[1-9]|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK)
end
def encoding_convertfrom(str, enc=nil)
- # str must be a Tcl's internal string expression in enc.
+ # str is an usual enc string or a Tcl's internal string expression
+ # in enc (which is returned from 'encoding_convertto' method).
# the return value is a UTF-8 string.
enc = encoding_system unless enc
- TkCore::INTERP.__invoke('encoding', 'convertfrom', enc, str)
+ ret = TkCore::INTERP.__invoke('encoding', 'convertfrom', enc, str)
+ ret.instance_variable_set('@encoding', 'utf-8')
+ ret
end
alias encoding_convert_from encoding_convertfrom
@@ -2245,7 +2248,9 @@ if (/^(8\.[1-9]|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK)
# The return value is a Tcl's internal string expression in enc.
# To get an usual enc string, use Tk.fromUTF8(ret_val, enc).
enc = encoding_system unless enc
- TkCore::INTERP.__invoke('encoding', 'convertto', enc, str)
+ ret = TkCore::INTERP.__invoke('encoding', 'convertto', enc, str)
+ ret.instance_variable_set('@encoding', 'binary')
+ ret
end
alias encoding_convert_to encoding_convertto
end
@@ -2710,6 +2715,11 @@ module TkConfigMethod
end
private :__numlistval_optkeys
+ def __tkvariable_optkeys
+ ['variable', 'textvariable']
+ end
+ private :__tkvariable_optkeys
+
def __methodcall_optkeys # { key=>method, ... }
{}
end
@@ -2815,6 +2825,10 @@ module TkConfigMethod
fnt
end
+ when /^(#{__tkvariable_optkeys.join('|')})$/
+ v = tk_call_without_enc(*(__cget_cmd << "-#{slot}"))
+ (v.empty?)? nil: TkVarAccess.new(v)
+
else
tk_tcl2ruby(tk_call_without_enc(*(__cget_cmd << "-#{slot}")), true)
end
@@ -2999,6 +3013,28 @@ module TkConfigMethod
when /^(#{__strval_optkeys.join('|')})$/
# conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}"))))
conf = tk_split_simplelist(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}")), false, true)
+
+ when /^(#{__tkvariable_optkeys.join('|')})$/
+ conf = tk_split_simplelist(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}")), false, true)
+
+ if ( __configinfo_struct[:default_value] \
+ && conf[__configinfo_struct[:default_value]])
+ v = conf[__configinfo_struct[:default_value]]
+ if v.empty?
+ conf[__configinfo_struct[:default_value]] = nil
+ else
+ conf[__configinfo_struct[:default_value]] = TkVarAccess.new(v)
+ end
+ end
+ if ( conf[__configinfo_struct[:current_value]] )
+ v = conf[__configinfo_struct[:current_value]]
+ if v.empty?
+ conf[__configinfo_struct[:current_value]] = nil
+ else
+ conf[__configinfo_struct[:current_value]] = TkVarAccess.new(v)
+ end
+ end
+
else
# conf = tk_split_list(_fromUTF8(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}"))))
conf = tk_split_list(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}")), 0, false, true)
@@ -3100,6 +3136,25 @@ module TkConfigMethod
list(conf[__configinfo_struct[:current_value]])
end
+ when /^(#{__tkvariable_optkeys.join('|')})$/
+ if ( __configinfo_struct[:default_value] \
+ && conf[__configinfo_struct[:default_value]] )
+ v = conf[__configinfo_struct[:default_value]]
+ if v.empty?
+ conf[__configinfo_struct[:default_value]] = nil
+ else
+ conf[__configinfo_struct[:default_value]] = TkVarAccess.new(v)
+ end
+ end
+ if ( conf[__configinfo_struct[:current_value]] )
+ v = conf[__configinfo_struct[:current_value]]
+ if v.empty?
+ conf[__configinfo_struct[:current_value]] = nil
+ else
+ conf[__configinfo_struct[:current_value]] = TkVarAccess.new(v)
+ end
+ end
+
else
if ( __configinfo_struct[:default_value] \
&& conf[__configinfo_struct[:default_value]] )
@@ -3269,6 +3324,27 @@ module TkConfigMethod
list(conf[__configinfo_struct[:current_value]])
end
+ when /^(#{__tkvariable_optkeys.join('|')})$/
+ conf = tk_split_simplelist(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}")), false, true)
+
+ if ( __configinfo_struct[:default_value] \
+ && conf[__configinfo_struct[:default_value]] )
+ v = conf[__configinfo_struct[:default_value]]
+ if v.empty?
+ conf[__configinfo_struct[:default_value]] = nil
+ else
+ conf[__configinfo_struct[:default_value]] = TkVarAccess.new(v)
+ end
+ end
+ if ( conf[__configinfo_struct[:current_value]] )
+ v = conf[__configinfo_struct[:current_value]]
+ if v.empty?
+ conf[__configinfo_struct[:current_value]] = nil
+ else
+ conf[__configinfo_struct[:current_value]] = TkVarAccess.new(v)
+ end
+ end
+
when /^(#{__strval_optkeys.join('|')})$/
# conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}"))))
conf = tk_split_simplelist(tk_call_without_enc(*(__confinfo_cmd << "-#{slot}")), false, true)
@@ -3376,6 +3452,25 @@ module TkConfigMethod
list(conf[__configinfo_struct[:current_value]])
end
+ when /^(#{__tkvariable_optkeys.join('|')})$/
+ if ( __configinfo_struct[:default_value] \
+ && conf[__configinfo_struct[:default_value]] )
+ v = conf[__configinfo_struct[:default_value]]
+ if v.empty?
+ conf[__configinfo_struct[:default_value]] = nil
+ else
+ conf[__configinfo_struct[:default_value]] = TkVarAccess.new
+ end
+ end
+ if ( conf[__configinfo_struct[:current_value]] )
+ v = conf[__configinfo_struct[:current_value]]
+ if v.empty?
+ conf[__configinfo_struct[:current_value]] = nil
+ else
+ conf[__configinfo_struct[:current_value]] = TkVarAccess.new
+ end
+ end
+
else
if ( __configinfo_struct[:default_value] \
&& conf[__configinfo_struct[:default_value]] )
diff --git a/ext/tk/lib/tk/itemconfig.rb b/ext/tk/lib/tk/itemconfig.rb
index f2f9cba65..f6cfc0b52 100644
--- a/ext/tk/lib/tk/itemconfig.rb
+++ b/ext/tk/lib/tk/itemconfig.rb
@@ -40,6 +40,11 @@ module TkItemConfigOptkeys
end
private :__item_numlistval_optkeys
+ def __item_tkvariable_optkeys
+ ['variable']
+ end
+ private :__item_tkvariable_optkeys
+
def __item_methodcall_optkeys(id) # { key=>method, ... }
# maybe need to override
# {'coords'=>'coords'}
@@ -161,6 +166,10 @@ module TkItemConfigMethod
conf
end
+ when /^(#{__item_tkvariable_optkeys(tagid(tagOrId)).join('|')})$/
+ v = tk_call_without_enc(*(__item_cget_cmd(tagid(tagOrId)) << "-#{option}"))
+ (v.empty?)? nil: TkVarAccess.new(v)
+
when /^(#{__item_strval_optkeys(tagid(tagOrId)).join('|')})$/
_fromUTF8(tk_call_without_enc(*(__item_cget_cmd(tagid(tagOrId)) << "-#{option}")))
@@ -357,6 +366,27 @@ module TkItemConfigMethod
# conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))))
conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), false, true)
+ when /^(#{__item_tkvariable_optkeys(tagid(tagOrId)).join('|')})$/
+ conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), false, true)
+
+ if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
+ && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
+ v = conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
+ if v.empty?
+ conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = nil
+ else
+ conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = TkVarAccess.new(v)
+ end
+ end
+ if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
+ v = conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]]
+ if v.empty?
+ conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = nil
+ else
+ conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = TkVarAccess.new(v)
+ end
+ end
+
else
# conf = tk_split_list(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))))
conf = tk_split_list(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), 0, false, true)
@@ -458,6 +488,25 @@ module TkItemConfigMethod
list(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
end
+ when /^(#{__item_tkvariable_optkeys(tagid(tagOrId)).join('|')})$/
+ if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
+ && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
+ v = conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
+ if v.empty?
+ conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = nil
+ else
+ conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = TkVarAccess.new(v)
+ end
+ end
+ if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
+ v = conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]]
+ if v.empty?
+ conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = nil
+ else
+ conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = TkVarAccess.new
+ end
+ end
+
else
if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
&& conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
@@ -630,6 +679,27 @@ module TkItemConfigMethod
# conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))))
conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), false, true)
+ when /^(#{__item_tkvariable_optkeys(tagid(tagOrId)).join('|')})$/
+ conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), false, true)
+
+ if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
+ && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
+ v = conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
+ if v.empty?
+ conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = nil
+ else
+ conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = TkVarAccess.new(v)
+ end
+ end
+ if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
+ v = conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]]
+ if v.empty?
+ conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = nil
+ else
+ conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = TkVarAccess.new(v)
+ end
+ end
+
else
# conf = tk_split_list(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))))
conf = tk_split_list(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), 0, false, true)
@@ -734,6 +804,25 @@ module TkItemConfigMethod
list(conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]])
end
+ when /^(#{__item_tkvariable_optkeys(tagid(tagOrId)).join('|')})$/
+ if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
+ && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
+ v = conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
+ if v.empty?
+ conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = nil
+ else
+ conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = TkVarAccess.new(v)
+ end
+ end
+ if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] )
+ v = conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]]
+ if v.empty?
+ conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = nil
+ else
+ conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = TkVarAccess.new(v)
+ end
+ end
+
else
if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \
&& conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] )
diff --git a/ext/tk/lib/tk/label.rb b/ext/tk/lib/tk/label.rb
index ea669d576..8b45db9b3 100644
--- a/ext/tk/lib/tk/label.rb
+++ b/ext/tk/lib/tk/label.rb
@@ -15,8 +15,4 @@ class TkLabel<TkWindow
# end
#end
#private :create_self
-
- def textvariable(v)
- configure 'textvariable', tk_trace_variable(v)
- end
end
diff --git a/ext/tk/lib/tk/radiobutton.rb b/ext/tk/lib/tk/radiobutton.rb
index 5649a5c44..6f7a5f60a 100644
--- a/ext/tk/lib/tk/radiobutton.rb
+++ b/ext/tk/lib/tk/radiobutton.rb
@@ -25,9 +25,6 @@ class TkRadioButton<TkButton
tk_send_without_enc('select')
self
end
- def variable(v)
- configure 'variable', tk_trace_variable(v)
- end
def get_value
var = tk_send_without_enc('cget', '-variable')
diff --git a/ext/tk/lib/tk/variable.rb b/ext/tk/lib/tk/variable.rb
index 397489d98..1ea41b729 100644
--- a/ext/tk/lib/tk/variable.rb
+++ b/ext/tk/lib/tk/variable.rb
@@ -1529,12 +1529,36 @@ end
class TkVarAccess<TkVariable
def self.new(name, *args)
- return TkVar_ID_TBL[name] if TkVar_ID_TBL[name]
+ if name.kind_of?(TkVariable)
+ name.value = args[0] unless args.empty?
+ return name
+ end
+
+ if v = TkVar_ID_TBL[name]
+ v.value = args[0] unless args.empty?
+ return v
+ end
+
super(name, *args)
end
def self.new_hash(name, *args)
- return TkVar_ID_TBL[name] if TkVar_ID_TBL[name]
+ if name.kind_of?(TkVariable)
+ unless name.is_hash?
+ fail ArgumentError, "already exist as a scalar variable"
+ end
+ name.value = args[0] unless args.empty?
+ return name
+ end
+
+ if v = TkVar_ID_TBL[name]
+ unless v.is_hash?
+ fail ArgumentError, "already exist as a scalar variable"
+ end
+ v.value = args[0] unless args.empty?
+ return v
+ end
+
INTERP._invoke_without_enc('global', name)
if args.empty? && INTERP._invoke_without_enc('array', 'exist', name) == '0'
self.new(name, {}) # force creating
diff --git a/ext/tk/sample/tkextlib/tile/demo.rb b/ext/tk/sample/tkextlib/tile/demo.rb
index fcda3e810..39592b88e 100644
--- a/ext/tk/sample/tkextlib/tile/demo.rb
+++ b/ext/tk/sample/tkextlib/tile/demo.rb
@@ -549,8 +549,8 @@ else # tile 0.5 or earlier
scale.command{|value| progress.set(value)}
vscale.command{|value| vprogress.set(value)}
else # this would also work. (via TkVariable#trace)
- v1 = $V.ref(:SCALE)
- v2 = $V.ref(:VSCALE)
+ v1 = scale.variable
+ v2 = vscale.variable
v1.trace('w', proc{ progress.set(v1.value) })
v2.trace('w', proc{ vprogress.set(v2.value) })
end