From 3dbbe5a7857da3ebde58fa993d9e56ee04dc51a6 Mon Sep 17 00:00:00 2001 From: nagai Date: Tue, 25 Jan 2005 05:09:22 +0000 Subject: * ext/tcltklib/tcltklib.c: fix SEGV bug; trouble on canceling remained after scripts [ruby-dev:25479]: NULL current namespce when deleting Tk interpreter [ruby-talk:126225] * ext/tcltklib/extconf.rb: bug fix; TCL_ENABLE_THREAD flag is inverted [ruby-talk:126360] * ext/tcltklib/extconf.rb: add yet another native-thread check * ext/tk/tkutil.c: fix SEGV bug; NULL string pointer when finalize Ruby interpreter * ext/tk/lib/multi-tk.rb: avoid warning for deleted safeTk ip frame * ext/tk/lib/tk/bindtag.rb: bug fix; new method of named bindtag doesn't return the created object [ruby-dev:25479] * ext/tk/lib/tk/menu.rb: bug on treating arguments [ruby-dev:25479] * ext/tk/lib/tk.rb: bug fix; cannot accept a callback ID string for a command argument [ruby-dev:25479] * ext/tk/lib/multi-tk.rb: ditto * ext/tk/lib/tk/*.rb: ditto * ext/tk/lib/tkextlib/*.rb: ditto * ext/tk/sample/demos-jp/anilabel.rb: new demo script * ext/tk/sample/demos-en/anilabel.rb: ditto * ext/tk/sample/tkHTML/ss.rb: local variable scope bug fix [ruby-dev:25479] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@7821 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/ChangeLog.tkextlib | 30 +++++ ext/tk/lib/multi-tk.rb | 18 ++- ext/tk/lib/remote-tk.rb | 4 + ext/tk/lib/tk.rb | 14 +- ext/tk/lib/tk/bindtag.rb | 1 + ext/tk/lib/tk/canvas.rb | 4 +- ext/tk/lib/tk/canvastag.rb | 4 +- ext/tk/lib/tk/menu.rb | 2 + ext/tk/lib/tk/text.rb | 4 +- ext/tk/lib/tk/texttag.rb | 4 +- ext/tk/lib/tkextlib/blt/component.rb | 4 +- ext/tk/lib/tkextlib/blt/tabset.rb | 8 +- ext/tk/lib/tkextlib/blt/treeview.rb | 8 +- ext/tk/lib/tkextlib/bwidget/labelentry.rb | 4 +- ext/tk/lib/tkextlib/bwidget/listbox.rb | 8 +- ext/tk/lib/tkextlib/bwidget/notebook.rb | 4 +- ext/tk/lib/tkextlib/bwidget/spinbox.rb | 4 +- ext/tk/lib/tkextlib/bwidget/tree.rb | 8 +- ext/tk/lib/tkextlib/itk/incr_tk.rb | 4 +- ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb | 4 +- ext/tk/lib/tkextlib/tkDND/tkdnd.rb | 4 +- ext/tk/lib/tkextlib/treectrl/tktreectrl.rb | 4 +- ext/tk/sample/demos-en/anilabel.rb | 172 ++++++++++++++++++++++++ ext/tk/sample/demos-en/widget | 7 +- ext/tk/sample/demos-jp/anilabel.rb | 174 +++++++++++++++++++++++++ ext/tk/sample/demos-jp/widget | 8 +- ext/tk/sample/tkextlib/tkHTML/ss.rb | 2 + ext/tk/tkutil.c | 10 +- 28 files changed, 469 insertions(+), 53 deletions(-) create mode 100644 ext/tk/sample/demos-en/anilabel.rb create mode 100644 ext/tk/sample/demos-jp/anilabel.rb (limited to 'ext/tk') diff --git a/ext/tk/ChangeLog.tkextlib b/ext/tk/ChangeLog.tkextlib index 653c6ef7d..0bfa0ba5f 100644 --- a/ext/tk/ChangeLog.tkextlib +++ b/ext/tk/ChangeLog.tkextlib @@ -1,3 +1,33 @@ +2005-01-25 Hidetoshi NAGAI + + * ext/tk/lib/tkextlib/blt/component.rb: bug fix. cannot accept + a callback ID string for a command argument. [ruby-dev:25479] + + * ext/tk/lib/tkextlib/blt/tabset.rb: ditto + + * ext/tk/lib/tkextlib/blt/treeview.rb: ditto + + * ext/tk/lib/tkextlib/bwidget/labelentry.rb: ditto + + * ext/tk/lib/tkextlib/bwidget/listbox.rb: ditto + + * ext/tk/lib/tkextlib/bwidget/notebook.rb: ditto + + * ext/tk/lib/tkextlib/bwidget/spinbox.rb: ditto + + * ext/tk/lib/tkextlib/bwidget/tree.rb: ditto + + * ext/tk/lib/tkextlib/itk/incr_tk.rb: ditto + + * ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb: ditto + + * ext/tk/lib/tkextlib/tkDND/tkdnd.rb: ditto + + * ext/tk/lib/tkextlib/treectrl/tktreectrl.rb: ditto + + * ext/tk/sample/tkHTML/ss.rb: local variable scope bug fix + [ruby-dev:25479] + 2004-12-24 Hidetoshi NAGAI * add BLT extension support diff --git a/ext/tk/lib/multi-tk.rb b/ext/tk/lib/multi-tk.rb index d292b5089..ef4868fde 100644 --- a/ext/tk/lib/multi-tk.rb +++ b/ext/tk/lib/multi-tk.rb @@ -762,7 +762,11 @@ class MultiTkIp #slave_ip.delete slave_ip._eval_without_enc('exit') end - top.destroy if top.winfo_exist? + begin + top.destroy if top.winfo_exist? + rescue + # ignore + end } tag = TkBindTag.new.bind('Destroy', slave_delete_proc) @@ -1560,10 +1564,14 @@ class << MultiTkIp __getip.delete end - def deleteed? + def deleted? __getip.deleted? end + def null_namespace? + __getip.null_namespace? + end + def abort(msg = nil) __getip.abort(msg) end @@ -1886,6 +1894,10 @@ class MultiTkIp @interp.deleted? end + def null_namespace? + @interp.null_namespace? + end + def abort(msg = nil) if master? if msg @@ -2217,7 +2229,7 @@ class MultiTkIp def set_bgerror_handler(cmd = Proc.new, slave = nil, &b) unless TkComm._callback_entry?(cmd) - unless slave + if !slave && b slave = cmd cmd = Proc.new(&b) end diff --git a/ext/tk/lib/remote-tk.rb b/ext/tk/lib/remote-tk.rb index 1ef5310bd..a2f8a46d4 100644 --- a/ext/tk/lib/remote-tk.rb +++ b/ext/tk/lib/remote-tk.rb @@ -282,6 +282,10 @@ class RemoteTkIp end end + def null_namespace? + false + end + def restart fail RuntimeError, 'cannot restart the remote interpreter' end diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index 9dae5f089..7f734a082 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -913,7 +913,7 @@ module TkComm #end def bind(tagOrClass, context, *args) # if args[0].kind_of?(Proc) || args[0].kind_of?(Method) - if TkComm._callback_entry?(args[0]) + if TkComm._callback_entry?(args[0]) || !block_given? cmd = args.shift else cmd = Proc.new @@ -928,7 +928,7 @@ module TkComm #end def bind_append(tagOrClass, context, *args) # if args[0].kind_of?(Proc) || args[0].kind_of?(Method) - if TkComm._callback_entry?(args[0]) + if TkComm._callback_entry?(args[0]) || !block_given? cmd = args.shift else cmd = Proc.new @@ -952,7 +952,7 @@ module TkComm #end def bind_all(context, *args) # if args[0].kind_of?(Proc) || args[0].kind_of?(Method) - if TkComm._callback_entry?(args[0]) + if TkComm._callback_entry?(args[0]) || !block_given? cmd = args.shift else cmd = Proc.new @@ -967,7 +967,7 @@ module TkComm #end def bind_append_all(context, *args) # if args[0].kind_of?(Proc) || args[0].kind_of?(Method) - if TkComm._callback_entry?(args[0]) + if TkComm._callback_entry?(args[0]) || !block_given? cmd = args.shift else cmd = Proc.new @@ -2131,7 +2131,7 @@ module TkBindCore #end def bind(context, *args) # if args[0].kind_of?(Proc) || args[0].kind_of?(Method) - if TkComm._callback_entry?(args[0]) + if TkComm._callback_entry?(args[0]) || !block_given? cmd = args.shift else cmd = Proc.new @@ -2144,7 +2144,7 @@ module TkBindCore #end def bind_append(context, *args) # if args[0].kind_of?(Proc) || args[0].kind_of?(Method) - if TkComm._callback_entry?(args[0]) + if TkComm._callback_entry?(args[0]) || !block_given? cmd = args.shift else cmd = Proc.new @@ -3940,7 +3940,7 @@ end #Tk.freeze module Tk - RELEASE_DATE = '2004-12-27'.freeze + RELEASE_DATE = '2005-01-25'.freeze autoload :AUTO_PATH, 'tk/variable' autoload :TCL_PACKAGE_PATH, 'tk/variable' diff --git a/ext/tk/lib/tk/bindtag.rb b/ext/tk/lib/tk/bindtag.rb index 737223e3d..9023a08e0 100644 --- a/ext/tk/lib/tk/bindtag.rb +++ b/ext/tk/lib/tk/bindtag.rb @@ -23,6 +23,7 @@ class TkBindTag @id = name BTagID_TBL[@id] = self bind(*args, &b) if args != [] + self } end diff --git a/ext/tk/lib/tk/canvas.rb b/ext/tk/lib/tk/canvas.rb index a0543cc42..e9a2caccd 100644 --- a/ext/tk/lib/tk/canvas.rb +++ b/ext/tk/lib/tk/canvas.rb @@ -100,7 +100,7 @@ class TkCanvas'top') + +# frame +TkFrame.new($anilabel_demo) {|frame| + TkButton.new(frame) { + text 'Dismiss' + command proc{ + tmppath = $anilabel_demo + $anilabel_demo = nil + tmppath.destroy + } + }.pack('side'=>'left', 'expand'=>'yes') + + TkButton.new(frame) { + text 'See Code' + command proc{showCode 'label'} + }.pack('side'=>'left', 'expand'=>'yes') + +}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') + +# create frame for label demo +f_left = TkLabelFrame.new($anilabel_demo, :text=>'Scrolling Texts') +f_right = TkLabelFrame.new($anilabel_demo, :text=>'GIF Image') +Tk.pack(f_left, f_right, 'side'=>'left', 'expand'=>'yes', 'fill'=>'both', + 'padx'=>10, 'pady'=>10) + +# animated label +class AnimatedTextLabel < TkLabel + def initialize(*args) + super(*args) + @timer = TkTimer.new{ _animation_callback } + @timer.loop_exec = -1 + # bind('Destroy'){ @timer.stop } + @btag = TkBindTag.new('Destroy'){ @timer.stop } + self.bindtags_unshift(@btag) + end + + def _animation_callback() + txt = self.text + self.text = (txt[1..-1] << txt[0]) + end + private :_animation_callback + + def start(interval) + @timer.set_interval(interval) + @timer.start + end + + def stop + @timer.stop + end +end + +# animated image +class AnimatedImageLabel < AnimatedTextLabel + def initialize(*args) + super(*args) + @destroy_image = false + @btag.bind_append('Destroy'){ + if @destroy_image + begin + self.image.delete + rescue + end + end + } + end + attr_accessor :destroy_image + + def _animation_callback() + img = self.image + + fmt = img.format + if fmt.kind_of?(Array) + if fmt[1].kind_of?(Hash) + # fmt == ['GIF', {'index'=>idx}] + idx = fmt[1]['index'] + else + # fmt == ['GIF', '-index', idx] :: Ruby1.8.2 returns this. + idx = fmt[2] + end + elsif fmt.kind_of?(String) && fmt =~ /GIF -index (\d+)/ + idx = $1.to_i + else + idx = -1 + end + + begin + img.format("GIF -index #{idx + 1}") + rescue => e + img.format("GIF -index 0") + end + end + private :_animation_callback +end + +# create labels +l1 = AnimatedTextLabel.new(f_left, :borderwidth=>4, :relief=>:ridge, + :font=>{:family=>'Courier', :size=>10}) +l2 = AnimatedTextLabel.new(f_left, :borderwidth=>4, :relief=>:groove, + :font=>{:family=>'Courier', :size=>10}) +l3 = AnimatedTextLabel.new(f_left, :borderwidth=>4, :relief=>:flat, + :font=>{:family=>'Courier', :size=>10}, :width=>18) +Tk.pack(l1, l2, l3, + :side=>:top, :expand=>true, :anchor=>:w, :padx=>10, :pady=>10) + +limg = AnimatedImageLabel.new(f_right, :borderwidth=>0) +limg.pack(:side=>:top, :expand=>true, :padx=>10, :pady=>10) + +# base64-encoded animated GIF file +tclPowerdData = <'GIF', :data=>tclPowerdData)).start(100) diff --git a/ext/tk/sample/demos-en/widget b/ext/tk/sample/demos-en/widget index 9df91c467..1a4fb0b96 100644 --- a/ext/tk/sample/demos-en/widget +++ b/ext/tk/sample/demos-en/widget @@ -388,6 +388,11 @@ txt.insert('end', " \n ", tag_demospace) txt.insert('end', "3. Color picker.\n", tag_demo, "demo-clrpick") txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "\n") +txt.insert('end', "Animation\n", tag_title) +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "1. Animated labels (if supported)\n", tag_demo, "demo-anilabel") + txt.insert('end', "\n") txt.insert('end', "Miscellaneous\n", tag_title) txt.insert('end', " \n ", tag_demospace) @@ -780,7 +785,7 @@ end # def aboutBox Tk.messageBox('icon'=>'info', 'type'=>'ok', 'title'=>'About Widget Demo', - 'message'=>"Ruby/Tk widget demonstration Ver.1.4.4-en\n\n" + + 'message'=>"Ruby/Tk widget demonstration Ver.1.5.0-en\n\n" + "based on demos of Tk8.1 -- 8.5 " + "( Copyright:: " + "(c) 1996-1997 Sun Microsystems, Inc. / " + diff --git a/ext/tk/sample/demos-jp/anilabel.rb b/ext/tk/sample/demos-jp/anilabel.rb new file mode 100644 index 000000000..8cbec5016 --- /dev/null +++ b/ext/tk/sample/demos-jp/anilabel.rb @@ -0,0 +1,174 @@ +# +# animated label widget demo (called by 'widget') +# +# based on Tcl/Tk8.5a2 widget demos + +# toplevel widget が存在すれば削除する +if defined?($anilabel_demo) && $anilabel_demo + $anilabel_demo.destroy + $anilabel_demo = nil +end + +# demo 用の toplevel widget を生成 +$anilabel_demo = TkToplevel.new {|w| + title("Animated Label Demonstration") + iconname("anilabel") + positionWindow(w) +} + +# label 生成 +msg = TkLabel.new($anilabel_demo) { + font $font + wraplength '4i' + justify 'left' + text "下には4つのアニメーションラベルが表示されています。左側にあるラベルは、内部のテキストメッセージをスクロールしたように見せることで動きを付けています。右側のラベルは、表示するイメージを変化させることで動きを与えています。" +} +msg.pack('side'=>'top') + +# frame 生成 +TkFrame.new($anilabel_demo) {|frame| + TkButton.new(frame) { + #text '了解' + text '閉じる' + command proc{ + tmppath = $anilabel_demo + $anilabel_demo = nil + tmppath.destroy + } + }.pack('side'=>'left', 'expand'=>'yes') + + TkButton.new(frame) { + text 'コード参照' + command proc{showCode 'label'} + }.pack('side'=>'left', 'expand'=>'yes') + +}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') + +# label demo 用フレーム生成 +f_left = TkLabelFrame.new($anilabel_demo, :text=>'Scrolling Texts') +f_right = TkLabelFrame.new($anilabel_demo, :text=>'GIF Image') +Tk.pack(f_left, f_right, 'side'=>'left', 'expand'=>'yes', 'fill'=>'both', + 'padx'=>10, 'pady'=>10) + +# animated label +class AnimatedTextLabel < TkLabel + def initialize(*args) + super(*args) + @timer = TkTimer.new{ _animation_callback } + @timer.loop_exec = -1 + # bind('Destroy'){ @timer.stop } + @btag = TkBindTag.new('Destroy'){ @timer.stop } + self.bindtags_unshift(@btag) + end + + def _animation_callback() + txt = self.text + self.text = (txt[1..-1] << txt[0]) + end + private :_animation_callback + + def start(interval) + @timer.set_interval(interval) + @timer.start + end + + def stop + @timer.stop + end +end + +# animated image +class AnimatedImageLabel < AnimatedTextLabel + def initialize(*args) + super(*args) + @destroy_image = false + @btag.bind_append('Destroy'){ + if @destroy_image + begin + self.image.delete + rescue + end + end + } + end + attr_accessor :destroy_image + + def _animation_callback() + img = self.image + + fmt = img.format + if fmt.kind_of?(Array) + if fmt[1].kind_of?(Hash) + # fmt == ['GIF', {'index'=>idx}] + idx = fmt[1]['index'] + else + # fmt == ['GIF', '-index', idx] :: Ruby1.8.2 returns this. + idx = fmt[2] + end + elsif fmt.kind_of?(String) && fmt =~ /GIF -index (\d+)/ + idx = $1.to_i + else + idx = -1 + end + + begin + img.format("GIF -index #{idx + 1}") + rescue => e + img.format("GIF -index 0") + end + end + private :_animation_callback +end + +# label 生成 +l1 = AnimatedTextLabel.new(f_left, :borderwidth=>4, :relief=>:ridge, + :font=>{:family=>'Courier', :size=>10}) +l2 = AnimatedTextLabel.new(f_left, :borderwidth=>4, :relief=>:groove, + :font=>{:family=>'Courier', :size=>10}) +l3 = AnimatedTextLabel.new(f_left, :borderwidth=>4, :relief=>:flat, + :font=>{:family=>'Courier', :size=>10}, :width=>18) +Tk.pack(l1, l2, l3, + :side=>:top, :expand=>true, :anchor=>:w, :padx=>10, :pady=>10) + +limg = AnimatedImageLabel.new(f_right, :borderwidth=>0) +limg.pack(:side=>:top, :expand=>true, :padx=>10, :pady=>10) + +# base64-encoded animated GIF file +tclPowerdData = <'GIF', :data=>tclPowerdData)).start(100) diff --git a/ext/tk/sample/demos-jp/widget b/ext/tk/sample/demos-jp/widget index 6eaaece4c..3be05c167 100644 --- a/ext/tk/sample/demos-jp/widget +++ b/ext/tk/sample/demos-jp/widget @@ -437,6 +437,12 @@ txt.insert('end', " \n ", tag_demospace) txt.insert('end', "3. 色選択ダイアログ\n", tag_demo, "demo-clrpick") txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "\n") +#txt.insert('end', "アニメーション\n", tag_middle) +txt.insert('end', "アニメーション\n", tag_kanji_title) +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "1. アニメーションラベル (機能に対応したバージョンのTkが必要)\n", tag_demo, "demo-anilabel") + txt.insert('end', "\n") #txt.insert('end', "その他\n", tag_middle) txt.insert('end', "その他\n", tag_kanji_title) @@ -807,7 +813,7 @@ end # def aboutBox Tk.messageBox('icon'=>'info', 'type'=>'ok', 'title'=>'About Widget Demo', - 'message'=>"Ruby/Tk ウィジェットデモ Ver.1.4.4-jp\n\n" + + 'message'=>"Ruby/Tk ウィジェットデモ Ver.1.5.0-jp\n\n" + "based on demos of Tk8.1 -- 8.5 " + "( Copyright:: " + "(c) 1996-1997 Sun Microsystems, Inc. / " + diff --git a/ext/tk/sample/tkextlib/tkHTML/ss.rb b/ext/tk/sample/tkextlib/tkHTML/ss.rb index 179bdc13c..3dbb7ec71 100644 --- a/ext/tk/sample/tkextlib/tkHTML/ss.rb +++ b/ext/tk/sample/tkextlib/tkHTML/ss.rb @@ -159,6 +159,8 @@ href_binding = proc{|w, x, y| # # last_dir = Dir.pwd +load_file = nil + sel_load = proc{ filetypes = [ ['Html Files', ['.html', '.htm']], diff --git a/ext/tk/tkutil.c b/ext/tk/tkutil.c index e36f92af0..d88f7b9a7 100644 --- a/ext/tk/tkutil.c +++ b/ext/tk/tkutil.c @@ -8,7 +8,7 @@ ************************************************/ -#define TKUTIL_RELEASE_DATE "2004-12-23" +#define TKUTIL_RELEASE_DATE "2005-01-25" #include "ruby.h" #include "rubysig.h" @@ -824,6 +824,8 @@ tcl2rb_bool(self, value) value = rb_funcall(value, ID_downcase, 0); + if (RSTRING(value)->ptr == (char*)NULL) return Qnil; + if (RSTRING(value)->ptr[0] == '\0' || strcmp(RSTRING(value)->ptr, "0") == 0 || strcmp(RSTRING(value)->ptr, "no") == 0 @@ -880,6 +882,8 @@ tkstr_to_number(value) { rb_check_type(value, T_STRING); + if (RSTRING(value)->ptr == (char*)NULL) return INT2FIX(0); + return rb_rescue2(tkstr_to_int, value, tkstr_rescue_float, value, rb_eArgError, 0); @@ -916,6 +920,8 @@ tcl2rb_string(self, value) { rb_check_type(value, T_STRING); + if (RSTRING(value)->ptr == (char*)NULL) return rb_tainted_str_new2(""); + return tkstr_to_str(value); } @@ -926,6 +932,8 @@ tcl2rb_num_or_str(self, value) { rb_check_type(value, T_STRING); + if (RSTRING(value)->ptr == (char*)NULL) return rb_tainted_str_new2(""); + return rb_rescue2(tkstr_to_number, value, tkstr_to_str, value, rb_eArgError, 0); -- cgit