1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/tk/lib : bug fix

* ext/tk/lib/tkextlib/itcl : add [incr Tcl] support
* ext/tk/lib/tkextlib/itk  : add [incr Tk] support
* ext/tk/lib/tkextlib/iwidgets : midway point of [incr Widgets] support
* ext/tk/sample/tkextlib/iwidgets : very simple examples of [incr Widgets]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagai 2004-07-08 16:50:07 +00:00
parent aa4878589c
commit afcfca607e
64 changed files with 2441 additions and 122 deletions

View file

@ -1,3 +1,12 @@
Fri Jul 9 01:47:08 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib : bug fix
* ext/tk/lib/tkextlib/itcl : add [incr Tcl] support
* ext/tk/lib/tkextlib/itk : add [incr Tk] support
* ext/tk/lib/tkextlib/iwidgets : midway point of [incr Widgets] support
* ext/tk/sample/tkextlib/iwidgets : very simple examples of
[incr Widgets]
Thu Jul 8 19:27:16 2004 Nobuyoshi Nakada <nobu@ruby-lang.org> Thu Jul 8 19:27:16 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (rb_cv_stack_end_address): detect stack end address * configure.in (rb_cv_stack_end_address): detect stack end address

View file

@ -1,3 +1,7 @@
2004-07-07 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* add [incr Tck], [incr Tk] support
2004-07-06 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> 2004-07-06 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* support BWidget extension * support BWidget extension

View file

@ -130,6 +130,16 @@ lib/tkextlib/bwidget/spinbox.rb
lib/tkextlib/bwidget/titleframe.rb lib/tkextlib/bwidget/titleframe.rb
lib/tkextlib/bwidget/tree.rb lib/tkextlib/bwidget/tree.rb
lib/tkextlib/bwidget/widget.rb lib/tkextlib/bwidget/widget.rb
lib/tkextlib/itcl.rb
lib/tkextlib/itcl/incr_tcl.rb
lib/tkextlib/itcl/setup.rb
lib/tkextlib/itk.rb
lib/tkextlib/itk/incr_tk.rb
lib/tkextlib/itk/setup.rb
lib/tkextlib/iwidgets.rb
lib/tkextlib/iwidgets/buttonbox.rb
lib/tkextlib/iwidgets/calendar.rb
lib/tkextlib/iwidgets/setup.rb
lib/tkextlib/tcllib.rb lib/tkextlib/tcllib.rb
lib/tkextlib/tcllib/README lib/tkextlib/tcllib/README
lib/tkextlib/tcllib/autoscroll.rb lib/tkextlib/tcllib/autoscroll.rb
@ -431,6 +441,8 @@ sample/tkextlib/bwidget/select.rb
sample/tkextlib/bwidget/tmpldlg.rb sample/tkextlib/bwidget/tmpldlg.rb
sample/tkextlib/bwidget/tree.rb sample/tkextlib/bwidget/tree.rb
sample/tkextlib/bwidget/x1.xbm sample/tkextlib/bwidget/x1.xbm
sample/tkextlib/iwidgets/sample/buttonbox.rb
sample/tkextlib/iwidgets/sample/calendar.rb
sample/tkextlib/tcllib/LICENSE.orig sample/tkextlib/tcllib/LICENSE.orig
sample/tkextlib/tcllib/datefield.rb sample/tkextlib/tcllib/datefield.rb
sample/tkextlib/tcllib/plotdemos1.rb sample/tkextlib/tcllib/plotdemos1.rb

View file

@ -3104,6 +3104,7 @@ class TkObject<TkKernel
end end
end end
=begin
def tk_trace_variable(v) def tk_trace_variable(v)
unless v.kind_of?(TkVariable) unless v.kind_of?(TkVariable)
fail(ArgumentError, "type error (#{v.class}); must be TkVariable object") fail(ArgumentError, "type error (#{v.class}); must be TkVariable object")
@ -3111,9 +3112,10 @@ class TkObject<TkKernel
v v
end end
private :tk_trace_variable private :tk_trace_variable
=end
def destroy def destroy
tk_call 'trace', 'vdelete', @tk_vn, 'w', @var_id if @var_id #tk_call 'trace', 'vdelete', @tk_vn, 'w', @var_id if @var_id
end end
end end

View file

@ -89,6 +89,8 @@ autoload :TkOptionMenubutton, 'tk/menu'
autoload :TkMenubar, 'tk/menubar' autoload :TkMenubar, 'tk/menubar'
autoload :TkMenuSpec, 'tk/menuspec'
autoload :TkMessage, 'tk/message' autoload :TkMessage, 'tk/message'
autoload :TkManageFocus, 'tk/mngfocus' autoload :TkManageFocus, 'tk/mngfocus'

View file

@ -53,8 +53,7 @@ class TkCanvas<TkWindow
if tag.kind_of?(TkcItem) || tag.kind_of?(TkcTag) if tag.kind_of?(TkcItem) || tag.kind_of?(TkcTag)
tag.id tag.id
else else
# tag tag # maybe an Array of configure paramters
_get_eval_string(tag)
end end
end end
private :tagid private :tagid

View file

@ -17,10 +17,7 @@ class TkEntry<TkLabel
WidgetClassNames[WidgetClassName] = self WidgetClassNames[WidgetClassName] = self
#def create_self(keys) #def create_self(keys)
# tk_call_without_enc('entry', @path) # super(__conv_vcmd_on_hash_kv(keys))
# if keys and keys != None
# configure(keys)
# end
#end #end
#private :create_self #private :create_self

View file

@ -135,8 +135,7 @@ class TkText<TkTextWin
|| tag.kind_of?(TkTextWindow) || tag.kind_of?(TkTextWindow)
tag.id tag.id
else else
# tag tag # maybe an Array of configure paramters
_get_eval_string(tag)
end end
end end
private :tagid private :tagid

View file

@ -289,13 +289,16 @@ class TkTimer
self self
end end
def set_start_proc(sleep, init_proc, *init_args) def set_start_proc(sleep, init_proc=nil, *init_args)
if !sleep == 'idle' && !sleep.kind_of?(Integer) if !sleep == 'idle' && !sleep.kind_of?(Integer)
fail ArguemntError, "expect Integer or 'idle' for 1st argument" fail ArguemntError, "expect Integer or 'idle' for 1st argument"
end end
@init_sleep = sleep @init_sleep = sleep
@init_proc = init_proc @init_proc = init_proc
@init_args = init_args @init_args = init_args
@init_proc = proc{|*args| } if @init_sleep > 0 && !@init_proc
self self
end end
@ -306,6 +309,10 @@ class TkTimer
@do_loop = @loop_exec @do_loop = @loop_exec
@current_pos = 0 @current_pos = 0
@init_sleep = 0
@init_proc = nil
@init_args = nil
argc = init_args.size argc = init_args.size
if argc > 0 if argc > 0
sleep = init_args.shift sleep = init_args.shift
@ -315,7 +322,9 @@ class TkTimer
@init_sleep = sleep @init_sleep = sleep
end end
@init_proc = init_args.shift if argc > 1 @init_proc = init_args.shift if argc > 1
@init_args = init_args if argc > 0 @init_args = init_args if argc > 2
@init_proc = proc{|*args| } if @init_sleep > 0 && !@init_proc
@current_sleep = @init_sleep @current_sleep = @init_sleep
@running = true @running = true

View file

