From e6697a6405f1330ef071220396b8afef1cd1079a Mon Sep 17 00:00:00 2001 From: nagai Date: Tue, 10 Jun 2008 20:59:10 +0000 Subject: * ext/tk/tcltklib.c: SEGV when tcltk-stubs is enabled. * ext/tk/tcltklib.c: avoid error on a shared object. * ext/tk/extconf.rb: support --with-tcltkversion * ext/tk/README.tcltklib: add document about --with-tcltkversion * ext/tk/lib/tk.rb, ext/tk/lib/multi-tk.rb, ext/tk/lib/remote-tk.rb: not work on $SAFE==4 * ext/tk/lib/multi-tk.rb: Object#methods returns Symbols on Ruby1.9. * ext/tk/lib/tk/timer.rb: add TkTimer#at_end(proc) to register the procedure which called at end of the timer. * ext/tk/lib/tk.rb, ext/tk/lib/tk/itemfont.rb, ext/tk/lib/font.rb: support __IGNORE_UNKNOWN_CONFIGURE_OPTION__ about font options. * ext/tk/lib/*: treat __IGNORE_UNKNOWN_CONFIGURE_OPTION__ * ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb, ext/tk/lib/tkextlib/iwidgets/scrolledlistbox.rb, ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb: bug fix. * ext/tk/lib/tk/text.rb: typo. call a wrong method. * ext/tk/lib/tk/itemconfig.rb: ditto. * ext/tk/lib/tk.rb, ext/tk/lib/tk/itemconfig.rb, ext/tk/lib/tk/canvas.rb: support alias names of option keys. * ext/tk/lib/tk/grid.rb: lack of module-method definitions. * ext/tk/lib/tk/pack.rb, ext/tk/lib/tk/grid.rb: increase supported parameter patterns of configure method. * ext/tk/lib/tk.rb: add TkWindow#grid_anchor, grid_column, grid_row. * ext/tk/lib/tk/wm.rb: methods of Tk::Wm_for_General module cannot pass the given block to methods of Tk::Wm module. * ext/tk/lib/tk/wm.rb: Wm#overrideredirect overwrites arguemnt to an invalid value. * ext/tk/lib/tk.rb: fix memory (object) leak bug. * ext/tk/tcltklib.c, ext/tk/tkutil/tkutil.c: fix memory leak. * ext/tk/sample/demos-jp/aniwave.rb, ext/tk/sample/demos-en/aniwave.rb: bug fix. * ext/tk/lib/tkextlib/blt/component.rb, ext/tk/lib/tkextlib/tile/tentry.rb, ext/tk/lib/tkextlib/tile/treeview.rb: ditto. * ext/tk/lib/tkextlib/tile/tpaned.rb: improve TPaned#add. * ext/tk/sample/demos-jp/widget, ext/tk/sample/demos-en/widget, ext/tk/sample/demos-jp/style.rb, ext/tk/sample/demos-en/style.rb, ext/tk/sample/demos-jp/bind.rb, ext/tk/sample/demos-en/bind.rb: bug fix. * ext/tk/sample/ttk_wrapper.rb: ditto. * ext/tk/sample/ttk_wrapper.rb: support "if __FILE__ == $0" idiom. * ext/tk/sample/tktextio.rb: add binding for 'Ctrl-u' at console mode. * ext/tk/lib/tkextlib/tile.rb, ext/tk/lib/tkextlib/tile/style.rb, ext/tk/sample/ttk_wrapper.rb: improve treating and control themes. add Tk::Tile.themes and Tk::Tile.set_theme(theme). * ext/tk/lib/tkextlib/tile.rb: lack of autoload definitions. * ext/tk/lib/tkextlib/tile/tnotebook.rb: cannot use kanji (not UTF-8) characters for headings. * ext/tk/lib/tkextlib/tkDND/shape.rb: wrong package name. * ext/tk/tkutil/tkutil.c: improve handling callback-subst-keys. Now, support longnam-keys (e.g. '%CTT' on tkdnd-2.0; however, still not support tkdnd-2.0 on tkextlib), and symbols of parameters (e.g. :widget=>'%W', :keycode=>'%k', '%x'=>:x, '%X'=>:root_x, and so on; those are attributes of event object). It means that Ruby/Tk accepts not only "widget.bind(ev, '%W', '%k', ...){|w, k, ...| ... }", but also "widget.bind(ev, :widget, :keycode, ...){|w, k, ...| ... }". It is potentially incompatible, when user passes symbols to the arguments of the callback block (the block receives the symbols as strings). I think that is very rare case (probably, used by Ruby/Tk experts only). When causes such trouble, please give strings instead of such symbol parameters (e.g. call Symbol#to_s method). * ext/tk/lib/tk/event.rb, ext/tk/lib/tk/validation.rb, ext/tk/lib/tkextlib/blt/treeview.rb, ext/tk/lib/tkextlib/winico/winico.rb: ditto. * ext/tk/tkutil/tkutil.c: strings are available on subst_tables on TkUtil::CallbackSubst class (it is useful on Ruby 1.9). * ext/tk/lib/tk/spinbox.rb, ext/tk/lib/tkextlib/iwidgets/hierarchy.rb, ext/tk/lib/tkextlib/iwidgets/spinner.rb, ext/tk/lib/tkextlib/iwidgets/entryfield.rb, ext/tk/lib/tkextlib/iwidgets/calendar.rb, ext/tk/lib/tkextlib/blt/dragdrop.rb, ext/tk/lib/tkextlib/tkDND/tkdnd.rb, ext/tk/lib/tkextlib/treectrl/tktreectrl.rb, ext/tk/lib/tkextlib/tktable/tktable.rb: disable code piece became unnecessary by reason of the changes of ext/tk/tkutil/tkutil.c. * ext/tk/lib/tk.rb, ext/tk/lib/multi-tk.rb: change strategy to define the constant WITH_ENCODING. * ext/tk/lib/tk.rb: fix bug on Tk::Encoding.tk_encoding_names. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17083 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/ChangeLog.tkextlib | 6 + ext/tk/README.tcltklib | 6 +- ext/tk/extconf.rb | 142 ++++- ext/tk/lib/multi-tk.rb | 150 ++++- ext/tk/lib/remote-tk.rb | 4 + ext/tk/lib/tk.rb | 254 +++++++-- ext/tk/lib/tk/canvas.rb | 9 + ext/tk/lib/tk/canvastag.rb | 3 + ext/tk/lib/tk/composite.rb | 52 ++ ext/tk/lib/tk/event.rb | 14 +- ext/tk/lib/tk/font.rb | 8 +- ext/tk/lib/tk/grid.rb | 49 +- ext/tk/lib/tk/image.rb | 19 +- ext/tk/lib/tk/itemconfig.rb | 69 ++- ext/tk/lib/tk/itemfont.rb | 33 +- ext/tk/lib/tk/menu.rb | 13 +- ext/tk/lib/tk/menuspec.rb | 14 +- ext/tk/lib/tk/namespace.rb | 14 + ext/tk/lib/tk/pack.rb | 17 + ext/tk/lib/tk/palette.rb | 2 +- ext/tk/lib/tk/panedwindow.rb | 23 +- ext/tk/lib/tk/scale.rb | 13 +- ext/tk/lib/tk/scrollbar.rb | 13 +- ext/tk/lib/tk/spinbox.rb | 2 + ext/tk/lib/tk/text.rb | 42 +- ext/tk/lib/tk/textimage.rb | 4 + ext/tk/lib/tk/texttag.rb | 3 + ext/tk/lib/tk/textwindow.rb | 3 + ext/tk/lib/tk/timer.rb | 38 +- ext/tk/lib/tk/toplevel.rb | 2 +- ext/tk/lib/tk/validation.rb | 9 +- ext/tk/lib/tk/wm.rb | 4 +- ext/tk/lib/tkextlib/blt/component.rb | 101 +++- ext/tk/lib/tkextlib/blt/dragdrop.rb | 6 + ext/tk/lib/tkextlib/blt/htext.rb | 1 + ext/tk/lib/tkextlib/blt/table.rb | 17 +- ext/tk/lib/tkextlib/blt/tabset.rb | 4 + ext/tk/lib/tkextlib/blt/ted.rb | 9 +- ext/tk/lib/tkextlib/blt/treeview.rb | 31 +- ext/tk/lib/tkextlib/blt/unix_dnd.rb | 16 +- ext/tk/lib/tkextlib/blt/watch.rb | 19 +- ext/tk/lib/tkextlib/bwidget/dialog.rb | 7 + ext/tk/lib/tkextlib/bwidget/dynamichelp.rb | 7 + ext/tk/lib/tkextlib/bwidget/listbox.rb | 3 + ext/tk/lib/tkextlib/bwidget/messagedlg.rb | 11 + ext/tk/lib/tkextlib/bwidget/tree.rb | 3 + ext/tk/lib/tkextlib/bwidget/widget.rb | 12 +- ext/tk/lib/tkextlib/iwidgets/buttonbox.rb | 5 +- ext/tk/lib/tkextlib/iwidgets/calendar.rb | 2 + ext/tk/lib/tkextlib/iwidgets/checkbox.rb | 5 +- ext/tk/lib/tkextlib/iwidgets/dialogshell.rb | 5 +- ext/tk/lib/tkextlib/iwidgets/entryfield.rb | 2 + ext/tk/lib/tkextlib/iwidgets/hierarchy.rb | 6 + ext/tk/lib/tkextlib/iwidgets/menubar.rb | 5 +- ext/tk/lib/tkextlib/iwidgets/messagebox.rb | 5 +- ext/tk/lib/tkextlib/iwidgets/notebook.rb | 5 +- ext/tk/lib/tkextlib/iwidgets/panedwindow.rb | 5 +- ext/tk/lib/tkextlib/iwidgets/radiobox.rb | 5 +- ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb | 2 +- ext/tk/lib/tkextlib/iwidgets/scrolledlistbox.rb | 2 +- ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb | 25 +- ext/tk/lib/tkextlib/iwidgets/spinner.rb | 2 + ext/tk/lib/tkextlib/iwidgets/tabnotebook.rb | 5 +- ext/tk/lib/tkextlib/iwidgets/tabset.rb | 5 +- ext/tk/lib/tkextlib/tcllib/getstring.rb | 5 +- ext/tk/lib/tkextlib/tcllib/swaplist.rb | 5 +- ext/tk/lib/tkextlib/tcllib/tablelist_core.rb | 16 +- ext/tk/lib/tkextlib/tile.rb | 42 +- ext/tk/lib/tkextlib/tile/dialog.rb | 14 +- ext/tk/lib/tkextlib/tile/style.rb | 58 +- ext/tk/lib/tkextlib/tile/tentry.rb | 5 + ext/tk/lib/tkextlib/tile/tnotebook.rb | 28 +- ext/tk/lib/tkextlib/tile/tpaned.rb | 43 +- ext/tk/lib/tkextlib/tile/treeview.rb | 60 +- ext/tk/lib/tkextlib/tkDND/shape.rb | 32 +- ext/tk/lib/tkextlib/tkDND/tkdnd.rb | 2 + ext/tk/lib/tkextlib/tktable/tktable.rb | 21 +- ext/tk/lib/tkextlib/treectrl/tktreectrl.rb | 67 ++- ext/tk/lib/tkextlib/version.rb | 2 +- ext/tk/lib/tkextlib/vu/pie.rb | 4 + ext/tk/lib/tkextlib/winico/winico.rb | 8 +- ext/tk/sample/demos-en/anilabel.rb | 10 +- ext/tk/sample/demos-en/aniwave.rb | 9 +- ext/tk/sample/demos-en/arrow.rb | 8 +- ext/tk/sample/demos-en/bind.rb | 24 +- ext/tk/sample/demos-en/bitmap.rb | 10 +- ext/tk/sample/demos-en/button.rb | 2 +- ext/tk/sample/demos-en/check.rb | 14 +- ext/tk/sample/demos-en/check2.rb | 14 +- ext/tk/sample/demos-en/clrpick.rb | 22 +- ext/tk/sample/demos-en/colors.rb | 18 +- ext/tk/sample/demos-en/combo.rb | 96 ++++ ext/tk/sample/demos-en/cscroll.rb | 14 +- ext/tk/sample/demos-en/ctext.rb | 8 +- ext/tk/sample/demos-en/entry1.rb | 12 +- ext/tk/sample/demos-en/entry2.rb | 8 +- ext/tk/sample/demos-en/entry3.rb | 48 +- ext/tk/sample/demos-en/filebox.rb | 17 +- ext/tk/sample/demos-en/floor.rb | 14 +- ext/tk/sample/demos-en/floor2.rb | 14 +- ext/tk/sample/demos-en/form.rb | 8 +- ext/tk/sample/demos-en/goldberg.rb | 23 +- ext/tk/sample/demos-en/hscale.rb | 29 +- ext/tk/sample/demos-en/icon.rb | 20 +- ext/tk/sample/demos-en/image1.rb | 13 +- ext/tk/sample/demos-en/image2.rb | 22 +- ext/tk/sample/demos-en/image3.rb | 29 +- ext/tk/sample/demos-en/items.rb | 8 +- ext/tk/sample/demos-en/knightstour.rb | 271 +++++++++ ext/tk/sample/demos-en/label.rb | 13 +- ext/tk/sample/demos-en/labelframe.rb | 8 +- ext/tk/sample/demos-en/mclist.rb | 117 ++++ ext/tk/sample/demos-en/menu.rb | 12 +- ext/tk/sample/demos-en/menu84.rb | 8 +- ext/tk/sample/demos-en/menubu.rb | 10 +- ext/tk/sample/demos-en/msgbox.rb | 10 +- ext/tk/sample/demos-en/msgbox2.rb | 91 +++ ext/tk/sample/demos-en/paned1.rb | 14 +- ext/tk/sample/demos-en/paned2.rb | 8 +- ext/tk/sample/demos-en/pendulum.rb | 10 +- ext/tk/sample/demos-en/plot.rb | 8 +- ext/tk/sample/demos-en/puzzle.rb | 32 +- ext/tk/sample/demos-en/radio.rb | 12 +- ext/tk/sample/demos-en/radio2.rb | 17 +- ext/tk/sample/demos-en/radio3.rb | 19 +- ext/tk/sample/demos-en/ruler.rb | 8 +- ext/tk/sample/demos-en/sayings.rb | 8 +- ext/tk/sample/demos-en/search.rb | 12 +- ext/tk/sample/demos-en/spin.rb | 12 +- ext/tk/sample/demos-en/states.rb | 8 +- ext/tk/sample/demos-en/style.rb | 10 +- ext/tk/sample/demos-en/text.rb | 8 +- ext/tk/sample/demos-en/textpeer.rb | 14 +- ext/tk/sample/demos-en/toolbar.rb | 130 +++++ ext/tk/sample/demos-en/tree.rb | 119 ++++ ext/tk/sample/demos-en/ttkbut.rb | 139 +++++ ext/tk/sample/demos-en/ttkmenu.rb | 85 +++ ext/tk/sample/demos-en/ttknote.rb | 89 +++ ext/tk/sample/demos-en/ttkpane.rb | 213 +++++++ ext/tk/sample/demos-en/ttkprogress.rb | 66 +++ ext/tk/sample/demos-en/twind.rb | 8 +- ext/tk/sample/demos-en/twind2.rb | 6 +- ext/tk/sample/demos-en/unicodeout.rb | 14 +- ext/tk/sample/demos-en/vscale.rb | 28 +- ext/tk/sample/demos-en/widget | 204 +++++-- ext/tk/sample/demos-jp/anilabel.rb | 10 +- ext/tk/sample/demos-jp/aniwave.rb | 9 +- ext/tk/sample/demos-jp/arrow.rb | 8 +- ext/tk/sample/demos-jp/bind.rb | 24 +- ext/tk/sample/demos-jp/bitmap.rb | 10 +- ext/tk/sample/demos-jp/button.rb | 3 +- ext/tk/sample/demos-jp/check.rb | 14 +- ext/tk/sample/demos-jp/check2.rb | 14 +- ext/tk/sample/demos-jp/clrpick.rb | 20 +- ext/tk/sample/demos-jp/colors.rb | 18 +- ext/tk/sample/demos-jp/combo.rb | 98 ++++ ext/tk/sample/demos-jp/cscroll.rb | 14 +- ext/tk/sample/demos-jp/ctext.rb | 8 +- ext/tk/sample/demos-jp/entry1.rb | 12 +- ext/tk/sample/demos-jp/entry2.rb | 8 +- ext/tk/sample/demos-jp/entry3.rb | 48 +- ext/tk/sample/demos-jp/filebox.rb | 17 +- ext/tk/sample/demos-jp/floor.rb | 14 +- ext/tk/sample/demos-jp/floor2.rb | 14 +- ext/tk/sample/demos-jp/form.rb | 8 +- ext/tk/sample/demos-jp/goldberg.rb | 23 +- ext/tk/sample/demos-jp/hscale.rb | 27 +- ext/tk/sample/demos-jp/icon.rb | 20 +- ext/tk/sample/demos-jp/image1.rb | 13 +- ext/tk/sample/demos-jp/image2.rb | 23 +- ext/tk/sample/demos-jp/image3.rb | 17 +- ext/tk/sample/demos-jp/items.rb | 8 +- ext/tk/sample/demos-jp/knightstour.rb | 273 +++++++++ ext/tk/sample/demos-jp/label.rb | 13 +- ext/tk/sample/demos-jp/labelframe.rb | 8 +- ext/tk/sample/demos-jp/mclist.rb | 121 ++++ ext/tk/sample/demos-jp/menu.rb | 14 +- ext/tk/sample/demos-jp/menu84.rb | 8 +- ext/tk/sample/demos-jp/menu8x.rb | 12 +- ext/tk/sample/demos-jp/menubu.rb | 10 +- ext/tk/sample/demos-jp/msgbox.rb | 14 +- ext/tk/sample/demos-jp/msgbox2.rb | 90 +++ ext/tk/sample/demos-jp/paned1.rb | 14 +- ext/tk/sample/demos-jp/paned2.rb | 8 +- ext/tk/sample/demos-jp/pendulum.rb | 10 +- ext/tk/sample/demos-jp/plot.rb | 8 +- ext/tk/sample/demos-jp/puzzle.rb | 32 +- ext/tk/sample/demos-jp/radio.rb | 12 +- ext/tk/sample/demos-jp/radio2.rb | 17 +- ext/tk/sample/demos-jp/radio3.rb | 19 +- ext/tk/sample/demos-jp/ruler.rb | 8 +- ext/tk/sample/demos-jp/sayings.rb | 8 +- ext/tk/sample/demos-jp/search.rb | 12 +- ext/tk/sample/demos-jp/spin.rb | 14 +- ext/tk/sample/demos-jp/states.rb | 8 +- ext/tk/sample/demos-jp/style.rb | 9 +- ext/tk/sample/demos-jp/text.rb | 8 +- ext/tk/sample/demos-jp/textpeer.rb | 14 +- ext/tk/sample/demos-jp/toolbar.rb | 136 +++++ ext/tk/sample/demos-jp/tree.rb | 120 ++++ ext/tk/sample/demos-jp/ttkbut.rb | 145 +++++ ext/tk/sample/demos-jp/ttkmenu.rb | 91 +++ ext/tk/sample/demos-jp/ttknote.rb | 97 ++++ ext/tk/sample/demos-jp/ttkpane.rb | 216 +++++++ ext/tk/sample/demos-jp/ttkprogress.rb | 71 +++ ext/tk/sample/demos-jp/twind.rb | 6 +- ext/tk/sample/demos-jp/twind2.rb | 6 +- ext/tk/sample/demos-jp/unicodeout.rb | 14 +- ext/tk/sample/demos-jp/vscale.rb | 29 +- ext/tk/sample/demos-jp/widget | 245 ++++++-- ext/tk/sample/figmemo_sample.rb | 456 +++++++++++++++ .../tkextlib/iwidgets/sample/entryfield-2.rb | 6 +- ext/tk/sample/tkextlib/tile/demo.rb | 4 +- ext/tk/sample/tkextlib/treectrl/demo.rb | 7 +- ext/tk/sample/tktextio.rb | 12 +- ext/tk/sample/ttk_wrapper.rb | 68 +-- ext/tk/tcltklib.c | 632 +++++++++++++++------ ext/tk/tkutil/extconf.rb | 1 + ext/tk/tkutil/tkutil.c | 481 +++++++++++----- 219 files changed, 6983 insertions(+), 1265 deletions(-) create mode 100644 ext/tk/sample/demos-en/combo.rb create mode 100644 ext/tk/sample/demos-en/knightstour.rb create mode 100644 ext/tk/sample/demos-en/mclist.rb create mode 100644 ext/tk/sample/demos-en/msgbox2.rb create mode 100644 ext/tk/sample/demos-en/toolbar.rb create mode 100644 ext/tk/sample/demos-en/tree.rb create mode 100644 ext/tk/sample/demos-en/ttkbut.rb create mode 100644 ext/tk/sample/demos-en/ttkmenu.rb create mode 100644 ext/tk/sample/demos-en/ttknote.rb create mode 100644 ext/tk/sample/demos-en/ttkpane.rb create mode 100644 ext/tk/sample/demos-en/ttkprogress.rb create mode 100644 ext/tk/sample/demos-jp/combo.rb create mode 100644 ext/tk/sample/demos-jp/knightstour.rb create mode 100644 ext/tk/sample/demos-jp/mclist.rb create mode 100644 ext/tk/sample/demos-jp/msgbox2.rb create mode 100644 ext/tk/sample/demos-jp/toolbar.rb create mode 100644 ext/tk/sample/demos-jp/tree.rb create mode 100644 ext/tk/sample/demos-jp/ttkbut.rb create mode 100644 ext/tk/sample/demos-jp/ttkmenu.rb create mode 100644 ext/tk/sample/demos-jp/ttknote.rb create mode 100644 ext/tk/sample/demos-jp/ttkpane.rb create mode 100644 ext/tk/sample/demos-jp/ttkprogress.rb create mode 100644 ext/tk/sample/figmemo_sample.rb (limited to 'ext') diff --git a/ext/tk/ChangeLog.tkextlib b/ext/tk/ChangeLog.tkextlib index 359b466a32..8c5d01a954 100644 --- a/ext/tk/ChangeLog.tkextlib +++ b/ext/tk/ChangeLog.tkextlib @@ -1,3 +1,9 @@ +2008-05-12 Hidetoshi NAGAI + + * ext/tk/lib/tkextlib/tkDND/shape.rb: wrong package name. + +--------------< ... some changes ... >------------------ + 2007-05-26 Hidetoshi NAGAI * ext/tk/lib/tkextlib/tcllib/tablelist.rb: fix typo. diff --git a/ext/tk/README.tcltklib b/ext/tk/README.tcltklib index b94d778104..8c6dd5178f 100644 --- a/ext/tk/README.tcltklib +++ b/ext/tk/README.tcltklib @@ -5,10 +5,14 @@ Tcl/Tk libraries or header files are installed but are not found, you can give the information by arguments of the 'configure' script. Please give some or all of the following options. + --with-tcltkversion= + force version of Tcl/Tk libaray + (e.g. libtcl8.4g.so ==> --with-tcltkversion=8.4g) + --with-tcllib= (e.g. libtcl8.4.so ==> --with-tcllib=tcl8.4) --with-tklib= (e.g. libtk8.4.so ==> --with-tklib=tk8.4) - --enable-tcltk_stubs (if you force to enable stubs) + --enable-tcltk-stubs (if you force to enable stubs) --with-tcl-dir= equal to "--with-tcl-include=/include --with-tcl-lib=/lib" diff --git a/ext/tk/extconf.rb b/ext/tk/extconf.rb index cb7621fbd4..4807ea7b40 100644 --- a/ext/tk/extconf.rb +++ b/ext/tk/extconf.rb @@ -48,15 +48,60 @@ tk_ldir2 = with_config("tk-lib") tcl_ldir2 = with_config("tcl-lib") x11_ldir2 = with_config("X11-lib") +tk_ldir_list = [tk_ldir2, tk_ldir] +tcl_ldir_list = [tcl_ldir2, tcl_ldir] + tklib = with_config("tklib") tcllib = with_config("tcllib") stubs = enable_config("tcltk_stubs") || with_config("tcltk_stubs") +tcltk_version = with_config("tcltkversion") + use_X = with_config("X11", (! is_win32)) -def find_tcl(tcllib, stubs, *opt_paths) +def check_tcltk_version(version) + return [nil, nil] unless version + + version = version.strip + + tclver = version.dup + tkver = version.dup + + major = dot = minor = dot = plvl = ext = nil + + if version =~ /^(\d)(\.?)(\d)(\.?)(\d*)(.*)$/ + major = $1; minor_dot = $2; minor = $3; plvl_dot = $4; plvl = $5; ext = $6 + dot = ! minor_dot.empty? + if plvl_dot.empty? && ! plvl.empty? + minor << plvl + end + elsif version =~ /^(\d)(\.?)(\d?)(.*)$/ + major = $1; minor_dot = $2; minor = $3; ext = $4 + dot = ! minor_dot.empty? + else # unknown -> believe user + return [tclver, tkver] + end + + # check Tcl7.6 / Tk4.2 ? + if major == "7" # Tcl7.6 ( not support Tclversion < 7.6 ) + # Tk4.2 + tkver = "4" + ((dot)? ".": "") + ((minor.empty)? "": "2") + ext + elsif major == "4" # Tk4.2 ( not support Tkversion < 4.2 ) + # Tcl7.6 + tclver = "7" + ((dot)? ".": "") + ((minor.empty)? "": "6") + ext + end + + [tclver, tkver] +end + +def find_tcl(tcllib, stubs, version, *opt_paths) default_paths = ["/usr/local/lib", "/usr/pkg/lib", "/usr/lib"] - paths = opt_paths.compact.concat(default_paths) + default_paths << "/Tcl/lib" # default for ActiveTcl + + if (paths = opt_paths.compact).empty? + paths = default_paths + end + if stubs func = "Tcl_InitStubs" lib = "tclstub" @@ -64,25 +109,42 @@ def find_tcl(tcllib, stubs, *opt_paths) func = "Tcl_FindExecutable" lib = "tcl" end + + if version && ! version.empty? + versions = [version] + else + versions = %w[8.6 8.5 8.4 8.3 8.2 8.1 8.0 7.6] + end + if tcllib - find_library(tcllib, func, *paths) + st = find_library(tcllib, func, *paths) else - %w[8.6 8.5 8.4 8.3 8.2 8.1 8.0 7.6].find { |ver| - find_library("#{lib}#{ver}", func, *paths) or - find_library("#{lib}#{ver.delete('.')}", func, *paths) or - find_library("#{lib}#{ver}g", func, *paths) or - find_library("#{lib}#{ver.delete('.')}g", func, *paths) or - find_library("tcl#{ver}", func, *paths) or - find_library("tcl#{ver.delete('.')}", func, *paths) or - find_library("tcl#{ver}g", func, *paths) or - find_library("tcl#{ver.delete('.')}g", func, *paths) - } || find_library(lib, func, *paths) + st = versions.find { |ver| + find_library("#{lib}#{ver}", func, *paths) or + find_library("#{lib}#{ver.delete('.')}", func, *paths) or + find_library("#{lib}#{ver}g", func, *paths) or + find_library("#{lib}#{ver.delete('.')}g", func, *paths) or + find_library("tcl#{ver}", func, *paths) or + find_library("tcl#{ver.delete('.')}", func, *paths) or + find_library("tcl#{ver}g", func, *paths) or + find_library("tcl#{ver.delete('.')}g", func, *paths) + } || (!version && find_library(lib, func, *paths)) + end + + unless st + puts("Warning:: cannot find Tcl library. tcltklib will not be compiled (tcltklib is disabled on your Ruby == Ruby/Tk will not work). Please check configure options.") end + st end -def find_tk(tklib, stubs, *opt_paths) +def find_tk(tklib, stubs, version, *opt_paths) default_paths = ["/usr/local/lib", "/usr/pkg/lib", "/usr/lib"] - paths = opt_paths.compact.concat(default_paths) + default_paths << "/Tcl/lib" # default for ActiveTcl + + if (paths = opt_paths.compact).empty? + paths = default_paths + end + if stubs func = "Tk_InitStubs" lib = "tkstub" @@ -90,27 +152,43 @@ def find_tk(tklib, stubs, *opt_paths) func = "Tk_Init" lib = "tk" end + + if version && ! version.empty? + versions = [version] + else + versions = %w[8.6 8.5 8.4 8.3 8.2 8.1 8.0 4.2] + end + if tklib - find_library(tklib, func, *paths) + st = find_library(tklib, func, *paths) else - %w[8.6 8.5 8.4 8.3 8.2 8.1 8.0 4.2].find { |ver| - find_library("#{lib}#{ver}", func, *paths) or - find_library("#{lib}#{ver.delete('.')}", func, *paths) or - find_library("#{lib}#{ver}g", func, *paths) or - find_library("#{lib}#{ver.delete('.')}g", func, *paths) or - find_library("tk#{ver}", func, *paths) or - find_library("tk#{ver.delete('.')}", func, *paths) or - find_library("tk#{ver}g", func, *paths) or - find_library("tk#{ver.delete('.')}g", func, *paths) - } || find_library(lib, func, *paths) + st = versions.find { |ver| + find_library("#{lib}#{ver}", func, *paths) or + find_library("#{lib}#{ver.delete('.')}", func, *paths) or + find_library("#{lib}#{ver}g", func, *paths) or + find_library("#{lib}#{ver.delete('.')}g", func, *paths) or + find_library("tk#{ver}", func, *paths) or + find_library("tk#{ver.delete('.')}", func, *paths) or + find_library("tk#{ver}g", func, *paths) or + find_library("tk#{ver.delete('.')}g", func, *paths) + } || (!version && find_library(lib, func, *paths)) end + + unless st + puts("Warning:: cannot find Tk library. tcltklib will not be compiled (tcltklib is disabled on your Ruby == Ruby/Tk will not work). Please check configure options.") + end + st end def find_X11(*opt_paths) default_paths = [ "/usr/X11/lib", "/usr/lib/X11", "/usr/X11R6/lib", "/usr/openwin/lib" ] paths = opt_paths.compact.concat(default_paths) - find_library("X11", "XOpenDisplay", *paths) + st = find_library("X11", "XOpenDisplay", *paths) + unless st + puts("Warning:: cannot find X11 library. tcltklib will not be compiled (tcltklib is disabled on your Ruby == Ruby/Tk will not work). Please check configure options. If your Tcl/Tk don't require X11, please try --without-X11.") + end + st end def pthread_check() @@ -291,11 +369,13 @@ EOF end end -if have_header("tcl.h") && have_header("tk.h") && +tclver, tkver = check_tcltk_version(tcltk_version) + +if have_header("tcl.h") && have_header("tk.h") && ( tcltk_framework || ( ( !use_X || find_X11(x11_ldir2, x11_ldir) ) && - find_tcl(tcllib, stubs, tcl_ldir2, tcl_ldir) && - find_tk(tklib, stubs, tk_ldir2, tk_ldir) ) ) + find_tcl(tcllib, stubs, tclver, *tcl_ldir_list) && + find_tk(tklib, stubs, tkver, *tk_ldir_list) ) ) $CPPFLAGS += ' -DUSE_TCL_STUBS -DUSE_TK_STUBS' if stubs $CPPFLAGS += ' -D_WIN32' if /cygwin/ =~ RUBY_PLATFORM @@ -322,6 +402,8 @@ if have_header("tcl.h") && have_header("tk.h") && $INSTALLFILES ||= [] $INSTALLFILES << ["lib/tkextlib/SUPPORT_STATUS", "$(RUBYLIBDIR)", "lib"] + have_func("rb_hash_lookup", "ruby.h") + # create $defs << %[-DRUBY_VERSION=\\"#{RUBY_VERSION}\\"] $defs << %[-DRUBY_RELEASE_DATE=\\"#{RUBY_RELEASE_DATE}\\"] diff --git a/ext/tk/lib/multi-tk.rb b/ext/tk/lib/multi-tk.rb index fd9a863888..4f39874d30 100644 --- a/ext/tk/lib/multi-tk.rb +++ b/ext/tk/lib/multi-tk.rb @@ -28,7 +28,13 @@ class << TclTkIp if Thread.current.group != ThreadGroup::Default raise SecurityError, 'only ThreadGroup::Default can call TclTkIp.new' end - __new__(*args) + obj = __new__(*args) + obj.instance_eval{ + @force_default_encoding ||= [false].taint + @encoding ||= [nil].taint + def @encoding.to_s; self.join(nil); end + } + obj end end @@ -115,7 +121,8 @@ class MultiTkIp BASE_DIR = File.dirname(__FILE__) WITH_RUBY_VM = Object.const_defined?(:VM) && ::VM.class == Class - WITH_ENCODING = Object.const_defined?(:Encoding) && ::Encoding.class == Class + WITH_ENCODING = defined?(::Encoding.default_external) + #WITH_ENCODING = Object.const_defined?(:Encoding) && ::Encoding.class == Class (@@SLAVE_IP_ID = ['slave'.freeze, '0'.taint]).instance_eval{ @mutex = Mutex.new @@ -226,8 +233,8 @@ class MultiTkIp def call(*args) unless @ip.deleted? current = Thread.current - backup_ip = current['callback_ip'] - current['callback_ip'] = @ip + backup_ip = current[:callback_ip] + current[:callback_ip] = @ip begin ret = @ip.cb_eval(@cmd, *args) fail ret if ret.kind_of?(Exception) @@ -260,7 +267,7 @@ class MultiTkIp fail e end ensure - current['callback_ip'] = backup_ip + current[:callback_ip] = backup_ip end end end @@ -753,14 +760,23 @@ class MultiTkIp current[:mutex] = mutex = Mutex.new current[:root_check] = cond_var = ConditionVariable.new + status = [nil] + def status.value + self[0] + end + def status.value=(val) + self[0] = val + end + current[:status] = status + begin - current[:status] = interp.mainloop(true) + current[:status].value = interp.mainloop(true) rescue Exception=>e - current[:status] = e + current[:status].value = e ensure mutex.synchronize{ cond_var.broadcast } end - current[:status] = interp.mainloop(false) + current[:status].value = interp.mainloop(false) } until @interp_thread[:interp] Thread.pass @@ -778,6 +794,12 @@ class MultiTkIp end end + @interp.instance_eval{ + @force_default_encoding ||= [false].taint + @encoding ||= [nil].taint + def @encoding.to_s; self.join(nil); end + } + @ip_name = nil @callback_status = [].taint @@ -951,8 +973,9 @@ class MultiTkIp begin class << subclass self.methods.each{|m| + name = m.to_s begin - unless m == '__id__' || m == '__send__' || m == 'freeze' + unless name == '__id__' || name == '__send__' || name == 'freeze' undef_method(m) end rescue Exception @@ -1157,6 +1180,11 @@ class MultiTkIp # safe interpreter ip_name = _create_slave_ip_name slave_ip = @interp.create_slave(ip_name, true) + slave_ip.instance_eval{ + @force_default_encoding ||= [false].taint + @encoding ||= [nil].taint + def @encoding.to_s; self.join(nil); end + } @slave_ip_tbl[ip_name] = slave_ip def slave_ip.safe_base? true @@ -1199,6 +1227,11 @@ class MultiTkIp ip_name = _create_slave_ip_name slave_ip = @interp.create_slave(ip_name, false) + slave_ip.instance_eval{ + @force_default_encoding ||= [false].taint + @encoding ||= [nil].taint + def @encoding.to_s; self.join(nil); end + } slave_ip._invoke('set', 'argv0', name) if name.kind_of?(String) slave_ip._invoke('set', 'argv', _keys2opts(keys)) @interp._invoke('load', '', 'Tk', ip_name) @@ -1268,9 +1301,21 @@ class MultiTkIp # create master-ip unless WITH_RUBY_VM @interp = TclTkIp.new(name, _keys2opts(tk_opts)) + @interp.instance_eval{ + @force_default_encoding ||= [false].taint + @encoding ||= [nil].taint + def @encoding.to_s; self.join(nil); end + } + else ### Ruby 1.9 !!!!!!!!!!! @interp_thread = Thread.new{ Thread.current[:interp] = interp = TclTkIp.new(name, _keys2opts(tk_opts)) + interp.instance_eval{ + @force_default_encoding ||= [false].taint + @encoding ||= [nil].taint + def @encoding.to_s; self.join(nil); end + } + #sleep TclTkLib.mainloop(true) } @@ -1400,8 +1445,8 @@ class MultiTkIp def self.__getip current = Thread.current - if TclTkLib.mainloop_thread? != false && current['callback_ip'] - return current['callback_ip'] + if TclTkLib.mainloop_thread? != false && current[:callback_ip] + return current[:callback_ip] end if current.group == ThreadGroup::Default @@DEFAULT_MASTER @@ -1993,12 +2038,12 @@ class MultiTkIp cmd = args.shift end current = Thread.current - backup_ip = current['callback_ip'] - current['callback_ip'] = self + backup_ip = current[:callback_ip] + current[:callback_ip] = self begin eval_proc_core(false, cmd, *args) ensure - current['callback_ip'] = backup_ip + current[:callback_ip] = backup_ip end end @@ -2016,8 +2061,8 @@ class MultiTkIp if TclTkLib.mainloop_thread? == true # call from eventloop current = Thread.current - backup_ip = current['callback_ip'] - current['callback_ip'] = self + backup_ip = current[:callback_ip] + current[:callback_ip] = self begin eval_proc_core(false, proc{|safe, *params| @@ -2025,7 +2070,7 @@ class MultiTkIp cmd.call(*params) }, *args) ensure - current['callback_ip'] = backup_ip + current[:callback_ip] = backup_ip end else eval_proc_core(true, @@ -2170,6 +2215,10 @@ end # event loop # all master/slave IPs are controled by only one event-loop class << MultiTkIp + def default_master? + __getip == @@DEFAULT_MASTER + end + def mainloop(check_root = true) __getip.mainloop(check_root) end @@ -2431,7 +2480,7 @@ class MultiTkIp def mainloop(check_root = true, restart_on_dead = true) raise SecurityError, "no permission to manipulate" unless self.manipulable? - unless WITH_RUBY_VM ### Ruby 1.9 !!!!!!!!!!! + if WITH_RUBY_VM ### Ruby 1.9 !!!!!!!!!!! return @interp_thread.value if @interp_thread end @@ -3289,6 +3338,42 @@ class << MultiTkIp def encoding_table __getip.encoding_table end + + def force_default_encoding=(mode) + __getip.force_default_encoding=(mode) + end + + def force_default_encoding? + __getip.force_default_encoding? + end + + def default_encoding=(enc) + __getip.default_encoding=(enc) + end + + def encoding=(enc) + __getip.encoding=(enc) + end + + def encoding_name + __getip.encoding_name + end + + def encoding_obj + __getip.encoding_obj + end + alias encoding encoding_name + alias default_encoding encoding_name + + def encoding_convertfrom(str, enc=None) + __getip.encoding_convertfrom(str, enc) + end + alias encoding_convert_from encoding_convertfrom + + def encoding_convertto(str, enc=None) + __getip.encoding_convertto(str, enc) + end + alias encoding_convert_to encoding_convertto end class MultiTkIp def encoding_table @@ -3339,6 +3424,7 @@ end # remove methods for security +=begin class MultiTkIp INTERP_THREAD = @@DEFAULT_MASTER.instance_variable_get('@interp_thread') INTERP_MUTEX = INTERP_THREAD[:mutex] @@ -3362,6 +3448,34 @@ class MultiTkIp remove_const(:INTERP_MUTEX) remove_const(:INTERP_ROOT_CHECK) end +=end +if MultiTkIp::WITH_RUBY_VM && + ! MultiTkIp::RUN_EVENTLOOP_ON_MAIN_THREAD ### check Ruby 1.9 !!!!!!! + class MultiTkIp + INTERP_THREAD = @@DEFAULT_MASTER.instance_variable_get('@interp_thread') + INTERP_THREAD_STATUS = INTERP_THREAD[:status] + INTERP_MUTEX = INTERP_THREAD[:mutex] + INTERP_ROOT_CHECK = INTERP_THREAD[:root_check] + end + module TkCore + INTERP_THREAD = MultiTkIp::INTERP_THREAD + INTERP_THREAD_STATUS = MultiTkIp::INTERP_THREAD_STATUS + INTERP_MUTEX = MultiTkIp::INTERP_MUTEX + INTERP_ROOT_CHECK = MultiTkIp::INTERP_ROOT_CHECK + end + class MultiTkIp + remove_const(:INTERP_THREAD) + remove_const(:INTERP_THREAD_STATUS) + remove_const(:INTERP_MUTEX) + remove_const(:INTERP_ROOT_CHECK) + end +end + +class MultiTkIp + # undef_method :instance_eval + undef_method :instance_variable_get + undef_method :instance_variable_set +end # end of MultiTkIp definition # defend against modification diff --git a/ext/tk/lib/remote-tk.rb b/ext/tk/lib/remote-tk.rb index 70115a60aa..f267900d53 100644 --- a/ext/tk/lib/remote-tk.rb +++ b/ext/tk/lib/remote-tk.rb @@ -88,6 +88,10 @@ class RemoteTkIp @slave_ip_tbl = {} @slave_ip_top = {} + @force_default_encoding ||= [false].taint + @encoding ||= [nil].taint + def @encoding.to_s; self.join(nil); end + @tk_windows.taint unless @tk_windows.tainted? @tk_table_list.taint unless @tk_table_list.tainted? @slave_ip_tbl.taint unless @slave_ip_tbl.tainted? diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index 0d00ecf207..88e47626f5 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -21,6 +21,17 @@ class TclTkIp # for RemoteTkIp '' end + + alias __initialize__ initialize + private :__initialize__ + + def initialize(*args) + __initialize__(*args) + + @force_default_encoding ||= [false].taint + @encoding ||= [nil].taint + def @encoding.to_s; self.join(nil); end + end end # define TkComm module (step 1: basic functions) @@ -775,7 +786,7 @@ end private :_curr_cmd_id, :_next_cmd_id module_function :_curr_cmd_id, :_next_cmd_id - def install_cmd(cmd) + def TkComm.install_cmd(cmd, local_cmdtbl=nil) return '' if cmd == '' begin ns = TkCore::INTERP._invoke_without_enc('namespace', 'current') @@ -794,6 +805,15 @@ end @cmdtbl = [] unless defined? @cmdtbl @cmdtbl.taint unless @cmdtbl.tainted? @cmdtbl.push id + + if local_cmdtbl && local_cmdtbl.kind_of?(Array) + begin + local_cmdtbl << id + rescue Exception + # ignore + end + end + #return Kernel.format("rb_out %s", id); if ns 'rb_out' << TkCore::INTERP._ip_id_ << ' ' << ns << ' ' << id @@ -801,14 +821,30 @@ end 'rb_out' << TkCore::INTERP._ip_id_ << ' ' << id end end - def uninstall_cmd(id) + def TkComm.uninstall_cmd(id, local_cmdtbl=nil) #id = $1 if /rb_out\S* (c(_\d+_)?\d+)/ =~ id id = $4 if id =~ /rb_out\S*(?:\s+(::\S*|[{](::.*)[}]|["](::.*)["]))? (c(_\d+_)?(\d+))/ + + if local_cmdtbl && local_cmdtbl.kind_of?(Array) + begin + local_cmdtbl.delete(id) + rescue Exception + # ignore + end + end + @cmdtbl.delete(id) + #Tk_CMDTBL.delete(id) TkCore::INTERP.tk_cmd_tbl.delete(id) end # private :install_cmd, :uninstall_cmd - module_function :install_cmd, :uninstall_cmd + # module_function :install_cmd, :uninstall_cmd + def install_cmd(cmd) + TkComm.install_cmd(cmd, @cmdtbl) + end + def uninstall_cmd(id) + TkComm.uninstall_cmd(id, @cmdtbl) + end =begin def install_win(ppath,name=nil) @@ -1074,7 +1110,8 @@ module TkCore extend TkComm WITH_RUBY_VM = Object.const_defined?(:VM) && ::VM.class == Class - WITH_ENCODING = Object.const_defined?(:Encoding) && ::Encoding.class == Class + WITH_ENCODING = defined?(::Encoding.default_external) + #WITH_ENCODING = Object.const_defined?(:Encoding) && ::Encoding.class == Class unless self.const_defined? :RUN_EVENTLOOP_ON_MAIN_THREAD ### Ruby 1.9 !!!!!!!!!!!!!!!!!!!!!!!!!! @@ -1110,17 +1147,26 @@ module TkCore Thread.current[:interp] = e raise e end - Thread.current[:status] = nil + + status = [nil] + def status.value + self[0] + end + def status.value=(val) + self[0] = val + end + + Thread.current[:status] = status #sleep begin - Thread.current[:status] = TclTkLib.mainloop(true) + Thread.current[:status].value = TclTkLib.mainloop(true) rescue Exception=>e - Thread.current[:status] = e + Thread.current[:status].value = e ensure INTERP_MUTEX.synchronize{ INTERP_ROOT_CHECK.broadcast } end - Thread.current[:status] = TclTkLib.mainloop(false) + Thread.current[:status].value = TclTkLib.mainloop(false) } until INTERP_THREAD[:interp] @@ -1130,11 +1176,15 @@ module TkCore raise INTERP_THREAD[:interp] if INTERP_THREAD[:interp].kind_of? Exception INTERP = INTERP_THREAD[:interp] + INTERP_THREAD_STATUS = INTERP_THREAD[:status] end def INTERP.__getip self end + def INTERP.default_master? + true + end INTERP.instance_eval{ # @tk_cmd_tbl = {}.taint @@ -1155,6 +1205,10 @@ module TkCore @init_ip_env = [].taint # table of Procs @add_tk_procs = [].taint # table of [name, args, body] + @force_default_encoding ||= [false].taint + @encoding ||= [nil].taint + def @encoding.to_s; self.join(nil); end + @cb_entry_class = Class.new(TkCallbackEntry){ class << self def inspect @@ -1273,7 +1327,7 @@ module TkCore }) << ' %W') INTERP.add_tk_procs(TclTkLib::FINALIZE_PROC_NAME, '', - "bind all <#{WIDGET_DESTROY_HOOK}> {}") + "catch { bind all <#{WIDGET_DESTROY_HOOK}> {} }") INTERP.add_tk_procs('rb_out', 'ns args', <<-'EOL') if [regexp {^::} $ns] { @@ -1441,7 +1495,9 @@ module TkCore def after(ms, cmd=Proc.new) cmdid = install_cmd(proc{ret = cmd.call;uninstall_cmd(cmdid); ret}) - tk_call_without_enc("after",ms,cmdid) # return id + after_id = tk_call_without_enc("after",ms,cmdid) + after_id.instance_variable_set('@cmdid', cmdid) + after_id end =begin def after(ms, cmd=Proc.new) @@ -1471,7 +1527,9 @@ module TkCore def after_idle(cmd=Proc.new) cmdid = install_cmd(proc{ret = cmd.call;uninstall_cmd(cmdid); ret}) - tk_call_without_enc('after','idle',cmdid) + after_id = tk_call_without_enc('after','idle',cmdid) + after_id.instance_variable_set('@cmdid', cmdid) + after_id end =begin def after_idle(cmd=Proc.new) @@ -1489,6 +1547,11 @@ module TkCore def after_cancel(afterId) tk_call_without_enc('after','cancel',afterId) + if (cmdid = afterId.instance_variable_get('@cmdid')) + afterId.instance_variable_set('@cmdid', nil) + uninstall_cmd(cmdid) + end + afterId end def windowingsystem @@ -1611,14 +1674,19 @@ module TkCore if !TkCore::WITH_RUBY_VM || TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD TclTkLib.mainloop(check_root) else ### Ruby 1.9 !!!!! + unless TkCore::INTERP.default_master? + # [MultiTkIp] slave interp ? + return TkCore::INTERP._thread_tkwait('window', '.') if check_root + end + begin TclTkLib.set_eventloop_window_mode(true) if check_root INTERP_MUTEX.synchronize{ INTERP_ROOT_CHECK.wait(INTERP_MUTEX) - status = INTERP_THREAD[:status] - if status - INTERP_THREAD[:status] = nil + status = INTERP_THREAD_STATUS.value + if status && TkCore::INTERP.default_master? + INTERP_THREAD_STATUS.value = nil if $SAFE < 4 raise status if status.kind_of?(Exception) end } @@ -2458,7 +2526,8 @@ if (/^(8\.[1-9]|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK) alias default_encoding encoding_name def tk_encoding_names - TkComm.simplelist(TkCore::INTERP._invoke_without_enc(Tk::Encoding::ENCNAMES_CMD[0], Tk::Encoding::ENCNAMES_CMD[1])) + #TkComm.simplelist(TkCore::INTERP._invoke_without_enc(Tk::Encoding::ENCNAMES_CMD[0], Tk::Encoding::ENCNAMES_CMD[1])) + TkComm.simplelist(TkCore::INTERP._invoke_without_enc('encoding', 'names')) end def encoding_names self.tk_encoding_names.find_all{|name| @@ -2592,16 +2661,16 @@ if (/^(8\.[1-9]|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK) class TclTkIp def force_default_encoding=(mode) - @force_default_encoding = (mode)? true: false + @force_default_encoding[0] = (mode)? true: false end def force_default_encoding? - @force_default_encoding ||= false + @force_default_encoding[0] ||= false end def default_encoding=(name) - name = name.name if name.kind_of?(::Encoding) if Tk::WITH_ENCODING - @encoding = name + name = name.name if Tk::WITH_ENCODING && name.kind_of?(::Encoding) + @encoding[0] = name.to_s.dup end # from tkencoding.rb by ttate@jaist.ac.jp @@ -2612,16 +2681,16 @@ if (/^(8\.[1-9]|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK) end def encoding_name - (@encoding)? @encoding.dup: nil + (@encoding[0])? @encoding[0].dup: nil end alias encoding encoding_name alias default_encoding encoding_name def encoding_obj if Tk::WITH_ENCODING - Tk::Encoding.tcl2rb_encoding(@encoding) + Tk::Encoding.tcl2rb_encoding(@encoding[0]) else - (@encoding)? @encoding.dup: nil + (@encoding[0])? @encoding[0].dup: nil end end @@ -3211,7 +3280,15 @@ module TkTreatFont next else fnt = hash_kv(fnt) if fnt.kind_of?(Hash) - tk_call(*(__config_cmd << "-#{optkey}" << fnt)) + unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ + tk_call(*(__config_cmd << "-#{optkey}" << fnt)) + else + begin + tk_call(*(__config_cmd << "-#{optkey}" << fnt)) + rescue + # ignore + end + end end end next @@ -3265,7 +3342,15 @@ module TkTreatFont fobj = fontobj # create a new TkFont object else ltn = hash_kv(ltn) if ltn.kind_of?(Hash) - tk_call(*(__config_cmd << "-#{optkey}" << ltn)) + unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ + tk_call(*(__config_cmd << "-#{optkey}" << ltn)) + else + begin + tk_call(*(__config_cmd << "-#{optkey}" << ltn)) + rescue => e + # ignore + end + end next end @@ -3317,7 +3402,15 @@ module TkTreatFont fobj = fontobj # create a new TkFont object else knj = hash_kv(knj) if knj.kind_of?(Hash) - tk_call(*(__config_cmd << "-#{optkey}" << knj)) + unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ + tk_call(*(__config_cmd << "-#{optkey}" << knj)) + else + begin + tk_call(*(__config_cmd << "-#{optkey}" << knj)) + rescue => e + # ignore + end + end next end @@ -3447,6 +3540,11 @@ module TkConfigMethod end private :__configinfo_struct + def __optkey_aliases + {} + end + private :__optkey_aliases + def __numval_optkeys [] end @@ -3561,6 +3659,11 @@ module TkConfigMethod fail ArgumentError, "Invalid option `#{orig_slot.inspect}'" end + alias_name, real_name = __optkey_aliases.find{|k, v| k.to_s == slot} + if real_name + slot = real_name.to_s + end + if ( method = _symbolkey2str(__val2ruby_optkeys())[slot] ) optval = tk_call_without_enc(*(__cget_cmd << "-#{slot}")) begin @@ -3635,14 +3738,35 @@ module TkConfigMethod unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ __cget_core(slot) else - __cget_core(slot) rescue nil + begin + __cget_core(slot) + rescue => e + if current_configinfo.has_key?(slot.to_s) + # error on known option + fail e + else + # unknown option + nil + end + end end end + def cget_strict(slot) + # never use TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ + __cget_core(slot) + end def __configure_core(slot, value=None) if slot.kind_of? Hash slot = _symbolkey2str(slot) + __optkey_aliases.each{|alias_name, real_name| + alias_name = alias_name.to_s + if slot.has_key?(alias_name) + slot[real_name.to_s] = slot.delete(alias_name) + end + } + __methodcall_optkeys.each{|key, method| value = slot.delete(key.to_s) self.__send__(method, value) if value @@ -3679,6 +3803,11 @@ module TkConfigMethod fail ArgumentError, "Invalid option `#{orig_slot.inspect}'" end + alias_name, real_name = __optkey_aliases.find{|k, v| k.to_s == slot} + if real_name + slot = real_name.to_s + end + if ( conf = __keyonly_optkeys.find{|k, v| k.to_s == slot} ) defkey, undefkey = conf if value @@ -3730,7 +3859,17 @@ module TkConfigMethod __configure_core(slot) unless slot.empty? end else - __configure_core(slot, value) rescue nil + begin + __configure_core(slot, value) + rescue => e + if current_configinfo.has_key?(slot.to_s) + # error on known option + fail e + else + # unknown option + nil + end + end end end self @@ -3766,6 +3905,12 @@ module TkConfigMethod else if slot slot = slot.to_s + + alias_name, real_name = __optkey_aliases.find{|k, v| k.to_s == slot} + if real_name + slot = real_name.to_s + end + case slot when /^(#{__val2ruby_optkeys().keys.join('|')})$/ method = _symbolkey2str(__val2ruby_optkeys())[slot] @@ -4139,6 +4284,12 @@ module TkConfigMethod else if slot slot = slot.to_s + + alias_name, real_name = __optkey_aliases.find{|k, v| k.to_s == slot} + if real_name + slot = real_name.to_s + end + case slot when /^(#{__val2ruby_optkeys().keys.join('|')})$/ method = _symbolkey2str(__val2ruby_optkeys())[slot] @@ -4734,6 +4885,13 @@ class TkWindow e tk_call_without_enc(cmd, @path) keys = __check_available_configure_options(keys) unless keys.empty? - tk_call_without_enc('destroy', @path) - tk_call_without_enc(cmd, @path, *hash_kv(keys, true)) + begin + # try to configure + configure(keys) + rescue + # fail => includes options adaptable when creattion only? + begin + tk_call_without_enc('destroy', @path) + rescue + # cannot rescue options error + fail e + else + # re-create widget + tk_call_without_enc(cmd, @path, *hash_kv(keys, true)) + end + end end end end @@ -4916,6 +5087,15 @@ class TkWindow, , ] + # the subst-key string will be converted to a bytecode (128+idx). + LONGKEY_TBL = [ + # for example, for %CTT and %CST subst-key on tkdnd-2.0 + # ['CTT', ?l, :drop_target_type], + # ['CST', ?l, :drop_source_type], + ] + # [ , ] PROC_TBL = [ [ ?n, TkComm.method(:num_or_str) ], @@ -371,6 +379,7 @@ module TkEvent nil ] +=begin # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) KEY_TBL.map!{|inf| if inf.kind_of?(Array) @@ -386,6 +395,7 @@ module TkEvent end inf } +=end # setup tables to be used by scan_args, _get_subst_key, _get_all_subst_keys # @@ -399,7 +409,8 @@ module TkEvent # ( which are Tcl strings ) to ruby objects based on the key string # that is generated by _get_subst_key() or _get_all_subst_keys(). # - _setup_subst_table(KEY_TBL, PROC_TBL); + _setup_subst_table(KEY_TBL, PROC_TBL) + # _setup_subst_table(KEY_TBL, LONGKEY_TBL, PROC_TBL) # if use longname-keys # # NOTE: The order of parameters which passed to callback procedure is @@ -447,6 +458,7 @@ module TkEvent extra_args_tbl = klass._get_extra_args_tbl if args.compact.size > 0 + args.map!{|arg| klass._sym2subst(arg)} args = args.join(' ') keys = klass._get_subst_key(args) diff --git a/ext/tk/lib/tk/font.rb b/ext/tk/lib/tk/font.rb index 4641d8a640..62d628c132 100644 --- a/ext/tk/lib/tk/font.rb +++ b/ext/tk/lib/tk/font.rb @@ -1056,7 +1056,13 @@ class TkFont keys = _symbolkey2str(args.pop).update(fontslot) args.concat(hash_kv(keys)) - tk_call(*args) + begin + tk_call(*args) + rescue => e + unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ + fail e + end + end Tk_FontUseTBL.mutex.synchronize{ Tk_FontUseTBL[[win, tag, optkey].join(';')] = self } diff --git a/ext/tk/lib/tk/grid.rb b/ext/tk/lib/tk/grid.rb index 10fdf3569b..0dfd7263a7 100644 --- a/ext/tk/lib/tk/grid.rb +++ b/ext/tk/lib/tk/grid.rb @@ -22,6 +22,7 @@ module TkGrid list(tk_call_without_enc('grid', 'bbox', *args)) end +=begin def configure(win, *args) if args[-1].kind_of?(Hash) opts = args.pop @@ -53,6 +54,48 @@ module TkGrid tk_call_without_enc('grid', 'configure', *params) end end +=end + def configure(*args) + if args[-1].kind_of?(Hash) + opts = args.pop + else + opts = {} + end + fail ArgumentError, 'no widget is given' if args.empty? + params = [] + args.flatten(1).each{|win| + case win + when '-', ?- # RELATIVE PLACEMENT (increase columnspan) + params.push('-') + when /^-+$/ # RELATIVE PLACEMENT (increase columnspan) + params.concat(win.to_s.split(//)) + when '^', ?^ # RELATIVE PLACEMENT (increase rowspan) + params.push('^') + when /^\^+$/ # RELATIVE PLACEMENT (increase rowspan) + params.concat(win.to_s.split(//)) + when 'x', :x, ?x, nil, '' # RELATIVE PLACEMENT (empty column) + params.push('x') + when /^x+$/ # RELATIVE PLACEMENT (empty column) + params.concat(win.to_s.split(//)) + else + params.push(_epath(win)) + end + } + opts.each{|k, v| + params.push("-#{k}") + params.push(_epath(v)) # have to use 'epath' (hash_kv() is unavailable) + } + if Tk::TCL_MAJOR_VERSION < 8 || + (Tk::TCL_MAJOR_VERSION == 8 && Tk::TCL_MINOR_VERSION <= 3) + if params[0] == '-' || params[0] == 'x' || params[0] == '^' + tk_call_without_enc('grid', *params) + else + tk_call_without_enc('grid', 'configure', *params) + end + else + tk_call_without_enc('grid', 'configure', *params) + end + end alias grid configure def columnconfigure(master, index, args) @@ -61,12 +104,14 @@ module TkGrid tk_call_without_enc("grid", 'columnconfigure', master, index, *hash_kv(args)) end + alias column columnconfigure def rowconfigure(master, index, args) # master = master.epath if master.kind_of?(TkObject) master = _epath(master) tk_call_without_enc("grid", 'rowconfigure', master, index, *hash_kv(args)) end + alias row rowconfigure def columnconfiginfo(master, index, slot=nil) # master = master.epath if master.kind_of?(TkObject) @@ -189,10 +234,10 @@ module TkGrid list(tk_call_without_enc('grid', 'slaves', master, *hash_kv(args))) end - module_function :bbox, :forget, :propagate, :info + module_function :anchor, :bbox, :add, :forget, :propagate, :info module_function :remove, :size, :slaves, :location module_function :grid, :configure, :columnconfigure, :rowconfigure - module_function :columnconfiginfo, :rowconfiginfo + module_function :column, :row, :columnconfiginfo, :rowconfiginfo end =begin def TkGrid(win, *args) diff --git a/ext/tk/lib/tk/image.rb b/ext/tk/lib/tk/image.rb index 57f82cb812..dffdc19644 100644 --- a/ext/tk/lib/tk/image.rb +++ b/ext/tk/lib/tk/image.rb @@ -156,7 +156,7 @@ class TkPhotoImage e + if current_configinfo.has_key?(option.to_s) + # error on known option + fail e + else + # unknown option + nil + end + end + end + end def copy(src, *opts) if opts.size == 0 diff --git a/ext/tk/lib/tk/itemconfig.rb b/ext/tk/lib/tk/itemconfig.rb index dbc45a9e7c..9c6a98d0f8 100644 --- a/ext/tk/lib/tk/itemconfig.rb +++ b/ext/tk/lib/tk/itemconfig.rb @@ -8,6 +8,11 @@ require 'tk/itemfont.rb' module TkItemConfigOptkeys include TkUtil + def __item_optkey_aliases(id) + {} + end + private :__item_optkey_aliases + def __item_numval_optkeys(id) [] end @@ -165,6 +170,11 @@ module TkItemConfigMethod fail ArgumentError, "Invalid option `#{orig_opt.inspect}'" end + alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == option} + if real_name + option = real_name.to_s + end + if ( method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[option] ) optval = tk_call_without_enc(*(__item_cget_cmd(tagid(tagOrId)) << "-#{option}")) begin @@ -242,20 +252,35 @@ module TkItemConfigMethod __itemcget_core(tagOrId, option) rescue => e begin - __itemconfiginfo_core(tagOrId) - # not tag error -> option is unknown - nil + if __current_itemconfiginfo(tagOrId).has_key?(option.to_s) + # not tag error & option is known -> error on known option + fail e + else + # not tag error & option is unknown + nil + end rescue fail e # tag error end end end end + def itemcget_strict(tagOrId, option) + # never use TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ + __itemcget_core(tagOrId, option) + end def __itemconfigure_core(tagOrId, slot, value=None) if slot.kind_of? Hash slot = _symbolkey2str(slot) + __item_optkey_aliases(tagid(tagOrId)).each{|alias_name, real_name| + alias_name = alias_name.to_s + if slot.has_key?(alias_name) + slot[real_name.to_s] = slot.delete(alias_name) + end + } + __item_methodcall_optkeys(tagid(tagOrId)).each{|key, method| value = slot.delete(key.to_s) self.__send__(method, tagOrId, value) if value @@ -292,6 +317,11 @@ module TkItemConfigMethod fail ArgumentError, "Invalid option `#{orig_slot.inspect}'" end + alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot} + if real_name + slot = real_name.to_s + end + if ( conf = __item_keyonly_optkeys(tagid(tagOrId)).find{|k, v| k.to_s == slot } ) defkey, undefkey = conf if value @@ -319,7 +349,8 @@ module TkItemConfigMethod def __check_available_itemconfigure_options(tagOrId, keys) id = tagid(tagOrId) - availables = self.current_itemconfiginfo(id).keys + + availables = self.__current_itemconfiginfo(id).keys # add non-standard keys availables |= __font_optkeys.map{|k| @@ -329,6 +360,7 @@ module TkItemConfigMethod availables |= __item_keyonly_optkeys(id).keys.map{|k| k.to_s} keys = _symbolkey2str(keys) + keys.delete_if{|k, v| !(availables.include?(k))} end @@ -340,7 +372,7 @@ module TkItemConfigMethod begin __itemconfigure_core(tagOrId, slot) rescue - slot = __check_available_configure_options(tagOrId, slot) + slot = __check_available_itemconfigure_options(tagOrId, slot) __itemconfigure_core(tagOrId, slot) unless slot.empty? end else @@ -348,7 +380,13 @@ module TkItemConfigMethod __itemconfigure_core(tagOrId, slot, value) rescue => e begin - __itemconfiginfo_core(tagOrId) + if __current_itemconfiginfo(tagOrId).has_key?(slot.to_s) + # not tag error & option is known -> error on known option + fail e + else + # not tag error & option is unknown + nil + end rescue fail e # tag error end @@ -383,6 +421,12 @@ module TkItemConfigMethod else if slot slot = slot.to_s + + alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot} + if real_name + slot = real_name.to_s + end + case slot when /^(#{__item_val2ruby_optkeys(tagid(tagOrId)).keys.join('|')})$/ method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[slot] @@ -754,6 +798,12 @@ module TkItemConfigMethod else if slot slot = slot.to_s + + alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot} + if real_name + slot = real_name.to_s + end + case slot when /^(#{__item_val2ruby_optkeys(tagid(tagOrId)).keys.join('|')})$/ method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[slot] @@ -1125,7 +1175,7 @@ module TkItemConfigMethod end end - def current_itemconfiginfo(tagOrId, slot = nil) + def __current_itemconfiginfo(tagOrId, slot = nil) if TkComm::GET_CONFIGINFO_AS_ARRAY if slot org_slot = slot @@ -1147,6 +1197,7 @@ module TkItemConfigMethod ret[conf[0]] = conf[-1] end } + ret end else # ! TkComm::GET_CONFIGINFO_AS_ARRAY @@ -1157,4 +1208,8 @@ module TkItemConfigMethod ret end end + + def current_itemconfiginfo(tagOrId, slot = nil) + __current_itemconfiginfo(tagOrId, slot) + end end diff --git a/ext/tk/lib/tk/itemfont.rb b/ext/tk/lib/tk/itemfont.rb index ab9e3ff6c9..4c5c917c57 100644 --- a/ext/tk/lib/tk/itemfont.rb +++ b/ext/tk/lib/tk/itemfont.rb @@ -94,7 +94,16 @@ module TkTreatItemFont *(__item_config_cmd(tagid(tagOrId)) << {})) next else - tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << fnt)) + fnt = hash_kv(fnt) if fnt.kind_of?(Hash) + unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ + tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << fnt)) + else + begin + tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << fnt)) + rescue => e + # ignore + end + end end end next @@ -147,7 +156,16 @@ module TkTreatItemFont elsif Tk::JAPANIZED_TK fobj = fontobj # create a new TkFont object else - tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << ltn)) + ltn = hash_kv(ltn) if ltn.kind_of?(Hash) + unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ + tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << ltn)) + else + begin + tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << ltn)) + rescue => e + # ignore + end + end next end @@ -198,7 +216,16 @@ module TkTreatItemFont elsif Tk::JAPANIZED_TK fobj = fontobj # create a new TkFont object else - tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << knj)) + knj = hash_kv(knj) if knj.kind_of?(Hash) + unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ + tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << knj)) + else + begin + tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << knj)) + rescue => e + # ignore + end + end next end diff --git a/ext/tk/lib/tk/menu.rb b/ext/tk/lib/tk/menu.rb index 8ba3156293..3ae0548dd1 100644 --- a/ext/tk/lib/tk/menu.rb +++ b/ext/tk/lib/tk/menu.rb @@ -34,12 +34,13 @@ module TkMenuEntryConfig private :__item_val2ruby_optkeys alias entrycget itemcget + alias entrycget_strict itemcget_strict alias entryconfigure itemconfigure alias entryconfiginfo itemconfiginfo alias current_entryconfiginfo current_itemconfiginfo - private :itemcget, :itemconfigure - private :itemconfiginfo, :current_itemconfiginfo + private :itemcget, :itemcget_strict + private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo end class Tk::Menu use current TkMenu class mbar = parent.menu - unless parent.menu.kind_of?(Tk::Menu) || parent.menu.kind_of?(TkMenu) + unless mbar.kind_of?(Tk::Menu) || mbar.kind_of?(TkMenu) #mbar = Tk::Menu.new(parent, :tearoff=>false) mbar = TkMenu.new(parent, :tearoff=>false) parent.menu(mbar) @@ -198,7 +195,6 @@ module TkMenuSpec if _use_menubar?(parent) # menubar by menu entries - mbar = _create_menu_for_menubar(parent) menu_name = nil diff --git a/ext/tk/lib/tk/namespace.rb b/ext/tk/lib/tk/namespace.rb index 9d2213ff51..20a8d65215 100644 --- a/ext/tk/lib/tk/namespace.rb +++ b/ext/tk/lib/tk/namespace.rb @@ -83,6 +83,20 @@ class TkNamespace < TkObject super(slot) end end + def cget_strict(slot) + if slot == :namespace || slot == 'namespace' + ns = super(slot) + Tk_Namespace_ID_TBL.mutex.synchronize{ + if TkNamespace::Tk_Namespace_ID_TBL.key?(ns) + TkNamespace::Tk_Namespace_ID_TBL[ns] + else + ns + end + } + else + super(slot) + end + end def configinfo(slot = nil) if slot diff --git a/ext/tk/lib/tk/pack.rb b/ext/tk/lib/tk/pack.rb index 8fab363121..220a38e524 100644 --- a/ext/tk/lib/tk/pack.rb +++ b/ext/tk/lib/tk/pack.rb @@ -9,6 +9,7 @@ module TkPack TkCommandNames = ['pack'.freeze].freeze +=begin def configure(win, *args) if args[-1].kind_of?(Hash) opts = args.pop @@ -29,6 +30,22 @@ module TkPack } tk_call_without_enc("pack", 'configure', *params) end +=end + def configure(*args) + if args[-1].kind_of?(Hash) + opts = args.pop + else + opts = {} + end + fail ArgumentError, 'no widget is given' if args.empty? + params = [] + args.flatten(1).each{|win| params.push(_epath(win))} + opts.each{|k, v| + params.push("-#{k}") + params.push(_epath(v)) # have to use 'epath' (hash_kv() is unavailable) + } + tk_call_without_enc("pack", 'configure', *params) + end alias pack configure def forget(*args) diff --git a/ext/tk/lib/tk/palette.rb b/ext/tk/lib/tk/palette.rb index 2b6fdf5d90..2d08d50f6a 100644 --- a/ext/tk/lib/tk/palette.rb +++ b/ext/tk/lib/tk/palette.rb @@ -15,7 +15,7 @@ module TkPalette ].freeze def TkPalette.set(*args) - args = args.to_a.flatten if args.kind_of? Hash + args = args[0].to_a.flatten if args[0].kind_of? Hash tk_call('tk_setPalette', *args) end def TkPalette.setPalette(*args) diff --git a/ext/tk/lib/tk/panedwindow.rb b/ext/tk/lib/tk/panedwindow.rb index ba8a7e9743..030144e677 100644 --- a/ext/tk/lib/tk/panedwindow.rb +++ b/ext/tk/lib/tk/panedwindow.rb @@ -76,11 +76,32 @@ class Tk::PanedWindow e + begin + if current_paneconfiginfo(win).has_key?(option.to_s) + # not tag error & option is known -> error on known option + fail e + else + # not tag error & option is unknown + nil + end + rescue + fail e # tag error + end + end + end + end def paneconfigure(win, key, value=nil) # win = win.epath if win.kind_of?(TkObject) diff --git a/ext/tk/lib/tk/scale.rb b/ext/tk/lib/tk/scale.rb index bf2791ec55..7e758d92f4 100644 --- a/ext/tk/lib/tk/scale.rb +++ b/ext/tk/lib/tk/scale.rb @@ -26,9 +26,16 @@ class Tk::Scale String --> char-code ( getbyte(0) ) KEY_TBL.map!{|inf| if inf.kind_of?(Array) @@ -52,6 +53,7 @@ class Tk::Spinbox e + begin + if current_image_configinfo(index).has_key?(slot.to_s) + # not tag error & option is known -> error on known option + fail e + else + # not tag error & option is unknown + nil + end + rescue + fail e # tag error + end + end + end + end + def image_configure(index, slot, value=None) if slot.kind_of?(Hash) _fromUTF8(tk_send_without_enc('image', 'configure', diff --git a/ext/tk/lib/tk/textimage.rb b/ext/tk/lib/tk/textimage.rb index d4c973213d..fb306a9c17 100644 --- a/ext/tk/lib/tk/textimage.rb +++ b/ext/tk/lib/tk/textimage.rb @@ -52,6 +52,10 @@ class TkTextImage= @proc_max @@ -120,7 +121,8 @@ class TkTimer else Tk_CBTBL.delete(@id) ;# for GC @running = false - @wait_var.value = 0 + # @wait_var.value = 0 + __at_end__ return end end @@ -151,6 +153,8 @@ class TkTimer @wait_var = TkVariable.new(0) + @at_end_proc = nil + @cb_cmd = TkCore::INTERP.get_cb_entry(self.method(:do_callback)) @set_next = true @@ -210,6 +214,12 @@ class TkTimer attr_accessor :loop_exec + def __at_end__ + @at_end_proc.call(self) if @at_end_proc + @wait_var.value = 0 # for wait + end + private :__at_end__ + def cb_call @cb_cmd.call end @@ -427,7 +437,8 @@ class TkTimer def cancel @running = false - @wait_var.value = 0 + # @wait_var.value = 0 + __at_end__ tk_call 'after', 'cancel', @after_id if @after_id @after_id = nil @@ -471,6 +482,21 @@ class TkTimer end end + def at_end(*arg, &b) + if arg.empty? + if b + @at_end_proc = b + else + # no proc + return @at_end_proc + end + else + fail ArgumentError, "wrong number of arguments" if arg.length != 1 || b + @at_end_proc = arg[0] + end + self + end + def wait(on_thread = true, check_root = false) if $SAFE >= 4 fail SecurityError, "can't wait timer at $SAFE >= 4" @@ -569,7 +595,8 @@ class TkRTTimer < TkTimer if @running == false || @proc_max == 0 || @do_loop == 0 Tk_CBTBL.delete(@id) ;# for GC @running = false - @wait_var.value = 0 + # @wait_var.value = 0 + __at_end__ return end if @current_pos >= @proc_max @@ -578,7 +605,8 @@ class TkRTTimer < TkTimer else Tk_CBTBL.delete(@id) ;# for GC @running = false - @wait_var.value = 0 + # @wait_var.value = 0 + __at_end__ return end end diff --git a/ext/tk/lib/tk/toplevel.rb b/ext/tk/lib/tk/toplevel.rb index 2d99eda44c..bd6e8307f5 100644 --- a/ext/tk/lib/tk/toplevel.rb +++ b/ext/tk/lib/tk/toplevel.rb @@ -72,7 +72,7 @@ class Tk::Toplevel String --> char-code ( getbyte(0) ) KEY_TBL.map!{|inf| if inf.kind_of?(Array) @@ -264,6 +267,7 @@ class TkValidateCommand end inf } +=end _setup_subst_table(KEY_TBL, PROC_TBL); @@ -293,6 +297,7 @@ class TkValidateCommand extra_args_tbl = klass._get_extra_args_tbl if args.compact.size > 0 + args.map!{|arg| klass._sym2subst(arg)} args = args.join(' ') keys = klass._get_subst_key(args) if cmd.kind_of?(String) diff --git a/ext/tk/lib/tk/wm.rb b/ext/tk/lib/tk/wm.rb index 49dd4d73c2..0394296189 100644 --- a/ext/tk/lib/tk/wm.rb +++ b/ext/tk/lib/tk/wm.rb @@ -362,7 +362,7 @@ module Tk end end def overrideredirect(mode=TkComm::None) - Wm.overrideredirect(self, mode=TkComm::None) + Wm.overrideredirect(self, mode) end alias wm_overrideredirect overrideredirect TOPLEVEL_METHODCALL_OPTKEYS['overrideredirect'] = 'overrideredirect' @@ -545,7 +545,7 @@ module Tk module Wm_for_General Wm.instance_methods.each{|m| if (m = m.to_s) =~ /^wm_(.*)$/ - eval "def #{m}(*args); Tk::Wm.#{$1}(self, *args); end" + eval "def #{m}(*args, &b); Tk::Wm.#{$1}(self, *args, &b); end" end } end diff --git a/ext/tk/lib/tkextlib/blt/component.rb b/ext/tk/lib/tkextlib/blt/component.rb index dd387634ee..b2005b2f2b 100644 --- a/ext/tk/lib/tkextlib/blt/component.rb +++ b/ext/tk/lib/tkextlib/blt/component.rb @@ -85,6 +85,9 @@ module Tk::BLT def axis_cget(id, option) ret = itemcget(['axis', tagid(id)], option) end + def axis_cget_strict(id, option) + ret = itemcget_strict(['axis', tagid(id)], option) + end def axis_configure(*args) slot = args.pop if slot.kind_of?(Hash) @@ -118,6 +121,9 @@ module Tk::BLT def crosshairs_cget(option) itemcget('crosshairs', option) end + def crosshairs_cget_strict(option) + itemcget_strict('crosshairs', option) + end def crosshairs_configure(slot, value=None) itemconfigure('crosshairs', slot, value) end @@ -131,6 +137,9 @@ module Tk::BLT def element_cget(id, option) itemcget(['element', tagid(id)], option) end + def element_cget_strict(id, option) + itemcget_strict(['element', tagid(id)], option) + end def element_configure(*args) slot = args.pop if slot.kind_of?(Hash) @@ -152,6 +161,9 @@ module Tk::BLT def bar_cget(id, option) itemcget(['bar', tagid(id)], option) end + def bar_cget_strict(id, option) + itemcget_strict(['bar', tagid(id)], option) + end def bar_configure(*args) slot = args.pop if slot.kind_of?(Hash) @@ -173,6 +185,9 @@ module Tk::BLT def line_cget(id, option) itemcget(['line', tagid(id)], option) end + def line_cget_strict(id, option) + itemcget_strict(['line', tagid(id)], option) + end def line_configure(*args) slot = args.pop if slot.kind_of?(Hash) @@ -194,6 +209,9 @@ module Tk::BLT def gridline_cget(option) itemcget('grid', option) end + def gridline_cget_strict(option) + itemcget_strict('grid', option) + end def gridline_configure(slot, value=None) itemconfigure('grid', slot, value) end @@ -207,6 +225,9 @@ module Tk::BLT def legend_cget(option) itemcget('legend', option) end + def legend_cget_strict(option) + itemcget_strict('legend', option) + end def legend_configure(slot, value=None) itemconfigure('legend', slot, value) end @@ -220,6 +241,9 @@ module Tk::BLT def pen_cget(id, option) itemcget(['pen', tagid(id)], option) end + def pen_cget_strict(id, option) + itemcget_strict(['pen', tagid(id)], option) + end def pen_configure(*args) slot = args.pop if slot.kind_of?(Hash) @@ -241,6 +265,9 @@ module Tk::BLT def postscript_cget(option) itemcget('postscript', option) end + def postscript_cget_strict(option) + itemcget_strict('postscript', option) + end def postscript_configure(slot, value=None) itemconfigure('postscript', slot, value) end @@ -254,6 +281,9 @@ module Tk::BLT def marker_cget(id, option) itemcget(['marker', tagid(id)], option) end + def marker_cget_strict(id, option) + itemcget_strict(['marker', tagid(id)], option) + end def marker_configure(*args) slot = args.pop if slot.kind_of?(Hash) @@ -273,11 +303,12 @@ module Tk::BLT end alias __itemcget itemcget + alias __itemcget_strict itemcget_strict alias __itemconfiginfo itemconfiginfo alias __current_itemconfiginfo current_itemconfiginfo private :__itemcget, :__itemconfiginfo, :__current_itemconfiginfo - def itemcget(tagOrId, option) + def itemcget_strict(tagOrId, option) ret = __itemcget(tagid(tagOrId), option) if option == 'bindtags' || option == :bindtags ret.collect{|tag| TkBindTag.id2obj(tag)} @@ -285,6 +316,27 @@ module Tk::BLT ret end end + def itemcget(tagOrId, option) + unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ + itemcget_strict(tagOrId, option) + else + begin + itemcget_strict(tagOrId, option) + rescue => e + begin + if current_itemconfiginfo(tagOrId).has_key?(option.to_s) + # error on known option + fail e + else + # unknown option + nil + end + rescue + fail e # tag error + end + end + end + end def itemconfiginfo(tagOrId, slot = nil) ret = __itemconfiginfo(tagid(tagOrId), slot) @@ -321,8 +373,8 @@ module Tk::BLT ret end - private :itemcget, :itemconfigure - private :itemconfiginfo, :current_itemconfiginfo + private :itemcget, :itemcget_strict + private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo ################# @@ -428,6 +480,9 @@ module Tk::BLT def cget(option) @chart.axis_cget(@id, option) end + def cget_strict(option) + @chart.axis_cget_strict(@id, option) + end def configure(key, value=None) @chart.axis_configure(@id, key, value) self @@ -530,6 +585,9 @@ module Tk::BLT def cget(option) @chart.crosshair_cget(option) end + def cget_strict(option) + @chart.crosshair_cget_strict(option) + end def configure(key, value=None) @chart.crosshair_configure(key, value) self @@ -675,6 +733,9 @@ module Tk::BLT # @chart.element_cget(@id, option) @chart.__send__(@typename + '_cget', @id, option) end + def cget_strict(option) + @chart.__send__(@typename + '_cget_strict', @id, option) + end def configure(key, value=None) # @chart.element_configure(@id, key, value) @chart.__send__(@typename + '_configure', @id, key, value) @@ -775,6 +836,9 @@ module Tk::BLT def cget(option) @chart.gridline_cget(option) end + def cget_strict(option) + @chart.gridline_cget_strict(option) + end def configure(key, value=None) @chart.gridline_configure(key, value) self @@ -846,6 +910,9 @@ module Tk::BLT def cget(option) @chart.legend_cget(option) end + def cget_strict(option) + @chart.legend_cget_strict(option) + end def configure(key, value=None) @chart.legend_configure(key, value) self @@ -972,6 +1039,9 @@ module Tk::BLT def cget(option) @chart.pen_cget(@id, option) end + def cget_strict(option) + @chart.pen_cget_strict(@id, option) + end def configure(key, value=None) @chart.pen_configure(@id, key, value) self @@ -1039,6 +1109,9 @@ module Tk::BLT def cget(option) @chart.postscript_cget(option) end + def cget_strict(option) + @chart.postscript_cget_strict(option) + end def configure(key, value=None) @chart.postscript_configure(key, value) self @@ -1117,6 +1190,13 @@ module Tk::BLT fontkeys[fkey] = keys.delete(fkey) if keys.key?(fkey) } + __item_optkey_aliases(nil).each{|alias_name, real_name| + alias_name = alias_name.to_s + if keys.has_key?(alias_name) + keys[real_name.to_s] = keys.delete(alias_name) + end + } + __item_methodcall_optkeys(nil).each{|key| key = key.to_s methodkeys[key] = keys.delete(key) if keys.key?(key) @@ -1192,6 +1272,9 @@ module Tk::BLT def cget(option) @chart.marker_cget(@id, option) end + def cget_strict(option) + @chart.marker_cget_strict(@id, option) + end def configure(key, value=None) @chart.marker_configure(@id, key, value) self @@ -1774,6 +1857,9 @@ module Tk::BLT def xaxis_cget(option) itemcget('xaxis', option) end + def xaxis_cget_strict(option) + itemcget_strict('xaxis', option) + end def xaxis_configure(slot, value=None) if slot.kind_of?(Hash) slot = _symbolkey2str(slot) @@ -1843,6 +1929,9 @@ module Tk::BLT def x2axis_cget(option) itemcget('x2axis', option) end + def x2axis_cget_strict(option) + itemcget_strict('x2axis', option) + end def x2axis_configure(slot, value=None) if slot.kind_of?(Hash) slot = _symbolkey2str(slot) @@ -1912,6 +2001,9 @@ module Tk::BLT def yaxis_cget(option) itemcget('yaxis', option) end + def yaxis_cget_strict(option) + itemcget_strict('yaxis', option) + end def yaxis_configure(slot, value=None) if slot.kind_of?(Hash) slot = _symbolkey2str(slot) @@ -1981,6 +2073,9 @@ module Tk::BLT def y2axis_cget(option) itemcget('y2axis', option) end + def y2axis_cget_strict(option) + itemcget_strict('y2axis', option) + end def y2axis_configure(slot, value=None) if slot.kind_of?(Hash) slot = _symbolkey2str(slot) diff --git a/ext/tk/lib/tkextlib/blt/dragdrop.rb b/ext/tk/lib/tkextlib/blt/dragdrop.rb index 98b1a4832f..201548504a 100644 --- a/ext/tk/lib/tkextlib/blt/dragdrop.rb +++ b/ext/tk/lib/tkextlib/blt/dragdrop.rb @@ -81,6 +81,7 @@ module Tk::BLT nil ] +=begin # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) KEY_TBL.map!{|inf| if inf.kind_of?(Array) @@ -96,6 +97,7 @@ module Tk::BLT end inf } +=end _setup_subst_table(KEY_TBL, PROC_TBL) @@ -123,6 +125,7 @@ module Tk::BLT nil ] +=begin # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) KEY_TBL.map!{|inf| if inf.kind_of?(Array) @@ -138,6 +141,7 @@ module Tk::BLT end inf } +=end _setup_subst_table(KEY_TBL, PROC_TBL) @@ -177,6 +181,7 @@ module Tk::BLT nil ] +=begin # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) KEY_TBL.map!{|inf| if inf.kind_of?(Array) @@ -192,6 +197,7 @@ module Tk::BLT end inf } +=end _setup_subst_table(KEY_TBL, PROC_TBL) end diff --git a/ext/tk/lib/tkextlib/blt/htext.rb b/ext/tk/lib/tkextlib/blt/htext.rb index a0cf3dc036..0d9cb30185 100644 --- a/ext/tk/lib/tkextlib/blt/htext.rb +++ b/ext/tk/lib/tkextlib/blt/htext.rb @@ -22,6 +22,7 @@ module Tk::BLT WidgetClassNames[WidgetClassName] = self alias window_cget itemcget + alias window_cget_strict itemcget_strict alias window_configure itemconfigure alias window_configuinfo itemconfiginfo alias current_window_configuinfo current_itemconfiginfo diff --git a/ext/tk/lib/tkextlib/blt/table.rb b/ext/tk/lib/tkextlib/blt/table.rb index 0be9d8d42a..dfa10269ed 100644 --- a/ext/tk/lib/tkextlib/blt/table.rb +++ b/ext/tk/lib/tkextlib/blt/table.rb @@ -29,6 +29,9 @@ module Tk::BLT def blt_table_cget(*args) Tk::BLT::Table.cget(self, *args) end + def blt_table_cget_strict(*args) + Tk::BLT::Table.cget_strict(self, *args) + end def blt_table_configure(*args) Tk::BLT::Table.configure(self, *args) @@ -92,6 +95,9 @@ module Tk::BLT def blt_table_itemcget(*args) Tk::BLT::Table.itemcget(self, *args) end + def blt_table_itemcget_strict(*args) + Tk::BLT::Table.itemcget_strict(self, *args) + end def blt_table_itemconfigure(*args) Tk::BLT::Table.itemconfigure(self, *args) @@ -136,12 +142,13 @@ class << Tk::BLT::Table private :__item_pathname alias __itemcget itemcget + alias __itemcget_strict itemcget_strict alias __itemconfigure itemconfigure alias __itemconfiginfo itemconfiginfo alias __current_itemconfiginfo current_itemconfiginfo - private :__itemcget, :__itemconfigure - private :__itemconfiginfo, :__current_itemconfiginfo + private :__itemcget, :__itemcget_strict + private :__itemconfigure, :__itemconfiginfo, :__current_itemconfiginfo def __boolval_optkeys super() << 'propagate' @@ -176,6 +183,9 @@ class << Tk::BLT::Table def cget(container, option) __itemcget([container], option) end + def cget_strict(container, option) + __itemcget_strict([container], option) + end def configure(container, *args) __itemconfigure([container], *args) @@ -192,6 +202,9 @@ class << Tk::BLT::Table def itemcget(container, item, option) __itemcget([container, tagid(item)], option) end + def itemcget_strict(container, item, option) + __itemcget_strict([container, tagid(item)], option) + end def itemconfigure(container, *args) if args[-1].kind_of?(Hash) diff --git a/ext/tk/lib/tkextlib/blt/tabset.rb b/ext/tk/lib/tkextlib/blt/tabset.rb index 1a0f312c4c..ca81ad8f95 100644 --- a/ext/tk/lib/tkextlib/blt/tabset.rb +++ b/ext/tk/lib/tkextlib/blt/tabset.rb @@ -128,6 +128,9 @@ module Tk::BLT def cget(*args) @t.tab_cget(@id, *args) end + def cget_strict(*args) + @t.tab_cget_strict(@id, *args) + end def configure(*args) @t.tab_configure(@id, *args) end @@ -240,6 +243,7 @@ module Tk::BLT private :__item_pathname alias tab_cget itemcget + alias tab_cget_strict itemcget_strict alias tab_configure itemconfigure alias tab_configinfo itemconfiginfo alias current_tab_configinfo current_itemconfiginfo diff --git a/ext/tk/lib/tkextlib/blt/ted.rb b/ext/tk/lib/tkextlib/blt/ted.rb index 39495842b4..670265fc78 100644 --- a/ext/tk/lib/tkextlib/blt/ted.rb +++ b/ext/tk/lib/tkextlib/blt/ted.rb @@ -30,11 +30,14 @@ module Tk::BLT end private :__item_config_cmd - private :itemcget, :itemconfigure - private :itemconfiginfo, :current_itemconfiginfo + private :itemcget, :itemcget_strict + private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo def cget(master, option) - itemconfigure(master, slot, value) + itemcget(master, option) + end + def cget_strict(master, option) + itemcget_strict(master, option) end def configure(master, slot, value=None) itemconfigure(master, slot, value) diff --git a/ext/tk/lib/tkextlib/blt/treeview.rb b/ext/tk/lib/tkextlib/blt/treeview.rb index fc890614be..c5a5697186 100644 --- a/ext/tk/lib/tkextlib/blt/treeview.rb +++ b/ext/tk/lib/tkextlib/blt/treeview.rb @@ -98,6 +98,9 @@ module Tk::BLT::Treeview::ConfigMethod def column_cget(name, option) itemcget(['column', name], option) end + def column_cget_strict(name, option) + itemcget_strict(['column', name], option) + end def column_configure(name, slot, value=None) itemconfigure(['column', name], slot, value) end @@ -111,6 +114,9 @@ module Tk::BLT::Treeview::ConfigMethod def button_cget(option) itemcget('button', option) end + def button_cget_strict(option) + itemcget_strict('button', option) + end def button_configure(slot, value=None) itemconfigure('button', slot, value) end @@ -129,6 +135,14 @@ module Tk::BLT::Treeview::ConfigMethod ret end end + def entry_cget_strict(option) + ret = itemcget_strict('entry', option) + if option == 'bindtags' || option == :bindtags + ret.collect{|tag| TkBindTag.id2obj(tag)} + else + ret + end + end def entry_configure(slot, value=None) itemconfigure('entry', slot, value) end @@ -170,6 +184,9 @@ module Tk::BLT::Treeview::ConfigMethod def sort_cget(option) itemcget('sort', option) end + def sort_cget_strict(option) + itemcget_strict('sort', option) + end def sort_configure(slot, value=None) itemconfigure('sort', slot, value) end @@ -183,6 +200,9 @@ module Tk::BLT::Treeview::ConfigMethod def text_cget(option) itemcget('text', option) end + def text_cget_strict(option) + itemcget_strict('text', option) + end def text_configure(slot, value=None) itemconfigure('text', slot, value) end @@ -193,8 +213,8 @@ module Tk::BLT::Treeview::ConfigMethod current_itemconfiginfo('text', slot) end - private :itemcget, :itemconfigure - private :itemconfiginfo, :current_itemconfiginfo + private :itemcget, :itemcget_strict + private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo end class Tk::BLT::Treeview @@ -239,6 +259,7 @@ class Tk::BLT::Treeview nil ] +=begin # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) KEY_TBL.map!{|inf| if inf.kind_of?(Array) @@ -254,6 +275,7 @@ class Tk::BLT::Treeview end inf } +=end _setup_subst_table(KEY_TBL, PROC_TBL); @@ -492,6 +514,7 @@ class Tk::BLT::Treeview nil ] +=begin # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) KEY_TBL.map!{|inf| if inf.kind_of?(Array) @@ -507,6 +530,7 @@ class Tk::BLT::Treeview end inf } +=end _setup_subst_table(KEY_TBL, PROC_TBL); @@ -523,7 +547,8 @@ class Tk::BLT::Treeview def _find_exec_flag_value(val) if val.kind_of?(Array) cmd, *args = val - FindExecFlagValue.new(cmd, args.join(' ')) + #FindExecFlagValue.new(cmd, args.join(' ')) + FindExecFlagValue.new(cmd, *args) elsif TkComm._callback_entry?(val) FindExecFlagValue.new(val) else diff --git a/ext/tk/lib/tkextlib/blt/unix_dnd.rb b/ext/tk/lib/tkextlib/blt/unix_dnd.rb index 3130c1e56f..445002d7a5 100644 --- a/ext/tk/lib/tkextlib/blt/unix_dnd.rb +++ b/ext/tk/lib/tkextlib/blt/unix_dnd.rb @@ -30,11 +30,14 @@ module Tk::BLT end private :__item_config_cmd - private :itemcget, :itemconfigure - private :itemconfiginfo, :current_itemconfiginfo + private :itemcget, :itemcget_strict + private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo def cget(win, option) - itemconfigure(['cget', win], slot, value) + itemcget(['cget', win], option) + end + def cget_strict(win, option) + itemcget_strict(['cget', win], option) end def configure(win, slot, value=None) itemconfigure(['configure', win], slot, value) @@ -46,8 +49,11 @@ module Tk::BLT current_itemconfiginfo(['configure', win], slot) end - def tokwn_cget(win, option) - itemconfigure(['token', 'cget', win], slot, value) + def token_cget(win, option) + itemcget(['token', 'cget', win], option) + end + def token_cget_strict(win, option) + itemcget_strict(['token', 'cget', win], option) end def token_configure(win, slot, value=None) itemconfigure(['token', 'configure', win], slot, value) diff --git a/ext/tk/lib/tkextlib/blt/watch.rb b/ext/tk/lib/tkextlib/blt/watch.rb index 2daf417e0b..219ff78e97 100644 --- a/ext/tk/lib/tkextlib/blt/watch.rb +++ b/ext/tk/lib/tkextlib/blt/watch.rb @@ -146,7 +146,7 @@ module Tk::BLT end end end - def cget(key) + def cget_strict(key) key = key.to_s begin info.assoc(key)[1] @@ -154,5 +154,22 @@ module Tk::BLT fail ArgumentError, "unknown option '#{key}'" end end + def cget(key) + unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ + cget_strict(key) + else + begin + cget_strict(key) + rescue => e + if current_configinfo.has_key?(key.to_s) + # error on known option + fail e + else + # unknown option + nil + end + end + end + end end end diff --git a/ext/tk/lib/tkextlib/bwidget/dialog.rb b/ext/tk/lib/tkextlib/bwidget/dialog.rb index 0ddee21d05..291ca4a962 100644 --- a/ext/tk/lib/tkextlib/bwidget/dialog.rb +++ b/ext/tk/lib/tkextlib/bwidget/dialog.rb @@ -59,6 +59,13 @@ class Tk::BWidget::Dialog end end + def cget_strict(slot) + if slot.to_s == 'relative' + super('parent') + else + super(slot) + end + end def cget(slot) if slot.to_s == 'relative' super('parent') diff --git a/ext/tk/lib/tkextlib/bwidget/dynamichelp.rb b/ext/tk/lib/tkextlib/bwidget/dynamichelp.rb index 224304f2ab..846e58062d 100644 --- a/ext/tk/lib/tkextlib/bwidget/dynamichelp.rb +++ b/ext/tk/lib/tkextlib/bwidget/dynamichelp.rb @@ -34,6 +34,13 @@ module Tk::BWidget::DynamicHelp ['DynamicHelp::configure'] end + def self.cget_strict(slot) + slot = slot.to_s + info = {} + self.current_configinfo.each{|k,v| info[k.to_s] = v if k.to_s == slot} + fail RuntimeError, "unknown option \"-#{slot}\"" if info.empty? + info.values[0] + end def self.cget(slot) self.current_configinfo(slot).values[0] end diff --git a/ext/tk/lib/tkextlib/bwidget/listbox.rb b/ext/tk/lib/tkextlib/bwidget/listbox.rb index d8cd72fec2..093fcb6fb3 100644 --- a/ext/tk/lib/tkextlib/bwidget/listbox.rb +++ b/ext/tk/lib/tkextlib/bwidget/listbox.rb @@ -297,6 +297,9 @@ class Tk::BWidget::ListBox::Item def cget(key) @listbox.itemcget(@id, key) end + def cget_strict(key) + @listbox.itemcget_strict(@id, key) + end def configure(key, val=None) @listbox.itemconfigure(@id, key, val) diff --git a/ext/tk/lib/tkextlib/bwidget/messagedlg.rb b/ext/tk/lib/tkextlib/bwidget/messagedlg.rb index cc8a996f46..b88461baf7 100644 --- a/ext/tk/lib/tkextlib/bwidget/messagedlg.rb +++ b/ext/tk/lib/tkextlib/bwidget/messagedlg.rb @@ -65,6 +65,17 @@ class Tk::BWidget::MessageDlg end @keys[slot] end + def cget_strict(slot) + slot = slot.to_s + if slot == 'relative' + slot = 'parent' + end + if winfo_exist? + val = super(slot) + @keys[slot] = val + end + @keys[slot] + end def configure(slot, value=None) if winfo_exist? diff --git a/ext/tk/lib/tkextlib/bwidget/tree.rb b/ext/tk/lib/tkextlib/bwidget/tree.rb index 7a46db575e..aed4512a73 100644 --- a/ext/tk/lib/tkextlib/bwidget/tree.rb +++ b/ext/tk/lib/tkextlib/bwidget/tree.rb @@ -358,6 +358,9 @@ class Tk::BWidget::Tree::Node def cget(key) @tree.itemcget(@id, key) end + def cget_strict(key) + @tree.itemcget_strict(@id, key) + end def configure(key, val=None) @tree.itemconfigure(@id, key, val) diff --git a/ext/tk/lib/tkextlib/bwidget/widget.rb b/ext/tk/lib/tkextlib/bwidget/widget.rb index 34e51308a5..a93364b567 100644 --- a/ext/tk/lib/tkextlib/bwidget/widget.rb +++ b/ext/tk/lib/tkextlib/bwidget/widget.rb @@ -29,6 +29,13 @@ module Tk::BWidget::Widget ['Widget::configure'] end + def self.cget_strict(slot) + slot = slot.to_s + info = {} + self.current_configinfo.each{|k,v| info[k.to_s] = v if k.to_s == slot} + fail RuntimeError, "unknown option \"-#{slot}\"" if info.empty? + info.values[0] + end def self.cget(slot) self.current_configinfo(slot).values[0] end @@ -105,9 +112,12 @@ module Tk::BWidget::Widget tk_call('Widget::setoption', win, option, value) end - def self.sub_cget(win, subwidget) + def self.sub_cget_strict(win, subwidget) tk_call('Widget::subcget', win, subwidget) end + def self.sub_cget(win, subwidget) + self.sub_cget_strict(win, subwidget) + end def self.sync_options(klass, subclass, subpath, options) tk_call('Widget::syncoptions', klass, subclass, subpath, options) diff --git a/ext/tk/lib/tkextlib/iwidgets/buttonbox.rb b/ext/tk/lib/tkextlib/iwidgets/buttonbox.rb index a055e07ac9..05d58c386f 100644 --- a/ext/tk/lib/tkextlib/iwidgets/buttonbox.rb +++ b/ext/tk/lib/tkextlib/iwidgets/buttonbox.rb @@ -47,12 +47,13 @@ class Tk::Iwidgets::Buttonbox end alias buttoncget itemcget + alias buttoncget_strict itemcget_strict alias buttonconfigure itemconfigure alias buttonconfiginfo itemconfiginfo alias current_buttonconfiginfo current_itemconfiginfo - private :itemcget, :itemconfigure - private :itemconfiginfo, :current_itemconfiginfo + private :itemcget, :itemcget_strict + private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo #################################### diff --git a/ext/tk/lib/tkextlib/iwidgets/calendar.rb b/ext/tk/lib/tkextlib/iwidgets/calendar.rb index 236ca96f00..8495f0e29b 100644 --- a/ext/tk/lib/tkextlib/iwidgets/calendar.rb +++ b/ext/tk/lib/tkextlib/iwidgets/calendar.rb @@ -46,6 +46,7 @@ class Tk::Iwidgets::Calendar KEY_TBL = [ [?d, ?s, :date], nil ] PROC_TBL = [ [?s, TkComm.method(:string) ], nil ] +=begin # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) KEY_TBL.map!{|inf| if inf.kind_of?(Array) @@ -61,6 +62,7 @@ class Tk::Iwidgets::Calendar end inf } +=end _setup_subst_table(KEY_TBL, PROC_TBL); diff --git a/ext/tk/lib/tkextlib/iwidgets/checkbox.rb b/ext/tk/lib/tkextlib/iwidgets/checkbox.rb index 7d2b41f806..c85d356c55 100644 --- a/ext/tk/lib/tkextlib/iwidgets/checkbox.rb +++ b/ext/tk/lib/tkextlib/iwidgets/checkbox.rb @@ -47,12 +47,13 @@ class Tk::Iwidgets::Checkbox end alias buttoncget itemcget + alias buttoncget_strict itemcget_strict alias buttonconfigure itemconfigure alias buttonconfiginfo itemconfiginfo alias current_buttonconfiginfo current_itemconfiginfo - private :itemcget, :itemconfigure - private :itemconfiginfo, :current_itemconfiginfo + private :itemcget, :itemcget_strict + private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo #################################### diff --git a/ext/tk/lib/tkextlib/iwidgets/dialogshell.rb b/ext/tk/lib/tkextlib/iwidgets/dialogshell.rb index d6c668621d..8d43cc07ab 100644 --- a/ext/tk/lib/tkextlib/iwidgets/dialogshell.rb +++ b/ext/tk/lib/tkextlib/iwidgets/dialogshell.rb @@ -47,12 +47,13 @@ class Tk::Iwidgets::Dialogshell end alias buttoncget itemcget + alias buttoncget_strict itemcget_strict alias buttonconfigure itemconfigure alias buttonconfiginfo itemconfiginfo alias current_buttonconfiginfo current_itemconfiginfo - private :itemcget, :itemconfigure - private :itemconfiginfo, :current_itemconfiginfo + private :itemcget, :itemcget_strict + private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo #################################### diff --git a/ext/tk/lib/tkextlib/iwidgets/entryfield.rb b/ext/tk/lib/tkextlib/iwidgets/entryfield.rb index 1f9effb46e..d53df216bf 100644 --- a/ext/tk/lib/tkextlib/iwidgets/entryfield.rb +++ b/ext/tk/lib/tkextlib/iwidgets/entryfield.rb @@ -43,6 +43,7 @@ class Tk::Iwidgets::Entryfield nil ] +=begin # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) KEY_TBL.map!{|inf| if inf.kind_of?(Array) @@ -58,6 +59,7 @@ class Tk::Iwidgets::Entryfield end inf } +=end _setup_subst_table(KEY_TBL, PROC_TBL); end diff --git a/ext/tk/lib/tkextlib/iwidgets/hierarchy.rb b/ext/tk/lib/tkextlib/iwidgets/hierarchy.rb index 4e7d8f8579..d9220fecbf 100644 --- a/ext/tk/lib/tkextlib/iwidgets/hierarchy.rb +++ b/ext/tk/lib/tkextlib/iwidgets/hierarchy.rb @@ -31,6 +31,7 @@ class Tk::Iwidgets::Hierarchy KEY_TBL = [ [?n, ?s, :node], nil ] PROC_TBL = [ [?s, TkComm.method(:string) ], nil ] +=begin # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) KEY_TBL.map!{|inf| if inf.kind_of?(Array) @@ -46,6 +47,7 @@ class Tk::Iwidgets::Hierarchy end inf } +=end _setup_subst_table(KEY_TBL, PROC_TBL); @@ -74,6 +76,7 @@ class Tk::Iwidgets::Hierarchy nil ] +=begin # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) KEY_TBL.map!{|inf| if inf.kind_of?(Array) @@ -89,6 +92,7 @@ class Tk::Iwidgets::Hierarchy end inf } +=end _setup_subst_table(KEY_TBL, PROC_TBL); @@ -112,6 +116,7 @@ class Tk::Iwidgets::Hierarchy ] PROC_TBL = [ [ ?s, TkComm.method(:string) ], nil ] +=begin # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) KEY_TBL.map!{|inf| if inf.kind_of?(Array) @@ -127,6 +132,7 @@ class Tk::Iwidgets::Hierarchy end inf } +=end _setup_subst_table(KEY_TBL, PROC_TBL); diff --git a/ext/tk/lib/tkextlib/iwidgets/menubar.rb b/ext/tk/lib/tkextlib/iwidgets/menubar.rb index dea3d34c2a..5aaefbe50d 100644 --- a/ext/tk/lib/tkextlib/iwidgets/menubar.rb +++ b/ext/tk/lib/tkextlib/iwidgets/menubar.rb @@ -62,12 +62,13 @@ class Tk::Iwidgets::Menubar end alias menucget itemcget + alias menucget_strict itemcget_strict alias menuconfigure itemconfigure alias menuconfiginfo itemconfiginfo alias current_menuconfiginfo current_itemconfiginfo - private :itemcget, :itemconfigure - private :itemconfiginfo, :current_itemconfiginfo + private :itemcget, :itemcget_strict + private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo #################################### diff --git a/ext/tk/lib/tkextlib/iwidgets/messagebox.rb b/ext/tk/lib/tkextlib/iwidgets/messagebox.rb index 2bbbec7666..98ac32900c 100644 --- a/ext/tk/lib/tkextlib/iwidgets/messagebox.rb +++ b/ext/tk/lib/tkextlib/iwidgets/messagebox.rb @@ -47,12 +47,13 @@ class Tk::Iwidgets::Messagebox private :__item_boolval_optkeys alias typecget itemcget + alias typecget_strict itemcget_strict alias typeconfigure itemconfigure alias typeconfiginfo itemconfiginfo alias current_typeconfiginfo current_itemconfiginfo - private :itemcget, :itemconfigure - private :itemconfiginfo, :current_itemconfiginfo + private :itemcget, :itemcget_strict + private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo #################################### diff --git a/ext/tk/lib/tkextlib/iwidgets/notebook.rb b/ext/tk/lib/tkextlib/iwidgets/notebook.rb index 268452afec..03b50633df 100644 --- a/ext/tk/lib/tkextlib/iwidgets/notebook.rb +++ b/ext/tk/lib/tkextlib/iwidgets/notebook.rb @@ -42,12 +42,13 @@ class Tk::Iwidgets::Notebook end alias pagecget itemcget + alias pagecget_strict itemcget_strict alias pageconfigure itemconfigure alias pageconfiginfo itemconfiginfo alias current_pageconfiginfo current_itemconfiginfo - private :itemcget, :itemconfigure - private :itemconfiginfo, :current_itemconfiginfo + private :itemcget, :itemcget_strict + private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo #################################### diff --git a/ext/tk/lib/tkextlib/iwidgets/panedwindow.rb b/ext/tk/lib/tkextlib/iwidgets/panedwindow.rb index 035df0a5b8..3bf73d69fe 100644 --- a/ext/tk/lib/tkextlib/iwidgets/panedwindow.rb +++ b/ext/tk/lib/tkextlib/iwidgets/panedwindow.rb @@ -42,12 +42,13 @@ class Tk::Iwidgets::Panedwindow end alias panecget itemcget + alias panecget_strict itemcget_strict alias paneconfigure itemconfigure alias paneconfiginfo itemconfiginfo alias current_paneconfiginfo current_itemconfiginfo - private :itemcget, :itemconfigure - private :itemconfiginfo, :current_itemconfiginfo + private :itemcget, :itemcget_strict + private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo #################################### diff --git a/ext/tk/lib/tkextlib/iwidgets/radiobox.rb b/ext/tk/lib/tkextlib/iwidgets/radiobox.rb index cfcbca1aad..e9d9521252 100644 --- a/ext/tk/lib/tkextlib/iwidgets/radiobox.rb +++ b/ext/tk/lib/tkextlib/iwidgets/radiobox.rb @@ -47,12 +47,13 @@ class Tk::Iwidgets::Radiobox end alias buttoncget itemcget + alias buttoncget_strict itemcget_strict alias buttonconfigure itemconfigure alias buttonconfiginfo itemconfiginfo alias current_buttonconfiginfo current_itemconfiginfo - private :itemcget, :itemconfigure - private :itemconfiginfo, :current_itemconfiginfo + private :itemcget, :itemcget_strict + private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo #################################### diff --git a/ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb b/ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb index b07602e340..67ad67d07e 100644 --- a/ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb +++ b/ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb @@ -37,7 +37,7 @@ class Tk::Iwidgets::Scrolledcanvas end def method_missing(id, *args) - if @canvas.methods.include?(id.id2name) + if @canvas.respond_to?(id) @canvas.__send__(id, *args) else super(id, *args) diff --git a/ext/tk/lib/tkextlib/iwidgets/scrolledlistbox.rb b/ext/tk/lib/tkextlib/iwidgets/scrolledlistbox.rb index cd1f6f0f79..7543d557e3 100644 --- a/ext/tk/lib/tkextlib/iwidgets/scrolledlistbox.rb +++ b/ext/tk/lib/tkextlib/iwidgets/scrolledlistbox.rb @@ -42,7 +42,7 @@ class Tk::Iwidgets::Scrolledlistbox end def method_missing(id, *args) - if @listbox.methods.include?(id.id2name) + if @listbox.respond_to?(id) @listbox.__send__(id, *args) else super(id, *args) diff --git a/ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb b/ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb index 2887b60815..d6436d202a 100644 --- a/ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb +++ b/ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb @@ -37,7 +37,7 @@ class Tk::Iwidgets::Scrolledtext end def method_missing(id, *args) - if @text.methods.include?(id.id2name) + if @text.respond_to?(id) @text.__send__(id, *args) else super(id, *args) @@ -116,7 +116,7 @@ class Tk::Iwidgets::Scrolledtext get('-displaychars', *index) end - def image_cget(index, slot) + def image_cget_strict(index, slot) case slot.to_s when 'text', 'label', 'show', 'data', 'file' _fromUTF8(tk_send_without_enc('image', 'cget', @@ -127,6 +127,27 @@ class Tk::Iwidgets::Scrolledtext "-#{slot}"))) end end + def image_cget(index, slot) + unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ + image_cget_strict(index, slot) + else + begin + image_cget_strict(index, slot) + rescue => e + begin + if current_image_configinfo.has_key?(slot.to_s) + # error on known option + fail e + else + # unknown option + nil + end + rescue + fail e # tag error + end + end + end + end def image_configure(index, slot, value=None) if slot.kind_of? Hash diff --git a/ext/tk/lib/tkextlib/iwidgets/spinner.rb b/ext/tk/lib/tkextlib/iwidgets/spinner.rb index 126cfe7c95..aeee5c9038 100644 --- a/ext/tk/lib/tkextlib/iwidgets/spinner.rb +++ b/ext/tk/lib/tkextlib/iwidgets/spinner.rb @@ -38,6 +38,7 @@ class Tk::Iwidgets::Spinner nil ] +=begin # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) KEY_TBL.map!{|inf| if inf.kind_of?(Array) @@ -53,6 +54,7 @@ class Tk::Iwidgets::Spinner end inf } +=end _setup_subst_table(KEY_TBL, PROC_TBL); end diff --git a/ext/tk/lib/tkextlib/iwidgets/tabnotebook.rb b/ext/tk/lib/tkextlib/iwidgets/tabnotebook.rb index 382604102e..dbb90e5102 100644 --- a/ext/tk/lib/tkextlib/iwidgets/tabnotebook.rb +++ b/ext/tk/lib/tkextlib/iwidgets/tabnotebook.rb @@ -47,12 +47,13 @@ class Tk::Iwidgets::Tabnotebook end alias pagecget itemcget + alias pagecget_strict itemcget_strict alias pageconfigure itemconfigure alias pageconfiginfo itemconfiginfo alias current_pageconfiginfo current_itemconfiginfo - private :itemcget, :itemconfigure - private :itemconfiginfo, :current_itemconfiginfo + private :itemcget, :itemcget_strict + private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo #################################### diff --git a/ext/tk/lib/tkextlib/iwidgets/tabset.rb b/ext/tk/lib/tkextlib/iwidgets/tabset.rb index 618260e8e3..300ba9dee0 100644 --- a/ext/tk/lib/tkextlib/iwidgets/tabset.rb +++ b/ext/tk/lib/tkextlib/iwidgets/tabset.rb @@ -42,12 +42,13 @@ class Tk::Iwidgets::Tabset end alias tabcget itemcget + alias tabcget_strict itemcget_strict alias tabconfigure itemconfigure alias tabconfiginfo itemconfiginfo alias current_tabconfiginfo current_itemconfiginfo - private :itemcget, :itemconfigure - private :itemconfiginfo, :current_itemconfiginfo + private :itemcget, :itemcget_strict + private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo #################################### diff --git a/ext/tk/lib/tkextlib/tcllib/getstring.rb b/ext/tk/lib/tkextlib/tcllib/getstring.rb index bf5e54e8cf..fc5d8b26d9 100644 --- a/ext/tk/lib/tkextlib/tcllib/getstring.rb +++ b/ext/tk/lib/tkextlib/tcllib/getstring.rb @@ -87,7 +87,7 @@ class Tk::Tcllib::GetString_Dialog @variable.value end - def cget(slot) + def cget_strict(slot) slot = slot.to_s if slot == 'text' @text @@ -95,6 +95,9 @@ class Tk::Tcllib::GetString_Dialog @keys[slot] end end + def cget(slot) + cget_strict(slot) + end def configure(slot, value=None) if slot.kind_of?(Hash) diff --git a/ext/tk/lib/tkextlib/tcllib/swaplist.rb b/ext/tk/lib/tkextlib/tcllib/swaplist.rb index 97de0a27c1..1c813e36da 100644 --- a/ext/tk/lib/tkextlib/tcllib/swaplist.rb +++ b/ext/tk/lib/tkextlib/tcllib/swaplist.rb @@ -90,7 +90,7 @@ class Tk::Tcllib::Swaplist_Dialog end alias selected value - def cget(slot) + def cget_strict(slot) slot = slot.to_s if slot == 'complete_list' @complete_list @@ -100,6 +100,9 @@ class Tk::Tcllib::Swaplist_Dialog @keys[slot] end end + def cget(slot) + cget_strict(slot) + end def configure(slot, value=None) if slot.kind_of?(Hash) diff --git a/ext/tk/lib/tkextlib/tcllib/tablelist_core.rb b/ext/tk/lib/tkextlib/tcllib/tablelist_core.rb index a939a58331..d7a6c97210 100644 --- a/ext/tk/lib/tkextlib/tcllib/tablelist_core.rb +++ b/ext/tk/lib/tkextlib/tcllib/tablelist_core.rb @@ -70,6 +70,9 @@ module Tk::Tcllib::TablelistItemConfig def cell_cget(tagOrId, option) itemcget(['cell', tagOrId], option) end + def cell_cget_strict(tagOrId, option) + itemcget_strict(['cell', tagOrId], option) + end def cell_configure(tagOrId, slot, value=None) itemconfigure(['cell', tagOrId], slot, value) end @@ -80,6 +83,7 @@ module Tk::Tcllib::TablelistItemConfig current_itemconfiginfo(['cell', tagOrId], slot) end alias cellcget cell_cget + alias cellcget_strict cell_cget_strict alias cellconfigure cell_configure alias cellconfiginfo cell_configinfo alias current_cellconfiginfo current_cell_configinfo @@ -87,6 +91,9 @@ module Tk::Tcllib::TablelistItemConfig def column_cget(tagOrId, option) itemcget(['column', tagOrId], option) end + def column_cget_strict(tagOrId, option) + itemcget_strict(['column', tagOrId], option) + end def column_configure(tagOrId, slot, value=None) itemconfigure(['column', tagOrId], slot, value) end @@ -97,6 +104,7 @@ module Tk::Tcllib::TablelistItemConfig current_itemconfiginfo(['column', tagOrId], slot) end alias columncget column_cget + alias columncget_strict column_cget_strict alias columnconfigure column_configure alias columnconfiginfo column_configinfo alias current_columnconfiginfo current_column_configinfo @@ -104,6 +112,9 @@ module Tk::Tcllib::TablelistItemConfig def row_cget(tagOrId, option) itemcget(['row', tagOrId], option) end + def row_cget_strict(tagOrId, option) + itemcget_strict(['row', tagOrId], option) + end def row_configure(tagOrId, slot, value=None) itemconfigure(['row', tagOrId], slot, value) end @@ -114,12 +125,13 @@ module Tk::Tcllib::TablelistItemConfig current_itemconfiginfo(['row', tagOrId], slot) end alias rowcget row_cget + alias rowcget_strict row_cget_strict alias rowconfigure row_configure alias rowconfiginfo row_configinfo alias current_rowconfiginfo current_row_configinfo - private :itemcget, :itemconfigure - private :itemconfiginfo, :current_itemconfiginfo + private :itemcget, :itemcget_strict + private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo end class Tk::Tcllib::Tablelist diff --git a/ext/tk/lib/tkextlib/tile.rb b/ext/tk/lib/tkextlib/tile.rb index 02473d57a1..60ea012cc0 100644 --- a/ext/tk/lib/tkextlib/tile.rb +++ b/ext/tk/lib/tkextlib/tile.rb @@ -133,7 +133,11 @@ module Tk ns_list.each{|ns| cmd = "#{ns}::#{proc_name}" unless Tk.info(:commands, cmd).empty? - fail RuntimeError, "can't define '#{cmd}' command (already exist)" + #fail RuntimeError, "can't define '#{cmd}' command (already exist)" + + # do nothing !!! + warn "Warning: can't define '#{cmd}' command (already exist)" if $DEBUG + next end TkNamespace.eval(ns){ TkCore::INTERP.add_tk_procs(proc_name, 'imgdir {patterns {*.gif}}', @@ -197,6 +201,38 @@ module Tk args.map!{|arg| TkComm._get_eval_string(arg)}.join('.') end + def self.themes(glob_ptn = nil) + if TILE_SPEC_VERSION_ID < 8 && Tk.info(:commands, '::ttk::themes').empty? + fail RuntimeError, 'not support glob option' if glob_ptn + cmd = ['::tile::availableThemes'] + else + glob_ptn = '*' unless glob_ptn + cmd = ['::ttk::themes', glob_ptn] + end + + begin + TkComm.simplelist(Tk.tk_call_without_enc(*cmd)) + rescue + TkComm.simplelist(Tk.tk_call('lsearch', '-all', '-inline', + Tk::Tile::Style.theme_names, + glob_ptn)) + end + end + + def self.set_theme(theme) + if TILE_SPEC_VERSION_ID < 8 && Tk.info(:commands, '::ttk::setTheme').empty? + cmd = '::tile::setTheme' + else + cmd = '::ttk::setTheme' + end + + begin + Tk.tk_call_without_enc(cmd, theme) + rescue + Tk::Tile::Style.theme_use(theme) + end + end + module KeyNav if Tk::Tile::TILE_SPEC_VERSION_ID < 8 def self.enableMnemonics(w) @@ -328,12 +364,16 @@ module Tk autoload :TLabelframe, 'tkextlib/tile/tlabelframe' autoload :Labelframe, 'tkextlib/tile/tlabelframe' + autoload :TLabelFrame, 'tkextlib/tile/tlabelframe' + autoload :LabelFrame, 'tkextlib/tile/tlabelframe' autoload :TLabel, 'tkextlib/tile/tlabel' autoload :Label, 'tkextlib/tile/tlabel' autoload :TMenubutton, 'tkextlib/tile/tmenubutton' autoload :Menubutton, 'tkextlib/tile/tmenubutton' + autoload :TMenuButton, 'tkextlib/tile/tmenubutton' + autoload :MenuButton, 'tkextlib/tile/tmenubutton' autoload :TNotebook, 'tkextlib/tile/tnotebook' autoload :Notebook, 'tkextlib/tile/tnotebook' diff --git a/ext/tk/lib/tkextlib/tile/dialog.rb b/ext/tk/lib/tkextlib/tile/dialog.rb index b10378d7de..ef2d1fe577 100644 --- a/ext/tk/lib/tkextlib/tile/dialog.rb +++ b/ext/tk/lib/tkextlib/tile/dialog.rb @@ -54,9 +54,21 @@ class Tk::Tile::Dialog window(tk_call_without_enc('::ttk::dialog::clientframe', @path)) end + def cget_strict(slot) + @keys[slot.to_s] + end + def cget(slot) + @keys[slot.to_s] + end +=begin def cget(slot) - @keys[slot] + unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ + cget_strict(slot) + else + cget_strict(slot) rescue nil + end end +=end def configure(slot, value=None) if slot.kind_of?(Hash) diff --git a/ext/tk/lib/tkextlib/tile/style.rb b/ext/tk/lib/tkextlib/tile/style.rb index bf8acb34b0..ca7ee99c32 100644 --- a/ext/tk/lib/tkextlib/tile/style.rb +++ b/ext/tk/lib/tkextlib/tile/style.rb @@ -33,9 +33,15 @@ class << Tk::Tile::Style # conflict with some definitions on Tcl/Tk scripts. if Tk::Tile::TILE_SPEC_VERSION_ID < 7 def __define_wrapper_proc_for_compatibility__! + __define_themes_and_setTheme_proc__! + unless Tk.info(:commands, '::ttk::style').empty? - fail RuntimeError, - "can't define ':ttk::style' command (already exist)" + # fail RuntimeError, + # "can't define '::ttk::style' command (already exist)" + + # do nothing !!! + warn "Warning: can't define '::ttk::style' command (already exist)" if $DEBUG + return end TkCore::INTERP.add_tk_procs('::ttk::style', 'args', <<-'EOS') if [string equal [lrange $args 0 1] {element create}] { @@ -55,9 +61,15 @@ class << Tk::Tile::Style end else ### TILE_SPEC_VERSION_ID == 7 def __define_wrapper_proc_for_compatibility__! + __define_themes_and_setTheme_proc__! + unless Tk.info(:commands, '::ttk::style').empty? - fail RuntimeError, - "can't define ':ttk::style' command (already exist)" + # fail RuntimeError, + # "can't define '::ttk::style' command (already exist)" + + # do nothing !!! + warn "Warning: can't define '::ttk::style' command (already exist)" if $DEBUG + return end TkCore::INTERP.add_tk_procs('::ttk::style', 'args', <<-'EOS') if [string equal [lrange $args 0 1] {element create}] { @@ -83,8 +95,14 @@ class << Tk::Tile::Style TkCommandNames = ['::ttk::style'.freeze].freeze def __define_wrapper_proc_for_compatibility__! + __define_themes_and_setTheme_proc__! + unless Tk.info(:commands, '::style').empty? - fail RuntimeError, "can't define '::style' command (already exist)" + # fail RuntimeError, "can't define '::style' command (already exist)" + + # do nothing !!! + warn "Warning: can't define '::style' command (already exist)" if $DEBUG + return end TkCore::INTERP.add_tk_procs('::style', 'args', <<-'EOS') if [string equal [lrange $args 0 1] {element create}] { @@ -108,6 +126,36 @@ class << Tk::Tile::Style end end + def __define_themes_and_setTheme_proc__! + TkCore::INTERP.add_tk_procs('::ttk::themes', '{ptn *}', <<-'EOS') + #set themes [list] + set themes [::ttk::style theme names] + foreach pkg [lsearch -inline -all -glob [package names] ttk::theme::$ptn] { + set theme [namespace tail $pkg] + if {[lsearch -exact $themes $theme] < 0} { + lappend themes $theme + } + } + foreach pkg [lsearch -inline -all -glob [package names] tile::theme::$ptn] { + set theme [namespace tail $pkg] + if {[lsearch -exact $themes $theme] < 0} { + lappend themes $theme + } + } + return $themes + EOS + ######################### + TkCore::INTERP.add_tk_procs('::ttk::setTheme', 'theme', <<-'EOS') + variable currentTheme + if {[lsearch -exact [::ttk::style theme names] $theme] < 0} { + package require [lsearch -inline -regexp [package names] (ttk|tile)::theme::$theme] + } + ::ttk::style theme use $theme + set currentTheme $theme + EOS + end + private :__define_themes_and_setTheme_proc__! + def configure(style=nil, keys=nil) if style.kind_of?(Hash) keys = style diff --git a/ext/tk/lib/tkextlib/tile/tentry.rb b/ext/tk/lib/tkextlib/tile/tentry.rb index 4b221fcb88..0bea98dcd9 100644 --- a/ext/tk/lib/tkextlib/tile/tentry.rb +++ b/ext/tk/lib/tkextlib/tile/tentry.rb @@ -27,6 +27,11 @@ class Tk::Tile::TEntry < Tk::Entry WidgetClassName = 'TEntry'.freeze WidgetClassNames[WidgetClassName] = self + def __optkey_aliases + {:vcmd=>:validatecommand, :invcmd=>:invalidcommand} + end + private :__optkey_aliases + def __boolval_optkeys super() << 'exportselection' end diff --git a/ext/tk/lib/tkextlib/tile/tnotebook.rb b/ext/tk/lib/tkextlib/tile/tnotebook.rb index 76f225c579..4d65e363da 100644 --- a/ext/tk/lib/tkextlib/tile/tnotebook.rb +++ b/ext/tk/lib/tkextlib/tile/tnotebook.rb @@ -41,13 +41,35 @@ class Tk::Tile::TNotebook < TkWindow private :__item_methodcall_optkeys #alias tabcget itemcget + #alias tabcget_strict itemcget_strict alias tabconfigure itemconfigure alias tabconfiginfo itemconfiginfo alias current_tabconfiginfo current_itemconfiginfo - def tabcget(tagOrId, option) + def tabcget_strict(tagOrId, option) tabconfigure(tagOrId, option)[-1] end + def tabcget(tagOrId, option) + unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ + tabcget_strict(tagOrId, option) + else + begin + tabcget_strict(tagOrId, option) + rescue => e + begin + if current_tabconfiginfo(tagOrId).has_key?(option.to_s) + # not tag error & option is known -> error on known option + fail e + else + # not tag error & option is unknown + nil + end + rescue + fail e # tag error + end + end + end + end ################################ include Tk::Tile::TileWidget @@ -77,9 +99,9 @@ class Tk::Tile::TNotebook < TkWindow def add(child, keys=nil) if keys && keys != None - tk_send_without_enc('add', _epath(child), *hash_kv(keys)) + tk_send('add', _epath(child), *hash_kv(keys)) else - tk_send_without_enc('add', _epath(child)) + tk_send('add', _epath(child)) end self end diff --git a/ext/tk/lib/tkextlib/tile/tpaned.rb b/ext/tk/lib/tkextlib/tile/tpaned.rb index 342b54d253..d96ff43973 100644 --- a/ext/tk/lib/tkextlib/tile/tpaned.rb +++ b/ext/tk/lib/tkextlib/tile/tpaned.rb @@ -36,9 +36,21 @@ class Tk::Tile::TPaned < TkWindow [self::WidgetClassName, *(args.map!{|a| _get_eval_string(a)})].join('.') end - def add(win, keys) - win = _epath(win) - tk_send_without_enc('add', win, *hash_kv(keys)) + def add(*args) + keys = args.pop + fail ArgumentError, "no window in arguments" unless keys + + if keys && keys.kind_of?(Hash) + fail ArgumentError, "no window in arguments" if args == [] + opts = hash_kv(keys) + else + args.push(keys) if keys + opts = [] + end + + args.each{|win| + tk_send_without_enc('add', _epath(win), *opts) + } self end @@ -54,10 +66,33 @@ class Tk::Tile::TPaned < TkWindow self end - def panecget(pane, slot) + def panecget_strict(pane, slot) pane = _epath(pane) tk_tcl2ruby(tk_send_without_enc('pane', pane, "-#{slot}")) end + alias pane_cget_strict panecget_strict + + def panecget(pane, slot) + unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ + panecget_strict(pane, slot) + else + begin + panecget_strict(pane, slot) + rescue => e + begin + if current_paneconfiginfo(pane).has_key?(slot.to_s) + # not tag error & option is known -> error on known option + fail e + else + # not tag error & option is unknown + nil + end + rescue + fail e # tag error + end + end + end + end alias pane_cget panecget def paneconfigure(pane, key, value=nil) diff --git a/ext/tk/lib/tkextlib/tile/treeview.rb b/ext/tk/lib/tkextlib/tile/treeview.rb index 7f31b9c233..c978a1a07b 100644 --- a/ext/tk/lib/tkextlib/tile/treeview.rb +++ b/ext/tk/lib/tkextlib/tile/treeview.rb @@ -33,6 +33,12 @@ module Tk::Tile::TreeviewConfig else if slot slot = slot.to_s + + alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot} + if real_name + slot = real_name.to_s + end + case slot when /^(#{__tile_specific_item_optkeys(tagid(tagOrId)).join('|')})$/ begin @@ -198,6 +204,12 @@ module Tk::Tile::TreeviewConfig else if slot slot = slot.to_s + + alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot} + if real_name + slot = real_name.to_s + end + case slot when /^(#{__tile_specific_item_optkeys(tagid(tagOrId)).join('|')})$/ begin @@ -508,17 +520,21 @@ module Tk::Tile::TreeviewConfig end alias __itemcget itemcget + alias __itemcget_strict itemcget_strict alias __itemconfigure itemconfigure alias __itemconfiginfo itemconfiginfo alias __current_itemconfiginfo current_itemconfiginfo - private :__itemcget, :__itemconfigure - private :__itemconfiginfo, :__current_itemconfiginfo + private :__itemcget, :__itemcget_strict + private :__itemconfigure, :__itemconfiginfo, :__current_itemconfiginfo # Treeview Item def itemcget(tagOrId, option) __itemcget([:item, tagOrId], option) end + def itemcget_strict(tagOrId, option) + __itemcget_strict([:item, tagOrId], option) + end def itemconfigure(tagOrId, slot, value=None) __itemconfigure([:item, tagOrId], slot, value) end @@ -533,6 +549,9 @@ module Tk::Tile::TreeviewConfig def columncget(tagOrId, option) __itemcget([:column, tagOrId], option) end + def columncget_strict(tagOrId, option) + __itemcget_strict([:column, tagOrId], option) + end def columnconfigure(tagOrId, slot, value=None) __itemconfigure([:column, tagOrId], slot, value) end @@ -543,12 +562,13 @@ module Tk::Tile::TreeviewConfig __current_itemconfiginfo([:column, tagOrId], slot) end alias column_cget columncget + alias column_cget_strict columncget_strict alias column_configure columnconfigure alias column_configinfo columnconfiginfo alias current_column_configinfo current_columnconfiginfo # Treeview Heading - def headingcget(tagOrId, option) + def headingcget_strict(tagOrId, option) if __tile_specific_item_optkeys([:heading, tagOrId]).index(option.to_s) begin # On tile-0.7.{2-8}, 'state' options has no '-' at its head. @@ -558,7 +578,28 @@ module Tk::Tile::TreeviewConfig tk_call(*(__item_cget_cmd([:heading, tagOrId]) << "-#{option}")) end else - __itemcget([:heading, tagOrId], option) + __itemcget_strict([:heading, tagOrId], option) + end + end + def headingcget(tagOrId, option) + unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ + headingcget_strict(tagOrId, option) + else + begin + headingcget_strict(tagOrId, option) + rescue => e + begin + if current_headingconfiginfo(tagOrId).has_key?(option.to_s) + # not tag error & option is known -> error on known option + fail e + else + # not tag error & option is unknown + nil + end + rescue + fail e # tag error + end + end end end def headingconfigure(tagOrId, slot, value=None) @@ -590,6 +631,7 @@ module Tk::Tile::TreeviewConfig __current_itemconfiginfo([:heading, tagOrId], slot) end alias heading_cget headingcget + alias heading_cget_strict headingcget_strict alias heading_configure headingconfigure alias heading_configinfo headingconfiginfo alias current_heading_configinfo current_headingconfiginfo @@ -598,6 +640,9 @@ module Tk::Tile::TreeviewConfig def tagcget(tagOrId, option) __itemcget([:tag, tagOrId], option) end + def tagcget_strict(tagOrId, option) + __itemcget_strict([:tag, tagOrId], option) + end def tagconfigure(tagOrId, slot, value=None) __itemconfigure([:tag, tagOrId], slot, value) end @@ -608,6 +653,7 @@ module Tk::Tile::TreeviewConfig __current_itemconfiginfo([:tag, tagOrId], slot) end alias tag_cget tagcget + alias tag_cget_strict tagcget_strict alias tag_configure tagconfigure alias tag_configinfo tagconfiginfo alias current_tag_configinfo current_tagconfiginfo @@ -694,6 +740,9 @@ class Tk::Tile::Treeview::Item < TkObject def cget(option) @t.itemcget(@id, option) end + def cget_strict(option) + @t.itemcget_strict(@id, option) + end def configure(key, value=None) @t.itemconfigure(@id, key, value) @@ -933,6 +982,9 @@ class Tk::Tile::Treeview::Tag < TkObject def cget(option) @t.tagcget(@id, option) end + def cget_strict(option) + @t.tagcget_strict(@id, option) + end def configure(key, value=None) @t.tagconfigure(@id, key, value) diff --git a/ext/tk/lib/tkextlib/tkDND/shape.rb b/ext/tk/lib/tkextlib/tkDND/shape.rb index 570c93b0d9..d44068ed33 100644 --- a/ext/tk/lib/tkextlib/tkDND/shape.rb +++ b/ext/tk/lib/tkextlib/tkDND/shape.rb @@ -11,15 +11,15 @@ require 'tkextlib/setup.rb' # call setup script require 'tkextlib/tkDND/setup.rb' -# TkPackage.require('shape', '0.3') -TkPackage.require('shape') +# TkPackage.require('Shape', '0.3') +TkPackage.require('Shape') module Tk module TkDND module Shape extend TkCore - PACKAGE_NAME = 'shape'.freeze + PACKAGE_NAME = 'Shape'.freeze def self.package_name PACKAGE_NAME end @@ -27,26 +27,28 @@ module Tk =begin def self.package_version begin - TkPackage.require('shape') + TkPackage.require('Shape') rescue '' end end =end - def self.package_version - Tk.tk_call('set', 'shape_version') - end - alias shape_version package_version + class << self + def package_version + Tk.tk_call('set', 'shape_version') + end + alias shape_version package_version - def self.package_patchlevel - Tk.tk_call('set', 'shape_patchlevel') - end - alias shape_patchlevel package_patchlevel + def package_patchlevel + Tk.tk_call('set', 'shape_patchLevel') + end + alias shape_patchlevel package_patchlevel - def self.version - tk_call('shape', 'version') + def version + tk_call('shape', 'version') + end + alias xshape_version version end - alias xshape_version version ############################ diff --git a/ext/tk/lib/tkextlib/tkDND/tkdnd.rb b/ext/tk/lib/tkextlib/tkDND/tkdnd.rb index ea91d3d1f4..9a9b2dc42c 100644 --- a/ext/tk/lib/tkextlib/tkDND/tkdnd.rb +++ b/ext/tk/lib/tkextlib/tkDND/tkdnd.rb @@ -57,6 +57,7 @@ module Tk nil ] +=begin # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) KEY_TBL.map!{|inf| if inf.kind_of?(Array) @@ -72,6 +73,7 @@ module Tk end inf } +=end # setup tables _setup_subst_table(KEY_TBL, PROC_TBL); diff --git a/ext/tk/lib/tkextlib/tktable/tktable.rb b/ext/tk/lib/tkextlib/tktable/tktable.rb index fb8a8b0f72..f6cf24b40f 100644 --- a/ext/tk/lib/tkextlib/tktable/tktable.rb +++ b/ext/tk/lib/tkextlib/tktable/tktable.rb @@ -77,6 +77,9 @@ module Tk::TkTable::ConfigMethod def tag_cget(tagOrId, option) itemcget(['tag', tagid(tagOrId)], option) end + def tag_cget_strict(tagOrId, option) + itemcget_strict(['tag', tagid(tagOrId)], option) + end def tag_configure(tagOrId, slot, value=None) itemconfigure(['tag', tagid(tagOrId)], slot, value) end @@ -90,6 +93,9 @@ module Tk::TkTable::ConfigMethod def window_cget(tagOrId, option) itemcget(['window', tagid(tagOrId)], option) end + def window_cget_strict(tagOrId, option) + itemcget_strict(['window', tagid(tagOrId)], option) + end def window_configure(tagOrId, slot, value=None) if slot == :window || slot == 'window' value = _epath(value) @@ -108,8 +114,8 @@ module Tk::TkTable::ConfigMethod current_itemconfiginfo(['window', tagid(tagOrId)], slot) end - private :itemcget, :itemconfigure - private :itemconfiginfo, :current_itemconfiginfo + private :itemcget, :itemcget_strict + private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo end ##################################################### @@ -194,6 +200,9 @@ class Tk::TkTable::CellTag def cget(key) @t.tag_cget(@id, key) end + def cget_strict(key) + @t.tag_cget_strict(@id, key) + end def configure(key, val=None) @t.tag_configure(@id, key, val) end @@ -291,6 +300,7 @@ class Tk::TkTable nil ] +=begin # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) KEY_TBL.map!{|inf| if inf.kind_of?(Array) @@ -306,6 +316,7 @@ class Tk::TkTable end inf } +=end _setup_subst_table(KEY_TBL, PROC_TBL); @@ -340,6 +351,7 @@ class Tk::TkTable nil ] +=begin # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) KEY_TBL.map!{|inf| if inf.kind_of?(Array) @@ -355,6 +367,7 @@ class Tk::TkTable end inf } +=end _setup_subst_table(KEY_TBL, PROC_TBL); @@ -387,6 +400,7 @@ class Tk::TkTable nil ] +=begin # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) KEY_TBL.map!{|inf| if inf.kind_of?(Array) @@ -402,6 +416,7 @@ class Tk::TkTable end inf } +=end _setup_subst_table(KEY_TBL, PROC_TBL); @@ -437,6 +452,7 @@ class Tk::TkTable nil ] +=begin # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) KEY_TBL.map!{|inf| if inf.kind_of?(Array) @@ -452,6 +468,7 @@ class Tk::TkTable end inf } +=end _setup_subst_table(KEY_TBL, PROC_TBL); end diff --git a/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb b/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb index b72b157dcd..e10e6e299e 100644 --- a/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb +++ b/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb @@ -137,6 +137,7 @@ class Tk::TreeCtrl::NotifyEvent nil ] +=begin # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) KEY_TBL.map!{|inf| if inf.kind_of?(Array) @@ -152,6 +153,7 @@ class Tk::TreeCtrl::NotifyEvent end inf } +=end # setup tables to be used by scan_args, _get_subst_key, _get_all_subst_keys # @@ -415,6 +417,9 @@ module Tk::TreeCtrl::ConfigMethod def column_cget(tagOrId, option) itemcget(['column', tagOrId], option) end + def column_cget_strict(tagOrId, option) + itemcget_strict(['column', tagOrId], option) + end def column_configure(tagOrId, slot, value=None) itemconfigure(['column', tagOrId], slot, value) end @@ -428,6 +433,9 @@ module Tk::TreeCtrl::ConfigMethod def column_dragcget(option) itemcget(['column', 'drag'], option) end + def column_dragcget_strict(option) + itemcget_strict(['column', 'drag'], option) + end def column_dragconfigure(slot, value=None) itemconfigure(['column', 'drag'], slot, value) end @@ -441,6 +449,9 @@ module Tk::TreeCtrl::ConfigMethod def debug_cget(option) itemcget('debug', option) end + def debug_cget_strict(option) + itemcget_strict('debug', option) + end def debug_configure(slot, value=None) itemconfigure('debug', slot, value) end @@ -454,6 +465,9 @@ module Tk::TreeCtrl::ConfigMethod def dragimage_cget(option) itemcget('dragimage', option) end + def dragimage_cget_strict(option) + itemcget_strict('dragimage', option) + end def dragimage_configure(slot, value=None) itemconfigure('dragimage', slot, value) end @@ -467,6 +481,9 @@ module Tk::TreeCtrl::ConfigMethod def element_cget(tagOrId, option) itemcget(['element', tagOrId], option) end + def element_cget_strict(tagOrId, option) + itemcget_strict(['element', tagOrId], option) + end def element_configure(tagOrId, slot, value=None) itemconfigure(['element', tagOrId], slot, value) end @@ -480,6 +497,9 @@ module Tk::TreeCtrl::ConfigMethod def item_cget(tagOrId, option) itemcget(['item', tagOrId], option) end + def item_cget_strict(tagOrId, option) + itemcget_strict(['item', tagOrId], option) + end def item_configure(tagOrId, slot, value=None) itemconfigure(['item', tagOrId], slot, value) end @@ -493,6 +513,9 @@ module Tk::TreeCtrl::ConfigMethod def item_element_cget(item, column, elem, option) itemcget([['item', 'element'], [item, column, elem]], option) end + def item_element_cget_strict(item, column, elem, option) + itemcget_strict([['item', 'element'], [item, column, elem]], option) + end def item_element_configure(item, column, elem, slot, value=None) itemconfigure([['item', 'element'], [item, column, elem]], slot, value) end @@ -506,6 +529,9 @@ module Tk::TreeCtrl::ConfigMethod def marquee_cget(option) itemcget('marquee', option) end + def marquee_cget_strict(option) + itemcget_strict('marquee', option) + end def marquee_configure(slot, value=None) itemconfigure('marquee', slot, value) end @@ -518,7 +544,19 @@ module Tk::TreeCtrl::ConfigMethod def notify_cget(win, pattern, option) pattern = "<#{pattern}>" - itemconfigure(['notify', [win, pattern]], option) + # "notify" doesn't have cget subcommand. + current_itemconfiginfo(['notify', [win, pattern]])[option.to_s] + end + def notify_cget_strict(win, pattern, option) + pattern = "<#{pattern}>" + # "notify" doesn't have cget subcommand. + info = current_itemconfiginfo(['notify', [win, pattern]]) + option = option.to_s + unless info.has_key?(option) + fail RuntimeError, "unknown option \"#{option}\"" + else + info[option] + end end def notify_configure(win, pattern, slot, value=None) pattern = "<#{pattern}>" @@ -528,11 +566,17 @@ module Tk::TreeCtrl::ConfigMethod pattern = "<#{pattern}>" itemconfiginfo(['notify', [win, pattern]], slot) end - alias current_notify_configinfo notify_configinfo + def current_notify_configinfo(tagOrId, slot=nil) + pattern = "<#{pattern}>" + current_itemconfiginfo(['notify', [win, pattern]], slot) + end def style_cget(tagOrId, option) itemcget(['style', tagOrId], option) end + def style_cget_strict(tagOrId, option) + itemcget_strict(['style', tagOrId], option) + end def style_configure(tagOrId, slot, value=None) itemconfigure(['style', tagOrId], slot, value) end @@ -543,8 +587,8 @@ module Tk::TreeCtrl::ConfigMethod current_itemconfiginfo(['style', tagOrId], slot) end - private :itemcget, :itemconfigure - private :itemconfiginfo, :current_itemconfiginfo + private :itemcget, :itemcget_strict + private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo end ############################################## @@ -1700,6 +1744,9 @@ class Tk::TreeCtrl::Column < TkObject def cget(opt) @tree.column_cget(@tree.column_index(@id), opt) end + def cget_strict(opt) + @tree.column_cget_strict(@tree.column_index(@id), opt) + end def configure(*args) @tree.column_configure(@tree.column_index(@id), *args) @@ -1800,6 +1847,9 @@ class Tk::TreeCtrl::Element < TkObject def cget(opt) @tree.element_cget(@id, opt) end + def cget_strict(opt) + @tree.element_cget_strict(@id, opt) + end def configure(*args) @tree.element_configure(@id, *args) @@ -1931,6 +1981,9 @@ class Tk::TreeCtrl::Item < TkObject def cget(opt) @tree.item_cget(@id, opt) end + def cget_strict(opt) + @tree.item_cget_strict(@id, opt) + end def configure(*args) @tree.item_configure(@id, *args) @@ -1964,6 +2017,9 @@ class Tk::TreeCtrl::Item < TkObject def element_cget(opt) @tree.item_element_cget(@id, opt) end + def element_cget_strict(opt) + @tree.item_element_cget_strict(@id, opt) + end def element_configure(*args) @tree.item_element_configure(@id, *args) @@ -2215,6 +2271,9 @@ class Tk::TreeCtrl::Style < TkObject def cget(opt) @tree.style_cget(@id, opt) end + def cget_strict(opt) + @tree.style_cget_strict(@id, opt) + end def configure(*args) @tree.style_configure(@id, *args) diff --git a/ext/tk/lib/tkextlib/version.rb b/ext/tk/lib/tkextlib/version.rb index 3542c79dbe..434ed11a2e 100644 --- a/ext/tk/lib/tkextlib/version.rb +++ b/ext/tk/lib/tkextlib/version.rb @@ -2,5 +2,5 @@ # release date of tkextlib # module Tk - Tkextlib_RELEASE_DATE = '2008-03-29'.freeze + Tkextlib_RELEASE_DATE = '2008-05-23'.freeze end diff --git a/ext/tk/lib/tkextlib/vu/pie.rb b/ext/tk/lib/tkextlib/vu/pie.rb index 1975803db1..c1fb6857bf 100644 --- a/ext/tk/lib/tkextlib/vu/pie.rb +++ b/ext/tk/lib/tkextlib/vu/pie.rb @@ -177,6 +177,10 @@ class Tk::Vu::PieSlice @pie.itemcget(@id, slot) end + def cget_strict(slot) + @pie.itemcget_strict(@id, slot) + end + def configure(*args) @pie.itemconfigure(@id, *args) self diff --git a/ext/tk/lib/tkextlib/winico/winico.rb b/ext/tk/lib/tkextlib/winico/winico.rb index 30fb9682d5..00316fd441 100644 --- a/ext/tk/lib/tkextlib/winico/winico.rb +++ b/ext/tk/lib/tkextlib/winico/winico.rb @@ -150,6 +150,7 @@ class Tk::Winico nil ] +=begin # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) KEY_TBL.map!{|inf| if inf.kind_of?(Array) @@ -165,6 +166,7 @@ class Tk::Winico end inf } +=end _setup_subst_table(KEY_TBL, PROC_TBL); @@ -185,7 +187,8 @@ class Tk::Winico Winico_callback._config_keys.each{|k| if keys[k].kind_of?(Array) cmd, *args = keys[k] - keys[k] = Winico_callback.new(cmd, args.join(' ')) + #keys[k] = Winico_callback.new(cmd, args.join(' ')) + keys[k] = Winico_callback.new(cmd, *args) # elsif keys[k].kind_of?(Proc) elsif TkComm._callback_entry?(keys[k]) keys[k] = Winico_callback.new(keys[k]) @@ -201,7 +204,8 @@ class Tk::Winico Winico_callback._config_keys.each{|k| if keys[k].kind_of?(Array) cmd, *args = keys[k] - keys[k] = Winico_callback.new(cmd, args.join(' ')) + #keys[k] = Winico_callback.new(cmd, args.join(' ')) + keys[k] = Winico_callback.new(cmd, *args) # elsif keys[k].kind_of?(Proc) elsif TkComm._callback_entry?(keys[k]) keys[k] = Winico_callback.new(keys[k]) diff --git a/ext/tk/sample/demos-en/anilabel.rb b/ext/tk/sample/demos-en/anilabel.rb index f063bc53a4..0b9bc7357e 100644 --- a/ext/tk/sample/demos-en/anilabel.rb +++ b/ext/tk/sample/demos-en/anilabel.rb @@ -15,8 +15,10 @@ $anilabel_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($anilabel_demo).pack(:fill=>:both, :expand=>true) + # label -msg = TkLabel.new($anilabel_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -25,7 +27,7 @@ msg = TkLabel.new($anilabel_demo) { msg.pack('side'=>'top') # frame -TkFrame.new($anilabel_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -43,8 +45,8 @@ TkFrame.new($anilabel_demo) {|frame| }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # create frame for label demo -f_left = TkLabelFrame.new($anilabel_demo, :text=>'Scrolling Texts') -f_right = TkLabelFrame.new($anilabel_demo, :text=>'GIF Image') +f_left = TkLabelFrame.new(base_frame, :text=>'Scrolling Texts') +f_right = TkLabelFrame.new(base_frame, :text=>'GIF Image') Tk.pack(f_left, f_right, 'side'=>'left', 'expand'=>'yes', 'fill'=>'both', 'padx'=>10, 'pady'=>10) diff --git a/ext/tk/sample/demos-en/aniwave.rb b/ext/tk/sample/demos-en/aniwave.rb index ebe27b875f..63a04a7b98 100644 --- a/ext/tk/sample/demos-en/aniwave.rb +++ b/ext/tk/sample/demos-en/aniwave.rb @@ -16,8 +16,10 @@ $aniwave_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($aniwave_demo).pack(:fill=>:both, :expand=>true) + # create label -msg = TkLabel.new($aniwave_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -26,7 +28,7 @@ msg = TkLabel.new($aniwave_demo) { msg.pack('side'=>'top') # create frame -TkFrame.new($aniwave_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -58,6 +60,7 @@ class AnimatedWaveDemo @backupCoords = [] n = 0 (-10..300).step(5){|n| @waveCoords << [n, 100]; @backupCoords << [n, 100] } + n = 305 @waveCoords << [n, 0]; @backupCoords << [n, 0] @waveCoords << [n+5, 200]; @backupCoords << [n+5, 200] @coordsLen = @waveCoords.length @@ -112,4 +115,4 @@ class AnimatedWaveDemo end # Start the animation processing -AnimatedWaveDemo.new($aniwave_demo, :left).move +AnimatedWaveDemo.new(base_frame, :left).move diff --git a/ext/tk/sample/demos-en/arrow.rb b/ext/tk/sample/demos-en/arrow.rb index 4a589a0892..055cd2af3c 100644 --- a/ext/tk/sample/demos-en/arrow.rb +++ b/ext/tk/sample/demos-en/arrow.rb @@ -107,14 +107,16 @@ $arrow_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($arrow_demo).pack(:fill=>:both, :expand=>true) + # label -TkLabel.new($arrow_demo, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left', +TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left', 'text'=>"This widget allows you to experiment with different widths and arrowhead shapes for lines in canvases. To change the line width or the shape of the arrowhead, drag any of the three boxes attached to the oversized arrow. The arrows on the right give examples at normal scale. The text at the bottom shows the configuration options as you'd enter them for a canvas line item."){ pack('side'=>'top') } # frame -$arrow_buttons = TkFrame.new($arrow_demo) {|frame| +$arrow_buttons = TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -132,7 +134,7 @@ $arrow_buttons = TkFrame.new($arrow_demo) {|frame| $arrow_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # canvas -$arrow_canvas = TkCanvas.new($arrow_demo, 'width'=>500, 'height'=>350, +$arrow_canvas = TkCanvas.new(base_frame, 'width'=>500, 'height'=>350, 'relief'=>'sunken', 'borderwidth'=>2) $arrow_canvas.pack('expand'=>'yes', 'fill'=>'both') diff --git a/ext/tk/sample/demos-en/bind.rb b/ext/tk/sample/demos-en/bind.rb index 5d6ec84edb..665592a2bc 100644 --- a/ext/tk/sample/demos-en/bind.rb +++ b/ext/tk/sample/demos-en/bind.rb @@ -19,8 +19,10 @@ $bind_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($bind_demo).pack(:fill=>:both, :expand=>true) + # frame -TkFrame.new($bind_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -43,14 +45,14 @@ def tag_binding_for_bind_demo(tag, enter_style, leave_style) end # text -txt = TkText.new($bind_demo){|t| +txt = TkText.new(base_frame){|t| # setgrid 'true' #width 60 #height 24 font $font wrap 'word' - TkScrollbar.new($bind_demo) {|s| + TkScrollbar.new(base_frame) {|s| pack('side'=>'right', 'fill'=>'y') command proc{|*args| t.yview(*args)} t.yscrollcommand proc{|first,last| s.set first,last} @@ -94,32 +96,32 @@ txt = TkText.new($bind_demo){|t| } d1.bind('1', proc{ - eval_samplecode(`cat #{[$demo_dir,'items.rb'].join(File::Separator)}`) + eval_samplecode(`cat #{[$demo_dir,'items.rb'].join(File::Separator)}`, 'items.rb') }) d2.bind('1', proc{ - eval_samplecode(`cat #{[$demo_dir,'plot.rb'].join(File::Separator)}`) + eval_samplecode(`cat #{[$demo_dir,'plot.rb'].join(File::Separator)}`, 'plot.rb') }) d3.bind('1', proc{ - eval_samplecode(`cat #{[$demo_dir,'ctext.rb'].join(File::Separator)}`) + eval_samplecode(`cat #{[$demo_dir,'ctext.rb'].join(File::Separator)}`, 'ctext.rb') }) d4.bind('1', proc{ - eval_samplecode(`cat #{[$demo_dir,'arrow.rb'].join(File::Separator)}`) + eval_samplecode(`cat #{[$demo_dir,'arrow.rb'].join(File::Separator)}`, 'arrow.rb') }) d5.bind('1', proc{ - eval_samplecode(`cat #{[$demo_dir,'ruler.rb'].join(File::Separator)}`) + eval_samplecode(`cat #{[$demo_dir,'ruler.rb'].join(File::Separator)}`, 'ruler.rb') }) d6.bind('1', proc{ - eval_samplecode(`cat #{[$demo_dir,'cscroll.rb'].join(File::Separator)}`) + eval_samplecode(`cat #{[$demo_dir,'cscroll.rb'].join(File::Separator)}`, 'cscroll.rb') }) TkTextMarkInsert.new(t, '0.0') configure('state','disabled') } -txt.width 60 -txt.width 24 +txt.width 60 +txt.height 24 diff --git a/ext/tk/sample/demos-en/bitmap.rb b/ext/tk/sample/demos-en/bitmap.rb index 7fd551c7a5..133adb0543 100644 --- a/ext/tk/sample/demos-en/bitmap.rb +++ b/ext/tk/sample/demos-en/bitmap.rb @@ -21,7 +21,7 @@ def bitmapRow(w,*args) TkFrame.new(row){|base| pack('side'=>'left', 'fill'=>'both', 'pady'=>'.25c', 'padx'=>'.25c') TkLabel.new(base, 'text'=>bitmap, 'width'=>9).pack('side'=>'bottom') - TkLabel.new(base, 'bitmap'=>bitmap).pack('side'=>'bottom') + Tk::Label.new(base, 'bitmap'=>bitmap).pack('side'=>'bottom') } end } @@ -40,14 +40,16 @@ $bitmap_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($bitmap_demo).pack(:fill=>:both, :expand=>true) + # label -TkLabel.new($bitmap_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left', +TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left', 'text'=>"This window displays all of Tk's built-in bitmaps, along with the names you can use for them in Tcl scripts."){ pack('side'=>'top') } # frame -$bitmap_buttons = TkFrame.new($bitmap_demo) {|frame| +$bitmap_buttons = TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -65,7 +67,7 @@ $bitmap_buttons = TkFrame.new($bitmap_demo) {|frame| $bitmap_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # frame -TkFrame.new($bitmap_demo){|f| +TkFrame.new(base_frame){|f| bitmapRow(f,'error','gray25','gray50','hourglass') bitmapRow(f,'info','question','questhead','warning') pack('side'=>'top', 'expand'=>'yes', 'fill'=>'both') diff --git a/ext/tk/sample/demos-en/button.rb b/ext/tk/sample/demos-en/button.rb index 6614d99c92..5c03bd499b 100644 --- a/ext/tk/sample/demos-en/button.rb +++ b/ext/tk/sample/demos-en/button.rb @@ -29,7 +29,7 @@ msg = TkLabel.new($button_demo) { msg.pack('side'=>'top') # frame -$button_buttons = TkFrame.new($button_demo) {|frame| +$button_buttons = Tk::Frame.new($button_demo) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ diff --git a/ext/tk/sample/demos-en/check.rb b/ext/tk/sample/demos-en/check.rb index 971a8fea73..2951962a79 100644 --- a/ext/tk/sample/demos-en/check.rb +++ b/ext/tk/sample/demos-en/check.rb @@ -19,8 +19,10 @@ $check_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($check_demo).pack(:fill=>:both, :expand=>true) + # label -msg = TkLabel.new($check_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -34,7 +36,7 @@ brakes = TkVariable.new(0) sober = TkVariable.new(0) # frame -TkFrame.new($check_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -54,7 +56,7 @@ TkFrame.new($check_demo) {|frame| TkButton.new(frame) { text 'See Variables' command proc{ - showVars($check_demo, + showVars(base_frame, ['wipers', wipers], ['brakes', brakes], ['sober', sober]) } }.pack('side'=>'left', 'expand'=>'yes') @@ -63,8 +65,8 @@ TkFrame.new($check_demo) {|frame| # checkbutton -[ TkCheckButton.new($check_demo, 'text'=>'Wipers OK', 'variable'=>wipers), - TkCheckButton.new($check_demo, 'text'=>'Brakes OK', 'variable'=>brakes), - TkCheckButton.new($check_demo, 'text'=>'Driver Sober', 'variable'=>sober) +[ TkCheckButton.new(base_frame, 'text'=>'Wipers OK', 'variable'=>wipers), + TkCheckButton.new(base_frame, 'text'=>'Brakes OK', 'variable'=>brakes), + TkCheckButton.new(base_frame, 'text'=>'Driver Sober', 'variable'=>sober) ].each{|w| w.relief('flat'); w.pack('side'=>'top', 'pady'=>2, 'anchor'=>'w')} diff --git a/ext/tk/sample/demos-en/check2.rb b/ext/tk/sample/demos-en/check2.rb index 97d61fba0c..faea748a87 100644 --- a/ext/tk/sample/demos-en/check2.rb +++ b/ext/tk/sample/demos-en/check2.rb @@ -15,8 +15,10 @@ $check2_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($check2_demo).pack(:fill=>:both, :expand=>true) + # label -msg = TkLabel.new($check2_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -31,7 +33,7 @@ brakes = TkVariable.new(0) sober = TkVariable.new(0) # frame -TkFrame.new($check2_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkGrid(TkFrame.new(frame, :height=>2, :relief=>:sunken, :bd=>2), :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) TkGrid('x', @@ -59,15 +61,15 @@ TkFrame.new($check2_demo) {|frame| # checkbutton -TkCheckButton.new($check2_demo, :text=>'Safety Check', :variable=>safety, +TkCheckButton.new(base_frame, :text=>'Safety Check', :variable=>safety, :relief=>:flat, :onvalue=>'all', :offvalue=>'none', :tristatevalue=>'partial'){ pack('side'=>'top', 'pady'=>2, 'anchor'=>'w') } -[ TkCheckButton.new($check2_demo, 'text'=>'Wipers OK', 'variable'=>wipers), - TkCheckButton.new($check2_demo, 'text'=>'Brakes OK', 'variable'=>brakes), - TkCheckButton.new($check2_demo, 'text'=>'Driver Sober', 'variable'=>sober) +[ TkCheckButton.new(base_frame, 'text'=>'Wipers OK', 'variable'=>wipers), + TkCheckButton.new(base_frame, 'text'=>'Brakes OK', 'variable'=>brakes), + TkCheckButton.new(base_frame, 'text'=>'Driver Sober', 'variable'=>sober) ].each{|w| w.relief('flat') w.pack('side'=>'top', 'padx'=>15, 'pady'=>2, 'anchor'=>'w') diff --git a/ext/tk/sample/demos-en/clrpick.rb b/ext/tk/sample/demos-en/clrpick.rb index 9486fde314..431439d55d 100644 --- a/ext/tk/sample/demos-en/clrpick.rb +++ b/ext/tk/sample/demos-en/clrpick.rb @@ -4,6 +4,8 @@ # # widget demo prompts the user to select a color (called by 'widget') # +# Note: don't support ttk_wrapper. work with standard widgets only. +# # toplevel widget if defined?($clrpick_demo) && $clrpick_demo @@ -18,13 +20,18 @@ $clrpick_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($clrpick_demo).pack(:fill=>:both, :expand=>true) + # label -TkLabel.new($clrpick_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left', +#TkLabel.new($clrpick_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left', +Tk::Label.new($clrpick_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left', 'text'=>"Press the buttons below to choose the foreground and background colors for the widgets in this window.").pack('side'=>'top') # frame -TkFrame.new($clrpick_demo) {|frame| - TkButton.new(frame) { +#TkFrame.new($clrpick_demo) {|frame| +Tk::Frame.new($clrpick_demo) {|frame| + # TkButton.new(frame) { + Tk::Button.new(frame) { text 'Dismiss' command proc{ tmppath = $clrpick_demo @@ -33,20 +40,23 @@ TkFrame.new($clrpick_demo) {|frame| } }.pack('side'=>'left', 'expand'=>'yes') - TkButton.new(frame) { + # TkButton.new(frame) { + Tk::Button.new(frame) { text 'Show Code' command proc{showCode 'clrpick'} }.pack('side'=>'left', 'expand'=>'yes') }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # button -TkButton.new($clrpick_demo, 'text'=>'Set background color ...') {|b| +# TkButton.new($clrpick_demo, 'text'=>'Set background color ...') {|b| +Tk::Button.new($clrpick_demo, 'text'=>'Set background color ...') {|b| command(proc{setColor $clrpick_demo, b, 'background', ['background', 'highlightbackground']}) pack('side'=>'top', 'anchor'=>'c', 'pady'=>'2m') } -TkButton.new($clrpick_demo, 'text'=>'Set foreground color ...') {|b| +# TkButton.new($clrpick_demo, 'text'=>'Set foreground color ...') {|b| +Tk::Button.new($clrpick_demo, 'text'=>'Set foreground color ...') {|b| command(proc{setColor $clrpick_demo, b, 'foreground', ['foreground']}) pack('side'=>'top', 'anchor'=>'c', 'pady'=>'2m') } diff --git a/ext/tk/sample/demos-en/colors.rb b/ext/tk/sample/demos-en/colors.rb index 66fb0afa36..4300a660ae 100644 --- a/ext/tk/sample/demos-en/colors.rb +++ b/ext/tk/sample/demos-en/colors.rb @@ -20,8 +20,10 @@ $colors_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($colors_demo).pack(:fill=>:both, :expand=>true) + # label -msg = TkLabel.new($colors_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -30,7 +32,7 @@ msg = TkLabel.new($colors_demo) { msg.pack('side'=>'top') # frame -TkFrame.new($colors_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -49,7 +51,7 @@ TkFrame.new($colors_demo) {|frame| # frame colors_lbox = nil -TkFrame.new($colors_demo, 'borderwidth'=>10) {|w| +TkFrame.new(base_frame, 'borderwidth'=>10) {|w| s = TkScrollbar.new(w) colors_lbox = TkListbox.new(w) { setgrid 1 @@ -62,7 +64,15 @@ TkFrame.new($colors_demo, 'borderwidth'=>10) {|w| colors_lbox.pack('side'=>'left', 'expand'=>1, 'fill'=>'both') }.pack('side'=>'top', 'expand'=>'yes', 'fill'=>'y') -colors_lbox.bind('Double-1', proc{TkPalette.setPalette TkSelection.get}) +#colors_lbox.bind('Double-1', proc{TkPalette.setPalette TkSelection.get}) +colors_lbox.bind('Double-1', proc{ + begin + TkPalette.setPalette TkSelection.get + rescue => e + p e + Tk.tk_call_without_enc('destroy', '.___tk_set_palette') + end + }) ins_data = [ 'gray60','gray70','gray80','gray85','gray90','gray95', diff --git a/ext/tk/sample/demos-en/combo.rb b/ext/tk/sample/demos-en/combo.rb new file mode 100644 index 0000000000..0907d9e8ec --- /dev/null +++ b/ext/tk/sample/demos-en/combo.rb @@ -0,0 +1,96 @@ +# combo.rb -- +# +# This demonstration script creates several combobox widgets. +# +# based on "Id: combo.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp" + +if defined?($combo_demo) && $combo_demo + $combo_demo.destroy + $combo_demo = nil +end + +$combo_demo = TkToplevel.new {|w| + title("Combobox Demonstration") + iconname("combo") + positionWindow(w) +} + +base_frame = TkFrame.new($combo_demo).pack(:fill=>:both, :expand=>true) + +Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'5i', :justify=>:left, + :text=><:top, :fill=>:x) +Three different combo-boxes are displayed below. \ +You can add characters to the first \ +one by pointing, clicking and typing, just as with an entry; pressing \ +Return will cause the current value to be added to the list that is \ +selectable from the drop-down list, and you can choose other values \ +by pressing the Down key, using the arrow keys to pick another one, \ +and pressing Return again. The second combo-box is fixed to a \ +particular value, and cannot be modified at all. The third one only \ +allows you to select values from its drop-down list of Australian \ +cities. +EOL + +## variables +firstValue = TkVariable.new +secondValue = TkVariable.new +ozCity = TkVariable.new + +## See Code / Dismiss buttons +Ttk::Frame.new(base_frame) {|frame| + sep = Ttk::Separator.new(frame) + Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) + TkGrid('x', + Ttk::Button.new(frame, :text=>'See Variables', + :image=>$image['view'], :compound=>:left, + :command=>proc{ + showVars(base_frame, + ['firstVariable', firstValue], + ['secondVariable', secondValue], + ['ozCity', ozCity]) + }), + Ttk::Button.new(frame, :text=>'See Code', + :image=>$image['view'], :compound=>:left, + :command=>proc{showCode 'combo'}), + Ttk::Button.new(frame, :text=>'Dismiss', + :image=>$image['delete'], :compound=>:left, + :command=>proc{ + $combo_demo.destroy + $combo_demo = nil + }), + :padx=>4, :pady=>4) + grid_columnconfigure(0, :weight=>1) + pack(:side=>:bottom, :fill=>:x) +} + +frame = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true) + +australianCities = [ + 'Canberra', 'Sydney', 'Melbourne', 'Perth', 'Adelaide', 'Brisbane', + 'Hobart', 'Darwin', 'Alice Springs' +] + + +secondValue.value = 'unchangable' +ozCity.value = 'Sydney' + +Tk.pack(Ttk::Labelframe.new(frame, :text=>'Fully Editable'){|f| + Ttk::Combobox.new(f, :textvariable=>firstValue){|b| + b.bind('Return', '%W'){|w| + w.values <<= w.value unless w.values.include?(w.value) + } + }.pack(:pady=>5, :padx=>10) + }, + + Ttk::LabelFrame.new(frame, :text=>'Disabled'){|f| + Ttk::Combobox.new(f, :textvariable=>secondValue, :state=>:disabled) . + pack(:pady=>5, :padx=>10) + }, + + Ttk::LabelFrame.new(frame, :text=>'Defined List Only'){|f| + Ttk::Combobox.new(f, :textvariable=>ozCity, :state=>:readonly, + :values=>australianCities) . + pack(:pady=>5, :padx=>10) + }, + + :side=>:top, :pady=>5, :padx=>10) diff --git a/ext/tk/sample/demos-en/cscroll.rb b/ext/tk/sample/demos-en/cscroll.rb index 0838dfbe08..259ed3bd8c 100644 --- a/ext/tk/sample/demos-en/cscroll.rb +++ b/ext/tk/sample/demos-en/cscroll.rb @@ -19,14 +19,16 @@ $cscroll_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($cscroll_demo).pack(:fill=>:both, :expand=>true) + # label -TkLabel.new($cscroll_demo, 'font'=>$font, 'wraplength'=>'4i', +TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left', 'text'=>"This window displays a canvas widget that can be scrolled either using the scrollbars or by dragging with button 2 in the canvas. If you click button 1 on one of the rectangles, its indices will be printed on stdout."){ pack('side'=>'top') } # frame -$cscroll_buttons = TkFrame.new($cscroll_demo) {|frame| +$cscroll_buttons = TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -45,7 +47,7 @@ $cscroll_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # frame unless $tk_version =~ /^4\.[01]/ - $cscroll_grid = TkFrame.new($cscroll_demo) { + $cscroll_grid = TkFrame.new(base_frame) { pack('expand'=>'yes', 'fill'=>'both', 'padx'=>1, 'pady'=>1) } TkGrid.rowconfigure($cscroll_grid, 0, 'weight'=>1, 'minsize'=>0) @@ -53,7 +55,7 @@ unless $tk_version =~ /^4\.[01]/ end # canvas -$cscroll_canvas = TkCanvas.new($cscroll_demo, +$cscroll_canvas = TkCanvas.new(base_frame, 'relief'=>'sunken', 'borderwidth'=>2, 'scrollregion'=>['-11c', '-11c', '50c', '20c'] ) {|c| @@ -64,7 +66,7 @@ $cscroll_canvas = TkCanvas.new($cscroll_demo, 'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news') end - TkScrollbar.new($cscroll_demo, 'command'=>proc{|*args| c.yview(*args)}) {|vs| + TkScrollbar.new(base_frame, 'command'=>proc{|*args| c.yview(*args)}) {|vs| c.yscrollcommand(proc{|first,last| vs.set first,last}) if $tk_version =~ /^4\.[01]/ pack('side'=>'right', 'fill'=>'y') @@ -74,7 +76,7 @@ $cscroll_canvas = TkCanvas.new($cscroll_demo, end } - TkScrollbar.new($cscroll_demo, 'orient'=>'horiz', + TkScrollbar.new(base_frame, 'orient'=>'horiz', 'command'=>proc{|*args| c.xview(*args)}) {|hs| c.xscrollcommand(proc{|first,last| hs.set first,last}) if $tk_version =~ /^4\.[01]/ diff --git a/ext/tk/sample/demos-en/ctext.rb b/ext/tk/sample/demos-en/ctext.rb index 8c10880ed6..01374b0321 100644 --- a/ext/tk/sample/demos-en/ctext.rb +++ b/ext/tk/sample/demos-en/ctext.rb @@ -19,8 +19,10 @@ $ctext_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($ctext_demo).pack(:fill=>:both, :expand=>true) + # label -TkLabel.new($ctext_demo, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left', +TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left', 'text'=>"This window displays a string of text to demonstrate the text facilities of canvas widgets. You can click in the boxes to adjust the position of the text relative to its positioning point or change its justification. The text also supports the following simple bindings for editing: 1. You can point, click, and type. 2. You can also select with button 1. @@ -33,7 +35,7 @@ TkLabel.new($ctext_demo, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left', } # frame -$ctext_buttons = TkFrame.new($ctext_demo) {|frame| +$ctext_buttons = TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -51,7 +53,7 @@ $ctext_buttons = TkFrame.new($ctext_demo) {|frame| $ctext_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # canvas -$ctext_canvas = TkCanvas.new($ctext_demo, 'relief'=>'flat', +$ctext_canvas = TkCanvas.new(base_frame, 'relief'=>'flat', 'borderwidth'=>0, 'width'=>500, 'height'=>350) $ctext_canvas.pack('side'=>'top', 'expand'=>'yes', 'fill'=>'both') diff --git a/ext/tk/sample/demos-en/entry1.rb b/ext/tk/sample/demos-en/entry1.rb index 29bc693395..6f5b10fb71 100644 --- a/ext/tk/sample/demos-en/entry1.rb +++ b/ext/tk/sample/demos-en/entry1.rb @@ -15,8 +15,10 @@ $entry1_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($entry1_demo).pack(:fill=>:both, :expand=>true) + # label -msg = TkLabel.new($entry1_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '5i' justify 'left' @@ -25,7 +27,7 @@ msg = TkLabel.new($entry1_demo) { msg.pack('side'=>'top') # frame -TkFrame.new($entry1_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -42,9 +44,9 @@ TkFrame.new($entry1_demo) {|frame| }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # -e1 = TkEntry.new($entry1_demo, 'relief'=>'sunken') -e2 = TkEntry.new($entry1_demo, 'relief'=>'sunken') -e3 = TkEntry.new($entry1_demo, 'relief'=>'sunken') +e1 = TkEntry.new(base_frame, 'relief'=>'sunken') +e2 = TkEntry.new(base_frame, 'relief'=>'sunken') +e3 = TkEntry.new(base_frame, 'relief'=>'sunken') [e1,e2,e3].each{|w| w.pack('side'=>'top', 'padx'=>10, 'pady'=>5, 'fill'=>'x')} # diff --git a/ext/tk/sample/demos-en/entry2.rb b/ext/tk/sample/demos-en/entry2.rb index d4e58d7dd5..d67d04b56d 100644 --- a/ext/tk/sample/demos-en/entry2.rb +++ b/ext/tk/sample/demos-en/entry2.rb @@ -19,8 +19,10 @@ $entry2_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($entry2_demo).pack(:fill=>:both, :expand=>true) + # label -msg = TkLabel.new($entry2_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '5i' justify 'left' @@ -29,7 +31,7 @@ msg = TkLabel.new($entry2_demo) { msg.pack('side'=>'top') # frame -TkFrame.new($entry2_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -46,7 +48,7 @@ TkFrame.new($entry2_demo) {|frame| }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # frame -TkFrame.new($entry2_demo, 'borderwidth'=>10) {|w| +TkFrame.new(base_frame, 'borderwidth'=>10) {|w| # entry 1 s1 = TkScrollbar.new(w, 'relief'=>'sunken', 'orient'=>'horiz') e1 = TkEntry.new(w, 'relief'=>'sunken') { diff --git a/ext/tk/sample/demos-en/entry3.rb b/ext/tk/sample/demos-en/entry3.rb index 68f77a0d48..f7df3a5653 100644 --- a/ext/tk/sample/demos-en/entry3.rb +++ b/ext/tk/sample/demos-en/entry3.rb @@ -17,7 +17,9 @@ $entry3_demo = TkToplevel.new {|w| positionWindow(w) } -TkLabel.new($entry3_demo, +base_frame = TkFrame.new($entry3_demo).pack(:fill=>:both, :expand=>true) + +TkLabel.new(base_frame, :font=>$font, :wraplength=>'5i', :justify=>:left, :text=><:top) Four different entries are displayed below. You can add characters \ @@ -34,7 +36,7 @@ characters (silently ignoring further ones), and displaying them as \ asterisk characters. EOL -TkFrame.new($entry3_demo){|f| +TkFrame.new(base_frame){|f| pack(:side=>:bottom, :fill=>:x, :pady=>'2m') TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{ @@ -60,23 +62,41 @@ TkFrame.new($entry3_demo){|f| # count - Counter to control the number of times flashed def focusAndFlash(widget, fg, bg, count=5) return if count <= 0 - TkTimer.new(200, count, - proc{widget.configure(:foreground=>bg, :background=>fg)}, - proc{widget.configure(:foreground=>fg, :background=>bg)} - ).start + if fg && !fg.empty? && bg && !bg.empty? + TkTimer.new(200, count, + proc{widget.configure(:foreground=>bg, :background=>fg)}, + proc{widget.configure(:foreground=>fg, :background=>bg)} + ).start + else + # TkTimer.new(150, 3){Tk.bell}.start + Tk.bell + TkTimer.new(200, count, + proc{widget.configure(:foreground=>'white', + :background=>'black')}, + proc{widget.configure(:foreground=>'black', + :background=>'white')} + ).at_end{begin + widget.configure(:foreground=>fg, + :background=>bg) + rescue + # ignore + end}.start + end widget.focus(true) end -l1 = TkLabelFrame.new($entry3_demo, :text=>"Integer Entry") +l1 = TkLabelFrame.new(base_frame, :text=>"Integer Entry") TkEntry.new(l1, :validate=>:focus, :vcmd=>[ proc{|s| s == '' || /^[+-]?\d+$/ =~ s }, '%P' ]) {|e| - invalidcommand [proc{|w| focusAndFlash(w, e.fg, e.bg)}, '%W'] + fg = e.foreground + bg = e.background + invalidcommand [proc{|w| focusAndFlash(w, fg, bg)}, '%W'] pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m') } -l2 = TkLabelFrame.new($entry3_demo, :text=>"Length-Constrained Entry") +l2 = TkLabelFrame.new(base_frame, :text=>"Length-Constrained Entry") TkEntry.new(l2, :validate=>:key, :invcmd=>proc{Tk.bell}, :vcmd=>[proc{|s| s.length < 10}, '%P'] ).pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m') @@ -158,14 +178,14 @@ def validatePhoneChange(widget, vmode, idx, char) widget.insert(idx, $phoneNumberMap[char] || char) Tk.after_idle(proc{phoneSkipRight(widget, -1)}) return true - # Tk.update(true) # Don't work 'update' inter validation callback. - # It depends on Tcl/Tk side (tested on Tcl/Tk8.5a1). + # Tk.update(true) # <- Don't work 'update' inter validation callback. + # It depends on Tcl/Tk side (tested on Tcl/Tk8.5a1). end return false end -l3 = TkLabelFrame.new($entry3_demo, :text=>"US Phone-Number Entry") +l3 = TkLabelFrame.new(base_frame, :text=>"US Phone-Number Entry") TkEntry.new(l3, :validate=>:key, :invcmd=>proc{Tk.bell}, :textvariable=>entry3content, :vcmd=>[ @@ -184,14 +204,14 @@ TkEntry.new(l3, :validate=>:key, :invcmd=>proc{Tk.bell}, pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m') } -l4 = TkLabelFrame.new($entry3_demo, :text=>"Password Entry") +l4 = TkLabelFrame.new(base_frame, :text=>"Password Entry") TkEntry.new(l4, :validate=>:key, :show=>'*', :vcmd=>[ proc{|s| s.length <= 8}, '%P' ]).pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m') -TkFrame.new($entry3_demo){|f| +TkFrame.new(base_frame){|f| lower TkGrid.configure(l1, l2, :in=>f, :padx=>'3m', :pady=>'1m', :sticky=>:ew) TkGrid.configure(l3, l4, :in=>f, :padx=>'3m', :pady=>'1m', :sticky=>:ew) diff --git a/ext/tk/sample/demos-en/filebox.rb b/ext/tk/sample/demos-en/filebox.rb index 36b19de557..676c347409 100644 --- a/ext/tk/sample/demos-en/filebox.rb +++ b/ext/tk/sample/demos-en/filebox.rb @@ -17,12 +17,14 @@ $filebox_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($filebox_demo).pack(:fill=>:both, :expand=>true) + # label -TkLabel.new($filebox_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left', +TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left', 'text'=>"Enter a file name in the entry box or click on the \"Browse\" buttons to select a file name using the file selection dialog.").pack('side'=>'top') # frame -TkFrame.new($filebox_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -40,7 +42,7 @@ TkFrame.new($filebox_demo) {|frame| # frame ['open', 'save'].each{|type| - TkFrame.new($filebox_demo) {|f| + TkFrame.new(base_frame) {|f| TkLabel.new(f, 'text'=>"Select a file to #{type}: ", 'anchor'=>'e')\ .pack('side'=>'left') @@ -48,7 +50,7 @@ TkFrame.new($filebox_demo) {|frame| pack('side'=>'left', 'expand'=>'yes', 'fill'=>'x') TkButton.new(f, 'text'=>'Browse ...', - 'command'=>proc{fileDialog $filebox_demo,e,type})\ + 'command'=>proc{fileDialog base_frame,e,type})\ .pack('side'=>'left') } @@ -58,7 +60,7 @@ TkFrame.new($filebox_demo) {|frame| $tk_strictMotif = TkVarAccess.new('tk_strictMotif') if ($tk_platform['platform'] == 'unix') - TkCheckButton.new($filebox_demo, + TkCheckButton.new(base_frame, 'text'=>'Use Motif Style Dialog', 'variable'=>$tk_strictMotif, 'onvalue'=>1, 'offvalue'=>0 ).pack('anchor'=>'c') @@ -91,7 +93,10 @@ def fileDialog(w,ent,operation) if file != "" ent.delete 0, 'end' ent.insert 0, file - ent.xview 'end' + # ent.xview 'end' + Tk.update_idletasks # need this for Tk::Tile::Entry + # (to find right position of 'xview'). + ent.xview(ent.index('end')) end end diff --git a/ext/tk/sample/demos-en/floor.rb b/ext/tk/sample/demos-en/floor.rb index 53adcf96b6..7023f2a72e 100644 --- a/ext/tk/sample/demos-en/floor.rb +++ b/ext/tk/sample/demos-en/floor.rb @@ -1590,14 +1590,16 @@ $floor_demo = TkToplevel.new {|w| minsize(100,100) } +base_frame = TkFrame.new($floor_demo).pack(:fill=>:both, :expand=>true) + # label -TkLabel.new($floor_demo, 'font'=>$font, 'wraplength'=>'8i', 'justify'=>'left', +TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'8i', 'justify'=>'left', 'text'=>"This window contains a canvas widget showing the floorplan of Digital Equipment Corporation's Western Research Laboratory. It has three levels. At any given time one of the levels is active, meaning that you can see its room structure. To activate a level, click the left mouse button anywhere on it. As the mouse moves over the active level, the room under the mouse lights up and its room number appears in the \"Room:\" entry. You can also type a room number in the entry and the room will light up."){ pack('side'=>'top') } # frame -$floor_buttons = TkFrame.new($floor_demo) {|frame| +$floor_buttons = TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -1620,17 +1622,17 @@ $floorItems = {} # canvas if $tk_version =~ /^4\.[01]/ - $floor_canvas_frame = TkFrame.new($floor_demo,'bd'=>2,'relief'=>'sunken', + $floor_canvas_frame = TkFrame.new(base_frame,'bd'=>2,'relief'=>'sunken', 'highlightthickness'=>2) $floor_canvas = TkCanvas.new($floor_canvas_frame, 'width'=>900, 'height'=>500, 'borderwidth'=>0, 'highlightthickness'=>0) {|c| - TkScrollbar.new($floor_demo, 'orient'=>'horiz', + TkScrollbar.new(base_frame, 'orient'=>'horiz', 'command'=>proc{|*args| c.xview(*args)}){|hs| c.xscrollcommand(proc{|first,last| hs.set first,last}) pack('side'=>'bottom', 'fill'=>'x') } - TkScrollbar.new($floor_demo, 'command'=>proc{|*args| c.yview(*args)}){|vs| + TkScrollbar.new(base_frame, 'command'=>proc{|*args| c.yview(*args)}){|vs| c.yscrollcommand(proc{|first,last| vs.set first,last}) pack('side'=>'right', 'fill'=>'y') } @@ -1639,7 +1641,7 @@ if $tk_version =~ /^4\.[01]/ $floor_canvas.pack('expand'=>'yes', 'fill'=>'both') else - TkFrame.new($floor_demo) {|f| + TkFrame.new(base_frame) {|f| pack('side'=>'top', 'fill'=>'both', 'expand'=>'yes') h = TkScrollbar.new(f, 'highlightthickness'=>0, 'orient'=>'horizontal') diff --git a/ext/tk/sample/demos-en/floor2.rb b/ext/tk/sample/demos-en/floor2.rb index efaf9e250d..88b07aeee4 100644 --- a/ext/tk/sample/demos-en/floor2.rb +++ b/ext/tk/sample/demos-en/floor2.rb @@ -1590,14 +1590,16 @@ $floor2_demo = TkToplevel.new {|w| minsize(100,100) } +base_frame = TkFrame.new($floor2_demo).pack(:fill=>:both, :expand=>true) + # label -TkLabel.new($floor2_demo, 'font'=>$font, 'wraplength'=>'8i', 'justify'=>'left', +TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'8i', 'justify'=>'left', 'text'=>"This window contains a canvas widget showing the floorplan of Digital Equipment Corporation's Western Research Laboratory. It has three levels. At any given time one of the levels is active, meaning that you can see its room structure. To activate a level, click the left mouse button anywhere on it. As the mouse moves over the active level, the room under the mouse lights up and its room number appears in the \"Room:\" entry. You can also type a room number in the entry and the room will light up."){ pack('side'=>'top') } # frame -$floor2_buttons = TkFrame.new($floor2_demo) {|frame| +$floor2_buttons = TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -1620,17 +1622,17 @@ $floorItems2 = {} # canvas if $tk_version =~ /^4\.[01]/ - $floor2_canvas_frame = TkFrame.new($floor2_demo,'bd'=>2,'relief'=>'sunken', + $floor2_canvas_frame = TkFrame.new(base_frame,'bd'=>2,'relief'=>'sunken', 'highlightthickness'=>2) $floor2_canvas = TkCanvas.new($floor2_canvas_frame, 'width'=>900, 'height'=>500, 'borderwidth'=>0, 'highlightthickness'=>0) {|c| - TkScrollbar.new($floor2_demo, 'orient'=>'horiz', + TkScrollbar.new(base_frame, 'orient'=>'horiz', 'command'=>proc{|*args| c.xview(*args)}){|hs| c.xscrollcommand(proc{|first,last| hs.set first,last}) pack('side'=>'bottom', 'fill'=>'x') } - TkScrollbar.new($floor2_demo, 'command'=>proc{|*args| c.yview(*args)}){|vs| + TkScrollbar.new(base_frame, 'command'=>proc{|*args| c.yview(*args)}){|vs| c.yscrollcommand(proc{|first,last| vs.set first,last}) pack('side'=>'right', 'fill'=>'y') } @@ -1639,7 +1641,7 @@ if $tk_version =~ /^4\.[01]/ $floor2_canvas.pack('expand'=>'yes', 'fill'=>'both') else - TkFrame.new($floor2_demo) {|f| + TkFrame.new(base_frame) {|f| pack('side'=>'top', 'fill'=>'both', 'expand'=>'yes') h = TkScrollbar.new(f, 'highlightthickness'=>0, 'orient'=>'horizontal') diff --git a/ext/tk/sample/demos-en/form.rb b/ext/tk/sample/demos-en/form.rb index dbb14302dc..3119752b1c 100644 --- a/ext/tk/sample/demos-en/form.rb +++ b/ext/tk/sample/demos-en/form.rb @@ -15,8 +15,10 @@ $form_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($form_demo).pack(:fill=>:both, :expand=>true) + # label -msg = TkLabel.new($form_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -25,7 +27,7 @@ msg = TkLabel.new($form_demo) { msg.pack('side'=>'top', 'fill'=>'x') # frame -TkFrame.new($form_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -44,7 +46,7 @@ TkFrame.new($form_demo) {|frame| # entry form_data = [] (1..5).each{|i| - f = TkFrame.new($form_demo, 'bd'=>2) + f = TkFrame.new(base_frame, 'bd'=>2) e = TkEntry.new(f, 'relief'=>'sunken', 'width'=>40) l = TkLabel.new(f) e.pack('side'=>'right') diff --git a/ext/tk/sample/demos-en/goldberg.rb b/ext/tk/sample/demos-en/goldberg.rb index 8d3f6d14f7..c6fa37c09c 100644 --- a/ext/tk/sample/demos-en/goldberg.rb +++ b/ext/tk/sample/demos-en/goldberg.rb @@ -54,6 +54,8 @@ $goldberg_demo = TkToplevel.new {|w| # positionWindow(w) } +base_frame = TkFrame.new($goldberg_demo).pack(:fill=>:both, :expand=>true) + =begin # label msg = TkLabel.new($goldberg_demo) { @@ -175,7 +177,8 @@ class TkGoldberg_Demo do_ctrl_frame do_detail_frame - msg = TkLabel.new(@parent, :bg=>@C['bg'], :fg=>'white') { + # msg = TkLabel.new(@parent, :bg=>@C['bg'], :fg=>'white') { + msg = Tk::Label.new(@parent, :bg=>@C['bg'], :fg=>'white') { font 'Arial 10' wraplength 600 justify 'left' @@ -185,7 +188,8 @@ class TkGoldberg_Demo frame = TkFrame.new(@parent, :bg=>@C['bg']) - TkButton.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) { + # TkButton.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) { + Tk::Button.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) { text 'Dismiss' command proc{ tmppath = $goldberg_demo @@ -194,12 +198,14 @@ class TkGoldberg_Demo } }.pack('side'=>'left') - TkButton.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) { + # TkButton.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) { + Tk::Button.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) { text 'See Code' command proc{showCode 'goldberg'} }.pack('side'=>'left', 'padx'=>5) - @show = TkButton.new(frame, :text=>'>>', :command=>proc{show_ctrl}, + # @show = TkButton.new(frame, :text=>'>>', :command=>proc{show_ctrl}, + @show = Tk::Button.new(frame, :text=>'>>', :command=>proc{show_ctrl}, :bg=>@C['bg'], :activebackground=>@C['bg']) @show.pack('side'=>'left') frame.place(:in=>@canvas, :relx=>1, :rely=>0, :anchor=>:ne) @@ -208,10 +214,11 @@ class TkGoldberg_Demo end def do_ctrl_frame - @start = TkButton.new(@parent, :text=>'Start', :bd=>6, + @start = Tk::Button.new(@parent, :text=>'Start', :bd=>6, :command=>proc{do_button(0)}) - @start.font(@start['font'].weight('bold')) - font = @start['font'] + if font = @start['font'] + @start.font(font.weight('bold')) + end @pause = TkCheckbutton.new(@parent, :text=>'Pause', :font=>font, :command=>proc{do_button(1)}, :relief=>:raised, @@ -1996,4 +2003,4 @@ class TkGoldberg_Demo end end -TkGoldberg_Demo.new($goldberg_demo) +TkGoldberg_Demo.new(base_frame) diff --git a/ext/tk/sample/demos-en/hscale.rb b/ext/tk/sample/demos-en/hscale.rb index 743c4b4852..e660216967 100644 --- a/ext/tk/sample/demos-en/hscale.rb +++ b/ext/tk/sample/demos-en/hscale.rb @@ -11,8 +11,9 @@ $hscale_demo = TkToplevel.new {|w| } positionWindow($hscale_demo) +base_frame = TkFrame.new($hscale_demo).pack(:fill=>:both, :expand=>true) -msg = TkLabel.new($hscale_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '3.5i' justify 'left' @@ -20,7 +21,7 @@ msg = TkLabel.new($hscale_demo) { } msg.pack('side'=>'top') -TkFrame.new($hscale_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc { @@ -36,7 +37,18 @@ TkFrame.new($hscale_demo) {|frame| }.pack('side'=>'left', 'expand'=>'yes') }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') -TkFrame.new($hscale_demo) {|frame| + +def setWidth(w, width) + width = width + 21 + x2 = width - 30 + if x2 < 21 + x2 = 21 + end + w.coords 'poly',20,15,20,35,x2,35,x2,45,width,25,x2,5,x2,15,20,15 + w.coords 'line',20,15,20,35,x2,35,x2,45,width,25,x2,5,x2,15,20,15 +end + +TkFrame.new(base_frame) {|frame| canvas = TkCanvas.new(frame) {|c| width 50 height 50 @@ -61,14 +73,3 @@ TkFrame.new($hscale_demo) {|frame| }.pack('side'=>'bottom', 'expand'=>'yes', 'anchor'=>'n') scale.set 75 }.pack('side'=>'top', 'fill'=>'x') - -def setWidth(w, width) - width = width + 21 - x2 = width - 30 - if x2 < 21 - x2 = 21 - end - w.coords 'poly',20,15,20,35,x2,35,x2,45,width,25,x2,5,x2,15,20,15 - w.coords 'line',20,15,20,35,x2,35,x2,45,width,25,x2,5,x2,15,20,15 -end - diff --git a/ext/tk/sample/demos-en/icon.rb b/ext/tk/sample/demos-en/icon.rb index 58aca2df07..a3921d2333 100644 --- a/ext/tk/sample/demos-en/icon.rb +++ b/ext/tk/sample/demos-en/icon.rb @@ -19,8 +19,10 @@ $icon_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($icon_demo).pack(:fill=>:both, :expand=>true) + # label -msg = TkLabel.new($icon_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '5i' justify 'left' @@ -29,7 +31,7 @@ msg = TkLabel.new($icon_demo) { msg.pack('side'=>'top') # frame -TkFrame.new($icon_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -63,16 +65,18 @@ TkBitmapImage.new('file'=>[$demo_dir,'..', letters = TkVariable.new # frame -TkFrame.new($icon_demo, 'borderwidth'=>10){|w| +TkFrame.new(base_frame, 'borderwidth'=>10){|w| TkFrame.new(w) {|f| - TkRadioButton.new(f){ + # TkRadioButton.new(f){ + Tk::RadioButton.new(f){ bitmap '@' + [$demo_dir,'..', 'images','letters.xbm'].join(File::Separator) variable letters value 'full' }.pack('side'=>'top', 'expand'=>'yes') - TkRadioButton.new(f){ + # TkRadioButton.new(f){ + Tk::RadioButton.new(f){ bitmap '@' + [$demo_dir,'..', 'images','noletter.xbm'].join(File::Separator) variable letters @@ -81,14 +85,16 @@ TkFrame.new($icon_demo, 'borderwidth'=>10){|w| }.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'5m') - TkCheckButton.new(w) { + # TkCheckButton.new(w) { + Tk::CheckButton.new(w) { image flagdown selectimage flagup indicatoron 0 selectcolor self['background'] }.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'5m') - TkCheckButton.new(w) { + # TkCheckButton.new(w) { + Tk::CheckButton.new(w) { bitmap '@' + [$demo_dir,'..', 'images','letters.xbm'].join(File::Separator) indicatoron 0 diff --git a/ext/tk/sample/demos-en/image1.rb b/ext/tk/sample/demos-en/image1.rb index 05c9705c9c..a9072bb308 100644 --- a/ext/tk/sample/demos-en/image1.rb +++ b/ext/tk/sample/demos-en/image1.rb @@ -18,8 +18,10 @@ $image1_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($image1_demo).pack(:fill=>:both, :expand=>true) + # label -msg = TkLabel.new($image1_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -28,7 +30,7 @@ msg = TkLabel.new($image1_demo) { msg.pack('side'=>'top') # frame -TkFrame.new($image1_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -54,7 +56,10 @@ TkPhotoImage.new('file'=>[$demo_dir,'..', 'images','earthris.gif'].join(File::Separator)) # label -[ TkLabel.new($image1_demo, 'image'=>image1a, 'bd'=>1, 'relief'=>'sunken'), - TkLabel.new($image1_demo, 'image'=>image1b, 'bd'=>1, 'relief'=>'sunken') +#[ TkLabel.new(base_frame, 'image'=>image1a, 'bd'=>1, 'relief'=>'sunken'), +# TkLabel.new(base_frame, 'image'=>image1b, 'bd'=>1, 'relief'=>'sunken') +#].each{|w| w.pack('side'=>'top', 'padx'=>'.5m', 'pady'=>'.5m')} +[ Tk::Label.new(base_frame, 'image'=>image1a, 'bd'=>1, 'relief'=>'sunken'), + Tk::Label.new(base_frame, 'image'=>image1b, 'bd'=>1, 'relief'=>'sunken') ].each{|w| w.pack('side'=>'top', 'padx'=>'.5m', 'pady'=>'.5m')} diff --git a/ext/tk/sample/demos-en/image2.rb b/ext/tk/sample/demos-en/image2.rb index 1aff7173be..1975dd6b02 100644 --- a/ext/tk/sample/demos-en/image2.rb +++ b/ext/tk/sample/demos-en/image2.rb @@ -19,8 +19,10 @@ $image2_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($image2_demo).pack(:fill=>:both, :expand=>true) + # label -msg = TkLabel.new($image2_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -29,7 +31,7 @@ msg = TkLabel.new($image2_demo) { msg.pack('side'=>'top') # frame -TkFrame.new($image2_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -53,21 +55,21 @@ $dirName = TkVariable.new([$demo_dir,'..','images'].join(File::Separator)) $image2a = TkPhotoImage.new # -TkLabel.new($image2_demo, 'text'=>'Directory:')\ +TkLabel.new(base_frame, 'text'=>'Directory:')\ .pack('side'=>'top', 'anchor'=>'w') -image2_e = TkEntry.new($image2_demo) { +image2_e = TkEntry.new(base_frame) { width 30 textvariable $dirName }.pack('side'=>'top', 'anchor'=>'w') -TkFrame.new($image2_demo, 'height'=>'3m', 'width'=>20)\ +TkFrame.new(base_frame, 'height'=>'3m', 'width'=>20)\ .pack('side'=>'top', 'anchor'=>'w') -TkLabel.new($image2_demo, 'text'=>'File:')\ +TkLabel.new(base_frame, 'text'=>'File:')\ .pack('side'=>'top', 'anchor'=>'w') -TkFrame.new($image2_demo){|w| +TkFrame.new(base_frame){|w| s = TkScrollbar.new(w) l = TkListbox.new(w) { width 20 @@ -86,9 +88,9 @@ TkFrame.new($image2_demo){|w| }.pack('side'=>'top', 'anchor'=>'w') # image -[ TkFrame.new($image2_demo, 'height'=>'3m', 'width'=>20), - TkLabel.new($image2_demo, 'text'=>'Image:'), - TkLabel.new($image2_demo, 'image'=>$image2a) +[ TkFrame.new(base_frame, 'height'=>'3m', 'width'=>20), + TkLabel.new(base_frame, 'text'=>'Image:'), + TkLabel.new(base_frame, 'image'=>$image2a) ].each{|w| w.pack('side'=>'top', 'anchor'=>'w')} # diff --git a/ext/tk/sample/demos-en/image3.rb b/ext/tk/sample/demos-en/image3.rb index e46d3796f2..43afab7ecd 100644 --- a/ext/tk/sample/demos-en/image3.rb +++ b/ext/tk/sample/demos-en/image3.rb @@ -19,27 +19,29 @@ $image3_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($image3_demo).pack(:fill=>:both, :expand=>true) + # -def loadDir(w) +def loadDir3(w) w.delete(0,'end') Dir.glob([$dirName,'*'].join(File::Separator)).sort.each{|f| w.insert('end',File.basename(f)) } end -# selectAndLoadDir -- +# selectAndLoadDir3 -- # This procedure pops up a dialog to ask for a directory to load into # the listobx and (if the user presses OK) reloads the directory # listbox from the directory named in the demo's entry. # # Arguments: # w - Name of the toplevel window of the demo. -def selectAndLoadDir(w, lbox) +def selectAndLoadDir3(w, lbox) dir = Tk.chooseDirectory(:initialdir=>$dirName.value, :parent=>w, :mustexist=>true) if dir.length > 0 $dirName.value = dir - loadDir(lbox) + loadDir3(lbox) end end @@ -49,7 +51,7 @@ end # label -msg = TkLabel.new($image3_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -58,7 +60,7 @@ msg = TkLabel.new($image3_demo) { msg.pack('side'=>'top') # frame -TkFrame.new($image3_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -86,11 +88,11 @@ end $image3a = TkPhotoImage.new # -image3_f = TkFrame.new($image3_demo).pack(:fill=>:both, :expand=>true) +image3_f = TkFrame.new(base_frame).pack(:fill=>:both, :expand=>true) -image3_df = TkLabelFrame.new($image3_demo, :text=>'Directory:') +image3_df = TkLabelFrame.new(base_frame, :text=>'Directory:') -image3_ff = TkLabelFrame.new($image3_demo, :text=>'File:', +image3_ff = TkLabelFrame.new(base_frame, :text=>'File:', :padx=>'2m', :pady=>'2m') image3_lbx = TkListbox.new(image3_ff, :width=>20, :height=>10) { pack(:side=>:left, :fill=>:y, :expand=>true) @@ -102,16 +104,17 @@ image3_lbx = TkListbox.new(image3_ff, :width=>20, :height=>10) { image3_ent = TkEntry.new(image3_df, :width=>30, :textvariable=>$dirName){ pack(:side=>:left, :fill=>:both, :padx=>'2m', :pady=>'2m', :expand=>true) - bind('Return', proc{loadDir(image3_lbx)}) + bind('Return', proc{loadDir3(image3_lbx)}) } TkButton.new(image3_df, :pady=>0, :padx=>'2m', :text=>"Select Dir.", - :command=>proc{selectAndLoadDir(image3_ent, image3_lbx)}) { + :command=>proc{selectAndLoadDir3(image3_ent, image3_lbx)}) { pack(:side=>:left, :fill=>:y, :padx=>[0, '2m'], :pady=>'2m') } -image3_if = TkLabelFrame.new($image3_demo, :text=>'Image:') {|f| - TkLabel.new(f, :image=>$image3a).pack(:padx=>'2m', :pady=>'2m') +image3_if = TkLabelFrame.new(base_frame, :text=>'Image:') {|f| + # TkLabel.new(f, :image=>$image3a).pack(:padx=>'2m', :pady=>'2m') + Tk::Label.new(f, :image=>$image3a).pack(:padx=>'2m', :pady=>'2m') } Tk.grid(image3_df, '-', diff --git a/ext/tk/sample/demos-en/items.rb b/ext/tk/sample/demos-en/items.rb index 23191b59b9..3fd44fd4f4 100644 --- a/ext/tk/sample/demos-en/items.rb +++ b/ext/tk/sample/demos-en/items.rb @@ -19,8 +19,10 @@ $items_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($items_demo).pack(:fill=>:both, :expand=>true) + # label -TkLabel.new($items_demo) { +TkLabel.new(base_frame) { font $font wraplength '5i' justify 'left' @@ -28,7 +30,7 @@ TkLabel.new($items_demo) { }.pack('side'=>'top') # frame -TkFrame.new($items_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -46,7 +48,7 @@ TkFrame.new($items_demo) {|frame| # frame cvs = nil -TkFrame.new($items_demo) {|cf| +TkFrame.new(base_frame) {|cf| # canvas cvs = TkCanvas.new(cf) {|c| focus diff --git a/ext/tk/sample/demos-en/knightstour.rb b/ext/tk/sample/demos-en/knightstour.rb new file mode 100644 index 0000000000..618fce5f02 --- /dev/null +++ b/ext/tk/sample/demos-en/knightstour.rb @@ -0,0 +1,271 @@ +# Based on the widget demo of Tcl/Tk8.5.2 +# The following is the original copyright text. +#---------------------------------------------------------------------------- +# Copyright (C) 2008 Pat Thoyts +# +# Calculate a Knight's tour of a chessboard. +# +# This uses Warnsdorff's rule to calculate the next square each +# time. This specifies that the next square should be the one that +# has the least number of available moves. +# +# Using this rule it is possible to get to a position where +# there are no squares available to move into. In this implementation +# this occurs when the starting square is d6. +# +# To solve this fault an enhancement to the rule is that if we +# have a choice of squares with an equal score, we should choose +# the one nearest the edge of the board. +# +# If the call to the Edgemost function is commented out you can see +# this occur. +# +# You can drag the knight to a specific square to start if you wish. +# If you let it repeat then it will choose random start positions +# for each new tour. +#---------------------------------------------------------------------------- +require 'tk' + +class Knights_Tour + # Return a list of accessible squares from a given square + def valid_moves(square) + moves = [] + [ + [-1,-2], [-2,-1], [-2,1], [-1,2], [1,2], [2,1], [2,-1], [1,-2] + ].each{|col_delta, row_delta| + col = (square % 8) + col_delta + row = (square.div(8)) + row_delta + moves << (row * 8 + col) if row > -1 && row < 8 && col > -1 && col < 8 + } + moves + end + + # Return the number of available moves for this square + def check_square(square) + valid_moves(square).find_all{|pos| ! @visited.include?(pos)}.length + end + + # Select the next square to move to. Returns -1 if there are no available + # squares remaining that we can move to. + def next_square(square) + minimum = 9 + nxt = -1 + valid_moves(square).each{|pos| + unless @visited.include?(pos) + cnt = check_square(pos) + if cnt < minimum + minimum = cnt + nxt = pos + elsif cnt == minimum + nxt = edgemost(nxt, pos) + end + end + } + nxt + end + + # Select the square nearest the edge of the board + def edgemost(nxt, pos) + col_A = 3 - ((3.5 - nxt % 8).abs.to_i) + col_B = 3 - ((3.5 - pos % 8).abs.to_i) + row_A = 3 - ((3.5 - nxt.div(8)).abs.to_i) + row_B = 3 - ((3.5 - pos.div(8)).abs.to_i) + (col_A * row_A < col_B * row_B)? nxt : pos + end + + # Display a square number as a standard chess square notation. + def _N(square) + '%c%d' % [(97 + square % 8), (square.div(8) + 1)] + end + + # Perform a Knight's move and schedule the next move. + def move_piece(last, square) + @log.insert(:end, "#{@visited.length}. #{_N last} -> #{_N square}\n", '') + @log.see(:end) + @board.itemconfigure(1+last, :state=>:normal, :outline=>'black') + @board.itemconfigure(1+square, :state=>:normal, :outline=>'red') + @knight.coords(@board.coords(1+square)[0..1]) + @visited << square + if (nxt = next_square(square)) != -1 + @after_id = Tk.after(@delay.numeric){move_piece(square, nxt) rescue nil} + else + @start_btn.state :normal + if @visited.length == 64 + if @initial == square + @log.insert :end, 'Closed tour!' + else + @log.insert :end, "Success\n", {} + Tk.after(@delay.numeric * 2){tour(rand(64))} if @continuous.bool + end + else + @log.insert :end, "FAILED!\n", {} + end + end + end + + # Begin a new tour of the board given a random start position + def tour(square = nil) + @visited.clear + @log.clear + @start_btn.state :disabled + 1.upto(64){|n| + @board.itemconfigure(n, :state=>:disabled, :outline=>'black') + } + unless square + square = @board.find_closest(*(@knight.coords << 0 << 65))[0].to_i - 1 + end + @initial = square + Tk.after_idle{ move_piece(@initial, @initial) rescue nil } + end + + def _stop + Tk.after_cancel(@after_id) rescue nil + end + + def _exit + _stop + $knightstour.destroy + end + + def set_delay(new) + @delay.numeric = new.to_i + end + + def drag_start(w, x, y) + w.dtag('selected') + w.addtag('selected', :withtag, 'current') + @dragging = [x, y] + end + + def drag_motion(w, x, y) + return unless @dragging + w.move('selected', x - @dragging[0], y - @dragging[1]) + @dragging = [x, y] + end + + def drag_end(w, x, y) + square = w.find_closest(x, y, 0, 65) + w.coords('selected', w.coords(square)[0..1]) + w.dtag('selected') + @dragging = nil + end + + def make_SeeDismiss + ## See Code / Dismiss + frame = Ttk::Frame.new($knightstour) + sep = Ttk::Separator.new(frame) + Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) + TkGrid('x', + Ttk::Button.new(frame, :text=>'See Code', + :image=>$image['view'], :compound=>:left, + :command=>proc{showCode 'knightstour'}), + Ttk::Button.new(frame, :text=>'Dismiss', + :image=>$image['delete'], :compound=>:left, + :command=>proc{ + $knightstour.destroy + $knightstour = nil + }), + :padx=>4, :pady=>4) + frame.grid_columnconfigure(0, :weight=>1) + frame + end + + def create_gui(parent = nil) + $knightstour.destroy rescue nil + $knightstour = Tk::Toplevel.new(parent, :title=>"Knight's tour") + $knightstour.withdraw + base_f = Ttk::Frame.new($knightstour) + @board = Tk::Canvas.new(base_f, :width=>240, :height=>240) + @log = Tk::Text.new(base_f, :width=>12, :height=>1, + :font=>'Arial 8', :background=>'white') + scr = @log.yscrollbar(Ttk::Scrollbar.new(base_f)) + + @visited = [] + @delay = TkVariable.new(600) + @continuous = TkVariable.new(false) + + tool_f = Ttk::Frame.new($knightstour) + label = Ttk::Label.new(tool_f, :text=>'Speed') + scale = Ttk::Scale.new(tool_f, :from=>8, :to=>2000, :variable=>@delay, + :command=>proc{|n| set_delay(n)}) + check = Ttk::Checkbutton.new(tool_f, :text=>'Repeat', + :variable=>@continuous) + @start_btn = Ttk::Button.new(tool_f, :text=>'Start', + :command=>proc{tour()}) + @exit_btn = Ttk::Button.new(tool_f, :text=>'Exit', + :command=>proc{_exit()}) + + 7.downto(0){|row| + 0.upto(7){|col| + if ((col & 1) ^ (row & 1)).zero? + fill = 'bisque' + dfill = 'bisque3' + else + fill = 'tan3' + dfill = 'tan4' + end + coords = [col * 30 + 4, row * 30 + 4, col * 30 + 30, row * 30 + 30] + @board.create(TkcRectangle, coords, + :fill=>fill, :disabledfill=>dfill, + :width=>2, :state=>:disabled) + } + } + + @knight_font = TkFont.new(:size=>-24) + @knight = TkcText.new(@board, 0, 0, :font=>@knight_font, + :text=>Tk::UTF8_String.new('\u265e'), + :anchor=>'nw', # :tags=>'knight', + :fill=>'black', :activefill=>'#600000') + @knight.coords(@board.coords(rand(64)+1)[0..1]) + @knight.bind('ButtonPress-1', '%W %x %y'){|w,x,y| drag_start(w,x,y)} + @knight.bind('Motion', '%W %x %y'){|w,x,y| drag_motion(w,x,y)} + @knight.bind('ButtonRelease-1', '%W %x %y'){|w,x,y| drag_end(w,x,y)} + + Tk.grid(@board, @log, scr, :sticky=>'news') + base_f.grid_rowconfigure(0, :weight=>1) + base_f.grid_columnconfigure(0, :weight=>1) + + Tk.grid(base_f, '-', '-', '-', '-', '-', :sticky=>'news') + widgets = [label, scale, check, @start_btn] + sg = nil + unless $RubyTk_WidgetDemo + widgets << @exit_btn + if Tk.windowingsystem != 'aqua' + #widgets.unshift(Ttk::SizeGrip.new(tool_f)) + Ttk::SizeGrip.new(tool_f).pack(:side=>:right, :anchor=>'se') + end + end + Tk.pack(widgets, :side=>:right) + if Tk.windowingsystem == 'aqua' + TkPack.configure(widgets, :padx=>[4, 4], :pady=>[12, 12]) + TkPack.configure(widgets[0], :padx=>[4, 24]) + TkPack.configure(widgets[-1], :padx=>[16, 4]) + end + + Tk.grid(tool_f, '-', '-', '-', '-', '-', :sticky=>'ew') + + if $RubyTk_WidgetDemo + Tk.grid(make_SeeDismiss(), '-', '-', '-', '-', '-', :sticky=>'ew') + end + + $knightstour.grid_rowconfigure(0, :weight=>1) + $knightstour.grid_columnconfigure(0, :weight=>1) + + $knightstour.bind('Control-F2'){TkConsole.show} + $knightstour.bind('Return'){@start_btn.invoke} + $knightstour.bind('Escape'){@exit_btn.invoke} + $knightstour.bind('Destroy'){ _stop } + $knightstour.protocol('WM_DELETE_WINDOW'){ _exit } + + $knightstour.deiconify + $knightstour.tkwait_destroy + end + + def initialize(parent = nil) + create_gui(parent) + end +end + +Tk.root.withdraw unless $RubyTk_WidgetDemo +Thread.new{Tk.mainloop} if __FILE__ == $0 +Knights_Tour.new diff --git a/ext/tk/sample/demos-en/label.rb b/ext/tk/sample/demos-en/label.rb index 55e07a5ebc..91e41e4a22 100644 --- a/ext/tk/sample/demos-en/label.rb +++ b/ext/tk/sample/demos-en/label.rb @@ -19,8 +19,10 @@ $label_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($label_demo).pack(:fill=>:both, :expand=>true) + # label -msg = TkLabel.new($label_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -29,7 +31,7 @@ msg = TkLabel.new($label_demo) { msg.pack('side'=>'top') # frame -TkFrame.new($label_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -47,8 +49,8 @@ TkFrame.new($label_demo) {|frame| }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # label demo -f_left = TkFrame.new($label_demo) -f_right = TkFrame.new($label_demo) +f_left = TkFrame.new(base_frame) +f_right = TkFrame.new(base_frame) [f_left, f_right].each{|w| w.pack('side'=>'left', 'expand'=>'yes', 'padx'=>10, 'pady'=>10, 'fill'=>'both')} @@ -59,7 +61,8 @@ f_right = TkFrame.new($label_demo) TkLabel.new(f_left, 'text'=>'Third label, sunken', 'relief'=>'sunken') ].each{|w| w.pack('side'=>'top', 'expand'=>'yes', 'pady'=>2, 'anchor'=>'w')} -TkLabel.new(f_right) { +# TkLabel.new(f_right) { +Tk::Label.new(f_right) { bitmap('@' + [$demo_dir,'..','images','face.xbm'].join(File::Separator)) borderwidth 2 relief 'sunken' diff --git a/ext/tk/sample/demos-en/labelframe.rb b/ext/tk/sample/demos-en/labelframe.rb index 842a4f6c04..c912ff4c52 100644 --- a/ext/tk/sample/demos-en/labelframe.rb +++ b/ext/tk/sample/demos-en/labelframe.rb @@ -17,8 +17,10 @@ $labelframe_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($labelframe_demo).pack(:fill=>:both, :expand=>true) + # Some information -TkLabel.new($labelframe_demo, +TkLabel.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left, :text=><:top) Labelframes are used to group related widgets together. \ @@ -29,7 +31,7 @@ which supports a 'labelframe' widget. EOL # The bottom buttons -TkFrame.new($labelframe_demo){|f| +TkFrame.new(base_frame){|f| pack(:side=>:bottom, :fill=>:x, :pady=>'2m') TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{ @@ -43,7 +45,7 @@ TkFrame.new($labelframe_demo){|f| } # Demo area -w = TkFrame.new($labelframe_demo).pack(:side=>:bottom, :fill=>:both, +w = TkFrame.new(base_frame).pack(:side=>:bottom, :fill=>:both, :expand=>true) # A group of radiobuttons in a labelframe diff --git a/ext/tk/sample/demos-en/mclist.rb b/ext/tk/sample/demos-en/mclist.rb new file mode 100644 index 0000000000..a849eba515 --- /dev/null +++ b/ext/tk/sample/demos-en/mclist.rb @@ -0,0 +1,117 @@ +# mclist.rb -- +# +# This demonstration script creates a toplevel window containing a Ttk +# tree widget configured as a multi-column listbox. +# +# based on "Id: mclist.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp" + +if defined?($mclist_demo) && $mclist_demo + $mclist_demo.destroy + $mclist_demo = nil +end + +$mclist_demo = TkToplevel.new {|w| + title("Multi-Column List") + iconname("mclist") + positionWindow(w) +} + +base_frame = TkFrame.new($mclist_demo).pack(:fill=>:both, :expand=>true) + +## Explanatory text +Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', + :justify=>:left, :anchor=>'n', :padding=>[10, 2, 10, 6], + :text=><:x) +Ttk is the new Tk themed widget set. \ +One of the widgets it includes is a tree widget, \ +which can be configured to display multiple columns of informational data \ +without displaying the tree itself. \ +This is a simple way to build a listbox that has multiple columns. \ +Clicking on the heading for a column will sort the data by that column. \ +You can also change the width of the columns \ +by dragging the boundary between them. +EOL + +## See Code / Dismiss +Ttk::Frame.new(base_frame) {|frame| + sep = Ttk::Separator.new(frame) + Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) + TkGrid('x', + Ttk::Button.new(frame, :text=>'See Code', + :image=>$image['view'], :compound=>:left, + :command=>proc{showCode 'mclist'}), + Ttk::Button.new(frame, :text=>'Dismiss', + :image=>$image['delete'], :compound=>:left, + :command=>proc{ + $mclist_demo.destroy + $mclist_demo = nil + }), + :padx=>4, :pady=>4) + grid_columnconfigure(0, :weight=>1) + pack(:side=>:bottom, :fill=>:x) +} + +container = Ttk::Frame.new(base_frame) +tree = Ttk::Treeview.new(base_frame, :columns=>%w(country capital currency), + :show=>:headings) +if Tk.windowingsystem != 'aqua' + vsb = tree.yscrollbar(Ttk::Scrollbar.new(base_frame)) + hsb = tree.xscrollbar(Ttk::Scrollbar.new(base_frame)) +else + vsb = tree.yscrollbar(Tk::Scrollbar.new(base_frame)) + hsb = tree.xscrollbar(Tk::Scrollbar.new(base_frame)) +end + +container.pack(:fill=>:both, :expand=>true) +Tk.grid(tree, vsb, :in=>container, :sticky=>'nsew') +Tk.grid(hsb, :in=>container, :sticky=>'nsew') +container.grid_columnconfigure(0, :weight=>1) +container.grid_rowconfigure(0, :weight=>1) + +## The data we're going to insert +data = [ + ['Argentina', 'Buenos Aires', 'ARS'], + ['Australia', 'Canberra', 'AUD'], + ['Brazil', 'Brazilia', 'BRL'], + ['Canada', 'Ottawa', 'CAD'], + ['China', 'Beijing', 'CNY'], + ['France', 'Paris', 'EUR'], + ['Germany', 'Berlin', 'EUR'], + ['India', 'New Delhi', 'INR'], + ['Italy', 'Rome', 'EUR'], + ['Japan', 'Tokyo', 'JPY'], + ['Mexico', 'Mexico City', 'MXN'], + ['Russia', 'Moscow', 'RUB'], + ['South Africa', 'Pretoria', 'ZAR'], + ['United Kingdom', 'London', 'GBP'], + ['United States', 'Washington, D.C.', 'USD'], +] + +## Code to insert the data nicely +font = Ttk::Style.lookup(tree[:style], :font) +cols = %w(country capital currency) +cols.zip(%w(Country Capital Currency)).each{|col, name| + tree.heading_configure(col, :text=>name, + :command=>proc{sort_by(tree, col, false)}) + tree.column_configure(col, :width=>TkFont.measure(font, name)) +} + +data.each{|country, capital, currency| + #tree.insert('', :end, :values=>[country, capital, currency]) + tree.insert(nil, :end, :values=>[country, capital, currency]) + cols.zip([country, capital, currency]).each{|col, val| + len = TkFont.measure(font, "#{val} ") + if tree.column_cget(col, :width) < len + tree.column_configure(col, :width=>len) + end + } +} + +## Code to do the sorting of the tree contents when clicked on +def sort_by(tree, col, direction) + tree.children(nil).map!{|row| [tree.get(row, col), row.id]} . + sort(&((direction)? proc{|x, y| y <=> x}: proc{|x, y| x <=> y})) . + each_with_index{|info, idx| tree.move(info[1], nil, idx)} + + tree.heading_configure(col, :command=>proc{sort_by(tree, col, ! direction)}) +end diff --git a/ext/tk/sample/demos-en/menu.rb b/ext/tk/sample/demos-en/menu.rb index 8370d2f5f0..bf6c22cb9d 100644 --- a/ext/tk/sample/demos-en/menu.rb +++ b/ext/tk/sample/demos-en/menu.rb @@ -15,8 +15,10 @@ $menu_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($menu_demo).pack(:fill=>:both, :expand=>true) + # menu frame -$menu_frame = TkFrame.new($menu_demo, 'relief'=>'raised', 'bd'=>2) +$menu_frame = TkFrame.new(base_frame, 'relief'=>'raised', 'bd'=>2) $menu_frame.pack('side'=>'top', 'fill'=>'x') begin @@ -26,7 +28,7 @@ rescue end # label -TkLabel.new($menu_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { +TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { if $tk_platform['platform'] == 'macintosh' || windowingsystem == "classic" || windowingsystem == "aqua" text("This window contains a menubar with cascaded menus. You can invoke entries with an accelerator by typing Command+x, where \"x\" is the character next to the command key symbol. The rightmost menu can be torn off into a palette by dragging outside of its bounds and releasing the mouse.") @@ -36,7 +38,7 @@ TkLabel.new($menu_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { }.pack('side'=>'top') # frame -TkFrame.new($menu_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -105,7 +107,7 @@ TkMenubutton.new($menu_frame, 'text'=>'Cascades', 'underline'=>0) {|m| 'accelerator'=>"#{modifier}+G", 'underline'=>6) $menu_demo.bind("#{modifier}-g", proc{print "Goodbye\n"}) - TkMenu.new(m, 'tearoff'=>false) {|cascade_check| + TkMenu.new(cascade_menu, 'tearoff'=>false) {|cascade_check| cascade_menu.add('cascade', 'label'=>'Check buttons', 'menu'=>cascade_check, 'underline'=>0) oil = TkVariable.new(0) @@ -127,7 +129,7 @@ TkMenubutton.new($menu_frame, 'text'=>'Cascades', 'underline'=>0) {|m| invoke 3 } - TkMenu.new(m, 'tearoff'=>false) {|cascade_radio| + TkMenu.new(cascade_menu, 'tearoff'=>false) {|cascade_radio| cascade_menu.add('cascade', 'label'=>'Radio buttons', 'menu'=>cascade_radio, 'underline'=>0) pointSize = TkVariable.new diff --git a/ext/tk/sample/demos-en/menu84.rb b/ext/tk/sample/demos-en/menu84.rb index cb616d8461..4029ce5541 100644 --- a/ext/tk/sample/demos-en/menu84.rb +++ b/ext/tk/sample/demos-en/menu84.rb @@ -15,6 +15,8 @@ $menu84_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($menu84_demo).pack(:fill=>:both, :expand=>true) + begin windowingsystem = Tk.windowingsystem() rescue @@ -22,7 +24,7 @@ rescue end # label -TkLabel.new($menu84_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { +TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { if $tk_platform['platform'] == 'macintosh' || windowingsystem == "classic" || windowingsystem == "aqua" text("This window contains a menubar with cascaded menus. You can invoke entries with an accelerator by typing Command+x, where \"x\" is the character next to the command key symbol. The rightmost menu can be torn off into a palette by dragging outside of its bounds and releasing the mouse.") @@ -33,7 +35,7 @@ TkLabel.new($menu84_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { menustatus = TkVariable.new(" ") -TkFrame.new($menu84_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkLabel.new(frame, 'textvariable'=>menustatus, 'relief'=>'sunken', 'bd'=>1, 'font'=>['Helvetica', '10'], 'anchor'=>'w').pack('side'=>'left', 'padx'=>2, @@ -43,7 +45,7 @@ TkFrame.new($menu84_demo) {|frame| # frame -TkFrame.new($menu84_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ diff --git a/ext/tk/sample/demos-en/menubu.rb b/ext/tk/sample/demos-en/menubu.rb index e2ddd07bc6..b37367e515 100644 --- a/ext/tk/sample/demos-en/menubu.rb +++ b/ext/tk/sample/demos-en/menubu.rb @@ -37,16 +37,18 @@ $menubu_demo = TkToplevel.new {|w| positionWindow($menubu_demo) +base_frame = TkFrame.new($menubu_demo).pack(:fill=>:both, :expand=>true) + # version check if $tk_version.to_f < 8.0 # label -TkLabel.new($menubu_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { +TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { text("This is a demonstration of menubuttons. The \"Below\" menubutton pops its menu below the button; the \"Right\" button pops to the right, etc. There are two option menus directly below this text; one is just a standard menu and the other is a 16-color palette.") }.pack('side'=>'top') # frame -TkFrame.new($menubu_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -64,7 +66,7 @@ TkFrame.new($menubu_demo) {|frame| else ; # Tk8.x -body = TkFrame.new($menubu_demo) +body = TkFrame.new(base_frame) body.pack('expand'=>'yes', 'fill'=>'both') below = TkMenubutton.new(body) { @@ -159,7 +161,7 @@ center = TkFrame.new(body) { grid('row'=>1, 'column'=>1, 'sticky'=>'news') } -TkFrame.new($menubu_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc { diff --git a/ext/tk/sample/demos-en/msgbox.rb b/ext/tk/sample/demos-en/msgbox.rb index aab1b619cf..62b1f2b985 100644 --- a/ext/tk/sample/demos-en/msgbox.rb +++ b/ext/tk/sample/demos-en/msgbox.rb @@ -18,12 +18,14 @@ $msgbox_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($msgbox_demo).pack(:fill=>:both, :expand=>true) + # label -TkLabel.new($msgbox_demo, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left', +TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left', 'text'=>"Choose the icon and type option of the message box. Then press the \"Message Box\" button to see the message box.").pack('side'=>'top') # frame -TkFrame.new($msgbox_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -45,8 +47,8 @@ TkFrame.new($msgbox_demo) {|frame| }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # frame -$msgbox_leftframe = TkFrame.new($msgbox_demo) -$msgbox_rightframe = TkFrame.new($msgbox_demo) +$msgbox_leftframe = TkFrame.new(base_frame) +$msgbox_rightframe = TkFrame.new(base_frame) $msgbox_leftframe .pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y', 'pady'=>'.5c', 'padx'=>'.5c') $msgbox_rightframe.pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y', diff --git a/ext/tk/sample/demos-en/msgbox2.rb b/ext/tk/sample/demos-en/msgbox2.rb new file mode 100644 index 0000000000..6fe6c778b3 --- /dev/null +++ b/ext/tk/sample/demos-en/msgbox2.rb @@ -0,0 +1,91 @@ +# msgbox2.rb +# +# This demonstration script creates message boxes of various type +# +# message boxes widget demo (called by 'widget') +# + +# toplevel widget +if defined?($msgbox2_demo) && $msgbox2_demo + $msgbox2_demo.destroy + $msgbox2_demo = nil +end + +# demo toplevel widget +$msgbox2_demo = TkToplevel.new {|w| + title("Message Box Demonstration") + iconname("messagebox") + positionWindow(w) +} + +base_frame = TkFrame.new($msgbox2_demo).pack(:fill=>:both, :expand=>true) + +# label +TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left', + 'text'=>"Choose the icon and type option of the message box. Then press the \"Message Box\" button to see the message box with both of a message and a detail.").pack('side'=>'top') + +# frame +TkFrame.new(base_frame) {|frame| + TkButton.new(frame) { + text 'Dismiss' + command proc{ + tmppath = $msgbox2_demo + $msgbox2_demo = nil + tmppath.destroy + } + }.pack('side'=>'left', 'expand'=>'yes') + + TkButton.new(frame) { + text 'Show Code' + command proc{showCode 'msgbox2'} + }.pack('side'=>'left', 'expand'=>'yes') + + TkButton.new(frame) { + text 'Message Box' + command proc{showMessageBox $msgbox2_demo} + }.pack('side'=>'left', 'expand'=>'yes') +}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') + +# frame +$msgbox_leftframe = TkFrame.new(base_frame) +$msgbox_rightframe = TkFrame.new(base_frame) +$msgbox_leftframe .pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y', + 'pady'=>'.5c', 'padx'=>'.5c') +$msgbox_rightframe.pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y', + 'pady'=>'.5c', 'padx'=>'.5c') + +TkLabel.new($msgbox_leftframe, 'text'=>'Icon').pack('side'=>'top') +TkFrame.new($msgbox_leftframe, 'relief'=>'ridge', 'bd'=>1, 'height'=>2)\ +.pack('side'=>'top', 'fill'=>'x', 'expand'=>'no') + +$msgboxIcon = TkVariable.new('info') +['error', 'info', 'question', 'warning'].each {|icon| + TkRadioButton.new($msgbox_leftframe, 'text'=>icon, 'variable'=>$msgboxIcon, + 'relief'=>'flat', 'value'=>icon, 'width'=>16, + 'anchor'=>'w').pack('side'=>'top', 'pady'=>2, + 'anchor'=>'w', 'fill'=>'x') +} + +TkLabel.new($msgbox_rightframe, 'text'=>'Type').pack('side'=>'top') +TkFrame.new($msgbox_rightframe, 'relief'=>'ridge', 'bd'=>1, 'height'=>2)\ +.pack('side'=>'top', 'fill'=>'x', 'expand'=>'no') + +$msgboxType = TkVariable.new('ok') +['abortretryignore', 'ok', 'okcancel', + 'retrycancel', 'yesno', 'yesnocancel'].each {|type| + TkRadioButton.new($msgbox_rightframe, 'text'=>type, 'variable'=>$msgboxType, + 'relief'=>'flat', 'value'=>type, 'width'=>16, + 'anchor'=>'w').pack('side'=>'top', 'pady'=>2, + 'anchor'=>'w', 'fill'=>'x') +} + +def showMessageBox(w) + button = Tk.messageBox('icon'=>$msgboxIcon.value, 'type'=>$msgboxType.value, + 'title'=>'Message', 'parent'=>w, + 'message'=>"\"#{$msgboxType.value}\" Type MessageBox", + 'detail'=>"This is a \"#{$msgboxType.value}\" type messagebox with the \"#{$msgboxIcon.value}\" icon. Please click one of the following button.") + + Tk.messageBox('icon'=>'info', 'type'=>'ok', 'parent'=>w, + 'message'=>"You have selected \"#{button}\"") +end + diff --git a/ext/tk/sample/demos-en/paned1.rb b/ext/tk/sample/demos-en/paned1.rb index 48ba86de02..26941b84a8 100644 --- a/ext/tk/sample/demos-en/paned1.rb +++ b/ext/tk/sample/demos-en/paned1.rb @@ -16,7 +16,9 @@ $paned1_demo = TkToplevel.new {|w| positionWindow(w) } -TkLabel.new($paned1_demo, +base_frame = TkFrame.new($paned1_demo).pack(:fill=>:both, :expand=>true) + +TkLabel.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left, :text=><:top) The sash between the two coloured windows below can be used to divide the area between them. Use the left mouse button to resize without redrawing by just moving the sash, and use the middle mouse button to resize opaquely (always redrawing the windows in each position.) @@ -24,7 +26,7 @@ If your Tk library linked to Ruby doesn't include a 'panedwindow', this demo doe EOL # The bottom buttons -TkFrame.new($paned1_demo){|f| +TkFrame.new(base_frame){|f| pack(:side=>:bottom, :fill=>:x, :pady=>'2m') TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{ @@ -37,9 +39,9 @@ TkFrame.new($paned1_demo){|f| }).pack(:side=>:left, :expand=>true) } -TkPanedwindow.new($paned1_demo){|f| - pack(:side=>:top, :expand=>true, :fill=>:both, :pady=>2, :padx=>'2m') +TkPanedwindow.new(base_frame, :orient=>:horizontal){|f| + add(Tk::Label.new(f, :text=>"This is the\nleft side", :bg=>'yellow'), + Tk::Label.new(f, :text=>"This is the\nright side", :bg=>'cyan')) - add(TkLabel.new(f, :text=>"This is the\nleft side", :bg=>'yellow'), - TkLabel.new(f, :text=>"This is the\nright side", :bg=>'cyan')) + pack(:side=>:top, :expand=>true, :fill=>:both, :pady=>2, :padx=>'2m') } diff --git a/ext/tk/sample/demos-en/paned2.rb b/ext/tk/sample/demos-en/paned2.rb index 5911cadab6..0e62013886 100644 --- a/ext/tk/sample/demos-en/paned2.rb +++ b/ext/tk/sample/demos-en/paned2.rb @@ -16,7 +16,9 @@ $paned2_demo = TkToplevel.new {|w| positionWindow(w) } -TkLabel.new($paned2_demo, +base_frame = TkFrame.new($paned2_demo).pack(:fill=>:both, :expand=>true) + +TkLabel.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left, :text=><:top) The sash between the two scrolled windows below can be used to divide the area between them. Use the left mouse button to resize without redrawing by just moving the sash, and use the middle mouse button to resize opaquely (always redrawing the windows in each position.) @@ -24,7 +26,7 @@ If your Tk library linked to Ruby doesn't include a 'panedwindow', this demo doe EOL # The bottom buttons -TkFrame.new($paned2_demo){|f| +TkFrame.new(base_frame){|f| pack(:side=>:bottom, :fill=>:x, :pady=>'2m') TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{ @@ -61,7 +63,7 @@ paneList.value = [ # ruby's array --> tcl's list ] # Create the pane itself -TkPanedwindow.new($paned2_demo, :orient=>:vertical){|f| +TkPanedwindow.new(base_frame, :orient=>:vertical){|f| pack(:side=>:top, :expand=>true, :fill=>:both, :pady=>2, :padx=>'2m') add(TkFrame.new(f){|paned2_top| diff --git a/ext/tk/sample/demos-en/pendulum.rb b/ext/tk/sample/demos-en/pendulum.rb index a3498d67cf..5f7d361170 100644 --- a/ext/tk/sample/demos-en/pendulum.rb +++ b/ext/tk/sample/demos-en/pendulum.rb @@ -18,8 +18,10 @@ $pendulum_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($pendulum_demo).pack(:fill=>:both, :expand=>true) + # create label -msg = TkLabel.new($pendulum_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -28,7 +30,7 @@ msg = TkLabel.new($pendulum_demo) { msg.pack('side'=>'top') # create frame -TkFrame.new($pendulum_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -49,7 +51,7 @@ TkFrame.new($pendulum_demo) {|frame| class PendulumAnimationDemo def initialize(frame) # Create some structural widgets - @pane = TkPanedWindow.new(frame).pack(:fill=>:both, :expand=>true) + @pane = TkPanedWindow.new(frame, :orient=>:horizontal).pack(:fill=>:both, :expand=>true) # @pane.add(@lf1 = TkLabelFrame.new(@pane, :text=>'Pendulum Simulation')) # @pane.add(@lf2 = TkLabelFrame.new(@pane, :text=>'Phase Space')) @lf1 = TkLabelFrame.new(@pane, :text=>'Pendulum Simulation') @@ -235,4 +237,4 @@ class PendulumAnimationDemo end # Start the animation processing -PendulumAnimationDemo.new($pendulum_demo) +PendulumAnimationDemo.new(base_frame) diff --git a/ext/tk/sample/demos-en/plot.rb b/ext/tk/sample/demos-en/plot.rb index 6d01deeef5..628c9df584 100644 --- a/ext/tk/sample/demos-en/plot.rb +++ b/ext/tk/sample/demos-en/plot.rb @@ -19,14 +19,16 @@ $plot_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($plot_demo).pack(:fill=>:both, :expand=>true) + # label -TkLabel.new($plot_demo, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left', +TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left', 'text'=>"This window displays a canvas widget containing a simple 2-dimensional plot. You can doctor the data by dragging any of the points with mouse button 1."){ pack('side'=>'top') } # frame -$plot_buttons = TkFrame.new($plot_demo) {|frame| +$plot_buttons = TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -47,7 +49,7 @@ $plot_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') plotFont = '-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*' # canvas -$plot_canvas = TkCanvas.new($plot_demo,'relief'=>'raised','width'=>450,'height'=>300) +$plot_canvas = TkCanvas.new(base_frame,'relief'=>'raised','width'=>450,'height'=>300) $plot_canvas.pack('side'=>'top', 'fill'=>'x') # plot diff --git a/ext/tk/sample/demos-en/puzzle.rb b/ext/tk/sample/demos-en/puzzle.rb index 0885cf2975..43c61f519f 100644 --- a/ext/tk/sample/demos-en/puzzle.rb +++ b/ext/tk/sample/demos-en/puzzle.rb @@ -19,8 +19,10 @@ $puzzle_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($puzzle_demo).pack(:fill=>:both, :expand=>true) + # label -msg = TkLabel.new($puzzle_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -29,7 +31,7 @@ msg = TkLabel.new($puzzle_demo) { msg.pack('side'=>'top') # frame -TkFrame.new($puzzle_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -52,18 +54,27 @@ TkFrame.new($puzzle_demo) {|frame| # scrollbar widget and using its trough color. begin if Tk.windowingsystem() == 'aqua' - frameSize = 160 + frameWidth = 168 + frameHeight = 168 + elsif Tk.default_widget_set == :Ttk + frameWidth = 148 + frameHeight = 124 else - frameSize = 120 + frameWidth = 120 + frameHeight = 120 end rescue - frameSize = 120 + frameWidth = 120 + frameHeight = 120 end + +# depend_on_button_width = true +depend_on_button_width = false -s = TkScrollbar.new($puzzle_demo) -base = TkFrame.new($puzzle_demo) { - width frameSize - height frameSize +s = TkScrollbar.new(base_frame) +base = TkFrame.new(base_frame) { + width frameWidth + height frameHeight borderwidth 2 relief 'sunken' bg s['troughcolor'] @@ -87,6 +98,9 @@ order = [3,1,6,2,5,7,15,13,4,11,8,9,14,10,12] text num highlightthickness 0 command def_puzzleswitch_proc(w, num) + if depend_on_button_width && (w.winfo_reqwidth * 4 > base.width) + base.width = w.winfo_reqwidth * 4 + end }.place('relx'=>$xpos[num], 'rely'=>$ypos[num], 'relwidth'=>0.25, 'relheight'=>0.25) } diff --git a/ext/tk/sample/demos-en/radio.rb b/ext/tk/sample/demos-en/radio.rb index 96cdc4c54a..25cfac2134 100644 --- a/ext/tk/sample/demos-en/radio.rb +++ b/ext/tk/sample/demos-en/radio.rb @@ -19,8 +19,10 @@ $radio_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($radio_demo).pack(:fill=>:both, :expand=>true) + # label -msg = TkLabel.new($radio_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -33,7 +35,7 @@ size = TkVariable.new color = TkVariable.new # frame -TkFrame.new($radio_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -52,14 +54,14 @@ TkFrame.new($radio_demo) {|frame| TkButton.new(frame) { text 'See Variables' command proc{ - showVars($radio_demo, ['size', size], ['color', color]) + showVars(base_frame, ['size', size], ['color', color]) } }.pack('side'=>'left', 'expand'=>'yes') }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # frame -f_left = TkFrame.new($radio_demo) -f_right = TkFrame.new($radio_demo) +f_left = TkFrame.new(base_frame) +f_right = TkFrame.new(base_frame) f_left.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c') f_right.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c') diff --git a/ext/tk/sample/demos-en/radio2.rb b/ext/tk/sample/demos-en/radio2.rb index 2b56ccc9b1..6c02aef0cf 100644 --- a/ext/tk/sample/demos-en/radio2.rb +++ b/ext/tk/sample/demos-en/radio2.rb @@ -19,8 +19,10 @@ $radio2_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($radio2_demo).pack(:fill=>:both, :expand=>true) + # label -msg = TkLabel.new($radio2_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '5i' justify 'left' @@ -34,7 +36,7 @@ color = TkVariable.new align = TkVariable.new # frame -TkFrame.new($radio2_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -53,18 +55,18 @@ TkFrame.new($radio2_demo) {|frame| TkButton.new(frame) { text 'See Variables' command proc{ - showVars($radio2_demo, + showVars(base_frame, ['size', size], ['color', color], ['compound', align]) } }.pack('side'=>'left', 'expand'=>'yes') }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # frame -f_left = TkLabelFrame.new($radio2_demo, 'text'=>'Point Size', +f_left = TkLabelFrame.new(base_frame, 'text'=>'Point Size', 'pady'=>2, 'padx'=>2) -f_mid = TkLabelFrame.new($radio2_demo, 'text'=>'Color', +f_mid = TkLabelFrame.new(base_frame, 'text'=>'Color', 'pady'=>2, 'padx'=>2) -f_right = TkLabelFrame.new($radio2_demo, 'text'=>'Alignment', +f_right = TkLabelFrame.new(base_frame, 'text'=>'Alignment', 'pady'=>2, 'padx'=>2) f_left.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c') f_mid.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c') @@ -90,7 +92,8 @@ f_right.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c') }.pack('side'=>'top', 'pady'=>2, 'fill'=>'x') } -label = TkLabel.new(f_right, 'text'=>'Label', 'bitmap'=>'questhead', +# label = TkLabel.new(f_right, 'text'=>'Label', 'bitmap'=>'questhead', +label = Tk::Label.new(f_right, 'text'=>'Label', 'bitmap'=>'questhead', 'compound'=>'left') label.configure('width'=>TkWinfo.reqwidth(label), 'compound'=>'top') label.height(TkWinfo.reqheight(label)) diff --git a/ext/tk/sample/demos-en/radio3.rb b/ext/tk/sample/demos-en/radio3.rb index 70c4abb3b5..9c9d75ef4a 100644 --- a/ext/tk/sample/demos-en/radio3.rb +++ b/ext/tk/sample/demos-en/radio3.rb @@ -19,8 +19,10 @@ $radio3_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($radio3_demo).pack(:fill=>:both, :expand=>true) + # label -msg = TkLabel.new($radio3_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '5i' justify 'left' @@ -34,14 +36,14 @@ color = TkVariable.new align = TkVariable.new # frame -TkFrame.new($radio3_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkGrid(TkFrame.new(frame, :height=>2, :relief=>:sunken, :bd=>2), :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) TkGrid('x', TkButton.new(frame, :text=>'See Variables', :image=>$image['view'], :compound=>:left, :command=>proc{ - showVars($radio3_demo, ['size', size], + showVars(base_frame, ['size', size], ['color', color], ['compound', align]) }), TkButton.new(frame, :text=>'See Code', @@ -61,17 +63,17 @@ TkFrame.new($radio3_demo) {|frame| } # frame -f_left = TkLabelFrame.new($radio3_demo, 'text'=>'Point Size', +f_left = TkLabelFrame.new(base_frame, 'text'=>'Point Size', 'pady'=>2, 'padx'=>2) -f_mid = TkLabelFrame.new($radio3_demo, 'text'=>'Color', +f_mid = TkLabelFrame.new(base_frame, 'text'=>'Color', 'pady'=>2, 'padx'=>2) -f_right = TkLabelFrame.new($radio3_demo, 'text'=>'Alignment', +f_right = TkLabelFrame.new(base_frame, 'text'=>'Alignment', 'pady'=>2, 'padx'=>2) f_left .grid('column'=>0, 'row'=>1, 'pady'=>'.5c', 'padx'=>'.5c', 'rowspan'=>2) f_mid .grid('column'=>1, 'row'=>1, 'pady'=>'.5c', 'padx'=>'.5c', 'rowspan'=>2) f_right.grid('column'=>2, 'row'=>1, 'pady'=>'.5c', 'padx'=>'.5c') -TkButton.new($radio3_demo, 'text'=>'Tristate', +TkButton.new(base_frame, 'text'=>'Tristate', 'command'=>proc{size.value = 'multi'; color.value = 'multi'}){ grid('column'=>2, 'row'=>2, 'pady'=>'.5c', 'padx'=>'.5c') } @@ -99,7 +101,8 @@ TkButton.new($radio3_demo, 'text'=>'Tristate', }.pack('side'=>'top', 'pady'=>2, 'fill'=>'x') } -label = TkLabel.new(f_right, 'text'=>'Label', 'bitmap'=>'questhead', +# label = TkLabel.new(f_right, 'text'=>'Label', 'bitmap'=>'questhead', +label = Tk::Label.new(f_right, 'text'=>'Label', 'bitmap'=>'questhead', 'compound'=>'left') label.configure('width'=>TkWinfo.reqwidth(label), 'compound'=>'top') label.height(TkWinfo.reqheight(label)) diff --git a/ext/tk/sample/demos-en/ruler.rb b/ext/tk/sample/demos-en/ruler.rb index 4299d57b4f..26cd4f3b1c 100644 --- a/ext/tk/sample/demos-en/ruler.rb +++ b/ext/tk/sample/demos-en/ruler.rb @@ -32,14 +32,16 @@ $ruler_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($ruler_demo).pack(:fill=>:both, :expand=>true) + # label -TkLabel.new($ruler_demo, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left', +TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left', 'text'=>"This canvas widget shows a mock-up of a ruler. You can create tab stops by dragging them out of the well to the right of the ruler. You can also drag existing tab stops. If you drag a tab stop far enough up or down so that it turns dim, it will be deleted when you release the mouse button."){ pack('side'=>'top') } # frame -$ruler_buttons = TkFrame.new($ruler_demo) {|frame| +$ruler_buttons = TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -57,7 +59,7 @@ $ruler_buttons = TkFrame.new($ruler_demo) {|frame| $ruler_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # canvas -$ruler_canvas = TkCanvas.new($ruler_demo, 'width'=>'14.8c', 'height'=>'2.5c') +$ruler_canvas = TkCanvas.new(base_frame, 'width'=>'14.8c', 'height'=>'2.5c') $ruler_canvas.pack('side'=>'top', 'fill'=>'x') # diff --git a/ext/tk/sample/demos-en/sayings.rb b/ext/tk/sample/demos-en/sayings.rb index cef0f4ecf4..06ec7c1e75 100644 --- a/ext/tk/sample/demos-en/sayings.rb +++ b/ext/tk/sample/demos-en/sayings.rb @@ -20,8 +20,10 @@ $sayings_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($sayings_demo).pack(:fill=>:both, :expand=>true) + # label -msg = TkLabel.new($sayings_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -30,7 +32,7 @@ msg = TkLabel.new($sayings_demo) { msg.pack('side'=>'top') # frame -TkFrame.new($sayings_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -49,7 +51,7 @@ TkFrame.new($sayings_demo) {|frame| # frame sayings_lbox = nil -TkFrame.new($sayings_demo, 'borderwidth'=>10) {|w| +TkFrame.new(base_frame, 'borderwidth'=>10) {|w| sv = TkScrollbar.new(w) sh = TkScrollbar.new(w, 'orient'=>'horizontal') sayings_lbox = TkListbox.new(w) { diff --git a/ext/tk/sample/demos-en/search.rb b/ext/tk/sample/demos-en/search.rb index 3749423bbc..e1fc565e9d 100644 --- a/ext/tk/sample/demos-en/search.rb +++ b/ext/tk/sample/demos-en/search.rb @@ -79,8 +79,10 @@ $search_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($search_demo).pack(:fill=>:both, :expand=>true) + # frame -$search_buttons = TkFrame.new($search_demo) {|frame| +$search_buttons = TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -98,7 +100,7 @@ $search_buttons = TkFrame.new($search_demo) {|frame| $search_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # frame -TkFrame.new($search_demo) {|f| +TkFrame.new(base_frame) {|f| TkLabel.new(f, 'text'=>'File name:', 'width'=>13, 'anchor'=>'w').pack('side'=>'left') $search_fileName = TkVariable.new @@ -115,7 +117,7 @@ TkFrame.new($search_demo) {|f| .pack('side'=>'left', 'pady'=>5, 'padx'=>10) }.pack('side'=>'top', 'fill'=>'x') -TkFrame.new($search_demo) {|f| +TkFrame.new(base_frame) {|f| TkLabel.new(f, 'text'=>'Search string:', 'width'=>13, 'anchor'=>'w').pack('side'=>'left') $search_searchString = TkVariable.new @@ -133,9 +135,9 @@ TkFrame.new($search_demo) {|f| } }.pack('side'=>'top', 'fill'=>'x') -$search_text = TkText.new($search_demo, 'setgrid'=>true, 'wrap'=>'word') {|t| +$search_text = TkText.new(base_frame, 'setgrid'=>true, 'wrap'=>'word') {|t| $search_Tag = TkTextTag.new(t) - TkScrollbar.new($search_demo, 'command'=>proc{|*args| t.yview(*args)}) {|sc| + TkScrollbar.new(base_frame, 'command'=>proc{|*args| t.yview(*args)}) {|sc| t.yscrollcommand(proc{|first,last| sc.set first,last}) pack('side'=>'right', 'fill'=>'y') } diff --git a/ext/tk/sample/demos-en/spin.rb b/ext/tk/sample/demos-en/spin.rb index 58616b1e02..c2a3a8949b 100644 --- a/ext/tk/sample/demos-en/spin.rb +++ b/ext/tk/sample/demos-en/spin.rb @@ -15,7 +15,9 @@ $spin_demo = TkToplevel.new {|w| positionWindow(w) } -TkLabel.new($spin_demo, +base_frame = TkFrame.new($spin_demo).pack(:fill=>:both, :expand=>true) + +TkLabel.new(base_frame, :font=>$font, :wraplength=>'5i', :justify=>:left, :text=><:top) Three different spin-boxes are displayed below. \ @@ -34,7 +36,7 @@ this demo doesn't work. Please use later version of Tk \ which supports a 'spinbox' widget. EOL -TkFrame.new($spin_demo){|f| +TkFrame.new(base_frame){|f| pack(:side=>:bottom, :fill=>:x, :pady=>'2m') TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{ @@ -53,11 +55,11 @@ australianCities = [ ] [ - TkSpinbox.new($spin_demo, :from=>1, :to=>10, :width=>10, :validate=>:key, + TkSpinbox.new(base_frame, :from=>1, :to=>10, :width=>10, :validate=>:key, :validatecommand=>[ proc{|s| s == '' || /^[+-]?\d+$/ =~ s }, '%P' ]), - TkSpinbox.new($spin_demo, :from=>0, :to=>3, :increment=>0.5, + TkSpinbox.new(base_frame, :from=>0, :to=>3, :increment=>0.5, :format=>'%05.2f', :width=>10), - TkSpinbox.new($spin_demo, :values=>australianCities, :width=>10) + TkSpinbox.new(base_frame, :values=>australianCities, :width=>10) ].each{|sbox| sbox.pack(:side=>:top, :pady=>5, :padx=>10)} diff --git a/ext/tk/sample/demos-en/states.rb b/ext/tk/sample/demos-en/states.rb index d38c1245af..add0e84800 100644 --- a/ext/tk/sample/demos-en/states.rb +++ b/ext/tk/sample/demos-en/states.rb @@ -19,8 +19,10 @@ $states_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($states_demo).pack(:fill=>:both, :expand=>true) + # label -msg = TkLabel.new($states_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -29,7 +31,7 @@ msg = TkLabel.new($states_demo) { msg.pack('side'=>'top') # frame -TkFrame.new($states_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -48,7 +50,7 @@ TkFrame.new($states_demo) {|frame| # frame states_lbox = nil -TkFrame.new($states_demo, 'borderwidth'=>'.5c') {|w| +TkFrame.new(base_frame, 'borderwidth'=>'.5c') {|w| s = TkScrollbar.new(w) states_lbox = TkListbox.new(w) { setgrid 1 diff --git a/ext/tk/sample/demos-en/style.rb b/ext/tk/sample/demos-en/style.rb index 8606893c9b..c2fed23926 100644 --- a/ext/tk/sample/demos-en/style.rb +++ b/ext/tk/sample/demos-en/style.rb @@ -19,8 +19,10 @@ $style_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($style_demo).pack(:fill=>:both, :expand=>true) + # frame -TkFrame.new($style_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -37,14 +39,14 @@ TkFrame.new($style_demo) {|frame| }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # text -TkText.new($style_demo){|t| +txt = TkText.new(base_frame){|t| # setgrid 'true' #width 70 #height 32 wrap 'word' font $font - TkScrollbar.new($style_demo) {|s| + TkScrollbar.new(base_frame) {|s| pack('side'=>'right', 'fill'=>'y') command proc{|*args| t.yview(*args)} t.yscrollcommand proc{|first,last| s.set first,last} @@ -64,7 +66,7 @@ TkText.new($style_demo){|t| style_tag_bold = TkTextTag.new(t, 'font'=>[family, 12, :bold, :italic]) style_tag_big = TkTextTag.new(t, 'font'=>[family, 14, :bold]) style_tag_verybig = TkTextTag.new(t, 'font'=>['Helvetica', 24, :bold]) - style_tag_small = TkTextTag.new(t, 'font'=>['Times 8 bold']) + style_tag_small = TkTextTag.new(t, 'font'=>'Times 8 bold') end ### # case($tk_version) diff --git a/ext/tk/sample/demos-en/text.rb b/ext/tk/sample/demos-en/text.rb index 4bb4b6bc7e..3ce8cdfda8 100644 --- a/ext/tk/sample/demos-en/text.rb +++ b/ext/tk/sample/demos-en/text.rb @@ -19,6 +19,8 @@ $text_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($text_demo).pack(:fill=>:both, :expand=>true) + # version check if ((Tk::TK_VERSION.split('.').collect{|n| n.to_i} <=> [8,4]) < 0) undo_support = false @@ -27,7 +29,7 @@ else end # frame -TkFrame.new($text_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -44,7 +46,7 @@ TkFrame.new($text_demo) {|frame| }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # text -TkText.new($text_demo){|t| +TkText.new(base_frame){|t| relief 'sunken' bd 2 setgrid 1 @@ -53,7 +55,7 @@ TkText.new($text_demo){|t| undo true autoseparators true end - TkScrollbar.new($text_demo) {|s| + TkScrollbar.new(base_frame) {|s| pack('side'=>'right', 'fill'=>'y') command proc{|*args| t.yview(*args)} t.yscrollcommand proc{|first,last| s.set first,last} diff --git a/ext/tk/sample/demos-en/textpeer.rb b/ext/tk/sample/demos-en/textpeer.rb index d98ef170b4..c25ce15e5c 100644 --- a/ext/tk/sample/demos-en/textpeer.rb +++ b/ext/tk/sample/demos-en/textpeer.rb @@ -15,10 +15,12 @@ $textpeer_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($textpeer_demo).pack(:fill=>:both, :expand=>true) + count = [0] ## Define a widget that we peer from; it won't ever actually be shown though -first = TkText.new($textpeer_demo, :widgetname=>"text#{count[0] += 1}") +first = TkText.new(base_frame, :widgetname=>"text#{count[0] += 1}") first.insert :end,"This is a coupled pair of text widgets; they are peers to " first.insert :end,"each other. They have the same underlying data model, but " first.insert :end,"can show different locations, have different current edit " @@ -28,6 +30,8 @@ first.insert :end,"the Make Peer button beside the text widget to clone, and " first.insert :end,"delete a particular peer widget using the Delete Peer " first.insert :end,"button." +Tk.update_idletasks ## for 'first' widget + ## Procedures to make and kill clones; most of this is just so that the demo ## looks nice... def makeClone(count, win, txt) @@ -52,12 +56,12 @@ def killClone(win, cnt) end ## Now set up the GUI -makeClone(count, $textpeer_demo, first) -makeClone(count, $textpeer_demo, first) +makeClone(count, base_frame, first) +makeClone(count, base_frame, first) first.destroy ## See Code / Dismiss buttons -TkFrame.new($textpeer_demo){|f| +TkFrame.new(base_frame){|f| TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{ $textpeer_demo.destroy $textpeer_demo = nil @@ -69,4 +73,4 @@ TkFrame.new($textpeer_demo){|f| TkGrid.configure(f, '-', '-', :sticky=>'ew', :row=>5000) } -TkGrid.columnconfigure($textpeer_demo, 0, :weight=>1) +TkGrid.columnconfigure(base_frame, 0, :weight=>1) diff --git a/ext/tk/sample/demos-en/toolbar.rb b/ext/tk/sample/demos-en/toolbar.rb new file mode 100644 index 0000000000..5cf863717b --- /dev/null +++ b/ext/tk/sample/demos-en/toolbar.rb @@ -0,0 +1,130 @@ +# toolbar.rb -- +# +# This demonstration script creates a toolbar that can be torn off. +# +# based on "Id: toolbar.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp" + +if defined?($toolbar_demo) && $toolbar_demo + $toolbar_demo.destroy + $toolbar_demo = nil +end + +$toolbar_demo = TkToplevel.new {|w| + title("Ttk Menu Buttons") + iconname("toolbar") + positionWindow(w) +} + +base_frame = Ttk::Frame.new($toolbar_demo).pack(:fill=>:both, :expand=>true) + +if Tk.windowingsystem != 'aqua' + msg = Ttk::Label.new(base_frame, :wraplength=>'4i', + :text=>Tk::UTF8_String.new(<'4i', + :text=>Tk::UTF8_String.new(<'toolbar') # for window title +sep = Ttk::Separator.new(base_frame) +to_base = Ttk::Frame.new(tbar_base, :cursor=>'fleur') +if Tk.windowingsystem != 'aqua' + to = Ttk::Separator.new(to_base, :orient=>:vertical) + to2 = Ttk::Separator.new(to_base, :orient=>:vertical) + to.pack(:fill=>:y, :expand=>true, :padx=>2, :side=>:left) + to2.pack(:fill=>:y, :expand=>true, :side=>:left) +end + +contents = Ttk::Frame.new(tbar_base) +Tk.grid(to_base, contents, :sticky=>'nsew') +tbar_base.grid_columnconfigure(contents, :weight=>1) +contents.grid_columnconfigure(1000, :weight=>1) + +if Tk.windowingsystem != 'aqua' + ## Bindings so that the toolbar can be torn off and reattached + to_base.bind('B1-Motion', '%X %Y'){|x, y| tbar_base.tearoff(to_base, x, y)} + to. bind('B1-Motion', '%X %Y'){|x, y| tbar_base.tearoff(to_base, x, y)} + to2. bind('B1-Motion', '%X %Y'){|x, y| tbar_base.tearoff(to_base, x, y)} + def tbar_base.tearoff(w, x, y) + on_win = TkWinfo.containing(x, y) + return unless (on_win && on_win.path =~ /^#{@path}(\.|$)/) + self.grid_remove + w.grid_remove + self.wm_manage + # self.wm_title('Toolbar') # if you don't want to use its widget name as a window title. + self.wm_protocol('WM_DELETE_WINDOW'){ self.untearoff(self) } + end + def tbar_base.untearoff(w) + self.wm_forget + w.grid + self.grid + end +end + +## Some content for the rest of the toplevel +text = TkText.new(base_frame, :width=>40, :height=>10) + +## Toolbar contents +tb_btn = Ttk::Button.new(tbar_base, :text=>'Button', :style=>'Toolbutton', + :command=>proc{text.insert(:end, "Button Pressed\n")}) +tb_chk = Ttk::Checkbutton.new(tbar_base, :text=>'Check', :style=>'Toolbutton', + :variable=>(check = TkVariable.new), + :command=>proc{ + text.insert(:end, "Check is #{check.value}\n") + }) +tb_mbtn = Ttk::Menubutton.new(tbar_base, :text=>'Menu') +tb_combo = Ttk::Combobox.new(tbar_base, :value=>TkFont.families, + :state=>:readonly) +tb_mbtn.menu(menu = Tk::Menu.new(tb_mbtn)) +menu.add(:command, :label=>'Just', :command=>proc{text.insert(:end, "Just\n")}) +menu.add(:command, :label=>'An', :command=>proc{text.insert(:end, "An\n")}) +menu.add(:command, :label=>'Example', + :command=>proc{text.insert(:end, "Example\n")}) +tb_combo.bind(''){ text.font.family = tb_combo.get } + +## Arrange contents +Tk.grid(tb_btn, tb_chk, tb_mbtn, tb_combo, + :in=>contents, :padx=>2, :sticky=>'ns') +Tk.grid(tbar_base, :sticky=>'ew') +Tk.grid(sep, :sticky=>'ew') +Tk.grid(msg, :sticky=>'ew') +Tk.grid(text, :sticky=>'nsew') +base_frame.grid_rowconfigure(text, :weight=>1) +base_frame.grid_columnconfigure(text, :weight=>1) + +## See Code / Dismiss buttons +Ttk::Frame.new(base_frame) {|frame| + sep = Ttk::Separator.new(frame) + Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) + TkGrid('x', + Ttk::Button.new(frame, :text=>'See Code', + :image=>$image['view'], :compound=>:left, + :command=>proc{showCode 'toolbar'}), + Ttk::Button.new(frame, :text=>'Dismiss', + :image=>$image['delete'], :compound=>:left, + :command=>proc{ + $toolbar_demo.destroy + $toolbar_demo = nil + }), + :padx=>4, :pady=>4) + grid_columnconfigure(0, :weight=>1) + Tk.grid(frame, :sticky=>'ew') +} diff --git a/ext/tk/sample/demos-en/tree.rb b/ext/tk/sample/demos-en/tree.rb new file mode 100644 index 0000000000..0c7f0e71a2 --- /dev/null +++ b/ext/tk/sample/demos-en/tree.rb @@ -0,0 +1,119 @@ +# tree.rb -- +# +# This demonstration script creates a toplevel window containing a Ttk +# tree widget. +# +# based on "Id: tree.tcl,v 1.4 2007/12/13 15:27:07 dgp Exp" + +if defined?($tree_demo) && $tree_demo + $tree_demo.destroy + $tree_demo = nil +end + +$tree_demo = TkToplevel.new {|w| + title("Directory Browser") + iconname("tree") + positionWindow(w) +} + +base_frame = TkFrame.new($tree_demo).pack(:fill=>:both, :expand=>true) + +## Explanatory text +Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', + :justify=>:left, :anchor=>'n', :padding=>[10, 2, 10, 6], + :text=><:x) +Ttk is the new Tk themed widget set. \ +One of the widgets it includes is a tree widget, \ +which allows the user to browse a hierarchical data-set such as a filesystem. \ +The tree widget not only allows for the tree part itself, \ +but it also supports an arbitrary number of additional columns \ +which can show additional data (in this case, the size of the files \ +found in your filesystem). \ +You can also change the width of the columns \ +by dragging the boundary between them. +EOL + +## See Code / Dismiss +Ttk::Frame.new(base_frame) {|frame| + sep = Ttk::Separator.new(frame) + Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) + TkGrid('x', + Ttk::Button.new(frame, :text=>'See Code', + :image=>$image['view'], :compound=>:left, + :command=>proc{showCode 'tree'}), + Ttk::Button.new(frame, :text=>'Dismiss', + :image=>$image['delete'], :compound=>:left, + :command=>proc{ + $tree_demo.destroy + $tree_demo = nil + }), + :padx=>4, :pady=>4) + grid_columnconfigure(0, :weight=>1) + pack(:side=>:bottom, :fill=>:x) +} + +## Code to populate the roots of the tree (can be more than one on Windows) +def populate_roots(tree) + TkComm.simplelist(Tk.tk_call('file', 'volumes')).sort.each{|dir| + populate_tree(tree, tree.insert(nil, :end, :text=>dir, + :values=>[dir, 'directory'])) + } +end + +## Code to populate a node of the tree +def populate_tree(tree, node) + return if tree.get(node, :type) != 'directory' + + path = tree.get(node, :fullpath) + tree.delete(tree.children(node)) + Dir.glob("#{path}/*").sort.each{|f| + type = File.ftype(f) + id = tree.insert(node, :end, + :text=>File.basename(f), :values=>[f, type]).id + if type == 'directory' + ## Make it so that this node is openable + tree.insert(id, 0, :text=>'dummy') + tree.itemconfigure(id, :text=>File.basename(f)) + elsif type == 'file' + size = File.size(f) + if size >= 1024*1024*1024 + size = '%.1f GB' % (size.to_f/1024/1024/1024) + elsif size >= 1024*1024 + size = '%.1f MB' % (size.to_f/1024/1024) + elsif size >= 1024 + size = '%.1f KB' % (size.to_f/1024) + else + size = '%.1f bytes' % (size.to_f/1024) + end + tree.set(id, :size, size) + end + } + + # Stop this code from rerunning on the current node + tree.set(node, :type, 'processed_directory') +end + +## Create the tree and set it up +tree = Ttk::Treeview.new(base_frame, :columns=>%w(fullpath type size), + :displaycolumns=>['size']) +if Tk.windowingsystem != 'aqua' + vsb = tree.yscrollbar(Ttk::Scrollbar.new(base_frame)) + hsb = tree.xscrollbar(Ttk::Scrollbar.new(base_frame)) +else + vsb = tree.yscrollbar(Tk::Scrollbar.new(base_frame)) + hsb = tree.xscrollbar(Tk::Scrollbar.new(base_frame)) +end + +tree.heading_configure('#0', :text=>'Directory Structure') +tree.heading_configure('size', :text=>'File Size') +tree.column_configure('size', :stretch=>0, :width=>70) +populate_roots(tree) +tree.bind('', '%W'){|w| populate_tree(w, w.focus_item)} + +## Arrange the tree and its scrollbars in the toplevel +container = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true) +container.lower +Tk.grid(tree, vsb, :in=>container, :sticky=>'nsew') +Tk.grid(hsb, :in=>container, :sticky=>'nsew') +container.grid_columnconfigure(0, :weight=>1) +container.grid_rowconfigure(0, :weight=>1) diff --git a/ext/tk/sample/demos-en/ttkbut.rb b/ext/tk/sample/demos-en/ttkbut.rb new file mode 100644 index 0000000000..b5780f589a --- /dev/null +++ b/ext/tk/sample/demos-en/ttkbut.rb @@ -0,0 +1,139 @@ +# ttkbut.rb +# +# This demonstration script creates a toplevel window containing several +# simple Ttk widgets, such as labels, labelframes, buttons, checkbuttons and +# radiobuttons. +# +# based on "Id: ttkbut.tcl,v 1.4 2007/12/13 15:27:07 dgp Exp" + +if defined?($ttkbut_demo) && $ttkbut_demo + $ttkbut_demo.destroy + $ttkbut_demo = nil +end + +$ttkbut_demo = TkToplevel.new {|w| + title("Simple Ttk Widgets") + iconname("ttkbut") + positionWindow(w) +} + +base_frame = TkFrame.new($ttkbut_demo).pack(:fill=>:both, :expand=>true) + +Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left, + :text=><:top, :fill=>:x) +Ttk is the new Tk themed widget set. This is a Ttk themed label, \ +and below are three groups of Ttk widgets in Ttk labelframes. \ +The first group are all buttons that set the current application theme \ +when pressed. The second group contains three sets of checkbuttons, \ +with a separator widget between the sets. Note that the "Enabled" \ +button controls whether all the other themed widgets in this toplevel are \ +in the disabled state. The third group has a collection of linked \ +radiobuttons. +EOL + +## Add buttons for setting the theme +buttons = Ttk::Labelframe.new(base_frame, :text=>'Buttons') +# Ttk::Style.theme_names.each{|theme| +# Ttk::Button.new(buttons, :text=>theme, +# :command=>proc{Ttk::Style.theme_use theme}).pack(:pady=>2) +# } +Ttk.themes.each{|theme| + Ttk::Button.new(buttons, :text=>theme, + :command=>proc{Ttk.set_theme theme}).pack(:pady=>2) +} + +## Helper procedure for the top checkbutton +def setState(root, value, *excepts) + return if excepts.member?(root) + + ## Non-Ttk widgets (e.g. the toplevel) will fail, so make it silent + begin + root.state = value + rescue + end + + ## Recursively invoke on all children of this root that are in the same + ## toplevel widget + root.winfo_children.each{|w| + setState(w, value, *excepts) if w.winfo_toplevel == root.winfo_toplevel + } +end + +## Set up the checkbutton group +checks = Ttk::Labelframe.new(base_frame, :text=>'Checkbuttons') +enabled = TkVariable.new(true) +e = Ttk::Checkbutton.new(checks, :text=>'Enabled', :variable=>enabled, + :command=>proc{ + setState($ttkbut_demo, + ((enabled.bool)? "!disabled" : "disabled"), + e) + }) + +## See ttk_widget(n) for other possible state flags +sep1 = Ttk::Separator.new(checks) +sep2 = Ttk::Separator.new(checks) + +cheese = TkVariable.new +tomato = TkVariable.new +basil = TkVariable.new +oregano = TkVariable.new + +c1 = Ttk::Checkbutton.new(checks, :text=>'Cheese', :variable=>cheese) +c2 = Ttk::Checkbutton.new(checks, :text=>'Tomato', :variable=>tomato) +c3 = Ttk::Checkbutton.new(checks, :text=>'Basil', :variable=>basil) +c4 = Ttk::Checkbutton.new(checks, :text=>'Oregano', :variable=>oregano) + +Tk.pack(e, sep1, c1, c2, sep2, c3, c4, :fill=>:x, :pady=>2) + +## Set up the radiobutton group +radios = Ttk::Labelframe.new(base_frame, :text=>'Radiobuttons') + +happyness = TkVariable.new + +r1 = Ttk::Radiobutton.new(radios, :variable=>happyness, + :text=>'Great', :value=>'great') +r2 = Ttk::Radiobutton.new(radios, :variable=>happyness, + :text=>'Good', :value=>'good') +r3 = Ttk::Radiobutton.new(radios, :variable=>happyness, + :text=>'Ok', :value=>'ok') +r4 = Ttk::Radiobutton.new(radios, :variable=>happyness, + :text=>'Poor', :value=>'poor') +r5 = Ttk::Radiobutton.new(radios, :variable=>happyness, + :text=>'Awful', :value=>'awful') + +Tk.pack(r1, r2, r3, r4, r5, :fill=>:x, :padx=>3, :pady=>2) + +## See Code / Dismiss +Ttk::Frame.new(base_frame) {|frame| + sep = Ttk::Separator.new(frame) + Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) + TkGrid('x', + Ttk::Button.new(frame, :text=>'See Variables', + :image=>$image['view'], :compound=>:left, + :command=>proc{ + showVars(base_frame, ['enabled', enabled], + ['cheese', cheese], ['tomato', tomato], + ['basil', basil], ['oregano', oregano], + ['happyness', happyness]) + }), + Ttk::Button.new(frame, :text=>'See Code', + :image=>$image['view'], :compound=>:left, + :command=>proc{showCode 'ttkbut'}), + Ttk::Button.new(frame, :text=>'Dismiss', + :image=>$image['delete'], :compound=>:left, + :command=>proc{ + tmppath = $ttkbut_demo + $ttkbut_demo = nil + $showVarsWin[tmppath.path] = nil + tmppath.destroy + }), + :padx=>4, :pady=>4) + grid_columnconfigure(0, :weight=>1) + pack(:side=>:bottom, :fill=>:x, :expand=>true) +} + +## Arrange things neatly +f = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true) +f.lower +Tk.grid(buttons, checks, radios, :in=>f, :sticky=>'nwe', :pady=>2, :padx=>3) +f.grid_columnconfigure([0, 1, 2], :weight=>1, :uniform=>:yes) diff --git a/ext/tk/sample/demos-en/ttkmenu.rb b/ext/tk/sample/demos-en/ttkmenu.rb new file mode 100644 index 0000000000..75ecdb09c4 --- /dev/null +++ b/ext/tk/sample/demos-en/ttkmenu.rb @@ -0,0 +1,85 @@ +# ttkmenu.rb -- +# +# This demonstration script creates a toplevel window containing several Ttk +# menubutton widgets. +# +# based on "Id: ttkmenu.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp" + +if defined?($ttkmenu_demo) && $ttkmenu_demo + $ttkmenu_demo.destroy + $ttkmenu_demo = nil +end + +$ttkmenu_demo = TkToplevel.new {|w| + title("Ttk Menu Buttons") + iconname("ttkmenu") + positionWindow(w) +} + +base_frame = Ttk::Frame.new($ttkmenu_demo).pack(:fill=>:both, :expand=>true) + +Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left, + :text=><:top, :fill=>:x) +Ttk is the new Tk themed widget set, \ +and one widget that is available in themed form is the menubutton. \ +Below are some themed menu buttons \ +that allow you to pick the current theme in use. \ +Notice how picking a theme changes the way \ +that the menu buttons themselves look, \ +and that the central menu button is styled differently \ +(in a way that is normally suitable for toolbars). \ +However, there are no themed menus; the standard Tk menus were judged \ +to have a sufficiently good look-and-feel on all platforms, \ +especially as they are implemented as native controls in many places. +EOL + +Ttk::Separator.new(base_frame).pack(:side=>:top, :fill=>:x) + +## See Code / Dismiss +Ttk::Frame.new($ttkmenu_demo) {|frame| + sep = Ttk::Separator.new(frame) + Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) + TkGrid('x', + Ttk::Button.new(frame, :text=>'See Code', + :image=>$image['view'], :compound=>:left, + :command=>proc{showCode 'ttkmenu'}), + Ttk::Button.new(frame, :text=>'Dismiss', + :image=>$image['delete'], :compound=>:left, + :command=>proc{ + $ttkmenu_demo.destroy + $ttkmenu_demo = nil + }), + :padx=>4, :pady=>4) + grid_columnconfigure(0, :weight=>1) + pack(:side=>:bottom, :fill=>:x) +} + +b1 = Ttk::Menubutton.new(base_frame,:text=>'Select a theme',:direction=>:above) +b2 = Ttk::Menubutton.new(base_frame,:text=>'Select a theme',:direction=>:left) +b3 = Ttk::Menubutton.new(base_frame,:text=>'Select a theme',:direction=>:right) +b4 = Ttk::Menubutton.new(base_frame,:text=>'Select a theme',:direction=>:flush, + :style=>Ttk::Menubutton.style('Toolbutton')) +b5 = Ttk::Menubutton.new(base_frame,:text=>'Select a theme',:direction=>:below) + +b1.menu(m1 = Tk::Menu.new(b1, :tearoff=>false)) +b2.menu(m2 = Tk::Menu.new(b2, :tearoff=>false)) +b3.menu(m3 = Tk::Menu.new(b3, :tearoff=>false)) +b4.menu(m4 = Tk::Menu.new(b4, :tearoff=>false)) +b5.menu(m5 = Tk::Menu.new(b5, :tearoff=>false)) + +Ttk.themes.each{|theme| + m1.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme}) + m2.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme}) + m3.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme}) + m4.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme}) + m5.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme}) +} + +f = Ttk::Frame.new(base_frame).pack(:fill=>:x) +f1 = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true) +f.lower + +f.grid_anchor(:center) +TkGrid('x', b1, 'x', :in=>f, :padx=>3, :pady=>2) +TkGrid(b2, b4, b3, :in=>f, :padx=>3, :pady=>2) +TkGrid('x', b5, 'x', :in=>f, :padx=>3, :pady=>2) diff --git a/ext/tk/sample/demos-en/ttknote.rb b/ext/tk/sample/demos-en/ttknote.rb new file mode 100644 index 0000000000..c2a22b447a --- /dev/null +++ b/ext/tk/sample/demos-en/ttknote.rb @@ -0,0 +1,89 @@ +# ttknote.rb -- +# +# This demonstration script creates a toplevel window containing a Ttk +# notebook widget. +# +# based on "Id: ttknote.tcl,v 1.5 2007/12/13 15:27:07 dgp Exp" + +if defined?($ttknote_demo) && $ttknote_demo + $ttknote_demo.destroy + $ttknote_demo = nil +end + +$ttknote_demo = TkToplevel.new {|w| + title("Ttk Notebook Widget") + iconname("ttknote") + positionWindow(w) +} + +## See Code / Dismiss +Ttk::Frame.new($ttknote_demo) {|frame| + sep = Ttk::Separator.new(frame) + Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) + TkGrid('x', + Ttk::Button.new(frame, :text=>'See Code', + :image=>$image['view'], :compound=>:left, + :command=>proc{showCode 'ttknote'}), + Ttk::Button.new(frame, :text=>'Dismiss', + :image=>$image['delete'], :compound=>:left, + :command=>proc{ + $ttknote_demo.destroy + $ttknote_demo = nil + }), + :padx=>4, :pady=>4) + grid_columnconfigure(0, :weight=>1) + pack(:side=>:bottom, :fill=>:x) +} + +base_frame = Ttk::Frame.new($ttknote_demo).pack(:fill=>:both, :expand=>true) + +## Make the notebook and set up Ctrl+Tab traversal +notebook = Ttk::Notebook.new(base_frame).pack(:fill=>:both, :expand=>true, + :padx=>2, :pady=>3) +notebook.enable_traversal + +## Popuplate the first pane +f_msg = Ttk::Frame.new(notebook) +msg_m = Ttk::Label.new(f_msg, :font=>$font, :wraplength=>'4i', + :justify=>:left, :anchor=>'n', :text=><'Neat!', :underline=>0, + :command=>proc{ + neat.value = 'Yeah, I know...' + Tk.after_cancel(after_id) if after_id + after_id = Tk.after(500){neat.value = ''} + }) +msg_b.winfo_toplevel.bind('Alt-n'){ msg_b.focus; msg_b.invoke } +msg_l = Ttk::Label.new(f_msg, :textvariable=>neat) +notebook.add(f_msg, :text=>'Description', :underline=>0, :padding=>2) +Tk.grid(msg_m, '-', :sticky=>'new', :pady=>2) +Tk.grid(msg_b, msg_l, :pady=>[2, 4]) +f_msg.grid_rowconfigure(1, :weight=>1) +f_msg.grid_columnconfigure([0, 1], :weight=>1, :uniform=>1) + +## Populate the second pane. Note that the content doesn't really matter +f_disabled = Ttk::Frame.new(notebook) +notebook.add(f_disabled, :text=>'Disabled', :state=>:disabled) + +## Popuplate the third pane +f_editor = Ttk::Frame.new(notebook) +notebook.add(f_editor, :text=>'Text Editor', :underline=>0) +editor_t = Tk::Text.new(f_editor, :width=>40, :height=>10, :wrap=>:char) +if Tk.windowingsystem != 'aqua' + editor_s = editor_t.yscrollbar(Ttk::Scrollbar.new(f_editor)) +else + editor_s = editor_t.yscrollbar(Tk::Scrollbar.new(f_editor)) +end +editor_s.pack(:side=>:right, :fill=>:y, :padx=>[0,2], :pady=>2) +editor_t.pack(:fill=>:both, :expand=>true, :padx=>[2,0], :pady=>2) diff --git a/ext/tk/sample/demos-en/ttkpane.rb b/ext/tk/sample/demos-en/ttkpane.rb new file mode 100644 index 0000000000..56df613db4 --- /dev/null +++ b/ext/tk/sample/demos-en/ttkpane.rb @@ -0,0 +1,213 @@ +# ttkpane.rb -- +# +# This demonstration script creates a Ttk pane with some content. +# +# based on "Id: ttkpane.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp" + +if defined?($ttkpane_demo) && $ttkpane_demo + $ttkpane_demo.destroy + $ttkpane_demo = nil +end + +$ttkpane_demo = TkToplevel.new {|w| + title("Themed Nested Panes") + iconname("ttkpane") + positionWindow(w) +} + +base_frame = TkFrame.new($ttkpane_demo).pack(:fill=>:both, :expand=>true) + +Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left, + :text=><:top, :fill=>:x) +This demonstration shows off a nested set of themed paned windows. \ +Their sizes can be changed by grabbing the area \ +between each contained pane and dragging the divider. +EOL + +Ttk::Separator.new(base_frame).pack(:side=>:top, :fill=>:x) + +## See Code / Dismiss +Ttk::Frame.new(base_frame) {|frame| + sep = Ttk::Separator.new(frame) + Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) + TkGrid('x', + Ttk::Button.new(frame, :text=>'See Code', + :image=>$image['view'], :compound=>:left, + :command=>proc{showCode 'ttkpane'}), + Ttk::Button.new(frame, :text=>'Dismiss', + :image=>$image['delete'], :compound=>:left, + :command=>proc{ + $ttkpane_demo.destroy + $ttkpane_demo = nil + }), + :padx=>4, :pady=>4) + grid_columnconfigure(0, :weight=>1) + pack(:side=>:bottom, :fill=>:x) +} + +frame = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true) + +outer = Ttk::Panedwindow.new(frame, :orient=>:horizontal) +outer.add(in_left = Ttk::Panedwindow.new(outer, :orient=>:vertical)) +outer.add(in_right = Ttk::Panedwindow.new(outer, :orient=>:vertical)) +in_left.add(left_top = Ttk::Labelframe.new(in_left, :text=>'Button')) +in_left.add(left_bot = Ttk::Labelframe.new(in_left, :text=>'Clocks')) +in_right.add(right_top = Ttk::Labelframe.new(in_right, :text=>'Progress')) +in_right.add(right_bot = Ttk::Labelframe.new(in_right, :text=>'Text')) +if Tk.windowingsystem == 'aqua' + [left_top, left_bot, right_top, right_bot].each{|w| w.padding(3) } +end + +# Fill the button pane +Ttk::Button.new(left_top, :text=>'Press Me', + :command=>proc{ + Tk.messageBox(:type=>'ok', :icon=>'info', :message=>'Ouch!', + :detail=>'That hurt...', :parent=>base_frame, + :title=>'Button Pressed') + }).pack(:padx=>2, :pady=>5) + + +zones_list = [ + [':Europe/Berlin'], + [':America/Argentina/Buenos_Aires', ':America/Buenos_Aires'], + [':Africa/Johannesburg'], + [':Europe/London'], + [':America/Los_Angeles'], + [':Europe/Moscow'], + [':America/New_York'], + [':Asia/Singapore'], + [':Australia/Sydney'], + [':Asia/Tokyo'], +] + +zones = [] + +# Check tzinfo support +if $tk_major_ver > 8 || ($tk_major_ver == 8 && $tk_minor_ver >= 5) + tzinfo = :tcl + + # Force a pre-load of all the timezones needed; otherwise can end up + # poor-looking synch problems! + zones_list.each{|list| + list.each{|zone| + begin + Tk.tk_call('clock', 'format', '0', '-timezone', zone) + rescue RuntimeError + # ignore + else + zones << [zone, zone[%r<[^/:]+$>].tr('_', ' ')] + break + end + } + } + +else + begin + require 'tzinfo' + tzinfo = :tzinfo + rescue Exception + begin + require 'tzfile' + tzinfo = :tzfile + rescue Exception + tzinfo = nil + end + end + + case tzinfo + when :tzinfo + zones_list.each{|list| + list.each{|zone| + begin + tz = TZInfo::Timezone.get(zone[%r<[^:]+$>]) + rescue Exception + # ignore + else + zones << [tz, zone[%r<[^/:]+$>].tr('_', ' ')] + break + end + } + } + + when :tzfile + zones_list.each{|list| + list.each{|zone| + begin + tz = TZFile.create(zone[%r<[^:]+$>]) + rescue Exception + # ignore + else + zones << [tz, zone[%r<[^/:]+$>].tr('_', ' ')] + break + end + } + } + + else + [ -7, -4, -2, -1, 0, +1, +3, +8, +9, +10 ].each{|zone| + zones << [zone, 'UTC%+03d00' % zone] + } + end +end + +time = TkVariable.new_hash + +case tzinfo +when :tcl + update_proc = proc{|now, tz, label| + time[label] = Tk.tk_call('clock', 'format', now.tv_sec, + '-timezone', tz, '-format', '%T') + } +when :tzinfo + update_proc = proc{|now, tz, label| + time[label] = tz.utc_to_local(now).strftime('%H:%M:%S') + } +when :tzfile + update_proc = proc{|now, tz, label| + time[label] = tz.at(now.tv_sec).strftime('%H:%M:%S') + } +else + update_proc = proc{|now, tz, label| + time[label] = (now + (tz * 3600)).strftime('%H:%M:%S') + } +end + +# Fill the clocks pane +zones.each_with_index{|(zone, label), idx| + Ttk::Separator.new(left_bot).pack(:fill=>:x) if idx > 0 + Ttk::Label.new(left_bot, :text=>label, :anchor=>'w').pack(:fill=>:x) + Ttk::Label.new(left_bot, :textvariable=>time.ref(label), + :anchor=>'w').pack(:fill=>:x) +} + +# Timer start +every = proc{ + now = Time.now.utc + zones.each{|zone, label| update_proc.call(now, zone, label) } +} +TkRTTimer.new(1000, -1, every).start(0, every) + +# Fill the progress pane +Ttk::Progressbar.new(right_top, :mode=>:indeterminate).pack(:fill=>:both, :expand=>true).start + +# Fill the text pane +if Tk.windowingsystem != 'aqua' + # The trick with the ttk::frame makes the text widget look like it fits with + # the current Ttk theme despite not being a themed widget itself. It is done + # by styling the frame like an entry, turning off the border in the text + # widget, and putting the text widget in the frame with enough space to allow + # the surrounding border to show through (2 pixels seems to be enough). + f = Ttk::Frame.new(right_bot, :style=>Ttk::Entry) + txt = TkText.new(frame, :wrap=>:word, :width=>30, :borderwidth=>0) + txt.pack(:fill=>:both, :expand=>true, :in=>f, :pady=>2, :padx=>2) + scr = txt.yscrollbar(Ttk::Scrollbar.new(frame)) + scr.pack(:side=>:right, :fill=>:y, :in=>right_bot) + f.pack(:fill=>:both, :expand=>true) + outer.pack(:fill=>:both, :expand=>true) +else + txt = TkText.new(frame, :wrap=>:word, :width=>30, :borderwidth=>0) + scr = txt.yscrollbar(TkScrollbar.new(frame)) + scr.pack(:side=>:right, :fill=>:y, :in=>right_bot) + txt.pack(:fill=>:both, :expand=>true, :in=>right_bot) + outer.pack(:fill=>:both, :expand=>true, :padx=>10, :pady=>[6, 10]) +end diff --git a/ext/tk/sample/demos-en/ttkprogress.rb b/ext/tk/sample/demos-en/ttkprogress.rb new file mode 100644 index 0000000000..3eb9a64a4a --- /dev/null +++ b/ext/tk/sample/demos-en/ttkprogress.rb @@ -0,0 +1,66 @@ +# ttkprogress.rb -- +# +# This demonstration script creates several progress bar widgets. +# +# based on "Id: ttkprogress.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp" + +if defined?($ttkprogress_demo) && $ttkprogress_demo + $ttkprogress_demo.destroy + $ttkprogress_demo = nil +end + +$ttkprogress_demo = TkToplevel.new {|w| + title("Progress Bar Demonstration") + iconname("ttkprogress") + positionWindow(w) +} + +base_frame = TkFrame.new($ttkprogress_demo).pack(:fill=>:both, :expand=>true) + +Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left, + :text=>Tk::UTF8_String.new(<:top, :fill=>:x) +Below are two progress bars. \ +The top one is a \\u201Cdeterminate\\u201D progress bar, \ +which is used for showing how far through a defined task the program has got. \ +The bottom one is an \\u201Cindeterminate\\u201D progress bar, \ +which is used to show that the program is busy \ +but does not know how long for. Both are run here in self-animated mode, \ +which can be turned on and off using the buttons underneath. +EOL + +## See Code / Dismiss buttons +Ttk::Frame.new(base_frame) {|frame| + sep = Ttk::Separator.new(frame) + Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) + TkGrid('x', + Ttk::Button.new(frame, :text=>'See Code', + :image=>$image['view'], :compound=>:left, + :command=>proc{showCode 'ttkprogress'}), + Ttk::Button.new(frame, :text=>'Dismiss', + :image=>$image['delete'], :compound=>:left, + :command=>proc{ + $ttkprogress_demo.destroy + $ttkprogress_demo = nil + }), + :padx=>4, :pady=>4) + grid_columnconfigure(0, :weight=>1) + pack(:side=>:bottom, :fill=>:x) +} + +frame = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true) + +p1 = Ttk::Progressbar.new(frame, :mode=>:determinate) +p2 = Ttk::Progressbar.new(frame, :mode=>:indeterminate) + +start = Ttk::Button.new(frame, :text=>'Start Progress', + :command=>proc{ p1.start; p2.start }) +stop = Ttk::Button.new(frame, :text=>'Stop Progress', + :command=>proc{ p1.stop; p2.stop }) + +Tk.grid(p1, '-', :pady=>5, :padx=>10) +Tk.grid(p2, '-', :pady=>5, :padx=>10) +Tk.grid(start, stop, :padx=>10, :pady=>5) +start.grid_configure(:sticky=>'e') +stop.grid_configure(:sticky=>'w') +frame.grid_columnconfigure(:all, :weight=>1) + diff --git a/ext/tk/sample/demos-en/twind.rb b/ext/tk/sample/demos-en/twind.rb index f29e49f35a..65ee712ff7 100644 --- a/ext/tk/sample/demos-en/twind.rb +++ b/ext/tk/sample/demos-en/twind.rb @@ -19,8 +19,10 @@ $twind_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($twind_demo).pack(:fill=>:both, :expand=>true) + # frame -$twind_buttons = TkFrame.new($twind_demo) {|frame| +$twind_buttons = TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc{ @@ -39,13 +41,13 @@ $twind_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # frame $twind_text = nil -TkFrame.new($twind_demo, 'highlightthickness'=>2, 'borderwidth'=>2, +TkFrame.new(base_frame, 'highlightthickness'=>2, 'borderwidth'=>2, 'relief'=>'sunken') {|f| $twind_text = TkText.new(f, 'setgrid'=>'true', 'font'=>$font, 'width'=>'70', 'height'=>35, 'wrap'=>'word', 'highlightthickness'=>0, 'borderwidth'=>0 ){|t| TkScrollbar.new(f) {|s| - command proc{|*args| t.yview(args)} + command proc{|*args| t.yview(*args)} t.yscrollcommand proc{|first,last| s.set first,last} }.pack('side'=>'right', 'fill'=>'y') }.pack('expand'=>'yes', 'fill'=>'both') diff --git a/ext/tk/sample/demos-en/twind2.rb b/ext/tk/sample/demos-en/twind2.rb index c42e0999d7..43990c1151 100644 --- a/ext/tk/sample/demos-en/twind2.rb +++ b/ext/tk/sample/demos-en/twind2.rb @@ -15,8 +15,10 @@ $twind2_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($twind2_demo).pack(:fill=>:both, :expand=>true) + # frame -$twind2_buttons = TkFrame.new($twind2_demo) {|frame| +$twind2_buttons = TkFrame.new(base_frame) {|frame| TkGrid(TkFrame.new(frame, :height=>2, :relief=>:sunken, :bd=>2), :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) TkGrid('x', @@ -38,7 +40,7 @@ $twind2_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # frame $twind2_text = nil -TkFrame.new($twind2_demo, 'highlightthickness'=>2, 'borderwidth'=>2, +TkFrame.new(base_frame, 'highlightthickness'=>2, 'borderwidth'=>2, 'relief'=>'sunken') {|f| $twind2_text = TkText.new(f, 'setgrid'=>true, 'font'=>$font, # 'width'=>'70', 'height'=>35, 'wrap'=>'word', diff --git a/ext/tk/sample/demos-en/unicodeout.rb b/ext/tk/sample/demos-en/unicodeout.rb index 07e3bf52b5..9c230a2536 100644 --- a/ext/tk/sample/demos-en/unicodeout.rb +++ b/ext/tk/sample/demos-en/unicodeout.rb @@ -16,7 +16,9 @@ $unicodeout_demo = TkToplevel.new {|w| positionWindow(w) } -TkLabel.new($unicodeout_demo, +base_frame = TkFrame.new($unicodeout_demo).pack(:fill=>:both, :expand=>true) + +TkLabel.new(base_frame, :font=>$font, :wraplength=>'5.4i', :justify=>:left, :text=><:top) This is a sample of Tk's support for languages that use non-Western \ @@ -36,7 +38,7 @@ The strings are converted to the encoded string objects \ And the Tk::UTF8_String objects are passed to the label widgets. EOL -TkFrame.new($unicodeout_demo){|f| +TkFrame.new(base_frame){|f| pack(:side=>:bottom, :fill=>:x, :pady=>'2m') TkButton.new(f, :text=>'Dismiss', :width=>15, :command=>proc{ @@ -49,7 +51,7 @@ TkFrame.new($unicodeout_demo){|f| }).pack(:side=>:left, :expand=>true) } -wait_msg = TkLabel.new($unicodeout_demo, +wait_msg = TkLabel.new(base_frame, :text=>"Please wait while loading fonts...", :font=>"Helvetica 12 italic").pack @@ -63,8 +65,8 @@ class Unicodeout_SampleFrame < TkFrame # @@font = 'Newspaper 12' # @@font = '{New century schoolbook} 12' - def initialize() - super($unicodeout_demo) + def initialize(base) + super(base) grid_columnconfig(1, :weight=>1) end @@ -79,7 +81,7 @@ class Unicodeout_SampleFrame < TkFrame l.grid_config(:padx, '1m') end end -f = Unicodeout_SampleFrame.new +f = Unicodeout_SampleFrame.new(base_frame) f.pack(:expand=>true, :fill=>:both, :padx=>'2m', :pady=>'1m') # Processing when some characters are missing might take a while, so make diff --git a/ext/tk/sample/demos-en/vscale.rb b/ext/tk/sample/demos-en/vscale.rb index c0170467d5..b05ed12072 100644 --- a/ext/tk/sample/demos-en/vscale.rb +++ b/ext/tk/sample/demos-en/vscale.rb @@ -15,7 +15,9 @@ $vscale_demo = TkToplevel.new {|w| } positionWindow($vscale_demo) -msg = TkLabel.new($vscale_demo) { +base_frame = TkFrame.new($vscale_demo).pack(:fill=>:both, :expand=>true) + +msg = TkLabel.new(base_frame) { font $font wraplength '3.5i' justify 'left' @@ -23,7 +25,7 @@ msg = TkLabel.new($vscale_demo) { } msg.pack('side'=>'top', 'padx'=>'.5c') -TkFrame.new($vscale_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { text 'Dismiss' command proc { @@ -39,7 +41,17 @@ TkFrame.new($vscale_demo) {|frame| }.pack('side'=>'left', 'expand'=>'yes') }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') -TkFrame.new($vscale_demo) {|frame| +def setHeight(w, height) + height = height + 21 + y2 = height - 30 + if y2 < 21 + y2 = 21 + end + w.coords 'poly',15,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20 + w.coords 'line',15,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20 +end + +TkFrame.new(base_frame) {|frame| borderwidth 10 canvas = TkCanvas.new(frame) {|c| width 50 @@ -65,13 +77,3 @@ TkFrame.new($vscale_demo) {|frame| }.pack('side'=>'left', 'anchor'=>'ne') scale.set 75 }.pack - -def setHeight(w, height) - height = height + 21 - y2 = height - 30 - if y2 < 21 - y2 = 21 - end - w.coords 'poly',15,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20 - w.coords 'line',15,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20 -end diff --git a/ext/tk/sample/demos-en/widget b/ext/tk/sample/demos-en/widget index 391d8532b6..9a0605d8b9 100644 --- a/ext/tk/sample/demos-en/widget +++ b/ext/tk/sample/demos-en/widget @@ -14,6 +14,8 @@ require 'tk' ### $DEBUG=1 ########## +$RubyTk_WidgetDemo = true + #---------------------------------------------------------------- # The code below create the main window, consisting of a menu bar # and a text widget that explains how to use the program, plus lists @@ -103,14 +105,22 @@ EOD end # -TkMenubar.new($root, - [[['File', 0], - ['About ... ', proc{aboutBox}, 0, ''], - '---', - ['Quit', proc{exit}, 0, 'Meta-Q'] - ]]).pack('side'=>'top', 'fill'=>'x') +if $tk_major_ver >= 8 + $root.add_menubar([[['File', 0], + ['About ... ', proc{aboutBox}, 0, ''], + '---', + ['Quit', proc{exit}, 0, 'Ctrl-Q'] + ]]) +else + TkMenubar.new($root, + [[['File', 0], + ['About ... ', proc{aboutBox}, 0, ''], + '---', + ['Quit', proc{exit}, 0, 'Ctrl-Q'] + ]]).pack('side'=>'top', 'fill'=>'x') +end $root.bind('F1', proc{aboutBox}) -$root.bind('Meta-q', proc{exit}) +$root.bind('Control-q', proc{exit}) =begin TkFrame.new($root){|frame| @@ -257,7 +267,10 @@ the demonstration. Once the demonstration window appears, you can \ click the "See Code" button to see the Ruby/Tk code that created the \ demonstration. If you wish, you can edit the code and click the \ "Rerun Demo" button in the code window to reinvoke the demonstration \ -with the modified code. +with the modified code. \ +Don't worry about breaking the source code. \ +Your modifications are not reflected on the original file. \ +Please try many kind of changes. Some demo scripts require the recent version of Tk library \ (e.g. Tk8.4 or later) \ @@ -266,6 +279,20 @@ required by the demo script, the demo doesn't work. \ In such a case, please re-compile tcltklib with the later Tk library \ which supports the required functions. +If your Tk supports Ttk (Tile) extension (included or installed), \ +please try the demo of Ttk extension (sample/tkextlib/tile/demo.rb) too. +( Probably, Ttk extension \ +#{ +begin + require 'tkextlib/tile' + "is already installed on your environment" +rescue + "is not installed on your environment yet" +end +}\ +. ) +Ttk extension is a standard feature of Tk8.5 or later. + EOT @@ -299,6 +326,8 @@ txt.insert('end', "13. A simple user interface for viewing images. (if supported txt.insert('end', " \n ", tag_demospace) txt.insert('end', "14. Labelled frames (if supported)\n", tag_demo, "demo-labelframe") txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "15. The simple Themed Tk widgets (require Tile/Ttk extension)\n", tag_demo, "demo-ttkbut") +txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") txt.insert('end', "Listboxes\n", tag_title) @@ -309,6 +338,10 @@ txt.insert('end', "2. Colors: change the color scheme for the application.\n", " txt.insert('end', " \n ", tag_demospace) txt.insert('end', "3. A collection of famous sayings.\n", tag_demo, "demo-sayings") txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "4. A multi-column list of contries. (require Tile/Ttk extension)\n", tag_demo, "demo-mclist") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "5. A directory browser tree. (require Tile/Ttk extension)\n", tag_demo, "demo-tree") +txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") txt.insert('end', "Entries and Spin-boxes\n", tag_title) @@ -323,7 +356,9 @@ txt.insert('end', txt.insert('end', " \n ", tag_demospace) txt.insert('end', "4. Spin-boxes. (if supported)\n", tag_demo, "demo-spin") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "5. Simple Rolodex-like form.\n", tag_demo, "demo-form") +txt.insert('end', "5. Combo-boxes. (require Tile/Ttk extension)\n", tag_demo, "demo-combo") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "6. Simple Rolodex-like form.\n", tag_demo, "demo-form") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") @@ -363,31 +398,43 @@ txt.insert('end', "7. A building floor plan. (another way to create canvas items txt.insert('end', " \n ", tag_demospace) txt.insert('end', "8. A simple scrollable canvas.\n", tag_demo, "demo-cscroll") txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "9. A Knight's tour of the chess board. (require Tile/Ttk extension)\n", tag_demo, "demo-knightstour") +txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") -txt.insert('end', "Scales\n", tag_title) +txt.insert('end', "Scales and Progress Bars\n", tag_title) txt.insert('end', " \n ", tag_demospace) txt.insert('end', "1. Vertical scale.\n", tag_demo.id, "demo-vscale") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "2. Horizontal scale.\n", tag_demo.id, "demo-hscale") txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "3. Progress bar. (require Tile/Ttk extension)\n", tag_demo.id, "demo-ttkprogress") +txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") -txt.insert('end', "Paned Windows\n", tag_title) +txt.insert('end', "Paned Windows and Notebooks\n", tag_title) txt.insert('end', " \n ", tag_demospace) txt.insert('end', "1. Horizontal paned window. (if supported)\n", tag_demo.id, "demo-paned1") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "2. Vertical paned window. (if supported)\n", tag_demo.id, "demo-paned2") txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "3. Themed nested panes. (require Tile/Ttk extension)\n", tag_demo.id, "demo-ttkpane") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "4. Notebook widget. (require Tile/Ttk extension)\n", tag_demo.id, "demo-ttknote") +txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") -txt.insert('end', "Menus\n", tag_title) +txt.insert('end', "Menus and Toolbars\n", tag_title) txt.insert('end', " \n ", tag_demospace) txt.insert('end', "1. Menus and cascades.\n", tag_demo, "demo-menu") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "2. Menus and cascades. (if supported)\n", tag_demo, "demo-menu84") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "3. Menubuttons\n", tag_demo, "demo-menubu") +txt.insert('end', "3. Menubuttons.\n", tag_demo, "demo-menubu") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "4. Themed menu buttons. (require Tile/Ttk extension)\n", tag_demo, "demo-ttkmenu") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "5. Themed toolbar. (require Tile/Ttk extension)\n", tag_demo, "demo-toolbar") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") @@ -395,9 +442,11 @@ txt.insert('end', "Common Dialogs\n", tag_title) txt.insert('end', " \n ", tag_demospace) txt.insert('end', "1. Message boxes.\n", tag_demo, "demo-msgbox") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "2. File selection dialog.\n", tag_demo, "demo-filebox") +txt.insert('end', "2. Message boxes with detail text. (if supported)\n", tag_demo, "demo-msgbox2") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "3. Color picker.\n", tag_demo, "demo-clrpick") +txt.insert('end', "3. File selection dialog.\n", tag_demo, "demo-filebox") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "4. Color picker.\n", tag_demo, "demo-clrpick") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") @@ -453,7 +502,8 @@ def showVars1(parent, *args) end w = TkToplevel.new(parent) {|w| title "Variable values" - TkLabel.new(w) { + base = TkFrame.new(w).pack(:fill=>:both, :expand=>true) + TkLabel.new(base) { text "Variable values:" width 20 anchor 'center' @@ -475,7 +525,7 @@ def showVars1(parent, *args) .pack('side'=>'left', 'expand'=>'yes', 'fill'=>'x') }.pack('side'=>'top', 'anchor'=>'w', 'fill'=>'x') } - TkButton.new(w) { + TkButton.new(base) { text "OK" command proc{w.destroy} }.pack('side'=>'bottom', 'pady'=>2) @@ -490,10 +540,12 @@ def showVars2(parent, *args) rescue end end - $showVarsWin[parent.path] = TkToplevel.new(parent) {|w| + $showVarsWin[parent.path] = TkToplevel.new(parent) {|top| title "Variable values" - TkLabelFrame.new(w, :text=>"Variable values:", + base = TkFrame.new(top).pack(:fill=>:both, :expand=>true) + + TkLabelFrame.new(base, :text=>"Variable values:", :font=>{:family=>'Helvetica', :size=>14}){|f| args.each{|vnam,vbody| TkGrid(TkLabel.new(f, :text=>"#{vnam}: ", :anchor=>'w'), @@ -505,15 +557,15 @@ def showVars2(parent, *args) f.grid_columnconfig(1, :weight=>1) f.grid_rowconfig(100, :weight=>1) } - TkButton.new(w, :text=>"OK", :width=>8, :default=>:active, - :command=>proc{w.destroy}){|b| - w.bind('Return', proc{b.invoke}) - w.bind('Escape', proc{b.invoke}) + TkButton.new(base, :text=>"OK", :width=>8, :default=>:active, + :command=>proc{top.destroy}){|b| + top.bind('Return', proc{b.invoke}) + top.bind('Escape', proc{b.invoke}) b.grid(:sticky=>'e', :padx=>4, :pady=>[6, 4]) } - w.grid_columnconfig(0, :weight=>1) - w.grid_rowconfig(0, :weight=>1) + base.grid_columnconfig(0, :weight=>1) + base.grid_rowconfig(0, :weight=>1) } end @@ -607,10 +659,27 @@ def _null_binding end private :_null_binding -def eval_samplecode(code) +def eval_samplecode(code, file=nil) #eval(code) #_null_binding.pseudo_toplevel_eval{ eval(code) } - Thread.new{ _null_binding.pseudo_toplevel_eval{ eval(code) } } + #Thread.new{ _null_binding.pseudo_toplevel_eval{ eval(code) } } + Thread.new{ + _null_binding.pseudo_toplevel_eval{ + begin + if file + eval(code, binding, "(eval:#{file})") + else + eval(code) + end + rescue Exception=>e + #p e + TkBgError.show(e.class.inspect + ': ' + e.message + "\n" + + "\n---< backtrace of Ruby side >-----\n" + + e.backtrace.join("\n") + + "\n---< backtrace of Tk side >-------") + end + } + } Tk.update end @@ -630,7 +699,7 @@ def invoke(txt, idx) Tk.update # eval(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join, _null_binding) # Tk.update - eval_samplecode(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join) + eval_samplecode(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join, tag[5..-1] + '.rb') txt.cursor(cursor) $tag_visited.add("#{idx} linestart +1 chars", "#{idx} lineend +1 chars") @@ -687,20 +756,32 @@ def showCode1(demo) if $code_window == nil || TkWinfo.exist?($code_window) == false $code_window = TkToplevel.new(nil) f = TkFrame.new($code_window) + TkButton.new(f) { text "Dismiss" command proc{ $code_window.destroy $code_window = nil } - }.pack('side'=>'left', 'expand'=>'yes', 'pady'=>2) + }.pack('side'=>'right', 'expand'=>'false', 'pady'=>2, 'padx'=>25) TkButton.new(f) { text "Rerun Demo" # command proc{eval($code_text.get('1.0','end'), _null_binding)} - command proc{eval_samplecode($code_text.get('1.0','end'))} - }.pack('side'=>'left', 'expand'=>'yes', 'pady'=>2) -# f.pack('side'=>'bottom', 'expand'=>'yes', 'fill'=>'x') - f.pack('side'=>'bottom', 'fill'=>'x') + command proc{eval_samplecode($code_text.get('1.0','end'), '')} + }.pack('side'=>'right', 'expand'=>'false', 'pady'=>2) + + TkLabel.new(f,'text'=>'line:').pack('side'=>'left') + linenum =TkLabel.new(f,'text'=>'').pack('side'=>'left') + TkLabel.new(f,'text'=>' pos:').pack('side'=>'left') + posnum =TkLabel.new(f,'text'=>'').pack('side'=>'left') + + $set_linenum = proc{|w| + line, pos = w.index('insert').split('.') + linenum.text = line + posnum.text = pos + } + + f.pack('side'=>'bottom', 'expand'=>'true', 'fill'=>'x') if $tk_version =~ /^4\.[01]/ s = TkScrollbar.new($code_window, 'orient'=>'vertical') @@ -745,10 +826,21 @@ def showCode1(demo) TkGrid.columnconfigure(f, 0, 'weight'=>1, 'minsize'=>0) } end + + btag = TkBindTag.new + + btag.bind('Key', $set_linenum, '%W') + btag.bind('Button', $set_linenum, '%W') + + btags = $code_text.bindtags + btags.insert(btags.index($code_text.class) + 1, btag) + $code_text.bindtags = btags + else $code_window.deiconify $code_window.raise end + $code_window.title("Demo code: #{file}") $code_window.iconname(file) # fid = open(file, 'r') @@ -759,6 +851,9 @@ def showCode1(demo) #$code_mark = TkTextMark.new($code_text, '1.0') #$code_text.set_insert('1.0') TkTextMarkInsert.new($code_text,'1.0') + + $set_linenum.call($code_text) + fid.close end @@ -779,7 +874,19 @@ def showCode2(demo) tf.grid_columnconfigure(0, :weight=>1) bf = TkFrame.new($code_window) - + + lf = TkFrame.new(bf) + TkLabel.new(lf, :text=>'line:').pack(:side=>:left) + linenum =TkLabel.new(lf, :text=>'').pack(:side=>:left) + TkLabel.new(lf, :text=>' pos:').pack(:side=>:left) + posnum =TkLabel.new(lf, :text=>'').pack(:side=>:left) + + $set_linenum = proc{|w| + line, pos = w.index('insert').split('.') + linenum.text = line + posnum.text = pos + } + b_dis = TkButton.new(bf, :text=>'Dismiss', :default=>:active, :command=>proc{ $code_window.destroy @@ -792,12 +899,12 @@ def showCode2(demo) b_run = TkButton.new(bf, :text=>'Rerun Demo', :command=>proc{ # eval($code_text.get('1.0','end'), _null_binding) - eval_samplecode($code_text.get('1.0','end')) + eval_samplecode($code_text.get('1.0','end'), '') }, :image=>$image['refresh'], :compound=>:left) - TkGrid('x', b_run, b_prn, b_dis, :padx=>4, :pady=>[6,4]) - bf.grid_columnconfigure(0, :weight=>1) + TkGrid(lf, 'x', b_run, b_prn, b_dis, :padx=>4, :pady=>[6,4]) + bf.grid_columnconfigure(1, :weight=>1) TkGrid(tf, :sticky=>'news') TkGrid(bf, :sticky=>'ew') @@ -810,6 +917,17 @@ def showCode2(demo) $code_window.bindinfo('Return').each{|cmd, arg| $code_window.bind_append('Escape', cmd, arg) } + + btag = TkBindTag.new + + btag.bind('Key', $set_linenum, '%W') + btag.bind('Button', $set_linenum, '%W') + btag.bind('Configure', $set_linenum, '%W') + + btags = $code_text.bindtags + btags.insert(btags.index($code_text.class) + 1, btag) + $code_text.bindtags = btags + else $code_window.deiconify $code_window.raise @@ -821,6 +939,9 @@ def showCode2(demo) $code_text.delete('1.0', 'end') $code_text.insert('1.0', fid.read) TkTextMarkInsert.new($code_text,'1.0') + + $set_linenum.call($code_text) + fid.close end @@ -914,12 +1035,13 @@ end # def aboutBox Tk.messageBox('icon'=>'info', 'type'=>'ok', 'title'=>'About Widget Demo', - 'message'=>"Ruby/Tk widget demonstration Ver.1.6.3-en\n\n" + + 'message'=>"Ruby/Tk widget demonstration Ver.1.7.0-en\n\n" + "based on demos of Tk8.1 -- 8.5 " + - "( Copyright:: " + + "( Copyright of Tcl/Tk demos:: " + "(c) 1996-1997 Sun Microsystems, Inc. / " + "(c) 1997-2000 Ajuba Solutions, Inc. / " + - "(c) 2001-2003 Donal K. Fellows )\n\n" + + "(c) 2001-2007 Donal K. Fellows / " + + "(c) 2002-2007 Daniel A. Steffen )\n\n" + "Your Ruby & Tk Version ::\n" + "Ruby#{RUBY_VERSION}(#{RUBY_RELEASE_DATE})[#{RUBY_PLATFORM}] / Tk#{$tk_patchlevel}#{(Tk::JAPANIZED_TK)? '-jp': ''}\n\n" + "Ruby/Tk release date :: tcltklib #{TclTkLib::RELEASE_DATE}; tk #{Tk::RELEASE_DATE}") @@ -941,7 +1063,7 @@ ARGV.each{|cmd| end #eval(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join, # _null_binding) - eval_samplecode(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join) + eval_samplecode(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join, cmd + '.rb') } if no_launcher $root.withdraw # hide root window diff --git a/ext/tk/sample/demos-jp/anilabel.rb b/ext/tk/sample/demos-jp/anilabel.rb index c6e5c7385b..aee57f9f6a 100644 --- a/ext/tk/sample/demos-jp/anilabel.rb +++ b/ext/tk/sample/demos-jp/anilabel.rb @@ -17,8 +17,10 @@ $anilabel_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($anilabel_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -msg = TkLabel.new($anilabel_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -27,7 +29,7 @@ msg = TkLabel.new($anilabel_demo) { msg.pack('side'=>'top') # frame À¸À® -TkFrame.new($anilabel_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -46,8 +48,8 @@ TkFrame.new($anilabel_demo) {|frame| }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # label demo Íѥե졼¥àÀ¸À® -f_left = TkLabelFrame.new($anilabel_demo, :text=>'Scrolling Texts') -f_right = TkLabelFrame.new($anilabel_demo, :text=>'GIF Image') +f_left = TkLabelFrame.new(base_frame, :text=>'Scrolling Texts') +f_right = TkLabelFrame.new(base_frame, :text=>'GIF Image') Tk.pack(f_left, f_right, 'side'=>'left', 'expand'=>'yes', 'fill'=>'both', 'padx'=>10, 'pady'=>10) diff --git a/ext/tk/sample/demos-jp/aniwave.rb b/ext/tk/sample/demos-jp/aniwave.rb index 5f94add111..8fa14f65fe 100644 --- a/ext/tk/sample/demos-jp/aniwave.rb +++ b/ext/tk/sample/demos-jp/aniwave.rb @@ -17,8 +17,10 @@ $aniwave_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($aniwave_demo).pack(:fill=>:both, :expand=>true) + # create label -msg = TkLabel.new($aniwave_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -27,7 +29,7 @@ msg = TkLabel.new($aniwave_demo) { msg.pack('side'=>'top') # create frame -TkFrame.new($aniwave_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -60,6 +62,7 @@ class AnimatedWaveDemo @backupCoords = [] n = 0 (-10..300).step(5){|n| @waveCoords << [n, 100]; @backupCoords << [n, 100] } + n = 305 @waveCoords << [n, 0]; @backupCoords << [n, 0] @waveCoords << [n+5, 200]; @backupCoords << [n+5, 200] @coordsLen = @waveCoords.length @@ -114,4 +117,4 @@ class AnimatedWaveDemo end # Start the animation processing -AnimatedWaveDemo.new($aniwave_demo, :left).move +AnimatedWaveDemo.new(base_frame, :left).move diff --git a/ext/tk/sample/demos-jp/arrow.rb b/ext/tk/sample/demos-jp/arrow.rb index b2c1067027..3c49e67b09 100644 --- a/ext/tk/sample/demos-jp/arrow.rb +++ b/ext/tk/sample/demos-jp/arrow.rb @@ -104,14 +104,16 @@ $arrow_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($arrow_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -TkLabel.new($arrow_demo, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left', +TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left', 'text'=>"¤³¤Î widget ¤Ç¡¢¥­¥ã¥ó¥Ð¥¹¤Ç»È¤ï¤ì¤ë¥é¥¤¥ó¤Ë¤Ä¤¤¤ÆÍÍ¡¹¤ÊÉý¤äÌð°õ¤ÎƬ¤Î·Á¤ò»î¤·¤Æ¤ß¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£Àþ¤ÎÉý¤äÌð°õ¤Î·Á¤òÊѤ¨¤ë¤Ë¤Ï¡¢³ÈÂ礵¤ì¤¿Ìð°õ¤Ë¤Ä¤¤¤Æ¤¤¤ë 3¤Ä¤Î»Í³Ñ¤ò¥É¥é¥Ã¥°¤·¤Æ¤¯¤À¤µ¤¤¡£±¦Â¦¤ÎÌð°õ¤ÏÉáÄ̤ÎÂ礭¤µ¤Ç¤Î¥µ¥ó¥×¥ë¤ò¼¨¤·¤Æ¤¤¤Þ¤¹¡£²¼¤Î¥Æ¥­¥¹¥È¤Ï¥é¥¤¥ó¥¢¥¤¥Æ¥à¤ËÂФ¹¤ëÀßÄꥪ¥×¥·¥ç¥ó¤Ç¤¹¡£"){ pack('side'=>'top') } # frame À¸À® -$arrow_buttons = TkFrame.new($arrow_demo) {|frame| +$arrow_buttons = TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -130,7 +132,7 @@ $arrow_buttons = TkFrame.new($arrow_demo) {|frame| $arrow_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # canvas ÀßÄê -$arrow_canvas = TkCanvas.new($arrow_demo, 'width'=>500, 'height'=>350, +$arrow_canvas = TkCanvas.new(base_frame, 'width'=>500, 'height'=>350, 'relief'=>'sunken', 'borderwidth'=>2) $arrow_canvas.pack('expand'=>'yes', 'fill'=>'both') diff --git a/ext/tk/sample/demos-jp/bind.rb b/ext/tk/sample/demos-jp/bind.rb index 3b6f6242c2..a1bcfdd2e7 100644 --- a/ext/tk/sample/demos-jp/bind.rb +++ b/ext/tk/sample/demos-jp/bind.rb @@ -16,8 +16,10 @@ $bind_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($bind_demo).pack(:fill=>:both, :expand=>true) + # frame À¸À® -TkFrame.new($bind_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -41,14 +43,14 @@ def tag_binding_for_bind_demo(tag, enter_style, leave_style) end # text À¸À® -txt = TkText.new($bind_demo){|t| +txt = TkText.new(base_frame){|t| # À¸À® setgrid 'true' #width 60 #height 24 font $font wrap 'word' - TkScrollbar.new($bind_demo) {|s| + TkScrollbar.new(base_frame) {|s| pack('side'=>'right', 'fill'=>'y') command proc{|*args| t.yview(*args)} t.yscrollcommand proc{|first,last| s.set first,last} @@ -92,32 +94,32 @@ txt = TkText.new($bind_demo){|t| } d1.bind('1', proc{ - eval_samplecode(`cat #{[$demo_dir,'items.rb'].join(File::Separator)}`) + eval_samplecode(`cat #{[$demo_dir,'items.rb'].join(File::Separator)}`, 'items.rb') }) d2.bind('1', proc{ - eval_samplecode(`cat #{[$demo_dir,'plot.rb'].join(File::Separator)}`) + eval_samplecode(`cat #{[$demo_dir,'plot.rb'].join(File::Separator)}`, 'plot.rb') }) d3.bind('1', proc{ - eval_samplecode(`cat #{[$demo_dir,'ctext.rb'].join(File::Separator)}`) + eval_samplecode(`cat #{[$demo_dir,'ctext.rb'].join(File::Separator)}`, 'ctext.rb') }) d4.bind('1', proc{ - eval_samplecode(`cat #{[$demo_dir,'arrow.rb'].join(File::Separator)}`) + eval_samplecode(`cat #{[$demo_dir,'arrow.rb'].join(File::Separator)}`, 'arrow.rb') }) d5.bind('1', proc{ - eval_samplecode(`cat #{[$demo_dir,'ruler.rb'].join(File::Separator)}`) + eval_samplecode(`cat #{[$demo_dir,'ruler.rb'].join(File::Separator)}`, 'ruler.rb') }) d6.bind('1', proc{ - eval_samplecode(`cat #{[$demo_dir,'cscroll.rb'].join(File::Separator)}`) + eval_samplecode(`cat #{[$demo_dir,'cscroll.rb'].join(File::Separator)}`, 'cscroll.rb') }) TkTextMarkInsert.new(t, '0.0') configure('state','disabled') } -txt.width 60 -txt.width 24 +txt.width 60 +txt.height 24 diff --git a/ext/tk/sample/demos-jp/bitmap.rb b/ext/tk/sample/demos-jp/bitmap.rb index 4594892c81..b6b0e54bbe 100644 --- a/ext/tk/sample/demos-jp/bitmap.rb +++ b/ext/tk/sample/demos-jp/bitmap.rb @@ -19,7 +19,7 @@ def bitmapRow(w,*args) TkFrame.new(row){|base| pack('side'=>'left', 'fill'=>'both', 'pady'=>'.25c', 'padx'=>'.25c') TkLabel.new(base, 'text'=>bitmap, 'width'=>9).pack('side'=>'bottom') - TkLabel.new(base, 'bitmap'=>bitmap).pack('side'=>'bottom') + Tk::Label.new(base, 'bitmap'=>bitmap).pack('side'=>'bottom') } end } @@ -38,14 +38,16 @@ $bitmap_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($bitmap_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -TkLabel.new($bitmap_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left', +TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left', 'text'=>"¤³¤Î¥¦¥£¥ó¥É¥¦¤Ë¤Ï¡¢Tk ¤ËÁȤ߹þ¤Þ¤ì¤¿¤¹¤Ù¤Æ¤Î¥Ó¥Ã¥È¥Þ¥Ã¥×¤¬¡¢¤½¤ì¤é¤Î̾Á°¤È¶¦¤Ëɽ¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡£Tcl ¤Î¥¹¥¯¥ê¥×¥ÈÃæ¤Ç¤Ï¡¢¤½¤ì¤¾¤ì¤Î̾Á°¤òÍѤ¤¤Æ»²¾È¤·¤Þ¤¹¡£"){ pack('side'=>'top') } # frame À¸À® -$bitmap_buttons = TkFrame.new($bitmap_demo) {|frame| +$bitmap_buttons = TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -64,7 +66,7 @@ $bitmap_buttons = TkFrame.new($bitmap_demo) {|frame| $bitmap_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # frame ÀßÄê -TkFrame.new($bitmap_demo){|f| +TkFrame.new(base_frame){|f| bitmapRow(f,'error','gray25','gray50','hourglass') bitmapRow(f,'info','question','questhead','warning') pack('side'=>'top', 'expand'=>'yes', 'fill'=>'both') diff --git a/ext/tk/sample/demos-jp/button.rb b/ext/tk/sample/demos-jp/button.rb index 7e9457f5b4..18e42008c9 100644 --- a/ext/tk/sample/demos-jp/button.rb +++ b/ext/tk/sample/demos-jp/button.rb @@ -2,6 +2,7 @@ # # button widget demo (called by 'widget') # +# # toplevel widget ¤¬Â¸ºß¤¹¤ì¤Ðºï½ü¤¹¤ë if defined?($button_demo) && $button_demo @@ -26,7 +27,7 @@ msg = TkLabel.new($button_demo) { msg.pack('side'=>'top') # frame À¸À® -$button_buttons = TkFrame.new($button_demo) {|frame| +$button_buttons = Tk::Frame.new($button_demo) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' diff --git a/ext/tk/sample/demos-jp/check.rb b/ext/tk/sample/demos-jp/check.rb index 7545df80fa..b953e7f623 100644 --- a/ext/tk/sample/demos-jp/check.rb +++ b/ext/tk/sample/demos-jp/check.rb @@ -16,8 +16,10 @@ $check_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($check_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -msg = TkLabel.new($check_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -31,7 +33,7 @@ brakes = TkVariable.new(0) sober = TkVariable.new(0) # frame À¸À® -TkFrame.new($check_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -52,7 +54,7 @@ TkFrame.new($check_demo) {|frame| TkButton.new(frame) { text 'ÊÑ¿ô»²¾È' command proc{ - showVars($check_demo, + showVars(base_frame, ['wipers', wipers], ['brakes', brakes], ['sober', sober]) } }.pack('side'=>'left', 'expand'=>'yes') @@ -61,8 +63,8 @@ TkFrame.new($check_demo) {|frame| # checkbutton À¸À® -[ TkCheckButton.new($check_demo, 'text'=>'¥ï¥¤¥Ñ¡¼ OK', 'variable'=>wipers), - TkCheckButton.new($check_demo, 'text'=>'¥Ö¥ì¡¼¥­ OK', 'variable'=>brakes), - TkCheckButton.new($check_demo, 'text'=>'±¿Å¾¼ê ÁÇÌÌ', 'variable'=>sober) +[ TkCheckButton.new(base_frame, 'text'=>'¥ï¥¤¥Ñ¡¼ OK', 'variable'=>wipers), + TkCheckButton.new(base_frame, 'text'=>'¥Ö¥ì¡¼¥­ OK', 'variable'=>brakes), + TkCheckButton.new(base_frame, 'text'=>'±¿Å¾¼ê ÁÇÌÌ', 'variable'=>sober) ].each{|w| w.relief('flat'); w.pack('side'=>'top', 'pady'=>2, 'anchor'=>'w')} diff --git a/ext/tk/sample/demos-jp/check2.rb b/ext/tk/sample/demos-jp/check2.rb index 90c6dd736f..7f7cb9e932 100644 --- a/ext/tk/sample/demos-jp/check2.rb +++ b/ext/tk/sample/demos-jp/check2.rb @@ -16,8 +16,10 @@ $check2_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($check2_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -msg = TkLabel.new($check2_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -32,7 +34,7 @@ brakes = TkVariable.new(0) sober = TkVariable.new(0) # frame À¸À® -TkFrame.new($check2_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkGrid(TkFrame.new(frame, :height=>2, :relief=>:sunken, :bd=>2), :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) TkGrid('x', @@ -60,15 +62,15 @@ TkFrame.new($check2_demo) {|frame| # checkbutton À¸À® -TkCheckButton.new($check2_demo, :text=>'°ÂÁ´À­¸¡ºº', :variable=>safety, +TkCheckButton.new(base_frame, :text=>'°ÂÁ´À­¸¡ºº', :variable=>safety, :relief=>:flat, :onvalue=>'all', :offvalue=>'none', :tristatevalue=>'partial'){ pack('side'=>'top', 'pady'=>2, 'anchor'=>'w') } -[ TkCheckButton.new($check2_demo, 'text'=>'¥ï¥¤¥Ñ¡¼ OK', 'variable'=>wipers), - TkCheckButton.new($check2_demo, 'text'=>'¥Ö¥ì¡¼¥­ OK', 'variable'=>brakes), - TkCheckButton.new($check2_demo, 'text'=>'±¿Å¾¼ê ÁÇÌÌ', 'variable'=>sober) +[ TkCheckButton.new(base_frame, 'text'=>'¥ï¥¤¥Ñ¡¼ OK', 'variable'=>wipers), + TkCheckButton.new(base_frame, 'text'=>'¥Ö¥ì¡¼¥­ OK', 'variable'=>brakes), + TkCheckButton.new(base_frame, 'text'=>'±¿Å¾¼ê ÁÇÌÌ', 'variable'=>sober) ].each{|w| w.relief('flat') w.pack('side'=>'top', 'padx'=>15, 'pady'=>2, 'anchor'=>'w') diff --git a/ext/tk/sample/demos-jp/clrpick.rb b/ext/tk/sample/demos-jp/clrpick.rb index d81ecebc83..ce6b99ab94 100644 --- a/ext/tk/sample/demos-jp/clrpick.rb +++ b/ext/tk/sample/demos-jp/clrpick.rb @@ -2,6 +2,8 @@ # # widget demo prompts the user to select a color (called by 'widget') # +# Note: don't support ttk_wrapper. work with standard widgets only. +# # toplevel widget ¤¬Â¸ºß¤¹¤ì¤Ðºï½ü¤¹¤ë if defined?($clrpick_demo) && $clrpick_demo @@ -17,12 +19,15 @@ $clrpick_demo = TkToplevel.new {|w| } # label À¸À® -TkLabel.new($clrpick_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left', +#TkLabel.new($clrpick_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left', +Tk::Label.new($clrpick_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left', 'text'=>"°Ê²¼¤Î¥Ü¥¿¥ó¤ò²¡¤·¤Æ¡¢¤³¤Î¥¦¥£¥ó¥É¥¦¾å¤Ë¤¢¤ë¥¦¥£¥¸¥§¥Ã¥È¤ÎÁ°·Ê¿§¤ÈÇØ·Ê¿§¤òÁªÂò¤·¤Æ²¼¤µ¤¤¡£").pack('side'=>'top') # frame À¸À® -TkFrame.new($clrpick_demo) {|frame| - TkButton.new(frame) { +# TkFrame.new($clrpick_demo) {|frame| +Tk::Frame.new($clrpick_demo) {|frame| + # TkButton.new(frame) { + Tk::Button.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' command proc{ @@ -32,20 +37,23 @@ TkFrame.new($clrpick_demo) {|frame| } }.pack('side'=>'left', 'expand'=>'yes') - TkButton.new(frame) { + # TkButton.new(frame) { + Tk::Button.new(frame) { text '¥³¡¼¥É»²¾È' command proc{showCode 'clrpick'} }.pack('side'=>'left', 'expand'=>'yes') }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # button À¸À® -TkButton.new($clrpick_demo, 'text'=>'ÇØ·Ê¿§¤òÀßÄê ...') {|b| +# TkButton.new($clrpick_demo, 'text'=>'ÇØ·Ê¿§¤òÀßÄê ...') {|b| +Tk::Button.new($clrpick_demo, 'text'=>'ÇØ·Ê¿§¤òÀßÄê ...') {|b| command(proc{setColor $clrpick_demo, b, 'background', ['background', 'highlightbackground']}) pack('side'=>'top', 'anchor'=>'c', 'pady'=>'2m') } -TkButton.new($clrpick_demo, 'text'=>'Á°·Ê¿§¤òÀßÄê ...') {|b| +# TkButton.new($clrpick_demo, 'text'=>'Á°·Ê¿§¤òÀßÄê ...') {|b| +Tk::Button.new($clrpick_demo, 'text'=>'Á°·Ê¿§¤òÀßÄê ...') {|b| command(proc{setColor $clrpick_demo, b, 'foreground', ['foreground']}) pack('side'=>'top', 'anchor'=>'c', 'pady'=>'2m') } diff --git a/ext/tk/sample/demos-jp/colors.rb b/ext/tk/sample/demos-jp/colors.rb index 68b40e69f0..91817a947b 100644 --- a/ext/tk/sample/demos-jp/colors.rb +++ b/ext/tk/sample/demos-jp/colors.rb @@ -16,8 +16,10 @@ $colors_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($colors_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -msg = TkLabel.new($colors_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -26,7 +28,7 @@ msg = TkLabel.new($colors_demo) { msg.pack('side'=>'top') # frame À¸À® -TkFrame.new($colors_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -46,7 +48,7 @@ TkFrame.new($colors_demo) {|frame| # frame À¸À® colors_lbox = nil -TkFrame.new($colors_demo, 'borderwidth'=>10) {|w| +TkFrame.new(base_frame, 'borderwidth'=>10) {|w| s = TkScrollbar.new(w) colors_lbox = TkListbox.new(w) { setgrid 1 @@ -59,7 +61,15 @@ TkFrame.new($colors_demo, 'borderwidth'=>10) {|w| colors_lbox.pack('side'=>'left', 'expand'=>1, 'fill'=>'both') }.pack('side'=>'top', 'expand'=>'yes', 'fill'=>'y') -colors_lbox.bind('Double-1', proc{TkPalette.setPalette TkSelection.get}) +#colors_lbox.bind('Double-1', proc{TkPalette.setPalette TkSelection.get}) +colors_lbox.bind('Double-1', proc{ + begin + TkPalette.setPalette TkSelection.get + rescue => e + p e + Tk.tk_call_without_enc('destroy', '.___tk_set_palette') + end + }) ins_data = [ 'gray60','gray70','gray80','gray85','gray90','gray95', diff --git a/ext/tk/sample/demos-jp/combo.rb b/ext/tk/sample/demos-jp/combo.rb new file mode 100644 index 0000000000..da00d712ba --- /dev/null +++ b/ext/tk/sample/demos-jp/combo.rb @@ -0,0 +1,98 @@ +# -*- coding: euc-jp -*- +# +# combo.rb -- +# +# This demonstration script creates several combobox widgets. +# +# based on "Id: combo.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp" + +if defined?($combo_demo) && $combo_demo + $combo_demo.destroy + $combo_demo = nil +end + +$combo_demo = TkToplevel.new {|w| + title("Combobox Demonstration") + iconname("combo") + positionWindow(w) +} + +base_frame = TkFrame.new($combo_demo).pack(:fill=>:both, :expand=>true) + +Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'5i', :justify=>:left, + :text=><:top, :fill=>:x) +°Ê²¼¤Ç¤Ï3¼ïÎà¤Î¥³¥ó¥Ü¥Ü¥Ã¥¯¥¹¤¬É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡¥\ +ºÇ½é¤Î¤â¤Î¤Ï¡¤¥¨¥ó¥È¥ê¥¦¥£¥¸¥§¥Ã¥È¤ÈƱ¤¸Íͤˡ¤\ +¥Ý¥¤¥ó¥È¤·¤¿¤ê¡¤¥¯¥ê¥Ã¥¯¤·¤¿¤ê¡¤¥¿¥¤¥×¤·¤¿¤ê¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡¥\ +¤Þ¤¿¡¤Return¥­¡¼¤òÆþÎϤ¹¤ì¤Ð¸½ºß¤ÎÃͤ¬¥ê¥¹¥È¤ËÄɲ䵤졤\ +¥É¥í¥Ã¥×¥À¥¦¥ó¥ê¥¹¥È¤«¤éÁªÂò¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡¥\ +¢­(²¼¸þ¤­Ìð°õ)¥­¡¼¤ò²¡¤·¤Æɽ¼¨¤µ¤ì¤¿¥ê¥¹¥È¤«¤é\ +Ìð°õ¥­¡¼¤Ç¾¤Î¸õÊä¤òÁª¤ó¤ÇReturn¥­¡¼¤ò²¡¤»¤Ð¡¤ÃͤòÁªÂò¤Ç¤­¤Þ¤¹¡¥\ +2ÈÖÌܤΥ³¥ó¥Ü¥Ü¥Ã¥¯¥¹¤ÏÆÃÄê¤ÎÃͤ˸ÇÄꤵ¤ì¤Æ¤ª¤ê¡¤°ìÀÚÊѹ¹¤Ç¤­¤Þ¤»¤ó¡¥\ +3ÈÖÌܤΤâ¤Î¤Ï¥ª¡¼¥¹¥È¥é¥ê¥¢¤ÎÅԻԤΥɥí¥Ã¥×¥À¥¦¥ó¥ê¥¹¥È¤«¤é\ +ÁªÂò¤¹¤ë¤³¤È¤À¤±¤¬²Äǽ¤È¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡¥ +EOL + +## variables +firstValue = TkVariable.new +secondValue = TkVariable.new +ozCity = TkVariable.new + +## See Code / Dismiss buttons +Ttk::Frame.new(base_frame) {|frame| + sep = Ttk::Separator.new(frame) + Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) + TkGrid('x', + Ttk::Button.new(frame, :text=>'ÊÑ¿ô»²¾È', + :image=>$image['view'], :compound=>:left, + :command=>proc{ + showVars(base_frame, + ['firstVariable', firstValue], + ['secondVariable', secondValue], + ['ozCity', ozCity]) + }), + Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È', + :image=>$image['view'], :compound=>:left, + :command=>proc{showCode 'combo'}), + Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë', + :image=>$image['delete'], :compound=>:left, + :command=>proc{ + $combo_demo.destroy + $combo_demo = nil + }), + :padx=>4, :pady=>4) + grid_columnconfigure(0, :weight=>1) + pack(:side=>:bottom, :fill=>:x) +} + +frame = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true) + +australianCities = [ + '¥­¥ã¥ó¥Ù¥é', '¥·¥É¥Ë¡¼', '¥á¥ë¥Ü¥ë¥ó', '¥Ñ¡¼¥¹', '¥¢¥Ç¥ì¡¼¥É', + '¥Ö¥ê¥¹¥Ù¡¼¥ó', '¥Û¥Ð¡¼¥È', '¥À¡¼¥¦¥£¥ó', '¥¢¥ê¥¹ ¥¹¥×¥ê¥ó¥°¥¹' +] + + +secondValue.value = 'Êѹ¹ÉÔ²Ä' +ozCity.value = '¥·¥É¥Ë¡¼' + +Tk.pack(Ttk::Labelframe.new(frame, :text=>'Fully Editable'){|f| + Ttk::Combobox.new(f, :textvariable=>firstValue){|b| + b.bind('Return', '%W'){|w| + w.values <<= w.value unless w.values.include?(w.value) + } + }.pack(:pady=>5, :padx=>10) + }, + + Ttk::LabelFrame.new(frame, :text=>'Disabled'){|f| + Ttk::Combobox.new(f, :textvariable=>secondValue, :state=>:disabled) . + pack(:pady=>5, :padx=>10) + }, + + Ttk::LabelFrame.new(frame, :text=>'Defined List Only'){|f| + Ttk::Combobox.new(f, :textvariable=>ozCity, :state=>:readonly, + :values=>australianCities) . + pack(:pady=>5, :padx=>10) + }, + + :side=>:top, :pady=>5, :padx=>10) diff --git a/ext/tk/sample/demos-jp/cscroll.rb b/ext/tk/sample/demos-jp/cscroll.rb index 0be26133c5..845952679a 100644 --- a/ext/tk/sample/demos-jp/cscroll.rb +++ b/ext/tk/sample/demos-jp/cscroll.rb @@ -16,14 +16,16 @@ $cscroll_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($cscroll_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -TkLabel.new($cscroll_demo, 'font'=>$font, 'wraplength'=>'4i', +TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left', 'text'=>"¤³¤Î¥¦¥£¥ó¥É¥¦¤Ë¤Ï¥¹¥¯¥í¡¼¥ë¥Ð¡¼¤ä¥Þ¥¦¥¹¤Î¥Ü¥¿¥ó2 ¤Ç¥¹¥¯¥í¡¼¥ë¤Ç¤­¤ë¥­¥ã¥ó¥Ð¥¹ widget ¤¬É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡£»Í³Ñ¤Î¾å¤Ç¥Ü¥¿¥ó1 ¤ò¥¯¥ê¥Ã¥¯¤¹¤ë¤È¡¢¤½¤Î¥¤¥ó¥Ç¥Ã¥¯¥¹¤¬É¸½à½ÐÎϤ˽ÐÎϤµ¤ì¤Þ¤¹¡£"){ pack('side'=>'top') } # frame À¸À® -$cscroll_buttons = TkFrame.new($cscroll_demo) {|frame| +$cscroll_buttons = TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -43,7 +45,7 @@ $cscroll_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # frame ÀßÄê unless $tk_version =~ /^4\.[01]/ - $cscroll_grid = TkFrame.new($cscroll_demo) { + $cscroll_grid = TkFrame.new(base_frame) { pack('expand'=>'yes', 'fill'=>'both', 'padx'=>1, 'pady'=>1) } TkGrid.rowconfigure($cscroll_grid, 0, 'weight'=>1, 'minsize'=>0) @@ -51,7 +53,7 @@ unless $tk_version =~ /^4\.[01]/ end # canvas ÀßÄê -$cscroll_canvas = TkCanvas.new($cscroll_demo, +$cscroll_canvas = TkCanvas.new(base_frame, 'relief'=>'sunken', 'borderwidth'=>2, 'scrollregion'=>['-11c', '-11c', '50c', '20c'] ) {|c| @@ -62,7 +64,7 @@ $cscroll_canvas = TkCanvas.new($cscroll_demo, 'rowspan'=>1, 'columnspan'=>1, 'sticky'=>'news') end - TkScrollbar.new($cscroll_demo, 'command'=>proc{|*args| c.yview(*args)}) {|vs| + TkScrollbar.new(base_frame, 'command'=>proc{|*args| c.yview(*args)}) {|vs| c.yscrollcommand(proc{|first,last| vs.set first,last}) if $tk_version =~ /^4\.[01]/ pack('side'=>'right', 'fill'=>'y') @@ -72,7 +74,7 @@ $cscroll_canvas = TkCanvas.new($cscroll_demo, end } - TkScrollbar.new($cscroll_demo, 'orient'=>'horiz', + TkScrollbar.new(base_frame, 'orient'=>'horiz', 'command'=>proc{|*args| c.xview(*args)}) {|hs| c.xscrollcommand(proc{|first,last| hs.set first,last}) if $tk_version =~ /^4\.[01]/ diff --git a/ext/tk/sample/demos-jp/ctext.rb b/ext/tk/sample/demos-jp/ctext.rb index f5daf7ca05..05ca732cfd 100644 --- a/ext/tk/sample/demos-jp/ctext.rb +++ b/ext/tk/sample/demos-jp/ctext.rb @@ -16,8 +16,10 @@ $ctext_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($ctext_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -TkLabel.new($ctext_demo, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left', +TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left', 'text'=>"¤³¤Î¥¦¥£¥ó¥É¥¦¤Ë¤Ï¥­¥ã¥ó¥Ð¥¹widget¤Î¥Æ¥­¥¹¥Èµ¡Ç½¤ò¥Ç¥â¤¹¤ë¤¿¤á¤Î¥Æ¥­¥¹¥Èʸ»úÎó¤¬É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡£¥Þ¥¦¥¹¤ò»Í³Ñ¤ÎÃæ¤Ë»ý¤Ã¤Æ¤¤¤­¡¢¥¯¥ê¥Ã¥¯¤¹¤ë¤È°ÌÃÖ¤®¤áÍѤÎÅÀ¤«¤é¤ÎÁêÂаÌÃÖ¤òÊѤ¨¤¿¤ê¡¢¹Ô·¤¨¤òÊѤ¨¤¿¤ê¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¤Þ¤¿°Ê²¼¤Î¤è¤¦¤ÊÊÔ½¸¤Î¤¿¤á¤Î´Êñ¤Ê¥Ð¥¤¥ó¥Ç¥£¥ó¥°¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤Þ¤¹¡£ 1. ¥Þ¥¦¥¹¤ò»ý¤Ã¤Æ¤¤¤­¡¢¥¯¥ê¥Ã¥¯¤·¡¢ÆþÎϤǤ­¤Þ¤¹¡£ @@ -29,7 +31,7 @@ TkLabel.new($ctext_demo, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left', } # frame À¸À® -$ctext_buttons = TkFrame.new($ctext_demo) {|frame| +$ctext_buttons = TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -48,7 +50,7 @@ $ctext_buttons = TkFrame.new($ctext_demo) {|frame| $ctext_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # canvas À¸À® -$ctext_canvas = TkCanvas.new($ctext_demo, 'relief'=>'flat', +$ctext_canvas = TkCanvas.new(base_frame, 'relief'=>'flat', 'borderwidth'=>0, 'width'=>500, 'height'=>350) $ctext_canvas.pack('side'=>'top', 'expand'=>'yes', 'fill'=>'both') diff --git a/ext/tk/sample/demos-jp/entry1.rb b/ext/tk/sample/demos-jp/entry1.rb index d794282284..2be29c18d3 100644 --- a/ext/tk/sample/demos-jp/entry1.rb +++ b/ext/tk/sample/demos-jp/entry1.rb @@ -16,8 +16,10 @@ $entry1_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($entry1_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -msg = TkLabel.new($entry1_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '5i' justify 'left' @@ -26,7 +28,7 @@ msg = TkLabel.new($entry1_demo) { msg.pack('side'=>'top') # frame À¸À® -TkFrame.new($entry1_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -44,9 +46,9 @@ TkFrame.new($entry1_demo) {|frame| }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # entry À¸À® -e1 = TkEntry.new($entry1_demo, 'relief'=>'sunken') -e2 = TkEntry.new($entry1_demo, 'relief'=>'sunken') -e3 = TkEntry.new($entry1_demo, 'relief'=>'sunken') +e1 = TkEntry.new(base_frame, 'relief'=>'sunken') +e2 = TkEntry.new(base_frame, 'relief'=>'sunken') +e3 = TkEntry.new(base_frame, 'relief'=>'sunken') [e1,e2,e3].each{|w| w.pack('side'=>'top', 'padx'=>10, 'pady'=>5, 'fill'=>'x')} # ½é´üÃÍÁÞÆþ diff --git a/ext/tk/sample/demos-jp/entry2.rb b/ext/tk/sample/demos-jp/entry2.rb index 528ad6dec4..2675b5d324 100644 --- a/ext/tk/sample/demos-jp/entry2.rb +++ b/ext/tk/sample/demos-jp/entry2.rb @@ -16,8 +16,10 @@ $entry2_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($entry2_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -msg = TkLabel.new($entry2_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '5i' justify 'left' @@ -26,7 +28,7 @@ msg = TkLabel.new($entry2_demo) { msg.pack('side'=>'top') # frame À¸À® -TkFrame.new($entry2_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -44,7 +46,7 @@ TkFrame.new($entry2_demo) {|frame| }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # frame À¸À® -TkFrame.new($entry2_demo, 'borderwidth'=>10) {|w| +TkFrame.new(base_frame, 'borderwidth'=>10) {|w| # entry 1 s1 = TkScrollbar.new(w, 'relief'=>'sunken', 'orient'=>'horiz') e1 = TkEntry.new(w, 'relief'=>'sunken') { diff --git a/ext/tk/sample/demos-jp/entry3.rb b/ext/tk/sample/demos-jp/entry3.rb index 46426af6ae..6b9cd4cf37 100644 --- a/ext/tk/sample/demos-jp/entry3.rb +++ b/ext/tk/sample/demos-jp/entry3.rb @@ -18,7 +18,9 @@ $entry3_demo = TkToplevel.new {|w| positionWindow(w) } -TkLabel.new($entry3_demo, +base_frame = TkFrame.new($entry3_demo).pack(:fill=>:both, :expand=>true) + +TkLabel.new(base_frame, :font=>$font, :wraplength=>'5i', :justify=>:left, :text=><:top) °Ê²¼¤Ë¤Ï£´¼ïÎà¤Î¥¨¥ó¥È¥ê¥Ü¥Ã¥¯¥¹¤¬É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡¥³Æ¥¨¥ó¥È¥ê¥Ü¥Ã¥¯¥¹¤Ï¡¤\ @@ -39,7 +41,7 @@ TkLabel.new($entry3_demo, ÆþÎϤµ¤ì¤¿Ê¸»ú¤Ï¥¢¥¹¥¿¥ê¥¹¥¯µ­¹æ¤ËÃÖ¤­´¹¤¨¤Æɽ¼¨¤µ¤ì¤Þ¤¹¡¥ EOL -TkFrame.new($entry3_demo){|f| +TkFrame.new(base_frame){|f| pack(:side=>:bottom, :fill=>:x, :pady=>'2m') TkButton.new(f, :text=>'ÊĤ¸¤ë', :width=>15, :command=>proc{ @@ -65,23 +67,41 @@ TkFrame.new($entry3_demo){|f| # count - Counter to control the number of times flashed def focusAndFlash(widget, fg, bg, count=5) return if count <= 0 - TkTimer.new(100, count, - proc{widget.configure(:foreground=>bg, :background=>fg)}, - proc{widget.configure(:foreground=>fg, :background=>bg)} - ).start + if fg && !fg.empty? && bg && !bg.empty? + TkTimer.new(200, count, + proc{widget.configure(:foreground=>bg, :background=>fg)}, + proc{widget.configure(:foreground=>fg, :background=>bg)} + ).start + else + # TkTimer.new(150, 3){Tk.bell}.start + Tk.bell + TkTimer.new(200, count, + proc{widget.configure(:foreground=>'white', + :background=>'black')}, + proc{widget.configure(:foreground=>'black', + :background=>'white')} + ).at_end{begin + widget.configure(:foreground=>fg, + :background=>bg) + rescue + # ignore + end}.start + end widget.focus(true) end -l1 = TkLabelFrame.new($entry3_demo, :text=>"À°¿ô¥¨¥ó¥È¥ê") +l1 = TkLabelFrame.new(base_frame, :text=>"À°¿ô¥¨¥ó¥È¥ê") TkEntry.new(l1, :validate=>:focus, :vcmd=>[ proc{|s| s == '' || /^[+-]?\d+$/ =~ s }, '%P' ]) {|e| - invalidcommand [proc{|w| focusAndFlash(w, e.fg, e.bg)}, '%W'] + fg = e.foreground + bg = e.background + invalidcommand [proc{|w| focusAndFlash(w, fg, bg)}, '%W'] pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m') } -l2 = TkLabelFrame.new($entry3_demo, :text=>"ŤµÀ©ÌóÉÕ¤­¥¨¥ó¥È¥ê") +l2 = TkLabelFrame.new(base_frame, :text=>"ŤµÀ©ÌóÉÕ¤­¥¨¥ó¥È¥ê") TkEntry.new(l2, :validate=>:key, :invcmd=>proc{Tk.bell}, :vcmd=>[proc{|s| s.length < 10}, '%P'] ).pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m') @@ -162,15 +182,15 @@ def validatePhoneChange(widget, vmode, idx, char) widget.delete(idx) widget.insert(idx, $phoneNumberMap[char] || char) Tk.after_idle(proc{phoneSkipRight(widget, -1)}) - # Tk.update(true) # Don't work 'update' inter validation callback. - # It depends on Tcl/Tk side (tested on Tcl/Tk8.5a1). + # Tk.update(true) # <- Don't work 'update' inter validation callback. + # It depends on Tcl/Tk side (tested on Tcl/Tk8.5a1). return true end return false end -l3 = TkLabelFrame.new($entry3_demo, :text=>"ÊƹñÅÅÏÃÈֹ楨¥ó¥È¥ê") +l3 = TkLabelFrame.new(base_frame, :text=>"ÊƹñÅÅÏÃÈֹ楨¥ó¥È¥ê") TkEntry.new(l3, :validate=>:key, :invcmd=>proc{Tk.bell}, :textvariable=>entry3content, :vcmd=>[ @@ -189,14 +209,14 @@ TkEntry.new(l3, :validate=>:key, :invcmd=>proc{Tk.bell}, pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m') } -l4 = TkLabelFrame.new($entry3_demo, :text=>"¥Ñ¥¹¥ï¡¼¥É¥¨¥ó¥È¥ê") +l4 = TkLabelFrame.new(base_frame, :text=>"¥Ñ¥¹¥ï¡¼¥É¥¨¥ó¥È¥ê") TkEntry.new(l4, :validate=>:key, :show=>'*', :vcmd=>[ proc{|s| s.length <= 8}, '%P' ]).pack(:fill=>:x, :expand=>true, :padx=>'1m', :pady=>'1m') -TkFrame.new($entry3_demo){|f| +TkFrame.new(base_frame){|f| lower TkGrid.configure(l1, l2, :in=>f, :padx=>'3m', :pady=>'1m', :sticky=>:ew) TkGrid.configure(l3, l4, :in=>f, :padx=>'3m', :pady=>'1m', :sticky=>:ew) diff --git a/ext/tk/sample/demos-jp/filebox.rb b/ext/tk/sample/demos-jp/filebox.rb index 04b4810b3b..b8846d08a0 100644 --- a/ext/tk/sample/demos-jp/filebox.rb +++ b/ext/tk/sample/demos-jp/filebox.rb @@ -16,12 +16,14 @@ $filebox_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($filebox_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -TkLabel.new($filebox_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left', +TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left', 'text'=>"¥¨¥ó¥È¥ê¤Ë¥Õ¥¡¥¤¥ë̾¤òľÀÜÆþÎϤ¹¤ë¤«¡¢\"Browse\" ¥Ü¥¿¥ó¤ò²¡¤·¤Æ¥Õ¥¡¥¤¥ëÁªÂò¥À¥¤¥¢¥í¥°¤«¤é¥Õ¥¡¥¤¥ë̾¤òÁª¤ó¤Ç²¼¤µ¤¤¡£").pack('side'=>'top') # frame À¸À® -TkFrame.new($filebox_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -40,7 +42,7 @@ TkFrame.new($filebox_demo) {|frame| # frame À¸À® ['³«¤¯', 'Êݸ'].each{|type| - TkFrame.new($filebox_demo) {|f| + TkFrame.new(base_frame) {|f| TkLabel.new(f, 'text'=>"¥Õ¥¡¥¤¥ë¤ò#{type}: ", 'anchor'=>'e')\ .pack('side'=>'left') @@ -48,7 +50,7 @@ TkFrame.new($filebox_demo) {|frame| pack('side'=>'left', 'expand'=>'yes', 'fill'=>'x') TkButton.new(f, 'text'=>'Browse ...', - 'command'=>proc{fileDialog $filebox_demo,e,type})\ + 'command'=>proc{fileDialog base_frame,e,type})\ .pack('side'=>'left') } @@ -58,7 +60,7 @@ TkFrame.new($filebox_demo) {|frame| $tk_strictMotif = TkVarAccess.new('tk_strictMotif') if ($tk_platform['platform'] == 'unix') - TkCheckButton.new($filebox_demo, + TkCheckButton.new(base_frame, 'text'=>'Motif¥¹¥¿¥¤¥ë¤Î¥À¥¤¥¢¥í¥°¤òÍѤ¤¤ë', 'variable'=>$tk_strictMotif, 'onvalue'=>1, 'offvalue'=>0 ).pack('anchor'=>'c') @@ -91,7 +93,10 @@ def fileDialog(w,ent,operation) if file != "" ent.delete 0, 'end' ent.insert 0, file - ent.xview 'end' + # ent.xview 'end' + Tk.update_idletasks # need this for Tk::Tile::Entry + # (to find right position of 'xview'). + ent.xview(ent.index('end')) end end diff --git a/ext/tk/sample/demos-jp/floor.rb b/ext/tk/sample/demos-jp/floor.rb index b7d07bdafa..a2ec2e9969 100644 --- a/ext/tk/sample/demos-jp/floor.rb +++ b/ext/tk/sample/demos-jp/floor.rb @@ -1587,14 +1587,16 @@ $floor_demo = TkToplevel.new {|w| minsize(100,100) } +base_frame = TkFrame.new($floor_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -TkLabel.new($floor_demo, 'font'=>$font, 'wraplength'=>'8i', 'justify'=>'left', +TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'8i', 'justify'=>'left', 'text'=>"¤³¤Î¥¦¥£¥ó¥É¥¦¤Ë¤Ï¥Ç¥£¥¸¥¿¥ë¥¨¥¯¥¤¥Ã¥×¥á¥ó¥È¼Ò¤Î¥¦¥§¥¹¥¿¥ó¥ê¥µ¡¼¥Á¥é¥Ü¥é¥È¥ê (DECWRL) ¤Î´Ö¼è¤ê¤¬½ñ¤«¤ì¤¿¥­¥ã¥ó¥Ð¥¹ widget ¤¬Æþ¤Ã¤Æ¤¤¤Þ¤¹¡£¤³¤ì¤Ï 3³¬·ú¤Æ¤Ç¡¢¾ï¤Ë¤½¤Î¤¦¤Á¤Î1³¬Ê¬¤¬ÁªÂò¡¢¤Ä¤Þ¤ê¤½¤Î´Ö¼è¤ê¤¬É½¼¨¤µ¤ì¤ë¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£¤¢¤ë³¬¤òÁªÂò¤¹¤ë¤Ë¤Ï¡¢¤½¤Î¾å¤Ç¥Þ¥¦¥¹¤Îº¸¥Ü¥¿¥ó¤ò¥¯¥ê¥Ã¥¯¤·¤Æ¤¯¤À¤µ¤¤¡£¥Þ¥¦¥¹¤¬ÁªÂò¤µ¤ì¤Æ¤¤¤ë³¬¤Î¾å¤òÆ°¤¯¤È¡¢¤½¤Î²¼¤Ë¤¢¤ëÉô²°¤Î¿§¤¬ÊѤï¤ê¡¢Éô²°Èֹ椬¡ÖÉô²°ÈÖ¹æ:¡×¥¨¥ó¥È¥ê¤Ëɽ¼¨¤µ¤ì¤Þ¤¹¡£¤Þ¤¿¡¢¥¨¥ó¥È¥ê¤ËÉô²°ÈÖ¹æ¤ò½ñ¤¯¤È¤½¤ÎÉô²°¤Î¿§¤¬ÊѤï¤ê¤Þ¤¹¡£"){ pack('side'=>'top') } # frame À¸À® -$floor_buttons = TkFrame.new($floor_demo) {|frame| +$floor_buttons = TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -1618,17 +1620,17 @@ $floorItems = {} # canvas ÀßÄê if $tk_version =~ /^4\.[01]/ - $floor_canvas_frame = TkFrame.new($floor_demo,'bd'=>2,'relief'=>'sunken', + $floor_canvas_frame = TkFrame.new(base_frame,'bd'=>2,'relief'=>'sunken', 'highlightthickness'=>2) $floor_canvas = TkCanvas.new($floor_canvas_frame, 'width'=>900, 'height'=>500, 'borderwidth'=>0, 'highlightthickness'=>0) {|c| - TkScrollbar.new($floor_demo, 'orient'=>'horiz', + TkScrollbar.new(base_frame, 'orient'=>'horiz', 'command'=>proc{|*args| c.xview(*args)}){|hs| c.xscrollcommand(proc{|first,last| hs.set first,last}) pack('side'=>'bottom', 'fill'=>'x') } - TkScrollbar.new($floor_demo, 'command'=>proc{|*args| c.yview(*args)}){|vs| + TkScrollbar.new(base_frame, 'command'=>proc{|*args| c.yview(*args)}){|vs| c.yscrollcommand(proc{|first,last| vs.set first,last}) pack('side'=>'right', 'fill'=>'y') } @@ -1637,7 +1639,7 @@ if $tk_version =~ /^4\.[01]/ $floor_canvas.pack('expand'=>'yes', 'fill'=>'both') else - TkFrame.new($floor_demo) {|f| + TkFrame.new(base_frame) {|f| pack('side'=>'top', 'fill'=>'both', 'expand'=>'yes') h = TkScrollbar.new(f, 'highlightthickness'=>0, 'orient'=>'horizontal') diff --git a/ext/tk/sample/demos-jp/floor2.rb b/ext/tk/sample/demos-jp/floor2.rb index b7571a592f..d4381c5543 100644 --- a/ext/tk/sample/demos-jp/floor2.rb +++ b/ext/tk/sample/demos-jp/floor2.rb @@ -1587,14 +1587,16 @@ $floor2_demo = TkToplevel.new {|w| minsize(100,100) } +base_frame = TkFrame.new($floor2_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -TkLabel.new($floor2_demo, 'font'=>$font, 'wraplength'=>'8i', 'justify'=>'left', +TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'8i', 'justify'=>'left', 'text'=>"¤³¤Î¥¦¥£¥ó¥É¥¦¤Ë¤Ï¥Ç¥£¥¸¥¿¥ë¥¨¥¯¥¤¥Ã¥×¥á¥ó¥È¼Ò¤Î¥¦¥§¥¹¥¿¥ó¥ê¥µ¡¼¥Á¥é¥Ü¥é¥È¥ê (DECWRL) ¤Î´Ö¼è¤ê¤¬½ñ¤«¤ì¤¿¥­¥ã¥ó¥Ð¥¹ widget ¤¬Æþ¤Ã¤Æ¤¤¤Þ¤¹¡£¤³¤ì¤Ï 3³¬·ú¤Æ¤Ç¡¢¾ï¤Ë¤½¤Î¤¦¤Á¤Î1³¬Ê¬¤¬ÁªÂò¡¢¤Ä¤Þ¤ê¤½¤Î´Ö¼è¤ê¤¬É½¼¨¤µ¤ì¤ë¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£¤¢¤ë³¬¤òÁªÂò¤¹¤ë¤Ë¤Ï¡¢¤½¤Î¾å¤Ç¥Þ¥¦¥¹¤Îº¸¥Ü¥¿¥ó¤ò¥¯¥ê¥Ã¥¯¤·¤Æ¤¯¤À¤µ¤¤¡£¥Þ¥¦¥¹¤¬ÁªÂò¤µ¤ì¤Æ¤¤¤ë³¬¤Î¾å¤òÆ°¤¯¤È¡¢¤½¤Î²¼¤Ë¤¢¤ëÉô²°¤Î¿§¤¬ÊѤï¤ê¡¢Éô²°Èֹ椬¡ÖÉô²°ÈÖ¹æ:¡×¥¨¥ó¥È¥ê¤Ëɽ¼¨¤µ¤ì¤Þ¤¹¡£¤Þ¤¿¡¢¥¨¥ó¥È¥ê¤ËÉô²°ÈÖ¹æ¤ò½ñ¤¯¤È¤½¤ÎÉô²°¤Î¿§¤¬ÊѤï¤ê¤Þ¤¹¡£"){ pack('side'=>'top') } # frame À¸À® -$floor2_buttons = TkFrame.new($floor2_demo) {|frame| +$floor2_buttons = TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -1618,17 +1620,17 @@ $floorItems2 = {} # canvas ÀßÄê if $tk_version =~ /^4\.[01]/ - $floor2_canvas_frame = TkFrame.new($floor2_demo,'bd'=>2,'relief'=>'sunken', + $floor2_canvas_frame = TkFrame.new(base_frame,'bd'=>2,'relief'=>'sunken', 'highlightthickness'=>2) $floor2_canvas = TkCanvas.new($floor2_canvas_frame, 'width'=>900, 'height'=>500, 'borderwidth'=>0, 'highlightthickness'=>0) {|c| - TkScrollbar.new($floor2_demo, 'orient'=>'horiz', + TkScrollbar.new(base_frame, 'orient'=>'horiz', 'command'=>proc{|*args| c.xview(*args)}){|hs| c.xscrollcommand(proc{|first,last| hs.set first,last}) pack('side'=>'bottom', 'fill'=>'x') } - TkScrollbar.new($floor2_demo, 'command'=>proc{|*args| c.yview(*args)}){|vs| + TkScrollbar.new(base_frame, 'command'=>proc{|*args| c.yview(*args)}){|vs| c.yscrollcommand(proc{|first,last| vs.set first,last}) pack('side'=>'right', 'fill'=>'y') } @@ -1637,7 +1639,7 @@ if $tk_version =~ /^4\.[01]/ $floor2_canvas.pack('expand'=>'yes', 'fill'=>'both') else - TkFrame.new($floor2_demo) {|f| + TkFrame.new(base_frame) {|f| pack('side'=>'top', 'fill'=>'both', 'expand'=>'yes') h = TkScrollbar.new(f, 'highlightthickness'=>0, 'orient'=>'horizontal') diff --git a/ext/tk/sample/demos-jp/form.rb b/ext/tk/sample/demos-jp/form.rb index 637dd9a8ea..4de7056764 100644 --- a/ext/tk/sample/demos-jp/form.rb +++ b/ext/tk/sample/demos-jp/form.rb @@ -16,8 +16,10 @@ $form_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($form_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -msg = TkLabel.new($form_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -26,7 +28,7 @@ msg = TkLabel.new($form_demo) { msg.pack('side'=>'top', 'fill'=>'x') # frame À¸À® -TkFrame.new($form_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -46,7 +48,7 @@ TkFrame.new($form_demo) {|frame| # entry À¸À® form_data = [] (1..5).each{|i| - f = TkFrame.new($form_demo, 'bd'=>2) + f = TkFrame.new(base_frame, 'bd'=>2) e = TkEntry.new(f, 'relief'=>'sunken', 'width'=>40) l = TkLabel.new(f) e.pack('side'=>'right') diff --git a/ext/tk/sample/demos-jp/goldberg.rb b/ext/tk/sample/demos-jp/goldberg.rb index 8bf0104c16..a81c7ec70c 100644 --- a/ext/tk/sample/demos-jp/goldberg.rb +++ b/ext/tk/sample/demos-jp/goldberg.rb @@ -55,6 +55,8 @@ $goldberg_demo = TkToplevel.new {|w| # positionWindow(w) } +base_frame = TkFrame.new($goldberg_demo).pack(:fill=>:both, :expand=>true) + =begin # label msg = TkLabel.new($goldberg_demo) { @@ -177,7 +179,8 @@ class TkGoldberg_Demo do_ctrl_frame do_detail_frame - msg = TkLabel.new(@parent, :bg=>@C['bg'], :fg=>'white') { + # msg = TkLabel.new(@parent, :bg=>@C['bg'], :fg=>'white') { + msg = Tk::Label.new(@parent, :bg=>@C['bg'], :fg=>'white') { font 'Arial 10' wraplength 600 justify 'left' @@ -187,7 +190,8 @@ class TkGoldberg_Demo frame = TkFrame.new(@parent, :bg=>@C['bg']) - TkButton.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) { + # TkButton.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) { + Tk::Button.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) { text 'ÊĤ¸¤ë' command proc{ tmppath = $goldberg_demo @@ -196,12 +200,14 @@ class TkGoldberg_Demo } }.pack('side'=>'left') - TkButton.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) { + # TkButton.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) { + Tk::Button.new(frame, :bg=>@C['bg'], :activebackground=>@C['bg']) { text '¥³¡¼¥É»²¾È' command proc{showCode 'goldberg'} }.pack('side'=>'left', 'padx'=>5) - @show = TkButton.new(frame, :text=>'>>', :command=>proc{show_ctrl}, + # @show = TkButton.new(frame, :text=>'>>', :command=>proc{show_ctrl}, + @show = Tk::Button.new(frame, :text=>'>>', :command=>proc{show_ctrl}, :bg=>@C['bg'], :activebackground=>@C['bg']) @show.pack('side'=>'left') frame.place(:in=>@canvas, :relx=>1, :rely=>0, :anchor=>:ne) @@ -210,10 +216,11 @@ class TkGoldberg_Demo end def do_ctrl_frame - @start = TkButton.new(@parent, :text=>'Start', :bd=>6, + @start = Tk::Button.new(@parent, :text=>'Start', :bd=>6, :command=>proc{do_button(0)}) - @start.font(@start['font'].weight('bold')) - font = @start['font'] + if font = @start['font'] + @start.font(font.weight('bold')) + end @pause = TkCheckbutton.new(@parent, :text=>'Pause', :font=>font, :command=>proc{do_button(1)}, :relief=>:raised, @@ -2001,4 +2008,4 @@ class TkGoldberg_Demo end end -TkGoldberg_Demo.new($goldberg_demo) +TkGoldberg_Demo.new(base_frame) diff --git a/ext/tk/sample/demos-jp/hscale.rb b/ext/tk/sample/demos-jp/hscale.rb index b636f0579f..5615aa50bd 100644 --- a/ext/tk/sample/demos-jp/hscale.rb +++ b/ext/tk/sample/demos-jp/hscale.rb @@ -12,8 +12,9 @@ $hscale_demo = TkToplevel.new {|w| } positionWindow($hscale_demo) +base_frame = TkFrame.new($hscale_demo).pack(:fill=>:both, :expand=>true) -msg = TkLabel.new($hscale_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '3.5i' justify 'left' @@ -23,7 +24,7 @@ msg = TkLabel.new($hscale_demo) { } msg.pack('side'=>'top') -TkFrame.new($hscale_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -40,7 +41,17 @@ TkFrame.new($hscale_demo) {|frame| }.pack('side'=>'left', 'expand'=>'yes') }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') -TkFrame.new($hscale_demo) {|frame| +def setWidth(w, width) + width = width + 21 + x2 = width - 30 + if x2 < 21 + x2 = 21 + end + w.coords 'poly',20,15,20,35,x2,35,x2,45,width,25,x2,5,x2,15,20,15 + w.coords 'line',20,15,20,35,x2,35,x2,45,width,25,x2,5,x2,15,20,15 +end + +TkFrame.new(base_frame) {|frame| canvas = TkCanvas.new(frame) {|c| width 50 height 50 @@ -65,13 +76,3 @@ TkFrame.new($hscale_demo) {|frame| }.pack('side'=>'bottom', 'expand'=>'yes', 'anchor'=>'n') scale.set 75 }.pack('side'=>'top', 'fill'=>'x') - -def setWidth(w, width) - width = width + 21 - x2 = width - 30 - if x2 < 21 - x2 = 21 - end - w.coords 'poly',20,15,20,35,x2,35,x2,45,width,25,x2,5,x2,15,20,15 - w.coords 'line',20,15,20,35,x2,35,x2,45,width,25,x2,5,x2,15,20,15 -end diff --git a/ext/tk/sample/demos-jp/icon.rb b/ext/tk/sample/demos-jp/icon.rb index 26382a57a7..a2ca6651dc 100644 --- a/ext/tk/sample/demos-jp/icon.rb +++ b/ext/tk/sample/demos-jp/icon.rb @@ -16,8 +16,10 @@ $icon_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($icon_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -msg = TkLabel.new($icon_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '5i' justify 'left' @@ -26,7 +28,7 @@ msg = TkLabel.new($icon_demo) { msg.pack('side'=>'top') # frame À¸À® -TkFrame.new($icon_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -61,16 +63,18 @@ TkBitmapImage.new('file'=>[$demo_dir,'..', letters = TkVariable.new # frame À¸À® -TkFrame.new($icon_demo, 'borderwidth'=>10){|w| +TkFrame.new(base_frame, 'borderwidth'=>10){|w| TkFrame.new(w) {|f| - TkRadioButton.new(f){ + # TkRadioButton.new(f){ + Tk::RadioButton.new(f){ bitmap '@' + [$demo_dir,'..', 'images','letters.xbm'].join(File::Separator) variable letters value 'full' }.pack('side'=>'top', 'expand'=>'yes') - TkRadioButton.new(f){ + # TkRadioButton.new(f){ + Tk::RadioButton.new(f){ bitmap '@' + [$demo_dir,'..', 'images','noletter.xbm'].join(File::Separator) variable letters @@ -79,14 +83,16 @@ TkFrame.new($icon_demo, 'borderwidth'=>10){|w| }.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'5m') - TkCheckButton.new(w) { + # TkCheckButton.new(w) { + Tk::CheckButton.new(w) { image flagdown selectimage flagup indicatoron 0 selectcolor self['background'] }.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'5m') - TkCheckButton.new(w) { + # TkCheckButton.new(w) { + Tk::CheckButton.new(w) { bitmap '@' + [$demo_dir,'..', 'images','letters.xbm'].join(File::Separator) indicatoron 0 diff --git a/ext/tk/sample/demos-jp/image1.rb b/ext/tk/sample/demos-jp/image1.rb index 3b56d240dc..d9435cc1a2 100644 --- a/ext/tk/sample/demos-jp/image1.rb +++ b/ext/tk/sample/demos-jp/image1.rb @@ -16,8 +16,10 @@ $image1_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($image1_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -msg = TkLabel.new($image1_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -26,7 +28,7 @@ msg = TkLabel.new($image1_demo) { msg.pack('side'=>'top') # frame À¸À® -TkFrame.new($image1_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -53,7 +55,10 @@ TkPhotoImage.new('file'=>[$demo_dir,'..', 'images','earthris.gif'].join(File::Separator)) # label À¸À® -[ TkLabel.new($image1_demo, 'image'=>image1a, 'bd'=>1, 'relief'=>'sunken'), - TkLabel.new($image1_demo, 'image'=>image1b, 'bd'=>1, 'relief'=>'sunken') +#[ TkLabel.new(base_frame, 'image'=>image1a, 'bd'=>1, 'relief'=>'sunken'), +# TkLabel.new(base_frame, 'image'=>image1b, 'bd'=>1, 'relief'=>'sunken') +#].each{|w| w.pack('side'=>'top', 'padx'=>'.5m', 'pady'=>'.5m')} +[ Tk::Label.new(base_frame, 'image'=>image1a, 'bd'=>1, 'relief'=>'sunken'), + Tk::Label.new(base_frame, 'image'=>image1b, 'bd'=>1, 'relief'=>'sunken') ].each{|w| w.pack('side'=>'top', 'padx'=>'.5m', 'pady'=>'.5m')} diff --git a/ext/tk/sample/demos-jp/image2.rb b/ext/tk/sample/demos-jp/image2.rb index de627448c1..1bb2c9e9c3 100644 --- a/ext/tk/sample/demos-jp/image2.rb +++ b/ext/tk/sample/demos-jp/image2.rb @@ -16,8 +16,10 @@ $image2_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($image2_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -msg = TkLabel.new($image2_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -26,7 +28,7 @@ msg = TkLabel.new($image2_demo) { msg.pack('side'=>'top') # frame À¸À® -TkFrame.new($image2_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -51,21 +53,21 @@ $dirName = TkVariable.new([$demo_dir,'..','images'].join(File::Separator)) $image2a = TkPhotoImage.new # ¥Õ¥¡¥¤¥ë̾ÆþÎÏÉô -TkLabel.new($image2_demo, 'text'=>'¥Ç¥£¥ì¥¯¥È¥ê:')\ +TkLabel.new(base_frame, 'text'=>'¥Ç¥£¥ì¥¯¥È¥ê:')\ .pack('side'=>'top', 'anchor'=>'w') -image2_e = TkEntry.new($image2_demo) { +image2_e = TkEntry.new(base_frame) { width 30 textvariable $dirName }.pack('side'=>'top', 'anchor'=>'w') -TkFrame.new($image2_demo, 'height'=>'3m', 'width'=>20)\ +TkFrame.new(base_frame, 'height'=>'3m', 'width'=>20)\ .pack('side'=>'top', 'anchor'=>'w') -TkLabel.new($image2_demo, 'text'=>'¥Õ¥¡¥¤¥ë:')\ +TkLabel.new(base_frame, 'text'=>'¥Õ¥¡¥¤¥ë:')\ .pack('side'=>'top', 'anchor'=>'w') -TkFrame.new($image2_demo){|w| +TkFrame.new(base_frame){|w| s = TkScrollbar.new(w) l = TkListbox.new(w) { width 20 @@ -84,9 +86,10 @@ TkFrame.new($image2_demo){|w| }.pack('side'=>'top', 'anchor'=>'w') # image ÇÛÃÖ -[ TkFrame.new($image2_demo, 'height'=>'3m', 'width'=>20), - TkLabel.new($image2_demo, 'text'=>'²èÁü:'), - TkLabel.new($image2_demo, 'image'=>$image2a) +[ TkFrame.new(base_frame, 'height'=>'3m', 'width'=>20), + TkLabel.new(base_frame, 'text'=>'²èÁü:'), + # TkLabel.new(base_frame, 'image'=>$image2a) + Tk::Label.new(base_frame, 'image'=>$image2a) ].each{|w| w.pack('side'=>'top', 'anchor'=>'w')} # ¥á¥½¥Ã¥ÉÄêµÁ diff --git a/ext/tk/sample/demos-jp/image3.rb b/ext/tk/sample/demos-jp/image3.rb index 36c1823745..12b8aafd8e 100644 --- a/ext/tk/sample/demos-jp/image3.rb +++ b/ext/tk/sample/demos-jp/image3.rb @@ -20,6 +20,8 @@ $image3_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($image3_demo).pack(:fill=>:both, :expand=>true) + # def loadDir3(w) w.delete(0,'end') @@ -50,7 +52,7 @@ end # label -msg = TkLabel.new($image3_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -59,7 +61,7 @@ msg = TkLabel.new($image3_demo) { msg.pack('side'=>'top') # frame -TkFrame.new($image3_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -88,11 +90,11 @@ end $image3a = TkPhotoImage.new # -image3_f = TkFrame.new($image3_demo).pack(:fill=>:both, :expand=>true) +image3_f = TkFrame.new(base_frame).pack(:fill=>:both, :expand=>true) -image3_df = TkLabelFrame.new($image3_demo, :text=>'¥Ç¥£¥ì¥¯¥È¥ê:') +image3_df = TkLabelFrame.new(base_frame, :text=>'¥Ç¥£¥ì¥¯¥È¥ê:') -image3_ff = TkLabelFrame.new($image3_demo, :text=>'¥Õ¥¡¥¤¥ë:', +image3_ff = TkLabelFrame.new(base_frame, :text=>'¥Õ¥¡¥¤¥ë:', :padx=>'2m', :pady=>'2m') image3_lbx = TkListbox.new(image3_ff, :width=>20, :height=>10) { pack(:side=>:left, :fill=>:y, :expand=>true) @@ -112,8 +114,9 @@ TkButton.new(image3_df, :pady=>0, :padx=>'2m', :text=>" pack(:side=>:left, :fill=>:y, :padx=>[0, '2m'], :pady=>'2m') } -image3_if = TkLabelFrame.new($image3_demo, :text=>'¥¤¥á¡¼¥¸:') {|f| - TkLabel.new(f, :image=>$image3a).pack(:padx=>'2m', :pady=>'2m') +image3_if = TkLabelFrame.new(base_frame, :text=>'¥¤¥á¡¼¥¸:') {|f| + # TkLabel.new(f, :image=>$image3a).pack(:padx=>'2m', :pady=>'2m') + Tk::Label.new(f, :image=>$image3a).pack(:padx=>'2m', :pady=>'2m') } Tk.grid(image3_df, '-', diff --git a/ext/tk/sample/demos-jp/items.rb b/ext/tk/sample/demos-jp/items.rb index c173d3b57f..64ceeff3ec 100644 --- a/ext/tk/sample/demos-jp/items.rb +++ b/ext/tk/sample/demos-jp/items.rb @@ -16,8 +16,10 @@ $items_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($items_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -TkLabel.new($items_demo) { +TkLabel.new(base_frame) { font $font wraplength '5i' justify 'left' @@ -25,7 +27,7 @@ TkLabel.new($items_demo) { }.pack('side'=>'top') # frame À¸À® -TkFrame.new($items_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -44,7 +46,7 @@ TkFrame.new($items_demo) {|frame| # frame À¸À® cvs = nil -TkFrame.new($items_demo) {|cf| +TkFrame.new(base_frame) {|cf| # canvas À¸À® cvs = TkCanvas.new(cf) {|c| focus diff --git a/ext/tk/sample/demos-jp/knightstour.rb b/ext/tk/sample/demos-jp/knightstour.rb new file mode 100644 index 0000000000..d4595ea441 --- /dev/null +++ b/ext/tk/sample/demos-jp/knightstour.rb @@ -0,0 +1,273 @@ +# -*- coding: euc-jp -*- +# +# Based on the widget demo of Tcl/Tk8.5.2 +# The following is the original copyright text. +#---------------------------------------------------------------------------- +# Copyright (C) 2008 Pat Thoyts +# +# Calculate a Knight's tour of a chessboard. +# +# This uses Warnsdorff's rule to calculate the next square each +# time. This specifies that the next square should be the one that +# has the least number of available moves. +# +# Using this rule it is possible to get to a position where +# there are no squares available to move into. In this implementation +# this occurs when the starting square is d6. +# +# To solve this fault an enhancement to the rule is that if we +# have a choice of squares with an equal score, we should choose +# the one nearest the edge of the board. +# +# If the call to the Edgemost function is commented out you can see +# this occur. +# +# You can drag the knight to a specific square to start if you wish. +# If you let it repeat then it will choose random start positions +# for each new tour. +#---------------------------------------------------------------------------- +require 'tk' + +class Knights_Tour + # Return a list of accessible squares from a given square + def valid_moves(square) + moves = [] + [ + [-1,-2], [-2,-1], [-2,1], [-1,2], [1,2], [2,1], [2,-1], [1,-2] + ].each{|col_delta, row_delta| + col = (square % 8) + col_delta + row = (square.div(8)) + row_delta + moves << (row * 8 + col) if row > -1 && row < 8 && col > -1 && col < 8 + } + moves + end + + # Return the number of available moves for this square + def check_square(square) + valid_moves(square).find_all{|pos| ! @visited.include?(pos)}.length + end + + # Select the next square to move to. Returns -1 if there are no available + # squares remaining that we can move to. + def next_square(square) + minimum = 9 + nxt = -1 + valid_moves(square).each{|pos| + unless @visited.include?(pos) + cnt = check_square(pos) + if cnt < minimum + minimum = cnt + nxt = pos + elsif cnt == minimum + nxt = edgemost(nxt, pos) + end + end + } + nxt + end + + # Select the square nearest the edge of the board + def edgemost(nxt, pos) + col_A = 3 - ((3.5 - nxt % 8).abs.to_i) + col_B = 3 - ((3.5 - pos % 8).abs.to_i) + row_A = 3 - ((3.5 - nxt.div(8)).abs.to_i) + row_B = 3 - ((3.5 - pos.div(8)).abs.to_i) + (col_A * row_A < col_B * row_B)? nxt : pos + end + + # Display a square number as a standard chess square notation. + def _N(square) + '%c%d' % [(97 + square % 8), (square.div(8) + 1)] + end + + # Perform a Knight's move and schedule the next move. + def move_piece(last, square) + @log.insert(:end, "#{@visited.length}. #{_N last} -> #{_N square}\n", '') + @log.see(:end) + @board.itemconfigure(1+last, :state=>:normal, :outline=>'black') + @board.itemconfigure(1+square, :state=>:normal, :outline=>'red') + @knight.coords(@board.coords(1+square)[0..1]) + @visited << square + if (nxt = next_square(square)) != -1 + @after_id = Tk.after(@delay.numeric){move_piece(square, nxt) rescue nil} + else + @start_btn.state :normal + if @visited.length == 64 + if @initial == square + @log.insert :end, '¼þÍ·(closed tour)À®¸ù¡ª' + else + @log.insert :end, "À®¸ù\n", {} + Tk.after(@delay.numeric * 2){tour(rand(64))} if @continuous.bool + end + else + @log.insert :end, "¼ºÇÔ¡ª\n", {} + end + end + end + + # Begin a new tour of the board given a random start position + def tour(square = nil) + @visited.clear + @log.clear + @start_btn.state :disabled + 1.upto(64){|n| + @board.itemconfigure(n, :state=>:disabled, :outline=>'black') + } + unless square + square = @board.find_closest(*(@knight.coords << 0 << 65))[0].to_i - 1 + end + @initial = square + Tk.after_idle{ move_piece(@initial, @initial) rescue nil } + end + + def _stop + Tk.after_cancel(@after_id) rescue nil + end + + def _exit + _stop + $knightstour.destroy + end + + def set_delay(new) + @delay.numeric = new.to_i + end + + def drag_start(w, x, y) + w.dtag('selected') + w.addtag('selected', :withtag, 'current') + @dragging = [x, y] + end + + def drag_motion(w, x, y) + return unless @dragging + w.move('selected', x - @dragging[0], y - @dragging[1]) + @dragging = [x, y] + end + + def drag_end(w, x, y) + square = w.find_closest(x, y, 0, 65) + w.coords('selected', w.coords(square)[0..1]) + w.dtag('selected') + @dragging = nil + end + + def make_SeeDismiss + ## See Code / Dismiss + frame = Ttk::Frame.new($knightstour) + sep = Ttk::Separator.new(frame) + Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) + TkGrid('x', + Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È', + :image=>$image['view'], :compound=>:left, + :command=>proc{showCode 'knightstour'}), + Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë', + :image=>$image['delete'], :compound=>:left, + :command=>proc{ + $knightstour.destroy + $knightstour = nil + }), + :padx=>4, :pady=>4) + frame.grid_columnconfigure(0, :weight=>1) + frame + end + + def create_gui(parent = nil) + $knightstour.destroy rescue nil + $knightstour = Tk::Toplevel.new(parent, :title=>"Knight's tour") + $knightstour.withdraw + base_f = Ttk::Frame.new($knightstour) + @board = Tk::Canvas.new(base_f, :width=>240, :height=>240) + @log = Tk::Text.new(base_f, :width=>12, :height=>1, + :font=>'Arial 8', :background=>'white') + scr = @log.yscrollbar(Ttk::Scrollbar.new(base_f)) + + @visited = [] + @delay = TkVariable.new(600) + @continuous = TkVariable.new(false) + + tool_f = Ttk::Frame.new($knightstour) + label = Ttk::Label.new(tool_f, :text=>'¼Â¹Ô®ÅÙ') + scale = Ttk::Scale.new(tool_f, :from=>8, :to=>2000, :variable=>@delay, + :command=>proc{|n| set_delay(n)}) + check = Ttk::Checkbutton.new(tool_f, :text=>'È¿Éü', + :variable=>@continuous) + @start_btn = Ttk::Button.new(tool_f, :text=>'³«»Ï', + :command=>proc{tour()}) + @exit_btn = Ttk::Button.new(tool_f, :text=>'½ªÎ»', + :command=>proc{_exit()}) + + 7.downto(0){|row| + 0.upto(7){|col| + if ((col & 1) ^ (row & 1)).zero? + fill = 'bisque' + dfill = 'bisque3' + else + fill = 'tan3' + dfill = 'tan4' + end + coords = [col * 30 + 4, row * 30 + 4, col * 30 + 30, row * 30 + 30] + @board.create(TkcRectangle, coords, + :fill=>fill, :disabledfill=>dfill, + :width=>2, :state=>:disabled) + } + } + + @knight_font = TkFont.new(:size=>-24) + @knight = TkcText.new(@board, 0, 0, :font=>@knight_font, + :text=>Tk::UTF8_String.new('\u265e'), + :anchor=>'nw', # :tags=>'knight', + :fill=>'black', :activefill=>'#600000') + @knight.coords(@board.coords(rand(64)+1)[0..1]) + @knight.bind('ButtonPress-1', '%W %x %y'){|w,x,y| drag_start(w,x,y)} + @knight.bind('Motion', '%W %x %y'){|w,x,y| drag_motion(w,x,y)} + @knight.bind('ButtonRelease-1', '%W %x %y'){|w,x,y| drag_end(w,x,y)} + + Tk.grid(@board, @log, scr, :sticky=>'news') + base_f.grid_rowconfigure(0, :weight=>1) + base_f.grid_columnconfigure(0, :weight=>1) + + Tk.grid(base_f, '-', '-', '-', '-', '-', :sticky=>'news') + widgets = [label, scale, check, @start_btn] + sg = nil + unless $RubyTk_WidgetDemo + widgets << @exit_btn + if Tk.windowingsystem != 'aqua' + #widgets.unshift(Ttk::SizeGrip.new(tool_f)) + Ttk::SizeGrip.new(tool_f).pack(:side=>:right, :anchor=>'se') + end + end + Tk.pack(widgets, :side=>:right) + if Tk.windowingsystem == 'aqua' + TkPack.configure(widgets, :padx=>[4, 4], :pady=>[12, 12]) + TkPack.configure(widgets[0], :padx=>[4, 24]) + TkPack.configure(widgets[-1], :padx=>[16, 4]) + end + + Tk.grid(tool_f, '-', '-', '-', '-', '-', :sticky=>'ew') + + if $RubyTk_WidgetDemo + Tk.grid(make_SeeDismiss(), '-', '-', '-', '-', '-', :sticky=>'ew') + end + + $knightstour.grid_rowconfigure(0, :weight=>1) + $knightstour.grid_columnconfigure(0, :weight=>1) + + $knightstour.bind('Control-F2'){TkConsole.show} + $knightstour.bind('Return'){@start_btn.invoke} + $knightstour.bind('Escape'){@exit_btn.invoke} + $knightstour.bind('Destroy'){ _stop } + $knightstour.protocol('WM_DELETE_WINDOW'){ _exit } + + $knightstour.deiconify + $knightstour.tkwait_destroy + end + + def initialize(parent = nil) + create_gui(parent) + end +end + +Tk.root.withdraw unless $RubyTk_WidgetDemo +Thread.new{Tk.mainloop} if __FILE__ == $0 +Knights_Tour.new diff --git a/ext/tk/sample/demos-jp/label.rb b/ext/tk/sample/demos-jp/label.rb index a1ecc2ec80..2e6b3e7e57 100644 --- a/ext/tk/sample/demos-jp/label.rb +++ b/ext/tk/sample/demos-jp/label.rb @@ -16,8 +16,10 @@ $label_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($label_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -msg = TkLabel.new($label_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -26,7 +28,7 @@ msg = TkLabel.new($label_demo) { msg.pack('side'=>'top') # frame À¸À® -TkFrame.new($label_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -45,8 +47,8 @@ TkFrame.new($label_demo) {|frame| }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # label demo Íѥե졼¥àÀ¸À® -f_left = TkFrame.new($label_demo) -f_right = TkFrame.new($label_demo) +f_left = TkFrame.new(base_frame) +f_right = TkFrame.new(base_frame) [f_left, f_right].each{|w| w.pack('side'=>'left', 'expand'=>'yes', 'padx'=>10, 'pady'=>10, 'fill'=>'both')} @@ -57,7 +59,8 @@ f_right = TkFrame.new($label_demo) TkLabel.new(f_left, 'text'=>'3 ÈÖÌÜ¡£ÄÀ¤ó¤Ç¤¤¤Þ¤¹ ', 'relief'=>'sunken') ].each{|w| w.pack('side'=>'top', 'expand'=>'yes', 'pady'=>2, 'anchor'=>'w')} -TkLabel.new(f_right) { +# TkLabel.new(f_right) { +Tk::Label.new(f_right) { bitmap('@' + [$demo_dir,'..','images','face.xbm'].join(File::Separator)) borderwidth 2 relief 'sunken' diff --git a/ext/tk/sample/demos-jp/labelframe.rb b/ext/tk/sample/demos-jp/labelframe.rb index f16b601ffd..11b0d27308 100644 --- a/ext/tk/sample/demos-jp/labelframe.rb +++ b/ext/tk/sample/demos-jp/labelframe.rb @@ -19,8 +19,10 @@ $labelframe_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($labelframe_demo).pack(:fill=>:both, :expand=>true) + # Some information -TkLabel.new($labelframe_demo, +TkLabel.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left, :text=><:top) TkLabelFrame ¥¦¥£¥¸¥§¥Ã¥È¤Ï´ØÏ¢¤¹¤ë widget @@ -36,7 +38,7 @@ labelframe EOL # The bottom buttons -TkFrame.new($labelframe_demo){|f| +TkFrame.new(base_frame){|f| pack(:side=>:bottom, :fill=>:x, :pady=>'2m') TkButton.new(f, :text=>'ÊĤ¸¤ë', :width=>15, :command=>proc{ @@ -50,7 +52,7 @@ TkFrame.new($labelframe_demo){|f| } # Demo area -w = TkFrame.new($labelframe_demo).pack(:side=>:bottom, :fill=>:both, +w = TkFrame.new(base_frame).pack(:side=>:bottom, :fill=>:both, :expand=>true) # A group of radiobuttons in a labelframe diff --git a/ext/tk/sample/demos-jp/mclist.rb b/ext/tk/sample/demos-jp/mclist.rb new file mode 100644 index 0000000000..a7834d2668 --- /dev/null +++ b/ext/tk/sample/demos-jp/mclist.rb @@ -0,0 +1,121 @@ +# -*- coding: euc-jp -*- +# +# mclist.rb -- +# +# This demonstration script creates a toplevel window containing a Ttk +# tree widget configured as a multi-column listbox. +# +# based on "Id: mclist.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp" + +if defined?($mclist_demo) && $mclist_demo + $mclist_demo.destroy + $mclist_demo = nil +end + +$mclist_demo = TkToplevel.new {|w| + title("Multi-Column List") + iconname("mclist") + positionWindow(w) +} + +base_frame = TkFrame.new($mclist_demo).pack(:fill=>:both, :expand=>true) + +## Explanatory text +Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', + :justify=>:left, :anchor=>'n', :padding=>[10, 2, 10, 6], + :text=><:x) +Ttk¤È¤Ï¡¤¥Æ¡¼¥Þ»ØÄê²Äǽ¤Ê¿·¤·¤¤¥¦¥£¥¸¥§¥Ã¥È½¸¹ç¤Ç¤¹¡¥\ +Ttk::Treeview¥¦¥£¥¸¥§¥Ã¥È¤Ï\ +Ttk¥¦¥£¥¸¥§¥Ã¥È¥»¥Ã¥È¤Ë´Þ¤Þ¤ì¤ë¥¦¥£¥¸¥§¥Ã¥È¤Î°ì¤Ä¤Ç¡¤\ +¤½¤ì¤¬ÊÝ»ý¤¹¤ëÌÚ¹½Â¤¤Î¥Ç¡¼¥¿¤½¤Î¤â¤Î¤Þ¤Ç¤Ïɽ¼¨¤¹¤ë¤³¤È¤Ê¤¯¡¤\ +¼¨¤·¤¿¤¤¾ðÊó¤ò¥Þ¥ë¥Á¥«¥é¥à¤Çɽ¼¨¤µ¤»¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡¥ +¤³¤Î¥µ¥ó¥×¥ë¤Ï¡¤Ê£¿ô¤Î¥«¥é¥à¤ò»ý¤Ã¤¿¥ê¥¹¥È¥Ü¥Ã¥¯¥¹¤òºîÀ®¤¹¤ë´Êñ¤ÊÎã¤Ç¤¹¡¥ +³Æ¥«¥é¥à¤Î¥¿¥¤¥È¥ë(heading)¤ò¥¯¥ê¥Ã¥¯¤¹¤ì¤Ð¡¤\ +¤½¤Î¥«¥é¥à¤Î¾ðÊó¤Ë´ð¤Å¤¤¤Æ¥ê¥¹¥È¤ÎʤÙÂؤ¨¤¬¤Ê¤µ¤ì¤ë¤Ï¤º¤Ç¤¹¡¥\ +¤Þ¤¿¡¤¥«¥é¥à¤Î¥¿¥¤¥È¥ë´Ö¤Î¶èÀÚ¤êÉôʬ¤ò¥É¥é¥Ã¥°¤¹¤ë¤³¤È¤Ç¡¤\ +¥«¥é¥à¤ÎÉý¤òÊѹ¹¤¹¤ë¤³¤È¤â²Äǽ¤Ç¤¹¡¥ +EOL + +## See Code / Dismiss +Ttk::Frame.new(base_frame) {|frame| + sep = Ttk::Separator.new(frame) + Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) + TkGrid('x', + Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È', + :image=>$image['view'], :compound=>:left, + :command=>proc{showCode 'mclist'}), + Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë', + :image=>$image['delete'], :compound=>:left, + :command=>proc{ + $mclist_demo.destroy + $mclist_demo = nil + }), + :padx=>4, :pady=>4) + grid_columnconfigure(0, :weight=>1) + pack(:side=>:bottom, :fill=>:x) +} + +container = Ttk::Frame.new(base_frame) +tree = Ttk::Treeview.new(base_frame, :columns=>%w(country capital currency), + :show=>:headings) +if Tk.windowingsystem != 'aquq' + vsb = tree.yscrollbar(Ttk::Scrollbar.new(base_frame)) + hsb = tree.xscrollbar(Ttk::Scrollbar.new(base_frame)) +else + vsb = tree.yscrollbar(Tk::Scrollbar.new(base_frame)) + hsb = tree.xscrollbar(Tk::Scrollbar.new(base_frame)) +end + +container.pack(:fill=>:both, :expand=>true) +Tk.grid(tree, vsb, :in=>container, :sticky=>'nsew') +Tk.grid(hsb, :in=>container, :sticky=>'nsew') +container.grid_columnconfigure(0, :weight=>1) +container.grid_rowconfigure(0, :weight=>1) + +## The data we're going to insert +data = [ + ['¥¢¥ë¥¼¥ó¥Á¥ó', '¥Ö¥¨¥Î¥¹¥¢¥¤¥ì¥¹', 'ARS'], + ['¥ª¡¼¥¹¥È¥é¥ê¥¢', '¥­¥ã¥ó¥Ù¥é', 'AUD'], + ['¥Ö¥é¥¸¥ë', '¥Ö¥é¥¸¥ê¥¢', 'BRL'], + ['¥«¥Ê¥À', '¥ª¥¿¥ï', 'CAD'], + ['Ãæ¹ñ', 'Ë̵þ', 'CNY'], + ['¥Õ¥é¥ó¥¹', '¥Ñ¥ê', 'EUR'], + ['¥É¥¤¥Ä', '¥Ù¥ë¥ê¥ó', 'EUR'], + ['¥¤¥ó¥É', '¥Ë¥å¡¼¥Ç¥ê¡¼', 'INR'], + ['¥¤¥¿¥ê¥¢', '¥í¡¼¥Þ', 'EUR'], + ['ÆüËÜ', 'Åìµþ', 'JPY'], + ['¥á¥­¥·¥³', '¥á¥­¥·¥³¥·¥Æ¥£', 'MXN'], + ['¥í¥·¥¢', '¥â¥¹¥¯¥ï', 'RUB'], + ['Æ¥Õ¥ê¥«', '¥×¥ì¥È¥ê¥¢', 'ZAR'], + ['±Ñ¹ñ', '¥í¥ó¥É¥ó', 'GBP'], + ['¥¢¥á¥ê¥«', '¥ï¥·¥ó¥È¥ó D.C.', 'USD'], +] + +## Code to insert the data nicely +font = Ttk::Style.lookup(tree[:style], :font) +cols = %w(country capital currency) +cols.zip(%w(¹ñ̾ ¼óÅÔ Ä̲ß)).each{|col, name| + tree.heading_configure(col, :text=>name, + :command=>proc{sort_by(tree, col, false)}) + tree.column_configure(col, :width=>TkFont.measure(font, name)) +} + +data.each{|country, capital, currency| + #tree.insert('', :end, :values=>[country, capital, currency]) + tree.insert(nil, :end, :values=>[country, capital, currency]) + cols.zip([country, capital, currency]).each{|col, val| + len = TkFont.measure(font, "#{val} ") + if tree.column_cget(col, :width) < len + tree.column_configure(col, :width=>len) + end + } +} + +## Code to do the sorting of the tree contents when clicked on +def sort_by(tree, col, direction) + tree.children(nil).map!{|row| [tree.get(row, col), row.id]} . + sort(&((direction)? proc{|x, y| y <=> x}: proc{|x, y| x <=> y})) . + each_with_index{|info, idx| tree.move(info[1], nil, idx)} + + tree.heading_configure(col, :command=>proc{sort_by(tree, col, ! direction)}) +end diff --git a/ext/tk/sample/demos-jp/menu.rb b/ext/tk/sample/demos-jp/menu.rb index 6b9e5c9e5e..c3d95176b4 100644 --- a/ext/tk/sample/demos-jp/menu.rb +++ b/ext/tk/sample/demos-jp/menu.rb @@ -16,8 +16,10 @@ $menu_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($menu_demo).pack(:fill=>:both, :expand=>true) + # menu frame À¸À® -$menu_frame = TkFrame.new($menu_demo, 'relief'=>'raised', 'bd'=>2) +$menu_frame = TkFrame.new(base_frame, 'relief'=>'raised', 'bd'=>2) $menu_frame.pack('side'=>'top', 'fill'=>'x') begin @@ -27,7 +29,7 @@ rescue end # label À¸À® -TkLabel.new($menu_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { +TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { if $tk_platform['platform'] == 'macintosh' || windowingsystem == "classic" || windowingsystem == "aqua" text("¤³¤Î¥¦¥£¥ó¥É¥¦¤ÏÍÍ¡¹¤Ê¥á¥Ë¥å¡¼¤È¥«¥¹¥±¡¼¥É¥á¥Ë¥å¡¼¤«¤é¹½À®¤µ¤ì¤Æ¤¤¤Þ¤¹¡£Command-X ¤òÆþÎϤ¹¤ë¤È¡¢X¤¬¥³¥Þ¥ó¥É¥­¡¼µ­¹æ¤Ë³¤¤¤Æɽ¼¨¤µ¤ì¤Æ¤¤¤ëʸ»ú¤Ê¤é¤Ð¡¢¥¢¥¯¥»¥é¥ì¡¼¥¿¤ò»È¤Ã¤¿¹àÌܵ¯Æ°¤ò¹Ô¤¦¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¥á¥Ë¥å¡¼Í×ÁÇÃæ¡¢ºÇ¸å¤Î¤â¤Î¤Ï¡¢¤½¤Î¥á¥Ë¥å¡¼¤ÎºÇ½é¤Î¹àÌܤòÁªÂò¤¹¤ë¤³¤È¤ÇÆÈΩ¤µ¤»¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£") @@ -37,7 +39,7 @@ TkLabel.new($menu_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { }.pack('side'=>'top') # frame À¸À® -TkFrame.new($menu_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -108,7 +110,8 @@ TkMenubutton.new($menu_frame, 'text'=>'Cascades', 'underline'=>0) {|m| 'accelerator'=>"#{modifier}+G", 'underline'=>6) $menu_demo.bind("#{modifier}-g", proc{print "Goodbye(¤µ¤è¤¦¤Ê¤é)\n"}) - TkMenu.new(m, 'tearoff'=>false) {|cascade_check| + # TkMenu.new(m, 'tearoff'=>false) {|cascade_check| + TkMenu.new(cascade_menu, 'tearoff'=>false) {|cascade_check| cascade_menu.add('cascade', 'label'=>'Check buttons(¥Á¥§¥Ã¥¯¥Ü¥¿¥ó)', 'menu'=>cascade_check, 'underline'=>0) oil = TkVariable.new(0) @@ -130,7 +133,8 @@ TkMenubutton.new($menu_frame, 'text'=>'Cascades', 'underline'=>0) {|m| invoke 3 } - TkMenu.new(m, 'tearoff'=>false) {|cascade_radio| + #TkMenu.new(m, 'tearoff'=>false) {|cascade_radio| + TkMenu.new(cascade_menu, 'tearoff'=>false) {|cascade_radio| cascade_menu.add('cascade', 'label'=>'Radio buttons(¥é¥¸¥ª¥Ü¥¿¥ó)', 'menu'=>cascade_radio, 'underline'=>0) pointSize = TkVariable.new diff --git a/ext/tk/sample/demos-jp/menu84.rb b/ext/tk/sample/demos-jp/menu84.rb index 762cfa53b8..a631bacd43 100644 --- a/ext/tk/sample/demos-jp/menu84.rb +++ b/ext/tk/sample/demos-jp/menu84.rb @@ -16,6 +16,8 @@ $menu84_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($menu84_demo).pack(:fill=>:both, :expand=>true) + begin windowingsystem = Tk.windowingsystem() rescue @@ -23,7 +25,7 @@ rescue end # label -TkLabel.new($menu84_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { +TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { if $tk_platform['platform'] == 'macintosh' || windowingsystem == "classic" || windowingsystem == "aqua" text("¤³¤Î¥¦¥£¥ó¥É¥¦¤Ë¤Ï¥«¥¹¥±¡¼¥É¥á¥Ë¥å¡¼¤ò»ý¤Ä¥á¥Ë¥å¡¼¥Ð¡¼¤¬ÉÕ¤±¤é¤ì¤Æ¤¤¤Þ¤¹¡£Command+x ('x'¤Ï¥³¥Þ¥ó¥É¥­¡¼¥·¥ó¥Ü¥ë¤Ë³¤±¤Æɽ¼¨¤µ¤ì¤Æ¤¤¤ëʸ»ú¤Ç¤¹) ¤È¥¿¥¤¥×¤¹¤ë¤³¤È¤Ë¤è¤Ã¤Æ¤â¹àÌܤε¡Ç½¤ò¸Æ¤Ó½Ð¤¹¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£ºÇ¸å¤Î¥á¥Ë¥å¡¼¤Ï¡¢¥Þ¥¦¥¹¤Ç¥¦¥£¥ó¥É¥¦¤Î³°¤Ë¥É¥é¥Ã¥°¤¹¤ë¤³¤È¤Ë¤è¤Ã¤Æ¡¢ÆÈΩ¤·¤¿¥Ñ¥ì¥Ã¥È¤È¤Ê¤ë¤è¤¦¤ËÀÚ¤êÊü¤¹¤³¤È¤¬²Äǽ¤Ç¤¹¡£") @@ -34,7 +36,7 @@ TkLabel.new($menu84_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { menustatus = TkVariable.new(" ") -TkFrame.new($menu84_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkLabel.new(frame, 'textvariable'=>menustatus, 'relief'=>'sunken', 'bd'=>1, 'font'=>['Helvetica', '10'], 'anchor'=>'w').pack('side'=>'left', 'padx'=>2, @@ -44,7 +46,7 @@ TkFrame.new($menu84_demo) {|frame| # frame -TkFrame.new($menu84_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' diff --git a/ext/tk/sample/demos-jp/menu8x.rb b/ext/tk/sample/demos-jp/menu8x.rb index 23efa7e790..9249f2491a 100644 --- a/ext/tk/sample/demos-jp/menu8x.rb +++ b/ext/tk/sample/demos-jp/menu8x.rb @@ -16,16 +16,18 @@ $menu8x_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($menu8x_demo).pack(:fill=>:both, :expand=>true) + # version check if $tk_version.to_f < 8.0 # label À¸À® -TkLabel.new($menu8x_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { +TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { text("¼Â¹Ô¤·¤è¤¦¤È¤·¤¿¥¹¥¯¥ê¥×¥È¤Ï Tk8.0 °Ê¾å¤ÇÍøÍѤǤ­¤ëµ¡Ç½¤òÍøÍѤ·¤Æ¤¤¤ë¤¿¤á¡¢¤¢¤Ê¤¿¤Î Ruby#{VERSION}/Tk#{$tk_version}#{(Tk::JAPANIZED_TK)? 'jp': ''} ¤Ç¤ÏÀµ¾ï¤Ë¼Â¹Ô¤Ç¤­¤Þ¤»¤ó¡£¤è¤Ã¤Æ¥Ç¥â¤Î¼Â¹Ô¤òÃæ»ß¤·¤Þ¤·¤¿¡£¤¿¤À¤·¡¢²¼¤Î¥³¡¼¥É»²¾È¥Ü¥¿¥ó¤ò²¡¤¹¤³¤È¤Ç¡¢¼Â¹Ô¤¬Ãæ»ß¤µ¤ì¤¿¥¹¥¯¥ê¥×¥È¤Î¥½¡¼¥¹¤ò»²¾È¤¹¤ë¤³¤È¤Ï²Äǽ¤Ç¤¹¡£") }.pack('side'=>'top') # frame À¸À® -TkFrame.new($menu8x_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -51,7 +53,7 @@ rescue end # label À¸À® -TkLabel.new($menu8x_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { +TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { if $tk_platform['platform'] == 'macintosh' || windowingsystem == "classic" || windowingsystem == "aqua" text("¤³¤Î¥¦¥£¥ó¥É¥¦¤ÏÍÍ¡¹¤Ê¥á¥Ë¥å¡¼¤È¥«¥¹¥±¡¼¥É¥á¥Ë¥å¡¼¤«¤é¹½À®¤µ¤ì¤Æ¤¤¤Þ¤¹¡£Command-X ¤òÆþÎϤ¹¤ë¤È¡¢X¤¬¥³¥Þ¥ó¥É¥­¡¼µ­¹æ¤Ë³¤¤¤Æɽ¼¨¤µ¤ì¤Æ¤¤¤ëʸ»ú¤Ê¤é¤Ð¡¢¥¢¥¯¥»¥é¥ì¡¼¥¿¤ò»È¤Ã¤¿¹àÌܵ¯Æ°¤ò¹Ô¤¦¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¥á¥Ë¥å¡¼Í×ÁÇÃæ¡¢ºÇ¸å¤Î¤â¤Î¤Ï¡¢¤½¤Î¥á¥Ë¥å¡¼¤ÎºÇ½é¤Î¹àÌܤòÁªÂò¤¹¤ë¤³¤È¤ÇÆÈΩ¤µ¤»¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£") @@ -62,14 +64,14 @@ TkLabel.new($menu8x_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { # ¾õÂÖɽ¼¨¤ÎÀ¸À® $menu8xstatus = TkVariable.new(" ") -TkFrame.new($menu8x_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkLabel.new(frame, 'textvariable'=>$menu8xstatus, 'relief'=>'sunken', 'bd'=>1, 'font'=>['Helvetica', '10'], 'anchor'=>'w')\ .pack('side'=>'left', 'padx'=>2, 'expand'=>'yes', 'fill'=>'both') }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>2) # frame À¸À® -TkFrame.new($menu8x_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' diff --git a/ext/tk/sample/demos-jp/menubu.rb b/ext/tk/sample/demos-jp/menubu.rb index e73c393aa5..90dc367305 100644 --- a/ext/tk/sample/demos-jp/menubu.rb +++ b/ext/tk/sample/demos-jp/menubu.rb @@ -33,16 +33,18 @@ $menubu_demo = TkToplevel.new {|w| positionWindow($menubu_demo) +base_frame = TkFrame.new($menubu_demo).pack(:fill=>:both, :expand=>true) + # version check if $tk_version.to_f < 8.0 # label À¸À® -TkLabel.new($menubu_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { +TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') { text("¼Â¹Ô¤·¤è¤¦¤È¤·¤¿¥¹¥¯¥ê¥×¥È¤Ï Tk8.0 °Ê¾å¤ÇÍøÍѤǤ­¤ëµ¡Ç½¤òÍøÍѤ·¤Æ¤¤¤ë¤¿¤á¡¢¤¢¤Ê¤¿¤Î Ruby#{VERSION}/Tk#{$tk_version}#{(Tk::JAPANIZED_TK)? 'jp': ''} ¤Ç¤ÏÀµ¾ï¤Ë¼Â¹Ô¤Ç¤­¤Þ¤»¤ó¡£¤è¤Ã¤Æ¥Ç¥â¤Î¼Â¹Ô¤òÃæ»ß¤·¤Þ¤·¤¿¡£¤¿¤À¤·¡¢²¼¤Î¥³¡¼¥É»²¾È¥Ü¥¿¥ó¤ò²¡¤¹¤³¤È¤Ç¡¢¼Â¹Ô¤¬Ãæ»ß¤µ¤ì¤¿¥¹¥¯¥ê¥×¥È¤Î¥½¡¼¥¹¤ò»²¾È¤¹¤ë¤³¤È¤Ï²Äǽ¤Ç¤¹¡£") }.pack('side'=>'top') # frame À¸À® -TkFrame.new($menubu_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -61,7 +63,7 @@ TkFrame.new($menubu_demo) {|frame| else ; # Tk8.x -body = TkFrame.new($menubu_demo) +body = TkFrame.new(base_frame) body.pack('expand'=>'yes', 'fill'=>'both') below = TkMenubutton.new(body) { @@ -156,7 +158,7 @@ center = TkFrame.new(body) { grid('row'=>1, 'column'=>1, 'sticky'=>'news') } -TkFrame.new($menubu_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' diff --git a/ext/tk/sample/demos-jp/msgbox.rb b/ext/tk/sample/demos-jp/msgbox.rb index 0fe5db7dd6..88380e08bd 100644 --- a/ext/tk/sample/demos-jp/msgbox.rb +++ b/ext/tk/sample/demos-jp/msgbox.rb @@ -16,12 +16,14 @@ $msgbox_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($msgbox_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -TkLabel.new($msgbox_demo, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left', - 'text'=>"ɽ¼¨¤¹¤ë¥¢¥¤¥³¥ó¤È¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹¤Î¼ïÎà¤òÁª¤ó¤Ç²¼¤µ¤¤¡£¤½¤·¤Æ \"¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹\" ¥Ü¥¿¥ó¤ò²¡¤¹¤È¡¢»ØÄꤷ¤¿¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£").pack('side'=>'top') +TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left', + 'text'=>"¤Þ¤ºÉ½¼¨¤¹¤ë¥¢¥¤¥³¥ó¤È¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹¤Î¼ïÎà¤òÁª¤ó¤Ç²¼¤µ¤¤¡£¤½¤Î¸å¤Ë\"¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹\"¥Ü¥¿¥ó¤ò²¡¤¹¤È¡¢»ØÄꤷ¤¿¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£").pack('side'=>'top') # frame À¸À® -TkFrame.new($msgbox_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -44,8 +46,8 @@ TkFrame.new($msgbox_demo) {|frame| }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # frame À¸À® -$msgbox_leftframe = TkFrame.new($msgbox_demo) -$msgbox_rightframe = TkFrame.new($msgbox_demo) +$msgbox_leftframe = TkFrame.new(base_frame) +$msgbox_rightframe = TkFrame.new(base_frame) $msgbox_leftframe .pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y', 'pady'=>'.5c', 'padx'=>'.5c') $msgbox_rightframe.pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y', @@ -79,7 +81,7 @@ $msgboxType = TkVariable.new('ok') def showMessageBox(w) button = Tk.messageBox('icon'=>$msgboxIcon.value, 'type'=>$msgboxType.value, 'title'=>'Message', 'parent'=>w, - 'message'=>"¤³¤ì¤Ï \"#{$msgboxType.value}\" ¤È¤¤¤¦¼ïÎà¤Î¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹¤Ç¡¢\"#{$msgboxIcon.value}\" ¤Î¥¢¥¤¥³¥ó¤¬É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡£") + 'message'=>"¤³¤ì¤Ï\"#{$msgboxType.value}\"¤È¤¤¤¦¼ïÎà¤Î¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹¤Ç¡¢\"#{$msgboxIcon.value}\"¤Î¥¢¥¤¥³¥ó¤¬É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡£") Tk.messageBox('icon'=>'info', 'type'=>'ok', 'parent'=>w, 'message'=>"¤¢¤Ê¤¿¤Ï \"#{button}\" ¤ò²¡¤·¤Þ¤·¤¿¤Í¡£") diff --git a/ext/tk/sample/demos-jp/msgbox2.rb b/ext/tk/sample/demos-jp/msgbox2.rb new file mode 100644 index 0000000000..d61f25129a --- /dev/null +++ b/ext/tk/sample/demos-jp/msgbox2.rb @@ -0,0 +1,90 @@ +# -*- coding: euc-jp -*- +# +# message boxes widget demo (called by 'widget') +# + +# toplevel widget ¤¬Â¸ºß¤¹¤ì¤Ðºï½ü¤¹¤ë +if defined?($msgbox2_demo) && $msgbox2_demo + $msgbox2_demo.destroy + $msgbox2_demo = nil +end + +# demo ÍѤΠtoplevel widget ¤òÀ¸À® +$msgbox2_demo = TkToplevel.new {|w| + title("Message Box Demonstration") + iconname("messagebox") + positionWindow(w) +} + +base_frame = TkFrame.new($msgbox2_demo).pack(:fill=>:both, :expand=>true) + +# label À¸À® +TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left', + 'text'=>"¤Þ¤ºÉ½¼¨¤¹¤ë¥¢¥¤¥³¥ó¤È¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹¤Î¼ïÎà¤òÁª¤ó¤Ç²¼¤µ¤¤¡£¤½¤Î¸å¤Ë\"¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹\"¥Ü¥¿¥ó¤ò²¡¤¹¤È¡¢»ØÄꤵ¤ì¤¿·Á¼°¤Ç¡¢¥á¥Ã¥»¡¼¥¸¤È¾ÜºÙ¥Æ¥­¥¹¥È¤È¤ò»ý¤Ã¤¿¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£").pack('side'=>'top') + +# frame À¸À® +TkFrame.new(base_frame) {|frame| + TkButton.new(frame) { + #text 'λ²ò' + text 'ÊĤ¸¤ë' + command proc{ + tmppath = $msgbox2_demo + $msgbox2_demo = nil + tmppath.destroy + } + }.pack('side'=>'left', 'expand'=>'yes') + + TkButton.new(frame) { + text '¥³¡¼¥É»²¾È' + command proc{showCode 'msgbox2'} + }.pack('side'=>'left', 'expand'=>'yes') + + TkButton.new(frame) { + text '¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹' + command proc{showMessageBox $msgbox2_demo} + }.pack('side'=>'left', 'expand'=>'yes') +}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') + +# frame À¸À® +$msgbox_leftframe = TkFrame.new(base_frame) +$msgbox_rightframe = TkFrame.new(base_frame) +$msgbox_leftframe .pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y', + 'pady'=>'.5c', 'padx'=>'.5c') +$msgbox_rightframe.pack('side'=>'left', 'expand'=>'yes', 'fill'=>'y', + 'pady'=>'.5c', 'padx'=>'.5c') + +TkLabel.new($msgbox_leftframe, 'text'=>'¥¢¥¤¥³¥ó').pack('side'=>'top') +TkFrame.new($msgbox_leftframe, 'relief'=>'ridge', 'bd'=>1, 'height'=>2)\ +.pack('side'=>'top', 'fill'=>'x', 'expand'=>'no') + +$msgboxIcon = TkVariable.new('info') +['error', 'info', 'question', 'warning'].each {|icon| + TkRadioButton.new($msgbox_leftframe, 'text'=>icon, 'variable'=>$msgboxIcon, + 'relief'=>'flat', 'value'=>icon, 'width'=>16, + 'anchor'=>'w').pack('side'=>'top', 'pady'=>2, + 'anchor'=>'w', 'fill'=>'x') +} + +TkLabel.new($msgbox_rightframe, 'text'=>'¼ïÎà').pack('side'=>'top') +TkFrame.new($msgbox_rightframe, 'relief'=>'ridge', 'bd'=>1, 'height'=>2)\ +.pack('side'=>'top', 'fill'=>'x', 'expand'=>'no') + +$msgboxType = TkVariable.new('ok') +['abortretryignore', 'ok', 'okcancel', + 'retrycancel', 'yesno', 'yesnocancel'].each {|type| + TkRadioButton.new($msgbox_rightframe, 'text'=>type, 'variable'=>$msgboxType, + 'relief'=>'flat', 'value'=>type, 'width'=>16, + 'anchor'=>'w').pack('side'=>'top', 'pady'=>2, + 'anchor'=>'w', 'fill'=>'x') +} + +def showMessageBox(w) + button = Tk.messageBox('icon'=>$msgboxIcon.value, 'type'=>$msgboxType.value, + 'title'=>'Message', 'parent'=>w, + 'message'=>"\"#{$msgboxType.value}\"¥¿¥¤¥×¤Î¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹", + 'detail'=>"¤³¤ì¤Ï\"#{$msgboxType.value}\"¤È¤¤¤¦¼ïÎà¤Î¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹¤Ç¡¢\"#{$msgboxIcon.value}\"¤Î¥¢¥¤¥³¥ó¤¬É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡£²¼¤Î¥Ü¥¿¥ó¤Î¤¤¤º¤ì¤«¤òÁªÂò¤·¤Æ¥¯¥ê¥Ã¥¯¤·¤Æ¤¯¤À¤µ¤¤¡£") + + Tk.messageBox('icon'=>'info', 'type'=>'ok', 'parent'=>w, + 'message'=>"¤¢¤Ê¤¿¤Ï \"#{button}\" ¤ò²¡¤·¤Þ¤·¤¿¤Í¡£") +end + diff --git a/ext/tk/sample/demos-jp/paned1.rb b/ext/tk/sample/demos-jp/paned1.rb index 137e187417..f994e83ff1 100644 --- a/ext/tk/sample/demos-jp/paned1.rb +++ b/ext/tk/sample/demos-jp/paned1.rb @@ -18,7 +18,9 @@ $paned1_demo = TkToplevel.new {|w| positionWindow(w) } -TkLabel.new($paned1_demo, +base_frame = TkFrame.new($paned1_demo).pack(:fill=>:both, :expand=>true) + +TkLabel.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left, :text=><:top) ²¼¤Î¿§ÉÕ¤±¤µ¤ì¤¿Æó¤Ä¤Î¥¦¥£¥ó¥É¥¦¤Î´Ö¤Î»ÅÀÚ¤êÏȤϡ¢°ì¤Ä¤ÎÎΰè¤ò¤½¤ì¤¾¤ì¤Î¥¦¥£¥ó¥É¥¦¤Î¤¿¤á¤Ëʬ³ä¤¹¤ë¤¿¤á¤Î¤â¤Î¤Ç¤¹¡£º¸¥Ü¥¿¥ó¤Ç»ÅÀÚ¤ê¤òÁàºî¤¹¤ë¤È¡¢Ê¬³ä¥µ¥¤¥ºÊѹ¹¤ÎÁàºîÅÓÃæ¤Ç¤ÏºÆɽ¼¨¤Ï¤Ê¤µ¤ì¤º¡¢³ÎÄꤵ¤»¤¿¤È¤­¤Ëɽ¼¨¤¬¹¹¿·¤µ¤ì¤Þ¤¹¡£¥Þ¥¦¥¹¤Ë¤è¤ë»ÅÀÚ¤ê¤ÎÁàºî¤ËÄɿ路¤Æ¥µ¥¤¥º¤òÊѹ¹¤·¤¿É½¼¨¤¬¤Ê¤ï¤ì¤ë¤è¤¦¤Ë¤·¤¿¤¤¾ì¹ç¤Ï¡¢¥Þ¥¦¥¹¤ÎÃæ±û¥Ü¥¿¥ó¤ò»È¤Ã¤Æ¤¯¤À¤µ¤¤¡£ @@ -29,7 +31,7 @@ TkLabel.new($paned1_demo, EOL # The bottom buttons -TkFrame.new($paned1_demo){|f| +TkFrame.new(base_frame){|f| pack(:side=>:bottom, :fill=>:x, :pady=>'2m') TkButton.new(f, :text=>'ÊĤ¸¤ë', :width=>15, :command=>proc{ @@ -42,9 +44,9 @@ TkFrame.new($paned1_demo){|f| }).pack(:side=>:left, :expand=>true) } -TkPanedwindow.new($paned1_demo){|f| - pack(:side=>:top, :expand=>true, :fill=>:both, :pady=>2, :padx=>'2m') +TkPanedwindow.new(base_frame, :orient=>:horizontal){|f| + add(Tk::Label.new(f, :text=>"This is the\nleft side", :bg=>'yellow'), + Tk::Label.new(f, :text=>"This is the\nright side", :bg=>'cyan')) - add(TkLabel.new(f, :text=>"This is the\nleft side", :bg=>'yellow'), - TkLabel.new(f, :text=>"This is the\nright side", :bg=>'cyan')) + pack(:side=>:top, :expand=>true, :fill=>:both, :pady=>2, :padx=>'2m') } diff --git a/ext/tk/sample/demos-jp/paned2.rb b/ext/tk/sample/demos-jp/paned2.rb index b394432b1c..cdc8253402 100644 --- a/ext/tk/sample/demos-jp/paned2.rb +++ b/ext/tk/sample/demos-jp/paned2.rb @@ -18,7 +18,9 @@ $paned2_demo = TkToplevel.new {|w| positionWindow(w) } -TkLabel.new($paned2_demo, +base_frame = TkFrame.new($paned2_demo).pack(:fill=>:both, :expand=>true) + +TkLabel.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left, :text=><:top) ²¼¤Î¥¹¥¯¥í¡¼¥ë¥Ð¡¼ÉÕ¤­¤Î¥¦¥£¥¸¥§¥Ã¥È¤¬ÃÖ¤«¤ì¤¿Æó¤Ä¤Î¥¦¥£¥ó¥É¥¦¤Î´Ö¤Î»ÅÀÚ¤êÏȤϡ¢°ì¤Ä¤ÎÎΰè¤ò¤½¤ì¤¾¤ì¤Î¥¦¥£¥ó¥É¥¦¤Î¤¿¤á¤Ëʬ³ä¤¹¤ë¤¿¤á¤Î¤â¤Î¤Ç¤¹¡£º¸¥Ü¥¿¥ó¤Ç»ÅÀÚ¤ê¤òÁàºî¤¹¤ë¤È¡¢Ê¬³ä¥µ¥¤¥ºÊѹ¹¤ÎÁàºîÅÓÃæ¤Ç¤ÏºÆɽ¼¨¤Ï¤Ê¤µ¤ì¤º¡¢³ÎÄꤵ¤»¤¿¤È¤­¤Ëɽ¼¨¤¬¹¹¿·¤µ¤ì¤Þ¤¹¡£¥Þ¥¦¥¹¤Ë¤è¤ë»ÅÀÚ¤ê¤ÎÁàºî¤ËÄɿ路¤Æ¥µ¥¤¥º¤òÊѹ¹¤·¤¿É½¼¨¤¬¤Ê¤ï¤ì¤ë¤è¤¦¤Ë¤·¤¿¤¤¾ì¹ç¤Ï¡¢¥Þ¥¦¥¹¤ÎÃæ±û¥Ü¥¿¥ó¤ò»È¤Ã¤Æ¤¯¤À¤µ¤¤¡£ @@ -29,7 +31,7 @@ TkLabel.new($paned2_demo, EOL # The bottom buttons -TkFrame.new($paned2_demo){|f| +TkFrame.new(base_frame){|f| pack(:side=>:bottom, :fill=>:x, :pady=>'2m') TkButton.new(f, :text=>'ÊĤ¸¤ë', :width=>15, :command=>proc{ @@ -66,7 +68,7 @@ paneList.value = [ # ruby's array --> tcl's list ] # Create the pane itself -TkPanedwindow.new($paned2_demo, :orient=>:vertical){|f| +TkPanedwindow.new(base_frame, :orient=>:vertical){|f| pack(:side=>:top, :expand=>true, :fill=>:both, :pady=>2, :padx=>'2m') add(TkFrame.new(f){|paned2_top| diff --git a/ext/tk/sample/demos-jp/pendulum.rb b/ext/tk/sample/demos-jp/pendulum.rb index e19b57a2d6..b115f5be2c 100644 --- a/ext/tk/sample/demos-jp/pendulum.rb +++ b/ext/tk/sample/demos-jp/pendulum.rb @@ -19,8 +19,10 @@ $pendulum_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($pendulum_demo).pack(:fill=>:both, :expand=>true) + # create label -msg = TkLabel.new($pendulum_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -29,7 +31,7 @@ msg = TkLabel.new($pendulum_demo) { msg.pack('side'=>'top') # create frame -TkFrame.new($pendulum_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -51,7 +53,7 @@ TkFrame.new($pendulum_demo) {|frame| class PendulumAnimationDemo def initialize(frame) # Create some structural widgets - @pane = TkPanedWindow.new(frame).pack(:fill=>:both, :expand=>true) + @pane = TkPanedWindow.new(frame, :orient=>:horizontal).pack(:fill=>:both, :expand=>true) # @pane.add(@lf1 = TkLabelFrame.new(@pane, :text=>'Pendulum Simulation')) # @pane.add(@lf2 = TkLabelFrame.new(@pane, :text=>'Phase Space')) @lf1 = TkLabelFrame.new(@pane, :text=>'Pendulum Simulation') @@ -237,4 +239,4 @@ class PendulumAnimationDemo end # Start the animation processing -PendulumAnimationDemo.new($pendulum_demo) +PendulumAnimationDemo.new(base_frame) diff --git a/ext/tk/sample/demos-jp/plot.rb b/ext/tk/sample/demos-jp/plot.rb index dbca3e971c..9ff71904cd 100644 --- a/ext/tk/sample/demos-jp/plot.rb +++ b/ext/tk/sample/demos-jp/plot.rb @@ -16,14 +16,16 @@ $plot_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($plot_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -TkLabel.new($plot_demo, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left', +TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left', 'text'=>"¤³¤Î¥¦¥£¥ó¥É¥¦¤Ï´Êñ¤Ê2¼¡¸µ¤Î¥×¥í¥Ã¥È¤ò´Þ¤ó¤À¥­¥ã¥ó¥Ð¥¹ widget¤Ç¤¹¡£É½¼¨¤µ¤ì¤¿ÅÀ¤ò¥Þ¥¦¥¹¥Ü¥¿¥ó1¤Ç¥É¥é¥Ã¥°¤·¤Æ¥Ç¡¼¥¿¤ò¤¤¤¸¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£"){ pack('side'=>'top') } # frame À¸À® -$plot_buttons = TkFrame.new($plot_demo) {|frame| +$plot_buttons = TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -49,7 +51,7 @@ $plot_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') end # canvas ÀßÄê -$plot_canvas = TkCanvas.new($plot_demo,'relief'=>'raised','width'=>450,'height'=>300) +$plot_canvas = TkCanvas.new(base_frame,'relief'=>'raised','width'=>450,'height'=>300) $plot_canvas.pack('side'=>'top', 'fill'=>'x') # plot À¸À® diff --git a/ext/tk/sample/demos-jp/puzzle.rb b/ext/tk/sample/demos-jp/puzzle.rb index 6a3c8c8ef6..2febc2c55a 100644 --- a/ext/tk/sample/demos-jp/puzzle.rb +++ b/ext/tk/sample/demos-jp/puzzle.rb @@ -16,8 +16,10 @@ $puzzle_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($puzzle_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -msg = TkLabel.new($puzzle_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -26,7 +28,7 @@ msg = TkLabel.new($puzzle_demo) { msg.pack('side'=>'top') # frame À¸À® -TkFrame.new($puzzle_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -51,18 +53,27 @@ TkFrame.new($puzzle_demo) {|frame| # begin if Tk.windowingsystem() == 'aqua' - frameSize = 160 + frameWidth = 168 + frameHeight = 168 + elsif Tk.default_widget_set == :Ttk + frameWidth = 148 + frameHeight = 124 else - frameSize = 120 + frameWidth = 120 + frameHeight = 120 end rescue - frameSize = 120 + frameWidth = 120 + frameHeight = 120 end + +# depend_on_button_width = true +depend_on_button_width = false -s = TkScrollbar.new($puzzle_demo) -base = TkFrame.new($puzzle_demo) { - width frameSize - height frameSize +s = TkScrollbar.new(base_frame) +base = TkFrame.new(base_frame) { + width frameWidth + height frameHeight borderwidth 2 relief 'sunken' bg s['troughcolor'] @@ -89,6 +100,9 @@ order = [3,1,6,2,5,7,15,13,4,11,8,9,14,10,12] text num highlightthickness 0 command def_puzzleswitch_proc(w, num) + if depend_on_button_width && (w.winfo_reqwidth * 4 > base.width) + base.width = w.winfo_reqwidth * 4 + end }.place('relx'=>$xpos[num], 'rely'=>$ypos[num], 'relwidth'=>0.25, 'relheight'=>0.25) } diff --git a/ext/tk/sample/demos-jp/radio.rb b/ext/tk/sample/demos-jp/radio.rb index 3a11c394a3..a61ad46d9b 100644 --- a/ext/tk/sample/demos-jp/radio.rb +++ b/ext/tk/sample/demos-jp/radio.rb @@ -16,8 +16,10 @@ $radio_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($radio_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -msg = TkLabel.new($radio_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -30,7 +32,7 @@ size = TkVariable.new color = TkVariable.new # frame À¸À® -TkFrame.new($radio_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -50,14 +52,14 @@ TkFrame.new($radio_demo) {|frame| TkButton.new(frame) { text 'ÊÑ¿ô»²¾È' command proc{ - showVars($radio_demo, ['size', size], ['color', color]) + showVars(base_frame, ['size', size], ['color', color]) } }.pack('side'=>'left', 'expand'=>'yes') }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # frame À¸À® -f_left = TkFrame.new($radio_demo) -f_right = TkFrame.new($radio_demo) +f_left = TkFrame.new(base_frame) +f_right = TkFrame.new(base_frame) f_left.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c') f_right.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c') diff --git a/ext/tk/sample/demos-jp/radio2.rb b/ext/tk/sample/demos-jp/radio2.rb index b89520cdc5..cf53e3e485 100644 --- a/ext/tk/sample/demos-jp/radio2.rb +++ b/ext/tk/sample/demos-jp/radio2.rb @@ -21,8 +21,10 @@ $radio2_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($radio2_demo).pack(:fill=>:both, :expand=>true) + # label -msg = TkLabel.new($radio2_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '5i' justify 'left' @@ -36,7 +38,7 @@ color = TkVariable.new align = TkVariable.new # frame -TkFrame.new($radio2_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -56,18 +58,18 @@ TkFrame.new($radio2_demo) {|frame| TkButton.new(frame) { text 'ÊÑ¿ô»²¾È' command proc{ - showVars($radio2_demo, + showVars(base_frame, ['size', size], ['color', color], ['compound', align]) } }.pack('side'=>'left', 'expand'=>'yes') }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # frame -f_left = TkLabelFrame.new($radio2_demo, 'text'=>'ʸ»ú¥µ¥¤¥º', +f_left = TkLabelFrame.new(base_frame, 'text'=>'ʸ»ú¥µ¥¤¥º', 'pady'=>2, 'padx'=>2) -f_mid = TkLabelFrame.new($radio2_demo, 'text'=>'¿§', +f_mid = TkLabelFrame.new(base_frame, 'text'=>'¿§', 'pady'=>2, 'padx'=>2) -f_right = TkLabelFrame.new($radio2_demo, 'text'=>'¥Ó¥Ã¥È¥Þ¥Ã¥×ÇÛÃÖ', +f_right = TkLabelFrame.new(base_frame, 'text'=>'¥Ó¥Ã¥È¥Þ¥Ã¥×ÇÛÃÖ', 'pady'=>2, 'padx'=>2) f_left.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c') f_mid.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c') @@ -93,7 +95,8 @@ f_right.pack('side'=>'left', 'expand'=>'yes', 'padx'=>'.5c', 'pady'=>'.5c') }.pack('side'=>'top', 'pady'=>2, 'fill'=>'x') } -label = TkLabel.new(f_right, 'text'=>'¥é¥Ù¥ë', 'bitmap'=>'questhead', +# label = TkLabel.new(f_right, 'text'=>'¥é¥Ù¥ë', 'bitmap'=>'questhead', +label = Tk::Label.new(f_right, 'text'=>'¥é¥Ù¥ë', 'bitmap'=>'questhead', 'compound'=>'left') label.configure('width'=>TkWinfo.reqwidth(label), 'compound'=>'top') label.height(TkWinfo.reqheight(label)) diff --git a/ext/tk/sample/demos-jp/radio3.rb b/ext/tk/sample/demos-jp/radio3.rb index a223a19bc2..4bbc1b31f5 100644 --- a/ext/tk/sample/demos-jp/radio3.rb +++ b/ext/tk/sample/demos-jp/radio3.rb @@ -21,8 +21,10 @@ $radio3_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($radio3_demo).pack(:fill=>:both, :expand=>true) + # label -msg = TkLabel.new($radio3_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '5i' justify 'left' @@ -36,14 +38,14 @@ color = TkVariable.new align = TkVariable.new # frame -TkFrame.new($radio3_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkGrid(TkFrame.new(frame, :height=>2, :relief=>:sunken, :bd=>2), :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) TkGrid('x', TkButton.new(frame, :text=>'ÊÑ¿ô»²¾È', :image=>$image['view'], :compound=>:left, :command=>proc{ - showVars($radio3_demo, ['size', size], + showVars(base_frame, ['size', size], ['color', color], ['compound', align]) }), TkButton.new(frame, :text=>'¥³¡¼¥É»²¾È', @@ -63,17 +65,17 @@ TkFrame.new($radio3_demo) {|frame| } # frame -f_left = TkLabelFrame.new($radio3_demo, 'text'=>'ʸ»ú¥µ¥¤¥º', +f_left = TkLabelFrame.new(base_frame, 'text'=>'ʸ»ú¥µ¥¤¥º', 'pady'=>2, 'padx'=>2) -f_mid = TkLabelFrame.new($radio3_demo, 'text'=>'¿§', +f_mid = TkLabelFrame.new(base_frame, 'text'=>'¿§', 'pady'=>2, 'padx'=>2) -f_right = TkLabelFrame.new($radio3_demo, 'text'=>'¥Ó¥Ã¥È¥Þ¥Ã¥×ÇÛÃÖ', +f_right = TkLabelFrame.new(base_frame, 'text'=>'¥Ó¥Ã¥È¥Þ¥Ã¥×ÇÛÃÖ', 'pady'=>2, 'padx'=>2) f_left .grid('column'=>0, 'row'=>1, 'pady'=>'.5c', 'padx'=>'.5c', 'rowspan'=>2) f_mid .grid('column'=>1, 'row'=>1, 'pady'=>'.5c', 'padx'=>'.5c', 'rowspan'=>2) f_right.grid('column'=>2, 'row'=>1, 'pady'=>'.5c', 'padx'=>'.5c') -TkButton.new($radio3_demo, 'text'=>'¥È¥é¥¤¥¹¥Æ¡¼¥È', +TkButton.new(base_frame, 'text'=>'¥È¥é¥¤¥¹¥Æ¡¼¥È', 'command'=>proc{size.value = 'multi'; color.value = 'multi'}){ grid('column'=>2, 'row'=>2, 'pady'=>'.5c', 'padx'=>'.5c') } @@ -101,7 +103,8 @@ TkButton.new($radio3_demo, 'text'=>' }.pack('side'=>'top', 'pady'=>2, 'fill'=>'x') } -label = TkLabel.new(f_right, 'text'=>'¥é¥Ù¥ë', 'bitmap'=>'questhead', +# label = TkLabel.new(f_right, 'text'=>'¥é¥Ù¥ë', 'bitmap'=>'questhead', +label = Tk::Label.new(f_right, 'text'=>'¥é¥Ù¥ë', 'bitmap'=>'questhead', 'compound'=>'left') label.configure('width'=>TkWinfo.reqwidth(label), 'compound'=>'top') label.height(TkWinfo.reqheight(label)) diff --git a/ext/tk/sample/demos-jp/ruler.rb b/ext/tk/sample/demos-jp/ruler.rb index c913e247d1..d6bc9e76d1 100644 --- a/ext/tk/sample/demos-jp/ruler.rb +++ b/ext/tk/sample/demos-jp/ruler.rb @@ -29,14 +29,16 @@ $ruler_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($ruler_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -TkLabel.new($ruler_demo, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left', +TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left', 'text'=>"¤³¤Î¥­¥ã¥ó¥Ð¥¹widget¤Ï¥ë¡¼¥é¡¼¤ÎÌÏ·¿¤Ç¤¹¡£¥ë¡¼¥é¡¼¤Î±¦¤Ë¤¢¤ë¤Î¤Ï¥¿¥Ö¥¹¥È¥Ã¥×¤Î°æ¸Í¤Ç¡¢¤³¤³¤«¤é°ú¤ÃÄ¥¤Ã¤Æ¤¯¤ë¤³¤È¤Ë¤è¤Ã¤Æ¥¿¥Ö¥¹¥È¥Ã¥×¤òºî¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¤Þ¤¿¡¢¤¹¤Ç¤Ë¤¢¤ë¥¿¥Ö¥¹¥È¥Ã¥×¤òÆ°¤«¤¹¤³¤È¤â¤Ç¤­¤Þ¤¹¡£¥¿¥Ö¥¹¥È¥Ã¥×¤ò¾åÊý¤Þ¤¿¤Ï²¼Êý¤Ë¤«¤¹¤ì¤Æɽ¼¨¤µ¤ì¤ë¤Þ¤Ç¥É¥é¥Ã¥°¤¹¤ë¤È¡¢¥Þ¥¦¥¹¥Ü¥¿¥ó¤òÎ¥¤·¤¿»þ¤Ë¤½¤Î¥¿¥Ö¥¹¥È¥Ã¥×¤Ï¾Ã¤¨¤Þ¤¹¡£"){ pack('side'=>'top') } # frame À¸À® -$ruler_buttons = TkFrame.new($ruler_demo) {|frame| +$ruler_buttons = TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -55,7 +57,7 @@ $ruler_buttons = TkFrame.new($ruler_demo) {|frame| $ruler_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # canvas ÀßÄê -$ruler_canvas = TkCanvas.new($ruler_demo, 'width'=>'14.8c', 'height'=>'2.5c') +$ruler_canvas = TkCanvas.new(base_frame, 'width'=>'14.8c', 'height'=>'2.5c') $ruler_canvas.pack('side'=>'top', 'fill'=>'x') # ÃÍÀßÄê diff --git a/ext/tk/sample/demos-jp/sayings.rb b/ext/tk/sample/demos-jp/sayings.rb index 24b011f5ab..aa24b3a2ad 100644 --- a/ext/tk/sample/demos-jp/sayings.rb +++ b/ext/tk/sample/demos-jp/sayings.rb @@ -16,8 +16,10 @@ $sayings_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($sayings_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -msg = TkLabel.new($sayings_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -26,7 +28,7 @@ msg = TkLabel.new($sayings_demo) { msg.pack('side'=>'top') # frame À¸À® -TkFrame.new($sayings_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -46,7 +48,7 @@ TkFrame.new($sayings_demo) {|frame| # frame À¸À® sayings_lbox = nil -TkFrame.new($sayings_demo, 'borderwidth'=>10) {|w| +TkFrame.new(base_frame, 'borderwidth'=>10) {|w| sv = TkScrollbar.new(w) sh = TkScrollbar.new(w, 'orient'=>'horizontal') sayings_lbox = TkListbox.new(w) { diff --git a/ext/tk/sample/demos-jp/search.rb b/ext/tk/sample/demos-jp/search.rb index d3692e2455..9838ff5d19 100644 --- a/ext/tk/sample/demos-jp/search.rb +++ b/ext/tk/sample/demos-jp/search.rb @@ -75,8 +75,10 @@ $search_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($search_demo).pack(:fill=>:both, :expand=>true) + # frame À¸À® -$search_buttons = TkFrame.new($search_demo) {|frame| +$search_buttons = TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -95,7 +97,7 @@ $search_buttons = TkFrame.new($search_demo) {|frame| $search_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # frame À¸À® -TkFrame.new($search_demo) {|f| +TkFrame.new(base_frame) {|f| TkLabel.new(f, 'text'=>'¥Õ¥¡¥¤¥ë̾:', 'width'=>13, 'anchor'=>'w').pack('side'=>'left') $search_fileName = TkVariable.new @@ -112,7 +114,7 @@ TkFrame.new($search_demo) {|f| .pack('side'=>'left', 'pady'=>5, 'padx'=>10) }.pack('side'=>'top', 'fill'=>'x') -TkFrame.new($search_demo) {|f| +TkFrame.new(base_frame) {|f| TkLabel.new(f, 'text'=>'¸¡º÷ʸ»úÎó:', 'width'=>13, 'anchor'=>'w').pack('side'=>'left') $search_searchString = TkVariable.new @@ -130,9 +132,9 @@ TkFrame.new($search_demo) {|f| } }.pack('side'=>'top', 'fill'=>'x') -$search_text = TkText.new($search_demo, 'setgrid'=>true) {|t| +$search_text = TkText.new(base_frame, 'setgrid'=>true) {|t| $search_Tag = TkTextTag.new(t) - TkScrollbar.new($search_demo, 'command'=>proc{|*args| t.yview(*args)}) {|sc| + TkScrollbar.new(base_frame, 'command'=>proc{|*args| t.yview(*args)}) {|sc| t.yscrollcommand(proc{|first,last| sc.set first,last}) pack('side'=>'right', 'fill'=>'y') } diff --git a/ext/tk/sample/demos-jp/spin.rb b/ext/tk/sample/demos-jp/spin.rb index b8eb99c4ed..8d4e33cda0 100644 --- a/ext/tk/sample/demos-jp/spin.rb +++ b/ext/tk/sample/demos-jp/spin.rb @@ -17,10 +17,12 @@ $spin_demo = TkToplevel.new {|w| positionWindow(w) } -TkLabel.new($spin_demo, +base_frame = TkFrame.new($spin_demo).pack(:fill=>:both, :expand=>true) + +TkLabel.new(base_frame, :font=>$font, :wraplength=>'5i', :justify=>:left, :text=><:top) -²¼¤Ë¤Ï£³¼ïÎà¤Î¥¹¥Ô¥ó¥Ü¥Ã¥¯¥¹¤¬É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡£\ +²¼¤Ë¤Ï£³¼ïÎà¤Î¥¹¥Ô¥ó¥Ü¥Ã¥¯¥¹¤¬É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡£ ¤½¤ì¤¾¤ì¡¢¥Þ¥¦¥¹¤ÇÁªÂò¤·¤Æʸ»ú¤òÆþÎϤ¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£ ÊÔ½¸Áàºî¤È¤·¤Æ¤Ï¡¢Emacs ·Á¼°¤Î¿¤¯¤Ë²Ã¤¨¤Æ¡¢°ìÈÌŪ¤Ê Motif ·Á¼°¤Î¥­¡¼Áàºî¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤Þ¤¹¡£¤¿¤È¤¨¤Ð¡¢ @@ -40,7 +42,7 @@ Backspace ¤òÁȤ߹ç¤ï¤»¤Æ»î¤¹¤è¤¦¤Ë¤·¤Æ¤¯¤À¤µ¤¤¡£ EOL -TkFrame.new($spin_demo){|f| +TkFrame.new(base_frame){|f| pack(:side=>:bottom, :fill=>:x, :pady=>'2m') TkButton.new(f, :text=>'ÊĤ¸¤ë', :width=>15, :command=>proc{ @@ -59,11 +61,11 @@ australianCities = [ ] [ - TkSpinbox.new($spin_demo, :from=>1, :to=>10, :width=>10, :validate=>:key, + TkSpinbox.new(base_frame, :from=>1, :to=>10, :width=>10, :validate=>:key, :validatecommand=>[ proc{|s| s == '' || /^[+-]?\d+$/ =~ s }, '%P' ]), - TkSpinbox.new($spin_demo, :from=>0, :to=>3, :increment=>0.5, + TkSpinbox.new(base_frame, :from=>0, :to=>3, :increment=>0.5, :format=>'%05.2f', :width=>10), - TkSpinbox.new($spin_demo, :values=>australianCities, :width=>10) + TkSpinbox.new(base_frame, :values=>australianCities, :width=>10) ].each{|sbox| sbox.pack(:side=>:top, :pady=>5, :padx=>10)} diff --git a/ext/tk/sample/demos-jp/states.rb b/ext/tk/sample/demos-jp/states.rb index 3c58711bd1..5e242b7c38 100644 --- a/ext/tk/sample/demos-jp/states.rb +++ b/ext/tk/sample/demos-jp/states.rb @@ -16,8 +16,10 @@ $states_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($states_demo).pack(:fill=>:both, :expand=>true) + # label À¸À® -msg = TkLabel.new($states_demo) { +msg = TkLabel.new(base_frame) { font $font wraplength '4i' justify 'left' @@ -26,7 +28,7 @@ msg = TkLabel.new($states_demo) { msg.pack('side'=>'top') # frame À¸À® -TkFrame.new($states_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -46,7 +48,7 @@ TkFrame.new($states_demo) {|frame| # frame À¸À® states_lbox = nil -TkFrame.new($states_demo, 'borderwidth'=>'.5c') {|w| +TkFrame.new(base_frame, 'borderwidth'=>'.5c') {|w| s = TkScrollbar.new(w) states_lbox = TkListbox.new(w) { setgrid 1 diff --git a/ext/tk/sample/demos-jp/style.rb b/ext/tk/sample/demos-jp/style.rb index c8c7850156..66b6de0251 100644 --- a/ext/tk/sample/demos-jp/style.rb +++ b/ext/tk/sample/demos-jp/style.rb @@ -17,9 +17,10 @@ $style_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($style_demo).pack(:fill=>:both, :expand=>true) # frame À¸À® -TkFrame.new($style_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -38,14 +39,14 @@ TkFrame.new($style_demo) {|frame| # text À¸À® -txt = TkText.new($style_demo){|t| +txt = TkText.new(base_frame){|t| # À¸À® setgrid 'true' #width 70 #height 32 wrap 'word' font $font - TkScrollbar.new($style_demo) {|s| + TkScrollbar.new(base_frame) {|s| pack('side'=>'right', 'fill'=>'y') command proc{|*args| t.yview(*args)} t.yscrollcommand proc{|first,last| s.set first,last} @@ -65,7 +66,7 @@ txt = TkText.new($style_demo){|t| style_tag_bold = TkTextTag.new(t, 'font'=>[family, 12, :bold, :italic]) style_tag_big = TkTextTag.new(t, 'font'=>[family, 14, :bold]) style_tag_verybig = TkTextTag.new(t, 'font'=>['Helvetica', 24, :bold]) - style_tag_small = TkTextTag.new(t, 'font'=>['Times 8 bold']) + style_tag_small = TkTextTag.new(t, 'font'=>'Times 8 bold') end ### # case($tk_version) diff --git a/ext/tk/sample/demos-jp/text.rb b/ext/tk/sample/demos-jp/text.rb index 25e0e64e9a..0ae480eb00 100644 --- a/ext/tk/sample/demos-jp/text.rb +++ b/ext/tk/sample/demos-jp/text.rb @@ -16,6 +16,8 @@ $text_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($text_demo).pack(:fill=>:both, :expand=>true) + # version check if ((Tk::TK_VERSION.split('.').collect{|n| n.to_i} <=> [8,4]) < 0) undo_support = false @@ -24,7 +26,7 @@ else end # frame À¸À® -TkFrame.new($text_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -42,13 +44,13 @@ TkFrame.new($text_demo) {|frame| }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # text À¸À® -TkText.new($text_demo){|t| +TkText.new(base_frame){|t| # À¸À® relief 'sunken' bd 2 setgrid 1 height 30 - TkScrollbar.new($text_demo) {|s| + TkScrollbar.new(base_frame) {|s| pack('side'=>'right', 'fill'=>'y') command proc{|*args| t.yview(*args)} t.yscrollcommand proc{|first,last| s.set first,last} diff --git a/ext/tk/sample/demos-jp/textpeer.rb b/ext/tk/sample/demos-jp/textpeer.rb index 9b2b57a698..4967a99c92 100644 --- a/ext/tk/sample/demos-jp/textpeer.rb +++ b/ext/tk/sample/demos-jp/textpeer.rb @@ -16,10 +16,12 @@ $textpeer_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($textpeer_demo).pack(:fill=>:both, :expand=>true) + count = [0] ## Define a widget that we peer from; it won't ever actually be shown though -first = TkText.new($textpeer_demo, :widgetname=>"text#{count[0] += 1}") +first = TkText.new(base_frame, :widgetname=>"text#{count[0] += 1}") first.insert :end,"¤³¤Î¥Ç¥â¤Ï°ì¤Ä¤ÎÁȤòÀ®¤·¤¿¥Æ¥­¥¹¥È¥¦¥£¥¸¥§¥Ã¥È¤ò¼¨¤·¤Þ¤¹¡£" first.insert :end,"¤½¤ì¤é¤Î¥Æ¥­¥¹¥È¥¦¥£¥¸¥§¥Ã¥È¤ÏÂÐÅù(¥Ô¥¢;peer)¤Î´Ø·¸¤Ë" first.insert :end,"¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£" @@ -32,6 +34,8 @@ first.insert :end," first.insert :end,"¤Þ¤¿¡Ö¥Ô¥¢(peer)¤Î¾Ãµî¡×¥Ü¥¿¥ó¤ò»È¤¨¤Ð¡¢" first.insert :end,"ÆÃÄê¤Î¥Ô¥¢¥¦¥£¥¸¥§¥Ã¥È¤ò¾Ãµî¤¹¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£" +Tk.update_idletasks ## for 'first' widget + ## Procedures to make and kill clones; most of this is just so that the demo ## looks nice... def makeClone(count, win, txt) @@ -58,12 +62,12 @@ def killClone(win, cnt) end ## Now set up the GUI -makeClone(count, $textpeer_demo, first) -makeClone(count, $textpeer_demo, first) +makeClone(count, base_frame, first) +makeClone(count, base_frame, first) first.destroy ## See Code / Dismiss buttons -TkFrame.new($textpeer_demo){|f| +TkFrame.new(base_frame){|f| TkButton.new(f, :text=>'ÊĤ¸¤ë', :width=>15, :command=>proc{ $textpeer_demo.destroy $textpeer_demo = nil @@ -75,4 +79,4 @@ TkFrame.new($textpeer_demo){|f| TkGrid.configure(f, '-', '-', :sticky=>'ew', :row=>5000) } -TkGrid.columnconfigure($textpeer_demo, 0, :weight=>1) +TkGrid.columnconfigure(base_frame, 0, :weight=>1) diff --git a/ext/tk/sample/demos-jp/toolbar.rb b/ext/tk/sample/demos-jp/toolbar.rb new file mode 100644 index 0000000000..9cb3834c34 --- /dev/null +++ b/ext/tk/sample/demos-jp/toolbar.rb @@ -0,0 +1,136 @@ +# -*- coding: euc-jp -*- +# +# toolbar.rb -- +# +# This demonstration script creates a toolbar that can be torn off. +# +# based on "Id: toolbar.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp" + +if defined?($toolbar_demo) && $toolbar_demo + $toolbar_demo.destroy + $toolbar_demo = nil +end + +$toolbar_demo = TkToplevel.new {|w| + title("Ttk Menu Buttons") + iconname("toolbar") + positionWindow(w) +} + +base_frame = Ttk::Frame.new($toolbar_demo).pack(:fill=>:both, :expand=>true) + +if Tk.windowingsystem != 'aqua' + msg = Ttk::Label.new(base_frame, :wraplength=>'4i', :text=><'4i', :text=><'toolbar') # ¥¦¥£¥ó¥É¥¦¥¿¥¤¥È¥ëʸ»úÎó¤È¤¹¤ë¤¿¤á¤Ë¡¤¥¦¥£¥¸¥§¥Ã¥È̾¤òÌÀ¼¨¤·¤Æ¤¤¤Þ¤¹¡¥ +sep = Ttk::Separator.new(base_frame) +to_base = Ttk::Frame.new(tbar_base, :cursor=>'fleur') +if Tk.windowingsystem != 'aqua' + to = Ttk::Separator.new(to_base, :orient=>:vertical) + to2 = Ttk::Separator.new(to_base, :orient=>:vertical) + to.pack(:fill=>:y, :expand=>true, :padx=>2, :side=>:left) + to2.pack(:fill=>:y, :expand=>true, :side=>:left) +end + +contents = Ttk::Frame.new(tbar_base) +Tk.grid(to_base, contents, :sticky=>'nsew') +tbar_base.grid_columnconfigure(contents, :weight=>1) +contents.grid_columnconfigure(1000, :weight=>1) + +if Tk.windowingsystem != 'aqua' + ## Bindings so that the toolbar can be torn off and reattached + to_base.bind('B1-Motion', '%X %Y'){|x, y| tbar_base.tearoff(to_base, x, y)} + to. bind('B1-Motion', '%X %Y'){|x, y| tbar_base.tearoff(to_base, x, y)} + to2. bind('B1-Motion', '%X %Y'){|x, y| tbar_base.tearoff(to_base, x, y)} + def tbar_base.tearoff(w, x, y) + on_win = TkWinfo.containing(x, y) + return unless (on_win && on_win.path =~ /^#{@path}(\.|$)/) + self.grid_remove + w.grid_remove + self.wm_manage + # self.wm_title('Toolbar') # ¤â¤·¥¦¥£¥¸¥§¥Ã¥È̾¤ò¥¦¥£¥ó¥É¥¦¥¿¥¤¥È¥ë¤Ë¤·¤¿¤¯¤Ê¤¤¤Ê¤é¡¤¤³¤³¤ÇÀßÄꤷ¤Æ¤¯¤À¤µ¤¤ + self.wm_protocol('WM_DELETE_WINDOW'){ self.untearoff(self) } + end + def tbar_base.untearoff(w) + self.wm_forget + w.grid + self.grid + end +end + +## Some content for the rest of the toplevel +text = TkText.new(base_frame, :width=>40, :height=>10) + +## Toolbar contents +tb_btn = Ttk::Button.new(tbar_base, :text=>'¥Ü¥¿¥ó', :style=>'Toolbutton', + :command=>proc{ + text.insert(:end, "¥Ü¥¿¥ó¤¬²¡¤µ¤ì¤Þ¤·¤¿¡¥\n") + }) +tb_chk = Ttk::Checkbutton.new(tbar_base, :text=>'¥Á¥§¥Ã¥¯¥Ü¥¿¥ó', + :style=>'Toolbutton', + :variable=>(check = TkVariable.new), + :command=>proc{ + text.insert(:end, "¥Á¥§¥Ã¥¯¥Ü¥¿¥ó¤ÎÃͤÏ#{check.value}¤Ç¤¹¡¥\n") + }) +tb_mbtn = Ttk::Menubutton.new(tbar_base, :text=>'¥á¥Ë¥å¡¼') +tb_combo = Ttk::Combobox.new(tbar_base, :value=>TkFont.families, + :state=>:readonly) +tb_mbtn.menu(menu = Tk::Menu.new(tb_mbtn)) +menu.add(:command, :label=>'Just', :command=>proc{text.insert(:end, "Just\n")}) +menu.add(:command, :label=>'An', :command=>proc{text.insert(:end, "An\n")}) +menu.add(:command, :label=>'Example', + :command=>proc{text.insert(:end, "Example\n")}) +tb_combo.bind(''){ text.font.family = tb_combo.get } + +## Arrange contents +Tk.grid(tb_btn, tb_chk, tb_mbtn, tb_combo, + :in=>contents, :padx=>2, :sticky=>'ns') +Tk.grid(tbar_base, :sticky=>'ew') +Tk.grid(sep, :sticky=>'ew') +Tk.grid(msg, :sticky=>'ew') +Tk.grid(text, :sticky=>'nsew') +base_frame.grid_rowconfigure(text, :weight=>1) +base_frame.grid_columnconfigure(text, :weight=>1) + +## See Code / Dismiss buttons +Ttk::Frame.new(base_frame) {|frame| + sep = Ttk::Separator.new(frame) + Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) + TkGrid('x', + Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È', + :image=>$image['view'], :compound=>:left, + :command=>proc{showCode 'toolbar'}), + Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë', + :image=>$image['delete'], :compound=>:left, + :command=>proc{ + $toolbar_demo.destroy + $toolbar_demo = nil + }), + :padx=>4, :pady=>4) + grid_columnconfigure(0, :weight=>1) + Tk.grid(frame, :sticky=>'ew') +} diff --git a/ext/tk/sample/demos-jp/tree.rb b/ext/tk/sample/demos-jp/tree.rb new file mode 100644 index 0000000000..c3b4191144 --- /dev/null +++ b/ext/tk/sample/demos-jp/tree.rb @@ -0,0 +1,120 @@ +# -*- coding: euc-jp -*- +# +# tree.rb -- +# +# This demonstration script creates a toplevel window containing a Ttk +# tree widget. +# +# based on "Id: tree.tcl,v 1.4 2007/12/13 15:27:07 dgp Exp" + +if defined?($tree_demo) && $tree_demo + $tree_demo.destroy + $tree_demo = nil +end + +$tree_demo = TkToplevel.new {|w| + title("Directory Browser") + iconname("tree") + positionWindow(w) +} + +base_frame = TkFrame.new($tree_demo).pack(:fill=>:both, :expand=>true) + +## Explanatory text +Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', + :justify=>:left, :anchor=>'n', :padding=>[10, 2, 10, 6], + :text=><:x) +Ttk¤È¤Ï¡¤¥Æ¡¼¥Þ»ØÄê²Äǽ¤Ê¿·¤·¤¤¥¦¥£¥¸¥§¥Ã¥È½¸¹ç¤Ç¤¹¡¥\ +¤³¤Î¥µ¥ó¥×¥ë¤Ï¡¤¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤Î¤è¤¦¤Ê³¬ÁØŪ¤Ê¥Ç¡¼¥¿½¸¹ç¤ò\ +»²¾È¤Ç¤­¤ë¤è¤¦¤Ë¤·¤¿Ttk::Treeview¥¦¥£¥¸¥§¥Ã¥È¤ò´Þ¤ó¤Ç¤¤¤Þ¤¹¡¥\ +Ttk::Treeview¥¦¥£¥¸¥§¥Ã¥È¤Ï¡¤ÌÚ¹½Â¤¼«ÂΤÎɽ¼¨¤ò²Äǽ¤Ë¤¹¤ë¤À¤±¤Ç¤Ê¤¯¡¤\ +ÄɲþðÊó(¤³¤Î¥µ¥ó¥×¥ë¤Î¾ì¹ç¤Ï¥Õ¥¡¥¤¥ë¥µ¥¤¥º)¤òɽ¼¨¤¹¤ë¤¿¤á¤Ë\ +Ǥ°Õ¤Î¸Ä¿ô¤ÎÄɲå«¥é¥à¤â°·¤¦¤³¤È¤â¤Ç¤­¤Þ¤¹¡¥\ +¤Þ¤¿¡¤¥«¥é¥à¤Î¥¿¥¤¥È¥ë´Ö¤Î¶èÀÚ¤êÉôʬ¤ò¥É¥é¥Ã¥°¤¹¤ë¤³¤È¤Ç¡¤\ +¥«¥é¥à¤ÎÉý¤òÊѹ¹¤¹¤ë¤³¤È¤â²Äǽ¤Ç¤¹¡¥ +EOL + +## See Code / Dismiss +Ttk::Frame.new(base_frame) {|frame| + sep = Ttk::Separator.new(frame) + Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) + TkGrid('x', + Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È', + :image=>$image['view'], :compound=>:left, + :command=>proc{showCode 'tree'}), + Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë', + :image=>$image['delete'], :compound=>:left, + :command=>proc{ + $tree_demo.destroy + $tree_demo = nil + }), + :padx=>4, :pady=>4) + grid_columnconfigure(0, :weight=>1) + pack(:side=>:bottom, :fill=>:x) +} + +## Code to populate the roots of the tree (can be more than one on Windows) +def populate_roots(tree) + TkComm.simplelist(Tk.tk_call('file', 'volumes')).sort.each{|dir| + populate_tree(tree, tree.insert(nil, :end, :text=>dir, + :values=>[dir, 'directory'])) + } +end + +## Code to populate a node of the tree +def populate_tree(tree, node) + return if tree.get(node, :type) != 'directory' + + path = tree.get(node, :fullpath) + tree.delete(tree.children(node)) + Dir.glob("#{path}/*").sort.each{|f| + type = File.ftype(f) + id = tree.insert(node, :end, + :text=>File.basename(f), :values=>[f, type]).id + if type == 'directory' + ## Make it so that this node is openable + tree.insert(id, 0, :text=>'dummy') + tree.itemconfigure(id, :text=>File.basename(f)) + elsif type == 'file' + size = File.size(f) + if size >= 1024*1024*1024 + size = '%.1f GB' % (size.to_f/1024/1024/1024) + elsif size >= 1024*1024 + size = '%.1f MB' % (size.to_f/1024/1024) + elsif size >= 1024 + size = '%.1f KB' % (size.to_f/1024) + else + size = '%.1f bytes' % (size.to_f/1024) + end + tree.set(id, :size, size) + end + } + + # Stop this code from rerunning on the current node + tree.set(node, :type, 'processed_directory') +end + +## Create the tree and set it up +tree = Ttk::Treeview.new(base_frame, :columns=>%w(fullpath type size), + :displaycolumns=>['size']) +if Tk.windowingsystem != 'aqua' + vsb = tree.yscrollbar(Ttk::Scrollbar.new(base_frame)) + hsb = tree.xscrollbar(Ttk::Scrollbar.new(base_frame)) +else + vsb = tree.yscrollbar(Tk::Scrollbar.new(base_frame)) + hsb = tree.xscrollbar(Tk::Scrollbar.new(base_frame)) +end + +tree.heading_configure('#0', :text=>'Directory Structure') +tree.heading_configure('size', :text=>'File Size') +tree.column_configure('size', :stretch=>0, :width=>70) +populate_roots(tree) +tree.bind('', '%W'){|w| populate_tree(w, w.focus_item)} + +## Arrange the tree and its scrollbars in the toplevel +container = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true) +container.lower +Tk.grid(tree, vsb, :in=>container, :sticky=>'nsew') +Tk.grid(hsb, :in=>container, :sticky=>'nsew') +container.grid_columnconfigure(0, :weight=>1) +container.grid_rowconfigure(0, :weight=>1) diff --git a/ext/tk/sample/demos-jp/ttkbut.rb b/ext/tk/sample/demos-jp/ttkbut.rb new file mode 100644 index 0000000000..4d577120bb --- /dev/null +++ b/ext/tk/sample/demos-jp/ttkbut.rb @@ -0,0 +1,145 @@ +# -*- coding: euc-jp -*- +# +# ttkbut.rb +# +# This demonstration script creates a toplevel window containing several +# simple Ttk widgets, such as labels, labelframes, buttons, checkbuttons and +# radiobuttons. +# +# based on "Id: ttkbut.tcl,v 1.4 2007/12/13 15:27:07 dgp Exp" + +if defined?($ttkbut_demo) && $ttkbut_demo + $ttkbut_demo.destroy + $ttkbut_demo = nil +end + +$ttkbut_demo = TkToplevel.new {|w| + title("Simple Ttk Widgets") + iconname("ttkbut") + positionWindow(w) +} + +base_frame = TkFrame.new($ttkbut_demo).pack(:fill=>:both, :expand=>true) + +Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left, + :text=><:top, :fill=>:x) +Ttk¤È¤Ï¡¤¥Æ¡¼¥Þ»ØÄê²Äǽ¤Ê¿·¤·¤¤¥¦¥£¥¸¥§¥Ã¥È½¸¹ç¤Ç¤¹¡¥\ +º£¡¤¤¢¤Ê¤¿¤¬Ìܤˤ·¤Æ¤¤¤ë¤Î¤ÏTtk¤Î¥Æ¡¼¥Þ²½¥é¥Ù¥ë¤Ç¡¤\ +²¼¤Ë¤ÏTtk¤Î¥é¥Ù¥ë¥Õ¥ì¡¼¥à¤ÎÃæ¤Ë»°¤Ä¤Î¥°¥ë¡¼¥×¤ÎTtk¥¦¥£¥¸¥§¥Ã¥È¤¬\ +ɽ¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡¥ +ºÇ½é¤Î¥°¥ë¡¼¥×¤ÏÁ´¤Æ¥Ü¥¿¥ó¤Ç¤¢¤ê¡¤\ +¤½¤ì¤¾¤ì¥¯¥ê¥Ã¥¯¤¹¤ì¤Ð¸½ºß¤Î¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î¥Æ¡¼¥Þ¤¬ÀßÄꤵ¤ì¤Þ¤¹¡¥ +£²ÈÖÌܤΥ°¥ë¡¼¥×¤Ï»°¤Ä¤Î¥Á¥§¥Ã¥¯¥Ü¥¿¥ó½¸¹ç¤Ç¤¹¡¥\ +³Æ½¸¹ç¤Î´Ö¤Ë¤Ï¡¤¥»¥Ñ¥ì¡¼¥¿¥¦¥£¥¸¥§¥Ã¥È¤¬ÃÖ¤«¤ì¤Æ¤¤¤Þ¤¹¡¥\ +¤Ê¤ª¡ÖÍ­¸ú²½¡×¥Ü¥¿¥ó¤Ï¡¤¤³¤Î¥È¥Ã¥×¥ì¥Ù¥ë¥¦¥£¥¸¥§¥Ã¥ÈÆâ¤Î\ +¾¤Î¤¹¤Ù¤Æ¤Î¥Æ¡¼¥Þ²½¥¦¥£¥¸¥§¥Ã¥È¤Î¾õÂÖ(state)¤¬"disabled"¤«¤É¤¦¤«¤ò\ +¥³¥ó¥È¥í¡¼¥ë¤¹¤ë¤³¤È¤ËÃí°Õ¤·¤Æ¤¯¤À¤µ¤¤¡¥ +£³ÈÖÌܤΥ°¥ë¡¼¥×¤Ï´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥é¥¸¥ª¥Ü¥¿¥ó½¸¹ç¤È¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡¥ +EOL + +## Add buttons for setting the theme +buttons = Ttk::Labelframe.new(base_frame, :text=>'¥Ü¥¿¥ó') +# Ttk::Style.theme_names.each{|theme| +# Ttk::Button.new(buttons, :text=>theme, +# :command=>proc{Ttk::Style.theme_use theme}).pack(:pady=>2) +# } +Ttk.themes.each{|theme| + Ttk::Button.new(buttons, :text=>theme, + :command=>proc{Ttk.set_theme theme}).pack(:pady=>2) +} + +## Helper procedure for the top checkbutton +def setState(root, value, *excepts) + return if excepts.member?(root) + + ## Non-Ttk widgets (e.g. the toplevel) will fail, so make it silent + begin + root.state = value + rescue + end + + ## Recursively invoke on all children of this root that are in the same + ## toplevel widget + root.winfo_children.each{|w| + setState(w, value, *excepts) if w.winfo_toplevel == root.winfo_toplevel + } +end + +## Set up the checkbutton group +checks = Ttk::Labelframe.new(base_frame, :text=>'¥Á¥§¥Ã¥¯¥Ü¥¿¥ó') +enabled = TkVariable.new(true) +e = Ttk::Checkbutton.new(checks, :text=>'Í­¸ú²½', :variable=>enabled, + :command=>proc{ + setState($ttkbut_demo, + ((enabled.bool)? "!disabled" : "disabled"), + e) + }) + +## See ttk_widget(n) for other possible state flags +sep1 = Ttk::Separator.new(checks) +sep2 = Ttk::Separator.new(checks) + +cheese = TkVariable.new +tomato = TkVariable.new +basil = TkVariable.new +oregano = TkVariable.new + +c1 = Ttk::Checkbutton.new(checks, :text=>'¥Á¡¼¥º', :variable=>cheese) +c2 = Ttk::Checkbutton.new(checks, :text=>'¥È¥Þ¥È', :variable=>tomato) +c3 = Ttk::Checkbutton.new(checks, :text=>'¥Ð¥¸¥ë', :variable=>basil) +c4 = Ttk::Checkbutton.new(checks, :text=>'¥ª¥ì¥¬¥Î', :variable=>oregano) + +Tk.pack(e, sep1, c1, c2, sep2, c3, c4, :fill=>:x, :pady=>2) + +## Set up the radiobutton group +radios = Ttk::Labelframe.new(base_frame, :text=>'¥é¥¸¥ª¥Ü¥¿¥ó') + +happyness = TkVariable.new + +r1 = Ttk::Radiobutton.new(radios, :variable=>happyness, + :text=>'Great', :value=>'great') +r2 = Ttk::Radiobutton.new(radios, :variable=>happyness, + :text=>'Good', :value=>'good') +r3 = Ttk::Radiobutton.new(radios, :variable=>happyness, + :text=>'Ok', :value=>'ok') +r4 = Ttk::Radiobutton.new(radios, :variable=>happyness, + :text=>'Poor', :value=>'poor') +r5 = Ttk::Radiobutton.new(radios, :variable=>happyness, + :text=>'Awful', :value=>'awful') + +Tk.pack(r1, r2, r3, r4, r5, :fill=>:x, :padx=>3, :pady=>2) + +## See Code / Dismiss +Ttk::Frame.new(base_frame) {|frame| + sep = Ttk::Separator.new(frame) + Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) + TkGrid('x', + Ttk::Button.new(frame, :text=>'ÊÑ¿ô»²¾È', + :image=>$image['view'], :compound=>:left, + :command=>proc{ + showVars(base_frame, ['Í­¸ú²½', enabled], + ['¥Á¡¼¥º', cheese], ['¥È¥Þ¥È', tomato], + ['¥Ð¥¸¥ë', basil], ['¥ª¥ì¥¬¥Î', oregano], + ['¹¬Ê¡ÅÙ', happyness]) + }), + Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È', + :image=>$image['view'], :compound=>:left, + :command=>proc{showCode 'ttkbut'}), + Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë', + :image=>$image['delete'], :compound=>:left, + :command=>proc{ + tmppath = $ttkbut_demo + $ttkbut_demo = nil + $showVarsWin[tmppath.path] = nil + tmppath.destroy + }), + :padx=>4, :pady=>4) + grid_columnconfigure(0, :weight=>1) + pack(:side=>:bottom, :fill=>:x, :expand=>true) +} + +## Arrange things neatly +f = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true) +f.lower +Tk.grid(buttons, checks, radios, :in=>f, :sticky=>'nwe', :pady=>2, :padx=>3) +f.grid_columnconfigure([0, 1, 2], :weight=>1, :uniform=>:yes) diff --git a/ext/tk/sample/demos-jp/ttkmenu.rb b/ext/tk/sample/demos-jp/ttkmenu.rb new file mode 100644 index 0000000000..d349b42d11 --- /dev/null +++ b/ext/tk/sample/demos-jp/ttkmenu.rb @@ -0,0 +1,91 @@ +# -*- coding: euc-jp -*- +# +# ttkmenu.rb -- +# +# This demonstration script creates a toplevel window containing several Ttk +# menubutton widgets. +# +# based on "Id: ttkmenu.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp" + +if defined?($ttkmenu_demo) && $ttkmenu_demo + $ttkmenu_demo.destroy + $ttkmenu_demo = nil +end + +$ttkmenu_demo = TkToplevel.new {|w| + title("Ttk Menu Buttons") + iconname("ttkmenu") + positionWindow(w) +} + +base_frame = Ttk::Frame.new($ttkmenu_demo).pack(:fill=>:both, :expand=>true) + +Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left, + :text=><:top, :fill=>:x) +Ttk¤È¤Ï¡¤¥Æ¡¼¥Þ»ØÄê²Äǽ¤Ê¿·¤·¤¤¥¦¥£¥¸¥§¥Ã¥È½¸¹ç¤Ç¤¹¡¥\ +¤³¤ì¤Ë¤è¤ê¥Æ¡¼¥Þ¤ËÂбþ¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤Ã¤¿¥¦¥£¥¸¥§¥Ã¥È¤Î¤Ò¤È¤Ä¤Ë\ +¥á¥Ë¥å¡¼¥Ü¥¿¥ó¤¬¤¢¤ê¤Þ¤¹¡¥\ +°Ê²¼¤Ç¤Ï¡¤¥Æ¡¼¥Þ¤ËÂбþ¤·¤¿¥á¥Ë¥å¡¼¥Ü¥¿¥ó¤¬¤¤¤¯¤Ä¤«É½¼¨¤µ¤ì¤Æ¤¤¤Þ¤¹¡¥\ +¤½¤ì¤é¤ò»È¤Ã¤Æ¡¤¸½ºß»ÈÍÑÃæ¤Î¥Æ¡¼¥Þ¤òÊѹ¹¤¹¤ë¤³¤È¤¬²Äǽ¤Ç¤¹¡¥\ +¥Æ¡¼¥Þ¤ÎÁªÂò¤¬¥á¥Ë¥å¡¼¥Ü¥¿¥ó¼«¿È¤Î¸«³Ý¤±¤òÊѲ½¤µ¤»¤ëÍͻҤ䡤\ +Ãæ±û¤Î¥á¥Ë¥å¡¼¥Ü¥¿¥ó¤À¤±¤¬°Û¤Ê¤ë¥¹¥¿¥¤¥ë\ +(¥Ä¡¼¥ë¥Ð¡¼¤Ç¤Î°ìÈÌŪ¤Êɽ¼¨¤ËŬ¤·¤¿¤â¤Î)¤Çɽ¼¨¤µ¤ì¤Æ¤¤¤ëÍͻҤË\ +ÃíÌܤ·¤Æ¤¯¤À¤µ¤¤¡¥\ +¤Ê¤ª¡¤¥á¥Ë¥å¡¼¥Ü¥¿¥ó¤Ë¤Ä¤¤¤Æ¤Ï¥Æ¡¼¥Þ¤ËÂбþ¤·¤¿¥¦¥£¥¸¥§¥Ã¥È¤¬¤¢¤ê¤Þ¤¹¤¬¡¤\ +¥á¥Ë¥å¡¼¤Ë¤Ä¤¤¤Æ¤Ï¥Æ¡¼¥Þ¤ËÂбþ¤·¤¿¥¦¥£¥¸¥§¥Ã¥È¤Ï´Þ¤Þ¤ì¤Æ¤¤¤Þ¤»¤ó¡¥\ +¤½¤ÎÍýͳ¤Ï¡¤É¸½à¤ÎTk¤Î¥á¥Ë¥å¡¼¥¦¥£¥¸¥§¥Ã¥È¤¬\ +¤¹¤Ù¤Æ¤Î¥×¥é¥Ã¥È¥Û¡¼¥à¤Ç½½Ê¬¤ËÎɹ¥¤Ê¸«³Ý¤±¤ÈÁàºîÀ­¤ò»ý¤Ã¤Æ¤¤¤ë¡¤\ +Æäˡ¤Â¿¤¯¤Î´Ä¶­¤Ç¤½¤Î´Ä¶­ËÜÍè¤ÎÁàºîÂηϤȤʤë¤è¤¦¤Ë¼ÂÁõ¤µ¤ì¤Æ¤¤¤ë¤È\ +ȽÃǤµ¤ì¤¿¤³¤È¤Ë¤è¤ê¤Þ¤¹¡¥ +EOL + +Ttk::Separator.new(base_frame).pack(:side=>:top, :fill=>:x) + +## See Code / Dismiss +Ttk::Frame.new($ttkmenu_demo) {|frame| + sep = Ttk::Separator.new(frame) + Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) + TkGrid('x', + Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È', + :image=>$image['view'], :compound=>:left, + :command=>proc{showCode 'ttkmenu'}), + Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë', + :image=>$image['delete'], :compound=>:left, + :command=>proc{ + $ttkmenu_demo.destroy + $ttkmenu_demo = nil + }), + :padx=>4, :pady=>4) + grid_columnconfigure(0, :weight=>1) + pack(:side=>:bottom, :fill=>:x) +} + +b1 = Ttk::Menubutton.new(base_frame,:text=>'¥Æ¡¼¥Þ¤òÁªÂò',:direction=>:above) +b2 = Ttk::Menubutton.new(base_frame,:text=>'¥Æ¡¼¥Þ¤òÁªÂò',:direction=>:left) +b3 = Ttk::Menubutton.new(base_frame,:text=>'¥Æ¡¼¥Þ¤òÁªÂò',:direction=>:right) +b4 = Ttk::Menubutton.new(base_frame,:text=>'¥Æ¡¼¥Þ¤òÁªÂò',:direction=>:flush, + :style=>Ttk::Menubutton.style('Toolbutton')) +b5 = Ttk::Menubutton.new(base_frame,:text=>'¥Æ¡¼¥Þ¤òÁªÂò',:direction=>:below) + +b1.menu(m1 = Tk::Menu.new(b1, :tearoff=>false)) +b2.menu(m2 = Tk::Menu.new(b2, :tearoff=>false)) +b3.menu(m3 = Tk::Menu.new(b3, :tearoff=>false)) +b4.menu(m4 = Tk::Menu.new(b4, :tearoff=>false)) +b5.menu(m5 = Tk::Menu.new(b5, :tearoff=>false)) + +Ttk.themes.each{|theme| + m1.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme}) + m2.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme}) + m3.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme}) + m4.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme}) + m5.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme}) +} + +f = Ttk::Frame.new(base_frame).pack(:fill=>:x) +f1 = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true) +f.lower + +f.grid_anchor(:center) +TkGrid('x', b1, 'x', :in=>f, :padx=>3, :pady=>2) +TkGrid(b2, b4, b3, :in=>f, :padx=>3, :pady=>2) +TkGrid('x', b5, 'x', :in=>f, :padx=>3, :pady=>2) diff --git a/ext/tk/sample/demos-jp/ttknote.rb b/ext/tk/sample/demos-jp/ttknote.rb new file mode 100644 index 0000000000..09cc7960a3 --- /dev/null +++ b/ext/tk/sample/demos-jp/ttknote.rb @@ -0,0 +1,97 @@ +# -*- coding: euc-jp -*- +# +# ttknote.rb -- +# +# This demonstration script creates a toplevel window containing a Ttk +# notebook widget. +# +# based on "Id: ttknote.tcl,v 1.5 2007/12/13 15:27:07 dgp Exp" + +if defined?($ttknote_demo) && $ttknote_demo + $ttknote_demo.destroy + $ttknote_demo = nil +end + +$ttknote_demo = TkToplevel.new {|w| + title("Ttk Notebook Widget") + iconname("ttknote") + positionWindow(w) +} + +## See Code / Dismiss +Ttk::Frame.new($ttknote_demo) {|frame| + sep = Ttk::Separator.new(frame) + Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) + TkGrid('x', + Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È', + :image=>$image['view'], :compound=>:left, + :command=>proc{showCode 'ttknote'}), + Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë', + :image=>$image['delete'], :compound=>:left, + :command=>proc{ + $ttknote_demo.destroy + $ttknote_demo = nil + }), + :padx=>4, :pady=>4) + grid_columnconfigure(0, :weight=>1) + pack(:side=>:bottom, :fill=>:x) +} + +base_frame = Ttk::Frame.new($ttknote_demo).pack(:fill=>:both, :expand=>true) + +## Make the notebook and set up Ctrl+Tab traversal +notebook = Ttk::Notebook.new(base_frame).pack(:fill=>:both, :expand=>true, + :padx=>2, :pady=>3) +notebook.enable_traversal + +## Popuplate the first pane +f_msg = Ttk::Frame.new(notebook) +msg_m = Ttk::Label.new(f_msg, :font=>$font, :wraplength=>'5i', + :justify=>:left, :anchor=>'n', :text=><'¤¹¤Æ¤­¤À¡ª(Neat!)', :underline=>6, + :command=>proc{ + neat.value = '¤¢¤¡¡¤¤½¤Î¤È¤ª¤ê¤µ¡¥¡¥¡¥' + Tk.after_cancel(after_id) if after_id + after_id = Tk.after(500){neat.value = ''} + }) +msg_b.winfo_toplevel.bind('Alt-n'){ msg_b.focus; msg_b.invoke } +msg_l = Ttk::Label.new(f_msg, :textvariable=>neat) +notebook.add(f_msg, :text=>'ÀâÌÀ(Description)', :underline=>3, :padding=>2) +Tk.grid(msg_m, '-', :sticky=>'new', :pady=>2) +Tk.grid(msg_b, msg_l, :pady=>[2, 4], :padx=>20) +msg_b.grid_configure(:sticky=>'e') +msg_l.grid_configure(:sticky=>'w') +f_msg.grid_rowconfigure(1, :weight=>1) +f_msg.grid_columnconfigure([0, 1], :weight=>1, :uniform=>1) + +## Populate the second pane. Note that the content doesn't really matter +f_disabled = Ttk::Frame.new(notebook) +notebook.add(f_disabled, :text=>'̵¸ú²½¤µ¤ì¤¿¥¿¥Ö', :state=>:disabled) + +## Popuplate the third pane +f_editor = Ttk::Frame.new(notebook) +notebook.add(f_editor, :text=>'¥Æ¥­¥¹¥È¥¨¥Ç¥£¥¿(Text Editor)', :underline=>9) +editor_t = Tk::Text.new(f_editor, :width=>40, :height=>10, :wrap=>:char) +if Tk.windowingsystem != 'aqua' + editor_s = editor_t.yscrollbar(Ttk::Scrollbar.new(f_editor)) +else + editor_s = editor_t.yscrollbar(Tk::Scrollbar.new(f_editor)) +end +editor_s.pack(:side=>:right, :fill=>:y, :padx=>[0,2], :pady=>2) +editor_t.pack(:fill=>:both, :expand=>true, :padx=>[2,0], :pady=>2) diff --git a/ext/tk/sample/demos-jp/ttkpane.rb b/ext/tk/sample/demos-jp/ttkpane.rb new file mode 100644 index 0000000000..96670c0e5c --- /dev/null +++ b/ext/tk/sample/demos-jp/ttkpane.rb @@ -0,0 +1,216 @@ +# -*- coding: euc-jp -*- +# +# ttkpane.rb -- +# +# This demonstration script creates a Ttk pane with some content. +# +# based on "Id: ttkpane.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp" + +if defined?($ttkpane_demo) && $ttkpane_demo + $ttkpane_demo.destroy + $ttkpane_demo = nil +end + +$ttkpane_demo = TkToplevel.new {|w| + title("Themed Nested Panes") + iconname("ttkpane") + positionWindow(w) +} + +base_frame = TkFrame.new($ttkpane_demo).pack(:fill=>:both, :expand=>true) + +Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left, + :text=><:top, :fill=>:x) +¤³¤Î¥Ç¥â¤Ï¡¤Ëä¤á¹þ¤ß´Ø·¸¤Ë¤¢¤ë¥Æ¡¼¥ÞÉÕ¤­¥Ú¥¤¥ó¥É¥¦¥£¥ó¥É¥¦¤ò¼¨¤·¤Æ¤¤¤Þ¤¹¡¥\ +¤½¤ì¤¾¤ì¤ÎÂ礭¤µ¤Ï¡¤´Þ¤Þ¤ì¤Æ¤¤¤ë¥Ú¥¤¥ó¤Î´Ö¤Ë¤¢¤ë¥¨¥ê¥¢¤ò¤Ä¤«¤ó¤Ç\ +¶­³¦¤ò¥É¥é¥Ã¥°¤¹¤ë¤³¤È¤ÇÊѹ¹¤Ç¤­¤Þ¤¹¡¥ +EOL + +Ttk::Separator.new(base_frame).pack(:side=>:top, :fill=>:x) + +## See Code / Dismiss +Ttk::Frame.new(base_frame) {|frame| + sep = Ttk::Separator.new(frame) + Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) + TkGrid('x', + Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È', + :image=>$image['view'], :compound=>:left, + :command=>proc{showCode 'ttkpane'}), + Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë', + :image=>$image['delete'], :compound=>:left, + :command=>proc{ + $ttkpane_demo.destroy + $ttkpane_demo = nil + }), + :padx=>4, :pady=>4) + grid_columnconfigure(0, :weight=>1) + pack(:side=>:bottom, :fill=>:x) +} + +frame = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true) + +outer = Ttk::Panedwindow.new(frame, :orient=>:horizontal) +outer.add(in_left = Ttk::Panedwindow.new(outer, :orient=>:vertical)) +outer.add(in_right = Ttk::Panedwindow.new(outer, :orient=>:vertical)) +in_left.add(left_top = Ttk::Labelframe.new(in_left, :text=>'¥Ü¥¿¥ó')) +in_left.add(left_bot = Ttk::Labelframe.new(in_left, :text=>'»þ·×')) +in_right.add(right_top = Ttk::Labelframe.new(in_right, :text=>'¥×¥í¥°¥ì¥¹')) +in_right.add(right_bot = Ttk::Labelframe.new(in_right, :text=>'¥Æ¥­¥¹¥È')) +if Tk.windowingsystem == 'aqua' + [left_top, left_bot, right_top, right_bot].each{|w| w.padding(3) } +end + +# Fill the button pane +Ttk::Button.new(left_top, :text=>'²¡¤·¤Æ¤Í', + :command=>proc{ + Tk.messageBox(:type=>'ok', :icon=>'info', + :message=>'¤¤¤Æ¤Æ¡ª', + :detail=>'That hurt...', :parent=>base_frame, + :title=>'Button Pressed') + }).pack(:padx=>2, :pady=>5) + + +zones_list = [ + [':Europe/Berlin'], + [':America/Argentina/Buenos_Aires', ':America/Buenos_Aires'], + [':Africa/Johannesburg'], + [':Europe/London'], + [':America/Los_Angeles'], + [':Europe/Moscow'], + [':America/New_York'], + [':Asia/Singapore'], + [':Australia/Sydney'], + [':Asia/Tokyo'], +] + +zones = [] + +# Check tzinfo support +if $tk_major_ver > 8 || ($tk_major_ver == 8 && $tk_minor_ver >= 5) + tzinfo = :tcl + + zones_list.each{|list| + list.each{|zone| + begin + # Force a pre-load of all the timezones needed; otherwise can end up + # poor-looking synch problems! + Tk.tk_call('clock', 'format', '0', '-timezone', zone) + rescue RuntimeError + # ignore + else + zones << [zone, zone[%r<[^/:]+$>].tr('_', ' ')] + break + end + } + } + +else + begin + require 'tzinfo' + tzinfo = :tzinfo + rescue Exception + begin + require 'tzfile' + tzinfo = :tzfile + rescue Exception + tzinfo = nil + end + end + + case tzinfo + when :tzinfo + zones_list.each{|list| + list.each{|zone| + begin + tz = TZInfo::Timezone.get(zone[%r<[^:]+$>]) + rescue Exception + # ignore + else + zones << [tz, zone[%r<[^/:]+$>].tr('_', ' ')] + break + end + } + } + + when :tzfile + zones_list.each{|list| + list.each{|zone| + begin + tz = TZFile.create(zone[%r<[^:]+$>]) + rescue Exception + # ignore + else + zones << [tz, zone[%r<[^/:]+$>].tr('_', ' ')] + break + end + } + } + + else + [ -7, -4, -2, -1, 0, +1, +3, +8, +9, +10 ].each{|zone| + zones << [zone, 'UTC%+03d00' % zone] + } + end +end + +time = TkVariable.new_hash + +case tzinfo +when :tcl + update_proc = proc{|now, tz, label| + time[label] = Tk.tk_call('clock', 'format', now.tv_sec, + '-timezone', tz, '-format', '%T') + } +when :tzinfo + update_proc = proc{|now, tz, label| + time[label] = tz.utc_to_local(now).strftime('%H:%M:%S') + } +when :tzfile + update_proc = proc{|now, tz, label| + time[label] = tz.at(now.tv_sec).strftime('%H:%M:%S') + } +else + update_proc = proc{|now, tz, label| + time[label] = (now + (tz * 3600)).strftime('%H:%M:%S') + } +end + +# Fill the clocks pane +zones.each_with_index{|(zone, label), idx| + Ttk::Separator.new(left_bot).pack(:fill=>:x) if idx > 0 + Ttk::Label.new(left_bot, :text=>label, :anchor=>'w').pack(:fill=>:x) + Ttk::Label.new(left_bot, :textvariable=>time.ref(label), + :anchor=>'w').pack(:fill=>:x) +} + +# Timer start +every = proc{ + now = Time.now.utc + zones.each{|zone, label| update_proc.call(now, zone, label) } +} +TkRTTimer.new(1000, -1, every).start(0, every) + +# Fill the progress pane +Ttk::Progressbar.new(right_top, :mode=>:indeterminate).pack(:fill=>:both, :expand=>true).start + +# Fill the text pane +if Tk.windowingsystem != 'aqua' + # The trick with the ttk::frame makes the text widget look like it fits with + # the current Ttk theme despite not being a themed widget itself. It is done + # by styling the frame like an entry, turning off the border in the text + # widget, and putting the text widget in the frame with enough space to allow + # the surrounding border to show through (2 pixels seems to be enough). + f = Ttk::Frame.new(right_bot, :style=>Ttk::Entry) + txt = TkText.new(frame, :wrap=>:word, :width=>30, :borderwidth=>0) + txt.pack(:fill=>:both, :expand=>true, :in=>f, :pady=>2, :padx=>2) + scr = txt.yscrollbar(Ttk::Scrollbar.new(frame)) + scr.pack(:side=>:right, :fill=>:y, :in=>right_bot) + f.pack(:fill=>:both, :expand=>true) + outer.pack(:fill=>:both, :expand=>true) +else + txt = TkText.new(frame, :wrap=>:word, :width=>30, :borderwidth=>0) + scr = txt.yscrollbar(TkScrollbar.new(frame)) + scr.pack(:side=>:right, :fill=>:y, :in=>right_bot) + txt.pack(:fill=>:both, :expand=>true, :in=>right_bot) + outer.pack(:fill=>:both, :expand=>true, :padx=>10, :pady=>[6, 10]) +end diff --git a/ext/tk/sample/demos-jp/ttkprogress.rb b/ext/tk/sample/demos-jp/ttkprogress.rb new file mode 100644 index 0000000000..43a9cbcd7e --- /dev/null +++ b/ext/tk/sample/demos-jp/ttkprogress.rb @@ -0,0 +1,71 @@ +# -*- coding: euc-jp -*- +# +# ttkprogress.rb -- +# +# This demonstration script creates several progress bar widgets. +# +# based on "Id: ttkprogress.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp" + +if defined?($ttkprogress_demo) && $ttkprogress_demo + $ttkprogress_demo.destroy + $ttkprogress_demo = nil +end + +$ttkprogress_demo = TkToplevel.new {|w| + title("Progress Bar Demonstration") + iconname("ttkprogress") + positionWindow(w) +} + +base_frame = TkFrame.new($ttkprogress_demo).pack(:fill=>:both, :expand=>true) + +Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left, + :text=><:top, :fill=>:x) +²¼¤Ë¤¢¤ë¤Î¤ÏÆó¤Ä¤Î¥×¥í¥°¥ì¥¹¥Ð¡¼¤Ç¤¹¡¥\ +¾å¤Î¤â¤Î¤Ï"determinate"¥¿¥¤¥×¤Î¥×¥í¥°¥ì¥¹¥Ð¡¼¤Ç¡¤\ +Î㤨¤Ð¥×¥í¥°¥é¥à¤¬Í¿¤¨¤é¤ì¤¿¥¿¥¹¥¯¤ò½ªÎ»¤¹¤ë¤Þ¤Ç¤Ë¤É¤Î¤¯¤é¤¤¤«¤«¤ë¤«¤ò\ +¼¨¤¹¤È¤­¤Ê¤É¤ËÍѤ¤¤é¤ì¤Þ¤¹¡¥\ +²¼¤Î¤â¤Î¤Ï"indeterminate"¥¿¥¤¥×¤Î¥×¥í¥°¥ì¥¹¥Ð¡¼¤Ç¡¤\ +Î㤨¤Ð¥×¥í¥°¥é¥à¤¬¼Â¹ÔÃæ(busy)¤Ç¤¢¤ë¤â¤Î¤Î\ +½ªÎ»¤Þ¤Ç¤Ë¤É¤ì¤¯¤é¤¤¤«¤«¤ë¤«¤Ïʬ¤«¤é¤Ê¤¤¤È¤¤¤¦¾õÂÖ¤ò\ +¼¨¤¹¤È¤­¤Ê¤É¤ËÍѤ¤¤é¤ì¤Þ¤¹¡¥\ +¤¤¤º¤ì¤Î¥×¥í¥°¥ì¥¹¥Ð¡¼¤â¡¤¤¹¤°²¼¤Ë¤¢¤ë¥Ü¥¿¥ó¤ò»È¤¦¤³¤È¤Ç\ +¼«Æ°¥¢¥Ë¥á¡¼¥·¥ç¥ó¥â¡¼¥É¤ÎON/OFF¤òÀÚÂؤ¨¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡¥ +EOL + +## See Code / Dismiss buttons +Ttk::Frame.new(base_frame) {|frame| + sep = Ttk::Separator.new(frame) + Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) + TkGrid('x', + Ttk::Button.new(frame, :text=>'¥³¡¼¥É»²¾È', + :image=>$image['view'], :compound=>:left, + :command=>proc{showCode 'ttkprogress'}), + Ttk::Button.new(frame, :text=>'ÊĤ¸¤ë', + :image=>$image['delete'], :compound=>:left, + :command=>proc{ + $ttkprogress_demo.destroy + $ttkprogress_demo = nil + }), + :padx=>4, :pady=>4) + grid_columnconfigure(0, :weight=>1) + pack(:side=>:bottom, :fill=>:x) +} + +frame = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true) + +p1 = Ttk::Progressbar.new(frame, :mode=>:determinate) +p2 = Ttk::Progressbar.new(frame, :mode=>:indeterminate) + +start = Ttk::Button.new(frame, :text=>'Start Progress', + :command=>proc{ p1.start; p2.start }) +stop = Ttk::Button.new(frame, :text=>'Stop Progress', + :command=>proc{ p1.stop; p2.stop }) + +Tk.grid(p1, '-', :pady=>5, :padx=>10) +Tk.grid(p2, '-', :pady=>5, :padx=>10) +Tk.grid(start, stop, :padx=>10, :pady=>5) +start.grid_configure(:sticky=>'e') +stop.grid_configure(:sticky=>'w') +frame.grid_columnconfigure(:all, :weight=>1) + diff --git a/ext/tk/sample/demos-jp/twind.rb b/ext/tk/sample/demos-jp/twind.rb index d0fa8ca49e..faefaefd6e 100644 --- a/ext/tk/sample/demos-jp/twind.rb +++ b/ext/tk/sample/demos-jp/twind.rb @@ -16,8 +16,10 @@ $twind_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($twind_demo).pack(:fill=>:both, :expand=>true) + # frame À¸À® -$twind_buttons = TkFrame.new($twind_demo) {|frame| +$twind_buttons = TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -37,7 +39,7 @@ $twind_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # frame À¸À® $twind_text = nil -TkFrame.new($twind_demo, 'highlightthickness'=>2, 'borderwidth'=>2, +TkFrame.new(base_frame, 'highlightthickness'=>2, 'borderwidth'=>2, 'relief'=>'sunken') {|f| $twind_text = TkText.new(f, 'setgrid'=>'true', 'font'=>$font, 'width'=>'70', 'height'=>35, 'wrap'=>'word', diff --git a/ext/tk/sample/demos-jp/twind2.rb b/ext/tk/sample/demos-jp/twind2.rb index e8009cef19..2a26b28ef6 100644 --- a/ext/tk/sample/demos-jp/twind2.rb +++ b/ext/tk/sample/demos-jp/twind2.rb @@ -16,8 +16,10 @@ $twind2_demo = TkToplevel.new {|w| positionWindow(w) } +base_frame = TkFrame.new($twind2_demo).pack(:fill=>:both, :expand=>true) + # frame À¸À® -$twind2_buttons = TkFrame.new($twind2_demo) {|frame| +$twind2_buttons = TkFrame.new(base_frame) {|frame| TkGrid(TkFrame.new(frame, :height=>2, :relief=>:sunken, :bd=>2), :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) TkGrid('x', @@ -39,7 +41,7 @@ $twind2_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') # frame À¸À® $twind2_text = nil -TkFrame.new($twind2_demo, 'highlightthickness'=>2, 'borderwidth'=>2, +TkFrame.new(base_frame, 'highlightthickness'=>2, 'borderwidth'=>2, 'relief'=>'sunken') {|f| $twind2_text = TkText.new(f, 'setgrid'=>true, 'font'=>$font, # 'width'=>'70', 'height'=>35, 'wrap'=>'word', diff --git a/ext/tk/sample/demos-jp/unicodeout.rb b/ext/tk/sample/demos-jp/unicodeout.rb index 7ab415fe57..178077ec08 100644 --- a/ext/tk/sample/demos-jp/unicodeout.rb +++ b/ext/tk/sample/demos-jp/unicodeout.rb @@ -18,7 +18,9 @@ $unicodeout_demo = TkToplevel.new {|w| positionWindow(w) } -TkLabel.new($unicodeout_demo, +base_frame = TkFrame.new($unicodeout_demo).pack(:fill=>:both, :expand=>true) + +TkLabel.new(base_frame, :font=>$font, :wraplength=>'5.4i', :justify=>:left, :text=><:top) ¤³¤ì¤Ï¡¤Tk¤Ë¤ª¤±¤ëÈó²¤ÊÆʸ»ú½¸¹ç¤òÍѤ¤¤ë¸À¸ì¤ËÂФ¹¤ë¥µ¥Ý¡¼¥È¤Ë¤Ä¤¤¤Æ¤Î\ @@ -40,7 +42,7 @@ Tcl EOL #' -TkFrame.new($unicodeout_demo){|f| +TkFrame.new(base_frame){|f| pack(:side=>:bottom, :fill=>:x, :pady=>'2m') TkButton.new(f, :text=>'ÊĤ¸¤ë', :width=>15, :command=>proc{ @@ -53,7 +55,7 @@ TkFrame.new($unicodeout_demo){|f| }).pack(:side=>:left, :expand=>true) } -wait_msg = TkLabel.new($unicodeout_demo, +wait_msg = TkLabel.new(base_frame, :text=>"¥Õ¥©¥ó¥ÈÆɤ߹þ¤ß¤Î´°Î»¤Þ¤Ç" + "¤·¤Ð¤é¤¯¤ªÂÔ¤Á²¼¤µ¤¤¡¥¡¥¡¥", :font=>"Helvetica 12 italic").pack @@ -68,8 +70,8 @@ class Unicodeout_SampleFrame < TkFrame # @@font = 'Newspaper 12' # @@font = '{New century schoolbook} 12' - def initialize() - super($unicodeout_demo) + def initialize(base) + super(base) grid_columnconfig(1, :weight=>1) end @@ -84,7 +86,7 @@ class Unicodeout_SampleFrame < TkFrame l.grid_config(:padx, '1m') end end -f = Unicodeout_SampleFrame.new +f = Unicodeout_SampleFrame.new(base_frame) f.pack(:expand=>true, :fill=>:both, :padx=>'2m', :pady=>'1m') # Processing when some characters are missing might take a while, so make diff --git a/ext/tk/sample/demos-jp/vscale.rb b/ext/tk/sample/demos-jp/vscale.rb index 990ca43215..a1097fd77f 100644 --- a/ext/tk/sample/demos-jp/vscale.rb +++ b/ext/tk/sample/demos-jp/vscale.rb @@ -12,7 +12,9 @@ $vscale_demo = TkToplevel.new {|w| } positionWindow($vscale_demo) -msg = TkLabel.new($vscale_demo) { +base_frame = TkFrame.new($vscale_demo).pack(:fill=>:both, :expand=>true) + +msg = TkLabel.new(base_frame) { font $font wraplength '3.5i' justify 'left' @@ -23,7 +25,7 @@ msg = TkLabel.new($vscale_demo) { } msg.pack('side'=>'top', 'padx'=>'.5c') -TkFrame.new($vscale_demo) {|frame| +TkFrame.new(base_frame) {|frame| TkButton.new(frame) { #text 'λ²ò' text 'ÊĤ¸¤ë' @@ -40,7 +42,17 @@ TkFrame.new($vscale_demo) {|frame| }.pack('side'=>'left', 'expand'=>'yes') }.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m') -TkFrame.new($vscale_demo) {|frame| +def setHeight(w, height) + height = height + 21 + y2 = height - 30 + if y2 < 21 + y2 = 21 + end + w.coords 'poly',15,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20 + w.coords 'line',15,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20 +end + +TkFrame.new(base_frame) {|frame| borderwidth 10 canvas = TkCanvas.new(frame) {|c| width 50 @@ -66,14 +78,3 @@ TkFrame.new($vscale_demo) {|frame| }.pack('side'=>'left', 'anchor'=>'ne') scale.set 75 }.pack - -def setHeight(w, height) - height = height + 21 - y2 = height - 30 - if y2 < 21 - y2 = 21 - end - w.coords 'poly',15,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20 - w.coords 'line',15,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20 -end - diff --git a/ext/tk/sample/demos-jp/widget b/ext/tk/sample/demos-jp/widget index 3eea4c7887..dad85c221f 100644 --- a/ext/tk/sample/demos-jp/widget +++ b/ext/tk/sample/demos-jp/widget @@ -2,7 +2,8 @@ # -*- coding: euc-jp -*- # ´Á»ú¥³¡¼¥ÉÀßÄê ( tk.rb ¤Î¥í¡¼¥É»þ¤Î encoding ¿äÄê/ÀßÄê¤Ë»È¤ï¤ì¤ë ) -if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!!!!! +#if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!!!!! +unless defined?(::Encoding.default_external) $KCODE = 'euc' else DEFAULT_TK_ENCODING = 'EUC-JP' @@ -12,6 +13,8 @@ end require 'tk' # require 'tkafter' +$RubyTk_WidgetDemo = true + # widget demo directory °ÌÃ֤γÍÆÀ # $demo_dir = File.dirname($0) $demo_dir = File.dirname(__FILE__) @@ -46,15 +49,15 @@ when /^4.*/ # $msg_kanji_font=TkFont.new('Helvetica 16', 'Gothic 16 bold') when /^8.*/ - $font = TkFont.new('Helvetica 12') - $kanji_font = TkFont.new('Helvetica 12', 'Mincho 12') + $font = TkFont.new('Helvetica -12') + $kanji_font = TkFont.new('Helvetica -12', 'Mincho -12') TkOption.add('*kanjiFont', knjfont, 'startupFile') - $msg_kanji_font=TkFont.new('Helvetica 18 bold', 'Gothic 18 bold') + $msg_kanji_font=TkFont.new('Helvetica 14 bold', 'Gothic 14 bold') else $font = TkFont.new('Helvetica 14', nil) knjfont = '-*--16-*-jisx0208.1983-0' - $kanji_font = TkFont.new('Helvetic 14', knj) + $kanji_font = TkFont.new('Helvetic 14', knjfont) TkOption.add('*kanjiFont', knjfont, 'startupFile') $msg_kanji_font=TkFont.new('Helvetica 14', '-*--24-*-jisx0208.1983-0') @@ -121,14 +124,22 @@ EOD end # ¥á¥Ë¥å¡¼ÀßÄê -TkMenubar.new($root, - [[['File', 0], - ['About ... ', proc{aboutBox}, 0, ''], - '---', - ['Quit', proc{exit}, 0, 'Meta-Q'] - ]]).pack('side'=>'top', 'fill'=>'x') +if $tk_major_ver >= 8 + $root.add_menubar([[['File', 0], + ['About ... ', proc{aboutBox}, 0, ''], + '---', + ['Quit', proc{exit}, 0, 'Ctrl-Q'] + ]]) +else + TkMenubar.new($root, + [[['File', 0], + ['About ... ', proc{aboutBox}, 0, ''], + '---', + ['Quit', proc{exit}, 0, 'Ctrl-Q'] + ]]).pack('side'=>'top', 'fill'=>'x') +end $root.bind('F1', proc{aboutBox}) -$root.bind('Meta-q', proc{exit}) +$root.bind('Control-q', proc{exit}) =begin TkFrame.new($root){|frame| @@ -276,14 +287,31 @@ txt.insert('end', <<"EOT") ¤ë¤¿¤á¤Ë¡¢"¥³¡¼¥É»²¾È"¥Ü¥¿¥ó¤ò¥¯¥ê¥Ã¥¯¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£¤¢¤Ê¤¿¤¬\ ˾¤à¤Ê¤é¡¢¤½¤Î¥³¡¼¥É¤ò½¤Àµ¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£½¤Àµ¤·¤¿¥³¡¼¥É¤Ç¥Ç¥â\ ¥ó¥¹¥È¥ì¡¼¥·¥ç¥ó¤òºÆ¼Â¹Ô¤¹¤ë¤¿¤á¤Ë¤Ï¡¢¥³¡¼¥É¤¬½ñ¤«¤ì¤¿¥¦¥£¥ó¥É¥¦¤Ë\ -¤¢¤ë"¥Ç¥âºÆ¼Â¹Ô" ¥Ü¥¿¥ó¤ò¥¯¥ê¥Ã¥¯¤·¤Æ¤¯¤À¤µ¤¤¡£ - -°ìÉô¤Î¥Ç¥â¤Ç¤Ï¡¤Èæ³ÓŪºÇ¶á¤Î¥Ð¡¼¥¸¥ç¥ó¤Î Tk ¤Ç¤Ê¤±¤ì¤Ð¥µ¥Ý¡¼¥È¤·¤Æ\ -¤¤¤Ê¤¤µ¡Ç½¤ò»È¤Ã¤Æ¼ÂÁõ¤·¤Æ¤¤¤Þ¤¹(Î㤨¤Ð Tk8.4 °Ê¾å¤Ê¤É)¡¥¤½¤Î¤¿¤á¡¤\ -¤½¤¦¤·¤¿µ¡Ç½¤ò»ý¤¿¤Ê¤¤ Tk ¥é¥¤¥Ö¥é¥ê¤ò»È¤Ã¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï¡¤¤½¤¦¤·¤¿\ -¥Ç¥â¤ÏÀµ¤·¤¯Æ°¤­¤Þ¤»¤ó¡¥¤½¤Î¤è¤¦¤Êµ¡Ç½¤¬É¬ÍפǤ¢¤ì¤Ð¡¤¤½¤ì¤ò¥µ¥Ý¡¼¥È\ -¤·¤Æ¤¤¤ë Tk ¥é¥¤¥Ö¥é¥ê¤ò»È¤¦¤è¤¦¤Ë¡¤tcltklib ¤ò¥³¥ó¥Ñ¥¤¥ë¤·¤Ê¤ª¤·¤Æ\ -¤¯¤À¤µ¤¤¡¥ +¤¢¤ë"¥Ç¥âºÆ¼Â¹Ô" ¥Ü¥¿¥ó¤ò¥¯¥ê¥Ã¥¯¤·¤Æ¤¯¤À¤µ¤¤¡£\ +¥³¡¼¥É¤ò½¤Àµ¤·¤Æ¤â¥ª¥ê¥¸¥Ê¥ë¤Î¥Õ¥¡¥¤¥ë¤¬½ñ¤­´¹¤¨¤é¤ì¤ë¤³¤È¤Ï\ +¤¢¤ê¤Þ¤»¤ó¤«¤é¡¢¿´ÇÛ¤»¤º¤Ë¿§¡¹¤ÊÊѹ¹¤ò»î¤·¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£ + +°ìÉô¤Î¥Ç¥â¤Ç¤Ï¡¢Èæ³ÓŪºÇ¶á¤Î¥Ð¡¼¥¸¥ç¥ó¤Î Tk ¤Ç¤Ê¤±¤ì¤Ð¥µ¥Ý¡¼¥È¤·¤Æ\ +¤¤¤Ê¤¤µ¡Ç½¤ò»È¤Ã¤Æ¼ÂÁõ¤·¤Æ¤¤¤Þ¤¹(Î㤨¤Ð Tk8.4 °Ê¾å¤Ê¤É)¡£¤½¤Î¤¿¤á¡¢\ +¤½¤¦¤·¤¿µ¡Ç½¤ò»ý¤¿¤Ê¤¤ Tk ¥é¥¤¥Ö¥é¥ê¤ò»È¤Ã¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï¡¢¤½¤¦¤·¤¿\ +¥Ç¥â¤ÏÀµ¤·¤¯Æ°¤­¤Þ¤»¤ó¡£¤½¤Î¤è¤¦¤Êµ¡Ç½¤¬É¬ÍפǤ¢¤ì¤Ð¡¢¤½¤ì¤ò¥µ¥Ý¡¼¥È\ +¤·¤Æ¤¤¤ë Tk ¥é¥¤¥Ö¥é¥ê¤ò»È¤¦¤è¤¦¤Ë tcltklib ¤ò¥³¥ó¥Ñ¥¤¥ë¤·¤Ê¤ª¤·¤Æ\ +¤¯¤À¤µ¤¤¡£ + +¤â¤·¤¢¤Ê¤¿¤Î Tk ¤¬ (ºÇ½é¤«¤é´Þ¤à¤«¥¤¥ó¥¹¥È¡¼¥ë¤·¤¿¤«¤Ë¤è¤ê) \ +Ttk (Tile) ³ÈÄ¥¤òÍøÍѤǤ­¤ë¾õÂ֤Ǥ¢¤ë¤Ê¤é¡¢\ +Ttk ³ÈÄ¥¤Î¥Ç¥â (sample/tkextlib/tile/demo.rb) ¤â¤¼¤Ò»î¤·¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£ +( ¿ʬ¡¤¸½ºß¤Î¤¢¤Ê¤¿¤Î´Ä¶­¤Ë¤Ï Ttk ³ÈÄ¥¤Ï\ +#{ +begin + require 'tkextlib/tile' + "¤¹¤Ç¤ËƳÆþ¤µ¤ì¤Æ¤¤¤Þ¤¹" +rescue + "¤Þ¤À¥¤¥ó¥¹¥È¡¼¥ë¤µ¤ì¤Æ¤¤¤Þ¤»¤ó" +end +}\ +¡£) +Ttk ³ÈÄ¥¤Ï¡¢Tk8.5 °Ê¾å¤Ç¤Ïɸ½à¤Îµ¡Ç½¤È¤·¤ÆÁȤ߹þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¡£ EOT @@ -332,6 +360,9 @@ txt.insert('end', " \n ", tag_demospace) txt.insert('end', "14. ¥é¥Ù¥ëÉÕ¤­¥Õ¥ì¡¼¥à (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤ÎTk¤¬É¬Í×)\n", tag_demo, "demo-labelframe") txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "15. ¥Æ¡¼¥Þ¤ËÂбþ¤·¤¿¥¦¥£¥¸¥§¥Ã¥È¤Î´Êñ¤ÊÎã (Tile/Ttk³ÈÄ¥¤Ø¤ÎÂбþ¤¬É¬Í×)\n", + tag_demo, "demo-ttkbut") +txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") #txt.insert('end', "¥ê¥¹¥È¥Ü¥Ã¥¯¥¹\n", tag_middle) @@ -344,6 +375,12 @@ txt.insert('end', "2. txt.insert('end', " \n ", tag_demospace) txt.insert('end', "3. ³Ê¸À½¸\n", tag_demo, "demo-sayings") txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "4. ¹ñ¤Ë¤Ä¤¤¤Æ¤Î¥Þ¥ë¥Á¥«¥é¥à¥ê¥¹¥È (Tile/Ttk³ÈÄ¥¤Ø¤ÎÂбþ¤¬É¬Í×)\n", + tag_demo, "demo-mclist") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "5. ¥Ç¥£¥ì¥¯¥È¥ê¥Ö¥é¥¦¥¶ (Tile/Ttk³ÈÄ¥¤Ø¤ÎÂбþ¤¬É¬Í×)\n", + tag_demo, "demo-tree") +txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") #txt.insert('end', "¥¨¥ó¥È¥ê¤È¥¹¥Ô¥ó¥Ü¥Ã¥¯¥¹\n", tag_middle) @@ -359,7 +396,10 @@ txt.insert('end', " \n ", tag_demospace) txt.insert('end', "4. ¥¹¥Ô¥ó¥Ü¥Ã¥¯¥¹ (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤ÎTk¤¬É¬Í×)\n", tag_demo, "demo-spin") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "5. ´Êñ¤Ê¥Õ¥©¡¼¥à\n", tag_demo, "demo-form") +txt.insert('end', "5. ¥³¥ó¥Ü¥Ü¥Ã¥¯¥¹ (Tile/Ttk³ÈÄ¥¤Ø¤ÎÂбþ¤¬É¬Í×)\n", + tag_demo, "demo-combo") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "6. ´Êñ¤Ê¥Õ¥©¡¼¥à\n", tag_demo, "demo-form") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") @@ -405,18 +445,23 @@ txt.insert('end', " \n ", tag_demospace) txt.insert('end', "8. ¥¹¥¯¥í¡¼¥ë²Äǽ¤Ê¥­¥ã¥ó¥Ð¥¹\n", tag_demo, "demo-cscroll") txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "9. ¥Á¥§¥¹¥Ü¡¼¥É¾å¤Îµ³»Î¤Î½ä²ó (Tile/Ttk³ÈÄ¥¤Ø¤ÎÂбþ¤¬É¬Í×)\n", + tag_demo, "demo-knightstour") +txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") -#txt.insert('end', "¥¹¥±¡¼¥ë\n", tag_middle) -txt.insert('end', "¥¹¥±¡¼¥ë\n", tag_kanji_title) +#txt.insert('end', "¥¹¥±¡¼¥ë¤È¥×¥í¥°¥ì¥¹¥Ð¡¼\n", tag_middle) +txt.insert('end', "¥¹¥±¡¼¥ë¤È¥×¥í¥°¥ì¥¹¥Ð¡¼\n", tag_kanji_title) txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "1. ¿âľ\n", tag_demo.id, "demo-vscale") +txt.insert('end', "1. ¿âľ¥¹¥±¡¼¥ë\n", tag_demo.id, "demo-vscale") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "2. ¿åÊ¿\n", tag_demo.id, "demo-hscale") +txt.insert('end', "2. ¿åÊ¿¥¹¥±¡¼¥ë\n", tag_demo.id, "demo-hscale") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "3. ¥×¥í¥°¥ì¥¹¥Ð¡¼ (Tile/Ttk³ÈÄ¥¤Ø¤ÎÂбþ¤¬É¬Í×)\n", tag_demo.id, "demo-ttkprogress") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") -txt.insert('end', "¥Ú¥¤¥ó¥É¥¦¥£¥ó¥É¥¦\n", tag_kanji_title) +txt.insert('end', "¥Ú¥¤¥ó¥É¥¦¥£¥ó¥É¥¦¤È¥Î¡¼¥È¥Ö¥Ã¥¯\n", tag_kanji_title) txt.insert('end', " \n ", tag_demospace) txt.insert('end', "1. ¿åÊ¿Êý¸þ (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤ÎTk¤¬É¬Í×)\n", tag_demo.id, "demo-paned1") @@ -424,10 +469,16 @@ txt.insert('end', " \n ", tag_demospace) txt.insert('end', "2. ¿âľÊý¸þ (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤ÎTk¤¬É¬Í×)\n", tag_demo.id, "demo-paned2") txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "3. ¥Æ¡¼¥Þ¤ËÂбþ¤·¤¿Ëä¤á¹þ¤ß¥Ú¥¤¥ó (Tile/Ttk³ÈÄ¥¤Ø¤ÎÂбþ¤¬É¬Í×)\n", + tag_demo.id, "demo-ttkpane") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "4. ¥Î¡¼¥È¥Ö¥Ã¥¯¥¦¥£¥¸¥§¥Ã¥È (Tile/Ttk³ÈÄ¥¤Ø¤ÎÂбþ¤¬É¬Í×)\n", + tag_demo.id, "demo-ttknote") +txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") -#txt.insert('end', "¥á¥Ë¥å¡¼\n", tag_middle) -txt.insert('end', "¥á¥Ë¥å¡¼\n", tag_kanji_title) +#txt.insert('end', "¥á¥Ë¥å¡¼¤È¥Ä¡¼¥ë¥Ð¡¼\n", tag_middle) +txt.insert('end', "¥á¥Ë¥å¡¼¤È¥Ä¡¼¥ë¥Ð¡¼\n", tag_kanji_title) txt.insert('end', " \n ", tag_demospace) txt.insert('end', "1. ¥á¥Ë¥å¡¼¤È¥«¥¹¥±¡¼¥É¤ò´Þ¤ó¤À¥¦¥£¥ó¥É¥¦\n", tag_demo, "demo-menu") @@ -441,6 +492,12 @@ txt.insert('end', " \n ", tag_demospace) txt.insert('end', "4. ¥á¥Ë¥å¡¼¥Ü¥¿¥ó (Tk8.x ÀìÍÑ)\n", tag_demo, "demo-menubu") txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "5. ¥Æ¡¼¥Þ¤ËÂбþ¤·¤¿¥á¥Ë¥å¡¼¥Ü¥¿¥ó (Tile/Ttk³ÈÄ¥¤Ø¤ÎÂбþ¤¬É¬Í×)\n", + tag_demo.id, "demo-ttkmenu") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "6. ¥Æ¡¼¥Þ¤ËÂбþ¤·¤¿¥Ä¡¼¥ë¥Ð¡¼ (Tile/Ttk³ÈÄ¥¤Ø¤ÎÂбþ¤¬É¬Í×)\n", + tag_demo.id, "demo-toolbar") +txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") #txt.insert('end', "¥À¥¤¥¢¥í¥°¥¦¥£¥ó¥É¥¦\n", tag_middle) @@ -448,9 +505,11 @@ txt.insert('end', " txt.insert('end', " \n ", tag_demospace) txt.insert('end', "1. ¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹\n", tag_demo, "demo-msgbox") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "2. ¥Õ¥¡¥¤¥ëÁªÂò¥À¥¤¥¢¥í¥°\n", tag_demo, "demo-filebox") +txt.insert('end', "2. ¾ÜºÙ¥Æ¥­¥¹¥ÈÉÕ¤­¤Î¥á¥Ã¥»¡¼¥¸¥Ü¥Ã¥¯¥¹ (µ¡Ç½¤ËÂбþ¤·¤¿¥Ð¡¼¥¸¥ç¥ó¤ÎTk¤¬É¬Í×)\n", tag_demo, "demo-msgbox2") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "3. ¿§ÁªÂò¥À¥¤¥¢¥í¥°\n", tag_demo, "demo-clrpick") +txt.insert('end', "3. ¥Õ¥¡¥¤¥ëÁªÂò¥À¥¤¥¢¥í¥°\n", tag_demo, "demo-filebox") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "4. ¿§ÁªÂò¥À¥¤¥¢¥í¥°\n", tag_demo, "demo-clrpick") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") @@ -499,7 +558,8 @@ def showVars1(parent, *args) end top = TkToplevel.new(parent) {|w| title "Variable values" - TkLabel.new(w) { + base = TkFrame.new(w).pack(:fill=>:both, :expand=>true) + TkLabel.new(base) { text "ÊÑ¿ôÃÍ:" width 20 anchor 'center' @@ -514,14 +574,14 @@ def showVars1(parent, *args) len = vnam.to_s.length if vnam.to_s.length > len } args.each{|vnam,vbody| - TkFrame.new(w){|f| + TkFrame.new(base){|f| #TkLabel.new(f, 'text'=>"#{vnam}: ").pack('side'=>'left') TkLabel.new(f, 'text'=>"#{vnam}: ",'width'=>len+2).pack('side'=>'left') TkLabel.new(f, 'textvariable'=>vbody, 'anchor'=>'w')\ .pack('side'=>'left', 'expand'=>'yes', 'fill'=>'x') }.pack('side'=>'top', 'anchor'=>'w', 'fill'=>'x') } - TkButton.new(w) { + TkButton.new(base) { text "λ²ò" command proc{w.destroy} }.pack('side'=>'bottom', 'pady'=>2) @@ -536,10 +596,12 @@ def showVars2(parent, *args) rescue end end - $showVarsWin[parent.path] = TkToplevel.new(parent) {|w| + $showVarsWin[parent.path] = TkToplevel.new(parent) {|top| title "Variable values" - TkLabelFrame.new(w, :text=>"ÊÑ¿ôÃÍ:", + base = TkFrame.new(top).pack(:fill=>:both, :expand=>true) + + TkLabelFrame.new(base, :text=>"ÊÑ¿ôÃÍ:", :font=>{:family=>'Helvetica', :size=>14}){|f| args.each{|vnam,vbody| TkGrid(TkLabel.new(f, :text=>"#{vnam}: ", :anchor=>'w'), @@ -551,15 +613,15 @@ def showVars2(parent, *args) f.grid_columnconfig(1, :weight=>1) f.grid_rowconfig(100, :weight=>1) } - TkButton.new(w, :text=>"λ²ò", :width=>8, :default=>:active, - :command=>proc{w.destroy}){|b| - w.bind('Return', proc{b.invoke}) - w.bind('Escape', proc{b.invoke}) + TkButton.new(base, :text=>"λ²ò", :width=>8, :default=>:active, + :command=>proc{top.destroy}){|b| + top.bind('Return', proc{b.invoke}) + top.bind('Escape', proc{b.invoke}) b.grid(:sticky=>'e', :padx=>4, :pady=>[6, 4]) } - w.grid_columnconfig(0, :weight=>1) - w.grid_rowconfig(0, :weight=>1) + base.grid_columnconfig(0, :weight=>1) + base.grid_rowconfig(0, :weight=>1) } end @@ -653,10 +715,27 @@ def _null_binding end private :_null_binding -def eval_samplecode(code) +def eval_samplecode(code, file=nil) #eval(code) #_null_binding.pseudo_toplevel_eval{ eval(code) } - Thread.new{ _null_binding.pseudo_toplevel_eval{ eval(code) } } + #Thread.new{ _null_binding.pseudo_toplevel_eval{ eval(code) } } + Thread.new{ + _null_binding.pseudo_toplevel_eval{ + begin + if file + eval(code, binding, "(eval:#{file})") + else + eval(code) + end + rescue Exception=>e + #p e + TkBgError.show(e.message + "\n" + + "\n---< backtrace of Ruby side >-----\n" + + e.backtrace.join("\n") + + "\n---< backtrace of Tk side >-------") + end + } + } Tk.update end @@ -670,7 +749,7 @@ def invoke(txt, idx) Tk.update # eval(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join, _null_binding) # Tk.update - eval_samplecode(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join) + eval_samplecode(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join, tag[5..-1] + '.rb') txt.cursor(cursor) $tag_visited.add("#{idx} linestart +1 chars", "#{idx} lineend +1 chars") @@ -716,6 +795,7 @@ def showCode1(demo) if $code_window == nil || TkWinfo.exist?($code_window) == false $code_window = TkToplevel.new(nil) f = TkFrame.new($code_window) + TkButton.new(f) { #text "λ²ò" text "ÊĤ¸¤ë" @@ -723,14 +803,25 @@ def showCode1(demo) $code_window.destroy $code_window = nil } - }.pack('side'=>'left', 'expand'=>'yes', 'pady'=>2) + }.pack('side'=>'right', 'expand'=>'false', 'pady'=>2) TkButton.new(f) { text "ºÆ¼Â¹Ô" # command proc{eval($code_text.get('1.0','end'), _null_binding)} - command proc{eval_samplecode($code_text.get('1.0','end'))} - }.pack('side'=>'left', 'expand'=>'yes', 'pady'=>2) -# f.pack('side'=>'bottom', 'expand'=>'yes', 'fill'=>'x') - f.pack('side'=>'bottom', 'fill'=>'x') + command proc{eval_samplecode($code_text.get('1.0','end'), '')} + }.pack('side'=>'right', 'expand'=>'false', 'pady'=>2) + + TkLabel.new(f,'text'=>'line:').pack('side'=>'left') + linenum =TkLabel.new(f,'text'=>'').pack('side'=>'left') + TkLabel.new(f,'text'=>' pos:').pack('side'=>'left') + posnum =TkLabel.new(f,'text'=>'').pack('side'=>'left') + + $set_linenum = proc{|w| + line, pos = w.index('insert').split('.') + linenum.text = line + posnum.text = pos + } + + f.pack('side'=>'bottom', 'expand'=>'true', 'fill'=>'x') if $tk_version =~ /^4\.[01]/ s = TkScrollbar.new($code_window, 'orient'=>'vertical') @@ -774,10 +865,21 @@ def showCode1(demo) TkGrid.columnconfigure(f, 0, 'weight'=>1, 'minsize'=>0) } end + + btag = TkBindTag.new + + btag.bind('Key', $set_linenum, '%W') + btag.bind('Button', $set_linenum, '%W') + + btags = $code_text.bindtags + btags.insert(btags.index($code_text.class) + 1, btag) + $code_text.bindtags = btags + else $code_window.deiconify $code_window.raise end + $code_window.title("Demo code: #{file}") $code_window.iconname(file) # fid = open(file, 'r') @@ -788,6 +890,9 @@ def showCode1(demo) #$code_mark = TkTextMark.new($code_text, '1.0') #$code_text.set_insert('1.0') TkTextMarkInsert.new($code_text,'1.0') + + $set_linenum.call($code_text) + fid.close end @@ -808,7 +913,19 @@ def showCode2(demo) tf.grid_columnconfigure(0, :weight=>1) bf = TkFrame.new($code_window) - + + lf = TkFrame.new(bf) + TkLabel.new(lf, :text=>'line:').pack(:side=>:left) + linenum =TkLabel.new(lf, :text=>'').pack(:side=>:left) + TkLabel.new(lf, :text=>' pos:').pack(:side=>:left) + posnum =TkLabel.new(lf, :text=>'').pack(:side=>:left) + + $set_linenum = proc{|w| + line, pos = w.index('insert').split('.') + linenum.text = line + posnum.text = pos + } + #b_dis = TkButton.new(bf, :text=>'λ²ò', :default=>:active, b_dis = TkButton.new(bf, :text=>'ÊĤ¸¤ë', :default=>:active, :command=>proc{ @@ -822,12 +939,12 @@ def showCode2(demo) b_run = TkButton.new(bf, :text=>'ºÆ¼Â¹Ô', :command=>proc{ # eval($code_text.get('1.0','end'), _null_binding) - eval_samplecode($code_text.get('1.0','end')) + eval_samplecode($code_text.get('1.0','end'), '') }, :image=>$image['refresh'], :compound=>:left) - TkGrid('x', b_run, b_prn, b_dis, :padx=>4, :pady=>[6,4]) - bf.grid_columnconfigure(0, :weight=>1) + TkGrid(lf, 'x', b_run, b_prn, b_dis, :padx=>4, :pady=>[6,4]) + bf.grid_columnconfigure(1, :weight=>1) TkGrid(tf, :sticky=>'news') TkGrid(bf, :sticky=>'ew') @@ -840,6 +957,16 @@ def showCode2(demo) $code_window.bindinfo('Return').each{|cmd, arg| $code_window.bind_append('Escape', cmd, arg) } + + btag = TkBindTag.new + + btag.bind('Key', $set_linenum, '%W') + btag.bind('Button', $set_linenum, '%W') + + btags = $code_text.bindtags + btags.insert(btags.index($code_text.class) + 1, btag) + $code_text.bindtags = btags + else $code_window.deiconify $code_window.raise @@ -851,6 +978,9 @@ def showCode2(demo) $code_text.delete('1.0', 'end') $code_text.insert('1.0', fid.read) TkTextMarkInsert.new($code_text,'1.0') + + $set_linenum.call($code_text) + fid.close end @@ -948,12 +1078,13 @@ end # def aboutBox Tk.messageBox('icon'=>'info', 'type'=>'ok', 'title'=>'About Widget Demo', - 'message'=>"Ruby/Tk ¥¦¥£¥¸¥§¥Ã¥È¥Ç¥â Ver.1.6.3-jp\n\n" + + 'message'=>"Ruby/Tk ¥¦¥£¥¸¥§¥Ã¥È¥Ç¥â Ver.1.7.0-jp\n\n" + "based on demos of Tk8.1 -- 8.5 " + - "( Copyright:: " + + "( Copyright of Tcl/Tk demos:: " + "(c) 1996-1997 Sun Microsystems, Inc. / " + "(c) 1997-2000 Ajuba Solutions, Inc. / " + - "(c) 2001-2003 Donal K. Fellows )\n\n" + + "(c) 2001-2007 Donal K. Fellows / " + + "(c) 2002-2007 Daniel A. Steffen )\n\n" + "Your Ruby & Tk Version ::\n" + "Ruby#{RUBY_VERSION}(#{RUBY_RELEASE_DATE})[#{RUBY_PLATFORM}] / Tk#{$tk_patchlevel}#{(Tk::JAPANIZED_TK)? '-jp': ''}\n\n" + "Ruby/Tk release date :: tcltklib #{TclTkLib::RELEASE_DATE}; tk #{Tk::RELEASE_DATE}") @@ -975,7 +1106,7 @@ ARGV.each{|cmd| end #eval(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join, # _null_binding) - eval_samplecode(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join) + eval_samplecode(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join, cmd + '.rb') } if no_launcher $root.withdraw # hide root window diff --git a/ext/tk/sample/figmemo_sample.rb b/ext/tk/sample/figmemo_sample.rb new file mode 100644 index 0000000000..1b6979d2dd --- /dev/null +++ b/ext/tk/sample/figmemo_sample.rb @@ -0,0 +1,456 @@ +#!/usr/bin/env ruby +require 'tk' + +begin + # try to use Img extension + require 'tkextlib/tkimg' +rescue Exception + # cannot use Img extention --> ignore +end + + +############################ +# scrolled_canvas +class TkScrolledCanvas < TkCanvas + include TkComposite + + def initialize_composite(keys={}) + @h_scr = TkScrollbar.new(@frame) + @v_scr = TkScrollbar.new(@frame) + + @canvas = TkCanvas.new(@frame) + @path = @canvas.path + + @canvas.xscrollbar(@h_scr) + @canvas.yscrollbar(@v_scr) + + TkGrid.rowconfigure(@frame, 0, :weight=>1, :minsize=>0) + TkGrid.columnconfigure(@frame, 0, :weight=>1, :minsize=>0) + + @canvas.grid(:row=>0, :column=>0, :sticky=>'news') + @h_scr.grid(:row=>1, :column=>0, :sticky=>'ew') + @v_scr.grid(:row=>0, :column=>1, :sticky=>'ns') + + delegate('DEFAULT', @canvas) + delegate('background', @canvas, @h_scr, @v_scr) + delegate('activebackground', @h_scr, @v_scr) + delegate('troughcolor', @h_scr, @v_scr) + delegate('repeatdelay', @h_scr, @v_scr) + delegate('repeatinterval', @h_scr, @v_scr) + delegate('borderwidth', @frame) + delegate('relief', @frame) + + delegate_alias('canvasborderwidth', 'borderwidth', @canvas) + delegate_alias('canvasrelief', 'relief', @canvas) + + delegate_alias('scrollbarborderwidth', 'borderwidth', @h_scr, @v_scr) + delegate_alias('scrollbarrelief', 'relief', @h_scr, @v_scr) + + configure(keys) unless keys.empty? + end +end + +############################ +class PhotoCanvas < TkScrolledCanvas + +USAGE = <@photo) + + width = self.width + height = self.height + @scr_region = [-width, -height, width, height] + self.scrollregion(@scr_region) + self.xview_moveto(0.25) + self.yview_moveto(0.25) + + @col = 'red' + @font = 'Helvetica -12' + + @memo_id_num = -1 + @memo_id_head = 'memo_' + @memo_id_tag = nil + @overlap_d = 2 + + @state = TkVariable.new + @border = 2 + @selectborder = 1 + @delta = @border + @selectborder + @entry = TkEntry.new(self, :relief=>:ridge, :borderwidth=>@border, + :selectborderwidth=>@selectborder, + :highlightthickness=>0) + @entry.bind('Return'){@state.value = 0} + + @mode = old_mode = 0 + + _state0() + + bind('2', :x, :y){|x,y| scan_mark(x,y)} + bind('B2-Motion', :x, :y){|x,y| scan_dragto(x,y)} + + bind('3'){ + next if (old_mode = @mode) == 0 + @items.each{|item| item.delete } + _state0() + } + + bind('Double-3', :widget, :x, :y){|w, x, y| + next if old_mode != 0 + x = w.canvasx(x) + y = w.canvasy(y) + tag = nil + w.find_overlapping(x - @overlap_d, y - @overlap_d, + x + @overlap_d, y + @overlap_d).find{|item| + ! (item.tags.find{|name| + if name =~ /^(#{@memo_id_head}\d+)$/ + tag = $1 + end + }.empty?) + } + w.delete(tag) if tag + } + end + + #----------------------------------- + private + def _state0() # init + @mode = 0 + + @memo_id_num += 1 + @memo_id_tag = @memo_id_head + @memo_id_num.to_s + + @target = nil + @items = [] + @mark = [0, 0] + bind_remove('Motion') + bind('ButtonRelease-1', proc{|x,y| _state1(x,y)}, '%x', '%y') + end + + def _state1(x,y) # set center + @mode = 1 + + @target = TkcOval.new(self, + [canvasx(x), canvasy(y)], [canvasx(x), canvasy(y)], + :outline=>@col, :width=>3, :tags=>[@memo_id_tag]) + @items << @target + @mark = [x,y] + + bind('Motion', proc{|x,y| _state2(x,y)}, '%x', '%y') + bind('ButtonRelease-1', proc{|x,y| _state3(x,y)}, '%x', '%y') + end + + def _state2(x,y) # create circle + @mode = 2 + + r = Integer(Math.sqrt((x-@mark[0])**2 + (y-@mark[1])**2)) + @target.coords([canvasx(@mark[0] - r), canvasy(@mark[1] - r)], + [canvasx(@mark[0] + r), canvasy(@mark[1] + r)]) + end + + def _state3(x,y) # set line start + @mode = 3 + + @target = TkcLine.new(self, + [canvasx(x), canvasy(y)], [canvasx(x), canvasy(y)], + :arrow=>:first, :arrowshape=>[10, 14, 5], + :fill=>@col, :tags=>[@memo_id_tag]) + @items << @target + @mark = [x, y] + + bind('Motion', proc{|x,y| _state4(x,y)}, '%x', '%y') + bind('ButtonRelease-1', proc{|x,y| _state5(x,y)}, '%x', '%y') + end + + def _state4(x,y) # create line + @mode = 4 + + @target.coords([canvasx(@mark[0]), canvasy(@mark[1])], + [canvasx(x), canvasy(y)]) + end + + def _state5(x,y) # set text + @mode = 5 + + if x - @mark[0] >= 0 + justify = 'left' + dx = - @delta + + if y - @mark[1] >= 0 + anchor = 'nw' + dy = - @delta + else + anchor = 'sw' + dy = @delta + end + else + justify = 'right' + dx = @delta + + if y - @mark[1] >= 0 + anchor = 'ne' + dy = - @delta + else + anchor = 'se' + dy = @delta + end + end + + bind_remove('Motion') + + @entry.value = '' + @entry.configure(:justify=>justify, :font=>@font, :foreground=>@col) + + ewin = TkcWindow.new(self, [canvasx(x)+dx, canvasy(y)+dy], + :window=>@entry, :state=>:normal, :anchor=>anchor, + :tags=>[@memo_id_tag]) + + @entry.focus + @entry.grab + @state.wait + @entry.grab_release + + ewin.delete + + @target = TkcText.new(self, [canvasx(x), canvasy(y)], + :anchor=>anchor, :justify=>justify, + :fill=>@col, :font=>@font, :text=>@entry.value, + :tags=>[@memo_id_tag]) + + _state0() + end + + #----------------------------------- + public + def load_photo(filename) + @photo.configure(:file=>filename) + end + + def modified? + ! ((find_withtag('all') - [@img]).empty?) + end + + def fig_erase + (find_withtag('all') - [@img]).each{|item| item.delete} + end + + def reset_region + width = @photo.width + height = @photo.height + + if width > @scr_region[2] + @scr_region[0] = -width + @scr_region[2] = width + end + + if height > @scr_region[3] + @scr_region[1] = -height + @scr_region[3] = height + end + + self.scrollregion(@scr_region) + self.xview_moveto(0.25) + self.yview_moveto(0.25) + end + + def get_texts + ret = [] + find_withtag('all').each{|item| + if item.kind_of?(TkcText) + ret << item[:text] + end + } + ret + end +end +############################ + +# define methods for menu +def open_file(canvas, fname) + if canvas.modified? + ret = Tk.messageBox(:icon=>'warning',:type=>'okcancel',:default=>'cancel', + :message=>'Canvas may be modified. Realy erase? ') + return if ret == 'cancel' + end + + filetypes = [ + ['GIF Files', '.gif'], + ['GIF Files', [], 'GIFF'], + ['PPM Files', '.ppm'], + ['PGM Files', '.pgm'] + ] + + begin + if Tk::Img::package_version != '' + filetypes << ['JPEG Files', ['.jpg', '.jpeg']] + filetypes << ['PNG Files', '.png'] + filetypes << ['PostScript Files', '.ps'] + filetypes << ['PDF Files', '.pdf'] + filetypes << ['Windows Bitmap Files', '.bmp'] + filetypes << ['Windows Icon Files', '.ico'] + filetypes << ['PCX Files', '.pcx'] + filetypes << ['Pixmap Files', '.pixmap'] + filetypes << ['SGI Files', '.sgi'] + filetypes << ['Sun Raster Files', '.sun'] + filetypes << ['TGA Files', '.tga'] + filetypes << ['TIFF Files', '.tiff'] + filetypes << ['XBM Files', '.xbm'] + filetypes << ['XPM Files', '.xpm'] + end + rescue + end + + filetypes << ['ALL Files', '*'] + + fpath = Tk.getOpenFile(:filetypes=>filetypes) + return if fpath.empty? + + begin + canvas.load_photo(fpath) + rescue => e + Tk.messageBox(:icon=>'error', :type=>'ok', + :message=>"Fail to read '#{fpath}'.\n#{e.message}") + end + + canvas.fig_erase + canvas.reset_region + + fname.value = fpath +end + +# -------------------------------- +def save_memo(canvas, fname) + initname = fname.value + if initname != '-' + initname = File.basename(initname, File.extname(initname)) + fpath = Tk.getSaveFile(:filetypes=>[ ['Text Files', '.txt'], + ['ALL Files', '*'] ], + :initialfile=>initname) + else + fpath = Tk.getSaveFile(:filetypes=>[ ['Text Files', '.txt'], + ['ALL Files', '*'] ]) + end + return if fpath.empty? + + begin + fid = open(fpath, 'w') + rescue => e + Tk.messageBox(:icon=>'error', :type=>'ok', + :message=>"Fail to open '#{fname.value}'.\n#{e.message}") + end + + begin + canvas.get_texts.each{|txt| + fid.print(txt, "\n") + } + ensure + fid.close + end +end + +# -------------------------------- +def ps_print(canvas, fname) + initname = fname.value + if initname != '-' + initname = File.basename(initname, File.extname(initname)) + fpath = Tk.getSaveFile(:filetypes=>[ ['Postscript Files', '.ps'], + ['ALL Files', '*'] ], + :initialfile=>initname) + else + fpath = Tk.getSaveFile(:filetypes=>[ ['Postscript Files', '.ps'], + ['ALL Files', '*'] ]) + end + return if fpath.empty? + + bbox = canvas.bbox('all') + canvas.postscript(:file=>fpath, :x=>bbox[0], :y=>bbox[1], + :width=>bbox[2] - bbox[0], :height=>bbox[3] - bbox[1]) +end + +# -------------------------------- +def quit(canvas) + ret = Tk.messageBox(:icon=>'warning', :type=>'okcancel', + :default=>'cancel', + :message=>'Realy quit? ') + exit if ret == 'ok' +end + +# -------------------------------- +# setup root +root = TkRoot.new(:title=>'Fig Memo') + +# create canvas frame +canvas = PhotoCanvas.new(root).pack(:fill=>:both, :expand=>true) +usage_frame = TkFrame.new(root, :relief=>:ridge, :borderwidth=>2) +hide_btn = TkButton.new(usage_frame, :text=>'hide usage', + :font=>{:size=>8}, :pady=>1, + :command=>proc{usage_frame.unpack}) +hide_btn.pack(:anchor=>'e', :padx=>5) +usage = TkLabel.new(usage_frame, :text=>PhotoCanvas::USAGE, + :font=>'Helvetica 8', :justify=>:left).pack + +show_usage = proc{ + usage_frame.pack(:before=>canvas, :fill=>:x, :expand=>true) +} + +fname = TkVariable.new('-') +f = TkFrame.new(root, :relief=>:sunken, :borderwidth=>1).pack(:fill=>:x) +label = TkLabel.new(f, :textvariable=>fname, + :font=>{:size=>-12, :weight=>:bold}, + :anchor=>'w').pack(:side=>:left, :fill=>:x, :padx=>10) + +# create menu +mspec = [ + [ ['File', 0], + ['Show Usage', proc{show_usage.call}, 5], + '---', + ['Open Image File', proc{open_file(canvas, fname)}, 0], + ['Save Memo Texts', proc{save_memo(canvas, fname)}, 0], + '---', + ['Save Postscript', proc{ps_print(canvas, fname)}, 5], + '---', + ['Quit', proc{quit(canvas)}, 0] + ] +] +root.add_menubar(mspec) + +# manage wm_protocol +root.protocol(:WM_DELETE_WINDOW){quit(canvas)} + +# show usage +show_usage.call + +# -------------------------------- +# start eventloop +Tk.mainloop diff --git a/ext/tk/sample/tkextlib/iwidgets/sample/entryfield-2.rb b/ext/tk/sample/tkextlib/iwidgets/sample/entryfield-2.rb index 4a4c2e7eb7..e2b4eec6bc 100644 --- a/ext/tk/sample/tkextlib/iwidgets/sample/entryfield-2.rb +++ b/ext/tk/sample/tkextlib/iwidgets/sample/entryfield-2.rb @@ -4,7 +4,11 @@ # set $KCODE to 'utf' for a utf8 charecter # ######################################################### -$KCODE='utf' +unless defined?(::Encoding.default_external) + $KCODE='utf' +else + DEFAULT_TK_ENCODING = 'UTF-8' +end require 'tk' require 'tkextlib/iwidgets' diff --git a/ext/tk/sample/tkextlib/tile/demo.rb b/ext/tk/sample/tkextlib/tile/demo.rb index 1a9c029701..633a072460 100644 --- a/ext/tk/sample/tkextlib/tile/demo.rb +++ b/ext/tk/sample/tkextlib/tile/demo.rb @@ -24,7 +24,9 @@ end Tk::Tile.__define_LoadImages_proc_for_compatibility__! Tk::Tile::Style.__define_wrapper_proc_for_compatibility__! -Tk::Tile::Style.theme_create('step') +unless Tk::Tile::Style.theme_names.include?('step') + Tk::Tile::Style.theme_create('step') +end Tk.load_tclscript(File.join(demodir, 'toolbutton.tcl')) Tk.load_tclscript(File.join(demodir, 'repeater.tcl')) diff --git a/ext/tk/sample/tkextlib/treectrl/demo.rb b/ext/tk/sample/tkextlib/treectrl/demo.rb index 50ecde91f0..eed95d0e1c 100644 --- a/ext/tk/sample/tkextlib/treectrl/demo.rb +++ b/ext/tk/sample/tkextlib/treectrl/demo.rb @@ -9,11 +9,12 @@ $HasColumnCreate = Tk::TreeCtrl::HasColumnCreateCommand $Version_1_1_OrLater = (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0) -if Hash.instance_methods.include?('key') - # probably ruby 1.9.x --> use Hash#key +#if Hash.instance_methods.include?(:key) +if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + # ruby 1.9.x --> use Hash#key # Because Hash#index show warning "Hash#index is deprecated; use Hash#key". else - # probably ruby 1.8.x --> use Hash#index + # ruby 1.8.x --> use Hash#index class Hash alias key index end diff --git a/ext/tk/sample/tktextio.rb b/ext/tk/sample/tktextio.rb index 4573bcebdf..9f012feada 100644 --- a/ext/tk/sample/tktextio.rb +++ b/ext/tk/sample/tktextio.rb @@ -254,7 +254,15 @@ class TkTextIO < TkText Tk.callback_break end end - private :_cb_up, :_cb_down, :_cb_left, :_cb_backspace, :_cb_ctrl_a + def _cb_ctrl_u + if @console_mode + mark_set('insert', @ins_head) + delete('insert', 'insert lineend') + Tk.callback_break + end + end + private :_cb_up, :_cb_down, :_cb_left, :_cb_backspace, + :_cb_ctrl_a, :_cb_ctrl_u def _setup_console_bindings @bindtag = TkBindTag.new @@ -328,6 +336,8 @@ class TkTextIO < TkText @bindtag.bind('Home'){ _cb_ctrl_a } @bindtag.bind('Control-a'){ _cb_ctrl_a } + + @bindtag.bind('Control-u'){ _cb_ctrl_u } end private :_setup_console_bindings diff --git a/ext/tk/sample/ttk_wrapper.rb b/ext/tk/sample/ttk_wrapper.rb index ddae24019f..1580668994 100644 --- a/ext/tk/sample/ttk_wrapper.rb +++ b/ext/tk/sample/ttk_wrapper.rb @@ -4,7 +4,7 @@ # # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # -version = '0.1' +version = '0.1.3' # ########################################################################## # parse commandline arguments @@ -51,6 +51,15 @@ if OPTS[:verbose] end +########################################################################## +# define Tcl/Tk procedures for compatibility. +# those are required when want to use themes included +# in "sample/tkextlib/tile/demo.rb". +########################################################################## +Tk::Tile.__define_LoadImages_proc_for_compatibility__! +Tk::Tile::Style.__define_wrapper_proc_for_compatibility__! + + ########################################################################## # use themes defined on the demo of Ttk (Tile) extension ########################################################################## @@ -91,15 +100,6 @@ themes_by_ruby.each{|f| } -########################################################################## -# define Tcl/Tk procedures for compatibility. -# those are required when want to use themes included -# in "sample/tkextlib/tile/demo.rb". -########################################################################## -Tk::Tile.__define_LoadImages_proc_for_compatibility__! -Tk::Tile::Style.__define_wrapper_proc_for_compatibility__! - - ########################################################################## # ignore unsupported options of Ttk widgets ########################################################################## @@ -108,44 +108,44 @@ TkItemConfigMethod.__set_IGNORE_UNKNOWN_CONFIGURE_OPTION__! true ########################################################################## -# define utility method +# set theme of widget style ########################################################################## -def setTheme(theme) - unless Tk::Tile::Style.theme_names.find{|n| n == theme} - if (pkg = TkPackage.names.find{|n| n =~ /(tile|ttk)::theme::#{theme}/}) - TkPackage.require(pkg) - end - end - Tk::Tile::Style.theme_use(theme) +if OPTS[:list] || OPTS[:verbose] + print "supported theme names: #{Tk::Tile.themes.inspect}\n" + exit if OPTS[:list] && ARGV.empty? end +print "use theme: \"#{OPTS[:theme]}\"\n" if OPTS[:theme] && OPTS[:verbose] +#setTheme(OPTS[:theme]) if OPTS[:theme] +Tk::Tile.set_theme(OPTS[:theme]) if OPTS[:theme] ########################################################################## -# make theme name list +# replace $0 and $RPAGRAM_NAME ########################################################################## -ThemesList = Tk::Tile::Style.theme_names -TkPackage.names.find_all{|n| n =~ /^(tile|ttk)::theme::/}.each{|pkg| - ThemesList << pkg.split('::')[-1] -} -ThemesList.uniq! +# When the expand_path of the target script is long, ruby sometimes +# fails to set the path to $0 (the path string is trimmed). +# The following replaces $0 and $PROGNAME to avoid such trouble. +progname_obj = $0.dup +$program_name = progname_obj +alias $REAL_PROGRAM_NAME $0 +alias $PROGRAM_NAME $program_name +alias $0 $program_name -########################################################################## -# set theme of widget style -########################################################################## -if OPTS[:list] || OPTS[:verbose] - print "supported theme names: #{ThemesList.inspect}\n" - exit if OPTS[:list] && ARGV.empty? -end -print "use theme: \"#{OPTS[:theme]}\"\n" if OPTS[:theme] && OPTS[:verbose] -setTheme(OPTS[:theme]) if OPTS[:theme] +trace_var(:$program_name){|val| + unless progname_obj.object_id == val.object_id + progname_obj.replace(val.to_s) + $program_name = progname_obj + end +} ########################################################################## # load script ########################################################################## -if (script = File.expand_path(ARGV.shift)) +if (path = ARGV.shift) && (script = File.expand_path(path)) print "load script \"#{script}\"\n" if OPTS[:verbose] + $0 = script load(script) else print "Error: no script is given.\n" diff --git a/ext/tk/tcltklib.c b/ext/tk/tcltklib.c index 18e0fd76fb..7fa85daecc 100644 --- a/ext/tk/tcltklib.c +++ b/ext/tk/tcltklib.c @@ -4,7 +4,7 @@ * Oct. 24, 1997 Y. Matsumoto */ -#define TCLTKLIB_RELEASE_DATE "2008-03-29" +#define TCLTKLIB_RELEASE_DATE "2008-06-11" #include "ruby.h" @@ -171,7 +171,7 @@ static ID ID_inspect; static VALUE ip_invoke_real _((int, VALUE*, VALUE)); static VALUE ip_invoke _((int, VALUE*, VALUE)); - +static VALUE ip_invoke_with_position _((int, VALUE*, VALUE, Tcl_QueuePosition)); static VALUE tk_funcall _((VALUE(), int, VALUE*, VALUE)); /* Tcl's object type */ @@ -189,6 +189,10 @@ static Tcl_ObjType *Tcl_ObjType_String; #endif #endif +#ifndef HAVE_RB_HASH_LOOKUP +#define rb_hash_lookup rb_hash_aref +#endif + /* safe Tcl_Eval and Tcl_GlobalEval */ static int #ifdef RUBY_VM @@ -393,19 +397,24 @@ static VALUE eventloop_thread; Tcl_ThreadId tk_eventloop_thread_id; /* native thread ID of Tcl interpreter */ #endif static VALUE eventloop_stack; -static int window_event_mode = ~(TCL_WINDOW_EVENTS | TCL_IDLE_EVENTS); +static int window_event_mode = ( ~ TCL_IDLE_EVENTS | TCL_WINDOW_EVENTS ); static VALUE watchdog_thread; Tcl_Interp *current_interp; /* thread control strategy */ -#define CONTROL_BY_STATUS_OF_RB_THREAD_WAIT_FOR_VALUE 0 +/* multi-tk works with the following settings only ??? + : CONTROL_BY_STATUS_OF_RB_THREAD_WAITING_FOR_VALUE 1 + : USE_TOGGLE_WINDOW_MODE_FOR_IDLE 0 + : DO_THREAD_SCHEDULE_AT_CALLBACK_DONE 0 +*/ +#define CONTROL_BY_STATUS_OF_RB_THREAD_WAITING_FOR_VALUE 1 #define USE_TOGGLE_WINDOW_MODE_FOR_IDLE 0 -#define DO_THREAD_SCHEDULE_AT_CALLBACK_DONE 1 +#define DO_THREAD_SCHEDULE_AT_CALLBACK_DONE 0 -#if CONTROL_BY_STATUS_OF_RB_THREAD_WAIT_FOR_VALUE -static int have_rb_thread_waited_for_value = 0; +#if CONTROL_BY_STATUS_OF_RB_THREAD_WAITING_FOR_VALUE +static int have_rb_thread_waiting_for_value = 0; #endif /* @@ -422,9 +431,6 @@ static int have_rb_thread_waited_for_value = 0; #define WATCHDOG_INTERVAL 10/*milliseconds ( 1 -- 999 ) */ #define DEFAULT_TIMER_TICK 0/*milliseconds ( 0 -- 999 ) */ #define NO_THREAD_INTERRUPT_TIME 100/*milliseconds ( 1 -- 999 ) */ -#if CONTROL_BY_STATUS_OF_RB_THREAD_WAIT_FOR_VALUE -#define DEFAULT_HAS_WAIT_THREAD_TICK 50/*counts*/ -#endif #else /* ! RUBY_VM */ #define DEFAULT_EVENT_LOOP_MAX 800/*counts*/ #define DEFAULT_NO_EVENT_TICK 10/*counts*/ @@ -432,9 +438,6 @@ static int have_rb_thread_waited_for_value = 0; #define WATCHDOG_INTERVAL 10/*milliseconds ( 1 -- 999 ) */ #define DEFAULT_TIMER_TICK 0/*milliseconds ( 0 -- 999 ) */ #define NO_THREAD_INTERRUPT_TIME 100/*milliseconds ( 1 -- 999 ) */ -#if CONTROL_BY_STATUS_OF_RB_THREAD_WAIT_FOR_VALUE -#define DEFAULT_HAS_WAIT_THREAD_TICK 50/*counts*/ -#endif #endif static int event_loop_max = DEFAULT_EVENT_LOOP_MAX; @@ -443,9 +446,6 @@ static int no_event_wait = DEFAULT_NO_EVENT_WAIT; static int timer_tick = DEFAULT_TIMER_TICK; static int req_timer_tick = DEFAULT_TIMER_TICK; static int run_timer_flag = 0; -#if CONTROL_BY_STATUS_OF_RB_THREAD_WAIT_FOR_VALUE -static int has_wait_thread_tick = DEFAULT_HAS_WAIT_THREAD_TICK; -#endif static int event_loop_wait_event = 0; static int event_loop_abort_on_exc = 1; @@ -963,8 +963,10 @@ call_original_exit(ptr, state) int thr_crit_bup; Tcl_CmdInfo *info; #if TCL_MAJOR_VERSION >= 8 + Tcl_Obj *cmd_obj; Tcl_Obj *state_obj; #endif + DUMP1("original_exit is called"); if (!(ptr->has_orig_exit)) return; @@ -982,35 +984,54 @@ call_original_exit(ptr, state) if (info->isNativeObjectProc) { Tcl_Obj **argv; - /* argv = (Tcl_Obj **)ALLOC_N(Tcl_Obj *, 3); */ /* XXXXXXXXXX */ +#define USE_RUBY_ALLOC 0 +#if USE_RUBY_ALLOC + argv = (Tcl_Obj **)ALLOC_N(Tcl_Obj *, 3); +#else /* not USE_RUBY_ALLOC */ argv = (Tcl_Obj **)ckalloc(sizeof(Tcl_Obj *) * 3); #if 0 /* use Tcl_Preserve/Release */ Tcl_Preserve((ClientData)argv); /* XXXXXXXX */ #endif - argv[0] = Tcl_NewStringObj("exit", 4); +#endif + cmd_obj = Tcl_NewStringObj("exit", 4); + Tcl_IncrRefCount(cmd_obj); + + argv[0] = cmd_obj; argv[1] = state_obj; argv[2] = (Tcl_Obj *)NULL; ptr->return_value = (*(info->objProc))(info->objClientData, ptr->ip, 2, argv); + Tcl_DecrRefCount(cmd_obj); + +#if USE_RUBY_ALLOC + free(argv); +#else /* not USE_RUBY_ALLOC */ #if 0 /* use Tcl_EventuallyFree */ Tcl_EventuallyFree((ClientData)argv, TCL_DYNAMIC); /* XXXXXXXX */ #else #if 0 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)argv); /* XXXXXXXX */ -#endif +#else /* free(argv); */ ckfree((char*)argv); #endif +#endif +#endif +#undef USE_RUBY_ALLOC } else { /* string interface */ char **argv; - /* argv = (char **)ALLOC_N(char *, 3); */ /* XXXXXXXXXX */ +#define USE_RUBY_ALLOC 0 +#if USE_RUBY_ALLOC + argv = (char **)ALLOC_N(char *, 3); /* XXXXXXXXXX */ +#else /* not USE_RUBY_ALLOC */ argv = (char **)ckalloc(sizeof(char *) * 3); #if 0 /* use Tcl_Preserve/Release */ Tcl_Preserve((ClientData)argv); /* XXXXXXXX */ +#endif #endif argv[0] = "exit"; /* argv[1] = Tcl_GetString(state_obj); */ @@ -1020,15 +1041,21 @@ call_original_exit(ptr, state) ptr->return_value = (*(info->proc))(info->clientData, ptr->ip, 2, (CONST84 char **)argv); +#if USE_RUBY_ALLOC + free(argv); +#else /* not USE_RUBY_ALLOC */ #if 0 /* use Tcl_EventuallyFree */ Tcl_EventuallyFree((ClientData)argv, TCL_DYNAMIC); /* XXXXXXXX */ #else #if 0 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)argv); /* XXXXXXXX */ -#endif +#else /* free(argv); */ ckfree((char*)argv); #endif +#endif +#endif +#undef USE_RUBY_ALLOC } Tcl_DecrRefCount(state_obj); @@ -1037,10 +1064,14 @@ call_original_exit(ptr, state) { /* string interface */ char **argv; - /* argv = (char **)ALLOC_N(char *, 3); */ +#define USE_RUBY_ALLOC 0 +#if USE_RUBY_ALLOC + argv = (char **)ALLOC_N(char *, 3); +#else /* not USE_RUBY_ALLOC */ argv = (char **)ckalloc(sizeof(char *) * 3); #if 0 /* use Tcl_Preserve/Release */ Tcl_Preserve((ClientData)argv); /* XXXXXXXX */ +#endif #endif argv[0] = "exit"; argv[1] = RSTRING_PTR(rb_fix2str(INT2NUM(state), 10)); @@ -1049,17 +1080,24 @@ call_original_exit(ptr, state) ptr->return_value = (*(info->proc))(info->clientData, ptr->ip, 2, argv); +#if USE_RUBY_ALLOC + free(argv); +#else /* not USE_RUBY_ALLOC */ #if 0 /* use Tcl_EventuallyFree */ Tcl_EventuallyFree((ClientData)argv, TCL_DYNAMIC); /* XXXXXXXX */ #else #if 0 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)argv); /* XXXXXXXX */ -#endif +#else /* free(argv); */ ckfree(argv); #endif +#endif +#endif +#undef USE_RUBY_ALLOC } #endif + DUMP1("complete original_exit"); rb_thread_critical = thr_crit_bup; } @@ -1106,10 +1144,14 @@ static int toggle_eventloop_window_mode_for_idle() { if (window_event_mode & TCL_IDLE_EVENTS) { + /* idle -> event */ + window_event_mode |= TCL_WINDOW_EVENTS; window_event_mode &= ~TCL_IDLE_EVENTS; return 1; } else { + /* event -> idle */ window_event_mode |= TCL_IDLE_EVENTS; + window_event_mode &= ~TCL_WINDOW_EVENTS; return 0; } } @@ -1439,7 +1481,11 @@ static VALUE lib_num_of_mainwindows(self) VALUE self; { +#ifdef RUBY_VM /* Ruby 1.9+ !!! */ return tk_funcall(lib_num_of_mainwindows_core, 0, (VALUE*)NULL, self); +#else + return lib_num_of_mainwindows_core(self, 0, (VALUE*)NULL); +#endif } @@ -1785,10 +1831,10 @@ lib_eventloop_core(check_root, update_flag, check_var, interp) if (!st) { if (toggle_eventloop_window_mode_for_idle()) { /* idle-mode -> event-mode*/ - tick_counter = 0; + tick_counter = event_loop_max; } else { /* event-mode -> idle-mode */ - tick_counter = event_loop_max; + tick_counter = 0; } } #endif @@ -1798,6 +1844,14 @@ lib_eventloop_core(check_root, update_flag, check_var, interp) st = RTEST(rb_protect(call_DoOneEvent, INT2FIX(event_flag), &status)); #endif + +#if CONTROL_BY_STATUS_OF_RB_THREAD_WAITING_FOR_VALUE + if (have_rb_thread_waiting_for_value) { + have_rb_thread_waiting_for_value = 0; + rb_thread_schedule(); + } +#endif + if (status) { switch (status) { case TAG_RAISE: @@ -1873,13 +1927,6 @@ lib_eventloop_core(check_root, update_flag, check_var, interp) return 0; } -#if CONTROL_BY_STATUS_OF_RB_THREAD_WAIT_FOR_VALUE - if (have_rb_thread_waited_for_value) { - tick_counter += no_event_tick; - have_rb_thread_waited_for_value = 0; - } -#endif - if (st) { tick_counter++; } else { @@ -1946,7 +1993,8 @@ lib_eventloop_core(check_root, update_flag, check_var, interp) } else { DUMP2("sleep eventloop %lx", current); DUMP2("eventloop thread is %lx", eventloop_thread); - rb_thread_stop(); + /* rb_thread_stop(); */ + rb_thread_sleep_forever(); } if (!NIL_P(watchdog_thread) && eventloop_thread != current) { @@ -2122,7 +2170,11 @@ lib_eventloop_ensure(args) break; } +#ifdef RUBY_VM if (RTEST(rb_funcall(eventloop_thread, ID_alive_p, 0, 0))) { +#else + if (RTEST(rb_thread_alive_p(eventloop_thread))) { +#endif DUMP2("eventloop-enshure: wake up parent %lx", eventloop_thread); rb_thread_wakeup(eventloop_thread); @@ -2440,7 +2492,11 @@ lib_thread_callback(argc, argv, self) foundEvent = RTEST(lib_eventloop_launcher(/* not check root-widget */0, 0, q->done, (Tcl_Interp*)NULL)); +#ifdef RUBY_VM if (RTEST(rb_funcall(th, ID_alive_p, 0))) { +#else + if (RTEST(rb_thread_alive_p(th))) { +#endif rb_funcall(th, ID_kill, 0); ret = Qnil; } else { @@ -2581,10 +2637,12 @@ ip_set_exc_message(interp, exc) if (NIL_P(enc)) { encoding = (Tcl_Encoding)NULL; } else if (TYPE(enc) == T_STRING) { - encoding = Tcl_GetEncoding(interp, RSTRING_PTR(enc)); + /* encoding = Tcl_GetEncoding(interp, RSTRING_PTR(enc)); */ + encoding = Tcl_GetEncoding((Tcl_Interp*)NULL, RSTRING_PTR(enc)); } else { enc = rb_funcall(enc, ID_to_s, 0, 0); - encoding = Tcl_GetEncoding(interp, RSTRING_PTR(enc)); + /* encoding = Tcl_GetEncoding(interp, RSTRING_PTR(enc)); */ + encoding = Tcl_GetEncoding((Tcl_Interp*)NULL, RSTRING_PTR(enc)); } /* to avoid a garbled error message dialog */ @@ -2652,12 +2710,15 @@ tcl_protect_core(interp, proc, data) /* should not raise exception */ int status = 0; int thr_crit_bup = rb_thread_critical; + Tcl_ResetResult(interp); + rb_thread_critical = Qfalse; ret = rb_protect(proc, data, &status); rb_thread_critical = Qtrue; if (status) { char *buf; - VALUE old_gc, type, str; + VALUE old_gc; + volatile VALUE type, str; old_gc = rb_gc_disable(); @@ -3119,10 +3180,6 @@ ip_ruby_cmd(clientData, interp, argc, argv) #endif } - /* allocate */ - arg = ALLOC(struct cmd_body_arg); - /* arg = (struct cmd_body_arg *)ckalloc(sizeof(struct cmd_body_arg)); */ - /* get arguments from Tcl objects */ thr_crit_bup = rb_thread_critical; rb_thread_critical = Qtrue; @@ -3147,6 +3204,7 @@ ip_ruby_cmd(clientData, interp, argc, argv) str, "'", (char *)NULL); rbtk_pending_exception = rb_exc_new2(rb_eArgError, Tcl_GetStringResult(interp)); + if (old_gc == Qfalse) rb_gc_enable(); return TCL_ERROR; #endif } @@ -3187,6 +3245,10 @@ ip_ruby_cmd(clientData, interp, argc, argv) if (old_gc == Qfalse) rb_gc_enable(); rb_thread_critical = thr_crit_bup; + /* allocate */ + arg = ALLOC(struct cmd_body_arg); + /* arg = (struct cmd_body_arg *)ckalloc(sizeof(struct cmd_body_arg)); */ + arg->receiver = receiver; arg->method = method; arg->args = args; @@ -3386,6 +3448,8 @@ ip_rbUpdateCommand(clientData, interp, objc, objv) #endif #endif + Tcl_ResetResult(interp); + if (objc == 1) { flags = TCL_DONT_WAIT; @@ -3554,6 +3618,8 @@ ip_rb_threadUpdateCommand(clientData, interp, objc, objv) DUMP1("start Ruby's 'thread_update' body"); + Tcl_ResetResult(interp); + if (objc == 1) { flags = TCL_DONT_WAIT; @@ -3613,7 +3679,8 @@ ip_rb_threadUpdateCommand(clientData, interp, objc, objv) while(!param->done) { DUMP1("wait for complete idle proc"); - rb_thread_stop(); + /* rb_thread_stop(); */ + rb_thread_sleep_forever(); } #if 0 /* use Tcl_EventuallyFree */ @@ -3621,9 +3688,10 @@ ip_rb_threadUpdateCommand(clientData, interp, objc, objv) #else #if 0 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)param); -#endif +#else /* Tcl_Free((char *)param); */ ckfree((char *)param); +#endif #endif DUMP1("finish Ruby's 'thread_update'"); @@ -3736,6 +3804,8 @@ ip_rbVwaitCommand(clientData, interp, objc, objv) #endif #endif + Tcl_ResetResult(interp); + if (objc != 2) { #ifdef Tcl_WrongNumArgs Tcl_WrongNumArgs(interp, 1, objv, "name"); @@ -3971,6 +4041,7 @@ ip_rbTkWaitCommand(clientData, interp, objc, objv) #endif Tcl_Preserve(interp); + Tcl_ResetResult(interp); if (objc != 3) { #ifdef Tcl_WrongNumArgs @@ -4327,7 +4398,7 @@ rb_threadVwaitProc(clientData, interp, name1, name2, flags) } else { param->done = 1; } - rb_thread_wakeup(param->thread); + if (param->done != 0) rb_thread_wakeup(param->thread); return (char *)NULL; } @@ -4349,7 +4420,7 @@ rb_threadWaitVisibilityProc(clientData, eventPtr) if (eventPtr->type == DestroyNotify) { param->done = TKWAIT_MODE_DESTROY; } - rb_thread_wakeup(param->thread); + if (param->done != 0) rb_thread_wakeup(param->thread); } static void rb_threadWaitWindowProc _((ClientData, XEvent *)); @@ -4363,7 +4434,7 @@ rb_threadWaitWindowProc(clientData, eventPtr) if (eventPtr->type == DestroyNotify) { param->done = TKWAIT_MODE_DESTROY; } - rb_thread_wakeup(param->thread); + if (param->done != 0) rb_thread_wakeup(param->thread); } #if TCL_MAJOR_VERSION >= 8 @@ -4406,6 +4477,7 @@ ip_rb_threadVwaitCommand(clientData, interp, objc, objv) } Tcl_Preserve(interp); + Tcl_ResetResult(interp); if (objc != 2) { #ifdef Tcl_WrongNumArgs @@ -4442,7 +4514,7 @@ ip_rb_threadVwaitCommand(clientData, interp, objc, objv) /* param = (struct th_vwait_param *)Tcl_Alloc(sizeof(struct th_vwait_param)); */ param = (struct th_vwait_param *)ckalloc(sizeof(struct th_vwait_param)); -#if 0 /* use Tcl_Preserve/Release */ +#if 1 /* use Tcl_Preserve/Release */ Tcl_Preserve((ClientData)param); #endif param->thread = current_thread; @@ -4465,12 +4537,13 @@ ip_rb_threadVwaitCommand(clientData, interp, objc, objv) #if 0 /* use Tcl_EventuallyFree */ Tcl_EventuallyFree((ClientData)param, TCL_DYNAMIC); /* XXXXXXXX */ #else -#if 0 /* use Tcl_Preserve/Release */ +#if 1 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)param); -#endif +#else /* Tcl_Free((char *)param); */ ckfree((char *)param); #endif +#endif #if TCL_MAJOR_VERSION >= 8 Tcl_DecrRefCount(objv[1]); @@ -4479,9 +4552,9 @@ ip_rb_threadVwaitCommand(clientData, interp, objc, objv) return TCL_ERROR; } - /* if (!param->done) { */ while(!param->done) { - rb_thread_stop(); + /* rb_thread_stop(); */ + rb_thread_sleep_forever(); } thr_crit_bup = rb_thread_critical; @@ -4496,11 +4569,12 @@ ip_rb_threadVwaitCommand(clientData, interp, objc, objv) #if 0 /* use Tcl_EventuallyFree */ Tcl_EventuallyFree((ClientData)param, TCL_DYNAMIC); /* XXXXXXXX */ #else -#if 0 /* use Tcl_Preserve/Release */ +#if 1 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)param); -#endif +#else /* Tcl_Free((char *)param); */ ckfree((char *)param); +#endif #endif rb_thread_critical = thr_crit_bup; @@ -4560,6 +4634,8 @@ ip_rb_threadTkWaitCommand(clientData, interp, objc, objv) Tcl_Preserve(interp); Tcl_Preserve(tkwin); + Tcl_ResetResult(interp); + if (objc != 3) { #ifdef Tcl_WrongNumArgs Tcl_WrongNumArgs(interp, 1, objv, "variable|visibility|window name"); @@ -4644,7 +4720,7 @@ ip_rb_threadTkWaitCommand(clientData, interp, objc, objv) /* param = (struct th_vwait_param *)Tcl_Alloc(sizeof(struct th_vwait_param)); */ param = (struct th_vwait_param *)ckalloc(sizeof(struct th_vwait_param)); -#if 0 /* use Tcl_Preserve/Release */ +#if 1 /* use Tcl_Preserve/Release */ Tcl_Preserve((ClientData)param); #endif param->thread = current_thread; @@ -4673,12 +4749,13 @@ ip_rb_threadTkWaitCommand(clientData, interp, objc, objv) #if 0 /* use Tcl_EventuallyFree */ Tcl_EventuallyFree((ClientData)param, TCL_DYNAMIC); /* XXXXXXXX */ #else -#if 0 /* use Tcl_Preserve/Release */ +#if 1 /* use Tcl_Preserve/Release */ Tcl_Release(param); -#endif +#else /* Tcl_Free((char *)param); */ ckfree((char *)param); #endif +#endif #if TCL_MAJOR_VERSION >= 8 Tcl_DecrRefCount(objv[2]); @@ -4689,9 +4766,9 @@ ip_rb_threadTkWaitCommand(clientData, interp, objc, objv) return TCL_ERROR; } - /* if (!param->done) { */ while(!param->done) { - rb_thread_stop(); + /* rb_thread_stop(); */ + rb_thread_sleep_forever(); } thr_crit_bup = rb_thread_critical; @@ -4745,12 +4822,13 @@ ip_rb_threadTkWaitCommand(clientData, interp, objc, objv) #if 0 /* use Tcl_EventuallyFree */ Tcl_EventuallyFree((ClientData)param, TCL_DYNAMIC); /* XXXXXXXX */ #else -#if 0 /* use Tcl_Preserve/Release */ +#if 1 /* use Tcl_Preserve/Release */ Tcl_Release(param); -#endif +#else /* Tcl_Free((char *)param); */ ckfree((char *)param); #endif +#endif #if TCL_MAJOR_VERSION >= 8 Tcl_DecrRefCount(objv[2]); @@ -4767,15 +4845,10 @@ ip_rb_threadTkWaitCommand(clientData, interp, objc, objv) rb_thread_critical = thr_crit_bup; - /* if (!param->done) { */ - /* - while(!param->done) { - rb_thread_stop(); - } - */ while(param->done != TKWAIT_MODE_VISIBILITY) { if (param->done == TKWAIT_MODE_DESTROY) break; - rb_thread_stop(); + /* rb_thread_stop(); */ + rb_thread_sleep_forever(); } thr_crit_bup = rb_thread_critical; @@ -4802,12 +4875,13 @@ ip_rb_threadTkWaitCommand(clientData, interp, objc, objv) #if 0 /* use Tcl_EventuallyFree */ Tcl_EventuallyFree((ClientData)param, TCL_DYNAMIC); /* XXXXXXXX */ #else -#if 0 /* use Tcl_Preserve/Release */ +#if 1 /* use Tcl_Preserve/Release */ Tcl_Release(param); -#endif +#else /* Tcl_Free((char *)param); */ ckfree((char *)param); #endif +#endif #if TCL_MAJOR_VERSION >= 8 Tcl_DecrRefCount(objv[2]); @@ -4866,11 +4940,12 @@ ip_rb_threadTkWaitCommand(clientData, interp, objc, objv) #if 0 /* use Tcl_EventuallyFree */ Tcl_EventuallyFree((ClientData)param, TCL_DYNAMIC); /* XXXXXXXX */ #else -#if 0 /* use Tcl_Preserve/Release */ +#if 1 /* use Tcl_Preserve/Release */ Tcl_Release(param); -#endif +#else /* Tcl_Free((char *)param); */ ckfree((char *)param); +#endif #endif Tcl_Release(tkwin); @@ -4885,14 +4960,9 @@ ip_rb_threadTkWaitCommand(clientData, interp, objc, objv) rb_thread_critical = thr_crit_bup; - /* if (!param->done) { */ - /* - while(!param->done) { - rb_thread_stop(); - } - */ while(param->done != TKWAIT_MODE_DESTROY) { - rb_thread_stop(); + /* rb_thread_stop(); */ + rb_thread_sleep_forever(); } Tcl_Release(window); @@ -4913,11 +4983,12 @@ ip_rb_threadTkWaitCommand(clientData, interp, objc, objv) #if 0 /* use Tcl_EventuallyFree */ Tcl_EventuallyFree((ClientData)param, TCL_DYNAMIC); /* XXXXXXXX */ #else -#if 0 /* use Tcl_Preserve/Release */ +#if 1 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)param); -#endif +#else /* Tcl_Free((char *)param); */ ckfree((char *)param); +#endif #endif /* @@ -4943,7 +5014,7 @@ ip_thread_vwait(self, var) argv[0] = cmd_str; argv[1] = var; - return ip_invoke_real(2, argv, self); + return ip_invoke_with_position(2, argv, self, TCL_QUEUE_TAIL); } static VALUE @@ -4959,7 +5030,7 @@ ip_thread_tkwait(self, mode, target) argv[1] = mode; argv[2] = target; - return ip_invoke_real(3, argv, self); + return ip_invoke_with_position(3, argv, self, TCL_QUEUE_TAIL); } @@ -5149,14 +5220,18 @@ ip_finalize(ip) Tcl_CreateCommand(ip, "ruby_cmd", ip_null_proc, (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL); #endif + /* + rb_thread_critical = thr_crit_bup; + return; + */ } /* delete root widget */ -#if 0 +#if 1 DUMP1("check `destroy'"); if (Tcl_GetCommandInfo(ip, "destroy", &info)) { - DUMP1("call `destroy'"); - Tcl_GlobalEval(ip, "destroy ."); + DUMP1("call `destroy .'"); + Tcl_GlobalEval(ip, "catch {destroy .}"); } #endif #if 1 @@ -5174,10 +5249,14 @@ ip_finalize(ip) * Although it is the problem, it is possibly avoidable by * rescuing exceptions and the finalize hook of the interp. */ + Tk_Window win = Tk_MainWindow(ip); + DUMP1("call Tk_DestroyWindow"); ruby_debug = Qfalse; ruby_verbose = Qnil; - Tk_DestroyWindow(Tk_MainWindow(ip)); + if (! (((Tk_FakeWin*)win)->flags & TK_ALREADY_DEAD)) { + Tk_DestroyWindow(win); + } ruby_debug = rb_debug_bup; ruby_verbose = rb_verbose_bup; } @@ -5200,7 +5279,7 @@ ip_finalize(ip) DUMP1("cancel after callbacks"); ruby_debug = Qfalse; ruby_verbose = Qnil; - Tcl_GlobalEval(ip, "foreach id [after info] {after cancel $id}"); + Tcl_GlobalEval(ip, "catch {foreach id [after info] {after cancel $id}}"); ruby_debug = rb_debug_bup; ruby_verbose = rb_verbose_bup; } @@ -5242,8 +5321,8 @@ ip_free(ptr) if (ptr->ip == (Tcl_Interp*)NULL) { DUMP1("ip_free is called for deleted IP"); - /* free(ptr); */ - ckfree((char*)ptr); + free(ptr); + /* ckfree((char*)ptr); */ rb_thread_critical = thr_crit_bup; return; } @@ -5396,9 +5475,10 @@ ip_rbNamespaceObjCmd(clientData, interp, objc, objv) #else #if 0 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)argv); /* XXXXXXXX */ -#endif +#else /* Tcl_Free((char*)argv); */ ckfree((char*)argv); +#endif #endif } @@ -6273,12 +6353,12 @@ call_queue_handler(evPtr, flags) struct call_queue *q = (struct call_queue *)evPtr; volatile VALUE ret; volatile VALUE q_dat; + volatile VALUE thread = q->thread; struct tcltkip *ptr; DUMP2("do_call_queue_handler : evPtr = %p", evPtr); DUMP2("call_queue_handler thread : %lx", rb_thread_current()); - DUMP2("added by thread : %lx", q->thread); - + DUMP2("added by thread : %lx", thread); if (*(q->done)) { DUMP1("processed by another event-loop"); @@ -6287,6 +6367,17 @@ call_queue_handler(evPtr, flags) DUMP1("process it on current event-loop"); } +#ifdef RUBY_VM + if (RTEST(rb_funcall(thread, ID_alive_p, 0)) + && ! RTEST(rb_funcall(thread, ID_stop_p, 0))) { +#else + if (RTEST(rb_thread_alive_p(thread)) + && ! RTEST(rb_funcall(thread, ID_stop_p, 0))) { +#endif + DUMP1("caller is not yet ready to receive the result -> pending"); + return 0; + } + /* process it */ *(q->done) = 1; @@ -6307,14 +6398,16 @@ call_queue_handler(evPtr, flags) ret = rb_funcall(rb_proc_new(callq_safelevel_handler, q_dat), ID_call, 0); rb_gc_force_recycle(q_dat); + q_dat = (VALUE)NULL; } else { - DUMP2("call function (for caller thread:%lx)", q->thread); + DUMP2("call function (for caller thread:%lx)", thread); DUMP2("call function (current thread:%lx)", rb_thread_current()); ret = (q->func)(q->interp, q->argc, q->argv); } /* set result */ RARRAY_PTR(q->result)[0] = ret; + ret = (VALUE)NULL; /* decr internal handler mark */ rbtk_internal_eventloop_handler--; @@ -6322,22 +6415,32 @@ call_queue_handler(evPtr, flags) /* complete */ *(q->done) = -1; + /* unlink ruby objects */ + q->argv = (VALUE*)NULL; + q->interp = (VALUE)NULL; + q->result = (VALUE)NULL; + q->thread = (VALUE)NULL; + /* back to caller */ - if (RTEST(rb_funcall(q->thread, ID_alive_p, 0, 0))) { - DUMP2("back to caller (caller thread:%lx)", q->thread); +#ifdef RUBY_VM + if (RTEST(rb_funcall(thread, ID_alive_p, 0, 0))) { +#else + if (RTEST(rb_thread_alive_p(thread))) { +#endif + DUMP2("back to caller (caller thread:%lx)", thread); DUMP2(" (current thread:%lx)", rb_thread_current()); -#if CONTROL_BY_STATUS_OF_RB_THREAD_WAIT_FOR_VALUE - have_rb_thread_waited_for_value = 1; - rb_thread_wakeup(q->thread); +#if CONTROL_BY_STATUS_OF_RB_THREAD_WAITING_FOR_VALUE + have_rb_thread_waiting_for_value = 1; + rb_thread_wakeup(thread); #else - rb_thread_run(q->thread); + rb_thread_run(thread); #endif DUMP1("finish back to caller"); #if DO_THREAD_SCHEDULE_AT_CALLBACK_DONE rb_thread_schedule(); #endif } else { - DUMP2("caller is dead (caller thread:%lx)", q->thread); + DUMP2("caller is dead (caller thread:%lx)", thread); DUMP2(" (current thread:%lx)", rb_thread_current()); } @@ -6425,7 +6528,7 @@ tk_funcall(func, argc, argv, obj) /* allocate memory (freed by Tcl_ServiceEvent) */ /* callq = (struct call_queue *)Tcl_Alloc(sizeof(struct call_queue)); */ callq = (struct call_queue *)ckalloc(sizeof(struct call_queue)); -#if 1 /* use Tcl_Preserve/Release */ +#if 0 /* use Tcl_Preserve/Release */ Tcl_Preserve(callq); #endif @@ -6447,17 +6550,24 @@ tk_funcall(func, argc, argv, obj) DUMP1("add handler"); #ifdef RUBY_VM if (ptr && ptr->tk_thread_id) { - Tcl_ThreadQueueEvent(ptr->tk_thread_id, &(callq->ev), TCL_QUEUE_HEAD); + /* Tcl_ThreadQueueEvent(ptr->tk_thread_id, + &(callq->ev), TCL_QUEUE_HEAD); */ + Tcl_ThreadQueueEvent(ptr->tk_thread_id, + (Tcl_Event*)callq, TCL_QUEUE_HEAD); Tcl_ThreadAlert(ptr->tk_thread_id); } else if (tk_eventloop_thread_id) { + /* Tcl_ThreadQueueEvent(tk_eventloop_thread_id, + &(callq->ev), TCL_QUEUE_HEAD); */ Tcl_ThreadQueueEvent(tk_eventloop_thread_id, - &(callq->ev), TCL_QUEUE_HEAD); + (Tcl_Event*)callq, TCL_QUEUE_HEAD); Tcl_ThreadAlert(tk_eventloop_thread_id); } else { - Tcl_QueueEvent(&(callq->ev), TCL_QUEUE_HEAD); + /* Tcl_QueueEvent(&(callq->ev), TCL_QUEUE_HEAD); */ + Tcl_QueueEvent((Tcl_Event*)callq, TCL_QUEUE_HEAD); } #else - Tcl_QueueEvent(&(callq->ev), TCL_QUEUE_HEAD); + /* Tcl_QueueEvent(&(callq->ev), TCL_QUEUE_HEAD); */ + Tcl_QueueEvent((Tcl_Event*)callq, TCL_QUEUE_HEAD); #endif rb_thread_critical = thr_crit_bup; @@ -6466,7 +6576,8 @@ tk_funcall(func, argc, argv, obj) DUMP2("wait for handler (current thread:%lx)", current); while(*alloc_done >= 0) { DUMP2("*** wait for handler (current thread:%lx)", current); - rb_thread_stop(); + /* rb_thread_stop(); */ + rb_thread_sleep_forever(); DUMP2("*** wakeup (current thread:%lx)", current); } DUMP2("back from handler (current thread:%lx)", current); @@ -6478,27 +6589,34 @@ tk_funcall(func, argc, argv, obj) #else #if 0 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)alloc_done); /* XXXXXXXX */ -#endif +#else /* free(alloc_done); */ ckfree((char*)alloc_done); +#endif #endif /* if (argv) free(argv); */ if (argv) { /* if argv != NULL, alloc as 'temp' */ + int i; + for(i = 0; i < argc; i++) { argv[i] = (VALUE)NULL; } + #if 0 /* use Tcl_EventuallyFree */ Tcl_EventuallyFree((ClientData)argv, TCL_DYNAMIC); /* XXXXXXXX */ #else #if 0 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)argv); /* XXXXXXXX */ -#endif +#else ckfree((char*)argv); +#endif #endif } -#if 1 /* use Tcl_Preserve/Release */ +#if 0 /* callq is freed by Tcl_ServiceEvent */ +#if 0 /* use Tcl_Preserve/Release */ Tcl_Release(callq); #else ckfree((char*)callq); +#endif #endif /* exception? */ @@ -6620,11 +6738,26 @@ ip_eval_real(self, cmd_str, cmd_len) return rbtk_pending_exception; } - if (ptr->return_value == TCL_ERROR) { + /* if (ptr->return_value == TCL_ERROR) { */ + if (ptr->return_value != TCL_OK) { if (event_loop_abort_on_exc > 0 && !Tcl_InterpDeleted(ptr->ip)) { volatile VALUE exc; - exc = create_ip_exc(self, rb_eRuntimeError, - "%s", Tcl_GetStringResult(ptr->ip)); + + switch (ptr->return_value) { + case TCL_RETURN: + exc = create_ip_exc(self, eTkCallbackReturn, + "ip_eval_real receives TCL_RETURN"); + case TCL_BREAK: + exc = create_ip_exc(self, eTkCallbackBreak, + "ip_eval_real receives TCL_BREAK"); + case TCL_CONTINUE: + exc = create_ip_exc(self, eTkCallbackContinue, + "ip_eval_real receives TCL_CONTINUE"); + default: + exc = create_ip_exc(self, rb_eRuntimeError, "%s", + Tcl_GetStringResult(ptr->ip)); + } + rbtk_release_ip(ptr); rb_thread_critical = thr_crit_bup; return exc; @@ -6666,10 +6799,23 @@ ip_eval_real(self, cmd_str, cmd_len) return rbtk_pending_exception; } - if (ptr->return_value == TCL_ERROR) { + /* if (ptr->return_value == TCL_ERROR) { */ + if (ptr->return_value != TCL_OK) { volatile VALUE exc; - exc = create_ip_exc(self, rb_eRuntimeError, "%s", ptr->ip->result); + switch (ptr->return_value) { + case TCL_RETURN: + exc = create_ip_exc(self, eTkCallbackReturn, + "ip_eval_real receives TCL_RETURN"); + case TCL_BREAK: + exc = create_ip_exc(self, eTkCallbackBreak, + "ip_eval_real receives TCL_BREAK"); + case TCL_CONTINUE: + exc = create_ip_exc(self, eTkCallbackContinue, + "ip_eval_real receives TCL_CONTINUE"); + default: + exc = create_ip_exc(self, rb_eRuntimeError, "%s", ptr->ip->result); + } rbtk_release_ip(ptr); return exc; @@ -6705,11 +6851,12 @@ eval_queue_handler(evPtr, flags) struct eval_queue *q = (struct eval_queue *)evPtr; volatile VALUE ret; volatile VALUE q_dat; + volatile VALUE thread = q->thread; struct tcltkip *ptr; DUMP2("do_eval_queue_handler : evPtr = %p", evPtr); DUMP2("eval_queue_thread : %lx", rb_thread_current()); - DUMP2("added by thread : %lx", q->thread); + DUMP2("added by thread : %lx", thread); if (*(q->done)) { DUMP1("processed by another event-loop"); @@ -6718,6 +6865,17 @@ eval_queue_handler(evPtr, flags) DUMP1("process it on current event-loop"); } +#ifdef RUBY_VM + if (RTEST(rb_funcall(thread, ID_alive_p, 0)) + && ! RTEST(rb_funcall(thread, ID_stop_p, 0))) { +#else + if (RTEST(rb_thread_alive_p(thread)) + && ! RTEST(rb_funcall(thread, ID_stop_p, 0))) { +#endif + DUMP1("caller is not yet ready to receive the result -> pending"); + return 0; + } + /* process it */ *(q->done) = 1; @@ -6751,12 +6909,14 @@ eval_queue_handler(evPtr, flags) ret = rb_funcall(rb_proc_new(evq_safelevel_handler, q_dat), ID_call, 0); rb_gc_force_recycle(q_dat); + q_dat = (VALUE)NULL; } else { ret = ip_eval_real(q->interp, q->str, q->len); } /* set result */ RARRAY_PTR(q->result)[0] = ret; + ret = (VALUE)NULL; /* decr internal handler mark */ rbtk_internal_eventloop_handler--; @@ -6764,22 +6924,31 @@ eval_queue_handler(evPtr, flags) /* complete */ *(q->done) = -1; + /* unlink ruby objects */ + q->interp = (VALUE)NULL; + q->result = (VALUE)NULL; + q->thread = (VALUE)NULL; + /* back to caller */ - if (RTEST(rb_funcall(q->thread, ID_alive_p, 0, 0))) { - DUMP2("back to caller (caller thread:%lx)", q->thread); +#ifdef RUBY_VM + if (RTEST(rb_funcall(thread, ID_alive_p, 0, 0))) { +#else + if (RTEST(rb_thread_alive_p(thread))) { +#endif + DUMP2("back to caller (caller thread:%lx)", thread); DUMP2(" (current thread:%lx)", rb_thread_current()); -#if CONTROL_BY_STATUS_OF_RB_THREAD_WAIT_FOR_VALUE - have_rb_thread_waited_for_value = 1; - rb_thread_wakeup(q->thread); +#if CONTROL_BY_STATUS_OF_RB_THREAD_WAITING_FOR_VALUE + have_rb_thread_waiting_for_value = 1; + rb_thread_wakeup(thread); #else - rb_thread_run(q->thread); + rb_thread_run(thread); #endif DUMP1("finish back to caller"); #if DO_THREAD_SCHEDULE_AT_CALLBACK_DONE rb_thread_schedule(); #endif } else { - DUMP2("caller is dead (caller thread:%lx)", q->thread); + DUMP2("caller is dead (caller thread:%lx)", thread); DUMP2(" (current thread:%lx)", rb_thread_current()); } @@ -6838,7 +7007,7 @@ ip_eval(self, str) thr_crit_bup = rb_thread_critical; rb_thread_critical = Qtrue; - /* allocate memory (protected from Tcl_ServiceEvent) */ + /* allocate memory (keep result) */ /* alloc_done = (int*)ALLOC(int); */ alloc_done = (int*)ckalloc(sizeof(int)); #if 0 /* use Tcl_Preserve/Release */ @@ -6857,7 +7026,7 @@ ip_eval(self, str) /* allocate memory (freed by Tcl_ServiceEvent) */ /* evq = (struct eval_queue *)Tcl_Alloc(sizeof(struct eval_queue)); */ evq = (struct eval_queue *)ckalloc(sizeof(struct eval_queue)); -#if 1 /* use Tcl_Preserve/Release */ +#if 0 /* use Tcl_Preserve/Release */ Tcl_Preserve(evq); #endif @@ -6880,13 +7049,21 @@ ip_eval(self, str) DUMP1("add handler"); #ifdef RUBY_VM if (ptr->tk_thread_id) { - Tcl_ThreadQueueEvent(ptr->tk_thread_id, &(evq->ev), position); + /* Tcl_ThreadQueueEvent(ptr->tk_thread_id, &(evq->ev), position); */ + Tcl_ThreadQueueEvent(ptr->tk_thread_id, (Tcl_Event*)evq, position); Tcl_ThreadAlert(ptr->tk_thread_id); + } else if (tk_eventloop_thread_id) { + Tcl_ThreadQueueEvent(tk_eventloop_thread_id, (Tcl_Event*)evq, position); + /* Tcl_ThreadQueueEvent(tk_eventloop_thread_id, + &(evq->ev), position); */ + Tcl_ThreadAlert(tk_eventloop_thread_id); } else { - Tcl_QueueEvent(&(evq->ev), position); + /* Tcl_QueueEvent(&(evq->ev), position); */ + Tcl_QueueEvent((Tcl_Event*)evq, position); } #else - Tcl_QueueEvent(&(evq->ev), position); + /* Tcl_QueueEvent(&(evq->ev), position); */ + Tcl_QueueEvent((Tcl_Event*)evq, position); #endif rb_thread_critical = thr_crit_bup; @@ -6895,7 +7072,8 @@ ip_eval(self, str) DUMP2("wait for handler (current thread:%lx)", current); while(*alloc_done >= 0) { DUMP2("*** wait for handler (current thread:%lx)", current); - rb_thread_stop(); + /* rb_thread_stop(); */ + rb_thread_sleep_forever(); DUMP2("*** wakeup (current thread:%lx)", current); } DUMP2("back from handler (current thread:%lx)", current); @@ -6908,23 +7086,27 @@ ip_eval(self, str) #else #if 0 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)alloc_done); /* XXXXXXXX */ -#endif +#else /* free(alloc_done); */ ckfree((char*)alloc_done); #endif +#endif #if 0 /* use Tcl_EventuallyFree */ Tcl_EventuallyFree((ClientData)eval_str, TCL_DYNAMIC); /* XXXXXXXX */ #else #if 0 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)eval_str); /* XXXXXXXX */ -#endif +#else /* free(eval_str); */ ckfree(eval_str); #endif -#if 1 /* use Tcl_Preserve/Release */ +#endif +#if 0 /* evq is freed by Tcl_ServiceEvent */ +#if 0 /* use Tcl_Preserve/Release */ Tcl_Release(evq); #else ckfree((char*)evq); +#endif #endif if (rb_obj_is_kind_of(ret, rb_eException)) { @@ -7100,11 +7282,18 @@ lib_toUTF8_core(ip_obj, src, encodename) if (NIL_P(enc)) { encoding = (Tcl_Encoding)NULL; } else { - StringValue(enc); - encoding = Tcl_GetEncoding(interp, RSTRING_PTR(enc)); - if (encoding == (Tcl_Encoding)NULL) { + /* StringValue(enc); */ + enc = rb_funcall(enc, ID_to_s, 0, 0); + /* encoding = Tcl_GetEncoding(interp, RSTRING_PTR(enc)); */ + if (!RSTRING_LEN(enc)) { + encoding = (Tcl_Encoding)NULL; + } else { + encoding = Tcl_GetEncoding((Tcl_Interp*)NULL, + RSTRING_PTR(enc)); + if (encoding == (Tcl_Encoding)NULL) { rb_warning("Tk-interp has unknown encoding information (@encoding:'%s')", RSTRING_PTR(enc)); - } + } + } } } } else { @@ -7117,7 +7306,9 @@ lib_toUTF8_core(ip_obj, src, encodename) rb_thread_critical = thr_crit_bup; return str; } - encoding = Tcl_GetEncoding(interp, RSTRING_PTR(enc)); + /* encoding = Tcl_GetEncoding(interp, RSTRING_PTR(enc)); */ + encoding = Tcl_GetEncoding((Tcl_Interp*)NULL, + RSTRING_PTR(enc)); if (encoding == (Tcl_Encoding)NULL) { rb_warning("string has unknown encoding information (@encoding:'%s')", RSTRING_PTR(enc)); } @@ -7135,7 +7326,8 @@ lib_toUTF8_core(ip_obj, src, encodename) rb_thread_critical = thr_crit_bup; return str; } - encoding = Tcl_GetEncoding(interp, RSTRING_PTR(encodename)); + /* encoding = Tcl_GetEncoding(interp, RSTRING_PTR(encodename)); */ + encoding = Tcl_GetEncoding((Tcl_Interp*)NULL, RSTRING_PTR(encodename)); if (encoding == (Tcl_Encoding)NULL) { /* rb_warning("unknown encoding name '%s'", @@ -7170,9 +7362,11 @@ lib_toUTF8_core(ip_obj, src, encodename) rb_ivar_set(str, ID_at_enc, ENCODING_NAME_UTF8); if (taint_flag) OBJ_TAINT(str); + /* if (encoding != (Tcl_Encoding)NULL) { Tcl_FreeEncoding(encoding); } + */ Tcl_DStringFree(&dstr); free(buf); @@ -7279,13 +7473,20 @@ lib_fromUTF8_core(ip_obj, src, encodename) if (NIL_P(enc)) { encoding = (Tcl_Encoding)NULL; } else { - StringValue(enc); - encoding = Tcl_GetEncoding(interp, RSTRING_PTR(enc)); - if (encoding == (Tcl_Encoding)NULL) { + /* StringValue(enc); */ + enc = rb_funcall(enc, ID_to_s, 0, 0); + /* encoding = Tcl_GetEncoding(interp, RSTRING_PTR(enc)); */ + if (!RSTRING_LEN(enc)) { + encoding = (Tcl_Encoding)NULL; + } else { + encoding = Tcl_GetEncoding((Tcl_Interp*)NULL, + RSTRING_PTR(enc)); + if (encoding == (Tcl_Encoding)NULL) { rb_warning("Tk-interp has unknown encoding information (@encoding:'%s')", RSTRING_PTR(enc)); - } else { - encodename = rb_obj_dup(enc); - } + } else { + encodename = rb_obj_dup(enc); + } + } } } @@ -7293,14 +7494,17 @@ lib_fromUTF8_core(ip_obj, src, encodename) StringValue(encodename); if (strcmp(RSTRING_PTR(encodename), "binary") == 0) { + Tcl_Obj *tclstr; char *s; int len; StringValue(str); - s = Tcl_GetByteArrayFromObj(Tcl_NewStringObj(RSTRING_PTR(str), - RSTRING_LEN(str)), - &len); + tclstr = Tcl_NewStringObj(RSTRING_PTR(str), RSTRING_LEN(str)); + Tcl_IncrRefCount(tclstr); + s = Tcl_GetByteArrayFromObj(tclstr, &len); str = rb_tainted_str_new(s, len); + s = (char*)NULL; + Tcl_DecrRefCount(tclstr); #ifdef RUBY_VM rb_enc_associate_index(str, ENCODING_INDEX_BINARY); #endif @@ -7310,7 +7514,8 @@ lib_fromUTF8_core(ip_obj, src, encodename) return str; } - encoding = Tcl_GetEncoding(interp, RSTRING_PTR(encodename)); + /* encoding = Tcl_GetEncoding(interp, RSTRING_PTR(encodename)); */ + encoding = Tcl_GetEncoding((Tcl_Interp*)NULL, RSTRING_PTR(encodename)); if (encoding == (Tcl_Encoding)NULL) { /* rb_warning("unknown encoding name '%s'", @@ -7359,9 +7564,11 @@ lib_fromUTF8_core(ip_obj, src, encodename) if (taint_flag) OBJ_TAINT(str); + /* if (encoding != (Tcl_Encoding)NULL) { Tcl_FreeEncoding(encoding); } + */ Tcl_DStringFree(&dstr); free(buf); @@ -7459,18 +7666,20 @@ lib_UTF_backslash_core(self, str, all_bs) #else #if 0 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)src_buf); /* XXXXXXXX */ -#endif +#else /* free(src_buf); */ ckfree(src_buf); #endif +#endif #if 0 /* use Tcl_EventuallyFree */ Tcl_EventuallyFree((ClientData)dst_buf, TCL_DYNAMIC); /* XXXXXXXX */ #else #if 0 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)dst_buf); /* XXXXXXXX */ -#endif +#else /* free(dst_buf); */ ckfree(dst_buf); +#endif #endif rb_thread_critical = thr_crit_bup; @@ -7596,10 +7805,11 @@ invoke_tcl_proc(arg) #else #if 0 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)argv); /* XXXXXXXX */ -#endif +#else /* free(argv); */ ckfree((char*)argv); #endif +#endif #else /* TCL_MAJOR_VERSION < 8 */ inf->ptr->return_value @@ -7829,10 +8039,11 @@ ip_invoke_core(interp, argc, argv) #else #if 0 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)argv); /* XXXXXXXX */ -#endif +#else /* free(argv); */ ckfree((char*)argv); #endif +#endif #else /* TCL_MAJOR_VERSION < 8 */ ptr->return_value = (*info.proc)(info.clientData, ptr->ip, @@ -7850,11 +8061,12 @@ ip_invoke_core(interp, argc, argv) #else #if 0 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)objv); /* XXXXXXXX */ -#endif +#else /* free(objv); */ ckfree((char*)objv); #endif -#else +#endif +#else /* TCL_MAJOR_VERSION < 8 */ free(argv[0]); /* ckfree(argv[0]); */ #if 0 /* use Tcl_EventuallyFree */ @@ -7862,10 +8074,11 @@ ip_invoke_core(interp, argc, argv) #else #if 0 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)argv); /* XXXXXXXX */ -#endif +#else /* free(argv); */ ckfree((char*)argv); #endif +#endif #endif } @@ -7876,11 +8089,24 @@ ip_invoke_core(interp, argc, argv) rb_thread_critical = thr_crit_bup; - if (ptr->return_value == TCL_ERROR) { + /* if (ptr->return_value == TCL_ERROR) { */ + if (ptr->return_value != TCL_OK) { if (event_loop_abort_on_exc > 0 && !Tcl_InterpDeleted(ptr->ip)) { + switch (ptr->return_value) { + case TCL_RETURN: + return create_ip_exc(interp, eTkCallbackReturn, + "ip_invoke_core receives TCL_RETURN"); + case TCL_BREAK: + return create_ip_exc(interp, eTkCallbackBreak, + "ip_invoke_core receives TCL_BREAK"); + case TCL_CONTINUE: + return create_ip_exc(interp, eTkCallbackContinue, + "ip_invoke_core receives TCL_CONTINUE"); + default: + return create_ip_exc(interp, rb_eRuntimeError, "%s", + Tcl_GetStringResult(ptr->ip)); + } - return create_ip_exc(interp, rb_eRuntimeError, - "%s", Tcl_GetStringResult(ptr->ip)); } else { if (event_loop_abort_on_exc < 0) { rb_warning("%s (ignore)", Tcl_GetStringResult(ptr->ip)); @@ -7963,8 +8189,10 @@ free_invoke_arguments(argc, av) for (i = 0; i < argc; ++i) { #if TCL_MAJOR_VERSION >= 8 Tcl_DecrRefCount(av[i]); + av[i] = (Tcl_Obj*)NULL; #else /* TCL_MAJOR_VERSION < 8 */ free(av[i]); + av[i] = (char*)NULL; #endif } #if TCL_MAJOR_VERSION >= 8 @@ -7973,20 +8201,22 @@ free_invoke_arguments(argc, av) #else #if 0 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)av); /* XXXXXXXX */ -#endif +#else ckfree((char*)av); #endif +#endif #else /* TCL_MAJOR_VERSION < 8 */ #if 0 /* use Tcl_EventuallyFree */ Tcl_EventuallyFree((ClientData)av, TCL_DYNAMIC); /* XXXXXXXX */ #else #if 0 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)av); /* XXXXXXXX */ -#endif +#else /* free(av); */ ckfree((char*)av); #endif #endif +#endif } static VALUE @@ -8049,11 +8279,12 @@ invoke_queue_handler(evPtr, flags) struct invoke_queue *q = (struct invoke_queue *)evPtr; volatile VALUE ret; volatile VALUE q_dat; + volatile VALUE thread = q->thread; struct tcltkip *ptr; DUMP2("do_invoke_queue_handler : evPtr = %p", evPtr); DUMP2("invoke queue_thread : %lx", rb_thread_current()); - DUMP2("added by thread : %lx", q->thread); + DUMP2("added by thread : %lx", thread); if (*(q->done)) { DUMP1("processed by another event-loop"); @@ -8062,6 +8293,17 @@ invoke_queue_handler(evPtr, flags) DUMP1("process it on current event-loop"); } +#ifdef RUBY_VM + if (RTEST(rb_funcall(thread, ID_alive_p, 0)) + && ! RTEST(rb_funcall(thread, ID_stop_p, 0))) { +#else + if (RTEST(rb_thread_alive_p(thread)) + && ! RTEST(rb_funcall(thread, ID_stop_p, 0))) { +#endif + DUMP1("caller is not yet ready to receive the result -> pending"); + return 0; + } + /* process it */ *(q->done) = 1; @@ -8082,14 +8324,16 @@ invoke_queue_handler(evPtr, flags) ret = rb_funcall(rb_proc_new(ivq_safelevel_handler, q_dat), ID_call, 0); rb_gc_force_recycle(q_dat); + q_dat = (VALUE)NULL; } else { - DUMP2("call invoke_real (for caller thread:%lx)", q->thread); + DUMP2("call invoke_real (for caller thread:%lx)", thread); DUMP2("call invoke_real (current thread:%lx)", rb_thread_current()); ret = ip_invoke_core(q->interp, q->argc, q->argv); } /* set result */ RARRAY_PTR(q->result)[0] = ret; + ret = (VALUE)NULL; /* decr internal handler mark */ rbtk_internal_eventloop_handler--; @@ -8097,22 +8341,31 @@ invoke_queue_handler(evPtr, flags) /* complete */ *(q->done) = -1; + /* unlink ruby objects */ + q->interp = (VALUE)NULL; + q->result = (VALUE)NULL; + q->thread = (VALUE)NULL; + /* back to caller */ - if (RTEST(rb_funcall(q->thread, ID_alive_p, 0, 0))) { - DUMP2("back to caller (caller thread:%lx)", q->thread); +#ifdef RUBY_VM + if (RTEST(rb_funcall(thread, ID_alive_p, 0, 0))) { +#else + if (RTEST(rb_thread_alive_p(thread))) { +#endif + DUMP2("back to caller (caller thread:%lx)", thread); DUMP2(" (current thread:%lx)", rb_thread_current()); -#if CONTROL_BY_STATUS_OF_RB_THREAD_WAIT_FOR_VALUE - have_rb_thread_waited_for_value = 1; - rb_thread_wakeup(q->thread); +#if CONTROL_BY_STATUS_OF_RB_THREAD_WAITING_FOR_VALUE + have_rb_thread_waiting_for_value = 1; + rb_thread_wakeup(thread); #else - rb_thread_run(q->thread); + rb_thread_run(thread); #endif DUMP1("finish back to caller"); #if DO_THREAD_SCHEDULE_AT_CALLBACK_DONE rb_thread_schedule(); #endif } else { - DUMP2("caller is dead (caller thread:%lx)", q->thread); + DUMP2("caller is dead (caller thread:%lx)", thread); DUMP2(" (current thread:%lx)", rb_thread_current()); } @@ -8150,9 +8403,11 @@ ip_invoke_with_position(argc, argv, obj, position) #ifdef RUBY_VM ptr = get_ip(ip_obj); - DUMP2("status: ptr->tk_thread_id %d", ptr->tk_thread_id); + DUMP2("status: ptr->tk_thread_id %p", ptr->tk_thread_id); + DUMP2("status: Tcl_GetCurrentThread %p", Tcl_GetCurrentThread()); +#else + DUMP2("status: Tcl_GetCurrentThread %lx", Tcl_GetCurrentThread()); #endif - DUMP2("status: Tcl_GetCurrentThread %d", Tcl_GetCurrentThread()); DUMP2("status: eventloopt_thread %lx", eventloop_thread); if ( @@ -8193,7 +8448,7 @@ ip_invoke_with_position(argc, argv, obj, position) /* allocate memory (freed by Tcl_ServiceEvent) */ /* ivq = (struct invoke_queue *)Tcl_Alloc(sizeof(struct invoke_queue)); */ ivq = (struct invoke_queue *)ckalloc(sizeof(struct invoke_queue)); -#if 1 /* use Tcl_Preserve/Release */ +#if 0 /* use Tcl_Preserve/Release */ Tcl_Preserve((ClientData)ivq); /* XXXXXXXX */ #endif @@ -8214,13 +8469,22 @@ ip_invoke_with_position(argc, argv, obj, position) DUMP1("add handler"); #ifdef RUBY_VM if (ptr->tk_thread_id) { - Tcl_ThreadQueueEvent(ptr->tk_thread_id, &(ivq->ev), position); + /* Tcl_ThreadQueueEvent(ptr->tk_thread_id, &(ivq->ev), position); */ + Tcl_ThreadQueueEvent(ptr->tk_thread_id, (Tcl_Event*)ivq, position); Tcl_ThreadAlert(ptr->tk_thread_id); + } else if (tk_eventloop_thread_id) { + /* Tcl_ThreadQueueEvent(tk_eventloop_thread_id, + &(ivq->ev), position); */ + Tcl_ThreadQueueEvent(tk_eventloop_thread_id, + (Tcl_Event*)ivq, position); + Tcl_ThreadAlert(tk_eventloop_thread_id); } else { - Tcl_QueueEvent(&(ivq->ev), position); + /* Tcl_QueueEvent(&(ivq->ev), position); */ + Tcl_QueueEvent((Tcl_Event*)ivq, position); } #else - Tcl_QueueEvent(&(ivq->ev), position); + /* Tcl_QueueEvent(&(ivq->ev), position); */ + Tcl_QueueEvent((Tcl_Event*)ivq, position); #endif rb_thread_critical = thr_crit_bup; @@ -8228,7 +8492,8 @@ ip_invoke_with_position(argc, argv, obj, position) /* wait for the handler to be processed */ DUMP2("wait for handler (current thread:%lx)", current); while(*alloc_done >= 0) { - rb_thread_stop(); + /* rb_thread_stop(); */ + rb_thread_sleep_forever(); } DUMP2("back from handler (current thread:%lx)", current); @@ -8239,19 +8504,22 @@ ip_invoke_with_position(argc, argv, obj, position) #else #if 0 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)alloc_done); /* XXXXXXXX */ -#endif +#else /* free(alloc_done); */ ckfree((char*)alloc_done); #endif +#endif +#if 0 /* ivq is freed by Tcl_ServiceEvent */ #if 0 /* use Tcl_EventuallyFree */ Tcl_EventuallyFree((ClientData)ivq, TCL_DYNAMIC); /* XXXXXXXX */ #else -#if 1 /* use Tcl_Preserve/Release */ +#if 0 /* use Tcl_Preserve/Release */ Tcl_Release(ivq); #else ckfree((char*)ivq); #endif +#endif #endif /* free allocated memory */ @@ -8938,9 +9206,10 @@ lib_merge_tklist(argc, argv, obj) #else #if 0 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)flagPtr); -#endif +#else /* free(flagPtr); */ ckfree((char*)flagPtr); +#endif #endif /* create object */ @@ -8951,9 +9220,10 @@ lib_merge_tklist(argc, argv, obj) #else #if 0 /* use Tcl_Preserve/Release */ Tcl_Release((ClientData)result); /* XXXXXXXXXXX */ -#endif +#else /* Tcl_Free(result); */ ckfree(result); +#endif #endif if (old_gc == Qfalse) rb_gc_enable(); @@ -9106,7 +9376,7 @@ create_dummy_encoding_for_tk_core(interp, name, error_mode) StringValue(name); #if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1) - if (Tcl_GetEncoding(ptr->ip, RSTRING_PTR(name)) == (Tcl_Encoding) NULL) { + if (Tcl_GetEncoding((Tcl_Interp*)NULL, RSTRING_PTR(name)) == (Tcl_Encoding)NULL) { if (RTEST(error_mode)) { rb_raise(rb_eArgError, "invalid Tk encoding name '%s'", RSTRING_PTR(name)); @@ -9704,6 +9974,7 @@ ip_make_menu_embeddable_core(interp, argc, argv) char *s = "normal"; /* Tcl_SetStringObj((menuRefPtr->menuPtr)->menuTypePtr, s, strlen(s));*/ (menuRefPtr->menuPtr)->menuTypePtr = Tcl_NewStringObj(s, strlen(s)); + /* Tcl_IncrRefCount((menuRefPtr->menuPtr)->menuTypePtr); */ /* (menuRefPtr->menuPtr)->menuType = TEAROFF_MENU; */ (menuRefPtr->menuPtr)->menuType = MASTER_MENU; } @@ -10048,6 +10319,9 @@ Init_tcltklib() /* --------------------------------------------------------------- */ + /* Tcl stub check */ + tcl_stubs_check(); + Tcl_ObjType_ByteArray = Tcl_GetObjType(Tcl_ObjTypeName_ByteArray); Tcl_ObjType_String = Tcl_GetObjType(Tcl_ObjTypeName_String); diff --git a/ext/tk/tkutil/extconf.rb b/ext/tk/tkutil/extconf.rb index 51f775619c..015bc3a45e 100644 --- a/ext/tk/tkutil/extconf.rb +++ b/ext/tk/tkutil/extconf.rb @@ -8,5 +8,6 @@ end if has_tk require 'mkmf' have_func("rb_obj_instance_exec", "ruby.h") + have_func("strndup", "string.h") create_makefile('tkutil') end diff --git a/ext/tk/tkutil/tkutil.c b/ext/tk/tkutil/tkutil.c index 1781dd5e4a..00d719143b 100644 --- a/ext/tk/tkutil/tkutil.c +++ b/ext/tk/tkutil/tkutil.c @@ -7,7 +7,7 @@ ************************************************/ -#define TKUTIL_RELEASE_DATE "2008-03-29" +#define TKUTIL_RELEASE_DATE "2008-05-23" #include "ruby.h" @@ -1073,11 +1073,13 @@ tcl2rb_num_or_str(self, value) /*************************************/ +#define CBSUBST_TBL_MAX (256) struct cbsubst_info { - int size; - char *key; - char *type; - ID *ivar; + int full_subst_length; + int keylen[CBSUBST_TBL_MAX]; + unsigned char *key[CBSUBST_TBL_MAX]; + unsigned char type[CBSUBST_TBL_MAX]; + ID ivar[CBSUBST_TBL_MAX]; VALUE proc; VALUE aliases; }; @@ -1094,42 +1096,52 @@ static void subst_free(ptr) struct cbsubst_info *ptr; { + int i; + if (ptr) { - if (ptr->key != (char*)NULL) free(ptr->key); - if (ptr->type != (char*)NULL) free(ptr->type); - if (ptr->ivar != (ID*)NULL) free(ptr->ivar); - free(ptr); + for(i = 0; i < CBSUBST_TBL_MAX; i++) { + if (ptr->key[i] != (unsigned char *)NULL) { + free(ptr->key[i]); + ptr->key[i] = (unsigned char *)NULL; + } + } + free(ptr); } } -static void -cbsubst_init() +static struct cbsubst_info * +allocate_cbsubst_info() { - struct cbsubst_info *inf; - ID *ivar; - volatile VALUE proc, aliases; - - inf = ALLOC(struct cbsubst_info); + struct cbsubst_info *inf; + volatile VALUE proc, aliases; + int idx; - inf->size = 0; + inf = ALLOC(struct cbsubst_info); - inf->key = ALLOC_N(char, 1); - inf->key[0] = '\0'; + inf->full_subst_length = 0; - inf->type = ALLOC_N(char, 1); - inf->type[0] = '\0'; + for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) { + inf->keylen[idx] = 0; + inf->key[idx] = (unsigned char *) NULL; + inf->type[idx] = '\0'; + inf->ivar[idx] = (ID) 0; + } - ivar = ALLOC_N(ID, 1); - inf->ivar = ivar; + proc = rb_hash_new(); + inf->proc = proc; - proc = rb_hash_new(); - inf->proc = proc; + aliases = rb_hash_new(); + inf->aliases = aliases; - aliases = rb_hash_new(); - inf->aliases = aliases; + return inf; +} +static void +cbsubst_init() +{ rb_const_set(cCB_SUBST, ID_SUBST_INFO, - Data_Wrap_Struct(cSUBST_INFO, subst_mark, subst_free, inf)); + Data_Wrap_Struct(cSUBST_INFO, subst_mark, subst_free, + allocate_cbsubst_info())); } static VALUE @@ -1139,24 +1151,29 @@ cbsubst_initialize(argc, argv, self) VALUE self; { struct cbsubst_info *inf; - int idx; + int idx, iv_idx; Data_Get_Struct(rb_const_get(rb_obj_class(self), ID_SUBST_INFO), struct cbsubst_info, inf); - for(idx = 0; idx < argc; idx++) { - rb_ivar_set(self, inf->ivar[idx], argv[idx]); + idx = 0; + for(iv_idx = 0; iv_idx < CBSUBST_TBL_MAX; iv_idx++) { + if ( inf->ivar[iv_idx] == (ID) 0 ) continue; + rb_ivar_set(self, inf->ivar[iv_idx], argv[idx++]); + if (idx >= argc) break; } return self; } - static VALUE cbsubst_ret_val(self, val) VALUE self; VALUE val; { + /* This method may be overwritten on some sub-classes. */ + /* This method is used for converting from ruby's callback-return-value */ + /* to tcl's value (e.g. validation procedure of entry widget). */ return val; } @@ -1216,6 +1233,59 @@ cbsubst_def_attr_aliases(self, tbl) return rb_funcall(inf->aliases, rb_intern("update"), 1, tbl); } +static VALUE +cbsubst_sym_to_subst(self, sym) + VALUE self; + VALUE sym; +{ + struct cbsubst_info *inf; + const char *str; + unsigned char *buf, *ptr; + int idx, len; + ID id; + volatile VALUE ret; + + if (TYPE(sym) != T_SYMBOL) return sym; + + Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO), + struct cbsubst_info, inf); + + if (!NIL_P(ret = rb_hash_aref(inf->aliases, sym))) { + str = rb_id2name(SYM2ID(ret)); + } else { + str = rb_id2name(SYM2ID(sym)); + } + + id = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), str))); + + for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) { + if (inf->ivar[idx] == id) break; + } + if (idx >= CBSUBST_TBL_MAX) return sym; + + ptr = buf = ALLOC_N(char, inf->full_subst_length + 1); + + *(ptr++) = '%'; + + if (len = inf->keylen[idx]) { + /* longname */ + strncpy(ptr, inf->key[idx], len); + ptr += len; + } else { + /* single char */ + *(ptr++) = idx; + } + + *(ptr++) = ' '; + *(ptr++) = '\0'; + + ret = rb_str_new2(buf); + + free(buf); + + return ret; +} + static VALUE cbsubst_get_subst_arg(argc, argv, self) int argc; @@ -1224,17 +1294,15 @@ cbsubst_get_subst_arg(argc, argv, self) { struct cbsubst_info *inf; const char *str; - char *buf, *ptr; - int i, j, len; + unsigned char *buf, *ptr; + int i, idx, len; ID id; volatile VALUE arg_sym, ret; Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO), struct cbsubst_info, inf); - buf = ALLOC_N(char, 3*argc + 1); - ptr = buf; - len = strlen(inf->key); + ptr = buf = ALLOC_N(char, inf->full_subst_length + 1); for(i = 0; i < argc; i++) { switch(TYPE(argv[i])) { @@ -1256,17 +1324,25 @@ cbsubst_get_subst_arg(argc, argv, self) id = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), str))); - for(j = 0; j < len; j++) { - if (inf->ivar[j] == id) break; - } - - if (j >= len) { + for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) { + if (inf->ivar[idx] == id) break; + } + if (idx >= CBSUBST_TBL_MAX) { rb_raise(rb_eArgError, "cannot find attribute :%s", str); } - *(ptr++) = '%'; - *(ptr++) = *(inf->key + j); - *(ptr++) = ' '; + *(ptr++) = '%'; + + if (len = inf->keylen[idx]) { + /* longname */ + strncpy(ptr, inf->key[idx], len); + ptr += len; + } else { + /* single char */ + *(ptr++) = idx; + } + + *(ptr++) = ' '; } *ptr = '\0'; @@ -1283,27 +1359,50 @@ cbsubst_get_subst_key(self, str) VALUE self; VALUE str; { + struct cbsubst_info *inf; volatile VALUE list; volatile VALUE ret; - int i, len; - char *buf, *ptr; + VALUE keyval; + int i, len, keylen, idx; + unsigned char *buf, *ptr, *key; list = rb_funcall(cTclTkLib, ID_split_tklist, 1, str); - len = RARRAY_LEN(list); - buf = ALLOC_N(char, len + 1); + + Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO), + struct cbsubst_info, inf); + + ptr = buf = ALLOC_N(unsigned char, inf->full_subst_length + len + 1); for(i = 0; i < len; i++) { - ptr = RSTRING_PTR(RARRAY_PTR(list)[i]); - if (*ptr == '%' && *(ptr + 2) == '\0') { - *(buf + i) = *(ptr + 1); - } else { - *(buf + i) = ' '; - } + keyval = RARRAY_PTR(list)[i]; + key = (unsigned char*)RSTRING_PTR(keyval); + if (*key == '%') { + if (*(key + 2) == '\0') { + /* single char */ + *(ptr++) = *(key + 1); + } else { + /* search longname-key */ + keylen = RSTRING_LEN(keyval) - 1; + for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) { + if (inf->keylen[idx] != keylen) continue; + if (inf->key[idx][0] != *(key + 1)) continue; + if (strncmp(inf->key[idx], key + 1, keylen)) continue; + break; + } + if (idx < CBSUBST_TBL_MAX) { + *(ptr++) = (unsigned char)idx; + } else { + *(ptr++) = ' '; + } + } + } else { + *(ptr++) = ' '; + } } - *(buf + len) = '\0'; + *ptr = '\0'; - ret = rb_str_new2(buf); + ret = rb_str_new2((const char*)buf); free(buf); return ret; } @@ -1313,100 +1412,166 @@ cbsubst_get_all_subst_keys(self) VALUE self; { struct cbsubst_info *inf; - char *buf, *ptr; - int i, len; + unsigned char *buf, *ptr; + unsigned char *keys_buf, *keys_ptr; + int idx, len; volatile VALUE ret; Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO), struct cbsubst_info, inf); - len = strlen(inf->key); - buf = ALLOC_N(char, 3*len + 1); - ptr = buf; - for(i = 0; i < len; i++) { - *(ptr++) = '%'; - *(ptr++) = *(inf->key + i); - *(ptr++) = ' '; + ptr = buf = ALLOC_N(unsigned char, inf->full_subst_length + 1); + keys_ptr = keys_buf = ALLOC_N(unsigned char, CBSUBST_TBL_MAX + 1); + + for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) { + if (inf->ivar[idx] == (ID) 0) continue; + + *(keys_ptr++) = (unsigned char)idx; + + *(ptr++) = '%'; + + if (len = inf->keylen[idx]) { + /* longname */ + strncpy(ptr, inf->key[idx], len); + ptr += len; + } else { + /* single char */ + *(ptr++) = (unsigned char)idx; + } + + *(ptr++) = ' '; } - *(buf + 3*len) = '\0'; - ret = rb_ary_new3(2, rb_str_new2(inf->key), rb_str_new2(buf)); + *ptr = '\0'; + *keys_ptr = '\0'; + + ret = rb_ary_new3(2, rb_str_new2(keys_buf), rb_str_new2((const char*)buf)); free(buf); + free(keys_buf); return ret; } static VALUE -cbsubst_table_setup(self, key_inf, proc_inf) - VALUE self; - VALUE key_inf; - VALUE proc_inf; +cbsubst_table_setup(argc, argv, self) + int argc; + VALUE *argv; + VALUE self; { - struct cbsubst_info *subst_inf; - int idx; - int len = RARRAY_LEN(key_inf); - int real_len = 0; - char *key = ALLOC_N(char, len + 1); - char *type = ALLOC_N(char, len + 1); - ID *ivar = ALLOC_N(ID, len + 1); - volatile VALUE proc = rb_hash_new(); - volatile VALUE aliases = rb_hash_new(); - volatile VALUE inf; - - /* init */ - subst_inf = ALLOC(struct cbsubst_info); - /* subst_inf->size = len; */ - subst_inf->key = key; - subst_inf->type = type; - subst_inf->ivar = ivar; - subst_inf->proc = proc; - subst_inf->aliases = aliases; - - /* - * keys : array of [subst, type, ivar] - * subst ==> char code - * type ==> char code - * ivar ==> symbol - */ - for(idx = 0; idx < len; idx++) { - inf = RARRAY_PTR(key_inf)[idx]; - if (TYPE(inf) != T_ARRAY) continue; - *(key + real_len) = NUM2CHR(RARRAY_PTR(inf)[0]); - *(type + real_len) = NUM2CHR(RARRAY_PTR(inf)[1]); - - *(ivar + real_len) - = rb_intern( - RSTRING_PTR( - rb_str_cat2(rb_str_new2("@"), - rb_id2name(SYM2ID(RARRAY_PTR(inf)[2]))) - ) - ); - - rb_attr(self, SYM2ID(RARRAY_PTR(inf)[2]), 1, 0, Qtrue); - real_len++; + volatile VALUE key_inf; + volatile VALUE longkey_inf; + volatile VALUE proc_inf; + VALUE inf; + ID id; + struct cbsubst_info *subst_inf; + int idx, len; + unsigned char chr; + + /* accept (key_inf, proc_inf) or (key_inf, longkey_inf, procinf) */ + if (rb_scan_args(argc, argv, "21", &key_inf, &longkey_inf, &proc_inf) == 2) { + proc_inf = longkey_inf; + longkey_inf = rb_ary_new(); + } + + /* check the number of longkeys */ + if (RARRAY_LEN(longkey_inf) > 125 /* from 0x80 to 0xFD */) { + rb_raise(rb_eArgError, "too many longname-key definitions"); + } + + /* init */ + subst_inf = allocate_cbsubst_info(); + + /* + * keys : array of [subst, type, ivar] + * subst ==> char code or string + * type ==> char code or string + * ivar ==> symbol + */ + len = RARRAY_LEN(key_inf); + for(idx = 0; idx < len; idx++) { + inf = RARRAY_PTR(key_inf)[idx]; + if (TYPE(inf) != T_ARRAY) continue; + + if (TYPE(RARRAY_PTR(inf)[0]) == T_STRING) { + chr = *(RSTRING_PTR(RARRAY_PTR(inf)[0])); + } else { + chr = NUM2CHR(RARRAY_PTR(inf)[0]); } - *(key + real_len) = '\0'; - *(type + real_len) = '\0'; - subst_inf->size = real_len; - - /* - * procs : array of [type, proc] - * type ==> char code - * proc ==> proc/method/obj (must respond to 'call') - */ - len = RARRAY_LEN(proc_inf); - for(idx = 0; idx < len; idx++) { - inf = RARRAY_PTR(proc_inf)[idx]; - if (TYPE(inf) != T_ARRAY) continue; - rb_hash_aset(proc, RARRAY_PTR(inf)[0], RARRAY_PTR(inf)[1]); + if (TYPE(RARRAY_PTR(inf)[1]) == T_STRING) { + subst_inf->type[chr] = *(RSTRING_PTR(RARRAY_PTR(inf)[1])); + } else { + subst_inf->type[chr] = NUM2CHR(RARRAY_PTR(inf)[1]); } - rb_const_set(self, ID_SUBST_INFO, - Data_Wrap_Struct(cSUBST_INFO, subst_mark, - subst_free, subst_inf)); + subst_inf->full_subst_length += 3; - return self; + id = SYM2ID(RARRAY_PTR(inf)[2]); + subst_inf->ivar[chr] = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), rb_id2name(id)))); + + rb_attr(self, id, 1, 0, Qtrue); + } + + + /* + * longkeys : array of [name, type, ivar] + * name ==> longname key string + * type ==> char code or string + * ivar ==> symbol + */ + len = RARRAY_LEN(longkey_inf); + for(idx = 0; idx < len; idx++) { + inf = RARRAY_PTR(longkey_inf)[idx]; + if (TYPE(inf) != T_ARRAY) continue; + + chr = (unsigned char)(0x80 + idx); + subst_inf->keylen[chr] = RSTRING_LEN(RARRAY_PTR(inf)[0]); +#if HAVE_STRNDUP + subst_inf->key[chr] = strndup(RSTRING_PTR(RARRAY_PTR(inf)[0]), + RSTRING_LEN(RARRAY_PTR(inf)[0])); +#else + subst_inf->key[chr] = malloc(RSTRING_LEN(RARRAY_PTR(inf)[0]) + 1); + if (subst_inf->key[chr]) { + strncpy(subst_inf->key[chr], RSTRING_PTR(RARRAY_PTR(inf)[0]), + RSTRING_LEN(RARRAY_PTR(inf)[0]) + 1); + subst_inf->key[chr][RSTRING_LEN(RARRAY_PTR(inf)[0])] = '\0'; + } +#endif + if (TYPE(RARRAY_PTR(inf)[1]) == T_STRING) { + subst_inf->type[chr] = *(RSTRING_PTR(RARRAY_PTR(inf)[1])); + } else { + subst_inf->type[chr] = NUM2CHR(RARRAY_PTR(inf)[1]); + } + + subst_inf->full_subst_length += (subst_inf->keylen[chr] + 2); + + id = SYM2ID(RARRAY_PTR(inf)[2]); + subst_inf->ivar[chr] = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), rb_id2name(id)))); + + rb_attr(self, id, 1, 0, Qtrue); + } + + /* + * procs : array of [type, proc] + * type ==> char code or string + * proc ==> proc/method/obj (must respond to 'call') + */ + len = RARRAY_LEN(proc_inf); + for(idx = 0; idx < len; idx++) { + inf = RARRAY_PTR(proc_inf)[idx]; + if (TYPE(inf) != T_ARRAY) continue; + rb_hash_aset(subst_inf->proc, + ((TYPE(RARRAY_PTR(inf)[0]) == T_STRING)? + INT2FIX(*(RSTRING_PTR(RARRAY_PTR(inf)[0]))) : + RARRAY_PTR(inf)[0]), + RARRAY_PTR(inf)[1]); + } + + rb_const_set(self, ID_SUBST_INFO, + Data_Wrap_Struct(cSUBST_INFO, subst_mark, + subst_free, subst_inf)); + + return self; } static VALUE @@ -1424,10 +1589,11 @@ cbsubst_scan_args(self, arg_key, val_ary) { struct cbsubst_info *inf; int idx; - int len = RARRAY_LEN(val_ary); - char c; - char *ptr; - volatile VALUE dst = rb_ary_new2(len); + unsigned char *keyptr = (unsigned char*)RSTRING_PTR(arg_key); + int keylen = RSTRING_LEN(arg_key); + int vallen = RARRAY_LEN(val_ary); + unsigned char type_chr; + volatile VALUE dst = rb_ary_new2(vallen); volatile VALUE proc; int thr_crit_bup; VALUE old_gc; @@ -1440,26 +1606,25 @@ cbsubst_scan_args(self, arg_key, val_ary) Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO), struct cbsubst_info, inf); - for(idx = 0; idx < len; idx++) { - if (idx >= RSTRING_LEN(arg_key)) { - proc = Qnil; - } else if (*(RSTRING_PTR(arg_key) + idx) == ' ') { - proc = Qnil; - } else { - ptr = strchr(inf->key, *(RSTRING_PTR(arg_key) + idx)); - if (ptr == (char*)NULL) { - proc = Qnil; - } else { - c = *(inf->type + (ptr - inf->key)); - proc = rb_hash_aref(inf->proc, INT2FIX(c)); - } - } - - if (NIL_P(proc)) { - rb_ary_push(dst, RARRAY_PTR(val_ary)[idx]); - } else { - rb_ary_push(dst, rb_funcall(proc, ID_call, 1, RARRAY_PTR(val_ary)[idx])); - } + for(idx = 0; idx < vallen; idx++) { + if (idx >= keylen) { + proc = Qnil; + } else if (*(keyptr + idx) == ' ') { + proc = Qnil; + } else { + if (type_chr = inf->type[*(keyptr + idx)]) { + proc = rb_hash_aref(inf->proc, INT2FIX((int)type_chr)); + } else { + proc = Qnil; + } + } + + if (NIL_P(proc)) { + rb_ary_push(dst, RARRAY_PTR(val_ary)[idx]); + } else { + rb_ary_push(dst, rb_funcall(proc, ID_call, 1, + RARRAY_PTR(val_ary)[idx])); + } } if (old_gc == Qfalse) rb_gc_enable(); @@ -1543,6 +1708,8 @@ Init_tkutil() ID_SUBST_INFO = rb_intern("SUBST_INFO"); rb_define_singleton_method(cCB_SUBST, "ret_val", cbsubst_ret_val, 1); rb_define_singleton_method(cCB_SUBST, "scan_args", cbsubst_scan_args, 2); + rb_define_singleton_method(cCB_SUBST, "_sym2subst", + cbsubst_sym_to_subst, 1); rb_define_singleton_method(cCB_SUBST, "subst_arg", cbsubst_get_subst_arg, -1); rb_define_singleton_method(cCB_SUBST, "_get_subst_key", @@ -1550,7 +1717,7 @@ Init_tkutil() rb_define_singleton_method(cCB_SUBST, "_get_all_subst_keys", cbsubst_get_all_subst_keys, 0); rb_define_singleton_method(cCB_SUBST, "_setup_subst_table", - cbsubst_table_setup, 2); + cbsubst_table_setup, -1); rb_define_singleton_method(cCB_SUBST, "_get_extra_args_tbl", cbsubst_get_extra_args_tbl, 0); rb_define_singleton_method(cCB_SUBST, "_define_attribute_aliases", -- cgit v1.2.3