1999-08-13 01:37:52 -04:00
|
|
|
#
|
|
|
|
# tktext.rb - Tk text classes
|
|
|
|
# $Date$
|
|
|
|
# by Yukihiro Matsumoto <matz@caelum.co.jp>
|
|
|
|
|
|
|
|
require 'tk.rb'
|
|
|
|
require 'tkfont'
|
|
|
|
|
|
|
|
module TkTreatTextTagFont
|
2002-02-28 01:53:33 -05:00
|
|
|
include TkTreatItemFont
|
1999-08-13 01:37:52 -04:00
|
|
|
|
2003-08-02 01:04:30 -04:00
|
|
|
ItemCMD = ['tag'.freeze, 'configure'.freeze].freeze
|
2002-02-28 01:53:33 -05:00
|
|
|
def __conf_cmd(idx)
|
|
|
|
ItemCMD[idx]
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2002-02-28 01:53:33 -05:00
|
|
|
def __item_pathname(tagOrId)
|
|
|
|
if tagOrId.kind_of?(TkTextTag)
|
|
|
|
self.path + ';' + tagOrId.id
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
2002-02-28 01:53:33 -05:00
|
|
|
self.path + ';' + tagOrId
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
2003-12-09 09:38:15 -05:00
|
|
|
|
|
|
|
private :__conf_cmd, :__item_pathname
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class TkText<TkTextWin
|
2003-08-02 01:04:30 -04:00
|
|
|
ItemConfCMD = ['tag'.freeze, 'configure'.freeze].freeze
|
1999-08-13 01:37:52 -04:00
|
|
|
include TkTreatTextTagFont
|
2000-01-17 03:37:53 -05:00
|
|
|
include Scrollable
|
1999-08-13 01:37:52 -04:00
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCommandNames = ['text'.freeze].freeze
|
1999-08-13 01:37:52 -04:00
|
|
|
WidgetClassName = 'Text'.freeze
|
1999-08-24 04:21:56 -04:00
|
|
|
WidgetClassNames[WidgetClassName] = self
|
2000-01-17 03:37:53 -05:00
|
|
|
|
2000-03-17 03:58:21 -05:00
|
|
|
def self.new(*args, &block)
|
2000-01-17 03:37:53 -05:00
|
|
|
obj = super(*args){}
|
|
|
|
obj.init_instance_variable
|
2002-03-08 02:03:09 -05:00
|
|
|
obj.instance_eval(&block) if defined? yield
|
2000-01-17 03:37:53 -05:00
|
|
|
obj
|
|
|
|
end
|
|
|
|
|
|
|
|
def init_instance_variable
|
2003-07-29 04:05:30 -04:00
|
|
|
@cmdtbl = []
|
2000-01-17 03:37:53 -05:00
|
|
|
@tags = {}
|
|
|
|
end
|
|
|
|
|
2003-06-25 01:49:10 -04:00
|
|
|
def __destroy_hook__
|
|
|
|
TTagID_TBL.delete(@path)
|
|
|
|
TMarkID_TBL.delete(@path)
|
|
|
|
end
|
|
|
|
|
2002-02-28 01:53:33 -05:00
|
|
|
def create_self(keys)
|
|
|
|
if keys and keys != None
|
|
|
|
tk_call 'text', @path, *hash_kv(keys)
|
|
|
|
else
|
|
|
|
tk_call 'text', @path
|
|
|
|
end
|
2000-01-17 03:37:53 -05:00
|
|
|
init_instance_variable
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-12-09 09:38:15 -05:00
|
|
|
private :create_self
|
2000-01-17 03:37:53 -05:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def index(index)
|
|
|
|
tk_send 'index', index
|
|
|
|
end
|
2000-01-17 03:37:53 -05:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def value
|
|
|
|
tk_send 'get', "1.0", "end - 1 char"
|
|
|
|
end
|
2000-01-17 03:37:53 -05:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def value= (val)
|
|
|
|
tk_send 'delete', "1.0", 'end'
|
|
|
|
tk_send 'insert', "1.0", val
|
|
|
|
end
|
2000-01-17 03:37:53 -05:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def _addcmd(cmd)
|
|
|
|
@cmdtbl.push cmd
|
|
|
|
end
|
2000-01-17 03:37:53 -05:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def _addtag(name, obj)
|
|
|
|
@tags[name] = obj
|
|
|
|
end
|
|
|
|
|
|
|
|
def tagid2obj(tagid)
|
2003-06-25 01:49:10 -04:00
|
|
|
if @tags[tagid]
|
1999-08-13 01:37:52 -04:00
|
|
|
@tags[tagid]
|
2003-06-25 01:49:10 -04:00
|
|
|
else
|
|
|
|
tagid
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def tag_names(index=None)
|
2003-06-18 15:46:20 -04:00
|
|
|
tk_split_simplelist(tk_send('tag', 'names', index)).collect{|elt|
|
1999-08-13 01:37:52 -04:00
|
|
|
tagid2obj(elt)
|
|
|
|
}
|
|
|
|
end
|
2000-01-17 03:37:53 -05:00
|
|
|
|
|
|
|
def mark_names
|
2003-06-18 15:46:20 -04:00
|
|
|
tk_split_simplelist(tk_send('mark', 'names')).collect{|elt|
|
2000-01-17 03:37:53 -05:00
|
|
|
tagid2obj(elt)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2003-06-25 01:49:10 -04:00
|
|
|
def mark_gravity(mark, direction=nil)
|
|
|
|
if direction
|
|
|
|
tk_send 'mark', 'gravity', mark, direction
|
|
|
|
self
|
|
|
|
else
|
|
|
|
tk_send 'mark', 'gravity', mark
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def mark_set(mark, index)
|
|
|
|
tk_send 'mark', 'set', mark, index
|
|
|
|
self
|
|
|
|
end
|
|
|
|
alias set_mark mark_set
|
|
|
|
|
|
|
|
def mark_unset(*marks)
|
|
|
|
tk_send 'mark', 'unset', *marks
|
|
|
|
self
|
|
|
|
end
|
|
|
|
alias unset_mark mark_unset
|
|
|
|
|
2001-03-27 02:10:58 -05:00
|
|
|
def mark_next(index)
|
|
|
|
tagid2obj(tk_send('mark', 'next', index))
|
|
|
|
end
|
2003-06-25 01:49:10 -04:00
|
|
|
alias next_mark mark_next
|
2001-03-27 02:10:58 -05:00
|
|
|
|
|
|
|
def mark_previous(index)
|
|
|
|
tagid2obj(tk_send('mark', 'previous', index))
|
|
|
|
end
|
2003-06-25 01:49:10 -04:00
|
|
|
alias previous_mark mark_previous
|
2001-03-27 02:10:58 -05:00
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
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
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2000-01-17 03:37:53 -05:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def image_names
|
2003-06-18 15:46:20 -04:00
|
|
|
tk_split_simplelist(tk_send('image', 'names')).collect{|elt|
|
1999-08-13 01:37:52 -04:00
|
|
|
tagid2obj(elt)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_insert(index)
|
|
|
|
tk_send 'mark', 'set', 'insert', index
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2000-01-17 03:37:53 -05:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def set_current(index)
|
|
|
|
tk_send 'mark', 'set', 'current', index
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def insert(index, chars, *tags)
|
2003-06-18 15:46:20 -04:00
|
|
|
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
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2000-01-17 03:37:53 -05:00
|
|
|
@tags = {} unless @tags
|
1999-08-13 01:37:52 -04:00
|
|
|
@tags.each_value do |t|
|
|
|
|
t.destroy
|
|
|
|
end
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def backspace
|
|
|
|
self.delete 'insert'
|
|
|
|
end
|
|
|
|
|
|
|
|
def compare(idx1, op, idx2)
|
|
|
|
bool(tk_send('compare', idx1, op, idx2))
|
|
|
|
end
|
|
|
|
|
|
|
|
def debug
|
|
|
|
bool(tk_send('debug'))
|
|
|
|
end
|
|
|
|
def debug=(boolean)
|
|
|
|
tk_send 'debug', boolean
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
def bbox(index)
|
2003-06-18 15:46:20 -04:00
|
|
|
list(tk_send('bbox', index))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def dlineinfo(index)
|
2003-06-18 15:46:20 -04:00
|
|
|
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
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def yview_pickplace(*what)
|
|
|
|
tk_send 'yview', '-pickplace', *what
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def xview_pickplace(*what)
|
|
|
|
tk_send 'xview', '-pickplace', *what
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2003-11-05 09:00:11 -05:00
|
|
|
def text_copy
|
|
|
|
# Tk8.4 feature
|
|
|
|
tk_call('tk_textCopy', @path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def text_cut
|
|
|
|
# Tk8.4 feature
|
|
|
|
tk_call('tk_textCut', @path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def text_paste
|
|
|
|
# Tk8.4 feature
|
|
|
|
tk_call('tk_textPaste', @path)
|
|
|
|
end
|
|
|
|
|
1999-08-24 04:21:56 -04:00
|
|
|
def tag_add(tag, index1, index2=None)
|
1999-08-13 01:37:52 -04:00
|
|
|
tk_send 'tag', 'add', tag, index1, index2
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
alias addtag tag_add
|
2003-06-25 01:49:10 -04:00
|
|
|
alias add_tag tag_add
|
2003-06-18 15:46:20 -04:00
|
|
|
|
|
|
|
def tag_delete(*tags)
|
|
|
|
tk_send 'tag', 'delete', *tags
|
2003-06-25 01:49:10 -04:00
|
|
|
if TkTextTag::TTagID_TBL[@path]
|
|
|
|
tags.each{|tag|
|
|
|
|
if tag.kind_of? TkTextTag
|
|
|
|
TTagID_TBL[@path].delete(tag.id)
|
|
|
|
else
|
|
|
|
TTagID_TBL[@path].delete(tag)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
|
|
|
end
|
|
|
|
alias deltag tag_delete
|
2003-06-25 01:49:10 -04:00
|
|
|
alias delete_tag tag_delete
|
1999-08-13 01:37:52 -04:00
|
|
|
|
2003-06-16 03:14:50 -04:00
|
|
|
def tag_bind(tag, seq, cmd=Proc.new, args=nil)
|
2003-06-18 15:46:20 -04:00
|
|
|
_bind([@path, 'tag', 'bind', tag], seq, cmd, args)
|
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2003-06-16 03:14:50 -04:00
|
|
|
def tag_bind_append(tag, seq, cmd=Proc.new, args=nil)
|
2003-06-18 15:46:20 -04:00
|
|
|
_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
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def tag_bindinfo(tag, context=nil)
|
2003-06-18 15:46:20 -04:00
|
|
|
_bindinfo([@path, 'tag', 'bind', tag], context)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def tag_cget(tag, key)
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
case key.to_s
|
2001-09-05 02:54:57 -04:00
|
|
|
when 'text', 'label', 'show', 'data', 'file'
|
2003-06-18 15:46:20 -04:00
|
|
|
tk_call(@path, 'tag', 'cget', tag, "-#{key}")
|
2003-08-29 04:34:14 -04:00
|
|
|
when 'font', 'kanjifont'
|
2003-09-02 01:04:30 -04:00
|
|
|
#fnt = tk_tcl2ruby(tk_send('tag', 'cget', tag, "-#{key}"))
|
|
|
|
fnt = tk_tcl2ruby(tk_send('tag', 'cget', tag, '-font'))
|
2003-08-29 04:34:14 -04:00
|
|
|
unless fnt.kind_of?(TkFont)
|
|
|
|
fnt = tagfontobj(tag, fnt)
|
|
|
|
end
|
2003-09-02 01:04:30 -04:00
|
|
|
if key.to_s == 'kanjifont' && JAPANIZED_TK && TK_VERSION =~ /^4\.*/
|
|
|
|
# obsolete; just for compatibility
|
|
|
|
fnt.kanji_font
|
|
|
|
else
|
|
|
|
fnt
|
|
|
|
end
|
2000-11-27 04:23:38 -05:00
|
|
|
else
|
2003-06-18 15:46:20 -04:00
|
|
|
tk_tcl2ruby(tk_call(@path, 'tag', 'cget', tag, "-#{key}"))
|
2000-11-27 04:23:38 -05:00
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def tag_configure(tag, key, val=None)
|
|
|
|
if key.kind_of? Hash
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
key = _symbolkey2str(key)
|
1999-08-13 01:37:52 -04:00
|
|
|
if ( key['font'] || key['kanjifont'] \
|
|
|
|
|| key['latinfont'] || key['asciifont'] )
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
tagfont_configure(tag, key)
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
|
|
|
tk_send 'tag', 'configure', tag, *hash_kv(key)
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
if key == 'font' || key == :font ||
|
|
|
|
key == 'kanjifont' || key == :kanjifont ||
|
|
|
|
key == 'latinfont' || key == :latinfont ||
|
|
|
|
key == 'asciifont' || key == :asciifont
|
2003-09-02 01:04:30 -04:00
|
|
|
if val == None
|
|
|
|
tagfontobj(tag)
|
|
|
|
else
|
|
|
|
tagfont_configure(tag, {key=>val})
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
|
|
|
tk_send 'tag', 'configure', tag, "-#{key}", val
|
|
|
|
end
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def tag_configinfo(tag, key=nil)
|
|
|
|
if key
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
case key.to_s
|
2001-09-05 02:54:57 -04:00
|
|
|
when 'text', 'label', 'show', 'data', 'file'
|
2000-11-27 04:23:38 -05:00
|
|
|
conf = tk_split_simplelist(tk_send('tag','configure',tag,"-#{key}"))
|
2003-08-29 04:34:14 -04:00
|
|
|
when 'font', 'kanjifont'
|
|
|
|
conf = tk_split_simplelist(tk_send('tag','configure',tag,"-#{key}") )
|
|
|
|
conf[4] = tagfont_configinfo(tag, conf[4])
|
2000-11-27 04:23:38 -05:00
|
|
|
else
|
|
|
|
conf = tk_split_list(tk_send('tag','configure',tag,"-#{key}"))
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
conf[0] = conf[0][1..-1]
|
|
|
|
conf
|
|
|
|
else
|
2003-08-29 04:34:14 -04:00
|
|
|
ret = tk_split_simplelist(tk_send('tag', 'configure',
|
|
|
|
tag)).collect{|conflist|
|
2000-11-27 04:23:38 -05:00
|
|
|
conf = tk_split_simplelist(conflist)
|
1999-08-13 01:37:52 -04:00
|
|
|
conf[0] = conf[0][1..-1]
|
2000-11-27 04:23:38 -05:00
|
|
|
case conf[0]
|
2001-09-05 02:54:57 -04:00
|
|
|
when 'text', 'label', 'show', 'data', 'file'
|
2000-11-27 04:23:38 -05:00
|
|
|
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
|
1999-08-13 01:37:52 -04:00
|
|
|
conf
|
|
|
|
}
|
2003-08-29 04:34:14 -04:00
|
|
|
fontconf = ret.assoc('font')
|
|
|
|
if fontconf
|
|
|
|
ret.delete_if{|item| item[0] == 'font' || item[0] == 'kanjifont'}
|
|
|
|
fontconf[4] = tagfont_configinfo(tag, fontconf[4])
|
|
|
|
ret.push(fontconf)
|
|
|
|
else
|
|
|
|
ret
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def tag_raise(tag, above=None)
|
|
|
|
tk_send 'tag', 'raise', tag, above
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def tag_lower(tag, below=None)
|
|
|
|
tk_send 'tag', 'lower', tag, below
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def tag_remove(tag, *index)
|
|
|
|
tk_send 'tag', 'remove', tag, *index
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def tag_ranges(tag)
|
|
|
|
l = tk_split_simplelist(tk_send('tag', 'ranges', tag))
|
|
|
|
r = []
|
|
|
|
while key=l.shift
|
|
|
|
r.push [key, l.shift]
|
|
|
|
end
|
|
|
|
r
|
|
|
|
end
|
|
|
|
|
|
|
|
def tag_nextrange(tag, first, last=None)
|
2003-06-18 15:46:20 -04:00
|
|
|
tk_split_list(tk_send('tag', 'nextrange', tag, first, last))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def tag_prevrange(tag, first, last=None)
|
2003-06-18 15:46:20 -04:00
|
|
|
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}")
|
2003-08-29 04:34:14 -04:00
|
|
|
when 'font', 'kanjifont'
|
2003-09-02 01:04:30 -04:00
|
|
|
#fnt = tk_tcl2ruby(tk_send('window', 'cget', index, "-#{slot}"))
|
|
|
|
fnt = tk_tcl2ruby(tk_send('window', 'cget', index, '-font'))
|
2003-08-29 04:34:14 -04:00
|
|
|
unless fnt.kind_of?(TkFont)
|
|
|
|
fnt = tagfontobj(index, fnt)
|
|
|
|
end
|
2003-09-02 01:04:30 -04:00
|
|
|
if slot.to_s == 'kanjifont' && JAPANIZED_TK && TK_VERSION =~ /^4\.*/
|
|
|
|
# obsolete; just for compatibility
|
|
|
|
fnt.kanji_font
|
|
|
|
else
|
|
|
|
fnt
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
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
|
2004-01-07 00:28:53 -05:00
|
|
|
slot = _symbolkey2str(slot)
|
|
|
|
win = slot['window']
|
|
|
|
slot['window'] = win.epath if win.kind_of?(TkWindow)
|
|
|
|
if slot['create']
|
|
|
|
p_create = slot['create']
|
|
|
|
if p_create.kind_of? Proc
|
|
|
|
slot['create'] = install_cmd(proc{
|
|
|
|
id = p_create.call
|
|
|
|
if id.kind_of?(TkWindow)
|
|
|
|
id.epath
|
|
|
|
else
|
|
|
|
id
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
tk_send('window', 'configure', index, *hash_kv(slot))
|
|
|
|
else
|
2004-01-07 00:28:53 -05:00
|
|
|
if slot == 'window' || slot == :window
|
|
|
|
id = value
|
|
|
|
value = id.epath if id.kind_of?(TkWindow)
|
|
|
|
end
|
|
|
|
if slot == 'create' || slot == :create
|
|
|
|
p_create = value
|
|
|
|
if p_create.kind_of? Proc
|
|
|
|
value = install_cmd(proc{
|
|
|
|
id = p_create.call
|
|
|
|
if id.kind_of?(TkWindow)
|
|
|
|
id.epath
|
|
|
|
else
|
|
|
|
id
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
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)
|
|
|
|
}
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2000-08-02 00:54:21 -04:00
|
|
|
def _ktext_length(txt)
|
|
|
|
if $KCODE !~ /n/i
|
|
|
|
return txt.gsub(/[^\Wa-zA-Z_\d]/, ' ').length
|
|
|
|
end
|
|
|
|
|
|
|
|
# $KCODE == 'NONE'
|
|
|
|
if JAPANIZED_TK
|
|
|
|
tk_call('kstring', 'length', txt).to_i
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
tk_call('encoding', 'convertto', 'ascii', txt).length
|
|
|
|
rescue StandardError, NameError
|
|
|
|
# sorry, I have no plan
|
|
|
|
txt.length
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
private :_ktext_length
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def search_with_length(pat,start,stop=None)
|
2000-08-02 00:54:21 -04:00
|
|
|
pat = pat.chr if pat.kind_of? Integer
|
1999-08-13 01:37:52 -04:00
|
|
|
if stop != None
|
|
|
|
return ["", 0] if compare(start,'>=',stop)
|
|
|
|
txt = get(start,stop)
|
|
|
|
if (pos = txt.index(pat))
|
2000-08-02 00:54:21 -04:00
|
|
|
match = $&
|
|
|
|
#pos = txt[0..(pos-1)].split('').length if pos > 0
|
|
|
|
pos = _ktext_length(txt[0..(pos-1)]) if pos > 0
|
1999-08-13 01:37:52 -04:00
|
|
|
if pat.kind_of? String
|
2000-08-02 00:54:21 -04:00
|
|
|
#return [index(start + " + #{pos} chars"), pat.split('').length]
|
|
|
|
return [index(start + " + #{pos} chars"),
|
|
|
|
_ktext_length(pat), pat.dup]
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
2000-08-02 00:54:21 -04:00
|
|
|
#return [index(start + " + #{pos} chars"), $&.split('').length]
|
|
|
|
return [index(start + " + #{pos} chars"),
|
|
|
|
_ktext_length(match), match]
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
else
|
|
|
|
return ["", 0]
|
|
|
|
end
|
|
|
|
else
|
|
|
|
txt = get(start,'end - 1 char')
|
|
|
|
if (pos = txt.index(pat))
|
2000-08-02 00:54:21 -04:00
|
|
|
match = $&
|
|
|
|
#pos = txt[0..(pos-1)].split('').length if pos > 0
|
|
|
|
pos = _ktext_length(txt[0..(pos-1)]) if pos > 0
|
1999-08-13 01:37:52 -04:00
|
|
|
if pat.kind_of? String
|
2000-08-02 00:54:21 -04:00
|
|
|
#return [index(start + " + #{pos} chars"), pat.split('').length]
|
|
|
|
return [index(start + " + #{pos} chars"),
|
|
|
|
_ktext_length(pat), pat.dup]
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
2000-08-02 00:54:21 -04:00
|
|
|
#return [index(start + " + #{pos} chars"), $&.split('').length]
|
|
|
|
return [index(start + " + #{pos} chars"),
|
|
|
|
_ktext_length(match), match]
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
else
|
|
|
|
txt = get('1.0','end - 1 char')
|
|
|
|
if (pos = txt.index(pat))
|
2000-08-02 00:54:21 -04:00
|
|
|
match = $&
|
|
|
|
#pos = txt[0..(pos-1)].split('').length if pos > 0
|
|
|
|
pos = _ktext_length(txt[0..(pos-1)]) if pos > 0
|
1999-08-13 01:37:52 -04:00
|
|
|
if pat.kind_of? String
|
2000-08-02 00:54:21 -04:00
|
|
|
#return [index("1.0 + #{pos} chars"), pat.split('').length]
|
|
|
|
return [index("1.0 + #{pos} chars"),
|
|
|
|
_ktext_length(pat), pat.dup]
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
2000-08-02 00:54:21 -04:00
|
|
|
#return [index("1.0 + #{pos} chars"), $&.split('').length]
|
|
|
|
return [index("1.0 + #{pos} chars"), _ktext_length(match), match]
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
else
|
|
|
|
return ["", 0]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def search(pat,start,stop=None)
|
|
|
|
search_with_length(pat,start,stop)[0]
|
|
|
|
end
|
|
|
|
|
|
|
|
def rsearch_with_length(pat,start,stop=None)
|
2000-08-02 00:54:21 -04:00
|
|
|
pat = pat.chr if pat.kind_of? Integer
|
1999-08-13 01:37:52 -04:00
|
|
|
if stop != None
|
|
|
|
return ["", 0] if compare(start,'<=',stop)
|
|
|
|
txt = get(stop,start)
|
|
|
|
if (pos = txt.rindex(pat))
|
2000-08-02 00:54:21 -04:00
|
|
|
match = $&
|
|
|
|
#pos = txt[0..(pos-1)].split('').length if pos > 0
|
|
|
|
pos = _ktext_length(txt[0..(pos-1)]) if pos > 0
|
1999-08-13 01:37:52 -04:00
|
|
|
if pat.kind_of? String
|
2000-08-02 00:54:21 -04:00
|
|
|
#return [index(stop + " + #{pos} chars"), pat.split('').length]
|
|
|
|
return [index(stop + " + #{pos} chars"), _ktext_length(pat), pat.dup]
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
2000-08-02 00:54:21 -04:00
|
|
|
#return [index(stop + " + #{pos} chars"), $&.split('').length]
|
|
|
|
return [index(stop + " + #{pos} chars"), _ktext_length(match), match]
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
else
|
|
|
|
return ["", 0]
|
|
|
|
end
|
|
|
|
else
|
|
|
|
txt = get('1.0',start)
|
|
|
|
if (pos = txt.rindex(pat))
|
2000-08-02 00:54:21 -04:00
|
|
|
match = $&
|
|
|
|
#pos = txt[0..(pos-1)].split('').length if pos > 0
|
|
|
|
pos = _ktext_length(txt[0..(pos-1)]) if pos > 0
|
1999-08-13 01:37:52 -04:00
|
|
|
if pat.kind_of? String
|
2000-08-02 00:54:21 -04:00
|
|
|
#return [index("1.0 + #{pos} chars"), pat.split('').length]
|
|
|
|
return [index("1.0 + #{pos} chars"), _ktext_length(pat), pat.dup]
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
2000-08-02 00:54:21 -04:00
|
|
|
#return [index("1.0 + #{pos} chars"), $&.split('').length]
|
|
|
|
return [index("1.0 + #{pos} chars"), _ktext_length(match), match]
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
else
|
|
|
|
txt = get('1.0','end - 1 char')
|
|
|
|
if (pos = txt.rindex(pat))
|
2000-08-02 00:54:21 -04:00
|
|
|
match = $&
|
|
|
|
#pos = txt[0..(pos-1)].split('').length if pos > 0
|
|
|
|
pos = _ktext_length(txt[0..(pos-1)]) if pos > 0
|
1999-08-13 01:37:52 -04:00
|
|
|
if pat.kind_of? String
|
2000-08-02 00:54:21 -04:00
|
|
|
#return [index("1.0 + #{pos} chars"), pat.split('').length]
|
|
|
|
return [index("1.0 + #{pos} chars"), _ktext_length(pat), pat.dup]
|
1999-08-13 01:37:52 -04:00
|
|
|
else
|
2000-08-02 00:54:21 -04:00
|
|
|
#return [index("1.0 + #{pos} chars"), $&.split('').length]
|
|
|
|
return [index("1.0 + #{pos} chars"), _ktext_length(match), match]
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
else
|
|
|
|
return ["", 0]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def rsearch(pat,start,stop=None)
|
|
|
|
rsearch_with_length(pat,start,stop)[0]
|
|
|
|
end
|
2000-04-10 01:48:43 -04:00
|
|
|
|
2000-05-01 05:42:38 -04:00
|
|
|
def dump(type_info, *index, &block)
|
|
|
|
args = type_info.collect{|inf| '-' + inf}
|
2003-06-03 05:40:21 -04:00
|
|
|
args << '-command' << block if block
|
2000-04-10 01:57:37 -04:00
|
|
|
str = tk_send('dump', *(args + index))
|
2000-04-10 01:48:43 -04:00
|
|
|
result = []
|
|
|
|
sel = nil
|
|
|
|
i = 0
|
|
|
|
while i < str.size
|
|
|
|
# retrieve key
|
|
|
|
idx = str.index(/ /, i)
|
|
|
|
result.push str[i..(idx-1)]
|
|
|
|
i = idx + 1
|
|
|
|
|
|
|
|
# retrieve value
|
|
|
|
case result[-1]
|
|
|
|
when 'text'
|
|
|
|
if str[i] == ?{
|
|
|
|
# text formed as {...}
|
|
|
|
val, i = _retrieve_braced_text(str, i)
|
|
|
|
result.push val
|
|
|
|
else
|
|
|
|
# text which may contain backslahes
|
|
|
|
val, i = _retrieve_backslashed_text(str, i)
|
|
|
|
result.push val
|
|
|
|
end
|
|
|
|
else
|
|
|
|
idx = str.index(/ /, i)
|
|
|
|
val = str[i..(idx-1)]
|
|
|
|
case result[-1]
|
|
|
|
when 'mark'
|
|
|
|
case val
|
|
|
|
when 'insert'
|
|
|
|
result.push TkTextMarkInsert.new(self)
|
|
|
|
when 'current'
|
|
|
|
result.push TkTextMarkCurrent.new(self)
|
|
|
|
when 'anchor'
|
|
|
|
result.push TkTextMarkAnchor.new(self)
|
|
|
|
else
|
2000-08-01 05:25:37 -04:00
|
|
|
result.push tk_tcl2ruby(val)
|
2000-04-10 01:48:43 -04:00
|
|
|
end
|
|
|
|
when 'tagon'
|
|
|
|
if val == 'sel'
|
|
|
|
if sel
|
|
|
|
result.push sel
|
|
|
|
else
|
|
|
|
result.push TkTextTagSel.new(self)
|
|
|
|
end
|
|
|
|
else
|
2000-08-01 05:25:37 -04:00
|
|
|
result.push tk_tcl2ruby(val)
|
2000-04-10 01:48:43 -04:00
|
|
|
end
|
|
|
|
when 'tagoff'
|
2003-06-18 15:46:20 -04:00
|
|
|
result.push tk_tcl2ruby(val)
|
2000-04-10 01:48:43 -04:00
|
|
|
when 'window'
|
2000-08-01 05:25:37 -04:00
|
|
|
result.push tk_tcl2ruby(val)
|
2000-04-10 01:48:43 -04:00
|
|
|
end
|
|
|
|
i = idx + 1
|
|
|
|
end
|
|
|
|
|
|
|
|
# retrieve index
|
|
|
|
idx = str.index(/ /, i)
|
|
|
|
if idx
|
|
|
|
result.push str[i..(idx-1)]
|
|
|
|
i = idx + 1
|
|
|
|
else
|
|
|
|
result.push str[i..-1]
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
kvis = []
|
|
|
|
until result.empty?
|
|
|
|
kvis.push [result.shift, result.shift, result.shift]
|
|
|
|
end
|
|
|
|
kvis # result is [[key1, value1, index1], [key2, value2, index2], ...]
|
|
|
|
end
|
2000-04-10 01:57:37 -04:00
|
|
|
|
|
|
|
def _retrieve_braced_text(str, i)
|
|
|
|
cnt = 0
|
|
|
|
idx = i
|
|
|
|
while idx < str.size
|
|
|
|
case str[idx]
|
|
|
|
when ?{
|
|
|
|
cnt += 1
|
|
|
|
when ?}
|
|
|
|
cnt -= 1
|
|
|
|
if cnt == 0
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
idx += 1
|
|
|
|
end
|
|
|
|
return str[i+1..idx-1], idx + 2
|
|
|
|
end
|
|
|
|
private :_retrieve_braced_text
|
|
|
|
|
|
|
|
def _retrieve_backslashed_text(str, i)
|
|
|
|
j = i
|
|
|
|
idx = nil
|
|
|
|
loop {
|
|
|
|
idx = str.index(/ /, j)
|
|
|
|
if str[idx-1] == ?\\
|
|
|
|
j += 1
|
|
|
|
else
|
|
|
|
break
|
|
|
|
end
|
|
|
|
}
|
|
|
|
val = str[i..(idx-1)]
|
|
|
|
val.gsub!(/\\( |\{|\})/, '\1')
|
|
|
|
return val, idx + 1
|
|
|
|
end
|
|
|
|
private :_retrieve_backslashed_text
|
2000-04-10 01:48:43 -04:00
|
|
|
|
2000-05-01 05:42:38 -04:00
|
|
|
def dump_all(*index, &block)
|
|
|
|
dump(['all'], *index, &block)
|
2000-04-10 01:57:37 -04:00
|
|
|
end
|
2000-05-01 05:42:38 -04:00
|
|
|
def dump_mark(*index, &block)
|
|
|
|
dump(['mark'], *index, &block)
|
2000-04-10 01:48:43 -04:00
|
|
|
end
|
2000-05-01 05:42:38 -04:00
|
|
|
def dump_tag(*index, &block)
|
|
|
|
dump(['tag'], *index, &block)
|
2000-04-10 01:48:43 -04:00
|
|
|
end
|
2000-05-01 05:42:38 -04:00
|
|
|
def dump_text(*index, &block)
|
|
|
|
dump(['text'], *index, &block)
|
2000-04-10 01:48:43 -04:00
|
|
|
end
|
2000-05-01 05:42:38 -04:00
|
|
|
def dump_window(*index, &block)
|
|
|
|
dump(['window'], *index, &block)
|
2000-04-10 01:48:43 -04:00
|
|
|
end
|
2000-05-01 05:42:38 -04:00
|
|
|
def dump_image(*index, &block)
|
|
|
|
dump(['image'], *index, &block)
|
2000-04-10 01:48:43 -04:00
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class TkTextTag<TkObject
|
|
|
|
include TkTreatTagFont
|
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
TTagID_TBL = TkCore::INTERP.create_table
|
2003-09-07 03:10:44 -04:00
|
|
|
Tk_TextTag_ID = ['tag'.freeze, '00000'.taint].freeze
|
2000-01-17 03:37:53 -05:00
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCore::INTERP.init_ip_env{ TTagID_TBL.clear }
|
2003-06-18 15:46:20 -04:00
|
|
|
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
def TkTextTag.id2obj(text, id)
|
|
|
|
tpath = text.path
|
|
|
|
return id unless TTagID_TBL[tpath]
|
|
|
|
TTagID_TBL[tpath][id]? TTagID_TBL[tpath][id]: id
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def initialize(parent, *args)
|
|
|
|
if not parent.kind_of?(TkText)
|
2003-12-02 23:55:07 -05:00
|
|
|
fail Kernel.format("%s need to be TkText", parent.inspect)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
@parent = @t = parent
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
@tpath = parent.path
|
2003-07-23 12:07:35 -04:00
|
|
|
@path = @id = Tk_TextTag_ID.join
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
TTagID_TBL[@id] = self
|
|
|
|
TTagID_TBL[@tpath] = {} unless TTagID_TBL[@tpath]
|
|
|
|
TTagID_TBL[@tpath][@id] = self
|
2003-07-23 12:07:35 -04:00
|
|
|
Tk_TextTag_ID[1].succ!
|
1999-08-13 01:37:52 -04:00
|
|
|
#tk_call @t.path, "tag", "configure", @id, *hash_kv(keys)
|
|
|
|
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
|
|
|
|
|
|
|
|
def id
|
2003-06-18 15:46:20 -04:00
|
|
|
@id
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def first
|
|
|
|
@id + '.first'
|
|
|
|
end
|
|
|
|
|
|
|
|
def last
|
|
|
|
@id + '.last'
|
|
|
|
end
|
|
|
|
|
|
|
|
def add(*index)
|
|
|
|
tk_call @t.path, 'tag', 'add', @id, *index
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def remove(*index)
|
|
|
|
tk_call @t.path, 'tag', 'remove', @id, *index
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def ranges
|
|
|
|
l = tk_split_simplelist(tk_call(@t.path, 'tag', 'ranges', @id))
|
|
|
|
r = []
|
|
|
|
while key=l.shift
|
|
|
|
r.push [key, l.shift]
|
|
|
|
end
|
|
|
|
r
|
|
|
|
end
|
|
|
|
|
|
|
|
def nextrange(first, last=None)
|
2003-06-18 15:46:20 -04:00
|
|
|
tk_split_list(tk_call(@t.path, 'tag', 'nextrange', @id, first, last))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def prevrange(first, last=None)
|
2003-06-18 15:46:20 -04:00
|
|
|
tk_split_list(tk_call(@t.path, 'tag', 'prevrange', @id, first, last))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def [](key)
|
|
|
|
cget key
|
|
|
|
end
|
|
|
|
|
|
|
|
def []=(key,val)
|
|
|
|
configure key, val
|
|
|
|
end
|
|
|
|
|
|
|
|
def cget(key)
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
case key.to_s
|
2001-09-05 02:54:57 -04:00
|
|
|
when 'text', 'label', 'show', 'data', 'file'
|
2000-11-27 04:23:38 -05:00
|
|
|
tk_call @t.path, 'tag', 'cget', @id, "-#{key}"
|
2003-08-29 04:34:14 -04:00
|
|
|
when 'font', 'kanjifont'
|
2003-09-02 01:04:30 -04:00
|
|
|
#fnt = tk_tcl2ruby(tk_call(@t.path, 'tag', 'cget', @id, "-#{key}"))
|
|
|
|
fnt = tk_tcl2ruby(tk_call(@t.path, 'tag', 'cget', @id, '-font'))
|
2003-08-29 04:34:14 -04:00
|
|
|
unless fnt.kind_of?(TkFont)
|
|
|
|
fnt = tagfontobj(@id, fnt)
|
|
|
|
end
|
2003-09-02 01:04:30 -04:00
|
|
|
if key.to_s == 'kanjifont' && JAPANIZED_TK && TK_VERSION =~ /^4\.*/
|
|
|
|
# obsolete; just for compatibility
|
|
|
|
fnt.kanji_font
|
|
|
|
else
|
|
|
|
fnt
|
|
|
|
end
|
2000-11-27 04:23:38 -05:00
|
|
|
else
|
2003-08-29 04:34:14 -04:00
|
|
|
tk_tcl2ruby(tk_call(@t.path, 'tag', 'cget', @id, "-#{key}"))
|
2000-11-27 04:23:38 -05:00
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def configure(key, val=None)
|
|
|
|
@t.tag_configure @id, key, val
|
|
|
|
end
|
|
|
|
# def configure(key, val=None)
|
|
|
|
# if key.kind_of? Hash
|
|
|
|
# tk_call @t.path, 'tag', 'configure', @id, *hash_kv(key)
|
|
|
|
# else
|
|
|
|
# tk_call @t.path, 'tag', 'configure', @id, "-#{key}", val
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# def configure(key, value)
|
|
|
|
# if value == FALSE
|
|
|
|
# value = "0"
|
|
|
|
# elsif value.kind_of? Proc
|
|
|
|
# value = install_cmd(value)
|
|
|
|
# end
|
|
|
|
# tk_call @t.path, 'tag', 'configure', @id, "-#{key}", value
|
|
|
|
# end
|
|
|
|
|
|
|
|
def configinfo(key=nil)
|
|
|
|
@t.tag_configinfo @id, key
|
|
|
|
end
|
|
|
|
|
2003-06-16 03:14:50 -04:00
|
|
|
def bind(seq, cmd=Proc.new, args=nil)
|
1999-08-24 04:21:56 -04:00
|
|
|
_bind([@t.path, 'tag', 'bind', @id], seq, cmd, args)
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-24 04:21:56 -04:00
|
|
|
end
|
|
|
|
|
2003-06-16 03:14:50 -04:00
|
|
|
def bind_append(seq, cmd=Proc.new, args=nil)
|
1999-08-24 04:21:56 -04:00
|
|
|
_bind_append([@t.path, 'tag', 'bind', @id], seq, cmd, args)
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def bind_remove(seq)
|
|
|
|
_bind_remove([@t.path, 'tag', 'bind', @id], seq)
|
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def bindinfo(context=nil)
|
1999-08-24 04:21:56 -04:00
|
|
|
_bindinfo([@t.path, 'tag', 'bind', @id], context)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def raise(above=None)
|
|
|
|
tk_call @t.path, 'tag', 'raise', @id, above
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def lower(below=None)
|
|
|
|
tk_call @t.path, 'tag', 'lower', @id, below
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
tk_call @t.path, 'tag', 'delete', @id
|
2003-06-25 01:49:10 -04:00
|
|
|
TTagID_TBL[@tpath].delete(@id) if TTagID_TBL[@tpath]
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TkTextNamedTag<TkTextTag
|
|
|
|
def self.new(parent, name, *args)
|
|
|
|
if TTagID_TBL[parent.path] && TTagID_TBL[parent.path][name]
|
2003-06-25 01:49:10 -04:00
|
|
|
tagobj = TTagID_TBL[parent.path][name]
|
|
|
|
if args != [] then
|
|
|
|
keys = args.pop
|
|
|
|
if keys.kind_of? Hash then
|
|
|
|
tagobj.add(*args) if args != []
|
|
|
|
tagobj.configure(keys)
|
|
|
|
else
|
|
|
|
args.push keys
|
|
|
|
tagobj.add(*args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return tagobj
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
else
|
|
|
|
super(parent, name, *args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(parent, name, *args)
|
|
|
|
if not parent.kind_of?(TkText)
|
2003-12-02 23:55:07 -05:00
|
|
|
fail Kernel.format("%s need to be TkText", parent.inspect)
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
end
|
2003-06-25 01:49:10 -04:00
|
|
|
@parent = @t = parent
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
@tpath = parent.path
|
|
|
|
@path = @id = name
|
|
|
|
TTagID_TBL[@tpath] = {} unless TTagID_TBL[@tpath]
|
2003-06-25 01:49:10 -04:00
|
|
|
TTagID_TBL[@tpath][@id] = self unless TTagID_TBL[@tpath][@id]
|
2003-06-18 15:46:20 -04:00
|
|
|
#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
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
@t._addtag id, self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-06-25 01:49:10 -04:00
|
|
|
class TkTextTagSel<TkTextNamedTag
|
|
|
|
def self.new(parent, *args)
|
|
|
|
super(parent, 'sel', *args)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TkTextMark<TkObject
|
2003-07-23 12:07:35 -04:00
|
|
|
TMarkID_TBL = TkCore::INTERP.create_table
|
2003-09-07 03:10:44 -04:00
|
|
|
Tk_TextMark_ID = ['mark'.freeze, '00000'.taint].freeze
|
2003-06-25 01:49:10 -04:00
|
|
|
|
2003-07-23 12:07:35 -04:00
|
|
|
TkCore::INTERP.init_ip_env{ TMarkID_TBL.clear }
|
2003-06-25 01:49:10 -04:00
|
|
|
|
|
|
|
def TkTextMark.id2obj(text, id)
|
|
|
|
tpath = text.path
|
|
|
|
return id unless TMarkID_TBL[tpath]
|
|
|
|
TMarkID_TBL[tpath][id]? TMarkID_TBL[tpath][id]: id
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def initialize(parent, index)
|
|
|
|
if not parent.kind_of?(TkText)
|
2003-12-02 23:55:07 -05:00
|
|
|
fail Kernel.format("%s need to be TkText", parent.inspect)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-25 01:49:10 -04:00
|
|
|
@parent = @t = parent
|
|
|
|
@tpath = parent.path
|
2003-07-23 12:07:35 -04:00
|
|
|
@path = @id = Tk_TextMark_ID.join
|
2003-06-25 01:49:10 -04:00
|
|
|
TMarkID_TBL[@id] = self
|
|
|
|
TMarkID_TBL[@tpath] = {} unless TMarkID_TBL[@tpath]
|
|
|
|
TMarkID_TBL[@tpath][@id] = self
|
2003-08-03 04:53:06 -04:00
|
|
|
Tk_TextMark_ID[1].succ!
|
1999-08-13 01:37:52 -04:00
|
|
|
tk_call @t.path, 'mark', 'set', @id, index
|
|
|
|
@t._addtag id, self
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def id
|
2003-06-18 15:46:20 -04:00
|
|
|
@id
|
|
|
|
end
|
|
|
|
|
|
|
|
def +(mod)
|
|
|
|
@id + ' + ' + mod
|
|
|
|
end
|
|
|
|
def -(mod)
|
|
|
|
@id + ' - ' + mod
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def set(where)
|
|
|
|
tk_call @t.path, 'mark', 'set', @id, where
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def unset
|
|
|
|
tk_call @t.path, 'mark', 'unset', @id
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
alias destroy unset
|
|
|
|
|
|
|
|
def gravity
|
|
|
|
tk_call @t.path, 'mark', 'gravity', @id
|
|
|
|
end
|
|
|
|
|
|
|
|
def gravity=(direction)
|
|
|
|
tk_call @t.path, 'mark', 'gravity', @id, direction
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2000-01-17 03:37:53 -05:00
|
|
|
|
2002-01-28 03:44:45 -05:00
|
|
|
def next(index = nil)
|
|
|
|
if index
|
|
|
|
@t.tagid2obj(tk_call(@t.path, 'mark', 'next', index))
|
|
|
|
else
|
|
|
|
@t.tagid2obj(tk_call(@t.path, 'mark', 'next', @id))
|
|
|
|
end
|
2000-01-17 03:37:53 -05:00
|
|
|
end
|
|
|
|
|
2002-01-28 03:44:45 -05:00
|
|
|
def previous(index = nil)
|
|
|
|
if index
|
|
|
|
@t.tagid2obj(tk_call(@t.path, 'mark', 'previous', index))
|
|
|
|
else
|
|
|
|
@t.tagid2obj(tk_call(@t.path, 'mark', 'previous', @id))
|
|
|
|
end
|
2000-01-17 03:37:53 -05:00
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
2003-06-25 01:49:10 -04:00
|
|
|
class TkTextNamedMark<TkTextMark
|
|
|
|
def self.new(parent, name, *args)
|
|
|
|
if TMarkID_TBL[parent.path] && TMarkID_TBL[parent.path][name]
|
|
|
|
return TMarkID_TBL[parent.path][name]
|
|
|
|
else
|
|
|
|
super(parent, name, *args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(parent, name, index=nil)
|
1999-08-13 01:37:52 -04:00
|
|
|
if not parent.kind_of?(TkText)
|
2003-12-02 23:55:07 -05:00
|
|
|
fail Kernel.format("%s need to be TkText", parent.inspect)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
2003-06-25 01:49:10 -04:00
|
|
|
@parent = @t = parent
|
|
|
|
@tpath = parent.path
|
|
|
|
@path = @id = name
|
|
|
|
TMarkID_TBL[@id] = self
|
|
|
|
TMarkID_TBL[@tpath] = {} unless TMarkID_TBL[@tpath]
|
|
|
|
TMarkID_TBL[@tpath][@id] = self unless TMarkID_TBL[@tpath][@id]
|
1999-08-13 01:37:52 -04:00
|
|
|
tk_call @t.path, 'mark', 'set', @id, index if index
|
|
|
|
@t._addtag id, self
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-06-25 01:49:10 -04:00
|
|
|
class TkTextMarkInsert<TkTextNamedMark
|
|
|
|
def self.new(parent,*args)
|
|
|
|
super(parent, 'insert', *args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
class TkTextMarkCurrent<TkTextMark
|
2003-06-25 01:49:10 -04:00
|
|
|
def self.new(parent,*args)
|
|
|
|
super(parent, 'current', *args)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TkTextMarkAnchor<TkTextMark
|
2003-06-25 01:49:10 -04:00
|
|
|
def self.new(parent,*args)
|
|
|
|
super(parent, 'anchor', *args)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TkTextWindow<TkObject
|
|
|
|
def initialize(parent, index, keys)
|
|
|
|
if not parent.kind_of?(TkText)
|
2003-12-02 23:55:07 -05:00
|
|
|
fail Kernel.format("%s need to be TkText", parent.inspect)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
@t = parent
|
|
|
|
if index == 'end'
|
|
|
|
@path = TkTextMark.new(@t, tk_call(@t.path, 'index', 'end - 1 chars'))
|
|
|
|
elsif index.kind_of? TkTextMark
|
|
|
|
if tk_call(@t.path,'index',index.path) == tk_call(@t.path,'index','end')
|
|
|
|
@path = TkTextMark.new(@t, tk_call(@t.path, 'index', 'end - 1 chars'))
|
|
|
|
else
|
|
|
|
@path = TkTextMark.new(@t, tk_call(@t.path, 'index', index.path))
|
|
|
|
end
|
|
|
|
else
|
|
|
|
@path = TkTextMark.new(@t, tk_call(@t.path, 'index', index))
|
|
|
|
end
|
|
|
|
@path.gravity = 'left'
|
|
|
|
@index = @path.path
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
keys = _symbolkey2str(keys)
|
1999-08-13 01:37:52 -04:00
|
|
|
@id = keys['window']
|
2004-01-07 00:28:53 -05:00
|
|
|
keys['window'] = @id.epath if @id.kind_of?(TkWindow)
|
1999-08-13 01:37:52 -04:00
|
|
|
if keys['create']
|
|
|
|
@p_create = keys['create']
|
|
|
|
if @p_create.kind_of? Proc
|
2004-01-07 00:28:53 -05:00
|
|
|
keys['create'] = install_cmd(proc{
|
|
|
|
@id = @p_create.call
|
|
|
|
if @id.kind_of?(TkWindow)
|
|
|
|
@id.epath
|
|
|
|
else
|
|
|
|
@id
|
|
|
|
end
|
|
|
|
})
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
tk_call @t.path, 'window', 'create', @index, *hash_kv(keys)
|
|
|
|
end
|
|
|
|
|
|
|
|
def [](slot)
|
|
|
|
cget(slot)
|
|
|
|
end
|
|
|
|
def []=(slot, value)
|
|
|
|
configure(slot, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
def cget(slot)
|
2003-06-18 15:46:20 -04:00
|
|
|
@t.window_cget(@index, slot)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def configure(slot, value=None)
|
|
|
|
if slot.kind_of? Hash
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
slot = _symbolkey2str(slot)
|
2004-01-07 00:28:53 -05:00
|
|
|
if slot['window']
|
|
|
|
@id = slot['window']
|
|
|
|
slot['window'] = @id.epath if @id.kind_of?(TkWindow)
|
|
|
|
end
|
1999-08-13 01:37:52 -04:00
|
|
|
if slot['create']
|
2004-01-07 00:28:53 -05:00
|
|
|
self.create=slot.delete('create')
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
if slot.size > 0
|
2003-06-18 15:46:20 -04:00
|
|
|
tk_call(@t.path, 'window', 'configure', @index, *hash_kv(slot))
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
else
|
2004-01-07 00:28:53 -05:00
|
|
|
if slot == 'window' || slot == :window
|
|
|
|
@id = value
|
|
|
|
value = @id.epath if @id.kind_of?(TkWindow)
|
|
|
|
end
|
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-06-04 03:03:33 -04:00
|
|
|
if slot == 'create' || slot == :create
|
1999-08-13 01:37:52 -04:00
|
|
|
self.create=value
|
|
|
|
else
|
2003-06-18 15:46:20 -04:00
|
|
|
tk_call(@t.path, 'window', 'configure', @index, "-#{slot}", value)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def configinfo(slot = nil)
|
|
|
|
@t.window_configinfo(@index, slot)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def window
|
|
|
|
@id
|
|
|
|
end
|
|
|
|
|
|
|
|
def window=(value)
|
|
|
|
@id = value
|
2004-01-07 00:28:53 -05:00
|
|
|
value = @id.epath if @id.kind_of?(TkWindow)
|
|
|
|
tk_call @t.path, 'window', 'configure', @index, '-window', value
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@p_create
|
|
|
|
end
|
|
|
|
|
|
|
|
def create=(value)
|
|
|
|
@p_create = value
|
|
|
|
if @p_create.kind_of? Proc
|
2004-01-07 00:28:53 -05:00
|
|
|
value = install_cmd(proc{
|
|
|
|
@id = @p_create.call
|
|
|
|
if @id.kind_of?(TkWindow)
|
|
|
|
@id.epath
|
|
|
|
else
|
|
|
|
@id
|
|
|
|
end
|
|
|
|
})
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
tk_call @t.path, 'window', 'configure', @index, '-create', value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TkTextImage<TkObject
|
|
|
|
def initialize(parent, index, keys)
|
|
|
|
if not parent.kind_of?(TkText)
|
2003-12-02 23:55:07 -05:00
|
|
|
fail Kernel.format("%s need to be TkText", parent.inspect)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
@t = parent
|
|
|
|
if index == 'end'
|
|
|
|
@path = TkTextMark.new(@t, tk_call(@t.path, 'index', 'end - 1 chars'))
|
|
|
|
elsif index.kind_of? TkTextMark
|
|
|
|
if tk_call(@t.path,'index',index.path) == tk_call(@t.path,'index','end')
|
|
|
|
@path = TkTextMark.new(@t, tk_call(@t.path, 'index', 'end - 1 chars'))
|
|
|
|
else
|
|
|
|
@path = TkTextMark.new(@t, tk_call(@t.path, 'index', index.path))
|
|
|
|
end
|
|
|
|
else
|
|
|
|
@path = TkTextMark.new(@t, tk_call(@t.path, 'index', index))
|
|
|
|
end
|
|
|
|
@path.gravity = 'left'
|
|
|
|
@index = @path.path
|
|
|
|
@id = tk_call(@t.path, 'image', 'create', @index, *hash_kv(keys))
|
|
|
|
end
|
|
|
|
|
|
|
|
def [](slot)
|
|
|
|
cget(slot)
|
|
|
|
end
|
|
|
|
def []=(slot, value)
|
|
|
|
configure(slot, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
def cget(slot)
|
2003-06-18 15:46:20 -04:00
|
|
|
@t.image_cget(@index, slot)
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def configure(slot, value=None)
|
2003-06-18 15:46:20 -04:00
|
|
|
@t.image_configure(@index, slot, value)
|
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
# def configure(slot, value)
|
|
|
|
# tk_call @t.path, 'image', 'configure', @index, "-#{slot}", value
|
|
|
|
# end
|
|
|
|
|
2003-06-18 15:46:20 -04:00
|
|
|
def configinfo(slot = nil)
|
|
|
|
@t.image_configinfo(@index, slot)
|
|
|
|
end
|
|
|
|
|
1999-08-13 01:37:52 -04:00
|
|
|
def image
|
2003-06-18 15:46:20 -04:00
|
|
|
img = tk_call(@t.path, 'image', 'configure', @index, '-image')
|
|
|
|
TkImage::Tk_IMGTBL[img]? TkImage::Tk_IMGTBL[img] : img
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def image=(value)
|
|
|
|
tk_call @t.path, 'image', 'configure', @index, '-image', value
|
2003-06-18 15:46:20 -04:00
|
|
|
self
|
1999-08-13 01:37:52 -04:00
|
|
|
end
|
|
|
|
end
|