@ -20,6 +20,26 @@ module Tk
k2c k2c
end end
def __conv_vcmd_on_hash_kv(keys)
key2class = __get_validate_key2class
keys = _symbolkey2str(keys)
key2class.each{|key, klass|
if keys[key].kind_of?(Array)
cmd, *args = keys[key]
keys[key] = klass.new(cmd, args.join(' '))
elsif keys[key].kind_of? Proc
keys[key] = klass.new(keys[key])
end
}
keys
end
def create_self(keys)
super(__conv_vcmd_on_hash_kv(keys))
end
private :create_self
def configure(slot, value=TkComm::None) def configure(slot, value=TkComm::None)
key2class = __get_validate_key2class key2class = __get_validate_key2class
@ -67,6 +87,21 @@ module Tk
} }
end end
def __conv_item_vcmd_on_hash_kv(keys)
key2class = __get_item_validate_key2class(tagid(tagOrId))
keys = _symbolkey2str(keys)
key2class.each{|key, klass|
if keys[key].kind_of?(Array)
cmd, *args = keys[key]
keys[key] = klass.new(cmd, args.join(' '))
elsif keys[key].kind_of? Proc
keys[key] = klass.new(keys[key])
end
}
keys
end
def itemconfigure(tagOrId, slot, value=TkComm::None) def itemconfigure(tagOrId, slot, value=TkComm::None)
key2class = __get_item_validate_key2class(tagid(tagOrId)) key2class = __get_item_validate_key2class(tagid(tagOrId))
@ -100,12 +135,119 @@ module Tk
end end
end end
class TkValidateCommand
include TkComm
class ValidateArgs < TkUtil::CallbackSubst
KEY_TBL = [
[ ?d, ?n, :action ],
[ ?i, ?x, :index ],
[ ?s, ?e, :current ],
[ ?v, ?s, :type ],
[ ?P, ?e, :value ],
[ ?S, ?e, :string ],
[ ?V, ?s, :triggered ],
[ ?W, ?w, :widget ],
nil
]
PROC_TBL = [
[ ?n, TkComm.method(:number) ],
[ ?s, TkComm.method(:string) ],
[ ?w, TkComm.method(:window) ],
[ ?e, proc{|val|
enc = Tk.encoding
if enc
Tk.fromUTF8(TkComm::string(val), enc)
else
TkComm::string(val)
end
}
],
[ ?x, proc{|val|
idx = TkComm::number(val)
if idx < 0
nil
else
idx
end
}
],
nil
]
_setup_subst_table(KEY_TBL, PROC_TBL);
def self.ret_val(val)
(val)? '1': '0'
end
#def self._get_extra_args_tbl
# # return an array of convert procs
# []
#end
end
###############################################
def self._config_keys
# array of config-option key (string or symbol)
['vcmd', 'validatecommand', 'invcmd', 'invalidcommand']
end
def _initialize_for_cb_class(klass, cmd = Proc.new, *args)
extra_args_tbl = klass._get_extra_args_tbl
if args.compact.size > 0
args = args.join(' ')
keys = klass._get_subst_key(args)
if cmd.kind_of?(String)
id = cmd
elsif cmd.kind_of?(TkCallbackEntry)
@id = install_cmd(cmd)
else
@id = install_cmd(proc{|*arg|
ex_args = []
extra_args_tbl.reverse_each{|conv| ex_args << conv.call(args.pop)}
klass.ret_val(cmd.call(
*(ex_args.concat(klass.scan_args(keys, arg)))
))
}) + ' ' + args
end
else
keys, args = klass._get_all_subst_keys
if cmd.kind_of?(String)
id = cmd
elsif cmd.kind_of?(TkCallbackEntry)
@id = install_cmd(cmd)
else
@id = install_cmd(proc{|*arg|
ex_args = []
extra_args_tbl.reverse_each{|conv| ex_args << conv.call(args.pop)}
klass.ret_val(cmd.call(
*(ex_args << klass.new(*klass.scan_args(keys,arg)))
))
}) + ' ' + args
end
end
end
def initialize(cmd = Proc.new, *args)
_initialize_for_cb_class(self.class::ValidateArgs, cmd, *args)
end
def to_eval
@id
end
end
module TkValidation module TkValidation
include Tk::ValidateConfigure include Tk::ValidateConfigure
class ValidateCmd class ValidateCmd < TkValidateCommand
include TkComm
module Action module Action
Insert = 1 Insert = 1
Delete = 0 Delete = 0
@ -115,111 +257,6 @@ module TkValidation
Textvariable = -1 Textvariable = -1
TextVariable = -1 TextVariable = -1
end end
class ValidateArgs < TkUtil::CallbackSubst
KEY_TBL = [
[ ?d, ?n, :action ],
[ ?i, ?x, :index ],
[ ?s, ?e, :current ],
[ ?v, ?s, :type ],
[ ?P, ?e, :value ],
[ ?S, ?e, :string ],
[ ?V, ?s, :triggered ],
[ ?W, ?w, :widget ],
nil
]
PROC_TBL = [
[ ?n, TkComm.method(:number) ],
[ ?s, TkComm.method(:string) ],
[ ?w, TkComm.method(:window) ],
[ ?e, proc{|val|
enc = Tk.encoding
if enc
Tk.fromUTF8(TkComm::string(val), enc)
else
TkComm::string(val)
end
}
],
[ ?x, proc{|val|
idx = TkComm::number(val)
if idx < 0
nil
else
idx
end
}
],
nil
]
_setup_subst_table(KEY_TBL, PROC_TBL);
def self.ret_val(val)
(val)? '1': '0'
end
#def self._get_extra_args_tbl
# # return an array of convert procs
# []
#end
end
##############################
def self._config_keys
# array of config-option key (string or symbol)
['vcmd', 'validatecommand', 'invcmd', 'invalidcommand']
end
def _initialize_for_cb_class(klass, cmd = Proc.new, *args)
extra_args_tbl = klass._get_extra_args_tbl
if args.compact.size > 0
args = args.join(' ')
keys = klass._get_subst_key(args)
if cmd.kind_of?(String)
id = cmd
elsif cmd.kind_of?(TkCallbackEntry)
@id = install_cmd(cmd)
else
@id = install_cmd(proc{|*arg|
ex_args = []
extra_args_tbl.reverse_each{|conv| ex_args << conv.call(args.pop)}
klass.ret_val(cmd.call(
*(ex_args.concat(klass.scan_args(keys, arg)))
))
}) + ' ' + args
end
else
keys, args = klass._get_all_subst_keys
if cmd.kind_of?(String)
id = cmd
elsif cmd.kind_of?(TkCallbackEntry)
@id = install_cmd(cmd)
else
@id = install_cmd(proc{|*arg|
ex_args = []
extra_args_tbl.reverse_each{|conv| ex_args << conv.call(args.pop)}
klass.ret_val(cmd.call(
*(ex_args << klass.new(*klass.scan_args(keys,arg)))
))
}) + ' ' + args
end
end
end
def initialize(cmd = Proc.new, *args)
_initialize_for_cb_class(ValidateArgs, cmd, *args)
end
def to_eval
@id
end
end end
##################################### #####################################

View file

@ -61,7 +61,9 @@ ICONS http://www.satisoft.com/tcltk/icons/ ==> ICONS
===< support (may be alpha or beta quality) >================================= ===< support (may be alpha or beta quality) >=================================
TkImg http://sf.net/projects/tkimg ==> tkimg IncrTcl http://sf.net/projects/incrTcl ==> itcl, itk
TkImg http://sf.net/projects/tkimg ==> tkimg
TkTreeCtrl http://tktreectrl.sourceforge.net/ ==> treectrl TkTreeCtrl http://tktreectrl.sourceforge.net/ ==> treectrl
@ -82,8 +84,6 @@ TkDND http://sourceforge.net/projects/tkdnd ==> tkDND
TclX http://sf.net/projects/tclx * may support Tk part only TclX http://sf.net/projects/tclx * may support Tk part only
IncrTcl http://sf.net/projects/incrTcl * may support Tk part only
IWidgets http://sf.net/projects/incrTcl IWidgets http://sf.net/projects/incrTcl
TkTable http://sf.net/projects/tktable TkTable http://sf.net/projects/tktable

View file

@ -0,0 +1,13 @@
#
# [incr Tcl] support
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
# call setup script for general 'tkextlib' libraries
require 'tkextlib/setup.rb'
# call setup script
require 'tkextlib/itcl/setup.rb'
# load library
require 'tkextlib/itcl/incr_tcl.rb'

View file

