diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-07-17 05:12:48 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-07-17 05:12:48 +0000 |
commit | c2fa49a9b453621dbe80630f3be88223fe10ab29 (patch) | |
tree | b7c9e8cc04031fd40639c05c2e96544d80934c1b /lib | |
parent | 20e305950e9fb53e1b1cb338f9b04b1be43fd7bb (diff) |
1.1c0
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@270 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tk.rb | 63 | ||||
-rw-r--r-- | lib/tkcanvas.rb | 14 | ||||
-rw-r--r-- | lib/tkdialog.rb | 91 | ||||
-rw-r--r-- | lib/tkfont.rb | 88 | ||||
-rw-r--r-- | lib/tktext.rb | 14 |
5 files changed, 238 insertions, 32 deletions
@@ -260,7 +260,18 @@ module TkComm end def tk_event_sequence(context) - context = context.join("><") if context.kind_of? Array + if context.kind_of? TkVirtualEvent + context = context.path + end + if context.kind_of? Array + context = context.collect{|ev| + if context.kind_of? TkVirtualEvent + ev.path + else + ev + end + }.join("><") + end if /,/ =~ context context = context.split(/\s*,\s*/).join("><") else @@ -303,7 +314,7 @@ module TkComm _bind_append tagOrClass, context, cmd, args end - def bindinfo(tagOrClass, context=nil) + def _bindinfo(tagOrClass, context=nil) if context (tk_call('bind', tagOrClass, "<#{tk_event_sequence(context)}>")).collect{|cmdline| @@ -320,6 +331,10 @@ module TkComm end end + def bindinfo(tagOrClass, context=nil) + _bindinfo tagOrClass, context + end + def pack(*args) TkPack.configure *args end @@ -414,10 +429,32 @@ module TkCore TclTkLib.mainloop end + def event_generate(window, context, keys=nil) + window = window.path if window.kind_of? TkObject + if keys + tk_call('event', 'generate', window, + "<#{tk_event_sequence(context)}>", *hash_kv(keys)) + else + tk_call('event', 'generate', window, "<#{tk_event_sequence(context)}>") + end + end + def messageBox(keys) tk_call 'tk_messageBox', *hash_kv(keys) end + def getOpenFile(keys) + tk_call 'tk_getOpenFile', *hash_kv(keys) + end + + def getSaveFile(keys) + tk_call 'tk_getSaveFile', *hash_kv(keys) + end + + def chooseColor(keys) + tk_call 'tk_chooseColor', *hash_kv(keys) + end + def tk_call(*args) print args.join(" "), "\n" if $DEBUG args.filter {|x|_get_eval_string(x)} @@ -629,8 +666,8 @@ class TkVariable if INTERP._eval(format('global %s; array exists %s', @id, @id)) != "1" raise else - Hash(*tk_tcl2ruby(INTERP._eval(format('global %s; array get %s', - @id, @id)))) + Hash[*tk_tcl2ruby(INTERP._eval(format('global %s; array get %s', + @id, @id)))] end end end @@ -1528,6 +1565,19 @@ class TkObject<TkKernel _bind_append path, context, cmd, args end + def bindinfo(context=nil) + _bindinfo path, context + end + + def event_generate(context, keys=nil) + if keys + tk_call('event', 'generate', path, + "<#{tk_event_sequence(context)}>", *hash_kv(keys)) + else + tk_call('event', 'generate', path, "<#{tk_event_sequence(context)}>") + end + end + def tk_trace_variable(v) unless v.kind_of?(TkVariable) fail ArgumentError, format("requires TkVariable given %s", v.type) @@ -1557,7 +1607,7 @@ module TkClassBind end def bindinfo(context=nil) - Tk.bind to_eval, context + Tk.bindinfo to_eval, context end end @@ -1651,7 +1701,7 @@ class TkWindow<TkObject when 'global' tk_call 'grab', 'set', '-global', path else - val = tk_call('grab', arg[0], path) + val = tk_call('grab', args[0], path) end case args[0] when 'current' @@ -2137,3 +2187,4 @@ autoload :TkMenubar, 'tkmenubar' autoload :TkAfter, 'tkafter' autoload :TkPalette, 'tkpalette' autoload :TkFont, 'tkfont' +autoload :TkVirtualEvent, 'tkvirtevent' diff --git a/lib/tkcanvas.rb b/lib/tkcanvas.rb index 613e97af38..3beb2ff1dc 100644 --- a/lib/tkcanvas.rb +++ b/lib/tkcanvas.rb @@ -60,8 +60,11 @@ module TkTreatCItemFont fobj = tagfontobj(tagOrId) if ltn.kind_of? TkFont conf = {} - ltn.latin_configinfo.each{|key,val| conf[key] = val} - if keys + ltn.latin_configinfo.each{|key,val| conf[key] = val if val != []} + if conf == {} + fobj.latin_replace(ltn) + fobj.latin_configure(keys) if keys + elsif keys fobj.latin_configure(conf.update(keys)) else fobj.latin_configure(conf) @@ -76,8 +79,11 @@ module TkTreatCItemFont fobj = tagfontobj(tagOrId) if knj.kind_of? TkFont conf = {} - knj.kanji_configinfo.each{|key,val| conf[key] = val} - if keys + knj.kanji_configinfo.each{|key,val| conf[key] = val if val != []} + if conf == {} + fobj.kanji_replace(knj) + fobj.kanji_configure(keys) if keys + elsif keys fobj.kanji_configure(conf.update(keys)) else fobj.kanji_configure(conf) diff --git a/lib/tkdialog.rb b/lib/tkdialog.rb index 011d431951..1133db6ae9 100644 --- a/lib/tkdialog.rb +++ b/lib/tkdialog.rb @@ -1,15 +1,84 @@ require "tk" class TkDialog < TkWindow + extend Tk + # initialize tk_dialog - def initialize - super + def initialize(keys = nil) + super() @var = TkVariable.new id = @var.id - INTERP._eval('eval {global '+id+';'+ + + @title = title + + @message = message + @message_config = message_config + + @bitmap = bitmap + @bitmap_config = message_config + + @default_button = default_button + + @buttons = buttons + @button_configs = proc{|num| button_configs num} + + if keys.kind_of? Hash + @title = keys['title'] if keys['title'] + @message = keys['message'] if keys['message'] + @bitmap = keys['bitmap'] if keys['bitmap'] + @default_button = keys['default'] if keys['default'] + @buttons = keys['buttons'] if keys['buttons'] + + @command = keys['prev_command'] + + @message_config = keys['message_config'] if keys['message_config'] + @bitmap_config = keys['bitmap_config'] if keys['bitmap_config'] + @button_configs = keys['button_configs'] if keys['button_configs'] + end + + if @title.include? ?\s + @title = '{' + @title + '}' + end + + @buttons = tk_split_list(@buttons) if @buttons.kind_of? String + @buttons = @buttons.collect{|s| + if s.kind_of? Array + s = s.join(' ') + end + if s.include? ?\s + '{' + s + '}' + else + s + end + } + + config = "" + if @message_config.kind_of? Hash + config << format("%s.msg configure %s\n", + @path, hash_kv(@message_config).join(' ')) + end + if @bitmap_config.kind_of? Hash + config << format("%s.msg configure %s\n", + @path, hash_kv(@bitmap_config).join(' ')) + end + if @button_configs.kind_of? Proc + @buttons.each_index{|i| + if (c = @button_configs.call(i)).kind_of? Hash + config << format("%s.button%s configure %s\n", + @path, i, hash_kv(c).join(' ')) + end + } + end + config = 'after idle {' + config + '};' if config != "" + + if @command.kind_of? Proc + @command.call(self) + end + + INTERP._eval('eval {global '+id+';'+config+ 'set '+id+' [tk_dialog '+ - @path+" "+title+" \"#{message}\" "+bitmap+" "+ - String(default_button)+" "+buttons+']}') + @path+" "+@title+" {#{@message}} "+@bitmap+" "+ + String(@default_button)+" "+@buttons.join(' ')+']}') end def value return @var.value.to_i @@ -25,14 +94,24 @@ class TkDialog < TkWindow def message return "MESSAGE" end + def message_config + return nil + end def bitmap return "info" end + def bitmap_config + return nil + end def default_button return 0 end def buttons - return "BUTTON1 BUTTON2" + #return "BUTTON1 BUTTON2" + return ["BUTTON1", "BUTTON2"] + end + def button_configs(num) + return nil end end diff --git a/lib/tkfont.rb b/lib/tkfont.rb index 0d926f00c8..86114c6b62 100644 --- a/lib/tkfont.rb +++ b/lib/tkfont.rb @@ -65,14 +65,27 @@ class TkFont case (Tk::TK_VERSION) when /^4\.*/ conf = tk_split_list(tk_call(*args)) - ltn = conf.assoc('font')[4] - ltn = nil if ltn == [] - knj = conf.assoc('kanjifont')[4] - knj = nil if knj == [] - TkFont.new(ltn, knj).call_font_configure(path, *args) + if font_inf = conf.assoc('-font') + ltn = font_inf[4] + ltn = nil if ltn == [] + else + #ltn = nil + raise RuntimeError, "unknown option '-font'" + end + if font_inf = conf.assoc('-kanjifont') + knj = font_inf[4] + knj = nil if knj == [] + else + knj = nil + end + TkFont.new(ltn, knj).call_font_configure(path, *(args + [{}])) when /^8\.*/ - fnt = tk_split_list(tk_call(*(args + ['-font'])))[4] + conf = tk_split_list(tk_call(*args)) + unless font_inf = conf.assoc('-font') + raise RuntimeError, "unknown option '-font'" + end + fnt = font_inf[4] if fnt == [] TkFont.new(nil, nil).call_font_configure(path, *(args + [{}])) else @@ -443,6 +456,28 @@ class TkFont end end + def delete_core_tk4x + Tk_FontNameTBL[@id] = nil + Tk_FontUseTBL.delete_if{|key,value| value == self} + end + + def delete_core_tk8x + begin + tk_call('font', 'delete', @latinfont) + rescue + end + begin + tk_call('font', 'delete', @kanjifont) + rescue + end + begin + tk_call('font', 'delete', @compoundfont) + rescue + end + Tk_FontNameTBL[@id] = nil + Tk_FontUseTBL.delete_if{|key,value| value == self} + end + def latin_replace_core_tk4x(ltn) create_latinfont_tk4x(ltn) @compoundfont[0] = [@latinfont] if JAPANIZED_TK @@ -453,9 +488,17 @@ class TkFont if w.include?(';') win, tag = w.split(';') winobj = tk_tcl2ruby(win) - winobj.tagfont_configure(tag, {'font'=>@latinfont}) +# winobj.tagfont_configure(tag, {'font'=>@latinfont}) + if winobj.kind_of? TkText + tk_call(win, 'tag', 'configure', tag, '-font', @latinfont) + elsif winobj.kind_of? TkCanvas + tk_call(win, 'itemconfigure', tag, '-font', @latinfont) + else + raise RuntimeError, "unknown widget type" + end else - tk_tcl2ruby(w).configure('font', @latinfont) +# tk_tcl2ruby(w).font_configure('font'=>@latinfont) + tk_call(w, 'configure', '-font', @latinfont) end rescue Tk_FontUseTBL[w] = nil @@ -477,9 +520,17 @@ class TkFont if w.include?(';') win, tag = w.split(';') winobj = tk_tcl2ruby(win) - winobj.tagfont_configure(tag, {'kanjifont'=>@kanjifont}) +# winobj.tagfont_configure(tag, {'kanjifont'=>@kanjifont}) + if winobj.kind_of? TkText + tk_call(win, 'tag', 'configure', tag, '-kanjifont', @kanjifont) + elsif winobj.kind_of? TkCanvas + tk_call(win, 'itemconfigure', tag, '-kanjifont', @kanjifont) + else + raise RuntimeError, "unknown widget type" + end else - tk_tcl2ruby(w).configure('kanjifont', @kanjifont) +# tk_tcl2ruby(w).font_configure('kanjifont'=>@kanjifont) + tk_call(w, 'configure', '-kanjifont', @kanjifont) end rescue Tk_FontUseTBL[w] = nil @@ -490,7 +541,10 @@ class TkFont end def latin_replace_core_tk8x(ltn) - tk_call('font', 'delete', @latinfont) + begin + tk_call('font', 'delete', @latinfont) + rescue + end create_latinfont(ltn) self end @@ -498,7 +552,10 @@ class TkFont def kanji_replace_core_tk80(knj) return self unless JAPANIZED_TK - tk_call('font', 'delete', @kanjifont) + begin + tk_call('font', 'delete', @kanjifont) + rescue + end create_kanjifont(knj) self end @@ -575,6 +632,7 @@ class TkFont alias actual_core actual_core_tk4x alias configure_core configure_core_tk4x alias configinfo_core configinfo_core_tk4x + alias delete_core delete_core_tk4x alias latin_replace_core latin_replace_core_tk4x alias kanji_replace_core kanji_replace_core_tk4x alias measure_core measure_core_tk4x @@ -587,6 +645,7 @@ class TkFont alias actual_core actual_core_tk8x alias configure_core configure_core_tk8x alias configinfo_core configinfo_core_tk8x + alias delete_core delete_core_tk8x alias latin_replace_core latin_replace_core_tk8x alias kanji_replace_core kanji_replace_core_tk80 alias measure_core measure_core_tk8x @@ -599,6 +658,7 @@ class TkFont alias actual_core actual_core_tk8x alias configure_core configure_core_tk8x alias configinfo_core configinfo_core_tk8x + alias delete_core delete_core_tk8x alias latin_replace_core latin_replace_core_tk8x alias kanji_replace_core kanji_replace_core_tk81 alias measure_core measure_core_tk8x @@ -715,6 +775,10 @@ class TkFont configinfo_core(@compoundfont, slot) end + def delete + delete_core + end + def latin_configure(slot, value=None) if JAPANIZED_TK configure_core(@latinfont, slot, value) diff --git a/lib/tktext.rb b/lib/tktext.rb index 8ffc626046..e0b4f9641e 100644 --- a/lib/tktext.rb +++ b/lib/tktext.rb @@ -58,8 +58,11 @@ module TkTreatTextTagFont fobj = tagfontobj(tag) if ltn.kind_of? TkFont conf = {} - ltn.latin_configinfo.each{|key,val| conf[key] = val} - if keys + ltn.latin_configinfo.each{|key,val| conf[key] = val if val != []} + if conf == {} + fobj.latin_replace(ltn) + fobj.latin_configure(keys) if keys + elsif keys fobj.latin_configure(conf.update(keys)) else fobj.latin_configure(conf) @@ -74,8 +77,11 @@ module TkTreatTextTagFont fobj = tagfontobj(tag) if knj.kind_of? TkFont conf = {} - knj.kanji_configinfo.each{|key,val| conf[key] = val} - if keys + knj.kanji_configinfo.each{|key,val| conf[key] = val if val != []} + if conf == {} + fobj.kanji_replace(knj) + fobj.kanji_configure(keys) if keys + elsif keys fobj.kanji_configure(conf.update(keys)) else fobj.kanji_configure(conf) |