* ext/tk/tcltklib.c (lib_eventloop_ensure): mis-delete a timer handler

when exit from a recursive called eventloop
* ext/tk/lib/tk/timer.rb: new TkRTTimer class, which can works for a
  realtime operation
* ext/tk/sample/tkrttimer.rb: sample of TkRTTimer class
* ext/tk/lib/tk/textmark.rb: move  TkTextMark#+ and TkTextMark#- to
  TkText::IndexModMethods
* ext/tk/lib/tk/text.rb: improve TkTextMark#+ and TkTextMark#-, and
  add them to TkText::IndexModMethods module
* ext/tk/sample/tktextio.rb: add test part of "seek by text index
  modifiers"


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagai 2005-03-10 10:13:30 +00:00
parent 7935361d36
commit d2a9e77748
35 changed files with 550 additions and 292 deletions

View File

@ -1,3 +1,22 @@
Thu Mar 10 19:10:29 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/tcltklib.c (lib_eventloop_ensure): mis-delete a timer handler
when exit from a recursive called eventloop
* ext/tk/lib/tk/timer.rb: new TkRTTimer class, which can works for a
realtime operation
* ext/tk/sample/tkrttimer.rb: sample of TkRTTimer class
* ext/tk/lib/tk/textmark.rb: move TkTextMark#+ and TkTextMark#- to
TkText::IndexModMethods
* ext/tk/lib/tk/text.rb: improve TkTextMark#+ and TkTextMark#-, and
add them to TkText::IndexModMethods module
* ext/tk/sample/tktextio.rb: add test part of "seek by text index
modifiers"
Wed Mar 9 23:55:34 2005 Tanaka Akira <akr@m17n.org> Wed Mar 9 23:55:34 2005 Tanaka Akira <akr@m17n.org>
* lib/pp.rb (PP::PPMethods#guard_inspect_key): support * lib/pp.rb (PP::PPMethods#guard_inspect_key): support

View File

@ -1470,14 +1470,14 @@ module TkCore
nil nil
end end
def event_generate(window, context, keys=nil) def event_generate(win, context, keys=nil)
#window = window.path if window.kind_of?(TkObject) #win = win.path if win.kind_of?(TkObject)
if keys if keys
tk_call_without_enc('event', 'generate', window, tk_call_without_enc('event', 'generate', win,
"<#{tk_event_sequence(context)}>", "<#{tk_event_sequence(context)}>",
*hash_kv(keys, true)) *hash_kv(keys, true))
else else
tk_call_without_enc('event', 'generate', window, tk_call_without_enc('event', 'generate', win,
"<#{tk_event_sequence(context)}>") "<#{tk_event_sequence(context)}>")
end end
nil nil
@ -1874,8 +1874,8 @@ module Tk
TkManageFocus.prev(win) TkManageFocus.prev(win)
end end
def Tk.strictMotif(bool=None) def Tk.strictMotif(mode=None)
bool(tk_call_without_enc('set', 'tk_strictMotif', bool)) bool(tk_call_without_enc('set', 'tk_strictMotif', mode))
end end
def Tk.show_kinsoku(mode='both') def Tk.show_kinsoku(mode='both')
@ -2435,18 +2435,18 @@ module TkTreatFont
self self
end end
def font_copy(window, wintag=nil, winkey=nil, targetkey=nil) def font_copy(win, wintag=nil, winkey=nil, targetkey=nil)
if wintag if wintag
if winkey if winkey
fnt = window.tagfontobj(wintag, winkey).dup fnt = win.tagfontobj(wintag, winkey).dup
else else
fnt = window.tagfontobj(wintag).dup fnt = win.tagfontobj(wintag).dup
end end
else else
if winkey if winkey
fnt = window.fontobj(winkey).dup fnt = win.fontobj(winkey).dup
else else
fnt = window.fontobj.dup fnt = win.fontobj.dup
end end
end end
@ -2458,7 +2458,7 @@ module TkTreatFont
self self
end end
def latinfont_copy(window, wintag=nil, winkey=nil, targetkey=nil) def latinfont_copy(win, wintag=nil, winkey=nil, targetkey=nil)
if targetkey if targetkey
fontobj(targetkey).dup.call_font_configure([__pathname, targetkey], fontobj(targetkey).dup.call_font_configure([__pathname, targetkey],
*(__config_cmd << {})) *(__config_cmd << {}))
@ -2468,22 +2468,22 @@ module TkTreatFont
if wintag if wintag
if winkey if winkey
fontobj.latin_replace(window.tagfontobj(wintag, winkey).latin_font_id) fontobj.latin_replace(win.tagfontobj(wintag, winkey).latin_font_id)
else else
fontobj.latin_replace(window.tagfontobj(wintag).latin_font_id) fontobj.latin_replace(win.tagfontobj(wintag).latin_font_id)
end end
else else
if winkey if winkey
fontobj.latin_replace(window.fontobj(winkey).latin_font_id) fontobj.latin_replace(win.fontobj(winkey).latin_font_id)
else else
fontobj.latin_replace(window.fontobj.latin_font_id) fontobj.latin_replace(win.fontobj.latin_font_id)
end end
end end
self self
end end
alias asciifont_copy latinfont_copy alias asciifont_copy latinfont_copy
def kanjifont_copy(window, wintag=nil, winkey=nil, targetkey=nil) def kanjifont_copy(win, wintag=nil, winkey=nil, targetkey=nil)
if targetkey if targetkey
fontobj(targetkey).dup.call_font_configure([__pathname, targetkey], fontobj(targetkey).dup.call_font_configure([__pathname, targetkey],
*(__config_cmd << {})) *(__config_cmd << {}))
@ -2493,15 +2493,15 @@ module TkTreatFont
if wintag if wintag
if winkey if winkey
fontobj.kanji_replace(window.tagfontobj(wintag, winkey).kanji_font_id) fontobj.kanji_replace(win.tagfontobj(wintag, winkey).kanji_font_id)
else else
fontobj.kanji_replace(window.tagfontobj(wintag).kanji_font_id) fontobj.kanji_replace(win.tagfontobj(wintag).kanji_font_id)
end end
else else
if winkey if winkey
fontobj.kanji_replace(window.fontobj(winkey).kanji_font_id) fontobj.kanji_replace(win.fontobj(winkey).kanji_font_id)
else else
fontobj.kanji_replace(window.fontobj.kanji_font_id) fontobj.kanji_replace(win.fontobj.kanji_font_id)
end end
end end
self self
@ -4002,7 +4002,7 @@ end
#Tk.freeze #Tk.freeze
module Tk module Tk
RELEASE_DATE = '2005-03-05'.freeze RELEASE_DATE = '2005-03-10'.freeze
autoload :AUTO_PATH, 'tk/variable' autoload :AUTO_PATH, 'tk/variable'
autoload :TCL_PACKAGE_PATH, 'tk/variable' autoload :TCL_PACKAGE_PATH, 'tk/variable'

View File

@ -148,6 +148,7 @@ autoload :TkTextWindow, 'tk/textwindow'
autoload :TkAfter, 'tk/timer' autoload :TkAfter, 'tk/timer'
autoload :TkTimer, 'tk/timer' autoload :TkTimer, 'tk/timer'
autoload :TkRTTimer, 'tk/timer'
autoload :TkToplevel, 'tk/toplevel' autoload :TkToplevel, 'tk/toplevel'

View File

@ -227,8 +227,8 @@ class TkCanvas<TkWindow
self self
end end
def index(tagOrId, index) def index(tagOrId, idx)
number(tk_send_without_enc('index', tagid(tagOrId), index)) number(tk_send_without_enc('index', tagid(tagOrId), idx))
end end
def insert(tagOrId, index, string) def insert(tagOrId, index, string)

View File

@ -112,8 +112,8 @@ module TkcTagAccess
self self
end end
def index(index) def index(idx)
@c.index(@id, index) @c.index(@id, idx)
end end
def insert(beforethis, string) def insert(beforethis, string)

View File

@ -32,8 +32,8 @@ class TkEntry<TkLabel
#self #self
index index
end end
def index(index) def index(idx)
number(tk_send_without_enc('index', index)) number(tk_send_without_enc('index', idx))
end end
def insert(pos,text) def insert(pos,text)
tk_send_without_enc('insert', pos, _get_eval_enc_str(text)) tk_send_without_enc('insert', pos, _get_eval_enc_str(text))

View File

@ -163,14 +163,14 @@ class TkFont
################################### ###################################
# class methods # class methods
################################### ###################################
def TkFont.families(window=nil) def TkFont.families(win=nil)
case (Tk::TK_VERSION) case (Tk::TK_VERSION)
when /^4\.*/ when /^4\.*/
['fixed'] ['fixed']
when /^8\.*/ when /^8\.*/
if window if win
tk_split_simplelist(tk_call('font', 'families', '-displayof', window)) tk_split_simplelist(tk_call('font', 'families', '-displayof', win))
else else
tk_split_simplelist(tk_call('font', 'families')) tk_split_simplelist(tk_call('font', 'families'))
end end
@ -675,7 +675,7 @@ class TkFont
end end
end end
def actual_core_tk4x(font, window=nil, option=nil) def actual_core_tk4x(font, win=nil, option=nil)
# dummy # dummy
if option == 'pointadjust' || option == :pointadjust if option == 'pointadjust' || option == :pointadjust
1.0 1.0
@ -695,13 +695,13 @@ class TkFont
end end
end end
def actual_core_tk8x(font, window=nil, option=nil) def actual_core_tk8x(font, win=nil, option=nil)
if option == 'compound' || option == :compound if option == 'compound' || option == :compound
"" ""
elsif option elsif option
if window if win
val = tk_call('font', 'actual', font, val = tk_call('font', 'actual', font,
"-displayof", window, "-#{option}") "-displayof", win, "-#{option}")
else else
val = tk_call('font', 'actual', font, "-#{option}") val = tk_call('font', 'actual', font, "-#{option}")
end end
@ -714,9 +714,9 @@ class TkFont
val val
end end
else else
l = tk_split_simplelist(if window l = tk_split_simplelist(if win
tk_call('font', 'actual', font, tk_call('font', 'actual', font,
"-displayof", window) "-displayof", win)
else else
tk_call('font', 'actual', font) tk_call('font', 'actual', font)
end) end)
@ -1124,20 +1124,20 @@ class TkFont
self self
end end
def measure_core_tk4x(window, text) def measure_core_tk4x(win, text)
0 0
end end
def measure_core_tk8x(window, text) def measure_core_tk8x(win, text)
if window if win
number(tk_call('font', 'measure', @compoundfont, number(tk_call('font', 'measure', @compoundfont,
'-displayof', window, text)) '-displayof', win, text))
else else
number(tk_call('font', 'measure', @compoundfont, text)) number(tk_call('font', 'measure', @compoundfont, text))
end end
end end
def metrics_core_tk4x(font, window, option=nil) def metrics_core_tk4x(font, win, option=nil)
# dummy # dummy
if option if option
"" ""
@ -1146,17 +1146,17 @@ class TkFont
end end
end end
def metrics_core_tk8x(font, window, option=nil) def metrics_core_tk8x(font, win, option=nil)
if option if option
if window if win
number(tk_call('font', 'metrics', font, number(tk_call('font', 'metrics', font,
"-displayof", window, "-#{option}")) "-displayof", win, "-#{option}"))
else else
number(tk_call('font', 'metrics', font, "-#{option}")) number(tk_call('font', 'metrics', font, "-#{option}"))
end end
else else
l = tk_split_list(if window l = tk_split_list(if win
tk_call('font','metrics',font,"-displayof",window) tk_call('font','metrics',font,"-displayof",win)
else else
tk_call('font','metrics',font) tk_call('font','metrics',font)
end) end)
@ -1357,18 +1357,18 @@ class TkFont
actual_core(@compoundfont, nil, option) actual_core(@compoundfont, nil, option)
end end
def actual_displayof(window, option=nil) def actual_displayof(win, option=nil)
window = '.' unless window win = '.' unless win
actual_core(@compoundfont, window, option) actual_core(@compoundfont, win, option)
end end
def latin_actual(option=nil) def latin_actual(option=nil)
actual_core(@latinfont, nil, option) actual_core(@latinfont, nil, option)
end end
def latin_actual_displayof(window, option=nil) def latin_actual_displayof(win, option=nil)
window = '.' unless window win = '.' unless win
actual_core(@latinfont, window, option) actual_core(@latinfont, win, option)
end end
def kanji_actual(option=nil) def kanji_actual(option=nil)
@ -1380,13 +1380,13 @@ class TkFont
end end
end end
def kanji_actual_displayof(window, option=nil) def kanji_actual_displayof(win, option=nil)
#if JAPANIZED_TK #if JAPANIZED_TK
if @kanjifont != "" if @kanjifont != ""
window = '.' unless window win = '.' unless win
actual_core(@kanjifont, window, option) actual_core(@kanjifont, win, option)
else else
actual_core_tk4x(nil, window, option) actual_core_tk4x(nil, win, option)
end end
end end
@ -1478,27 +1478,27 @@ class TkFont
measure_core(nil, text) measure_core(nil, text)
end end
def measure_displayof(window, text) def measure_displayof(win, text)
window = '.' unless window win = '.' unless win
measure_core(window, text) measure_core(win, text)
end end
def metrics(option=nil) def metrics(option=nil)
metrics_core(@compoundfont, nil, option) metrics_core(@compoundfont, nil, option)
end end
def metrics_displayof(window, option=nil) def metrics_displayof(win, option=nil)
window = '.' unless window win = '.' unless win
metrics_core(@compoundfont, window, option) metrics_core(@compoundfont, win, option)
end end
def latin_metrics(option=nil) def latin_metrics(option=nil)
metrics_core(@latinfont, nil, option) metrics_core(@latinfont, nil, option)
end end
def latin_metrics_displayof(window, option=nil) def latin_metrics_displayof(win, option=nil)
window = '.' unless window win = '.' unless win
metrics_core(@latinfont, window, option) metrics_core(@latinfont, win, option)
end end
def kanji_metrics(option=nil) def kanji_metrics(option=nil)
@ -1509,12 +1509,12 @@ class TkFont
end end
end end
def kanji_metrics_displayof(window, option=nil) def kanji_metrics_displayof(win, option=nil)
if JAPANIZED_TK if JAPANIZED_TK
window = '.' unless window win = '.' unless win
metrics_core(@kanjifont, window, option) metrics_core(@kanjifont, win, option)
else else
metrics_core_tk4x(nil, window, option) metrics_core_tk4x(nil, win, option)
end end
end end

View File

@ -158,13 +158,13 @@ module TkGrid
list(tk_call_without_enc('grid', 'location', master, x, y)) list(tk_call_without_enc('grid', 'location', master, x, y))
end end
def propagate(master, bool=None) def propagate(master, mode=None)
# master = master.epath if master.kind_of?(TkObject) # master = master.epath if master.kind_of?(TkObject)
master = _epath(master) master = _epath(master)
if bool == None if mode == None
bool(tk_call_without_enc('grid', 'propagate', master)) bool(tk_call_without_enc('grid', 'propagate', master))
else else
tk_call_without_enc('grid', 'propagate', master, bool) tk_call_without_enc('grid', 'propagate', master, mode)
end end
end end

View File

@ -221,18 +221,18 @@ module TkTreatItemFont
self self
end end
def tagfont_copy(tagOrId, window, wintag=nil, winkey=nil, targetkey=nil) def tagfont_copy(tagOrId, win, wintag=nil, winkey=nil, targetkey=nil)
if wintag if wintag
if winkey if winkey
fnt = window.tagfontobj(wintag, winkey).dup fnt = win.tagfontobj(wintag, winkey).dup
else else
fnt = window.tagfontobj(wintag).dup fnt = win.tagfontobj(wintag).dup
end end
else else
if winkey if winkey
fnt = window.fontobj(winkey).dup fnt = win.fontobj(winkey).dup
else else
fnt = window.fontobj.dup fnt = win.fontobj.dup
end end
end end
@ -247,7 +247,7 @@ module TkTreatItemFont
end end
def latintagfont_copy(tagOrId, window, wintag=nil, winkey=nil, targetkey=nil) def latintagfont_copy(tagOrId, win, wintag=nil, winkey=nil, targetkey=nil)
if targetkey if targetkey
fontobj(targetkey).dup.call_font_configure([__item_pathname(tagid(tagOrId)), targetkey], fontobj(targetkey).dup.call_font_configure([__item_pathname(tagid(tagOrId)), targetkey],
*(__item_config_cmd(tagid(tagOrId)) << {})) *(__item_config_cmd(tagid(tagOrId)) << {}))
@ -258,22 +258,22 @@ module TkTreatItemFont
if wintag if wintag
if winkey if winkey
fontobj.latin_replace(window.tagfontobj(wintag, winkey).latin_font_id) fontobj.latin_replace(win.tagfontobj(wintag, winkey).latin_font_id)
else else
fontobj.latin_replace(window.tagfontobj(wintag).latin_font_id) fontobj.latin_replace(win.tagfontobj(wintag).latin_font_id)
end end
else else
if winkey if winkey
fontobj.latin_replace(window.fontobj(winkey).latin_font_id) fontobj.latin_replace(win.fontobj(winkey).latin_font_id)
else else
fontobj.latin_replace(window.fontobj.latin_font_id) fontobj.latin_replace(win.fontobj.latin_font_id)
end end
end end
self self
end end
alias asciitagfont_copy latintagfont_copy alias asciitagfont_copy latintagfont_copy
def kanjifont_copy(tagOrId, window, wintag=nil, winkey=nil, targetkey=nil) def kanjifont_copy(tagOrId, win, wintag=nil, winkey=nil, targetkey=nil)
if targetkey if targetkey
fontobj(targetkey).dup.call_font_configure([__item_pathname(tagid(tagOrId)), targetkey], fontobj(targetkey).dup.call_font_configure([__item_pathname(tagid(tagOrId)), targetkey],
*(__item_config_cmd(tagid(tagOrId)) << {})) *(__item_config_cmd(tagid(tagOrId)) << {}))
@ -284,15 +284,15 @@ module TkTreatItemFont
if wintag if wintag
if winkey if winkey
fontobj.kanji_replace(window.tagfontobj(wintag, winkey).kanji_font_id) fontobj.kanji_replace(win.tagfontobj(wintag, winkey).kanji_font_id)
else else
fontobj.kanji_replace(window.tagfontobj(wintag).kanji_font_id) fontobj.kanji_replace(win.tagfontobj(wintag).kanji_font_id)
end end
else else
if winkey if winkey
fontobj.kanji_replace(window.fontobj(winkey).kanji_font_id) fontobj.kanji_replace(win.fontobj(winkey).kanji_font_id)
else else
fontobj.kanji_replace(window.fontobj.kanji_font_id) fontobj.kanji_replace(win.fontobj.kanji_font_id)
end end
end end
self self

View File

@ -13,46 +13,46 @@ module TkKinput
'kanjiInput'.freeze 'kanjiInput'.freeze
].freeze ].freeze
def TkKinput.start(window, style=None) def TkKinput.start(win, style=None)
tk_call('kinput_start', window, style) tk_call('kinput_start', win, style)
end end
def kinput_start(style=None) def kinput_start(style=None)
TkKinput.start(self, style) TkKinput.start(self, style)
end end
def TkKinput.send_spot(window) def TkKinput.send_spot(win)
tk_call('kinput_send_spot', window) tk_call('kinput_send_spot', win)
end end
def kinput_send_spot def kinput_send_spot
TkKinput.send_spot(self) TkKinput.send_spot(self)
end end
def TkKinput.input_start(window, keys=nil) def TkKinput.input_start(win, keys=nil)
tk_call('kanjiInput', 'start', window, *hash_kv(keys)) tk_call('kanjiInput', 'start', win, *hash_kv(keys))
end end
def kanji_input_start(keys=nil) def kanji_input_start(keys=nil)
TkKinput.input_start(self, keys) TkKinput.input_start(self, keys)
end end
def TkKinput.attribute_config(window, slot, value=None) def TkKinput.attribute_config(win, slot, value=None)
if slot.kind_of? Hash if slot.kind_of? Hash
tk_call('kanjiInput', 'attribute', window, *hash_kv(slot)) tk_call('kanjiInput', 'attribute', win, *hash_kv(slot))
else else
tk_call('kanjiInput', 'attribute', window, "-#{slot}", value) tk_call('kanjiInput', 'attribute', win, "-#{slot}", value)
end end
end end
def kinput_attribute_config(slot, value=None) def kinput_attribute_config(slot, value=None)
TkKinput.attribute_config(self, slot, value) TkKinput.attribute_config(self, slot, value)
end end
def TkKinput.attribute_info(window, slot=nil) def TkKinput.attribute_info(win, slot=nil)
if slot if slot
conf = tk_split_list(tk_call('kanjiInput', 'attribute', conf = tk_split_list(tk_call('kanjiInput', 'attribute',
window, "-#{slot}")) win, "-#{slot}"))
conf[0] = conf[0][1..-1] conf[0] = conf[0][1..-1]
conf conf
else else
tk_split_list(tk_call('kanjiInput', 'attribute', window)).collect{|conf| tk_split_list(tk_call('kanjiInput', 'attribute', win)).collect{|conf|
conf[0] = conf[0][1..-1] conf[0] = conf[0][1..-1]
conf conf
} }
@ -62,8 +62,8 @@ module TkKinput
TkKinput.attribute_info(self, slot) TkKinput.attribute_info(self, slot)
end end
def TkKinput.input_end(window) def TkKinput.input_end(win)
tk_call('kanjiInput', 'end', window) tk_call('kanjiInput', 'end', win)
end end
def kanji_input_end def kanji_input_end
TkKinput.input_end(self) TkKinput.input_end(self)