@ -0,0 +1,167 @@
#
# tkextlib/itk/incr_tcl.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
# call setup script
require 'tkextlib/itcl.rb'
# TkPackage.require('Itcl', '3.2')
TkPackage.require('Itcl')
module Tk
module Itcl
include Tk
extend Tk
LIBRARY = TkVarAccess.new('::itcl::library')
PURIST = TkVarAccess.new('::itcl::purist')
VERSION = TkCore::INTERP._invoke("set", "::itcl::version").freeze
PATCHLEVEL = TkCore::INTERP._invoke("set", "::itcl::patchLevel").freeze
def self.package_version
begin
TkPackage.require('Itcl')
rescue
''
end
end
##############################################
class ItclObject < TkObject
ITCL_CLASSNAME = ''.freeze
ITCL_OBJ_ID = ['itclobj'.freeze, '00000'.taint].freeze
ITCL_OBJ_TBL = {}.taint
def initialize(*args)
if (@klass = self.class::ITCL_CLASSNAME).empty?
fail RuntimeError, 'unknown itcl class (abstract class?)'
end
@id = Tk::Itcl::ItclObject::TCL_OBJ_ID.join(TkCore::INTERP._ip_id_)
@path = @id
Tk::Itcl::ItclObject::ITCL_OBJ_ID[1].succ!
end
def self.call_proc(name, *args)
tk_call("#{ITCL_CLASSNAME}::#{cmd}", *args)
end
def call_method(name, *args)
tk_call(@path, name, *args)
end
def isa(klass)
bool(tk_call(@path, 'isa', klass))
end
alias itcl_kind_of? isa
def info_class
tk_call(@path, 'info', 'class')
end
def info_inherit
simplelist(tk_call(@path, 'info', 'inherit'))
end
def info_heritage
list(tk_call(@path, 'info', 'heritage'))
end
def info_function(*args)
if args[-1].kind_of?(Array)
params = args.pop
params.each{|param|
param = param.to_s
args << ( (param[0] == ?-)? param: "-#{param}" )
}
end
list(tk_call(@path, 'info', 'function', *args))
end
def info_variable(*args)
if args[-1].kind_of?(Array)
params = args.pop
params.each{|param|
param = param.to_s
args << ( (param[0] == ?-)? param: "-#{param}" )
}
end
list(tk_call(@path, 'info', 'variable', *args))
end
end
##############################################
def self.body(klass, func, args, body)
tk_call('::itcl::body', "#{klass}::#{func}", args, body)
end
def self.code(cmd, *args)
tk_call('::itcl::code', cmd, *args)
end
def self.code_in_namespace(namespace, cmd, *args)
tk_call('::itcl::code', '-namespace', namespace, cmd, *args)
end
def self.configbody(klass, var, body)
tk_call('::itcl::configbody', "#{klass}::#{var}", body)
end
def self.create_itcl_class(name, body)
TkCore::INTERP._invoke('::itcl::class', name, body)
klass = Class.new(Tk::Itcl::ItclObject)
klass.const_set('ITCL_CLASSNAME', name.dup.freeze)
klass
end
def self.delete_itcl_class(*names)
tk_call('::itcl::delete', 'class', *names)
end
def self.delete_itcl_object(*names)
tk_call('::itcl::delete', 'object', *names)
end
def self.delete_namespace(*names)
tk_call('::itcl::delete', 'namespace', *names)
end
def self.ensemble(name, *args)
tk_call('::itcl::ensemble', name, *args)
end
def self.find_classes(pat=None)
simplelist(tk_call('::itcl::find', 'classes', pat))
end
def self.find_objects(*args)
simplelist(tk_call('::itcl::find', 'objects', *args))
end
def self.is_itcl_class(target)
bool(tk_call('::itcl::is', 'class', target))
end
def self.is_itcl_object(target)
bool(tk_call('::itcl::is', 'object', target))
end
def self.create_local_obj(klass, name, *args)
tk_call('::itcl::local', klass, name, *args)
end
def self.is_itcl_instance(klass, target)
bool(tk_call('::itcl::is', 'object', '-class', klass, target))
end
def self.scope(var)
tk_call('::itcl::scope', var)
end
end
end

View file

@ -0,0 +1,13 @@
#
# setup.rb -- setup script before calling TkPackage.require()
#
# If you need some setup operations (for example, add a library path
# to the library search path) before using Tcl/Tk library packages
# wrapped by Ruby scripts in this directory, please write the setup
# operations in this file.
#
# set [incr Tcl] library directory
# ENV['ITCL_LIBRARY'] = '/usr/local/ActiveTcl/lib/itcl3.2/'

View file

@ -0,0 +1,13 @@
#
# [incr Tk] support
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
# call setup script for general 'tkextlib' libraries
require 'tkextlib/setup.rb'
# call setup script
require 'tkextlib/itk/setup.rb'
# load library
require 'tkextlib/itk/incr_tk.rb'

View file

@ -0,0 +1,376 @@
#
# tkextlib/itk/incr_tk.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tk/menuspec'
require 'tkextlib/itcl.rb'
# call setup script
require 'tkextlib/itk.rb'
#TkPackage.require('Itk', '3.2')
TkPackage.require('Itk')
module Tk
module Itk
include Tk
extend Tk
LIBRARY = TkVarAccess.new('::itk::library')
def self.package_version
begin
TkPackage.require('Itk')
rescue
''
end
end
def self.usual(arg, *args)
tk_call('::itk::usual', arg, *args)
end
def self.usual_names
list(tk_call('::itk::usual'))
end
############################
class Archetype < TkWindow
TkCommandNames = [].freeze
# WidgetClassName = 'Archetype'.freeze
# WidgetClassNames[WidgetClassName] = self
def self.to_eval
'::itk::' << self::WidgetClassName
end
#### [incr Tk] public methods
def component
simplelist(tk_send('component'))
end
def component_path(name)
window(tk_send('component', name))
end
def component_invoke(name, cmd, *args)
window(tk_send('component', name, cmd, *args))
end
def component_obj(*names)
names = component if names.empty?
names.collect{|name| Tk::Itk::Component.new(self.path, name) }
end
#### [incr Tk] protected methods
=begin
def itk_component_add(visibility, name, create_cmds, option_cmds=None)
args = []
visibility.each{|v| v = v.to_s; args << ( (v[0] == ?-)? v: "-#{v}" )}
args << '--' << name << create_cmd << option_cmds
tk_call('itk_component', 'add', *args)
end
def itk_component_delete(*names)
tk_call('itk_component', 'delete', *names)
end
def itk_initialize(keys={})
tk_call('itk_initialize', keys)
end
def itk_option_add(*args)
tk_call('itk_option', 'add', *args)
end
def itk_option_define(name, resource, klass, init, config=None)
tk_call('itk_option', 'define', name, resource, klass, init, config)
end
def itk_option_remove(*args)
tk_call('itk_option', 'remove', *args)
end
=end
end
############################
class Toplevel < Archetype
TkCommandNames = ['::itk::Toplevel'].freeze
WidgetClassName = 'Toplevel'.freeze
WidgetClassNames[WidgetClassName] = self
include Wm
include TkMenuSpec
end
############################
class Widget < Archetype
TkCommandNames = ['::itk::Widget'].freeze
WidgetClassName = 'Widget'.freeze
WidgetClassNames[WidgetClassName] = self
end
############################
class Component < TkObject
def __cget_cmd
[self.master, 'component', self.name, 'cget']
end
def __config_cmd
[self.master, 'component', self.name, 'configure']
end
ComponentID_TBL = TkCore::INTERP.create_table
Itk_Component_ID = ['itk_component'.freeze, '00000'.taint].freeze
TkCore::INTERP.init_ip_env{ ComponentID_TBL.clear }
def self.id2obj(master, id)
if master.kind_of?(TkObject)
master = master.path
else
master = master.to_s
end
return id unless ComponentID_TBL.key?(master)
(ComponentID_TBL.key?(id))? ComponentID_TBL[master][id]: id
end
def self.new(master, component=nil)
if master.kind_of?(TkObject)
master = master.path
else
master = master.to_s
end
if component.kind_of?(Tk::Itk::Component)
component = component.name
elsif component
component = component.to_s
else
component = Itk_Component_ID.join(TkCore::INTERP._ip_id_)
Itk_Component_ID[1].succ!
end
if ComponentID_TBL.key?(master)
if ComponentID_TBL[master].key?(component)
return ComponentID_TBL[master][component]
end
else
ComponentID_TBL[master] = {}
end
super(master, component)
end
def initialize(master, component)
@master = master
@component = component
ComponentID_TBL[@master][@component] = self
begin
@widget = window(tk_call(@master, 'component', @component))
@path = @widget.path
rescue
@widget = nil
@path = nil
end
end
def path
unless @path
begin
@widget = window(tk_call(@master, 'component', @component))
@path = @widget.path
rescue
fail RuntimeError, 'component is not assigned to a widget'
end
end
@path
end
def epath
path()
end
def to_eval
path()
end
def master
@master
end
def name
@component
end
def widget
unless @widget
begin
@widget = window(tk_call(@master, 'component', @component))
@path = @widget.path
rescue
fail RuntimeError, 'component is not assigned to a widget'
end
end
@widget
end
def widget_class
unless @widget
begin
@widget = window(tk_call(@master, 'component', @component))
@path = @widget.path
@widget.classname
rescue
nil
end
end
end
def method_missing(id, *args)
name = id.id2name
# try 1 : component command
begin
return tk_call(@master, 'component', @component, name, *args)
rescue
end
# try 2 : component configure
len = args.length
begin
case len
when 1
if name[-1] == ?=
return configure(name[0..-2], args[0])
else
return configure(name, args[0])
end
when 0
return cget(name)
end
rescue
end
# try 3 : widget method or widget configure
begin
unless @widget
@widget = window(tk_call(@master, 'component', @component))
@path = @widget.path
end
@widget.__send__(id, *args)
rescue
end
# unknown method
fail RuntimeError, "unknown method '#{name}' for #{self.inspect}"
end
def tk_send(cmd, *rest)
begin
tk_call(@master, 'component', @component, cmd, *rest)
rescue
unless @path
begin
@widget = window(tk_call(@master, 'component', @component))
@path = @widget.path
rescue
fail RuntimeError, 'component is not assigned to a widget'
end
end
tk_call(@path, cmd, *rest)
end
end
def tk_send_without_enc(cmd, *rest)
begin
tk_call_without_enc(@master, 'component', @component, cmd, *rest)
rescue
unless @path
begin
@widget = window(tk_call(@master, 'component', @component))
@path = @widget.path
rescue
fail RuntimeError, 'component is not assigned to a widget'
end
end
tk_call_without_enc(@path, cmd, *rest)
end
end
def tk_send_with_enc(cmd, *rest)
begin
tk_call_with_enc(@master, 'component', @component, cmd, *rest)
rescue
unless @path
begin
@widget = window(tk_call(@master, 'component', @component))
@path = @widget.path
rescue
fail RuntimeError, 'component is not assigned to a widget'
end
end
tk_call_with_enc(@path, cmd, *rest)
end
end
def bind(*args)
unless @widget
begin
@widget = window(tk_call(@master, 'component', @component))
@path = @widget.path
rescue
fail RuntimeError, 'component is not assigned to a widget'
end
end
@widget.bind(*args)
end
def bind_append(*args)
unless @widget
begin
@widget = window(tk_call(@master, 'component', @component))
@path = @widget.path
rescue
fail RuntimeError, 'component is not assigned to a widget'
end
end
@widget.bind_append(*args)
end
def bind_remove(*args)
unless @widget
begin
@widget = window(tk_call(@master, 'component', @component))
@path = @widget.path
rescue
fail RuntimeError, 'component is not assigned to a widget'
end
end
@widget.bind_remove(*args)
end
def bindinfo(*args)
unless @widget
begin
@widget = window(tk_call(@master, 'component', @component))
@path = @widget.path
rescue
fail RuntimeError, 'component is not assigned to a widget'
end
end
@widget.bindinfo(*args)
end
end
end
end

