tk-win 0.2.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/lib/tcltk.rb +367 -0
- data/lib/tk.rb +5682 -0
- data/lib/tk/after.rb +6 -0
- data/lib/tk/autoload.rb +760 -0
- data/lib/tk/bgerror.rb +29 -0
- data/lib/tk/bindtag.rb +138 -0
- data/lib/tk/button.rb +31 -0
- data/lib/tk/canvas.rb +816 -0
- data/lib/tk/canvastag.rb +459 -0
- data/lib/tk/checkbutton.rb +32 -0
- data/lib/tk/clipboard.rb +75 -0
- data/lib/tk/clock.rb +71 -0
- data/lib/tk/composite.rb +484 -0
- data/lib/tk/console.rb +52 -0
- data/lib/tk/dialog.rb +326 -0
- data/lib/tk/encodedstr.rb +187 -0
- data/lib/tk/entry.rb +120 -0
- data/lib/tk/event.rb +562 -0
- data/lib/tk/font.rb +2351 -0
- data/lib/tk/frame.rb +132 -0
- data/lib/tk/grid.rb +279 -0
- data/lib/tk/image.rb +275 -0
- data/lib/tk/itemconfig.rb +1222 -0
- data/lib/tk/itemfont.rb +327 -0
- data/lib/tk/kinput.rb +71 -0
- data/lib/tk/label.rb +22 -0
- data/lib/tk/labelframe.rb +31 -0
- data/lib/tk/listbox.rb +284 -0
- data/lib/tk/macpkg.rb +80 -0
- data/lib/tk/menu.rb +718 -0
- data/lib/tk/menubar.rb +137 -0
- data/lib/tk/menuspec.rb +456 -0
- data/lib/tk/message.rb +24 -0
- data/lib/tk/mngfocus.rb +33 -0
- data/lib/tk/msgcat.rb +296 -0
- data/lib/tk/namespace.rb +551 -0
- data/lib/tk/optiondb.rb +377 -0
- data/lib/tk/optionobj.rb +212 -0
- data/lib/tk/pack.rb +107 -0
- data/lib/tk/package.rb +143 -0
- data/lib/tk/palette.rb +55 -0
- data/lib/tk/panedwindow.rb +260 -0
- data/lib/tk/place.rb +128 -0
- data/lib/tk/radiobutton.rb +73 -0
- data/lib/tk/root.rb +95 -0
- data/lib/tk/scale.rb +112 -0
- data/lib/tk/scrollable.rb +82 -0
- data/lib/tk/scrollbar.rb +183 -0
- data/lib/tk/scrollbox.rb +39 -0
- data/lib/tk/selection.rb +86 -0
- data/lib/tk/spinbox.rb +144 -0
- data/lib/tk/tagfont.rb +43 -0
- data/lib/tk/text.rb +1604 -0
- data/lib/tk/textimage.rb +88 -0
- data/lib/tk/textmark.rb +204 -0
- data/lib/tk/texttag.rb +321 -0
- data/lib/tk/textwindow.rb +154 -0
- data/lib/tk/timer.rb +669 -0
- data/lib/tk/toplevel.rb +264 -0
- data/lib/tk/ttk_selector.rb +98 -0
- data/lib/tk/txtwin_abst.rb +39 -0
- data/lib/tk/validation.rb +397 -0
- data/lib/tk/variable.rb +1799 -0
- data/lib/tk/virtevent.rb +139 -0
- data/lib/tk/winfo.rb +392 -0
- data/lib/tk/winpkg.rb +156 -0
- data/lib/tk/wm.rb +552 -0
- data/lib/tk/xim.rb +122 -0
- data/lib/tkafter.rb +4 -0
- data/lib/tkbgerror.rb +4 -0
- data/lib/tkcanvas.rb +4 -0
- data/lib/tkclass.rb +47 -0
- data/lib/tkconsole.rb +4 -0
- data/lib/tkdialog.rb +4 -0
- data/lib/tkentry.rb +4 -0
- data/lib/tkextlib/ICONS.rb +13 -0
- data/lib/tkextlib/ICONS/icons.rb +129 -0
- data/lib/tkextlib/ICONS/setup.rb +8 -0
- data/lib/tkextlib/SUPPORT_STATUS +198 -0
- data/lib/tkextlib/blt.rb +189 -0
- data/lib/tkextlib/blt/barchart.rb +79 -0
- data/lib/tkextlib/blt/bitmap.rb +112 -0
- data/lib/tkextlib/blt/busy.rb +83 -0
- data/lib/tkextlib/blt/component.rb +2218 -0
- data/lib/tkextlib/blt/container.rb +28 -0
- data/lib/tkextlib/blt/cutbuffer.rb +23 -0
- data/lib/tkextlib/blt/dragdrop.rb +269 -0
- data/lib/tkextlib/blt/eps.rb +32 -0
- data/lib/tkextlib/blt/graph.rb +67 -0
- data/lib/tkextlib/blt/htext.rb +112 -0
- data/lib/tkextlib/blt/setup.rb +8 -0
- data/lib/tkextlib/blt/spline.rb +23 -0
- data/lib/tkextlib/blt/stripchart.rb +74 -0
- data/lib/tkextlib/blt/table.rb +412 -0
- data/lib/tkextlib/blt/tabnotebook.rb +110 -0
- data/lib/tkextlib/blt/tabset.rb +504 -0
- data/lib/tkextlib/blt/ted.rb +68 -0
- data/lib/tkextlib/blt/tile.rb +25 -0
- data/lib/tkextlib/blt/tile/button.rb +16 -0
- data/lib/tkextlib/blt/tile/checkbutton.rb +17 -0
- data/lib/tkextlib/blt/tile/frame.rb +16 -0
- data/lib/tkextlib/blt/tile/label.rb +16 -0
- data/lib/tkextlib/blt/tile/radiobutton.rb +17 -0
- data/lib/tkextlib/blt/tile/scrollbar.rb +16 -0
- data/lib/tkextlib/blt/tile/toplevel.rb +16 -0
- data/lib/tkextlib/blt/tree.rb +1058 -0
- data/lib/tkextlib/blt/treeview.rb +1287 -0
- data/lib/tkextlib/blt/unix_dnd.rb +141 -0
- data/lib/tkextlib/blt/vector.rb +256 -0
- data/lib/tkextlib/blt/watch.rb +175 -0
- data/lib/tkextlib/blt/win_printer.rb +61 -0
- data/lib/tkextlib/blt/winop.rb +107 -0
- data/lib/tkextlib/bwidget.rb +153 -0
- data/lib/tkextlib/bwidget/arrowbutton.rb +21 -0
- data/lib/tkextlib/bwidget/bitmap.rb +21 -0
- data/lib/tkextlib/bwidget/button.rb +31 -0
- data/lib/tkextlib/bwidget/buttonbox.rb +90 -0
- data/lib/tkextlib/bwidget/combobox.rb +62 -0
- data/lib/tkextlib/bwidget/dialog.rb +194 -0
- data/lib/tkextlib/bwidget/dragsite.rb +31 -0
- data/lib/tkextlib/bwidget/dropsite.rb +39 -0
- data/lib/tkextlib/bwidget/dynamichelp.rb +63 -0
- data/lib/tkextlib/bwidget/entry.rb +43 -0
- data/lib/tkextlib/bwidget/label.rb +41 -0
- data/lib/tkextlib/bwidget/labelentry.rb +80 -0
- data/lib/tkextlib/bwidget/labelframe.rb +52 -0
- data/lib/tkextlib/bwidget/listbox.rb +361 -0
- data/lib/tkextlib/bwidget/mainframe.rb +132 -0
- data/lib/tkextlib/bwidget/messagedlg.rb +192 -0
- data/lib/tkextlib/bwidget/notebook.rb +166 -0
- data/lib/tkextlib/bwidget/pagesmanager.rb +73 -0
- data/lib/tkextlib/bwidget/panedwindow.rb +42 -0
- data/lib/tkextlib/bwidget/panelframe.rb +67 -0
- data/lib/tkextlib/bwidget/passwddlg.rb +44 -0
- data/lib/tkextlib/bwidget/progressbar.rb +20 -0
- data/lib/tkextlib/bwidget/progressdlg.rb +58 -0
- data/lib/tkextlib/bwidget/scrollableframe.rb +40 -0
- data/lib/tkextlib/bwidget/scrolledwindow.rb +48 -0
- data/lib/tkextlib/bwidget/scrollview.rb +25 -0
- data/lib/tkextlib/bwidget/selectcolor.rb +73 -0
- data/lib/tkextlib/bwidget/selectfont.rb +91 -0
- data/lib/tkextlib/bwidget/separator.rb +20 -0
- data/lib/tkextlib/bwidget/setup.rb +8 -0
- data/lib/tkextlib/bwidget/spinbox.rb +98 -0
- data/lib/tkextlib/bwidget/statusbar.rb +62 -0
- data/lib/tkextlib/bwidget/titleframe.rb +33 -0
- data/lib/tkextlib/bwidget/tree.rb +500 -0
- data/lib/tkextlib/bwidget/widget.rb +129 -0
- data/lib/tkextlib/itcl.rb +13 -0
- data/lib/tkextlib/itcl/incr_tcl.rb +178 -0
- data/lib/tkextlib/itcl/setup.rb +13 -0
- data/lib/tkextlib/itk.rb +13 -0
- data/lib/tkextlib/itk/incr_tk.rb +446 -0
- data/lib/tkextlib/itk/setup.rb +13 -0
- data/lib/tkextlib/iwidgets.rb +94 -0
- data/lib/tkextlib/iwidgets/buttonbox.rb +121 -0
- data/lib/tkextlib/iwidgets/calendar.rb +125 -0
- data/lib/tkextlib/iwidgets/canvasprintbox.rb +53 -0
- data/lib/tkextlib/iwidgets/canvasprintdialog.rb +38 -0
- data/lib/tkextlib/iwidgets/checkbox.rb +130 -0
- data/lib/tkextlib/iwidgets/combobox.rb +104 -0
- data/lib/tkextlib/iwidgets/dateentry.rb +20 -0
- data/lib/tkextlib/iwidgets/datefield.rb +58 -0
- data/lib/tkextlib/iwidgets/dialog.rb +20 -0
- data/lib/tkextlib/iwidgets/dialogshell.rb +121 -0
- data/lib/tkextlib/iwidgets/disjointlistbox.rb +50 -0
- data/lib/tkextlib/iwidgets/entryfield.rb +185 -0
- data/lib/tkextlib/iwidgets/extbutton.rb +40 -0
- data/lib/tkextlib/iwidgets/extfileselectionbox.rb +46 -0
- data/lib/tkextlib/iwidgets/extfileselectiondialog.rb +33 -0
- data/lib/tkextlib/iwidgets/feedback.rb +35 -0
- data/lib/tkextlib/iwidgets/fileselectionbox.rb +46 -0
- data/lib/tkextlib/iwidgets/fileselectiondialog.rb +33 -0
- data/lib/tkextlib/iwidgets/finddialog.rb +42 -0
- data/lib/tkextlib/iwidgets/hierarchy.rb +365 -0
- data/lib/tkextlib/iwidgets/hyperhelp.rb +50 -0
- data/lib/tkextlib/iwidgets/labeledframe.rb +39 -0
- data/lib/tkextlib/iwidgets/labeledwidget.rb +45 -0
- data/lib/tkextlib/iwidgets/mainwindow.rb +67 -0
- data/lib/tkextlib/iwidgets/menubar.rb +212 -0
- data/lib/tkextlib/iwidgets/messagebox.rb +93 -0
- data/lib/tkextlib/iwidgets/messagedialog.rb +20 -0
- data/lib/tkextlib/iwidgets/notebook.rb +175 -0
- data/lib/tkextlib/iwidgets/optionmenu.rb +92 -0
- data/lib/tkextlib/iwidgets/panedwindow.rb +134 -0
- data/lib/tkextlib/iwidgets/promptdialog.rb +131 -0
- data/lib/tkextlib/iwidgets/pushbutton.rb +35 -0
- data/lib/tkextlib/iwidgets/radiobox.rb +121 -0
- data/lib/tkextlib/iwidgets/scopedobject.rb +24 -0
- data/lib/tkextlib/iwidgets/scrolledcanvas.rb +353 -0
- data/lib/tkextlib/iwidgets/scrolledframe.rb +59 -0
- data/lib/tkextlib/iwidgets/scrolledhtml.rb +58 -0
- data/lib/tkextlib/iwidgets/scrolledlistbox.rb +207 -0
- data/lib/tkextlib/iwidgets/scrolledtext.rb +568 -0
- data/lib/tkextlib/iwidgets/scrolledwidget.rb +20 -0
- data/lib/tkextlib/iwidgets/selectionbox.rb +102 -0
- data/lib/tkextlib/iwidgets/selectiondialog.rb +92 -0
- data/lib/tkextlib/iwidgets/setup.rb +8 -0
- data/lib/tkextlib/iwidgets/shell.rb +38 -0
- data/lib/tkextlib/iwidgets/spindate.rb +48 -0
- data/lib/tkextlib/iwidgets/spinint.rb +30 -0
- data/lib/tkextlib/iwidgets/spinner.rb +169 -0
- data/lib/tkextlib/iwidgets/spintime.rb +48 -0
- data/lib/tkextlib/iwidgets/tabnotebook.rb +181 -0
- data/lib/tkextlib/iwidgets/tabset.rb +145 -0
- data/lib/tkextlib/iwidgets/timeentry.rb +25 -0
- data/lib/tkextlib/iwidgets/timefield.rb +58 -0
- data/lib/tkextlib/iwidgets/toolbar.rb +112 -0
- data/lib/tkextlib/iwidgets/watch.rb +56 -0
- data/lib/tkextlib/pkg_checker.rb +184 -0
- data/lib/tkextlib/setup.rb +8 -0
- data/lib/tkextlib/tcllib.rb +105 -0
- data/lib/tkextlib/tcllib/autoscroll.rb +158 -0
- data/lib/tkextlib/tcllib/ctext.rb +160 -0
- data/lib/tkextlib/tcllib/cursor.rb +97 -0
- data/lib/tkextlib/tcllib/datefield.rb +57 -0
- data/lib/tkextlib/tcllib/dialog.rb +84 -0
- data/lib/tkextlib/tcllib/getstring.rb +134 -0
- data/lib/tkextlib/tcllib/history.rb +73 -0
- data/lib/tkextlib/tcllib/ico.rb +146 -0
- data/lib/tkextlib/tcllib/ip_entry.rb +75 -0
- data/lib/tkextlib/tcllib/panelframe.rb +78 -0
- data/lib/tkextlib/tcllib/plotchart.rb +1404 -0
- data/lib/tkextlib/tcllib/ruler.rb +65 -0
- data/lib/tkextlib/tcllib/screenruler.rb +68 -0
- data/lib/tkextlib/tcllib/scrollwin.rb +61 -0
- data/lib/tkextlib/tcllib/setup.rb +8 -0
- data/lib/tkextlib/tcllib/style.rb +61 -0
- data/lib/tkextlib/tcllib/superframe.rb +51 -0
- data/lib/tkextlib/tcllib/swaplist.rb +150 -0
- data/lib/tkextlib/tcllib/tablelist.rb +28 -0
- data/lib/tkextlib/tcllib/tablelist_core.rb +1072 -0
- data/lib/tkextlib/tcllib/tablelist_tile.rb +43 -0
- data/lib/tkextlib/tcllib/tkpiechart.rb +314 -0
- data/lib/tkextlib/tcllib/tooltip.rb +104 -0
- data/lib/tkextlib/tcllib/widget.rb +82 -0
- data/lib/tkextlib/tclx.rb +13 -0
- data/lib/tkextlib/tclx/setup.rb +8 -0
- data/lib/tkextlib/tclx/tclx.rb +74 -0
- data/lib/tkextlib/tile.rb +449 -0
- data/lib/tkextlib/tile/dialog.rb +102 -0
- data/lib/tkextlib/tile/setup.rb +8 -0
- data/lib/tkextlib/tile/sizegrip.rb +32 -0
- data/lib/tkextlib/tile/style.rb +336 -0
- data/lib/tkextlib/tile/tbutton.rb +34 -0
- data/lib/tkextlib/tile/tcheckbutton.rb +38 -0
- data/lib/tkextlib/tile/tcombobox.rb +55 -0
- data/lib/tkextlib/tile/tentry.rb +49 -0
- data/lib/tkextlib/tile/tframe.rb +34 -0
- data/lib/tkextlib/tile/tlabel.rb +34 -0
- data/lib/tkextlib/tile/tlabelframe.rb +38 -0
- data/lib/tkextlib/tile/tmenubutton.rb +38 -0
- data/lib/tkextlib/tile/tnotebook.rb +147 -0
- data/lib/tkextlib/tile/tpaned.rb +245 -0
- data/lib/tkextlib/tile/tprogressbar.rb +57 -0
- data/lib/tkextlib/tile/tradiobutton.rb +38 -0
- data/lib/tkextlib/tile/treeview.rb +1306 -0
- data/lib/tkextlib/tile/tscale.rb +56 -0
- data/lib/tkextlib/tile/tscrollbar.rb +63 -0
- data/lib/tkextlib/tile/tseparator.rb +34 -0
- data/lib/tkextlib/tile/tsquare.rb +30 -0
- data/lib/tkextlib/tkDND.rb +18 -0
- data/lib/tkextlib/tkDND/setup.rb +8 -0
- data/lib/tkextlib/tkDND/shape.rb +125 -0
- data/lib/tkextlib/tkDND/tkdnd.rb +182 -0
- data/lib/tkextlib/tkHTML.rb +13 -0
- data/lib/tkextlib/tkHTML/htmlwidget.rb +453 -0
- data/lib/tkextlib/tkHTML/setup.rb +8 -0
- data/lib/tkextlib/tkimg.rb +36 -0
- data/lib/tkextlib/tkimg/bmp.rb +33 -0
- data/lib/tkextlib/tkimg/gif.rb +33 -0
- data/lib/tkextlib/tkimg/ico.rb +33 -0
- data/lib/tkextlib/tkimg/jpeg.rb +33 -0
- data/lib/tkextlib/tkimg/pcx.rb +33 -0
- data/lib/tkextlib/tkimg/pixmap.rb +44 -0
- data/lib/tkextlib/tkimg/png.rb +33 -0
- data/lib/tkextlib/tkimg/ppm.rb +33 -0
- data/lib/tkextlib/tkimg/ps.rb +33 -0
- data/lib/tkextlib/tkimg/setup.rb +8 -0
- data/lib/tkextlib/tkimg/sgi.rb +33 -0
- data/lib/tkextlib/tkimg/sun.rb +33 -0
- data/lib/tkextlib/tkimg/tga.rb +33 -0
- data/lib/tkextlib/tkimg/tiff.rb +33 -0
- data/lib/tkextlib/tkimg/window.rb +33 -0
- data/lib/tkextlib/tkimg/xbm.rb +33 -0
- data/lib/tkextlib/tkimg/xpm.rb +33 -0
- data/lib/tkextlib/tktable.rb +14 -0
- data/lib/tkextlib/tktable/setup.rb +8 -0
- data/lib/tkextlib/tktable/tktable.rb +966 -0
- data/lib/tkextlib/tktrans.rb +14 -0
- data/lib/tkextlib/tktrans/setup.rb +8 -0
- data/lib/tkextlib/tktrans/tktrans.rb +64 -0
- data/lib/tkextlib/treectrl.rb +13 -0
- data/lib/tkextlib/treectrl/setup.rb +8 -0
- data/lib/tkextlib/treectrl/tktreectrl.rb +2522 -0
- data/lib/tkextlib/trofs.rb +13 -0
- data/lib/tkextlib/trofs/setup.rb +8 -0
- data/lib/tkextlib/trofs/trofs.rb +51 -0
- data/lib/tkextlib/version.rb +6 -0
- data/lib/tkextlib/vu.rb +48 -0
- data/lib/tkextlib/vu/bargraph.rb +61 -0
- data/lib/tkextlib/vu/charts.rb +53 -0
- data/lib/tkextlib/vu/dial.rb +102 -0
- data/lib/tkextlib/vu/pie.rb +286 -0
- data/lib/tkextlib/vu/setup.rb +8 -0
- data/lib/tkextlib/vu/spinbox.rb +22 -0
- data/lib/tkextlib/winico.rb +14 -0
- data/lib/tkextlib/winico/setup.rb +8 -0
- data/lib/tkextlib/winico/winico.rb +224 -0
- data/lib/tkfont.rb +4 -0
- data/lib/tkmacpkg.rb +4 -0
- data/lib/tkmenubar.rb +4 -0
- data/lib/tkmngfocus.rb +4 -0
- data/lib/tkpalette.rb +4 -0
- data/lib/tkscrollbox.rb +4 -0
- data/lib/tktext.rb +4 -0
- data/lib/tkvirtevent.rb +4 -0
- data/lib/tkwinpkg.rb +4 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/tk-win_spec.rb +7 -0
- data/tk-win.gemspec +373 -0
- metadata +412 -0
data/lib/tk/message.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#
|
2
|
+
# tk/message.rb : treat message widget
|
3
|
+
#
|
4
|
+
require 'tk'
|
5
|
+
require 'tk/label'
|
6
|
+
|
7
|
+
class Tk::Message<Tk::Label
|
8
|
+
TkCommandNames = ['message'.freeze].freeze
|
9
|
+
WidgetClassName = 'Message'.freeze
|
10
|
+
WidgetClassNames[WidgetClassName] ||= self
|
11
|
+
#def create_self(keys)
|
12
|
+
# if keys and keys != None
|
13
|
+
# tk_call_without_enc('message', @path, *hash_kv(keys, true))
|
14
|
+
# else
|
15
|
+
# tk_call_without_enc('message', @path)
|
16
|
+
# end
|
17
|
+
#end
|
18
|
+
private :create_self
|
19
|
+
end
|
20
|
+
|
21
|
+
#TkMessage = Tk::Message unless Object.const_defined? :TkMessage
|
22
|
+
#Tk.__set_toplevel_aliases__(:Tk, Tk::Message, :TkMessage)
|
23
|
+
Tk.__set_loaded_toplevel_aliases__('tk/message.rb', :Tk, Tk::Message,
|
24
|
+
:TkMessage)
|
data/lib/tk/mngfocus.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#
|
2
|
+
# tk/mngfocus.rb : methods for Tcl/Tk standard library 'focus.tcl'
|
3
|
+
# by Hidetoshi Nagai <nagai@ai.kyutech.ac.jp>
|
4
|
+
#
|
5
|
+
require 'tk'
|
6
|
+
|
7
|
+
module TkManageFocus
|
8
|
+
extend Tk
|
9
|
+
|
10
|
+
TkCommandNames = [
|
11
|
+
'tk_focusFollowMouse'.freeze,
|
12
|
+
'tk_focusNext'.freeze,
|
13
|
+
'tk_focusPrev'.freeze
|
14
|
+
].freeze
|
15
|
+
|
16
|
+
def TkManageFocus.followsMouse
|
17
|
+
tk_call_without_enc('tk_focusFollowsMouse')
|
18
|
+
end
|
19
|
+
|
20
|
+
def TkManageFocus.next(win)
|
21
|
+
tk_tcl2ruby(tk_call('tk_focusNext', win))
|
22
|
+
end
|
23
|
+
def focusNext
|
24
|
+
TkManageFocus.next(self)
|
25
|
+
end
|
26
|
+
|
27
|
+
def TkManageFocus.prev(win)
|
28
|
+
tk_tcl2ruby(tk_call('tk_focusPrev', win))
|
29
|
+
end
|
30
|
+
def focusPrev
|
31
|
+
TkManageFocus.prev(self)
|
32
|
+
end
|
33
|
+
end
|
data/lib/tk/msgcat.rb
ADDED
@@ -0,0 +1,296 @@
|
|
1
|
+
#
|
2
|
+
# tk/msgcat.rb : methods for Tcl message catalog
|
3
|
+
# by Hidetoshi Nagai <nagai@ai.kyutech.ac.jp>
|
4
|
+
#
|
5
|
+
require 'tk'
|
6
|
+
|
7
|
+
#class TkMsgCatalog
|
8
|
+
class TkMsgCatalog < TkObject
|
9
|
+
include TkCore
|
10
|
+
extend Tk
|
11
|
+
#extend TkMsgCatalog
|
12
|
+
|
13
|
+
TkCommandNames = [
|
14
|
+
'::msgcat::mc'.freeze,
|
15
|
+
'::msgcat::mcmax'.freeze,
|
16
|
+
'::msgcat::mclocale'.freeze,
|
17
|
+
'::msgcat::mcpreferences'.freeze,
|
18
|
+
'::msgcat::mcload'.freeze,
|
19
|
+
'::msgcat::mcset'.freeze,
|
20
|
+
'::msgcat::mcmset'.freeze,
|
21
|
+
'::msgcat::mcunknown'.freeze
|
22
|
+
].freeze
|
23
|
+
|
24
|
+
tk_call_without_enc('package', 'require', 'Tcl', '8.2')
|
25
|
+
|
26
|
+
PACKAGE_NAME = 'msgcat'.freeze
|
27
|
+
def self.package_name
|
28
|
+
PACKAGE_NAME
|
29
|
+
end
|
30
|
+
|
31
|
+
if self.const_defined? :FORCE_VERSION
|
32
|
+
tk_call_without_enc('package', 'require', 'msgcat', FORCE_VERSION)
|
33
|
+
else
|
34
|
+
tk_call_without_enc('package', 'require', 'msgcat')
|
35
|
+
end
|
36
|
+
|
37
|
+
MSGCAT_EXT = '.msg'
|
38
|
+
|
39
|
+
UNKNOWN_CBTBL = TkUtil.untrust(Hash.new{|hash,key| hash[key] = {}})
|
40
|
+
|
41
|
+
TkCore::INTERP.add_tk_procs('::msgcat::mcunknown', 'args', <<-'EOL')
|
42
|
+
if {[set st [catch {eval {ruby_cmd TkMsgCatalog callback} [namespace current] $args} ret]] != 0} {
|
43
|
+
#return -code $st $ret
|
44
|
+
set idx [string first "\n\n" $ret]
|
45
|
+
if {$idx > 0} {
|
46
|
+
return -code $st \
|
47
|
+
-errorinfo [string range $ret [expr $idx + 2] \
|
48
|
+
[string length $ret]] \
|
49
|
+
[string range $ret 0 [expr $idx - 1]]
|
50
|
+
} else {
|
51
|
+
return -code $st $ret
|
52
|
+
}
|
53
|
+
} else {
|
54
|
+
return $ret
|
55
|
+
}
|
56
|
+
EOL
|
57
|
+
|
58
|
+
def self.callback(namespace, locale, src_str, *args)
|
59
|
+
src_str = sprintf(src_str, *args) unless args.empty?
|
60
|
+
cmd_tbl = TkMsgCatalog::UNKNOWN_CBTBL[TkCore::INTERP.__getip]
|
61
|
+
cmd = cmd_tbl[namespace]
|
62
|
+
cmd = cmd_tbl['::'] unless cmd # use global scope as interp default
|
63
|
+
return src_str unless cmd # no cmd -> return src-str (default action)
|
64
|
+
begin
|
65
|
+
cmd.call(locale, src_str)
|
66
|
+
rescue SystemExit
|
67
|
+
exit(0)
|
68
|
+
rescue Interrupt
|
69
|
+
exit!(1)
|
70
|
+
rescue Exception => e
|
71
|
+
begin
|
72
|
+
msg = _toUTF8(e.class.inspect) + ': ' +
|
73
|
+
_toUTF8(e.message) + "\n" +
|
74
|
+
"\n---< backtrace of Ruby side >-----\n" +
|
75
|
+
_toUTF8(e.backtrace.join("\n")) +
|
76
|
+
"\n---< backtrace of Tk side >-------"
|
77
|
+
if TkCore::WITH_ENCODING
|
78
|
+
msg.force_encoding('utf-8')
|
79
|
+
else
|
80
|
+
msg.instance_variable_set(:@encoding, 'utf-8')
|
81
|
+
end
|
82
|
+
rescue Exception
|
83
|
+
msg = e.class.inspect + ': ' + e.message + "\n" +
|
84
|
+
"\n---< backtrace of Ruby side >-----\n" +
|
85
|
+
e.backtrace.join("\n") +
|
86
|
+
"\n---< backtrace of Tk side >-------"
|
87
|
+
end
|
88
|
+
fail(e, msg)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def initialize(namespace = nil)
|
93
|
+
if namespace.kind_of?(TkNamespace)
|
94
|
+
@namespace = namespace
|
95
|
+
elsif namespace == nil
|
96
|
+
@namespace = TkNamespace.new('::') # global namespace
|
97
|
+
else
|
98
|
+
@namespace = TkNamespace.new(namespace)
|
99
|
+
end
|
100
|
+
@path = @namespace.path
|
101
|
+
|
102
|
+
@msgcat_ext = '.msg'
|
103
|
+
end
|
104
|
+
attr_accessor :msgcat_ext
|
105
|
+
|
106
|
+
def method_missing(id, *args)
|
107
|
+
# locale(src, trans) ==> set_translation(locale, src, trans)
|
108
|
+
loc = id.id2name
|
109
|
+
case args.length
|
110
|
+
when 0 # set locale
|
111
|
+
self.locale=(loc)
|
112
|
+
|
113
|
+
when 1 # src only, or trans_list
|
114
|
+
if args[0].kind_of?(Array)
|
115
|
+
# trans_list
|
116
|
+
#list = args[0].collect{|src, trans|
|
117
|
+
# [ Tk::UTF8_String.new(src), Tk::UTF8_String.new(trans) ]
|
118
|
+
#}
|
119
|
+
self.set_translation_list(loc, args[0])
|
120
|
+
else
|
121
|
+
# src
|
122
|
+
#self.set_translation(loc, Tk::UTF8_String.new(args[0]))
|
123
|
+
self.set_translation(loc, args[0])
|
124
|
+
end
|
125
|
+
|
126
|
+
when 2 # src and trans, or, trans_list and enc
|
127
|
+
if args[0].kind_of?(Array)
|
128
|
+
else
|
129
|
+
#self.set_translation(loc, args[0], Tk::UTF8_String.new(args[1]))
|
130
|
+
self.set_translation(loc, *args)
|
131
|
+
end
|
132
|
+
|
133
|
+
when 3 # src and trans and enc
|
134
|
+
self.set_translation(loc, *args)
|
135
|
+
|
136
|
+
else
|
137
|
+
super(id, *args)
|
138
|
+
# fail NameError, "undefined method `#{name}' for #{self.to_s}", error_at
|
139
|
+
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# *args ::= form, arg, arg, ...
|
144
|
+
def self.translate(*args)
|
145
|
+
dst = args.collect{|src|
|
146
|
+
tk_call_without_enc('::msgcat::mc', _get_eval_string(src, true))
|
147
|
+
}
|
148
|
+
Tk.UTF8_String(sprintf(*dst))
|
149
|
+
end
|
150
|
+
class << self
|
151
|
+
alias mc translate
|
152
|
+
alias [] translate
|
153
|
+
end
|
154
|
+
def translate(*args)
|
155
|
+
dst = args.collect{|src|
|
156
|
+
@namespace.eval{tk_call_without_enc('::msgcat::mc',
|
157
|
+
_get_eval_string(src, true))}
|
158
|
+
}
|
159
|
+
Tk.UTF8_String(sprintf(*dst))
|
160
|
+
end
|
161
|
+
alias mc translate
|
162
|
+
alias [] translate
|
163
|
+
|
164
|
+
def self.maxlen(*src_strings)
|
165
|
+
tk_call('::msgcat::mcmax', *src_strings).to_i
|
166
|
+
end
|
167
|
+
def maxlen(*src_strings)
|
168
|
+
@namespace.eval{tk_call('::msgcat::mcmax', *src_strings).to_i}
|
169
|
+
end
|
170
|
+
|
171
|
+
def self.locale
|
172
|
+
tk_call('::msgcat::mclocale')
|
173
|
+
end
|
174
|
+
def locale
|
175
|
+
@namespace.eval{tk_call('::msgcat::mclocale')}
|
176
|
+
end
|
177
|
+
|
178
|
+
def self.locale=(locale)
|
179
|
+
tk_call('::msgcat::mclocale', locale)
|
180
|
+
end
|
181
|
+
def locale=(locale)
|
182
|
+
@namespace.eval{tk_call('::msgcat::mclocale', locale)}
|
183
|
+
end
|
184
|
+
|
185
|
+
def self.preferences
|
186
|
+
tk_split_simplelist(tk_call('::msgcat::mcpreferences'))
|
187
|
+
end
|
188
|
+
def preferences
|
189
|
+
tk_split_simplelist(@namespace.eval{tk_call('::msgcat::mcpreferences')})
|
190
|
+
end
|
191
|
+
|
192
|
+
def self.load_tk(dir)
|
193
|
+
number(tk_call('::msgcat::mcload', dir))
|
194
|
+
end
|
195
|
+
|
196
|
+
def self.load_rb(dir)
|
197
|
+
count = 0
|
198
|
+
preferences().each{|loc|
|
199
|
+
file = File.join(dir, loc + self::MSGCAT_EXT)
|
200
|
+
if File.readable?(file)
|
201
|
+
count += 1
|
202
|
+
eval(open(file){|f| f.read})
|
203
|
+
end
|
204
|
+
}
|
205
|
+
count
|
206
|
+
end
|
207
|
+
|
208
|
+
def load_tk(dir)
|
209
|
+
number(@namespace.eval{tk_call('::msgcat::mcload', dir)})
|
210
|
+
end
|
211
|
+
|
212
|
+
def load_rb(dir)
|
213
|
+
count = 0
|
214
|
+
preferences().each{|loc|
|
215
|
+
file = File.join(dir, loc + @msgcat_ext)
|
216
|
+
if File.readable?(file)
|
217
|
+
count += 1
|
218
|
+
@namespace.eval(open(file){|f| f.read})
|
219
|
+
end
|
220
|
+
}
|
221
|
+
count
|
222
|
+
end
|
223
|
+
|
224
|
+
def self.load(dir)
|
225
|
+
self.load_rb(dir)
|
226
|
+
end
|
227
|
+
alias load load_rb
|
228
|
+
|
229
|
+
def self.set_translation(locale, src_str, trans_str=None, enc='utf-8')
|
230
|
+
if trans_str && trans_str != None
|
231
|
+
trans_str = Tk.UTF8_String(_toUTF8(trans_str, enc))
|
232
|
+
Tk.UTF8_String(tk_call_without_enc('::msgcat::mcset',
|
233
|
+
locale,
|
234
|
+
_get_eval_string(src_str, true),
|
235
|
+
trans_str))
|
236
|
+
else
|
237
|
+
Tk.UTF8_String(tk_call_without_enc('::msgcat::mcset',
|
238
|
+
locale,
|
239
|
+
_get_eval_string(src_str, true)))
|
240
|
+
end
|
241
|
+
end
|
242
|
+
def set_translation(locale, src_str, trans_str=None, enc='utf-8')
|
243
|
+
if trans_str && trans_str != None
|
244
|
+
trans_str = Tk.UTF8_String(_toUTF8(trans_str, enc))
|
245
|
+
Tk.UTF8_String(@namespace.eval{
|
246
|
+
tk_call_without_enc('::msgcat::mcset',
|
247
|
+
locale,
|
248
|
+
_get_eval_string(src_str, true),
|
249
|
+
trans_str)
|
250
|
+
})
|
251
|
+
else
|
252
|
+
Tk.UTF8_String(@namespace.eval{
|
253
|
+
tk_call_without_enc('::msgcat::mcset',
|
254
|
+
locale,
|
255
|
+
_get_eval_string(src_str, true))})
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
def self.set_translation_list(locale, trans_list, enc='utf-8')
|
260
|
+
# trans_list ::= [ [src, trans], [src, trans], ... ]
|
261
|
+
list = []
|
262
|
+
trans_list.each{|src, trans|
|
263
|
+
if trans && trans != None
|
264
|
+
list << _get_eval_string(src, true)
|
265
|
+
list << Tk.UTF8_Stirng(_toUTF8(trans, enc))
|
266
|
+
else
|
267
|
+
list << _get_eval_string(src, true) << ''
|
268
|
+
end
|
269
|
+
}
|
270
|
+
number(tk_call_without_enc('::msgcat::mcmset', locale, list))
|
271
|
+
end
|
272
|
+
def set_translation_list(locale, trans_list, enc='utf-8')
|
273
|
+
# trans_list ::= [ [src, trans], [src, trans], ... ]
|
274
|
+
list = []
|
275
|
+
trans_list.each{|src, trans|
|
276
|
+
if trans && trans != None
|
277
|
+
list << _get_eval_string(src, true)
|
278
|
+
list << Tk.UTF8_String(_toUTF8(trans, enc))
|
279
|
+
else
|
280
|
+
list << _get_eval_string(src, true) << ''
|
281
|
+
end
|
282
|
+
}
|
283
|
+
number(@namespace.eval{
|
284
|
+
tk_call_without_enc('::msgcat::mcmset', locale, list)
|
285
|
+
})
|
286
|
+
end
|
287
|
+
|
288
|
+
def self.def_unknown_proc(cmd=Proc.new)
|
289
|
+
TkMsgCatalog::UNKNOWN_CBTBL[TkCore::INTERP.__getip]['::'] = cmd
|
290
|
+
end
|
291
|
+
def def_unknown_proc(cmd=Proc.new)
|
292
|
+
TkMsgCatalog::UNKNOWN_CBTBL[TkCore::INTERP.__getip][@namespace.path] = cmd
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
TkMsgCat = TkMsgCatalog
|
data/lib/tk/namespace.rb
ADDED
@@ -0,0 +1,551 @@
|
|
1
|
+
#
|
2
|
+
# tk/namespace.rb : methods to manipulate Tcl/Tk namespace
|
3
|
+
# by Hidetoshi Nagai <nagai@ai.kyutech.ac.jp>
|
4
|
+
#
|
5
|
+
require 'tk'
|
6
|
+
|
7
|
+
class TkNamespace < TkObject
|
8
|
+
extend Tk
|
9
|
+
|
10
|
+
TkCommandNames = [
|
11
|
+
'namespace'.freeze,
|
12
|
+
].freeze
|
13
|
+
|
14
|
+
Tk_Namespace_ID_TBL = TkCore::INTERP.create_table
|
15
|
+
|
16
|
+
(Tk_Namespace_ID = ["ns".freeze, TkUtil.untrust("00000")]).instance_eval{
|
17
|
+
@mutex = Mutex.new
|
18
|
+
def mutex; @mutex; end
|
19
|
+
freeze
|
20
|
+
}
|
21
|
+
|
22
|
+
Tk_NsCode_RetObjID_TBL = TkCore::INTERP.create_table
|
23
|
+
|
24
|
+
TkCore::INTERP.init_ip_env{
|
25
|
+
Tk_Namespace_ID_TBL.mutex.synchronize{ Tk_Namespace_ID_TBL.clear }
|
26
|
+
Tk_NsCode_RetObjID_TBL.mutex.synchronize{ Tk_NsCode_RetObjID_TBL.clear }
|
27
|
+
}
|
28
|
+
|
29
|
+
def TkNamespace.id2obj(id)
|
30
|
+
Tk_Namespace_ID_TBL.mutex.synchronize{
|
31
|
+
Tk_Namespace_ID_TBL[id]? Tk_Namespace_ID_TBL[id]: id
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
#####################################
|
36
|
+
|
37
|
+
class Ensemble < TkObject
|
38
|
+
def __cget_cmd
|
39
|
+
['namespace', 'ensemble', 'configure', self.path]
|
40
|
+
end
|
41
|
+
private :__cget_cmd
|
42
|
+
|
43
|
+
def __config_cmd
|
44
|
+
['namespace', 'ensemble', 'configure', self.path]
|
45
|
+
end
|
46
|
+
private :__config_cmd
|
47
|
+
|
48
|
+
def __configinfo_struct
|
49
|
+
{:key=>0, :alias=>nil, :db_name=>nil, :db_class=>nil,
|
50
|
+
:default_value=>nil, :current_value=>2}
|
51
|
+
end
|
52
|
+
private :__configinfo_struct
|
53
|
+
|
54
|
+
def __boolval_optkeys
|
55
|
+
['prefixes']
|
56
|
+
end
|
57
|
+
private :__boolval_optkeys
|
58
|
+
|
59
|
+
def __listval_optkeys
|
60
|
+
['map', 'subcommands', 'unknown']
|
61
|
+
end
|
62
|
+
private :__listval_optkeys
|
63
|
+
|
64
|
+
def self.exist?(ensemble)
|
65
|
+
bool(tk_call('namespace', 'ensemble', 'exists', ensemble))
|
66
|
+
end
|
67
|
+
|
68
|
+
def initialize(keys = {})
|
69
|
+
@ensemble = @path = tk_call('namespace', 'ensemble', 'create', keys)
|
70
|
+
end
|
71
|
+
|
72
|
+
def cget(slot)
|
73
|
+
if slot == :namespace || slot == 'namespace'
|
74
|
+
ns = super(slot)
|
75
|
+
Tk_Namespace_ID_TBL.mutex.synchronize{
|
76
|
+
if TkNamespace::Tk_Namespace_ID_TBL.key?(ns)
|
77
|
+
TkNamespace::Tk_Namespace_ID_TBL[ns]
|
78
|
+
else
|
79
|
+
ns
|
80
|
+
end
|
81
|
+
}
|
82
|
+
else
|
83
|
+
super(slot)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
def cget_strict(slot)
|
87
|
+
if slot == :namespace || slot == 'namespace'
|
88
|
+
ns = super(slot)
|
89
|
+
Tk_Namespace_ID_TBL.mutex.synchronize{
|
90
|
+
if TkNamespace::Tk_Namespace_ID_TBL.key?(ns)
|
91
|
+
TkNamespace::Tk_Namespace_ID_TBL[ns]
|
92
|
+
else
|
93
|
+
ns
|
94
|
+
end
|
95
|
+
}
|
96
|
+
else
|
97
|
+
super(slot)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def configinfo(slot = nil)
|
102
|
+
if slot
|
103
|
+
if slot == :namespace || slot == 'namespace'
|
104
|
+
val = super(slot)
|
105
|
+
Tk_Namespace_ID_TBL.mutex.synchronize{
|
106
|
+
if TkNamespace::Tk_Namespace_ID_TBL.key?(val)
|
107
|
+
val = TkNamespace::Tk_Namespace_ID_TBL[val]
|
108
|
+
end
|
109
|
+
}
|
110
|
+
else
|
111
|
+
val = super(slot)
|
112
|
+
end
|
113
|
+
|
114
|
+
if TkComm::GET_CONFIGINFO_AS_ARRAY
|
115
|
+
[slot.to_s, val]
|
116
|
+
else # ! TkComm::GET_CONFIGINFO_AS_ARRAY
|
117
|
+
{slot.to_s => val}
|
118
|
+
end
|
119
|
+
|
120
|
+
else
|
121
|
+
info = super()
|
122
|
+
|
123
|
+
if TkComm::GET_CONFIGINFO_AS_ARRAY
|
124
|
+
Tk_Namespace_ID_TBL.mutex.synchronize{
|
125
|
+
info.map!{|inf|
|
126
|
+
if inf[0] == 'namespace' &&
|
127
|
+
TkNamespace::Tk_Namespace_ID_TBL.key?(inf[-1])
|
128
|
+
[inf[0], TkNamespace::Tk_Namespace_ID_TBL[inf[-1]]]
|
129
|
+
else
|
130
|
+
inf
|
131
|
+
end
|
132
|
+
}
|
133
|
+
}
|
134
|
+
else # ! TkComm::GET_CONFIGINFO_AS_ARRAY
|
135
|
+
val = info['namespace']
|
136
|
+
Tk_Namespace_ID_TBL.mutex.synchronize{
|
137
|
+
if TkNamespace::Tk_Namespace_ID_TBL.key?(val)
|
138
|
+
info['namespace'] = TkNamespace::Tk_Namespace_ID_TBL[val]
|
139
|
+
end
|
140
|
+
}
|
141
|
+
end
|
142
|
+
|
143
|
+
info
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def exists?
|
148
|
+
bool(tk_call('namespace', 'ensemble', 'exists', @path))
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
#####################################
|
153
|
+
|
154
|
+
class ScopeArgs < Array
|
155
|
+
include Tk
|
156
|
+
|
157
|
+
# alias __tk_call tk_call
|
158
|
+
# alias __tk_call_without_enc tk_call_without_enc
|
159
|
+
# alias __tk_call_with_enc tk_call_with_enc
|
160
|
+
def tk_call(*args)
|
161
|
+
#super('namespace', 'eval', @namespace, *args)
|
162
|
+
args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''}
|
163
|
+
super('namespace', 'eval', @namespace,
|
164
|
+
TkCore::INTERP._merge_tklist(*args))
|
165
|
+
end
|
166
|
+
def tk_call_without_enc(*args)
|
167
|
+
#super('namespace', 'eval', @namespace, *args)
|
168
|
+
args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''}
|
169
|
+
super('namespace', 'eval', @namespace,
|
170
|
+
TkCore::INTERP._merge_tklist(*args))
|
171
|
+
end
|
172
|
+
def tk_call_with_enc(*args)
|
173
|
+
#super('namespace', 'eval', @namespace, *args)
|
174
|
+
args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''}
|
175
|
+
super('namespace', 'eval', @namespace,
|
176
|
+
TkCore::INTERP._merge_tklist(*args))
|
177
|
+
end
|
178
|
+
|
179
|
+
def initialize(namespace, *args)
|
180
|
+
@namespace = namespace
|
181
|
+
super(args.size)
|
182
|
+
self.replace(args)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
#####################################
|
187
|
+
|
188
|
+
class NsCode < TkObject
|
189
|
+
def initialize(scope, use_obj_id = false)
|
190
|
+
@scope = scope + ' '
|
191
|
+
@use_obj_id = use_obj_id
|
192
|
+
end
|
193
|
+
def path
|
194
|
+
@scope
|
195
|
+
end
|
196
|
+
def to_eval
|
197
|
+
@scope
|
198
|
+
end
|
199
|
+
def call(*args)
|
200
|
+
ret = TkCore::INTERP._eval_without_enc(@scope + array2tk_list(args))
|
201
|
+
if @use_obj_id
|
202
|
+
ret = TkNamespace::Tk_NsCode_RetObjID_TBL.delete(ret.to_i)
|
203
|
+
end
|
204
|
+
ret
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
#####################################
|
209
|
+
|
210
|
+
def install_cmd(cmd)
|
211
|
+
lst = tk_split_simplelist(super(cmd), false, false)
|
212
|
+
if lst[1] =~ /^::/
|
213
|
+
lst[1] = @fullname
|
214
|
+
else
|
215
|
+
lst.insert(1, @fullname)
|
216
|
+
end
|
217
|
+
TkCore::INTERP._merge_tklist(*lst)
|
218
|
+
end
|
219
|
+
|
220
|
+
alias __tk_call tk_call
|
221
|
+
alias __tk_call_without_enc tk_call_without_enc
|
222
|
+
alias __tk_call_with_enc tk_call_with_enc
|
223
|
+
def tk_call(*args)
|
224
|
+
#super('namespace', 'eval', @fullname, *args)
|
225
|
+
args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''}
|
226
|
+
super('namespace', 'eval', @fullname,
|
227
|
+
TkCore::INTERP._merge_tklist(*args))
|
228
|
+
end
|
229
|
+
def tk_call_without_enc(*args)
|
230
|
+
#super('namespace', 'eval', @fullname, *args)
|
231
|
+
args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''}
|
232
|
+
super('namespace', 'eval', @fullname,
|
233
|
+
TkCore::INTERP._merge_tklist(*args))
|
234
|
+
end
|
235
|
+
def tk_call_with_enc(*args)
|
236
|
+
#super('namespace', 'eval', @fullname, *args)
|
237
|
+
args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''}
|
238
|
+
super('namespace', 'eval', @fullname,
|
239
|
+
TkCore::INTERP._merge_tklist(*args))
|
240
|
+
end
|
241
|
+
alias ns_tk_call tk_call
|
242
|
+
alias ns_tk_call_without_enc tk_call_without_enc
|
243
|
+
alias ns_tk_call_with_enc tk_call_with_enc
|
244
|
+
|
245
|
+
def initialize(name = nil, parent = nil)
|
246
|
+
unless name
|
247
|
+
Tk_Namespace_ID.mutex.synchronize{
|
248
|
+
# name = Tk_Namespace_ID.join('')
|
249
|
+
name = Tk_Namespace_ID.join(TkCore::INTERP._ip_id_)
|
250
|
+
Tk_Namespace_ID[1].succ!
|
251
|
+
}
|
252
|
+
end
|
253
|
+
name = __tk_call('namespace', 'current') if name == ''
|
254
|
+
if parent
|
255
|
+
if parent =~ /^::/
|
256
|
+
if name =~ /^::/
|
257
|
+
@fullname = parent + name
|
258
|
+
else
|
259
|
+
@fullname = parent +'::'+ name
|
260
|
+
end
|
261
|
+
else
|
262
|
+
ancestor = __tk_call('namespace', 'current')
|
263
|
+
ancestor = '' if ancestor == '::'
|
264
|
+
if name =~ /^::/
|
265
|
+
@fullname = ancestor + '::' + parent + name
|
266
|
+
else
|
267
|
+
@fullname = ancestor + '::'+ parent +'::'+ name
|
268
|
+
end
|
269
|
+
end
|
270
|
+
else # parent == nil
|
271
|
+
ancestor = __tk_call('namespace', 'current')
|
272
|
+
ancestor = '' if ancestor == '::'
|
273
|
+
if name =~ /^::/
|
274
|
+
@fullname = name
|
275
|
+
else
|
276
|
+
@fullname = ancestor + '::' + name
|
277
|
+
end
|
278
|
+
end
|
279
|
+
@path = @fullname
|
280
|
+
@parent = __tk_call('namespace', 'qualifiers', @fullname)
|
281
|
+
@name = __tk_call('namespace', 'tail', @fullname)
|
282
|
+
|
283
|
+
# create namespace
|
284
|
+
__tk_call('namespace', 'eval', @fullname, '')
|
285
|
+
|
286
|
+
Tk_Namespace_ID_TBL.mutex.synchronize{
|
287
|
+
Tk_Namespace_ID_TBL[@fullname] = self
|
288
|
+
}
|
289
|
+
end
|
290
|
+
|
291
|
+
def self.children(*args)
|
292
|
+
# args ::= [<namespace>] [<pattern>]
|
293
|
+
# <pattern> must be glob-style pattern
|
294
|
+
tk_split_simplelist(tk_call('namespace', 'children', *args)).collect{|ns|
|
295
|
+
# ns is fullname
|
296
|
+
Tk_Namespace_ID_TBL.mutex.synchronize{
|
297
|
+
if Tk_Namespace_ID_TBL.key?(ns)
|
298
|
+
Tk_Namespace_ID_TBL[ns]
|
299
|
+
else
|
300
|
+
ns
|
301
|
+
end
|
302
|
+
}
|
303
|
+
}
|
304
|
+
end
|
305
|
+
def children(pattern=None)
|
306
|
+
TkNamespace.children(@fullname, pattern)
|
307
|
+
end
|
308
|
+
|
309
|
+
def self.code(script = Proc.new)
|
310
|
+
TkNamespace.new('').code(script)
|
311
|
+
end
|
312
|
+
=begin
|
313
|
+
def code(script = Proc.new)
|
314
|
+
if script.kind_of?(String)
|
315
|
+
cmd = proc{|*args| ScopeArgs.new(@fullname,*args).instance_eval(script)}
|
316
|
+
elsif script.kind_of?(Proc)
|
317
|
+
cmd = proc{|*args| ScopeArgs.new(@fullname,*args).instance_eval(&script)}
|
318
|
+
else
|
319
|
+
fail ArgumentError, "String or Proc is expected"
|
320
|
+
end
|
321
|
+
TkNamespace::NsCode.new(tk_call_without_enc('namespace', 'code',
|
322
|
+
_get_eval_string(cmd, false)))
|
323
|
+
end
|
324
|
+
=end
|
325
|
+
def code(script = Proc.new)
|
326
|
+
if script.kind_of?(String)
|
327
|
+
cmd = proc{|*args|
|
328
|
+
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
|
329
|
+
obj = ScopeArgs.new(@fullname,*args)
|
330
|
+
ret = obj.instance_exec(obj, script)
|
331
|
+
else
|
332
|
+
ret = ScopeArgs.new(@fullname,*args).instance_eval(script)
|
333
|
+
end
|
334
|
+
id = ret.object_id
|
335
|
+
TkNamespace::Tk_NsCode_RetObjID_TBL[id] = ret
|
336
|
+
id
|
337
|
+
}
|
338
|
+
elsif script.kind_of?(Proc)
|
339
|
+
cmd = proc{|*args|
|
340
|
+
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
|
341
|
+
obj = ScopeArgs.new(@fullname,*args)
|
342
|
+
ret = obj.instance_exec(obj, &script)
|
343
|
+
else
|
344
|
+
ret = ScopeArgs.new(@fullname,*args).instance_eval(&script)
|
345
|
+
end
|
346
|
+
id = ret.object_id
|
347
|
+
TkNamespace::Tk_NsCode_RetObjID_TBL[id] = ret
|
348
|
+
id
|
349
|
+
}
|
350
|
+
else
|
351
|
+
fail ArgumentError, "String or Proc is expected"
|
352
|
+
end
|
353
|
+
TkNamespace::NsCode.new(tk_call_without_enc('namespace', 'code',
|
354
|
+
_get_eval_string(cmd, false)),
|
355
|
+
true)
|
356
|
+
end
|
357
|
+
|
358
|
+
def self.current_path
|
359
|
+
tk_call('namespace', 'current')
|
360
|
+
end
|
361
|
+
def current_path
|
362
|
+
@fullname
|
363
|
+
end
|
364
|
+
|
365
|
+
def self.current
|
366
|
+
ns = self.current_path
|
367
|
+
Tk_Namespace_ID_TBL.mutex.synchronize{
|
368
|
+
if Tk_Namespace_ID_TBL.key?(ns)
|
369
|
+
Tk_Namespace_ID_TBL[ns]
|
370
|
+
else
|
371
|
+
ns
|
372
|
+
end
|
373
|
+
}
|
374
|
+
end
|
375
|
+
def current_namespace
|
376
|
+
# ns_tk_call('namespace', 'current')
|
377
|
+
# @fullname
|
378
|
+
self
|
379
|
+
end
|
380
|
+
alias current current_namespace
|
381
|
+
|
382
|
+
def self.delete(*ns_list)
|
383
|
+
tk_call('namespace', 'delete', *ns_list)
|
384
|
+
ns_list.each{|ns|
|
385
|
+
Tk_Namespace_ID_TBL.mutex.synchronize{
|
386
|
+
if ns.kind_of?(TkNamespace)
|
387
|
+
Tk_Namespace_ID_TBL.delete(ns.path)
|
388
|
+
else
|
389
|
+
Tk_Namespace_ID_TBL.delete(ns.to_s)
|
390
|
+
end
|
391
|
+
}
|
392
|
+
}
|
393
|
+
end
|
394
|
+
def delete
|
395
|
+
TkNamespece.delete(@fullname)
|
396
|
+
end
|
397
|
+
|
398
|
+
def self.ensemble_create(*keys)
|
399
|
+
tk_call('namespace', 'ensemble', 'create', *hash_kv(keys))
|
400
|
+
end
|
401
|
+
def self.ensemble_configure(cmd, slot, value=None)
|
402
|
+
if slot.kind_of?(Hash)
|
403
|
+
tk_call('namespace', 'ensemble', 'configure', cmd, *hash_kv(slot))
|
404
|
+
else
|
405
|
+
tk_call('namespace', 'ensemble', 'configure', cmd, '-'+slot.to_s, value)
|
406
|
+
end
|
407
|
+
end
|
408
|
+
def self.ensemble_configinfo(cmd, slot = nil)
|
409
|
+
if slot
|
410
|
+
tk_call('namespace', 'ensemble', 'configure', cmd, '-' + slot.to_s)
|
411
|
+
else
|
412
|
+
inf = {}
|
413
|
+
Hash(*tk_split_simplelist(tk_call('namespace', 'ensemble', 'configure', cmd))).each{|k, v| inf[k[1..-1]] = v}
|
414
|
+
inf
|
415
|
+
end
|
416
|
+
end
|
417
|
+
def self.ensemble_exist?(cmd)
|
418
|
+
bool(tk_call('namespace', 'ensemble', 'exists', cmd))
|
419
|
+
end
|
420
|
+
|
421
|
+
def self.eval(namespace, cmd = Proc.new, *args)
|
422
|
+
#tk_call('namespace', 'eval', namespace, cmd, *args)
|
423
|
+
TkNamespace.new(namespace).eval(cmd, *args)
|
424
|
+
end
|
425
|
+
=begin
|
426
|
+
def eval(cmd = Proc.new, *args)
|
427
|
+
#TkNamespace.eval(@fullname, cmd, *args)
|
428
|
+
#ns_tk_call(cmd, *args)
|
429
|
+
code_obj = code(cmd)
|
430
|
+
ret = code_obj.call(*args)
|
431
|
+
# uninstall_cmd(TkCore::INTERP._split_tklist(code_obj.path)[-1])
|
432
|
+
uninstall_cmd(_fromUTF8(TkCore::INTERP._split_tklist(_toUTF8(code_obj.path))[-1]))
|
433
|
+
tk_tcl2ruby(ret)
|
434
|
+
end
|
435
|
+
=end
|
436
|
+
def eval(cmd = Proc.new, *args)
|
437
|
+
code_obj = code(cmd)
|
438
|
+
ret = code_obj.call(*args)
|
439
|
+
uninstall_cmd(_fromUTF8(TkCore::INTERP._split_tklist(_toUTF8(code_obj.path))[-1]))
|
440
|
+
ret
|
441
|
+
end
|
442
|
+
|
443
|
+
def self.exist?(ns)
|
444
|
+
bool(tk_call('namespace', 'exists', ns))
|
445
|
+
end
|
446
|
+
def exist?
|
447
|
+
TkNamespece.exist?(@fullname)
|
448
|
+
end
|
449
|
+
|
450
|
+
def self.export(*patterns)
|
451
|
+
tk_call('namespace', 'export', *patterns)
|
452
|
+
end
|
453
|
+
def self.export_with_clear(*patterns)
|
454
|
+
tk_call('namespace', 'export', '-clear', *patterns)
|
455
|
+
end
|
456
|
+
def export
|
457
|
+
TkNamespace.export(@fullname)
|
458
|
+
end
|
459
|
+
def export_with_clear
|
460
|
+
TkNamespace.export_with_clear(@fullname)
|
461
|
+
end
|
462
|
+
|
463
|
+
def self.forget(*patterns)
|
464
|
+
tk_call('namespace', 'forget', *patterns)
|
465
|
+
end
|
466
|
+
def forget
|
467
|
+
TkNamespace.forget(@fullname)
|
468
|
+
end
|
469
|
+
|
470
|
+
def self.import(*patterns)
|
471
|
+
tk_call('namespace', 'import', *patterns)
|
472
|
+
end
|
473
|
+
def self.force_import(*patterns)
|
474
|
+
tk_call('namespace', 'import', '-force', *patterns)
|
475
|
+
end
|
476
|
+
def import
|
477
|
+
TkNamespace.import(@fullname)
|
478
|
+
end
|
479
|
+
def force_import
|
480
|
+
TkNamespace.force_import(@fullname)
|
481
|
+
end
|
482
|
+
|
483
|
+
def self.inscope(namespace, script, *args)
|
484
|
+
tk_call('namespace', 'inscope', namespace, script, *args)
|
485
|
+
end
|
486
|
+
def inscope(script, *args)
|
487
|
+
TkNamespace.inscope(@fullname, script, *args)
|
488
|
+
end
|
489
|
+
|
490
|
+
def self.origin(cmd)
|
491
|
+
tk_call('namespace', 'origin', cmd)
|
492
|
+
end
|
493
|
+
|
494
|
+
def self.parent(namespace=None)
|
495
|
+
ns = tk_call('namespace', 'parent', namespace)
|
496
|
+
Tk_Namespace_ID_TBL.mutex.synchronize{
|
497
|
+
if Tk_Namespace_ID_TBL.key?(ns)
|
498
|
+
Tk_Namespace_ID_TBL[ns]
|
499
|
+
else
|
500
|
+
ns
|
501
|
+
end
|
502
|
+
}
|
503
|
+
end
|
504
|
+
def parent
|
505
|
+
tk_call('namespace', 'parent', @fullname)
|
506
|
+
end
|
507
|
+
|
508
|
+
def self.get_path
|
509
|
+
tk_call('namespace', 'path')
|
510
|
+
end
|
511
|
+
def self.set_path(*namespace_list)
|
512
|
+
tk_call('namespace', 'path', array2tk_list(namespace_list))
|
513
|
+
end
|
514
|
+
def set_path
|
515
|
+
tk_call('namespace', 'path', @fullname)
|
516
|
+
end
|
517
|
+
|
518
|
+
def self.qualifiers(str)
|
519
|
+
tk_call('namespace', 'qualifiers', str)
|
520
|
+
end
|
521
|
+
|
522
|
+
def self.tail(str)
|
523
|
+
tk_call('namespace', 'tail', str)
|
524
|
+
end
|
525
|
+
|
526
|
+
def self.upvar(namespace, *var_pairs)
|
527
|
+
tk_call('namespace', 'upvar', namespace, *(var_pairs.flatten))
|
528
|
+
end
|
529
|
+
def upvar(*var_pairs)
|
530
|
+
TkNamespace.inscope(@fullname, *(var_pairs.flatten))
|
531
|
+
end
|
532
|
+
|
533
|
+
def self.get_unknown_handler
|
534
|
+
tk_tcl2ruby(tk_call('namespace', 'unknown'))
|
535
|
+
end
|
536
|
+
def self.set_unknown_handler(cmd = Proc.new)
|
537
|
+
tk_call('namespace', 'unknown', cmd)
|
538
|
+
end
|
539
|
+
|
540
|
+
def self.which(name)
|
541
|
+
tk_call('namespace', 'which', name)
|
542
|
+
end
|
543
|
+
def self.which_command(name)
|
544
|
+
tk_call('namespace', 'which', '-command', name)
|
545
|
+
end
|
546
|
+
def self.which_variable(name)
|
547
|
+
tk_call('namespace', 'which', '-variable', name)
|
548
|
+
end
|
549
|
+
end
|
550
|
+
|
551
|
+
TkNamespace::Global = TkNamespace.new('::')
|