From 10484e5c95d649554fc353012626c3696edd2eac 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@7821 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/sample/demos-en/anilabel.rb | 172 +++++++++++++++++++++++++++++++++++++ ext/tk/sample/demos-en/widget | 7 +- 2 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 ext/tk/sample/demos-en/anilabel.rb (limited to 'ext/tk/sample/demos-en') diff --git a/ext/tk/sample/demos-en/anilabel.rb b/ext/tk/sample/demos-en/anilabel.rb new file mode 100644 index 0000000000..36989c5c91 --- /dev/null +++ b/ext/tk/sample/demos-en/anilabel.rb @@ -0,0 +1,172 @@ +# +# animated label widget demo (called by 'widget') +# +# based on Tcl/Tk8.5a2 widget demos + +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 "Four animated labels are displayed below; each of the labels on the left is animated by making the text message inside it appear to scroll, and the label on the right is animated by animating the image that it displays." +} +msg.pack('side'=>'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 9df91c467b..1a4fb0b96d 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. / " + -- cgit v1.2.3