1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
* small bug fix
 * rename 'no_create' option to 'without_creating'
 * add TkWindow#pack_in,  TkWindow#grid_in,  TkWindow#place_in
 * add TkWindow#bind_class and TkWindow#database_class
   If defined specific_class (@db_class), bind_class returns @db_class.
   In other case, bind_class returns TkWinow#class().
   It is useful for binding.
   TkWindow#database_class is defined for querying the option database.
   It's same to TkWinfo.classname(self).
 * add TkBindTag.new_by_name and TkDatabaseClass for binding to database class
 * check varname whether already exsist or not. (TkVarAccess.new)
 * TkTextWin#bbox returns an array of four numbers
 * autoload TkDialog2, TkWarning2
 * scan event callback arguments and convert to proper type
 * TkBindTag.new accepts a block ( TkBindTag.new(context){callback} )
 * If given taglist, TkWindow#bindtags(taglist) returns taglist
 * add TkWindow#bindtags=(taglist)
 * Tk.focue and Tk.focus_lastfor return nil if there is no target widget.
 * Tk::Wm.client returns the argument string when setting name
 * TkGrid.columnconfiginfo and rowconfiginfo given a slot return a number.
 * TkWindow.grid_columnconfiginfo and grid_rowconfiginfo :: ditto
 * rename and define alias :: TkOption ==> TkOptionDB
 * define alias :: TkTimer ==> TkAfter
 * some instance methods change from public to private
 * some TkComm methods change to module functions
   (help to treat return values from Tk)
 * add support for -displayof option to some TkWinfo methods
 * bind, bind_append and bind_remove :: returns the target of event-binding
 * add Tk8.4 features
 * add TkPaneWindow

tkdialog.rb:
 * classes without showing at initialize : TkDialog2, TkWarning2
 * add show method to reuse TkDialog object
 * some instance methods change from public to private
 * add new features for configuration

tktext.rb :
 * small bug fix
 * some methods return self
 * add TkTextMark#+(mod) and TkTextMark#-(mod) (e.g. mark + '3 chars')
 * add some methods

tkcanvas.rb :
 * small bug fix
 * some methods return self

tkentry.rb :
 * some methods return self
 * TkEntry#bbox returns an array of four numbers
 * scan validatecommand arguments and convert to proper type

tkbgerror.rb :
 * support to define a error handler by user

tcltklib.rb :
 * reported by Ferenc Engard <engard@all.hu> on [ruby-talk:60759]

                                     ... and so on


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3960 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagai 2003-06-18 19:46:20 +00:00
parent 151f1241c6
commit d8b02b5096
14 changed files with 1659 additions and 441 deletions

View file

@ -93,9 +93,11 @@ class TclTkInterpreter
# ruby_fmt command format arguments by `format' and call `ruby' command
# (notice ruby command receives only one argument)
if $DEBUG
@ip._eval("proc ruby_fmt {fmt args} { puts \"ruby_fmt: $fmt $args\" ; ruby [format $fmt $args] }")
@ip._eval("proc ruby_fmt {fmt args} { puts \"ruby_fmt: $fmt
$args\" ; set cmd [list ruby [format $fmt $args]] ; uplevel $cmd }")
else
@ip._eval("proc ruby_fmt {fmt args} { ruby [format $fmt $args] }")
@ip._eval("proc ruby_fmt {fmt args} { set cmd [list ruby [format
$fmt $args]] ; uplevel $cmd }")
end
# @ip._get_eval_string(*args): generate string to evaluate in tcl interpreter

View file

@ -8,6 +8,7 @@ lib/tkafter.rb
lib/tkbgerror.rb
lib/tkcanvas.rb
lib/tkclass.rb
lib/tkconsole.rb
lib/tkdialog.rb
lib/tkentry.rb
lib/tkfont.rb

View file

@ -4,6 +4,7 @@ tkafter.rb handles Tcl after
tkbgerror.rb Tk error module
tkcanvas.rb Tk canvas interface
tkclass.rb provides generic names for Tk classes
tkconsole.rb console command support
tkdialog.rb Tk dialog class
tkentry.rb Tk entry class
tkfont.rb Tk font support

File diff suppressed because it is too large Load diff

View file

@ -12,7 +12,15 @@ class TkAfter
Tk_CBID = [0]
Tk_CBTBL = {}
INTERP._invoke("proc", "rb_after", "id", "ruby [format \"TkAfter.callback %%Q!%s!\" $id]")
TkComm::INITIALIZE_TARGETS << self
def self.__init_tables__
# cannot clear
# Tcl interpreter may keep callbacks
end
INTERP._invoke("proc", "rb_after", "id",
"ruby [format \"TkAfter.callback %%Q!%s!\" $id]")
###############################
# class methods
@ -310,3 +318,5 @@ class TkAfter
end
end
end
TkTimer = TkAfter

View file

@ -12,6 +12,16 @@ module TkBgError
end
alias tkerror bgerror
alias show bgerror
module_function :bgerror, :tkerror, :show
def set_handler(hdlr = Proc.new) #==> handler :: proc{|msg| ...body... }
tk_call('proc', 'bgerror', 'msg', install_cmd(hdlr) + ' $msg')
end
def set_default
begin
tk_call('rename', 'bgerror', '')
rescue RuntimeError
end
end
module_function :set_handler, :set_default
end

View file

