Extended maintenance of Ruby 1.9.3 ended on February 23, 2015. Read more
BasicObject
autoload
A photo is an image whose pixels can display any color or be transparent. At present, only GIF and PPM/PGM formats are supported, but an interface exists to allow additional image file formats to be added easily.
This class documentation is a copy from the original Tcl/Tk at www.tcl.tk/man/tcl8.5/TkCmd/photo.htm with some rewrited parts.
class TkMsgCatalog
dialog for warning
#<RDoc::Comment:0x00000001eea998>
#<RDoc::Comment:0x00000001f25250>
# File tk/lib/tk/autoload.rb, line 18
def TkGrid(*args); TkGrid.configure(*args); end
# File tk/lib/tk/autoload.rb, line 21
def TkPack(*args); TkPack.configure(*args); end
# File tk/lib/tk/autoload.rb, line 24
def TkPlace(*args); TkPlace.configure(*args); end
# File tk/lib/tkextlib/pkg_checker.rb, line 91
def check_pkg(file, verbose=false)
pkg_list = get_pkg_list(file)
error_list = []
success_list = {}
pkg_list.each{|name, type|
next if success_list[name]
begin
case type
when :package
ver = TkPackage.require(name)
success_list[name] = ver
error_list.delete_if{|n, t| n == name}
when :library
Tk.load_tcllibrary(name)
success_list[name] = :library
error_list.delete_if{|n, t| n == name}
when :script
Tk.load_tclscript(name)
success_list[name] = :script
error_list.delete_if{|n, t| n == name}
when :require_ruby_lib
require name
end
rescue => e
if verbose
error_list << [name, type, e.message]
else
error_list << [name, type]
end
end
}
success_list.dup.each{|name, ver|
unless ver.kind_of?(String)
begin
ver = TkPackage.require(name)
sccess_list[name] = ver
rescue
end
end
}
[success_list, error_list]
end
# File tk/old-extconf.rb, line 79
def check_tcltk_version(version)
return [nil, nil] unless version
version = version.strip
tclver = version.dup
tkver = version.dup
major = dot = minor = dot = plvl = ext = nil
if version =~ /^(\d)(\.?)(\d)(\.?)(\d*)(.*)$/
major = $1; minor_dot = $2; minor = $3; plvl_dot = $4; plvl = $5; ext = $6
dot = ! minor_dot.empty?
if plvl_dot.empty? && ! plvl.empty?
minor << plvl
end
elsif version =~ /^(\d)(\.?)(\d?)(.*)$/
major = $1; minor_dot = $2; minor = $3; ext = $4
dot = ! minor_dot.empty?
else # unknown -> believe user
return [tclver, tkver]
end
# check Tcl7.6 / Tk4.2 ?
if major == "7" # Tcl7.6 ( not support Tclversion < 7.6 )
# Tk4.2
tkver = "4" + ((dot)? ".": "") + ((minor.empty)? "": "2") + ext
elsif major == "4" # Tk4.2 ( not support Tkversion < 4.2 )
# Tcl7.6
tclver = "7" + ((dot)? ".": "") + ((minor.empty)? "": "6") + ext
end
[tclver, tkver]
end
# File tk/old-extconf.rb, line 229
def find_X11(*opt_paths)
default_paths =
[ "/usr/X11/lib", "/usr/lib/X11", "/usr/X11R6/lib", "/usr/openwin/lib" ]
paths = opt_paths.compact.concat(default_paths)
st = find_library("X11", "XOpenDisplay", *paths)
unless st
puts("Warning:: cannot find X11 library. tcltklib will not be compiled (tcltklib is disabled on your Ruby == Ruby/Tk will not work). Please check configure options. If your Tcl/Tk don't require X11, please try --without-X11.")
end
st
end
# File tk/old-extconf.rb, line 14
def find_framework(tcl_hdr, tk_hdr)
if framework_dir = with_config("tcltk-framework")
paths = [framework_dir]
else
unless tcl_hdr || tk_hdr ||
enable_config("tcltk-framework", false) ||
enable_config("mac-tcltk-framework", false)
return false
end
paths = ["/Library/Frameworks", "/System/Library/Frameworks"]
end
checking_for('Tcl/Tk Framework') {
paths.find{|dir|
dir.strip!
dir.chomp!('/')
(tcl_hdr || FileTest.directory?(dir + "/Tcl.framework/") ) &&
(tk_hdr || FileTest.directory?(dir + "/Tk.framework/") )
}
}
end
# File tk/old-extconf.rb, line 114
def find_tcl(tcllib, stubs, version, *opt_paths)
default_paths = ["/usr/local/lib", "/usr/pkg/lib", "/usr/lib"]
default_paths << "/Tcl/lib" # default for ActiveTcl
if (paths = opt_paths.compact).empty?
paths = default_paths
end
if stubs
func = "Tcl_InitStubs"
lib = "tclstub"
else
func = "Tcl_FindExecutable"
lib = "tcl"
end
if version && ! version.empty?
versions = [version]
else
versions = %w[8.7 8.6 8.5 8.4 8.3 8.2 8.1 8.0 7.6]
end
if tcllib
st = find_library(tcllib, func, *paths)
else
st = versions.find { |ver|
find_library("#{lib}#{ver}", func, *paths) or
find_library("#{lib}#{ver.delete('.')}", func, *paths) or
find_library("#{lib}#{ver}g", func, *paths) or
find_library("#{lib}#{ver.delete('.')}g", func, *paths) or
find_library("tcl#{ver}", func, *paths) or
find_library("tcl#{ver.delete('.')}", func, *paths) or
find_library("tcl#{ver}g", func, *paths) or
find_library("tcl#{ver.delete('.')}g", func, *paths)
} || (!version && find_library(lib, func, *paths))
end
unless st
puts("Warning:: cannot find Tcl library. tcltklib will not be compiled (tcltklib is disabled on your Ruby == Ruby/Tk will not work). Please check configure options.")
end
st
end
# File tk/old-extconf.rb, line 200
def find_tcltk_header(tclver, tkver)
base_dir = ['/usr/local/include', '/usr/pkg/include', '/usr/include']
base_dir << '/Tcl/include' # default for ActiveTcl
unless have_tcl_h = have_header('tcl.h')
if tclver && ! tclver.empty?
versions = [tclver]
else
versions = %w[8.7 8.6 8.5 8.4 8.3 8.2 8.1 8.0 7.6]
end
paths = base_dir.dup
versions.each{|ver| paths.concat(base_dir.map{|dir| dir + '/tcl' + ver})}
have_tcl_h = find_header('tcl.h', *paths)
end
unless have_tk_h = have_header("tk.h")
if tkver && ! tkver.empty?
versions = [tkver]
else
versions = %w[8.7 8.6 8.5 8.4 8.3 8.2 8.1 8.0 4.2]
end
paths = base_dir.dup
versions.each{|ver| paths.concat(base_dir.map{|dir| dir + '/tk' + ver})}
have_tk_h = find_header('tk.h', *paths)
end
have_tcl_h && have_tk_h
end
# File tk/old-extconf.rb, line 157
def find_tk(tklib, stubs, version, *opt_paths)
default_paths = ["/usr/local/lib", "/usr/pkg/lib", "/usr/lib"]
default_paths << "/Tcl/lib" # default for ActiveTcl
if (paths = opt_paths.compact).empty?
paths = default_paths
end
if stubs
func = "Tk_InitStubs"
lib = "tkstub"
else
func = "Tk_Init"
lib = "tk"
end
if version && ! version.empty?
versions = [version]
else
versions = %w[8.7 8.6 8.5 8.4 8.3 8.2 8.1 8.0 4.2]
end
if tklib
st = find_library(tklib, func, *paths)
else
st = versions.find { |ver|
find_library("#{lib}#{ver}", func, *paths) or
find_library("#{lib}#{ver.delete('.')}", func, *paths) or
find_library("#{lib}#{ver}g", func, *paths) or
find_library("#{lib}#{ver.delete('.')}g", func, *paths) or
find_library("tk#{ver}", func, *paths) or
find_library("tk#{ver.delete('.')}", func, *paths) or
find_library("tk#{ver}g", func, *paths) or
find_library("tk#{ver.delete('.')}g", func, *paths)
} || (!version && find_library(lib, func, *paths))
end
unless st
puts("Warning:: cannot find Tk library. tcltklib will not be compiled (tcltklib is disabled on your Ruby == Ruby/Tk will not work). Please check configure options.")
end
st
end
# File tk/lib/tkextlib/pkg_checker.rb, line 66
def get_pkg_list(file)
pkg_list = []
File.foreach(file){|l|
if l =~ /^(?:[^#]+\s|\s*)(?:|;\s*)TkPackage\s*\.\s*require\s*\(?\s*(["'])((\w|:)+)\1/
pkg = [$2, :package]
pkg_list << pkg unless pkg_list.member?(pkg)
end
if l =~ /^(?:[^#]+\s|\s*)(?:|;\s*)Tk\s*\.\s*load_tcllibrary\s*\(?\s*(["'])((\w|:)+)\1/
pkg = [$2, :library]
pkg_list << pkg unless pkg_list.member?(pkg)
end
if l =~ /^(?:[^#]+\s|\s*)(?:|;\s*)Tk\s*\.\s*load_tclscript\s*\(?\s*(["'])((\w|:)+)\1/
pkg = [$2, :script]
pkg_list << pkg unless pkg_list.member?(pkg)
end
if l =~ /^(?:[^#]+\s|\s*)(?:|;\s*)require\s*\(?\s*(["'])((\w|\/|:)+)\1/
pkg = [$2, :require_ruby_lib]
pkg_list << pkg unless pkg_list.member?(pkg)
end
}
pkg_list
end
# File tk/lib/tkextlib/pkg_checker.rb, line 16
def help_msg
print "Usage: #{$0} [-l] [-v] [-h] [--] [dir]\n"
print "\tIf dir is omitted, check the directry that this command exists.\n"
print "\tAvailable options are \n"
print "\t -l : Add dir to $LOAD_PATH\n"
print "\t (If dir == '<parent>/tkextlib', add <parent> also.)\n"
print "\t -v : Verbose mode (show reason of fail)\n"
print "\t -h : Show this message\n"
print "\t -- : End of options\n"
end
# File tk/lib/multi-tk.rb, line 2075
def method_missing(id, *args)
begin
has_top = (top = MultiTkIp.__getip.__pseudo_toplevel) &&
top.respond_to?(:pseudo_toplevel_evaluable?) &&
top.pseudo_toplevel_evaluable? &&
top.respond_to?(id)
rescue Exception => e
has_top = false
end
if has_top
top.__send__(id, *args)
else
__method_missing_alias_for_MultiTkIp__(id, *args)
end
end
# File tk/old-extconf.rb, line 67
def parse_tclConfig(file)
# check tclConfig.sh/tkConfig.sh
tbl = {}
IO.foreach(file){|line|
line.strip!
next if line !~ /^([^\#=][^=]*)=(['"]|)(.*)\2$/
key, val = $1, $3
tbl[key] = val.gsub(/\$\{([^}]+)\}/){|s| tbl[$1]} rescue nil
}
tbl
end
# File tk/old-extconf.rb, line 240
def pthread_check()
tcl_major_ver = nil
tcl_minor_ver = nil
# Is tcl-thread given by user ?
case enable_config("tcl-thread")
when true
tcl_enable_thread = true
when false
tcl_enable_thread = false
else
tcl_enable_thread = nil
end
if (tclConfig = with_config("tclConfig-file"))
if tcl_enable_thread == true
puts("Warning: --with-tclConfig-file option is ignored, because --enable-tcl-thread option is given.")
elsif tcl_enable_thread == false
puts("Warning: --with-tclConfig-file option is ignored, because --disable-tcl-thread option is given.")
else
# tcl-thread is unknown and tclConfig.sh is given
begin
tbl = parse_tclConfig(tclConfig)
if tbl['TCL_THREADS']
tcl_enable_thread = (tbl['TCL_THREADS'] == "1")
else
tcl_major_ver = tbl['TCL_MAJOR_VERSION'].to_i
tcl_minor_ver = tbl['TCL_MINOR_VERSION'].to_i
if tcl_major_ver < 8 || (tcl_major_ver == 8 && tcl_minor_ver == 0)
tcl_enable_thread = false
end
end
if tcl_enable_thread == nil
# cannot find definition
if tcl_major_ver
puts("Warning: '#{tclConfig}' doesn't include TCL_THREADS definition.")
else
puts("Warning: '#{tclConfig}' may not be a tclConfig file.")
end
tclConfig = false
end
rescue Exception
puts("Warning: fail to read '#{tclConfig}'!! --> ignore the file")
tclConfig = false
end
end
end
if tcl_enable_thread == nil && !tclConfig
# tcl-thread is unknown and tclConfig is unavailable
begin
try_run_available = try_run("int main() { exit(0); }")
rescue Exception
# cannot try_run. Is CROSS-COMPILE environment?
puts(%Q'\
*****************************************************************************
**
** PTHREAD SUPPORT CHECK WARNING:
**
** We cannot check the consistency of pthread support between Ruby
** and the Tcl/Tk library in your environment (are you perhaps
** cross-compiling?). If pthread support for these 2 packages is
** inconsistent you may find you get errors when running Ruby/Tk
** (e.g. hangs or segmentation faults). We strongly recommend
** you to check the consistency manually.
**
*****************************************************************************
')
return true
end
end
if tcl_enable_thread == nil
# tcl-thread is unknown
if try_run("#include <tcl.h>
int main() {
Tcl_Interp *ip;
ip = Tcl_CreateInterp();
exit((Tcl_Eval(ip, "set tcl_platform(threaded)") == TCL_OK)? 0: 1);
}
")
tcl_enable_thread = true
elsif try_run("#include <tcl.h>
static Tcl_ThreadDataKey dataKey;
int main() { exit((Tcl_GetThreadData(&dataKey, 1) == dataKey)? 1: 0); }
")
tcl_enable_thread = true
else
tcl_enable_thread = false
end
end
# check pthread mode
if (macro_defined?('HAVE_NATIVETHREAD', '#include "ruby.h"'))
# ruby -> enable
unless tcl_enable_thread
# ruby -> enable && tcl -> disable
puts(%Q'\
*****************************************************************************
**
** PTHREAD SUPPORT MODE WARNING:
**
** Ruby is compiled with --enable-pthread, but your Tcl/Tk library
** seems to be compiled without pthread support. Although you can
** create the tcltklib library, this combination may cause errors
** (e.g. hangs or segmentation faults). If you have no reason to
** keep the current pthread support status, we recommend you reconfigure
** and recompile the libraries so that both or neither support pthreads.
**
** If you want change the status of pthread support, please recompile
** Ruby without "--enable-pthread" configure option or recompile Tcl/Tk
** with "--enable-threads" configure option (if your Tcl/Tk is later
** than or equal to Tcl/Tk 8.1).
**
*****************************************************************************
')
end
# ruby -> enable && tcl -> enable/disable
if tcl_enable_thread
$CPPFLAGS += ' -DWITH_TCL_ENABLE_THREAD=1'
else
$CPPFLAGS += ' -DWITH_TCL_ENABLE_THREAD=0'
end
return true
else
# ruby -> disable
if tcl_enable_thread
# ruby -> disable && tcl -> enable
puts(%Q'\
*****************************************************************************
**
** PTHREAD SUPPORT MODE ERROR:
**
** Ruby is not compiled with --enable-pthread, but your Tcl/Tk
** library seems to be compiled with pthread support. This
** combination may cause frequent hang or segmentation fault
** errors when Ruby/Tk is working. We recommend that you NEVER
** create the library with such a combination of pthread support.
**
** Please recompile Ruby with the "--enable-pthread" configure option
** or recompile Tcl/Tk with the "--disable-threads" configure option.
**
*****************************************************************************
')
$CPPFLAGS += ' -DWITH_TCL_ENABLE_THREAD=1'
return false
else
# ruby -> disable && tcl -> disable
$CPPFLAGS += ' -DWITH_TCL_ENABLE_THREAD=0'
return true
end
end
end
# File tk/lib/tkextlib/pkg_checker.rb, line 143
def subdir_check(dir, verbose=false)
Dir.foreach(dir){|f|
next if f == '.' || f == '..'
if File.directory?(f)
subdir_check(File.join(dir, f))
elsif File.extname(f) == '.rb'
path = File.join(dir, f)
suc, err = check_pkg(path, verbose)
if err.empty?
print 'Ready : ', path, ' : require->', suc.inspect, "\n"
else
print '*LACK : ', path, ' : require->', suc.inspect,
' FAIL->', err.inspect, "\n"
end
end
}
end
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.