View File

@ -73,8 +73,8 @@ class TkListbox<TkTextWin
self self
end end
def index(index) def index(idx)
tk_send_without_enc('index', index).to_i tk_send_without_enc('index', idx).to_i
end end
def value def value

View File

@ -95,8 +95,8 @@ class TkMenu<TkWindow
def add_separator(keys=nil) def add_separator(keys=nil)
add('separator', keys) add('separator', keys)
end end
def index(index) def index(idx)
ret = tk_send_without_enc('index', _get_eval_enc_str(index)) ret = tk_send_without_enc('index', _get_eval_enc_str(idx))
(ret == 'none')? nil: number(ret) (ret == 'none')? nil: number(ret)
end end
def invoke(index) def invoke(index)

View File

@ -17,15 +17,15 @@ module TkManageFocus
tk_call_without_enc('tk_focusFollowsMouse') tk_call_without_enc('tk_focusFollowsMouse')
end end
def TkManageFocus.next(window) def TkManageFocus.next(win)
tk_tcl2ruby(tk_call('tk_focusNext', window)) tk_tcl2ruby(tk_call('tk_focusNext', win))
end end
def focusNext def focusNext
TkManageFocus.next(self) TkManageFocus.next(self)
end end
def TkManageFocus.prev(window) def TkManageFocus.prev(win)
tk_tcl2ruby(tk_call('tk_focusPrev', window)) tk_tcl2ruby(tk_call('tk_focusPrev', win))
end end
def focusPrev def focusPrev
TkManageFocus.prev(self) TkManageFocus.prev(self)

