diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 15:13:14 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 15:13:14 +0000 |
commit | d0233291bc8a5068e52c69c210e5979e5324b5bc (patch) | |
tree | 7d9459449c33792c63eeb7baa071e76352e0baab /trunk/ext/tk/sample/binding_sample.rb | |
parent | 0dc342de848a642ecce8db697b8fecd83a63e117 (diff) | |
parent | 72eaacaa15256ab95c3b52ea386f88586fb9da40 (diff) |
re-adding tag v1_9_0_4 as an alias of trunk@18848v1_9_0_4
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_9_0_4@18849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'trunk/ext/tk/sample/binding_sample.rb')
-rw-r--r-- | trunk/ext/tk/sample/binding_sample.rb | 87 |
1 files changed, 0 insertions, 87 deletions
diff --git a/trunk/ext/tk/sample/binding_sample.rb b/trunk/ext/tk/sample/binding_sample.rb deleted file mode 100644 index 693cc7de2f..0000000000 --- a/trunk/ext/tk/sample/binding_sample.rb +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/env ruby - -require 'tk' - -class Button_clone < TkLabel - def initialize(*args) - @command = nil - - if args[-1].kind_of?(Hash) - keys = _symbolkey2str(args.pop) - @command = keys.delete('command') - - keys['highlightthickness'] = 1 unless keys.key?('highlightthickness') - keys['padx'] = '3m' unless keys.key?('padx') - keys['pady'] = '1m' unless keys.key?('pady') - keys['relief'] = 'raised' unless keys.key?('relief') - - args.push(keys) - end - - super(*args) - - @press = false - - self.bind('Enter', proc{self.background(self.activebackground)}) - self.bind('Leave', proc{ - @press = false - self.background(self.highlightbackground) - self.relief('raised') - }) - - self.bind('ButtonPress-1', proc{@press = true; self.relief('sunken')}) - self.bind('ButtonRelease-1', proc{ - self.relief('raised') - @command.call if @press && @command - @press = false - }) - end - - def command(cmd = Proc.new) - @command = cmd - end - - def invoke - if @command - @command.call - else - '' - end - end -end - -TkLabel.new(:text=><<EOT).pack -This is a sample of 'event binding'. -The first button is a normal button widget. -And the second one is a normal label widget -but with some bindings like a button widget. -EOT - -lbl = TkLabel.new(:foreground=>'red').pack(:pady=>3) - -v = TkVariable.new(0) - -TkFrame.new{|f| - TkLabel.new(f, :text=>'click count : ').pack(:side=>:left) - TkLabel.new(f, :textvariable=>v).pack(:side=>:left) -}.pack - -TkButton.new(:text=>'normal Button widget', - :command=>proc{ - puts 'button is clicked!!' - lbl.text 'button is clicked!!' - v.numeric += 1 - }){ - pack(:fill=>:x, :expand=>true) -} - -Button_clone.new(:text=>'Label with Button binding', - :command=>proc{ - puts 'label is clicked!!' - lbl.text 'label is clicked!!' - v.numeric += 1 - }){ - pack(:fill=>:x, :expand=>true) -} - -Tk.mainloop |