diff options
author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-07-06 09:42:12 +0000 |
---|---|---|
committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-07-06 09:42:12 +0000 |
commit | 903fff28e85f80f6e2ef750193464ab1b5370d7e (patch) | |
tree | ea1597d41d1de11febd12cc38b71838e0691bfcb /ext/tk/lib | |
parent | d34d3d9597476eb06a5b49f4ce9c358b0d006e3f (diff) | |
download | ruby-903fff28e85f80f6e2ef750193464ab1b5370d7e.tar.gz ruby-903fff28e85f80f6e2ef750193464ab1b5370d7e.tar.xz ruby-903fff28e85f80f6e2ef750193464ab1b5370d7e.zip |
* ext/tk/lib : improve framework of developping Tcl/Tk extension wrappers
* BWidget extension support on Ruby/Tk
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@6586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib')
116 files changed, 3235 insertions, 413 deletions
diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index 9cf2ac3e0..720f2060d 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -807,8 +807,39 @@ module TkComm } end end + + def _bind_core_for_event_class(klass, mode, what, context, cmd, args=nil) + id = install_bind_for_event_class(klass, cmd, args) if cmd + begin + tk_call_without_enc(*(what + ["<#{tk_event_sequence(context)}>", + mode + id])) + rescue + uninstall_cmd(id) if cmd + fail + end + end + + def _bind_for_event_class(klass, what, context, cmd, args=nil) + _bind_core_for_event_class(klass, '', what, context, cmd, args) + end + + def _bind_append_for_event_class(klass, what, context, cmd, args=nil) + _bind_core_for_event_class(klass, '+', what, context, cmd, args) + end + + def _bind_remove_for_event_class(klass, what, context) + _bind_remove(what, context) + end + + def _bindinfo_for_event_class(klass, what, context=nil) + _bindinfo(what, context) + end + private :tk_event_sequence private :_bind_core, :_bind, :_bind_append, :_bind_remove, :_bindinfo + private :_bind_core_for_event_class, :_bind_for_event_class, + :_bind_append_for_event_class, :_bind_remove_for_event_class, + :_bindinfo_for_event_class def bind(tagOrClass, context, cmd=Proc.new, args=nil) _bind(["bind", tagOrClass], context, cmd, args) @@ -1437,28 +1468,34 @@ module Tk def Tk.const_missing(sym) case(sym) when :TCL_LIBRARY + INTERP._invoke_without_enc('global', 'tcl_library') INTERP._invoke("set", "tcl_library").freeze when :TK_LIBRARY + INTERP._invoke_without_enc('global', 'tk_library') INTERP._invoke("set", "tk_library").freeze when :LIBRARY INTERP._invoke("info", "library").freeze #when :PKG_PATH, :PACKAGE_PATH, :TCL_PACKAGE_PATH + # INTERP._invoke_without_enc('global', 'tcl_pkgPath') # tk_split_simplelist(INTERP._invoke('set', 'tcl_pkgPath')) #when :LIB_PATH, :LIBRARY_PATH, :TCL_LIBRARY_PATH + # INTERP._invoke_without_enc('global', 'tcl_libPath') # tk_split_simplelist(INTERP._invoke('set', 'tcl_libPath')) when :PLATFORM, :TCL_PLATFORM if $SAFE >= 4 fail SecurityError, "can't get #{sym} when $SAFE >= 4" end + INTERP._invoke_without_enc('global', 'tcl_platform') Hash[*tk_split_simplelist(INTERP._invoke_without_enc('array', 'get', 'tcl_platform'))] when :ENV + INTERP._invoke_without_enc('global', 'env') Hash[*tk_split_simplelist(INTERP._invoke('array', 'get', 'env'))] #when :AUTO_PATH #<=== @@ -1468,6 +1505,7 @@ module Tk # tk_split_simplelist(INTERP._invoke('set', 'auto_oldpath')) when :AUTO_INDEX + INTERP._invoke_without_enc('global', 'auto_index') Hash[*tk_split_simplelist(INTERP._invoke('array', 'get', 'auto_index'))] when :PRIV, :PRIVATE, :TK_PRIV @@ -1477,6 +1515,7 @@ module Tk else var_nam = 'tkPriv' end + INTERP._invoke_without_enc('global', var_nam) Hash[*tk_split_simplelist(INTERP._invoke('array', 'get', var_nam))].each{|k,v| k.freeze @@ -2302,6 +2341,15 @@ module TkConfigMethod ################################ + def [](id) + cget(id) + end + + def []=(id, val) + configure(id, val) + val + end + def cget(slot) slot = slot.to_s @@ -3031,6 +3079,7 @@ class TkObject<TkKernel end end +=begin def [](id) cget(id) end @@ -3039,6 +3088,7 @@ class TkObject<TkKernel configure(id, val) val end +=end def event_generate(context, keys=nil) if keys diff --git a/ext/tk/lib/tk/button.rb b/ext/tk/lib/tk/button.rb index 15e87c300..407a47c40 100644 --- a/ext/tk/lib/tk/button.rb +++ b/ext/tk/lib/tk/button.rb @@ -8,14 +8,14 @@ class TkButton<TkLabel TkCommandNames = ['button'.freeze].freeze WidgetClassName = 'Button'.freeze WidgetClassNames[WidgetClassName] = self - def create_self(keys) - if keys and keys != None - tk_call_without_enc('button', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('button', @path) - end - end - private :create_self + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('button', @path, *hash_kv(keys, true)) + # else + # tk_call_without_enc('button', @path) + # end + #end + #private :create_self def invoke _fromUTF8(tk_send_without_enc('invoke')) diff --git a/ext/tk/lib/tk/canvas.rb b/ext/tk/lib/tk/canvas.rb index 17a05c0ce..0f3a4fc48 100644 --- a/ext/tk/lib/tk/canvas.rb +++ b/ext/tk/lib/tk/canvas.rb @@ -40,20 +40,21 @@ class TkCanvas<TkWindow TkcItem::CItemID_TBL.delete(@path) end - def create_self(keys) - if keys and keys != None - tk_call_without_enc('canvas', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('canvas', @path) - end - end - private :create_self + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('canvas', @path, *hash_kv(keys, true)) + # else + # tk_call_without_enc('canvas', @path) + # end + #end + #private :create_self def tagid(tag) if tag.kind_of?(TkcItem) || tag.kind_of?(TkcTag) tag.id else - tag + # tag + _get_eval_string(tag) end end private :tagid diff --git a/ext/tk/lib/tk/canvastag.rb b/ext/tk/lib/tk/canvastag.rb index 056bf74c0..1db7b7b76 100644 --- a/ext/tk/lib/tk/canvastag.rb +++ b/ext/tk/lib/tk/canvastag.rb @@ -316,7 +316,8 @@ end class TkcGroup<TkcTag Tk_cGroup_ID = ['tkcg'.freeze, '00000'.taint].freeze - def create_self(parent, *args) + #def create_self(parent, *args) + def initialize(parent, *args) unless parent.kind_of?(TkCanvas) fail ArguemntError, "expect TkCanvas for 1st argument" end @@ -329,7 +330,7 @@ class TkcGroup<TkcTag Tk_cGroup_ID[1].succ! add(*args) if args != [] end - private :create_self + #private :create_self def include(*tags) for i in tags diff --git a/ext/tk/lib/tk/checkbutton.rb b/ext/tk/lib/tk/checkbutton.rb index a1ee5e876..d76d99c0f 100644 --- a/ext/tk/lib/tk/checkbutton.rb +++ b/ext/tk/lib/tk/checkbutton.rb @@ -8,14 +8,14 @@ class TkCheckButton<TkRadioButton TkCommandNames = ['checkbutton'.freeze].freeze WidgetClassName = 'Checkbutton'.freeze WidgetClassNames[WidgetClassName] = self - def create_self(keys) - if keys and keys != None - tk_call_without_enc('checkbutton', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('checkbutton', @path) - end - end - private :create_self + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('checkbutton', @path, *hash_kv(keys, true)) + # else + # tk_call_without_enc('checkbutton', @path) + # end + #end + #private :create_self def toggle tk_send_without_enc('toggle') diff --git a/ext/tk/lib/tk/dialog.rb b/ext/tk/lib/tk/dialog.rb index 30521e126..d6355f21c 100644 --- a/ext/tk/lib/tk/dialog.rb +++ b/ext/tk/lib/tk/dialog.rb @@ -162,8 +162,11 @@ class TkDialog2 < TkWindow # @path+" "+@title+" {#{@message}} "+@bitmap+" "+ # String(default_button)+" "+@buttons.join(' ')+']}') Tk.ip_eval(@config) - @val = Tk.ip_eval('tk_dialog ' + @path + ' ' + @title + - ' {' + @message + '} ' + @bitmap + ' ' + + # @val = Tk.ip_eval('tk_dialog ' + @path + ' ' + @title + + # ' {' + @message + '} ' + @bitmap + ' ' + + # String(default_button) + ' ' + @buttons.join(' ')).to_i + @val = Tk.ip_eval(self.class::TkCommandNames[0] + ' ' + @path + ' ' + + @title + ' {' + @message + '} ' + @bitmap + ' ' + String(default_button) + ' ' + @buttons.join(' ')).to_i end diff --git a/ext/tk/lib/tk/entry.rb b/ext/tk/lib/tk/entry.rb index 2077c1e9e..f12573941 100644 --- a/ext/tk/lib/tk/entry.rb +++ b/ext/tk/lib/tk/entry.rb @@ -16,14 +16,13 @@ class TkEntry<TkLabel WidgetClassName = 'Entry'.freeze WidgetClassNames[WidgetClassName] = self - - def create_self(keys) - tk_call_without_enc('entry', @path) - if keys and keys != None - configure(keys) - end - end - private :create_self + #def create_self(keys) + # tk_call_without_enc('entry', @path) + # if keys and keys != None + # configure(keys) + # end + #end + #private :create_self def bbox(index) list(tk_send_without_enc('bbox', index)) diff --git a/ext/tk/lib/tk/event.rb b/ext/tk/lib/tk/event.rb index 4c6c0844b..19fd9dbf0 100644 --- a/ext/tk/lib/tk/event.rb +++ b/ext/tk/lib/tk/event.rb @@ -117,9 +117,21 @@ module TkEvent # that is generated by _get_subst_key() or _get_all_subst_keys(). # _setup_subst_table(KEY_TBL, PROC_TBL); + + + # If you need support extra arguments given by Tcl/Tk, + # please override _get_extra_args_tbl + # + #def self._get_extra_args_tbl + # # return an array of convert procs + # [] + #end + end def install_bind_for_event_class(klass, cmd, *args) + extra_args_tbl = klass._get_extra_args_tbl + if args.compact.size > 0 args = args.join(' ') keys = klass._get_subst_key(args) @@ -130,7 +142,9 @@ module TkEvent id = install_cmd(cmd) else id = install_cmd(proc{|*arg| - TkUtil.eval_cmd(cmd, *klass.scan_args(keys, arg)) + ex_args = [] + extra_args_tbl.reverse_each{|conv| ex_args << conv.call(arg.pop)} + TkUtil.eval_cmd(cmd, *(ex_args.concat(klass.scan_args(keys, arg)))) }) end id + ' ' + args @@ -143,7 +157,10 @@ module TkEvent id = install_cmd(cmd) else id = install_cmd(proc{|*arg| - TkUtil.eval_cmd(cmd, klass.new(*klass.scan_args(keys, arg))) + ex_args = [] + extra_args_tbl.reverse_each{|conv| ex_args << conv.call(arg.pop)} + TkUtil.eval_cmd(cmd, + *(ex_args << klass.new(*klass.scan_args(keys, arg)))) }) end id + ' ' + args @@ -151,7 +168,7 @@ module TkEvent end def install_bind(cmd, *args) - install_bind_for_event_class(Event, cmd, *args) + install_bind_for_event_class(TkEvent::Event, cmd, *args) end end diff --git a/ext/tk/lib/tk/font.rb b/ext/tk/lib/tk/font.rb index b4c5c7921..527584f1e 100644 --- a/ext/tk/lib/tk/font.rb +++ b/ext/tk/lib/tk/font.rb @@ -197,7 +197,7 @@ class TkFont def TkFont.init_widget_font(pathname, *args) win, tag, key = pathname.split(';') - key = 'font' unless key + key = 'font' if key == nil || key == '' path = [win, tag, key].join(';') case (Tk::TK_VERSION) @@ -868,7 +868,7 @@ class TkFont begin if w.include?(';') win, tag, optkey = w.split(';') - optkey = 'font' unless optkey + optkey = 'font' if optkey == nil || optkey == '' winobj = tk_tcl2ruby(win) # winobj.tagfont_configure(tag, {'font'=>@latinfont}) if winobj.kind_of? TkText diff --git a/ext/tk/lib/tk/frame.rb b/ext/tk/lib/tk/frame.rb index 6598ceb55..4f01825da 100644 --- a/ext/tk/lib/tk/frame.rb +++ b/ext/tk/lib/tk/frame.rb @@ -32,7 +32,7 @@ class TkFrame<TkWindow def initialize(parent=nil, keys=nil) my_class_name = nil - if self.class < WidgetClassNames[WidgetClassName] + if self.class < WidgetClassNames[self.class::WidgetClassName] my_class_name = self.class.name my_class_name = nil if my_class_name == '' end @@ -68,14 +68,14 @@ class TkFrame<TkWindow super(keys) end - def create_self(keys) - if keys and keys != None - tk_call_without_enc('frame', @path, *hash_kv(keys)) - else - tk_call_without_enc( 'frame', @path) - end - end - private :create_self + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('frame', @path, *hash_kv(keys)) + # else + # tk_call_without_enc( 'frame', @path) + # end + #end + #private :create_self def database_classname @classname diff --git a/ext/tk/lib/tk/itemconfig.rb b/ext/tk/lib/tk/itemconfig.rb index b1cc77674..271450041 100644 --- a/ext/tk/lib/tk/itemconfig.rb +++ b/ext/tk/lib/tk/itemconfig.rb @@ -105,6 +105,13 @@ module TkItemConfigMethod ################################################ + def tagid(tagOrId) + # maybe need to override + tagOrId + end + + ################################################ + def itemcget(tagOrId, option) option = option.to_s diff --git a/ext/tk/lib/tk/itemfont.rb b/ext/tk/lib/tk/itemfont.rb index f653755b0..f194595d5 100644 --- a/ext/tk/lib/tk/itemfont.rb +++ b/ext/tk/lib/tk/itemfont.rb @@ -28,7 +28,7 @@ module TkTreatItemFont fail ArgumentError, "unknown font option name `#{key}'" end - win, tag = __item_pathname(tagid(tagOrId)).split(':') + win, tag = __item_pathname(tagid(tagOrId)).split(';') if key pathname = [win, tag, key].join(';') @@ -130,7 +130,7 @@ module TkTreatItemFont fail ArgumentError, "unknown font option name `#{key}'" end - win, tag = __item_pathname(tagid(tagOrId)).split(':') + win, tag = __item_pathname(tagid(tagOrId)).split(';') optkeys = [key] if key @@ -181,7 +181,7 @@ module TkTreatItemFont fail ArgumentError, "unknown font option name `#{key}'" end - win, tag = __item_pathname(tagid(tagOrId)).split(':') + win, tag = __item_pathname(tagid(tagOrId)).split(';') optkeys = [key] if key diff --git a/ext/tk/lib/tk/label.rb b/ext/tk/lib/tk/label.rb index fe2640958..ea669d576 100644 --- a/ext/tk/lib/tk/label.rb +++ b/ext/tk/lib/tk/label.rb @@ -7,14 +7,14 @@ class TkLabel<TkWindow TkCommandNames = ['label'.freeze].freeze WidgetClassName = 'Label'.freeze WidgetClassNames[WidgetClassName] = self - def create_self(keys) - if keys and keys != None - tk_call_without_enc('label', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('label', @path) - end - end - private :create_self + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('label', @path, *hash_kv(keys, true)) + # else + # tk_call_without_enc('label', @path) + # end + #end + #private :create_self def textvariable(v) configure 'textvariable', tk_trace_variable(v) diff --git a/ext/tk/lib/tk/labelframe.rb b/ext/tk/lib/tk/labelframe.rb index fa658848c..fd16d3419 100644 --- a/ext/tk/lib/tk/labelframe.rb +++ b/ext/tk/lib/tk/labelframe.rb @@ -8,13 +8,13 @@ class TkLabelFrame<TkFrame TkCommandNames = ['labelframe'.freeze].freeze WidgetClassName = 'Labelframe'.freeze WidgetClassNames[WidgetClassName] = self - def create_self(keys) - if keys and keys != None - tk_call_without_enc('labelframe', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('labelframe', @path) - end - end - private :create_self + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('labelframe', @path, *hash_kv(keys, true)) + # else + # tk_call_without_enc('labelframe', @path) + # end + #end + #private :create_self end TkLabelframe = TkLabelFrame diff --git a/ext/tk/lib/tk/listbox.rb b/ext/tk/lib/tk/listbox.rb index 799d573b1..70df0ad68 100644 --- a/ext/tk/lib/tk/listbox.rb +++ b/ext/tk/lib/tk/listbox.rb @@ -23,17 +23,18 @@ class TkListbox<TkTextWin WidgetClassName = 'Listbox'.freeze WidgetClassNames[WidgetClassName] = self - def create_self(keys) - if keys and keys != None - tk_call_without_enc('listbox', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('listbox', @path) - end - end - private :create_self + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('listbox', @path, *hash_kv(keys, true)) + # else + # tk_call_without_enc('listbox', @path) + # end + #end + #private :create_self def tagid(id) - id.to_s + #id.to_s + _get_eval_string(id) end def activate(y) diff --git a/ext/tk/lib/tk/menu.rb b/ext/tk/lib/tk/menu.rb index f5a16cf3c..fdb4ec201 100644 --- a/ext/tk/lib/tk/menu.rb +++ b/ext/tk/lib/tk/menu.rb @@ -38,17 +38,18 @@ class TkMenu<TkWindow WidgetClassName = 'Menu'.freeze WidgetClassNames[WidgetClassName] = self - def create_self(keys) - if keys and keys != None - tk_call_without_enc('menu', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('menu', @path) - end - end - private :create_self + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('menu', @path, *hash_kv(keys, true)) + # else + # tk_call_without_enc('menu', @path) + # end + #end + #private :create_self def tagid(id) - id.to_s + #id.to_s + _get_eval_string(id) end def activate(index) diff --git a/ext/tk/lib/tk/message.rb b/ext/tk/lib/tk/message.rb index b35980014..79121bebb 100644 --- a/ext/tk/lib/tk/message.rb +++ b/ext/tk/lib/tk/message.rb @@ -8,12 +8,12 @@ class TkMessage<TkLabel TkCommandNames = ['message'.freeze].freeze WidgetClassName = 'Message'.freeze WidgetClassNames[WidgetClassName] = self - def create_self(keys) - if keys and keys != None - tk_call_without_enc('message', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('message', @path) - end - end + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('message', @path, *hash_kv(keys, true)) + # else + # tk_call_without_enc('message', @path) + # end + #end private :create_self end diff --git a/ext/tk/lib/tk/optiondb.rb b/ext/tk/lib/tk/optiondb.rb index 46d17a202..db735d929 100644 --- a/ext/tk/lib/tk/optiondb.rb +++ b/ext/tk/lib/tk/optiondb.rb @@ -34,7 +34,8 @@ module TkOptionDB def readfile(file, pri=None) tk_call('option', 'readfile', file, pri) end - module_function :add, :clear, :get, :readfile + alias read_file readfile + module_function :add, :clear, :get, :readfile, :read_file def read_entries(file, f_enc=nil) if TkCore::INTERP.safe? diff --git a/ext/tk/lib/tk/panedwindow.rb b/ext/tk/lib/tk/panedwindow.rb index 1cfc7bad7..1e0430b60 100644 --- a/ext/tk/lib/tk/panedwindow.rb +++ b/ext/tk/lib/tk/panedwindow.rb @@ -7,14 +7,14 @@ class TkPanedWindow<TkWindow TkCommandNames = ['panedwindow'.freeze].freeze WidgetClassName = 'Panedwindow'.freeze WidgetClassNames[WidgetClassName] = self - def create_self(keys) - if keys and keys != None - tk_call_without_enc('panedwindow', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('panedwindow', @path) - end - end - private :create_self + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('panedwindow', @path, *hash_kv(keys, true)) + # else + # tk_call_without_enc('panedwindow', @path) + # end + #end + #private :create_self def add(*args) keys = args.pop diff --git a/ext/tk/lib/tk/radiobutton.rb b/ext/tk/lib/tk/radiobutton.rb index e00f0a03e..697c02128 100644 --- a/ext/tk/lib/tk/radiobutton.rb +++ b/ext/tk/lib/tk/radiobutton.rb @@ -8,14 +8,14 @@ class TkRadioButton<TkButton TkCommandNames = ['radiobutton'.freeze].freeze WidgetClassName = 'Radiobutton'.freeze WidgetClassNames[WidgetClassName] = self - def create_self(keys) - if keys and keys != None - tk_call_without_enc('radiobutton', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('radiobutton', @path) - end - end - private :create_self + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('radiobutton', @path, *hash_kv(keys, true)) + # else + # tk_call_without_enc('radiobutton', @path) + # end + #end + #private :create_self def deselect tk_send_without_enc('deselect') diff --git a/ext/tk/lib/tk/scale.rb b/ext/tk/lib/tk/scale.rb index 9398a6cd5..135a0cf62 100644 --- a/ext/tk/lib/tk/scale.rb +++ b/ext/tk/lib/tk/scale.rb @@ -10,13 +10,16 @@ class TkScale<TkWindow def create_self(keys) if keys and keys != None - if keys.key?('command') + if keys.key?('command') && ! keys['command'].kind_of?(String) cmd = keys.delete('command') keys['command'] = proc{|val| cmd.call(val.to_f)} end - tk_call_without_enc('scale', @path, *hash_kv(keys, true)) + #tk_call_without_enc('scale', @path, *hash_kv(keys, true)) + tk_call_without_enc(self.class::TkCommandNames[0], @path, + *hash_kv(keys, true)) else - tk_call_without_enc('scale', @path) + #tk_call_without_enc('scale', @path) + tk_call_without_enc(self.class::TkCommandNames[0], @path) end end private :create_self diff --git a/ext/tk/lib/tk/scrollable.rb b/ext/tk/lib/tk/scrollable.rb index c5f4fdb70..6e10ef51a 100644 --- a/ext/tk/lib/tk/scrollable.rb +++ b/ext/tk/lib/tk/scrollable.rb @@ -52,8 +52,8 @@ module Tk @xscrollbar.orient 'horizontal' self.xscrollcommand {|*arg| @xscrollbar.set(*arg)} @xscrollbar.command {|*arg| self.xview(*arg)} + Tk.update # avoid scrollbar trouble end - Tk.update # avoid scrollbar trouble @xscrollbar end def yscrollbar(bar=nil) @@ -62,8 +62,8 @@ module Tk @yscrollbar.orient 'vertical' self.yscrollcommand {|*arg| @yscrollbar.set(*arg)} @yscrollbar.command {|*arg| self.yview(*arg)} + Tk.update # avoid scrollbar trouble end - Tk.update # avoid scrollbar trouble @yscrollbar end end diff --git a/ext/tk/lib/tk/scrollbar.rb b/ext/tk/lib/tk/scrollbar.rb index 8d4d40322..98b024720 100644 --- a/ext/tk/lib/tk/scrollbar.rb +++ b/ext/tk/lib/tk/scrollbar.rb @@ -19,9 +19,12 @@ class TkScrollbar<TkWindow } if keys and keys != None - tk_call_without_enc('scrollbar', @path, *hash_kv(keys, true)) + #tk_call_without_enc('scrollbar', @path, *hash_kv(keys, true)) + tk_call_without_enc(self.class::TkCommandNames[0], @path, + *hash_kv(keys, true)) else - tk_call_without_enc('scrollbar', @path) + #tk_call_without_enc('scrollbar', @path) + tk_call_without_enc(self.class::TkCommandNames[0], @path) end end private :create_self diff --git a/ext/tk/lib/tk/spinbox.rb b/ext/tk/lib/tk/spinbox.rb index 1c58f9199..664df6175 100644 --- a/ext/tk/lib/tk/spinbox.rb +++ b/ext/tk/lib/tk/spinbox.rb @@ -11,13 +11,13 @@ class TkSpinbox<TkEntry WidgetClassName = 'Spinbox'.freeze WidgetClassNames[WidgetClassName] = self - def create_self(keys) - tk_call_without_enc('spinbox', @path) - if keys and keys != None - configure(keys) - end - end - private :create_self + #def create_self(keys) + # tk_call_without_enc('spinbox', @path) + # if keys and keys != None + # configure(keys) + # end + #end + #private :create_self def identify(x, y) tk_send_without_enc('identify', x, y) diff --git a/ext/tk/lib/tk/text.rb b/ext/tk/lib/tk/text.rb index 7593b5936..b992db5ff 100644 --- a/ext/tk/lib/tk/text.rb +++ b/ext/tk/lib/tk/text.rb @@ -88,11 +88,15 @@ class TkText<TkTextWin end def create_self(keys) - if keys and keys != None - tk_call_without_enc('text', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('text', @path) - end + #if keys and keys != None + # #tk_call_without_enc('text', @path, *hash_kv(keys, true)) + # tk_call_without_enc(self.class::TkCommandNames[0], @path, + # *hash_kv(keys, true)) + #else + # #tk_call_without_enc('text', @path) + # tk_call_without_enc(self.class::TkCommandNames[0], @path) + #end + super(keys) init_instance_variable end private :create_self @@ -131,7 +135,8 @@ class TkText<TkTextWin || tag.kind_of?(TkTextWindow) tag.id else - tag + # tag + _get_eval_string(tag) end end private :tagid diff --git a/ext/tk/lib/tk/toplevel.rb b/ext/tk/lib/tk/toplevel.rb index c95002dbe..198495224 100644 --- a/ext/tk/lib/tk/toplevel.rb +++ b/ext/tk/lib/tk/toplevel.rb @@ -158,14 +158,14 @@ class TkToplevel<TkWindow } end - def create_self(keys) - if keys and keys != None - tk_call_without_enc('toplevel', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('toplevel', @path) - end - end - private :create_self + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('toplevel', @path, *hash_kv(keys, true)) + # else + # tk_call_without_enc('toplevel', @path) + # end + #end + #private :create_self def specific_class @classname diff --git a/ext/tk/lib/tk/txtwin_abst.rb b/ext/tk/lib/tk/txtwin_abst.rb index 63da9da11..5520360ea 100644 --- a/ext/tk/lib/tk/txtwin_abst.rb +++ b/ext/tk/lib/tk/txtwin_abst.rb @@ -4,10 +4,11 @@ require 'tk' class TkTextWin<TkWindow - def create_self - fail RuntimeError, "TkTextWin is an abstract class" - end - private :create_self + TkCommnadNames = [].freeze + #def create_self + # fail RuntimeError, "TkTextWin is an abstract class" + #end + #private :create_self def bbox(index) list(tk_send_without_enc('bbox', index)) diff --git a/ext/tk/lib/tk/validation.rb b/ext/tk/lib/tk/validation.rb index 0524a4375..30111f20c 100644 --- a/ext/tk/lib/tk/validation.rb +++ b/ext/tk/lib/tk/validation.rb @@ -158,6 +158,15 @@ module TkValidation ] _setup_subst_table(KEY_TBL, PROC_TBL); + + def self.ret_val(val) + (val)? '1': '0' + end + + #def self._get_extra_args_tbl + # # return an array of convert procs + # [] + #end end ############################## @@ -168,6 +177,8 @@ module TkValidation end def _initialize_for_cb_class(klass, cmd = Proc.new, *args) + extra_args_tbl = klass._get_extra_args_tbl + if args.compact.size > 0 args = args.join(' ') keys = klass._get_subst_key(args) @@ -177,7 +188,11 @@ module TkValidation @id = install_cmd(cmd) else @id = install_cmd(proc{|*arg| - (cmd.call(*klass.scan_args(keys, arg)))? '1':'0' + ex_args = [] + extra_args_tbl.reverse_each{|conv| ex_args << conv.call(args.pop)} + klass.ret_val(cmd.call( + *(ex_args.concat(klass.scan_args(keys, arg))) + )) }) + ' ' + args end else @@ -188,9 +203,11 @@ module TkValidation @id = install_cmd(cmd) else @id = install_cmd(proc{|*arg| - (cmd.call( - klass.new(*klass.scan_args(keys,arg))) - )? '1': '0' + ex_args = [] + extra_args_tbl.reverse_each{|conv| ex_args << conv.call(args.pop)} + klass.ret_val(cmd.call( + *(ex_args << klass.new(*klass.scan_args(keys,arg))) + )) }) + ' ' + args end end diff --git a/ext/tk/lib/tk/variable.rb b/ext/tk/lib/tk/variable.rb index 61d6e8a41..bfa19fc18 100644 --- a/ext/tk/lib/tk/variable.rb +++ b/ext/tk/lib/tk/variable.rb @@ -197,8 +197,13 @@ TkCore::INTERP.add_tk_procs('rb_var', 'args', <<-'EOL') @id end + def ref(*idxs) + "#{@id}(#{idxs.collect{|idx| _get_eval_string(idx)}.join(',')})" + end + def is_hash? #ITNERP._eval("global #{@id}; array exist #{@id}") == '1' + INTERP._invoke_without_enc('global', @id) INTERP._invoke_without_enc('array', 'exist', @id) == '1' end @@ -211,6 +216,7 @@ TkCore::INTERP.add_tk_procs('rb_var', 'args', <<-'EOL') fail RuntimeError, 'cannot get keys from a scalar variable' end #tk_split_simplelist(INTERP._eval("global #{@id}; array get #{@id}")) + INTERP._invoke_without_enc('global', @id) tk_split_simplelist(INTERP._fromUTF8(INTERP._invoke_without_enc('array', 'names', @id))) end @@ -242,6 +248,7 @@ if USE_TCLs_SET_VARIABLE_FUNCTIONS def value #if INTERP._eval("global #{@id}; array exist #{@id}") == '1' + INTERP._invoke_without_enc('global', @id) if INTERP._invoke('array', 'exist', @id) == '1' #Hash[*tk_split_simplelist(INTERP._eval("global #{@id}; array get #{@id}"))] Hash[*tk_split_simplelist(INTERP._invoke('array', 'get', @id))] @@ -277,16 +284,21 @@ if USE_TCLs_SET_VARIABLE_FUNCTIONS end end - def [](index) + def [](*idxs) + index = idxs.collect{|idx| _get_eval_string(idx, true)}.join(',') + _fromUTF8(INTERP._get_global_var2(@id, index)) #_fromUTF8(INTERP._get_global_var2(@id, _toUTF8(_get_eval_string(index)))) - _fromUTF8(INTERP._get_global_var2(@id, _get_eval_string(index, true))) + #_fromUTF8(INTERP._get_global_var2(@id, _get_eval_string(index, true))) end - def []=(index,val) + def []=(*args) + val = args.pop + 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)), # _toUTF8(_get_eval_string(val)))) - _fromUTF8(INTERP._set_global_var2(@id, _get_eval_string(index, true), - _get_eval_string(val, true))) + #_fromUTF8(INTERP._set_global_var2(@id, _get_eval_string(index, true), + # _get_eval_string(val, true))) end def unset(elem=nil) @@ -371,16 +383,22 @@ else end end - def [](index) - INTERP._eval(Kernel.format('global %s; set %s(%s)', - @id, @id, _get_eval_string(index))) + def [](*idxs) + index = idxs.collect{|idx| _get_eval_string(idx)}.join(',') + INTERP._eval(Kernel.format('global %s; set %s(%s)', @id, @id, index)) + #INTERP._eval(Kernel.format('global %s; set %s(%s)', + # @id, @id, _get_eval_string(index))) #INTERP._eval(Kernel.format('set %s(%s)', @id, _get_eval_string(index))) #INTERP._eval('set ' + @id + '(' + _get_eval_string(index) + ')') end - def []=(index,val) + def []=(*args) + val = args.pop + index = args.collect{|idx| _get_eval_string(idx)}.join(',') INTERP._eval(Kernel.format('global %s; set %s(%s) %s', @id, @id, - _get_eval_string(index), _get_eval_string(val))) + index, _get_eval_string(val))) + #INTERP._eval(Kernel.format('global %s; set %s(%s) %s', @id, @id, + # _get_eval_string(index), _get_eval_string(val))) #INTERP._eval(Kernel.format('set %s(%s) %s', @id, # _get_eval_string(index), _get_eval_string(val))) #INTERP._eval('set ' + @id + '(' + _get_eval_string(index) + ') ' + @@ -869,6 +887,7 @@ class TkVarAccess<TkVariable def self.new_hash(name, *args) return TkVar_ID_TBL[name] if TkVar_ID_TBL[name] + INTERP._invoke_without_enc('global', name) if args.empty? && INTERP._invoke_without_enc('array', 'exist', name) == '0' self.new(name, {}) # force creating else diff --git a/ext/tk/lib/tk/wm.rb b/ext/tk/lib/tk/wm.rb index 246765683..b5106adad 100644 --- a/ext/tk/lib/tk/wm.rb +++ b/ext/tk/lib/tk/wm.rb @@ -178,10 +178,13 @@ module Tk self end end - def protocol(name=nil, cmd=nil) + def protocol(name=nil, cmd=nil, &b) if cmd tk_call_without_enc('wm', 'protocol', path, name, cmd) self + elsif b + tk_call_without_enc('wm', 'protocol', path, name, proc(&b)) + self elsif name result = tk_call_without_enc('wm', 'protocol', path, name) (result == "")? nil : tk_tcl2ruby(result) diff --git a/ext/tk/lib/tkextlib/ICONS.rb b/ext/tk/lib/tkextlib/ICONS.rb index 84f4204c6..18d84c05e 100644 --- a/ext/tk/lib/tkextlib/ICONS.rb +++ b/ext/tk/lib/tkextlib/ICONS.rb @@ -6,11 +6,8 @@ # call setup script for general 'tkextlib' libraries require 'tkextlib/setup.rb' -# library directory -dir = File.expand_path(__FILE__).sub(/#{File.extname(__FILE__)}$/, '') - # call setup script -require File.join(dir, 'setup.rb') +require 'tkextlib/ICONS/setup.rb' # load library -require File.join(dir, 'icons') +require 'tkextlib/ICONS/icons' diff --git a/ext/tk/lib/tkextlib/ICONS/icons.rb b/ext/tk/lib/tkextlib/ICONS/icons.rb index fe8351fa5..275903f30 100644 --- a/ext/tk/lib/tkextlib/ICONS/icons.rb +++ b/ext/tk/lib/tkextlib/ICONS/icons.rb @@ -9,39 +9,63 @@ require 'tk' require 'tkextlib/setup.rb' # call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/ICONS/setup.rb' # TkPackage.require('icons', '1.0') TkPackage.require('icons') module Tk class ICONS < TkImage - def self.create(*args) # icon, icon, ..., keys + extend Tk + + def self.package_version + begin + TkPackage.require('icons') + rescue + '' + end + end + + def self.create(*args) # icon, icon, ..., ?option=>value, ...? if args[-1].kind_of?(Hash) keys = args.pop icons = simplelist(tk_call('::icons::icons', 'create', - *(hash_kv(keys).concat(args.flatten)))) + *(hash_kv(keys) << (args.flatten)))) else icons = simplelist(tk_call('::icons::icons', 'create', - *(args.flatten))) + args.flatten)) end icons.collect{|icon| self.new(icon, :without_creating=>true)} end - def self.delete(*icons) + def self.delete(*icons) # icon, icon, ... + icons = icons.flatten return if icons.empty? + icons.map!{|icon| + if icon.kind_of?(Tk::ICONS) + Tk_IMGTBL.delete(icon.path) + icon.name + elsif icon.to_s =~ /^::icon::(.*)/ + name = $1 + Tk_IMGTBL.delete(icon) + name + else + Tk_IMGTBL.delete("::icon::#{icon}") + icon + end + } tk_call('::icons::icons', 'delete', icons) end - def self.query(*args) + def self.query(*args) # icon, icon, ..., ?option=>value, ...? if args[-1].kind_of?(Hash) keys = args.pop - list(tk_call('::icons::icons', 'query', - *(hash_kv(keys).concat(args.flatten)))) + simplelist(tk_call('::icons::icons', 'query', + *(hash_kv(keys) << (args.flatten)))) else - list(tk_call('::icons::icons', 'query', *(args.flatten))) - end + simplelist(tk_call('::icons::icons', 'query', args.flatten)) + end . map{|inf| list(inf) } end ########################################## @@ -75,7 +99,7 @@ module Tk self end - def query(keys) + def query(keys={}) list(simplelist(tk_call('::icons::icons', 'query', *(hash_kv(keys) << @name)) )[0]) diff --git a/ext/tk/lib/tkextlib/SUPPORT_STATUS b/ext/tk/lib/tkextlib/SUPPORT_STATUS index 6cc5e1561..58ac30785 100644 --- a/ext/tk/lib/tkextlib/SUPPORT_STATUS +++ b/ext/tk/lib/tkextlib/SUPPORT_STATUS @@ -47,33 +47,35 @@ script may give you some hints about that. ===< support with some examples (may be beta quality) >======================= Tcllib http://sf.net/projects/tcllib - ==> tcllib (partial support; Tklib part only) + ==> tcllib (partial support; Tklib part only) + +BWidgets http://sf.net/projects/tcllib ==> bwidget vu http://tktable.sourceforge.net ==> vu -TkHTML http://www.hwaci.com/sw/tkhtml/index.html ==> tkHTML +TkHTML http://www.hwaci.com/sw/tkhtml/index.html ==> tkHTML + +ICONS http://www.satisoft.com/tcltk/icons/ ==> ICONS ===< support (may be alpha or beta quality) >================================= -TkImg http://sf.net/projects/tkimg ==> tkimg +TkImg http://sf.net/projects/tkimg ==> tkimg -TkTreeCtrl http://tktreectrl.sourceforge.net/ ==> treectrl +TkTreeCtrl http://tktreectrl.sourceforge.net/ ==> treectrl -Tile http://tktable.sourceforge.net/tile/ ==> tile +Tile http://tktable.sourceforge.net/tile/ ==> tile -===< possibly support (not tested; alpha quality) >=========================== +===< possibly available (not tested; alpha quality) >========================= TkTrans http://www2.cmp.uea.ac.uk/~fuzz/tktrans/default.html ==> tktrans (win32 only) TkDND http://sourceforge.net/projects/tkdnd ==> tkDND -ICONS http://www.satisoft.com/tcltk/icons/ ==> ICONS - ===< plan to support (alpha quality libraries may be included) >============== @@ -87,8 +89,6 @@ IWidgets http://sf.net/projects/incrTcl TkTable http://sf.net/projects/tktable * see http://www.korus.hu/~fery/ruby/tktable.rb -BWidgets http://sf.net/projects/tcllib - winico http://tktable.sourceforge.net diff --git a/ext/tk/lib/tkextlib/bwidget.rb b/ext/tk/lib/tkextlib/bwidget.rb new file mode 100644 index 000000000..78d7d5230 --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget.rb @@ -0,0 +1,144 @@ +# +# BWidget extension support +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' + +# call setup script for general 'tkextlib' libraries +require 'tkextlib/setup.rb' + +# call setup script +require 'tkextlib/bwidget/setup.rb' + +# load all image format handlers +#TkPackage.require('BWidget', '1.7') +TkPackage.require('BWidget') + +module Tk + module BWidget + extend TkCore + + LIBRARY = tk_call('set', '::BWIDGET::LIBRARY') + + def self.package_version + begin + TkPackage.require('BWidget') + rescue + '' + end + end + + def self.XLFDfont(cmd, *args) + if args[-1].kind_of?(Hash) + keys = args.pop + args.concat(hash_kv(keys)) + end + tk_call('BWidget::XLFDfont', cmd, *args) + end + + def self.assert(exp, msg=None) + tk_call('BWidget::assert', exp, msg) + end + + def self.badOptionString(type, value, list) + tk_call('BWidget::badOptionString', type, value, list) + end + + def self.bindMouseWheel(widget) + tk_call('BWidget::bindMouseWheel', widget) + end + + def self.classes(klass) + list(tk_call('BWidget::classes', klass)) + end + + def self.clonename(menu) + tk_call('BWidget::clonename', menu) + end + + def self.focus(opt, path) + tk_call('BWidget::focus', opt, path) + end + + def self.get3dcolor(path, bgcolor) + tk_call('BWidget::get3dcolor', path, bgcolor) + end + + def self.getname(name) + tk_call('BWidget::getname', name) + end + + def self.grab(opt, path) + tk_call('BWidget::', opt, path) + end + + def self.inuse(klass) + bool(tk_call('BWidget::inuse', klass)) + end + + def self.library(klass, *klasses) + tk_call('BWidget::library', klass, *klasses) + end + + def self.lreorder(list, neworder) + tk_call('BWidget::lreorder', list, neworder) + end + + def self.parsetext(text) + tk_call('BWidget::parsetext', text) + end + + def self.place(path, w, h, *args) + if args[-1].kind_of?(Hash) + keys = args.pop + args.concat(hash_kv(keys)) + end + tk_call('BWidget::place', path, w, h, *(args.flatten)) + end + + def self.write(file, mode=None) + tk_call('BWidget::write', file, mode) + end + + def self.wrongNumArgsString(str) + tk_call('BWidget::wrongNumArgsString', str) + end + + #################################################### + + autoload :ArrowButton, 'tkextlib/bwidget/arrowbutton' + autoload :Bitmap, 'tkextlib/bwidget/bitmap' + autoload :Button, 'tkextlib/bwidget/button' + autoload :ButtonBox, 'tkextlib/bwidget/buttonbox' + autoload :ComboBox, 'tkextlib/bwidget/combobox' + autoload :Dialog, 'tkextlib/bwidget/dialog' + autoload :DragSite, 'tkextlib/bwidget/dragsite' + autoload :DropSite, 'tkextlib/bwidget/dropsite' + autoload :DynamicHelp, 'tkextlib/bwidget/dynamichelp' + autoload :Entry, 'tkextlib/bwidget/entry' + autoload :Label, 'tkextlib/bwidget/label' + autoload :LabelEntry, 'tkextlib/bwidget/labelentry' + autoload :LabelFrame, 'tkextlib/bwidget/labelframe' + autoload :ListBox, 'tkextlib/bwidget/listbox' + autoload :MainFrame, 'tkextlib/bwidget/mainframe' + autoload :MessageDlg, 'tkextlib/bwidget/messagedlg' + autoload :NoteBook, 'tkextlib/bwidget/notebook' + autoload :PagesManager, 'tkextlib/bwidget/pagesmanager' + autoload :PanedWindow, 'tkextlib/bwidget/panedwindow' + autoload :PasswdDlg, 'tkextlib/bwidget/passwddlg' + autoload :ProgressBar, 'tkextlib/bwidget/progressbar' + autoload :ProgressDlg, 'tkextlib/bwidget/progressdlg' + autoload :ScrollableFrame, 'tkextlib/bwidget/scrollableframe' + autoload :ScrolledWindow, 'tkextlib/bwidget/scrolledwindow' + autoload :ScrollView, 'tkextlib/bwidget/scrollview' + autoload :SelectColor, 'tkextlib/bwidget/selectcolor' + autoload :SelectFont, 'tkextlib/bwidget/selectfont' + autoload :Separator, 'tkextlib/bwidget/separator' + autoload :SpinBox, 'tkextlib/bwidget/spinbox' + autoload :TitleFrame, 'tkextlib/bwidget/titleframe' + autoload :Tree, 'tkextlib/bwidget/tree' + autoload :Widget, 'tkextlib/bwidget/widget' + + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/arrowbutton.rb b/ext/tk/lib/tkextlib/bwidget/arrowbutton.rb new file mode 100644 index 000000000..770e5e9ef --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/arrowbutton.rb @@ -0,0 +1,21 @@ +# +# tkextlib/bwidget/arrowbutton.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/bwidget.rb' +require 'tkextlib/bwidget/button' + +module Tk + module BWidget + class ArrowButton < Tk::BWidget::Button + end + end +end + +class Tk::BWidget::ArrowButton + TkCommandNames = ['ArrowButton'.freeze].freeze + WidgetClassName = 'ArrowButton'.freeze + WidgetClassNames[WidgetClassName] = self +end diff --git a/ext/tk/lib/tkextlib/bwidget/bitmap.rb b/ext/tk/lib/tkextlib/bwidget/bitmap.rb new file mode 100644 index 000000000..6cfde203e --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/bitmap.rb @@ -0,0 +1,21 @@ +# +# tkextlib/bwidget/bitmap.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# +require 'tk' +require 'tk/image' +require 'tkextlib/bwidget.rb' + +module Tk + module BWidget + class Bitmap < TkPhotoImage + end + end +end + +class Tk::BWidget::Bitmap + def initialize(name) + @path = tk_call_without_enc('Bitmap::get', name) + Tk_IMGTBL[@path] = self + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/button.rb b/ext/tk/lib/tkextlib/bwidget/button.rb new file mode 100644 index 000000000..246afebe2 --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/button.rb @@ -0,0 +1,21 @@ +# +# tkextlib/bwidget/button.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tk/button' +require 'tkextlib/bwidget.rb' + +module Tk + module BWidget + class Button < TkButton + end + end +end + +class Tk::BWidget::Button + TkCommandNames = ['Button'.freeze].freeze + WidgetClassName = 'Button'.freeze + WidgetClassNames[WidgetClassName] = self +end diff --git a/ext/tk/lib/tkextlib/bwidget/buttonbox.rb b/ext/tk/lib/tkextlib/bwidget/buttonbox.rb new file mode 100644 index 000000000..477de8a61 --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/buttonbox.rb @@ -0,0 +1,73 @@ +# +# tkextlib/bwidget/buttonbox.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/bwidget.rb' +require 'tkextlib/bwidget/button' + +module Tk + module BWidget + class ButtonBox < TkWindow + end + end +end + +class Tk::BWidget::ButtonBox + TkCommandNames = ['ButtonBox'.freeze].freeze + WidgetClassName = 'ButtonBox'.freeze + WidgetClassNames[WidgetClassName] = self + + include TkItemConfigMethod + + def tagid(tagOrId) + if tagOrId.kind_of?(Tk::BWidget::Button) + name = tagOrId[:name] + return index(name) unless name.empty? + end + if tagOrId.kind_of?(TkButton) + return index(tagOrId[:text]) + end + # index(tagOrId.to_s) + index(_get_eval_string(tagOrId)) + end + + def add(keys={}, &b) + win = window(tk_send('add', *hash_kv(keys))) + win.instance_eval(&b) if b + win + end + + def delete(idx) + tk_send('delete', tagid(idx)) + self + end + + def index(idx) + if idx.kind_of?(Tk::BWidget::Button) + name = idx[:name] + idx = name unless name.empty? + end + if idx.kind_of?(TkButton) + idx = idx[:text] + end + number(tk_send('index', idx.to_s)) + end + + def insert(idx, keys={}, &b) + win = window(tk_send('insert', tagid(idx), *hash_kv(keys))) + win.instance_eval(&b) if b + win + end + + def invoke(idx) + tk_send('invoke', tagid(idx)) + self + end + + def set_focus(idx) + tk_send('setfocus', tagid(idx)) + self + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/combobox.rb b/ext/tk/lib/tkextlib/bwidget/combobox.rb new file mode 100644 index 000000000..31f71c3aa --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/combobox.rb @@ -0,0 +1,45 @@ +# +# tkextlib/bwidget/combobox.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tk/entry' +require 'tkextlib/bwidget.rb' +require 'tkextlib/bwidget/listbox' +require 'tkextlib/bwidget/spinbox' + +module Tk + module BWidget + class ComboBox < Tk::BWidget::SpinBox + end + end +end + +class Tk::BWidget::ComboBox + include Scrollable + + TkCommandNames = ['ComboBox'.freeze].freeze + WidgetClassName = 'ComboBox'.freeze + WidgetClassNames[WidgetClassName] = self + + def get_listbox(&b) + win = window(tk_send_without_enc('getlistbox')) + win.instance_eval(&b) if b + win + end + + def icursor(idx) + tk_send_without_enc('icursor', idx) + end + + def post + tk_send_without_enc('post') + self + end + + def unpost + tk_send_without_enc('unpost') + self + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/dialog.rb b/ext/tk/lib/tkextlib/bwidget/dialog.rb new file mode 100644 index 000000000..4a60a7ceb --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/dialog.rb @@ -0,0 +1,147 @@ +# +# tkextlib/bwidget/dialog.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tk/frame' +require 'tkextlib/bwidget.rb' +require 'tkextlib/bwidget/buttonbox' + +module Tk + module BWidget + class Dialog < TkWindow + end + end +end + +class Tk::BWidget::Dialog + TkCommandNames = ['Dialog'.freeze].freeze + WidgetClassName = 'Dialog'.freeze + WidgetClassNames[WidgetClassName] = self + + include TkItemConfigMethod + + def initialize(parent=nil, keys=nil) + @relative = '' + if parent.kind_of?(Hash) + keys = _symbolkey2str(parent) + @relative = keys['parent'] if keys.key?('parent') + @relative = keys.delete('relative') if keys.key?('relative') + super(keys) + elsif keys + keys = _symbolkey2str(keys) + @relative = keys.delete('parent') if keys.key?('parent') + @relative = keys.delete('relative') if keys.key?('relative') + super(parent, keys) + else + super(parent) + end + end + + def create_self(keys) + cmd = self.class::TkCommandNames[0] + if keys and keys != None + tk_call_without_enc(cmd, @path, '-parent', @relative, + *hash_kv(keys, true)) + else + tk_call_without_enc(cmd, @path, '-parent', @relative) + end + end + + def cget(slot) + if slot.to_s == 'relative' + super('parent') + else + super(slot) + end + end + + def configure(slot, value=None) + if slot.kind_of?(Hash) + slot = _symbolkey2str(slot) + slot['parent'] = slot.delete('relative') if slot.key?('relative') + super(slot) + else + if slot.to_s == 'relative' + super('parent', value) + else + super(slot, value) + end + end + end + + def configinfo(slot=nil) + if slot + if slot.to_s == 'relative' + super('parent') + else + super(slot) + end + else + ret = super() + if TkComm::GET_CONFIGINFO_AS_ARRAY + ret << ['relative', 'parent'] + else + ret['relative'] = 'parent' + end + end + end + + def tagid(tagOrId) + if tagOrId.kind_of?(Tk::BWidget::Button) + name = tagOrId[:name] + return index(name) unless name.empty? + end + if tagOrId.kind_of?(TkButton) + return index(tagOrId[:text]) + end + # index(tagOrId.to_s) + index(_get_eval_string(tagOrId)) + end + + def add(keys={}, &b) + win = window(tk_send('add', *hash_kv(keys))) + win.instance_eval(&b) if b + win + end + + def get_frame(&b) + win = window(tk_send('getframe')) + win.instance_eval(&b) if b + win + end + + def get_buttonbox(&b) + win = window(@path + '.bbox') + win.instance_eval(&b) if b + win + end + + def draw(focus_win=None) + tk_send('draw', focus_win) + end + + def enddialog(ret) + tk_send('enddialog', ret) + end + + def index(idx) + get_buttonbox.index(idx) + end + + def invoke(idx) + tk_send('invoke', tagid(idx)) + self + end + + def set_focus(idx) + tk_send('setfocus', tagid(idx)) + self + end + + def withdraw + tk_send('withdraw') + self + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/dragsite.rb b/ext/tk/lib/tkextlib/bwidget/dragsite.rb new file mode 100644 index 000000000..4d4de1780 --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/dragsite.rb @@ -0,0 +1,31 @@ +# +# tkextlib/bwidget/dragsite.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/bwidget.rb' + +module Tk + module BWidget + module DragSite + end + end +end + +module Tk::BWidget::DragSite + include Tk + extend Tk + + def self.include(klass, type, event) + tk_call('DragSite::include', klass, type, event) + end + + def self.register(path, keys={}) + tk_call('DragSite::register', path, *hash_kv(keys)) + end + + def self.set_drag(path, subpath, initcmd, endcmd, force=None) + tk_call('DragSite::setdrag', path, subpath, initcmd, endcmd, force) + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/dropsite.rb b/ext/tk/lib/tkextlib/bwidget/dropsite.rb new file mode 100644 index 000000000..e5e98fbc5 --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/dropsite.rb @@ -0,0 +1,39 @@ +# +# tkextlib/bwidget/dropsite.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/bwidget.rb' + +module Tk + module BWidget + module DropSite + end + end +end + +module Tk::BWidget::DropSite + include Tk + extend Tk + + def self.include(klass, type) + tk_call('DropSite::include', klass, type) + end + + def self.register(path, keys={}) + tk_call('DropSite::register', path, *hash_kv(keys)) + end + + def self.set_cursor(cursor) + tk_call('DropSite::setcursor', cursor) + end + + def self.set_drop(path, subpath, dropover, drop, force=None) + tk_call('DropSite::setdrop', path, subpath, dropover, drop, force) + end + + def self.set_operation(op) + tk_call('DropSite::setoperation', op) + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/dynamichelp.rb b/ext/tk/lib/tkextlib/bwidget/dynamichelp.rb new file mode 100644 index 000000000..4766a1ec6 --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/dynamichelp.rb @@ -0,0 +1,51 @@ +# +# tkextlib/bwidget/dynamichelp.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/bwidget.rb' + +module Tk + module BWidget + module DynamicHelp + end + end +end + +module Tk::BWidget::DynamicHelp + include Tk + extend Tk + + def self.__pathname + 'DynamicHelp::configure' + end + + def self.__cget_cmd + ['DynamicHelp::configure'] + end + + def self.__config_cmd + ['DynamicHelp::configure'] + end + + def self.cget(slot) + self.current_configinfo(slot).values[0] + end + + def self.add(widget, keys={}) + tk_call('DynamicHelp::add', widget, *hash_kv(keys)) + end + + def self.delete(widget) + tk_call('DynamicHelp::delete', widget) + end + + def self.include(klass, type) + tk_call('DynamicHelp::include', klass, type) + end + + def self.sethelp(path, subpath, force=None) + tk_call('DynamicHelp::sethelp', path, subpath, force) + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/entry.rb b/ext/tk/lib/tkextlib/bwidget/entry.rb new file mode 100644 index 000000000..9867a1ac3 --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/entry.rb @@ -0,0 +1,28 @@ +# +# tkextlib/bwidget/entry.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tk/entry' +require 'tkextlib/bwidget.rb' + +module Tk + module BWidget + class Entry < TkEntry + end + end +end + +class Tk::BWidget::Entry + include Scrollable + + TkCommandNames = ['Entry'.freeze].freeze + WidgetClassName = 'Entry'.freeze + WidgetClassNames[WidgetClassName] = self + + def invoke + tk_send_without_enc('invoke') + self + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/label.rb b/ext/tk/lib/tkextlib/bwidget/label.rb new file mode 100644 index 000000000..1d4c63870 --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/label.rb @@ -0,0 +1,26 @@ +# +# tkextlib/bwidget/label.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tk/label' +require 'tkextlib/bwidget.rb' + +module Tk + module BWidget + class Label < TkLabel + end + end +end + +class Tk::BWidget::Label + TkCommandNames = ['Label'.freeze].freeze + WidgetClassName = 'Label'.freeze + WidgetClassNames[WidgetClassName] = self + + def set_focus + tk_send_without_enc('setfocus') + self + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/labelentry.rb b/ext/tk/lib/tkextlib/bwidget/labelentry.rb new file mode 100644 index 000000000..7a6a7f01d --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/labelentry.rb @@ -0,0 +1,45 @@ +# +# tkextlib/bwidget/labelentry.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tk/entry' +require 'tkextlib/bwidget.rb' +require 'tkextlib/bwidget/labelframe' +require 'tkextlib/bwidget/entry' + +module Tk + module BWidget + class LabelEntry < TkEntry + end + end +end + +class Tk::BWidget::LabelEntry + include Scrollable + + TkCommandNames = ['LabelEntry'.freeze].freeze + WidgetClassName = 'LabelEntry'.freeze + WidgetClassNames[WidgetClassName] = self + + def entrybind(*args) + _bind([path, 'bind'], *args) + self + end + + def entrybind_append(*args) + _bind_append([path, 'bind'], *args) + self + end + + def entrybind_remove(*args) + _bind_remove([path, 'bind'], *args) + self + end + + def entrybindinfo(*args) + _bindinfo([path, 'bind'], *args) + self + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/labelframe.rb b/ext/tk/lib/tkextlib/bwidget/labelframe.rb new file mode 100644 index 000000000..453756a16 --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/labelframe.rb @@ -0,0 +1,30 @@ +# +# tkextlib/bwidget/labelframe.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tk/frame' +require 'tkextlib/bwidget.rb' + +module Tk + module BWidget + class LabelFrame < TkWindow + end + end +end + +class Tk::BWidget::LabelFrame + TkCommandNames = ['LabelFrame'.freeze].freeze + WidgetClassName = 'LabelFrame'.freeze + WidgetClassNames[WidgetClassName] = self + + def self.align(*args) + tk_call('LabelFrame::align', *args) + end + def get_frame(&b) + win = window(tk_send_without_enc('getframe')) + win.instance_eval(&b) if b + win + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/listbox.rb b/ext/tk/lib/tkextlib/bwidget/listbox.rb new file mode 100644 index 000000000..28173fb7f --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/listbox.rb @@ -0,0 +1,290 @@ +# +# tkextlib/bwidget/listbox.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tk/canvas' +require 'tkextlib/bwidget.rb' + +module Tk + module BWidget + class ListBox < TkWindow + # is NOT a subclass of a listbox widget class. + # because it constructed on a canvas widget. + + class Item < TkObject + end + end + end +end + +class Tk::BWidget::ListBox + include TkItemConfigMethod + include Scrollable + + TkCommandNames = ['ListBox'.freeze].freeze + WidgetClassName = 'ListBox'.freeze + WidgetClassNames[WidgetClassName] = self + + class Event_for_Items < TkEvent::Event + def self._get_extra_args_tbl + [ + TkComm.method(:string) # item idenfier + ] + end + end + + def tagid(tag) + if tag.kind_of?(Tk::BWidget::ListBox::Item) + tag.id + else + # tag + _get_eval_string(tag) + end + end + + def imagebind(*args) + _bind_for_event_class(Event_for_Items, [path, 'bindImage'], *args) + self + end + + def imagebind_append(*args) + _bind_append_for_event_class(Event_for_Items, [path, 'bindImage'], *args) + self + end + + def imagebind_remove(*args) + _bind_remove_for_event_class(Event_for_Items, [path, 'bindImage'], *args) + self + end + + def imagebindinfo(*args) + _bindinfo_for_event_class(Event_for_Items, [path, 'bindImage'], *args) + end + + def textbind(*args) + _bind_for_event_class(Event_for_Items, [path, 'bindText'], *args) + self + end + + def textbind_append(*args) + _bind_append_for_event_class(Event_for_Items, [path, 'bindText'], *args) + self + end + + def textbind_remove(*args) + _bind_remove_for_event_class(Event_for_Items, [path, 'bindText'], *args) + self + end + + def textbindinfo(*args) + _bindinfo_for_event_class(Event_for_Items, [path, 'bindText'], *args) + end + + def delete(*args) + tk_send('delete', *args) + self + end + + def edit(item, text, *args) + tk_send('edit', tagid(item), text, *args) + self + end + + def exist?(item) + bool(tk_send('exists', tagid(item))) + end + + def index(item) + num_or_str(tk_send('index', tagid(item))) + end + + def insert(idx, item, keys={}) + tk_send('insert', idx, tagid(item), *hash_kv(keys)) + self + end + + def get_item(idx) + tk_send('items', idx) + end + + def items(first=None, last=None) + list(tk_send('items', first, last)) + end + + def move(item, idx) + tk_send('move', tagid(item), idx) + self + end + + def reorder(neworder) + tk_send('reorder', neworder) + self + end + + def see(item) + tk_send('see', tagid(item)) + self + end + + def selection_clear + tk_send_without_enc('selection', 'clear') + self + end + + def selection_set(*args) + tk_send_without_enc('selection', 'set', + *(args.collect{|item| tagid(item)})) + self + end + + def selection_add(*args) + tk_send_without_enc('selection', 'add', + *(args.collect{|item| tagid(item)})) + self + end + + def selection_remove(*args) + tk_send_without_enc('selection', 'remove', + *(args.collect{|item| tagid(item)})) + self + end + + def selection_get(*args) + simplelist(tk_send_without_enc('selection', 'get')).collect{|item| + Tk::BWidget::ListBox::Item.id2obj(self, item) + } + end +end + +class Tk::BWidget::ListBox::Item + include TkTreatTagFont + + ListItem_TBL = TkCore::INTERP.create_table + ListItem_ID = ['item:'.freeze, '00000'.taint].freeze + + TkCore::INTERP.init_ip_env{ ListItem_TBL.clear } + + def self.id2obj(lbox, id) + lpath = lbox.path + return id unless ListItem_TBL[lpath] + ListItem_TBL[lpath][id]? ListItem_TBL[lpath][id]: id + end + + def initialize(lbox, *args) + if lbox.kind_of?(Tk::BWidget::ListBox) + @listbox = lbox + else + fail RuntimeError, + "expect Tk::BWidget::ListBox or Tk::BWidget::ListBox::Item for 1st argument" + end + + if args[-1].kind_of?(Hash) + keys = _symbolkey2str(args.pop) + else + keys = {} + end + + index = keys.delete('index') + unless args.empty? + index = args.shift + end + index = 'end' unless index + + unless args.empty? + fail RuntimeError, 'too much arguments' + end + + @lpath = @listbox.path + + if keys.key?('itemname') + @path = @id = keys.delete('itemname') + else + @path = @id = ListItem_ID.join(TkCore::INTERP._ip_id_) + ListItem_ID[1].succ! + end + + ListItem_TBL[@id] = self + ListItem_TBL[@lpath] = {} unless ListItem_TBL[@lpath] + ListItem_TBL[@lpath][@id] = self + + @listbox.insert(index, @id, keys) + end + + def listbox + @listbox + end + + def id + @id + end + + def [](key) + cget(key) + end + + def []=(key, val) + configure(key, val) + val + end + + def cget(key) + @listbox.itemcget(@id, key) + end + + def configure(key, val=None) + @listbox.itemconfigure(@id, key, val) + end + + def configinfo(key=nil) + @listbox.itemconfiginfo(@id, key) + end + + def current_configinfo(key=nil) + @listbox.current_itemconfiginfo(@id, key) + end + + def delete + @listbox.delete(@id) + self + end + + def edit(*args) + @listbox.edit(@id, *args) + self + end + + def exist? + @listbox.exist?(@id) + end + + def index + @listbox.index(@id) + end + + def move(index) + @listbox.move(@id, index) + end + + def see + @listbox.see(@id) + end + + def selection_add + @listbox.selection_add(@id) + end + + def selection_remove + @listbox.selection_remove(@id) + end + + def selection_set + @listbox.selection_set(@id) + end + + def selection_toggle + @listbox.selection_toggle(@id) + end +end + diff --git a/ext/tk/lib/tkextlib/bwidget/mainframe.rb b/ext/tk/lib/tkextlib/bwidget/mainframe.rb new file mode 100644 index 000000000..e52f4b2f4 --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/mainframe.rb @@ -0,0 +1,73 @@ +# +# tkextlib/bwidget/mainframe.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tk/frame' +require 'tkextlib/bwidget.rb' +require 'tkextlib/bwidget/progressbar' + +module Tk + module BWidget + class MainFrame < TkWindow + end + end +end + +class Tk::BWidget::MainFrame + TkCommandNames = ['MainFrame'.freeze].freeze + WidgetClassName = 'MainFrame'.freeze + WidgetClassNames[WidgetClassName] = self + + def add_indicator(keys={}, &b) + win = window(tk_send('addindicator', *hash_kv(keys))) + win.instance_eval(&b) if b + win + end + + def add_toolbar(&b) + win = window(tk_send('addtoolbar')) + win.instance_eval(&b) if b + win + end + + def get_frame(&b) + win = window(tk_send('getframe')) + win.instance_eval(&b) if b + win + end + + def get_indicator(idx, &b) + win = window(tk_send('getindicator', idx)) + win.instance_eval(&b) if b + win + end + + def get_menu(menu_id, &b) + win = window(tk_send('getmenu', menu_id)) + win.instance_eval(&b) if b + win + end + + def get_toolbar(idx, &b) + win = window(tk_send('gettoolbar', idx)) + win.instance_eval(&b) if b + win + end + + def set_menustate(tag, state) + tk_send('setmenustate', tag, state) + self + end + + def show_statusbar(name) + tk_send('showstatusbar', name) + self + end + + def show_toolbar(idx, mode) + tk_send('showtoolbar', idx, mode) + self + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/messagedlg.rb b/ext/tk/lib/tkextlib/bwidget/messagedlg.rb new file mode 100644 index 000000000..55cc4ba0d --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/messagedlg.rb @@ -0,0 +1,167 @@ +# +# tkextlib/bwidget/messagedlg.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/bwidget.rb' + +module Tk + module BWidget + class MessageDlg < TkWindow + end + end +end + +class Tk::BWidget::MessageDlg + TkCommandNames = ['MessageDlg'.freeze].freeze + WidgetClassName = 'MessageDlg'.freeze + WidgetClassNames[WidgetClassName] = self + + def initialize(parent=nil, keys=nil) + @relative = '' + if parent.kind_of?(Hash) + keys = _symbolkey2str(parent) + @relative = keys['parent'] if keys.key?('parent') + @relative = keys.delete('relative') if keys.key?('relative') + super(keys) + elsif keys + keys = _symbolkey2str(keys) + @relative = keys.delete('parent') if keys.key?('parent') + @relative = keys.delete('relative') if keys.key?('relative') + super(parent, keys) + else + super(parent) + end + end + + def create_self(keys) + # NOT create widget. + # Because the widget no longer exist when returning from creation. + @keys = _symbolkey2str(keys).update('parent'=>@relative) + @info = nil + end + private :create_self + + def cget(slot) + slot = slot.to_s + if slot == 'relative' + slot = 'parent' + end + if winfo_exist? + val = super(slot) + @keys[slot] = val + end + @keys[slot] + end + + def configure(slot, value=None) + if winfo_exist? + super(slot, value) + end + if slot.kind_of?(Hash) + slot = _symbolkey2str(slot) + slot['parent'] = slot.delete('relative') if slot.key?('relative') + @keys.update(slot) + + if @info + # update @info + slot.each{|k, v| + if TkComm::GET_CONFIGINFO_AS_ARRAY + if (inf = @info.assoc(k)) + inf[-1] = v + else + @info << [k, '', '', '', v] + end + else + if (inf = @info[k]) + inf[-1] = v + else + @info[k] = ['', '', '', v] + end + end + } + end + + else # ! Hash + slot = slot.to_s + slot = 'parent' if slot == 'relative' + @keys[slot] = value + + if @info + # update @info + if TkComm::GET_CONFIGINFO_AS_ARRAY + if (inf = @info.assoc(slot)) + inf[-1] = value + else + @info << [slot, '', '', '', value] + end + else + if (inf = @info[slot]) + inf[-1] = value + else + @info[slot] = ['', '', '', value] + end + end + end + end + + self + end + + def configinfo(slot=nil) + if winfo_exist? + @info = super() + if TkComm::GET_CONFIGINFO_AS_ARRAY + @info << ['relative', 'parent'] + else + @info['relative'] = 'parent' + end + end + + if TkComm::GET_CONFIGINFO_AS_ARRAY + if @info + if winfo_exist? + # update @keys + @info.each{|inf| @keys[inf[0]] = inf[-1] if inf.size > 2 } + end + else + @info = [] + @keys.each{|k, v| + @info << [k, '', '', '', v] + } + @info << ['relative', 'parent'] + end + + if slot + @info.asoc(slot.to_s).dup + else + @info.dup + end + + else # ! TkComm::GET_CONFIGINFO_AS_ARRAY + if @info + if winfo_exist? + # update @keys + @info.each{|k, inf| @keys[k] = inf[-1] if inf.size > 2 } + end + else + @info = {} + @keys.each{|k, v| + @info[k] = ['', '', '', v] + } + @info['relative'] = 'parent' + end + + if slot + @info[slot.to_s].dup + else + @info.dup + end + end + end + + def create + num_or_str(tk_call(self.class::TkCommandNames[0], @path, *hash_kv(@keys))) + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/notebook.rb b/ext/tk/lib/tkextlib/bwidget/notebook.rb new file mode 100644 index 000000000..26c11ac0d --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/notebook.rb @@ -0,0 +1,116 @@ +# +# tkextlib/bwidget/notebook.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tk/frame' +require 'tkextlib/bwidget.rb' + +module Tk + module BWidget + class NoteBook < TkWindow + end + end +end + +class Tk::BWidget::NoteBook + include TkItemConfigMethod + + TkCommandNames = ['NoteBook'.freeze].freeze + WidgetClassName = 'NoteBook'.freeze + WidgetClassNames[WidgetClassName] = self + + class Event_for_Tabs < TkEvent::Event + def self._get_extra_args_tbl + [ + TkComm.method(:string) # page idenfier + ] + end + end + + def tagid(id) + if id.kind_of?(TkWindow) + id.path + elsif id.kind_of?(TkObject) + id.to_eval + else + # id.to_s + _get_eval_string(id) + end + end + + def tabbind(*args) + _bind_for_event_class(Event_for_Tabs, [path, 'bindtabs'], *args) + self + end + + def tabbind_append(*args) + _bind_append_for_event_class(Event_for_Tabs, [path, 'bindtabs'], *args) + self + end + + def tabbind_remove(*args) + _bind_remove_for_event_class(Event_for_Tabs, [path, 'bindtabs'], *args) + self + end + + def tabbindinfo(*args) + _bindinfo_for_event_class(Event_for_Tabs, [path, 'bindtabs'], *args) + end + + def add(page, &b) + win = window(tk_send('add', tagid(page))) + win.instance_eval(&b) if b + win + end + + def compute_size + tk_send('compute_size') + self + end + + def delete(page, destroyframe=None) + tk_send('delete', tagid(page), destroyframe) + self + end + + def get_frame(page, &b) + win = window(tk_send('getframe', tagid(page))) + win.instance_eval(&b) if b + win + end + + def index(page) + num_or_str(tk_send('index', tagid(page))) + end + + def insert(index, page, keys={}, &b) + win = window(tk_send('insert', index, tagid(page), *hash_kv(keys))) + win.instance_eval(&b) if b + win + end + + def move(page, index) + tk_send('move', tagid(page), index) + self + end + + def get_page(page) + tk_send('pages', page) + end + + def pages(first=None, last=None) + list(tk_send('pages', first, last)) + end + + def raise(page=None) + tk_send('raise', page) + self + end + + def see(page) + tk_send('see', page) + self + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/pagesmanager.rb b/ext/tk/lib/tkextlib/bwidget/pagesmanager.rb new file mode 100644 index 000000000..fc01284be --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/pagesmanager.rb @@ -0,0 +1,61 @@ +# +# tkextlib/bwidget/pagesmanager.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tk/frame' +require 'tkextlib/bwidget.rb' + +module Tk + module BWidget + class PagesManager < TkWindow + end + end +end + +class Tk::BWidget::PagesManager + TkCommandNames = ['PagesManager'.freeze].freeze + WidgetClassName = 'PagesManager'.freeze + WidgetClassNames[WidgetClassName] = self + + def tagid(id) + # id.to_s + _get_eval_string(id) + end + + def add(page, &b) + win = window(tk_send('add', tagid(page))) + win.instance_eval(&b) if b + win + end + + def compute_size + tk_send('compute_size') + self + end + + def delete(page) + tk_send('delete', tagid(page)) + self + end + + def get_frame(page, &b) + win = window(tk_send('getframe', tagid(page))) + win.instance_eval(&b) if b + win + end + + def get_page(page) + tk_send('pages', page) + end + + def pages(first=None, last=None) + list(tk_send('pages', first, last)) + end + + def raise(page=None) + tk_send('raise', page) + self + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/panedwindow.rb b/ext/tk/lib/tkextlib/bwidget/panedwindow.rb new file mode 100644 index 000000000..19982c609 --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/panedwindow.rb @@ -0,0 +1,31 @@ +# +# tkextlib/bwidget/panedwindow.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tk/frame' +require 'tkextlib/bwidget.rb' + +module Tk + module BWidget + class PanedWindow < TkWindow + end + end +end + +class Tk::BWidget::PanedWindow + TkCommandNames = ['PanedWindow'.freeze].freeze + WidgetClassName = 'PanedWindow'.freeze + WidgetClassNames[WidgetClassName] = self + + def add(keys={}) + window(tk_send('add', *hash_kv(keys))) + end + + def get_frame(idx, &b) + win = window(tk_send_without_enc('getframe', idx)) + win.instance_eval(&b) if b + win + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/passwddlg.rb b/ext/tk/lib/tkextlib/bwidget/passwddlg.rb new file mode 100644 index 000000000..399353367 --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/passwddlg.rb @@ -0,0 +1,27 @@ +# +# tkextlib/bwidget/passwddlg.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/bwidget.rb' +require 'tkextlib/bwidget/messagedlg' + +module Tk + module BWidget + class PasswdDlg < Tk::BWidget::MessageDlg + end + end +end + +class Tk::BWidget::PasswdDlg + TkCommandNames = ['PasswdDlg'.freeze].freeze + WidgetClassName = 'PasswdDlg'.freeze + WidgetClassNames[WidgetClassName] = self + + def create + login, passwd = simplelist(tk_call(self.class::TkCommandNames[0], + @path, *hash_kv(@keys))) + [login, passwd] + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/progressbar.rb b/ext/tk/lib/tkextlib/bwidget/progressbar.rb new file mode 100644 index 000000000..0253ce2ad --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/progressbar.rb @@ -0,0 +1,20 @@ +# +# tkextlib/bwidget/progressbar.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/bwidget.rb' + +module Tk + module BWidget + class ProgressBar < TkWindow + end + end +end + +class Tk::BWidget::ProgressBar + TkCommandNames = ['ProgressBar'.freeze].freeze + WidgetClassName = 'ProgressBar'.freeze + WidgetClassNames[WidgetClassName] = self +end diff --git a/ext/tk/lib/tkextlib/bwidget/progressdlg.rb b/ext/tk/lib/tkextlib/bwidget/progressdlg.rb new file mode 100644 index 000000000..fbf00f3b0 --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/progressdlg.rb @@ -0,0 +1,54 @@ +# +# tkextlib/bwidget/progressdlg.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tk/variable' +require 'tkextlib/bwidget.rb' +require 'tkextlib/bwidget/progressbar' +require 'tkextlib/bwidget/messagedlg' + +module Tk + module BWidget + class ProgressDlg < Tk::BWidget::MessageDlg + end + end +end + +class Tk::BWidget::ProgressDlg + TkCommandNames = ['ProgressDlg'.freeze].freeze + WidgetClassName = 'ProgressDlg'.freeze + WidgetClassNames[WidgetClassName] = self + + def create_self(keys) + # NOT create widget for reusing the object + super(keys) + @keys['textvariable'] = TkVariable.new unless @keys.key?('textvariable') + @keys['variable'] = TkVariable.new unless @keys.key?('variable') + end + + def textvariable + @keys['textvariable'] + end + + def text + @keys['textvariable'].value + end + + def text= (txt) + @keys['textvariable'].value = txt + end + + def variable + @keys['variable'] + end + + def value + @keys['variable'].value + end + + def value= (val) + @keys['variable'].value = val + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/scrollableframe.rb b/ext/tk/lib/tkextlib/bwidget/scrollableframe.rb new file mode 100644 index 000000000..a3986681a --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/scrollableframe.rb @@ -0,0 +1,34 @@ +# +# tkextlib/bwidget/scrollableframe.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tk/frame' +require 'tkextlib/bwidget.rb' + +module Tk + module BWidget + class ScrollableFrame < TkWindow + end + end +end + +class Tk::BWidget::ScrollableFrame + include Scrollable + + TkCommandNames = ['ScrollableFrame'.freeze].freeze + WidgetClassName = 'ScrollableFrame'.freeze + WidgetClassNames[WidgetClassName] = self + + def get_frame(&b) + win = window(tk_send_without_enc('getframe')) + win.instance_eval(&b) if b + win + end + + def see(win, vert=None, horiz=None) + tk_send_without_enc('see', win, vert, horiz) + self + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/scrolledwindow.rb b/ext/tk/lib/tkextlib/bwidget/scrolledwindow.rb new file mode 100644 index 000000000..e9e53235b --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/scrolledwindow.rb @@ -0,0 +1,32 @@ +# +# tkextlib/bwidget/scrolledwindow.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tk/frame' +require 'tkextlib/bwidget.rb' + +module Tk + module BWidget + class ScrolledWindow < TkWindow + end + end +end + +class Tk::BWidget::ScrolledWindow + TkCommandNames = ['ScrolledWindow'.freeze].freeze + WidgetClassName = 'ScrolledWindow'.freeze + WidgetClassNames[WidgetClassName] = self + + def get_frame(&b) + win = window(tk_send_without_enc('getframe')) + win.instance_eval(&b) if b + win + end + + def set_widget(win) + tk_send_without_enc('setwidget', win) + self + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/scrollview.rb b/ext/tk/lib/tkextlib/bwidget/scrollview.rb new file mode 100644 index 000000000..5da528bd4 --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/scrollview.rb @@ -0,0 +1,20 @@ +# +# tkextlib/bwidget/scrollview.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/bwidget.rb' + +module Tk + module BWidget + class ScrollView < TkWindow + end + end +end + +class Tk::BWidget::ScrollView + TkCommandNames = ['ScrollView'.freeze].freeze + WidgetClassName = 'ScrollView'.freeze + WidgetClassNames[WidgetClassName] = self +end diff --git a/ext/tk/lib/tkextlib/bwidget/selectcolor.rb b/ext/tk/lib/tkextlib/bwidget/selectcolor.rb new file mode 100644 index 000000000..742a84cd8 --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/selectcolor.rb @@ -0,0 +1,45 @@ +# +# tkextlib/bwidget/selectcolor.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/bwidget.rb' +require 'tkextlib/bwidget/messagedlg' + +module Tk + module BWidget + class SelectColor < Tk::BWidget::MessageDlg + end + end +end + +class Tk::BWidget::SelectColor + extend Tk + + TkCommandNames = ['SelectColor'.freeze].freeze + WidgetClassName = 'SelectColor'.freeze + WidgetClassNames[WidgetClassName] = self + + def dialog(keys={}) + newkeys = @keys.dup + newkeys.update(_symbolkey2str(keys)) + tk_call('SelectColor::dialog', @path, *hash_kv(newkeys)) + end + + def menu(*args) + if args[-1].kind_of?(Hash) + keys = args.pop + else + keys = {} + end + place = args.flatten + newkeys = @keys.dup + newkeys.update(_symbolkey2str(keys)) + tk_call('SelectColor::menu', @path, place, *hash_kv(newkeys)) + end + + def self.set_color(idx, color) + tk_call('SelectColor::setcolor', idx, color) + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/selectfont.rb b/ext/tk/lib/tkextlib/bwidget/selectfont.rb new file mode 100644 index 000000000..46ca0dbca --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/selectfont.rb @@ -0,0 +1,79 @@ +# +# tkextlib/bwidget/selectfont.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/bwidget.rb' +require 'tkextlib/bwidget/messagedlg' + +module Tk + module BWidget + class SelectFont < Tk::BWidget::MessageDlg + class Dialog < Tk::BWidget::SelectFont + end + class Toolbar < TkWindow + end + end + end +end + +class Tk::BWidget::SelectFont + extend Tk + + TkCommandNames = ['SelectFont'.freeze].freeze + WidgetClassName = 'SelectFont'.freeze + WidgetClassNames[WidgetClassName] = self + + def __font_optkeys + [] # without fontobj operation + end + + def create + tk_call(self.class::TkCommandNames[0], @path, *hash_kv(@keys)) + end + + def self.load_font + tk_call('SelectFont::loadfont') + end +end + +class Tk::BWidget::SelectFont::Dialog + def __font_optkeys + [] # without fontobj operation + end + + def create_self(keys) + super(keys) + @keys['type'] = 'dialog' + end + + def configure(slot, value=None) + if slot.kind_of?(Hash) + slot.delete['type'] + slot.delete[:type] + return self if slot.empty? + else + return self if slot == 'type' || slot == :type + end + super(slot, value) + end + + def create + @keys['type'] = 'dialog' + tk_call(Tk::BWidget::SelectFont::TkCommandNames[0], @path, *hash_kv(@keys)) + end +end + +class Tk::BWidget::SelectFont::Toolbar + def __font_optkeys + [] # without fontobj operation + end + + def create_self(keys) + keys = {} unless keys + keys = _symbolkey2str(keys) + keys['type'] = 'toolbar' + tk_call(Tk::BWidget::SelectFont::TkCommandNames[0], @path, *hash_kv(keys)) + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/separator.rb b/ext/tk/lib/tkextlib/bwidget/separator.rb new file mode 100644 index 000000000..d9c3458e5 --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/separator.rb @@ -0,0 +1,20 @@ +# +# tkextlib/bwidget/separator.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/bwidget.rb' + +module Tk + module BWidget + class Separator < TkWindow + end + end +end + +class Tk::BWidget::Separator + TkCommandNames = ['Separator'.freeze].freeze + WidgetClassName = 'Separator'.freeze + WidgetClassNames[WidgetClassName] = self +end diff --git a/ext/tk/lib/tkextlib/bwidget/setup.rb b/ext/tk/lib/tkextlib/bwidget/setup.rb new file mode 100644 index 000000000..ce0f0bd4d --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/setup.rb @@ -0,0 +1,8 @@ +# +# setup.rb -- setup script before calling TkPackage.require() +# +# If you need some setup operations (for example, add a library path +# to the library search path) before using Tcl/Tk library packages +# wrapped by Ruby scripts in this directory, please write the setup +# operations in this file. +# diff --git a/ext/tk/lib/tkextlib/bwidget/spinbox.rb b/ext/tk/lib/tkextlib/bwidget/spinbox.rb new file mode 100644 index 000000000..4380e3835 --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/spinbox.rb @@ -0,0 +1,58 @@ +# +# tkextlib/bwidget/entry.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/bwidget.rb' +require 'tkextlib/bwidget/arrowbutton' +require 'tkextlib/bwidget/entry' + +module Tk + module BWidget + class SpinBox < TkEntry + end + end +end + +class Tk::BWidget::SpinBox + include Scrollable + + TkCommandNames = ['SpinBox'.freeze].freeze + WidgetClassName = 'SpinBox'.freeze + WidgetClassNames[WidgetClassName] = self + + def entrybind(*args) + _bind([path, 'bind'], *args) + self + end + + def entrybind_append(*args) + _bind_append([path, 'bind'], *args) + self + end + + def entrybind_remove(*args) + _bind_remove([path, 'bind'], *args) + self + end + + def entrybindinfo(*args) + _bindinfo([path, 'bind'], *args) + self + end + + def get_index_of_value + number(tk_send_without_enc('getvalue')) + end + alias get_value get_index_of_value + alias get_value_index get_index_of_value + + def set_value_by_index(idx) + idx = "@#{idx}" if idx.kind_of?(Integer) + tk_send_without_enc('setvalue', idx) + self + end + alias set_value set_value_by_index + alias set_index_value set_value_by_index +end diff --git a/ext/tk/lib/tkextlib/bwidget/titleframe.rb b/ext/tk/lib/tkextlib/bwidget/titleframe.rb new file mode 100644 index 000000000..f51949043 --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/titleframe.rb @@ -0,0 +1,27 @@ +# +# tkextlib/bwidget/titleframe.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tk/frame' +require 'tkextlib/bwidget.rb' + +module Tk + module BWidget + class TitleFrame < TkWindow + end + end +end + +class Tk::BWidget::TitleFrame + TkCommandNames = ['TitleFrame'.freeze].freeze + WidgetClassName = 'TitleFrame'.freeze + WidgetClassNames[WidgetClassName] = self + + def get_frame(&b) + win = window(tk_send_without_enc('getframe')) + win.instance_eval(&b) if b + win + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/tree.rb b/ext/tk/lib/tkextlib/bwidget/tree.rb new file mode 100644 index 000000000..888ce9409 --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/tree.rb @@ -0,0 +1,374 @@ +# +# tkextlib/bwidget/tree.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tk/canvas' +require 'tkextlib/bwidget.rb' + +module Tk + module BWidget + class Tree < TkWindow + class Node < TkObject + end + end + end +end + +class Tk::BWidget::Tree + include TkItemConfigMethod + include Scrollable + + TkCommandNames = ['Tree'.freeze].freeze + WidgetClassName = 'Tree'.freeze + WidgetClassNames[WidgetClassName] = self + + class Event_for_Items < TkEvent::Event + def self._get_extra_args_tbl + [ + TkComm.method(:string) # item idenfier + ] + end + end + + def tagid(tag) + if tag.kind_of?(Tk::BWidget::Tree::Node) + tag.id + else + # tag + _get_eval_string(tag) + end + end + + def imagebind(*args) + _bind_for_event_class(Event_for_Items, [path, 'bindImage'], *args) + self + end + + def imagebind_append(*args) + _bind_append_for_event_class(Event_for_Items, [path, 'bindImage'], *args) + self + end + + def imagebind_remove(*args) + _bind_remove_for_event_class(Event_for_Items, [path, 'bindImage'], *args) + self + end + + def imagebindinfo(*args) + _bindinfo_for_event_class(Event_for_Items, [path, 'bindImage'], *args) + end + + def textbind(*args) + _bind_for_event_class(Event_for_Items, [path, 'bindText'], *args) + self + end + + def textbind_append(*args) + _bind_append_for_event_class(Event_for_Items, [path, 'bindText'], *args) + self + end + + def textbind_remove(*args) + _bind_remove_for_event_class(Event_for_Items, [path, 'bindText'], *args) + self + end + + def textbindinfo(*args) + _bindinfo_for_event_class(Event_for_Items, [path, 'bindText'], *args) + end + + def close_tree(node, recurse=None) + tk_send('closetree', tagid(node), recurse) + self + end + + def delete(*args) + tk_send('delete', *(args.collect{|node| tagid(node)})) + self + end + + def edit(node, text, *args) + tk_send('edit', tagid(node), text, *args) + self + end + + def exist?(node) + bool(tk_send('exists', tagid(node))) + end + + def index(node) + num_or_str(tk_send('index', tagid(node))) + end + + def insert(idx, parent, node, keys={}) + tk_send('insert', idx, tagid(parent), tagid(node), *hash_kv(keys)) + self + end + + def move(parent, node, idx) + tk_send('move', tagid(parent), tagid(node), idx) + self + end + + def get_node(node, idx) + Tk::BWidget::Tree::Node.id2obj(self, tk_send('nodes', tagid(node), idx)) + end + + def nodes(node, first=None, last=None) + simplelist(tk_send('nodes', tagid(node), first, last)).collect{|node| + Tk::BWidget::Tree::Node.id2obj(self, node) + } + end + + def open?(node) + bool(@tree.itemcget(tagid(node), 'open')) + end + + def open_tree(node, recurse=None) + tk_send('opentree', tagid(node), recurse) + self + end + + def parent(node) + Tk::BWidget::Tree::Node.id2obj(self, tk_send('parent', tagid(node))) + end + + def reorder(node, neworder) + tk_send('reorder', tagid(node), neworder) + self + end + + def see(node) + tk_send('see', tagid(node)) + self + end + + def selection_add(*args) + tk_send_without_enc('selection', 'add', + *(args.collect{|node| tagid(node)})) + self + end + + def selection_clear + tk_send_without_enc('selection', 'clear') + self + end + + def selection_get + list(tk_send_without_enc('selection', 'get')) + end + + def selection_include?(*args) + bool(tk_send_without_enc('selection', 'get', + *(args.collect{|node| tagid(node)}))) + end + + def selection_range(*args) + tk_send_without_enc('selection', 'range', + *(args.collect{|node| tagid(node)})) + self + end + + def selection_remove(*args) + tk_send_without_enc('selection', 'remove', + *(args.collect{|node| tagid(node)})) + self + end + + def selection_set(*args) + tk_send_without_enc('selection', 'set', + *(args.collect{|node| tagid(node)})) + self + end + + def selection_toggle(*args) + tk_send_without_enc('selection', 'toggle', + *(args.collect{|node| tagid(node)})) + self + end + + def toggle(node) + tk_send_without_enc('toggle', tagid(node)) + self + end + + def visible(node) + bool(tk_send_without_enc('visible', tagid(node))) + end +end + +class Tk::BWidget::Tree::Node + include TkTreatTagFont + + TreeNode_TBL = TkCore::INTERP.create_table + TreeNode_ID = ['node:'.freeze, '00000'.taint].freeze + + TkCore::INTERP.init_ip_env{ TreeNode_TBL.clear } + + def self.id2obj(tree, id) + tpath = tree.path + return id unless TreeNode_TBL[tpath] + TreeNode_TBL[tpath][id]? TreeNode_TBL[tpath][id]: id + end + + def initialize(tree, *args) + if tree.kind_of?(Tk::BWidget::Tree) + @tree = tree + parent = args.shift + if parent.kind_of?(Tk::BWidget::Tree::Node) + if parent.tree.path != @tree.path + fail RuntimeError, 'tree of parent node is not match' + end + end + elsif tree.kind_of?(Tk::BWidget::Tree::Node) + @tree = tree.tree + parent = tree.parent + else + fail RuntimeError, + "expect Tk::BWidget::Tree or Tk::BWidget::Tree::Node for 1st argument" + end + + if args[-1].kind_of?(Hash) + keys = _symbolkey2str(args.pop) + else + keys = {} + end + + index = keys.delete('index') + unless args.empty? + index = args.shift + end + index = 'end' unless index + + unless args.empty? + fail RuntimeError, 'too much arguments' + end + + @tpath = @tree.path + + if keys.key?('nodename') + @path = @id = keys.delete('nodename') + else + @path = @id = TreeNode_ID.join(TkCore::INTERP._ip_id_) + TreeNode_ID[1].succ! + end + + TreeNode_TBL[@id] = self + TreeNode_TBL[@tpath] = {} unless TreeNode_TBL[@tpath] + TreeNode_TBL[@tpath][@id] = self + + @tree.insert(index, parent, @id, keys) + end + + def tree + @tree + end + + def id + @id + end + + def [](key) + cget(key) + end + + def []=(key, val) + configure(key, val) + val + end + + def cget(key) + @tree.itemcget(@id, key) + end + + def configure(key, val=None) + @tree.itemconfigure(@id, key, val) + end + + def configinfo(key=nil) + @tree.itemconfiginfo(@id, key) + end + + def current_configinfo(key=nil) + @tree.current_itemconfiginfo(@id, key) + end + + def close_tree(recurse=None) + @tree.close_tree(@id, recurse) + self + end + + def delete + @tree.delete(@id) + self + end + + def edit(*args) + @tree.edit(@id, *args) + self + end + + def exist? + @tree.exist?(@id) + end + + def index + @tree.index(@id) + end + + def move(index, parent=nil) + if parent + @tree.move(parent, @id, index) + else + @tree.move(self.parent, @id, index) + end + end + + def open_tree(recurse=None) + @tree.open_tree(@id, recurse) + self + end + + def open? + bool(@tree.itemcget(@id, 'open')) + end + + def parent + @tree.parent(@id) + end + + def reorder(neworder) + @tree.reorder(@id, neworder) + end + + def see + @tree.see(@id) + end + + def selection_add + @tree.selection_add(@id) + end + + def selection_remove + @tree.selection_remove(@id) + end + + def selection_set + @tree.selection_set(@id) + end + + def selection_toggle + @tree.selection_toggle(@id) + end + + def toggle + @tree.toggle(@id) + end + + def visible + @tree.visible(@id) + end +end + diff --git a/ext/tk/lib/tkextlib/bwidget/widget.rb b/ext/tk/lib/tkextlib/bwidget/widget.rb new file mode 100644 index 000000000..eadf59c11 --- /dev/null +++ b/ext/tk/lib/tkextlib/bwidget/widget.rb @@ -0,0 +1,113 @@ +# +# tkextlib/bwidget/widget.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/bwidget.rb' + +module Tk + module BWidget + module Widget + end + end +end + +module Tk::BWidget::Widget + include Tk + extend Tk + + def self.__pathname + 'Widget::configure' + end + + def self.__cget_cmd + ['Widget::cget'] + end + + def self.__config_cmd + ['Widget::configure'] + end + + def self.cget(slot) + self.current_configinfo(slot).values[0] + end + + def self.add_map(klass, subclass, subpath, opts) + tk_call('Widget::addmap', klass, subclass, subpath, opts) + end + + def self.bwinclude(klass, subclass, subpath, *args) + tk_call('Widget::bwinclude', klass, subclass, subpath, *args) + end + + def self.create(klass, path, rename=None, &b) + win = window(tk_call('Widget::create', klass, path, rename)) + win.instance_eval(&b) if b + win + end + + def self.declare(klass, optlist) + tk_call('Widget::declare', klass, optlist) + end + + def self.define(klass, filename, *args) + tk_call('Widget::define', klass, filename, *args) + end + + def self.destroy(win) + tk_call('Widget::destroy', win) + end + + def self.focus_next(win) + tk_call('Widget::focusNext', win) + end + + def self.focus_ok(win) + tk_call('Widget::focusOk', win) + end + + def self.focus_prev(win) + tk_call('Widget::focusPrev', win) + end + + def self.generate_doc(dir, widgetlist) + tk_call('Widget::generate-doc', dir, widgetlist) + end + + def self.generate_widget_doc(klass, iscmd, file) + tk_call('Widget::generate-widget-doc', klass, iscmd, file) + end + + def self.get_option(win, option) + tk_call('Widget::getoption', win, option) + end + + def self.get_variable(win, varname, my_varname=None) + tk_call('Widget::getVariable', win, varname, my_varname) + end + + def self.has_changed(win, option, pvalue) + tk_call('Widget::hasChanged', win, option, pvalue) + end + + def self.init(klass, win, options) + tk_call('Widget::init', klass, win, options) + end + + def self.set_option(win, option, value) + tk_call('Widget::setoption', win, option, value) + end + + def self.sub_cget(win, subwidget) + tk_call('Widget::subcget', win, subwidget) + end + + def self.sync_options(klass, subclass, subpath, options) + tk_call('Widget::syncoptions', klass, subclass, subpath, options) + end + + def self.tkinclude(klass, tkwidget, subpath, *args) + tk_call('Widget::tkinclude', klass, tkwidget, subpath, *args) + end +end diff --git a/ext/tk/lib/tkextlib/tcllib.rb b/ext/tk/lib/tkextlib/tcllib.rb index 56f21556a..2955416b2 100644 --- a/ext/tk/lib/tkextlib/tcllib.rb +++ b/ext/tk/lib/tkextlib/tcllib.rb @@ -8,50 +8,36 @@ require 'tk' # call setup script for general 'tkextlib' libraries require 'tkextlib/setup.rb' -# library directory -dir = File.expand_path(__FILE__).sub(/#{File.extname(__FILE__)}$/, '') - # call setup script -require File.join(dir, 'setup.rb') +require 'tkextlib/tcllib/setup.rb' # package:: autoscroll -#require 'tkextlib/tcllib/autoscroll' -require File.join(dir, 'autoscroll') +require 'tkextlib/tcllib/autoscroll' # package:: cursor -#require 'tkextlib/tcllib/cursor' -require File.join(dir, 'cursor') +require 'tkextlib/tcllib/cursor' # package:: style -#require 'tkextlib/tcllib/style' -require File.join(dir, 'style') +require 'tkextlib/tcllib/style' # autoload module Tk module Tcllib - dir = File.expand_path(__FILE__).sub(/#{File.extname(__FILE__)}$/, '') - # package:: ctext - #autoload :CText, 'tkextlib/tcllib/ctext' - autoload :CText, File.join(dir, 'ctext') + autoload :CText, 'tkextlib/tcllib/ctext' # package:: datefield - #autoload :Datefield, 'tkextlib/tcllib/datefield' - #autoload :DateField, 'tkextlib/tcllib/datefield' - autoload :Datefield, File.join(dir, 'datefield') - autoload :DateField, File.join(dir, 'datefield') + autoload :Datefield, 'tkextlib/tcllib/datefield' + autoload :DateField, 'tkextlib/tcllib/datefield' # package:: ipentry - #autoload :IP_Entry, 'tkextlib/tcllib/ip_entry' - autoload :IP_Entry, File.join(dir, 'ip_entry') + autoload :IP_Entry, 'tkextlib/tcllib/ip_entry' # package:: Plotchart - #autoload :Plotchart, 'tkextlib/tcllib/plotchart' - autoload :Plotchart, File.join(dir, 'plotchart') + autoload :Plotchart, 'tkextlib/tcllib/plotchart' # package:: tkpiechart - #autoload :Tkpiechart, 'tkextlib/tcllib/tkpiechart' - autoload :Tkpiechart, File.join(dir, 'tkpiechart') + autoload :Tkpiechart, 'tkextlib/tcllib/tkpiechart' end end diff --git a/ext/tk/lib/tkextlib/tcllib/autoscroll.rb b/ext/tk/lib/tkextlib/tcllib/autoscroll.rb index 9c161d7ec..800a70744 100644 --- a/ext/tk/lib/tkextlib/tcllib/autoscroll.rb +++ b/ext/tk/lib/tkextlib/tcllib/autoscroll.rb @@ -26,17 +26,24 @@ require 'tk' require 'tk/scrollbar' - -# call setup script for general 'tkextlib' libraries -require 'tkextlib/setup.rb' - -# call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tcllib.rb' # TkPackage.require('autoscroll', '1.0') TkPackage.require('autoscroll') module Tk + module Tcllib + module Autoscroll + def self.package_version + begin + TkPackage.require('autoscroll') + rescue + '' + end + end + end + end + module Scrollable def autoscroll(mode = nil) case mode diff --git a/ext/tk/lib/tkextlib/tcllib/ctext.rb b/ext/tk/lib/tkextlib/tcllib/ctext.rb index 6fa3e2edd..2318235a4 100644 --- a/ext/tk/lib/tkextlib/tcllib/ctext.rb +++ b/ext/tk/lib/tkextlib/tcllib/ctext.rb @@ -8,12 +8,7 @@ require 'tk' require 'tk/text' - -# call setup script for general 'tkextlib' libraries -require 'tkextlib/setup.rb' - -# call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tcllib.rb' # TkPackage.require('ctext', '3.1') TkPackage.require('ctext') @@ -21,6 +16,13 @@ TkPackage.require('ctext') module Tk module Tcllib class CText < TkText + def self.package_version + begin + TkPackage.require('ctext') + rescue + '' + end + end end end end diff --git a/ext/tk/lib/tkextlib/tcllib/cursor.rb b/ext/tk/lib/tkextlib/tcllib/cursor.rb index cf4f24720..119b8a143 100644 --- a/ext/tk/lib/tkextlib/tcllib/cursor.rb +++ b/ext/tk/lib/tkextlib/tcllib/cursor.rb @@ -7,17 +7,24 @@ # require 'tk' - -# call setup script for general 'tkextlib' libraries -require 'tkextlib/setup.rb' - -# call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tcllib.rb' # TkPackage.require('cursor', '0.1') TkPackage.require('cursor') module Tk + module Tcllib + module Cursor + def self.package_version + begin + TkPackage.require('ipentry') + rescue + '' + end + end + end + end + def self.cursor_display(parent=None) # Pops up a dialog with a listbox containing all the cursor names. # Selecting a cursor name will display it in that dialog. diff --git a/ext/tk/lib/tkextlib/tcllib/datefield.rb b/ext/tk/lib/tkextlib/tcllib/datefield.rb index 6d3ba4693..4d80b0686 100644 --- a/ext/tk/lib/tkextlib/tcllib/datefield.rb +++ b/ext/tk/lib/tkextlib/tcllib/datefield.rb @@ -17,12 +17,7 @@ require 'tk' require 'tk/entry' - -# call setup script for general 'tkextlib' libraries -require 'tkextlib/setup.rb' - -# call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tcllib.rb' # TkPackage.require('datefield', '0.1') TkPackage.require('datefield') @@ -30,6 +25,13 @@ TkPackage.require('datefield') module Tk module Tcllib class Datefield < TkEntry + def self.package_version + begin + TkPackage.require('datefield') + rescue + '' + end + end end DateField = Datefield end diff --git a/ext/tk/lib/tkextlib/tcllib/ip_entry.rb b/ext/tk/lib/tkextlib/tcllib/ip_entry.rb index aed47da63..748478a32 100644 --- a/ext/tk/lib/tkextlib/tcllib/ip_entry.rb +++ b/ext/tk/lib/tkextlib/tcllib/ip_entry.rb @@ -11,13 +11,7 @@ # It guarantees a valid address at all times. require 'tk' -require 'tk/entry' - -# call setup script for general 'tkextlib' libraries -require 'tkextlib/setup.rb' - -# call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tcllib.rb' # TkPackage.require('ipentry', '0.1') TkPackage.require('ipentry') @@ -25,6 +19,13 @@ TkPackage.require('ipentry') module Tk module Tcllib class IP_Entry < TkEntry + def self.package_version + begin + TkPackage.require('ipentry') + rescue + '' + end + end end end end diff --git a/ext/tk/lib/tkextlib/tcllib/plotchart.rb b/ext/tk/lib/tkextlib/tcllib/plotchart.rb index 108507b05..b22a4ebbd 100644 --- a/ext/tk/lib/tkextlib/tcllib/plotchart.rb +++ b/ext/tk/lib/tkextlib/tcllib/plotchart.rb @@ -58,12 +58,7 @@ # require 'tk' - -# call setup script for general 'tkextlib' libraries -require 'tkextlib/setup.rb' - -# call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tcllib.rb' # TkPackage.require('Plotchart', '0.9') TkPackage.require('Plotchart') @@ -71,6 +66,13 @@ TkPackage.require('Plotchart') module Tk module Tcllib module Plotchart + def self.package_version + begin + TkPackage.require('Plotchart') + rescue + '' + end + end end end end @@ -122,7 +124,7 @@ module Tk::Tcllib::Plotchart ############################ module ChartMethod - include TkUtil + include TkCore def title(str) tk_call_without_enc(@chart, 'title', _get_eval_enc_str(str)) diff --git a/ext/tk/lib/tkextlib/tcllib/style.rb b/ext/tk/lib/tkextlib/tcllib/style.rb index e441cd83b..dea2962b7 100644 --- a/ext/tk/lib/tkextlib/tcllib/style.rb +++ b/ext/tk/lib/tkextlib/tcllib/style.rb @@ -7,18 +7,21 @@ # require 'tk' - -# call setup script for general 'tkextlib' libraries -require 'tkextlib/setup.rb' - -# call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tcllib.rb' # TkPackage.require('style', '0.1') TkPackage.require('style') module Tk module Style + def self.package_version + begin + TkPackage.require('style') + rescue + '' + end + end + def self.names tk_split_simplelist(tk_call('style::names')) end diff --git a/ext/tk/lib/tkextlib/tcllib/tkpiechart.rb b/ext/tk/lib/tkextlib/tcllib/tkpiechart.rb index 1ef49ef4f..4665edca7 100644 --- a/ext/tk/lib/tkextlib/tcllib/tkpiechart.rb +++ b/ext/tk/lib/tkextlib/tcllib/tkpiechart.rb @@ -8,12 +8,7 @@ require 'tk' require 'tk/canvas' - -# call setup script for general 'tkextlib' libraries -require 'tkextlib/setup.rb' - -# call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tcllib.rb' # TkPackage.require('tkpiechart', '6.6') TkPackage.require('tkpiechart') @@ -26,6 +21,14 @@ module Tk end module Tk::Tcllib::Tkpiechart + def self.package_version + begin + TkPackage.require('tkpiechart') + rescue + '' + end + end + module ConfigMethod include TkConfigMethod diff --git a/ext/tk/lib/tkextlib/tile.rb b/ext/tk/lib/tkextlib/tile.rb index 866cdf064..763398155 100644 --- a/ext/tk/lib/tkextlib/tile.rb +++ b/ext/tk/lib/tkextlib/tile.rb @@ -9,10 +9,7 @@ require 'tk' require 'tkextlib/setup.rb' # library directory -dir = File.expand_path(__FILE__).sub(/#{File.extname(__FILE__)}$/, '') - -# call setup script -require File.join(dir, 'setup.rb') +require 'tkextlib/tile/setup.rb' # load package # TkPackage.require('tile', '0.4') @@ -21,6 +18,14 @@ TkPackage.require('tile') # autoload module Tk module Tile + def self.package_version + begin + TkPackage.require('tile') + rescue + '' + end + end + module TileWidget def instate(state, script=nil, &b) if script @@ -41,33 +46,22 @@ module Tk end end + ###################################### - # library directory - dir = File.expand_path(__FILE__).sub(/#{File.extname(__FILE__)}$/, '') - - #autoload :TButton, 'tkextlib/tile/tbutton' - autoload :TButton, File.join(dir, 'tbutton') + autoload :TButton, 'tkextlib/tile/tbutton' - #autoload :TCheckButton, 'tkextlib/tile/tcheckbutton' - #autoload :TCheckbutton, 'tkextlib/tile/tcheckbutton' - autoload :TCheckButton, File.join(dir, 'tcheckbutton') - autoload :TCheckbutton, File.join(dir, 'tcheckbutton') + autoload :TCheckButton, 'tkextlib/tile/tcheckbutton' + autoload :TCheckbutton, 'tkextlib/tile/tcheckbutton' - #autoload :TLabel, 'tkextlib/tile/tlabel' - autoload :TLabel, File.join(dir, 'tlabel') + autoload :TLabel, 'tkextlib/tile/tlabel' - #autoload :TMenubutton, 'tkextlib/tile/tmenubutton' - autoload :TMenubutton, File.join(dir, 'tmenubutton') + autoload :TMenubutton, 'tkextlib/tile/tmenubutton' - #autoload :TNotebook, 'tkextlib/tile/tnotebook' - autoload :TNotebook, File.join(dir, 'tnotebook') + autoload :TNotebook, 'tkextlib/tile/tnotebook' - #autoload :TRadioButton, 'tkextlib/tile/tradiobutton' - #autoload :TRadiobutton, 'tkextlib/tile/tradiobutton' - autoload :TRadioButton, File.join(dir, 'tradiobutton') - autoload :TRadiobutton, File.join(dir, 'tradiobutton') + autoload :TRadioButton, 'tkextlib/tile/tradiobutton' + autoload :TRadiobutton, 'tkextlib/tile/tradiobutton' - #autoload :Style, 'tkextlib/tile/style' - autoload :Style, File.join(dir, 'style') + autoload :Style, 'tkextlib/tile/style' end end diff --git a/ext/tk/lib/tkextlib/tile/style.rb b/ext/tk/lib/tkextlib/tile/style.rb index be4b45ab7..474c4f21b 100644 --- a/ext/tk/lib/tkextlib/tile/style.rb +++ b/ext/tk/lib/tkextlib/tile/style.rb @@ -3,12 +3,14 @@ # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' +require 'tkextlib/tile.rb' -# call setup script for general 'tkextlib' libraries -require 'tkextlib/setup.rb' - -# call setup script -- <libdir>/tkextlib/tile.rb -require(File.dirname(File.expand_path(__FILE__)) + '.rb') +module Tk + module Tile + module Style + end + end +end module Tk::Tile::Style end diff --git a/ext/tk/lib/tkextlib/tile/tbutton.rb b/ext/tk/lib/tkextlib/tile/tbutton.rb index c73b7904e..b5c347569 100644 --- a/ext/tk/lib/tkextlib/tile/tbutton.rb +++ b/ext/tk/lib/tkextlib/tile/tbutton.rb @@ -3,12 +3,14 @@ # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' +require 'tkextlib/tile.rb' -# call setup script for general 'tkextlib' libraries -require 'tkextlib/setup.rb' - -# call setup script -- <libdir>/tkextlib/tile.rb -require(File.dirname(File.expand_path(__FILE__)) + '.rb') +module Tk + module Tile + class TButton < TkButton + end + end +end class Tk::Tile::TButton < TkButton include Tk::Tile::TileWidget diff --git a/ext/tk/lib/tkextlib/tile/tcheckbutton.rb b/ext/tk/lib/tkextlib/tile/tcheckbutton.rb index f5ab00882..4ba77d95d 100644 --- a/ext/tk/lib/tkextlib/tile/tcheckbutton.rb +++ b/ext/tk/lib/tkextlib/tile/tcheckbutton.rb @@ -3,12 +3,15 @@ # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' +require 'tkextlib/tile.rb' -# call setup script for general 'tkextlib' libraries -require 'tkextlib/setup.rb' - -# call setup script -- <libdir>/tkextlib/tile.rb -require(File.dirname(File.expand_path(__FILE__)) + '.rb') +module Tk + module Tile + class TCheckButton < TkCheckButton + end + TCheckbutton = TCheckButton + end +end class Tk::Tile::TCheckButton < TkCheckButton include Tk::Tile::TileWidget @@ -26,8 +29,3 @@ class Tk::Tile::TCheckButton < TkCheckButton end private :create_self end -module Tk - module Tile - TCheckbutton = TCheckButton - end -end diff --git a/ext/tk/lib/tkextlib/tile/tlabel.rb b/ext/tk/lib/tkextlib/tile/tlabel.rb index 1b7302cab..d2eaf4527 100644 --- a/ext/tk/lib/tkextlib/tile/tlabel.rb +++ b/ext/tk/lib/tkextlib/tile/tlabel.rb @@ -3,12 +3,14 @@ # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' +require 'tkextlib/tile.rb' -# call setup script for general 'tkextlib' libraries -require 'tkextlib/setup.rb' - -# call setup script -- <libdir>/tkextlib/tile.rb -require(File.dirname(File.expand_path(__FILE__)) + '.rb') +module Tk + module Tile + class TLabel < TkLabel + end + end +end class Tk::Tile::TLabel < TkLabel include Tk::Tile::TileWidget diff --git a/ext/tk/lib/tkextlib/tile/tmenubutton.rb b/ext/tk/lib/tkextlib/tile/tmenubutton.rb index c827629c7..332db2b74 100644 --- a/ext/tk/lib/tkextlib/tile/tmenubutton.rb +++ b/ext/tk/lib/tkextlib/tile/tmenubutton.rb @@ -3,12 +3,14 @@ # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' +require 'tkextlib/tile.rb' -# call setup script for general 'tkextlib' libraries -require 'tkextlib/setup.rb' - -# call setup script -- <libdir>/tkextlib/tile.rb -require(File.dirname(File.expand_path(__FILE__)) + '.rb') +module Tk + module Tile + class TMenubutton < TkMenubutton + end + end +end class Tk::Tile::TMenubutton < TkMenubutton include Tk::Tile::TileWidget diff --git a/ext/tk/lib/tkextlib/tile/tnotebook.rb b/ext/tk/lib/tkextlib/tile/tnotebook.rb index 40242b523..c693d5ce2 100644 --- a/ext/tk/lib/tkextlib/tile/tnotebook.rb +++ b/ext/tk/lib/tkextlib/tile/tnotebook.rb @@ -3,12 +3,14 @@ # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' +require 'tkextlib/tile.rb' -# call setup script for general 'tkextlib' libraries -require 'tkextlib/setup.rb' - -# call setup script -- <libdir>/tkextlib/tile.rb -require(File.dirname(File.expand_path(__FILE__)) + '.rb') +module Tk + module Tile + class TNotebook < TkWindow + end + end +end class Tk::Tile::TNotebook < TkWindow ################################ diff --git a/ext/tk/lib/tkextlib/tile/tradiobutton.rb b/ext/tk/lib/tkextlib/tile/tradiobutton.rb index 2587a74cf..66cba6296 100644 --- a/ext/tk/lib/tkextlib/tile/tradiobutton.rb +++ b/ext/tk/lib/tkextlib/tile/tradiobutton.rb @@ -3,12 +3,15 @@ # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' +require 'tkextlib/tile.rb' -# call setup script for general 'tkextlib' libraries -require 'tkextlib/setup.rb' - -# call setup script -- <libdir>/tkextlib/tile.rb -require(File.dirname(File.expand_path(__FILE__)) + '.rb') +module Tk + module Tile + class TRadioButton < TkRadioButton + end + TRadiobutton = TRadioButton + end +end class Tk::Tile::TRadioButton < TkRadioButton include Tk::Tile::TileWidget @@ -26,8 +29,3 @@ class Tk::Tile::TRadioButton < TkRadioButton end private :create_self end -module Tk - module Tile - TRadiobutton = TRadioButton - end -end diff --git a/ext/tk/lib/tkextlib/tkDND.rb b/ext/tk/lib/tkextlib/tkDND.rb index 260769df7..5d52e3441 100644 --- a/ext/tk/lib/tkextlib/tkDND.rb +++ b/ext/tk/lib/tkextlib/tkDND.rb @@ -7,19 +7,12 @@ require 'tk' # call setup script for general 'tkextlib' libraries require 'tkextlib/setup.rb' -# library directory -dir = File.expand_path(__FILE__).sub(/#{File.extname(__FILE__)}$/, '') - # call setup script -require File.join(dir, 'setup.rb') +require 'tkextlib/tkDND/setup.rb' module Tk module TkDND - dir = File.expand_path(__FILE__).sub(/#{File.extname(__FILE__)}$/, '') - - #autoload :DND, 'tkextlib/tkDND/tkdnd' - #autoload :Shape, 'tkextlib/tkDND/shape' - autoload :DND, File.join(dir, 'tkdnd') - autoload :Shape, File.join(dir, 'shape') + autoload :DND, 'tkextlib/tkDND/tkdnd' + autoload :Shape, 'tkextlib/tkDND/shape' end end diff --git a/ext/tk/lib/tkextlib/tkDND/shape.rb b/ext/tk/lib/tkextlib/tkDND/shape.rb index 3e4a94f52..8f4716cee 100644 --- a/ext/tk/lib/tkextlib/tkDND/shape.rb +++ b/ext/tk/lib/tkextlib/tkDND/shape.rb @@ -9,7 +9,7 @@ require 'tk' require 'tkextlib/setup.rb' # call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tkDND/setup.rb' # TkPackage.require('shape', '0.3') TkPackage.require('shape') @@ -17,9 +17,29 @@ TkPackage.require('shape') module Tk module TkDND module Shape +=begin + def self.package_version + begin + TkPackage.require('shape') + rescue + '' + end + end +=end + def self.package_version + Tk.tk_call('set', 'shape_version') + end + alias shape_version package_version + + def self.package_patchlevel + Tk.tk_call('set', 'shape_patchlevel') + end + alias shape_patchlevel package_patchlevel + def self.version tk_call('shape', 'version') end + alias xshape_version version ############################ diff --git a/ext/tk/lib/tkextlib/tkDND/tkdnd.rb b/ext/tk/lib/tkextlib/tkDND/tkdnd.rb index 036d1998b..d0895c2af 100644 --- a/ext/tk/lib/tkextlib/tkDND/tkdnd.rb +++ b/ext/tk/lib/tkextlib/tkDND/tkdnd.rb @@ -9,12 +9,20 @@ require 'tk' require 'tkextlib/setup.rb' # call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tkDND/setup.rb' TkPackage.require('tkdnd') module Tk module TkDND + def self.package_version + begin + TkPackage.require('tkdnd') + rescue + '' + end + end + class DND_Subst < TkUtil::CallbackSubst KEY_TBL = [ [ ?a, ?l, :actions ], @@ -49,6 +57,14 @@ module Tk end module DND + def self.version + begin + TkPackage.require('tkdnd') + rescue + '' + end + end + def dnd_bindtarget_info(type=nil, event=nil) if event procedure(tk_call('dnd', 'bindtarget', @path, type, event)) diff --git a/ext/tk/lib/tkextlib/tkHTML.rb b/ext/tk/lib/tkextlib/tkHTML.rb index f32aed99f..5fddde72f 100644 --- a/ext/tk/lib/tkextlib/tkHTML.rb +++ b/ext/tk/lib/tkextlib/tkHTML.rb @@ -6,11 +6,8 @@ # call setup script for general 'tkextlib' libraries require 'tkextlib/setup.rb' -# library directory -dir = File.expand_path(__FILE__).sub(/#{File.extname(__FILE__)}$/, '') - # call setup script -require File.join(dir, 'setup.rb') +require 'tkextlib/tkHTML/setup.rb' # load library -require File.join(dir, 'htmlwidget') +require 'tkextlib/tkHTML/htmlwidget' diff --git a/ext/tk/lib/tkextlib/tkHTML/htmlwidget.rb b/ext/tk/lib/tkextlib/tkHTML/htmlwidget.rb index 5c0657025..0c900cdb8 100644 --- a/ext/tk/lib/tkextlib/tkHTML/htmlwidget.rb +++ b/ext/tk/lib/tkextlib/tkHTML/htmlwidget.rb @@ -9,21 +9,27 @@ require 'tk' require 'tkextlib/setup.rb' # call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tkHTML/setup.rb' # TkPackage.require('Tkhtml', '2.0') TkPackage.require('Tkhtml') module Tk class HTML_Widget < TkWindow + def self.package_version + begin + TkPackage.require('Tkhtml') + rescue + '' + end + end + class ClippingWindow < TkWindow end end end class Tk::HTML_Widget::ClippingWindow - extend TkUtil - WidgetClassName = 'HtmlClip'.freeze WidgetClassNames[WidgetClassName] = self @@ -32,7 +38,7 @@ class Tk::HTML_Widget::ClippingWindow def self.new(parent, keys={}) if parent.kind_of?(Hash) - keys = _symbolkey2str(parent) + keys = TkComm._symbolkey2str(parent) parent = keys.delete('parent') end diff --git a/ext/tk/lib/tkextlib/tkimg.rb b/ext/tk/lib/tkextlib/tkimg.rb index 06184589b..f70d76c9d 100644 --- a/ext/tk/lib/tkextlib/tkimg.rb +++ b/ext/tk/lib/tkextlib/tkimg.rb @@ -8,16 +8,24 @@ require 'tk' # call setup script for general 'tkextlib' libraries require 'tkextlib/setup.rb' -# library directory -dir = File.expand_path(__FILE__).sub(/#{File.extname(__FILE__)}$/, '') - # call setup script -require File.join(dir, 'setup.rb') +require 'tkextlib/tkimg/setup.rb' # load all image format handlers #TkPackage.require('Img', '1.3') TkPackage.require('Img') +module Tk + module Img + def self.package_version + begin + TkPackage.require('Img') + rescue + '' + end + end + end +end + # autoload -#autoload :TkPixmapImage, 'tkextlib/tkimg/pixmap' -autoload :TkPixmapImage, File.join(dir, 'pixmap') +autoload :TkPixmapImage, 'tkextlib/tkimg/pixmap' diff --git a/ext/tk/lib/tkextlib/tkimg/bmp.rb b/ext/tk/lib/tkextlib/tkimg/bmp.rb index 5bef0c716..e6031a43e 100644 --- a/ext/tk/lib/tkextlib/tkimg/bmp.rb +++ b/ext/tk/lib/tkextlib/tkimg/bmp.rb @@ -8,7 +8,21 @@ require 'tk' require 'tkextlib/setup.rb' # call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tkimg/setup.rb' #TkPackage.require('img::bmp', '1.3') TkPackage.require('img::bmp') + +module Tk + module Img + module BMP + def self.package_version + begin + TkPackage.require('img::bmp') + rescue + '' + end + end + end + end +end diff --git a/ext/tk/lib/tkextlib/tkimg/gif.rb b/ext/tk/lib/tkextlib/tkimg/gif.rb index 65c3b88a5..b46443449 100644 --- a/ext/tk/lib/tkextlib/tkimg/gif.rb +++ b/ext/tk/lib/tkextlib/tkimg/gif.rb @@ -8,7 +8,21 @@ require 'tk' require 'tkextlib/setup.rb' # call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tkimg/setup.rb' # TkPackage.require('img::gif', '1.3') TkPackage.require('img::gif') + +module Tk + module Img + module GIF + def self.package_version + begin + TkPackage.require('img::gif') + rescue + '' + end + end + end + end +end diff --git a/ext/tk/lib/tkextlib/tkimg/ico.rb b/ext/tk/lib/tkextlib/tkimg/ico.rb index 43646ec8d..2872a621a 100644 --- a/ext/tk/lib/tkextlib/tkimg/ico.rb +++ b/ext/tk/lib/tkextlib/tkimg/ico.rb @@ -8,7 +8,21 @@ require 'tk' require 'tkextlib/setup.rb' # call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tkimg/setup.rb' # TkPackage.require('img::ico', '1.3') TkPackage.require('img::ico') + +module Tk + module Img + module ICO + def self.package_version + begin + TkPackage.require('img::ico') + rescue + '' + end + end + end + end +end diff --git a/ext/tk/lib/tkextlib/tkimg/jpeg.rb b/ext/tk/lib/tkextlib/tkimg/jpeg.rb index 7b4df8c05..eac39083b 100644 --- a/ext/tk/lib/tkextlib/tkimg/jpeg.rb +++ b/ext/tk/lib/tkextlib/tkimg/jpeg.rb @@ -8,7 +8,21 @@ require 'tk' require 'tkextlib/setup.rb' # call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tkimg/setup.rb' # TkPackage.require('img::jpeg', '1.3') TkPackage.require('img::jpeg') + +module Tk + module Img + module JPEG + def self.package_version + begin + TkPackage.require('img::jpeg') + rescue + '' + end + end + end + end +end diff --git a/ext/tk/lib/tkextlib/tkimg/pcx.rb b/ext/tk/lib/tkextlib/tkimg/pcx.rb index 4486ba244..26311e598 100644 --- a/ext/tk/lib/tkextlib/tkimg/pcx.rb +++ b/ext/tk/lib/tkextlib/tkimg/pcx.rb @@ -8,7 +8,21 @@ require 'tk' require 'tkextlib/setup.rb' # call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tkimg/setup.rb' # TkPackage.require('img::pcx', '1.3') TkPackage.require('img::pcx') + +module Tk + module Img + module PCX + def self.package_version + begin + TkPackage.require('img::pcx') + rescue + '' + end + end + end + end +end diff --git a/ext/tk/lib/tkextlib/tkimg/pixmap.rb b/ext/tk/lib/tkextlib/tkimg/pixmap.rb index 0c18c7140..ae8d3201c 100644 --- a/ext/tk/lib/tkextlib/tkimg/pixmap.rb +++ b/ext/tk/lib/tkextlib/tkimg/pixmap.rb @@ -8,12 +8,30 @@ require 'tk' require 'tkextlib/setup.rb' # call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tkimg/setup.rb' # TkPackage.require('img::pixmap', '1.3') TkPackage.require('img::pixmap') +module Tk + module Img + module PIXMAP + def self.package_version + begin + TkPackage.require('img::pixmap') + rescue + '' + end + end + end + end +end + class TkPixmapImage<TkImage + def self.version + Tk::Img::PIXMAP.version + end + def initialize(*args) @type = 'pixmap' super diff --git a/ext/tk/lib/tkextlib/tkimg/png.rb b/ext/tk/lib/tkextlib/tkimg/png.rb index 275035f47..acdd8c536 100644 --- a/ext/tk/lib/tkextlib/tkimg/png.rb +++ b/ext/tk/lib/tkextlib/tkimg/png.rb @@ -8,7 +8,21 @@ require 'tk' require 'tkextlib/setup.rb' # call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tkimg/setup.rb' # TkPackage.require('img::png', '1.3') TkPackage.require('img::png') + +module Tk + module Img + module PNG + def self.package_version + begin + TkPackage.require('img::png') + rescue + '' + end + end + end + end +end diff --git a/ext/tk/lib/tkextlib/tkimg/ppm.rb b/ext/tk/lib/tkextlib/tkimg/ppm.rb index 730978b28..f15bdb9f1 100644 --- a/ext/tk/lib/tkextlib/tkimg/ppm.rb +++ b/ext/tk/lib/tkextlib/tkimg/ppm.rb @@ -8,7 +8,21 @@ require 'tk' require 'tkextlib/setup.rb' # call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tkimg/setup.rb' # TkPackage.require('img::ppm', '1.3') TkPackage.require('img::ppm') + +module Tk + module Img + module PPM + def self.package_version + begin + TkPackage.require('img::ppm') + rescue + '' + end + end + end + end +end diff --git a/ext/tk/lib/tkextlib/tkimg/ps.rb b/ext/tk/lib/tkextlib/tkimg/ps.rb index edfb8dd78..7c5cab2a4 100644 --- a/ext/tk/lib/tkextlib/tkimg/ps.rb +++ b/ext/tk/lib/tkextlib/tkimg/ps.rb @@ -8,7 +8,21 @@ require 'tk' require 'tkextlib/setup.rb' # call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tkimg/setup.rb' # TkPackage.require('img::ps', '1.3') TkPackage.require('img::ps') + +module Tk + module Img + module PS + def self.package_version + begin + TkPackage.require('img::ps') + rescue + '' + end + end + end + end +end diff --git a/ext/tk/lib/tkextlib/tkimg/sgi.rb b/ext/tk/lib/tkextlib/tkimg/sgi.rb index 9dcfa614b..1cdf60e64 100644 --- a/ext/tk/lib/tkextlib/tkimg/sgi.rb +++ b/ext/tk/lib/tkextlib/tkimg/sgi.rb @@ -8,7 +8,21 @@ require 'tk' require 'tkextlib/setup.rb' # call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tkimg/setup.rb' # TkPackage.require('img::sgi', '1.3') TkPackage.require('img::sgi') + +module Tk + module Img + module SGI + def self.package_version + begin + TkPackage.require('img::sgi') + rescue + '' + end + end + end + end +end diff --git a/ext/tk/lib/tkextlib/tkimg/sun.rb b/ext/tk/lib/tkextlib/tkimg/sun.rb index 4ada9c7ff..88f9a4465 100644 --- a/ext/tk/lib/tkextlib/tkimg/sun.rb +++ b/ext/tk/lib/tkextlib/tkimg/sun.rb @@ -8,7 +8,21 @@ require 'tk' require 'tkextlib/setup.rb' # call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tkimg/setup.rb' # TkPackage.require('img::sun', '1.3') TkPackage.require('img::sun') + +module Tk + module Img + module SUN + def self.package_version + begin + TkPackage.require('img::sun') + rescue + '' + end + end + end + end +end diff --git a/ext/tk/lib/tkextlib/tkimg/tga.rb b/ext/tk/lib/tkextlib/tkimg/tga.rb index 221ebe5db..c4068a729 100644 --- a/ext/tk/lib/tkextlib/tkimg/tga.rb +++ b/ext/tk/lib/tkextlib/tkimg/tga.rb @@ -8,7 +8,21 @@ require 'tk' require 'tkextlib/setup.rb' # call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tkimg/setup.rb' # TkPackage.require('img::tga', '1.3') TkPackage.require('img::tga') + +module Tk + module Img + module TGA + def self.package_version + begin + TkPackage.require('img::tga') + rescue + '' + end + end + end + end +end diff --git a/ext/tk/lib/tkextlib/tkimg/tiff.rb b/ext/tk/lib/tkextlib/tkimg/tiff.rb index 1c7e94084..529999ef2 100644 --- a/ext/tk/lib/tkextlib/tkimg/tiff.rb +++ b/ext/tk/lib/tkextlib/tkimg/tiff.rb @@ -8,7 +8,21 @@ require 'tk' require 'tkextlib/setup.rb' # call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tkimg/setup.rb' # TkPackage.require('img::tiff', '1.3') TkPackage.require('img::tiff') + +module Tk + module Img + module TIFF + def self.package_version + begin + TkPackage.require('img::tiff') + rescue + '' + end + end + end + end +end diff --git a/ext/tk/lib/tkextlib/tkimg/window.rb b/ext/tk/lib/tkextlib/tkimg/window.rb index 056aa8f3c..229445dd4 100644 --- a/ext/tk/lib/tkextlib/tkimg/window.rb +++ b/ext/tk/lib/tkextlib/tkimg/window.rb @@ -8,7 +8,21 @@ require 'tk' require 'tkextlib/setup.rb' # call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tkimg/setup.rb' # TkPackage.require('img::window', '1.3') TkPackage.require('img::window') + +module Tk + module Img + module WINDOW + def self.package_version + begin + TkPackage.require('img::window') + rescue + '' + end + end + end + end +end diff --git a/ext/tk/lib/tkextlib/tkimg/xbm.rb b/ext/tk/lib/tkextlib/tkimg/xbm.rb index 80010c77d..3b680d9b5 100644 --- a/ext/tk/lib/tkextlib/tkimg/xbm.rb +++ b/ext/tk/lib/tkextlib/tkimg/xbm.rb @@ -8,7 +8,21 @@ require 'tk' require 'tkextlib/setup.rb' # call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tkimg/setup.rb' # TkPackage.require('img::xbm', '1.3') TkPackage.require('img::xbm') + +module Tk + module Img + module XBM + def self.package_version + begin + TkPackage.require('img::xbm') + rescue + '' + end + end + end + end +end diff --git a/ext/tk/lib/tkextlib/tkimg/xpm.rb b/ext/tk/lib/tkextlib/tkimg/xpm.rb index 04d56287e..eff1e3c2b 100644 --- a/ext/tk/lib/tkextlib/tkimg/xpm.rb +++ b/ext/tk/lib/tkextlib/tkimg/xpm.rb @@ -8,7 +8,21 @@ require 'tk' require 'tkextlib/setup.rb' # call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tkimg/setup.rb' # TkPackage.require('img::xpm', '1.3') TkPackage.require('img::xpm') + +module Tk + module Img + module XPM + def self.package_version + begin + TkPackage.require('img::xpm') + rescue + '' + end + end + end + end +end diff --git a/ext/tk/lib/tkextlib/tktrans.rb b/ext/tk/lib/tkextlib/tktrans.rb index 93bb338a9..3236b5342 100644 --- a/ext/tk/lib/tkextlib/tktrans.rb +++ b/ext/tk/lib/tkextlib/tktrans.rb @@ -7,11 +7,8 @@ require 'tk' # call setup script for general 'tkextlib' libraries require 'tkextlib/setup.rb' -# library directory -dir = File.expand_path(__FILE__).sub(/#{File.extname(__FILE__)}$/, '') - # call setup script -require File.join(dir, 'setup.rb') +require 'tkextlib/tktrans/setup.rb' # load library -require File.join(dir, 'tktrans') +require 'tkextlib/tktrans/tktrans') diff --git a/ext/tk/lib/tkextlib/tktrans/tktrans.rb b/ext/tk/lib/tkextlib/tktrans/tktrans.rb index fa5d7a2ea..2acdac721 100644 --- a/ext/tk/lib/tkextlib/tktrans/tktrans.rb +++ b/ext/tk/lib/tkextlib/tktrans/tktrans.rb @@ -8,17 +8,23 @@ require 'tk' require 'tkextlib/setup.rb' # call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/tktrans/setup.rb' TkPackage.require('tktrans') rescue Tk.load_tcllibrary('tktrans') -class TkWindow - begin - TkTrans_VERSION = TkPackage.require('tktrans') - rescue - TkTrans_VERSION = nil +module Tk + module TkTrans + def self.package_version + begin + TkPackage.require('tktrans') + rescue + '' + end + end end +end +class TkWindow def tktrans_set_image(img) tk_send('tktrans::setwidget', @path, img) self diff --git a/ext/tk/lib/tkextlib/treectrl.rb b/ext/tk/lib/tkextlib/treectrl.rb index fb03283a8..c8fba54a6 100644 --- a/ext/tk/lib/tkextlib/treectrl.rb +++ b/ext/tk/lib/tkextlib/treectrl.rb @@ -6,11 +6,8 @@ # call setup script for general 'tkextlib' libraries require 'tkextlib/setup.rb' -# library directory -dir = File.expand_path(__FILE__).sub(/#{File.extname(__FILE__)}$/, '') - # call setup script -require File.join(dir, 'setup.rb') +require 'tkextlib/treectrl/setup.rb' # load library -require File.join(dir, 'tktreectrl') +require 'tkextlib/treectrl/tktreectrl') diff --git a/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb b/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb index fb74b72c3..4b5219e60 100644 --- a/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb +++ b/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb @@ -5,16 +5,24 @@ require 'tk' +# call setup script for general 'tkextlib' libraries +require 'tkextlib/setup.rb' + # call setup script -require File.join(File.dirname(File.expand_path(__FILE__)), 'setup.rb') +require 'tkextlib/treectrl/setup.rb' # TkPackage.require('treectrl', '1.0') -#TkPackage.require('treectrl') +TkPackage.require('treectrl') module Tk class TreeCtrl_Widget < TkWindow - #VERSION = TkPackage.require('treectrl', '1.0') - VERSION = TkPackage.require('treectrl') + def self.package_version + begin + TkPackage.require('treectrl') + rescue + '' + end + end class NotifyEvent < TkUtil::CallbackSubst end @@ -312,6 +320,12 @@ class Tk::TreeCtrl_Widget WidgetClassName = ''.freeze WidgetClassNames[WidgetClassName] = self + def install_bind(cmd, *args) + install_bind_for_event_class(Tk::TreeCtrl_Widget::NotifyEvent, cmd, *args) + end + + ######################### + def create_self(keys) if keys and keys != None tk_call_without_enc('treectrl', @path, *hash_kv(keys, true)) diff --git a/ext/tk/lib/tkextlib/vu.rb b/ext/tk/lib/tkextlib/vu.rb index 923b67ce4..4d6124334 100644 --- a/ext/tk/lib/tkextlib/vu.rb +++ b/ext/tk/lib/tkextlib/vu.rb @@ -8,33 +8,34 @@ require 'tk' # call setup script for general 'tkextlib' libraries require 'tkextlib/setup.rb' -# library directory -dir = File.expand_path(__FILE__).sub(/#{File.extname(__FILE__)}$/, '') - # call setup script -require File.join(dir, 'setup.rb') +require 'tkextlib/vu/setup.rb' # load package # TkPackage.require('vu', '2.1') -#TkPackage.require('vu') +TkPackage.require('vu') # autoload module Tk module Vu - # load package - # VERSION = TkPackage.require('vu', '2.1') - VERSION = TkPackage.require('vu') + def self.package_version + begin + TkPackage.require('vu') + rescue + '' + end + end - dir = File.expand_path(__FILE__).sub(/#{File.extname(__FILE__)}$/, '') + ########################################## - autoload :Dial, File.join(dir, 'dial') + autoload :Dial, 'tkextlib/vu/dial' - autoload :Pie, File.join(dir, 'pie') - autoload :PieSlice, File.join(dir, 'pie') - autoload :NamedPieSlice, File.join(dir, 'pie') + autoload :Pie, 'tkextlib/vu/pie' + autoload :PieSlice, 'tkextlib/vu/pie' + autoload :NamedPieSlice, 'tkextlib/vu/pie' - autoload :Spinbox, File.join(dir, 'spinbox') + autoload :Spinbox, 'tkextlib/vu/spinbox' - autoload :Bargraph, File.join(dir, 'bargraph') + autoload :Bargraph, 'tkextlib/vu/bargraph' end end diff --git a/ext/tk/lib/tkextlib/vu/bargraph.rb b/ext/tk/lib/tkextlib/vu/bargraph.rb index 1dbd49db2..3ac08a26a 100644 --- a/ext/tk/lib/tkextlib/vu/bargraph.rb +++ b/ext/tk/lib/tkextlib/vu/bargraph.rb @@ -12,8 +12,9 @@ module Tk end end + # call setup script -- <libdir>/tkextlib/vu.rb -require(File.dirname(File.expand_path(__FILE__)) + '.rb') +require 'tkextlib/vu.rb' class Tk::Vu::Bargraph < TkWindow TkCommandNames = ['::vu::bargraph'.freeze].freeze diff --git a/ext/tk/lib/tkextlib/vu/charts.rb b/ext/tk/lib/tkextlib/vu/charts.rb index bf2a3075b..594582d69 100644 --- a/ext/tk/lib/tkextlib/vu/charts.rb +++ b/ext/tk/lib/tkextlib/vu/charts.rb @@ -6,7 +6,7 @@ require 'tk' require 'tk/canvas' # call setup script -- <libdir>/tkextlib/vu.rb -require(File.dirname(File.expand_path(__FILE__)) + '.rb') +require 'tkextlib/vu.rb' module Tk module Vu diff --git a/ext/tk/lib/tkextlib/vu/dial.rb b/ext/tk/lib/tkextlib/vu/dial.rb index 4d5770a32..e675ceb2d 100644 --- a/ext/tk/lib/tkextlib/vu/dial.rb +++ b/ext/tk/lib/tkextlib/vu/dial.rb @@ -13,7 +13,7 @@ module Tk end # call setup script -- <libdir>/tkextlib/vu.rb -require(File.dirname(File.expand_path(__FILE__)) + '.rb') +require 'tkextlib/vu.rb' # define module/class class Tk::Vu::Dial < TkWindow diff --git a/ext/tk/lib/tkextlib/vu/pie.rb b/ext/tk/lib/tkextlib/vu/pie.rb index 833039c9f..cacca594e 100644 --- a/ext/tk/lib/tkextlib/vu/pie.rb +++ b/ext/tk/lib/tkextlib/vu/pie.rb @@ -18,7 +18,7 @@ module Tk end # call setup script -- <libdir>/tkextlib/vu.rb -require(File.dirname(File.expand_path(__FILE__)) + '.rb') +require 'tkextlib/vu.rb' module Tk::Vu::PieSliceConfigMethod include TkItemConfigMethod @@ -46,7 +46,8 @@ class Tk::Vu::Pie < TkWindow if tag.kind_of?(Tk::Vu::PieSlice) tag.id else - tag + # tag + _get_eval_string(tag) end end diff --git a/ext/tk/lib/tkextlib/vu/spinbox.rb b/ext/tk/lib/tkextlib/vu/spinbox.rb index db2743613..f58643413 100644 --- a/ext/tk/lib/tkextlib/vu/spinbox.rb +++ b/ext/tk/lib/tkextlib/vu/spinbox.rb @@ -9,7 +9,7 @@ if (Tk::TK_MAJOR_VERSION < 8 || (Tk::TK_MAJOR_VERSION == 8 && Tk::TK_MINOR_VERSION < 4)) # call setup script -- <libdir>/tkextlib/vu.rb - require(File.dirname(File.expand_path(__FILE__)) + '.rb') + require 'tkextlib/vu.rb' Tk.tk_call('namespace', 'import', '::vu::spinbox') end |