@ -31,9 +31,6 @@ class TkCanvas<TkWindow
WidgetClassName = 'Canvas'.freeze
WidgetClassNames[WidgetClassName] = self
def self.to_eval
WidgetClassName
end
def create_self(keys)
if keys and keys != None
@ -54,6 +51,7 @@ class TkCanvas<TkWindow
def addtag(tag, mode, *args)
tk_send 'addtag', tagid(tag), mode, *args
self
end
def addtag_above(tagOrId, target)
addtag(tagOrId, 'above', tagid(target))
@ -83,10 +81,17 @@ class TkCanvas<TkWindow
def itembind(tag, context, cmd=Proc.new, args=nil)
_bind([path, "bind", tagid(tag)], context, cmd, args)
self
end
def itembind_append(tag, context, cmd=Proc.new, args=nil)
_bind_append([path, "bind", tagid(tag)], context, cmd, args)
self
end
def itembind_remove(tag, context)
_bind_remove([path, "bind", tagid(tag)], context)
self
end
def itembindinfo(tag, context=nil)
@ -104,21 +109,24 @@ class TkCanvas<TkWindow
if args == []
tk_split_list(tk_send('coords', tagid(tag)))
else
tk_send('coords', tagid(tag), *args)
tk_send('coords', tagid(tag), *(args.flatten))
end
end
def dchars(tag, first, last=None)
tk_send 'dchars', tagid(tag), first, last
self
end
def delete(*args)
tk_send 'delete', *args.collect{|t| tagid(t)}
self
end
alias remove delete
def dtag(tag, tag_to_del=None)
tk_send 'dtag', tagid(tag), tag_to_del
self
end
def find(mode, *args)
@ -151,6 +159,7 @@ class TkCanvas<TkWindow
def itemfocus(tagOrId=nil)
if tagOrId
tk_send 'focus', tagid(tagOrId)
self
else
ret = tk_send('focus')
if ret == ""
@ -169,14 +178,16 @@ class TkCanvas<TkWindow
def icursor(tagOrId, index)
tk_send 'icursor', tagid(tagOrId), index
self
end
def index(tagOrId, index)
tk_send 'index', tagid(tagOrId), index
number(tk_send('index', tagid(tagOrId), index))
end
def insert(tagOrId, index, string)
tk_send 'insert', tagid(tagOrId), index, string
self
end
def itemcget(tagOrId, option)
@ -215,6 +226,7 @@ class TkCanvas<TkWindow
tk_send 'itemconfigure', tagid(tagOrId), "-#{key}", value
end
end
self
end
# def itemconfigure(tagOrId, key, value=None)
# if key.kind_of? Hash
@ -285,10 +297,12 @@ class TkCanvas<TkWindow
def lower(tag, below=None)
tk_send 'lower', tagid(tag), tagid(below)
self
end
def move(tag, x, y)
tk_send 'move', tagid(tag), x, y
self
end
def postscript(keys)
@ -297,21 +311,26 @@ class TkCanvas<TkWindow
def raise(tag, above=None)
tk_send 'raise', tagid(tag), tagid(above)
self
end
def scale(tag, x, y, xs, ys)
tk_send 'scale', tagid(tag), x, y, xs, ys
self
end
def scan_mark(x, y)
tk_send 'scan', 'mark', x, y
self
end
def scan_dragto(x, y)
tk_send 'scan', 'dragto', x, y
self
end
def select(mode, *args)
tk_send 'select', mode, *args
r = tk_send('select', mode, *args)
(mode == 'item')? TkcItem.id2obj(self, r): self
end
def select_adjust(tagOrId, index)
select('adjust', tagid(tagOrId), index)
@ -340,6 +359,7 @@ module TkcTagAccess
def addtag(tag)
@c.addtag(tag, 'with', @id)
self
end
def bbox
@ -348,6 +368,17 @@ module TkcTagAccess
def bind(seq, cmd=Proc.new, args=nil)
@c.itembind @id, seq, cmd, args
self
end
def bind_append(seq, cmd=Proc.new, args=nil)
@c.itembind_append @id, seq, cmd, args
self
end
def bind_remove(seq)
@c.itembind_remove @id, seq
self
end
def bindinfo(seq=nil)
@ -360,6 +391,7 @@ module TkcTagAccess
def configure(key, value=None)
@c.itemconfigure @id, key, value
self
end
# def configure(keys)
# @c.itemconfigure @id, keys
@ -375,10 +407,12 @@ module TkcTagAccess
def dchars(first, last=None)
@c.dchars @id, first, last
self
end
def dtag(tag_to_del=None)
@c.dtag @id, tag_to_del
self
end
def find
@ -396,6 +430,7 @@ module TkcTagAccess
def icursor(index)
@c.icursor @id, index
self
end
def index(index)
@ -404,32 +439,40 @@ module TkcTagAccess
def insert(beforethis, string)
@c.insert @id, beforethis, string
self
end
def lower(belowthis=None)
@c.lower @id, belowthis
self
end
def move(xamount, yamount)
@c.move @id, xamount, yamount
self
end
def raise(abovethis=None)
@c.raise @id, abovethis
self
end
def scale(xorigin, yorigin, xscale, yscale)
@c.scale @id, xorigin, yorigin, xscale, yscale
self
end
def select_adjust(index)
@c.select('adjust', @id, index)
self
end
def select_from(index)
@c.select('from', @id, index)
self
end
def select_to(index)
@c.select('to', @id, index)
self
end
def itemtype
@ -478,6 +521,13 @@ class TkcTag<TkObject
CTagID_TBL = {}
Tk_CanvasTag_ID = ['ctag0000']
TkComm::INITIALIZE_TARGETS << self
def self.__init_tables__
CTagID_TBL.clear
Tk_CanvasTag_ID[0] = 'ctag0000'
end
def TkcTag.id2obj(canvas, id)
cpath = canvas.path
return id unless CTagID_TBL[cpath]
@ -499,48 +549,56 @@ class TkcTag<TkObject
end
end
def id
return @id
@id
end
def delete
@c.delete @id
CTagID_TBL[@cpath].delete(@id) if CTagID_TBL[@cpath]
self
end
alias remove delete
alias destroy delete
def set_to_above(target)
@c.addtag_above(@id, target)
self
end
alias above set_to_above
def set_to_all
@c.addtag_all(@id)
self
end
alias all set_to_all
def set_to_below(target)
@c.addtag_below(@id, target)
self
end
alias below set_to_below
def set_to_closest(x, y, halo=None, start=None)
@c.addtag_closest(@id, x, y, halo, start)
self
end
alias closest set_to_closest
def set_to_enclosed(x1, y1, x2, y2)
@c.addtag_enclosed(@id, x1, y1, x2, y2)
self
end
alias enclosed set_to_enclosed
def set_to_overlapping(x1, y1, x2, y2)
@c.addtag_overlapping(@id, x1, y1, x2, y2)
self
end
alias overlapping set_to_overlapping
def set_to_withtag(target)
@c.addtag_withtag(@id, target)
self
end
alias withtag set_to_withtag
end
@ -615,12 +673,14 @@ class TkcGroup<TkcTag
for i in tags
i.addtag @id
end
self
end
def exclude(*tags)
for i in tags
i.delete @id
end
self
end
end
@ -630,6 +690,12 @@ class TkcItem<TkObject
CItemTypeToClass = {}
CItemID_TBL = {}
TkComm::INITIALIZE_TARGETS << self
def self.__init_tables__
CItemID_TBL.clear
end
def TkcItem.type2class(type)
CItemTypeToClass[type]
end
@ -683,12 +749,13 @@ class TkcItem<TkObject
def create_self(*args); end
private :create_self
def id
return @id
@id
end
def delete
@c.delete @id
CItemID_TBL[@path].delete(@id) if CItemID_TBL[@path]
self
end
alias remove delete
alias destroy delete
@ -753,8 +820,15 @@ class TkImage<TkObject
include Tk
Tk_IMGTBL = {}
Tk_Image_ID = ['i00000']
TkComm::INITIALIZE_TARGETS << self
def self.__init_tables__
Tk_IMGTBL.clear
Tk_Image_ID[0] = 'i00000'
end
def initialize(keys=nil)
@path = Tk_Image_ID[0]
Tk_Image_ID[0] = Tk_Image_ID[0].succ
@ -765,6 +839,7 @@ class TkImage<TkObject
def delete
Tk_IMGTBL.delete(@id) if @id
tk_call('image', 'delete', @path)
self
end
def height
number(tk_call('image', 'height', @path))
@ -805,6 +880,7 @@ class TkPhotoImage<TkImage
def blank
tk_send 'blank'
self
end
def cget(option)
@ -826,14 +902,16 @@ class TkPhotoImage<TkImage
}.flatten
tk_send 'copy', source, *args
self
end
def data(keys=nil)
tk_send 'data', *hash_kv(keys)
tk_send('data', *hash_kv(keys))
end
def get(x, y)
tk_send 'get', x, y
tk_send('get', x, y).split.collect{|n| n.to_i}
end
def put(data, *to)
@ -842,6 +920,7 @@ class TkPhotoImage<TkImage
else
tk_send 'put', data, '-to', *to
end
self
end
def read(file, *opts)
@ -854,10 +933,21 @@ class TkPhotoImage<TkImage
}.flatten
tk_send 'read', file, *args
self
end
def redither
tk_send 'redither'
self
end
def get_transparency(x, y)
bool(tk_send('transparency', 'get', x, y))
end
def set_transparency(x, y, st)
tk_send('transparency', 'set', x, y, st)
self
end
def write(file, *opts)
@ -870,5 +960,7 @@ class TkPhotoImage<TkImage
}.flatten
tk_send 'write', file, *args
self
end
end

