~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to ext/tk/sample/demos-jp/anilabel.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# animated label widget demo (called by 'widget')
 
3
#
 
4
# based on Tcl/Tk8.5a2 widget demos
 
5
 
 
6
# toplevel widget ��¸�ߤ���к������
 
7
if defined?($anilabel_demo) && $anilabel_demo
 
8
  $anilabel_demo.destroy 
 
9
  $anilabel_demo = nil
 
10
end
 
11
 
 
12
# demo �Ѥ� toplevel widget ������
 
13
$anilabel_demo = TkToplevel.new {|w|
 
14
  title("Animated Label Demonstration")
 
15
  iconname("anilabel")
 
16
  positionWindow(w)
 
17
}
 
18
 
 
19
# label ����
 
20
msg = TkLabel.new($anilabel_demo) {
 
21
  font $font
 
22
  wraplength '4i'
 
23
  justify 'left'
 
24
  text "���ˤ�4�ĤΥ��˥᡼������٥뤬ɽ������Ƥ��ޤ�����¦�ˤ����٥�ϡ������Υƥ����ȥ�å������򥹥������뤷���褦�˸����뤳�Ȥ�ư�����դ��Ƥ��ޤ�����¦�Υ�٥�ϡ�ɽ�����륤�᡼�����Ѳ������뤳�Ȥ�ư����Ϳ���Ƥ��ޤ���"
 
25
}
 
26
msg.pack('side'=>'top')
 
27
 
 
28
# frame ����
 