View File

@ -51,13 +51,13 @@ module TkPack
return info return info
end end
def propagate(master, bool=None) def propagate(master, mode=None)
# master = master.epath if master.kind_of?(TkObject) # master = master.epath if master.kind_of?(TkObject)
master = _epath(master) master = _epath(master)
if bool == None if mode == None
bool(tk_call_without_enc('pack', 'propagate', master)) bool(tk_call_without_enc('pack', 'propagate', master))
else else
tk_call_without_enc('pack', 'propagate', master, bool) tk_call_without_enc('pack', 'propagate', master, mode)
end end
end end

View File

@ -30,22 +30,22 @@ module TkPalette
tk_call('tkDarken', color, percent) tk_call('tkDarken', color, percent)
end end
def TkPalette.recolorTree(window, colors) def TkPalette.recolorTree(win, colors)
if not colors.kind_of?(Hash) if not colors.kind_of?(Hash)
fail "2nd arg need to be Hash" fail "2nd arg need to be Hash"
end end
colors.each{|key, value| colors.each{|key, value|
begin begin
if window.cget(key) == tk_call('set', "tkPalette(#{key})") if win.cget(key) == tk_call('set', "tkPalette(#{key})")
window[key] = colors[key] win[key] = colors[key]
end end
rescue rescue
# ignore # ignore
end end
} }
TkWinfo.children(window).each{|w| TkPalette.recolorTree(w, colors)} TkWinfo.children(win).each{|w| TkPalette.recolorTree(w, colors)}
end end
def recolorTree(colors) def recolorTree(colors)

