From 9945dd1adf9eee1f19ea1f7a736e97f74596e9bc Mon Sep 17 00:00:00 2001 From: nagai Date: Thu, 8 Jul 2004 16:50:07 +0000 Subject: * 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/branches/ruby_1_8@6602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/lib/tk.rb | 4 +- ext/tk/lib/tk/autoload.rb | 2 + ext/tk/lib/tk/canvas.rb | 3 +- ext/tk/lib/tk/entry.rb | 5 +- ext/tk/lib/tk/text.rb | 3 +- ext/tk/lib/tk/timer.rb | 13 +- ext/tk/lib/tk/validation.rb | 229 +++++++------ ext/tk/lib/tkextlib/SUPPORT_STATUS | 6 +- ext/tk/lib/tkextlib/itcl.rb | 13 + ext/tk/lib/tkextlib/itcl/incr_tcl.rb | 167 +++++++++ ext/tk/lib/tkextlib/itcl/setup.rb | 13 + ext/tk/lib/tkextlib/itk.rb | 13 + ext/tk/lib/tkextlib/itk/incr_tk.rb | 376 +++++++++++++++++++++ ext/tk/lib/tkextlib/itk/setup.rb | 13 + ext/tk/lib/tkextlib/iwidgets.rb | 57 ++++ ext/tk/lib/tkextlib/iwidgets/buttonbox.rb | 109 ++++++ ext/tk/lib/tkextlib/iwidgets/calendar.rb | 85 +++++ ext/tk/lib/tkextlib/iwidgets/canvasprintbox.rb | 43 +++ ext/tk/lib/tkextlib/iwidgets/canvasprintdialog.rb | 38 +++ ext/tk/lib/tkextlib/iwidgets/checkbox.rb | 106 ++++++ ext/tk/lib/tkextlib/iwidgets/combobox.rb | 98 ++++++ ext/tk/lib/tkextlib/iwidgets/dateentry.rb | 20 ++ ext/tk/lib/tkextlib/iwidgets/datefield.rb | 42 +++ ext/tk/lib/tkextlib/iwidgets/dialog.rb | 20 ++ ext/tk/lib/tkextlib/iwidgets/dialogshell.rb | 109 ++++++ ext/tk/lib/tkextlib/iwidgets/disjointlistbox.rb | 45 +++ ext/tk/lib/tkextlib/iwidgets/entryfield.rb | 152 +++++++++ ext/tk/lib/tkextlib/iwidgets/extbutton.rb | 30 ++ .../lib/tkextlib/iwidgets/extfileselectionbox.rb | 33 ++ .../tkextlib/iwidgets/extfileselectiondialog.rb | 33 ++ ext/tk/lib/tkextlib/iwidgets/feedback.rb | 30 ++ ext/tk/lib/tkextlib/iwidgets/fileselectionbox.rb | 33 ++ .../lib/tkextlib/iwidgets/fileselectiondialog.rb | 33 ++ ext/tk/lib/tkextlib/iwidgets/finddialog.rb | 29 ++ ext/tk/lib/tkextlib/iwidgets/labeledframe.rb | 24 ++ ext/tk/lib/tkextlib/iwidgets/labeledwidget.rb | 30 ++ ext/tk/lib/tkextlib/iwidgets/setup.rb | 8 + ext/tk/lib/tkextlib/iwidgets/shell.rb | 38 +++ 38 files changed, 1995 insertions(+), 110 deletions(-) create mode 100644 ext/tk/lib/tkextlib/itcl.rb create mode 100644 ext/tk/lib/tkextlib/itcl/incr_tcl.rb create mode 100644 ext/tk/lib/tkextlib/itcl/setup.rb create mode 100644 ext/tk/lib/tkextlib/itk.rb create mode 100644 ext/tk/lib/tkextlib/itk/incr_tk.rb create mode 100644 ext/tk/lib/tkextlib/itk/setup.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/buttonbox.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/calendar.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/canvasprintbox.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/canvasprintdialog.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/checkbox.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/combobox.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/dateentry.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/datefield.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/dialog.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/dialogshell.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/disjointlistbox.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/entryfield.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/extbutton.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/extfileselectionbox.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/extfileselectiondialog.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/feedback.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/fileselectionbox.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/fileselectiondialog.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/finddialog.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/labeledframe.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/labeledwidget.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/setup.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/shell.rb (limited to 'ext/tk/lib') diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index 720f2060d2..cae832fc0c 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -3104,6 +3104,7 @@ class TkObject 0 && !@init_proc + self end @@ -306,6 +309,10 @@ class TkTimer @do_loop = @loop_exec @current_pos = 0 + @init_sleep = 0 + @init_proc = nil + @init_args = nil + argc = init_args.size if argc > 0 sleep = init_args.shift @@ -315,7 +322,9 @@ class TkTimer @init_sleep = sleep end @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 @running = true diff --git a/ext/tk/lib/tk/validation.rb b/ext/tk/lib/tk/validation.rb index 30111f20cc..cc205c5ef9 100644 --- a/ext/tk/lib/tk/validation.rb +++ b/ext/tk/lib/tk/validation.rb @@ -20,6 +20,26 @@ module Tk k2c 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) key2class = __get_validate_key2class @@ -67,6 +87,21 @@ module Tk } 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) key2class = __get_item_validate_key2class(tagid(tagOrId)) @@ -100,125 +135,127 @@ module Tk end end -module TkValidation - include Tk::ValidateConfigure +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 + } + ], - class ValidateCmd - include TkComm + nil + ] - module Action - Insert = 1 - Delete = 0 - Others = -1 - Focus = -1 - Forced = -1 - Textvariable = -1 - TextVariable = -1 + _setup_subst_table(KEY_TBL, PROC_TBL); + + def self.ret_val(val) + (val)? '1': '0' 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._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 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 - 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| + 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 + }) + ' ' + 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 - 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| + @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 + }) + ' ' + args end end + end - def initialize(cmd = Proc.new, *args) - _initialize_for_cb_class(ValidateArgs, cmd, *args) - end + def initialize(cmd = Proc.new, *args) + _initialize_for_cb_class(self.class::ValidateArgs, cmd, *args) + end - def to_eval - @id + def to_eval + @id + end +end + +module TkValidation + include Tk::ValidateConfigure + + class ValidateCmd < TkValidateCommand + module Action + Insert = 1 + Delete = 0 + Others = -1 + Focus = -1 + Forced = -1 + Textvariable = -1 + TextVariable = -1 end end diff --git a/ext/tk/lib/tkextlib/SUPPORT_STATUS b/ext/tk/lib/tkextlib/SUPPORT_STATUS index 58ac307857..4fd652a8a2 100644 --- a/ext/tk/lib/tkextlib/SUPPORT_STATUS +++ b/ext/tk/lib/tkextlib/SUPPORT_STATUS @@ -61,7 +61,9 @@ ICONS http://www.satisoft.com/tcltk/icons/ ==> ICONS ===< 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 @@ -82,8 +84,6 @@ TkDND http://sourceforge.net/projects/tkdnd ==> tkDND 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 TkTable http://sf.net/projects/tktable diff --git a/ext/tk/lib/tkextlib/itcl.rb b/ext/tk/lib/tkextlib/itcl.rb new file mode 100644 index 0000000000..1d6ecf04f2 --- /dev/null +++ b/ext/tk/lib/tkextlib/itcl.rb @@ -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' diff --git a/ext/tk/lib/tkextlib/itcl/incr_tcl.rb b/ext/tk/lib/tkextlib/itcl/incr_tcl.rb new file mode 100644 index 0000000000..9e53a9be8b --- /dev/null +++ b/ext/tk/lib/tkextlib/itcl/incr_tcl.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/itcl/setup.rb b/ext/tk/lib/tkextlib/itcl/setup.rb new file mode 100644 index 0000000000..5be0588703 --- /dev/null +++ b/ext/tk/lib/tkextlib/itcl/setup.rb @@ -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/' diff --git a/ext/tk/lib/tkextlib/itk.rb b/ext/tk/lib/tkextlib/itk.rb new file mode 100644 index 0000000000..7492bd3eb4 --- /dev/null +++ b/ext/tk/lib/tkextlib/itk.rb @@ -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' diff --git a/ext/tk/lib/tkextlib/itk/incr_tk.rb b/ext/tk/lib/tkextlib/itk/incr_tk.rb new file mode 100644 index 0000000000..1cc52c510b --- /dev/null +++ b/ext/tk/lib/tkextlib/itk/incr_tk.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/itk/setup.rb b/ext/tk/lib/tkextlib/itk/setup.rb new file mode 100644 index 0000000000..e47b64adae --- /dev/null +++ b/ext/tk/lib/tkextlib/itk/setup.rb @@ -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/' diff --git a/ext/tk/lib/tkextlib/iwidgets.rb b/ext/tk/lib/tkextlib/iwidgets.rb new file mode 100644 index 0000000000..7edd43346c --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/iwidgets/buttonbox.rb b/ext/tk/lib/tkextlib/iwidgets/buttonbox.rb new file mode 100644 index 0000000000..fef442a769 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/buttonbox.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/iwidgets/calendar.rb b/ext/tk/lib/tkextlib/iwidgets/calendar.rb new file mode 100644 index 0000000000..7a9763addc --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/calendar.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/iwidgets/canvasprintbox.rb b/ext/tk/lib/tkextlib/iwidgets/canvasprintbox.rb new file mode 100644 index 0000000000..1e2a476591 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/canvasprintbox.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/iwidgets/canvasprintdialog.rb b/ext/tk/lib/tkextlib/iwidgets/canvasprintdialog.rb new file mode 100644 index 0000000000..bbf507677c --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/canvasprintdialog.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/iwidgets/checkbox.rb b/ext/tk/lib/tkextlib/iwidgets/checkbox.rb new file mode 100644 index 0000000000..9845439ac4 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/checkbox.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/iwidgets/combobox.rb b/ext/tk/lib/tkextlib/iwidgets/combobox.rb new file mode 100644 index 0000000000..ca0e57c233 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/combobox.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/iwidgets/dateentry.rb b/ext/tk/lib/tkextlib/iwidgets/dateentry.rb new file mode 100644 index 0000000000..0a8897f50d --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/dateentry.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/iwidgets/datefield.rb b/ext/tk/lib/tkextlib/iwidgets/datefield.rb new file mode 100644 index 0000000000..a757403d6e --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/datefield.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/iwidgets/dialog.rb b/ext/tk/lib/tkextlib/iwidgets/dialog.rb new file mode 100644 index 0000000000..8540eae1b5 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/dialog.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/iwidgets/dialogshell.rb b/ext/tk/lib/tkextlib/iwidgets/dialogshell.rb new file mode 100644 index 0000000000..8359a3c551 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/dialogshell.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/iwidgets/disjointlistbox.rb b/ext/tk/lib/tkextlib/iwidgets/disjointlistbox.rb new file mode 100644 index 0000000000..8418467925 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/disjointlistbox.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/iwidgets/entryfield.rb b/ext/tk/lib/tkextlib/iwidgets/entryfield.rb new file mode 100644 index 0000000000..b38615a671 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/entryfield.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/iwidgets/extbutton.rb b/ext/tk/lib/tkextlib/iwidgets/extbutton.rb new file mode 100644 index 0000000000..7b1e35aa2d --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/extbutton.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/iwidgets/extfileselectionbox.rb b/ext/tk/lib/tkextlib/iwidgets/extfileselectionbox.rb new file mode 100644 index 0000000000..282647893c --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/extfileselectionbox.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/iwidgets/extfileselectiondialog.rb b/ext/tk/lib/tkextlib/iwidgets/extfileselectiondialog.rb new file mode 100644 index 0000000000..14388be7c4 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/extfileselectiondialog.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/iwidgets/feedback.rb b/ext/tk/lib/tkextlib/iwidgets/feedback.rb new file mode 100644 index 0000000000..d7439d818a --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/feedback.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/iwidgets/fileselectionbox.rb b/ext/tk/lib/tkextlib/iwidgets/fileselectionbox.rb new file mode 100644 index 0000000000..46de13d1b2 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/fileselectionbox.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/iwidgets/fileselectiondialog.rb b/ext/tk/lib/tkextlib/iwidgets/fileselectiondialog.rb new file mode 100644 index 0000000000..50f459e56d --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/fileselectiondialog.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/iwidgets/finddialog.rb b/ext/tk/lib/tkextlib/iwidgets/finddialog.rb new file mode 100644 index 0000000000..a161c3c2a4 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/finddialog.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/iwidgets/labeledframe.rb b/ext/tk/lib/tkextlib/iwidgets/labeledframe.rb new file mode 100644 index 0000000000..89669ea815 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/labeledframe.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/iwidgets/labeledwidget.rb b/ext/tk/lib/tkextlib/iwidgets/labeledwidget.rb new file mode 100644 index 0000000000..f847922386 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/labeledwidget.rb @@ -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 diff --git a/ext/tk/lib/tkextlib/iwidgets/setup.rb b/ext/tk/lib/tkextlib/iwidgets/setup.rb new file mode 100644 index 0000000000..ce0f0bd4d4 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/setup.rb @@ -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. +# diff --git a/ext/tk/lib/tkextlib/iwidgets/shell.rb b/ext/tk/lib/tkextlib/iwidgets/shell.rb new file mode 100644 index 0000000000..dabf2e6f25 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/shell.rb @@ -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 -- cgit v1.2.3