29
TkFrame.new($anilabel_demo) {|frame|
 
30
  TkButton.new(frame) {
 
31
    #text 'λ��'
 
32
    text '�Ĥ���'
 
33
    command proc{
 
34
      tmppath = $anilabel_demo
 
35
      $anilabel_demo = nil
 
36
      tmppath.destroy
 
37
    }
 
38
  }.pack('side'=>'left', 'expand'=>'yes')
 
39
 
 
40
  TkButton.new(frame) {
 
41
    text '�����ɻ���'
 
42
    command proc{showCode 'anilabel'}
 
43
  }.pack('side'=>'left', 'expand'=>'yes')
 
44
 
 
45
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
 
46
 
 
47
# label demo �ѥե졼������
 
48
f_left = TkLabelFrame.new($anilabel_demo,  :text=>'Scrolling Texts')
 
49
f_right = TkLabelFrame.new($anilabel_demo, :text=>'GIF Image')
 
50
Tk.pack(f_left, f_right, 'side'=>'left', 'expand'=>'yes', 'fill'=>'both', 
 
51
        'padx'=>10, 'pady'=>10)
 
52
 
 
53
# animated label
 
54
class AnimatedTextLabel < TkLabel
 
55
  def initialize(*args)
 
56
    super(*args)
 
57
    @timer = TkTimer.new{ _animation_callback }
 
58
    @timer.loop_exec = -1
 
59
    # bind('Destroy'){ @timer.stop }
 
60
    @btag = TkBindTag.new('Destroy'){ @timer.stop }
 
61
    self.bindtags_unshift(@btag)
 
62
  end
 
63
 
 
64
  def _animation_callback()
 
65
    txt = self.text
 
66
    self.text = (txt[1..-1] << txt[0])
 
67
  end
 
68
  private :_animation_callback
 
69
 
 
70
  def start(interval)
 
71
    @timer.set_interval(interval)
 
72
    @timer.start
 
73
  end
 
74
 
 
75
  def stop
 
76
    @timer.stop
 
77
  end
 
78
end
 
79
 
 
80
# animated image
 
81
class AnimatedImageLabel < AnimatedTextLabel
 
82
  def initialize(*args)
 
83
    super(*args)
 
84
    @destroy_image = false
 
85
    @btag.bind_append('Destroy'){
 
86
      if @destroy_image
 
87
        begin
 
88
          self.image.delete 
 
89
        rescue
 
90
        end
 
91
      end
 
92
    }
 
93
  end
 
94
  attr_accessor :destroy_image
 
95
 
 
96
  def _animation_callback()
 
97
    img = self.image
 
98
 
 
99
    fmt = img.format
 
100
    if fmt.kind_of?(Array)
 
101
      if fmt[1].kind_of?(Hash)
 
102
        # fmt == ['GIF', {'index'=>idx}]
 
103
        idx = fmt[1]['index']
 
104
      else
 
105
        # fmt == ['GIF', '-index', idx]  :: Ruby1.8.2 returns this.
 
106
        idx = fmt[2]
 
107
      end
 
108
    elsif fmt.kind_of?(String) && fmt =~ /GIF -index (\d+)/
 
109
      idx = $1.to_i
 
110
    else
 
111
      idx = -1
 
112
    end
 
113
 
 
114
    begin
 
115
      img.format("GIF -index #{idx + 1}")
 
116
    rescue => e
 
117
      img.format("GIF -index 0")
 
118
    end
 
119
  end
 
120
  private :_animation_callback
 
121
end
 
122
 
 
123
# label ����
 
124
l1 = AnimatedTextLabel.new(f_left, :borderwidth=>4, :relief=>:ridge, 
 
125
                           :font=>{:family=>'Courier', :size=>10})
 
126
l2 = AnimatedTextLabel.new(f_left, :borderwidth=>4, :relief=>:groove, 
 
127
                           :font=>{:family=>'Courier', :size=>10})
 
128
l3 = AnimatedTextLabel.new(f_left, :borderwidth=>4, :relief=>:flat, 
 
129
                           :font=>{:family=>'Courier', :size=>10}, :width=>18)
 
130
Tk.pack(l1, l2, l3, 
 
131
        :side=>:top, :expand=>true, :anchor=>:w, :padx=>10, :pady=>10)
 
132
 
 
133
limg = AnimatedImageLabel.new(f_right, :borderwidth=>0)
 
134
limg.pack(:side=>:top, :expand=>true, :padx=>10, :pady=>10)
 
135
 
 
136
# base64-encoded animated GIF file
 
137
tclPowerdData = <<EOD
 
138
    R0lGODlhKgBAAPQAAP//////zP//AP/MzP/Mmf/MAP+Zmf+ZZv+ZAMz//8zM
 
139
    zMyZmcyZZsxmZsxmAMwzAJnMzJmZzJmZmZlmmZlmZplmM5kzM2aZzGZmzGZm
 
140
    mWZmZmYzZmYzMzNmzDMzZgAzmSH+IE1hZGUgd2l0aCBHSU1QIGJ5IExARGVt
 
141
    YWlsbHkuY29tACH5BAVkAAEALAAAAAAqAEAAAAX+YCCOZEkyTKM2jOm66yPP
 
142
    dF03bx7YcuHIDkGBR7SZeIyhTID4FZ+4Es8nQyCe2EeUNJ0peY2s9mi7PhAM
 
143
    ngEAMGRbUpvzSxskLh1J+Hkg134OdDIDEB+GHxtYMEQMTjMGEYeGFoomezaC
 
144
    DZGSHFmLXTQKkh8eNQVpZ2afmDQGHaOYSoEyhhcklzVmMpuHnaZmDqiGJbg0
 
145
    qFqvh6UNAwB7VA+OwydEjgujkgrPNhbTI8dFvNgEYcHcHx0lB1kX2IYeA2G6
 
146
    NN0YfkXJ2BsAMuAzHB9cZMk3qoEbRzUACsRCUBK5JxsC3iMiKd8GN088SIyT
 
147
    0RAFSROyeEg38caDiB/+JEgqxsODrZJ1BkT0oHKSmI0ceQxo94HDpg0qsuDk
 
148
    UmRAMgu8OgwQ+uIJgUMVeGXA+IQkzEeHGvD8cIGlDXsLiRjQ+EHroQhea7xY
 
149
    8IQBSgYYDi1IS+OFBCgaDMGVS3fGi5BPJpBaENdQ0EomKGD56IHwO39EXiSC
 
150
    Ysgxor5+Xfgq0qByYUpiXmwuoredB2aYH4gWWda0B7SeNENpEJHC1ghi+pS4
 
151
    AJpIAwWvKPBi+8YEht5EriEqpFfMlhEdkBNpx0HUhwypx5T4IB1MBg/Ws2sn
 
152
    wV3MSQOkzI8fUd48Aw3dOZto71x85hHtHijYv18Gf/3GqCdDCXHNoICBobSo
 
153
    IqBqJLyCoH8JPrLgdh88CKCFD0CGmAiGYPgffwceZh6FC2ohIIklnkhehTNY
 
154
    4CIHHGzgwYw01ujBBhvAqKOLLq5AAk9kuSPkkKO40NB+h1gnypJIIvkBf09a
 
155
    N5QIRz5p5ZJXJpmlIVhOGQA2TmIJZZhKKmmll2BqyWSXWUrZpQtpatlmk1c2
 
156
    KaWRHeTZEJF8SqLDn/hhsOeQgBbqAh6DGqronxeARUIIACH5BAUeAAAALAUA
 
157
    LgAFAAUAAAUM4CeKz/OV5YmqaRkCACH5BAUeAAEALAUALgAKAAUAAAUUICCK
 
158
    z/OdJVCaa7p+7aOWcDvTZwgAIfkEBR4AAQAsCwAuAAkABQAABRPgA4zP95zA
 
159
    eZqoWqqpyqLkZ38hACH5BAUKAAEALAcALgANAA4AAAU7ICA+jwiUJEqeKau+
 
160
    r+vGaTmac63v/GP9HM7GQyx+jsgkkoRUHJ3Qx0cK/VQVTKtWwbVKn9suNunc
 
161
    WkMAIfkEBQoAAAAsBwA3AAcABQAABRGgIHzk842j+Yjlt5KuO8JmCAAh+QQF
 
162
    CgAAACwLADcABwAFAAAFEeAnfN9TjqP5oOWziq05lmUIACH5BAUKAAAALA8A
 
163
    NwAHAAUAAAUPoPCJTymS3yiQj4qOcPmEACH5BAUKAAAALBMANwAHAAUAAAUR
 
164
    oCB+z/MJX2o+I2miKimiawgAIfkEBQoAAAAsFwA3AAcABQAABRGgIHzfY47j
 
165
    Q4qk+aHl+pZmCAAh+QQFCgAAACwbADcABwAFAAAFEaAgfs/zCV9qPiNJouo7
 
166
    ll8IACH5BAUKAAAALB8ANwADAAUAAAUIoCB8o0iWZggAOw==
 
167
EOD
 
168
 
 
169
l1.text('* Slow Animation *').start(300)
 
170
l2.text('* Fast Animation *').start(80)
 
171
l3.text('This is a longer scrolling text in a widget that will not show the whole message at once. ').start(150)
 
172
 
 
173
limg.destroy_image = true
 
174
limg.image(TkPhotoImage.new(:format=>'GIF', :data=>tclPowerdData)).start(100)