From 7738391d237112db43bb47f793fc0939fb561d00 Mon Sep 17 00:00:00 2001 From: nagai Date: Sat, 26 Mar 2005 13:58:11 +0000 Subject: * ext/tk/lib/tk.rb (_callback_entry_class?): add for checking whether a class is available for a callback entry. * ext/tk/lib/tk.rb (after_cancel): add Tk.after_cancel(afterID) method. * ext/tk/lib/tk.rb (array2tk_list): change from private module method of TkComm to public module method. * ext/tk/lib/tk.rb (cget): add check that slot argument is not empty string. * ext/tk/lib/tk.rb (configinfo): ditto. * ext/tk/lib/tk/itemconfig.rb (itemcget): add check that slot argument is not empty string. * ext/tk/lib/tk/itemconfig.rb (itemconfiginfo): ditto. * ext/tk/lib/tk/entry.rb: add TkEntry#icursor and icursor= (alias of cursor and cursor= method). * ext/tk/lib/tk/font.rb: improve font treatment when the font name is empty string. * ext/tk/lib/tk/variable.rb: add :variable, :window and :procedure type. * ext/tk/lib/tk/variable.rb: improve treatment of array-type tkvariable. * ext/tk/lib/tkextlib/blt.rb: add commands for zooming. * ext/tk/lib/tkextlib/blt/*: bug fix. * ext/tk/lib/tkextlib/treectrl/tktreectrl.rb: bug fix and add methods to call TreeCtrl commands for bindings. * ext/tk/sample/tkextlib/blt/*: new sample scritps. * ext/tk/sample/tkextlib/treectrl/*: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/lib/tk.rb | 30 +- ext/tk/lib/tk/entry.rb | 2 + ext/tk/lib/tk/font.rb | 113 +++++- ext/tk/lib/tk/itemconfig.rb | 16 +- ext/tk/lib/tk/variable.rb | 528 +++++++++++++++++++++++++---- ext/tk/lib/tkextlib/SUPPORT_STATUS | 15 +- ext/tk/lib/tkextlib/blt.rb | 41 +++ ext/tk/lib/tkextlib/blt/barchart.rb | 1 + ext/tk/lib/tkextlib/blt/bitmap.rb | 35 +- ext/tk/lib/tkextlib/blt/busy.rb | 42 +-- ext/tk/lib/tkextlib/blt/component.rb | 251 +++++++++++--- ext/tk/lib/tkextlib/blt/graph.rb | 1 + ext/tk/lib/tkextlib/blt/htext.rb | 5 + ext/tk/lib/tkextlib/blt/stripchart.rb | 1 + ext/tk/lib/tkextlib/blt/table.rb | 17 +- ext/tk/lib/tkextlib/treectrl/tktreectrl.rb | 280 ++++++++++++--- 16 files changed, 1170 insertions(+), 208 deletions(-) (limited to 'ext/tk/lib') diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index d246cd9a0c..61e76c29bc 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -448,7 +448,7 @@ end private_class_method :tk_split_escstr, :tk_split_sublist private_class_method :tk_split_list, :tk_split_simplelist - private_class_method :array2tk_list +# private_class_method :array2tk_list =begin ### --> definition is moved to TkUtil module @@ -583,6 +583,12 @@ end private :_toUTF8, :_fromUTF8 module_function :_toUTF8, :_fromUTF8 + def _callback_entry_class?(cls) + cls <= Proc || cls <= Method || cls <= TkCallbackEntry + end + private :_callback_entry_class? + module_function :_callback_entry_class? + def _callback_entry?(obj) obj.kind_of?(Proc) || obj.kind_of?(Method) || obj.kind_of?(TkCallbackEntry) end @@ -1301,6 +1307,10 @@ module TkCore tk_call_without_enc('after','idle',cmdid) end + def after_cancel(afterId) + tk_call_without_enc('after','cancel',afterId) + end + def windowingsystem tk_call_without_enc('tk', 'windowingsystem') end @@ -2612,7 +2622,12 @@ module TkConfigMethod end def cget(slot) + orig_slot = slot slot = slot.to_s + + if slot.length == 0 + fail ArgumentError, "Invalid option `#{orig_slot.inspect}'" + end if ( method = _symbolkey2str(__methodcall_optkeys)[slot] ) return self.__send__(method) @@ -2698,7 +2713,12 @@ module TkConfigMethod end else + orig_slot = slot slot = slot.to_s + if slot.length == 0 + fail ArgumentError, "Invalid option `#{orig_slot.inspect}'" + end + if ( conf = __keyonly_optkeys.find{|k, v| k.to_s == slot} ) defkey, undefkey = conf if value @@ -2727,7 +2747,8 @@ module TkConfigMethod def configinfo(slot = nil) if TkComm::GET_CONFIGINFO_AS_ARRAY - if (slot.to_s =~ /^(|latin|ascii|kanji)(#{__font_optkeys.join('|')})$/) + if (slot && + slot.to_s =~ /^(|latin|ascii|kanji)(#{__font_optkeys.join('|')})$/) fontkey = $2 conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__confinfo_cmd << "-#{fontkey}")))) conf[__configinfo_struct[:key]] = @@ -2984,7 +3005,8 @@ module TkConfigMethod end else # ! TkComm::GET_CONFIGINFO_AS_ARRAY - if (slot.to_s =~ /^(|latin|ascii|kanji)(#{__font_optkeys.join('|')})$/) + if (slot && + slot.to_s =~ /^(|latin|ascii|kanji)(#{__font_optkeys.join('|')})$/) fontkey = $2 conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__confinfo_cmd << "-#{fontkey}")))) conf[__configinfo_struct[:key]] = @@ -4002,7 +4024,7 @@ end #Tk.freeze module Tk - RELEASE_DATE = '2005-03-14'.freeze + RELEASE_DATE = '2005-03-26'.freeze autoload :AUTO_PATH, 'tk/variable' autoload :TCL_PACKAGE_PATH, 'tk/variable' diff --git a/ext/tk/lib/tk/entry.rb b/ext/tk/lib/tk/entry.rb index 0fe553d55c..63051979e6 100644 --- a/ext/tk/lib/tk/entry.rb +++ b/ext/tk/lib/tk/entry.rb @@ -27,11 +27,13 @@ class TkEntry@latinfont, 'kanjifont'=>@kanjifont} + else + @compoundfont = @latinfont + @fontslot = {'font'=>@latinfont} + end + else + @latinfont = @id + 'l' + @kanjifont = @id + 'k' + @compoundfont = @id + 'c' + + if JAPANIZED_TK + tk_call('font', 'create', @latinfont, '-charset', 'iso8859') + tk_call('font', 'create', @kanjifont, '-charset', 'jisx0208.1983') + tk_call('font', 'create', @compoundfont, + '-compound', [@latinfont, @kanjifont]) + else + tk_call('font', 'create', @latinfont) + tk_call('font', 'create', @kanjifont) + tk_call('font', 'create', @compoundfont) + end + + @fontslot = {'font'=>@compoundfont} + end + + self + end + def initialize(ltn=nil, knj=nil, keys=nil) + ltn = '{}' if ltn == '' + knj = '{}' if knj == '' + # @id = Tk_FontID.join('') @id = Tk_FontID.join(TkCore::INTERP._ip_id_) Tk_FontID[1].succ! @@ -657,10 +711,17 @@ class TkFont end def create_compoundfont_tk8x(ltn, knj, keys) - create_latinfont(ltn) - create_kanjifont(knj) + if knj + create_latinfont(ltn) + create_kanjifont(knj) + else + cfnt = ltn + create_kanjifont(cfnt) + create_latinfont(cfnt) + end @compoundfont = @id + 'c' + if JAPANIZED_TK unless keys keys = {} @@ -735,6 +796,7 @@ class TkFont end if knj + compoundkeys = nil kanjikeys = {} begin actual_core(@kanjifont).each{|key,val| kanjikeys[key] = val} @@ -746,6 +808,17 @@ class TkFont end end + if cfnt + if cfnt.kind_of?(Hash) + compoundkeys = cfnt.dup + else + compoundkeys = {} + actual_core(cfnt).each{|key,val| compoundkeys[key] = val} + end + compoundkeys.update(_symbolkey2str(keys)) + keys = compoundkeys + end + @fontslot = {'font'=>@compoundfont} tk_call('font', 'configure', @compoundfont, *hash_kv(keys)) end @@ -754,11 +827,21 @@ class TkFont ################################### public ################################### + def inspect + sprintf("#<%s:%0x:%s>", self.class.inspect, self.__id__, @compoundfont) + end + def method_missing(id, *args) name = id.id2name case args.length when 1 - configure name, args[0] + if name[-1] == ?= + configure name[0..-2], args[0] + args[0] + else + configure name, args[0] + self + end when 0 begin configinfo name @@ -1099,6 +1182,7 @@ class TkFont alias ascii_metrics latin_metrics ################################### +=begin def dup src = self obj = super() @@ -1111,6 +1195,13 @@ class TkFont obj.instance_eval{ initialize(src) } obj end +=end + def dup + TkFont.new(self) + end + def clone + TkFont.new(self) + end end module TkFont::CoreMethods @@ -1140,6 +1231,8 @@ module TkFont::CoreMethods end def actual_core_tk8x(font, win=nil, option=nil) + font = '{}' if font == '' + if option == 'compound' || option == :compound "" elsif option @@ -1465,6 +1558,8 @@ module TkFont::CoreMethods end def latin_replace_core_tk8x(ltn) + ltn = '{}' if ltn == '' + if JAPANIZED_TK begin tk_call('font', 'delete', '@font_tmp') @@ -1528,6 +1623,8 @@ module TkFont::CoreMethods end def kanji_replace_core_tk8x(knj) + knj = '{}' if knj == '' + if JAPANIZED_TK begin tk_call('font', 'delete', '@font_tmp') @@ -1573,6 +1670,8 @@ module TkFont::CoreMethods end def measure_core_tk8x(font, win, text) + font = '{}' if font == '' + if win number(tk_call('font', 'measure', font, '-displayof', win, text)) @@ -1591,6 +1690,8 @@ module TkFont::CoreMethods end def metrics_core_tk8x(font, win, option=nil) + font = '{}' if font == '' + if option if win number(tk_call('font', 'metrics', font, diff --git a/ext/tk/lib/tk/itemconfig.rb b/ext/tk/lib/tk/itemconfig.rb index f0f13e63bd..72225e7522 100644 --- a/ext/tk/lib/tk/itemconfig.rb +++ b/ext/tk/lib/tk/itemconfig.rb @@ -6,6 +6,8 @@ require 'tkutil' require 'tk/itemfont.rb' module TkItemConfigOptkeys + include TkUtil + def __item_numval_optkeys(id) [] end @@ -119,8 +121,13 @@ module TkItemConfigMethod ################################################ def itemcget(tagOrId, option) + orig_opt = option option = option.to_s + if option.length == 0 + fail ArgumentError, "Invalid option `#{orig_opt.inspect}'" + end + if ( method = _symbolkey2str(__item_methodcall_optkeys(tagid(tagOrId)))[option] ) return self.__send__(method, tagOrId) end @@ -204,7 +211,12 @@ module TkItemConfigMethod end else + orig_slot = slot slot = slot.to_s + if slot.length == 0 + fail ArgumentError, "Invalid option `#{orig_slot.inspect}'" + end + if ( conf = __item_keyonly_optkeys(tagid(tagOrId)).find{|k, v| k.to_s == slot } ) defkey, undefkey = conf if value @@ -229,7 +241,7 @@ module TkItemConfigMethod def itemconfiginfo(tagOrId, slot = nil) if TkComm::GET_CONFIGINFO_AS_ARRAY - if (slot.to_s =~ /^(|latin|ascii|kanji)(#{__item_font_optkeys(tagid(tagOrId)).join('|')})$/) + if (slot && slot.to_s =~ /^(|latin|ascii|kanji)(#{__item_font_optkeys(tagid(tagOrId)).join('|')})$/) fontkey = $2 conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{fontkey}")))) conf[__item_configinfo_struct(tagid(tagOrId))[:key]] = @@ -487,7 +499,7 @@ module TkItemConfigMethod end else # ! TkComm::GET_CONFIGINFO_AS_ARRAY - if (slot.to_s =~ /^(|latin|ascii|kanji)(#{__item_font_optkeys(tagid(tagOrId)).join('|')})$/) + if (slot && slot.to_s =~ /^(|latin|ascii|kanji)(#{__item_font_optkeys(tagid(tagOrId)).join('|')})$/) fontkey = $2 conf = tk_split_simplelist(_fromUTF8(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{fontkey}")))) conf[__item_configinfo_struct(tagid(tagOrId))[:key]] = diff --git a/ext/tk/lib/tk/variable.rb b/ext/tk/lib/tk/variable.rb index e3a08dfdcf..982182c2a8 100644 --- a/ext/tk/lib/tk/variable.rb +++ b/ext/tk/lib/tk/variable.rb @@ -109,11 +109,12 @@ TkCore::INTERP.add_tk_procs('rb_var', 'args', <<-'EOL') end self end - def default_value=(val) + def set_default_value(val) @def_default = :val @default_val = val self end + alias default_value= set_default_value def default_proc(cmd = Proc.new) @def_default = :proc @default_val = cmd @@ -129,59 +130,111 @@ TkCore::INTERP.add_tk_procs('rb_var', 'args', <<-'EOL') def default_value_type @type end + def default_element_value_type(idxs) + if idxs.kind_of?(Array) + index = idxs.collect{|idx| _get_eval_string(idx, true)}.join(',') + else + index = _get_eval_string(idxs, true) + end + @element_type[index] + end - def default_value_type=(type) + def _set_default_value_type_core(type, idxs) if type.kind_of?(Class) if type == NilClass - @type = nil + type = nil elsif type == Numeric - @type = :numeric + type = :numeric elsif type == TrueClass || type == FalseClass - @type = :bool + type = :bool elsif type == String - @type = :string + type = :string elsif type == Symbol - @type = :symbol + type = :symbol elsif type == Array - @type = :list + type = :list + elsif type <= TkVariable + type = :variable + elsif type <= TkWindow + type = :window + elsif TkComm._callback_entry_class?(type) + type = :procedure else - @type = nil + type = nil end else case(type) when nil - @type = nil + type = nil when :numeric, 'numeric' - @type = :numeric + type = :numeric when true, false, :bool, 'bool' - @type = :bool + type = :bool when :string, 'string' - @type = :string + type = :string when :symbol, 'symbol' - @type = :symbol + type = :symbol when :list, 'list' - @type = :list + type = :list when :numlist, 'numlist' - @type = :numlist + type = :numlist + when :variable, 'variable' + type = :variable + when :window, 'window' + type = :window + when :procedure, 'procedure' + type = :procedure else - self.default_value_type = type.class + return _set_default_value_type_core(type.class, idxs) end end - @type + if idxs + if idxs.kind_of?(Array) + index = idxs.collect{|idx| _get_eval_string(idx, true)}.join(',') + else + index = _get_eval_string(idxs, true) + end + @element_type[index] = type + else + @type = type + end + type + end + private :_set_default_value_type_core + + def set_default_value_type(type) + _set_default_value_type_core(type, nil) + self end + alias default_value_type= set_default_value_type - def _to_default_type(val) - return val unless @type + def set_default_element_value_type(idxs, type) + _set_default_value_type_core(type, idxs) + self + end + + def _to_default_type(val, idxs = nil) + if idxs + if idxs.kind_of?(Array) + index = idxs.collect{|idx| _get_eval_string(idx, true)}.join(',') + else + index = _get_eval_string(idxs, true) + end + type = @element_type[index] + else + type = @type + end + return val unless type if val.kind_of?(Hash) - val.keys.each{|k| val[k] = _to_default_type(val[k]) } + val.keys.each{|k| val[k] = _to_default_type(val[k], idxs) } val else begin - case(@type) + case(type) when :numeric number(val) when :bool - TkComm + TkComm.bool(val) when :string val when :symbol @@ -190,6 +243,12 @@ TkCore::INTERP.add_tk_procs('rb_var', 'args', <<-'EOL') tk_split_simplelist(val) when :numlist tk_split_simplelist(val).collect!{|v| number(v)} + when :variable + TkVarAccess.new(val) + when :window + TkComm.window(val) + when :procedure + TkComm.procedure(val) else val end @@ -200,6 +259,11 @@ TkCore::INTERP.add_tk_procs('rb_var', 'args', <<-'EOL') end private :_to_default_type + def _to_default_element_type(idxs, val) + _to_default_type(val, idxs) + end + private :_to_default_element_type + def initialize(val="", type=nil) # @id = Tk_VARIABLE_ID.join('') @id = Tk_VARIABLE_ID.join(TkCore::INTERP._ip_id_) @@ -213,6 +277,10 @@ TkCore::INTERP.add_tk_procs('rb_var', 'args', <<-'EOL') @trace_elem = nil @trace_opts = nil + @type = nil + var = self + @element_type = Hash.new{|k,v| var.default_value_type } + self.default_value_type = type begin @@ -326,14 +394,15 @@ TkCore::INTERP.add_tk_procs('rb_var', 'args', <<-'EOL') ! is_hash? end - def exist?(idx = nil) + def exist?(*elems) INTERP._invoke_without_enc('global', @id) - if idx + if elems.empty? + TkComm.bool(tk_call('info', 'exist', @id)) + else # array + index = elems.collect{|idx| _get_eval_string(idx, true)}.join(',') TkComm.bool(tk_call('info', 'exist', "#{@id}")) && - TkComm.bool(tk_call('info', 'exist', "#{@id}(#{idx})")) - else - TkComm.bool(tk_call('info', 'exist', @id)) + TkComm.bool(tk_call('info', 'exist', "#{@id}(#{index})")) end end @@ -389,6 +458,7 @@ if USE_TCLs_SET_VARIABLE_FUNCTIONS end def value=(val) + val = val._value if !@type && @type != :variable && val.kind_of?(TkVariable) if val.kind_of?(Hash) self.clear val.each{|k, v| @@ -418,11 +488,10 @@ if USE_TCLs_SET_VARIABLE_FUNCTIONS end end - def [](*idxs) + def _element_value(*idxs) index = idxs.collect{|idx| _get_eval_string(idx, true)}.join(',') begin - # _fromUTF8(INTERP._get_global_var2(@id, index)) - _to_default_type(_fromUTF8(INTERP._get_global_var2(@id, index))) + _fromUTF8(INTERP._get_global_var2(@id, index)) rescue => e case @def_default when :proc @@ -440,6 +509,8 @@ if USE_TCLs_SET_VARIABLE_FUNCTIONS def []=(*args) val = args.pop + type = default_element_value_type(args) + val = val._value if !type && type != :variable && val.kind_of?(TkVariable) index = args.collect{|idx| _get_eval_string(idx, true)}.join(',') _fromUTF8(INTERP._set_global_var2(@id, index, _get_eval_string(val, true))) #_fromUTF8(INTERP._set_global_var2(@id, _toUTF8(_get_eval_string(index)), @@ -448,11 +519,12 @@ if USE_TCLs_SET_VARIABLE_FUNCTIONS # _get_eval_string(val, true))) end - def unset(elem=nil) - if elem - INTERP._unset_global_var2(@id, _get_eval_string(elem, true)) - else + def unset(*elems) + if elems.empty? INTERP._unset_global_var(@id) + else + index = elems.collect{|idx| _get_eval_string(idx, true)}.join(',') + INTERP._unset_global_var2(@id, index) end end alias remove unset @@ -481,6 +553,7 @@ else end def value=(val) + val = val._value if !@type && @type != :variable && val.kind_of?(TkVariable) begin #s = '"' + _get_eval_string(val).gsub(/[\[\]$"]/, '\\\\\&') + '"' s = '"' + _get_eval_string(val).gsub(/[\[\]$"\\]/, '\\\\\&') + '"' @@ -530,11 +603,10 @@ else end end - def [](*idxs) + def _element_value(*idxs) index = idxs.collect{|idx| _get_eval_string(idx)}.join(',') begin - # INTERP._eval(Kernel.format('global %s; set %s(%s)', @id, @id, index)) - _to_default_type(INTERP._eval(Kernel.format('global %s; set %s(%s)', @id, @id, index))) + INTERP._eval(Kernel.format('global %s; set %s(%s)', @id, @id, index)) rescue => e case @def_default when :proc @@ -554,6 +626,8 @@ else def []=(*args) val = args.pop + type = default_element_value_type(args) + val = val._value if !type && type != :variable && val.kind_of?(TkVariable) index = args.collect{|idx| _get_eval_string(idx)}.join(',') INTERP._eval(Kernel.format('global %s; set %s(%s) %s', @id, @id, index, _get_eval_string(val))) @@ -565,37 +639,73 @@ else # _get_eval_string(val)) end - def unset(elem=nil) - if elem - INTERP._eval(Kernel.format('global %s; unset %s(%s)', - @id, @id, _get_eval_string(elem))) - #INTERP._eval(Kernel.format('unset %s(%s)', @id, tk_tcl2ruby(elem))) - #INTERP._eval('unset ' + @id + '(' + _get_eval_string(elem) + ')') - else + def unset(*elems) + if elems.empty? INTERP._eval(Kernel.format('global %s; unset %s', @id, @id)) #INTERP._eval(Kernel.format('unset %s', @id)) #INTERP._eval('unset ' + @id) + else + index = elems.collect{|idx| _get_eval_string(idx, true)}.join(',') + INTERP._eval(Kernel.format('global %s; unset %s(%s)', @id, @id, index)) + #INTERP._eval(Kernel.format('global %s; unset %s(%s)', + # @id, @id, _get_eval_string(elem))) + #INTERP._eval(Kernel.format('unset %s(%s)', @id, tk_tcl2ruby(elem))) + #INTERP._eval('unset ' + @id + '(' + _get_eval_string(elem) + ')') end end alias remove unset end - protected :_value + protected :_value, :_element_value def value _to_default_type(_value) end - def value_type=(val) - self.default_value_type = val - self.value=(val) + def [](*idxs) + _to_default_element_type(idxs, _element_value(*idxs)) + end + + def set_value(val) + self.value = val + self + end + + def set_element_value(idxs, val) + if idxs.kind_of?(Array) + self[*idxs]=val + else + self[idxs]=val + end + self + end + + def set_value_type(val) + self.default_value_type = val.class + self.value = val + self + end + + alias value_type= set_value_type + + def set_element_value_type(idxs, val) + self.set_default_element_value_type(idxs, val.class) + if idxs.kind_of?(Array) + self[*idxs]=val + else + self[idxs]=val + end + self end def numeric number(_value) end - def numeric=(val) + def numeric_element(*idxs) + number(_element_value(*idxs)) + end + def set_numeric(val) case val when Numeric self.value=(val) @@ -604,14 +714,39 @@ end else raise ArgumentError, "Numeric is expected" end - val + self + end + alias numeric= set_numeric + def set_numeric_element(idxs, val) + case val + when Numeric + val + when TkVariable + val = val.numeric + else + raise ArgumentError, "Numeric is expected" + end + if idxs.kind_of?(Array) + self[*idxs]=val + else + self[idxs]=val + end + self end - def numeric_type=(val) + def set_numeric_type(val) @type = :numeric self.numeric=(val) + self + end + alias numeric_type= set_numeric_type + def set_numeric_element_type(idxs, val) + self.set_default_element_value_type(idxs, :numeric) + self.set_numeric_element(idxs, val) end def bool + TkComm.bool(_value) +=begin # see Tcl_GetBoolean man-page case _value.downcase when '0', 'false', 'no', 'off' @@ -619,8 +754,12 @@ end else true end +=end + end + def bool_element(*idxs) + TkComm.bool(_element_value(*idxs)) end - def bool=(val) + def set_bool(val) if ! val self.value = '0' else @@ -631,37 +770,216 @@ end self.value = '1' end end + self + end + alias bool= set_bool + def set_bool_element(idxs, val) + if ! val + val = '0' + else + case val.to_s.downcase + when 'false', '0', 'no', 'off' + val = '0' + else + val = '1' + end + end + if idxs.kind_of?(Array) + self[*idxs]=val + else + self[idxs]=val + end + self end - def bool_type=(val) + def set_bool_type(val) @type = :bool self.bool=(val) + self + end + alias bool_type= set_bool_type + def set_bool_element_type(idxs, val) + self.set_default_element_value_type(idxs, :bool) + self.set_bool_element(idxs, val) + end + + def variable + TkVarAccess.new(self._value) + end + def variable_element(*idxs) + TkVarAccess.new(_element_value(*idxs)) + end + def set_variable(var) + var = var.id if var.kind_of?(TkVariable) + self.value = var + self + end + alias variable= set_variable + def set_variable_element(idxs, var) + var = var.id if var.kind_of?(TkVariable) + if idxs.kind_of?(Array) + self[*idxs]=var + else + self[idxs]=var + end + self + end + def set_variable_type(var) + @type = :variable + var = var.id if var.kind_of?(TkVariable) + self.value = var + self + end + alias variable_type= set_variable_type + def set_variable_element_type(idxs, var) + self.set_default_element_value_type(idxs, :variable) + self.set_variable_element(idxs, var) + end + + def window + TkComm.window(self._value) + end + def window_element(*idxs) + TkComm.window(_element_value(*idxs)) + end + def set_window(win) + win = win._value if win.kind_of?(TkVariable) + self.value = win + self + end + alias window= set_window + def set_window_element(idxs, win) + win = win._value if win.kind_of?(TkVariable) + if idxs.kind_of?(Array) + self[*idxs]=win + else + self[idxs]=win + end + self + end + def set_window_type(win) + @type = :window + self.window=(win) + self + end + alias window_type= set_window_type + def set_window_element_type(idxs, win) + self.set_default_element_value_type(idxs, :window) + self.set_window_element(idxs, win) + end + + def procedure + TkComm.procedure(self._value) + end + def procedure_element(*idxs) + TkComm.procedure(_element_value(*idxs)) + end + def set_procedure(cmd) + self.value = cmd + self + end + alias procedure= set_procedure + def set_procedure_element(idxs, cmd) + cmd = cmd._value if cmd.kind_of?(TkVariable) + if idxs.kind_of?(Array) + self[*idxs]=cmd + else + self[idxs]=cmd + end + self + end + def set_procedure_type(cmd) + @type = :procedure + self.procedure=(cmd) + self + end + alias procedure_type= set_procedure_type + def set_procedure_element_type(idxs, cmd) + self.set_default_element_value_type(idxs, :procedure) + self.set_proceure_element(idxs, cmd) end def to_i number(_value).to_i end + def element_to_i(*idxs) + number(_element_value(*idxs)).to_i + end def to_f number(_value).to_f end + def element_to_f(*idxs) + number(_element_value(*idxs)).to_f + end def to_s #string(value).to_s _value end - alias string= value= - def string_type=(val) + def element_to_s(*idxs) + _element_value(*idxs) + end + def string_element(*idxs) + _element_value(*idxs) + end + def set_string(val) + val = val._value if val.kind_of?(TkVariable) + self.value=val + self + end + alias string= set_string + def set_string_element(idxs, val) + val = val._value if val.kind_of?(TkVariable) + if idxs.kind_of?(Array) + self[*idxs]=val + else + self[idxs]=val + end + self + end + def set_string_type(val) @type = :string - self.value=(val) + self.string=(val) + self + end + alias string_type= set_string_type + def set_string_element_type(idxs, val) + self.set_default_element_value_type(idxs, :string) + self.set_string_element(idxs, val) end def to_sym _value.intern end - alias symbol= value= - def symbol_type=(val) + alias symbol to_sym + def element_to_sym(*idxs) + _element_value(*idxs).intern + end + alias symbol_element element_to_sym + def set_symbol(val) + val = val._value if val.kind_of?(TkVariable) + self.value=val + self + end + alias symbol= set_symbol + def set_symbol_element(idxs, val) + val = val._value if val.kind_of?(TkVariable) + if idxs.kind_of?(Array) + self[*idxs]=val + else + self[idxs]=val + end + self + end + def set_symbol_type(val) @type = :symbol self.value=(val) + self + end + alias symbol_type= set_symbol_type + def set_symbol_element_type(idxs, val) + self.set_default_element_value_type(idxs, :symbol) + self.set_symbol_element(idxs, val) end def list @@ -669,12 +987,19 @@ end tk_split_simplelist(_value) end alias to_a list + def list_element(*idxs) + tk_split_simplelist(_element_value(*idxs)) + end + alias element_to_a list_element def numlist list.collect!{|val| number(val)} end + def numlist_element(*idxs) + list_element(*idxs).collect!{|val| number(val)} + end - def list=(val) + def set_list(val) case val when Array self.value=(val) @@ -683,41 +1008,103 @@ end else raise ArgumentError, "Array is expected" end - val + self end - alias numlist= list= + alias list= set_list + + alias set_numlist set_list + alias numlist= set_numlist - def list_type=(val) + def set_list_element(idxs, val) + case val + when Array + val + when TkVariable + val = val.list + else + raise ArgumentError, "Array is expected" + end + if idxs.kind_of?(Array) + self[*idxs]=val + else + self[idxs]=val + end + self + end + alias set_numlist_element set_list_element + + def set_list_type(val) @type = :list self.list=(val) + self + end + alias list_type= set_list_type + def set_list_element_type(idxs, val) + self.set_default_element_value_type(idxs, :list) + self.set_list_element(idxs, val) end - def numlist_type=(val) + def set_numlist_type(val) @type = :numlist self.numlist=(val) + self + end + alias numlist_type= set_numlist_type + def set_numlist_element_type(idxs, val) + self.set_default_element_value_type(idxs, :numlist) + self.set_numlist_element(idxs, val) end def lappend(*elems) tk_call('lappend', @id, *elems) self end + def element_lappend(idxs, *elems) + if idxs.kind_of?(Array) + idxs = idxs.collect{|idx| _get_eval_string(idx, true)}.join(',') + end + tk_call('lappend', "#{@id}(#{idxs})", *elems) + self + end def lindex(idx) tk_call('lindex', self._value, idx) end alias lget lindex + def element_lindex(elem_idxs, idx) + if elem_idxs.kind_of?(Array) + val = _element_value(*elem_idxs) + else + val = _element_value(elem_idxs) + end + tk_call('lindex', val, idx) + end + alias element_lget element_lindex def lget_i(idx) number(lget(idx)).to_i end + def element_lget_i(elem_idxs, idx) + number(element_lget(elem_idxs, idx)).to_i + end def lget_f(idx) number(lget(idx)).to_f end + def element_lget_f(elem_idxs, idx) + number(element_lget(elem_idxs, idx)).to_f + end def lset(idx, val) tk_call('lset', @id, idx, val) self end + def element_lset(elem_idxs, idx, val) + if elem_idxs.kind_of?(Array) + idxs = elem_idxs.collect{|i| _get_eval_string(i, true)}.join(',') + end + tk_call('lset', "#{@id}(#{idxs})", idx, val) + self + end def inspect #Kernel.format "#", @id @@ -823,7 +1210,8 @@ end # false if self is not an assoc array self._value == other else - false + # false + self._value == _get_eval_string(other) end end @@ -842,13 +1230,14 @@ end rescue other = other._value end - end - if other.kind_of?(Numeric) + elsif other.kind_of?(Numeric) begin return self.numeric <=> other rescue return self._value <=> other.to_s end + elsif other.kind_of?(Array) + return self.list <=> other else return self._value <=> other end @@ -1107,7 +1496,6 @@ end end end - class TkVarAccess ICONS TkImg 1.3 http://sf.net/projects/tkimg ==> tkimg +BLT 2.4z http://sourceforge.net/projects/blt + * see also tcltk-ext library on RAA + (http://raa.ruby-lang.org/) + ==> blt + +TkTreeCtrl 1.1 http://tktreectrl.sourceforge.net/ ==> treectrl + + ===< support (may be alpha or beta quality) >================================= @@ -84,19 +92,12 @@ TclX CVS/Hd(2005-02-07) ==> tclx (partial support; infox command and XPG/3 message catalogs only) -TkTreeCtrl 1.1 http://tktreectrl.sourceforge.net/ ==> treectrl - Tile 0.6 http://tktable.sourceforge.net/tile/ ==> tile ===< possibly available (not tested; alpha quality) >========================= -BLT 2.4z http://sourceforge.net/projects/blt - * see also tcltk-ext library on RAA - (http://raa.ruby-lang.org/) - ==> blt - winico CVS/Hd(2004-11-02) http://tktable.sourceforge.net ==> winico (win32 only) diff --git a/ext/tk/lib/tkextlib/blt.rb b/ext/tk/lib/tkextlib/blt.rb index 965886762e..60ed39a0cf 100644 --- a/ext/tk/lib/tkextlib/blt.rb +++ b/ext/tk/lib/tkextlib/blt.rb @@ -105,6 +105,47 @@ module Tk #################################################### + def self.active_legend(graph) + tk_call_without_enc('Blt_ActiveLegend', graph) + end + def self.crosshairs(graph) + tk_call_without_enc('Blt_Crosshairs', graph) + end + def self.zoom_stack(graph) + tk_call_without_enc('Blt_ZoomStack', graph) + end + def self.print_key(graph) + tk_call_without_enc('Blt_PrintKey', graph) + end + def self.closest_point(graph) + tk_call_without_enc('Blt_ClosestPoint', graph) + end + + module GraphCommand + def active_legend + tk_call_without_enc('Blt_ActiveLegend', @path) + self + end + def crosshairs + tk_call_without_enc('Blt_Crosshairs', @path) + self + end + def zoom_stack + tk_call_without_enc('Blt_ZoomStack', @path) + self + end + def print_key + tk_call_without_enc('Blt_PrintKey', @path) + self + end + def closest_point + tk_call_without_enc('Blt_ClosestPoint', @path) + self + end + end + + #################################################### + autoload :PlotComponent,'tkextlib/blt/component.rb' autoload :Barchart, 'tkextlib/blt/barchart.rb' diff --git a/ext/tk/lib/tkextlib/blt/barchart.rb b/ext/tk/lib/tkextlib/blt/barchart.rb index 624906b8bd..d8ecad834f 100644 --- a/ext/tk/lib/tkextlib/blt/barchart.rb +++ b/ext/tk/lib/tkextlib/blt/barchart.rb @@ -14,6 +14,7 @@ module Tk::BLT WidgetClassNames[WidgetClassName] = self include PlotComponent + include GraphCommand def __boolval_optkeys ['bufferelements', 'invertxy'] diff --git a/ext/tk/lib/tkextlib/blt/bitmap.rb b/ext/tk/lib/tkextlib/blt/bitmap.rb index 11ad5883d0..31cf8d4229 100644 --- a/ext/tk/lib/tkextlib/blt/bitmap.rb +++ b/ext/tk/lib/tkextlib/blt/bitmap.rb @@ -42,26 +42,41 @@ module Tk::BLT alias _new new def new(data, keys={}) - _new(:data, data, keys) + _new(:data, nil, data, keys) end alias define new + def new_with_name(name, data, keys={}) + _new(:data, name, data, keys) + end + alias define_with_name new_with_name + def compose(text, keys={}) - _new(:text, text, keys) + _new(:text, nil, text, keys) + end + + def compose_with_name(name, text, keys={}) + _new(:text, name, text, keys) end end - def initialize(type, data, keys = {}) - @id = BITMAP_ID.join(TkCore::INTERP._ip_id_) - BITMAP_ID[1].succ! - BITMAP_ID_TBL[@id] = self + def initialize(type, name, data, keys = {}) + if name + @id = name + else + @id = BITMAP_ID.join(TkCore::INTERP._ip_id_) + BITMAP_ID[1].succ! + BITMAP_ID_TBL[@id] = self + end @path = @id - if type == :text - tk_call('::blt::bitmap', 'compose', @id, *hash_kv(keys)) - else # :data - tk_call('::blt::bitmap', 'define', @id, *hash_kv(keys)) + unless bool(tk_call('::blt::bitmap', 'exists', @id)) + if type == :text + tk_call('::blt::bitmap', 'compose', @id, data, *hash_kv(keys)) + else # :data + tk_call('::blt::bitmap', 'define', @id, data, *hash_kv(keys)) + end end end diff --git a/ext/tk/lib/tkextlib/blt/busy.rb b/ext/tk/lib/tkextlib/blt/busy.rb index c0740dc2d7..4726e466f4 100644 --- a/ext/tk/lib/tkextlib/blt/busy.rb +++ b/ext/tk/lib/tkextlib/blt/busy.rb @@ -13,6 +13,27 @@ module Tk::BLT extend TkItemConfigMethod TkCommandNames = ['::blt::busy'.freeze].freeze + + ########################### + + class Shield < TkWindow + def self.shield_path(win) + win = window(win) unless win.kind_of?(TkWindow) + if win.kind_of?(TkToplevel) + win.path + '._Busy' + else + win.path + '_Busy' + end + end + + def initialize(win) + @path = self.class.shield_path(win) + end + end + + def self.shield_path(win) + Tk::BLT::Busy::Shield.shield_path(win) + end end end @@ -30,27 +51,6 @@ class << Tk::BLT::Busy ################################## - class Shield < TkWindow - def self.shield_path(win) - win = window(win) unless win.kind_of?(TkWindow) - if win.kind_of?(TkToplevel) - win.path + '._Busy' - else - win.path + '_Busy' - end - end - - def initialize(win) - @path = self.class.shield_path(win) - end - end - - def shield_path(win) - Tk::BLT::Busy::Shield.shield_path(win) - end - - ################################## - def hold(win, keys={}) tk_call('::blt::busy', 'hold', win, *hash_kv(keys)) end diff --git a/ext/tk/lib/tkextlib/blt/component.rb b/ext/tk/lib/tkextlib/blt/component.rb index 8e36946d0b..c5152ddab4 100644 --- a/ext/tk/lib/tkextlib/blt/component.rb +++ b/ext/tk/lib/tkextlib/blt/component.rb @@ -34,7 +34,7 @@ module Tk::BLT end private :__item_strval_optkeys - def _item_listval_optkeys(id) + def __item_listval_optkeys(id) ['bindtags'] end private :__item_listval_optkeys @@ -266,8 +266,9 @@ module Tk::BLT @cpath = @chart.path Axis::OBJ_TBL[@cpath][@axis] = self keys = _symbolkey2str(keys) - unless keys.delete['without_creating'] - @chart.axis_create(@axis, keys) + unless keys.delete('without_creating') + # @chart.axis_create(@axis, keys) + tk_call(@chart, 'axis', 'create', @axis, keys) end end @@ -420,8 +421,9 @@ module Tk::BLT @cpath = @chart.path Element::OBJ_TBL[@cpath][@element] = self keys = _symbolkey2str(keys) - unless keys.delete['without_creating'] - @chart.element_create(@element, keys) + unless keys.delete('without_creating') + # @chart.element_create(@element, keys) + tk_call(@chart, 'element', 'create', @element, keys) end end @@ -623,8 +625,9 @@ module Tk::BLT @cpath = @chart.path Pen::OBJ_TBL[@cpath][@pen] = self keys = _symbolkey2str(keys) - unless keys.delete['without_creating'] - @chart.pen_create(@pen, keys) + unless keys.delete('without_creating') + # @chart.pen_create(@pen, keys) + tk_call(@chart, 'pen', 'create', @pen, keys) end end @@ -784,6 +787,24 @@ module Tk::BLT idnum.to_i # 'item id' is an integer number end + def self.create_type(chart, type, keys={}) + args, fontkeys = _parse_create_args(keys) + idnum = tk_call_without_enc(chart.path, 'create', type, *args) + chart.marker_configure(idnum, fontkeys) unless fontkeys.empty? + id = idnum.to_i # 'item id' is an integer number + obj = self.allocate + obj.instance_eval{ + @parent = @chart = chart + @path = chart.path + @id = id + unless Tk::BLT::PlotComponent::MarkerID_TBL[@path] + Tk::BLT::PlotComponent::MarkerID_TBL[@path] = {} + end + Tk::BLT::PlotComponent::MarkerID_TBL[@path][@id] = self + } + obj + end + def initialize(parent, *args) @parent = @chart = parent @path = parent.path @@ -980,12 +1001,10 @@ module Tk::BLT ################### - def marker_create(type, *args) - type.create(self, *args) + def axis_create(id=nil, keys={}) + # tk_send('axis', 'create', tagid(id), keys) + Tk::BLT::PlotComponent::Axis.new(self, id, keys) end - - ################### - def axis_delete(*ids) tk_send('axis', 'delete', *(ids.collect{|id| tagid(id)})) self @@ -1033,6 +1052,10 @@ module Tk::BLT ################### + def element_create(id=nil, keys={}) + # tk_send('element', 'create', tagid(id), keys) + Tk::BLT::PlotComponent::Element.new(self, id, keys) + end def element_activate(id, *indices) tk_send('element', 'activate', tagid(id), *indices) self @@ -1109,6 +1132,10 @@ module Tk::BLT ################### + def pen_create(id=nil, keys={}) + # tk_send('pen', 'create', tagid(id), keys) + Tk::BLT::PlotComponent::Pen.new(self, id, keys) + end def pen_delete(*ids) tk_send('pen', 'delete', *(ids.collect{|id| tagid(id)})) self @@ -1137,6 +1164,28 @@ module Tk::BLT ################### + def marker_create(type, keys={}) + case type + when :text, 'text' + Tk::BLT::PlotComponent::TextMarker.new(self, keys) + when :line, 'line' + Tk::BLT::PlotComponent::LineMarker.new(self, keys) + when :bitmap, 'bitmap' + Tk::BLT::PlotComponent::BitmapMarker.new(self, keys) + when :image, 'image' + Tk::BLT::PlotComponent::ImageMarker.new(self, keys) + when :polygon, 'polygon' + Tk::BLT::PlotComponent::PolygonMarker.new(self, keys) + when :window, 'window' + Tk::BLT::PlotComponent::WindowMarker.new(self, keys) + else + if type.kind_of?(Tk::BLT::PlotComponent::Marker) + type.new(self, keys) + else + Tk::BLT::PlotComponent::Marker.create_type(self, type, keys) + end + end + end def marker_after(id, target=nil) if target tk_send_without_enc('marker', 'after', tagid(id), tagid(target)) @@ -1183,103 +1232,219 @@ module Tk::BLT ################### def xaxis_cget(option) - axis_cget('xaxis', option) + itemcget('xaxis', option) end def xaxis_configure(slot, value=None) - axis_configure('xaxis', slot, value) + itemconfigure('xaxis', slot, value) end def xaxis_configinfo(slot=nil) - axis_configinfo('xaxis', slot) + itemconfiginfo('xaxis', slot) end def current_xaxis_configinfo(slot=nil) - current_axis_configinfo('xaxis', slot) + current_itemconfiginfo('xaxis', slot) + end + def xaxis_bind(context, *args) + if TkComm._callback_entry?(args[0]) || !block_given? + cmd = args.shift + else + cmd = Proc.new + end + _bind([path, 'xaxis', 'bind'], context, cmd, *args) + self + end + def xaxis_bind_append(context, *args) + if TkComm._callback_entry?(args[0]) || !block_given? + cmd = args.shift + else + cmd = Proc.new + end + _bind_append([path, 'xaxis', 'bind'], context, cmd, *args) + self + end + def xaxis_bind_remove(context) + _bind_remove([path, 'xaxis', 'bind'], context) + self + end + def xaxis_bindinfo(context=nil) + _bindinfo([path, 'xaxis', 'bind'], context) end def xaxis_invtransform(val) - axis_invtransform('xaxis', val) + list(tk_send('xaxis', 'invtransform', val)) end def xaxis_limits - axis_limits('xaxis') + list(tk_send('xaxis', 'limits')) end def xaxis_transform(val) - axis_transform('xaxis', val) + list(tk_send('xaxis', 'transform', val)) end def xaxis_use(target=nil) - axis_use('xaxis', target) + if target + Axis.id2obj(self, tk_send('xaxis', 'use', tagid(target))) + else + Axis.id2obj(self, tk_send('xaxis', 'use')) + end end def x2axis_cget(option) - axis_cget('x2axis', option) + itemcget('x2axis', option) end def x2axis_configure(slot, value=None) - axis_configure('x2axis', slot, value) + itemconfigure('x2axis', slot, value) end def x2axis_configinfo(slot=nil) - axis_configinfo('x2axis', slot) + itemconfiginfo('x2axis', slot) end def current_x2axis_configinfo(slot=nil) - current_axis_configinfo('x2axis', slot) + current_itemconfiginfo('x2axis', slot) + end + def x2axis_bind(context, *args) + if TkComm._callback_entry?(args[0]) || !block_given? + cmd = args.shift + else + cmd = Proc.new + end + _bind([path, 'x2axis', 'bind'], context, cmd, *args) + self + end + def x2axis_bind_append(context, *args) + if TkComm._callback_entry?(args[0]) || !block_given? + cmd = args.shift + else + cmd = Proc.new + end + _bind_append([path, 'x2axis', 'bind'], context, cmd, *args) + self + end + def x2axis_bind_remove(context) + _bind_remove([path, 'x2axis', 'bind'], context) + self + end + def x2axis_bindinfo(context=nil) + _bindinfo([path, 'x2axis', 'bind'], context) end def x2axis_invtransform(val) - axis_invtransform('x2axis', val) + list(tk_send('x2axis', 'invtransform', val)) end def x2axis_limits - axis_limits('x2axis') + list(tk_send('x2axis', 'limits')) end def x2axis_transform(val) - axis_transform('x2axis', val) + list(tk_send('x2axis', 'transform', val)) end def x2axis_use(target=nil) - axis_use('x2axis', target) + if target + Axis.id2obj(self, tk_send('x2axis', 'use', tagid(target))) + else + Axis.id2obj(self, tk_send('x2axis', 'use')) + end end def yaxis_cget(option) - axis_cget('yaxis', option) + itemcget('yaxis', option) end def yaxis_configure(slot, value=None) - axis_configure('yaxis', slot, value) + itemconfigure('yaxis', slot, value) end def yaxis_configinfo(slot=nil) - axis_configinfo('yaxis', slot) + itemconfiginfo('yaxis', slot) end def current_yaxis_configinfo(slot=nil) - current_axis_configinfo('yaxis', slot) + current_itemconfiginfo('yaxis', slot) + end + def yaxis_bind(context, *args) + if TkComm._callback_entry?(args[0]) || !block_given? + cmd = args.shift + else + cmd = Proc.new + end + _bind([path, 'yaxis', 'bind'], context, cmd, *args) + self + end + def yaxis_bind_append(context, *args) + if TkComm._callback_entry?(args[0]) || !block_given? + cmd = args.shift + else + cmd = Proc.new + end + _bind_append([path, 'yaxis', 'bind'], context, cmd, *args) + self + end + def yaxis_bind_remove(context) + _bind_remove([path, 'yaxis', 'bind'], context) + self + end + def yaxis_bindinfo(context=nil) + _bindinfo([path, 'yaxis', 'bind'], context) end def yaxis_invtransform(val) - axis_invtransform('yaxis', val) + list(tk_send('yaxis', 'invtransform', val)) end def yaxis_limits - axis_limits('yaxis') + list(tk_send('yaxis', 'limits')) end def yaxis_transform(val) - axis_transform('yaxis', val) + list(tk_send('yaxis', 'transform', val)) end def yaxis_use(target=nil) - axis_use('yaxis', target) + if target + Axis.id2obj(self, tk_send('yaxis', 'use', tagid(target))) + else + Axis.id2obj(self, tk_send('yaxis', 'use')) + end end def y2axis_cget(option) - axis_cget('y2axis', option) + itemcget('y2axis', option) end def y2axis_configure(slot, value=None) - axis_configure('y2axis', slot, value) + itemconfigure('y2axis', slot, value) end def y2axis_configinfo(slot=nil) axis_configinfo('y2axis', slot) end def current_y2axis_configinfo(slot=nil) - current_axis_configinfo('y2axis', slot) + current_itemconfiginfo('y2axis', slot) + end + def y2axis_bind(context, *args) + if TkComm._callback_entry?(args[0]) || !block_given? + cmd = args.shift + else + cmd = Proc.new + end + _bind([path, 'y2axis', 'bind'], context, cmd, *args) + self + end + def y2axis_bind_append(context, *args) + if TkComm._callback_entry?(args[0]) || !block_given? + cmd = args.shift + else + cmd = Proc.new + end + _bind_append([path, 'y2axis', 'bind'], context, cmd, *args) + self + end + def y2axis_bind_remove(context) + _bind_remove([path, 'y2axis', 'bind'], context) + self + end + def y2axis_bindinfo(context=nil) + _bindinfo([path, 'y2axis', 'bind'], context) end def y2axis_invtransform(val) - axis_invtransform('y2axis', val) + list(tk_send('y2axis', 'invtransform', val)) end def y2axis_limits - axis_limits('y2axis') + list(tk_send('y2axis', 'limits')) end def y2axis_transform(val) - axis_transform('y2axis', val) + list(tk_send('y2axis', 'transform', val)) end def y2axis_use(target=nil) - axis_use('y2axis', target) + if target + Axis.id2obj(self, tk_send('y2axis', 'use', tagid(target))) + else + Axis.id2obj(self, tk_send('y2axis', 'use')) + end end end end diff --git a/ext/tk/lib/tkextlib/blt/graph.rb b/ext/tk/lib/tkextlib/blt/graph.rb index 0c49a70ec4..b16c72458a 100644 --- a/ext/tk/lib/tkextlib/blt/graph.rb +++ b/ext/tk/lib/tkextlib/blt/graph.rb @@ -14,6 +14,7 @@ module Tk::BLT WidgetClassNames[WidgetClassName] = self include PlotComponent + include GraphCommand def __boolval_optkeys ['bufferelements', 'invertxy'] diff --git a/ext/tk/lib/tkextlib/blt/htext.rb b/ext/tk/lib/tkextlib/blt/htext.rb index 29da9aa87f..3bc35b7e10 100644 --- a/ext/tk/lib/tkextlib/blt/htext.rb +++ b/ext/tk/lib/tkextlib/blt/htext.rb @@ -9,6 +9,11 @@ require 'tkextlib/blt.rb' module Tk::BLT class Htext= 0) + # dummy :: # pkgIndex.tcl of TreeCtrl-1.0 doesn't support auto_load for # 'loupe' command (probably it is bug, I think). @@ -146,7 +151,7 @@ module Tk::TreeCtrl::ConfigMethod None when 'dragimage' - obj + None when 'element' obj @@ -155,7 +160,7 @@ module Tk::TreeCtrl::ConfigMethod obj when 'marquee' - obj + None when 'notify' obj @@ -171,6 +176,10 @@ module Tk::TreeCtrl::ConfigMethod def tagid(mixed_id) if mixed_id == 'debug' ['debug', None] + elsif mixed_id == 'dragimage' + ['dragimage', None] + elsif mixed_id == 'marquee' + ['marquee', None] elsif mixed_id.kind_of?(Array) [mixed_id[0], treectrl_tagid(*mixed_id)] else @@ -237,6 +246,17 @@ module Tk::TreeCtrl::ConfigMethod end private :__item_configinfo_struct + + def __item_font_optkeys(id) + if id.kind_of?(Array) && (id[0] == 'element' || + (id[0].kind_of?(Array) && id[0][1] == 'element')) + [] + else + ['font'] + end + end + private :__item_font_optkeys + def __item_numstrval_optkeys(id) if id == 'debug' ['displaydelay'] @@ -249,14 +269,28 @@ module Tk::TreeCtrl::ConfigMethod def __item_boolval_optkeys(id) if id == 'debug' ['data', 'display', 'enable'] + elsif id == 'dragimage' + ['visible'] + elsif id == 'marquee' + ['visible'] elsif id.kind_of?(Array) case id[0] + when 'item' + ['button', 'visible'] when 'column' ['button', 'expand', 'squeeze', 'sunken', 'visible', 'widthhack'] when 'element' ['filled', 'showfocus'] + when 'notify' + ['active'] + when 'style' + ['detach'] else - super(id) + if id[0].kind_of?(Array) && id[0][1] == 'element' + ['filled', 'showfocus'] + else + super(id) + end end else super(id) @@ -280,8 +314,14 @@ module Tk::TreeCtrl::ConfigMethod ['itembackground'] when 'element' ['relief'] + when 'style' + ['union'] else - [] + if id[0].kind_of?(Array) && id[0][1] == 'element' + ['relief'] + else + [] + end end else [] @@ -328,17 +368,17 @@ module Tk::TreeCtrl::ConfigMethod current_itemconfiginfo('debug', slot) end - def dragimage_cget(tagOrId, option) - itemcget(['dragimage', tagOrId], option) + def dragimage_cget(option) + itemcget('dragimage', option) end - def dragimage_configure(tagOrId, slot, value=None) - itemconfigure(['dragimage', tagOrId], slot, value) + def dragimage_configure(slot, value=None) + itemconfigure('dragimage', slot, value) end - def dragimage_configinfo(tagOrId, slot=nil) - itemconfiginfo(['dragimage', tagOrId], slot) + def dragimage_configinfo(slot=nil) + itemconfiginfo('dragimage', slot) end - def current_dragimage_configinfo(tagOrId, slot=nil) - current_itemconfiginfo(['dragimage', tagOrId], slot) + def current_dragimage_configinfo(slot=nil) + current_itemconfiginfo('dragimage', slot) end def element_cget(tagOrId, option) @@ -380,17 +420,17 @@ module Tk::TreeCtrl::ConfigMethod current_itemconfiginfo([['item', 'element'], [item, column, elem]], slot) end - def marquee_cget(tagOrId, option) - itemcget(['marquee', tagOrId], option) + def marquee_cget(option) + itemcget('marquee', option) end - def marquee_configure(tagOrId, slot, value=None) - itemconfigure(['marquee', tagOrId], slot, value) + def marquee_configure(slot, value=None) + itemconfigure('marquee', slot, value) end - def marquee_configinfo(tagOrId, slot=nil) - itemconfiginfo(['marquee', tagOrId], slot) + def marquee_configinfo(slot=nil) + itemconfiginfo('marquee', slot) end - def current_marquee_configinfo(tagOrId, slot=nil) - current_itemconfiginfo(['marquee', tagOrId], slot) + def current_marquee_configinfo(slot=nil) + current_itemconfiginfo('marquee', slot) end def notify_cget(win, pattern, option) @@ -757,17 +797,20 @@ class Tk::TreeCtrl end alias item_first_child item_firstchild - def item_hashbutton(item, st=None) + def item_hasbutton(item, st=None) if st == None - bool(tk_send('item', 'hashbutton')) + bool(tk_send('item', 'hasbutton')) else - tk_send('item', 'hashbutton', st) + tk_send('item', 'hasbutton', st) self end end - def item_hashbutton?(item) - item_hashbutton(item) + alias item_has_button item_hasbutton + + def item_hasbutton?(item) + item_hasbutton(item) end + alias item_has_button? item_hasbutton? def item_index(item) list(tk_send('item', 'index', item)) @@ -811,8 +854,8 @@ class Tk::TreeCtrl end alias item_next_sibling item_nextsibling - def item_numchildren() - number(tk_send('item', 'numchildren')) + def item_numchildren(item) + number(tk_send('item', 'numchildren', item)) end alias item_num_children item_numchildren alias item_children_size item_numchildren @@ -850,10 +893,10 @@ class Tk::TreeCtrl opts = opts.collect{|param| if param.kind_of?(Hash) param = _symbolkey2str(param) - if param.key('column') + if param.key?('column') key = '-column' desc = param.delete('column') - elsif param.key('element') + elsif param.key?('element') key = '-element' desc = param.delete('element') else @@ -863,7 +906,7 @@ class Tk::TreeCtrl if param.empty? param = None else - param = __conv_item_keyonly_opts(item, param).to_a + param = hash_kv(__conv_item_keyonly_opts(item, param)) end if key @@ -874,7 +917,7 @@ class Tk::TreeCtrl elsif param.kind_of?(Array) if param[2].kind_of?(Hash) - param[2] = __conv_item_keyonly_opts(item, param[2]).to_a + param[2] = hash_kv(__conv_item_keyonly_opts(item, param[2])) end param @@ -898,17 +941,15 @@ class Tk::TreeCtrl end private :_item_sort_core - def item_sort_not_really(item, *opts) - _item_sort_core(false, item, *opts) - end - def item_sort(item, *opts) _item_sort_core(true, item, *opts) end + def item_sort_not_really(item, *opts) + _item_sort_core(false, item, *opts) + end def item_state_forcolumn(item, column, *args) tk_send('item', 'state', 'forcolumn', item, column, *args) - self end alias item_state_for_column item_state_forcolumn @@ -922,7 +963,6 @@ class Tk::TreeCtrl def item_state_set(item, *args) tk_send('item', 'state', 'set', item, *args) - self end def item_style_elements(item, column) @@ -1230,7 +1270,8 @@ class Tk::TreeCtrl def _conv_style_layout_val(sty, val) case sty.to_s when 'padx', 'pady', 'ipadx', 'ipady' - number(val) + lst = list(val) + (lst.size == 1)? lst[0]: lst when 'detach' bool(val) when 'union' @@ -1256,6 +1297,7 @@ class Tk::TreeCtrl else ret = Hash.new Hash[*simplelist(tk_send('style', 'layout', style, elem))].each{|k, v| + k = k[1..-1] ret[k] = _conv_style_layout_val(k, v) } ret @@ -1599,18 +1641,20 @@ class Tk::TreeCtrl::Item < TkObject end alias first_child firstchild - def hashbutton(st=None) + def hasbutton(st=None) if st == None - @tree.item_hashbutton(@id) + @tree.item_hasbutton(@id) else - @tree.item_hashbutton(@id, st) + @tree.item_hasbutton(@id, st) self end end + alias has_button hasbutton - def hashbutton? - @tree.item_hashbutton(@id) + def hasbutton? + @tree.item_hasbutton(@id) end + alias has_button? hasbutton? def index @tree.item_index(@id) @@ -1685,6 +1729,10 @@ class Tk::TreeCtrl::Item < TkObject def sort(*opts) @tree.item_sort(@id, *opts) end + def sort_not_really(*opts) + @tree.item_sort_not_really(@id, *opts) + self + end def state_forcolumn(column, *args) @tree.item_state_forcolumn(@id, column, *args) @@ -1829,3 +1877,149 @@ class Tk::TreeCtrl::Style < TkObject end end end + +module Tk::TreeCtrl::BindCallback + include Tk + extend Tk +end + +class << Tk::TreeCtrl::BindCallback + def cursorCheck(w, x, y) + tk_call('::TreeCtrl::CursorCheck', w, x, y) + end + def cursorCheckAux(w) + tk_call('::TreeCtrl::CursorCheckAux', w) + end + def cursorCancel(w) + tk_call('::TreeCtrl::CursorCancel', w) + end + def buttonPress1(w, x, y) + tk_call('::TreeCtrl::ButtonPress1', w, x, y) + end + def doubleButton1(w, x, y) + tk_call('::TreeCtrl::DoubleButton1', w, x, y) + end + def motion1(w, x, y) + tk_call('::TreeCtrl::Motion1', w, x, y) + end + def leave1(w, x, y) + tk_call('::TreeCtrl::Leave1', w, x, y) + end + def release1(w, x, y) + tk_call('::TreeCtrl::Release1', w, x, y) + end + def beginSelect(w, el) + tk_call('::TreeCtrl::BeginSelect', w, el) + end + def motion(w, le) + tk_call('::TreeCtrl::Motion', w, el) + end + def beginExtend(w, el) + tk_call('::TreeCtrl::BeginExtend', w, el) + end + def beginToggle(w, el) + tk_call('::TreeCtrl::BeginToggle', w, el) + end + def cancelRepeat + tk_call('::TreeCtrl::CancelRepeat') + end + def autoScanCheck(w, x, y) + tk_call('::TreeCtrl::AutoScanCheck', w, x, y) + end + def autoScanCheckAux(w) + tk_call('::TreeCtrl::AutoScanCheckAux', w) + end + def autoScanCancel(w) + tk_call('::TreeCtrl::AutoScanCancel', w) + end + def up_down(w, n) + tk_call('::TreeCtrl::UpDown', w, n) + end + def left_right(w, n) + tk_call('::TreeCtrl::LeftRight', w, n) + end + def setActiveItem(w, idx) + tk_call('::TreeCtrl::SetActiveItem', w, idx) + end + def extendUpDown(w, amount) + tk_call('::TreeCtrl::ExtendUpDown', w, amount) + end + def dataExtend(w, el) + tk_call('::TreeCtrl::DataExtend', w, el) + end + def cancel(w) + tk_call('::TreeCtrl::Cancel', w) + end + def selectAll(w) + tk_call('::TreeCtrl::selectAll', w) + end + def marqueeBegin(w, x, y) + tk_call('::TreeCtrl::MarqueeBegin', w, x, y) + end + def marqueeUpdate(w, x, y) + tk_call('::TreeCtrl::MarqueeUpdate', w, x, y) + end + def marqueeEnd(w, x, y) + tk_call('::TreeCtrl::MarqueeEnd', w, x, y) + end + def scanMark(w, x, y) + tk_call('::TreeCtrl::ScanMark', w, x, y) + end + def scanDrag(w, x, y) + tk_call('::TreeCtrl::ScanDrag', w, x, y) + end + + # filelist-bindings + def fileList_button1(w, x, y) + tk_call('::TreeCtrl::FileListButton1', w, x, y) + end + def fileList_motion1(w, x, y) + tk_call('::TreeCtrl::FileListMotion1', w, x, y) + end + def fileList_motion(w, x, y) + tk_call('::TreeCtrl::FileListMotion', w, x, y) + end + def fileList_leave1(w, x, y) + tk_call('::TreeCtrl::FileListLeave1', w, x, y) + end + def fileList_release1(w, x, y) + tk_call('::TreeCtrl::FileListRelease1', w, x, y) + end + def fileList_edit(w, i, s, e) + tk_call('::TreeCtrl::FileListEdit', w, i, s, e) + end + def fileList_editCancel(w) + tk_call('::TreeCtrl::FileListEditCancel', w) + end + def fileList_autoScanCheck(w, x, y) + tk_call('::TreeCtrl::FileListAutoScanCheck', w, x, y) + end + def fileList_autoScanCheckAux(w) + tk_call('::TreeCtrl::FileListAutoScanCheckAux', w) + end + + def entryOpen(w, item, col, elem) + tk_call('::::TreeCtrl::EntryOpen', w, item, col, elem) + end + def entryExpanderOpen(w, item, col, elem) + tk_call('::TreeCtrl::EntryExpanderOpen', w, item, col, elem) + end + def entryClose(w, accept) + tk_call('::TreeCtrl::EntryClose', w, accept) + end + def entryExpanderKeypress(w) + tk_call('::TreeCtrl::EntryExpanderKeypress', w) + end + def textOpen(w, item, col, elem, width=0, height=0) + tk_call('::TreeCtrl::TextOpen', w, item, col, elem, width, height) + end + def textExpanderOpen(w, item, col, elem, width) + tk_call('::TreeCtrl::TextOpen', w, item, col, elem, width) + end + def textClose(w, accept) + tk_call('::TreeCtrl::TextClose', w, accept) + end + def textExpanderKeypress(w) + tk_call('::TreeCtrl::TextExpanderKeypress', w) + end +end -- cgit v1.2.3