From 24d2225afde5beb0771c8987c2e1c80ce900b52a Mon Sep 17 00:00:00 2001 From: nagai Date: Fri, 9 Jul 2004 19:29:29 +0000 Subject: * ext/tk/lib/tk.rb: better operation for SIGINT when processing callbacks. * ext/tk/lib/tk/msgcat.rb: ditto. * ext/tk/lib/tk/variable.rb: ditto. * ext/tk/lib/tk/timer.rb: ditto. * ext/tk/lib/tk/validation.rb: add Tk::ValidateConfigure.__def_validcmd() to define validatecommand methods easier git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/ChangeLog.tkextlib | 16 ++ ext/tk/MANIFEST | 22 +- ext/tk/lib/tk.rb | 4 + ext/tk/lib/tk/canvastag.rb | 5 +- ext/tk/lib/tk/msgcat.rb | 4 + ext/tk/lib/tk/timer.rb | 5 + ext/tk/lib/tk/validation.rb | 62 ++++- ext/tk/lib/tk/variable.rb | 4 + ext/tk/lib/tk/winfo.rb | 3 + ext/tk/lib/tkextlib/itk/incr_tk.rb | 1 + ext/tk/lib/tkextlib/iwidgets.rb | 11 + ext/tk/lib/tkextlib/iwidgets/buttonbox.rb | 3 +- ext/tk/lib/tkextlib/iwidgets/calendar.rb | 3 + ext/tk/lib/tkextlib/iwidgets/checkbox.rb | 3 +- ext/tk/lib/tkextlib/iwidgets/combobox.rb | 3 +- ext/tk/lib/tkextlib/iwidgets/datefield.rb | 3 +- ext/tk/lib/tkextlib/iwidgets/dialogshell.rb | 3 +- ext/tk/lib/tkextlib/iwidgets/entryfield.rb | 3 + ext/tk/lib/tkextlib/iwidgets/hierarchy.rb | 294 +++++++++++++++++++++ ext/tk/lib/tkextlib/iwidgets/hyperhelp.rb | 40 +++ ext/tk/lib/tkextlib/iwidgets/mainwindow.rb | 52 ++++ ext/tk/lib/tkextlib/iwidgets/messagebox.rb | 81 ++++++ ext/tk/lib/tkextlib/iwidgets/messagedialog.rb | 20 ++ ext/tk/lib/tkextlib/iwidgets/radiobox.rb | 107 ++++++++ ext/tk/lib/tkextlib/iwidgets/scrolledwidget.rb | 20 ++ ext/tk/lib/tkextlib/iwidgets/timeentry.rb | 20 ++ ext/tk/lib/tkextlib/iwidgets/timefield.rb | 43 +++ ext/tk/lib/tkextlib/iwidgets/toolbar.rb | 86 ++++++ ext/tk/lib/tkextlib/iwidgets/watch.rb | 45 ++++ ext/tk/lib/tkextlib/tcllib.rb | 29 +- ext/tk/lib/tkextlib/tcllib/autoscroll.rb | 8 +- ext/tk/lib/tkextlib/tcllib/ctext.rb | 2 +- ext/tk/lib/tkextlib/treectrl/tktreectrl.rb | 8 +- ext/tk/lib/tkextlib/vu/pie.rb | 1 + ext/tk/lib/tkextlib/vu/spinbox.rb | 7 +- .../sample/tkextlib/iwidgets/sample/hierarchy.rb | 25 ++ .../sample/tkextlib/iwidgets/sample/hyperhelp.rb | 14 + .../sample/tkextlib/iwidgets/sample/messagebox1.rb | 19 ++ .../sample/tkextlib/iwidgets/sample/messagebox2.rb | 19 ++ .../tkextlib/iwidgets/sample/messagedialog.rb | 44 +++ ext/tk/sample/tkextlib/iwidgets/sample/radiobox.rb | 13 + .../sample/tkextlib/iwidgets/sample/timeentry.rb | 7 + .../sample/tkextlib/iwidgets/sample/timefield.rb | 8 + ext/tk/sample/tkextlib/iwidgets/sample/watch.rb | 18 ++ ext/tk/tkutil.c | 4 + 45 files changed, 1171 insertions(+), 21 deletions(-) create mode 100644 ext/tk/lib/tkextlib/iwidgets/hierarchy.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/hyperhelp.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/mainwindow.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/messagebox.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/messagedialog.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/radiobox.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/scrolledwidget.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/timeentry.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/timefield.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/toolbar.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/watch.rb create mode 100644 ext/tk/sample/tkextlib/iwidgets/sample/hierarchy.rb create mode 100644 ext/tk/sample/tkextlib/iwidgets/sample/hyperhelp.rb create mode 100644 ext/tk/sample/tkextlib/iwidgets/sample/messagebox1.rb create mode 100644 ext/tk/sample/tkextlib/iwidgets/sample/messagebox2.rb create mode 100644 ext/tk/sample/tkextlib/iwidgets/sample/messagedialog.rb create mode 100644 ext/tk/sample/tkextlib/iwidgets/sample/radiobox.rb create mode 100644 ext/tk/sample/tkextlib/iwidgets/sample/timeentry.rb create mode 100644 ext/tk/sample/tkextlib/iwidgets/sample/timefield.rb create mode 100644 ext/tk/sample/tkextlib/iwidgets/sample/watch.rb (limited to 'ext') diff --git a/ext/tk/ChangeLog.tkextlib b/ext/tk/ChangeLog.tkextlib index 5045ae36a4..484624b179 100644 --- a/ext/tk/ChangeLog.tkextlib +++ b/ext/tk/ChangeLog.tkextlib @@ -1,3 +1,19 @@ +2004-07-10 Hidetoshi NAGAI + + * bug fix + + * add more part of [incr Widget] support (about 65%? are complete) + + * use Tk::ValidateConfigure.__def_validcmd() method + (new function to define validatecommand methods easier) + + * tcllib.rb : avoid the loading trouble that almost all part of + the extension is not available when some libraries are invalid. + +2004-07-09 Hidetoshi NAGAI + + * add some part of [incr Widget] support (about 50%? are complete) + 2004-07-07 Hidetoshi NAGAI * add [incr Tck], [incr Tk] support diff --git a/ext/tk/MANIFEST b/ext/tk/MANIFEST index 2a912a013c..e80b654306 100644 --- a/ext/tk/MANIFEST +++ b/ext/tk/MANIFEST @@ -139,7 +139,6 @@ 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/iwidgets/canvasprintbox.rb lib/tkextlib/iwidgets/canvasprintdialog.rb lib/tkextlib/iwidgets/checkbox.rb @@ -157,9 +156,21 @@ lib/tkextlib/iwidgets/feedback.rb lib/tkextlib/iwidgets/fileselectionbox.rb lib/tkextlib/iwidgets/fileselectiondialog.rb lib/tkextlib/iwidgets/finddialog.rb +lib/tkextlib/iwidgets/hierarchy.rb +lib/tkextlib/iwidgets/hyperhelp.rb lib/tkextlib/iwidgets/labeledframe.rb lib/tkextlib/iwidgets/labeledwidget.rb +lib/tkextlib/iwidgets/mainwindow.rb +lib/tkextlib/iwidgets/messagebox.rb +lib/tkextlib/iwidgets/messagedialog.rb +lib/tkextlib/iwidgets/radiobox.rb +lib/tkextlib/iwidgets/scrolledwidget.rb +lib/tkextlib/iwidgets/setup.rb lib/tkextlib/iwidgets/shell.rb +lib/tkextlib/iwidgets/timeentry.rb +lib/tkextlib/iwidgets/timefield.rb +lib/tkextlib/iwidgets/toolbar.rb +lib/tkextlib/iwidgets/watch.rb lib/tkextlib/tcllib.rb lib/tkextlib/tcllib/README lib/tkextlib/tcllib/autoscroll.rb @@ -482,8 +493,17 @@ sample/tkextlib/iwidgets/sample/extfileselectiondialog.rb sample/tkextlib/iwidgets/sample/feedback.rb sample/tkextlib/iwidgets/sample/fileselectionbox.rb sample/tkextlib/iwidgets/sample/fileselectiondialog.rb +sample/tkextlib/iwidgets/sample/hierarchy.rb +sample/tkextlib/iwidgets/sample/hyperhelp.rb sample/tkextlib/iwidgets/sample/labeledwidget.rb +sample/tkextlib/iwidgets/sample/messagebox1.rb +sample/tkextlib/iwidgets/sample/messagebox2.rb +sample/tkextlib/iwidgets/sample/messagedialog.rb +sample/tkextlib/iwidgets/sample/radiobox.rb sample/tkextlib/iwidgets/sample/shell.rb +sample/tkextlib/iwidgets/sample/timeentry.rb +sample/tkextlib/iwidgets/sample/timefield.rb +sample/tkextlib/iwidgets/sample/watch.rb sample/tkextlib/tcllib/LICENSE.orig sample/tkextlib/tcllib/datefield.rb sample/tkextlib/tcllib/plotdemos1.rb diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index cae832fc0c..bb2335f107 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -1070,6 +1070,10 @@ module TkCore def TkCore.callback(*arg) begin TkCore::INTERP.tk_cmd_tbl[arg.shift].call(*arg) + rescue SystemExit + exit(0) + rescue Interrupt + exit!(1) rescue Exception => e begin msg = _toUTF8(e.class.inspect) + ': ' + diff --git a/ext/tk/lib/tk/canvastag.rb b/ext/tk/lib/tk/canvastag.rb index 1db7b7b768..bcd7a96430 100644 --- a/ext/tk/lib/tk/canvastag.rb +++ b/ext/tk/lib/tk/canvastag.rb @@ -2,13 +2,16 @@ # tk/canvastag.rb - methods for treating canvas tags # require 'tk' -require 'tk/canvas' require 'tk/tagfont' module TkcTagAccess include TkComm include TkTreatTagFont +end +require 'tk/canvas' + +module TkcTagAccess def addtag(tag) @c.addtag(tag, 'with', @id) self diff --git a/ext/tk/lib/tk/msgcat.rb b/ext/tk/lib/tk/msgcat.rb index 6c46542faf..361b9a5de3 100644 --- a/ext/tk/lib/tk/msgcat.rb +++ b/ext/tk/lib/tk/msgcat.rb @@ -57,6 +57,10 @@ class TkMsgCatalog < TkObject return src_str unless cmd # no cmd -> return src-str (default action) begin cmd.call(locale, src_str) + rescue SystemExit + exit(0) + rescue Interrupt + exit!(1) rescue Exception => e begin msg = _toUTF8(e.class.inspect) + ': ' + diff --git a/ext/tk/lib/tk/timer.rb b/ext/tk/lib/tk/timer.rb index 3696de168b..fa0a582205 100644 --- a/ext/tk/lib/tk/timer.rb +++ b/ext/tk/lib/tk/timer.rb @@ -61,11 +61,16 @@ class TkTimer @in_callback = true begin @return_value = @current_proc.call(self) + rescue SystemExit + exit(0) + rescue Interrupt + exit!(1) rescue Exception => e if @cancel_on_exception && @cancel_on_exception.find{|exc| e.kind_of?(exc)} cancel @return_value = e + @in_callback = false return e else fail e diff --git a/ext/tk/lib/tk/validation.rb b/ext/tk/lib/tk/validation.rb index cc205c5ef9..a0bb5feb8b 100644 --- a/ext/tk/lib/tk/validation.rb +++ b/ext/tk/lib/tk/validation.rb @@ -5,6 +5,29 @@ require 'tk' module Tk module ValidateConfigure + def self.__def_validcmd(scope, klass, keys=nil) + keys = klass._config_keys unless keys + keys.each{|key| + eval("def #{key}(*args, &b) + __validcmd_call(#{klass.name}, '#{key}', *args, &b) + end", scope) + } + end + + def __validcmd_call(klass, key, *args, &b) + return cget(key) if args.empty? && !b + + cmd = (b)? proc(&b) : args.shift + + if cmd.kind_of?(klass) + configure(key, cmd) + elsif !args.empty? + configure(key, [cmd, args]) + else + configure(key, cmd) + end + end + def __validation_class_list # maybe need to override [] @@ -73,6 +96,29 @@ module Tk end module ItemValidateConfigure + def self.__def_validcmd(scope, klass, keys=nil) + keys = klass._config_keys unless keys + keys.each{|key| + eval("def item_#{key}(id, *args, &b) + __item_validcmd_call(#{klass.name}, '#{key}', id, *args, &b) + end", scope) + } + end + + def __item_validcmd_call(tagOrId, klass, key, *args, &b) + return itemcget(tagid(tagOrId), key) if args.empty? && !b + + cmd = (b)? proc(&b) : args.shift + + if cmd.kind_of?(klass) + itemconfigure(tagid(tagOrId), key, cmd) + elsif !args.empty? + itemconfigure(tagid(tagOrId), key, [cmd, args]) + else + itemconfigure(tagid(tagOrId), key, cmd) + end + end + def __item_validation_class_list(id) # maybe need to override [] @@ -265,6 +311,9 @@ module TkValidation super << ValidateCmd end + Tk::ValidateConfigure.__def_validcmd(binding, ValidateCmd) + +=begin def validatecommand(cmd = Proc.new, args = nil) if cmd.kind_of?(ValidateCmd) configure('validatecommand', cmd) @@ -274,8 +323,13 @@ module TkValidation configure('validatecommand', cmd) end end - alias vcmd validatecommand +=end +# def validatecommand(*args, &b) +# __validcmd_call(ValidateCmd, 'validatecommand', *args, &b) +# end +# alias vcmd validatecommand +=begin def invalidcommand(cmd = Proc.new, args = nil) if cmd.kind_of?(ValidateCmd) configure('invalidcommand', cmd) @@ -285,5 +339,9 @@ module TkValidation configure('invalidcommand', cmd) end end - alias invcmd invalidcommand +=end +# def invalidcommand(*args, &b) +# __validcmd_call(ValidateCmd, 'invalidcommand', *args, &b) +# end +# alias invcmd invalidcommand end diff --git a/ext/tk/lib/tk/variable.rb b/ext/tk/lib/tk/variable.rb index bfa19fc18d..6398537bfa 100644 --- a/ext/tk/lib/tk/variable.rb +++ b/ext/tk/lib/tk/variable.rb @@ -48,6 +48,10 @@ TkCore::INTERP.add_tk_procs('rb_var', 'args', <<-'EOL') #_get_eval_string(TkVar_CB_TBL[name1].trace_callback(name2,op)) begin _get_eval_string(TkVar_CB_TBL[name1].trace_callback(name2, op)) + rescue SystemExit + exit(0) + rescue Interrupt + exit!(1) rescue Exception => e begin msg = _toUTF8(e.class.inspect) + ': ' + diff --git a/ext/tk/lib/tk/winfo.rb b/ext/tk/lib/tk/winfo.rb index a3ce2b2cd2..b4cb79a29a 100644 --- a/ext/tk/lib/tk/winfo.rb +++ b/ext/tk/lib/tk/winfo.rb @@ -1,6 +1,9 @@ # # tk/winfo.rb : methods for winfo command # +module TkWinfo +end + require 'tk' module TkWinfo diff --git a/ext/tk/lib/tkextlib/itk/incr_tk.rb b/ext/tk/lib/tkextlib/itk/incr_tk.rb index 1cc52c510b..db01bfe85e 100644 --- a/ext/tk/lib/tkextlib/itk/incr_tk.rb +++ b/ext/tk/lib/tkextlib/itk/incr_tk.rb @@ -55,6 +55,7 @@ module Tk def component_path(name) window(tk_send('component', name)) end + alias component_widget component_path def component_invoke(name, cmd, *args) window(tk_send('component', name, cmd, *args)) diff --git a/ext/tk/lib/tkextlib/iwidgets.rb b/ext/tk/lib/tkextlib/iwidgets.rb index 7edd43346c..0370ad5d23 100644 --- a/ext/tk/lib/tkextlib/iwidgets.rb +++ b/ext/tk/lib/tkextlib/iwidgets.rb @@ -50,8 +50,19 @@ module Tk autoload :Fileselectionbox, 'tkextlib/iwidgets/fileselectionbox' autoload :Fileselectiondialog, 'tkextlib/iwidgets/fileselectiondialog' autoload :Finddialog, 'tkextlib/iwidgets/finddialog' + autoload :Hierarchy, 'tkextlib/iwidgets/hierarchy' + autoload :Hyperhelp, 'tkextlib/iwidgets/hyperhelp' autoload :Labeledframe, 'tkextlib/iwidgets/labeledframe' autoload :Labeledwidget, 'tkextlib/iwidgets/labeledwidget' + autoload :Mainwindow, 'tkextlib/iwidgets/mainwindow' + autoload :Messagebox, 'tkextlib/iwidgets/messagebox' + autoload :Messagedialog, 'tkextlib/iwidgets/messagedialog' + autoload :Radiobox, 'tkextlib/iwidgets/radiobox' + autoload :Scrolledwidget, 'tkextlib/iwidgets/scrolledwidget' autoload :Shell, 'tkextlib/iwidgets/shell' + autoload :Timeentry, 'tkextlib/iwidgets/timeentry' + autoload :Timefield, 'tkextlib/iwidgets/timefield' + autoload :Toolbar, 'tkextlib/iwidgets/toolbar' + autoload :Watch, 'tkextlib/iwidgets/watch' end end diff --git a/ext/tk/lib/tkextlib/iwidgets/buttonbox.rb b/ext/tk/lib/tkextlib/iwidgets/buttonbox.rb index fef442a769..5ca48ed229 100644 --- a/ext/tk/lib/tkextlib/iwidgets/buttonbox.rb +++ b/ext/tk/lib/tkextlib/iwidgets/buttonbox.rb @@ -36,7 +36,8 @@ class Tk::Iwidgets::Buttonbox if tagOrId.kind_of?(Tk::Itk::Component) tagOrId.name else - _get_eval_string(tagOrId) + #_get_eval_string(tagOrId) + tagOrId end end diff --git a/ext/tk/lib/tkextlib/iwidgets/calendar.rb b/ext/tk/lib/tkextlib/iwidgets/calendar.rb index 7a9763addc..dab10b118b 100644 --- a/ext/tk/lib/tkextlib/iwidgets/calendar.rb +++ b/ext/tk/lib/tkextlib/iwidgets/calendar.rb @@ -48,6 +48,8 @@ class Tk::Iwidgets::Calendar super << CalendarCommand end + Tk::ValidateConfigure.__def_validcmd(binding, CalendarCommand) +=begin def command(cmd = Proc.new, args = nil) if cmd.kind_of?(CalendarCommand) configure('command', cmd) @@ -57,6 +59,7 @@ class Tk::Iwidgets::Calendar configure('command', cmd) end end +=end #################################### diff --git a/ext/tk/lib/tkextlib/iwidgets/checkbox.rb b/ext/tk/lib/tkextlib/iwidgets/checkbox.rb index 9845439ac4..5e0fb5e7b6 100644 --- a/ext/tk/lib/tkextlib/iwidgets/checkbox.rb +++ b/ext/tk/lib/tkextlib/iwidgets/checkbox.rb @@ -36,7 +36,8 @@ class Tk::Iwidgets::Checkbox if tagOrId.kind_of?(Tk::Itk::Component) tagOrId.name else - _get_eval_string(tagOrId) + #_get_eval_string(tagOrId) + tagOrId end end diff --git a/ext/tk/lib/tkextlib/iwidgets/combobox.rb b/ext/tk/lib/tkextlib/iwidgets/combobox.rb index ca0e57c233..1cf10b4004 100644 --- a/ext/tk/lib/tkextlib/iwidgets/combobox.rb +++ b/ext/tk/lib/tkextlib/iwidgets/combobox.rb @@ -82,7 +82,7 @@ class Tk::Iwidgets::Combobox def sort(*params, &b) # see 'lsort' man page about params if b - tk_call(@path, 'sort', *params, -'command', proc(&b)) + tk_call(@path, 'sort', '-command', proc(&b), *params) else tk_call(@path, 'sort', *params) end @@ -91,6 +91,7 @@ class Tk::Iwidgets::Combobox def sort_ascending tk_call(@path, 'sort', 'ascending') self + end def sort_descending tk_call(@path, 'sort', 'descending') self diff --git a/ext/tk/lib/tkextlib/iwidgets/datefield.rb b/ext/tk/lib/tkextlib/iwidgets/datefield.rb index a757403d6e..924aef9c4d 100644 --- a/ext/tk/lib/tkextlib/iwidgets/datefield.rb +++ b/ext/tk/lib/tkextlib/iwidgets/datefield.rb @@ -30,8 +30,9 @@ class Tk::Iwidgets::Datefield def valid? bool(tk_call(@path, 'isvalid')) end + alias isvalid? valid? - def show(date) + def show(date=None) tk_call(@path, 'show', date) self end diff --git a/ext/tk/lib/tkextlib/iwidgets/dialogshell.rb b/ext/tk/lib/tkextlib/iwidgets/dialogshell.rb index 8359a3c551..4736ebab77 100644 --- a/ext/tk/lib/tkextlib/iwidgets/dialogshell.rb +++ b/ext/tk/lib/tkextlib/iwidgets/dialogshell.rb @@ -36,7 +36,8 @@ class Tk::Iwidgets::Dialogshell if tagOrId.kind_of?(Tk::Itk::Component) tagOrId.name else - _get_eval_string(tagOrId) + #_get_eval_string(tagOrId) + tagOrId end end diff --git a/ext/tk/lib/tkextlib/iwidgets/entryfield.rb b/ext/tk/lib/tkextlib/iwidgets/entryfield.rb index b38615a671..6299259b9b 100644 --- a/ext/tk/lib/tkextlib/iwidgets/entryfield.rb +++ b/ext/tk/lib/tkextlib/iwidgets/entryfield.rb @@ -49,6 +49,8 @@ class Tk::Iwidgets::Entryfield super << EntryfieldValidate end + Tk::ValidateConfigure.__def_validcmd(binding, EntryfieldValidate) +=begin def validate(cmd = Proc.new, args = nil) if cmd.kind_of?(ValidateCmd) configure('validate', cmd) @@ -68,6 +70,7 @@ class Tk::Iwidgets::Entryfield configure('invalid', cmd) end end +=end #################################### diff --git a/ext/tk/lib/tkextlib/iwidgets/hierarchy.rb b/ext/tk/lib/tkextlib/iwidgets/hierarchy.rb new file mode 100644 index 0000000000..a7024356ac --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/hierarchy.rb @@ -0,0 +1,294 @@ +# +# tkextlib/iwidgets/hierarchy.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tk/text' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Hierarchy < Tk::Iwidgets::Scrolledwidget + end + end +end + +class Tk::Iwidgets::Hierarchy + ItemConfCMD = ['tag'.freeze, 'configure'.freeze].freeze + include TkTextTagConfig + + TkCommandNames = ['::iwidgets::hierarchy'.freeze].freeze + WidgetClassName = 'Hierarchy'.freeze + WidgetClassNames[WidgetClassName] = self + + #################################### + + include Tk::ValidateConfigure + + class QueryCommand < TkValidateCommand + class ValidateArgs < TkUtil::CallbackSubst + KEY_TBL = [ [?n, ?s, :node], 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) + ['querycommand'] + end + end + + class IndicatorCommand < TkValidateCommand + class ValidateArgs < TkUtil::CallbackSubst + KEY_TBL = [ + [ ?n, ?s, :node ], + [ ?s, ?b, :status ], + nil + ] + + PROC_TBL = [ + [ ?s, TkComm.method(:string) ], + [ ?b, TkComm.method(:bool) ], + 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) + ['iconcommand', 'icondblcommand', 'imagedblcommand'] + end + end + + class IconCommand < TkValidateCommand + class ValidateArgs < TkUtil::CallbackSubst + KEY_TBL = [ + [ ?n, ?s, :node ], + [ ?i, ?s, :icon ], + 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) + ['dblclickcommand', 'imagecommand', 'selectcommand'] + end + end + + def __validation_class_list + super << QueryCommand << IndicatorCommand << IconCommand + end + + Tk::ValidateConfigure.__def_validcmd(binding, QueryCommand) + Tk::ValidateConfigure.__def_validcmd(binding, IndicatorCommand) + Tk::ValidateConfigure.__def_validcmd(binding, IconCommand) + + #################################### + + def clear + tk_call(@path, 'clear') + self + end + + def collapse(node) + tk_call(@path, 'collapse') + self + end + + def current + tk_call(@path, 'current') + end + + def draw(mode=None) + case mode + when None + # do nothing + when 'now', :now + mode = '-now' + when 'eventually', :eventually + mode = '-eventually' + when String, Symbol + mode = mode.to_s + mode = '-' << mode if mode[0] != ?- + end + tk_call(@path, 'draw', mode) + end + + def expand(node) + tk_call(@path, 'expand', node) + self + end + + def expanded?(node) + bool(tk_call(@path, 'expanded', node)) + end + + def exp_state + list(tk_call(@path, 'expState')) + end + alias expand_state exp_state + alias expanded_list exp_state + + def mark_clear + tk_call(@path, 'mark', 'clear') + self + end + def mark_add(*nodes) + tk_call(@path, 'mark', 'add', *nodes) + self + end + def mark_remove(*nodes) + tk_call(@path, 'mark', 'remove', *nodes) + self + end + def mark_get + list(tk_call(@path, 'mark', 'get')) + end + + def refresh(node) + tk_call(@path, 'refresh', node) + self + end + + def prune(node) + tk_call(@path, 'prune', node) + self + end + + def selection_clear + tk_call(@path, 'selection', 'clear') + self + end + def selection_add(*nodes) + tk_call(@path, 'selection', 'add', *nodes) + self + end + def selection_remove(*nodes) + tk_call(@path, 'selection', 'remove', *nodes) + self + end + def selection_get + list(tk_call(@path, 'selection', 'get')) + end + + def toggle(node) + tk_call(@path, 'toggle', node) + self + end + + # based on TkText widget + + def bbox(index) + list(tk_send_without_enc('bbox', _get_eval_enc_str(index))) + end + + def compare(idx1, op, idx2) + bool(tk_send_without_enc('compare', _get_eval_enc_str(idx1), + op, _get_eval_enc_str(idx2))) + end + + def debug + bool(tk_send_without_enc('debug')) + end + def debug=(boolean) + tk_send_without_enc('debug', boolean) + #self + boolean + end + + def delete(first, last=None) + tk_send_without_enc('delete', first, last) + self + end + + def dlineinfo(index) + list(tk_send_without_enc('dlineinfo', _get_eval_enc_str(index))) + end + + def get(*index) + _fromUTF8(tk_send_without_enc('get', *index)) + end + + def index(index) + tk_send_without_enc('index', _get_eval_enc_str(index)) + end + + def insert(index, chars, *tags) + if tags[0].kind_of? Array + # multiple chars-taglist argument :: str, [tag,...], str, [tag,...], ... + args = [chars] + while tags.size > 0 + args << tags.shift.collect{|x|_get_eval_string(x)}.join(' ') # taglist + args << tags.shift if tags.size > 0 # chars + end + super index, *args + else + # single chars-taglist argument :: str, tag, tag, ... + if tags.size == 0 + super index, chars + else + super index, chars, tags.collect{|x|_get_eval_string(x)}.join(' ') + end + end + end + + def scan_mark(x, y) + tk_send_without_enc('scan', 'mark', x, y) + self + end + def scan_dragto(x, y) + tk_send_without_enc('scan', 'dragto', x, y) + self + end + def see(index) + tk_send_without_enc('see', 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 + + def yview(*index) + if index.size == 0 + list(tk_send_without_enc('yview')) + else + tk_send_without_enc('yview', *index) + self + end + end + def yview_moveto(*index) + yview('moveto', *index) + end + def yview_scroll(*index) + yview('scroll', *index) + end +end diff --git a/ext/tk/lib/tkextlib/iwidgets/hyperhelp.rb b/ext/tk/lib/tkextlib/iwidgets/hyperhelp.rb new file mode 100644 index 0000000000..22e86339a6 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/hyperhelp.rb @@ -0,0 +1,40 @@ +# +# tkextlib/iwidgets/hyperhelp.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Hyperhelp < Tk::Iwidgets::Shell + end + end +end + +class Tk::Iwidgets::Hyperhelp + TkCommandNames = ['::iwidgets::hyperhelp'.freeze].freeze + WidgetClassName = 'Hyperhelp'.freeze + WidgetClassNames[WidgetClassName] = self + + def show_topic(topic) + tk_call(@path, 'showtopic', topic) + self + end + + def follow_link(href) + tk_call(@path, 'followlink', href) + self + end + + def forward + tk_call(@path, 'forward') + self + end + + def back + tk_call(@path, 'back') + self + end +end diff --git a/ext/tk/lib/tkextlib/iwidgets/mainwindow.rb b/ext/tk/lib/tkextlib/iwidgets/mainwindow.rb new file mode 100644 index 0000000000..4570afc6d0 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/mainwindow.rb @@ -0,0 +1,52 @@ +# +# tkextlib/iwidgets/mainwindow.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Mainwindow < Tk::Iwidgets::Shell + end + end +end + +class Tk::Iwidgets::Mainwindow + TkCommandNames = ['::iwidgets::mainwindow'.freeze].freeze + WidgetClassName = 'Mainwindow'.freeze + WidgetClassNames[WidgetClassName] = self + + def child_site + window(tk_call(@path, 'childsite')) + end + + def menubar(*args) + unless args.empty? + tk_call(@path, 'menubar', *args) + end + window(tk_call(@path, 'menubar')) + end + + def mousebar(*args) + unless args.empty? + tk_call(@path, 'mousebar', *args) + end + window(tk_call(@path, 'mousebar')) + end + + def msgd(*args) + unless args.empty? + tk_call(@path, 'msgd', *args) + end + window(tk_call(@path, 'msgd')) + end + + def toolbar(*args) + unless args.empty? + tk_call(@path, 'toolbar', *args) + end + window(tk_call(@path, 'toolbar')) + end +end diff --git a/ext/tk/lib/tkextlib/iwidgets/messagebox.rb b/ext/tk/lib/tkextlib/iwidgets/messagebox.rb new file mode 100644 index 0000000000..a9d9775c75 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/messagebox.rb @@ -0,0 +1,81 @@ +# +# tkextlib/iwidgets/messagebox.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Messagebox < Tk::Iwidgets::Scrolledwidget + end + end +end + +class Tk::Iwidgets::Messagebox + TkCommandNames = ['::iwidgets::messagebox'.freeze].freeze + WidgetClassName = 'Messagebox'.freeze + WidgetClassNames[WidgetClassName] = self + + #################################### + + include TkItemConfigMethod + + def __item_cget_cmd(id) + [self.path, 'type', 'cget', id] + end + private :__item_cget_cmd + + def __item_config_cmd(id) + [self.path, 'type', 'configure', id] + end + private :__item_config_cmd + + def tagid(tagOrId) + if tagOrId.kind_of?(Tk::Itk::Component) + tagOrId.name + else + #_get_eval_string(tagOrId) + tagOrId + end + end + + alias type_cget itemcget + alias type_configure itemconfigure + alias type_configinfo itemconfiginfo + alias current_type_configinfo current_itemconfiginfo + + private :itemcget, :itemconfigure + private :itemconfiginfo, :current_itemconfiginfo + + #################################### + + def type_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, 'type', 'add', tagid(tag), *hash_kv(keys)) + tag + end + + def clear + tk_call(@path, 'clear') + self + end + + def export(file) + tk_call(@path, 'export', file) + self + end + + def issue(string, type=None, *args) + tk_call(@path, 'issue', string, tagid(type), *args) + self + end + +end diff --git a/ext/tk/lib/tkextlib/iwidgets/messagedialog.rb b/ext/tk/lib/tkextlib/iwidgets/messagedialog.rb new file mode 100644 index 0000000000..c19b83e517 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/messagedialog.rb @@ -0,0 +1,20 @@ +# +# tkextlib/iwidgets/messagedialog.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Messagedialog < Tk::Iwidgets::Dialog + end + end +end + +class Tk::Iwidgets::Messagedialog + TkCommandNames = ['::iwidgets::messagedialog'.freeze].freeze + WidgetClassName = 'Messagedialog'.freeze + WidgetClassNames[WidgetClassName] = self +end diff --git a/ext/tk/lib/tkextlib/iwidgets/radiobox.rb b/ext/tk/lib/tkextlib/iwidgets/radiobox.rb new file mode 100644 index 0000000000..dd96089ffa --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/radiobox.rb @@ -0,0 +1,107 @@ +# +# tkextlib/iwidgets/radiobox.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Radiobox < Tk::Iwidgets::Labeledframe + end + end +end + +class Tk::Iwidgets::Radiobox + TkCommandNames = ['::iwidgets::radiobox'.freeze].freeze + WidgetClassName = 'Radiobox'.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) + 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/scrolledwidget.rb b/ext/tk/lib/tkextlib/iwidgets/scrolledwidget.rb new file mode 100644 index 0000000000..eef093d314 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/scrolledwidget.rb @@ -0,0 +1,20 @@ +# +# tkextlib/iwidgets/scrolledwidget.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Scrolledwidget < Tk::Iwidgets::Labeledwidget + end + end +end + +class Tk::Iwidgets::Scrolledwidget + TkCommandNames = ['::iwidgets::scrolledwidget'.freeze].freeze + WidgetClassName = 'Scrolledwidget'.freeze + WidgetClassNames[WidgetClassName] = self +end diff --git a/ext/tk/lib/tkextlib/iwidgets/timeentry.rb b/ext/tk/lib/tkextlib/iwidgets/timeentry.rb new file mode 100644 index 0000000000..987cddc1e0 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/timeentry.rb @@ -0,0 +1,20 @@ +# +# tkextlib/iwidgets/timeentry.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Timeentry < Tk::Iwidgets::Timefield + end + end +end + +class Tk::Iwidgets::Timeentry + TkCommandNames = ['::iwidgets::timeentry'.freeze].freeze + WidgetClassName = 'Timeentry'.freeze + WidgetClassNames[WidgetClassName] = self +end diff --git a/ext/tk/lib/tkextlib/iwidgets/timefield.rb b/ext/tk/lib/tkextlib/iwidgets/timefield.rb new file mode 100644 index 0000000000..602093eb7e --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/timefield.rb @@ -0,0 +1,43 @@ +# +# tkextlib/iwidgets/timefield.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Timefield < Tk::Iwidgets::Labeledwidget + end + end +end + +class Tk::Iwidgets::Timefield + TkCommandNames = ['::iwidgets::timefield'.freeze].freeze + WidgetClassName = 'Timefield'.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 + alias isvalid? valid? + + def show(time=None) + tk_call(@path, 'show', time) + self + end + def show_now + tk_call(@path, 'show', 'now') + self + end +end diff --git a/ext/tk/lib/tkextlib/iwidgets/toolbar.rb b/ext/tk/lib/tkextlib/iwidgets/toolbar.rb new file mode 100644 index 0000000000..81239f9b97 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/toolbar.rb @@ -0,0 +1,86 @@ +# +# tkextlib/iwidgets/toolbar.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Toolbar < Tk::Itk::Widget + end + end +end + +class Tk::Iwidgets::Toolbar + TkCommandNames = ['::iwidgets::toolbar'.freeze].freeze + WidgetClassName = 'Toolbar'.freeze + WidgetClassNames[WidgetClassName] = self + + #################################### + + include TkItemConfigMethod + + def tagid(tagOrId) + if tagOrId.kind_of?(Tk::Itk::Component) + tagOrId.name + else + #_get_eval_string(tagOrId) + tagOrId + end + end + + #################################### + + def add(type, 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', type, tagid(tag), *hash_kv(keys)) + tag + end + + def delete(idx1, idx2=nil) + if idx2 + tk_call(@path, 'delete', index(idx1), index(idx2)) + else + tk_call(@path, 'delete', index(idx1)) + end + self + end + + def index(idx) + number(tk_call(@path, 'index', tagid(idx))) + end + + def insert(idx, type, 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), type, 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/watch.rb b/ext/tk/lib/tkextlib/iwidgets/watch.rb new file mode 100644 index 0000000000..f62c0b931e --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/watch.rb @@ -0,0 +1,45 @@ +# +# tkextlib/iwidgets/watch.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Watch < Tk::Itk::Widget + end + end +end + +class Tk::Iwidgets::Watch + TkCommandNames = ['::iwidgets::watch'.freeze].freeze + WidgetClassName = 'Watch'.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 show(time=None) + tk_call(@path, 'show', time) + self + end + def show_now + tk_call(@path, 'show', 'now') + self + end + + def watch(*args) + unless args.empty? + tk_call(@path, 'watch', *args) + end + component_path('canvas') + end +end diff --git a/ext/tk/lib/tkextlib/tcllib.rb b/ext/tk/lib/tkextlib/tcllib.rb index 2955416b2b..831cc5a327 100644 --- a/ext/tk/lib/tkextlib/tcllib.rb +++ b/ext/tk/lib/tkextlib/tcllib.rb @@ -11,15 +11,31 @@ require 'tkextlib/setup.rb' # call setup script require 'tkextlib/tcllib/setup.rb' +err = '' + # package:: autoscroll -require 'tkextlib/tcllib/autoscroll' +target = 'tkextlib/tcllib/autoscroll' +begin + require target +rescue => e + err << "\n ['" << target << "'] " << e.class.name << ' : ' << e.message +end # package:: cursor -require 'tkextlib/tcllib/cursor' +target = 'tkextlib/tcllib/cursor' +begin + require target +rescue => e + err << "\n ['" << target << "'] " << e.class.name << ' : ' << e.message +end # package:: style -require 'tkextlib/tcllib/style' - +target = 'tkextlib/tcllib/style' +begin + require target +rescue => e + err << "\n ['" << target << "'] " << e.class.name << ' : ' << e.message +end # autoload module Tk @@ -41,3 +57,8 @@ module Tk autoload :Tkpiechart, 'tkextlib/tcllib/tkpiechart' end end + +unless err.empty? + warn("Warning: some sub-packages are failed to require : " + err) +end + diff --git a/ext/tk/lib/tkextlib/tcllib/autoscroll.rb b/ext/tk/lib/tkextlib/tcllib/autoscroll.rb index 800a70744c..117ed8d98a 100644 --- a/ext/tk/lib/tkextlib/tcllib/autoscroll.rb +++ b/ext/tk/lib/tkextlib/tcllib/autoscroll.rb @@ -28,9 +28,6 @@ require 'tk' require 'tk/scrollbar' require 'tkextlib/tcllib.rb' -# TkPackage.require('autoscroll', '1.0') -TkPackage.require('autoscroll') - module Tk module Tcllib module Autoscroll @@ -43,7 +40,12 @@ module Tk end end end +end +# TkPackage.require('autoscroll', '1.0') +TkPackage.require('autoscroll') + +module Tk module Scrollable def autoscroll(mode = nil) case mode diff --git a/ext/tk/lib/tkextlib/tcllib/ctext.rb b/ext/tk/lib/tkextlib/tcllib/ctext.rb index 2318235a4d..0a043b1730 100644 --- a/ext/tk/lib/tkextlib/tcllib/ctext.rb +++ b/ext/tk/lib/tkextlib/tcllib/ctext.rb @@ -137,7 +137,7 @@ class Tk::Tcllib::CText self end - def modified(mode) + def modified?(mode) bool(tk_call('ctext::modified', @path, mode)) end end diff --git a/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb b/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb index 4b5219e60b..0e57b7c194 100644 --- a/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb +++ b/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb @@ -539,9 +539,11 @@ class Tk::TreeCtrl_Widget def item_isopen(item) bool(tk_send('item', 'isopen', item)) end - alias item_is_open item_isopen - alias item_isopen? item_isopen - alias item_is_open? item_isopen + alias item_is_open item_isopen + alias item_isopen? item_isopen + alias item_is_open? item_isopen + alias item_isopened? item_isopen + alias item_is_opened? item_isopen def item_lastchild(parent, child=nil) if child diff --git a/ext/tk/lib/tkextlib/vu/pie.rb b/ext/tk/lib/tkextlib/vu/pie.rb index cacca594e6..b4506e10b5 100644 --- a/ext/tk/lib/tkextlib/vu/pie.rb +++ b/ext/tk/lib/tkextlib/vu/pie.rb @@ -2,6 +2,7 @@ # ::vu::pie widget # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # +require 'tk' # create module/class module Tk diff --git a/ext/tk/lib/tkextlib/vu/spinbox.rb b/ext/tk/lib/tkextlib/vu/spinbox.rb index f586434138..b6499645a3 100644 --- a/ext/tk/lib/tkextlib/vu/spinbox.rb +++ b/ext/tk/lib/tkextlib/vu/spinbox.rb @@ -5,6 +5,7 @@ # a standard spinbox (<= 8.3) # This is the same as the 8.4 core spinbox widget. # +require 'tk' if (Tk::TK_MAJOR_VERSION < 8 || (Tk::TK_MAJOR_VERSION == 8 && Tk::TK_MINOR_VERSION < 4)) @@ -14,4 +15,8 @@ if (Tk::TK_MAJOR_VERSION < 8 || Tk.tk_call('namespace', 'import', '::vu::spinbox') end -Tk::Vu::Spinbox = TkSpinbox +module Tk + module Vu + Spinbox = TkSpinbox + end +end diff --git a/ext/tk/sample/tkextlib/iwidgets/sample/hierarchy.rb b/ext/tk/sample/tkextlib/iwidgets/sample/hierarchy.rb new file mode 100644 index 0000000000..594158294e --- /dev/null +++ b/ext/tk/sample/tkextlib/iwidgets/sample/hierarchy.rb @@ -0,0 +1,25 @@ +#!/usr/bin/env ruby +require 'tk' +require 'tkextlib/iwidgets' + +def get_files(file) + dir = (file.empty?)? ENV['HOME'] : file + Dir.chdir(dir) rescue return '' + rlist = [] + Dir['*'].sort.each{|f| rlist << File.join(dir, f) } + rlist +end + +Tk::Iwidgets::Hierarchy.new(:querycommand=>proc{|arg| get_files(arg.node)}, + :visibleitems=>'30x15', + :labeltext=>ENV['HOME']).pack(:side=>:left, + :expand=>true, + :fill=>:both) + +# Tk::Iwidgets::Hierarchy.new(:querycommand=>[proc{|n| get_files(n)}, '%n'], +# :visibleitems=>'30x15', +# :labeltext=>ENV['HOME']).pack(:side=>:left, +# :expand=>true, +# :fill=>:both) + +Tk.mainloop diff --git a/ext/tk/sample/tkextlib/iwidgets/sample/hyperhelp.rb b/ext/tk/sample/tkextlib/iwidgets/sample/hyperhelp.rb new file mode 100644 index 0000000000..f9c92bf6dc --- /dev/null +++ b/ext/tk/sample/tkextlib/iwidgets/sample/hyperhelp.rb @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby +require 'tk' +require 'tkextlib/iwidgets' + +mainloop = Thread.new{Tk.mainloop} + +dir = '/usr/local/ActiveTcl/demos/IWidgets/html/' +href = [ 'hyperhelp.n', 'buttonbox.n', 'calendar.n' ] + +hh = Tk::Iwidgets::Hyperhelp.new(:topics=>href, :helpdir=>dir) +hh.show_topic('hyperhelp.n') +hh.activate + +mainloop.join diff --git a/ext/tk/sample/tkextlib/iwidgets/sample/messagebox1.rb b/ext/tk/sample/tkextlib/iwidgets/sample/messagebox1.rb new file mode 100644 index 0000000000..3f7b137b19 --- /dev/null +++ b/ext/tk/sample/tkextlib/iwidgets/sample/messagebox1.rb @@ -0,0 +1,19 @@ +#!/usr/bin/env ruby +require 'tk' +require 'tkextlib/iwidgets' + +mb = Tk::Iwidgets::Messagebox.new(:hscrollmode=>:dynamic, + :labeltext=>'Messages', :labelpos=>:n, + :height=>120, :width=>550, + :savedir=>'/tmp', :textbackground=>'#d9d9d9') +mb.pack(:padx=>5, :pady=>5, :fill=>:both, :expand=>true) + +mb.type_add('ERROR', :background=>'red', :foreground=>'white', :bell=>true) +mb.type_add('WARNING', :background=>'yellow', :foreground=>'black') +mb.type_add('INFO', :background=>'white', :foreground=>'black') + +mb.issue('This is an error message in red with a beep', 'ERROR') +mb.issue('This warning message in yellow', 'WARNING') +mb.issue('This is an informational message', 'INFO') + +Tk.mainloop diff --git a/ext/tk/sample/tkextlib/iwidgets/sample/messagebox2.rb b/ext/tk/sample/tkextlib/iwidgets/sample/messagebox2.rb new file mode 100644 index 0000000000..1aae7587e4 --- /dev/null +++ b/ext/tk/sample/tkextlib/iwidgets/sample/messagebox2.rb @@ -0,0 +1,19 @@ +#!/usr/bin/env ruby +require 'tk' +require 'tkextlib/iwidgets' + +mb = Tk::Iwidgets::Messagebox.new(:hscrollmode=>:dynamic, + :labeltext=>'Messages', :labelpos=>:n, + :height=>120, :width=>550, + :savedir=>'/tmp', :textbackground=>'#d9d9d9') +mb.pack(:padx=>5, :pady=>5, :fill=>:both, :expand=>true) + +error = mb.type_add(:background=>'red', :foreground=>'white', :bell=>true) +warning = mb.type_add(:background=>'yellow', :foreground=>'black') +info = mb.type_add(:background=>'white', :foreground=>'black') + +mb.issue('This is an error message in red with a beep', error) +mb.issue('This warning message in yellow', warning) +mb.issue('This is an informational message', info) + +Tk.mainloop diff --git a/ext/tk/sample/tkextlib/iwidgets/sample/messagedialog.rb b/ext/tk/sample/tkextlib/iwidgets/sample/messagedialog.rb new file mode 100644 index 0000000000..8cf373f964 --- /dev/null +++ b/ext/tk/sample/tkextlib/iwidgets/sample/messagedialog.rb @@ -0,0 +1,44 @@ +#!/usr/bin/env ruby +require 'tk' +require 'tkextlib/iwidgets' + +mainloop = Thread.new{Tk.mainloop} + +# +# Standard question message dialog used for confirmation. +# +md = Tk::Iwidgets::Messagedialog.new(:title=>'Message Dialog', + :text=>'Are you sure ? ', + :bitmap=>'questhead', :modality=>:global) + +md.buttonconfigure('OK', :text=>'Yes') +md.buttonconfigure('Cancel', :text=>'No') + +if TkComm.bool(md.activate) + md.text('Are you really sure ? ') + if TkComm.bool(md.activate) + puts 'Yes' + else + puts 'No' + end +else + puts 'No' +end + +md.destroy + +# +# Copyright notice with automatic deactivation. +# +bmp = '@' + File.join(File.dirname(File.expand_path(__FILE__)), '../catalog_demo/images/text.xbm') + +cr = Tk::Iwidgets::Messagedialog.new(:title=>'Copyright', + :bitmap=>bmp, :imagepos=>:n, + :text=>"Copyright 200x XXX Corporation\nAll rights reserved") + +cr.hide('Cancel') + +cr.activate +Tk.after(7000, proc{cr.deactivate; Tk.root.destroy}) + +mainloop.join diff --git a/ext/tk/sample/tkextlib/iwidgets/sample/radiobox.rb b/ext/tk/sample/tkextlib/iwidgets/sample/radiobox.rb new file mode 100644 index 0000000000..9cd6a002b0 --- /dev/null +++ b/ext/tk/sample/tkextlib/iwidgets/sample/radiobox.rb @@ -0,0 +1,13 @@ +#!/usr/bin/env ruby +require 'tk' +require 'tkextlib/iwidgets' + +rb = Tk::Iwidgets::Radiobox.new(:labeltext=>'Fonts') +rb.add('times', :text=>'Times') +rb.add('helvetica', :text=>'Helvetica') +rb.add('courier', :text=>'Courier') +rb.add('symbol', :text=>'Symbol') +rb.select('courier') +rb.pack(:expand=>true, :fill=>:both, :padx=>10, :pady=>10) + +Tk.mainloop diff --git a/ext/tk/sample/tkextlib/iwidgets/sample/timeentry.rb b/ext/tk/sample/tkextlib/iwidgets/sample/timeentry.rb new file mode 100644 index 0000000000..465939947b --- /dev/null +++ b/ext/tk/sample/tkextlib/iwidgets/sample/timeentry.rb @@ -0,0 +1,7 @@ +#!/usr/bin/env ruby +require 'tk' +require 'tkextlib/iwidgets' + +Tk::Iwidgets::Timeentry.new.pack + +Tk.mainloop diff --git a/ext/tk/sample/tkextlib/iwidgets/sample/timefield.rb b/ext/tk/sample/tkextlib/iwidgets/sample/timefield.rb new file mode 100644 index 0000000000..bb5945048d --- /dev/null +++ b/ext/tk/sample/tkextlib/iwidgets/sample/timefield.rb @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +require 'tk' +require 'tkextlib/iwidgets' + +tf = Tk::Iwidgets::Timefield.new(:command=>proc{puts(tf.get)}) +tf.pack(:fill=>:x, :expand=>true, :padx=>10, :pady=>10) + +Tk.mainloop diff --git a/ext/tk/sample/tkextlib/iwidgets/sample/watch.rb b/ext/tk/sample/tkextlib/iwidgets/sample/watch.rb new file mode 100644 index 0000000000..d2b6246bf3 --- /dev/null +++ b/ext/tk/sample/tkextlib/iwidgets/sample/watch.rb @@ -0,0 +1,18 @@ +#!/usr/bin/env ruby +require 'tk' +require 'tkextlib/iwidgets' + +Thread.new{ + trap('INT') {puts 'catch SIGINT'} + sleep 5 + trap('INT', 'DEFAULT') +} + +Tk::Iwidgets::Watch.new(:state=>:disabled, :showampm=>:no, + :width=>155, :height=>155){|w| + w.pack(:padx=>10, :pady=>10, :fill=>:both, :expand=>true) + # TkTimer.new(1000, -1, proc{w.show; Tk.update}).start + TkTimer.new(25, -1, proc{w.show; Tk.update}).start +} + +Tk.mainloop diff --git a/ext/tk/tkutil.c b/ext/tk/tkutil.c index 39047804b3..4654619169 100644 --- a/ext/tk/tkutil.c +++ b/ext/tk/tkutil.c @@ -214,6 +214,10 @@ tk_symbolkey2str(self, keys) { volatile VALUE new_keys = rb_hash_new(); + if NIL_P(keys) return new_keys; + if (TYPE(keys) != T_HASH) { + rb_raise(rb_eArgError, "Hash is expected"); + } st_foreach(RHASH(keys)->tbl, to_strkey, new_keys); return new_keys; } -- cgit v1.2.3