* ext/tk/tcltklib.c, ext/tk/tkutil/tkutil.c: fix memory leak.

* ext/tk/lib/tk.rb: avoid trouble when finalize TclTkIp.

* ext/tk/lib/tk.rb, ext/tk/lib/tk/*: help to fix troubles when 
  use Ttk widgets on old Tk scripts.

* ext/tk/sample/*: update and add demo stcipts. some of them are 
  introduction about new features of Tcl/Tk8.5.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagai 2008-05-22 19:24:24 +00:00
parent 461d682980
commit 20b20bb72a
186 changed files with 5715 additions and 923 deletions

View file

@ -1,3 +1,15 @@
Fri May 23 04:22:19 2008 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/tcltklib.c, ext/tk/tkutil/tkutil.c: fix memory leak.
* ext/tk/lib/tk.rb: avoid trouble when finalize TclTkIp.
* ext/tk/lib/tk.rb, ext/tk/lib/tk/*: help to fix troubles when
use Ttk widgets on old Tk scripts.
* ext/tk/sample/*: update and add demo stcipts. some of them are
introduction about new features of Tcl/Tk8.5.
Fri May 23 03:48:10 2008 Akinori MUSHA <knu@iDaemons.org> Fri May 23 03:48:10 2008 Akinori MUSHA <knu@iDaemons.org>
* class.c (clone_method): Just use ruby_cref as cref. * class.c (clone_method): Just use ruby_cref as cref.

View file

@ -2431,7 +2431,7 @@ class MultiTkIp
def mainloop(check_root = true, restart_on_dead = true) def mainloop(check_root = true, restart_on_dead = true)
raise SecurityError, "no permission to manipulate" unless self.manipulable? raise SecurityError, "no permission to manipulate" unless self.manipulable?
unless WITH_RUBY_VM ### Ruby 1.9 !!!!!!!!!!! if WITH_RUBY_VM ### Ruby 1.9 !!!!!!!!!!!
return @interp_thread.value if @interp_thread return @interp_thread.value if @interp_thread
end end

View file

@ -1298,7 +1298,7 @@ module TkCore
}) << ' %W') }) << ' %W')
INTERP.add_tk_procs(TclTkLib::FINALIZE_PROC_NAME, '', INTERP.add_tk_procs(TclTkLib::FINALIZE_PROC_NAME, '',
"bind all <#{WIDGET_DESTROY_HOOK}> {}") "catch { bind all <#{WIDGET_DESTROY_HOOK}> {} }")
INTERP.add_tk_procs('rb_out', 'ns args', <<-'EOL') INTERP.add_tk_procs('rb_out', 'ns args', <<-'EOL')
if [regexp {^::} $ns] { if [regexp {^::} $ns] {
@ -3245,11 +3245,13 @@ module TkTreatFont
next next
else else
fnt = hash_kv(fnt) if fnt.kind_of?(Hash) fnt = hash_kv(fnt) if fnt.kind_of?(Hash)
unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
tk_call(*(__config_cmd << "-#{optkey}" << fnt))
else
begin begin
tk_call(*(__config_cmd << "-#{optkey}" << fnt)) tk_call(*(__config_cmd << "-#{optkey}" << fnt))
rescue => e rescue
unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ # ignore
fail e
end end
end end
end end
@ -3305,11 +3307,13 @@ module TkTreatFont
fobj = fontobj # create a new TkFont object fobj = fontobj # create a new TkFont object
else else
ltn = hash_kv(ltn) if ltn.kind_of?(Hash) ltn = hash_kv(ltn) if ltn.kind_of?(Hash)
unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
tk_call(*(__config_cmd << "-#{optkey}" << ltn))
else
begin begin
tk_call(*(__config_cmd << "-#{optkey}" << ltn)) tk_call(*(__config_cmd << "-#{optkey}" << ltn))
rescue => e rescue => e
unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ # ignore
fail e
end end
end end
next next
@ -3363,11 +3367,13 @@ module TkTreatFont
fobj = fontobj # create a new TkFont object fobj = fontobj # create a new TkFont object
else else
knj = hash_kv(knj) if knj.kind_of?(Hash) knj = hash_kv(knj) if knj.kind_of?(Hash)
unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
tk_call(*(__config_cmd << "-#{optkey}" << knj))
else
begin begin
tk_call(*(__config_cmd << "-#{optkey}" << knj)) tk_call(*(__config_cmd << "-#{optkey}" << knj))
rescue => e rescue => e
unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ # ignore
fail e
end end
end end
next next
@ -3499,6 +3505,11 @@ module TkConfigMethod
end end
private :__configinfo_struct private :__configinfo_struct
def __optkey_aliases
{}
end
private :__optkey_aliases
def __numval_optkeys def __numval_optkeys
[] []
end end
@ -3613,6 +3624,11 @@ module TkConfigMethod
fail ArgumentError, "Invalid option `#{orig_slot.inspect}'" fail ArgumentError, "Invalid option `#{orig_slot.inspect}'"
end end
alias_name, real_name = __optkey_aliases.find{|k, v| k.to_s == slot}
if real_name
slot = real_name.to_s
end
if ( method = _symbolkey2str(__val2ruby_optkeys())[slot] ) if ( method = _symbolkey2str(__val2ruby_optkeys())[slot] )
optval = tk_call_without_enc(*(__cget_cmd << "-#{slot}")) optval = tk_call_without_enc(*(__cget_cmd << "-#{slot}"))
begin begin
@ -3687,14 +3703,35 @@ module TkConfigMethod
unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
__cget_core(slot) __cget_core(slot)
else else
__cget_core(slot) rescue nil begin
__cget_core(slot)
rescue => e
if current_configinfo.has_key?(slot.to_s)
# error on known option
fail e
else
# unknown option
nil
end end
end end
end
end
def cget_strict(slot)
# never use TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
__cget_core(slot)
end
def __configure_core(slot, value=None) def __configure_core(slot, value=None)
if slot.kind_of? Hash if slot.kind_of? Hash
slot = _symbolkey2str(slot) slot = _symbolkey2str(slot)
__optkey_aliases.each{|alias_name, real_name|
alias_name = alias_name.to_s
if slot.has_key?(alias_name)
slot[real_name.to_s] = slot.delete(alias_name)
end
}
__methodcall_optkeys.each{|key, method| __methodcall_optkeys.each{|key, method|
value = slot.delete(key.to_s) value = slot.delete(key.to_s)
self.__send__(method, value) if value self.__send__(method, value) if value
@ -3731,6 +3768,11 @@ module TkConfigMethod
fail ArgumentError, "Invalid option `#{orig_slot.inspect}'" fail ArgumentError, "Invalid option `#{orig_slot.inspect}'"
end end
alias_name, real_name = __optkey_aliases.find{|k, v| k.to_s == slot}
if real_name
slot = real_name.to_s
end
if ( conf = __keyonly_optkeys.find{|k, v| k.to_s == slot} ) if ( conf = __keyonly_optkeys.find{|k, v| k.to_s == slot} )
defkey, undefkey = conf defkey, undefkey = conf
if value if value
@ -3782,7 +3824,17 @@ module TkConfigMethod
__configure_core(slot) unless slot.empty? __configure_core(slot) unless slot.empty?
end end
else else
__configure_core(slot, value) rescue nil begin
__configure_core(slot, value)
rescue => e
if current_configinfo.has_key?(slot.to_s)
# error on known option
fail e
else
# unknown option
nil
end
end
end end
end end
self self
@ -3818,6 +3870,12 @@ module TkConfigMethod
else else
if slot if slot
slot = slot.to_s slot = slot.to_s
alias_name, real_name = __optkey_aliases.find{|k, v| k.to_s == slot}
if real_name
slot = real_name.to_s
end
case slot case slot
when /^(#{__val2ruby_optkeys().keys.join('|')})$/ when /^(#{__val2ruby_optkeys().keys.join('|')})$/
method = _symbolkey2str(__val2ruby_optkeys())[slot] method = _symbolkey2str(__val2ruby_optkeys())[slot]
@ -4191,6 +4249,12 @@ module TkConfigMethod
else else
if slot if slot
slot = slot.to_s slot = slot.to_s
alias_name, real_name = __optkey_aliases.find{|k, v| k.to_s == slot}
if real_name
slot = real_name.to_s
end
case slot case slot
when /^(#{__val2ruby_optkeys().keys.join('|')})$/ when /^(#{__val2ruby_optkeys().keys.join('|')})$/
method = _symbolkey2str(__val2ruby_optkeys())[slot] method = _symbolkey2str(__val2ruby_optkeys())[slot]
@ -4786,6 +4850,13 @@ class TkWindow<TkObject
fontkeys[fkey] = keys.delete(fkey) if keys.key?(fkey) fontkeys[fkey] = keys.delete(fkey) if keys.key?(fkey)
} }
__optkey_aliases.each{|alias_name, real_name|
alias_name = alias_name.to_s
if keys.has_key?(alias_name)
keys[real_name.to_s] = keys.delete(alias_name)
end
}
__methodcall_optkeys.each{|key| __methodcall_optkeys.each{|key|
key = key.to_s key = key.to_s
methodkeys[key] = keys.delete(key) if keys.key?(key) methodkeys[key] = keys.delete(key) if keys.key?(key)
@ -4823,15 +4894,20 @@ class TkWindow<TkObject
else else
begin begin
tk_call_without_enc(cmd, @path, *hash_kv(keys, true)) tk_call_without_enc(cmd, @path, *hash_kv(keys, true))
rescue rescue => e
tk_call_without_enc(cmd, @path) tk_call_without_enc(cmd, @path)
keys = __check_available_configure_options(keys) keys = __check_available_configure_options(keys)
unless keys.empty? unless keys.empty?
begin
# try to configure
configure(keys)
rescue
# fail => includes options adaptable when creattion only?
begin begin
tk_call_without_enc('destroy', @path) tk_call_without_enc('destroy', @path)
rescue rescue
# cannot destroy # cannot rescue options error
configure(keys) fail e
else else
# re-create widget # re-create widget
tk_call_without_enc(cmd, @path, *hash_kv(keys, true)) tk_call_without_enc(cmd, @path, *hash_kv(keys, true))
@ -4839,6 +4915,7 @@ class TkWindow<TkObject
end end
end end
end end
end
else else
tk_call_without_enc(cmd, @path) tk_call_without_enc(cmd, @path)
end end
@ -5389,7 +5466,7 @@ TkWidget = TkWindow
#Tk.freeze #Tk.freeze
module Tk module Tk
RELEASE_DATE = '2008-05-16'.freeze RELEASE_DATE = '2008-05-23'.freeze
autoload :AUTO_PATH, 'tk/variable' autoload :AUTO_PATH, 'tk/variable'
autoload :TCL_PACKAGE_PATH, 'tk/variable' autoload :TCL_PACKAGE_PATH, 'tk/variable'

View file

@ -168,6 +168,8 @@ class Tk::Canvas<TkWindow
#tk_tcl2ruby(tk_send_without_enc('canvasy', screen_y, *args)) #tk_tcl2ruby(tk_send_without_enc('canvasy', screen_y, *args))
number(tk_send_without_enc('canvasy', screen_y, *args)) number(tk_send_without_enc('canvasy', screen_y, *args))
end end
alias canvas_x canvasx
alias canvas_y canvasy
def coords(tag, *args) def coords(tag, *args)
if args == [] if args == []
@ -642,6 +644,13 @@ class TkcItem<TkObject
fontkeys[fkey] = keys.delete(fkey) if keys.key?(fkey) fontkeys[fkey] = keys.delete(fkey) if keys.key?(fkey)
} }
__item_optkey_aliases(nil).each{|alias_name, real_name|
alias_name = alias_name.to_s
if keys.has_key?(alias_name)
keys[real_name.to_s] = keys.delete(alias_name)
end
}
__item_methodcall_optkeys(nil).each{|key| __item_methodcall_optkeys(nil).each{|key|
key = key.to_s key = key.to_s
methodkeys[key] = keys.delete(key) if keys.key?(key) methodkeys[key] = keys.delete(key) if keys.key?(key)

View file

@ -63,6 +63,9 @@ module TkcTagAccess
def cget(option) def cget(option)
@c.itemcget(@id, option) @c.itemcget(@id, option)
end end
def cget_strict(option)
@c.itemcget_strict(@id, option)
end
def configure(key, value=None) def configure(key, value=None)
@c.itemconfigure(@id, key, value) @c.itemconfigure(@id, key, value)

View file

@ -181,6 +181,57 @@ module TkComposite
delegate_alias(option, option, *wins) delegate_alias(option, option, *wins)
end end
def __cget_delegates(slot)
slot = slot.to_s
if @option_methods.include?(slot)
if @option_methods[slot][:cget]
return self.__send__(@option_methods[slot][:cget])
else
if @option_setting[slot]
return @option_setting[slot]
else
return ''
end
end
end
tbl = @delegates[slot]
tbl = @delegates['DEFAULT'] unless tbl
begin
if tbl
opt, wins = tbl[-1]
opt = slot if opt == 'DEFAULT'
if wins && wins[-1]
# return wins[-1].cget(opt)
return wins[-1].cget_strict(opt)
end
end
rescue
end
return None
end
private :__cget_delegates
def cget(slot)
if (ret = __cget_delegates(slot)) == None
super(slot)
else
ret
end
end
def cget_strict(slot)
if (ret = __cget_delegates(slot)) == None
super(slot)
else
ret
end
end
=begin
def cget(slot) def cget(slot)
slot = slot.to_s slot = slot.to_s
@ -212,6 +263,7 @@ module TkComposite
super(slot) super(slot)
end end
=end
def configure(slot, value=None) def configure(slot, value=None)
if slot.kind_of? Hash if slot.kind_of? Hash

View file

@ -156,7 +156,7 @@ class TkPhotoImage<TkImage
self self
end end
def cget(option) def cget_strict(option)
case option.to_s case option.to_s
when 'data', 'file' when 'data', 'file'
tk_send 'cget', '-' << option.to_s tk_send 'cget', '-' << option.to_s
@ -164,6 +164,23 @@ class TkPhotoImage<TkImage
tk_tcl2ruby(tk_send('cget', '-' << option.to_s)) tk_tcl2ruby(tk_send('cget', '-' << option.to_s))
end end
end end
def cget(option)
unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
cget_strict(option)
else
begin
cget_strict(option)
rescue => e
if current_configinfo.has_key?(option.to_s)
# error on known option
fail e
else
# unknown option
nil
end
end
end
end
def copy(src, *opts) def copy(src, *opts)
if opts.size == 0 if opts.size == 0

View file

@ -8,6 +8,11 @@ require 'tk/itemfont.rb'
module TkItemConfigOptkeys module TkItemConfigOptkeys
include TkUtil include TkUtil
def __item_optkey_aliases(id)
{}
end
private :__item_optkey_aliases
def __item_numval_optkeys(id) def __item_numval_optkeys(id)
[] []
end end
@ -165,6 +170,11 @@ module TkItemConfigMethod
fail ArgumentError, "Invalid option `#{orig_opt.inspect}'" fail ArgumentError, "Invalid option `#{orig_opt.inspect}'"
end end
alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == option}
if real_name
option = real_name.to_s
end
if ( method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[option] ) if ( method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[option] )
optval = tk_call_without_enc(*(__item_cget_cmd(tagid(tagOrId)) << "-#{option}")) optval = tk_call_without_enc(*(__item_cget_cmd(tagid(tagOrId)) << "-#{option}"))
begin begin
@ -242,20 +252,35 @@ module TkItemConfigMethod
__itemcget_core(tagOrId, option) __itemcget_core(tagOrId, option)
rescue => e rescue => e
begin begin
__itemcget_core(tagOrId) if __current_itemconfiginfo(tagOrId).has_key?(option.to_s)
# not tag error -> option is unknown # not tag error & option is known -> error on known option
fail e
else
# not tag error & option is unknown
nil nil
end
rescue rescue
fail e # tag error fail e # tag error
end end
end end
end end
end end
def itemcget_strict(tagOrId, option)
# never use TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
__itemcget_core(tagOrId, option)
end
def __itemconfigure_core(tagOrId, slot, value=None) def __itemconfigure_core(tagOrId, slot, value=None)
if slot.kind_of? Hash if slot.kind_of? Hash
slot = _symbolkey2str(slot) slot = _symbolkey2str(slot)
__item_optkey_aliases(tagid(tagOrId)).each{|alias_name, real_name|
alias_name = alias_name.to_s
if slot.has_key?(alias_name)
slot[real_name.to_s] = slot.delete(alias_name)
end
}
__item_methodcall_optkeys(tagid(tagOrId)).each{|key, method| __item_methodcall_optkeys(tagid(tagOrId)).each{|key, method|
value = slot.delete(key.to_s) value = slot.delete(key.to_s)
self.__send__(method, tagOrId, value) if value self.__send__(method, tagOrId, value) if value
@ -292,6 +317,11 @@ module TkItemConfigMethod
fail ArgumentError, "Invalid option `#{orig_slot.inspect}'" fail ArgumentError, "Invalid option `#{orig_slot.inspect}'"
end end
alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot}
if real_name
slot = real_name.to_s
end
if ( conf = __item_keyonly_optkeys(tagid(tagOrId)).find{|k, v| k.to_s == slot } ) if ( conf = __item_keyonly_optkeys(tagid(tagOrId)).find{|k, v| k.to_s == slot } )
defkey, undefkey = conf defkey, undefkey = conf
if value if value
@ -350,8 +380,13 @@ module TkItemConfigMethod
__itemconfigure_core(tagOrId, slot, value) __itemconfigure_core(tagOrId, slot, value)
rescue => e rescue => e
begin begin
__itemconfiginfo_core(tagOrId) if __current_itemconfiginfo(tagOrId).has_key?(slot.to_s)
# not tag error -> option is unknown # not tag error & option is known -> error on known option
fail e
else
# not tag error & option is unknown
nil
end
rescue rescue
fail e # tag error fail e # tag error
end end
@ -386,6 +421,12 @@ module TkItemConfigMethod
else else
if slot if slot
slot = slot.to_s slot = slot.to_s
alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot}
if real_name
slot = real_name.to_s
end
case slot case slot
when /^(#{__item_val2ruby_optkeys(tagid(tagOrId)).keys.join('|')})$/ when /^(#{__item_val2ruby_optkeys(tagid(tagOrId)).keys.join('|')})$/
method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[slot] method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[slot]
@ -757,6 +798,12 @@ module TkItemConfigMethod
else else
if slot if slot
slot = slot.to_s slot = slot.to_s
alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot}
if real_name
slot = real_name.to_s
end
case slot case slot
when /^(#{__item_val2ruby_optkeys(tagid(tagOrId)).keys.join('|')})$/ when /^(#{__item_val2ruby_optkeys(tagid(tagOrId)).keys.join('|')})$/
method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[slot] method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[slot]

View file

@ -93,12 +93,15 @@ module TkTreatItemFont
fnt.call_font_configure([pathname, optkey], fnt.call_font_configure([pathname, optkey],
*(__item_config_cmd(tagid(tagOrId)) << {})) *(__item_config_cmd(tagid(tagOrId)) << {}))
next next
else
fnt = hash_kv(fnt) if fnt.kind_of?(Hash)
unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << fnt))
else else
begin begin
tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << fnt)) tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << fnt))
rescue => e rescue => e
unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ # ignore
fail e
end end
end end
end end
@ -152,12 +155,15 @@ module TkTreatItemFont
fobj = TkFont.new(fobj) # create a new TkFont object fobj = TkFont.new(fobj) # create a new TkFont object
elsif Tk::JAPANIZED_TK elsif Tk::JAPANIZED_TK
fobj = fontobj # create a new TkFont object fobj = fontobj # create a new TkFont object
else
ltn = hash_kv(ltn) if ltn.kind_of?(Hash)
unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << ltn))
else else
begin begin
tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << ltn)) tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << ltn))
rescue => e rescue => e
unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ # ignore
fail e
end end
end end
next next
@ -209,12 +215,15 @@ module TkTreatItemFont
fobj = TkFont.new(fobj) # create a new TkFont object fobj = TkFont.new(fobj) # create a new TkFont object
elsif Tk::JAPANIZED_TK elsif Tk::JAPANIZED_TK
fobj = fontobj # create a new TkFont object fobj = fontobj # create a new TkFont object
else
knj = hash_kv(knj) if knj.kind_of?(Hash)
unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << knj))
else else
begin begin
tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << knj)) tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << knj))
rescue => e rescue => e
unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ # ignore
fail e
end end
end end
next next

View file

@ -34,12 +34,13 @@ module TkMenuEntryConfig
private :__item_val2ruby_optkeys private :__item_val2ruby_optkeys
alias entrycget itemcget alias entrycget itemcget
alias entrycget_strict itemcget_strict
alias entryconfigure itemconfigure alias entryconfigure itemconfigure
alias entryconfiginfo itemconfiginfo alias entryconfiginfo itemconfiginfo
alias current_entryconfiginfo current_itemconfiginfo alias current_entryconfiginfo current_itemconfiginfo
private :itemcget, :itemconfigure private :itemcget, :itemcget_strict
private :itemconfiginfo, :current_itemconfiginfo private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
end end
class Tk::Menu<TkWindow class Tk::Menu<TkWindow
@ -518,7 +519,7 @@ class Tk::Menubutton<Tk::Label
tk_call_without_enc(self.class::TkCommandNames[0], @path) tk_call_without_enc(self.class::TkCommandNames[0], @path)
keys = __check_available_configure_options(keys) keys = __check_available_configure_options(keys)
unless keys.empty? unless keys.empty?
tk_call_without_enc('destroy', @path) tk_call_without_enc('destroy', @path) rescue nil
tk_call_without_enc(self.class::TkCommandNames[0], @path, tk_call_without_enc(self.class::TkCommandNames[0], @path,
*hash_kv(keys, true)) *hash_kv(keys, true))
end end
@ -642,6 +643,9 @@ class Tk::OptionMenubutton<Tk::Menubutton
def menucget(key) def menucget(key)
@menu.cget(key) @menu.cget(key)
end end
def menucget_strict(key)
@menu.cget_strict(key)
end
def menuconfigure(key, val=None) def menuconfigure(key, val=None)
@menu.configure(key, val) @menu.configure(key, val)
self self
@ -655,6 +659,9 @@ class Tk::OptionMenubutton<Tk::Menubutton
def entrycget(index, key) def entrycget(index, key)
@menu.entrycget(index, key) @menu.entrycget(index, key)
end end
def entrycget_strict(index, key)
@menu.entrycget_strict(index, key)
end
def entryconfigure(index, key, val=None) def entryconfigure(index, key, val=None)
@menu.entryconfigure(index, key, val) @menu.entryconfigure(index, key, val)
self self

View file

@ -83,6 +83,20 @@ class TkNamespace < TkObject
super(slot) super(slot)
end end
end end
def cget_strict(slot)
if slot == :namespace || slot == 'namespace'
ns = super(slot)
Tk_Namespace_ID_TBL.mutex.synchronize{
if TkNamespace::Tk_Namespace_ID_TBL.key?(ns)
TkNamespace::Tk_Namespace_ID_TBL[ns]
else
ns
end
}
else
super(slot)
end
end
def configinfo(slot = nil) def configinfo(slot = nil)
if slot if slot

View file

@ -76,11 +76,32 @@ class Tk::PanedWindow<TkWindow
self self
end end
def panecget(win, key) def panecget_strict(win, key)
# win = win.epath if win.kind_of?(TkObject) # win = win.epath if win.kind_of?(TkObject)
win = _epath(win) win = _epath(win)
tk_tcl2ruby(tk_send_without_enc('panecget', win, "-#{key}")) tk_tcl2ruby(tk_send_without_enc('panecget', win, "-#{key}"))
end end
def panecget(win, key)
unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
panecget_strict(win, key)
else
begin
panecget_strict(win, key)
rescue => e
begin
if current_paneconfiginfo(win).has_key?(option.to_s)
# not tag error & option is known -> error on known option
fail e
else
# not tag error & option is unknown
nil
end
rescue
fail e # tag error
end
end
end
end
def paneconfigure(win, key, value=nil) def paneconfigure(win, key, value=nil)
# win = win.epath if win.kind_of?(TkObject) # win = win.epath if win.kind_of?(TkObject)

View file

@ -32,6 +32,9 @@ module TkTextTagConfig
def tag_cget(tagOrId, option) def tag_cget(tagOrId, option)
itemcget(['tag', tagOrId], option) itemcget(['tag', tagOrId], option)
end end
def tag_cget_strict(tagOrId, option)
itemcget_strict(['tag', tagOrId], option)
end
def tag_configure(tagOrId, slot, value=None) def tag_configure(tagOrId, slot, value=None)
itemconfigure(['tag', tagOrId], slot, value) itemconfigure(['tag', tagOrId], slot, value)
end end
@ -45,6 +48,9 @@ module TkTextTagConfig
def window_cget(tagOrId, option) def window_cget(tagOrId, option)
itemcget(['window', tagOrId], option) itemcget(['window', tagOrId], option)
end end
def window_cget_strict(tagOrId, option)
itemcget_strict(['window', tagOrId], option)
end
def window_configure(tagOrId, slot, value=None) def window_configure(tagOrId, slot, value=None)
itemconfigure(['window', tagOrId], slot, value) itemconfigure(['window', tagOrId], slot, value)
end end
@ -55,8 +61,8 @@ module TkTextTagConfig
current_itemconfiginfo(['window', tagOrId], slot) current_itemconfiginfo(['window', tagOrId], slot)
end end
private :itemcget, :itemconfigure private :itemcget, :itemcget_strict
private :itemconfiginfo, :current_itemconfiginfo private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
end end
class Tk::Text<TkTextWin class Tk::Text<TkTextWin
@ -403,7 +409,7 @@ class Tk::Text<TkTextWin
end end
alias previous_mark mark_previous alias previous_mark mark_previous
def image_cget(index, slot) def image_cget_strict(index, slot)
case slot.to_s case slot.to_s
when 'text', 'label', 'show', 'data', 'file' when 'text', 'label', 'show', 'data', 'file'
_fromUTF8(tk_send_without_enc('image', 'cget', _fromUTF8(tk_send_without_enc('image', 'cget',
@ -415,6 +421,28 @@ class Tk::Text<TkTextWin
end end
end end
def image_cget(index, slot)
unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
image_cget_strict(index, slot)
else
begin
image_cget_strict(index, slot)
rescue => e
begin
if current_image_configinfo(index).has_key?(slot.to_s)
# not tag error & option is known -> error on known option
fail e
else
# not tag error & option is unknown
nil
end
rescue
fail e # tag error
end
end
end
end
def image_configure(index, slot, value=None) def image_configure(index, slot, value=None)
if slot.kind_of?(Hash) if slot.kind_of?(Hash)
_fromUTF8(tk_send_without_enc('image', 'configure', _fromUTF8(tk_send_without_enc('image', 'configure',

View file

@ -52,6 +52,10 @@ class TkTextImage<TkObject
@t.image_cget(@index, slot) @t.image_cget(@index, slot)
end end
def cget_strict(slot)
@t.image_cget_strict(@index, slot)
end
def configure(slot, value=None) def configure(slot, value=None)
@t.image_configure(@index, slot, value) @t.image_configure(@index, slot, value)
self self

View file

@ -132,6 +132,9 @@ class TkTextTag<TkObject
def cget(key) def cget(key)
@t.tag_cget @id, key @t.tag_cget @id, key
end end
def cget_strict(key)
@t.tag_cget_strict @id, key
end
=begin =begin
def cget(key) def cget(key)
case key.to_s case key.to_s

View file

@ -72,6 +72,9 @@ class TkTextWindow<TkObject
def cget(slot) def cget(slot)
@t.window_cget(@index, slot) @t.window_cget(@index, slot)
end end
def cget_strict(slot)
@t.window_cget_strict(@index, slot)
end
def configure(slot, value=None) def configure(slot, value=None)
if slot.kind_of?(Hash) if slot.kind_of?(Hash)

View file

@ -85,6 +85,9 @@ module Tk::BLT
def axis_cget(id, option) def axis_cget(id, option)
ret = itemcget(['axis', tagid(id)], option) ret = itemcget(['axis', tagid(id)], option)
end end
def axis_cget_strict(id, option)
ret = itemcget_strict(['axis', tagid(id)], option)
end
def axis_configure(*args) def axis_configure(*args)
slot = args.pop slot = args.pop
if slot.kind_of?(Hash) if slot.kind_of?(Hash)
@ -118,6 +121,9 @@ module Tk::BLT
def crosshairs_cget(option) def crosshairs_cget(option)
itemcget('crosshairs', option) itemcget('crosshairs', option)
end end
def crosshairs_cget_strict(option)
itemcget_strict('crosshairs', option)
end
def crosshairs_configure(slot, value=None) def crosshairs_configure(slot, value=None)
itemconfigure('crosshairs', slot, value) itemconfigure('crosshairs', slot, value)
end end
@ -131,6 +137,9 @@ module Tk::BLT
def element_cget(id, option) def element_cget(id, option)
itemcget(['element', tagid(id)], option) itemcget(['element', tagid(id)], option)
end end
def element_cget_strict(id, option)
itemcget_strict(['element', tagid(id)], option)
end
def element_configure(*args) def element_configure(*args)
slot = args.pop slot = args.pop
if slot.kind_of?(Hash) if slot.kind_of?(Hash)
@ -152,6 +161,9 @@ module Tk::BLT
def bar_cget(id, option) def bar_cget(id, option)
itemcget(['bar', tagid(id)], option) itemcget(['bar', tagid(id)], option)
end end
def bar_cget_strict(id, option)
itemcget_strict(['bar', tagid(id)], option)
end
def bar_configure(*args) def bar_configure(*args)
slot = args.pop slot = args.pop
if slot.kind_of?(Hash) if slot.kind_of?(Hash)
@ -173,6 +185,9 @@ module Tk::BLT
def line_cget(id, option) def line_cget(id, option)
itemcget(['line', tagid(id)], option) itemcget(['line', tagid(id)], option)
end end
def line_cget_strict(id, option)
itemcget_strict(['line', tagid(id)], option)
end
def line_configure(*args) def line_configure(*args)
slot = args.pop slot = args.pop
if slot.kind_of?(Hash) if slot.kind_of?(Hash)
@ -194,6 +209,9 @@ module Tk::BLT
def gridline_cget(option) def gridline_cget(option)
itemcget('grid', option) itemcget('grid', option)
end end
def gridline_cget_strict(option)
itemcget_strict('grid', option)
end
def gridline_configure(slot, value=None) def gridline_configure(slot, value=None)
itemconfigure('grid', slot, value) itemconfigure('grid', slot, value)
end end
@ -207,6 +225,9 @@ module Tk::BLT
def legend_cget(option) def legend_cget(option)
itemcget('legend', option) itemcget('legend', option)
end end
def legend_cget_strict(option)
itemcget_strict('legend', option)
end
def legend_configure(slot, value=None) def legend_configure(slot, value=None)
itemconfigure('legend', slot, value) itemconfigure('legend', slot, value)
end end
@ -220,6 +241,9 @@ module Tk::BLT
def pen_cget(id, option) def pen_cget(id, option)
itemcget(['pen', tagid(id)], option) itemcget(['pen', tagid(id)], option)
end end
def pen_cget_strict(id, option)
itemcget_strict(['pen', tagid(id)], option)
end
def pen_configure(*args) def pen_configure(*args)
slot = args.pop slot = args.pop
if slot.kind_of?(Hash) if slot.kind_of?(Hash)
@ -241,6 +265,9 @@ module Tk::BLT
def postscript_cget(option) def postscript_cget(option)
itemcget('postscript', option) itemcget('postscript', option)
end end
def postscript_cget_strict(option)
itemcget_strict('postscript', option)
end
def postscript_configure(slot, value=None) def postscript_configure(slot, value=None)
itemconfigure('postscript', slot, value) itemconfigure('postscript', slot, value)
end end
@ -254,6 +281,9 @@ module Tk::BLT
def marker_cget(id, option) def marker_cget(id, option)
itemcget(['marker', tagid(id)], option) itemcget(['marker', tagid(id)], option)
end end
def marker_cget_strict(id, option)
itemcget_strict(['marker', tagid(id)], option)
end
def marker_configure(*args) def marker_configure(*args)
slot = args.pop slot = args.pop
if slot.kind_of?(Hash) if slot.kind_of?(Hash)
@ -273,11 +303,12 @@ module Tk::BLT
end end
alias __itemcget itemcget alias __itemcget itemcget
alias __itemcget_strict itemcget_strict
alias __itemconfiginfo itemconfiginfo alias __itemconfiginfo itemconfiginfo
alias __current_itemconfiginfo current_itemconfiginfo alias __current_itemconfiginfo current_itemconfiginfo
private :__itemcget, :__itemconfiginfo, :__current_itemconfiginfo private :__itemcget, :__itemconfiginfo, :__current_itemconfiginfo
def itemcget(tagOrId, option) def itemcget_strict(tagOrId, option)
ret = __itemcget(tagid(tagOrId), option) ret = __itemcget(tagid(tagOrId), option)
if option == 'bindtags' || option == :bindtags if option == 'bindtags' || option == :bindtags
ret.collect{|tag| TkBindTag.id2obj(tag)} ret.collect{|tag| TkBindTag.id2obj(tag)}
@ -285,6 +316,27 @@ module Tk::BLT
ret ret
end end
end end
def itemcget(tagOrId, option)
unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
itemcget_strict(tagOrId, option)
else
begin
itemcget_strict(tagOrId, option)
rescue => e
begin
if current_itemconfiginfo(tagOrId).has_key?(option.to_s)
# error on known option
fail e
else
# unknown option
nil
end
rescue
fail e # tag error
end
end
end
end
def itemconfiginfo(tagOrId, slot = nil) def itemconfiginfo(tagOrId, slot = nil)
ret = __itemconfiginfo(tagid(tagOrId), slot) ret = __itemconfiginfo(tagid(tagOrId), slot)
@ -321,8 +373,8 @@ module Tk::BLT
ret ret
end end
private :itemcget, :itemconfigure private :itemcget, :itemcget_strict
private :itemconfiginfo, :current_itemconfiginfo private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
################# #################
@ -428,6 +480,9 @@ module Tk::BLT
def cget(option) def cget(option)
@chart.axis_cget(@id, option) @chart.axis_cget(@id, option)
end end
def cget_strict(option)
@chart.axis_cget_strict(@id, option)
end
def configure(key, value=None) def configure(key, value=None)
@chart.axis_configure(@id, key, value) @chart.axis_configure(@id, key, value)
self self
@ -530,6 +585,9 @@ module Tk::BLT
def cget(option) def cget(option)
@chart.crosshair_cget(option) @chart.crosshair_cget(option)
end end
def cget_strict(option)
@chart.crosshair_cget_strict(option)
end
def configure(key, value=None) def configure(key, value=None)
@chart.crosshair_configure(key, value) @chart.crosshair_configure(key, value)
self self
@ -675,6 +733,9 @@ module Tk::BLT
# @chart.element_cget(@id, option) # @chart.element_cget(@id, option)
@chart.__send__(@typename + '_cget', @id, option) @chart.__send__(@typename + '_cget', @id, option)
end end
def cget_strict(option)
@chart.__send__(@typename + '_cget_strict', @id, option)
end
def configure(key, value=None) def configure(key, value=None)
# @chart.element_configure(@id, key, value) # @chart.element_configure(@id, key, value)
@chart.__send__(@typename + '_configure', @id, key, value) @chart.__send__(@typename + '_configure', @id, key, value)
@ -775,6 +836,9 @@ module Tk::BLT
def cget(option) def cget(option)
@chart.gridline_cget(option) @chart.gridline_cget(option)
end end
def cget_strict(option)
@chart.gridline_cget_strict(option)
end
def configure(key, value=None) def configure(key, value=None)
@chart.gridline_configure(key, value) @chart.gridline_configure(key, value)
self self
@ -846,6 +910,9 @@ module Tk::BLT
def cget(option) def cget(option)
@chart.legend_cget(option) @chart.legend_cget(option)
end end
def cget_strict(option)
@chart.legend_cget_strict(option)
end
def configure(key, value=None) def configure(key, value=None)
@chart.legend_configure(key, value) @chart.legend_configure(key, value)
self self
@ -972,6 +1039,9 @@ module Tk::BLT
def cget(option) def cget(option)
@chart.pen_cget(@id, option) @chart.pen_cget(@id, option)
end end
def cget_strict(option)
@chart.pen_cget_strict(@id, option)
end
def configure(key, value=None) def configure(key, value=None)
@chart.pen_configure(@id, key, value) @chart.pen_configure(@id, key, value)
self self
@ -1039,6 +1109,9 @@ module Tk::BLT
def cget(option) def cget(option)
@chart.postscript_cget(option) @chart.postscript_cget(option)
end end
def cget_strict(option)
@chart.postscript_cget_strict(option)
end
def configure(key, value=None) def configure(key, value=None)
@chart.postscript_configure(key, value) @chart.postscript_configure(key, value)
self self
@ -1117,6 +1190,13 @@ module Tk::BLT
fontkeys[fkey] = keys.delete(fkey) if keys.key?(fkey) fontkeys[fkey] = keys.delete(fkey) if keys.key?(fkey)
} }
__item_optkey_aliases(nil).each{|alias_name, real_name|
alias_name = alias_name.to_s
if keys.has_key?(alias_name)
keys[real_name.to_s] = keys.delete(alias_name)
end
}
__item_methodcall_optkeys(nil).each{|key| __item_methodcall_optkeys(nil).each{|key|
key = key.to_s key = key.to_s
methodkeys[key] = keys.delete(key) if keys.key?(key) methodkeys[key] = keys.delete(key) if keys.key?(key)
@ -1192,6 +1272,9 @@ module Tk::BLT
def cget(option) def cget(option)
@chart.marker_cget(@id, option) @chart.marker_cget(@id, option)
end end
def cget_strict(option)
@chart.marker_cget_strict(@id, option)
end
def configure(key, value=None) def configure(key, value=None)
@chart.marker_configure(@id, key, value) @chart.marker_configure(@id, key, value)
self self
@ -1774,6 +1857,9 @@ module Tk::BLT
def xaxis_cget(option) def xaxis_cget(option)
itemcget('xaxis', option) itemcget('xaxis', option)
end end
def xaxis_cget_strict(option)
itemcget_strict('xaxis', option)
end
def xaxis_configure(slot, value=None) def xaxis_configure(slot, value=None)
if slot.kind_of?(Hash) if slot.kind_of?(Hash)
slot = _symbolkey2str(slot) slot = _symbolkey2str(slot)
@ -1843,6 +1929,9 @@ module Tk::BLT
def x2axis_cget(option) def x2axis_cget(option)
itemcget('x2axis', option) itemcget('x2axis', option)
end end
def x2axis_cget_strict(option)
itemcget_strict('x2axis', option)
end
def x2axis_configure(slot, value=None) def x2axis_configure(slot, value=None)
if slot.kind_of?(Hash) if slot.kind_of?(Hash)
slot = _symbolkey2str(slot) slot = _symbolkey2str(slot)
@ -1912,6 +2001,9 @@ module Tk::BLT
def yaxis_cget(option) def yaxis_cget(option)
itemcget('yaxis', option) itemcget('yaxis', option)
end end
def yaxis_cget_strict(option)
itemcget_strict('yaxis', option)
end
def yaxis_configure(slot, value=None) def yaxis_configure(slot, value=None)
if slot.kind_of?(Hash) if slot.kind_of?(Hash)
slot = _symbolkey2str(slot) slot = _symbolkey2str(slot)
@ -1981,6 +2073,9 @@ module Tk::BLT
def y2axis_cget(option) def y2axis_cget(option)
itemcget('y2axis', option) itemcget('y2axis', option)
end end
def y2axis_cget_strict(option)
itemcget_strict('y2axis', option)
end
def y2axis_configure(slot, value=None) def y2axis_configure(slot, value=None)
if slot.kind_of?(Hash) if slot.kind_of?(Hash)
slot = _symbolkey2str(slot) slot = _symbolkey2str(slot)

View file

@ -22,6 +22,7 @@ module Tk::BLT
WidgetClassNames[WidgetClassName] = self WidgetClassNames[WidgetClassName] = self
alias window_cget itemcget alias window_cget itemcget
alias window_cget_strict itemcget_strict
alias window_configure itemconfigure alias window_configure itemconfigure
alias window_configuinfo itemconfiginfo alias window_configuinfo itemconfiginfo
alias current_window_configuinfo current_itemconfiginfo alias current_window_configuinfo current_itemconfiginfo

View file

@ -29,6 +29,9 @@ module Tk::BLT
def blt_table_cget(*args) def blt_table_cget(*args)
Tk::BLT::Table.cget(self, *args) Tk::BLT::Table.cget(self, *args)
end end
def blt_table_cget_strict(*args)
Tk::BLT::Table.cget_strict(self, *args)
end
def blt_table_configure(*args) def blt_table_configure(*args)
Tk::BLT::Table.configure(self, *args) Tk::BLT::Table.configure(self, *args)
@ -92,6 +95,9 @@ module Tk::BLT
def blt_table_itemcget(*args) def blt_table_itemcget(*args)
Tk::BLT::Table.itemcget(self, *args) Tk::BLT::Table.itemcget(self, *args)
end end
def blt_table_itemcget_strict(*args)
Tk::BLT::Table.itemcget_strict(self, *args)
end
def blt_table_itemconfigure(*args) def blt_table_itemconfigure(*args)
Tk::BLT::Table.itemconfigure(self, *args) Tk::BLT::Table.itemconfigure(self, *args)
@ -136,12 +142,13 @@ class << Tk::BLT::Table
private :__item_pathname private :__item_pathname
alias __itemcget itemcget alias __itemcget itemcget
alias __itemcget_strict itemcget_strict
alias __itemconfigure itemconfigure alias __itemconfigure itemconfigure
alias __itemconfiginfo itemconfiginfo alias __itemconfiginfo itemconfiginfo
alias __current_itemconfiginfo current_itemconfiginfo alias __current_itemconfiginfo current_itemconfiginfo
private :__itemcget, :__itemconfigure private :__itemcget, :__itemcget_strict
private :__itemconfiginfo, :__current_itemconfiginfo private :__itemconfigure, :__itemconfiginfo, :__current_itemconfiginfo
def __boolval_optkeys def __boolval_optkeys
super() << 'propagate' super() << 'propagate'
@ -176,6 +183,9 @@ class << Tk::BLT::Table
def cget(container, option) def cget(container, option)
__itemcget([container], option) __itemcget([container], option)
end end
def cget_strict(container, option)
__itemcget_strict([container], option)
end
def configure(container, *args) def configure(container, *args)
__itemconfigure([container], *args) __itemconfigure([container], *args)
@ -192,6 +202,9 @@ class << Tk::BLT::Table
def itemcget(container, item, option) def itemcget(container, item, option)
__itemcget([container, tagid(item)], option) __itemcget([container, tagid(item)], option)
end end
def itemcget_strict(container, item, option)
__itemcget_strict([container, tagid(item)], option)
end
def itemconfigure(container, *args) def itemconfigure(container, *args)
if args[-1].kind_of?(Hash) if args[-1].kind_of?(Hash)

View file

@ -128,6 +128,9 @@ module Tk::BLT
def cget(*args) def cget(*args)
@t.tab_cget(@id, *args) @t.tab_cget(@id, *args)
end end
def cget_strict(*args)
@t.tab_cget_strict(@id, *args)
end
def configure(*args) def configure(*args)
@t.tab_configure(@id, *args) @t.tab_configure(@id, *args)
end end
@ -240,6 +243,7 @@ module Tk::BLT
private :__item_pathname private :__item_pathname
alias tab_cget itemcget alias tab_cget itemcget
alias tab_cget_strict itemcget_strict
alias tab_configure itemconfigure alias tab_configure itemconfigure
alias tab_configinfo itemconfiginfo alias tab_configinfo itemconfiginfo
alias current_tab_configinfo current_itemconfiginfo alias current_tab_configinfo current_itemconfiginfo

View file

@ -30,12 +30,15 @@ module Tk::BLT
end end
private :__item_config_cmd private :__item_config_cmd
private :itemcget, :itemconfigure private :itemcget, :itemcget_strict
private :itemconfiginfo, :current_itemconfiginfo private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
def cget(master, option) def cget(master, option)
itemcget(master, option) itemcget(master, option)
end end
def cget_strict(master, option)
itemcget_strict(master, option)
end
def configure(master, slot, value=None) def configure(master, slot, value=None)
itemconfigure(master, slot, value) itemconfigure(master, slot, value)
end end

View file

@ -98,6 +98,9 @@ module Tk::BLT::Treeview::ConfigMethod
def column_cget(name, option) def column_cget(name, option)
itemcget(['column', name], option) itemcget(['column', name], option)
end end
def column_cget_strict(name, option)
itemcget_strict(['column', name], option)
end
def column_configure(name, slot, value=None) def column_configure(name, slot, value=None)
itemconfigure(['column', name], slot, value) itemconfigure(['column', name], slot, value)
end end
@ -111,6 +114,9 @@ module Tk::BLT::Treeview::ConfigMethod
def button_cget(option) def button_cget(option)
itemcget('button', option) itemcget('button', option)
end end
def button_cget_strict(option)
itemcget_strict('button', option)
end
def button_configure(slot, value=None) def button_configure(slot, value=None)
itemconfigure('button', slot, value) itemconfigure('button', slot, value)
end end
@ -129,6 +135,14 @@ module Tk::BLT::Treeview::ConfigMethod
ret ret
end end
end end
def entry_cget_strict(option)
ret = itemcget_strict('entry', option)
if option == 'bindtags' || option == :bindtags
ret.collect{|tag| TkBindTag.id2obj(tag)}
else
ret
end
end
def entry_configure(slot, value=None) def entry_configure(slot, value=None)
itemconfigure('entry', slot, value) itemconfigure('entry', slot, value)
end end
@ -170,6 +184,9 @@ module Tk::BLT::Treeview::ConfigMethod
def sort_cget(option) def sort_cget(option)
itemcget('sort', option) itemcget('sort', option)
end end
def sort_cget_strict(option)
itemcget_strict('sort', option)
end
def sort_configure(slot, value=None) def sort_configure(slot, value=None)
itemconfigure('sort', slot, value) itemconfigure('sort', slot, value)
end end
@ -183,6 +200,9 @@ module Tk::BLT::Treeview::ConfigMethod
def text_cget(option) def text_cget(option)
itemcget('text', option) itemcget('text', option)
end end
def text_cget_strict(option)
itemcget_strict('text', option)
end
def text_configure(slot, value=None) def text_configure(slot, value=None)
itemconfigure('text', slot, value) itemconfigure('text', slot, value)
end end
@ -193,8 +213,8 @@ module Tk::BLT::Treeview::ConfigMethod
current_itemconfiginfo('text', slot) current_itemconfiginfo('text', slot)
end end
private :itemcget, :itemconfigure private :itemcget, :itemcget_strict
private :itemconfiginfo, :current_itemconfiginfo private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
end end
class Tk::BLT::Treeview class Tk::BLT::Treeview

View file

@ -30,12 +30,15 @@ module Tk::BLT
end end
private :__item_config_cmd private :__item_config_cmd
private :itemcget, :itemconfigure private :itemcget, :itemcget_strict
private :itemconfiginfo, :current_itemconfiginfo private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
def cget(win, option) def cget(win, option)
itemcget(['cget', win], option) itemcget(['cget', win], option)
end end
def cget_strict(win, option)
itemcget_strict(['cget', win], option)
end
def configure(win, slot, value=None) def configure(win, slot, value=None)
itemconfigure(['configure', win], slot, value) itemconfigure(['configure', win], slot, value)
end end
@ -49,6 +52,9 @@ module Tk::BLT
def token_cget(win, option) def token_cget(win, option)
itemcget(['token', 'cget', win], option) itemcget(['token', 'cget', win], option)
end end
def token_cget_strict(win, option)
itemcget_strict(['token', 'cget', win], option)
end
def token_configure(win, slot, value=None) def token_configure(win, slot, value=None)
itemconfigure(['token', 'configure', win], slot, value) itemconfigure(['token', 'configure', win], slot, value)
end end

View file

@ -146,7 +146,7 @@ module Tk::BLT
end end
end end
end end
def cget(key) def cget_strict(key)
key = key.to_s key = key.to_s
begin begin
info.assoc(key)[1] info.assoc(key)[1]
@ -154,5 +154,22 @@ module Tk::BLT
fail ArgumentError, "unknown option '#{key}'" fail ArgumentError, "unknown option '#{key}'"
end end
end end
def cget(key)
unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
cget_strict(key)
else
begin
cget_strict(key)
rescue => e
if current_configinfo.has_key?(key.to_s)
# error on known option
fail e
else
# unknown option
nil
end
end
end
end
end end
end end

View file

@ -59,6 +59,13 @@ class Tk::BWidget::Dialog
end end
end end
def cget_strict(slot)
if slot.to_s == 'relative'
super('parent')
else
super(slot)
end
end
def cget(slot) def cget(slot)
if slot.to_s == 'relative' if slot.to_s == 'relative'
super('parent') super('parent')

View file

@ -34,6 +34,13 @@ module Tk::BWidget::DynamicHelp
['DynamicHelp::configure'] ['DynamicHelp::configure']
end end
def self.cget_strict(slot)
slot = slot.to_s
info = {}
self.current_configinfo.each{|k,v| info[k.to_s] = v if k.to_s == slot}
fail RuntimeError, "unknown option \"-#{slot}\"" if info.empty?
info.values[0]
end
def self.cget(slot) def self.cget(slot)
self.current_configinfo(slot).values[0] self.current_configinfo(slot).values[0]
end end

View file

@ -297,6 +297,9 @@ class Tk::BWidget::ListBox::Item
def cget(key) def cget(key)
@listbox.itemcget(@id, key) @listbox.itemcget(@id, key)
end end
def cget_strict(key)
@listbox.itemcget_strict(@id, key)
end
def configure(key, val=None) def configure(key, val=None)
@listbox.itemconfigure(@id, key, val) @listbox.itemconfigure(@id, key, val)

View file

@ -65,6 +65,17 @@ class Tk::BWidget::MessageDlg
end end
@keys[slot] @keys[slot]
end end
def cget_strict(slot)
slot = slot.to_s
if slot == 'relative'
slot = 'parent'
end
if winfo_exist?
val = super(slot)
@keys[slot] = val
end
@keys[slot]
end
def configure(slot, value=None) def configure(slot, value=None)
if winfo_exist? if winfo_exist?

View file

@ -358,6 +358,9 @@ class Tk::BWidget::Tree::Node
def cget(key) def cget(key)
@tree.itemcget(@id, key) @tree.itemcget(@id, key)
end end
def cget_strict(key)
@tree.itemcget_strict(@id, key)
end
def configure(key, val=None) def configure(key, val=None)
@tree.itemconfigure(@id, key, val) @tree.itemconfigure(@id, key, val)

View file

@ -29,6 +29,13 @@ module Tk::BWidget::Widget
['Widget::configure'] ['Widget::configure']
end end
def self.cget_strict(slot)
slot = slot.to_s
info = {}
self.current_configinfo.each{|k,v| info[k.to_s] = v if k.to_s == slot}
fail RuntimeError, "unknown option \"-#{slot}\"" if info.empty?
info.values[0]
end
def self.cget(slot) def self.cget(slot)
self.current_configinfo(slot).values[0] self.current_configinfo(slot).values[0]
end end
@ -105,9 +112,12 @@ module Tk::BWidget::Widget
tk_call('Widget::setoption', win, option, value) tk_call('Widget::setoption', win, option, value)
end end
def self.sub_cget(win, subwidget) def self.sub_cget_strict(win, subwidget)
tk_call('Widget::subcget', win, subwidget) tk_call('Widget::subcget', win, subwidget)
end end
def self.sub_cget(win, subwidget)
self.sub_cget_strict(win, subwidget)
end
def self.sync_options(klass, subclass, subpath, options) def self.sync_options(klass, subclass, subpath, options)
tk_call('Widget::syncoptions', klass, subclass, subpath, options) tk_call('Widget::syncoptions', klass, subclass, subpath, options)

View file

@ -47,12 +47,13 @@ class Tk::Iwidgets::Buttonbox
end end
alias buttoncget itemcget alias buttoncget itemcget
alias buttoncget_strict itemcget_strict
alias buttonconfigure itemconfigure alias buttonconfigure itemconfigure
alias buttonconfiginfo itemconfiginfo alias buttonconfiginfo itemconfiginfo
alias current_buttonconfiginfo current_itemconfiginfo alias current_buttonconfiginfo current_itemconfiginfo
private :itemcget, :itemconfigure private :itemcget, :itemcget_strict
private :itemconfiginfo, :current_itemconfiginfo private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
#################################### ####################################

View file

@ -47,12 +47,13 @@ class Tk::Iwidgets::Checkbox
end end
alias buttoncget itemcget alias buttoncget itemcget
alias buttoncget_strict itemcget_strict
alias buttonconfigure itemconfigure alias buttonconfigure itemconfigure
alias buttonconfiginfo itemconfiginfo alias buttonconfiginfo itemconfiginfo
alias current_buttonconfiginfo current_itemconfiginfo alias current_buttonconfiginfo current_itemconfiginfo
private :itemcget, :itemconfigure private :itemcget, :itemcget_strict
private :itemconfiginfo, :current_itemconfiginfo private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
#################################### ####################################

View file

@ -47,12 +47,13 @@ class Tk::Iwidgets::Dialogshell
end end
alias buttoncget itemcget alias buttoncget itemcget
alias buttoncget_strict itemcget_strict
alias buttonconfigure itemconfigure alias buttonconfigure itemconfigure
alias buttonconfiginfo itemconfiginfo alias buttonconfiginfo itemconfiginfo
alias current_buttonconfiginfo current_itemconfiginfo alias current_buttonconfiginfo current_itemconfiginfo
private :itemcget, :itemconfigure private :itemcget, :itemcget_strict
private :itemconfiginfo, :current_itemconfiginfo private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
#################################### ####################################

View file

@ -62,12 +62,13 @@ class Tk::Iwidgets::Menubar
end end
alias menucget itemcget alias menucget itemcget
alias menucget_strict itemcget_strict
alias menuconfigure itemconfigure alias menuconfigure itemconfigure
alias menuconfiginfo itemconfiginfo alias menuconfiginfo itemconfiginfo
alias current_menuconfiginfo current_itemconfiginfo alias current_menuconfiginfo current_itemconfiginfo
private :itemcget, :itemconfigure private :itemcget, :itemcget_strict
private :itemconfiginfo, :current_itemconfiginfo private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
#################################### ####################################

View file

@ -47,12 +47,13 @@ class Tk::Iwidgets::Messagebox
private :__item_boolval_optkeys private :__item_boolval_optkeys
alias typecget itemcget alias typecget itemcget
alias typecget_strict itemcget_strict
alias typeconfigure itemconfigure alias typeconfigure itemconfigure
alias typeconfiginfo itemconfiginfo alias typeconfiginfo itemconfiginfo
alias current_typeconfiginfo current_itemconfiginfo alias current_typeconfiginfo current_itemconfiginfo
private :itemcget, :itemconfigure private :itemcget, :itemcget_strict
private :itemconfiginfo, :current_itemconfiginfo private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
#################################### ####################################

View file

@ -42,12 +42,13 @@ class Tk::Iwidgets::Notebook
end end
alias pagecget itemcget alias pagecget itemcget
alias pagecget_strict itemcget_strict
alias pageconfigure itemconfigure alias pageconfigure itemconfigure
alias pageconfiginfo itemconfiginfo alias pageconfiginfo itemconfiginfo
alias current_pageconfiginfo current_itemconfiginfo alias current_pageconfiginfo current_itemconfiginfo
private :itemcget, :itemconfigure private :itemcget, :itemcget_strict
private :itemconfiginfo, :current_itemconfiginfo private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
#################################### ####################################

View file

@ -42,12 +42,13 @@ class Tk::Iwidgets::Panedwindow
end end
alias panecget itemcget alias panecget itemcget
alias panecget_strict itemcget_strict
alias paneconfigure itemconfigure alias paneconfigure itemconfigure
alias paneconfiginfo itemconfiginfo alias paneconfiginfo itemconfiginfo
alias current_paneconfiginfo current_itemconfiginfo alias current_paneconfiginfo current_itemconfiginfo
private :itemcget, :itemconfigure private :itemcget, :itemcget_strict
private :itemconfiginfo, :current_itemconfiginfo private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
#################################### ####################################

View file

@ -47,12 +47,13 @@ class Tk::Iwidgets::Radiobox
end end
alias buttoncget itemcget alias buttoncget itemcget
alias buttoncget_strict itemcget_strict
alias buttonconfigure itemconfigure alias buttonconfigure itemconfigure
alias buttonconfiginfo itemconfiginfo alias buttonconfiginfo itemconfiginfo
alias current_buttonconfiginfo current_itemconfiginfo alias current_buttonconfiginfo current_itemconfiginfo
private :itemcget, :itemconfigure private :itemcget, :itemcget_strict
private :itemconfiginfo, :current_itemconfiginfo private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
#################################### ####################################

View file

@ -116,7 +116,7 @@ class Tk::Iwidgets::Scrolledtext
get('-displaychars', *index) get('-displaychars', *index)
end end
def image_cget(index, slot) def image_cget_strict(index, slot)
case slot.to_s case slot.to_s
when 'text', 'label', 'show', 'data', 'file' when 'text', 'label', 'show', 'data', 'file'
_fromUTF8(tk_send_without_enc('image', 'cget', _fromUTF8(tk_send_without_enc('image', 'cget',
@ -127,6 +127,27 @@ class Tk::Iwidgets::Scrolledtext
"-#{slot}"))) "-#{slot}")))
end end
end end
def image_cget(index, slot)
unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
image_cget_strict(index, slot)
else
begin
image_cget_strict(index, slot)
rescue => e
begin
if current_image_configinfo.has_key?(slot.to_s)
# error on known option
fail e
else
# unknown option
nil
end
rescue
fail e # tag error
end
end
end
end
def image_configure(index, slot, value=None) def image_configure(index, slot, value=None)
if slot.kind_of? Hash if slot.kind_of? Hash

View file

@ -47,12 +47,13 @@ class Tk::Iwidgets::Tabnotebook
end end
alias pagecget itemcget alias pagecget itemcget
alias pagecget_strict itemcget_strict
alias pageconfigure itemconfigure alias pageconfigure itemconfigure
alias pageconfiginfo itemconfiginfo alias pageconfiginfo itemconfiginfo
alias current_pageconfiginfo current_itemconfiginfo alias current_pageconfiginfo current_itemconfiginfo
private :itemcget, :itemconfigure private :itemcget, :itemcget_strict
private :itemconfiginfo, :current_itemconfiginfo private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
#################################### ####################################

View file

@ -42,12 +42,13 @@ class Tk::Iwidgets::Tabset
end end
alias tabcget itemcget alias tabcget itemcget
alias tabcget_strict itemcget_strict
alias tabconfigure itemconfigure alias tabconfigure itemconfigure
alias tabconfiginfo itemconfiginfo alias tabconfiginfo itemconfiginfo
alias current_tabconfiginfo current_itemconfiginfo alias current_tabconfiginfo current_itemconfiginfo
private :itemcget, :itemconfigure private :itemcget, :itemcget_strict
private :itemconfiginfo, :current_itemconfiginfo private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
#################################### ####################################

View file

@ -87,7 +87,7 @@ class Tk::Tcllib::GetString_Dialog
@variable.value @variable.value
end end
def cget(slot) def cget_strict(slot)
slot = slot.to_s slot = slot.to_s
if slot == 'text' if slot == 'text'
@text @text
@ -95,6 +95,9 @@ class Tk::Tcllib::GetString_Dialog
@keys[slot] @keys[slot]
end end
end end
def cget(slot)
cget_strict(slot)
end
def configure(slot, value=None) def configure(slot, value=None)
if slot.kind_of?(Hash) if slot.kind_of?(Hash)

View file

@ -90,7 +90,7 @@ class Tk::Tcllib::Swaplist_Dialog
end end
alias selected value alias selected value
def cget(slot) def cget_strict(slot)
slot = slot.to_s slot = slot.to_s
if slot == 'complete_list' if slot == 'complete_list'
@complete_list @complete_list
@ -100,6 +100,9 @@ class Tk::Tcllib::Swaplist_Dialog
@keys[slot] @keys[slot]
end end
end end
def cget(slot)
cget_strict(slot)
end
def configure(slot, value=None) def configure(slot, value=None)
if slot.kind_of?(Hash) if slot.kind_of?(Hash)

View file

@ -70,6 +70,9 @@ module Tk::Tcllib::TablelistItemConfig
def cell_cget(tagOrId, option) def cell_cget(tagOrId, option)
itemcget(['cell', tagOrId], option) itemcget(['cell', tagOrId], option)
end end
def cell_cget_strict(tagOrId, option)
itemcget_strict(['cell', tagOrId], option)
end
def cell_configure(tagOrId, slot, value=None) def cell_configure(tagOrId, slot, value=None)
itemconfigure(['cell', tagOrId], slot, value) itemconfigure(['cell', tagOrId], slot, value)
end end
@ -80,6 +83,7 @@ module Tk::Tcllib::TablelistItemConfig
current_itemconfiginfo(['cell', tagOrId], slot) current_itemconfiginfo(['cell', tagOrId], slot)
end end
alias cellcget cell_cget alias cellcget cell_cget
alias cellcget_strict cell_cget_strict
alias cellconfigure cell_configure alias cellconfigure cell_configure
alias cellconfiginfo cell_configinfo alias cellconfiginfo cell_configinfo
alias current_cellconfiginfo current_cell_configinfo alias current_cellconfiginfo current_cell_configinfo
@ -87,6 +91,9 @@ module Tk::Tcllib::TablelistItemConfig
def column_cget(tagOrId, option) def column_cget(tagOrId, option)
itemcget(['column', tagOrId], option) itemcget(['column', tagOrId], option)
end end
def column_cget_strict(tagOrId, option)
itemcget_strict(['column', tagOrId], option)
end
def column_configure(tagOrId, slot, value=None) def column_configure(tagOrId, slot, value=None)
itemconfigure(['column', tagOrId], slot, value) itemconfigure(['column', tagOrId], slot, value)
end end
@ -97,6 +104,7 @@ module Tk::Tcllib::TablelistItemConfig
current_itemconfiginfo(['column', tagOrId], slot) current_itemconfiginfo(['column', tagOrId], slot)
end end
alias columncget column_cget alias columncget column_cget
alias columncget_strict column_cget_strict
alias columnconfigure column_configure alias columnconfigure column_configure
alias columnconfiginfo column_configinfo alias columnconfiginfo column_configinfo
alias current_columnconfiginfo current_column_configinfo alias current_columnconfiginfo current_column_configinfo
@ -104,6 +112,9 @@ module Tk::Tcllib::TablelistItemConfig
def row_cget(tagOrId, option) def row_cget(tagOrId, option)
itemcget(['row', tagOrId], option) itemcget(['row', tagOrId], option)
end end
def row_cget_strict(tagOrId, option)
itemcget_strict(['row', tagOrId], option)
end
def row_configure(tagOrId, slot, value=None) def row_configure(tagOrId, slot, value=None)
itemconfigure(['row', tagOrId], slot, value) itemconfigure(['row', tagOrId], slot, value)
end end
@ -114,12 +125,13 @@ module Tk::Tcllib::TablelistItemConfig
current_itemconfiginfo(['row', tagOrId], slot) current_itemconfiginfo(['row', tagOrId], slot)
end end
alias rowcget row_cget alias rowcget row_cget
alias rowcget_strict row_cget_strict
alias rowconfigure row_configure alias rowconfigure row_configure
alias rowconfiginfo row_configinfo alias rowconfiginfo row_configinfo
alias current_rowconfiginfo current_row_configinfo alias current_rowconfiginfo current_row_configinfo
private :itemcget, :itemconfigure private :itemcget, :itemcget_strict
private :itemconfiginfo, :current_itemconfiginfo private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
end end
class Tk::Tcllib::Tablelist class Tk::Tcllib::Tablelist

View file

@ -54,9 +54,21 @@ class Tk::Tile::Dialog
window(tk_call_without_enc('::ttk::dialog::clientframe', @path)) window(tk_call_without_enc('::ttk::dialog::clientframe', @path))
end end
def cget(slot) def cget_strict(slot)
@keys[slot] @keys[slot.to_s]
end end
def cget(slot)
@keys[slot.to_s]
end
=begin
def cget(slot)
unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
cget_strict(slot)
else
cget_strict(slot) rescue nil
end
end
=end
def configure(slot, value=None) def configure(slot, value=None)
if slot.kind_of?(Hash) if slot.kind_of?(Hash)

View file

@ -27,6 +27,11 @@ class Tk::Tile::TEntry < Tk::Entry
WidgetClassName = 'TEntry'.freeze WidgetClassName = 'TEntry'.freeze
WidgetClassNames[WidgetClassName] = self WidgetClassNames[WidgetClassName] = self
def __optkey_aliases
{:vcmd=>:validatecommand, :invcmd=>:invalidcommand}
end
private :__optkey_aliases
def __boolval_optkeys def __boolval_optkeys
super() << 'exportselection' super() << 'exportselection'
end end

View file

@ -41,13 +41,35 @@ class Tk::Tile::TNotebook < TkWindow
private :__item_methodcall_optkeys private :__item_methodcall_optkeys
#alias tabcget itemcget #alias tabcget itemcget
#alias tabcget_strict itemcget_strict
alias tabconfigure itemconfigure alias tabconfigure itemconfigure
alias tabconfiginfo itemconfiginfo alias tabconfiginfo itemconfiginfo
alias current_tabconfiginfo current_itemconfiginfo alias current_tabconfiginfo current_itemconfiginfo
def tabcget(tagOrId, option) def tabcget_strict(tagOrId, option)
tabconfigure(tagOrId, option)[-1] tabconfigure(tagOrId, option)[-1]
end end
def tabcget(tagOrId, option)
unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
tabcget_strict(tagOrId, option)
else
begin
tabcget_strict(tagOrId, option)
rescue => e
begin
if current_tabconfiginfo(tagOrId).has_key?(option.to_s)
# not tag error & option is known -> error on known option
fail e
else
# not tag error & option is unknown
nil
end
rescue
fail e # tag error
end
end
end
end
################################ ################################
include Tk::Tile::TileWidget include Tk::Tile::TileWidget

View file

@ -66,10 +66,33 @@ class Tk::Tile::TPaned < TkWindow
self self
end end
def panecget(pane, slot) def panecget_strict(pane, slot)
pane = _epath(pane) pane = _epath(pane)
tk_tcl2ruby(tk_send_without_enc('pane', pane, "-#{slot}")) tk_tcl2ruby(tk_send_without_enc('pane', pane, "-#{slot}"))
end end
alias pane_cget_strict panecget_strict
def panecget(pane, slot)
unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
panecget_strict(pane, slot)
else
begin
panecget_strict(pane, slot)
rescue => e
begin
if current_paneconfiginfo(pane).has_key?(slot.to_s)
# not tag error & option is known -> error on known option
fail e
else
# not tag error & option is unknown
nil
end
rescue
fail e # tag error
end
end
end
end
alias pane_cget panecget alias pane_cget panecget
def paneconfigure(pane, key, value=nil) def paneconfigure(pane, key, value=nil)

View file

@ -33,6 +33,12 @@ module Tk::Tile::TreeviewConfig
else else
if slot if slot
slot = slot.to_s slot = slot.to_s
alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot}
if real_name
slot = real_name.to_s
end
case slot case slot
when /^(#{__tile_specific_item_optkeys(tagid(tagOrId)).join('|')})$/ when /^(#{__tile_specific_item_optkeys(tagid(tagOrId)).join('|')})$/
begin begin
@ -198,6 +204,12 @@ module Tk::Tile::TreeviewConfig
else else
if slot if slot
slot = slot.to_s slot = slot.to_s
alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot}
if real_name
slot = real_name.to_s
end
case slot case slot
when /^(#{__tile_specific_item_optkeys(tagid(tagOrId)).join('|')})$/ when /^(#{__tile_specific_item_optkeys(tagid(tagOrId)).join('|')})$/
begin begin
@ -508,17 +520,21 @@ module Tk::Tile::TreeviewConfig
end end
alias __itemcget itemcget alias __itemcget itemcget
alias __itemcget_strict itemcget_strict
alias __itemconfigure itemconfigure alias __itemconfigure itemconfigure
alias __itemconfiginfo itemconfiginfo alias __itemconfiginfo itemconfiginfo
alias __current_itemconfiginfo current_itemconfiginfo alias __current_itemconfiginfo current_itemconfiginfo
private :__itemcget, :__itemconfigure private :__itemcget, :__itemcget_strict
private :__itemconfiginfo, :__current_itemconfiginfo private :__itemconfigure, :__itemconfiginfo, :__current_itemconfiginfo
# Treeview Item # Treeview Item
def itemcget(tagOrId, option) def itemcget(tagOrId, option)
__itemcget([:item, tagOrId], option) __itemcget([:item, tagOrId], option)
end end
def itemcget_strict(tagOrId, option)
__itemcget_strict([:item, tagOrId], option)
end
def itemconfigure(tagOrId, slot, value=None) def itemconfigure(tagOrId, slot, value=None)
__itemconfigure([:item, tagOrId], slot, value) __itemconfigure([:item, tagOrId], slot, value)
end end
@ -533,6 +549,9 @@ module Tk::Tile::TreeviewConfig
def columncget(tagOrId, option) def columncget(tagOrId, option)
__itemcget([:column, tagOrId], option) __itemcget([:column, tagOrId], option)
end end
def columncget_strict(tagOrId, option)
__itemcget_strict([:column, tagOrId], option)
end
def columnconfigure(tagOrId, slot, value=None) def columnconfigure(tagOrId, slot, value=None)
__itemconfigure([:column, tagOrId], slot, value) __itemconfigure([:column, tagOrId], slot, value)
end end
@ -543,12 +562,13 @@ module Tk::Tile::TreeviewConfig
__current_itemconfiginfo([:column, tagOrId], slot) __current_itemconfiginfo([:column, tagOrId], slot)
end end
alias column_cget columncget alias column_cget columncget
alias column_cget_strict columncget_strict
alias column_configure columnconfigure alias column_configure columnconfigure
alias column_configinfo columnconfiginfo alias column_configinfo columnconfiginfo
alias current_column_configinfo current_columnconfiginfo alias current_column_configinfo current_columnconfiginfo
# Treeview Heading # Treeview Heading
def headingcget(tagOrId, option) def headingcget_strict(tagOrId, option)
if __tile_specific_item_optkeys([:heading, tagOrId]).index(option.to_s) if __tile_specific_item_optkeys([:heading, tagOrId]).index(option.to_s)
begin begin
# On tile-0.7.{2-8}, 'state' options has no '-' at its head. # On tile-0.7.{2-8}, 'state' options has no '-' at its head.
@ -558,7 +578,28 @@ module Tk::Tile::TreeviewConfig
tk_call(*(__item_cget_cmd([:heading, tagOrId]) << "-#{option}")) tk_call(*(__item_cget_cmd([:heading, tagOrId]) << "-#{option}"))
end end
else else
__itemcget([:heading, tagOrId], option) __itemcget_strict([:heading, tagOrId], option)
end
end
def headingcget(tagOrId, option)
unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
headingcget_strict(tagOrId, option)
else
begin
headingcget_strict(tagOrId, option)
rescue => e
begin
if current_headingconfiginfo(tagOrId).has_key?(option.to_s)
# not tag error & option is known -> error on known option
fail e
else
# not tag error & option is unknown
nil
end
rescue
fail e # tag error
end
end
end end
end end
def headingconfigure(tagOrId, slot, value=None) def headingconfigure(tagOrId, slot, value=None)
@ -590,6 +631,7 @@ module Tk::Tile::TreeviewConfig
__current_itemconfiginfo([:heading, tagOrId], slot) __current_itemconfiginfo([:heading, tagOrId], slot)
end end
alias heading_cget headingcget alias heading_cget headingcget
alias heading_cget_strict headingcget_strict
alias heading_configure headingconfigure alias heading_configure headingconfigure
alias heading_configinfo headingconfiginfo alias heading_configinfo headingconfiginfo
alias current_heading_configinfo current_headingconfiginfo alias current_heading_configinfo current_headingconfiginfo
@ -598,6 +640,9 @@ module Tk::Tile::TreeviewConfig
def tagcget(tagOrId, option) def tagcget(tagOrId, option)
__itemcget([:tag, tagOrId], option) __itemcget([:tag, tagOrId], option)
end end
def tagcget_strict(tagOrId, option)
__itemcget_strict([:tag, tagOrId], option)
end
def tagconfigure(tagOrId, slot, value=None) def tagconfigure(tagOrId, slot, value=None)
__itemconfigure([:tag, tagOrId], slot, value) __itemconfigure([:tag, tagOrId], slot, value)
end end
@ -608,6 +653,7 @@ module Tk::Tile::TreeviewConfig
__current_itemconfiginfo([:tag, tagOrId], slot) __current_itemconfiginfo([:tag, tagOrId], slot)
end end
alias tag_cget tagcget alias tag_cget tagcget
alias tag_cget_strict tagcget_strict
alias tag_configure tagconfigure alias tag_configure tagconfigure
alias tag_configinfo tagconfiginfo alias tag_configinfo tagconfiginfo
alias current_tag_configinfo current_tagconfiginfo alias current_tag_configinfo current_tagconfiginfo
@ -694,6 +740,9 @@ class Tk::Tile::Treeview::Item < TkObject
def cget(option) def cget(option)
@t.itemcget(@id, option) @t.itemcget(@id, option)
end end
def cget_strict(option)
@t.itemcget_strict(@id, option)
end
def configure(key, value=None) def configure(key, value=None)
@t.itemconfigure(@id, key, value) @t.itemconfigure(@id, key, value)
@ -933,6 +982,9 @@ class Tk::Tile::Treeview::Tag < TkObject
def cget(option) def cget(option)
@t.tagcget(@id, option) @t.tagcget(@id, option)
end end
def cget_strict(option)
@t.tagcget_strict(@id, option)
end
def configure(key, value=None) def configure(key, value=None)
@t.tagconfigure(@id, key, value) @t.tagconfigure(@id, key, value)

View file

@ -77,6 +77,9 @@ module Tk::TkTable::ConfigMethod
def tag_cget(tagOrId, option) def tag_cget(tagOrId, option)
itemcget(['tag', tagid(tagOrId)], option) itemcget(['tag', tagid(tagOrId)], option)
end end
def tag_cget_strict(tagOrId, option)
itemcget_strict(['tag', tagid(tagOrId)], option)
end
def tag_configure(tagOrId, slot, value=None) def tag_configure(tagOrId, slot, value=None)
itemconfigure(['tag', tagid(tagOrId)], slot, value) itemconfigure(['tag', tagid(tagOrId)], slot, value)
end end
@ -90,6 +93,9 @@ module Tk::TkTable::ConfigMethod
def window_cget(tagOrId, option) def window_cget(tagOrId, option)
itemcget(['window', tagid(tagOrId)], option) itemcget(['window', tagid(tagOrId)], option)
end end
def window_cget_strict(tagOrId, option)
itemcget_strict(['window', tagid(tagOrId)], option)
end
def window_configure(tagOrId, slot, value=None) def window_configure(tagOrId, slot, value=None)
if slot == :window || slot == 'window' if slot == :window || slot == 'window'
value = _epath(value) value = _epath(value)
@ -108,8 +114,8 @@ module Tk::TkTable::ConfigMethod
current_itemconfiginfo(['window', tagid(tagOrId)], slot) current_itemconfiginfo(['window', tagid(tagOrId)], slot)
end end
private :itemcget, :itemconfigure private :itemcget, :itemcget_strict
private :itemconfiginfo, :current_itemconfiginfo private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
end end
##################################################### #####################################################
@ -194,6 +200,9 @@ class Tk::TkTable::CellTag
def cget(key) def cget(key)
@t.tag_cget(@id, key) @t.tag_cget(@id, key)
end end
def cget_strict(key)
@t.tag_cget_strict(@id, key)
end
def configure(key, val=None) def configure(key, val=None)
@t.tag_configure(@id, key, val) @t.tag_configure(@id, key, val)
end end

View file

@ -417,6 +417,9 @@ module Tk::TreeCtrl::ConfigMethod
def column_cget(tagOrId, option) def column_cget(tagOrId, option)
itemcget(['column', tagOrId], option) itemcget(['column', tagOrId], option)
end end
def column_cget_strict(tagOrId, option)
itemcget_strict(['column', tagOrId], option)
end
def column_configure(tagOrId, slot, value=None) def column_configure(tagOrId, slot, value=None)
itemconfigure(['column', tagOrId], slot, value) itemconfigure(['column', tagOrId], slot, value)
end end
@ -430,6 +433,9 @@ module Tk::TreeCtrl::ConfigMethod
def column_dragcget(option) def column_dragcget(option)
itemcget(['column', 'drag'], option) itemcget(['column', 'drag'], option)
end end
def column_dragcget_strict(option)
itemcget_strict(['column', 'drag'], option)
end
def column_dragconfigure(slot, value=None) def column_dragconfigure(slot, value=None)
itemconfigure(['column', 'drag'], slot, value) itemconfigure(['column', 'drag'], slot, value)
end end
@ -443,6 +449,9 @@ module Tk::TreeCtrl::ConfigMethod
def debug_cget(option) def debug_cget(option)
itemcget('debug', option) itemcget('debug', option)
end end
def debug_cget_strict(option)
itemcget_strict('debug', option)
end
def debug_configure(slot, value=None) def debug_configure(slot, value=None)
itemconfigure('debug', slot, value) itemconfigure('debug', slot, value)
end end
@ -456,6 +465,9 @@ module Tk::TreeCtrl::ConfigMethod
def dragimage_cget(option) def dragimage_cget(option)
itemcget('dragimage', option) itemcget('dragimage', option)
end end
def dragimage_cget_strict(option)
itemcget_strict('dragimage', option)
end
def dragimage_configure(slot, value=None) def dragimage_configure(slot, value=None)
itemconfigure('dragimage', slot, value) itemconfigure('dragimage', slot, value)
end end
@ -469,6 +481,9 @@ module Tk::TreeCtrl::ConfigMethod
def element_cget(tagOrId, option) def element_cget(tagOrId, option)
itemcget(['element', tagOrId], option) itemcget(['element', tagOrId], option)
end end
def element_cget_strict(tagOrId, option)
itemcget_strict(['element', tagOrId], option)
end
def element_configure(tagOrId, slot, value=None) def element_configure(tagOrId, slot, value=None)
itemconfigure(['element', tagOrId], slot, value) itemconfigure(['element', tagOrId], slot, value)
end end
@ -482,6 +497,9 @@ module Tk::TreeCtrl::ConfigMethod
def item_cget(tagOrId, option) def item_cget(tagOrId, option)
itemcget(['item', tagOrId], option) itemcget(['item', tagOrId], option)
end end
def item_cget_strict(tagOrId, option)
itemcget_strict(['item', tagOrId], option)
end
def item_configure(tagOrId, slot, value=None) def item_configure(tagOrId, slot, value=None)
itemconfigure(['item', tagOrId], slot, value) itemconfigure(['item', tagOrId], slot, value)
end end
@ -495,6 +513,9 @@ module Tk::TreeCtrl::ConfigMethod
def item_element_cget(item, column, elem, option) def item_element_cget(item, column, elem, option)
itemcget([['item', 'element'], [item, column, elem]], option) itemcget([['item', 'element'], [item, column, elem]], option)
end end
def item_element_cget_strict(item, column, elem, option)
itemcget_strict([['item', 'element'], [item, column, elem]], option)
end
def item_element_configure(item, column, elem, slot, value=None) def item_element_configure(item, column, elem, slot, value=None)
itemconfigure([['item', 'element'], [item, column, elem]], slot, value) itemconfigure([['item', 'element'], [item, column, elem]], slot, value)
end end
@ -508,6 +529,9 @@ module Tk::TreeCtrl::ConfigMethod
def marquee_cget(option) def marquee_cget(option)
itemcget('marquee', option) itemcget('marquee', option)
end end
def marquee_cget_strict(option)
itemcget_strict('marquee', option)
end
def marquee_configure(slot, value=None) def marquee_configure(slot, value=None)
itemconfigure('marquee', slot, value) itemconfigure('marquee', slot, value)
end end
@ -523,6 +547,17 @@ module Tk::TreeCtrl::ConfigMethod
# "notify" doesn't have cget subcommand. # "notify" doesn't have cget subcommand.
current_itemconfiginfo(['notify', [win, pattern]])[option.to_s] current_itemconfiginfo(['notify', [win, pattern]])[option.to_s]
end end
def notify_cget_strict(win, pattern, option)
pattern = "<#{pattern}>"
# "notify" doesn't have cget subcommand.
info = current_itemconfiginfo(['notify', [win, pattern]])
option = option.to_s
unless info.has_key?(option)
fail RuntimeError, "unknown option \"#{option}\""
else
info[option]
end
end
def notify_configure(win, pattern, slot, value=None) def notify_configure(win, pattern, slot, value=None)
pattern = "<#{pattern}>" pattern = "<#{pattern}>"
itemconfigure(['notify', [win, pattern]], slot, value) itemconfigure(['notify', [win, pattern]], slot, value)
@ -539,6 +574,9 @@ module Tk::TreeCtrl::ConfigMethod
def style_cget(tagOrId, option) def style_cget(tagOrId, option)
itemcget(['style', tagOrId], option) itemcget(['style', tagOrId], option)
end end
def style_cget_strict(tagOrId, option)
itemcget_strict(['style', tagOrId], option)
end
def style_configure(tagOrId, slot, value=None) def style_configure(tagOrId, slot, value=None)
itemconfigure(['style', tagOrId], slot, value) itemconfigure(['style', tagOrId], slot, value)
end end
@ -549,8 +587,8 @@ module Tk::TreeCtrl::ConfigMethod
current_itemconfiginfo(['style', tagOrId], slot) current_itemconfiginfo(['style', tagOrId], slot)
end end
private :itemcget, :itemconfigure private :itemcget, :itemcget_strict
private :itemconfiginfo, :current_itemconfiginfo private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
end end
############################################## ##############################################
@ -1706,6 +1744,9 @@ class Tk::TreeCtrl::Column < TkObject
def cget(opt) def cget(opt)
@tree.column_cget(@tree.column_index(@id), opt) @tree.column_cget(@tree.column_index(@id), opt)
end end
def cget_strict(opt)
@tree.column_cget_strict(@tree.column_index(@id), opt)
end
def configure(*args) def configure(*args)
@tree.column_configure(@tree.column_index(@id), *args) @tree.column_configure(@tree.column_index(@id), *args)
@ -1806,6 +1847,9 @@ class Tk::TreeCtrl::Element < TkObject
def cget(opt) def cget(opt)
@tree.element_cget(@id, opt) @tree.element_cget(@id, opt)
end end
def cget_strict(opt)
@tree.element_cget_strict(@id, opt)
end
def configure(*args) def configure(*args)
@tree.element_configure(@id, *args) @tree.element_configure(@id, *args)
@ -1937,6 +1981,9 @@ class Tk::TreeCtrl::Item < TkObject
def cget(opt) def cget(opt)
@tree.item_cget(@id, opt) @tree.item_cget(@id, opt)
end end
def cget_strict(opt)
@tree.item_cget_strict(@id, opt)
end
def configure(*args) def configure(*args)
@tree.item_configure(@id, *args) @tree.item_configure(@id, *args)
@ -1970,6 +2017,9 @@ class Tk::TreeCtrl::Item < TkObject
def element_cget(opt) def element_cget(opt)
@tree.item_element_cget(@id, opt) @tree.item_element_cget(@id, opt)
end end
def element_cget_strict(opt)
@tree.item_element_cget_strict(@id, opt)
end
def element_configure(*args) def element_configure(*args)
@tree.item_element_configure(@id, *args) @tree.item_element_configure(@id, *args)
@ -2221,6 +2271,9 @@ class Tk::TreeCtrl::Style < TkObject
def cget(opt) def cget(opt)
@tree.style_cget(@id, opt) @tree.style_cget(@id, opt)
end end
def cget_strict(opt)
@tree.style_cget_strict(@id, opt)
end
def configure(*args) def configure(*args)
@tree.style_configure(@id, *args) @tree.style_configure(@id, *args)

View file

@ -2,5 +2,5 @@
# release date of tkextlib # release date of tkextlib
# #
module Tk module Tk
Tkextlib_RELEASE_DATE = '2008-05-14'.freeze Tkextlib_RELEASE_DATE = '2008-05-23'.freeze
end end

View file

@ -177,6 +177,10 @@ class Tk::Vu::PieSlice
@pie.itemcget(@id, slot) @pie.itemcget(@id, slot)
end end
def cget_strict(slot)
@pie.itemcget_strict(@id, slot)
end
def configure(*args) def configure(*args)
@pie.itemconfigure(@id, *args) @pie.itemconfigure(@id, *args)
self self

View file

@ -15,8 +15,10 @@ $anilabel_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($anilabel_demo).pack(:fill=>:both, :expand=>true)
# label # label
msg = TkLabel.new($anilabel_demo) { msg = TkLabel.new(base_frame) {
font $font font $font
wraplength '4i' wraplength '4i'
justify 'left' justify 'left'
@ -25,7 +27,7 @@ msg = TkLabel.new($anilabel_demo) {
msg.pack('side'=>'top') msg.pack('side'=>'top')
# frame # frame
TkFrame.new($anilabel_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -43,8 +45,8 @@ TkFrame.new($anilabel_demo) {|frame|
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# create frame for label demo # create frame for label demo
f_left = TkLabelFrame.new($anilabel_demo, :text=>'Scrolling Texts') f_left = TkLabelFrame.new(base_frame, :text=>'Scrolling Texts')
f_right = TkLabelFrame.new($anilabel_demo, :text=>'GIF Image') f_right = TkLabelFrame.new(base_frame, :text=>'GIF Image')
Tk.pack(f_left, f_right, 'side'=>'left', 'expand'=>'yes', 'fill'=>'both', Tk.pack(f_left, f_right, 'side'=>'left', 'expand'=>'yes', 'fill'=>'both',
'padx'=>10, 'pady'=>10) 'padx'=>10, 'pady'=>10)

View file

@ -16,8 +16,10 @@ $aniwave_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($aniwave_demo).pack(:fill=>:both, :expand=>true)
# create label # create label
msg = TkLabel.new($aniwave_demo) { msg = TkLabel.new(base_frame) {
font $font font $font
wraplength '4i' wraplength '4i'
justify 'left' justify 'left'
@ -26,7 +28,7 @@ msg = TkLabel.new($aniwave_demo) {
msg.pack('side'=>'top') msg.pack('side'=>'top')
# create frame # create frame
TkFrame.new($aniwave_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -113,4 +115,4 @@ class AnimatedWaveDemo
end end
# Start the animation processing # Start the animation processing
AnimatedWaveDemo.new($aniwave_demo, :left).move AnimatedWaveDemo.new(base_frame, :left).move

View file

@ -107,14 +107,16 @@ $arrow_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($arrow_demo).pack(:fill=>:both, :expand=>true)
# label # label
TkLabel.new($arrow_demo, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left', TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left',
'text'=>"This widget allows you to experiment with different widths and arrowhead shapes for lines in canvases. To change the line width or the shape of the arrowhead, drag any of the three boxes attached to the oversized arrow. The arrows on the right give examples at normal scale. The text at the bottom shows the configuration options as you'd enter them for a canvas line item."){ 'text'=>"This widget allows you to experiment with different widths and arrowhead shapes for lines in canvases. To change the line width or the shape of the arrowhead, drag any of the three boxes attached to the oversized arrow. The arrows on the right give examples at normal scale. The text at the bottom shows the configuration options as you'd enter them for a canvas line item."){
pack('side'=>'top') pack('side'=>'top')
} }
# frame # frame
$arrow_buttons = TkFrame.new($arrow_demo) {|frame| $arrow_buttons = TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -132,7 +134,7 @@ $arrow_buttons = TkFrame.new($arrow_demo) {|frame|
$arrow_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') $arrow_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# canvas # canvas
$arrow_canvas = TkCanvas.new($arrow_demo, 'width'=>500, 'height'=>350, $arrow_canvas = TkCanvas.new(base_frame, 'width'=>500, 'height'=>350,
'relief'=>'sunken', 'borderwidth'=>2) 'relief'=>'sunken', 'borderwidth'=>2)
$arrow_canvas.pack('expand'=>'yes', 'fill'=>'both') $arrow_canvas.pack('expand'=>'yes', 'fill'=>'both')

View file

@ -19,8 +19,10 @@ $bind_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($bind_demo).pack(:fill=>:both, :expand=>true)
# frame # frame
TkFrame.new($bind_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -43,14 +45,14 @@ def tag_binding_for_bind_demo(tag, enter_style, leave_style)
end end
# text # text
txt = TkText.new($bind_demo){|t| txt = TkText.new(base_frame){|t|
# #
setgrid 'true' setgrid 'true'
#width 60 #width 60
#height 24 #height 24
font $font font $font
wrap 'word' wrap 'word'
TkScrollbar.new($bind_demo) {|s| TkScrollbar.new(base_frame) {|s|
pack('side'=>'right', 'fill'=>'y') pack('side'=>'right', 'fill'=>'y')
command proc{|*args| t.yview(*args)} command proc{|*args| t.yview(*args)}
t.yscrollcommand proc{|first,last| s.set first,last} t.yscrollcommand proc{|first,last| s.set first,last}
@ -94,27 +96,27 @@ txt = TkText.new($bind_demo){|t|
} }
d1.bind('1', d1.bind('1',
proc{ proc{
eval_samplecode(`cat #{[$demo_dir,'items.rb'].join(File::Separator)}`) eval_samplecode(`cat #{[$demo_dir,'items.rb'].join(File::Separator)}`, 'items.rb')
}) })
d2.bind('1', d2.bind('1',
proc{ proc{
eval_samplecode(`cat #{[$demo_dir,'plot.rb'].join(File::Separator)}`) eval_samplecode(`cat #{[$demo_dir,'plot.rb'].join(File::Separator)}`, 'plot.rb')
}) })
d3.bind('1', d3.bind('1',
proc{ proc{
eval_samplecode(`cat #{[$demo_dir,'ctext.rb'].join(File::Separator)}`) eval_samplecode(`cat #{[$demo_dir,'ctext.rb'].join(File::Separator)}`, 'ctext.rb')
}) })
d4.bind('1', d4.bind('1',
proc{ proc{
eval_samplecode(`cat #{[$demo_dir,'arrow.rb'].join(File::Separator)}`) eval_samplecode(`cat #{[$demo_dir,'arrow.rb'].join(File::Separator)}`, 'arrow.rb')
}) })
d5.bind('1', d5.bind('1',
proc{ proc{
eval_samplecode(`cat #{[$demo_dir,'ruler.rb'].join(File::Separator)}`) eval_samplecode(`cat #{[$demo_dir,'ruler.rb'].join(File::Separator)}`, 'ruler.rb')
}) })
d6.bind('1', d6.bind('1',
proc{ proc{
eval_samplecode(`cat #{[$demo_dir,'cscroll.rb'].join(File::Separator)}`) eval_samplecode(`cat #{[$demo_dir,'cscroll.rb'].join(File::Separator)}`, 'cscroll.rb')
}) })
TkTextMarkInsert.new(t, '0.0') TkTextMarkInsert.new(t, '0.0')

View file

@ -21,7 +21,7 @@ def bitmapRow(w,*args)
TkFrame.new(row){|base| TkFrame.new(row){|base|
pack('side'=>'left', 'fill'=>'both', 'pady'=>'.25c', 'padx'=>'.25c') pack('side'=>'left', 'fill'=>'both', 'pady'=>'.25c', 'padx'=>'.25c')
TkLabel.new(base, 'text'=>bitmap, 'width'=>9).pack('side'=>'bottom') TkLabel.new(base, 'text'=>bitmap, 'width'=>9).pack('side'=>'bottom')
TkLabel.new(base, 'bitmap'=>bitmap).pack('side'=>'bottom') Tk::Label.new(base, 'bitmap'=>bitmap).pack('side'=>'bottom')
} }
end end
} }
@ -40,14 +40,16 @@ $bitmap_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($bitmap_demo).pack(:fill=>:both, :expand=>true)
# label # label
TkLabel.new($bitmap_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left', TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left',
'text'=>"This window displays all of Tk's built-in bitmaps, along with the names you can use for them in Tcl scripts."){ 'text'=>"This window displays all of Tk's built-in bitmaps, along with the names you can use for them in Tcl scripts."){
pack('side'=>'top') pack('side'=>'top')
} }
# frame # frame
$bitmap_buttons = TkFrame.new($bitmap_demo) {|frame| $bitmap_buttons = TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -65,7 +67,7 @@ $bitmap_buttons = TkFrame.new($bitmap_demo) {|frame|
$bitmap_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') $bitmap_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame # frame
TkFrame.new($bitmap_demo){|f| TkFrame.new(base_frame){|f|
bitmapRow(f,'error','gray25','gray50','hourglass') bitmapRow(f,'error','gray25','gray50','hourglass')
bitmapRow(f,'info','question','questhead','warning') bitmapRow(f,'info','question','questhead','warning')
pack('side'=>'top', 'expand'=>'yes', 'fill'=>'both') pack('side'=>'top', 'expand'=>'yes', 'fill'=>'both')

View file

@ -29,7 +29,7 @@ msg = TkLabel.new($button_demo) {
msg.pack('side'=>'top') msg.pack('side'=>'top')
# frame # frame
$button_buttons = TkFrame.new($button_demo) {|frame| $button_buttons = Tk::Frame.new($button_demo) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{

View file

@ -19,8 +19,10 @@ $check_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($check_demo).pack(:fill=>:both, :expand=>true)
# label # label
msg = TkLabel.new($check_demo) { msg = TkLabel.new(base_frame) {
font $font font $font
wraplength '4i' wraplength '4i'
justify 'left' justify 'left'
@ -34,7 +36,7 @@ brakes = TkVariable.new(0)
sober = TkVariable.new(0) sober = TkVariable.new(0)
# frame # frame
TkFrame.new($check_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -54,7 +56,7 @@ TkFrame.new($check_demo) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'See Variables' text 'See Variables'
command proc{ command proc{
showVars($check_demo, showVars(base_frame,
['wipers', wipers], ['brakes', brakes], ['sober', sober]) ['wipers', wipers], ['brakes', brakes], ['sober', sober])
} }
}.pack('side'=>'left', 'expand'=>'yes') }.pack('side'=>'left', 'expand'=>'yes')
@ -63,8 +65,8 @@ TkFrame.new($check_demo) {|frame|
# checkbutton # checkbutton
[ TkCheckButton.new($check_demo, 'text'=>'Wipers OK', 'variable'=>wipers), [ TkCheckButton.new(base_frame, 'text'=>'Wipers OK', 'variable'=>wipers),
TkCheckButton.new($check_demo, 'text'=>'Brakes OK', 'variable'=>brakes), TkCheckButton.new(base_frame, 'text'=>'Brakes OK', 'variable'=>brakes),
TkCheckButton.new($check_demo, 'text'=>'Driver Sober', 'variable'=>sober) TkCheckButton.new(base_frame, 'text'=>'Driver Sober', 'variable'=>sober)
].each{|w| w.relief('flat'); w.pack('side'=>'top', 'pady'=>2, 'anchor'=>'w')} ].each{|w| w.relief('flat'); w.pack('side'=>'top', 'pady'=>2, 'anchor'=>'w')}

View file

@ -15,8 +15,10 @@ $check2_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($check2_demo).pack(:fill=>:both, :expand=>true)
# label # label
msg = TkLabel.new($check2_demo) { msg = TkLabel.new(base_frame) {
font $font font $font
wraplength '4i' wraplength '4i'
justify 'left' justify 'left'
@ -31,7 +33,7 @@ brakes = TkVariable.new(0)
sober = TkVariable.new(0) sober = TkVariable.new(0)
# frame # frame
TkFrame.new($check2_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkGrid(TkFrame.new(frame, :height=>2, :relief=>:sunken, :bd=>2), TkGrid(TkFrame.new(frame, :height=>2, :relief=>:sunken, :bd=>2),
:columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
TkGrid('x', TkGrid('x',
@ -59,15 +61,15 @@ TkFrame.new($check2_demo) {|frame|
# checkbutton # checkbutton
TkCheckButton.new($check2_demo, :text=>'Safety Check', :variable=>safety, TkCheckButton.new(base_frame, :text=>'Safety Check', :variable=>safety,
:relief=>:flat, :onvalue=>'all', :offvalue=>'none', :relief=>:flat, :onvalue=>'all', :offvalue=>'none',
:tristatevalue=>'partial'){ :tristatevalue=>'partial'){
pack('side'=>'top', 'pady'=>2, 'anchor'=>'w') pack('side'=>'top', 'pady'=>2, 'anchor'=>'w')
} }
[ TkCheckButton.new($check2_demo, 'text'=>'Wipers OK', 'variable'=>wipers), [ TkCheckButton.new(base_frame, 'text'=>'Wipers OK', 'variable'=>wipers),
TkCheckButton.new($check2_demo, 'text'=>'Brakes OK', 'variable'=>brakes), TkCheckButton.new(base_frame, 'text'=>'Brakes OK', 'variable'=>brakes),
TkCheckButton.new($check2_demo, 'text'=>'Driver Sober', 'variable'=>sober) TkCheckButton.new(base_frame, 'text'=>'Driver Sober', 'variable'=>sober)
].each{|w| ].each{|w|
w.relief('flat') w.relief('flat')
w.pack('side'=>'top', 'padx'=>15, 'pady'=>2, 'anchor'=>'w') w.pack('side'=>'top', 'padx'=>15, 'pady'=>2, 'anchor'=>'w')

View file

@ -4,6 +4,8 @@
# #
# widget demo prompts the user to select a color (called by 'widget') # widget demo prompts the user to select a color (called by 'widget')
# #
# Note: don't support ttk_wrapper. work with standard widgets only.
#
# toplevel widget # toplevel widget
if defined?($clrpick_demo) && $clrpick_demo if defined?($clrpick_demo) && $clrpick_demo
@ -18,13 +20,18 @@ $clrpick_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($clrpick_demo).pack(:fill=>:both, :expand=>true)
# label # label
TkLabel.new($clrpick_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left', #TkLabel.new($clrpick_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left',
Tk::Label.new($clrpick_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left',
'text'=>"Press the buttons below to choose the foreground and background colors for the widgets in this window.").pack('side'=>'top') 'text'=>"Press the buttons below to choose the foreground and background colors for the widgets in this window.").pack('side'=>'top')
# frame # frame
TkFrame.new($clrpick_demo) {|frame| #TkFrame.new($clrpick_demo) {|frame|
TkButton.new(frame) { Tk::Frame.new($clrpick_demo) {|frame|
# TkButton.new(frame) {
Tk::Button.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
tmppath = $clrpick_demo tmppath = $clrpick_demo
@ -33,20 +40,23 @@ TkFrame.new($clrpick_demo) {|frame|
} }
}.pack('side'=>'left', 'expand'=>'yes') }.pack('side'=>'left', 'expand'=>'yes')
TkButton.new(frame) { # TkButton.new(frame) {
Tk::Button.new(frame) {
text 'Show Code' text 'Show Code'
command proc{showCode 'clrpick'} command proc{showCode 'clrpick'}
}.pack('side'=>'left', 'expand'=>'yes') }.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# button # button
TkButton.new($clrpick_demo, 'text'=>'Set background color ...') {|b| # TkButton.new($clrpick_demo, 'text'=>'Set background color ...') {|b|
Tk::Button.new($clrpick_demo, 'text'=>'Set background color ...') {|b|
command(proc{setColor $clrpick_demo, b, 'background', command(proc{setColor $clrpick_demo, b, 'background',
['background', 'highlightbackground']}) ['background', 'highlightbackground']})
pack('side'=>'top', 'anchor'=>'c', 'pady'=>'2m') pack('side'=>'top', 'anchor'=>'c', 'pady'=>'2m')
} }
TkButton.new($clrpick_demo, 'text'=>'Set foreground color ...') {|b| # TkButton.new($clrpick_demo, 'text'=>'Set foreground color ...') {|b|
Tk::Button.new($clrpick_demo, 'text'=>'Set foreground color ...') {|b|
command(proc{setColor $clrpick_demo, b, 'foreground', ['foreground']}) command(proc{setColor $clrpick_demo, b, 'foreground', ['foreground']})
pack('side'=>'top', 'anchor'=>'c', 'pady'=>'2m') pack('side'=>'top', 'anchor'=>'c', 'pady'=>'2m')
} }

View file

@ -20,8 +20,10 @@ $colors_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($colors_demo).pack(:fill=>:both, :expand=>true)
# label # label
msg = TkLabel.new($colors_demo) { msg = TkLabel.new(base_frame) {
font $font font $font
wraplength '4i' wraplength '4i'
justify 'left' justify 'left'
@ -30,7 +32,7 @@ msg = TkLabel.new($colors_demo) {
msg.pack('side'=>'top') msg.pack('side'=>'top')
# frame # frame
TkFrame.new($colors_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -49,7 +51,7 @@ TkFrame.new($colors_demo) {|frame|
# frame # frame
colors_lbox = nil colors_lbox = nil
TkFrame.new($colors_demo, 'borderwidth'=>10) {|w| TkFrame.new(base_frame, 'borderwidth'=>10) {|w|
s = TkScrollbar.new(w) s = TkScrollbar.new(w)
colors_lbox = TkListbox.new(w) { colors_lbox = TkListbox.new(w) {
setgrid 1 setgrid 1
@ -62,7 +64,15 @@ TkFrame.new($colors_demo, 'borderwidth'=>10) {|w|
colors_lbox.pack('side'=>'left', 'expand'=>1, 'fill'=>'both') colors_lbox.pack('side'=>'left', 'expand'=>1, 'fill'=>'both')
}.pack('side'=>'top', 'expand'=>'yes', 'fill'=>'y') }.pack('side'=>'top', 'expand'=>'yes', 'fill'=>'y')
colors_lbox.bind('Double-1', proc{TkPalette.setPalette TkSelection.get}) #colors_lbox.bind('Double-1', proc{TkPalette.setPalette TkSelection.get})
colors_lbox.bind('Double-1', proc{
begin
TkPalette.setPalette TkSelection.get
rescue => e
p e
Tk.tk_call_without_enc('destroy', '.___tk_set_palette')
end
})
ins_data = [ ins_data = [
'gray60','gray70','gray80','gray85','gray90','gray95', 'gray60','gray70','gray80','gray85','gray90','gray95',

View file

@ -0,0 +1,96 @@
# combo.rb --
#
# This demonstration script creates several combobox widgets.
#
# based on "Id: combo.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp"
if defined?($combo_demo) && $combo_demo
$combo_demo.destroy
$combo_demo = nil
end
$combo_demo = TkToplevel.new {|w|
title("Combobox Demonstration")
iconname("combo")
positionWindow(w)
}
base_frame = TkFrame.new($combo_demo).pack(:fill=>:both, :expand=>true)
Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'5i', :justify=>:left,
:text=><<EOL).pack(:side=>:top, :fill=>:x)
Three different combo-boxes are displayed below. \
You can add characters to the first \
one by pointing, clicking and typing, just as with an entry; pressing \
Return will cause the current value to be added to the list that is \
selectable from the drop-down list, and you can choose other values \
by pressing the Down key, using the arrow keys to pick another one, \
and pressing Return again. The second combo-box is fixed to a \
particular value, and cannot be modified at all. The third one only \
allows you to select values from its drop-down list of Australian \
cities.
EOL
## variables
firstValue = TkVariable.new
secondValue = TkVariable.new
ozCity = TkVariable.new
## See Code / Dismiss buttons
Ttk::Frame.new(base_frame) {|frame|
sep = Ttk::Separator.new(frame)
Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
TkGrid('x',
Ttk::Button.new(frame, :text=>'See Variables',
:image=>$image['view'], :compound=>:left,
:command=>proc{
showVars(base_frame,
['firstVariable', firstValue],
['secondVariable', secondValue],
['ozCity', ozCity])
}),
Ttk::Button.new(frame, :text=>'See Code',
:image=>$image['view'], :compound=>:left,
:command=>proc{showCode 'combo'}),
Ttk::Button.new(frame, :text=>'Dismiss',
:image=>$image['delete'], :compound=>:left,
:command=>proc{
$combo_demo.destroy
$combo_demo = nil
}),
:padx=>4, :pady=>4)
grid_columnconfigure(0, :weight=>1)
pack(:side=>:bottom, :fill=>:x)
}
frame = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true)
australianCities = [
'Canberra', 'Sydney', 'Melbourne', 'Perth', 'Adelaide', 'Brisbane',
'Hobart', 'Darwin', 'Alice Springs'
]
secondValue.value = 'unchangable'
ozCity.value = 'Sydney'
Tk.pack(Ttk::Labelframe.new(frame, :text=>'Fully Editable'){|f|
Ttk::Combobox.new(f, :textvariable=>firstValue){|b|
b.bind('Return', '%W'){|w|
w.values <<= w.value unless w.values.include?(w.value)
}
}.pack(:pady=>5, :padx=>10)
},
Ttk::LabelFrame.new(frame, :text=>'Disabled'){|f|
Ttk::Combobox.new(f, :textvariable=>secondValue, :state=>:disabled) .
pack(:pady=>5, :padx=>10)
},
Ttk::LabelFrame.new(frame, :text=>'Defined List Only'){|f|
Ttk::Combobox.new(f, :textvariable=>ozCity, :state=>:readonly,
:values=>australianCities) .
pack(:pady=>5, :padx=>10)
},
:side=>:top, :pady=>5, :padx=>10)

View file

@ -19,14 +19,16 @@ $cscroll_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($cscroll_demo).pack(:fill=>:both, :expand=>true)
# label # label
TkLabel.new($cscroll_demo, 'font'=>$font, 'wraplength'=>'4i', TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'4i',
'justify'=>'left', 'text'=>"This window displays a canvas widget that can be scrolled either using the scrollbars or by dragging with button 2 in the canvas. If you click button 1 on one of the rectangles, its indices will be printed on stdout."){ 'justify'=>'left', 'text'=>"This window displays a canvas widget that can be scrolled either using the scrollbars or by dragging with button 2 in the canvas. If you click button 1 on one of the rectangles, its indices will be printed on stdout."){
pack('side'=>'top') pack('side'=>'top')
} }
# frame # frame
$cscroll_buttons = TkFrame.new($cscroll_demo) {|frame| $cscroll_buttons = TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -45,7 +47,7 @@ $cscroll_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame # frame
unless $tk_version =~ /^4\.[01]/ unless $tk_version =~ /^4\.[01]/
$cscroll_grid = TkFrame.new($cscroll_demo) { $cscroll_grid = TkFrame.new(base_frame) {
pack('expand'=>'yes', 'fill'=>'both', 'padx'=>1, 'pady'=>1) pack('expand'=>'yes', 'fill'=>'both', 'padx'=>1, 'pady'=>1)
} }
TkGrid.rowconfigure($cscroll_grid, 0, 'weight'=>1, 'minsize'=>0) TkGrid.rowconfigure($cscroll_grid, 0, 'weight'=>1, 'minsize'=>0)
@ -53,7 +55,7 @@ unless $tk_version =~ /^4\.[01]/
end end
# canvas # canvas
$cscroll_canvas = TkCanvas.new($cscroll_demo, $cscroll_canvas = TkCanvas.new(base_frame,
'relief'=>'sunken', 'borderwidth'=>2, 'relief'=>'sunken', 'borderwidth'=>2,
'scrollregion'=>['-11c', '-11c', '50c', '20c'] 'scrollregion'=>['-11c', '-11c', '50c', '20c']
) {|c| ) {|c|
@ -64,7 +66,7 @@ $cscroll_canvas = TkCanvas.new($cscroll_demo,
'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news') 'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news')
end end
TkScrollbar.new($cscroll_demo, 'command'=>proc{|*args| c.yview(*args)}) {|vs| TkScrollbar.new(base_frame, 'command'=>proc{|*args| c.yview(*args)}) {|vs|
c.yscrollcommand(proc{|first,last| vs.set first,last}) c.yscrollcommand(proc{|first,last| vs.set first,last})
if $tk_version =~ /^4\.[01]/ if $tk_version =~ /^4\.[01]/
pack('side'=>'right', 'fill'=>'y') pack('side'=>'right', 'fill'=>'y')
@ -74,7 +76,7 @@ $cscroll_canvas = TkCanvas.new($cscroll_demo,
end end
} }
TkScrollbar.new($cscroll_demo, 'orient'=>'horiz', TkScrollbar.new(base_frame, 'orient'=>'horiz',
'command'=>proc{|*args| c.xview(*args)}) {|hs| 'command'=>proc{|*args| c.xview(*args)}) {|hs|
c.xscrollcommand(proc{|first,last| hs.set first,last}) c.xscrollcommand(proc{|first,last| hs.set first,last})
if $tk_version =~ /^4\.[01]/ if $tk_version =~ /^4\.[01]/

View file

@ -19,8 +19,10 @@ $ctext_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($ctext_demo).pack(:fill=>:both, :expand=>true)
# label # label
TkLabel.new($ctext_demo, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left', TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left',
'text'=>"This window displays a string of text to demonstrate the text facilities of canvas widgets. You can click in the boxes to adjust the position of the text relative to its positioning point or change its justification. The text also supports the following simple bindings for editing: 'text'=>"This window displays a string of text to demonstrate the text facilities of canvas widgets. You can click in the boxes to adjust the position of the text relative to its positioning point or change its justification. The text also supports the following simple bindings for editing:
1. You can point, click, and type. 1. You can point, click, and type.
2. You can also select with button 1. 2. You can also select with button 1.
@ -33,7 +35,7 @@ TkLabel.new($ctext_demo, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left',
} }
# frame # frame
$ctext_buttons = TkFrame.new($ctext_demo) {|frame| $ctext_buttons = TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -51,7 +53,7 @@ $ctext_buttons = TkFrame.new($ctext_demo) {|frame|
$ctext_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') $ctext_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# canvas # canvas
$ctext_canvas = TkCanvas.new($ctext_demo, 'relief'=>'flat', $ctext_canvas = TkCanvas.new(base_frame, 'relief'=>'flat',
'borderwidth'=>0, 'width'=>500, 'height'=>350) 'borderwidth'=>0, 'width'=>500, 'height'=>350)
$ctext_canvas.pack('side'=>'top', 'expand'=>'yes', 'fill'=>'both') $ctext_canvas.pack('side'=>'top', 'expand'=>'yes', 'fill'=>'both')

View file

@ -15,8 +15,10 @@ $entry1_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($entry1_demo).pack(:fill=>:both, :expand=>true)
# label # label
msg = TkLabel.new($entry1_demo) { msg = TkLabel.new(base_frame) {
font $font font $font
wraplength '5i' wraplength '5i'
justify 'left' justify 'left'
@ -25,7 +27,7 @@ msg = TkLabel.new($entry1_demo) {
msg.pack('side'=>'top') msg.pack('side'=>'top')
# frame # frame
TkFrame.new($entry1_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -42,9 +44,9 @@ TkFrame.new($entry1_demo) {|frame|
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# #
e1 = TkEntry.new($entry1_demo, 'relief'=>'sunken') e1 = TkEntry.new(base_frame, 'relief'=>'sunken')
e2 = TkEntry.new($entry1_demo, 'relief'=>'sunken') e2 = TkEntry.new(base_frame, 'relief'=>'sunken')
e3 = TkEntry.new($entry1_demo, 'relief'=>'sunken') e3 = TkEntry.new(base_frame, 'relief'=>'sunken')
[e1,e2,e3].each{|w| w.pack('side'=>'top', 'padx'=>10, 'pady'=>5, 'fill'=>'x')} [e1,e2,e3].each{|w| w.pack('side'=>'top', 'padx'=>10, 'pady'=>5, 'fill'=>'x')}
# #

View file

@ -19,8 +19,10 @@ $entry2_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($entry2_demo).pack(:fill=>:both, :expand=>true)
# label # label
msg = TkLabel.new($entry2_demo) { msg = TkLabel.new(base_frame) {
font $font font $font
wraplength '5i' wraplength '5i'
justify 'left' justify 'left'
@ -29,7 +31,7 @@ msg = TkLabel.new($entry2_demo) {
msg.pack('side'=>'top') msg.pack('side'=>'top')
# frame # frame
TkFrame.new($entry2_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -46,7 +48,7 @@ TkFrame.new($entry2_demo) {|frame|
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame # frame
TkFrame.new($entry2_demo, 'borderwidth'=>10) {|w| TkFrame.new(base_frame, 'borderwidth'=>10) {|w|
# entry 1 # entry 1
s1 = TkScrollbar.new(w, 'relief'=>'sunken', 'orient'=>'horiz') s1 = TkScrollbar.new(w, 'relief'=>'sunken', 'orient'=>'horiz')
e1 = TkEntry.new(w, 'relief'=>'sunken') { e1 = TkEntry.new(w, 'relief'=>'sunken') {

View file

@ -17,7 +17,9 @@ $entry3_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
TkLabel.new($entry3_demo, base_frame = TkFrame.new($entry3_demo).pack(:fill=>:both, :expand=>true)
TkLabel.new(base_frame,
:font=>$font, :wraplength=>'5i', :justify=>:left, :font=>$font, :wraplength=>'5i', :justify=>:left,
:text=><<EOL).pack(:side=>:top) :text=><<EOL).pack(:side=>:top)
Four different entries are displayed below. You can add characters \ Four different entries are displayed below. You can add characters \
@ -34,7 +36,7 @@ characters (silently ignoring further ones), and displaying them as \
asterisk characters. asterisk characters.
EOL EOL
TkFrame.new($entry3_demo){|f| TkFrame.new(base_frame){|f|
pack(:side=>:bottom, :fill=>:x, :pady=>'2m') pack(:side=>:bottom, :fill=>:x, :pady=>'2m')
TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{ TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{
@ -60,23 +62,41 @@ TkFrame.new($entry3_demo){|f|
# count - Counter to control the number of times flashed # count - Counter to control the number of times flashed
def focusAndFlash(widget, fg, bg, count=5) def focusAndFlash(widget, fg, bg, count=5)
return if count <= 0 return if count <= 0
if fg && !fg.empty? && bg && !bg.empty?
TkTimer.new(200, count, TkTimer.new(200, count,
proc{widget.configure(:foreground=>bg, :background=>fg)}, proc{widget.configure(:foreground=>bg, :background=>fg)},
proc{widget.configure(:foreground=>fg, :background=>bg)} proc{widget.configure(:foreground=>fg, :background=>bg)}
).start ).start
else
# TkTimer.new(150, 3){Tk.bell}.start
Tk.bell
TkTimer.new(200, count,
proc{widget.configure(:foreground=>'white',
:background=>'black')},
proc{widget.configure(:foreground=>'black',
:background=>'white')}
).at_end{begin
widget.configure(:foreground=>fg,
:background=>bg)
rescue
# ignore
end}.start
end
widget.focus(true) widget.focus(true)
end end
l1 = TkLabelFrame.new($entry3_demo, :text=>"Integer Entry") l1 = TkLabelFrame.new(base_frame, :text=>"Integer Entry")
TkEntry.new(l1, :validate=>:focus, TkEntry.new(l1, :validate=>:focus,
:vcmd=>[ :vcmd=>[
proc{|s| s == '' || /^[+-]?\d+$/ =~ s }, '%P' proc{|s| s == '' || /^[+-]?\d+$/ =~ s }, '%P'
]) {|e| ]) {|e|
invalidcommand [proc{|w| focusAndFlash(w, e.fg, e.bg)}, '%W'] fg = e.foreground
bg = e.background
invalidcommand [proc{|w| focusAndFlash(w, fg, bg)}, '%W']
pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m') pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m')
} }
l2 = TkLabelFrame.new($entry3_demo, :text=>"Length-Constrained Entry") l2 = TkLabelFrame.new(base_frame, :text=>"Length-Constrained Entry")
TkEntry.new(l2, :validate=>:key, :invcmd=>proc{Tk.bell}, TkEntry.new(l2, :validate=>:key, :invcmd=>proc{Tk.bell},
:vcmd=>[proc{|s| s.length < 10}, '%P'] :vcmd=>[proc{|s| s.length < 10}, '%P']
).pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m') ).pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m')
@ -158,14 +178,14 @@ def validatePhoneChange(widget, vmode, idx, char)
widget.insert(idx, $phoneNumberMap[char] || char) widget.insert(idx, $phoneNumberMap[char] || char)
Tk.after_idle(proc{phoneSkipRight(widget, -1)}) Tk.after_idle(proc{phoneSkipRight(widget, -1)})
return true return true
# Tk.update(true) # Don't work 'update' inter validation callback. # Tk.update(true) # <- Don't work 'update' inter validation callback.
# It depends on Tcl/Tk side (tested on Tcl/Tk8.5a1). # It depends on Tcl/Tk side (tested on Tcl/Tk8.5a1).
end end
return false return false
end end
l3 = TkLabelFrame.new($entry3_demo, :text=>"US Phone-Number Entry") l3 = TkLabelFrame.new(base_frame, :text=>"US Phone-Number Entry")
TkEntry.new(l3, :validate=>:key, :invcmd=>proc{Tk.bell}, TkEntry.new(l3, :validate=>:key, :invcmd=>proc{Tk.bell},
:textvariable=>entry3content, :textvariable=>entry3content,
:vcmd=>[ :vcmd=>[
@ -184,14 +204,14 @@ TkEntry.new(l3, :validate=>:key, :invcmd=>proc{Tk.bell},
pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m') pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m')
} }
l4 = TkLabelFrame.new($entry3_demo, :text=>"Password Entry") l4 = TkLabelFrame.new(base_frame, :text=>"Password Entry")
TkEntry.new(l4, :validate=>:key, :show=>'*', TkEntry.new(l4, :validate=>:key, :show=>'*',
:vcmd=>[ :vcmd=>[
proc{|s| s.length <= 8}, proc{|s| s.length <= 8},
'%P' '%P'
]).pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m') ]).pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m')
TkFrame.new($entry3_demo){|f| TkFrame.new(base_frame){|f|
lower lower
TkGrid.configure(l1, l2, :in=>f, :padx=>'3m', :pady=>'1m', :sticky=>:ew) TkGrid.configure(l1, l2, :in=>f, :padx=>'3m', :pady=>'1m', :sticky=>:ew)
TkGrid.configure(l3, l4, :in=>f, :padx=>'3m', :pady=>'1m', :sticky=>:ew) TkGrid.configure(l3, l4, :in=>f, :padx=>'3m', :pady=>'1m', :sticky=>:ew)

View file

@ -17,12 +17,14 @@ $filebox_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($filebox_demo).pack(:fill=>:both, :expand=>true)
# label # label
TkLabel.new($filebox_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left', TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left',
'text'=>"Enter a file name in the entry box or click on the \"Browse\" buttons to select a file name using the file selection dialog.").pack('side'=>'top') 'text'=>"Enter a file name in the entry box or click on the \"Browse\" buttons to select a file name using the file selection dialog.").pack('side'=>'top')
# frame # frame
TkFrame.new($filebox_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -40,7 +42,7 @@ TkFrame.new($filebox_demo) {|frame|
# frame # frame
['open', 'save'].each{|type| ['open', 'save'].each{|type|
TkFrame.new($filebox_demo) {|f| TkFrame.new(base_frame) {|f|
TkLabel.new(f, 'text'=>"Select a file to #{type}: ", 'anchor'=>'e')\ TkLabel.new(f, 'text'=>"Select a file to #{type}: ", 'anchor'=>'e')\
.pack('side'=>'left') .pack('side'=>'left')
@ -48,7 +50,7 @@ TkFrame.new($filebox_demo) {|frame|
pack('side'=>'left', 'expand'=>'yes', 'fill'=>'x') pack('side'=>'left', 'expand'=>'yes', 'fill'=>'x')
TkButton.new(f, 'text'=>'Browse ...', TkButton.new(f, 'text'=>'Browse ...',
'command'=>proc{fileDialog $filebox_demo,e,type})\ 'command'=>proc{fileDialog base_frame,e,type})\
.pack('side'=>'left') .pack('side'=>'left')
} }
@ -58,7 +60,7 @@ TkFrame.new($filebox_demo) {|frame|
$tk_strictMotif = TkVarAccess.new('tk_strictMotif') $tk_strictMotif = TkVarAccess.new('tk_strictMotif')
if ($tk_platform['platform'] == 'unix') if ($tk_platform['platform'] == 'unix')
TkCheckButton.new($filebox_demo, TkCheckButton.new(base_frame,
'text'=>'Use Motif Style Dialog', 'text'=>'Use Motif Style Dialog',
'variable'=>$tk_strictMotif, 'variable'=>$tk_strictMotif,
'onvalue'=>1, 'offvalue'=>0 ).pack('anchor'=>'c') 'onvalue'=>1, 'offvalue'=>0 ).pack('anchor'=>'c')
@ -91,7 +93,10 @@ def fileDialog(w,ent,operation)
if file != "" if file != ""
ent.delete 0, 'end' ent.delete 0, 'end'
ent.insert 0, file ent.insert 0, file
ent.xview 'end' # ent.xview 'end'
Tk.update_idletasks # need this for Tk::Tile::Entry
# (to find right position of 'xview').
ent.xview(ent.index('end'))
end end
end end

View file

@ -1590,14 +1590,16 @@ $floor_demo = TkToplevel.new {|w|
minsize(100,100) minsize(100,100)
} }
base_frame = TkFrame.new($floor_demo).pack(:fill=>:both, :expand=>true)
# label # label
TkLabel.new($floor_demo, 'font'=>$font, 'wraplength'=>'8i', 'justify'=>'left', TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'8i', 'justify'=>'left',
'text'=>"This window contains a canvas widget showing the floorplan of Digital Equipment Corporation's Western Research Laboratory. It has three levels. At any given time one of the levels is active, meaning that you can see its room structure. To activate a level, click the left mouse button anywhere on it. As the mouse moves over the active level, the room under the mouse lights up and its room number appears in the \"Room:\" entry. You can also type a room number in the entry and the room will light up."){ 'text'=>"This window contains a canvas widget showing the floorplan of Digital Equipment Corporation's Western Research Laboratory. It has three levels. At any given time one of the levels is active, meaning that you can see its room structure. To activate a level, click the left mouse button anywhere on it. As the mouse moves over the active level, the room under the mouse lights up and its room number appears in the \"Room:\" entry. You can also type a room number in the entry and the room will light up."){
pack('side'=>'top') pack('side'=>'top')
} }
# frame # frame
$floor_buttons = TkFrame.new($floor_demo) {|frame| $floor_buttons = TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -1620,17 +1622,17 @@ $floorItems = {}
# canvas # canvas
if $tk_version =~ /^4\.[01]/ if $tk_version =~ /^4\.[01]/
$floor_canvas_frame = TkFrame.new($floor_demo,'bd'=>2,'relief'=>'sunken', $floor_canvas_frame = TkFrame.new(base_frame,'bd'=>2,'relief'=>'sunken',
'highlightthickness'=>2) 'highlightthickness'=>2)
$floor_canvas = TkCanvas.new($floor_canvas_frame, $floor_canvas = TkCanvas.new($floor_canvas_frame,
'width'=>900, 'height'=>500, 'borderwidth'=>0, 'width'=>900, 'height'=>500, 'borderwidth'=>0,
'highlightthickness'=>0) {|c| 'highlightthickness'=>0) {|c|
TkScrollbar.new($floor_demo, 'orient'=>'horiz', TkScrollbar.new(base_frame, 'orient'=>'horiz',
'command'=>proc{|*args| c.xview(*args)}){|hs| 'command'=>proc{|*args| c.xview(*args)}){|hs|
c.xscrollcommand(proc{|first,last| hs.set first,last}) c.xscrollcommand(proc{|first,last| hs.set first,last})
pack('side'=>'bottom', 'fill'=>'x') pack('side'=>'bottom', 'fill'=>'x')
} }
TkScrollbar.new($floor_demo, 'command'=>proc{|*args| c.yview(*args)}){|vs| TkScrollbar.new(base_frame, 'command'=>proc{|*args| c.yview(*args)}){|vs|
c.yscrollcommand(proc{|first,last| vs.set first,last}) c.yscrollcommand(proc{|first,last| vs.set first,last})
pack('side'=>'right', 'fill'=>'y') pack('side'=>'right', 'fill'=>'y')
} }
@ -1639,7 +1641,7 @@ if $tk_version =~ /^4\.[01]/
$floor_canvas.pack('expand'=>'yes', 'fill'=>'both') $floor_canvas.pack('expand'=>'yes', 'fill'=>'both')
else else
TkFrame.new($floor_demo) {|f| TkFrame.new(base_frame) {|f|
pack('side'=>'top', 'fill'=>'both', 'expand'=>'yes') pack('side'=>'top', 'fill'=>'both', 'expand'=>'yes')
h = TkScrollbar.new(f, 'highlightthickness'=>0, 'orient'=>'horizontal') h = TkScrollbar.new(f, 'highlightthickness'=>0, 'orient'=>'horizontal')

View file

@ -1590,14 +1590,16 @@ $floor2_demo = TkToplevel.new {|w|
minsize(100,100) minsize(100,100)
} }
base_frame = TkFrame.new($floor2_demo).pack(:fill=>:both, :expand=>true)
# label # label
TkLabel.new($floor2_demo, 'font'=>$font, 'wraplength'=>'8i', 'justify'=>'left', TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'8i', 'justify'=>'left',
'text'=>"This window contains a canvas widget showing the floorplan of Digital Equipment Corporation's Western Research Laboratory. It has three levels. At any given time one of the levels is active, meaning that you can see its room structure. To activate a level, click the left mouse button anywhere on it. As the mouse moves over the active level, the room under the mouse lights up and its room number appears in the \"Room:\" entry. You can also type a room number in the entry and the room will light up."){ 'text'=>"This window contains a canvas widget showing the floorplan of Digital Equipment Corporation's Western Research Laboratory. It has three levels. At any given time one of the levels is active, meaning that you can see its room structure. To activate a level, click the left mouse button anywhere on it. As the mouse moves over the active level, the room under the mouse lights up and its room number appears in the \"Room:\" entry. You can also type a room number in the entry and the room will light up."){
pack('side'=>'top') pack('side'=>'top')
} }
# frame # frame
$floor2_buttons = TkFrame.new($floor2_demo) {|frame| $floor2_buttons = TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -1620,17 +1622,17 @@ $floorItems2 = {}
# canvas # canvas
if $tk_version =~ /^4\.[01]/ if $tk_version =~ /^4\.[01]/
$floor2_canvas_frame = TkFrame.new($floor2_demo,'bd'=>2,'relief'=>'sunken', $floor2_canvas_frame = TkFrame.new(base_frame,'bd'=>2,'relief'=>'sunken',
'highlightthickness'=>2) 'highlightthickness'=>2)
$floor2_canvas = TkCanvas.new($floor2_canvas_frame, $floor2_canvas = TkCanvas.new($floor2_canvas_frame,
'width'=>900, 'height'=>500, 'borderwidth'=>0, 'width'=>900, 'height'=>500, 'borderwidth'=>0,
'highlightthickness'=>0) {|c| 'highlightthickness'=>0) {|c|
TkScrollbar.new($floor2_demo, 'orient'=>'horiz', TkScrollbar.new(base_frame, 'orient'=>'horiz',
'command'=>proc{|*args| c.xview(*args)}){|hs| 'command'=>proc{|*args| c.xview(*args)}){|hs|
c.xscrollcommand(proc{|first,last| hs.set first,last}) c.xscrollcommand(proc{|first,last| hs.set first,last})
pack('side'=>'bottom', 'fill'=>'x') pack('side'=>'bottom', 'fill'=>'x')
} }
TkScrollbar.new($floor2_demo, 'command'=>proc{|*args| c.yview(*args)}){|vs| TkScrollbar.new(base_frame, 'command'=>proc{|*args| c.yview(*args)}){|vs|
c.yscrollcommand(proc{|first,last| vs.set first,last}) c.yscrollcommand(proc{|first,last| vs.set first,last})
pack('side'=>'right', 'fill'=>'y') pack('side'=>'right', 'fill'=>'y')
} }
@ -1639,7 +1641,7 @@ if $tk_version =~ /^4\.[01]/
$floor2_canvas.pack('expand'=>'yes', 'fill'=>'both') $floor2_canvas.pack('expand'=>'yes', 'fill'=>'both')
else else
TkFrame.new($floor2_demo) {|f| TkFrame.new(base_frame) {|f|
pack('side'=>'top', 'fill'=>'both', 'expand'=>'yes') pack('side'=>'top', 'fill'=>'both', 'expand'=>'yes')
h = TkScrollbar.new(f, 'highlightthickness'=>0, 'orient'=>'horizontal') h = TkScrollbar.new(f, 'highlightthickness'=>0, 'orient'=>'horizontal')

View file

@ -15,8 +15,10 @@ $form_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($form_demo).pack(:fill=>:both, :expand=>true)
# label # label
msg = TkLabel.new($form_demo) { msg = TkLabel.new(base_frame) {
font $font font $font
wraplength '4i' wraplength '4i'
justify 'left' justify 'left'
@ -25,7 +27,7 @@ msg = TkLabel.new($form_demo) {
msg.pack('side'=>'top', 'fill'=>'x') msg.pack('side'=>'top', 'fill'=>'x')
# frame # frame
TkFrame.new($form_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -44,7 +46,7 @@ TkFrame.new($form_demo) {|frame|
# entry # entry
form_data = [] form_data = []
(1..5).each{|i| (1..5).each{|i|
f = TkFrame.new($form_demo, 'bd'=>2) f = TkFrame.new(base_frame, 'bd'=>2)
e = TkEntry.new(f, 'relief'=>'sunken', 'width'=>40) e = TkEntry.new(f, 'relief'=>'sunken', 'width'=>40)
l = TkLabel.new(f) l = TkLabel.new(f)
e.pack('side'=>'right') e.pack('side'=>'right')

View file

@ -54,6 +54,8 @@ $goldberg_demo = TkToplevel.new {|w|
# positionWindow(w) # positionWindow(w)
} }
base_frame = TkFrame.new($goldberg_demo).pack(:fill=>:both, :expand=>true)
=begin =begin
# label # label
msg = TkLabel.new($goldberg_demo) { msg = TkLabel.new($goldberg_demo) {
@ -175,7 +177,8 @@ class TkGoldberg_Demo
do_ctrl_frame do_ctrl_frame
do_detail_frame do_detail_frame
msg = TkLabel.new(@parent, :bg=>@C['bg'], :fg=>'white') { # msg = TkLabel.new(@parent, :bg=>@C['bg'], :fg=>'white') {
msg = Tk::Label.new(@parent, :bg=>@C['bg'], :fg=>'white') {
font 'Arial 10' font 'Arial 10'
wraplength 600 wraplength 600
justify 'left' justify 'left'
@ -185,7 +188,8 @@ class TkGoldberg_Demo
frame = TkFrame.new(@parent, :bg=>@C['bg']) frame = TkFrame.new(@parent, :bg=>@C['bg'])
TkButton.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) { # TkButton.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) {
Tk::Button.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
tmppath = $goldberg_demo tmppath = $goldberg_demo
@ -194,12 +198,14 @@ class TkGoldberg_Demo
} }
}.pack('side'=>'left') }.pack('side'=>'left')
TkButton.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) { # TkButton.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) {
Tk::Button.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) {
text 'See Code' text 'See Code'
command proc{showCode 'goldberg'} command proc{showCode 'goldberg'}
}.pack('side'=>'left', 'padx'=>5) }.pack('side'=>'left', 'padx'=>5)
@show = TkButton.new(frame, :text=>'>>', :command=>proc{show_ctrl}, # @show = TkButton.new(frame, :text=>'>>', :command=>proc{show_ctrl},
@show = Tk::Button.new(frame, :text=>'>>', :command=>proc{show_ctrl},
:bg=>@C['bg'], :activebackground=>@C['bg']) :bg=>@C['bg'], :activebackground=>@C['bg'])
@show.pack('side'=>'left') @show.pack('side'=>'left')
frame.place(:in=>@canvas, :relx=>1, :rely=>0, :anchor=>:ne) frame.place(:in=>@canvas, :relx=>1, :rely=>0, :anchor=>:ne)
@ -208,10 +214,11 @@ class TkGoldberg_Demo
end end
def do_ctrl_frame def do_ctrl_frame
@start = TkButton.new(@parent, :text=>'Start', :bd=>6, @start = Tk::Button.new(@parent, :text=>'Start', :bd=>6,
:command=>proc{do_button(0)}) :command=>proc{do_button(0)})
@start.font(@start['font'].weight('bold')) if font = @start['font']
font = @start['font'] @start.font(font.weight('bold'))
end
@pause = TkCheckbutton.new(@parent, :text=>'Pause', :font=>font, @pause = TkCheckbutton.new(@parent, :text=>'Pause', :font=>font,
:command=>proc{do_button(1)}, :relief=>:raised, :command=>proc{do_button(1)}, :relief=>:raised,
@ -1996,4 +2003,4 @@ class TkGoldberg_Demo
end end
end end
TkGoldberg_Demo.new($goldberg_demo) TkGoldberg_Demo.new(base_frame)

View file

@ -11,8 +11,9 @@ $hscale_demo = TkToplevel.new {|w|
} }
positionWindow($hscale_demo) positionWindow($hscale_demo)
base_frame = TkFrame.new($hscale_demo).pack(:fill=>:both, :expand=>true)
msg = TkLabel.new($hscale_demo) { msg = TkLabel.new(base_frame) {
font $font font $font
wraplength '3.5i' wraplength '3.5i'
justify 'left' justify 'left'
@ -20,7 +21,7 @@ msg = TkLabel.new($hscale_demo) {
} }
msg.pack('side'=>'top') msg.pack('side'=>'top')
TkFrame.new($hscale_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc { command proc {
@ -36,7 +37,18 @@ TkFrame.new($hscale_demo) {|frame|
}.pack('side'=>'left', 'expand'=>'yes') }.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
TkFrame.new($hscale_demo) {|frame|
def setWidth(w, width)
width = width + 21
x2 = width - 30
if x2 < 21
x2 = 21
end
w.coords 'poly',20,15,20,35,x2,35,x2,45,width,25,x2,5,x2,15,20,15
w.coords 'line',20,15,20,35,x2,35,x2,45,width,25,x2,5,x2,15,20,15
end
TkFrame.new(base_frame) {|frame|
canvas = TkCanvas.new(frame) {|c| canvas = TkCanvas.new(frame) {|c|
width 50 width 50
height 50 height 50
@ -61,14 +73,3 @@ TkFrame.new($hscale_demo) {|frame|
}.pack('side'=>'bottom', 'expand'=>'yes', 'anchor'=>'n') }.pack('side'=>'bottom', 'expand'=>'yes', 'anchor'=>'n')
scale.set 75 scale.set 75
}.pack('side'=>'top', 'fill'=>'x') }.pack('side'=>'top', 'fill'=>'x')
def setWidth(w, width)
width = width + 21
x2 = width - 30
if x2 < 21
x2 = 21
end
w.coords 'poly',20,15,20,35,x2,35,x2,45,width,25,x2,5,x2,15,20,15
w.coords 'line',20,15,20,35,x2,35,x2,45,width,25,x2,5,x2,15,20,15
end

View file

@ -19,8 +19,10 @@ $icon_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($icon_demo).pack(:fill=>:both, :expand=>true)
# label # label
msg = TkLabel.new($icon_demo) { msg = TkLabel.new(base_frame) {
font $font font $font
wraplength '5i' wraplength '5i'
justify 'left' justify 'left'
@ -29,7 +31,7 @@ msg = TkLabel.new($icon_demo) {
msg.pack('side'=>'top') msg.pack('side'=>'top')
# frame # frame
TkFrame.new($icon_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -63,16 +65,18 @@ TkBitmapImage.new('file'=>[$demo_dir,'..',
letters = TkVariable.new letters = TkVariable.new
# frame # frame
TkFrame.new($icon_demo, 'borderwidth'=>10){|w| TkFrame.new(base_frame, 'borderwidth'=>10){|w|
TkFrame.new(w) {|f| TkFrame.new(w) {|f|
TkRadioButton.new(f){ # TkRadioButton.new(f){
Tk::RadioButton.new(f){
bitmap '@' + [$demo_dir,'..', bitmap '@' + [$demo_dir,'..',
'images','letters.xbm'].join(File::Separator) 'images','letters.xbm'].join(File::Separator)
variable letters variable letters
value 'full' value 'full'
}.pack('side'=>'top', 'expand'=>'yes') }.pack('side'=>'top', 'expand'=>'yes')
TkRadioButton.new(f){ # TkRadioButton.new(f){
Tk::RadioButton.new(f){
bitmap '@' + [$demo_dir,'..', bitmap '@' + [$demo_dir,'..',
'images','noletter.xbm'].join(File::Separator) 'images','noletter.xbm'].join(File::Separator)
variable letters variable letters
@ -81,14 +85,16 @@ TkFrame.new($icon_demo, 'borderwidth'=>10){|w|
}.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'5m') }.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'5m')
TkCheckButton.new(w) { # TkCheckButton.new(w) {
Tk::CheckButton.new(w) {
image flagdown image flagdown
selectimage flagup selectimage flagup
indicatoron 0 indicatoron 0
selectcolor self['background'] selectcolor self['background']
}.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'5m') }.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'5m')
TkCheckButton.new(w) { # TkCheckButton.new(w) {
Tk::CheckButton.new(w) {
bitmap '@' + [$demo_dir,'..', bitmap '@' + [$demo_dir,'..',
'images','letters.xbm'].join(File::Separator) 'images','letters.xbm'].join(File::Separator)
indicatoron 0 indicatoron 0

View file

@ -18,8 +18,10 @@ $image1_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($image1_demo).pack(:fill=>:both, :expand=>true)
# label # label
msg = TkLabel.new($image1_demo) { msg = TkLabel.new(base_frame) {
font $font font $font
wraplength '4i' wraplength '4i'
justify 'left' justify 'left'
@ -28,7 +30,7 @@ msg = TkLabel.new($image1_demo) {
msg.pack('side'=>'top') msg.pack('side'=>'top')
# frame # frame
TkFrame.new($image1_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -54,7 +56,10 @@ TkPhotoImage.new('file'=>[$demo_dir,'..',
'images','earthris.gif'].join(File::Separator)) 'images','earthris.gif'].join(File::Separator))
# label # label
[ TkLabel.new($image1_demo, 'image'=>image1a, 'bd'=>1, 'relief'=>'sunken'), #[ TkLabel.new(base_frame, 'image'=>image1a, 'bd'=>1, 'relief'=>'sunken'),
TkLabel.new($image1_demo, 'image'=>image1b, 'bd'=>1, 'relief'=>'sunken') # TkLabel.new(base_frame, 'image'=>image1b, 'bd'=>1, 'relief'=>'sunken')
#].each{|w| w.pack('side'=>'top', 'padx'=>'.5m', 'pady'=>'.5m')}
[ Tk::Label.new(base_frame, 'image'=>image1a, 'bd'=>1, 'relief'=>'sunken'),
Tk::Label.new(base_frame, 'image'=>image1b, 'bd'=>1, 'relief'=>'sunken')
].each{|w| w.pack('side'=>'top', 'padx'=>'.5m', 'pady'=>'.5m')} ].each{|w| w.pack('side'=>'top', 'padx'=>'.5m', 'pady'=>'.5m')}

View file

@ -19,8 +19,10 @@ $image2_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($image2_demo).pack(:fill=>:both, :expand=>true)
# label # label
msg = TkLabel.new($image2_demo) { msg = TkLabel.new(base_frame) {
font $font font $font
wraplength '4i' wraplength '4i'
justify 'left' justify 'left'
@ -29,7 +31,7 @@ msg = TkLabel.new($image2_demo) {
msg.pack('side'=>'top') msg.pack('side'=>'top')
# frame # frame
TkFrame.new($image2_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -53,21 +55,21 @@ $dirName = TkVariable.new([$demo_dir,'..','images'].join(File::Separator))
$image2a = TkPhotoImage.new $image2a = TkPhotoImage.new
# #
TkLabel.new($image2_demo, 'text'=>'Directory:')\ TkLabel.new(base_frame, 'text'=>'Directory:')\
.pack('side'=>'top', 'anchor'=>'w') .pack('side'=>'top', 'anchor'=>'w')
image2_e = TkEntry.new($image2_demo) { image2_e = TkEntry.new(base_frame) {
width 30 width 30
textvariable $dirName textvariable $dirName
}.pack('side'=>'top', 'anchor'=>'w') }.pack('side'=>'top', 'anchor'=>'w')
TkFrame.new($image2_demo, 'height'=>'3m', 'width'=>20)\ TkFrame.new(base_frame, 'height'=>'3m', 'width'=>20)\
.pack('side'=>'top', 'anchor'=>'w') .pack('side'=>'top', 'anchor'=>'w')
TkLabel.new($image2_demo, 'text'=>'File:')\ TkLabel.new(base_frame, 'text'=>'File:')\
.pack('side'=>'top', 'anchor'=>'w') .pack('side'=>'top', 'anchor'=>'w')
TkFrame.new($image2_demo){|w| TkFrame.new(base_frame){|w|
s = TkScrollbar.new(w) s = TkScrollbar.new(w)
l = TkListbox.new(w) { l = TkListbox.new(w) {
width 20 width 20
@ -86,9 +88,9 @@ TkFrame.new($image2_demo){|w|
}.pack('side'=>'top', 'anchor'=>'w') }.pack('side'=>'top', 'anchor'=>'w')
# image # image
[ TkFrame.new($image2_demo, 'height'=>'3m', 'width'=>20), [ TkFrame.new(base_frame, 'height'=>'3m', 'width'=>20),
TkLabel.new($image2_demo, 'text'=>'Image:'), TkLabel.new(base_frame, 'text'=>'Image:'),
TkLabel.new($image2_demo, 'image'=>$image2a) TkLabel.new(base_frame, 'image'=>$image2a)
].each{|w| w.pack('side'=>'top', 'anchor'=>'w')} ].each{|w| w.pack('side'=>'top', 'anchor'=>'w')}
# #

View file

@ -19,27 +19,29 @@ $image3_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($image3_demo).pack(:fill=>:both, :expand=>true)
# #
def loadDir(w) def loadDir3(w)
w.delete(0,'end') w.delete(0,'end')
Dir.glob([$dirName,'*'].join(File::Separator)).sort.each{|f| Dir.glob([$dirName,'*'].join(File::Separator)).sort.each{|f|
w.insert('end',File.basename(f)) w.insert('end',File.basename(f))
} }
end end
# selectAndLoadDir -- # selectAndLoadDir3 --
# This procedure pops up a dialog to ask for a directory to load into # This procedure pops up a dialog to ask for a directory to load into
# the listobx and (if the user presses OK) reloads the directory # the listobx and (if the user presses OK) reloads the directory
# listbox from the directory named in the demo's entry. # listbox from the directory named in the demo's entry.
# #
# Arguments: # Arguments:
# w - Name of the toplevel window of the demo. # w - Name of the toplevel window of the demo.
def selectAndLoadDir(w, lbox) def selectAndLoadDir3(w, lbox)
dir = Tk.chooseDirectory(:initialdir=>$dirName.value, dir = Tk.chooseDirectory(:initialdir=>$dirName.value,
:parent=>w, :mustexist=>true) :parent=>w, :mustexist=>true)
if dir.length > 0 if dir.length > 0
$dirName.value = dir $dirName.value = dir
loadDir(lbox) loadDir3(lbox)
end end
end end
@ -49,7 +51,7 @@ end
# label # label
msg = TkLabel.new($image3_demo) { msg = TkLabel.new(base_frame) {
font $font font $font
wraplength '4i' wraplength '4i'
justify 'left' justify 'left'
@ -58,7 +60,7 @@ msg = TkLabel.new($image3_demo) {
msg.pack('side'=>'top') msg.pack('side'=>'top')
# frame # frame
TkFrame.new($image3_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -86,11 +88,11 @@ end
$image3a = TkPhotoImage.new $image3a = TkPhotoImage.new
# #
image3_f = TkFrame.new($image3_demo).pack(:fill=>:both, :expand=>true) image3_f = TkFrame.new(base_frame).pack(:fill=>:both, :expand=>true)
image3_df = TkLabelFrame.new($image3_demo, :text=>'Directory:') image3_df = TkLabelFrame.new(base_frame, :text=>'Directory:')
image3_ff = TkLabelFrame.new($image3_demo, :text=>'File:', image3_ff = TkLabelFrame.new(base_frame, :text=>'File:',
:padx=>'2m', :pady=>'2m') :padx=>'2m', :pady=>'2m')
image3_lbx = TkListbox.new(image3_ff, :width=>20, :height=>10) { image3_lbx = TkListbox.new(image3_ff, :width=>20, :height=>10) {
pack(:side=>:left, :fill=>:y, :expand=>true) pack(:side=>:left, :fill=>:y, :expand=>true)
@ -102,16 +104,17 @@ image3_lbx = TkListbox.new(image3_ff, :width=>20, :height=>10) {
image3_ent = TkEntry.new(image3_df, :width=>30, :textvariable=>$dirName){ image3_ent = TkEntry.new(image3_df, :width=>30, :textvariable=>$dirName){
pack(:side=>:left, :fill=>:both, :padx=>'2m', :pady=>'2m', :expand=>true) pack(:side=>:left, :fill=>:both, :padx=>'2m', :pady=>'2m', :expand=>true)
bind('Return', proc{loadDir(image3_lbx)}) bind('Return', proc{loadDir3(image3_lbx)})
} }
TkButton.new(image3_df, :pady=>0, :padx=>'2m', :text=>"Select Dir.", TkButton.new(image3_df, :pady=>0, :padx=>'2m', :text=>"Select Dir.",
:command=>proc{selectAndLoadDir(image3_ent, image3_lbx)}) { :command=>proc{selectAndLoadDir3(image3_ent, image3_lbx)}) {
pack(:side=>:left, :fill=>:y, :padx=>[0, '2m'], :pady=>'2m') pack(:side=>:left, :fill=>:y, :padx=>[0, '2m'], :pady=>'2m')
} }
image3_if = TkLabelFrame.new($image3_demo, :text=>'Image:') {|f| image3_if = TkLabelFrame.new(base_frame, :text=>'Image:') {|f|
TkLabel.new(f, :image=>$image3a).pack(:padx=>'2m', :pady=>'2m') # TkLabel.new(f, :image=>$image3a).pack(:padx=>'2m', :pady=>'2m')
Tk::Label.new(f, :image=>$image3a).pack(:padx=>'2m', :pady=>'2m')
} }
Tk.grid(image3_df, '-', Tk.grid(image3_df, '-',

View file

@ -19,8 +19,10 @@ $items_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($items_demo).pack(:fill=>:both, :expand=>true)
# label # label
TkLabel.new($items_demo) { TkLabel.new(base_frame) {
font $font font $font
wraplength '5i' wraplength '5i'
justify 'left' justify 'left'
@ -28,7 +30,7 @@ TkLabel.new($items_demo) {
}.pack('side'=>'top') }.pack('side'=>'top')
# frame # frame
TkFrame.new($items_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -46,7 +48,7 @@ TkFrame.new($items_demo) {|frame|
# frame # frame
cvs = nil cvs = nil
TkFrame.new($items_demo) {|cf| TkFrame.new(base_frame) {|cf|
# canvas # canvas
cvs = TkCanvas.new(cf) {|c| cvs = TkCanvas.new(cf) {|c|
focus focus

View file

@ -0,0 +1,271 @@
# Based on the widget demo of Tcl/Tk8.5.2
# The following is the original copyright text.
#----------------------------------------------------------------------------
# Copyright (C) 2008 Pat Thoyts <patthoyts@users.sourceforge.net>
#
# Calculate a Knight's tour of a chessboard.
#
# This uses Warnsdorff's rule to calculate the next square each
# time. This specifies that the next square should be the one that
# has the least number of available moves.
#
# Using this rule it is possible to get to a position where
# there are no squares available to move into. In this implementation
# this occurs when the starting square is d6.
#
# To solve this fault an enhancement to the rule is that if we
# have a choice of squares with an equal score, we should choose
# the one nearest the edge of the board.
#
# If the call to the Edgemost function is commented out you can see
# this occur.
#
# You can drag the knight to a specific square to start if you wish.
# If you let it repeat then it will choose random start positions
# for each new tour.
#----------------------------------------------------------------------------
require 'tk'
class Knights_Tour
# Return a list of accessible squares from a given square
def valid_moves(square)
moves = []
[
[-1,-2], [-2,-1], [-2,1], [-1,2], [1,2], [2,1], [2,-1], [1,-2]
].each{|col_delta, row_delta|
col = (square % 8) + col_delta
row = (square.div(8)) + row_delta
moves << (row * 8 + col) if row > -1 && row < 8 && col > -1 && col < 8
}
moves
end
# Return the number of available moves for this square
def check_square(square)
valid_moves(square).find_all{|pos| ! @visited.include?(pos)}.length
end
# Select the next square to move to. Returns -1 if there are no available
# squares remaining that we can move to.
def next_square(square)
minimum = 9
nxt = -1
valid_moves(square).each{|pos|
unless @visited.include?(pos)
cnt = check_square(pos)
if cnt < minimum
minimum = cnt
nxt = pos
elsif cnt == minimum
nxt = edgemost(nxt, pos)
end
end
}
nxt
end
# Select the square nearest the edge of the board
def edgemost(nxt, pos)
col_A = 3 - ((3.5 - nxt % 8).abs.to_i)
col_B = 3 - ((3.5 - pos % 8).abs.to_i)
row_A = 3 - ((3.5 - nxt.div(8)).abs.to_i)
row_B = 3 - ((3.5 - pos.div(8)).abs.to_i)
(col_A * row_A < col_B * row_B)? nxt : pos
end
# Display a square number as a standard chess square notation.
def _N(square)
'%c%d' % [(97 + square % 8), (square.div(8) + 1)]
end
# Perform a Knight's move and schedule the next move.
def move_piece(last, square)
@log.insert(:end, "#{@visited.length}. #{_N last} -> #{_N square}\n", '')
@log.see(:end)
@board.itemconfigure(1+last, :state=>:normal, :outline=>'black')
@board.itemconfigure(1+square, :state=>:normal, :outline=>'red')
@knight.coords(@board.coords(1+square)[0..1])
@visited << square
if (nxt = next_square(square)) != -1
@after_id = Tk.after(@delay.numeric){move_piece(square, nxt) rescue nil}
else
@start_btn.state :normal
if @visited.length == 64
if @initial == square
@log.insert :end, 'Closed tour!'
else
@log.insert :end, "Success\n", {}
Tk.after(@delay.numeric * 2){tour(rand(64))} if @continuous.bool
end
else
@log.insert :end, "FAILED!\n", {}
end
end
end
# Begin a new tour of the board given a random start position
def tour(square = nil)
@visited.clear
@log.clear
@start_btn.state :disabled
1.upto(64){|n|
@board.itemconfigure(n, :state=>:disabled, :outline=>'black')
}
unless square
square = @board.find_closest(*(@knight.coords << 0 << 65))[0].to_i - 1
end
@initial = square
Tk.after_idle{ move_piece(@initial, @initial) rescue nil }
end
def _stop
Tk.after_cancel(@after_id) rescue nil
end
def _exit
_stop
$knightstour.destroy
end
def set_delay(new)
@delay.numeric = new.to_i
end
def drag_start(w, x, y)
w.dtag('selected')
w.addtag('selected', :withtag, 'current')
@dragging = [x, y]
end
def drag_motion(w, x, y)
return unless @dragging
w.move('selected', x - @dragging[0], y - @dragging[1])
@dragging = [x, y]
end
def drag_end(w, x, y)
square = w.find_closest(x, y, 0, 65)
w.coords('selected', w.coords(square)[0..1])
w.dtag('selected')
@dragging = nil
end
def make_SeeDismiss
## See Code / Dismiss
frame = Ttk::Frame.new($knightstour)
sep = Ttk::Separator.new(frame)
Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
TkGrid('x',
Ttk::Button.new(frame, :text=>'See Code',
:image=>$image['view'], :compound=>:left,
:command=>proc{showCode 'knightstour'}),
Ttk::Button.new(frame, :text=>'Dismiss',
:image=>$image['delete'], :compound=>:left,
:command=>proc{
$knightstour.destroy
$knightstour = nil
}),
:padx=>4, :pady=>4)
frame.grid_columnconfigure(0, :weight=>1)
frame
end
def create_gui(parent = nil)
$knightstour.destroy rescue nil
$knightstour = Tk::Toplevel.new(parent, :title=>"Knight's tour")
$knightstour.withdraw
base_f = Ttk::Frame.new($knightstour)
@board = Tk::Canvas.new(base_f, :width=>240, :height=>240)
@log = Tk::Text.new(base_f, :width=>12, :height=>1,
:font=>'Arial 8', :background=>'white')
scr = @log.yscrollbar(Ttk::Scrollbar.new(base_f))
@visited = []
@delay = TkVariable.new(600)
@continuous = TkVariable.new(false)
tool_f = Ttk::Frame.new($knightstour)
label = Ttk::Label.new(tool_f, :text=>'Speed')
scale = Ttk::Scale.new(tool_f, :from=>8, :to=>2000, :variable=>@delay,
:command=>proc{|n| set_delay(n)})
check = Ttk::Checkbutton.new(tool_f, :text=>'Repeat',
:variable=>@continuous)
@start_btn = Ttk::Button.new(tool_f, :text=>'Start',
:command=>proc{tour()})
@exit_btn = Ttk::Button.new(tool_f, :text=>'Exit',
:command=>proc{_exit()})
7.downto(0){|row|
0.upto(7){|col|
if ((col & 1) ^ (row & 1)).zero?
fill = 'bisque'
dfill = 'bisque3'
else
fill = 'tan3'
dfill = 'tan4'
end
coords = [col * 30 + 4, row * 30 + 4, col * 30 + 30, row * 30 + 30]
@board.create(TkcRectangle, coords,
:fill=>fill, :disabledfill=>dfill,
:width=>2, :state=>:disabled)
}
}
@knight_font = TkFont.new(:size=>-24)
@knight = TkcText.new(@board, 0, 0, :font=>@knight_font,
:text=>Tk::UTF8_String.new('\u265e'),
:anchor=>'nw', # :tags=>'knight',
:fill=>'black', :activefill=>'#600000')
@knight.coords(@board.coords(rand(64)+1)[0..1])
@knight.bind('ButtonPress-1', '%W %x %y'){|w,x,y| drag_start(w,x,y)}
@knight.bind('Motion', '%W %x %y'){|w,x,y| drag_motion(w,x,y)}
@knight.bind('ButtonRelease-1', '%W %x %y'){|w,x,y| drag_end(w,x,y)}
Tk.grid(@board, @log, scr, :sticky=>'news')
base_f.grid_rowconfigure(0, :weight=>1)
base_f.grid_columnconfigure(0, :weight=>1)
Tk.grid(base_f, '-', '-', '-', '-', '-', :sticky=>'news')
widgets = [label, scale, check, @start_btn]
sg = nil
unless $RubyTk_WidgetDemo
widgets << @exit_btn
if Tk.windowingsystem != 'aqua'
#widgets.unshift(Ttk::SizeGrip.new(tool_f))
Ttk::SizeGrip.new(tool_f).pack(:side=>:right, :anchor=>'se')
end
end
Tk.pack(widgets, :side=>:right)
if Tk.windowingsystem == 'aqua'
TkPack.configure(widgets, :padx=>[4, 4], :pady=>[12, 12])
TkPack.configure(widgets[0], :padx=>[4, 24])
TkPack.configure(widgets[-1], :padx=>[16, 4])
end
Tk.grid(tool_f, '-', '-', '-', '-', '-', :sticky=>'ew')
if $RubyTk_WidgetDemo
Tk.grid(make_SeeDismiss(), '-', '-', '-', '-', '-', :sticky=>'ew')
end
$knightstour.grid_rowconfigure(0, :weight=>1)
$knightstour.grid_columnconfigure(0, :weight=>1)
$knightstour.bind('Control-F2'){TkConsole.show}
$knightstour.bind('Return'){@start_btn.invoke}
$knightstour.bind('Escape'){@exit_btn.invoke}
$knightstour.bind('Destroy'){ _stop }
$knightstour.protocol('WM_DELETE_WINDOW'){ _exit }
$knightstour.deiconify
$knightstour.tkwait_destroy
end
def initialize(parent = nil)
create_gui(parent)
end
end
Tk.root.withdraw unless $RubyTk_WidgetDemo
Thread.new{Tk.mainloop} if __FILE__ == $0
Knights_Tour.new

View file

@ -19,8 +19,10 @@ $label_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($label_demo).pack(:fill=>:both, :expand=>true)
# label # label
msg = TkLabel.new($label_demo) { msg = TkLabel.new(base_frame) {
font $font font $font
wraplength '4i' wraplength '4i'
justify 'left' justify 'left'
@ -29,7 +31,7 @@ msg = TkLabel.new($label_demo) {
msg.pack('side'=>'top') msg.pack('side'=>'top')
# frame # frame
TkFrame.new($label_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -47,8 +49,8 @@ TkFrame.new($label_demo) {|frame|
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# label demo # label demo
f_left = TkFrame.new($label_demo) f_left = TkFrame.new(base_frame)
f_right = TkFrame.new($label_demo) f_right = TkFrame.new(base_frame)
[f_left, f_right].each{|w| w.pack('side'=>'left', 'expand'=>'yes', [f_left, f_right].each{|w| w.pack('side'=>'left', 'expand'=>'yes',
'padx'=>10, 'pady'=>10, 'fill'=>'both')} 'padx'=>10, 'pady'=>10, 'fill'=>'both')}
@ -59,7 +61,8 @@ f_right = TkFrame.new($label_demo)
TkLabel.new(f_left, 'text'=>'Third label, sunken', 'relief'=>'sunken') TkLabel.new(f_left, 'text'=>'Third label, sunken', 'relief'=>'sunken')
].each{|w| w.pack('side'=>'top', 'expand'=>'yes', 'pady'=>2, 'anchor'=>'w')} ].each{|w| w.pack('side'=>'top', 'expand'=>'yes', 'pady'=>2, 'anchor'=>'w')}
TkLabel.new(f_right) { # TkLabel.new(f_right) {
Tk::Label.new(f_right) {
bitmap('@' + [$demo_dir,'..','images','face.xbm'].join(File::Separator)) bitmap('@' + [$demo_dir,'..','images','face.xbm'].join(File::Separator))
borderwidth 2 borderwidth 2
relief 'sunken' relief 'sunken'

View file

@ -17,8 +17,10 @@ $labelframe_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($labelframe_demo).pack(:fill=>:both, :expand=>true)
# Some information # Some information
TkLabel.new($labelframe_demo, TkLabel.new(base_frame,
:font=>$font, :wraplength=>'4i', :justify=>:left, :font=>$font, :wraplength=>'4i', :justify=>:left,
:text=><<EOL).pack(:side=>:top) :text=><<EOL).pack(:side=>:top)
Labelframes are used to group related widgets together. \ Labelframes are used to group related widgets together. \
@ -29,7 +31,7 @@ which supports a 'labelframe' widget.
EOL EOL
# The bottom buttons # The bottom buttons
TkFrame.new($labelframe_demo){|f| TkFrame.new(base_frame){|f|
pack(:side=>:bottom, :fill=>:x, :pady=>'2m') pack(:side=>:bottom, :fill=>:x, :pady=>'2m')
TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{ TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{
@ -43,7 +45,7 @@ TkFrame.new($labelframe_demo){|f|
} }
# Demo area # Demo area
w = TkFrame.new($labelframe_demo).pack(:side=>:bottom, :fill=>:both, w = TkFrame.new(base_frame).pack(:side=>:bottom, :fill=>:both,
:expand=>true) :expand=>true)
# A group of radiobuttons in a labelframe # A group of radiobuttons in a labelframe

View file

@ -0,0 +1,117 @@
# mclist.rb --
#
# This demonstration script creates a toplevel window containing a Ttk
# tree widget configured as a multi-column listbox.
#
# based on "Id: mclist.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp"
if defined?($mclist_demo) && $mclist_demo
$mclist_demo.destroy
$mclist_demo = nil
end
$mclist_demo = TkToplevel.new {|w|
title("Multi-Column List")
iconname("mclist")
positionWindow(w)
}
base_frame = TkFrame.new($mclist_demo).pack(:fill=>:both, :expand=>true)
## Explanatory text
Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i',
:justify=>:left, :anchor=>'n', :padding=>[10, 2, 10, 6],
:text=><<EOL).pack(:fill=>:x)
Ttk is the new Tk themed widget set. \
One of the widgets it includes is a tree widget, \
which can be configured to display multiple columns of informational data \
without displaying the tree itself. \
This is a simple way to build a listbox that has multiple columns. \
Clicking on the heading for a column will sort the data by that column. \
You can also change the width of the columns \
by dragging the boundary between them.
EOL
## See Code / Dismiss
Ttk::Frame.new(base_frame) {|frame|
sep = Ttk::Separator.new(frame)
Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
TkGrid('x',
Ttk::Button.new(frame, :text=>'See Code',
:image=>$image['view'], :compound=>:left,
:command=>proc{showCode 'mclist'}),
Ttk::Button.new(frame, :text=>'Dismiss',
:image=>$image['delete'], :compound=>:left,
:command=>proc{
$mclist_demo.destroy
$mclist_demo = nil
}),
:padx=>4, :pady=>4)
grid_columnconfigure(0, :weight=>1)
pack(:side=>:bottom, :fill=>:x)
}
container = Ttk::Frame.new(base_frame)
tree = Ttk::Treeview.new(base_frame, :columns=>%w(country capital currency),
:show=>:headings)
if Tk.windowingsystem != 'aqua'
vsb = tree.yscrollbar(Ttk::Scrollbar.new(base_frame))
hsb = tree.xscrollbar(Ttk::Scrollbar.new(base_frame))
else
vsb = tree.yscrollbar(Tk::Scrollbar.new(base_frame))
hsb = tree.xscrollbar(Tk::Scrollbar.new(base_frame))
end
container.pack(:fill=>:both, :expand=>true)
Tk.grid(tree, vsb, :in=>container, :sticky=>'nsew')
Tk.grid(hsb, :in=>container, :sticky=>'nsew')
container.grid_columnconfigure(0, :weight=>1)
container.grid_rowconfigure(0, :weight=>1)
## The data we're going to insert
data = [
['Argentina', 'Buenos Aires', 'ARS'],
['Australia', 'Canberra', 'AUD'],
['Brazil', 'Brazilia', 'BRL'],
['Canada', 'Ottawa', 'CAD'],
['China', 'Beijing', 'CNY'],
['France', 'Paris', 'EUR'],
['Germany', 'Berlin', 'EUR'],
['India', 'New Delhi', 'INR'],
['Italy', 'Rome', 'EUR'],
['Japan', 'Tokyo', 'JPY'],
['Mexico', 'Mexico City', 'MXN'],
['Russia', 'Moscow', 'RUB'],
['South Africa', 'Pretoria', 'ZAR'],
['United Kingdom', 'London', 'GBP'],
['United States', 'Washington, D.C.', 'USD'],
]
## Code to insert the data nicely
font = Ttk::Style.lookup(tree[:style], :font)
cols = %w(country capital currency)
cols.zip(%w(Country Capital Currency)).each{|col, name|
tree.heading_configure(col, :text=>name,
:command=>proc{sort_by(tree, col, false)})
tree.column_configure(col, :width=>TkFont.measure(font, name))
}
data.each{|country, capital, currency|
#tree.insert('', :end, :values=>[country, capital, currency])
tree.insert(nil, :end, :values=>[country, capital, currency])
cols.zip([country, capital, currency]).each{|col, val|
len = TkFont.measure(font, "#{val} ")
if tree.column_cget(col, :width) < len
tree.column_configure(col, :width=>len)
end
}
}
## Code to do the sorting of the tree contents when clicked on
def sort_by(tree, col, direction)
tree.children(nil).map!{|row| [tree.get(row, col), row.id]} .
sort(&((direction)? proc{|x, y| y <=> x}: proc{|x, y| x <=> y})) .
each_with_index{|info, idx| tree.move(info[1], nil, idx)}
tree.heading_configure(col, :command=>proc{sort_by(tree, col, ! direction)})
end

View file

@ -15,8 +15,10 @@ $menu_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($menu_demo).pack(:fill=>:both, :expand=>true)
# menu frame # menu frame
$menu_frame = TkFrame.new($menu_demo, 'relief'=>'raised', 'bd'=>2) $menu_frame = TkFrame.new(base_frame, 'relief'=>'raised', 'bd'=>2)
$menu_frame.pack('side'=>'top', 'fill'=>'x') $menu_frame.pack('side'=>'top', 'fill'=>'x')
begin begin
@ -26,7 +28,7 @@ rescue
end end
# label # label
TkLabel.new($menu_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
if $tk_platform['platform'] == 'macintosh' || if $tk_platform['platform'] == 'macintosh' ||
windowingsystem == "classic" || windowingsystem == "aqua" windowingsystem == "classic" || windowingsystem == "aqua"
text("This window contains a menubar with cascaded menus. You can invoke entries with an accelerator by typing Command+x, where \"x\" is the character next to the command key symbol. The rightmost menu can be torn off into a palette by dragging outside of its bounds and releasing the mouse.") text("This window contains a menubar with cascaded menus. You can invoke entries with an accelerator by typing Command+x, where \"x\" is the character next to the command key symbol. The rightmost menu can be torn off into a palette by dragging outside of its bounds and releasing the mouse.")
@ -36,7 +38,7 @@ TkLabel.new($menu_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
}.pack('side'=>'top') }.pack('side'=>'top')
# frame # frame
TkFrame.new($menu_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -105,7 +107,7 @@ TkMenubutton.new($menu_frame, 'text'=>'Cascades', 'underline'=>0) {|m|
'accelerator'=>"#{modifier}+G", 'underline'=>6) 'accelerator'=>"#{modifier}+G", 'underline'=>6)
$menu_demo.bind("#{modifier}-g", proc{print "Goodbye\n"}) $menu_demo.bind("#{modifier}-g", proc{print "Goodbye\n"})
TkMenu.new(m, 'tearoff'=>false) {|cascade_check| TkMenu.new(cascade_menu, 'tearoff'=>false) {|cascade_check|
cascade_menu.add('cascade', 'label'=>'Check buttons', cascade_menu.add('cascade', 'label'=>'Check buttons',
'menu'=>cascade_check, 'underline'=>0) 'menu'=>cascade_check, 'underline'=>0)
oil = TkVariable.new(0) oil = TkVariable.new(0)
@ -127,7 +129,7 @@ TkMenubutton.new($menu_frame, 'text'=>'Cascades', 'underline'=>0) {|m|
invoke 3 invoke 3
} }
TkMenu.new(m, 'tearoff'=>false) {|cascade_radio| TkMenu.new(cascade_menu, 'tearoff'=>false) {|cascade_radio|
cascade_menu.add('cascade', 'label'=>'Radio buttons', cascade_menu.add('cascade', 'label'=>'Radio buttons',
'menu'=>cascade_radio, 'underline'=>0) 'menu'=>cascade_radio, 'underline'=>0)
pointSize = TkVariable.new pointSize = TkVariable.new

View file

@ -15,6 +15,8 @@ $menu84_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($menu84_demo).pack(:fill=>:both, :expand=>true)
begin begin
windowingsystem = Tk.windowingsystem() windowingsystem = Tk.windowingsystem()
rescue rescue
@ -22,7 +24,7 @@ rescue
end end
# label # label
TkLabel.new($menu84_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
if $tk_platform['platform'] == 'macintosh' || if $tk_platform['platform'] == 'macintosh' ||
windowingsystem == "classic" || windowingsystem == "aqua" windowingsystem == "classic" || windowingsystem == "aqua"
text("This window contains a menubar with cascaded menus. You can invoke entries with an accelerator by typing Command+x, where \"x\" is the character next to the command key symbol. The rightmost menu can be torn off into a palette by dragging outside of its bounds and releasing the mouse.") text("This window contains a menubar with cascaded menus. You can invoke entries with an accelerator by typing Command+x, where \"x\" is the character next to the command key symbol. The rightmost menu can be torn off into a palette by dragging outside of its bounds and releasing the mouse.")
@ -33,7 +35,7 @@ TkLabel.new($menu84_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
menustatus = TkVariable.new(" ") menustatus = TkVariable.new(" ")
TkFrame.new($menu84_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkLabel.new(frame, 'textvariable'=>menustatus, 'relief'=>'sunken', TkLabel.new(frame, 'textvariable'=>menustatus, 'relief'=>'sunken',
'bd'=>1, 'font'=>['Helvetica', '10'], 'bd'=>1, 'font'=>['Helvetica', '10'],
'anchor'=>'w').pack('side'=>'left', 'padx'=>2, 'anchor'=>'w').pack('side'=>'left', 'padx'=>2,
@ -43,7 +45,7 @@ TkFrame.new($menu84_demo) {|frame|
# frame # frame
TkFrame.new($menu84_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{

View file

@ -37,16 +37,18 @@ $menubu_demo = TkToplevel.new {|w|
positionWindow($menubu_demo) positionWindow($menubu_demo)
base_frame = TkFrame.new($menubu_demo).pack(:fill=>:both, :expand=>true)
# version check # version check
if $tk_version.to_f < 8.0 if $tk_version.to_f < 8.0
# label # label
TkLabel.new($menubu_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
text("This is a demonstration of menubuttons. The \"Below\" menubutton pops its menu below the button; the \"Right\" button pops to the right, etc. There are two option menus directly below this text; one is just a standard menu and the other is a 16-color palette.") text("This is a demonstration of menubuttons. The \"Below\" menubutton pops its menu below the button; the \"Right\" button pops to the right, etc. There are two option menus directly below this text; one is just a standard menu and the other is a 16-color palette.")
}.pack('side'=>'top') }.pack('side'=>'top')
# frame # frame
TkFrame.new($menubu_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -64,7 +66,7 @@ TkFrame.new($menubu_demo) {|frame|
else ; # Tk8.x else ; # Tk8.x
body = TkFrame.new($menubu_demo) body = TkFrame.new(base_frame)
body.pack('expand'=>'yes', 'fill'=>'both') body.pack('expand'=>'yes', 'fill'=>'both')
below = TkMenubutton.new(body) { below = TkMenubutton.new(body) {
@ -159,7 +161,7 @@ center = TkFrame.new(body) {
grid('row'=>1, 'column'=>1, 'sticky'=>'news') grid('row'=>1, 'column'=>1, 'sticky'=>'news')
} }
TkFrame.new($menubu_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc { command proc {

View file

@ -18,12 +18,14 @@ $msgbox_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($msgbox_demo).pack(:fill=>:both, :expand=>true)
# label # label
TkLabel.new($msgbox_demo, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left', TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left',
'text'=>"Choose the icon and type option of the message box. Then press the \"Message Box\" button to see the message box.").pack('side'=>'top') 'text'=>"Choose the icon and type option of the message box. Then press the \"Message Box\" button to see the message box.").pack('side'=>'top')
# frame # frame
TkFrame.new($msgbox_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -45,8 +47,8 @@ TkFrame.new($msgbox_demo) {|frame|
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame # frame
$msgbox_leftframe = TkFrame.new($msgbox_demo) $msgbox_leftframe = TkFrame.new(base_frame)
$msgbox_rightframe = TkFrame.new($msgbox_demo) $msgbox_rightframe = TkFrame.new(base_frame)
$msgbox_leftframe .pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y', $msgbox_leftframe .pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y',
'pady'=>'.5c', 'padx'=>'.5c') 'pady'=>'.5c', 'padx'=>'.5c')
$msgbox_rightframe.pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y', $msgbox_rightframe.pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y',

View file

@ -0,0 +1,91 @@
# msgbox2.rb
#
# This demonstration script creates message boxes of various type
#
# message boxes widget demo (called by 'widget')
#
# toplevel widget
if defined?($msgbox2_demo) && $msgbox2_demo
$msgbox2_demo.destroy
$msgbox2_demo = nil
end
# demo toplevel widget
$msgbox2_demo = TkToplevel.new {|w|
title("Message Box Demonstration")
iconname("messagebox")
positionWindow(w)
}
base_frame = TkFrame.new($msgbox2_demo).pack(:fill=>:both, :expand=>true)
# label
TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left',
'text'=>"Choose the icon and type option of the message box. Then press the \"Message Box\" button to see the message box with both of a message and a detail.").pack('side'=>'top')
# frame
TkFrame.new(base_frame) {|frame|
TkButton.new(frame) {
text 'Dismiss'
command proc{
tmppath = $msgbox2_demo
$msgbox2_demo = nil
tmppath.destroy
}
}.pack('side'=>'left', 'expand'=>'yes')
TkButton.new(frame) {
text 'Show Code'
command proc{showCode 'msgbox2'}
}.pack('side'=>'left', 'expand'=>'yes')
TkButton.new(frame) {
text 'Message Box'
command proc{showMessageBox $msgbox2_demo}
}.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame
$msgbox_leftframe = TkFrame.new(base_frame)
$msgbox_rightframe = TkFrame.new(base_frame)
$msgbox_leftframe .pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y',
'pady'=>'.5c', 'padx'=>'.5c')
$msgbox_rightframe.pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y',
'pady'=>'.5c', 'padx'=>'.5c')
TkLabel.new($msgbox_leftframe, 'text'=>'Icon').pack('side'=>'top')
TkFrame.new($msgbox_leftframe, 'relief'=>'ridge', 'bd'=>1, 'height'=>2)\
.pack('side'=>'top', 'fill'=>'x', 'expand'=>'no')
$msgboxIcon = TkVariable.new('info')
['error', 'info', 'question', 'warning'].each {|icon|
TkRadioButton.new($msgbox_leftframe, 'text'=>icon, 'variable'=>$msgboxIcon,
'relief'=>'flat', 'value'=>icon, 'width'=>16,
'anchor'=>'w').pack('side'=>'top', 'pady'=>2,
'anchor'=>'w', 'fill'=>'x')
}
TkLabel.new($msgbox_rightframe, 'text'=>'Type').pack('side'=>'top')
TkFrame.new($msgbox_rightframe, 'relief'=>'ridge', 'bd'=>1, 'height'=>2)\
.pack('side'=>'top', 'fill'=>'x', 'expand'=>'no')
$msgboxType = TkVariable.new('ok')
['abortretryignore', 'ok', 'okcancel',
'retrycancel', 'yesno', 'yesnocancel'].each {|type|
TkRadioButton.new($msgbox_rightframe, 'text'=>type, 'variable'=>$msgboxType,
'relief'=>'flat', 'value'=>type, 'width'=>16,
'anchor'=>'w').pack('side'=>'top', 'pady'=>2,
'anchor'=>'w', 'fill'=>'x')
}
def showMessageBox(w)
button = Tk.messageBox('icon'=>$msgboxIcon.value, 'type'=>$msgboxType.value,
'title'=>'Message', 'parent'=>w,
'message'=>"\"#{$msgboxType.value}\" Type MessageBox",
'detail'=>"This is a \"#{$msgboxType.value}\" type messagebox with the \"#{$msgboxIcon.value}\" icon. Please click one of the following button.")
Tk.messageBox('icon'=>'info', 'type'=>'ok', 'parent'=>w,
'message'=>"You have selected \"#{button}\"")
end

View file

@ -16,7 +16,9 @@ $paned1_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
TkLabel.new($paned1_demo, base_frame = TkFrame.new($paned1_demo).pack(:fill=>:both, :expand=>true)
TkLabel.new(base_frame,
:font=>$font, :wraplength=>'4i', :justify=>:left, :font=>$font, :wraplength=>'4i', :justify=>:left,
:text=><<EOL).pack(:side=>:top) :text=><<EOL).pack(:side=>:top)
The sash between the two coloured windows below can be used to divide the area between them. Use the left mouse button to resize without redrawing by just moving the sash, and use the middle mouse button to resize opaquely (always redrawing the windows in each position.) The sash between the two coloured windows below can be used to divide the area between them. Use the left mouse button to resize without redrawing by just moving the sash, and use the middle mouse button to resize opaquely (always redrawing the windows in each position.)
@ -24,7 +26,7 @@ If your Tk library linked to Ruby doesn't include a 'panedwindow', this demo doe
EOL EOL
# The bottom buttons # The bottom buttons
TkFrame.new($paned1_demo){|f| TkFrame.new(base_frame){|f|
pack(:side=>:bottom, :fill=>:x, :pady=>'2m') pack(:side=>:bottom, :fill=>:x, :pady=>'2m')
TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{ TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{
@ -37,9 +39,9 @@ TkFrame.new($paned1_demo){|f|
}).pack(:side=>:left, :expand=>true) }).pack(:side=>:left, :expand=>true)
} }
TkPanedwindow.new($paned1_demo){|f| TkPanedwindow.new(base_frame, :orient=>:horizontal){|f|
pack(:side=>:top, :expand=>true, :fill=>:both, :pady=>2, :padx=>'2m') add(Tk::Label.new(f, :text=>"This is the\nleft side", :bg=>'yellow'),
Tk::Label.new(f, :text=>"This is the\nright side", :bg=>'cyan'))
add(TkLabel.new(f, :text=>"This is the\nleft side", :bg=>'yellow'), pack(:side=>:top, :expand=>true, :fill=>:both, :pady=>2, :padx=>'2m')
TkLabel.new(f, :text=>"This is the\nright side", :bg=>'cyan'))
} }

View file

@ -16,7 +16,9 @@ $paned2_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
TkLabel.new($paned2_demo, base_frame = TkFrame.new($paned2_demo).pack(:fill=>:both, :expand=>true)
TkLabel.new(base_frame,
:font=>$font, :wraplength=>'4i', :justify=>:left, :font=>$font, :wraplength=>'4i', :justify=>:left,
:text=><<EOL).pack(:side=>:top) :text=><<EOL).pack(:side=>:top)
The sash between the two scrolled windows below can be used to divide the area between them. Use the left mouse button to resize without redrawing by just moving the sash, and use the middle mouse button to resize opaquely (always redrawing the windows in each position.) The sash between the two scrolled windows below can be used to divide the area between them. Use the left mouse button to resize without redrawing by just moving the sash, and use the middle mouse button to resize opaquely (always redrawing the windows in each position.)
@ -24,7 +26,7 @@ If your Tk library linked to Ruby doesn't include a 'panedwindow', this demo doe
EOL EOL
# The bottom buttons # The bottom buttons
TkFrame.new($paned2_demo){|f| TkFrame.new(base_frame){|f|
pack(:side=>:bottom, :fill=>:x, :pady=>'2m') pack(:side=>:bottom, :fill=>:x, :pady=>'2m')
TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{ TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{
@ -61,7 +63,7 @@ paneList.value = [ # ruby's array --> tcl's list
] ]
# Create the pane itself # Create the pane itself
TkPanedwindow.new($paned2_demo, :orient=>:vertical){|f| TkPanedwindow.new(base_frame, :orient=>:vertical){|f|
pack(:side=>:top, :expand=>true, :fill=>:both, :pady=>2, :padx=>'2m') pack(:side=>:top, :expand=>true, :fill=>:both, :pady=>2, :padx=>'2m')
add(TkFrame.new(f){|paned2_top| add(TkFrame.new(f){|paned2_top|

View file

@ -18,8 +18,10 @@ $pendulum_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($pendulum_demo).pack(:fill=>:both, :expand=>true)
# create label # create label
msg = TkLabel.new($pendulum_demo) { msg = TkLabel.new(base_frame) {
font $font font $font
wraplength '4i' wraplength '4i'
justify 'left' justify 'left'
@ -28,7 +30,7 @@ msg = TkLabel.new($pendulum_demo) {
msg.pack('side'=>'top') msg.pack('side'=>'top')
# create frame # create frame
TkFrame.new($pendulum_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -49,7 +51,7 @@ TkFrame.new($pendulum_demo) {|frame|
class PendulumAnimationDemo class PendulumAnimationDemo
def initialize(frame) def initialize(frame)
# Create some structural widgets # Create some structural widgets
@pane = TkPanedWindow.new(frame).pack(:fill=>:both, :expand=>true) @pane = TkPanedWindow.new(frame, :orient=>:horizontal).pack(:fill=>:both, :expand=>true)
# @pane.add(@lf1 = TkLabelFrame.new(@pane, :text=>'Pendulum Simulation')) # @pane.add(@lf1 = TkLabelFrame.new(@pane, :text=>'Pendulum Simulation'))
# @pane.add(@lf2 = TkLabelFrame.new(@pane, :text=>'Phase Space')) # @pane.add(@lf2 = TkLabelFrame.new(@pane, :text=>'Phase Space'))
@lf1 = TkLabelFrame.new(@pane, :text=>'Pendulum Simulation') @lf1 = TkLabelFrame.new(@pane, :text=>'Pendulum Simulation')
@ -235,4 +237,4 @@ class PendulumAnimationDemo
end end
# Start the animation processing # Start the animation processing
PendulumAnimationDemo.new($pendulum_demo) PendulumAnimationDemo.new(base_frame)

View file

@ -19,14 +19,16 @@ $plot_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($plot_demo).pack(:fill=>:both, :expand=>true)
# label # label
TkLabel.new($plot_demo, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left', TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left',
'text'=>"This window displays a canvas widget containing a simple 2-dimensional plot. You can doctor the data by dragging any of the points with mouse button 1."){ 'text'=>"This window displays a canvas widget containing a simple 2-dimensional plot. You can doctor the data by dragging any of the points with mouse button 1."){
pack('side'=>'top') pack('side'=>'top')
} }
# frame # frame
$plot_buttons = TkFrame.new($plot_demo) {|frame| $plot_buttons = TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -47,7 +49,7 @@ $plot_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
plotFont = '-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*' plotFont = '-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*'
# canvas # canvas
$plot_canvas = TkCanvas.new($plot_demo,'relief'=>'raised','width'=>450,'height'=>300) $plot_canvas = TkCanvas.new(base_frame,'relief'=>'raised','width'=>450,'height'=>300)
$plot_canvas.pack('side'=>'top', 'fill'=>'x') $plot_canvas.pack('side'=>'top', 'fill'=>'x')
# plot # plot

View file

@ -19,8 +19,10 @@ $puzzle_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($puzzle_demo).pack(:fill=>:both, :expand=>true)
# label # label
msg = TkLabel.new($puzzle_demo) { msg = TkLabel.new(base_frame) {
font $font font $font
wraplength '4i' wraplength '4i'
justify 'left' justify 'left'
@ -29,7 +31,7 @@ msg = TkLabel.new($puzzle_demo) {
msg.pack('side'=>'top') msg.pack('side'=>'top')
# frame # frame
TkFrame.new($puzzle_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -52,18 +54,27 @@ TkFrame.new($puzzle_demo) {|frame|
# scrollbar widget and using its trough color. # scrollbar widget and using its trough color.
begin begin
if Tk.windowingsystem() == 'aqua' if Tk.windowingsystem() == 'aqua'
frameSize = 160 frameWidth = 168
frameHeight = 168
elsif Tk.default_widget_set == :Ttk
frameWidth = 148
frameHeight = 124
else else
frameSize = 120 frameWidth = 120
frameHeight = 120
end end
rescue rescue
frameSize = 120 frameWidth = 120
frameHeight = 120
end end
s = TkScrollbar.new($puzzle_demo) # depend_on_button_width = true
base = TkFrame.new($puzzle_demo) { depend_on_button_width = false
width frameSize
height frameSize s = TkScrollbar.new(base_frame)
base = TkFrame.new(base_frame) {
width frameWidth
height frameHeight
borderwidth 2 borderwidth 2
relief 'sunken' relief 'sunken'
bg s['troughcolor'] bg s['troughcolor']
@ -87,6 +98,9 @@ order = [3,1,6,2,5,7,15,13,4,11,8,9,14,10,12]
text num text num
highlightthickness 0 highlightthickness 0
command def_puzzleswitch_proc(w, num) command def_puzzleswitch_proc(w, num)
if depend_on_button_width && (w.winfo_reqwidth * 4 > base.width)
base.width = w.winfo_reqwidth * 4
end
}.place('relx'=>$xpos[num], 'rely'=>$ypos[num], }.place('relx'=>$xpos[num], 'rely'=>$ypos[num],
'relwidth'=>0.25, 'relheight'=>0.25) 'relwidth'=>0.25, 'relheight'=>0.25)
} }

View file

@ -19,8 +19,10 @@ $radio_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($radio_demo).pack(:fill=>:both, :expand=>true)
# label # label
msg = TkLabel.new($radio_demo) { msg = TkLabel.new(base_frame) {
font $font font $font
wraplength '4i' wraplength '4i'
justify 'left' justify 'left'
@ -33,7 +35,7 @@ size = TkVariable.new
color = TkVariable.new color = TkVariable.new
# frame # frame
TkFrame.new($radio_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -52,14 +54,14 @@ TkFrame.new($radio_demo) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'See Variables' text 'See Variables'
command proc{ command proc{
showVars($radio_demo, ['size', size], ['color', color]) showVars(base_frame, ['size', size], ['color', color])
} }
}.pack('side'=>'left', 'expand'=>'yes') }.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame # frame
f_left = TkFrame.new($radio_demo) f_left = TkFrame.new(base_frame)
f_right = TkFrame.new($radio_demo) f_right = TkFrame.new(base_frame)
f_left.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c') f_left.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c')
f_right.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c') f_right.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c')

View file

@ -19,8 +19,10 @@ $radio2_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($radio2_demo).pack(:fill=>:both, :expand=>true)
# label # label
msg = TkLabel.new($radio2_demo) { msg = TkLabel.new(base_frame) {
font $font font $font
wraplength '5i' wraplength '5i'
justify 'left' justify 'left'
@ -34,7 +36,7 @@ color = TkVariable.new
align = TkVariable.new align = TkVariable.new
# frame # frame
TkFrame.new($radio2_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -53,18 +55,18 @@ TkFrame.new($radio2_demo) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'See Variables' text 'See Variables'
command proc{ command proc{
showVars($radio2_demo, showVars(base_frame,
['size', size], ['color', color], ['compound', align]) ['size', size], ['color', color], ['compound', align])
} }
}.pack('side'=>'left', 'expand'=>'yes') }.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame # frame
f_left = TkLabelFrame.new($radio2_demo, 'text'=>'Point Size', f_left = TkLabelFrame.new(base_frame, 'text'=>'Point Size',
'pady'=>2, 'padx'=>2) 'pady'=>2, 'padx'=>2)
f_mid = TkLabelFrame.new($radio2_demo, 'text'=>'Color', f_mid = TkLabelFrame.new(base_frame, 'text'=>'Color',
'pady'=>2, 'padx'=>2) 'pady'=>2, 'padx'=>2)
f_right = TkLabelFrame.new($radio2_demo, 'text'=>'Alignment', f_right = TkLabelFrame.new(base_frame, 'text'=>'Alignment',
'pady'=>2, 'padx'=>2) 'pady'=>2, 'padx'=>2)
f_left.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c') f_left.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c')
f_mid.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c') f_mid.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c')
@ -90,7 +92,8 @@ f_right.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c')
}.pack('side'=>'top', 'pady'=>2, 'fill'=>'x') }.pack('side'=>'top', 'pady'=>2, 'fill'=>'x')
} }
label = TkLabel.new(f_right, 'text'=>'Label', 'bitmap'=>'questhead', # label = TkLabel.new(f_right, 'text'=>'Label', 'bitmap'=>'questhead',
label = Tk::Label.new(f_right, 'text'=>'Label', 'bitmap'=>'questhead',
'compound'=>'left') 'compound'=>'left')
label.configure('width'=>TkWinfo.reqwidth(label), 'compound'=>'top') label.configure('width'=>TkWinfo.reqwidth(label), 'compound'=>'top')
label.height(TkWinfo.reqheight(label)) label.height(TkWinfo.reqheight(label))

View file

@ -19,8 +19,10 @@ $radio3_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($radio3_demo).pack(:fill=>:both, :expand=>true)
# label # label
msg = TkLabel.new($radio3_demo) { msg = TkLabel.new(base_frame) {
font $font font $font
wraplength '5i' wraplength '5i'
justify 'left' justify 'left'
@ -34,14 +36,14 @@ color = TkVariable.new
align = TkVariable.new align = TkVariable.new
# frame # frame
TkFrame.new($radio3_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkGrid(TkFrame.new(frame, :height=>2, :relief=>:sunken, :bd=>2), TkGrid(TkFrame.new(frame, :height=>2, :relief=>:sunken, :bd=>2),
:columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
TkGrid('x', TkGrid('x',
TkButton.new(frame, :text=>'See Variables', TkButton.new(frame, :text=>'See Variables',
:image=>$image['view'], :compound=>:left, :image=>$image['view'], :compound=>:left,
:command=>proc{ :command=>proc{
showVars($radio3_demo, ['size', size], showVars(base_frame, ['size', size],
['color', color], ['compound', align]) ['color', color], ['compound', align])
}), }),
TkButton.new(frame, :text=>'See Code', TkButton.new(frame, :text=>'See Code',
@ -61,17 +63,17 @@ TkFrame.new($radio3_demo) {|frame|
} }
# frame # frame
f_left = TkLabelFrame.new($radio3_demo, 'text'=>'Point Size', f_left = TkLabelFrame.new(base_frame, 'text'=>'Point Size',
'pady'=>2, 'padx'=>2) 'pady'=>2, 'padx'=>2)
f_mid = TkLabelFrame.new($radio3_demo, 'text'=>'Color', f_mid = TkLabelFrame.new(base_frame, 'text'=>'Color',
'pady'=>2, 'padx'=>2) 'pady'=>2, 'padx'=>2)
f_right = TkLabelFrame.new($radio3_demo, 'text'=>'Alignment', f_right = TkLabelFrame.new(base_frame, 'text'=>'Alignment',
'pady'=>2, 'padx'=>2) 'pady'=>2, 'padx'=>2)
f_left .grid('column'=>0, 'row'=>1, 'pady'=>'.5c', 'padx'=>'.5c', 'rowspan'=>2) f_left .grid('column'=>0, 'row'=>1, 'pady'=>'.5c', 'padx'=>'.5c', 'rowspan'=>2)
f_mid .grid('column'=>1, 'row'=>1, 'pady'=>'.5c', 'padx'=>'.5c', 'rowspan'=>2) f_mid .grid('column'=>1, 'row'=>1, 'pady'=>'.5c', 'padx'=>'.5c', 'rowspan'=>2)
f_right.grid('column'=>2, 'row'=>1, 'pady'=>'.5c', 'padx'=>'.5c') f_right.grid('column'=>2, 'row'=>1, 'pady'=>'.5c', 'padx'=>'.5c')
TkButton.new($radio3_demo, 'text'=>'Tristate', TkButton.new(base_frame, 'text'=>'Tristate',
'command'=>proc{size.value = 'multi'; color.value = 'multi'}){ 'command'=>proc{size.value = 'multi'; color.value = 'multi'}){
grid('column'=>2, 'row'=>2, 'pady'=>'.5c', 'padx'=>'.5c') grid('column'=>2, 'row'=>2, 'pady'=>'.5c', 'padx'=>'.5c')
} }
@ -99,7 +101,8 @@ TkButton.new($radio3_demo, 'text'=>'Tristate',
}.pack('side'=>'top', 'pady'=>2, 'fill'=>'x') }.pack('side'=>'top', 'pady'=>2, 'fill'=>'x')
} }
label = TkLabel.new(f_right, 'text'=>'Label', 'bitmap'=>'questhead', # label = TkLabel.new(f_right, 'text'=>'Label', 'bitmap'=>'questhead',
label = Tk::Label.new(f_right, 'text'=>'Label', 'bitmap'=>'questhead',
'compound'=>'left') 'compound'=>'left')
label.configure('width'=>TkWinfo.reqwidth(label), 'compound'=>'top') label.configure('width'=>TkWinfo.reqwidth(label), 'compound'=>'top')
label.height(TkWinfo.reqheight(label)) label.height(TkWinfo.reqheight(label))

View file

@ -32,14 +32,16 @@ $ruler_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($ruler_demo).pack(:fill=>:both, :expand=>true)
# label # label
TkLabel.new($ruler_demo, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left', TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left',
'text'=>"This canvas widget shows a mock-up of a ruler. You can create tab stops by dragging them out of the well to the right of the ruler. You can also drag existing tab stops. If you drag a tab stop far enough up or down so that it turns dim, it will be deleted when you release the mouse button."){ 'text'=>"This canvas widget shows a mock-up of a ruler. You can create tab stops by dragging them out of the well to the right of the ruler. You can also drag existing tab stops. If you drag a tab stop far enough up or down so that it turns dim, it will be deleted when you release the mouse button."){
pack('side'=>'top') pack('side'=>'top')
} }
# frame # frame
$ruler_buttons = TkFrame.new($ruler_demo) {|frame| $ruler_buttons = TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -57,7 +59,7 @@ $ruler_buttons = TkFrame.new($ruler_demo) {|frame|
$ruler_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') $ruler_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# canvas # canvas
$ruler_canvas = TkCanvas.new($ruler_demo, 'width'=>'14.8c', 'height'=>'2.5c') $ruler_canvas = TkCanvas.new(base_frame, 'width'=>'14.8c', 'height'=>'2.5c')
$ruler_canvas.pack('side'=>'top', 'fill'=>'x') $ruler_canvas.pack('side'=>'top', 'fill'=>'x')
# #

View file

@ -20,8 +20,10 @@ $sayings_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($sayings_demo).pack(:fill=>:both, :expand=>true)
# label # label
msg = TkLabel.new($sayings_demo) { msg = TkLabel.new(base_frame) {
font $font font $font
wraplength '4i' wraplength '4i'
justify 'left' justify 'left'
@ -30,7 +32,7 @@ msg = TkLabel.new($sayings_demo) {
msg.pack('side'=>'top') msg.pack('side'=>'top')
# frame # frame
TkFrame.new($sayings_demo) {|frame| TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -49,7 +51,7 @@ TkFrame.new($sayings_demo) {|frame|
# frame # frame
sayings_lbox = nil sayings_lbox = nil
TkFrame.new($sayings_demo, 'borderwidth'=>10) {|w| TkFrame.new(base_frame, 'borderwidth'=>10) {|w|
sv = TkScrollbar.new(w) sv = TkScrollbar.new(w)
sh = TkScrollbar.new(w, 'orient'=>'horizontal') sh = TkScrollbar.new(w, 'orient'=>'horizontal')
sayings_lbox = TkListbox.new(w) { sayings_lbox = TkListbox.new(w) {

View file

@ -79,8 +79,10 @@ $search_demo = TkToplevel.new {|w|
positionWindow(w) positionWindow(w)
} }
base_frame = TkFrame.new($search_demo).pack(:fill=>:both, :expand=>true)
# frame # frame
$search_buttons = TkFrame.new($search_demo) {|frame| $search_buttons = TkFrame.new(base_frame) {|frame|
TkButton.new(frame) { TkButton.new(frame) {
text 'Dismiss' text 'Dismiss'
command proc{ command proc{
@ -98,7 +100,7 @@ $search_buttons = TkFrame.new($search_demo) {|frame|
$search_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') $search_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame # frame
TkFrame.new($search_demo) {|f| TkFrame.new(base_frame) {|f|
TkLabel.new(f, 'text'=>'File name:', TkLabel.new(f, 'text'=>'File name:',
'width'=>13, 'anchor'=>'w').pack('side'=>'left') 'width'=>13, 'anchor'=>'w').pack('side'=>'left')
$search_fileName = TkVariable.new $search_fileName = TkVariable.new
@ -115,7 +117,7 @@ TkFrame.new($search_demo) {|f|
.pack('side'=>'left', 'pady'=>5, 'padx'=>10) .pack('side'=>'left', 'pady'=>5, 'padx'=>10)
}.pack('side'=>'top', 'fill'=>'x') }.pack('side'=>'top', 'fill'=>'x')
TkFrame.new($search_demo) {|f| TkFrame.new(base_frame) {|f|
TkLabel.new(f, 'text'=>'Search string:', TkLabel.new(f, 'text'=>'Search string:',
'width'=>13, 'anchor'=>'w').pack('side'=>'left') 'width'=>13, 'anchor'=>'w').pack('side'=>'left')
$search_searchString = TkVariable.new $search_searchString = TkVariable.new
@ -133,9 +135,9 @@ TkFrame.new($search_demo) {|f|
} }
}.pack('side'=>'top', 'fill'=>'x') }.pack('side'=>'top', 'fill'=>'x')
$search_text = TkText.new($search_demo, 'setgrid'=>true, 'wrap'=>'word') {|t| $search_text = TkText.new(base_frame, 'setgrid'=>true, 'wrap'=>'word') {|t|
$search_Tag = TkTextTag.new(t) $search_Tag = TkTextTag.new(t)
TkScrollbar.new($search_demo, 'command'=>proc{|*args| t.yview(*args)}) {|sc| TkScrollbar.new(base_frame, 'command'=>proc{|*args| t.yview(*args)}) {|sc|
t.yscrollcommand(proc{|first,last| sc.set first,last}) t.yscrollcommand(proc{|first,last| sc.set first,last})
pack('side'=>'right', 'fill'=>'y') pack('side'=>'right', 'fill'=>'y')
} }

Some files were not shown because too many files have changed in this diff Show more