View File

@ -25,19 +25,19 @@ module TkTreatTagFont
self self
end end
def font_copy(window, wintag=nil) def font_copy(win, wintag=nil)
@parent.tagfont_copy(@id, window, wintag) @parent.tagfont_copy(@id, win, wintag)
self self
end end
def latinfont_copy(window, wintag=nil) def latinfont_copy(win, wintag=nil)
@parent.latintagfont_copy(@id, window, wintag) @parent.latintagfont_copy(@id, win, wintag)
self self
end end
alias asciifont_copy latinfont_copy alias asciifont_copy latinfont_copy
def kanjifont_copy(window, wintag=nil) def kanjifont_copy(win, wintag=nil)
@parent.kanjitagfont_copy(@id, window, wintag) @parent.kanjitagfont_copy(@id, win, wintag)
self self
end end
end end

View File

@ -69,12 +69,36 @@ class TkText<TkTextWin
####################################### #######################################
module IndexModMethods module IndexModMethods
def +(mod)
return chars(mod) if mod.kind_of?(Numeric)
mod = mod.to_s
if mod =~ /^\s*[+-]?\d/
TkText::IndexString.new(String.new(id) << ' + ' << mod)
else
TkText::IndexString.new(String.new(id) << ' ' << mod)
end
end
def -(mod)
return chars(-mod) if mod.kind_of?(Numeric)
mod = mod.to_s
if mod =~ /^\s*[+-]?\d/
TkText::IndexString.new(String.new(id) << ' - ' << mod)
elsif mod =~ /^\s*[-]\s+(\d.*)$/
TkText::IndexString.new(String.new(id) << ' - -' << $1)
else
TkText::IndexString.new(String.new(id) << ' ' << mod)
end
end
def chars(mod) def chars(mod)
fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer) fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer)
if mod < 0 if mod < 0
TkText::IndexString.new(id + ' ' << mod.to_s << ' chars') TkText::IndexString.new(String.new(id) << ' ' << mod.to_s << ' chars')
else else
TkText::IndexString.new(id + ' + ' << mod.to_s << ' chars') TkText::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' chars')
end end
end end
alias char chars alias char chars
@ -82,25 +106,25 @@ class TkText<TkTextWin
def lines(mod) def lines(mod)
fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer) fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer)
if mod < 0 if mod < 0
TkText::IndexString.new(id + ' ' << mod.to_s << ' lines') TkText::IndexString.new(String.new(id) << ' ' << mod.to_s << ' lines')
else else
TkText::IndexString.new(id + ' + ' << mod.to_s << ' lines') TkText::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' lines')
end end
end end
alias line lines alias line lines
def linestart def linestart
TkText::IndexString.new(id + ' linestart') TkText::IndexString.new(String.new(id) << ' linestart')
end end
def lineend def lineend
TkText::IndexString.new(id + ' lineend') TkText::IndexString.new(String.new(id) << ' lineend')
end end
def wordstart def wordstart
TkText::IndexString.new(id + ' wordstart') TkText::IndexString.new(String.new(id) << ' wordstart')
end end
def wordend def wordend
TkText::IndexString.new(id + ' wordend') TkText::IndexString.new(String.new(id) << ' wordend')
end end
end end
@ -159,9 +183,9 @@ class TkText<TkTextWin
end end
private :create_self private :create_self
def index(index) def index(idx)
TkText::IndexString.new(tk_send_without_enc('index', TkText::IndexString.new(tk_send_without_enc('index',
_get_eval_enc_str(index))) _get_eval_enc_str(idx)))
end end
def get_displaychars(*index) def get_displaychars(*index)

View File

@ -47,11 +47,39 @@ class TkTextMark<TkObject
end end
end end
=begin
# move to TkText::IndexModMethods module
def +(mod) def +(mod)
TkText::IndexString.new(@id + ' + ' + mod) return chars(mod) if mod.kind_of?(Numeric)
mod = mod.to_s
if mod =~ /^\s*[+-]?\d/
TkText::IndexString.new(@id + ' + ' + mod)
else
TkText::IndexString.new(@id + ' ' + mod)
end
end end
def -(mod) def -(mod)
TkText::IndexString.new(@id + ' - ' + mod) return chars(-mod) if mod.kind_of?(Numeric)
mod = mod.to_s
if mod =~ /^\s*[+-]?\d/
TkText::IndexString.new(@id + ' - ' + mod)
elsif mod =~ /^\s*[-]\s+(\d.*)$/
TkText::IndexString.new(@id + ' - -' + $1)
else
TkText::IndexString.new(@id + ' ' + mod)
end
end
=end
def pos
@t.index(@id)
end
def pos=(where)
set(where)
end end
def set(where) def set(where)

View File

@ -401,6 +401,8 @@ class TkTimer
@current_pos = 0 @current_pos = 0
@current_args = @init_args @current_args = @init_args
@current_script = []
@set_next = false if @in_callback @set_next = false if @in_callback
self self
@ -428,6 +430,7 @@ class TkTimer
def continue(wait=nil) def continue(wait=nil)
fail RuntimeError, "is already running" if @running fail RuntimeError, "is already running" if @running
return restart() if @current_script.empty?
sleep, cmd = @current_script sleep, cmd = @current_script
fail RuntimeError, "no procedure to continue" unless cmd fail RuntimeError, "no procedure to continue" unless cmd
if wait if wait
@ -498,3 +501,98 @@ class TkTimer
end end
TkAfter = TkTimer TkAfter = TkTimer
class TkRTTimer < TkTimer
DEFAULT_OFFSET_LIST_SIZE = 5
def initialize(*args, &b)
super(*args, &b)
@offset_list = Array.new(DEFAULT_OFFSET_LIST_SIZE, 0.0)
@est_time = nil
end
def start(*args, &b)
return nil if @running
@est_time = nil
@cb_start_time = Time.now
super(*args, &b)
end
def cancel
super()
@est_time = nil
self
end
alias stop cancel
def set_interval(interval)
super(interval)
@est_time = nil
end
def _offset_ave
size = @offset_list.size.to_f
s = 0.0
@offset_list.each{|n| s + n}
s / size
end
private :_offset_ave
def set_next_callback(args)
if @running == false || @proc_max == 0 || @do_loop == 0
Tk_CBTBL.delete(@id) ;# for GC
@running = false
@wait_var.value = 0
return
end
if @current_pos >= @proc_max
if @do_loop < 0 || (@do_loop -= 1) > 0
@current_pos = 0
else
Tk_CBTBL.delete(@id) ;# for GC
@running = false
@wait_var.value = 0
return
end
end
@current_args = args
cmd, *cmd_args = @loop_proc[@current_pos]
@current_pos += 1
@current_proc = cmd
if TkComm._callback_entry?(@sleep_time)
sleep = @sleep_time.call(self)
else
sleep = @sleep_time
end
if @est_time
@est_time = Time.at(@est_time.to_f + sleep / 1000.0)
else
@est_time = Time.at(@cb_start_time.to_f + sleep / 1000.0)
end
offset = _offset_ave
real_sleep = ((@est_time - Time.now)*1000.0 + offset).round
real_sleep = 0 if real_sleep < 0
@current_sleep = real_sleep
set_callback(real_sleep, cmd_args)
end
def cb_call
@cb_start_time = Time.now
if @est_time
@offset_list.shift
@offset_list.push((@est_time - @cb_start_time) * 1000.0)
end
@cb_cmd.call
end
end

View File