View file

@ -0,0 +1,13 @@
#
# setup.rb -- setup script before calling TkPackage.require()
#
# If you need some setup operations (for example, add a library path
# to the library search path) before using Tcl/Tk library packages
# wrapped by Ruby scripts in this directory, please write the setup
# operations in this file.
#
# set [incr Tk] library directory
# ENV['ITK_LIBRARY'] = '/usr/local/ActiveTcl/lib/itk3.2/'

View file

@ -0,0 +1,57 @@
#
# [incr Widgets] support
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/itcl'
require 'tkextlib/itk'
# call setup script for general 'tkextlib' libraries
#require 'tkextlib/setup.rb'
# call setup script
#require 'tkextlib/iwidgets/setup.rb'
# load all image format handlers
#TkPackage.require('Iwidgets', '4.0')
TkPackage.require('Iwidgets')
module Tk
module Iwidgets
extend TkCore
def self.package_version
begin
TkPackage.require('Iwidgets')
rescue
''
end
end
####################################################
autoload :Buttonbox, 'tkextlib/iwidgets/buttonbox'
autoload :Calendar, 'tkextlib/iwidgets/calendar'
autoload :Canvasprintbox, 'tkextlib/iwidgets/canvasprintbox'
autoload :Canvasprintdialog, 'tkextlib/iwidgets/canvasprintdialog'
autoload :Checkbox, 'tkextlib/iwidgets/checkbox'
autoload :Combobox, 'tkextlib/iwidgets/combobox'
autoload :Dateentry, 'tkextlib/iwidgets/dateentry'
autoload :Datefield, 'tkextlib/iwidgets/datefield'
autoload :Dialog, 'tkextlib/iwidgets/dialog'
autoload :Dialogshell, 'tkextlib/iwidgets/dialogshell'
autoload :Disjointlistbox, 'tkextlib/iwidgets/disjointlistbox'
autoload :Entryfield, 'tkextlib/iwidgets/entryfield'
autoload :Extbutton, 'tkextlib/iwidgets/extbutton'
autoload :Extfileselectionbox, 'tkextlib/iwidgets/extfileselectionbox'
autoload :Extfileselectiondialog,'tkextlib/iwidgets/extfileselectiondialog'
autoload :Feedback, 'tkextlib/iwidgets/feedback'
autoload :Fileselectionbox, 'tkextlib/iwidgets/fileselectionbox'
autoload :Fileselectiondialog, 'tkextlib/iwidgets/fileselectiondialog'
autoload :Finddialog, 'tkextlib/iwidgets/finddialog'
autoload :Labeledframe, 'tkextlib/iwidgets/labeledframe'
autoload :Labeledwidget, 'tkextlib/iwidgets/labeledwidget'
autoload :Shell, 'tkextlib/iwidgets/shell'
end
end

View file

@ -0,0 +1,109 @@
#
# tkextlib/iwidgets/buttonbox.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/iwidgets.rb'
module Tk
module Iwidgets
class Buttonbox < Tk::Itk::Widget
end
end
end
class Tk::Iwidgets::Buttonbox
TkCommandNames = ['::iwidgets::buttonbox'.freeze].freeze
WidgetClassName = 'Buttonbox'.freeze
WidgetClassNames[WidgetClassName] = self
####################################
include TkItemConfigMethod
def __item_cget_cmd(id)
[self.path, 'buttoncget', id]
end
private :__item_cget_cmd
def __item_config_cmd(id)
[self.path, 'buttonconfigure', id]
end
private :__item_config_cmd
def tagid(tagOrId)
if tagOrId.kind_of?(Tk::Itk::Component)
tagOrId.name
else
_get_eval_string(tagOrId)
end
end
alias buttoncget itemcget
alias buttonconfigure itemconfigure
alias buttonconfiginfo itemconfiginfo
alias current_buttonconfiginfo current_itemconfiginfo
private :itemcget, :itemconfigure
private :itemconfiginfo, :current_itemconfiginfo
####################################
def add(tag=nil, keys={})
if tag.kind_of?(Hash)
keys = tag
tag = nil
end
unless tag
tag = Tk::Itk::Component.new(self)
end
tk_call(@path, 'add', tagid(tag), *hash_kv(keys))
tag
end
def default(idx)
tk_call(@path, 'default', index(idx))
self
end
def delete(idx)
tk_call(@path, 'delete', index(idx))
self
end
def hide(idx)
tk_call(@path, 'hide', index(idx))
self
end
def index(idx)
number(tk_call(@path, 'index', tagid(idx)))
end
def insert(idx, tag=nil, keys={})
if tag.kind_of?(Hash)
keys = tag
tag = nil
end
unless tag
tag = Tk::Itk::Component.new(self)
end
tk_call(@path, 'insert', index(idx), tagid(tag), *hash_kv(keys))
tag
end
def invoke(idx=nil)
if idx
tk_call(@path, 'invoke', index(idx))
else
tk_call(@path, 'invoke')
end
self
end
def show(idx)
tk_call(@path, 'show', index(idx))
self
end
end

View file

