mirror of
https://github.com/ruby/ruby.git
synced 2025-09-17 01:23:57 +02:00

* ext/tk/*: Support new features of Tcl/Tk8.6b1 and minor bug fixes. ( [KNOWN BUG] Ruby/Tk on Ruby 1.9 will not work on Cygwin. ) * ext/tk/*: Unify sources between Ruby 1.8 & 1.9. Improve default_widget_set handling. * ext/tk/*: Multi-TkInterpreter (multi-tk.rb) works on Ruby 1.8 & 1.9. ( [KNOWN BUG] On Ruby 1.8, join to a long term Thread on Tk callbacks may freeze. On Ruby 1.9, cannot create a second master interpreter (creating slaves are OK); supported master interpreter is the default master interpreter only. ) * ext/tk/lib/tkextlib/*: Update supported versions of Tk extensions. Tcllib 1.8/Tklib 0.4.1 ==> Tcllib 1.11.1/Tklib 0.5 BWidgets 1.7 ==> BWidgets 1.8 TkTable 2.9 ==> TkTable 2.10 TkTreeCtrl 2005-12-02 ==> TkTreeCtrl 2.2.9 Tile 0.8.0/8.5.1 ==> Tile 0.8.3/8.6b1 IncrTcl 2005-02-14 ==> IncrTcl 2008-12-15 TclX 2005-02-07 ==> TclX 2008-12-15 Trofs 0.4.3 ==> Trofs 0.4.4 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@24064 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
87 lines
2.1 KiB
Ruby
87 lines
2.1 KiB
Ruby
#!/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
|