@ -36,30 +36,30 @@ module TkWinfo
TkWinfo.atomname(id, self) TkWinfo.atomname(id, self)
end end
def TkWinfo.cells(window) def TkWinfo.cells(win)
number(tk_call_without_enc('winfo', 'cells', window)) number(tk_call_without_enc('winfo', 'cells', win))
end end
def winfo_cells def winfo_cells
TkWinfo.cells self TkWinfo.cells self
end end
def TkWinfo.children(window) def TkWinfo.children(win)
list(tk_call_without_enc('winfo', 'children', window)) list(tk_call_without_enc('winfo', 'children', win))
end end
def winfo_children def winfo_children
TkWinfo.children self TkWinfo.children self
end end
def TkWinfo.classname(window) def TkWinfo.classname(win)
tk_call_without_enc('winfo', 'class', window) tk_call_without_enc('winfo', 'class', win)
end end
def winfo_classname def winfo_classname
TkWinfo.classname self TkWinfo.classname self
end end
alias winfo_class winfo_classname alias winfo_class winfo_classname
def TkWinfo.colormapfull(window) def TkWinfo.colormapfull(win)
bool(tk_call_without_enc('winfo', 'colormapfull', window)) bool(tk_call_without_enc('winfo', 'colormapfull', win))
end end
def winfo_colormapfull def winfo_colormapfull
TkWinfo.colormapfull self TkWinfo.colormapfull self
@ -77,52 +77,52 @@ module TkWinfo
TkWinfo.containing(x, y, self) TkWinfo.containing(x, y, self)
end end
def TkWinfo.depth(window) def TkWinfo.depth(win)
number(tk_call_without_enc('winfo', 'depth', window)) number(tk_call_without_enc('winfo', 'depth', win))
end end
def winfo_depth def winfo_depth
TkWinfo.depth self TkWinfo.depth self
end end
def TkWinfo.exist?(window) def TkWinfo.exist?(win)
bool(tk_call_without_enc('winfo', 'exists', window)) bool(tk_call_without_enc('winfo', 'exists', win))
end end
def winfo_exist? def winfo_exist?
TkWinfo.exist? self TkWinfo.exist? self
end end
def TkWinfo.fpixels(window, dist) def TkWinfo.fpixels(win, dist)
number(tk_call_without_enc('winfo', 'fpixels', window, dist)) number(tk_call_without_enc('winfo', 'fpixels', win, dist))
end end
def winfo_fpixels(dist) def winfo_fpixels(dist)
TkWinfo.fpixels self, dist TkWinfo.fpixels self, dist
end end
def TkWinfo.geometry(window) def TkWinfo.geometry(win)
tk_call_without_enc('winfo', 'geometry', window) tk_call_without_enc('winfo', 'geometry', win)
end end
def winfo_geometry def winfo_geometry
TkWinfo.geometry self TkWinfo.geometry self
end end
def TkWinfo.height(window) def TkWinfo.height(win)
number(tk_call_without_enc('winfo', 'height', window)) number(tk_call_without_enc('winfo', 'height', win))
end end
def winfo_height def winfo_height
TkWinfo.height self TkWinfo.height self
end end
def TkWinfo.id(window) def TkWinfo.id(win)
tk_call_without_enc('winfo', 'id', window) tk_call_without_enc('winfo', 'id', win)
end end
def winfo_id def winfo_id
TkWinfo.id self TkWinfo.id self
end end
def TkWinfo.interps(window=nil) def TkWinfo.interps(win=nil)
if window if win
tk_split_simplelist(tk_call_without_enc('winfo', 'interps', tk_split_simplelist(tk_call_without_enc('winfo', 'interps',
'-displayof', window)) '-displayof', win))
else else
tk_split_simplelist(tk_call_without_enc('winfo', 'interps')) tk_split_simplelist(tk_call_without_enc('winfo', 'interps'))
end end
@ -131,29 +131,29 @@ module TkWinfo
TkWinfo.interps self TkWinfo.interps self
end end
def TkWinfo.mapped?(window) def TkWinfo.mapped?(win)
bool(tk_call_without_enc('winfo', 'ismapped', window)) bool(tk_call_without_enc('winfo', 'ismapped', win))
end end
def winfo_mapped? def winfo_mapped?
TkWinfo.mapped? self TkWinfo.mapped? self
end end
def TkWinfo.manager(window) def TkWinfo.manager(win)
tk_call_without_enc('winfo', 'manager', window) tk_call_without_enc('winfo', 'manager', win)
end end
def winfo_manager def winfo_manager
TkWinfo.manager self TkWinfo.manager self
end end
def TkWinfo.appname(window) def TkWinfo.appname(win)
tk_call('winfo', 'name', window) tk_call('winfo', 'name', win)
end end
def winfo_appname def winfo_appname
TkWinfo.appname self TkWinfo.appname self
end end
def TkWinfo.parent(window) def TkWinfo.parent(win)
window(tk_call_without_enc('winfo', 'parent', window)) window(tk_call_without_enc('winfo', 'parent', win))
end end
def winfo_parent def winfo_parent
TkWinfo.parent self TkWinfo.parent self
@ -170,216 +170,216 @@ module TkWinfo
TkWinfo.widget id, self TkWinfo.widget id, self
end end
def TkWinfo.pixels(window, dist) def TkWinfo.pixels(win, dist)
number(tk_call_without_enc('winfo', 'pixels', window, dist)) number(tk_call_without_enc('winfo', 'pixels', win, dist))
end end
def winfo_pixels(dist) def winfo_pixels(dist)
TkWinfo.pixels self, dist TkWinfo.pixels self, dist
end end
def TkWinfo.reqheight(window) def TkWinfo.reqheight(win)
number(tk_call_without_enc('winfo', 'reqheight', window)) number(tk_call_without_enc('winfo', 'reqheight', win))
end end
def winfo_reqheight def winfo_reqheight
TkWinfo.reqheight self TkWinfo.reqheight self
end end
def TkWinfo.reqwidth(window) def TkWinfo.reqwidth(win)
number(tk_call_without_enc('winfo', 'reqwidth', window)) number(tk_call_without_enc('winfo', 'reqwidth', win))
end end
def winfo_reqwidth def winfo_reqwidth
TkWinfo.reqwidth self TkWinfo.reqwidth self
end end
def TkWinfo.rgb(window, color) def TkWinfo.rgb(win, color)
list(tk_call_without_enc('winfo', 'rgb', window, color)) list(tk_call_without_enc('winfo', 'rgb', win, color))
end end
def winfo_rgb(color) def winfo_rgb(color)
TkWinfo.rgb self, color TkWinfo.rgb self, color
end end
def TkWinfo.rootx(window) def TkWinfo.rootx(win)
number(tk_call_without_enc('winfo', 'rootx', window)) number(tk_call_without_enc('winfo', 'rootx', win))
end end
def winfo_rootx def winfo_rootx
TkWinfo.rootx self TkWinfo.rootx self
end end
def TkWinfo.rooty(window) def TkWinfo.rooty(win)
number(tk_call_without_enc('winfo', 'rooty', window)) number(tk_call_without_enc('winfo', 'rooty', win))
end end
def winfo_rooty def winfo_rooty
TkWinfo.rooty self TkWinfo.rooty self
end end
def TkWinfo.screen(window) def TkWinfo.screen(win)
tk_call('winfo', 'screen', window) tk_call('winfo', 'screen', win)
end end
def winfo_screen def winfo_screen
TkWinfo.screen self TkWinfo.screen self
end end
def TkWinfo.screencells(window) def TkWinfo.screencells(win)
number(tk_call_without_enc('winfo', 'screencells', window)) number(tk_call_without_enc('winfo', 'screencells', win))
end end
def winfo_screencells def winfo_screencells
TkWinfo.screencells self TkWinfo.screencells self
end end
def TkWinfo.screendepth(window) def TkWinfo.screendepth(win)
number(tk_call_without_enc('winfo', 'screendepth', window)) number(tk_call_without_enc('winfo', 'screendepth', win))
end end
def winfo_screendepth def winfo_screendepth
TkWinfo.screendepth self TkWinfo.screendepth self
end end
def TkWinfo.screenheight (window) def TkWinfo.screenheight (win)
number(tk_call_without_enc('winfo', 'screenheight', window)) number(tk_call_without_enc('winfo', 'screenheight', win))
end end
def winfo_screenheight def winfo_screenheight
TkWinfo.screenheight self TkWinfo.screenheight self
end end
def TkWinfo.screenmmheight(window) def TkWinfo.screenmmheight(win)
number(tk_call_without_enc('winfo', 'screenmmheight', window)) number(tk_call_without_enc('winfo', 'screenmmheight', win))
end end
def winfo_screenmmheight def winfo_screenmmheight
TkWinfo.screenmmheight self TkWinfo.screenmmheight self
end end
def TkWinfo.screenmmwidth(window) def TkWinfo.screenmmwidth(win)
number(tk_call_without_enc('winfo', 'screenmmwidth', window)) number(tk_call_without_enc('winfo', 'screenmmwidth', win))
end end
def winfo_screenmmwidth def winfo_screenmmwidth
TkWinfo.screenmmwidth self TkWinfo.screenmmwidth self
end end
def TkWinfo.screenvisual(window) def TkWinfo.screenvisual(win)
tk_call_without_enc('winfo', 'screenvisual', window) tk_call_without_enc('winfo', 'screenvisual', win)
end end
def winfo_screenvisual def winfo_screenvisual
TkWinfo.screenvisual self TkWinfo.screenvisual self
end end
def TkWinfo.screenwidth(window) def TkWinfo.screenwidth(win)
number(tk_call_without_enc('winfo', 'screenwidth', window)) number(tk_call_without_enc('winfo', 'screenwidth', win))
end end
def winfo_screenwidth def winfo_screenwidth
TkWinfo.screenwidth self TkWinfo.screenwidth self
end end
def TkWinfo.server(window) def TkWinfo.server(win)
tk_call('winfo', 'server', window) tk_call('winfo', 'server', win)
end end
def winfo_server def winfo_server
TkWinfo.server self TkWinfo.server self
end end
def TkWinfo.toplevel(window) def TkWinfo.toplevel(win)
window(tk_call_without_enc('winfo', 'toplevel', window)) window(tk_call_without_enc('winfo', 'toplevel', win))
end end
def winfo_toplevel def winfo_toplevel
TkWinfo.toplevel self TkWinfo.toplevel self
end end
def TkWinfo.visual(window) def TkWinfo.visual(win)
tk_call_without_enc('winfo', 'visual', window) tk_call_without_enc('winfo', 'visual', win)
end end
def winfo_visual def winfo_visual
TkWinfo.visual self TkWinfo.visual self
end end
def TkWinfo.visualid(window) def TkWinfo.visualid(win)
tk_call_without_enc('winfo', 'visualid', window) tk_call_without_enc('winfo', 'visualid', win)
end end
def winfo_visualid def winfo_visualid
TkWinfo.visualid self TkWinfo.visualid self
end end
def TkWinfo.visualsavailable(window, includeids=false) def TkWinfo.visualsavailable(win, includeids=false)
if includeids if includeids
list(tk_call_without_enc('winfo', 'visualsavailable', list(tk_call_without_enc('winfo', 'visualsavailable',
window, "includeids")) win, "includeids"))
else else
list(tk_call_without_enc('winfo', 'visualsavailable', window)) list(tk_call_without_enc('winfo', 'visualsavailable', win))
end end
end end
def winfo_visualsavailable(includeids=false) def winfo_visualsavailable(includeids=false)
TkWinfo.visualsavailable self, includeids TkWinfo.visualsavailable self, includeids
end end
def TkWinfo.vrootheight(window) def TkWinfo.vrootheight(win)
number(tk_call_without_enc('winfo', 'vrootheight', window)) number(tk_call_without_enc('winfo', 'vrootheight', win))
end end
def winfo_vrootheight def winfo_vrootheight
TkWinfo.vrootheight self TkWinfo.vrootheight self
end end
def TkWinfo.vrootwidth(window) def TkWinfo.vrootwidth(win)
number(tk_call_without_enc('winfo', 'vrootwidth', window)) number(tk_call_without_enc('winfo', 'vrootwidth', win))
end end
def winfo_vrootwidth def winfo_vrootwidth
TkWinfo.vrootwidth self TkWinfo.vrootwidth self
end end
def TkWinfo.vrootx(window) def TkWinfo.vrootx(win)
number(tk_call_without_enc('winfo', 'vrootx', window)) number(tk_call_without_enc('winfo', 'vrootx', win))
end end
def winfo_vrootx def winfo_vrootx
TkWinfo.vrootx self TkWinfo.vrootx self
end end
def TkWinfo.vrooty(window) def TkWinfo.vrooty(win)
number(tk_call_without_enc('winfo', 'vrooty', window)) number(tk_call_without_enc('winfo', 'vrooty', win))
end end
def winfo_vrooty def winfo_vrooty
TkWinfo.vrooty self TkWinfo.vrooty self
end end
def TkWinfo.width(window) def TkWinfo.width(win)
number(tk_call_without_enc('winfo', 'width', window)) number(tk_call_without_enc('winfo', 'width', win))
end end
def winfo_width def winfo_width
TkWinfo.width self TkWinfo.width self
end end
def TkWinfo.x(window) def TkWinfo.x(win)
number(tk_call_without_enc('winfo', 'x', window)) number(tk_call_without_enc('winfo', 'x', win))
end end
def winfo_x def winfo_x
TkWinfo.x self TkWinfo.x self
end end
def TkWinfo.y(window) def TkWinfo.y(win)
number(tk_call_without_enc('winfo', 'y', window)) number(tk_call_without_enc('winfo', 'y', win))
end end
def winfo_y def winfo_y
TkWinfo.y self TkWinfo.y self
end end
def TkWinfo.viewable(window) def TkWinfo.viewable(win)
bool(tk_call_without_enc('winfo', 'viewable', window)) bool(tk_call_without_enc('winfo', 'viewable', win))
end end
def winfo_viewable def winfo_viewable
TkWinfo.viewable self TkWinfo.viewable self
end end
def TkWinfo.pointerx(window) def TkWinfo.pointerx(win)
number(tk_call_without_enc('winfo', 'pointerx', window)) number(tk_call_without_enc('winfo', 'pointerx', win))
end end
def winfo_pointerx def winfo_pointerx
TkWinfo.pointerx self TkWinfo.pointerx self
end end
def TkWinfo.pointery(window) def TkWinfo.pointery(win)
number(tk_call_without_enc('winfo', 'pointery', window)) number(tk_call_without_enc('winfo', 'pointery', win))
end end
def winfo_pointery def winfo_pointery
TkWinfo.pointery self TkWinfo.pointery self
end end
def TkWinfo.pointerxy(window) def TkWinfo.pointerxy(win)
list(tk_call_without_enc('winfo', 'pointerxy', window)) list(tk_call_without_enc('winfo', 'pointerxy', win))
end end
def winfo_pointerxy def winfo_pointerxy
TkWinfo.pointerxy self TkWinfo.pointerxy self