@ -0,0 +1,85 @@
#
# tkextlib/iwidgets/calendar.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/iwidgets.rb'
module Tk
module Iwidgets
class Calendar < Tk::Itk::Widget
end
end
end
class Tk::Iwidgets::Calendar
TkCommandNames = ['::iwidgets::calendar'.freeze].freeze
WidgetClassName = 'Calendar'.freeze
WidgetClassNames[WidgetClassName] = self
####################################
include Tk::ValidateConfigure
class CalendarCommand < TkValidateCommand
#class CalCmdArgs < TkUtil::CallbackSubst
class ValidateArgs < TkUtil::CallbackSubst
KEY_TBL = [ [?d, ?s, :date], nil ]
PROC_TBL = [ [?s, TkComm.method(:string) ], nil ]
_setup_subst_table(KEY_TBL, PROC_TBL);
def self.ret_val(val)
val
end
end
def self._config_keys
# array of config-option key (string or symbol)
['command']
end
#def initialize(cmd = Proc.new, *args)
# _initialize_for_cb_class(CalCmdArgs, cmd, *args)
#end
end
def __validation_class_list
super << CalendarCommand
end
def command(cmd = Proc.new, args = nil)
if cmd.kind_of?(CalendarCommand)
configure('command', cmd)
elsif args
configure('command', [cmd, args])
else
configure('command', cmd)
end
end
####################################
def get_string
tk_call(@path, 'get', '-string')
end
alias get get_string
def get_clicks
number(tk_call(@path, 'get', '-clicks'))
end
def select(date)
tk_call(@path, 'select', date)
self
end
def show(date)
tk_call(@path, 'show', date)
self
end
def show_now
tk_call(@path, 'show', 'now')
self
end
end

View file

@ -0,0 +1,43 @@
#
# tkextlib/iwidgets/canvasprintbox.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/iwidgets.rb'
module Tk
module Iwidgets
class Canvasprintbox < Tk::Itk::Widget
end
end
end
class Tk::Iwidgets::Canvasprintbox
TkCommandNames = ['::iwidgets::canvasprintbox'.freeze].freeze
WidgetClassName = 'Canvasprintbox'.freeze
WidgetClassNames[WidgetClassName] = self
def get_output
tk_call(@path, 'getoutput')
end
def print
bool(tk_call(@path, 'print'))
end
def refresh
tk_call(@path, 'refresh')
self
end
def set_canvas(win)
tk_call(@path, 'setcanvas', win)
self
end
def stop
tk_call(@path, 'stop')
self
end
end

View file

@ -0,0 +1,38 @@
#
# tkextlib/iwidgets/canvasprintdialog.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/iwidgets.rb'
module Tk
module Iwidgets
class Canvasprintdialog < Tk::Iwidgets::Dialog
end
end
end
class Tk::Iwidgets::Canvasprintdialog
TkCommandNames = ['::iwidgets::canvasprintdialog'.freeze].freeze
WidgetClassName = 'Canvasprintdialog'.freeze
WidgetClassNames[WidgetClassName] = self
def get_output
tk_call(@path, 'getoutput')
end
def print
bool(tk_call(@path, 'print'))
end
def refresh
tk_call(@path, 'refresh')
self
end
def set_canvas(win)
tk_call(@path, 'setcanvas', win)
self
end
end

View file

@ -0,0 +1,106 @@
#
# tkextlib/iwidgets/checkbox.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/iwidgets.rb'
module Tk
module Iwidgets
class Checkbox < Tk::Iwidgets::Labeledframe
end
end
end
class Tk::Iwidgets::Checkbox
TkCommandNames = ['::iwidgets::checkbox'.freeze].freeze
WidgetClassName = 'Checkbox'.freeze
WidgetClassNames[WidgetClassName] = self
####################################
include TkItemConfigMethod
def __item_cget_cmd(id)
[self.path, 'buttoncget', id]
end
private :__item_cget_cmd
def __item_config_cmd(id)
[self.path, 'buttonconfigure', id]
end
private :__item_config_cmd
def tagid(tagOrId)
if tagOrId.kind_of?(Tk::Itk::Component)
tagOrId.name
else
_get_eval_string(tagOrId)
end
end
alias buttoncget itemcget
alias buttonconfigure itemconfigure
alias buttonconfiginfo itemconfiginfo
alias current_buttonconfiginfo current_itemconfiginfo
private :itemcget, :itemconfigure
private :itemconfiginfo, :current_itemconfiginfo
####################################
def add(tag=nil, keys={})
if tag.kind_of?(Hash)
keys = tag
tag = nil
end
unless tag
tag = Tk::Itk::Component.new(self)
end
tk_call(@path, 'add', tagid(tag), *hash_kv(keys))
tag
end
def delete(idx)
tk_call(@path, 'delete', index(idx))
self
end
def deselect(idx)
tk_call(@path, 'deselect', index(idx))
self
end
def flash(idx)
tk_call(@path, 'flash', index(idx))
self
end
def get(idx)
simplelist(tk_call(@path, 'get', index(idx))).collect{|id|
Tk::Itk::Component.id2obj(id)
}
end
def index(idx)
number(tk_call(@path, 'index', tagid(idx)))
end
def insert(idx, tag=nil, keys={})
if tag.kind_of?(Hash)
keys = tag
tag = nil
end
unless tag
tag = Tk::Itk::Component.new(self)
end
tk_call(@path, 'insert', index(idx), tagid(tag), *hash_kv(keys))
tag
end
def select(idx)
tk_call(@path, 'select', index(idx))
self
end
end

View file

@ -0,0 +1,98 @@
#
# tkextlib/iwidgets/combobox.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/iwidgets.rb'
module Tk
module Iwidgets
class Combobox < Tk::Iwidgets::Entryfield
end
end
end
class Tk::Iwidgets::Combobox
TkCommandNames = ['::iwidgets::combobox'.freeze].freeze
WidgetClassName = 'Combobox'.freeze
WidgetClassNames[WidgetClassName] = self
def clear(component=None)
tk_call(@path, 'clear', component)
self
end
def delete_list(first, last=None)
tk_call(@path, 'delete', 'list', first, last)
self
end
def delete_entry(first, last=None)
tk_call(@path, 'delete', 'entry', first, last)
self
end
def get_list_contents(index)
tk_call(@path, 'get', index)
end
def insert_list(idx, *elems)
tk_call(@path, 'insert', 'list', idx, *elems)
self
end
def insert_entry(idx, *elems)
tk_call(@path, 'insert', 'entry', idx, *elems)
self
end
# listbox methods
def size
tk_send_without_enc('size').to_i
end
def see(index)
tk_send_without_enc('see', index)
self
end
def selection_anchor(index)
tk_send_without_enc('selection', 'anchor', index)
self
end
def selection_clear(first, last=None)
tk_send_without_enc('selection', 'clear', first, last)
self
end
def selection_includes(index)
bool(tk_send_without_enc('selection', 'includes', index))
end
def selection_set(first, last=None)
tk_send_without_enc('selection', 'set', first, last)
self
end
# scrolledlistbox methods
def get_curselection
tk_call(@path, 'getcurselection')
end
def justify(dir)
tk_call(@path, 'justify', dir)
self
end
def sort(*params, &b)
# see 'lsort' man page about params
if b
tk_call(@path, 'sort', *params, -'command', proc(&b))
else
tk_call(@path, 'sort', *params)
end
self
end
def sort_ascending
tk_call(@path, 'sort', 'ascending')
self
def sort_descending
tk_call(@path, 'sort', 'descending')
self
end
end

View file

@ -0,0 +1,20 @@
#
# tkextlib/iwidgets/dateentry.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/iwidgets.rb'
module Tk
module Iwidgets
class Dateentry < Tk::Iwidgets::Datefield
end
end
end
class Tk::Iwidgets::Dateentry
TkCommandNames = ['::iwidgets::dateentry'.freeze].freeze
WidgetClassName = 'Dateentry'.freeze
WidgetClassNames[WidgetClassName] = self
end

View file

@ -0,0 +1,42 @@
#
# tkextlib/iwidgets/datefield.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/iwidgets.rb'
module Tk
module Iwidgets
class Datefield < Tk::Iwidgets::Labeledwidget
end
end
end
class Tk::Iwidgets::Datefield
TkCommandNames = ['::iwidgets::datefield'.freeze].freeze
WidgetClassName = 'Datefield'.freeze
WidgetClassNames[WidgetClassName] = self
def get_string
tk_call(@path, 'get', '-string')
end
alias get get_string
def get_clicks
number(tk_call(@path, 'get', '-clicks'))
end
def valid?
bool(tk_call(@path, 'isvalid'))
end
def show(date)
tk_call(@path, 'show', date)
self
end
def show_now
tk_call(@path, 'show', 'now')
self
end
end

View file

@ -0,0 +1,20 @@
#
# tkextlib/iwidgets/dialog.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/iwidgets.rb'
module Tk
module Iwidgets
class Dialog < Tk::Iwidgets::Dialogshell
end
end
end
class Tk::Iwidgets::Dialog
TkCommandNames = ['::iwidgets::dialog'.freeze].freeze
WidgetClassName = 'Dialog'.freeze
WidgetClassNames[WidgetClassName] = self
end

