lib/ffi-tk.rb in ffi-tk-2010.03 vs lib/ffi-tk.rb in ffi-tk-2010.06

- old
+ new

@@ -2,46 +2,67 @@ require 'ffi' $LOAD_PATH.unshift File.dirname(__FILE__) module Tk - LIBPATH = { tcl: [], tk: [] } + TCL_LIBPATH = ENV['TCL_LIBPATH'].to_s.split(':') + TK_LIBPATH = ENV[ 'TK_LIBPATH'].to_s.split(':') - if ENV['Apple_PubSub_Socket_Render'] - RUN_EVENTLOOP_ON_MAIN_THREAD = true - + if FFI::Platform.mac? if ENV['NO_AQUA'] || ENV['USE_X11'] # macports-x11 libtk - LIBPATH[:tcl] << '/opt/local/lib/libtcl8.5.dylib' - LIBPATH[:tk] << '/opt/local/lib/libtk8.5.dylib' + TCL_LIBPATH << '/opt/local/lib/libtcl8.5.dylib' + TK_LIBPATH << '/opt/local/lib/libtk8.5.dylib' else # Tcl/Tk Aqua >= 8.5 - LIBPATH[:tcl] << '/Library/Frameworks/Tcl.framework/Tcl' - LIBPATH[:tk] << '/Library/Frameworks/Tk.framework/Tk' + TCL_LIBPATH << '/Library/Frameworks/Tcl.framework/Tcl' + TK_LIBPATH << '/Library/Frameworks/Tk.framework/Tk' end end -end -require 'ffi-tk/thread_sender' -require 'ffi-tk/ffi/tcl' -require 'ffi-tk/ffi/tk' + TCL_LIBPATH << 'tcl' << 'tcl86' << 'tcl85' << 'tcl8.6' << 'tcl8.5' + TK_LIBPATH << 'tk' << 'tk86' << 'tk85' << 'tk8.6' << 'tk8.5' -module Tk - Error = Class.new(RuntimeError) + unless const_defined?(:RUN_EVENTLOOP_ON_MAIN_THREAD) + if FFI::Platform.mac? + # In some cases Tk has trouble running, this seems to happen on windows and + # OSX/TkAqua mostly. + # In these cases please use: + # module Tk; RUN_EVENTLOOP_ON_MAIN_THREAD = true; end + # before you require 'tk' + RUN_EVENTLOOP_ON_MAIN_THREAD = true + else + RUN_EVENTLOOP_ON_MAIN_THREAD = false + end + end + DONT_WAIT = 1 << 1 + WINDOW_EVENTS = 1 << 2 + FILE_EVENTS = 1 << 3 + TIMER_EVENTS = 1 << 4 + IDLE_EVENTS = 1 << 5 + ALL_EVENTS = ~DONT_WAIT + OK = 0 ERROR = 1 RETURN = 2 BREAK = 3 CONTINUE = 4 + Error = Class.new(RuntimeError) None = Object.new class << None def to_tcl; nil; end def to_tcl_options?; self; end def to_tcl_option?; self; end def inspect; '#<None>'; end end +end +require 'ffi-tk/thread_sender' +require 'ffi-tk/ffi/tcl' +require 'ffi-tk/ffi/tk' + +module Tk autoload :Button, 'ffi-tk/widget/button' autoload :Canvas, 'ffi-tk/widget/canvas' autoload :CheckButton, 'ffi-tk/widget/checkbutton' autoload :Entry, 'ffi-tk/widget/entry' autoload :Frame, 'ffi-tk/widget/frame'