summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-07-29 09:50:58 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-07-29 09:50:58 +0000
commit2562004338bc2694a7d8da75f4effcb9aa889641 (patch)
tree0af9582deace7d436b411552640555f90d7cd9fa /lib
parent3b0fec9a5f966fd7ae26bc7b84877fa7209d8605 (diff)
sync ev
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@280 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/tempfile.rb24
-rw-r--r--lib/tk.rb37
-rw-r--r--lib/tkcanvas.rb2
-rw-r--r--lib/tkfont.rb46
4 files changed, 74 insertions, 35 deletions
diff --git a/lib/tempfile.rb b/lib/tempfile.rb
index 9f23075..2de1ebd 100644
--- a/lib/tempfile.rb
+++ b/lib/tempfile.rb
@@ -17,41 +17,44 @@ class Tempfile < SimpleDelegator
def Tempfile.callback(path)
lambda{
- print "removing ", path, "..."
+ print "removing ", path, "..." if $DEBUG
if File.exist?(path)
File.unlink(path)
end
if File.exist?(path + '.lock')
- File.unlink(path + '.lock')
+ File.rmdir(path + '.lock')
end
- print "done\n"
+ print "done\n" if $DEBUG
}
end
def initialize(basename, tmpdir = '/tmp')
umask = File.umask(0177)
+ tmpname = lock = nil
begin
n = 0
while true
begin
- @tmpname = sprintf('%s/%s.%d.%d', tmpdir, basename, $$, n)
- unless File.exist?(@tmpname)
- File.symlink(tmpdir, @tmpname + '.lock')
+ tmpname = sprintf('%s/%s.%d.%d', tmpdir, basename, $$, n)
+ lock = tmpname + '.lock'
+ unless File.exist?(lock)
+ Dir.mkdir(lock)
break
end
rescue
- raise "cannot generate tmpfile `%s'" % @tmpname if n >= Max_try
+ raise "cannot generate tmpfile `%s'" % tmpname if n >= Max_try
#sleep(1)
end
n += 1
end
- @clean_files = Tempfile.callback(@tmpname)
+ @clean_files = Tempfile.callback(tmpname)
ObjectSpace.define_finalizer(self, @clean_files)
- @tmpfile = File.open(@tmpname, 'w+')
+ @tmpname = tmpname
+ @tmpfile = File.open(tmpname, 'w+')
super(@tmpfile)
- File.unlink(@tmpname + '.lock')
+ Dir.rmdir(lock)
ensure
File.umask(umask)
end
@@ -78,6 +81,7 @@ class Tempfile < SimpleDelegator
end
if __FILE__ == $0
+# $DEBUG = true
f = Tempfile.new("foo")
f.print("foo\n")
f.close
diff --git a/lib/tk.rb b/lib/tk.rb
index 0bc3107..13cb49b 100644
--- a/lib/tk.rb
+++ b/lib/tk.rb
@@ -548,6 +548,19 @@ module Tk
tk_call 'bell'
end
+ def Tk.focus(display=nil)
+ if display == nil
+ r = tk_call('focus')
+ else
+ r = tk_call('focus', '-displayof', display)
+ end
+ tk_tcl2ruby(r)
+ end
+
+ def Tk.focus_lastfor(win)
+ tk_tcl2ruby(tk_call('focus', '-lastfor', win))
+ end
+
def toUTF8(str,encoding)
INTERP._toUTF8(str,encoding)
end
@@ -636,9 +649,15 @@ module Tk
def positionfrom(*args)
tk_call 'wm', 'positionfrom', path, *args
end
- def protocol(name, func=None)
- func = install_cmd(func) if not func == None
- tk_call 'wm', 'command', path, name, func
+ def protocol(name=nil, cmd=nil)
+ if cmd
+ tk_call('wm', 'protocol', path, name, cmd)
+ elsif name
+ result = tk_call('wm', 'protocol', path, name)
+ (result == "")? nil : tk_tcl2ruby(result)
+ else
+ tk_split_simplelist(tk_call('wm', 'protocol', path))
+ end
end
def resizable(*args)
w = tk_call('wm', 'resizable', path, *args)
@@ -1402,8 +1421,8 @@ module TkOption
def clear
tk_call 'option', 'clear'
end
- def get win, classname, name
- tk_call 'option', 'get', classname, name
+ def get win, name, klass
+ tk_call 'option', 'get', win ,name, klass
end
def readfile file, pri=None
tk_call 'option', 'readfile', file, pri
@@ -1735,8 +1754,12 @@ class TkWindow<TkObject
list(tk_call('place', 'slaves', epath))
end
- def focus
- tk_call 'focus', path
+ def focus(force=false)
+ if force
+ tk_call 'focus', '-force', path
+ else
+ tk_call 'focus', path
+ end
self
end
diff --git a/lib/tkcanvas.rb b/lib/tkcanvas.rb
index d5ddafd..c4a7478 100644
--- a/lib/tkcanvas.rb
+++ b/lib/tkcanvas.rb
@@ -310,7 +310,7 @@ class TkCanvas<TkWindow
|| key == 'latinfont' || key == 'asciifont' )
tagfont_configure(tagid(tagOrId), {key=>value})
else
- tk_call 'itemconfigure', tagid(tagOrId), "-#{key}", value
+ tk_send 'itemconfigure', tagid(tagOrId), "-#{key}", value
end
end
end
diff --git a/lib/tkfont.rb b/lib/tkfont.rb
index 9c2f4c1..1c11f8f 100644
--- a/lib/tkfont.rb
+++ b/lib/tkfont.rb
@@ -42,7 +42,7 @@ class TkFont
r | []
when /^8\.*/
- list(tk_call('font', 'names'))
+ tk_split_simplelist(tk_call('font', 'names'))
end
end
@@ -89,10 +89,14 @@ class TkFont
if fnt == []
TkFont.new(nil, nil).call_font_configure(path, *(args + [{}]))
else
- compound = Hash[*list(tk_call('font', 'configure',
- fnt))].collect{|key,value|
- [key[1..-1], value]
- }.assoc('compound')[1]
+ begin
+ compound = Hash[*list(tk_call('font', 'configure',
+ fnt))].collect{|key,value|
+ [key[1..-1], value]
+ }.assoc('compound')[1]
+ rescue
+ compound = []
+ end
if compound == []
TkFont.new(fnt, DEFAULT_KANJI_FONT_NAME) \
.call_font_configure(path, *(args + [{}]))
@@ -156,14 +160,19 @@ class TkFont
elsif font.kind_of? Array
finfo = {}
finfo['family'] = font[0].to_s
- if font[1] && font[1] != '0' && font[1] =~ /^(|\+|-)([0-9]+)$/
- if $1 == '-'
- finfo['pixels'] = font[1].to_s
+ if font[1]
+ fsize = font[1].to_s
+ if fsize != '0' && fsize =~ /^(|\+|-)([0-9]+)$/
+ if $1 == '-'
+ finfo['pixels'] = $2
+ else
+ finfo['points'] = $2
+ end
else
- finfo['points'] = font[1].to_s
+ finfo['points'] = '13'
end
end
- finfo[2..-1].each{|style|
+ font[2..-1].each{|style|
case (style)
when 'normal'
finfo['weight'] = style
@@ -199,16 +208,19 @@ class TkFont
elsif font.kind_of? Array
finfo = {}
finfo['family'] = font[0].to_s
- if font[1] && font[1] != '0' && font[1] =~ /^(|\+|-)([0-9]+)$/
- if $1 == '-'
- finfo['pixels'] = $2
+ if font[1]
+ fsize = font[1].to_s
+ if fsize != '0' && fsize =~ /^(|\+|-)([0-9]+)$/
+ if $1 == '-'
+ finfo['pixels'] = $2
+ else
+ finfo['points'] = $2
+ end
else
- finfo['points'] = $2
+ finfo['points'] = '13'
end
- else
- finfo['points'] = '13'
end
- finfo[2..-1].each{|style|
+ font[2..-1].each{|style|
case (style)
when 'normal'
finfo['weight'] = style