View file

@ -0,0 +1,109 @@
#
# tkextlib/iwidgets/dialogshell.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/iwidgets.rb'
module Tk
module Iwidgets
class Dialogshell < Tk::Iwidgets::Shell
end
end
end
class Tk::Iwidgets::Dialogshell
TkCommandNames = ['::iwidgets::dialogshell'.freeze].freeze
WidgetClassName = 'Dialogshell'.freeze
WidgetClassNames[WidgetClassName] = self
####################################
include TkItemConfigMethod
def __item_cget_cmd(id)
[self.path, 'buttoncget', id]
end
private :__item_cget_cmd
def __item_config_cmd(id)
[self.path, 'buttonconfigure', id]
end
private :__item_config_cmd
def tagid(tagOrId)
if tagOrId.kind_of?(Tk::Itk::Component)
tagOrId.name
else
_get_eval_string(tagOrId)
end
end
alias buttoncget itemcget
alias buttonconfigure itemconfigure
alias buttonconfiginfo itemconfiginfo
alias current_buttonconfiginfo current_itemconfiginfo
private :itemcget, :itemconfigure
private :itemconfiginfo, :current_itemconfiginfo
####################################
def add(tag=nil, keys={})
if tag.kind_of?(Hash)
keys = tag
tag = nil
end
unless tag
tag = Tk::Itk::Component.new(self)
end
tk_call(@path, 'add', tagid(tag), *hash_kv(keys))
tag
end
def default(idx)
tk_call(@path, 'default', index(idx))
self
end
def delete(idx)
tk_call(@path, 'delete', index(idx))
self
end
def hide(idx)
tk_call(@path, 'hide', index(idx))
self
end
def index(idx)
number(tk_call(@path, 'index', tagid(idx)))
end
def insert(idx, tag=nil, keys={})
if tag.kind_of?(Hash)
keys = tag
tag = nil
end
unless tag
tag = Tk::Itk::Component.new(self)
end
tk_call(@path, 'insert', index(idx), tagid(tag), *hash_kv(keys))
tag
end
def invoke(idx=nil)
if idx
tk_call(@path, 'invoke', index(idx))
else
tk_call(@path, 'invoke')
end
self
end
def show(idx)
tk_call(@path, 'show', index(idx))
self
end
end

View file

@ -0,0 +1,45 @@
#
# tkextlib/iwidgets/disjointlistbox.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/iwidgets.rb'
module Tk
module Iwidgets
class Disjointlistbox < Tk::Itk::Widget
end
end
end
class Tk::Iwidgets::Disjointlistbox
TkCommandNames = ['::iwidgets::disjointlistbox'.freeze].freeze
WidgetClassName = 'Disjointlistbox'.freeze
WidgetClassNames[WidgetClassName] = self
def set_lhs(*items)
tk_call(@path, 'setlhs', items)
self
end
def set_rhs(*items)
tk_call(@path, 'setrhs', items)
self
end
def get_lhs
simplelist(tk_call(@path, 'getlhs'))
end
def get_rhs
simplelist(tk_call(@path, 'getrhs'))
end
def insert_lhs(*items)
tk_call(@path, 'insertlhs', items)
self
end
def insert_rhs(*items)
tk_call(@path, 'insertrhs', items)
self
end
end

View file

@ -0,0 +1,152 @@
#
# tkextlib/iwidgets/entryfield.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/iwidgets.rb'
module Tk
module Iwidgets
class Entryfield < Tk::Iwidgets::Labeledwidget
end
end
end
class Tk::Iwidgets::Entryfield
TkCommandNames = ['::iwidgets::entryfield'.freeze].freeze
WidgetClassName = 'Entryfield'.freeze
WidgetClassNames[WidgetClassName] = self
####################################
include Tk::ValidateConfigure
class EntryfieldValidate < TkValidateCommand
#class CalCmdArgs < TkUtil::CallbackSubst
class ValidateArgs < TkUtil::CallbackSubst
KEY_TBL = [
[ ?c, ?s, :char ],
[ ?P, ?s, :post ],
[ ?S, ?s, :current ],
[ ?W, ?w, :widget ],
nil
]
PROC_TBL = [
[ ?s, TkComm.method(:string) ],
[ ?w, TkComm.method(:window) ],
nil
]
_setup_subst_table(KEY_TBL, PROC_TBL);
end
def self._config_keys
['validate', 'invalid']
end
end
def __validation_class_list
super << EntryfieldValidate
end
def validate(cmd = Proc.new, args = nil)
if cmd.kind_of?(ValidateCmd)
configure('validate', cmd)
elsif args
configure('validate', [cmd, args])
else
configure('validate', cmd)
end
end
def invalid(cmd = Proc.new, args = nil)
if cmd.kind_of?(ValidateCmd)
configure('invalid', cmd)
elsif args
configure('invalid', [cmd, args])
else
configure('invalid', cmd)
end
end
####################################
def clear
tk_call(@path, 'clear')
self
end
def delete(first, last=None)
tk_send_without_enc('delete', first, last)
self
end
def value
_fromUTF8(tk_send_without_enc('get'))
end
alias get value
def cursor=(index)
tk_send_without_enc('icursor', index)
#self
index
end
alias icursor cursor=
def index(index)
number(tk_send_without_enc('index', index))
end
def insert(pos,text)
tk_send_without_enc('insert', pos, _get_eval_enc_str(text))
self
end
def mark(pos)
tk_send_without_enc('scan', 'mark', pos)
self
end
def dragto(pos)
tk_send_without_enc('scan', 'dragto', pos)
self
end
def selection_adjust(index)
tk_send_without_enc('selection', 'adjust', index)
self
end
def selection_clear
tk_send_without_enc('selection', 'clear')
self
end
def selection_from(index)
tk_send_without_enc('selection', 'from', index)
self
end
def selection_present()
bool(tk_send_without_enc('selection', 'present'))
end
def selection_range(s, e)
tk_send_without_enc('selection', 'range', s, e)
self
end
def selection_to(index)
tk_send_without_enc('selection', 'to', index)
self
end
# based on tk/scrollable.rb
def xview(*index)
if index.size == 0
list(tk_send_without_enc('xview'))
else
tk_send_without_enc('xview', *index)
self
end
end
def xview_moveto(*index)
xview('moveto', *index)
end
def xview_scroll(*index)
xview('scroll', *index)
end
end

View file

@ -0,0 +1,30 @@
#
# tkextlib/iwidgets/extbutton.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/iwidgets.rb'
module Tk
module Iwidgets
class Extbutton < Tk::Itk::Widget
end
end
end
class Tk::Iwidgets::Extbutton
TkCommandNames = ['::iwidgets::extbutton'.freeze].freeze
WidgetClassName = 'Extbutton'.freeze
WidgetClassNames[WidgetClassName] = self
def invoke
tk_call(@path, 'invoke')
self
end
def flash
tk_call(@path, 'flash')
self
end
end

View file

@ -0,0 +1,33 @@
#
# tkextlib/iwidgets/extfileselectionbox.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/iwidgets.rb'
module Tk
module Iwidgets
class Extfileselectionbox < Tk::Itk::Widget
end
end
end
class Tk::Iwidgets::Extfileselectionbox
TkCommandNames = ['::iwidgets::extfileselectionbox'.freeze].freeze
WidgetClassName = 'Extfileselectionbox'.freeze
WidgetClassNames[WidgetClassName] = self
def child_site
window(tk_call(@path, 'childsite'))
end
def filter
tk_call(@path, 'filter')
self
end
def get
tk_call(@path, 'get')
end
end

View file

@ -0,0 +1,33 @@
#
# tkextlib/iwidgets/extfileselectiondialog.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/iwidgets.rb'
module Tk
module Iwidgets
class Extfileselectiondialog < Tk::Iwidgets::Dialog
end
end
end
class Tk::Iwidgets::Extfileselectiondialog
TkCommandNames = ['::iwidgets::extfileselectiondialog'.freeze].freeze
WidgetClassName = 'Extfileselectiondialog'.freeze
WidgetClassNames[WidgetClassName] = self
def child_site
window(tk_call(@path, 'childsite'))
end
def filter
tk_call(@path, 'filter')
self
end
def get
tk_call(@path, 'get')
end
end

View file