View File

@ -192,11 +192,11 @@ module Tk
end end
end end
def overrideredirect(bool=None) def overrideredirect(mode=None)
if bool == None if mode == None
bool(tk_call_without_enc('wm', 'overrideredirect', path)) bool(tk_call_without_enc('wm', 'overrideredirect', path))
else else
tk_call_without_enc('wm', 'overrideredirect', path, bool) tk_call_without_enc('wm', 'overrideredirect', path, mode)
self self
end end
end end
@ -257,9 +257,9 @@ module Tk
bool(tk_call('wm', 'stackorder', path, 'isbelow', win)) bool(tk_call('wm', 'stackorder', path, 'isbelow', win))
end end
def state(state=nil) def state(st=nil)
if state if st
tk_call_without_enc('wm', 'state', path, state) tk_call_without_enc('wm', 'state', path, st)
self self
else else
tk_call_without_enc('wm', 'state', path) tk_call_without_enc('wm', 'state', path)

View File

@ -9,34 +9,34 @@ module TkXIM
TkCommandNames = ['imconfigure'.freeze].freeze TkCommandNames = ['imconfigure'.freeze].freeze
def TkXIM.useinputmethods(value = None, window = nil) def TkXIM.useinputmethods(value = None, win = nil)
if value == None if value == None
if window if win
bool(tk_call_without_enc('tk', 'useinputmethods', bool(tk_call_without_enc('tk', 'useinputmethods',
'-displayof', window)) '-displayof', win))
else else
bool(tk_call_without_enc('tk', 'useinputmethods')) bool(tk_call_without_enc('tk', 'useinputmethods'))
end end
else else
if window if win
bool(tk_call_without_enc('tk', 'useinputmethods', bool(tk_call_without_enc('tk', 'useinputmethods',
'-displayof', window, value)) '-displayof', win, value))
else else
bool(tk_call_without_enc('tk', 'useinputmethods', value)) bool(tk_call_without_enc('tk', 'useinputmethods', value))
end end
end end
end end
def TkXIM.useinputmethods_displayof(window, value = None) def TkXIM.useinputmethods_displayof(win, value = None)
TkXIM.useinputmethods(value, window) TkXIM.useinputmethods(value, win)
end end
def TkXIM.caret(window, keys=nil) def TkXIM.caret(win, keys=nil)
if keys if keys
tk_call_without_enc('tk', 'caret', window, *hash_kv(keys)) tk_call_without_enc('tk', 'caret', win, *hash_kv(keys))
self self
else else
lst = tk_split_list(tk_call_without_enc('tk', 'caret', window)) lst = tk_split_list(tk_call_without_enc('tk', 'caret', win))
info = {} info = {}
while key = lst.shift while key = lst.shift
info[key[1..-1]] = lst.shift info[key[1..-1]] = lst.shift
@ -45,29 +45,29 @@ module TkXIM
end end
end end
def TkXIM.configure(window, slot, value=None) def TkXIM.configure(win, slot, value=None)
begin begin
if /^8\.*/ === Tk::TK_VERSION && JAPANIZED_TK if /^8\.*/ === Tk::TK_VERSION && JAPANIZED_TK
if slot.kind_of? Hash if slot.kind_of? Hash
tk_call('imconfigure', window, *hash_kv(slot)) tk_call('imconfigure', win, *hash_kv(slot))
else else
tk_call('imconfigure', window, "-#{slot}", value) tk_call('imconfigure', win, "-#{slot}", value)
end end
end end
rescue rescue
end end
end end
def TkXIM.configinfo(window, slot=nil) def TkXIM.configinfo(win, slot=nil)
if TkComm::GET_CONFIGINFOwoRES_AS_ARRAY if TkComm::GET_CONFIGINFOwoRES_AS_ARRAY
begin begin
if /^8\.*/ === Tk::TK_VERSION && JAPANIZED_TK if /^8\.*/ === Tk::TK_VERSION && JAPANIZED_TK
if slot if slot
conf = tk_split_list(tk_call('imconfigure', window, "-#{slot}")) conf = tk_split_list(tk_call('imconfigure', win, "-#{slot}"))
conf[0] = conf[0][1..-1] conf[0] = conf[0][1..-1]
conf conf
else else
tk_split_list(tk_call('imconfigure', window)).collect{|conf| tk_split_list(tk_call('imconfigure', win)).collect{|conf|
conf[0] = conf[0][1..-1] conf[0] = conf[0][1..-1]
conf conf
} }
@ -79,19 +79,19 @@ module TkXIM
[] []
end end
else # ! TkComm::GET_CONFIGINFOwoRES_AS_ARRAY else # ! TkComm::GET_CONFIGINFOwoRES_AS_ARRAY
TkXIM.current_configinfo(window, slot) TkXIM.current_configinfo(win, slot)
end end
end end
def TkXIM.current_configinfo(window, slot=nil) def TkXIM.current_configinfo(win, slot=nil)
begin begin
if /^8\.*/ === Tk::TK_VERSION && JAPANIZED_TK if /^8\.*/ === Tk::TK_VERSION && JAPANIZED_TK
if slot if slot
conf = tk_split_list(tk_call('imconfigure', window, "-#{slot}")) conf = tk_split_list(tk_call('imconfigure', win, "-#{slot}"))
{ conf[0][1..-1] => conf[1] } { conf[0][1..-1] => conf[1] }
else else
ret = {} ret = {}
tk_split_list(tk_call('imconfigure', window)).each{|conf| tk_split_list(tk_call('imconfigure', win)).each{|conf|
ret[conf[0][1..-1]] = conf[1] ret[conf[0][1..-1]] = conf[1]
} }
ret ret

