* ext/tk/lib/tkextlib/blt.rb: add BLT extension support

* ext/tk/lib/tkextlib/blt/*.rb: ditto
* ext/tk/lib/tkextlib/blt/tile/*.rb: ditto


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7645 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagai 2004-12-23 16:23:30 +00:00
Родитель d34a65bc40
Коммит 532e34fcd2
37 изменённых файлов: 5819 добавлений и 6 удалений

Просмотреть файл

@ -1,3 +1,11 @@
Fri Dec 24 01:21:00 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tkextlib/blt.rb: add BLT extension support
* ext/tk/lib/tkextlib/blt/*.rb: ditto
* ext/tk/lib/tkextlib/blt/tile/*.rb: ditto
Thu Dec 23 23:43:24 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* process.c (proc_setgroups): check if the argument lenght is

Просмотреть файл

@ -1,3 +1,7 @@
2004-12-24 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* add BLT extension support
2004-12-16 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* bwidget/labelentry.rb: use TkCore.callback_obj?()

Просмотреть файл

@ -3940,7 +3940,7 @@ end
#Tk.freeze
module Tk
RELEASE_DATE = '2004-12-23'.freeze
RELEASE_DATE = '2004-12-24'.freeze
autoload :AUTO_PATH, 'tk/variable'
autoload :TCL_PACKAGE_PATH, 'tk/variable'

Просмотреть файл

@ -83,6 +83,10 @@ Tile http://tktable.sourceforge.net/tile/ ==> tile
===< possibly available (not tested; alpha quality) >=========================
BLT http://sourceforge.net/projects/blt
* see tcltk-ext library on RAA (http://raa.ruby-lang.org/)
==> blt
winico http://tktable.sourceforge.net
==> winico (win32 only)
@ -95,9 +99,6 @@ TkDND http://sourceforge.net/projects/tkdnd ==> tkDND
===< plan to support (alpha quality libraries may be included) >==============
BLT http://sourceforge.net/projects/blt
* see tcltk-ext library on RAA (http://raa.ruby-lang.org/)
GraphViz http://www.graphviz.org/
Tkgeomap http://tkgeomap.sourceforge.net/index.html
@ -169,5 +170,4 @@ Memchan http://memchan.sourceforge.net/
tbcload/tclcompiler http://www.tcl.tk/software/tclpro/
(End of List)
(End of List)

142
ext/tk/lib/tkextlib/blt.rb Normal file
Просмотреть файл

@ -0,0 +1,142 @@
#
# BLT support
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tk/variable'
# call setup script for general 'tkextlib' libraries
require 'tkextlib/setup.rb'
# call setup script
require 'tkextlib/blt/setup.rb'
# load all image format handlers
#TkPackage.require('BLT', '2.4')
TkPackage.require('BLT')
module Tk
module BLT
TkComm::TkExtlibAutoloadModule.unshift(self)
extend TkCore
VERSION = tk_call('set', 'blt_version')
PATCH_LEVEL = tk_call('set', 'blt_patchLevel')
begin
lib = INTERP._invoke('set', 'blt_library')
rescue
lib = ''
end
LIBRARY = TkVarAccess.new('blt_library', lib)
begin
lib = INTERP._invoke('set', 'blt_libPath')
rescue
lib = ''
end
LIB_PATH = TkVarAccess.new('blt_libPath', lib)
def self.package_version
begin
TkPackage.require('BLT')
rescue
''
end
end
####################################################
def self.beep(percent = 50)
tk_call('::blt::beep', percent)
end
def self.bgexec(*args)
if args[0].kind_of?(TkVariable)
var = args.shift
else
var = TkVariable.new
end
params = [var]
params.concat(hash_kv(args.shift, true)) if args[0].kind_of?(Hash)
params << '--'
params.concat(args)
tk_call('::blt::bgexec', *params)
var
end
def self.detach_bgexec(*args)
if args[0].kind_of?(TkVariable)
var = args.shift
else
var = TkVariable.new
end
params = [var]
params.concat(hash_kv(args.shift, true)) if args[0].kind_of?(Hash)
params << '--'
params.concat(args)
params << '&'
[var, tk_split_list(tk_call('::blt::bgexec', *params))]
end
def self.bltdebug(lvl = nil)
if lvl
tk_call('::blt::bltdebug', lvl)
else
number(tk_call('::blt::bltdebug'))
end
end
def self.crc32_file(name)
tk_call_without_enc('::blt::crc32', name)
end
def self.crc32_data(dat)
tk_call_without_enc('::blt::crc32', '-data', dat)
end
####################################################
autoload :PlotComponent,'tkextlib/blt/component.rb'
autoload :Barchart, 'tkextlib/blt/barchart.rb'
autoload :Bitmap, 'tkextlib/blt/bitmap.rb'
autoload :Busy, 'tkextlib/blt/busy.rb'
autoload :Container, 'tkextlib/blt/container.rb'
autoload :CutBuffer, 'tkextlib/blt/cutbuffer.rb'
autoload :DragDrop, 'tkextlib/blt/dragdrop.rb'
autoload :EPS, 'tkextlib/blt/eps.rb'
autoload :Htext, 'tkextlib/blt/htext.rb'
autoload :Graph, 'tkextlib/blt/graph.rb'
autoload :Spline, 'tkextlib/blt/spline.rb'
autoload :Stripchart, 'tkextlib/blt/stripchart.rb'
autoload :Table, 'tkextlib/blt/table.rb'
autoload :Tabnotebook, 'tkextlib/blt/tabnotebook.rb'
autoload :Tabset, 'tkextlib/blt/tabset.rb'
autoload :Ted, 'tkextlib/blt/ted.rb'
autoload :Tile, 'tkextlib/blt/tile.rb'
autoload :Tree, 'tkextlib/blt/tree.rb'
autoload :TreeView, 'tkextlib/blt/treeview.rb'
autoload :Hiertable, 'tkextlib/blt/treeview.rb'
# Hierbox is obsolete
autoload :Vector, 'tkextlib/blt/vector.rb'
autoload :VectorAccess, 'tkextlib/blt/vector.rb'
autoload :Watch, 'tkextlib/blt/watch.rb'
autoload :Winop, 'tkextlib/blt/winop.rb'
autoload :WinOp, 'tkextlib/blt/winop.rb'
# Unix only
autoload :DnD, 'tkextlib/blt/unix_dnd.rb'
# Windows only
autoload :Printer, 'tkextlib/blt/win_printer.rb'
end
end

Просмотреть файл

@ -0,0 +1,70 @@
#
# tkextlib/blt/barchart.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/blt.rb'
require 'tkextlib/blt/component.rb'
module Tk::BLT
class Barchart < TkWindow
TkCommandNames = ['::blt::barchart'.freeze].freeze
WidgetClassName = 'Barchart'.freeze
WidgetClassNames[WidgetClassName] = self
include PlotComponent
def __boolval_optkeys
['bufferelements', 'invertxy']
end
private :__boolval_optkeys
def __strval_optkeys
['text', 'label', 'title', 'file']
end
private :__strval_optkeys
BarElement_ID = ['blt_barchart_bar'.freeze, '00000'.taint].freeze
def bar(elem=nil, keys={})
if elem.kind_of?(Hash)
keys = elem
elem = nil
end
unless elem
elem = BarElement_ID.join(TkCore::INTERP._ip_id_).freeze
BarElement_ID[1].succ!
end
tk_send('bar', elem, keys)
Element.new(self, elem, :without_creating=>true)
end
def extents(item)
num_or_str(tk_send_without_enc('extents', item))
end
def invtransform(x, y)
list(tk_send_without_enc('invtransform', x, y))
end
def inside(x, y)
bool(tk_send_without_enc('inside', x, y))
end
def metafile(file=None)
# Windows only
tk_send('metafile', file)
self
end
def snap(output, keys={})
tk_send_without_enc('snap', *(hash_kv(keys, false) + output))
self
end
def transform(x, y)
list(tk_send_without_enc('transform', x, y))
end
end
end

Просмотреть файл

@ -0,0 +1,84 @@
#
# tkextlib/blt/bitmap.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/blt.rb'
module Tk::BLT
class Bitmap < TkObject
extend TkCore
TkCommandNames = ['::blt::bitmap'.freeze].freeze
BITMAP_ID_TBL = TkCore::INTERP.create_table
BITMAP_ID = ['blt_bitmap_id'.freeze, '00000'.taint].freeze
def self.data(name)
dat = tk_simple_list(tk_call('::blt::bitmap', 'data', name))
[ tk_split_list(dat[0]), tk_simple_list(dat[1]) ]
end
def self.exist?(name)
bool(tk_call('::blt::bitmap', 'exists', name))
end
def self.height(name)
number(tk_call('::blt::bitmap', 'height', name))
end
def self.width(name)
number(tk_call('::blt::bitmap', 'width', name))
end
def self.source(name)
tk_simple_list(tk_call('::blt::bitmap', 'source', name))
end
#################################
class << self
alias _new new
def new(data, keys={})
_new(:data, data, keys)
end
alias define new
def compose(text, keys={})
_new(:text, text, keys)
end
end
def initialize(type, data, keys = {})
@id = BITMAP_ID.join(TkCore::INTERP._ip_id_)
BITMAP_ID[1].succ!
BITMAP_ID_TBL[@id] = self
@path = @id
if type == :text
tk_call('::blt::bitmap', 'compose', @id, *hash_kv(keys))
else # :data
tk_call('::blt::bitmap', 'define', @id, *hash_kv(keys))
end
end
def exist?
bool(tk_call('::blt::bitmap', 'exists', @id))
end
def height
number(tk_call('::blt::bitmap', 'height', @id))
end
def width
number(tk_call('::blt::bitmap', 'width', @id))
end
def source
tk_simple_list(tk_call('::blt::bitmap', 'source', @id))
end
end
end

Просмотреть файл

@ -0,0 +1,82 @@
#
# tkextlib/blt/busy.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tk/itemconfig.rb'
require 'tkextlib/blt.rb'
module Tk::BLT
module Busy
extend TkCore
extend TkItemConfigMethod
TkCommandNames = ['::blt::busy'.freeze].freeze
end
end
class << Tk::BLT::Busy
def __item_config_cmd(win)
['::blt::busy', 'configure', win]
end
private :__item_config_cmd
undef itemcget
alias configure itemconfigure
alias configinfo itemconfiginfo
alias current_configinfo current_itemconfiginfo
private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
##################################
class Shield < TkWindow
def self.shield_path(win)
win = window(win) unless win.kind_of?(TkWindow)
if win.kind_of?(TkToplevel)
win.path + '._Busy'
else
win.path + '_Busy'
end
end
def initialize(win)
@path = self.class.shield_path(win)
end
end
def shield_path(win)
Tk::BLT::Busy::Shield.shield_path(win)
end
##################################
def hold(win, keys={})
tk_call('::blt::busy', 'hold', win, *hash_kv(keys))
end
def release(*wins)
tk_call('::blt::busy', 'release', *wins)
end
def forget(*wins)
tk_call('::blt::busy', 'forget', *wins)
end
def is_busy(pat=None)
tk_split_list(tk_call('::blt::busy', 'isbusy', pat))
end
def names(pat=None)
tk_split_list(tk_call('::blt::busy', 'names', pat))
end
alias windows names
def check(win)
bool(tk_call('::blt::busy', 'check', win))
end
def status(win)
bool(tk_call('::blt::busy', 'status', win))
end
end

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,23 @@
#
# tkextlib/blt/container.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/blt.rb'
module Tk::BLT
class Container < TkWindow
TkCommandNames = ['::blt::container'.freeze].freeze
WidgetClassName = 'Container'.freeze
WidgetClassNames[WidgetClassName] = self
end
def find_command(pat)
list(tk_send_without_enc(tk_call(self.path, 'find', '-command', pat)))
end
def find_name(pat)
list(tk_send_without_enc(tk_call(self.path, 'find', '-name', pat)))
end
end

Просмотреть файл

@ -0,0 +1,23 @@
#
# tkextlib/blt/cutbuffer.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/blt.rb'
module Tk::BLT
module CutBuffer
TkCommandNames = ['::blt::cutbuffer'.freeze].freeze
def self.get(num = 0)
Tk.tk_call('::blt::cutbuffer', 'get', num)
end
def self.rotate(count = 1)
Tk.tk_call('::blt::cutbuffer', 'rotate', count)
end
def self.set(val, num = 0)
Tk.tk_call('::blt::cutbuffer', 'set', val, num)
end
end
end

Просмотреть файл

@ -0,0 +1,199 @@
#
# tkextlib/blt/dragdrop.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tk/itemconfig'
require 'tkextlib/blt.rb'
module Tk::BLT
module DragDrop
extend TkCore
TkCommandNames = ['::blt::drag&drop'.freeze].freeze
class Token < TkWindow
WidgetClassName = 'DragDropToken'.freeze
WidgetClassNames[WidgetClassName] = self
def initialize(arg)
if arg.kind_of?(Hash) # arg is a hash includes the widgetpath of token
arg = _symbolkey2str(arg)
install_win(nil, arg['widgetname'])
else # arg is a drag&drop source
tk_call('::blt::drag&drop', 'source', arg)
install_win(nil, tk_call('::blt::drag&drop', 'token', arg))
end
end
end
###################################
extend TkItemConfigMethod
extend Tk::ValidateConfigure
class << self
def __item_config_cmd(id) # id := ['source'|'target', win]
['::blt::drag&drop', id[0], id[1]]
end
private :__item_config_cmd
undef itemcget
private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
def source_configure(win, slot, value=None)
itemconfigure(['source', win], slot, value)
end
def source_configinfo(win, slot=nil)
itemconfiginfo(['source', win], slot)
end
def current_source_configinfo(win, slot=nil)
current_itemconfiginfo(['source', win], slot)
end
end
class PackageCommand < TkValidateCommand
class ValidateArgs < TkUtil::CallbackSubst
KEY_TBL = [
[ ?t, ?w, :token ],
[ ?W, ?w, :widget ],
nil
]
PROC_TBL = [
[ ?w, TkComm.method(:window) ],
nil
]
_setup_subst_table(KEY_TBL, PROC_TBL)
def self.ret_val(val)
val
end
end
def self._config_keys
['packagecmd']
end
end
class SiteCommand < TkValidateCommand
class ValidateArgs < TkUtil::CallbackSubst
KEY_TBL = [
[ ?s, ?b, :compatible ],
[ ?t, ?w, :token ],
nil
]
PROC_TBL = [
[ ?b, TkComm.method(:bool) ],
[ ?w, TkComm.method(:window) ],
nil
]
_setup_subst_table(KEY_TBL, PROC_TBL)
def self.ret_val(val)
val
end
end
def self._config_keys
['sitecmd']
end
end
def self.__validation_class_list
super << PackageCommand << SiteCommand
end
class << self
Tk::ValidateConfigure.__def_validcmd(binding, PackageCommand)
Tk::ValidateConfigure.__def_validcmd(binding, SiteCommand)
end
###################################
class DnD_Handle < TkUtil::CallbackSubst
KEY_TBL = [
[ ?i, ?s, :ip_name ],
[ ?v, ?v, :value ],
[ ?W, ?w, :widget ],
nil
]
PROC_TBL = [
[ ?i, TkComm.method(:string) ],
[ ?v, TkComm.method(:tk_tcl2ruby) ],
[ ?w, TkComm.method(:window) ],
nil
]
_setup_subst_table(KEY_TBL, PROC_TBL)
end
def self.source_handler(win, datatype, cmd=Proc.new, *args)
_bind_for_event_class(DnD_Handle,
['::blt::drag&drop', 'source', win, 'handler'],
cmd, *args)
end
def self.target_handler(win, datatype, cmd=Proc.new, *args)
_bind_for_event_class(DnD_Handle,
['::blt::drag&drop', 'target', win, 'handler'],
cmd, *args)
end
###################################
def self.init_source(win)
tk_call('::blt::drag&drop', 'source', win)
end
def self.source()
list(tk_call('::blt::drag&drop', 'source'))
end
def self.source_handler_list(win)
simplelist(tk_call('::blt::drag&drop', 'source', win, 'handler'))
end
def self.source_handler_info(win, type)
tk_tcl2ruby(tk_call('::blt::drag&drop', 'source', win, 'handler', type))
end
def self.target
list(tk_call('::blt::drag&drop', 'target'))
end
def self.target_handler_list(win)
simplelist(tk_call('::blt::drag&drop', 'target', win, 'handler'))
end
def self.handle_target(win, type, val=None)
tk_call('::blt::drag&drop', 'target', win, 'handle', type, val)
end
def self.token(win)
window(tk_call('::blt::drag&drop', 'token', win))
end
def self.drag(win, x, y)
tk_call('::blt::drag&drop', 'drag', win, x, y)
end
def self.drop(win, x, y)
tk_call('::blt::drag&drop', 'drop', win, x, y)
end
def self.errors(cmd=Proc.new)
tk_call('::blt::drag&drop', 'errors', cmd)
end
def self.active
bool(tk_call('::blt::drag&drop', 'active'))
end
def self.location(x=None, y=None)
list(tk_call('::blt::drag&drop', 'location', x, y))
end
end
end

Просмотреть файл

@ -0,0 +1,15 @@
#
# tkextlib/blt/eps.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tk/canvas'
require 'tkextlib/blt.rb'
module Tk::BLT
class EPS < TkcItem
CItemTypeName = 'eps'.freeze
CItemTypeToClass[CItemTypeName] = self
end
end

Просмотреть файл

@ -0,0 +1,64 @@
#
# tkextlib/blt/graph.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/blt.rb'
require 'tkextlib/blt/component.rb'
module Tk::BLT
class Graph < TkWindow
TkCommandNames = ['::blt::graph'.freeze].freeze
WidgetClassName = 'Graph'.freeze
WidgetClassNames[WidgetClassName] = self
include PlotComponent
def __boolval_optkeys
['bufferelements', 'invertxy']
end
private :__boolval_optkeys
def __strval_optkeys
['text', 'label', 'title', 'file']
end
private :__strval_optkeys
BarElement_ID = ['blt_graph_bar'.freeze, '00000'.taint].freeze
def bar(elem=nil, keys={})
if elem.kind_of?(Hash)
keys = elem
elem = nil
end
unless elem
elem = BarElement_ID.join(TkCore::INTERP._ip_id_).freeze
BarElement_ID[1].succ!
end
tk_send('bar', elem, keys)
Element.new(self, elem, :without_creating=>true)
end
def extents(item)
num_or_str(tk_send_without_enc('extents', item))
end
def invtransform(x, y)
list(tk_send_without_enc('invtransform', x, y))
end
def inside(x, y)
bool(tk_send_without_enc('inside', x, y))
end
def snap(output, keys={})
tk_send_without_enc('snap', *(hash_kv(keys, false) + output))
self
end
def transform(x, y)
list(tk_send_without_enc('transform', x, y))
end
end
end

Просмотреть файл

@ -0,0 +1,100 @@
#
# tkextlib/blt/htext.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tk/itemconfig.rb'
require 'tkextlib/blt.rb'
module Tk::BLT
class Htext<TkWindow
include TkItemConfigMethod
include Scrollable
TkCommandNames = ['::blt::htext'.freeze].freeze
WidgetClassName = 'Htext'.freeze
WidgetClassNames[WidgetClassName] = self
alias window_cget itemcget
alias window_configure itemconfigure
alias window_configuinfo itemconfiginfo
alias current_window_configuinfo current_itemconfiginfo
def append(win, keys={})
tk_send('append', _epath(win), keys)
self
end
def goto_line(idx)
tk_send_without_enc('gotoline', idx)
self
end
def current_line
number(tk_send_without_enc('gotoline'))
end
def index(str)
number(tk_send('index', str))
end
def line_pos(str)
tk_send('linepos', str)
end
def range(from=None, to=None)
tk_send_without_enc('range', from, to)
end
def scan_mark(pos)
tk_send_without_enc('scan', 'mark', pos)
self
end
def scan_dragto(pos)
tk_send_without_enc('scan', 'dragto', pos)
self
end
def search(pat, from=None, to=None)
num = number(tk_send('search', pat, from, to))
(num < 0)? nil: num
end
def selection_adjust(index)
tk_send_without_enc('selection', 'adjust', index)
self
end
def selection_clear()
tk_send_without_enc('selection', 'clear')
self
end
def selection_from(index)
tk_send_without_enc('selection', 'from', index)
self
end
def selection_line(index)
tk_send_without_enc('selection', 'line', index)
self
end
def selection_present()
bool(tk_send_without_enc('selection', 'present'))
end
def selection_range(first, last)
tk_send_without_enc('selection', 'range', first, last)
self
end
def selection_to(index)
tk_send_without_enc('selection', 'to', index)
self
end
def selection_word(index)
tk_send_without_enc('selection', 'word', index)
self
end
def windows(pat=None)
list(tk_send('windows', pat))
end
end
end

Просмотреть файл

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

Просмотреть файл

@ -0,0 +1,23 @@
#
# tkextlib/blt/spline.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/blt.rb'
module Tk::BLT
module Spline
extend TkCore
TkCommandNames = ['::blt::spline'.freeze].freeze
def self.natural(x, y, sx, sy)
tk_call('::blt::spline', 'natural', x, y, sx, sy)
end
def self.quadratic(x, y, sx, sy)
tk_call('::blt::spline', 'quadratic', x, y, sx, sy)
end
end
end

Просмотреть файл

@ -0,0 +1,70 @@
#
# tkextlib/blt/stripchart.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/blt.rb'
require 'tkextlib/blt/component.rb'
module Tk::BLT
class Stripchart < TkWindow
TkCommandNames = ['::blt::stripchart'.freeze].freeze
WidgetClassName = 'Stripchart'.freeze
WidgetClassNames[WidgetClassName] = self
include PlotComponent
def __boolval_optkeys
['bufferelements', 'buffergraph', 'invertxy']
end
private :__boolval_optkeys
def __strval_optkeys
['text', 'label', 'title', 'file']
end
private :__strval_optkeys
BarElement_ID = ['blt_stripchart_bar'.freeze, '00000'.taint].freeze
def bar(elem=nil, keys={})
if elem.kind_of?(Hash)
keys = elem
elem = nil
end
unless elem
elem = BarElement_ID.join(TkCore::INTERP._ip_id_).freeze
BarElement_ID[1].succ!
end
tk_send('bar', elem, keys)
Element.new(self, elem, :without_creating=>true)
end
def extents(item)
num_or_str(tk_send_without_enc('extents', item))
end
def invtransform(x, y)
list(tk_send_without_enc('invtransform', x, y))
end
def inside(x, y)
bool(tk_send_without_enc('inside', x, y))
end
def metafile(file=None)
# Windows only
tk_send('metafile', file)
self
end
def snap(output, keys={})
tk_send_without_enc('snap', *(hash_kv(keys, false) + output))
self
end
def transform(x, y)
list(tk_send_without_enc('transform', x, y))
end
end
end

Просмотреть файл

@ -0,0 +1,330 @@
#
# tkextlib/blt/table.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tk/itemconfig.rb'
require 'tkextlib/blt.rb'
module Tk::BLT
module Table
include Tk
extend Tk
extend TkItemConfigMethod
TkCommandNames = ['::blt::table'.freeze].freeze
module TableContainer
def blt_table_add(*args)
Tk::BLT::Table.add(@path, *args)
self
end
def blt_table_arrange()
Tk::BLT::Table.arrange(@path)
self
end
def blt_table_cget(*args)
Tk::BLT::Table.cget(@path, *args)
end
def blt_table_configure(*args)
Tk::BLT::Table.configure(@path, *args)
self
end
def blt_table_configinfo(*args)
Tk::BLT::Table.configinfo(@path, *args)
end
def blt_table_current_configinfo(*args)
Tk::BLT::Table.current_configinfo(@path, *args)
end
def blt_table_locate(x, y)
Tk::BLT::Table.locate(@path, x, y)
end
def blt_table_delete(*args)
Tk::BLT::Table.delete(@path, *args)
self
end
def blt_table_extents(item)
Tk::BLT::Table.extents(@path, item)
end
def blt_table_insert(*args)
Tk::BLT::Table.insert(@path, *args)
self
end
def blt_table_insert_before(*args)
Tk::BLT::Table.insert_before(@path, *args)
self
end
def blt_table_insert_after(*args)
Tk::BLT::Table.insert_after(@path, *args)
self
end
def blt_table_join(first, last)
Tk::BLT::Table.join(@path, first, last)
self
end
def blt_table_save()
Tk::BLT::Table.save(@path)
end
def blt_table_search(*args)
Tk::BLT::Table.search(@path, *args)
end
def blt_table_split(*args)
Tk::BLT::Table.split(@path, *args)
self
end
def blt_table_itemcget(*args)
Tk::BLT::Table.itemcget(@path, *args)
end
def blt_table_itemconfigure(*args)
Tk::BLT::Table.itemconfigure(@path, *args)
self
end
def blt_table_itemconfiginfo(*args)
Tk::BLT::Table.itemconfiginfo(@path, *args)
end
def blt_table_current_itemconfiginfo(*args)
Tk::BLT::Table.current_itemconfiginfo(@path, *args)
end
def blt_table_iteminfo(item)
Tk::BLT::Table.iteminfo(@path, item)
end
end
end
end
############################################
class << Tk::BLT::Table
def __item_cget_cmd(id) # id := [ container, item ]
['::blt::table', 'cget', id[0].path, id[1]]
end
private :__item_cget_cmd
def __item_config_cmd(id) # id := [ container, item, ... ]
container, *items = id
['::blt::table', 'configure', container.path, *items]
end
private :__item_config_cmd
def __item_pathname(id)
id[0].path + ';'
end
private :__item_pathname
alias __itemcget itemcget
alias __itemconfigure itemconfigure
alias __itemconfiginfo itemconfiginfo
alias __current_itemconfiginfo current_itemconfiginfo
private :__itemcget, :__itemconfigure
private :__itemconfiginfo, :__current_itemconfiginfo
def tagid(tag)
if tag.kind_of?(Array)
case tag[0]
when Integer
# [row, col]
tag.join(',')
when :c, :C, 'c', 'C', :r, :R, 'r', 'R'
# c0 or r1 or C*, and so on
tag.collect{|elem| elem.to_s}.join('')
else
tag
end
elsif tag.kind_of?(TkWindow)
_epath(tag)
else
tag
end
end
def tagid2obj(tagid)
tagid
end
############################################
def cget(container, option)
__itemcget([container], option)
end
def configure(container, *args)
__itemconfigure([container], *args)
end
def configinfo(container, *args)
__itemconfiginfo([container], *args)
end
def current_configinfo(container, *args)
__current_itemconfiginfo([container], *args)
end
def itemcget(container, item, option)
__itemcget([container, tagid(item)], option)
end
def itemconfigure(container, *args)
if args[-1].kind_of?(Hash)
# container, item, item, ... , hash_optkeys
keys = args.pop
id = [container]
args.each{|item| id << tagid(item)}
__itemconfigure(id, keys)
else
# container, item, item, ... , option, value
val = args.pop
opt = args.pop
id = [container]
args.each{|item| id << tagid(item)}
__itemconfigure(id, opt, val)
end
end
def itemconfiginfo(container, *args)
slot = args[-1]
if slot.kind_of?(String) || slot.kind_of?(Symbol)
slot = slot.to_s
if slot[0] == ?. || slot =~ /^\d+,\d+$/ || slot =~ /^(c|C|r|R)(\*|\d+)/
# widget || row,col || Ci or Ri
slot = nil
else
# option
slot = args.pop
end
else
slot = nil
end
id = [container]
args.each{|item| id << tagid(item)}
__itemconfiginfo(id, slot)
end
def info(container)
ret = {}
inf = list(tk_call('::blt::table', 'info', container))
until inf.empty?
opt = inf.slice!(0..1)
ret[opt[1..-1]] = opt[1]
end
ret
end
def iteminfo(container, item)
ret = {}
inf = list(tk_call('::blt::table', 'info', container, tagid(item)))
until inf.empty?
opt = inf.slice!(0..1)
ret[opt[1..-1]] = opt[1]
end
ret
end
############################################
def create_container(container)
tk_call('::blt::table', container)
begin
class << container
include Tk::BLT::TABLE::TableContainer
end
rescue
warn('fail to include TableContainer methods (frozen object?)')
end
container
end
def add(container, win=nil, *args)
if win
tk_call('::blt::table', container, _epath(win), *args)
else
tk_call('::blt::table', container)
end
end
def arrange(container)
tk_call('::blt::table', 'arrange', container)
end
def delete(container, *args)
tk_call('::blt::table', 'delete', container, *args)
end
def extents(container, item)
ret = []
inf = list(tk_call('::blt::table', 'extents', container, item))
ret << inf.slice!(0..4) until inf.empty?
ret
end
def forget(*wins)
wins = wins.collect{|win| _epath(win)}
tk_call('::blt::table', 'forget', *wins)
end
def insert(container, *args)
tk_call('::blt::table', 'insert', container, *args)
end
def insert_before(container, *args)
tk_call('::blt::table', 'insert', container, '-before', *args)
end
def insert_after(container, *args)
tk_call('::blt::table', 'insert', container, '-after', *args)
end
def join(container, first, last)
tk_call('::blt::table', 'join', container, first, last)
end
def locate(container, x, y)
tk_call('::blt::table', 'locate', container, x, y)
end
def containers(arg={})
list(tk_call('::blt::table', 'containers', *hash_kv(arg)))
end
def containers_pattern(pat)
list(tk_call('::blt::table', 'containers', '-pattern', pat))
end
def containers_slave(win)
list(tk_call('::blt::table', 'containers', '-slave', win))
end
def save(container)
tk_call('::blt::table', 'save', container)
end
def search(container, keys={})
list(tk_call('::blt::table', 'containers', *hash_kv(keys)))
end
def split(container, *args)
tk_call('::blt::table', 'split', container, *args)
end
end

Просмотреть файл

@ -0,0 +1,21 @@
#
# tkextlib/blt/tabnotebook.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/blt.rb'
require 'tkextlib/blt/tabset.rb'
module Tk::BLT
class Tabnotebook < Tabset
TkCommandNames = ['::blt::tabnotebook'.freeze].freeze
WidgetClassName = 'Tabnotebook'.freeze
WidgetClassNames[WidgetClassName] = self
def get_tab(index)
Tk::BLT::Tabset::Tab.id2obj(tk_send_without_enc('id', tagindex(index)))
end
alias get_id get_tab
end
end

Просмотреть файл

@ -0,0 +1,386 @@
#
# tkextlib/blt/tabset.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/blt.rb'
module Tk::BLT
class Tabset < TkWindow
class Tab < TkObject
include TkTreatItemFont
TabID_TBL = TkCore::INTERP.create_table
TabsetTab_ID = ['blt_tabset_tab'.freeze, '00000'.taint].freeze
TkCore::INTERP.init_ip_env{ TabID_TBL.clear }
def self.id2obj(tabset, id)
tpath = tabset.path
return id unless TabID_TBL[tpath]
TabID_TBL[tpath][id]? TabID_TBL[tpath]: id
end
def self.new(parent, pos=nil, name=nil, keys={})
if pos.kind_of?(Hash)
keys = pos
name = nil
pos = nil
end
if name.kind_of?(Hash)
keys = name
name = nil
end
if name && TabID_TBL[parent.path] && TabID_TBL[parent.path][name]
TabID_TBL[parent.path][name]
else
super(parent, pos, name, keys)
end
end
def initialize(parent, pos, name, keys)
@t = parent
@tpath = parent.path
if name
@path = @id = name
TabID_TBL[@tpath] = {} unless TabID_TBL[@tpath]
TabID_TBL[@tpath][@id] = self
unless (list(tk_call(@tpath, 'tab', 'names', @id)).empty?)
if pos
idx = tk_call(@tpath, 'index', '-name', @id)
if pos.to_s == 'end'
tk_call(@tpath, idx, 'moveto', 'after', 'end')
else
tk_call(@tpath, idx, 'moveto', 'before', pos)
end
end
tk_call(@tpath, 'tab', 'configure', @id, keys)
return
end
else
@path = @id = TabsetTab_ID.join(TkCore::INTERP._ip_id_)
TabID_TBL[@tpath] = {} unless TabID_TBL[@tpath]
TabID_TBL[@tpath][@id] = self
TabsetTab_ID[1].succ!
end
pos = 'end' unless pos
tk_call(@tpath, 'insert', pos, @id, keys)
end
#def bind(context, cmd=Proc.new, *args)
# @t.tab_bind(@id, context, cmd, *args)
# self
#end
def bind(context, *args)
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
if TkComm._callback_entry?(args[0])
cmd = args.shift
else
cmd = Proc.new
end
@t.tab_bind(@id, context, cmd, *args)
self
end
#def bind_append(context, cmd=Proc.new, *args)
# @t.tab_bind_append(@id, context, cmd, *args)
# self
#end
def bind_append(context, *args)
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
if TkComm._callback_entry?(args[0])
cmd = args.shift
else
cmd = Proc.new
end
@t.tab_bind_append(@id, context, cmd, *args)
self
end
def bind_remove(context)
@t.tab_bind_remove(@id, context)
self
end
def bindinfo(context=nil)
@t.tab_bindinfo(@id, context)
end
def cget(*args)
@t.tab_cget(@id, *args)
end
def configure(*args)
@t.tab_configure(@id, *args)
end
def configinfo(*args)
@t.tab_configinfo(@id, *args)
end
def current_configinfo(*args)
@t.current_tab_configinfo(@id, *args)
end
def delete()
@t.delete(@id)
TabID_TBL[@tpath].delete(@id)
self
end
def get_name()
@id.dup
end
def focus()
@t.focus(self.index)
end
def index()
@t.index_name(@id)
end
def invoke()
@t.invoke(self.index)
end
def move_before(idx)
@t.move_before(self.index, idx)
end
def move_after(idx)
@t.move_after(self.index, idx)
end
def perforation_highlight(mode)
@t.perforation.highlight(self.index, mode)
end
def perforation_invoke()
@t.perforation.invoke(self.index)
end
def see()
@t.see(self.index)
end
def tearoff(name=None)
@t.tab_tearoff(self.index, *args)
end
end
########################################
class NamedTab < Tab
def self.new(parent, name)
super(parent, nil, name, {})
end
end
########################################
include X_Scrollable
include TkItemConfigMethod
TkCommandNames = ['::blt::tabset'.freeze].freeze
WidgetClassName = 'Tabset'.freeze
WidgetClassNames[WidgetClassName] = self
def __destroy_hook__
Tk::BLT::Tabset::Tab::TabID_TBL.delete(@path)
end
########################################
def __item_cget_cmd(id)
[self.path, 'tab', 'cget', id]
end
private :__item_cget_cmd
def __item_config_cmd(id)
[self.path, 'tab', 'configure', id]
end
private :__item_config_cmd
def __item_pathname(tagOrId)
if tagOrId.kind_of?(Tk::BLT::Tabset::Tab)
self.path + ';' + tagOrId.id.to_s
else
self.path + ';' + tagOrId.to_s
end
end
private :__item_pathname
alias tab_cget itemcget
alias tab_configure itemconfigure
alias tab_configinfo itemconfiginfo
alias current_tab_configinfo current_itemconfiginfo
def tagid(tab)
if tab.kind_of?(Tk::BLT::Tabset::Tab)
tab.id
else
tab
end
end
def tagindex(tab)
if tab.kind_of?(Tk::BLT::Tabset::Tab)
tab.index
else
tab
end
end
########################################
def activate(index)
tk_send('activate', tagindex(index))
self
end
alias highlight activate
#def tabbind(tag, context, cmd=Proc.new, *args)
# _bind([path, "bind", tagid(tag)], context, cmd, *args)
# self
#end
def tabbind(tag, context, *args)
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
if TkComm._callback_entry?(args[0])
cmd = args.shift
else
cmd = Proc.new
end
_bind([path, "bind", tagid(tag)], context, cmd, *args)
self
end
#def tabbind_append(tag, context, cmd=Proc.new, *args)
# _bind_append([path, "bind", tagid(tag)], context, cmd, *args)
# self
#end
def tabbind_append(tag, context, *args)
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
if TkComm._callback_entry?(args[0])
cmd = args.shift
else
cmd = Proc.new
end
_bind_append([path, "bind", tagid(tag)], context, cmd, *args)
self
end
def tabbind_remove(tag, context)
_bind_remove([path, "bind", tagid(tag)], context)
self
end
def tabbindinfo(tag, context=nil)
_bindinfo([path, "bind", tagid(tag)], context)
end
def delete(first, last=None)
tk_send('delete', tagindex(first), tagindex(last))
if first.kind_of?(Tk::BLT::Tabset::Tab)
TabID_TBL[@path].delete(first.id)
end
# middle tabs of the range are unknown
if last.kind_of?(Tk::BLT::Tabset::Tab)
TabID_TBL[@path].delete(last.id)
end
self
end
def focus(index)
tk_send('focus', tagindex(index))
self
end
def get_tab(index)
Tk::BLT::Tabset::Tab.id2obj(tk_send_without_enc('get', tagindex(index)))
end
def index(str)
num_or_str(tk_send('index', str))
end
def index_name(tab)
num_or_str(tk_send('index', '-mame', tagid(tab)))
end
def insert(pos, tab, keys={})
Tk::BLT::Tabset::Tab.new(self, tagindex(pos), tagid(tab), keys)
end
def invoke(index)
tk_send('invoke', tagindex(index))
end
def move_before(index, base_idx)
tk_send('move', tagindex(index), 'before', tagindex(base_idx))
self
end
def move_after(index, base_idx)
tk_send('move', tagindex(index), 'after', tagindex(base_idx))
self
end
def nearest(x, y)
Tk::BLT::Tabset::Tab.id2obj(num_or_str(tk_send_without_enc('nearest', x, y)))
end
def perforation_highlight(index, mode)
tk_send('perforation', 'highlight', tagindex(index), mode)
self
end
def perforation_invoke(index)
tk_send('perforation', 'invoke', tagindex(index))
end
def scan_mark(x, y)
tk_send_without_enc('scan', 'mark', x, y)
self
end
def scan_dragto(x, y)
tk_send_without_enc('scan', 'dragto', x, y)
self
end
def see(index)
tk_send('see', tagindex(index))
self
end
def size()
number(tk_send_without_enc('size'))
end
def select(index)
tk_send('select', tagindex(index))
self
end
def tab_names(pat=None)
simplelist(tk_send('tab', 'names', pat)).collect{|name|
Tk::BLT::Tabset::Tab.id2obj(name)
}
end
def tab_tearoff(index, name=None)
window(tk_send('tab', 'tearoff', tagindex(index), name))
end
def xscrollcommand(cmd=Proc.new)
configure_cmd 'scrollcommand', cmd
self
end
alias scrollcommand xscrollcommand
def xview(*index)
if index.empty?
list(tk_send_without_enc('view'))
else
tk_send_without_enc('view', *index)
self
end
end
alias view xview
alias view_moveto xview_moveto
alias view_scroll xview_scroll
alias scrollbar xscrollbar
end
end

Просмотреть файл

@ -0,0 +1,62 @@
#
# tkextlib/blt/ted.rb
#
# *** This is alpha version, because there is no document on BLT. ***
#
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/blt.rb'
module Tk::BLT
module Ted
extend TkCore
TkCommandNames = ['::blt::ted'.freeze].freeze
##############################
extend TkItemConfigMethod
class << self
def __item_cget_cmd(id)
['::blt::ted', 'cget', id]
end
private :__item_cget_cmd
def __item_config_cmd(id)
['::blt::ted', 'configure', id]
end
private :__item_config_cmd
private :itemcget, :itemconfigure
private :itemconfiginfo, :current_itemconfiginfo
def cget(master, option)
itemconfigure(master, slot, value)
end
def configure(master, slot, value=None)
itemconfigure(master, slot, value)
end
def configinfo(master, slot=nil)
itemconfiginfo(master, slot)
end
def current_configinfo(master, slot=nil)
current_itemconfiginfo(master, slot)
end
end
##############################
def self.edit(master, *args)
tk_call('::blt::ted', 'edit', master, *args)
end
def self.rep(master, *args)
tk_call('::blt::ted', 'rep', master, *args)
end
def self.select(master, *args)
tk_call('::blt::ted', 'select', master, *args)
end
end
end

Просмотреть файл

@ -0,0 +1,21 @@
#
# tkextlib/blt/tile.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/blt.rb'
module Tk::BLT
module Tile
autoload :Button, 'tkextlib/blt/tile/button.rb'
autoload :CheckButton, 'tkextlib/blt/tile/checkbutton.rb'
autoload :Checkbutton, 'tkextlib/blt/tile/checkbutton.rb'
autoload :Radiobutton, 'tkextlib/blt/tile/radiobutton.rb'
autoload :RadioButton, 'tkextlib/blt/tile/radiobutton.rb'
autoload :Frame, 'tkextlib/blt/tile/frame.rb'
autoload :Label, 'tkextlib/blt/tile/label.rb'
autoload :Scrollbar, 'tkextlib/blt/tile/scrollbar.rb'
autoload :Toplevel, 'tkextlib/blt/tile/toplevel.rb'
end
end

Просмотреть файл

@ -0,0 +1,16 @@
#
# tkextlib/blt/tile/button.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tk/button'
require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
class Button < TkButton
TkCommandNames = ['::blt::tile::button'.freeze].freeze
end
end
end

Просмотреть файл

@ -0,0 +1,17 @@
#
# tkextlib/blt/tile/checkbutton.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tk/checkbutton'
require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
class Checkbutton < TkCheckbutton
TkCommandNames = ['::blt::tile::checkbutton'.freeze].freeze
end
CheckButton = Checkbutton
end
end

Просмотреть файл

@ -0,0 +1,16 @@
#
# tkextlib/blt/tile/frame.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tk/frame'
require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
class Frame < TkFrame
TkCommandNames = ['::blt::tile::frame'.freeze].freeze
end
end
end

Просмотреть файл

@ -0,0 +1,16 @@
#
# tkextlib/blt/tile/label.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tk/label'
require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
class Label < TkLabel
TkCommandNames = ['::blt::tile::label'.freeze].freeze
end
end
end

Просмотреть файл

@ -0,0 +1,17 @@
#
# tkextlib/blt/tile/radiobutton.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tk/radiobutton'
require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
class Radiobutton < TkRadiobutton
TkCommandNames = ['::blt::tile::radiobutton'.freeze].freeze
end
RadioButton = Radiobutton
end
end

Просмотреть файл

@ -0,0 +1,16 @@
#
# tkextlib/blt/tile/scrollbar.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tk/scrollbar'
require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
class Scrollbar < TkScrollbar
TkCommandNames = ['::blt::tile::scrollbar'.freeze].freeze
end
end
end

Просмотреть файл

@ -0,0 +1,16 @@
#
# tkextlib/blt/tile/toplevel.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tk/toplevel'
require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
class Toplevel < TkToplevel
TkCommandNames = ['::blt::tile::toplevel'.freeze].freeze
end
end
end

Просмотреть файл

@ -0,0 +1,881 @@
#
# tkextlib/blt/tree.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/blt.rb'
module Tk::BLT
class Tree < TkObject
TkCommandNames = ['::blt::tree'.freeze].freeze
###################################
class Node < TkObject
TreeNodeID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{ TreeNodeID_TBL.clear }
def self.id2obj(tree, id)
tpath = tree.path
return id unless TreeNodeID_TBL[tpath]
if TreeNodeID_TBL[tpath][id]
TreeNodeID_TBL[tpath][id]
else
begin
self.new(tree, nil, 'node'=>Integer(id))
rescue
id
end
end
end
def self.new(tree, parent, keys={})
keys = _symbolkey2str(keys)
tpath = tree.path
if (id = keys['node']) && (obj = TreeNodeID_TBL[tpath][id])
keys.delete('node')
tk_call(tree.path, 'move', id, parent, keys) if parent
return obj
end
super(tree, parent, keys)
end
def initialize(tree, parent, keys={})
@parent = @tree = tree
@tpath = @parent.path
parent = tk_call(@tpath, 'root') unless parent
if (id = keys['node']) && bool(tk_call(@tpath, 'exists', id))
@path = @id = id
keys.delete('node')
tk_call(@tpath, 'move', @id, parent, keys) if parent
else
@path = @id = tk_call(@tpath, 'insert', parent, keys)
end
TreeNodeID_TBL[@tpath] = {} unless TreeNodeID_TBL[@tpath]
TreeNodeID_TBL[@tpath][@id] = self
end
def id
@id
end
def apply(keys={})
@tree.apply(@id, keys)
self
end
def children()
@tree.children(@id)
end
def copy(parent, keys={})
@tree.copy(@id, parent, keys)
end
def copy_to(dest_tree, parent, keys={})
@tree.copy_to(@id, dest_tree, parent, keys)
end
def degree()
@tree.degree(@id)
end
def delete()
@tree.delete(@id)
self
end
def depth()
@tree.depth(@id)
end
def dump()
@tree.dump(@id)
end
def dump_to_file(file)
@tree.dump_to_file(@id, file)
self
end
def exist?(keys={})
@tree.exist?(@id, keys)
end
def find(keys={})
@tree.find(@id, keys)
end
def find_child(label)
@tree.find_child(@id, label)
end
def first_child()
@tree.first_child(@id)
end
def get()
@tree.get(@id)
end
def get_value(key, default_val=None)
@tree.get_value(@id, key, default_val)
end
def index()
@tree.index(@id)
end
def leaf?()
@tree.leaf?(@id)
end
def link?()
@tree.link?(@id)
end
def root?()
@tree.root?(@id)
end
def keys()
@tree.keys(@id)
end
def label(text = nil)
@tree.label(@id, nil)
end
def label=(text)
@tree.label(@id, text)
end
def last_child()
@tree.last_child(@id)
end
def move(dest, keys={})
@tree.keys(@id, dest, keys)
self
end
def next()
@tree.next(@id)
end
def next_sibling()
@tree.next_sibling(@id)
end
def parent()
@tree.parent(@id)
end
def fullpath()
@tree.fullpath(@id)
end
def position()
@tree.position(@id)
end
def previous()
@tree.previous(@id)
end
def prev_sibling()
@tree.prev_sibling(@id)
end
def restore(str, keys={})
@tree.restore(@id, str, keys)
self
end
def restore_overwrite(str, keys={})
@tree.restore_overwrite(@id, str, keys)
self
end
def restore_from_file(file, keys={})
@tree.restore_from_file(@id, file, keys)
self
end
def restore_overwrite_from_file(file, keys={})
@tree.restore_overwrite_from_file(@id, file, keys)
self
end
def root()
@tree.root(@id)
self
end
def set(data)
@tree.set(@id, data)
self
end
def size()
@tree.size(@id)
end
def sort(keys={})
@tree.sort(@id, keys)
self
end
def type(key)
@tree.type(@id, key)
end
def unset(*keys)
@tree.unset(@id, *keys)
self
end
def values(key=None)
@tree.values(@id, key)
end
end
###################################
class Tag < TkObject
TreeTagID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{ TreeTagID_TBL.clear }
TreeTag_ID = ['blt_tree_tag'.freeze, '00000'.taint].freeze
def self.id2obj(tree, id)
tpath = tree.path
return id unless TreeTagID_TBL[tpath]
if TreeTagID_TBL[tpath][id]
TreeTagID_TBL[tpath][id]
else
self.new(tree, id)
end
end
def initialize(tree, tag_str = nil)
@parent = @tree = tree
@tpath = @parent.path
if tag_str
@path = @id = tag_str.dup.freeze
else
@path = @id = TreeTag_ID.join(TkCore::INTERP._ip_id_)
TreeTagID_TBL[@id] = self
TreeTag_ID[1].succ!
end
TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath]
TreeTagID_TBL[@tpath][@id] = self
end
def add(*nodes)
tk_call(@tpath, 'tag', 'add', @id, *nodes)
self
end
def delete(*nodes)
tk_call(@tpath, 'tag', 'delete', @id, *nodes)
self
end
def forget()
tk_call(@tpath, 'tag', 'forget', @id)
TreeTagID_TBL[@tpath].delete(@id)
self
end
def nodes()
simplelist(tk_call(@tpath, 'tag', 'nodes', @id)).collect{|node|
Tk::BLT::Tree::Node.id2obj(@path, node)
}
end
def set(node)
tk_call(@tpath, 'tag', 'set', node, @id)
self
end
def unset(node)
tk_call(@tpath, 'tag', 'unset', node, @id)
self
end
end
###################################
class Notify < TkObject
NotifyID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{ NotifyID_TBL.clear }
def self.id2obj(tree, id)
tpath = tree.path
return id unless NotifyID_TBL[tpath]
if NotifyID_TBL[tpath][id]
NotifyID_TBL[tpath][id]
else
begin
self.new([tree, id])
rescue
id
end
end
end
def self.new(tree, *args, &b)
if tree.kind_of?(Array)
# not create
if obj = NotifyID_TBL[tree[0].path][tree[1]]
return obj
else
return super(false, tree[0], tree[1])
end
end
super(true, tree, *args, &b)
end
def initialize(create, tree, *args, &b)
@parent = @tree = tree
@tpath = @parent.path
unless create
@path = @id = args[0]
return
end
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
if TkComm._callback_entry?(args[0])
cmd = args.shift
# elsif args[-1].kind_of?(Proc) || args[-1].kind_of?(Method)
elsif TkComm._callback_entry?(args[-1])
cmd = args.pop
elsif b
cmd = Proc.new(&b)
else
fail ArgumentError, "lack of 'command' argument"
end
args = args.collect{|arg| '-' << arg.to_s}
args << proc{|id, type|
cmd.call(Tk::BLT::Tree::Node.id2obj(@tree, id),
((type[0] == ?-)? type[1..-1]: type))
}
@path = @id = tk_call(@tpath, 'notify', 'create', *args)
end
def delete()
tk_call(@tpath, 'notify', 'delete', @id)
NotifyID_TBL[tpath].delete(@id)
self
end
def info()
lst = simplelist(tk_call(@tpath, 'notify', 'info', id))
lst[0] = Tk::BLT::Tree::Notify.id2obj(@tree, lst[0])
lst[1] = simplelist(lst[1]).collect{|flag| flag[1..-1]}
lst[2] = tk_tcl2ruby(lst[2])
lst
end
end
###################################
class Trace < TkObject
TraceID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{ TraceID_TBL.clear }
def self.id2obj(tree, id)
tpath = tree.path
return id unless TraceID_TBL[tpath]
if TraceID_TBL[tpath][id]
TraceID_TBL[tpath][id]
else
begin
self.new([tree, id])
rescue
id
end
end
end
def self.new(tree, *args, &b)
if tree.kind_of?(Array)
# not create
if obj = TraceID_TBL[tree[0].path][tree[1]]
return obj
else
return super(false, tree[0], tree[1])
end
end
super(true, tree, *args, &b)
end
def initialize(create, tree, node, key, opts, cmd=nil, &b)
@parent = @tree = tree
@tpath = @parent.path
unless create
@path = @id = node # == traceID
return
end
if !cmd
if b
cmd = Proc.new(&b)
else
fail ArgumentError, "lack of 'command' argument"
end
end
@path = @id = tk_call(@tpath, 'trace', 'create', node, key, opts,
proc{|t, id, k, ops|
tobj = Tk::BLT::Tree.id2obj(t)
if tobj.kind_of?(Tk::BLT::Tree)
nobj = Tk::BLT::Tree::Node.id2obj(tobj, id)
else
nobj = id
end
cmd.call(tobj, nobj, k, ops)
})
end
def delete()
tk_call(@tpath, 'trace', 'delete', @id)
TraceID_TBL[tpath].delete(@id)
self
end
def info()
lst = simplelist(tk_call(@tpath, 'trace', 'info', id))
lst[0] = Tk::BLT::Tree::Trace.id2obj(@tree, lst[0])
lst[2] = simplelist(lst[2])
lst[3] = tk_tcl2ruby(lst[3])
lst
end
end
###################################
TreeID_TBL = TkCore::INTERP.create_table
Tree_ID = ['blt_tree'.freeze, '00000'.taint].freeze
def __keyonly_optkeys
{
# apply / find command
'invert'=>nil, 'leafonly'=>nil, 'nocase'=>nil,
# apply / find / sort command
'path'=>nil,
# copy / restore / restorefile command
'overwrite'=>nil,
# copy command
'recurse'=>nil, 'tags'=>nil,
# sort command
'ascii'=>nil, 'decreasing'=>nil, 'disctionary'=>nil,
'integer'=>nil, 'real'=>nil, 'recurse'=>nil, 'reorder'=>nil,
}
end
def self.id2obj(id)
TreeID_TBL[id]? TreeID_TBL[id]: id
end
def self.names(pat = None)
simplelist(tk_call('::blt::tree', 'names', pat)).collect{|name|
id2obj(name)
}
end
def self.destroy(*names)
tk_call('::blt::tree', 'destroy',
*(names.collect{|n| (n.kind_of?(Tk::BLT::Tree))? n.id: n }) )
end
def self.new(name = nil)
return TreeID_TBL[name] if name && TreeID_TBL[name]
super(name)
end
def initialzie(name = nil)
if name
@path = @id = name
else
@path = @id = Tree_ID.join(TkCore::INTERP._ip_id_)
TreeID_TBL[@id] = self
Tree_ID[1].succ!
end
TreeID_TBL[@id] = self
tk_call('::blt::tree', 'create', @id)
end
def __destroy_hook__
Tk::BLT::Tree::Node::TreeNodeID_TBL.delete(@path)
Tk::BLT::Tree::Tag::TreeTagID_TBL.delete(@path)
Tk::BLT::Tree::Notify::NotifyID_TBL.delete(@path)
Tk::BLT::Tree::Trace::TraceID_TBL.delete(@path)
end
def destroy()
tk_call('::blt::tree', 'destroy', @id)
self
end
def ancestor(node1, node2)
Tk::BLT::Tree::Node.id2obj(self, tk_call('::blt::tree', 'ancestor',
node1, node2))
end
def apply(node, keys={})
tk_call('::blt::tree', 'apply', node, __conv_keyonly_opts(keys))
self
end
def attach(tree_obj)
tk_call('::blt::tree', 'attach', tree_obj)
self
end
def children(node)
simplelist(tk_call('::blt::tree', 'children', node)).collect{|n|
Tk::BLT::Tree::Node.id2obj(self, n)
}
end
def copy(src, parent, keys={})
id = tk_call('::blt::tree', 'copy', src, parent,
__conv_keyonly_opts(keys))
Tk::BLT::Tree::Node.new(self, nil, 'node'=>id)
end
def copy_to(src, dest_tree, parent, keys={})
return copy(src, parent, keys={}) unless dest_tree
id = tk_call('::blt::tree', 'copy', src, dest_tree, parent,
__conv_keyonly_opts(keys))
Tk::BLT::Tree::Node.new(dest_tree, nil, 'node'=>id)
end
def degree(node)
number(tk_call('::blt::tree', 'degree', node))
end
def delete(*nodes)
tk_call('::blt::tree', 'delete', *nodes)
nodes.each{|node|
if node.kind_of?(Tk::BLT::Tree::Node)
Tk::BLT::Tree::Node::TreeNodeID_TBL[@path].delete(node.id)
else
Tk::BLT::Tree::Node::TreeNodeID_TBL[@path].delete(node.to_s)
end
}
self
end
def depth(node)
number(tk_call('::blt::tree', 'depth', node))
end
def dump(node)
simplelist(tk_call('::blt::tree', 'dump', node)).collect{|n|
simplelist(n)
}
end
def dump_to_file(node, file)
tk_call('::blt::tree', 'dumpfile', node, file)
self
end
def exist?(node, key=None)
bool(tk_call('::blt::tree', 'exists', node, key))
end
def find(node, keys={})
simplelist(tk_call('::blt::tree', 'find', node,
__conv_keyonly_opts(keys))).collect{|n|
Tk::BLT::Tree::Node.id2obj(self, n)
}
end
def find_child(node, label)
ret = tk_call('::blt::tree', 'findchild', node, label)
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end
def first_child(node)
ret = tk_call('::blt::tree', 'firstchild', node)
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end
def get(node)
Hash[*simplelist(tk_call('::blt::tree', 'get', node))]
end
def get_value(node, key, default_val=None)
tk_call('::blt::tree', 'get', node, key, default_val)
end
def index(node)
Tk::BLT::Tree::Node.id2obj(self, tk_call('::blt::tree', 'index', node))
end
def insert(parent, keys={})
id = tk_call('::blt::tree', 'insert', parent, keys)
Tk::BLT::Tree::Node.new(self, nil, 'node'=>id)
end
def ancestor?(node1, node2)
bool(tk_call('::blt::tree', 'is', 'ancestor', node1, node2))
end
def before?(node1, node2)
bool(tk_call('::blt::tree', 'is', 'before', node1, node2))
end
def leaf?(node)
bool(tk_call('::blt::tree', 'is', 'leaf', node))
end
def link?(node)
bool(tk_call('::blt::tree', 'is', 'link', node))
end
def root?(node)
bool(tk_call('::blt::tree', 'is', 'root', node))
end
def keys(node, *nodes)
if nodes.empty?
simplelist(tk_call('blt::tree', 'keys', node))
else
simplelist(tk_call('blt::tree', 'keys', node, *nodes)).collect{|lst|
simplelist(lst)
}
end
end
def label(node, text=nil)
if text
tk_call('::blt::tree', 'label', node, text)
text
else
tk_call('::blt::tree', 'label', node)
end
end
def last_child(node)
ret = tk_call('::blt::tree', 'lastchild', node)
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end
def link(parent, node, keys={})
ret = tk_call('::blt::tree', 'link', parent, node,
__conv_keyonly_opts(keys))
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end
def move(node, dest, keys={})
tk_call('::blt::tree', 'move', node, dest, keys)
self
end
def next(node)
ret = tk_call('::blt::tree', 'next', node)
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end
def next_sibling(node)
ret = tk_call('::blt::tree', 'nextsibling', node)
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end
def notify_create(*args, &b)
Tk::BLT::Tree::Notify.new(self, *args, &b)
end
def notify_delete(id)
if id.kind_of?(Tk::BLT::Tree::Notify)
id.delete
else
tk_call(@path, 'notify', 'delete', id)
Tk::BLT::Tree::Notify::NotifyID_TBL[@path].delete(id.to_s)
end
self
end
def notify_info(id)
lst = simplelist(tk_call(@path, 'notify', 'info', id))
lst[0] = Tk::BLT::Tree::Notify.id2obj(self, lst[0])
lst[1] = simplelist(lst[1]).collect{|flag| flag[1..-1]}
lst[2] = tk_tcl2ruby(lst[2])
lst
end
def notify_names()
tk_call(@path, 'notify', 'names').collect{|id|
Tk::BLT::Tree::Notify.id2obj(self, id)
}
end
def parent(node)
ret = tk_call('::blt::tree', 'parent', node)
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end
def fullpath(node)
tk_call('::blt::tree', 'path', node)
end
def position(node)
number(tk_call('::blt::tree', 'position', node))
end
def previous(node)
ret = tk_call('::blt::tree', 'previous', node)
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end
def prev_sibling(node)
ret = tk_call('::blt::tree', 'prevsibling', node)
(ret == '-1')? nil: Tk::BLT::Tree::Node.id2obj(self, ret)
end
def restore(node, str, keys={})
tk_call('::blt::tree', 'restore', node, str,
__conv_keyonly_opts(keys))
self
end
def restore_overwrite(node, str, keys={})
keys = __conv_keyonly_opts(keys)
keys.delete('overwrite')
keys.delete(:overwrite)
tk_call('::blt::tree', 'restore', node, str, '-overwrite', keys)
self
end
def restore_from_file(node, file, keys={})
tk_call('::blt::tree', 'restorefile', node, file,
__conv_keyonly_opts(keys))
self
end
def restore_overwrite_from_file(node, file, keys={})
keys = __conv_keyonly_opts(keys)
keys.delete('overwrite')
keys.delete(:overwrite)
tk_call('::blt::tree', 'restorefile', node, file, '-overwrite', keys)
self
end
def root(node=None)
Tk::BLT::Tree::Node.id2obj(self, tk_call('::blt::tree', 'root', node))
end
def set(node, data)
unless data.kind_of?(Hash)
fail ArgumentError, 'Hash is expected for data'
end
args = []
data.each{|k, v| args << k << v}
tk_call('::blt::tree', 'set', node, *args)
self
end
def size(node)
number(tk_call('::blt::tree', 'size', node))
end
def sort(node, keys={})
tk_call('::blt::tree', 'sort', node, __conv_keyonly_opts(keys))
self
end
def tag_add(tag, *nodes)
tk_call(@path, 'tag', 'add', tag, *nodes)
self
end
def tag_delete(tag, *nodes)
tk_call(@path, 'tag', 'delete', tag, *nodes)
self
end
def tag_forget(tag)
tag = tag.id if tag.kind_of?(Tk::BLT::Tree::Tag)
tk_call(@path, 'tag', 'forget', tag)
TreeTagID_TBL[@path].delete(tag)
self
end
def tag_get(node, *patterns)
simplelist(tk_call(@tpath, 'tag', 'get', node, *patterns)).collect{|str|
Tk::BLT::Tree::Tag.id2obj(self, str)
}
end
def tag_names(node = None)
simplelist(tk_call(@tpath, 'tag', 'names', node)).collect{|str|
Tk::BLT::Tree::Tag.id2obj(self, str)
}
end
def tag_nodes(tag)
simplelist(tk_call(@tpath, 'tag', 'nodes',tag)).collect{|node|
Tk::BLT::Tree::Node.id2obj(self, node)
}
end
def tag_set(node, *tags)
tk_call(@path, 'tag', 'set', node, *tags)
self
end
def tag_unset(node, *tags)
tk_call(@path, 'tag', 'unset', node, *tags)
self
end
def trace_create(*args, &b)
Tk::BLT::Tree::Trace.new(self, *args, &b)
end
def trace_delete(*args)
if id.kind_of?(Tk::BLT::Tree::Trace)
id.delete
else
tk_call(@path, 'trace', 'delete', id)
Tk::BLT::Tree::Trace::TraceID_TBL[@path].delete(id.to_s)
end
self
end
def trace_info(*args)
lst = simplelist(tk_call(@path, 'trace', 'info', id))
lst[0] = Tk::BLT::Tree::Trace.id2obj(self, lst[0])
lst[2] = simplelist(lst[2])
lst[3] = tk_tcl2ruby(lst[3])
lst
end
def trace_names()
tk_call(@path, 'trace', 'names').collect{|id|
Tk::BLT::Tree::Trace.id2obj(self, id)
}
end
def type(node, key)
tk_call('::blt::tree', 'type', node, key)
end
def unset(node, *keys)
tk_call('::blt::tree', 'unset', node, *keys)
self
end
def values(node, key=None)
simplelist(tk_call('::blt::tree', 'values', node, key))
end
end
end

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,129 @@
#
# tkextlib/blt/unix_dnd.rb
#
# *** This is alpha version, because there is no document on BLT. ***
#
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/blt.rb'
module Tk::BLT
module DnD
extend TkCore
TkCommandNames = ['::blt::dnd'.freeze].freeze
##############################
extend TkItemConfigMethod
class << self
def __item_cget_cmd(id)
['::blt::dnd', *id]
end
private :__item_cget_cmd
def __item_config_cmd(id)
['::blt::dnd', *id]
end
private :__item_config_cmd
private :itemcget, :itemconfigure
private :itemconfiginfo, :current_itemconfiginfo
def cget(win, option)
itemconfigure(['cget', win], slot, value)
end
def configure(win, slot, value=None)
itemconfigure(['configure', win], slot, value)
end
def configinfo(win, slot=nil)
itemconfiginfo(['configure', win], slot)
end
def current_configinfo(win, slot=nil)
current_itemconfiginfo(['configure', win], slot)
end
def tokwn_cget(win, option)
itemconfigure(['token', 'cget', win], slot, value)
end
def token_configure(win, slot, value=None)
itemconfigure(['token', 'configure', win], slot, value)
end
def token_configinfo(win, slot=nil)
itemconfiginfo(['token', 'configure', win], slot)
end
def current_token_configinfo(win, slot=nil)
current_itemconfiginfo(['token', 'configure', win], slot)
end
def token_windowconfigure(win, slot, value=None)
itemconfigure(['token', 'window', win], slot, value)
end
def token_windowconfiginfo(win, slot=nil)
itemconfiginfo(['token', 'window', win], slot)
end
def current_token_windowconfiginfo(win, slot=nil)
current_itemconfiginfo(['token', 'window', win], slot)
end
end
##############################
def self.cancel(win)
tk_call('::blt::dnd', 'cancel', *wins)
end
def self.delete(*wins)
tk_call('::blt::dnd', 'delete', *wins)
end
def self.delete_source(*wins)
tk_call('::blt::dnd', 'delete', '-source', *wins)
end
def self.delete_target(*wins)
tk_call('::blt::dnd', 'delete', '-target', *wins)
end
def self.drag(win, x, y, token=None)
tk_call('::blt::dnd', 'drag', win, x, y, token)
end
def self.drop(win, x, y, token=None)
tk_call('::blt::dnd', 'drop', win, x, y, token)
end
def self.get_data(win, fmt=nil, cmd=nil)
if fmt
tk_call('::blt::dnd', 'getdata', win, fmt, cmd)
else
list(tk_call('::blt::dnd', 'getdata', win))
end
end
def self.names(pat=None)
list(tk_call('::blt::dnd', 'names', pat))
end
def self.source_names(pat=None)
list(tk_call('::blt::dnd', 'names', '-source', pat))
end
def self.target_names(pat=None)
list(tk_call('::blt::dnd', 'names', '-target', pat))
end
def self.pull(win, fmt)
tk_call('::blt::dnd', 'pull', win, fmt)
end
def self.register(win, keys={})
tk_call('::blt::dnd', 'register', win, keys)
end
def self.select(win, x, y, timestamp)
tk_call('::blt::dnd', 'select', win, x, y, timestamp)
end
def self.set_data(win, fmt=nil, cmd=nil)
if fmt
tk_call('::blt::dnd', 'setdata', win, fmt, cmd)
else
list(tk_call('::blt::dnd', 'setdata', win))
end
end
def self.token(*args)
tk_call('::blt::dnd', 'token', *args)
end
end
end

Просмотреть файл

@ -0,0 +1,243 @@
#
# tkextlib/blt/vector.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/blt.rb'
module Tk::BLT
class Vector < TkVariable
TkCommandNames = ['::blt::vector'.freeze].freeze
def self.create(*args)
tk_call('::blt::vector', 'create', *args)
end
def self.destroy(*args)
tk_call('::blt::vector', 'destroy', *args)
end
def self.expr(expression)
tk_call('::blt::vector', 'expr', expression)
end
def self.names(pat=None)
simplelist(tk_call('::blt::vector', 'names', pat)).collect{|name|
if TkVar_ID_TBL[name]
TkVar_ID_TBL[name]
elsif name[0..1] == '::' && TkVar_ID_TBL[name[2..-1]]
TkVar_ID_TBL[name[2..-1]]
else
name
end
}
end
####################################
def initialize(size=nil, keys={})
if size.kind_of?(Hash)
keys = size
size = nil
end
if size.kind_of?(Array)
# [first, last]
size = size.join(':')
end
if size
@id = INTERP._invoke('::blt::vector', 'create',
"#auto(#{size})", *hash_kv(keys))
else
@id = INTERP._invoke('::blt::vector', 'create',
"#auto", *hash_kv(keys))
end
TkVar_ID_TBL[@id] = self
@def_default = false
@default_val = nil
@trace_var = nil
@trace_elem = nil
@trace_opts = nil
# teach Tk-ip that @id is global var
INTERP._invoke_without_enc('global', @id)
end
def destroy
tk_call('::blt::vector', 'destroy', @id)
end
def inspect
'#<Tk::BLT::Vector: ' + @id + '>'
end
def to_s
@id
end
def *(item)
list(tk_call(@id, '*', item))
end
def +(item)
list(tk_call(@id, '+', item))
end
def -(item)
list(tk_call(@id, '-', item))
end
def /(item)
list(tk_call(@id, '/', item))
end
def append(*vectors)
tk_call(@id, 'append', *vectors)
end
def binread(channel, len=None, keys={})
if len.kind_of?(Hash)
keys = len
len = None
end
keys = _symbolkey2str(keys)
keys['swap'] = None if keys.delete('swap')
tk_call(@id, 'binread', channel, len, keys)
end
def clear()
tk_call(@id, 'clear')
self
end
def delete(*indices)
tk_call(@id, 'delete', *indices)
self
end
def dup_vector(vec)
tk_call(@id, 'dup', vec)
self
end
def expr(expression)
tk_call(@id, 'expr', expression)
self
end
def index(idx, val=None)
number(tk_call(@id, 'index', idx, val))
end
def [](idx)
index(idx)
end
def []=(idx, val)
index(idx, val)
end
def length()
number(tk_call(@id, 'length'))
end
def length=(size)
number(tk_call(@id, 'length', size))
end
def merge(*vectors)
tk_call(@id, 'merge', *vectors)
self
end
def normalize(vec=None)
tk_call(@id, 'normalize', vec)
self
end
def notify(keyword)
tk_call(@id, 'notify', keyword)
self
end
def offset()
number(tk_call(@id, 'offset'))
end
def offset=(val)
number(tk_call(@id, 'offset', val))
end
def random()
tk_call(@id, 'random')
end
def populate(vector, density=None)
tk_call(@id, 'populate', vector, density)
self
end
def range(first, last=None)
list(tk_call(@id, 'range', first, last))
end
def search(val1, val2=None)
list(tk_call(@id, 'search', val1, val2))
end
def set(item)
tk_call(@id, 'set', item)
self
end
def seq(start, finish=None, step=None)
tk_call(@id, 'seq', start, finish, step)
self
end
def sort(*vectors)
tk_call(@id, 'sort', *vectors)
self
end
def sort_reverse(*vectors)
tk_call(@id, 'sort', '-reverse', *vectors)
self
end
def split(*vectors)
tk_call(@id, 'split', *vectors)
self
end
def variable(var)
tk_call(@id, 'variable', var)
self
end
end
class VectorAccess < Vector
def self.new(name)
return TkVar_ID_TBL[name] if TkVar_ID_TBL[name]
super(name, size=nil, keys={})
end
def initialize(vec_name)
@id = vec_name
TkVar_ID_TBL[@id] = self
@def_default = false
@default_val = nil
@trace_var = nil
@trace_elem = nil
@trace_opts = nil
# teach Tk-ip that @id is global var
INTERP._invoke_without_enc('global', @id)
end
end
end

Просмотреть файл

@ -0,0 +1,142 @@
#
# tkextlib/blt/watch.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/blt.rb'
module Tk::BLT
class Watch < TkObject
extend TkCore
TkCommandNames = ['::blt::watch'.freeze].freeze
WATCH_ID_TBL = TkCore::INTERP.create_table
BLT_WATCH_ID = ['blt_watch_id'.freeze, '00000'.taint].freeze
def self.names(state = None)
tk_split_list(tk_call('::blt::watch', 'names', state)).collect{|name|
WATCH_ID_TBL[name] || name
}
end
def __numval_optkeys
['maxlevel']
end
private :__numval_optkeys
def __boolval_optkeys
['active']
end
private :__boolval_optkeys
def __config_cmd
['::blt::watch', 'configure', self.path]
end
private :__config_cmd
def initialize(name = nil, keys = {})
if name.kind_of?(Hash)
keys = name
name = nil
end
if name
@id = name.to_s
else
@id = BLT_WATCH_ID.join(TkCore::INTERP._ip_id_)
BLT_WATCH_ID[1].succ!
end
@path = @id
WATCH_ID_TBL[@id] = self
tk_call('::blt::watch', 'create', @id, *hash_kv(keys))
end
def activate
tk_call('::blt::watch', 'activate', @id)
self
end
def deactivate
tk_call('::blt::watch', 'deactivate', @id)
self
end
def delete
tk_call('::blt::watch', 'delete', @id)
self
end
def info
ret = []
lst = tk_split_simplelist(tk_call('::blt::watch', 'info', @id))
until lst.empty?
k, v, *lst = lst
k = k[1..-1]
case k
when /^(#{__strval_optkeys.join('|')})$/
# do nothing
when /^(#{__numval_optkeys.join('|')})$/
begin
v = number(v)
rescue
v = nil
end
when /^(#{__numstrval_optkeys.join('|')})$/
v = num_or_str(v)
when /^(#{__boolval_optkeys.join('|')})$/
begin
v = bool(v)
rescue
v = nil
end
when /^(#{__listval_optkeys.join('|')})$/
v = simplelist(v)
when /^(#{__numlistval_optkeys.join('|')})$/
v = list(v)
else
if v.index('{')
v = tk_split_list(v)
else
v = tk_tcl2ruby(v)
end
end
ret << [k, v]
end
ret
end
def configinfo(slot = nil)
if slot
slot = slot.to_s
v = cget(slot)
if TkComm::GET_CONFIGINFO_AS_ARRAY
[slot, v]
else
{slot=>v}
end
else
if TkComm::GET_CONFIGINFO_AS_ARRAY
info
else
Hash[*(info.flatten)]
end
end
end
def cget(key)
key = key.to_s
begin
info.assoc(key)[1]
rescue
fail ArgumentError, "unknown option '#{key}'"
end
end
end
end

Просмотреть файл

@ -0,0 +1,61 @@
#
# tkextlib/blt/win_printer.rb
#
# *** Windows only ***
#
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/blt.rb'
module Tk::BLT
class Printer < TkObject
extend TkCore
TkCommandNames = ['::blt::printer'.freeze].freeze
def self.enum(attribute)
simplelist(tk_call('::blt::printer', 'enum', attribute))
end
def self.names(pat=None)
simplelist(tk_call('::blt::printer', 'names', pat))
end
def self.open(printer)
self.new(printer)
end
#################################
def initialize(printer)
@printer_id = tk_call('::blt::printer', 'open', printer)
end
def close
tk_call('::blt::print', 'close', @printer_id)
self
end
def get_attrs(var)
tk_call('::blt::print', 'getattrs', @printer_id, var)
var
end
def set_attrs(var)
tk_call('::blt::print', 'setattrs', @printer_id, var)
self
end
def snap(win)
tk_call('::blt::print', 'snap', @printer_id, win)
self
end
def write(str)
tk_call('::blt::print', 'write', @printer_id, str)
self
end
def write_with_title(title, str)
tk_call('::blt::print', 'write', @printer_id, title, str)
self
end
end
end

Просмотреть файл

@ -0,0 +1,107 @@
#
# tkextlib/blt/winop.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
require 'tk'
require 'tkextlib/blt.rb'
module Tk::BLT
module Winop
extend TkCore
TkCommandNames = ['::blt::winop'.freeze].freeze
end
WinOp = Winop
end
class << Tk::BLT::Winop
def changes(win)
tk_call('::blt::winop', 'changes', win)
end
def colormap(win)
Hash[*list(tk_call('::blt::winop', 'colormap', win))]
end
def convolve(src, dest, filter)
tk_call('::blt::winop', 'convolve', src, dest, filter)
end
def image_convolve(src, dest, filter)
tk_call('::blt::winop', 'image', 'convolve', src, dest, filter)
end
def image_gradient(photo, left, right, type)
tk_call('::blt::winop', 'image', 'gradient', photo, left, right, type)
end
def image_read_jpeg(file, photo)
tk_call('::blt::winop', 'image', 'readjpeg', file, photo)
end
def image_resample(src, dest, horiz_filter=None, vert_filter=None)
tk_call('::blt::winop', 'image', 'resample',
src, dest, horiz_filter, vert_filter)
end
def image_rotate(src, dest, angle)
tk_call('::blt::winop', 'image', 'rotate', src, dest, angle)
end
def image_snap(win, photo, width=None, height=None)
tk_call('::blt::winop', 'image', 'snap', win, photo, width, height)
end
def image_subample(src, dest, x, y, width, height,
horiz_filter=None, vert_filter=None)
tk_call('::blt::winop', 'image', 'subsample',
src, dest, x, y, width, height, horiz_filter, vert_filter)
end
def quantize(src, dest, colors)
tk_call('::blt::winop', 'quantize', src, dest, colors)
end
def query()
tk_call('::blt::winop', 'query')
end
def read_jpeg(file, photo)
tk_call('::blt::winop', 'readjpeg', file, photo)
end
def resample(src, dest, horiz_filter=None, vert_filter=None)
tk_call('::blt::winop', 'resample',
src, dest, horiz_filter, vert_filter)
end
def subsample(src, dest, x, y, width, height,
horiz_filter=None, vert_filter=None)
tk_call('::blt::winop', 'subsample',
src, dest, x, y, width, height, horiz_filter, vert_filter)
end
def raise(*wins)
tk_call('::blt::winop', 'raise', *wins)
end
def lower(*wins)
tk_call('::blt::winop', 'lower', *wins)
end
def map(*wins)
tk_call('::blt::winop', 'map', *wins)
end
def unmap(*wins)
tk_call('::blt::winop', 'unmap', *wins)
end
def move(win, x, y)
tk_call('::blt::winop', 'move', win, x, y)
end
def snap(win, photo)
tk_call('::blt::winop', 'snap', win, photo)
end
def warpto(win = None)
tk_call('::blt::winop', 'warpto', win)
end
alias warp_to warpto
end