@ -0,0 +1,30 @@
#
# tkextlib/iwidgets/feedback.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/iwidgets.rb'
module Tk
module Iwidgets
class Feedback < Tk::Iwidgets::Labeledwidget
end
end
end
class Tk::Iwidgets::Feedback
TkCommandNames = ['::iwidgets::feedback'.freeze].freeze
WidgetClassName = 'Feedback'.freeze
WidgetClassNames[WidgetClassName] = self
def reset
tk_call(@path, 'reset')
self
end
def step(inc=1)
tk_call(@path, 'step', inc)
self
end
end

View file

@ -0,0 +1,33 @@
#
# tkextlib/iwidgets/fileselectionbox.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/iwidgets.rb'
module Tk
module Iwidgets
class Fileselectionbox < Tk::Itk::Widget
end
end
end
class Tk::Iwidgets::Fileselectionbox
TkCommandNames = ['::iwidgets::fileselectionbox'.freeze].freeze
WidgetClassName = 'Fileselectionbox'.freeze
WidgetClassNames[WidgetClassName] = self
def child_site
window(tk_call(@path, 'childsite'))
end
def filter
tk_call(@path, 'filter')
self
end
def get
tk_call(@path, 'get')
end
end

View file

@ -0,0 +1,33 @@
#
# tkextlib/iwidgets/fileselectiondialog.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/iwidgets.rb'
module Tk
module Iwidgets
class Fileselectiondialog < Tk::Iwidgets::Dialog
end
end
end
class Tk::Iwidgets::Fileselectiondialog
TkCommandNames = ['::iwidgets::fileselectiondialog'.freeze].freeze
WidgetClassName = 'Fileselectiondialog'.freeze
WidgetClassNames[WidgetClassName] = self
def child_site
window(tk_call(@path, 'childsite'))
end
def filter
tk_call(@path, 'filter')
self
end
def get
tk_call(@path, 'get')
end
end

View file

@ -0,0 +1,29 @@
#
# tkextlib/iwidgets/finddialog.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/iwidgets.rb'
module Tk
module Iwidgets
class Finddialog < Tk::Iwidgets::Dialogshell
end
end
end
class Tk::Iwidgets::Finddialog
TkCommandNames = ['::iwidgets::finddialog'.freeze].freeze
WidgetClassName = 'Finddialog'.freeze
WidgetClassNames[WidgetClassName] = self
def clear
tk_call(@path, 'clear')
self
end
def find
tk_call(@path, 'find')
end
end

View file

@ -0,0 +1,24 @@
#
# tkextlib/iwidgets/labeledframe.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/iwidgets.rb'
module Tk
module Iwidgets
class Labeledframe < Tk::Itk::Archetype
end
end
end
class Tk::Iwidgets::Labeledframe
TkCommandNames = ['::iwidgets::labeledframe'.freeze].freeze
WidgetClassName = 'Labeledframe'.freeze
WidgetClassNames[WidgetClassName] = self
def child_site
window(tk_call(@path, 'childsite'))
end
end

View file

@ -0,0 +1,30 @@
#
# tkextlib/iwidgets/labeledwidget.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/iwidgets.rb'
module Tk
module Iwidgets
class Labeledwidget < Tk::Itk::Widget
end
end
end
class Tk::Iwidgets::Labeledwidget
extend TkCore
TkCommandNames = ['::iwidgets::labeledwidget'.freeze].freeze
WidgetClassName = 'Labeledwidget'.freeze
WidgetClassNames[WidgetClassName] = self
def self.alignlabels(*wins)
tk_call('::iwidgets::Labeledwidget::alignlabels', *wins)
end
def child_site
window(tk_call(@path, 'childsite'))
end
end

View file

@ -0,0 +1,8 @@
#
# setup.rb -- setup script before calling TkPackage.require()
#
# If you need some setup operations (for example, add a library path
# to the library search path) before using Tcl/Tk library packages
# wrapped by Ruby scripts in this directory, please write the setup
# operations in this file.
#

View file

@ -0,0 +1,38 @@
#
# tkextlib/iwidgets/shell.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/iwidgets.rb'
module Tk
module Iwidgets
class Shell < Tk::Itk::Toplevel
end
end
end
class Tk::Iwidgets::Shell
TkCommandNames = ['::iwidgets::shell'.freeze].freeze
WidgetClassName = 'Shell'.freeze
WidgetClassNames[WidgetClassName] = self
def activate
tk_call(@path, 'activate') # may return val of deactibate method
end
def center(win=None)
tk_call(@path, 'center', win)
self
end
def child_site
window(tk_call(@path, 'childsite'))
end
def deactivate(val=None)
tk_call(@path, 'deactivate', val)
self
end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 B

View file

@ -0,0 +1,22 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
# sample 1
p bb1 = Tk::Iwidgets::Buttonbox.new
p bb1.add('Yes', :text=>'Yes', :command=>proc{puts 'Yes'})
p bb1.add('No', :text=>'No', :command=>proc{puts 'No'})
p bb1.add('Maybe', :text=>'Maybe', :command=>proc{puts 'Maybe'})
bb1.default('Yes')
bb1.pack(:expand=>true, :fill=>:both, :pady=>5)
print "\n"
# sample 2
p bb2 = Tk::Iwidgets::Buttonbox.new
p btn1 = bb2.add(:text=>'Yes', :command=>proc{puts 'Yes'})
p btn2 = bb2.add(:text=>'No', :command=>proc{puts 'No'})
p btn3 = bb2.add(:text=>'Maybe', :command=>proc{puts 'Maybe'})
bb2.default(btn1)
bb2.pack(:expand=>true, :fill=>:both, :pady=>5)
Tk.mainloop

View file

@ -0,0 +1,10 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
Tk::Iwidgets::Calendar.new(:command=>proc{|arg| puts(arg.date)},
:weekendbackground=>'mistyrose',
:weekdaybackground=>'ghostwhite',
:outline=>'black', :startday=>'wednesday',
:days=>%w(We Th Fr Sa Su Mo Tu)).pack
Tk.mainloop

View file

@ -0,0 +1,8 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
Tk::Iwidgets::Canvasprintbox.new(:orient=>:landscape, :stretch=>1) \
.pack(:padx=>10, :pady=>10, :fill=>:both, :expand=>true)
Tk.mainloop

View file

@ -0,0 +1,8 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
Tk::Iwidgets::Canvasprintdialog.new.activate
Tk.mainloop

View file

@ -0,0 +1,12 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
cb = Tk::Iwidgets::Checkbox.new
cb.add('bold', :text=>'Bold')
cb.add('italic', :text=>'Italic')
cb.add('underline', :text=>'Underline')
cb.select('underline')
cb.pack(:expand=>true, :fill=>:both, :padx=>10, :pady=>10)
Tk.mainloop

View file

@ -0,0 +1,32 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
#
# Non-editable Dropdown Combobox
#
cb1 = Tk::Iwidgets::Combobox.new(:labeltext=>'Month:',
:selectioncommand=>proc{
puts(cb1.get_curselection)
},
:editable=>false, :listheight=>185,
:popupcursor=>'hand1')
cb1.insert_list('end', *%w(Jan Feb Mar Apr May June Jul Aug Sept Oct Nov Dec))
#
# Editable Dropdown Combobox
#
cb2 = Tk::Iwidgets::Combobox.new(:labeltext=>'Operating System:',
:selectioncommand=>proc{
puts(cb2.get_curselection)
})
cb2.insert_list('end', *%w(Linux HP-UX SunOS Solaris Irix))
cb2.insert_entry('end', 'L')
cb1.pack(:padx=>10, :pady=>10, :fill=>:x)
cb2.pack(:padx=>10, :pady=>10, :fill=>:x)
Tk.mainloop

View file

@ -0,0 +1,7 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
Tk::Iwidgets::Dateentry.new.pack
Tk.mainloop

View file

@ -0,0 +1,8 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
df = Tk::Iwidgets::Datefield.new(:command=>proc{puts(df.get)})
df.pack(:fill=>:x, :expand=>true, :padx=>10, :pady=>10)
Tk.mainloop

View file

@ -0,0 +1,20 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
Thread.new{Tk.mainloop}
d = Tk::Iwidgets::Dialog.new(:modality=>:application)
d.buttonconfigure('OK', :command=>proc{puts 'OK'; d.deactivate true})
d.buttonconfigure('Apply', :command=>proc{puts 'Apply'})
d.buttonconfigure('Cancel', :command=>proc{puts 'Cancel'; d.deactivate false})
d.buttonconfigure('Help', :command=>proc{puts 'Help'})
TkListbox.new(d.child_site, :relief=>:sunken).pack(:expand=>true, :fill=>:both)
if TkComm.bool(d.activate)
puts "Exit via OK button"
else
puts "Exit via Cancel button"
end