View File

@ -139,24 +139,24 @@ class Tk::Iwidgets::Notebook
end end
alias scrollbar yscrollbar alias scrollbar yscrollbar
def view(*index) def view(*idxs)
if index.size == 0 if idxss.size == 0
window(tk_send_without_enc('view')) window(tk_send_without_enc('view'))
else else
tk_send_without_enc('view', *index) tk_send_without_enc('view', *idxs)
self self
end end
end end
alias xview view alias xview view
alias yview view alias yview view
def view_moveto(*index) def view_moveto(*idxs)
view('moveto', *index) view('moveto', *idxs)
end end
alias xview_moveto view_moveto alias xview_moveto view_moveto
alias yview_moveto view_moveto alias yview_moveto view_moveto
def view_scroll(*index) def view_scroll(*idxs)
view('scroll', *index) view('scroll', *idxs)
end end
alias xview_scroll view_scroll alias xview_scroll view_scroll
alias yview_scroll view_scroll alias yview_scroll view_scroll

View File

@ -73,8 +73,8 @@ class Tk::Iwidgets::Promptdialog
end end
alias icursor cursor= alias icursor cursor=
def index(index) def index(idx)
number(tk_send_without_enc('index', index)) number(tk_send_without_enc('index', idx))
end end
def insert(pos,text) def insert(pos,text)

View File

@ -228,8 +228,8 @@ class Tk::Iwidgets::Scrolledcanvas
self self
end end
def index(tagOrId, index) def index(tagOrId, idx)
number(tk_send_without_enc('index', tagid(tagOrId), index)) number(tk_send_without_enc('index', tagid(tagOrId), idx))
end end
def insert(tagOrId, index, string) def insert(tagOrId, index, string)

View File

@ -152,8 +152,8 @@ class Tk::Iwidgets::Scrolledlistbox
self self
end end
def index(index) def index(idx)
tk_send_without_enc('index', index).to_i tk_send_without_enc('index', idx).to_i
end end
##################################### #####################################

View File

@ -240,8 +240,8 @@ class Tk::Iwidgets::Scrolledtext
} }
end end
def index(index) def index(idx)
tk_send_without_enc('index', _get_eval_enc_str(index)) tk_send_without_enc('index', _get_eval_enc_str(idx))
end end
def insert(index, *args) def insert(index, *args)

View File

@ -57,8 +57,8 @@ class Tk::Iwidgets::Selectionbox
tk_send_without_enc('delete', first, last) tk_send_without_enc('delete', first, last)
self self
end end
def index(index) def index(idx)
tk_send_without_enc('index', index).to_i tk_send_without_enc('index', idx).to_i
end end
def nearest(y) def nearest(y)
tk_send_without_enc('nearest', y).to_i tk_send_without_enc('nearest', y).to_i

View File

@ -57,8 +57,8 @@ class Tk::Iwidgets::Selectiondialog
tk_send_without_enc('delete', first, last) tk_send_without_enc('delete', first, last)
self self
end end
def index(index) def index(idx)
tk_send_without_enc('index', index).to_i tk_send_without_enc('index', idx).to_i
end end
def nearest(y) def nearest(y)
tk_send_without_enc('nearest', y).to_i tk_send_without_enc('nearest', y).to_i

View File

@ -91,8 +91,8 @@ class Tk::Iwidgets::Spinner
end end
alias icursor cursor= alias icursor cursor=
def index(index) def index(idx)
number(tk_send_without_enc('index', index)) number(tk_send_without_enc('index', idx))
end end
def insert(pos,text) def insert(pos,text)

View File

