diff options
author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-06-25 14:40:32 +0000 |
---|---|---|
committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-06-25 14:40:32 +0000 |
commit | 79edd1af703289bfa827ac6418916ba28f490690 (patch) | |
tree | 8da67d71873fd5d0371809db0e3471b72a3f97ec /ext/tk/sample | |
parent | dff438fba3e5d4da6f2aad0b0dafe28a2fc61619 (diff) | |
download | ruby-79edd1af703289bfa827ac6418916ba28f490690.tar.gz |
tk.rb :
* add and modify :
TkWidget.database_class, TkWidget.database_classname,
TkWidget#database_class, TkWidget#database_classname
* instances of a subclass of TkToplevel or TkFrame are
created with ":class=>subclass" option as default.
For example, the followings create similar objects.
(1) TkFrame.new(:class=>'XXX')
(2) class XXX < TkFrame; end; XXX.new
sample/tkoptdb.rb :
* add new part of sample script
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4003 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/sample')
-rw-r--r-- | ext/tk/sample/tkoptdb.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/ext/tk/sample/tkoptdb.rb b/ext/tk/sample/tkoptdb.rb index 930985dc22..066bd9501a 100644 --- a/ext/tk/sample/tkoptdb.rb +++ b/ext/tk/sample/tkoptdb.rb @@ -31,6 +31,7 @@ cmd = TkOptionDB.new_proc_class(:BTN_CMD, [:show_msg, :bye_msg], 2) { end } +# following two frame widgets use same database entry TkFrame.new(:class=>'BtnFrame'){|f| pack(:padx=>5, :pady=>5) TkButton.new(:parent=>f, :widgetname=>'hello'){ @@ -46,4 +47,36 @@ TkFrame.new(:class=>'BtnFrame'){|f| } } +class BtnFrame < TkFrame; end +BtnFrame.new{|f| + pack(:padx=>5, :pady=>5) + TkButton.new(:parent=>f, :widgetname=>'hello'){ + command proc{ + print "($SAFE=#{$SAFE}) : " + cmd.show_msg(TkOptionDB.inspect) + } + pack(:fill=>:x, :padx=>10, :pady=>10) + } + TkButton.new(:command=>proc{print "($SAFE=#{$SAFE}) : "; cmd.bye_msg; exit}, + :parent=>f, :widgetname=>'quit'){ + pack(:fill=>:x, :padx=>10, :pady=>10) + } +} + +# if unknown class, use default option values +TkFrame.new(:class=>'BtnFrame2'){|f| + pack(:padx=>5, :pady=>5) + TkButton.new(:parent=>f, :widgetname=>'hello'){ + command proc{ + print "($SAFE=#{$SAFE}) : " + cmd.show_msg(TkOptionDB.inspect) + } + pack(:fill=>:x, :padx=>10, :pady=>10) + } + TkButton.new(:command=>proc{print "($SAFE=#{$SAFE}) : "; cmd.bye_msg; exit}, + :parent=>f, :widgetname=>'quit'){ + pack(:fill=>:x, :padx=>10, :pady=>10) + } +} + Tk.mainloop |