View file

@ -0,0 +1,14 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
ds = Tk::Iwidgets::Dialogshell.new(:modality=>:none)
ds.add('OK', :text=>'OK', :command=>proc{puts 'OK'; ds.deactivate})
ds.add('Cancel', :text=>'Cancel', :command=>proc{puts 'Cancel'; ds.deactivate})
ds.default('OK')
TkButton.new(:text=>'ACTIVATE', :padx=>7, :pady=>7,
:command=>proc{puts ds.activate}).pack(:padx=>10, :pady=>10)
Tk.mainloop

View file

@ -0,0 +1,16 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
djl = Tk::Iwidgets::Disjointlistbox.new.pack(:fill=>:both, :expand=>true,
:padx=>10, :pady=>10)
djl.set_lhs(*[0,2,4,5])
djl.set_rhs(3,6)
djl.insert_lhs(1,7,8)
djl.insert_rhs(9)
p djl.get_lhs
p djl.get_rhs
Tk.mainloop

View file

@ -0,0 +1,39 @@
#!/usr/bin/env ruby
#########################################################
#
# use Tk::UTF8_String() for a utf8 charecter
#
#########################################################
require 'tk'
require 'tkextlib/iwidgets'
TkOption.add('*textBackground', 'white')
ef = Tk::Iwidgets::Entryfield.new(:command=>proc{puts "Return Pressed"})
fef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Fixed:',
:fixed=>10, :width=>12)
nef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Numeric:',
:validate=>:numeric, :width=>12)
aef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Alphabetic:',
:validate=>:alphabetic, :width=>12,
:invalid=>proc{
puts "Alphabetic contents invalid"
})
pef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Password:', :width=>12,
:show=>Tk::UTF8_String("\267"),
## <=== utf8 character
:command=>proc{puts "Return Pressed"})
Tk::Iwidgets::Labeledwidget.alignlabels(ef, fef, nef, aef, pef)
ef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
fef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
nef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
aef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
pef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
Tk.mainloop

View file

@ -0,0 +1,40 @@
#!/usr/bin/env ruby
#########################################################
#
# set $KCODE to 'utf' for a utf8 charecter
#
#########################################################
$KCODE='utf'
require 'tk'
require 'tkextlib/iwidgets'
TkOption.add('*textBackground', 'white')
ef = Tk::Iwidgets::Entryfield.new(:command=>proc{puts "Return Pressed"})
fef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Fixed:',
:fixed=>10, :width=>12)
nef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Numeric:',
:validate=>:numeric, :width=>12)
aef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Alphabetic:',
:validate=>:alphabetic, :width=>12,
:invalid=>proc{
puts "Alphabetic contents invalid"
})
pef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Password:', :width=>12,
:show=>"\267", ## <=== utf8 character
:command=>proc{puts "Return Pressed"})
Tk::Iwidgets::Labeledwidget.alignlabels(ef, fef, nef, aef, pef)
ef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
fef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
nef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
aef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
pef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
Tk.mainloop

View file

@ -0,0 +1,40 @@
#!/usr/bin/env ruby
#########################################################
#
# set Tk.encoding = 'utf-8' for a utf8 charecter
#
#########################################################
require 'tk'
require 'tkextlib/iwidgets'
Tk.encoding = 'utf-8'
TkOption.add('*textBackground', 'white')
ef = Tk::Iwidgets::Entryfield.new(:command=>proc{puts "Return Pressed"})
fef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Fixed:',
:fixed=>10, :width=>12)
nef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Numeric:',
:validate=>:numeric, :width=>12)
aef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Alphabetic:',
:validate=>:alphabetic, :width=>12,
:invalid=>proc{
puts "Alphabetic contents invalid"
})
pef = Tk::Iwidgets::Entryfield.new(:labeltext=>'Password:', :width=>12,
:show=>"\267", ## <=== utf8 character
:command=>proc{puts "Return Pressed"})
Tk::Iwidgets::Labeledwidget.alignlabels(ef, fef, nef, aef, pef)
ef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
fef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
nef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
aef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
pef.pack(:fil=>:x, :expand=>true, :padx=>10, :pady=>5)
Tk.mainloop

View file

@ -0,0 +1,20 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
Tk::Iwidgets::Extbutton.new(:text=>'Bitmap example', :bitmap=>'info',
:background=>'bisque', :activeforeground=>'red',
:bitmapforeground=>'blue', :defaultring=>true,
:command=>proc{
puts "Bisque is beautiful"
}).pack(:expand=>true)
#img = TkPhotoImage.new(:file=>File.join(File.dirname(File.expand_path(__FILE__)), '../../../images/earthris.gif'))
img = TkPhotoImage.new(:file=>File.join(File.dirname(File.expand_path(__FILE__)), '../catalog_demo/images/clear.gif'))
Tk::Iwidgets::Extbutton.new(:text=>'Image example', :relief=>:ridge,
:image=>img, :imagepos=>:e, :font=>'9x15bold',
:activebackground=>'lightyellow',
:background=>'lightgreen').pack(:expand=>true)
Tk.mainloop

View file

@ -0,0 +1,8 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
Tk::Iwidgets::Extfileselectionbox.new.pack(:padx=>10, :pady=>10,
:fill=>:both, :expand=>true)
Tk.mainloop

View file

@ -0,0 +1,29 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
mainloop = Thread.new{Tk.mainloop}
#
# Non-modal example
#
nmfsd = Tk::Iwidgets::Extfileselectiondialog.new(:title=>'Non-Modal')
nmfsd.buttonconfigure('OK', :command=>proc{
puts "You selected #{nmfsd.get}"
nmfsd.deactivate
})
nmfsd.activate
#
# Modal example
#
mfsd = Tk::Iwidgets::Extfileselectiondialog.new(:modality=>:application)
mfsd.center
if TkComm.bool(mfsd.activate)
puts "You selected #{mfsd.get}"
else
puts "You cancelled the dialog"
end
mainloop.join

View file

@ -0,0 +1,10 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
Tk::Iwidgets::Feedback.new(:labeltext=>'Status', :steps=>20){|fb|
pack(:padx=>10, :pady=>10, :fill=>:both, :expand=>true)
TkTimer.new(500, 20, proc{fb.step}).start(5000)
}
Tk.mainloop

View file

@ -0,0 +1,8 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
Tk::Iwidgets::Fileselectionbox.new.pack(:padx=>10, :pady=>10,
:fill=>:both, :expand=>true)
Tk.mainloop

View file

@ -0,0 +1,28 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
mainloop = Thread.new{Tk.mainloop}
#
# Non-modal example
#
nmfsd = Tk::Iwidgets::Fileselectiondialog.new(:title=>'Non-Modal')
nmfsd.buttonconfigure('OK', :command=>proc{
puts "You selected #{nmfsd.get}"
nmfsd.deactivate
})
nmfsd.activate
#
# Modal example
#
mfsd = Tk::Iwidgets::Fileselectiondialog.new(:modality=>:application)
mfsd.center
if TkComm.bool(mfsd.activate)
puts "You selected #{mfsd.get}"
else
puts "You cancelled the dialog"
end
mainloop.join

View file

@ -0,0 +1,13 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
lw = Tk::Iwidgets::Labeledwidget.new(:labeltext=>'Canvas Widget',
:labelpos=>:s)
lw.pack(:fill=>:both, :expand=>true, :padx=>10, :pady=>10)
cw = TkCanvas.new(lw.child_site, :relief=>:raised, :width=>200, :height=>200,
:borderwidth=>3, :background=>:white)
cw.pack(:padx=>10, :pady=>10)
Tk.mainloop

View file

@ -0,0 +1,17 @@
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
sh = Tk::Iwidgets::Shell.new(:modality=>:application,
:padx=>20, :pady=>20, :title=>'Shell')
TkButton.new(:text=>'ACTIVATE', :padx=>7, :pady=>7,
:command=>proc{puts sh.activate}).pack(:padx=>10, :pady=>10)
TkLabel.new(sh.child_site, :text=>'SHELL').pack
TkButton.new(sh.child_site, :text=>'YES',
:command=>proc{sh.deactivate 'press YES'}).pack(:fill=>:x)
TkButton.new(sh.child_site, :text=>'NO',
:command=>proc{sh.deactivate 'press NO'}).pack(:fill=>:x)
Tk.mainloop