26
ext/tk/lib/tkconsole.rb Normal file
View file

@ -0,0 +1,26 @@
#
# tkconsole.rb : control the console on system without a real console
#
require 'tk'
module TkConsole
include Tk
extend Tk
def self.title(str=None)
tk_call 'console', str
end
def self.hide
tk_call 'console', 'hide'
end
def self.show
tk_call 'console', 'show'
end
def self.eval(tcl_script)
#
# supports a Tcl script only
# I have no idea to support a Ruby script seamlessly.
#
tk_call 'console', 'eval', tcl_script
end
end

View file

@ -1,13 +1,55 @@
require "tk"
class TkDialog < TkWindow
class TkDialog2 < TkWindow
extend Tk
def self.show(*args)
dlog = self.new(*args)
dlog.show
dlog
end
def _set_button_config(configs)
set_config = proc{|c,i|
if $VERBOSE && (c.has_key?('command') || c.has_key?(:command))
STDERR.print("Warning: cannot give a command option " +
"to the dialog button#{i}. It was removed.\n")
end
c.delete('command'); c.delete(:command)
@config << format("%s.button%s configure %s; ",
@path, i, hash_kv(c).join(' '))
}
case configs
when Proc
@buttons.each_index{|i|
if (c = configs.call(i)).kind_of? Hash
set_config.call(c,i)
end
}
when Array
@buttons.each_index{|i|
if (c = configs[i]).kind_of? Hash
set_config.call(c,i)
end
}
when Hash
@buttons.each_with_index{|s,i|
if (c = configs[s]).kind_of? Hash
set_config.call(c,i)
end
}
end
@config = 'after idle {' + @config + '};' if @config != ""
end
private :_set_button_config
# initialize tk_dialog
def initialize(keys = nil)
super()
@var = TkVariable.new
id = @var.id
@title = title
@ -20,28 +62,42 @@ class TkDialog < TkWindow
@default_button = default_button
@buttons = buttons
@button_configs = proc{|num| button_configs num}
@button_configs = proc{|num| button_configs(num)}
#@config = "puts [winfo children .w0000];"
@config = ""
if keys.kind_of? Hash
keys = _symbolkey2str(keys)
@title = keys['title'] if keys['title']
@message = keys['message'] if keys['message']
@bitmap = keys['bitmap'] if keys['bitmap']
@default_button = keys['default'] if keys['default']
@buttons = keys['buttons'] if keys['buttons']
@title = keys['title'] if keys.key? 'title'
@message = keys['message'] if keys.key? 'message'
@bitmap = keys['bitmap'] if keys.key? 'bitmap'
@default_button = keys['default'] if keys.key? 'default'
@buttons = keys['buttons'] if keys.key? 'buttons'
@command = keys['prev_command']
@message_config = keys['message_config'] if keys['message_config']
@bitmap_config = keys['bitmap_config'] if keys['bitmap_config']
@button_configs = keys['button_configs'] if keys['button_configs']
@message_config = keys['message_config'] if keys.key? 'message_config'
@msgframe_config = keys['msgframe_config'] if keys.key? 'msgframe_config'
@bitmap_config = keys['bitmap_config'] if keys.key? 'bitmap_config'
@button_configs = keys['button_configs'] if keys.key? 'button_configs'
@btnframe_config = keys['btnframe_config'] if keys.key? 'btnframe_config'
end
if @title.include? ?\s
@title = '{' + @title + '}'
end
@buttons = tk_split_list(@buttons) if @buttons.kind_of? String
if @buttons.kind_of? Array
_set_button_config(@buttons.collect{|cfg|
(cfg.kind_of? Array)? cfg[1]: nil})
@buttons = @buttons.collect{|cfg| (cfg.kind_of? Array)? cfg[0]: cfg}
end
if @buttons.kind_of? Hash
_set_button_config(@buttons)
@buttons = @buttons.keys
end
@buttons = tk_split_simplelist(@buttons) if @buttons.kind_of? String
@buttons = @buttons.collect{|s|
if s.kind_of? Array
s = s.join(' ')
@ -53,34 +109,46 @@ class TkDialog < TkWindow
end
}
config = ""
if @message_config.kind_of? Hash
config << format("%s.msg configure %s\n",
@config << format("%s.msg configure %s;",
@path, hash_kv(@message_config).join(' '))
end
if @msgframe_config.kind_of? Hash
@config << format("%s.top configure %s;",
@path, hash_kv(@msgframe_config).join(' '))
end
if @btnframe_config.kind_of? Hash
@config << format("%s.bot configure %s;",
@path, hash_kv(@btnframe_config).join(' '))
end
if @bitmap_config.kind_of? Hash
config << format("%s.msg configure %s\n",
@config << format("%s.bitmap configure %s;",
@path, hash_kv(@bitmap_config).join(' '))
end
if @button_configs.kind_of? Proc
@buttons.each_index{|i|
if (c = @button_configs.call(i)).kind_of? Hash
config << format("%s.button%s configure %s\n",
@path, i, hash_kv(c).join(' '))
end
}
end
config = 'after idle {' + config + '};' if config != ""
_set_button_config(@button_configs) if @button_configs
if @command.kind_of? Proc
@command.call(self)
end
INTERP._eval('eval {global '+id+';'+config+
'set '+id+' [tk_dialog '+
@path+" "+@title+" {#{@message}} "+@bitmap+" "+
String(@default_button)+" "+@buttons.join(' ')+']}')
end
def show
if @default_button.kind_of? String
default_button = @buttons.index(@default_button)
else
default_button = @default_button
end
default_button = '{}' if default_button == nil
INTERP._eval('eval {global '+@var.id+';'+@config+
'set '+@var.id+' [tk_dialog '+
@path+" "+@title+" {#{@message}} "+@bitmap+" "+
String(default_button)+" "+@buttons.join(' ')+']}')
end
def value
return @var.value.to_i
end
@ -89,22 +157,36 @@ class TkDialog < TkWindow
# these methods must be overridden for each dialog #
# #
######################################################
private
def title
# returns a title string of the dialog window
return "DIALOG"
end
def message
# returns a message text to display on the dialog
return "MESSAGE"
end
def message_config
# returns a Hash {option=>value, ...} for the message text
return nil
end
def msgframe_config
# returns a Hash {option=>value, ...} for the message text frame
return nil
end
def bitmap
# returns a bitmap name or a bitmap file path
# (@ + path ; e.g. '@/usr/share/bitmap/sample.xbm')
return "info"
end
def bitmap_config
# returns nil or a Hash {option=>value, ...} for the bitmap
return nil
end
def default_button
# returns a default button's number or name
# if nil or null string, set no-default
return 0
end
def buttons
@ -112,21 +194,50 @@ class TkDialog < TkWindow
return ["BUTTON1", "BUTTON2"]
end
def button_configs(num)
# returns nil / Proc / Array or Hash (see _set_button_config)
return nil
end
def btnframe_config
# returns nil or a Hash {option=>value, ...} for the button frame
return nil
end
end
#
# TkDialog : with showing at initialize
#
class TkDialog < TkDialog2
def self.show(*args)
self.new(*args)
end
def initialize(*args)
super(*args)
show
end
end
#
# dialog for warning
#
class TkWarning < TkDialog
class TkWarning2 < TkDialog2
def initialize(mes)
@mes = mes
super()
super(:message=>mes)
end
def message
return @mes
def show(mes = nil)
mes_bup = @message
@message = mes if mes
ret = super()
@message = mes_bup
ret
end
#######
private
def title
return "WARNING";
end
@ -140,3 +251,13 @@ class TkWarning < TkDialog
return "OK";
end
end
class TkWarning < TkWarning2
def self.show(*args)
self.new(*args)
end
def initialize(mes)
super(mes)
show
end
end

View file

@ -10,14 +10,39 @@ class TkEntry<TkLabel
WidgetClassName = 'Entry'.freeze
WidgetClassNames[WidgetClassName] = self
def self.to_eval
WidgetClassName
end
class ValidateCmd
include TkComm
class ValidateArgs
VARG_KEY = 'disvPSVW'
VARG_TYPE = 'nnsssssw'
def self.scan_args(arg_str, arg_val)
arg_cnv = []
arg_str.strip.split(/\s+/).each_with_index{|kwd,idx|
if kwd =~ /^%(.)$/
if num = VARG_KEY.index($1)
case VARG_TYPE[num]
when ?n
arg_cnv << TkComm::number(arg_val[idx])
when ?s
arg_cnv << TkComm::string(arg_val[idx])
when ?w
arg_cnv << TkComm::window(arg_val[idx])
else
arg_cnv << arg_val[idx]
end
else
arg_cnv << arg_val[idx]
end
else
arg_cnv << arg_val[idx]
end
}
arg_cnv
end
def initialize(d,i,s,v,pp,ss,vv,ww)
@action = d
@index = i
@ -40,13 +65,19 @@ class TkEntry<TkLabel
def initialize(cmd = Proc.new, args=nil)
if args
@id = install_cmd(proc{|*arg|
TkUtil.eval_cmd cmd, *arg
}) + " " + args
@id =
install_cmd(proc{|*arg|
TkUtil.eval_cmd(cmd, ValidateArgs.scan_args(args, arg))
}) + " " + args
else
@id = install_cmd(proc{|arg|
TkUtil.eval_cmd cmd, ValidateArgs.new(*arg)
}) + ' %d %i %s %v %P %S %V %W'
args = ' %d %i %s %v %P %S %V %W'
@id =
install_cmd(proc{|*arg|
TkUtil.eval_cmd(
cmd,
ValidateArgs.new(ValidateArgs.scan_args(args, arg))
)
}) + args
end
end
@ -63,14 +94,6 @@ class TkEntry<TkLabel
end
end
def bbox(index)
tk_send 'bbox', index
end
def delete(s, e=None)
tk_send 'delete', s, e
end
def configure(slot, value=None)
if slot.kind_of? Hash
slot = _symbolkey2str(slot)
@ -113,54 +136,60 @@ class TkEntry<TkLabel
end
super(slot, value)
end
self
end
def cursor
tk_send 'index', 'insert'
number(tk_send('index', 'insert'))
end
def cursor=(index)
tk_send 'icursor', index
self
end
def index(index)
number(tk_send('index', index))
end
def insert(pos,text)
tk_send 'insert', pos, text
self
end
def mark(pos)
tk_send 'scan', 'mark', pos
self
end
def dragto(pos)
tk_send 'scan', 'dragto', pos
self
end
def selection_adjust(index)
tk_send 'selection', 'adjust', index
self
end
def selection_clear
tk_send 'selection', 'clear'
self
end
def selection_from(index)
tk_send 'selection', 'from', index
self
end
def selection_present()
bool(tk_send('selection', 'present'))
end
def selection_range(s, e)
tk_send 'selection', 'range', s, e
self
end
def selection_to(index)
tk_send 'selection', 'to', index
self
end
def validate(mode = nil)
if mode
configure 'validate', mode
else
if tk_send('validate') == '0'
false
else
true
end
bool(tk_send('validate'))
end
end
@ -194,9 +223,6 @@ end
class TkSpinbox<TkEntry
WidgetClassName = 'Spinbox'.freeze
WidgetClassNames[WidgetClassName] = self
def self.to_eval
WidgetClassName
end
def create_self(keys)
if keys and keys != None
@ -212,10 +238,12 @@ class TkSpinbox<TkEntry
def spinup
tk_send 'invoke', 'spinup'
self
end
def spindown
tk_send 'invoke', 'spindown'
self
end
def set(str)

View file

@ -13,6 +13,14 @@ class TkFont
Tk_FontNameTBL = {}
Tk_FontUseTBL = {}
TkComm::INITIALIZE_TARGETS << self
def self.__init_tables__
Tk_FontNameTBL.clear
Tk_FontUseTBL.clear
Tk_FontID[0] = 0
end
# set default font
case Tk::TK_VERSION
when /^4\.*/
@ -879,6 +887,7 @@ class TkFont
def configure(slot, value=None)
configure_core(@compoundfont, slot, value)
self
end
def configinfo(slot=nil)
@ -895,6 +904,7 @@ class TkFont
else
configure(slot, value)
end
self
end
def latin_configinfo(slot=nil)
@ -914,6 +924,7 @@ class TkFont
#""
configure(slot, value)
end
self
end
def kanji_configinfo(slot=nil)
@ -935,11 +946,13 @@ class TkFont
def latin_replace(ltn)
latin_replace_core(ltn)
reset_pointadjust
self
end
def kanji_replace(knj)
kanji_replace_core(knj)
reset_pointadjust
self
end
def measure(text)
@ -1019,27 +1032,33 @@ module TkTreatTagFont
def font_configure(slot)
@parent.tagfont_configure(@id, slot)
self
end
def latinfont_configure(ltn, keys=nil)
@parent.latintagfont_configure(@id, ltn, keys)
self
end
alias asciifont_configure latinfont_configure
def kanjifont_configure(knj, keys=nil)
@parent.kanjitagfont_configure(@id, ltn, keys)
self
end
def font_copy(window, wintag=nil)
@parent.tagfont_copy(@id, window, wintag)
self
end
def latinfont_copy(window, wintag=nil)
@parent.latintagfont_copy(@id, window, wintag)
self
end
alias asciifont_copy latinfont_copy
def kanjifont_copy(window, wintag=nil)
@parent.kanjitagfont_copy(@id, window, wintag)
self
end
end

View file

@ -1,6 +1,6 @@
#
# tkmngfocus.rb : methods for Tcl/Tk standard library 'focus.tcl'
# 1998/07/16 by Hidetoshi Nagai <nagai@ai.kyutech.ac.jp>
# by Hidetoshi Nagai <nagai@ai.kyutech.ac.jp>
#
require 'tk'
@ -12,14 +12,14 @@ module TkManageFocus
end
def TkManageFocus.next(window)
tk_call 'tk_focusNext', window
tk_tcl2ruby(tk_call('tk_focusNext', window))
end
def focusNext
TkManageFocus.next(self)
end
def TkManageFocus.prev(window)
tk_call 'tk_focusPrev', window
tk_tcl2ruby(tk_call('tk_focusPrev', window))
end
def focusPrev
TkManageFocus.prev(self)

View file

@ -31,10 +31,6 @@ class TkText<TkTextWin
WidgetClassName = 'Text'.freeze
WidgetClassNames[WidgetClassName] = self
def self.to_eval
WidgetClassName
end
def self.new(*args, &block)
obj = super(*args){}
obj.init_instance_variable
@ -85,13 +81,13 @@ class TkText<TkTextWin
end
def tag_names(index=None)
tk_split_list(tk_send('tag', 'names', index)).collect{|elt|
tk_split_simplelist(tk_send('tag', 'names', index)).collect{|elt|
tagid2obj(elt)
}
end
def mark_names
tk_split_list(tk_send('mark', 'names')).collect{|elt|
tk_split_simplelist(tk_send('mark', 'names')).collect{|elt|
tagid2obj(elt)
}
end
@ -104,28 +100,93 @@ class TkText<TkTextWin
tagid2obj(tk_send('mark', 'previous', index))
end
def window_names
tk_send('window', 'names').collect{|elt|
tagid2obj(elt)
}
def image_cget(index, slot)
case slot.to_s
when 'text', 'label', 'show', 'data', 'file'
tk_send('image', 'cget', index, "-#{slot}")
else
tk_tcl2ruby(tk_send('image', 'cget', index, "-#{slot}"))
end
end
def image_configure(index, slot, value=None)
if slot.kind_of? Hash
tk_send('image', 'configure', index, *hash_kv(slot))
else
tk_send('image', 'configure', index, "-#{slot}", value)
end
self
end
def image_configinfo(index, slot = nil)
if slot
case slot.to_s
when 'text', 'label', 'show', 'data', 'file'
conf = tk_split_simplelist(tk_send('image', 'configure',
index, "-#{slot}"))
else
conf = tk_split_list(tk_send('image', 'configure',
index, "-#{slot}"))
end
conf[0] = conf[0][1..-1]
conf
else
tk_split_simplelist(tk_send('image', 'configure',
index)).collect{|conflist|
conf = tk_split_simplelist(conflist)
conf[0] = conf[0][1..-1]
case conf[0]
when 'text', 'label', 'show', 'data', 'file'
else
if conf[3]
if conf[3].index('{')
conf[3] = tk_split_list(conf[3])
else
conf[3] = tk_tcl2ruby(conf[3])
end
end
if conf[4]
if conf[4].index('{')
conf[4] = tk_split_list(conf[4])
else
conf[4] = tk_tcl2ruby(conf[4])
end
end
end
conf
}
end
end
def image_names
tk_send('image', 'names').collect{|elt|
tk_split_simplelist(tk_send('image', 'names')).collect{|elt|
tagid2obj(elt)
}
end
def set_insert(index)
tk_send 'mark', 'set', 'insert', index
self
end
def set_current(index)
tk_send 'mark', 'set', 'current', index
self
end
def insert(index, chars, *tags)
super index, chars, tags.collect{|x|_get_eval_string(x)}.join(' ')
if tags[0].kind_of? Array
# multiple chars-taglist argument
args = [chars]
while tags.size > 0
tags.shift.collect{|x|_get_eval_string(x)}.join(' ') # taglist
args << tags.shift if tags.size > 0 # chars
end
super index, *args
else
# single chars-taglist argument
super index, chars, tags.collect{|x|_get_eval_string(x)}.join(' ')
end
end
def destroy
@ -149,47 +210,87 @@ class TkText<TkTextWin
end
def debug=(boolean)
tk_send 'debug', boolean
self
end
def bbox(index)
list(tk_send('bbox', index))
end
def bbox(index)
inf = tk_send('bbox', index)
(inf == "")? [0,0,0,0]: inf
end
def dlineinfo(index)
inf = tk_send('dlineinfo', index)
(inf == "")? [0,0,0,0,0]: inf
list(tk_send('dlineinfo', index))
end
def modified?
bool(tk_send('edit', 'modified'))
end
def modified(mode)
tk_send('edit', 'modified', mode)
self
end
def edit_redo
tk_send('edit', 'redo')
self
end
def edit_reset
tk_send('edit', 'reset')
self
end
def edit_separator
tk_send('edit', 'separator')
self
end
def edit_undo
tk_send('edit', 'undo')
self
end
def yview_pickplace(*what)
tk_send 'yview', '-pickplace', *what
self
end
def xview_pickplace(*what)
tk_send 'xview', '-pickplace', *what
self
end
def tag_add(tag, index1, index2=None)
tk_send 'tag', 'add', tag, index1, index2
self
end
alias addtag tag_add
def tag_delete(*tags)
tk_send 'tag', 'delete', *tags
self
end
alias deltag tag_delete
def tag_bind(tag, seq, cmd=Proc.new, args=nil)
_bind(['tag', 'bind', tag], seq, cmd, args)
_bind([@path, 'tag', 'bind', tag], seq, cmd, args)
self
end
def tag_bind_append(tag, seq, cmd=Proc.new, args=nil)
_bind_append(['tag', 'bind', tag], seq, cmd, args)
_bind_append([@path, 'tag', 'bind', tag], seq, cmd, args)
self
end
def tag_bind_remove(tag, seq)
_bind_remove([@path, 'tag', 'bind', tag], seq)
self
end
def tag_bindinfo(tag, context=nil)
_bindinfo(['tag', 'bind', tag], context)
_bindinfo([@path, 'tag', 'bind', tag], context)
end
def tag_cget(tag, key)
case key.to_s
when 'text', 'label', 'show', 'data', 'file'
tk_call @path, 'tag', 'cget', tag, "-#{key}"
tk_call(@path, 'tag', 'cget', tag, "-#{key}")
else
tk_tcl2ruby tk_call(@path, 'tag', 'cget', tag, "-#{key}")
tk_tcl2ruby(tk_call(@path, 'tag', 'cget', tag, "-#{key}"))
end
end
@ -213,6 +314,7 @@ class TkText<TkTextWin
tk_send 'tag', 'configure', tag, "-#{key}", val
end
end
self
end
def tag_configinfo(tag, key=nil)
@ -254,14 +356,17 @@ class TkText<TkTextWin
def tag_raise(tag, above=None)
tk_send 'tag', 'raise', tag, above
self
end
def tag_lower(tag, below=None)
tk_send 'tag', 'lower', tag, below
self
end
def tag_remove(tag, *index)
tk_send 'tag', 'remove', tag, *index
self
end
def tag_ranges(tag)
@ -274,11 +379,79 @@ class TkText<TkTextWin
end
def tag_nextrange(tag, first, last=None)
tk_split_simplelist(tk_send('tag', 'nextrange', tag, first, last))
tk_split_list(tk_send('tag', 'nextrange', tag, first, last))
end
def tag_prevrange(tag, first, last=None)
tk_split_simplelist(tk_send('tag', 'prevrange', tag, first, last))
tk_split_list(tk_send('tag', 'prevrange', tag, first, last))
end
def window_cget(index, slot)
case slot.to_s
when 'text', 'label', 'show', 'data', 'file'
tk_send('window', 'cget', index, "-#{slot}")
else
tk_tcl2ruby(tk_send('window', 'cget', index, "-#{slot}"))
end
end
def window_configure(index, slot, value=None)
if index.kind_of? TkTextWindow
index.configure(slot, value)
else
if slot.kind_of? Hash
tk_send('window', 'configure', index, *hash_kv(slot))
else
tk_send('window', 'configure', index, "-#{slot}", value)
end
end
self
end
def window_configinfo(win, slot = nil)
if slot
case slot.to_s
when 'text', 'label', 'show', 'data', 'file'
conf = tk_split_simplelist(tk_send('window', 'configure',
win, "-#{slot}"))
else
conf = tk_split_list(tk_send('window', 'configure',
win, "-#{slot}"))
end
conf[0] = conf[0][1..-1]
conf
else
tk_split_simplelist(tk_send('window', 'configure',
win)).collect{|conflist|
conf = tk_split_simplelist(conflist)
conf[0] = conf[0][1..-1]
case conf[0]
when 'text', 'label', 'show', 'data', 'file'
else
if conf[3]
if conf[3].index('{')
conf[3] = tk_split_list(conf[3])
else
conf[3] = tk_tcl2ruby(conf[3])
end
end
if conf[4]
if conf[4].index('{')
conf[4] = tk_split_list(conf[4])
else
conf[4] = tk_tcl2ruby(conf[4])
end
end
end
conf
}
end
end
def window_names
tk_split_simplelist(tk_send('window', 'names')).collect{|elt|
tagid2obj(elt)
}
end
def _ktext_length(txt)
@ -468,7 +641,7 @@ class TkText<TkTextWin
result.push tk_tcl2ruby(val)
end
when 'tagoff'
result.push tk_tcl2ruby(sel)
result.push tk_tcl2ruby(val)
when 'window'
result.push tk_tcl2ruby(val)
end
@ -555,6 +728,13 @@ class TkTextTag<TkObject
TTagID_TBL = {}
Tk_TextTag_ID = ['tag0000']
TkComm::INITIALIZE_TARGETS << self
def self.__init_tables__
TTagID_TBL.clear
Tk_TextTag_ID[0] = 'tag0000'
end
def TkTextTag.id2obj(text, id)
tpath = text.path
return id unless TTagID_TBL[tpath]
@ -587,7 +767,7 @@ class TkTextTag<TkObject
end
def id
return @id
@id
end
def first
@ -600,10 +780,12 @@ class TkTextTag<TkObject
def add(*index)
tk_call @t.path, 'tag', 'add', @id, *index
self
end
def remove(*index)
tk_call @t.path, 'tag', 'remove', @id, *index
self
end
def ranges
@ -616,11 +798,11 @@ class TkTextTag<TkObject
end
def nextrange(first, last=None)
tk_split_simplelist(tk_call(@t.path, 'tag', 'nextrange', @id, first, last))
tk_split_list(tk_call(@t.path, 'tag', 'nextrange', @id, first, last))
end
def prevrange(first, last=None)
tk_split_simplelist(tk_call(@t.path, 'tag', 'prevrange', @id, first, last))
tk_split_list(tk_call(@t.path, 'tag', 'prevrange', @id, first, last))
end
def [](key)
@ -665,10 +847,17 @@ class TkTextTag<TkObject
def bind(seq, cmd=Proc.new, args=nil)
_bind([@t.path, 'tag', 'bind', @id], seq, cmd, args)
self
end
def bind_append(seq, cmd=Proc.new, args=nil)
_bind_append([@t.path, 'tag', 'bind', @id], seq, cmd, args)
self
end
def bind_remove(seq)
_bind_remove([@t.path, 'tag', 'bind', @id], seq)
self
end
def bindinfo(context=nil)
@ -677,15 +866,18 @@ class TkTextTag<TkObject
def raise(above=None)
tk_call @t.path, 'tag', 'raise', @id, above
self
end
def lower(below=None)
tk_call @t.path, 'tag', 'lower', @id, below
self
end
def destroy
tk_call @t.path, 'tag', 'delete', @id
TTagID_TBL[@tpath].delete(@id) if CTagID_TBL[@tpath]
self
end
end
@ -707,9 +899,20 @@ class TkTextNamedTag<TkTextTag
@path = @id = name
TTagID_TBL[@tpath] = {} unless TTagID_TBL[@tpath]
TTagID_TBL[@tpath][@id] = self
if mode
tk_call @t.path, "addtag", @id, *args
#if mode
# tk_call @t.path, "addtag", @id, *args
#end
if args != [] then
keys = args.pop
if keys.kind_of? Hash then
add(*args) if args != []
configure(keys)
else
args.push keys
add(*args)
end
end
@t._addtag id, self
end
end
@ -738,16 +941,26 @@ class TkTextMark<TkObject
tk_call @t.path, 'mark', 'set', @id, index
@t._addtag id, self
end
def id
return @id
@id
end
def +(mod)
@id + ' + ' + mod
end
def -(mod)
@id + ' - ' + mod
end
def set(where)
tk_call @t.path, 'mark', 'set', @id, where
self
end
def unset
tk_call @t.path, 'mark', 'unset', @id
self
end
alias destroy unset
@ -757,6 +970,7 @@ class TkTextMark<TkObject
def gravity=(direction)
tk_call @t.path, 'mark', 'gravity', @id, direction
self
end
def next(index = nil)
@ -850,12 +1064,7 @@ class TkTextWindow<TkObject
end
def cget(slot)
case slot.to_s
when 'text', 'label', 'show', 'data', 'file'
tk_call @t.path, 'window', 'cget', @index, "-#{slot}"
else
tk_tcl2ruby tk_call(@t.path, 'window', 'cget', @index, "-#{slot}")
end
@t.window_cget(@index, slot)
end
def configure(slot, value=None)
@ -867,16 +1076,21 @@ class TkTextWindow<TkObject
slot['create']=nil
end
if slot.size > 0
tk_call @t.path, 'window', 'configure', @index, *hash_kv(slot)
tk_call(@t.path, 'window', 'configure', @index, *hash_kv(slot))
end
else
@id = value if slot == 'window' || slot == :window
if slot == 'create' || slot == :create
self.create=value
else
tk_call @t.path, 'window', 'configure', @index, "-#{slot}", value
tk_call(@t.path, 'window', 'configure', @index, "-#{slot}", value)
end
end
self
end
def configinfo(slot = nil)
@t.window_configinfo(@index, slot)
end
def window
@ -899,47 +1113,6 @@ class TkTextWindow<TkObject
end
tk_call @t.path, 'window', 'configure', @index, '-create', value
end
def configinfo(slot = nil)
if slot
case slot.to_s
when 'text', 'label', 'show', 'data', 'file'
conf = tk_split_simplelist(tk_call(@t.path, 'window', 'configure',
@index, "-#{slot}"))
else
conf = tk_split_list(tk_call(@t.path, 'window', 'configure',
@index, "-#{slot}"))
end
conf[0] = conf[0][1..-1]
conf
else
tk_split_simplelist(tk_call(@t.path, 'window', 'configure',
@index)).collect{|conflist|
conf = tk_split_simplelist(conflist)
conf[0] = conf[0][1..-1]
case conf[0]
when 'text', 'label', 'show', 'data', 'file'
else
if conf[3]
if conf[3].index('{')
conf[3] = tk_split_list(conf[3])
else
conf[3] = tk_tcl2ruby(conf[3])
end
end
if conf[4]
if conf[4].index('{')
conf[4] = tk_split_list(conf[4])
else
conf[4] = tk_tcl2ruby(conf[4])
end
end
end
conf
}
end
end
end
class TkTextImage<TkObject
@ -972,70 +1145,28 @@ class TkTextImage<TkObject
end
def cget(slot)
case slot.to_s
when 'text', 'label', 'show', 'data', 'file'
tk_call @t.path, 'image', 'cget', @index, "-#{slot}"
else
tk_tcl2ruby tk_call(@t.path, 'image', 'cget', @index, "-#{slot}")
end
@t.image_cget(@index, slot)
end
def configure(slot, value=None)
if slot.kind_of? Hash
tk_call @t.path, 'image', 'configure', @index, *hash_kv(slot)
else
tk_call @t.path, 'image', 'configure', @index, "-#{slot}", value
end
@t.image_configure(@index, slot, value)
self
end
# def configure(slot, value)
# tk_call @t.path, 'image', 'configure', @index, "-#{slot}", value
# end
def configinfo(slot = nil)
@t.image_configinfo(@index, slot)
end
def image
tk_call @t.path, 'image', 'configure', @index, '-image'
img = tk_call(@t.path, 'image', 'configure', @index, '-image')
TkImage::Tk_IMGTBL[img]? TkImage::Tk_IMGTBL[img] : img
end
def image=(value)
tk_call @t.path, 'image', 'configure', @index, '-image', value
end
def configinfo(slot = nil)
if slot
case slot.to_s
when 'text', 'label', 'show', 'data', 'file'
conf = tk_split_simplelist(tk_call(@t.path, 'image', 'configure',
@index, "-#{slot}"))
else
conf = tk_split_list(tk_call(@t.path, 'image', 'configure',
@index, "-#{slot}"))
end
conf[0] = conf[0][1..-1]
conf
else
tk_split_simplelist(tk_call(@t.path, 'image', 'configure',
@index)).collect{|conflist|
conf = tk_split_simplelist(conflist)
conf[0] = conf[0][1..-1]
case conf[0]
when 'text', 'label', 'show', 'data', 'file'
else
if conf[3]
if conf[3].index('{')
conf[3] = tk_split_list(conf[3])
else
conf[3] = tk_tcl2ruby(conf[3])
end
end
if conf[4]
if conf[4].index('{')
conf[4] = tk_split_list(conf[4])
else
conf[4] = tk_tcl2ruby(conf[4])
end
end
end
conf
}
end
self
end
end

View file

@ -10,6 +10,13 @@ class TkVirtualEvent<TkObject
TkVirtualEventID = [0]
TkVirtualEventTBL = {}
TkComm::INITIALIZE_TARGETS << self
def self.__init_tables__
TkVirtualEventTBL.clear
TkVirtualEventID[0] = 0
end
class PreDefVirtEvent<self
def initialize(event)
@path = @id = event