@ -517,10 +517,10 @@ end
# txt - Name of text widget # txt - Name of text widget
# index - The index of the character that the user clicked on. # index - The index of the character that the user clicked on.
def invoke (txt, index) def invoke (txt, idx)
tag = txt.tag_names(index).find{|t| t.kind_of?(String) && t =~ /^demo-/} tag = txt.tag_names(idx).find{|t| t.kind_of?(String) && t =~ /^demo-/}
return unless tag return unless tag
cursor = txt.cget('cursor') current_cursor = txt.cget('cursor')
txt.cursor('watch') txt.cursor('watch')
Tk.update Tk.update
# eval `cat #{tag[5..-1]}.rb` # eval `cat #{tag[5..-1]}.rb`
@ -528,9 +528,9 @@ def invoke (txt, index)
eval IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join eval IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join
Tk.update Tk.update
# txt.cursor('xterm') # txt.cursor('xterm')
txt.cursor(cursor) txt.cursor(current_cursor)
$tag_visited.add("#{index} linestart +1 chars", "#{index} lineend +1 chars") $tag_visited.add("#{idx} linestart +1 chars", "#{idx} lineend +1 chars")
end end
# showStatus -- # showStatus --
@ -791,7 +791,7 @@ end
# #
def aboutBox def aboutBox
Tk.messageBox('icon'=>'info', 'type'=>'ok', 'title'=>'About Widget Demo', Tk.messageBox('icon'=>'info', 'type'=>'ok', 'title'=>'About Widget Demo',
'message'=>"Ruby/Tk widget demonstration Ver.1.5.2-en\n\n" + 'message'=>"Ruby/Tk widget demonstration Ver.1.5.3-en\n\n" +
"based on demos of Tk8.1 -- 8.5 " + "based on demos of Tk8.1 -- 8.5 " +
"( Copyright:: " + "( Copyright:: " +
"(c) 1996-1997 Sun Microsystems, Inc. / " + "(c) 1996-1997 Sun Microsystems, Inc. / " +

View File

@ -552,10 +552,10 @@ else # ver >= 8.4
end end
# テキスト上での click に対する動作 # テキスト上での click に対する動作
def invoke (txt, index) def invoke (txt, idx)
tag = txt.tag_names(index).find{|t| t.kind_of?(String) && t =~ /^demo-/} tag = txt.tag_names(idx).find{|t| t.kind_of?(String) && t =~ /^demo-/}
return unless tag return unless tag
cursor = txt.cget('cursor') current_cursor = txt.cget('cursor')
txt.cursor('watch') txt.cursor('watch')
Tk.update Tk.update
# eval `cat #{tag[5..-1]}.rb` # eval `cat #{tag[5..-1]}.rb`
@ -563,9 +563,9 @@ def invoke (txt, index)
eval IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join eval IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join
Tk.update Tk.update
# txt.cursor('xterm') # txt.cursor('xterm')
txt.cursor(cursor) txt.cursor(current_cursor)
$tag_visited.add("#{index} linestart +1 chars", "#{index} lineend +1 chars") $tag_visited.add("#{idx} linestart +1 chars", "#{idx} lineend +1 chars")
end end
# 状態表示 # 状態表示
@ -819,7 +819,7 @@ end
# #
def aboutBox def aboutBox
Tk.messageBox('icon'=>'info', 'type'=>'ok', 'title'=>'About Widget Demo', Tk.messageBox('icon'=>'info', 'type'=>'ok', 'title'=>'About Widget Demo',
'message'=>"Ruby/Tk ウィジェットデモ Ver.1.5.2-jp\n\n" + 'message'=>"Ruby/Tk ウィジェットデモ Ver.1.5.3-jp\n\n" +
"based on demos of Tk8.1 -- 8.5 " + "based on demos of Tk8.1 -- 8.5 " +
"( Copyright:: " + "( Copyright:: " +
"(c) 1996-1997 Sun Microsystems, Inc. / " + "(c) 1996-1997 Sun Microsystems, Inc. / " +

View File

@ -0,0 +1,68 @@
#!/usr/bin/env ruby
# This script is a re-implementation of tktimer.rb with TkTimer(TkAfter) class.
require "tk"
root = TkRoot.new(:title=>'realtime timer sample')
f1 = TkFrame.new(:borderwidth=>2, :relief=>:ridge)
f1.pack(:side=>:bottom, :fill=>:both)
TkLabel.new(f1, :text=>'use TkTimer (TkAfter) class').pack(:anchor=>:center)
label1 = TkLabel.new(:parent=>f1, :relief=>:raised,
:width=>10).pack(:fill=>:both)
f2 = TkFrame.new(:borderwidth=>2, :relief=>:ridge)
f2.pack(:side=>:bottom, :fill=>:both)
TkLabel.new(f2, :text=>'use TkRTTimer class').pack
label2 = TkLabel.new(:parent=>f2, :relief=>:raised,
:width=>10).pack(:fill=>:both)
TkLabel.new(:text=>'Interval setting of each timer is 10 ms.',
:padx=>10, :pady=>5).pack
# define the procedure repeated by the TkTimer object
tick = proc{|aobj| #<== TkTimer object
cnt = aobj.return_value + 1 # return_value keeps a result of the last proc
label = aobj.current_args[0]
label.text format("%d.%02d", *(cnt.divmod(100)))
cnt #==> return value is kept by TkTimer object
# (so, can be send to the next repeat-proc)
}
timer1 = TkTimer.new(10, -1, [tick, label1]) # 10 ms interval
timer2 = TkRTTimer.new(10, -1, [tick, label2]) # 10 ms interval
timer1.start(0, proc{ label1.text('0.00'); 0 })
timer2.start(0, proc{ label2.text('0.00'); 0 })
b_start = TkButton.new(:text=>'Start', :state=>:disabled) {
pack(:side=>:left, :fill=>:both, :expand=>true)
}
b_stop = TkButton.new(:text=>'Stop', :state=>:normal) {
pack('side'=>'left', 'fill'=>'both', 'expand'=>'yes')
}
b_start.command {
timer1.continue
timer2.continue
b_stop.state(:normal)
b_start.state(:disabled)
}
b_stop.command {
timer1.stop
timer2.stop
b_start.state(:normal)
b_stop.state(:disabled)
}
TkButton.new(:text=>'Reset', :state=>:normal) {
command { timer1.reset; timer2.reset }
pack(:side=>:right, :fill=>:both, :expand=>:yes)
}
ev_quit = TkVirtualEvent.new('Control-c', 'Control-q')
Tk.root.bind(ev_quit, proc{Tk.exit}).focus
Tk.mainloop

View File

@ -581,5 +581,23 @@ if __FILE__ == $0
STDOUT.print("\n================================================\n\n") STDOUT.print("\n================================================\n\n")
STDOUT.print("\n========= reverse order (seek by lines) ========\n\n")
tio.seek(-1, IO::SEEK_END)
begin
begin
tio.seek(:linestart, IO::SEEK_CUR)
rescue
# maybe use old version of tk/textmark.rb
tio.seek('0 char linestart', IO::SEEK_CUR)
end
STDOUT.print(gets)
tio.seek('-1 char linestart -1 char', IO::SEEK_CUR)
end while(tio.pos > 0)
STDOUT.print("\n================================================\n\n")
tio.seek(0, IO::SEEK_END)
Tk.mainloop Tk.mainloop
end end

View File

@ -4,7 +4,7 @@
* Oct. 24, 1997 Y. Matsumoto * Oct. 24, 1997 Y. Matsumoto
*/ */
#define TCLTKLIB_RELEASE_DATE "2005-03-02" #define TCLTKLIB_RELEASE_DATE "2005-03-10"
#include "ruby.h" #include "ruby.h"
#include "rubysig.h" #include "rubysig.h"
@ -652,7 +652,7 @@ _timer_for_tcl(clientData)
/* struct invoke_queue *q, *tmp; */ /* struct invoke_queue *q, *tmp; */
/* VALUE thread; */ /* VALUE thread; */
DUMP1("called timer_for_tcl"); DUMP1("call _timer_for_tcl");
thr_crit_bup = rb_thread_critical; thr_crit_bup = rb_thread_critical;
rb_thread_critical = Qtrue; rb_thread_critical = Qtrue;
@ -1402,9 +1402,6 @@ lib_eventloop_ensure(args)
struct evloop_params *ptr = (struct evloop_params *)args; struct evloop_params *ptr = (struct evloop_params *)args;
volatile VALUE current_evloop = rb_thread_current(); volatile VALUE current_evloop = rb_thread_current();
Tk_DeleteTimerHandler(timer_token);
timer_token = (Tcl_TimerToken)NULL;
DUMP2("eventloop_ensure: current-thread : %lx", current_evloop); DUMP2("eventloop_ensure: current-thread : %lx", current_evloop);
DUMP2("eventloop_ensure: eventloop-thread : %lx", eventloop_thread); DUMP2("eventloop_ensure: eventloop-thread : %lx", eventloop_thread);
if (eventloop_thread != current_evloop) { if (eventloop_thread != current_evloop) {
@ -1422,7 +1419,12 @@ lib_eventloop_ensure(args)
break; break;
} }
if (NIL_P(eventloop_thread)) break; if (NIL_P(eventloop_thread)) {
Tk_DeleteTimerHandler(timer_token);
timer_token = (Tcl_TimerToken)NULL;
break;
}
if (RTEST(rb_funcall(eventloop_thread, ID_alive_p, 0, 0))) { if (RTEST(rb_funcall(eventloop_thread, ID_alive_p, 0, 0))) {
DUMP2("eventloop-enshure: wake up parent %lx", eventloop_thread); DUMP2("eventloop-enshure: wake up parent %lx", eventloop_thread);