1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/tk/*: full update Ruby/Tk to support Ruby(1.9|1.8) and Tc/Tk8.5.

* ext/tk/lib/tkextlib/tile.rb: [incompatible] remove TileWidgets' 
  instate/state/identify method to avoid the conflict with standard
  widget options. Those methods are renamed to ttk_instate/ttk_state/
  ttk_identify (tile_instate/tile_state/tile_identify are available 
  too). Although I don't recommend, if you realy need old methods, 
  please define "Tk::USE_OBSOLETE_TILE_STATE_METHOD = true" before 
  "require 'tkextlib/tile'".

* ext/tk/lib/tkextlib/tile.rb: "Tk::Tile::__Import_Tile_Widgets__!"
  is obsolete. It outputs warning. To control default widget set, 
  use "Tk.default_widget_set = :Ttk".

* ext/tk/lib/tk.rb: __IGNORE_UNKNOWN_CONFIGURE_OPTION__ method and 
  __set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode) method are defind 
  as module methods of TkConfigMethod. It may help users to wrap old 
  Ruby/Tk scripts (use standard widgets) to force to use Ttk widgets.
  Ttk widgets don't have some options of standard widgets which are 
  control the view of widgets. When set ignore-mode true, configure 
  method tries to ignoure such unknown options with no exception. 
  Of course, it may raise other troubles on the GUI design. 
  So, those are a little danger methods. 

* ext/tk/lib/tk/itemconfig.rb: __IGNORE_UNKNOWN_CONFIGURE_OPTION__ 
  method and __set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode) method 
  are defind as module methods of TkItemConfigMethod as the same 
  purpose as TkConfigMethod's ones.

* ext/tk/sample/ttk_wrapper.rb: A new example. This is a tool for 
  wrapping old Ruby/Tk scripts (which use standard widgets) to use 
  Ttk (Tile) widgets as default.

* ext/tk/sample/tkextlib/tile/demo.rb: use ttk_instate/ttk_state 
  method instead of instate/state method.

* ext/tk/lib/tk/root, ext/tk/lib/tk/namespace.rb,
  ext/tk/lib/tk/text.rb, ext/tk/lib/tkextlib/*: some 'instance_eval's  
  are replaced to "instance_exec(self)".

* ext/tk/lib/tk/event.rb: bug fix on KEY_TBL and PROC_TBL (?x is not 
  a character code on Ruby1.9).

* ext/tk/lib/tk/variable.rb: support new style of operation argument 
  on Tcl/Tk's 'trace' command for variables. 

* ext/tk/sample/demos-jp/widget, ext/tk/sample/demos-en/widget: bug fix

* ext/tk/sammple/demos-jp/textpeer.rb, 
  ext/tk/sammple/demos-en/textpeer.rb: new widget demo.

* ext/tk/tcltklib.c: decrase SEGV troubles (probably)

* ext/tk/lib/tk.rb: remove Thread.critical access if Ruby1.9

* ext/tk/lib/tk/multi-tk.rb: support Ruby1.9 (probably)

* ext/tk/lib/tkextlib/tile.rb: add method to define Tcl/Tk command 
  to make Tcl/Tk theme sources (based on different version of Tile 
  extension) available. 
  (Tk::Tile::__define_LoadImages_proc_for_comaptibility__)

* ext/tk/lib/tk.rb, ext/tk/lib/tk/wm.rb: support dockable frames
  (Tcl/Tk8.5 feature). 'wm' command can treat many kinds of widgets 
  as toplevel widgets.

* ext/tk/lib/tkextlib/tile/style.rb: ditto.
  (Tk::Tile::Style.__define_wrapper_proc_for_compatibility__)

* ext/tk/lib/tk/font.rb: add actual_hash and metrics_hash to get 
  properties as a hash. metrics_hash method returns a boolean value 
  for 'fixed' option. But metrics method returns numeric value 
  (0 or 1) for 'fixed' option, because of backward compatibility. 

* ext/tk/lib/tk/timer.rb: somtimes fail to set callback procedure.

* ext/tk/lib/tk.rb: add Tk.sleep and Tk.wakeup method. Tk.sleep 
  doesn't block the eventloop. It will be better to use the method 
  in event callbacks.

* ext/tk/sample/tksleep_sample.rb: sample script about Tk.sleep.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@15849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagai 2008-03-29 05:25:45 +00:00
parent 058c981311
commit aff4ce9c77
238 changed files with 9566 additions and 2732 deletions

View file

@ -1,3 +1,87 @@
Sat Mar 29 14:18:41 2008 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/*: full update Ruby/Tk to support Ruby(1.9|1.8) and Tc/Tk8.5.
* ext/tk/lib/tkextlib/tile.rb: [incompatible] remove TileWidgets'
instate/state/identify method to avoid the conflict with standard
widget options. Those methods are renamed to ttk_instate/ttk_state/
ttk_identify (tile_instate/tile_state/tile_identify are available
too). Although I don't recommend, if you realy need old methods,
please define "Tk::USE_OBSOLETE_TILE_STATE_METHOD = true" before
"require 'tkextlib/tile'".
* ext/tk/lib/tkextlib/tile.rb: "Tk::Tile::__Import_Tile_Widgets__!"
is obsolete. It outputs warning. To control default widget set,
use "Tk.default_widget_set = :Ttk".
* ext/tk/lib/tk.rb: __IGNORE_UNKNOWN_CONFIGURE_OPTION__ method and
__set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode) method are defind
as module methods of TkConfigMethod. It may help users to wrap old
Ruby/Tk scripts (use standard widgets) to force to use Ttk widgets.
Ttk widgets don't have some options of standard widgets which are
control the view of widgets. When set ignore-mode true, configure
method tries to ignoure such unknown options with no exception.
Of course, it may raise other troubles on the GUI design.
So, those are a little danger methods.
* ext/tk/lib/tk/itemconfig.rb: __IGNORE_UNKNOWN_CONFIGURE_OPTION__
method and __set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode) method
are defind as module methods of TkItemConfigMethod as the same
purpose as TkConfigMethod's ones.
* ext/tk/sample/ttk_wrapper.rb: A new example. This is a tool for
wrapping old Ruby/Tk scripts (which use standard widgets) to use
Ttk (Tile) widgets as default.
* ext/tk/sample/tkextlib/tile/demo.rb: use ttk_instate/ttk_state
method instead of instate/state method.
* ext/tk/lib/tk/root, ext/tk/lib/tk/namespace.rb,
ext/tk/lib/tk/text.rb, ext/tk/lib/tkextlib/*: some 'instance_eval's
are replaced to "instance_exec(self)".
* ext/tk/lib/tk/event.rb: bug fix on KEY_TBL and PROC_TBL (?x is not
a character code on Ruby1.9).
* ext/tk/lib/tk/variable.rb: support new style of operation argument
on Tcl/Tk's 'trace' command for variables.
* ext/tk/sample/demos-jp/widget, ext/tk/sample/demos-en/widget: bug fix
* ext/tk/sammple/demos-jp/textpeer.rb,
ext/tk/sammple/demos-en/textpeer.rb: new widget demo.
* ext/tk/tcltklib.c: decrase SEGV troubles (probably)
* ext/tk/lib/tk.rb: remove Thread.critical access if Ruby1.9
* ext/tk/lib/tk/multi-tk.rb: support Ruby1.9 (probably)
* ext/tk/lib/tkextlib/tile.rb: add method to define Tcl/Tk command
to make Tcl/Tk theme sources (based on different version of Tile
extension) available.
(Tk::Tile::__define_LoadImages_proc_for_comaptibility__)
* ext/tk/lib/tk.rb, ext/tk/lib/tk/wm.rb: support dockable frames
(Tcl/Tk8.5 feature). 'wm' command can treat many kinds of widgets
as toplevel widgets.
* ext/tk/lib/tkextlib/tile/style.rb: ditto.
(Tk::Tile::Style.__define_wrapper_proc_for_compatibility__)
* ext/tk/lib/tk/font.rb: add actual_hash and metrics_hash to get
properties as a hash. metrics_hash method returns a boolean value
for 'fixed' option. But metrics method returns numeric value
(0 or 1) for 'fixed' option, because of backward compatibility.
* ext/tk/lib/tk/timer.rb: somtimes fail to set callback procedure.
* ext/tk/lib/tk.rb: add Tk.sleep and Tk.wakeup method. Tk.sleep
doesn't block the eventloop. It will be better to use the method
in event callbacks.
* ext/tk/sample/tksleep_sample.rb: sample script about Tk.sleep.
Mon Mar 24 20:07:42 2008 Akinori MUSHA <knu@iDaemons.org>
* eval.c (rb_eval): Call trace hook for if expression after the

View file

@ -125,7 +125,24 @@ module TclTklib
: Tcl7.6 doesn't have this flag. So PARSE_VARNAME is
: defined as 0.
module TclTkLib::RELEASE_TYPE
: Defines release type number of Tcl/Tk
ALPHA
: ALPHA release
BETA
: BETA release
FINAL
: FINAL release
[module methods]
get_version()
: return an array of major, minor, release-type number,
: number, release-type name, and patchlevel of current
: Tcl/Tk library.
mainloop(check_root = true)
: Starts the eventloop. If 'check_root' is true, this method
: doesn't return when a root widget exists.
@ -431,6 +448,10 @@ class TclTkIp
: slave interpreter, same to the TclTkLib module method with
: the same name.
encoding_table
: For Ruby m17n. Return encoding relation table between Ruby's
: Encoding object and Tcl's encoding name.
class TkCallbackBreak < StandardError
class TkCallbackContinue < StandardError
: They are exception classes to break or continue the Tk callback
@ -441,5 +462,8 @@ class TkCallbackContinue < StandardError
: If raise TkCallbackContinue, returns 'continue' code (Then the Tk
: interpreter will break the operateion for the current bindtag and
: starts the operation for the next buindtag for the current event).
: However, current tcltklib supports Ruby's 'break' and 'next' to
: get the same effect. That is, those classes are obsolete. Those
: exist for backward compatibility.
(eof)

View file

@ -221,7 +221,23 @@ require "tcltklib"
: から抽出されるはずであるからindex_name 引数は nil と
: せねばならない.
モジュール TclTkLib::RELEASE_TYPE
: Tcl/Tk のリリースタイプ番号の定義
定数 ALPHA
: ALPHA リリース
定数 BETA
: BETA リリース
定数 FINAL
: FINAL リリース
モジュールメソッド
get_version()
: Tcl/Tk の major, minor, release-type 番号, release-type 名,
: patchlevel を配列にして返す.
mainloop(check_root = true)
: イベントループを起動するcheck_root が true であれば,
: root widget が存在する限り,このメソッドは終了しない.
@ -543,6 +559,9 @@ require "tcltklib"
: スレーブ IP の場合には値の設定が許されない (無視される)
: それ以外の点では引数を含めて TclTkLib の同名メソッドに同じ.
encoding_table
: Ruby m17n 用に Ruby と Tk との間の encoding 対応表を返す.
クラス TkCallbackBreak < StandardError
クラス TkCallbackContinue < StandardError
: これらはイベントコールバックにおいて,コールバック処理を適切に中
@ -553,5 +572,8 @@ require "tcltklib"
: ドを返す必要があるRuby の手続きが普通に値を返すのでは,それが普
: 通の戻り値であるのか否かを区別ができないため,例外発生を利用した
: 実装を行っている.
: ただし現在では,コールバック手続きを Ruby の break, next で終了す
: ることで同等の結果を得ることができるようになっている.それゆえ,
: これらは必要ないものではあるが,互換性のために残してある.
(eof)

View file

@ -1,7 +1,6 @@
If you want to use Ruby/Tk (tk.rb and so on), you must have tcltklib.so
which is working correctly. If you fail to call 'require "tcltklib"',
you may not have tcltklib.so. When you have some troubles on compiling
tcltklib, please read README files on tcltklib.
which is working correctly. When you have some troubles on compiling,
please read README.tcltklib and README.ActiveTcl.
Even if there is a tcltklib.so on your Ruby library directry, it will not
work without Tcl/Tk libraries (e.g. libtcl8.4.so) on your environment.
You must also check that your Tcl/Tk is installed properly.
@ -9,11 +8,9 @@ You must also check that your Tcl/Tk is installed properly.
--------------------------------------------
( the following is written in EUC-JP )
Ruby/Tk (tk.rb など) を使いたい場合にはtcltklib.so が正しく動いて
いなければなりません.もし 'require "tcltklib"' に失敗するようなら,
tcltklib.so がインストールされていないのかもしれませんtcltklib の
コンパイル時に何か問題が生じている場合はtcltklib の README ファイル
を見てください.
Ruby/Tk (tk.rb など) を使いたい場合にはtcltklib.so が正しく動いていな
ければなりませんコンパイル時に何か問題が生じた場合はREADME.tcltklib
や README.ActiveTcl を見てください.
たとえ Ruby のライブラリディレクトリに tcltklib.so が存在していたとして
も,実行環境に Tcl/Tk ライブラリ (libtcl8.4.so など) がなければ機能しま
せんTcl/Tk が正しくインストールされているかもチェックしてください.

View file

@ -16,18 +16,18 @@ some or all of the following options.
--with-tk-dir=<path>
equal to "--with-tk-include=<path>/include --with-tk-lib=<path>/lib"
--with-tcl-include=<dir> the directry containts 'tcl.h'
--with-tk-include=<dir> the directry containts 'tk.h'
--with-tcl-include=<dir> the directry contains 'tcl.h'
--with-tk-include=<dir> the directry contains 'tk.h'
--with-tcl-lib=<dir> the directry containts 'libtcl<version>.so'
--with-tk-lib=<dir> the directry containts 'libtk<version>.so'
--with-tcl-lib=<dir> the directry contains 'libtcl<version>.so'
--with-tk-lib=<dir> the directry contains 'libtk<version>.so'
--enable-mac-tcltk-framework (MacOS X) use Tcl/Tk framework
(Obsolete. Please use '--enable-tcltk-framework'.)
--enable-tcltk-framework use Tcl/Tk framework
--with-tcltk-framework=<dir> the directory containts Tcl/Tk framework;
--with-tcltk-framework=<dir> the directory contains Tcl/Tk framework;
"<dir>/Tcl.framework" and "<dir>/Tk.framework".
When this option is given, it is assumed that
--enable-tcltk-framework option is given also.
@ -46,8 +46,8 @@ some or all of the following options.
--with-X11-dir=<path>
equal to "--with-X11-include=<path>/include --with-X11-lib=<path>/lib"
--with-X11-include=<dir> the directry contains X11 header files
--with-X11-lib=<dir> the directry contains X11 libraries
--with-X11-include=<dir> the directry contais X11 header files
--with-X11-lib=<dir> the directry contais X11 libraries
If you forgot to give the options when do 'configure' on toplevel

View file

@ -2,7 +2,8 @@
require 'mkmf'
is_win32 = (/mswin32|mingw|cygwin|bccwin32/ =~ RUBY_PLATFORM)
#is_win32 = (/mswin32|mingw|cygwin|bccwin32/ =~ RUBY_PLATFORM)
is_win32 = (/mswin|mingw|cygwin|bccwin|wince/ =~ RUBY_PLATFORM)
#is_macosx = (/darwin/ =~ RUBY_PLATFORM)
def find_framework(tcl_hdr, tk_hdr)
@ -39,9 +40,13 @@ unless is_win32
have_library("m", "log")
end
dir_config("tk")
dir_config("tcl")
dir_config("X11")
tk_idir, tk_ldir = dir_config("tk")
tcl_idir, tcl_ldir = dir_config("tcl")
x11_idir, x11_ldir = dir_config("X11")
tk_ldir2 = with_config("tk-lib")
tcl_ldir2 = with_config("tcl-lib")
x11_ldir2 = with_config("X11-lib")
tklib = with_config("tklib")
tcllib = with_config("tcllib")
@ -49,8 +54,9 @@ stubs = enable_config("tcltk_stubs") || with_config("tcltk_stubs")
use_X = with_config("X11", (! is_win32))
def find_tcl(tcllib, stubs)
paths = ["/usr/local/lib", "/usr/pkg/lib", "/usr/lib"]
def find_tcl(tcllib, stubs, *opt_paths)
default_paths = ["/usr/local/lib", "/usr/pkg/lib", "/usr/lib"]
paths = opt_paths.compact.concat(default_paths)
if stubs
func = "Tcl_InitStubs"
lib = "tclstub"
@ -60,20 +66,23 @@ def find_tcl(tcllib, stubs)
end
if tcllib
find_library(tcllib, func, *paths)
elsif find_library(lib, func, *paths)
true
else
%w[8.5 8.4 8.3 8.2 8.1 8.0 7.6].find { |ver|
%w[8.6 8.5 8.4 8.3 8.2 8.1 8.0 7.6].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)
}
find_library("tcl#{ver.delete('.')}", func, *paths) or
find_library("tcl#{ver}g", func, *paths) or
find_library("tcl#{ver.delete('.')}g", func, *paths)
} || find_library(lib, func, *paths)
end
end
def find_tk(tklib, stubs)
paths = ["/usr/local/lib", "/usr/pkg/lib", "/usr/lib"]
def find_tk(tklib, stubs, *opt_paths)
default_paths = ["/usr/local/lib", "/usr/pkg/lib", "/usr/lib"]
paths = opt_paths.compact.concat(default_paths)
if stubs
func = "Tk_InitStubs"
lib = "tkstub"
@ -83,18 +92,27 @@ def find_tk(tklib, stubs)
end
if tklib
find_library(tklib, func, *paths)
elsif find_library(lib, func, *paths)
true
else
%w[8.5 8.4 8.3 8.2 8.1 8.0 4.2].find { |ver|
%w[8.6 8.5 8.4 8.3 8.2 8.1 8.0 4.2].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)
}
find_library("tk#{ver.delete('.')}", func, *paths) or
find_library("tk#{ver}g", func, *paths) or
find_library("tk#{ver.delete('.')}g", func, *paths)
} || find_library(lib, func, *paths)
end
end
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)
find_library("X11", "XOpenDisplay", *paths)
end
def pthread_check()
tcl_major_ver = nil
tcl_minor_ver = nil
@ -273,13 +291,11 @@ EOF
end
end
if tcltk_framework ||
(have_header("tcl.h") && have_header("tk.h") &&
( !use_X || find_library("X11", "XOpenDisplay",
"/usr/X11/lib", "/usr/lib/X11",
"/usr/X11R6/lib", "/usr/openwin/lib")) &&
find_tcl(tcllib, stubs) &&
find_tk(tklib, stubs))
if have_header("tcl.h") && have_header("tk.h") &&
( tcltk_framework ||
( ( !use_X || find_X11(x11_ldir2, x11_ldir) ) &&
find_tcl(tcllib, stubs, tcl_ldir2, tcl_ldir) &&
find_tk(tklib, stubs, tk_ldir2, tk_ldir) ) )
$CPPFLAGS += ' -DUSE_TCL_STUBS -DUSE_TK_STUBS' if stubs
$CPPFLAGS += ' -D_WIN32' if /cygwin/ =~ RUBY_PLATFORM
@ -307,6 +323,8 @@ if tcltk_framework ||
$INSTALLFILES << ["lib/tkextlib/SUPPORT_STATUS", "$(RUBYLIBDIR)", "lib"]
# create
$defs << %[-DRUBY_VERSION=\\"#{RUBY_VERSION}\\"]
$defs << %[-DRUBY_RELEASE_DATE=\\"#{RUBY_RELEASE_DATE}\\"]
create_makefile("tcltklib")
end
end

View file

@ -114,7 +114,14 @@ MultiTkIp_OK.freeze
class MultiTkIp
BASE_DIR = File.dirname(__FILE__)
@@SLAVE_IP_ID = ['slave'.freeze, '0'.taint].freeze
WITH_RUBY_VM = Object.const_defined?(:VM) && ::VM.class == Class
WITH_ENCODING = Object.const_defined?(:Encoding) && ::Encoding.class == Class
(@@SLAVE_IP_ID = ['slave'.freeze, '0'.taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
@@IP_TABLE = {}.taint unless defined?(@@IP_TABLE)
@ -126,14 +133,18 @@ class MultiTkIp
unless defined?(@@TK_CMD_TBL)
@@TK_CMD_TBL = Object.new.taint
@@TK_CMD_TBL.instance_variable_set('@tbl', {}.taint)
# @@TK_CMD_TBL.instance_variable_set('@tbl', {}.taint)
@@TK_CMD_TBL.instance_variable_set('@tbl', Hash.new{|hash,key|
fail IndexError,
"unknown command ID '#{key}'"
}.taint)
class << @@TK_CMD_TBL
allow = [
'__send__', '__id__', 'freeze', 'inspect', 'kind_of?',
'__send__', '__id__', 'freeze', 'inspect', 'kind_of?', 'object_id',
'[]', '[]=', 'delete', 'each', 'has_key?'
]
instance_methods.each{|m| undef_method(m) unless allow.index(m)}
instance_methods.each{|m| undef_method(m) unless allow.index(m.to_s)}
def kind_of?(klass)
@tbl.kind_of?(klass)
@ -206,7 +217,7 @@ class MultiTkIp
def initialize(ip, cmd)
@ip = ip
@cmd = cmd
freeze
self.freeze
end
attr_reader :ip, :cmd
def inspect
@ -573,7 +584,11 @@ class MultiTkIp
# raise exception
begin
bt = _toUTF8(e.backtrace.join("\n"))
if MultiTkIp::WITH_ENCODING
bt.force_encoding('utf-8')
else
bt.instance_variable_set(:@encoding, 'utf-8')
end
rescue Exception
bt = e.backtrace.join("\n")
end
@ -695,6 +710,11 @@ class MultiTkIp
######################################
unless self.const_defined? :RUN_EVENTLOOP_ON_MAIN_THREAD
### Ruby 1.9 !!!!!!!!!!!!!!!!!!!!!!!!!!
RUN_EVENTLOOP_ON_MAIN_THREAD = false
end
if self.const_defined? :DEFAULT_MASTER_NAME
name = DEFAULT_MASTER_NAME.to_s
else
@ -723,7 +743,41 @@ class MultiTkIp
fail ArgumentError, "expecting a Hash object for the 2nd argument"
end
if !WITH_RUBY_VM || RUN_EVENTLOOP_ON_MAIN_THREAD ### check Ruby 1.9 !!!!!!!
@interp = TclTkIp.new(name, _keys2opts(keys))
else ### Ruby 1.9 !!!!!!!!!!!
@interp_thread = Thread.new{
current = Thread.current
current[:interp] = interp = TclTkIp.new(name, _keys2opts(keys))
#sleep
current[:mutex] = mutex = Mutex.new
current[:root_check] = cond_var = ConditionVariable.new
begin
current[:status] = interp.mainloop(true)
rescue Exception=>e
current[:status] = e
ensure
mutex.synchronize{ cond_var.broadcast }
end
current[:status] = interp.mainloop(false)
}
until @interp_thread[:interp]
Thread.pass
end
# INTERP_THREAD.run
@interp = @interp_thread[:interp]
def self.mainloop(check_root = true)
begin
TclTkLib.set_eventloop_window_mode(true)
@interp_thread.value
ensure
TclTkLib.set_eventloop_window_mode(false)
end
end
end
@ip_name = nil
@callback_status = [].taint
@ -853,22 +907,26 @@ class MultiTkIp
Thread.new{
current = Thread.current
loop {
mtx, ret, table, script = @init_ip_env_queue.deq
mtx, cond, ret, table, script = @init_ip_env_queue.deq
begin
ret[0] = table.each{|tg, ip| ip._init_ip_env(script) }
rescue Exception => e
ret[0] = e
ensure
mtx.unlock
mtx.synchronize{ cond.signal }
end
mtx = cond = ret = table = script = nil # clear variables for GC
}
}
def self.__init_ip_env__(table, script)
ret = []
mtx = Mutex.new.lock
@init_ip_env_queue.enq([mtx, ret, table, script])
mtx.lock
mtx = (Thread.current[:MultiTk_ip_Mutex] ||= Mutex.new)
cond = (Thread.current[:MultiTk_ip_CondVar] ||= ConditionVariable.new)
mtx.synchronize{
@init_ip_env_queue.enq([mtx, cond, ret, table, script])
cond.wait(mtx)
}
if ret[0].kind_of?(Exception)
raise ret[0]
else
@ -947,9 +1005,11 @@ class MultiTkIp
private :_parse_slaveopts
def _create_slave_ip_name
@@SLAVE_IP_ID.mutex.synchronize{
name = @@SLAVE_IP_ID.join('')
@@SLAVE_IP_ID[1].succ!
name.freeze
}
end
private :_create_slave_ip_name
@ -1206,7 +1266,20 @@ class MultiTkIp
if safeip == nil
# create master-ip
unless WITH_RUBY_VM
@interp = TclTkIp.new(name, _keys2opts(tk_opts))
else ### Ruby 1.9 !!!!!!!!!!!
@interp_thread = Thread.new{
Thread.current[:interp] = interp = TclTkIp.new(name, _keys2opts(tk_opts))
#sleep
TclTkLib.mainloop(true)
}
until @interp_thread[:interp]
Thread.pass
end
# INTERP_THREAD.run
@interp = @interp_thread[:interp]
end
@ip_name = nil
if safe
@ -1221,6 +1294,8 @@ class MultiTkIp
@safe_base = true
@interp, @ip_name = master.__create_safe_slave_obj(safe_opts,
name, tk_opts)
# @interp_thread = nil if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!!
@interp_thread = nil unless WITH_RUBY_VM ### Ruby 1.9 !!!!!!!!!!!
if safe
safe = master.safe_level if safe < master.safe_level
@safe_level = [safe]
@ -1229,6 +1304,8 @@ class MultiTkIp
end
else
@interp, @ip_name = master.__create_trusted_slave_obj(name, tk_opts)
# @interp_thread = nil if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!!
@interp_thread = nil unless WITH_RUBY_VM ### Ruby 1.9 !!!!!!!!!!!
if safe
safe = master.safe_level if safe < master.safe_level
@safe_level = [safe]
@ -1263,11 +1340,11 @@ class MultiTkIp
@@DEFAULT_MASTER.assign_receiver_and_watchdog(self)
@@IP_TABLE[@threadgroup] = self
_init_ip_internal(@@INIT_IP_ENV, @@ADD_TK_PROCS)
@@TK_TABLE_LIST.size.times{
(tbl = {}).tainted? || tbl.taint
@tk_table_list << tbl
}
_init_ip_internal(@@INIT_IP_ENV, @@ADD_TK_PROCS)
class << self
undef :instance_eval
@ -1345,8 +1422,13 @@ class << MultiTkIp
alias __new new
private :__new
def new_master(safe=nil, keys={})
if MultiTkIp::WITH_RUBY_VM
#### TODO !!!!!!
fail RuntimeError,
'sorry, still not support multiple master-interpreters on Ruby VM'
end
if safe.kind_of?(Hash)
keys = safe
elsif safe.kind_of?(Integer)
@ -1563,8 +1645,13 @@ class MultiTkIp
return if slave?
names.each{|name|
name = name.to_s
return if @interp.deleted?
@interp._invoke('rename', name, '')
return if @interp.deleted?
@interp._invoke('interp', 'slaves').split.each{|slave|
return if @interp.deleted?
@interp._invoke('interp', 'alias', slave, name, '') rescue nil
}
}
@ -1614,11 +1701,16 @@ class MultiTkIp
id = @@TK_TABLE_LIST.size
obj = Object.new
@@TK_TABLE_LIST << obj
obj.instance_eval <<-EOD
def self.method_missing(m, *args)
MultiTkIp.tk_object_table(#{id}).__send__(m, *args)
obj.instance_variable_set(:@id, id)
obj.instance_variable_set(:@mutex, Mutex.new)
obj.instance_eval{
def self.mutex
@mutex
end
EOD
def self.method_missing(m, *args)
MultiTkIp.tk_object_table(@id).__send__(m, *args)
end
}
obj.freeze
@@IP_TABLE.each{|tg, ip| ip._add_new_tables }
return obj
@ -2338,6 +2430,11 @@ end
class MultiTkIp
def mainloop(check_root = true, restart_on_dead = true)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
unless WITH_RUBY_VM ### Ruby 1.9 !!!!!!!!!!!
return @interp_thread.value if @interp_thread
end
#return self if self.slave?
#return self if self != @@DEFAULT_MASTER
if self != @@DEFAULT_MASTER
@ -2746,9 +2843,10 @@ class MultiTkIp
i = -1
brace = 1
str.each_byte {|c|
c = c.chr
i += 1
brace += 1 if c == ?{
brace -= 1 if c == ?}
brace += 1 if c == '{'
brace -= 1 if c == '}'
break if brace == 0
}
if i == 0
@ -3187,15 +3285,44 @@ end
# encoding convert
class MultiTkIp
def encoding
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.encoding
class << MultiTkIp
def encoding_table
__getip.encoding_table
end
end
class MultiTkIp
def encoding_table
@interp.encoding_table
end
def force_default_encoding=(mode)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.force_default_encoding = mode
end
def force_default_encoding?
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.force_default_encoding?
end
def default_encoding=(enc)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.default_encoding = enc
end
def encoding=(enc)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.encoding = enc
end
def encoding_name
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.encoding_name
end
def encoding_obj
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@interp.encoding_obj
end
alias encoding encoding_name
alias default_encoding encoding_name
def encoding_convertfrom(str, enc=None)
raise SecurityError, "no permission to manipulate" unless self.manipulable?
@ -3213,12 +3340,28 @@ end
# remove methods for security
class MultiTkIp
INTERP_THREAD = @@DEFAULT_MASTER.instance_variable_get('@interp_thread')
INTERP_MUTEX = INTERP_THREAD[:mutex]
INTERP_ROOT_CHECK = INTERP_THREAD[:root_check]
# undef_method :instance_eval
undef_method :instance_variable_get
undef_method :instance_variable_set
end
module TkCore
if MultiTkIp::WITH_RUBY_VM &&
! MultiTkIp::RUN_EVENTLOOP_ON_MAIN_THREAD ### check Ruby 1.9 !!!!!!!
INTERP_THREAD = MultiTkIp::INTERP_THREAD
INTERP_MUTEX = MultiTkIp::INTERP_MUTEX
INTERP_ROOT_CHECK = MultiTkIp::INTERP_ROOT_CHECK
end
end
class MultiTkIp
remove_const(:INTERP_THREAD)
remove_const(:INTERP_MUTEX)
remove_const(:INTERP_ROOT_CHECK)
end
# end of MultiTkIp definition
# defend against modification

View file

@ -265,7 +265,7 @@ class TclTkWidget < TclTkCommand
# (used in TclTkInterpreter#initialize())
# need two arguments
fail("illegal # of parameter") if args.size != 2
fail("invalid # of parameter") if args.size != 2
# ip: interpreter(TclTkIp)
# exp: tcl/tk representation

File diff suppressed because it is too large Load diff

View file

@ -1,9 +1,19 @@
#
# autoload
#
#######################
############################################
# geometry manager
module Tk
autoload :Grid, 'tk/grid'
def Grid(*args); TkGrid.configure(*args); end
autoload :Pack, 'tk/pack'
def Pack(*args); TkPack.configure(*args); end
autoload :Place, 'tk/place'
def Place(*args); TkPlace.configure(*args); end
end
autoload :TkGrid, 'tk/grid'
def TkGrid(*args); TkGrid.configure(*args); end
@ -14,19 +24,117 @@ autoload :TkPlace, 'tk/place'
def TkPlace(*args); TkPlace.configure(*args); end
#######################
# others
############################################
# classes on Tk module
module Tk
autoload :Button, 'tk/button'
autoload :Canvas, 'tk/canvas'
autoload :CheckButton, 'tk/checkbutton'
autoload :Checkbutton, 'tk/checkbutton'
autoload :Entry, 'tk/entry'
autoload :Frame, 'tk/frame'
autoload :Label, 'tk/label'
autoload :LabelFrame, 'tk/labelframe'
autoload :Labelframe, 'tk/labelframe'
autoload :Listbox, 'tk/listbox'
autoload :Menu, 'tk/menu'
autoload :MenuClone, 'tk/menu'
autoload :CloneMenu, 'tk/menu'
autoload :SystemMenu, 'tk/menu'
autoload :SysMenu_Help, 'tk/menu'
autoload :SysMenu_System, 'tk/menu'
autoload :SysMenu_Apple, 'tk/menu'
autoload :Menubutton, 'tk/menu'
autoload :MenuButton, 'tk/menu'
autoload :OptionMenubutton, 'tk/menu'
autoload :OptionMenBbutton, 'tk/menu'
autoload :Message, 'tk/message'
autoload :PanedWindow, 'tk/panedwindow'
autoload :Panedwindow, 'tk/panedwindow'
autoload :RadioButton, 'tk/radiobutton'
autoload :Radiobutton, 'tk/radiobutton'
autoload :Root, 'tk/root'
autoload :Scale, 'tk/scale'
autoload :Scrollbar, 'tk/scrollbar'
autoload :XScrollbar, 'tk/scrollbar'
autoload :YScrollbar, 'tk/scrollbar'
autoload :Spinbox, 'tk/spinbox'
autoload :Text, 'tk/text'
autoload :Toplevel, 'tk/toplevel'
end
############################################
# sub-module of Tk
module Tk
autoload :Clock, 'tk/clock'
autoload :OptionObj, 'tk/optionobj'
autoload :X_Scrollable, 'tk/scrollable'
autoload :Y_Scrollable, 'tk/scrollable'
autoload :Scrollable, 'tk/scrollable'
autoload :Wm, 'tk/wm'
autoload :Wm_for_General, 'tk/wm'
autoload :MacResource, 'tk/macpkg'
autoload :WinDDE, 'tk/winpkg'
autoload :WinRegistry, 'tk/winpkg'
autoload :ValidateConfigure, 'tk/validation'
autoload :ItemValidateConfigure, 'tk/validation'
autoload :EncodedString, 'tk/encodedstr'
def Tk.EncodedString(str, enc = nil); Tk::EncodedString.new(str, enc); end
autoload :BinaryString, 'tk/encodedstr'
def Tk.BinaryString(str); Tk::BinaryString.new(str); end
autoload :UTF8_String, 'tk/encodedstr'
def Tk.UTF8_String(str); Tk::UTF8_String.new(str); end
end
############################################
# toplevel classes/modules (fixed)
autoload :TkBgError, 'tk/bgerror'
autoload :TkBindTag, 'tk/bindtag'
autoload :TkBindTagAll, 'tk/bindtag'
autoload :TkDatabaseClass, 'tk/bindtag'
autoload :TkButton, 'tk/button'
autoload :TkConsole, 'tk/console'
autoload :TkCanvas, 'tk/canvas'
autoload :TkcItem, 'tk/canvas'
autoload :TkcArc, 'tk/canvas'
autoload :TkcBitmap, 'tk/canvas'
autoload :TkcImage, 'tk/canvas'
autoload :TkcLine, 'tk/canvas'
autoload :TkcOval, 'tk/canvas'
autoload :TkcPolygon, 'tk/canvas'
autoload :TkcRectangle, 'tk/canvas'
autoload :TkcText, 'tk/canvas'
autoload :TkcWindow, 'tk/canvas'
autoload :TkcTagAccess, 'tk/canvastag'
autoload :TkcTag, 'tk/canvastag'
@ -36,9 +144,6 @@ autoload :TkcTagAll, 'tk/canvastag'
autoload :TkcTagCurrent, 'tk/canvastag'
autoload :TkcTagGroup, 'tk/canvastag'
autoload :TkCheckButton, 'tk/checkbutton'
autoload :TkCheckbutton, 'tk/checkbutton'
autoload :TkClipboard, 'tk/clipboard'
autoload :TkComposite, 'tk/composite'
@ -52,14 +157,10 @@ autoload :TkWarning, 'tk/dialog'
autoload :TkWarning2, 'tk/dialog'
autoload :TkWarningObj, 'tk/dialog'
autoload :TkEntry, 'tk/entry'
autoload :TkEvent, 'tk/event'
autoload :TkFont, 'tk/font'
autoload :TkTreatTagFont, 'tk/font'
autoload :TkFrame, 'tk/frame'
autoload :TkNamedFont, 'tk/font'
autoload :TkImage, 'tk/image'
autoload :TkBitmapImage, 'tk/image'
@ -71,30 +172,12 @@ autoload :TkTreatItemFont, 'tk/itemfont'
autoload :TkKinput, 'tk/kinput'
autoload :TkLabel, 'tk/label'
autoload :TkLabelFrame, 'tk/labelframe'
autoload :TkLabelframe, 'tk/labelframe'
autoload :TkListbox, 'tk/listbox'
autoload :TkMacResource, 'tk/macpkg'
autoload :TkMenu, 'tk/menu'
autoload :TkMenuClone, 'tk/menu'
autoload :TkSystemMenu, 'tk/menu'
autoload :TkSysMenu_Help, 'tk/menu'
autoload :TkSysMenu_System, 'tk/menu'
autoload :TkSysMenu_Apple, 'tk/menu'
autoload :TkMenubutton, 'tk/menu'
autoload :TkOptionMenubutton, 'tk/menu'
autoload :TkMenubar, 'tk/menubar'
autoload :TkMenuSpec, 'tk/menuspec'
autoload :TkMessage, 'tk/message'
autoload :TkManageFocus, 'tk/mngfocus'
autoload :TkMsgCatalog, 'tk/msgcat'
@ -110,53 +193,46 @@ autoload :TkPackage, 'tk/package'
autoload :TkPalette, 'tk/palette'
autoload :TkPanedWindow, 'tk/panedwindow'
autoload :TkPanedwindow, 'tk/panedwindow'
autoload :TkRadioButton, 'tk/radiobutton'
autoload :TkRadiobutton, 'tk/radiobutton'
autoload :TkRoot, 'tk/root'
autoload :TkScale, 'tk/scale'
autoload :TkScrollbar, 'tk/scrollbar'
autoload :TkXScrollbar, 'tk/scrollbar'
autoload :TkYScrollbar, 'tk/scrollbar'
autoload :TkScrollbox, 'tk/scrollbox'
autoload :TkSelection, 'tk/selection'
autoload :TkSpinbox, 'tk/spinbox'
autoload :TkTreatTagFont, 'tk/tagfont'
autoload :TkText, 'tk/text'
autoload :TkTextImage, 'tk/textimage'
autoload :TktImage, 'tk/textimage'
autoload :TkTextMark, 'tk/textmark'
autoload :TkTextNamedMark, 'tk/textmark'
autoload :TkTextMarkInsert, 'tk/textmark'
autoload :TkTextMarkCurrent, 'tk/textmark'
autoload :TkTextMarkAnchor, 'tk/textmark'
autoload :TktMark, 'tk/textmark'
autoload :TktNamedMark, 'tk/textmark'
autoload :TktMarkInsert, 'tk/textmark'
autoload :TktMarkCurrent, 'tk/textmark'
autoload :TktMarkAnchor, 'tk/textmark'
autoload :TkTextTag, 'tk/texttag'
autoload :TkTextNamedTag, 'tk/texttag'
autoload :TkTextTagSel, 'tk/texttag'
autoload :TktTag, 'tk/texttag'
autoload :TktNamedTag, 'tk/texttag'
autoload :TktTagSel, 'tk/texttag'
autoload :TkTextWindow, 'tk/textwindow'
autoload :TktWindow, 'tk/textwindow'
autoload :TkAfter, 'tk/timer'
autoload :TkTimer, 'tk/timer'
autoload :TkRTTimer, 'tk/timer'
autoload :TkToplevel, 'tk/toplevel'
autoload :TkTextWin, 'tk/txtwin_abst'
autoload :TkValidation, 'tk/validation'
autoload :TkValidateCommand, 'tk/validation'
autoload :TkVariable, 'tk/variable'
autoload :TkVarAccess, 'tk/variable'
@ -166,31 +242,173 @@ autoload :TkNamedVirtualEvent,'tk/virtevent'
autoload :TkWinfo, 'tk/winfo'
autoload :TkWinDDE, 'tk/winpkg'
autoload :TkWinRegistry, 'tk/winpkg'
autoload :TkXIM, 'tk/xim'
#######################
# sub-module of Tk
############################################
# toplevel classes/modules (switchable)
module Tk
autoload :Clock, 'tk/clock'
autoload :OptionObj, 'tk/optionobj'
autoload :X_Scrollable, 'tk/scrollable'
autoload :Y_Scrollable, 'tk/scrollable'
autoload :Scrollable, 'tk/scrollable'
autoload :Wm, 'tk/wm'
@TOPLEVEL_ALIAS_TABLE = {}
@TOPLEVEL_ALIAS_TABLE[:Tk] = {
:TkButton => 'tk/button',
autoload :ValidateConfigure, 'tk/validation'
autoload :ItemValidateConfigure, 'tk/validation'
:TkCanvas => 'tk/canvas',
autoload :EncodedString, 'tk/encodedstr'
def Tk.EncodedString(str, enc = nil); Tk::EncodedString.new(str, enc); end
:TkCheckButton => 'tk/checkbutton',
:TkCheckbutton => 'tk/checkbutton',
autoload :BinaryString, 'tk/encodedstr'
def Tk.BinaryString(str); Tk::BinaryString.new(str); end
# :TkDialog => 'tk/dialog',
# :TkDialog2 => 'tk/dialog',
# :TkDialogObj => 'tk/dialog',
# :TkWarning => 'tk/dialog',
# :TkWarning2 => 'tk/dialog',
# :TkWarningObj => 'tk/dialog',
autoload :UTF8_String, 'tk/encodedstr'
def Tk.UTF8_String(str); Tk::UTF8_String.new(str); end
:TkEntry => 'tk/entry',
:TkFrame => 'tk/frame',
:TkLabel => 'tk/label',
:TkLabelFrame => 'tk/labelframe',
:TkLabelframe => 'tk/labelframe',
:TkListbox => 'tk/listbox',
:TkMacResource => 'tk/macpkg',
:TkMenu => 'tk/menu',
:TkMenuClone => 'tk/menu',
:TkCloneMenu => 'tk/menu',
# :TkSystemMenu => 'tk/menu',
:TkSysMenu_Help => 'tk/menu',
:TkSysMenu_System => 'tk/menu',
:TkSysMenu_Apple => 'tk/menu',
:TkMenubutton => 'tk/menu',
:TkMenuButton => 'tk/menu',
:TkOptionMenubutton => 'tk/menu',
:TkOptionMenuButton => 'tk/menu',
:TkMessage => 'tk/message',
:TkPanedWindow => 'tk/panedwindow',
:TkPanedwindow => 'tk/panedwindow',
:TkRadioButton => 'tk/radiobutton',
:TkRadiobutton => 'tk/radiobutton',
# :TkRoot => 'tk/root',
:TkScale => 'tk/scale',
:TkScrollbar => 'tk/scrollbar',
:TkXScrollbar => 'tk/scrollbar',
:TkYScrollbar => 'tk/scrollbar',
:TkSpinbox => 'tk/spinbox',
:TkText => 'tk/text',
:TkToplevel => 'tk/toplevel',
:TkWinDDE => 'tk/winpkg',
:TkWinRegistry => 'tk/winpkg',
}
@TOPLEVEL_ALIAS_OWNER = {}
@TOPLEVEL_ALIAS_SETUP_PROC = {}
@current_default_widget_set = nil
end
############################################
# methods to control default widget set
############################################
class << Tk
def default_widget_set
@current_default_widget_set
end
def default_widget_set=(target)
target = target.to_sym
return target if target == @current_default_widget_set
if (cmd = @TOPLEVEL_ALIAS_SETUP_PROC[target])
cmd.call(target)
end
_replace_toplevel_aliases(target)
end
def __set_toplevel_aliases__(target, obj, *symbols)
@TOPLEVEL_ALIAS_TABLE[target = target.to_sym] ||= {}
symbols.each{|sym|
@TOPLEVEL_ALIAS_TABLE[target][sym = sym.to_sym] = obj
# if @current_default_widget_set == target
if @TOPLEVEL_ALIAS_OWNER[sym] == target
Object.class_eval{remove_const sym} if Object.const_defined?(sym)
Object.const_set(sym, obj)
end
}
end
###################################
private
def _replace_toplevel_aliases(target)
# check already autoloaded
if (table = @TOPLEVEL_ALIAS_TABLE[current = @current_default_widget_set])
table.each{|sym, file|
if !Object.autoload?(sym) && Object.const_defined?(sym) &&
@TOPLEVEL_ALIAS_TABLE[current][sym].kind_of?(String)
# autoload -> class
@TOPLEVEL_ALIAS_TABLE[current][sym] = Object.const_get(sym)
end
}
end
# setup autoloads
@TOPLEVEL_ALIAS_TABLE[target].each{|sym, file|
Object.class_eval{remove_const sym} if Object.const_defined?(sym)
if file.kind_of?(String)
# file => autoload target file
Object.autoload(sym, file)
else
# file => loaded class object
Object.const_set(sym, file)
end
@TOPLEVEL_ALIAS_OWNER[sym] = target
}
# update current alias
@current_default_widget_set = target
end
end
############################################
# setup default widget set => :Tk
Tk.default_widget_set = :Tk
############################################
# depend on the version of Tcl/Tk
# major, minor, type, type_name, patchlevel = TclTkLib.get_version
############################################
# Ttk (Tile) support
=begin
if major > 8 ||
(major == 8 && minor > 5) ||
(major == 8 && minor == 5 && type >= TclTkLib::RELEASE_TYPE::BETA)
# Tcl/Tk 8.5 beta or later
Object.autoload :Ttk, 'tkextlib/tile'
Tk.autoload :Tile, 'tkextlib/tile'
require 'tk/ttk_selector'
end
=end
Object.autoload :Ttk, 'tkextlib/tile'
Tk.autoload :Tile, 'tkextlib/tile'
require 'tk/ttk_selector'

View file

@ -8,30 +8,64 @@ class TkBindTag
#BTagID_TBL = {}
BTagID_TBL = TkCore::INTERP.create_table
Tk_BINDTAG_ID = ["btag".freeze, "00000".taint].freeze
TkCore::INTERP.init_ip_env{ BTagID_TBL.clear }
(Tk_BINDTAG_ID = ["btag".freeze, "00000".taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
TkCore::INTERP.init_ip_env{
BTagID_TBL.mutex.synchronize{ BTagID_TBL.clear }
}
def TkBindTag.id2obj(id)
BTagID_TBL[id]? BTagID_TBL[id]: id
BTagID_TBL.mutex.synchronize{
(BTagID_TBL[id])? BTagID_TBL[id]: id
}
end
=begin
def TkBindTag.new_by_name(name, *args, &b)
BTagID_TBL.mutex.synchronize{
return BTagID_TBL[name] if BTagID_TBL[name]
}
self.new.instance_eval{
BTagID_TBL.mutex.synchronize{
BTagID_TBL.delete @id
@id = name
BTagID_TBL[@id] = self
}
bind(*args, &b) if args != []
self
}
end
=end
def TkBindTag.new_by_name(name, *args, &b)
obj = nil
BTagID_TBL.mutex.synchronize{
if BTagID_TBL[name]
obj = BTagID_TBL[name]
else
(obj = BTagID_TBL[name] = self.allocate).instance_eval{
@id = name
}
end
}
bind(*args, &b) if obj && args != []
obj
end
def initialize(*args, &b)
Tk_BINDTAG_ID.mutex.synchronize{
# @id = Tk_BINDTAG_ID.join('')
@id = Tk_BINDTAG_ID.join(TkCore::INTERP._ip_id_)
Tk_BINDTAG_ID[1].succ!
}
BTagID_TBL.mutex.synchronize{
BTagID_TBL[@id] = self
}
bind(*args, &b) if args != []
end
@ -63,14 +97,37 @@ end
class TkDatabaseClass<TkBindTag
=begin
def self.new(name, *args, &b)
BTagID_TBL.mutex.synchronize{
return BTagID_TBL[name] if BTagID_TBL[name]
}
super(name, *args, &b)
end
def initialize(name, *args, &b)
@id = name
BTagID_TBL.mutex.synchronize{
BTagID_TBL[@id] = self
}
bind(*args, &b) if args != []
end
=end
def self.new(name, *args, &b)
BTagID_TBL.mutex.synchronize{
if BTagID_TBL[name]
BTagID_TBL[name]
else
BTagID_TBL[name] = self.allocate.instance_eval{
initialize(name, *args, &b)
self
}
end
}
end
def initialize(name, *args, &b)
@id = name
bind(*args, &b) if args != []
end

View file

@ -4,7 +4,7 @@
require 'tk'
require 'tk/label'
class TkButton<TkLabel
class Tk::Button<Tk::Label
TkCommandNames = ['button'.freeze].freeze
WidgetClassName = 'Button'.freeze
WidgetClassNames[WidgetClassName] = self
@ -25,3 +25,6 @@ class TkButton<TkLabel
self
end
end
#TkButton = Tk::Button unless Object.const_defined? :TkButton
Tk.__set_toplevel_aliases__(:Tk, Tk::Button, :TkButton)

View file

@ -1,6 +1,5 @@
#
# tk/canvas.rb - Tk canvas classes
# $Date$
# by Yukihiro Matsumoto <matz@caelum.co.jp>
#
require 'tk'
@ -40,7 +39,7 @@ module TkCanvasItemConfig
private :__item_pathname
end
class TkCanvas<TkWindow
class Tk::Canvas<TkWindow
include TkCanvasItemConfig
include Tk::Scrollable
@ -186,11 +185,17 @@ class TkCanvas<TkWindow
end
def delete(*args)
if TkcItem::CItemID_TBL[self.path]
tbl = nil
TkcItem::CItemID_TBL.mutex.synchronize{
tbl = TkcItem::CItemID_TBL[self.path]
}
if tbl
args.each{|tag|
find('withtag', tag).each{|item|
if item.kind_of?(TkcItem)
TkcItem::CItemID_TBL[self.path].delete(item.id)
TkcItem::CItemID_TBL.mutex.synchronize{
tbl.delete(item.id)
}
end
}
}
@ -573,6 +578,10 @@ class TkCanvas<TkWindow
end
end
#TkCanvas = Tk::Canvas unless Object.const_defined? :TkCanvas
Tk.__set_toplevel_aliases__(:Tk, Tk::Canvas, :TkCanvas)
class TkcItem<TkObject
extend Tk
include TkcTagAccess
@ -581,9 +590,12 @@ class TkcItem<TkObject
CItemTypeName = nil
CItemTypeToClass = {}
CItemID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{ CItemID_TBL.clear }
TkCore::INTERP.init_ip_env{
CItemID_TBL.mutex.synchronize{ CItemID_TBL.clear }
}
def TkcItem.type2class(type)
CItemTypeToClass[type]
@ -591,8 +603,13 @@ class TkcItem<TkObject
def TkcItem.id2obj(canvas, id)
cpath = canvas.path
return id unless CItemID_TBL[cpath]
CItemID_TBL.mutex.synchronize{
if CItemID_TBL[cpath]
CItemID_TBL[cpath][id]? CItemID_TBL[cpath][id]: id
else
id
end
}
end
########################################
@ -658,15 +675,17 @@ class TkcItem<TkObject
########################################
def initialize(parent, *args)
#unless parent.kind_of?(TkCanvas)
# fail ArgumentError, "expect TkCanvas for 1st argument"
#unless parent.kind_of?(Tk::Canvas)
# fail ArgumentError, "expect Tk::Canvas for 1st argument"
#end
@parent = @c = parent
@path = parent.path
@id = create_self(*args) # an integer number as 'canvas item id'
CItemID_TBL.mutex.synchronize{
CItemID_TBL[@path] = {} unless CItemID_TBL[@path]
CItemID_TBL[@path][@id] = self
}
end
def create_self(*args)
self.class.create(@c, *args) # return an integer number as 'canvas item id'
@ -687,7 +706,9 @@ class TkcItem<TkObject
def delete
@c.delete @id
CItemID_TBL.mutex.synchronize{
CItemID_TBL[@path].delete(@id) if CItemID_TBL[@path]
}
self
end
alias remove delete

View file

@ -199,14 +199,26 @@ class TkcTag<TkObject
include TkcTagAccess
CTagID_TBL = TkCore::INTERP.create_table
Tk_CanvasTag_ID = ['ctag'.freeze, '00000'.taint].freeze
TkCore::INTERP.init_ip_env{ CTagID_TBL.clear }
(Tk_CanvasTag_ID = ['ctag'.freeze, '00000'.taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
TkCore::INTERP.init_ip_env{
CTagID_TBL.mutex.synchronize{ CTagID_TBL.clear }
}
def TkcTag.id2obj(canvas, id)
cpath = canvas.path
return id unless CTagID_TBL[cpath]
CTagID_TBL.mutex.synchronize{
if CTagID_TBL[cpath]
CTagID_TBL[cpath][id]? CTagID_TBL[cpath][id]: id
else
id
end
}
end
def initialize(parent, mode=nil, *args)
@ -215,11 +227,15 @@ class TkcTag<TkObject
#end
@c = parent
@cpath = parent.path
Tk_CanvasTag_ID.mutex.synchronize{
# @path = @id = Tk_CanvasTag_ID.join('')
@path = @id = Tk_CanvasTag_ID.join(TkCore::INTERP._ip_id_)
Tk_CanvasTag_ID[1].succ!
}
CTagID_TBL.mutex.synchronize{
CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
CTagID_TBL[@cpath][@id] = self
Tk_CanvasTag_ID[1].succ!
}
if mode
tk_call_without_enc(@c.path, "addtag", @id, mode, *args)
end
@ -238,7 +254,9 @@ class TkcTag<TkObject
def delete
@c.delete @id
CTagID_TBL.mutex.synchronize{
CTagID_TBL[@cpath].delete(@id) if CTagID_TBL[@cpath]
}
self
end
alias remove delete
@ -288,23 +306,38 @@ class TkcTag<TkObject
end
class TkcTagString<TkcTag
def self.new(parent, name, *args)
def self.new(parent, name, mode=nil, *args)
obj = nil
CTagID_TBL.mutex.synchronize{
if CTagID_TBL[parent.path] && CTagID_TBL[parent.path][name]
return CTagID_TBL[parent.path][name]
obj = CTagID_TBL[parent.path][name]
else
super(parent, name, *args)
# super(parent, name, *args)
(obj = self.allocate).instance_eval{
@c = parent
@cpath = parent.path
@path = @id = name
CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
CTagID_TBL[@cpath][@id] = self
}
end
}
if obj && mode
tk_call_without_enc(@c.path, "addtag", @id, mode, *args)
end
obj
end
def initialize(parent, name, mode=nil, *args)
# dummy:: not called by 'new' method
#unless parent.kind_of?(TkCanvas)
# fail ArgumentError, "expect TkCanvas for 1st argument"
#end
@c = parent
@cpath = parent.path
@path = @id = name
CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
CTagID_TBL[@cpath][@id] = self
if mode
tk_call_without_enc(@c.path, "addtag", @id, mode, *args)
end
@ -312,7 +345,11 @@ class TkcTagString<TkcTag
end
TkcNamedTag = TkcTagString
class TkcTagAll<TkcTag
class TkcTagAll<TkcTagString
def self.new(parent)
super(parent, 'all')
end
=begin
def initialize(parent)
#unless parent.kind_of?(TkCanvas)
# fail ArgumentError, "expect TkCanvas for 1st argument"
@ -320,12 +357,19 @@ class TkcTagAll<TkcTag
@c = parent
@cpath = parent.path
@path = @id = 'all'
CTagID_TBL.mutex.synchronize{
CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
CTagID_TBL[@cpath][@id] = self
}
end
=end
end
class TkcTagCurrent<TkcTag
class TkcTagCurrent<TkcTagString
def self.new(parent)
super(parent, 'current')
end
=begin
def initialize(parent)
#unless parent.kind_of?(TkCanvas)
# fail ArgumentError, "expect TkCanvas for 1st argument"
@ -333,13 +377,21 @@ class TkcTagCurrent<TkcTag
@c = parent
@cpath = parent.path
@path = @id = 'current'
CTagID_TBL.mutex.synchronize{
CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
CTagID_TBL[@cpath][@id] = self
}
end
=end
end
class TkcGroup<TkcTag
Tk_cGroup_ID = ['tkcg'.freeze, '00000'.taint].freeze
(Tk_cGroup_ID = ['tkcg'.freeze, '00000'.taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
#def create_self(parent, *args)
def initialize(parent, *args)
#unless parent.kind_of?(TkCanvas)
@ -347,11 +399,15 @@ class TkcGroup<TkcTag
#end
@c = parent
@cpath = parent.path
Tk_cGroup_ID.mutex.synchronize{
# @path = @id = Tk_cGroup_ID.join('')
@path = @id = Tk_cGroup_ID.join(TkCore::INTERP._ip_id_)
Tk_cGroup_ID[1].succ!
}
CTagID_TBL.mutex.synchronize{
CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
CTagID_TBL[@cpath][@id] = self
Tk_cGroup_ID[1].succ!
}
include(*args) if args != []
end
#private :create_self

View file

@ -4,7 +4,7 @@
require 'tk'
require 'tk/radiobutton'
class TkCheckButton<TkRadioButton
class Tk::CheckButton<Tk::RadioButton
TkCommandNames = ['checkbutton'.freeze].freeze
WidgetClassName = 'Checkbutton'.freeze
WidgetClassNames[WidgetClassName] = self
@ -22,4 +22,9 @@ class TkCheckButton<TkRadioButton
self
end
end
TkCheckbutton = TkCheckButton
Tk::Checkbutton = Tk::CheckButton
#TkCheckButton = Tk::CheckButton unless Object.const_defined? :TkCheckButton
#TkCheckbutton = Tk::Checkbutton unless Object.const_defined? :TkCheckbutton
Tk.__set_toplevel_aliases__(:Tk, Tk::CheckButton,
:TkCheckButton, :TkCheckbutton)

View file

@ -34,7 +34,8 @@ module TkComposite
if klass
# WidgetClassName is a known class
if klass <= TkFrame || klass < TkComposite
#if klass <= TkFrame || klass < TkComposite
if klass <= TkFrame || klass < Tk::Frame || klass < TkComposite
# klass is valid for the base frame
if self.class <= klass
# use my classname
@ -50,7 +51,8 @@ module TkComposite
else
# klass is invalid for the base frame
if self.class < TkFrame || self.class.superclass < TkComposite
#if self.class < TkFrame || self.class.superclass < TkComposite
if self.class < TkFrame || self.class.superclass < Tk::Frame || self.class.superclass < TkComposite
# my class name is valid for the base frame -> use my classname
base_class_name = self.class.name
if base_class_name == ''
@ -69,7 +71,8 @@ module TkComposite
else
# no valid WidgetClassName
if self.class < TkFrame || self.class.superclass < TkComposite
#if self.class < TkFrame || self.class.superclass < TkComposite
if self.class < TkFrame || self.class.superclass < Tk::Frame || self.class.superclass < TkComposite
# my class name is valid for the base frame -> use my classname
base_class_name = self.class.name
if base_class_name == ''
@ -108,8 +111,12 @@ module TkComposite
end
if base_class_name
# @frame = Tk::Frame.new(parent, :class=>base_class_name)
# --> use current TkFrame class
@frame = TkFrame.new(parent, :class=>base_class_name)
else
# @frame = Tk::Frame.new(parent)
# --> use current TkFrame class
@frame = TkFrame.new(parent)
end
@path = @epath = @frame.path
@ -133,6 +140,11 @@ module TkComposite
def initialize_composite(*args) end
private :initialize_composite
def inspect
str = super
str.chop << ' @epath=' << @epath.inspect << '>'
end
def option_methods(*opts)
opts.each{|m_set, m_cget, m_info|
m_set = m_set.to_s

View file

@ -70,13 +70,89 @@ module Tk
# @encoding = ( enc ||
# ((self.class::Encoding)?
# self.class::Encoding : Tk.encoding_system) )
@encoding = ( enc ||
((self.class::Encoding)?
enc ||= (self.class::Encoding)?
self.class::Encoding :
((Tk.encoding)? Tk.encoding : Tk.encoding_system) ) )
((Tk.encoding)? Tk.encoding : Tk.encoding_system)
if TkCore::WITH_ENCODING
unless encobj = Tk::Encoding::ENCODING_TABLE.get_obj(enc)
fail ArgumentError, "unsupported Tk encoding '#{enc}'"
end
self.force_encoding(encobj)
else
@encoding = enc
end
end
attr_reader :encoding
if TkCore::WITH_ENCODING
alias encoding_obj encoding
alias __encoding encoding
def encoding
Tk::Encoding::ENCODING_TABLE.get_name(super())
end
else
def encoding
@encoding
end
alias encoding_obj encoding
end
if TkCore::WITH_ENCODING
# wrapper methods for compatibility
alias __instance_variable_get instance_variable_get
alias __instance_variable_set instance_variable_set
alias __instance_eval instance_eval
alias __instance_variables instance_variables
def instance_variable_get(key)
if (key.to_s == '@encoding')
self.encoding
else
super(key)
end
end
def instance_variable_set(key, value)
if (key.to_s == '@encoding')
if value
self.force_encoding(value)
else
self.force_encoding(Tk::Encoding::UNKNOWN)
end
value
else
super(key, value)
end
end
def instance_eval(*args, &b)
old_enc = @encoding = self.encoding
ret = super(*args, &b)
if @encoding
if @encoding != old_enc
# modified by user
self.force_encoding(@encoding)
end
remove_instance_variable(:@encoding)
else
begin
remove_instance_variable(:@encoding)
# user sets to nil -> use current default
self.force_encoding(Tk.encoding)
rescue NameError
# removed by user -> ignore, because user don't use @encoding
end
end
ret
end
end
def instance_variables
ret = super()
ret << :@encoding # fake !!
ret
end
end
# def Tk.EncodedString(str, enc = nil)
# Tk::EncodedString.new(str, enc)

View file

@ -1,6 +1,5 @@
#
# tk/entry.rb - Tk entry classes
# $Date$
# by Yukihiro Matsumoto <matz@caelum.co.jp>
require 'tk'
@ -8,7 +7,7 @@ require 'tk/label'
require 'tk/scrollable'
require 'tk/validation'
class TkEntry<TkLabel
class Tk::Entry<Tk::Label
include X_Scrollable
include TkValidation
@ -115,3 +114,6 @@ class TkEntry<TkLabel
val
end
end
#TkEntry = Tk::Entry unless Object.const_defined? :TkEntry
Tk.__set_toplevel_aliases__(:Tk, Tk::Entry, :TkEntry)

View file

@ -39,7 +39,9 @@ module TkEvent
RESIZEREQ = 0x200000
CIRCREQ = 0x400000
MWHEEL = 0x10000000
MWHEEL = KEY
STRING_DATA = 0x80000000 # special flag for 'data' field
ALL = 0xFFFFFFFF
@ -155,7 +157,7 @@ module TkEvent
'borderwidth' => (Grp::CREATE|Grp::CONFIG),
'button' => Grp::BUTTON,
'count' => Grp::EXPOSE,
'data' => Grp::VIRTUAL,
'data' => (Grp::VIRTUAL|Grp::STRING_DATA),
'delta' => Grp::MWHEEL,
'detail' => (Grp::FOCUS|Grp::CROSSING),
'focus' => Grp::CROSSING,
@ -223,7 +225,8 @@ module TkEvent
rescue
next
end
next if !val || val == '??'
# next if !val || val == '??'
next if !val || (val == '??' && (flag & Grp::STRING_DATA))
fields[key] = val
}
@ -298,31 +301,54 @@ module TkEvent
[ ?b, ?n, :num ],
[ ?c, ?n, :count ],
[ ?d, ?s, :detail ],
# ?e
[ ?f, ?b, :focus ],
# ?g
[ ?h, ?n, :height ],
[ ?i, ?s, :win_hex ],
# ?j
[ ?k, ?n, :keycode ],
# ?l
[ ?m, ?s, :mode ],
# ?n
[ ?o, ?b, :override ],
[ ?p, ?s, :place ],
# ?q
# ?r
[ ?s, ?x, :state ],
[ ?t, ?n, :time ],
# ?u
[ ?v, ?n, :value_mask ],
[ ?w, ?n, :width ],
[ ?x, ?n, :x ],
[ ?y, ?n, :y ],
# ?z
[ ?A, ?s, :char ],
[ ?B, ?n, :borderwidth ],
# ?C
[ ?D, ?n, :wheel_delta ],
[ ?E, ?b, :send_event ],
# ?F
# ?G
# ?H
# ?I
# ?J
[ ?K, ?s, :keysym ],
# ?L
# ?M
[ ?N, ?n, :keysym_num ],
# ?O
[ ?P, ?s, :property ],
# ?Q
[ ?R, ?s, :rootwin_id ],
[ ?S, ?s, :subwindow ],
[ ?T, ?n, :type ],
# ?U
# ?V
[ ?W, ?w, :widget ],
[ ?X, ?n, :x_root ],
[ ?Y, ?n, :y_root ],
# ?Z
nil
]
@ -345,6 +371,22 @@ module TkEvent
nil
]
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf|
if inf.kind_of?(Array)
inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
end
inf
}
PROC_TBL.map!{|inf|
if inf.kind_of?(Array)
inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
end
inf
}
# setup tables to be used by scan_args, _get_subst_key, _get_all_subst_keys
#
# _get_subst_key() and _get_all_subst_keys() generates key-string

File diff suppressed because it is too large Load diff

View file

@ -3,7 +3,7 @@
#
require 'tk'
class TkFrame<TkWindow
class Tk::Frame<TkWindow
TkCommandNames = ['frame'.freeze].freeze
WidgetClassName = 'Frame'.freeze
WidgetClassNames[WidgetClassName] = self
@ -126,3 +126,6 @@ class TkFrame<TkWindow
end
end
end
#TkFrame = Tk::Frame unless Object.const_defined? :TkFrame
Tk.__set_toplevel_aliases__(:Tk, Tk::Frame, :TkFrame)

View file

@ -10,9 +10,16 @@ class TkImage<TkObject
TkCommandNames = ['image'.freeze].freeze
Tk_IMGTBL = TkCore::INTERP.create_table
Tk_Image_ID = ['i'.freeze, '00000'.taint].freeze
TkCore::INTERP.init_ip_env{ Tk_IMGTBL.clear }
(Tk_Image_ID = ['i'.freeze, '00000'.taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
TkCore::INTERP.init_ip_env{
Tk_IMGTBL.mutex.synchronize{ Tk_IMGTBL.clear }
}
def self.new(keys=nil)
if keys.kind_of?(Hash)
@ -27,7 +34,10 @@ class TkImage<TkObject
obj = name
else
name = _get_eval_string(name)
obj = nil
Tk_IMGTBL.mutex.synchronize{
obj = Tk_IMGTBL[name]
}
end
if obj
if !(keys[:without_creating] || keys['without_creating'])
@ -43,7 +53,13 @@ class TkImage<TkObject
end
end
end
super(keys)
(obj = self.allocate).instance_eval{
Tk_IMGTBL.mutex.synchronize{
initialize(keys)
Tk_IMGTBL[@path] = self
}
}
obj
end
def initialize(keys=nil)
@ -55,19 +71,22 @@ class TkImage<TkObject
without_creating = keys.delete('without_creating')
end
unless @path
Tk_Image_ID.mutex.synchronize{
# @path = Tk_Image_ID.join('')
@path = Tk_Image_ID.join(TkCore::INTERP._ip_id_)
Tk_Image_ID[1].succ!
}
end
unless without_creating
tk_call_without_enc('image', 'create',
@type, @path, *hash_kv(keys, true))
end
Tk_IMGTBL[@path] = self
end
def delete
Tk_IMGTBL.mutex.synchronize{
Tk_IMGTBL.delete(@id) if @id
}
tk_call_without_enc('image', 'delete', @path)
self
end
@ -85,9 +104,11 @@ class TkImage<TkObject
end
def TkImage.names
Tk_IMGTBL.mutex.synchronize{
Tk.tk_call_without_enc('image', 'names').split.collect!{|id|
(Tk_IMGTBL[id])? Tk_IMGTBL[id] : id
}
}
end
def TkImage.types

View file

@ -115,6 +115,14 @@ module TkItemConfigMethod
include TkTreatItemFont
include TkItemConfigOptkeys
def TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
@mode || false
end
def TkItemConfigMethod.__set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode)
fail SecurityError, "can't change the mode" if $SAFE>=4
@mode = (mode)? true: false
end
def __item_cget_cmd(id)
# maybe need to override
[self.path, 'itemcget', id]
@ -149,7 +157,7 @@ module TkItemConfigMethod
################################################
def itemcget(tagOrId, option)
def __itemcget_core(tagOrId, option)
orig_opt = option
option = option.to_s
@ -224,8 +232,27 @@ module TkItemConfigMethod
tk_tcl2ruby(tk_call_without_enc(*(__item_cget_cmd(tagid(tagOrId)) << "-#{option}")), true)
end
end
private :__itemcget_core
def itemconfigure(tagOrId, slot, value=None)
def itemcget(tagOrId, option)
unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
__itemcget_core(tagOrId, option)
else
begin
__itemcget_core(tagOrId, option)
rescue => e
begin
__itemconfiginfo_core(tagOrId)
# not tag error -> option is unknown
nil
rescue
fail e # tag error
end
end
end
end
def __itemconfigure_core(tagOrId, slot, value=None)
if slot.kind_of? Hash
slot = _symbolkey2str(slot)
@ -288,6 +315,48 @@ module TkItemConfigMethod
end
self
end
private :__itemconfigure_core
def __check_available_itemconfigure_options(tagOrId, keys)
id = tagid(tagOrId)
availables = self.current_itemconfiginfo(id).keys
# add non-standard keys
availables |= __font_optkeys.map{|k|
[k.to_s, "latin#{k}", "ascii#{k}", "kanji#{k}"]
}.flatten
availables |= __item_methodcall_optkeys(id).keys.map{|k| k.to_s}
availables |= __item_keyonly_optkeys(id).keys.map{|k| k.to_s}
keys = _symbolkey2str(keys)
keys.delete_if{|k, v| !(availables.include?(k))}
end
def itemconfigure(tagOrId, slot, value=None)
unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
__itemconfigure_core(tagOrId, slot, value)
else
if slot.kind_of?(Hash)
begin
__itemconfigure_core(tagOrId, slot)
rescue
slot = __check_available_configure_options(tagOrId, slot)
__itemconfigure_core(tagOrId, slot) unless slot.empty?
end
else
begin
__itemconfigure_core(tagOrId, slot, value)
rescue => e
begin
__itemconfiginfo_core(tagOrId)
rescue
fail e # tag error
end
end
end
end
self
end
def __itemconfiginfo_core(tagOrId, slot = nil)
if TkComm::GET_CONFIGINFO_AS_ARRAY
@ -299,6 +368,10 @@ module TkItemConfigMethod
conf[__item_configinfo_struct(tagid(tagOrId))[:key]][1..-1]
if ( ! __item_configinfo_struct(tagid(tagOrId))[:alias] \
|| conf.size > __item_configinfo_struct(tagid(tagOrId))[:alias] + 1 )
fnt = conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
if TkFont.is_system_font?(fnt)
conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = TkNamedFont.new(fnt)
end
conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = tagfontobj(tagid(tagOrId), fontkey)
elsif ( __item_configinfo_struct(tagid(tagOrId))[:alias] \
&& conf.size == __item_configinfo_struct(tagid(tagOrId))[:alias] + 1 \
@ -635,6 +708,10 @@ module TkItemConfigMethod
fontconf = ret.assoc(optkey)
if fontconf && fontconf.size > 2
ret.delete_if{|inf| inf[0] =~ /^(|latin|ascii|kanji)#{optkey}$/}
fnt = fontconf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
if TkFont.is_system_font?(fnt)
fontconf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = TkNamedFont.new(fnt)
end
fontconf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = tagfontobj(tagid(tagOrId), optkey)
ret.push(fontconf)
end
@ -658,7 +735,11 @@ module TkItemConfigMethod
if ( ! __item_configinfo_struct(tagid(tagOrId))[:alias] \
|| conf.size > __item_configinfo_struct(tagid(tagOrId))[:alias] + 1 )
conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = fontobj(tagid(tagOrId), fontkey)
fnt = conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
if TkFont.is_system_font?(fnt)
conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = TkNamedFont.new(fnt)
end
conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = tagfontobj(tagid(tagOrId), fontkey)
{ conf.shift => conf }
elsif ( __item_configinfo_struct(tagid(tagOrId))[:alias] \
&& conf.size == __item_configinfo_struct(tagid(tagOrId))[:alias] + 1 )
@ -1006,6 +1087,10 @@ module TkItemConfigMethod
ret.delete('latin' << optkey)
ret.delete('ascii' << optkey)
ret.delete('kanji' << optkey)
fnt = fontconf[__item_configinfo_struct(tagid(tagOrId))[:default_value]]
if TkFont.is_system_font?(fnt)
fontconf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = TkNamedFont.new(fnt)
end
fontconf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = tagfontobj(tagid(tagOrId), optkey)
ret[optkey] = fontconf
end
@ -1023,7 +1108,21 @@ module TkItemConfigMethod
private :__itemconfiginfo_core
def itemconfiginfo(tagOrId, slot = nil)
if slot && TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
begin
__itemconfiginfo_core(tagOrId, slot)
rescue => e
begin
__itemconfiginfo_core(tagOrId)
# not tag error -> option is unknown
Array.new(__item_configinfo_struct.values.max).unshift(slot.to_s)
rescue
fail e # tag error
end
end
else
__itemconfiginfo_core(tagOrId, slot)
end
end
def current_itemconfiginfo(tagOrId, slot = nil)

View file

@ -3,7 +3,7 @@
#
require 'tk'
class TkLabel<TkWindow
class Tk::Label<TkWindow
TkCommandNames = ['label'.freeze].freeze
WidgetClassName = 'Label'.freeze
WidgetClassNames[WidgetClassName] = self
@ -16,3 +16,6 @@ class TkLabel<TkWindow
#end
#private :create_self
end
#TkLabel = Tk::Label unless Object.const_defined? :TkLabel
Tk.__set_toplevel_aliases__(:Tk, Tk::Label, :TkLabel)

View file

@ -4,7 +4,7 @@
require 'tk'
require 'tk/frame'
class TkLabelFrame<TkFrame
class Tk::LabelFrame<Tk::Frame
TkCommandNames = ['labelframe'.freeze].freeze
WidgetClassName = 'Labelframe'.freeze
WidgetClassNames[WidgetClassName] = self
@ -22,4 +22,8 @@ class TkLabelFrame<TkFrame
end
private :__val2ruby_optkeys
end
TkLabelframe = TkLabelFrame
Tk::Labelframe = Tk::LabelFrame
#TkLabelFrame = Tk::LabelFrame unless Object.const_defined? :TkLabelFrame
#TkLabelframe = Tk::Labelframe unless Object.const_defined? :TkLabelframe
Tk.__set_toplevel_aliases__(:Tk, Tk::LabelFrame, :TkLabelFrame, :TkLabelframe)

View file

@ -15,7 +15,7 @@ module TkListItemConfig
private :__item_listval_optkeys
end
class TkListbox<TkTextWin
class Tk::Listbox<TkTextWin
include TkListItemConfig
include Scrollable
@ -277,3 +277,6 @@ class TkListbox<TkTextWin
end
=end
end
#TkListbox = Tk::Listbox unless Object.const_defined? :TkListbox
Tk.__set_toplevel_aliases__(:Tk, Tk::Listbox, :TkListbox)

View file

@ -20,9 +20,14 @@ module Tk
end
end
module TkMacResource
module Tk::MacResource
end
#TkMacResource = Tk::MacResource
Tk.__set_toplevel_aliases__(:Tk, Tk::MacResource, :TkMacResource)
module Tk::MacResource
extend Tk
extend TkMacResource
extend Tk::MacResource
TkCommandNames = ['resource'.freeze].freeze

View file

@ -42,7 +42,7 @@ module TkMenuEntryConfig
private :itemconfiginfo, :current_itemconfiginfo
end
class TkMenu<TkWindow
class Tk::Menu<TkWindow
include Wm
include TkMenuEntryConfig
extend TkMenuSpec
@ -140,9 +140,9 @@ class TkMenu<TkWindow
type = keys.delete('type') if keys.has_key?('type')
if keys.empty?
TkMenuClone.new(self, parent, type)
Tk::MenuClone.new(self, parent, type)
else
TkMenuClone.new(self, parent, type, keys)
Tk::MenuClone.new(self, parent, type, keys)
end
end
@ -202,6 +202,9 @@ class TkMenu<TkWindow
tk_send_without_enc('unpost')
self
end
def xposition(index)
number(tk_send_without_enc('xposition', _get_eval_enc_str(index)))
end
def yposition(index)
number(tk_send_without_enc('yposition', _get_eval_enc_str(index)))
end
@ -381,8 +384,11 @@ class TkMenu<TkWindow
=end
end
#TkMenu = Tk::Menu unless Object.const_defined? :TkMenu
Tk.__set_toplevel_aliases__(:Tk, Tk::Menu, :TkMenu)
class TkMenuClone<TkMenu
class Tk::MenuClone<Tk::Menu
=begin
def initialize(parent, type=None)
widgetname = nil
@ -436,9 +442,12 @@ class TkMenuClone<TkMenu
@src_menu
end
end
TkCloneMenu = TkMenuClone
Tk::CloneMenu = Tk::MenuClone
#TkMenuClone = Tk::MenuClone unless Object.const_defined? :TkMenuClone
#TkCloneMenu = Tk::CloneMenu unless Object.const_defined? :TkCloneMenu
Tk.__set_toplevel_aliases__(:Tk, Tk::MenuClone, :TkMenuClone, :TkCloneMenu)
module TkSystemMenu
module Tk::SystemMenu
def initialize(parent, keys=nil)
if parent.kind_of? Hash
keys = _symbolkey2str(parent)
@ -461,38 +470,60 @@ module TkSystemMenu
end
end
end
TkSystemMenu = Tk::SystemMenu
class TkSysMenu_Help<TkMenu
class Tk::SysMenu_Help<Tk::Menu
# for all platform
include TkSystemMenu
include Tk::SystemMenu
SYSMENU_NAME = 'help'
end
#TkSysMenu_Help = Tk::SysMenu_Help unless Object.const_defined? :TkSysMenu_Help
Tk.__set_toplevel_aliases__(:Tk, Tk::SysMenu_Help, :TkSysMenu_Help)
class TkSysMenu_System<TkMenu
class Tk::SysMenu_System<Tk::Menu
# for Windows
include TkSystemMenu
include Tk::SystemMenu
SYSMENU_NAME = 'system'
end
#TkSysMenu_System = Tk::SysMenu_System unless Object.const_defined? :TkSysMenu_System
Tk.__set_toplevel_aliases__(:Tk, Tk::SysMenu_System, :TkSysMenu_System)
class TkSysMenu_Apple<TkMenu
class Tk::SysMenu_Apple<Tk::Menu
# for Machintosh
include TkSystemMenu
include Tk::SystemMenu
SYSMENU_NAME = 'apple'
end
#TkSysMenu_Apple = Tk::SysMenu_Apple unless Object.const_defined? :TkSysMenu_Apple
Tk.__set_toplevel_aliases__(:Tk, Tk::SysMenu_Apple, :TkSysMenu_Apple)
class TkMenubutton<TkLabel
class Tk::Menubutton<Tk::Label
TkCommandNames = ['menubutton'.freeze].freeze
WidgetClassName = 'Menubutton'.freeze
WidgetClassNames[WidgetClassName] = self
def create_self(keys)
if keys and keys != None
unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
# tk_call_without_enc('menubutton', @path, *hash_kv(keys, true))
tk_call_without_enc(self.class::TkCommandNames[0], @path,
*hash_kv(keys, true))
else
begin
tk_call_without_enc(self.class::TkCommandNames[0], @path,
*hash_kv(keys, true))
rescue
tk_call_without_enc(self.class::TkCommandNames[0], @path)
keys = __check_available_configure_options(keys)
unless keys.empty?
tk_call_without_enc('destroy', @path)
tk_call_without_enc(self.class::TkCommandNames[0], @path,
*hash_kv(keys, true))
end
end
end
else
# tk_call_without_enc('menubutton', @path)
tk_call_without_enc(self.class::TkCommandNames[0], @path)
@ -506,10 +537,13 @@ class TkMenubutton<TkLabel
private :__boolval_optkeys
end
TkMenuButton = TkMenubutton
Tk::MenuButton = Tk::Menubutton
#TkMenubutton = Tk::Menubutton unless Object.const_defined? :TkMenubutton
#TkMenuButton = Tk::MenuButton unless Object.const_defined? :TkMenuButton
Tk.__set_toplevel_aliases__(:Tk, Tk::Menubutton, :TkMenubutton, :TkMenuButton)
class TkOptionMenubutton<TkMenubutton
class Tk::OptionMenubutton<Tk::Menubutton
TkCommandNames = ['tk_optionMenu'.freeze].freeze
class OptionMenu<TkMenu
@ -596,6 +630,9 @@ class TkOptionMenubutton<TkMenubutton
@menu.delete(index, last)
self
end
def xposition(index)
@menu.xposition(index)
end
def yposition(index)
@menu.yposition(index)
end
@ -629,4 +666,9 @@ class TkOptionMenubutton<TkMenubutton
@menu.current_entryconfiginfo(index, key)
end
end
TkOptionMenuButton = TkOptionMenubutton
Tk::OptionMenuButton = Tk::OptionMenubutton
#TkOptionMenubutton = Tk::OptionMenubutton unless Object.const_defined? :TkOptionMenubutton
#TkOptionMenuButton = Tk::OptionMenuButton unless Object.const_defined? :TkOptionMenuButton
Tk.__set_toplevel_aliases__(:Tk, Tk::OptionMenubutton,
:TkOptionMenubutton, :TkOptionMenuButton)

View file

@ -89,7 +89,7 @@ require 'tk/frame'
require 'tk/composite'
require 'tk/menuspec'
class TkMenubar<TkFrame
class TkMenubar<Tk::Frame
include TkComposite
include TkMenuSpec

View file

@ -61,8 +61,12 @@ module TkMenuSpec
tearoff = orig_opts.delete('tearoff') if orig_opts.key?('tearoff')
if menu_name
#menu = Tk::Menu.new(parent, :widgetname=>menu_name, :tearoff=>tearoff)
# --> use current TkMenu class
menu = TkMenu.new(parent, :widgetname=>menu_name, :tearoff=>tearoff)
else
#menu = Tk::Menu.new(parent, :tearoff=>tearoff)
# --> use current TkMenu class
menu = TkMenu.new(parent, :tearoff=>tearoff)
end
@ -150,7 +154,7 @@ module TkMenuSpec
def _use_menubar?(parent)
use_menubar = false
if parent.kind_of?(TkRoot) || parent.kind_of?(TkToplevel)
if parent.kind_of?(Tk::Root) || parent.kind_of?(Tk::Toplevel)
return true
else
begin
@ -164,7 +168,11 @@ module TkMenuSpec
private :_use_menubar?
def _create_menu_for_menubar(parent)
unless (mbar = parent.menu).kind_of?(TkMenu)
#unless (mbar = parent.menu).kind_of?(TkMenu)
# --> use current TkMenu class
mbar = parent.menu
unless parent.menu.kind_of?(Tk::Menu) || parent.menu.kind_of?(TkMenu)
#mbar = Tk::Menu.new(parent, :tearoff=>false)
mbar = TkMenu.new(parent, :tearoff=>false)
parent.menu(mbar)
end
@ -221,6 +229,8 @@ module TkMenuSpec
else
# menubar by menubuttons
#mbtn = Tk::Menubutton.new(parent)
# --> use current TkMenubutton class
mbtn = TkMenubutton.new(parent)
menu_name = nil

View file

@ -4,7 +4,7 @@
require 'tk'
require 'tk/label'
class TkMessage<TkLabel
class Tk::Message<Tk::Label
TkCommandNames = ['message'.freeze].freeze
WidgetClassName = 'Message'.freeze
WidgetClassNames[WidgetClassName] = self
@ -17,3 +17,6 @@ class TkMessage<TkLabel
#end
private :create_self
end
#TkMessage = Tk::Message unless Object.const_defined? :TkMessage
Tk.__set_toplevel_aliases__(:Tk, Tk::Message, :TkMessage)

View file

@ -74,7 +74,11 @@ class TkMsgCatalog < TkObject
"\n---< backtrace of Ruby side >-----\n" +
_toUTF8(e.backtrace.join("\n")) +
"\n---< backtrace of Tk side >-------"
if TkCore::WITH_ENCODING
msg.force_encoding('utf-8')
else
msg.instance_variable_set(:@encoding, 'utf-8')
end
rescue Exception
msg = e.class.inspect + ': ' + e.message + "\n" +
"\n---< backtrace of Ruby side >-----\n" +

View file

@ -12,17 +12,24 @@ class TkNamespace < TkObject
].freeze
Tk_Namespace_ID_TBL = TkCore::INTERP.create_table
Tk_Namespace_ID = ["ns".freeze, "00000".taint].freeze
(Tk_Namespace_ID = ["ns".freeze, "00000".taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
Tk_NsCode_RetObjID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{
Tk_Namespace_ID_TBL.clear
Tk_NsCode_RetObjID_TBL.clear
Tk_Namespace_ID_TBL.mutex.synchronize{ Tk_Namespace_ID_TBL.clear }
Tk_NsCode_RetObjID_TBL.mutex.synchronize{ Tk_NsCode_RetObjID_TBL.clear }
}
def TkNamespace.id2obj(id)
Tk_Namespace_ID_TBL.mutex.synchronize{
Tk_Namespace_ID_TBL[id]? Tk_Namespace_ID_TBL[id]: id
}
end
#####################################
@ -65,11 +72,13 @@ class TkNamespace < TkObject
def cget(slot)
if slot == :namespace || slot == 'namespace'
ns = super(slot)
Tk_Namespace_ID_TBL.mutex.synchronize{
if TkNamespace::Tk_Namespace_ID_TBL.key?(ns)
TkNamespace::Tk_Namespace_ID_TBL[ns]
else
ns
end
}
else
super(slot)
end
@ -79,9 +88,11 @@ class TkNamespace < TkObject
if slot
if slot == :namespace || slot == 'namespace'
val = super(slot)
Tk_Namespace_ID_TBL.mutex.synchronize{
if TkNamespace::Tk_Namespace_ID_TBL.key?(val)
val = TkNamespace::Tk_Namespace_ID_TBL[val]
end
}
else
val = super(slot)
end
@ -96,6 +107,7 @@ class TkNamespace < TkObject
info = super()
if TkComm::GET_CONFIGINFO_AS_ARRAY
Tk_Namespace_ID_TBL.mutex.synchronize{
info.map!{|inf|
if inf[0] == 'namespace' &&
TkNamespace::Tk_Namespace_ID_TBL.key?(inf[-1])
@ -104,11 +116,14 @@ class TkNamespace < TkObject
inf
end
}
}
else # ! TkComm::GET_CONFIGINFO_AS_ARRAY
val = info['namespace']
Tk_Namespace_ID_TBL.mutex.synchronize{
if TkNamespace::Tk_Namespace_ID_TBL.key?(val)
info['namespace'] = TkNamespace::Tk_Namespace_ID_TBL[val]
end
}
end
info
@ -215,9 +230,11 @@ class TkNamespace < TkObject
def initialize(name = nil, parent = nil)
unless name
Tk_Namespace_ID.mutex.synchronize{
# name = Tk_Namespace_ID.join('')
name = Tk_Namespace_ID.join(TkCore::INTERP._ip_id_)
Tk_Namespace_ID[1].succ!
}
end
name = __tk_call('namespace', 'current') if name == ''
if parent
@ -252,7 +269,9 @@ class TkNamespace < TkObject
# create namespace
__tk_call('namespace', 'eval', @fullname, '')
Tk_Namespace_ID_TBL.mutex.synchronize{
Tk_Namespace_ID_TBL[@fullname] = self
}
end
def self.children(*args)
@ -260,12 +279,14 @@ class TkNamespace < TkObject
# <pattern> must be glob-style pattern
tk_split_simplelist(tk_call('namespace', 'children', *args)).collect{|ns|
# ns is fullname
Tk_Namespace_ID_TBL.mutex.synchronize{
if Tk_Namespace_ID_TBL.key?(ns)
Tk_Namespace_ID_TBL[ns]
else
ns
end
}
}
end
def children(pattern=None)
TkNamespace.children(@fullname, pattern)
@ -290,14 +311,24 @@ class TkNamespace < TkObject
def code(script = Proc.new)
if script.kind_of?(String)
cmd = proc{|*args|
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
obj = ScopeArgs.new(@fullname,*args)
ret = obj.instance_exec(obj, script)
else
ret = ScopeArgs.new(@fullname,*args).instance_eval(script)
end
id = ret.object_id
TkNamespace::Tk_NsCode_RetObjID_TBL[id] = ret
id
}
elsif script.kind_of?(Proc)
cmd = proc{|*args|
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
obj = ScopeArgs.new(@fullname,*args)
ret = obj.instance_exec(obj, &script)
else
ret = ScopeArgs.new(@fullname,*args).instance_eval(&script)
end
id = ret.object_id
TkNamespace::Tk_NsCode_RetObjID_TBL[id] = ret
id
@ -319,11 +350,13 @@ class TkNamespace < TkObject
def self.current
ns = self.current_path
Tk_Namespace_ID_TBL.mutex.synchronize{
if Tk_Namespace_ID_TBL.key?(ns)
Tk_Namespace_ID_TBL[ns]
else
ns
end
}
end
def current_namespace
# ns_tk_call('namespace', 'current')
@ -335,12 +368,14 @@ class TkNamespace < TkObject
def self.delete(*ns_list)
tk_call('namespace', 'delete', *ns_list)
ns_list.each{|ns|
Tk_Namespace_ID_TBL.mutex.synchronize{
if ns.kind_of?(TkNamespace)
Tk_Namespace_ID_TBL.delete(ns.path)
else
Tk_Namespace_ID_TBL.delete(ns.to_s)
end
}
}
end
def delete
TkNamespece.delete(@fullname)
@ -371,7 +406,7 @@ class TkNamespace < TkObject
def self.eval(namespace, cmd = Proc.new, *args)
#tk_call('namespace', 'eval', namespace, cmd, *args)
TkNamespace.new(namespece).eval(cmd, *args)
TkNamespace.new(namespace).eval(cmd, *args)
end
=begin
def eval(cmd = Proc.new, *args)
@ -444,11 +479,13 @@ class TkNamespace < TkObject
def self.parent(namespace=None)
ns = tk_call('namespace', 'parent', namespace)
Tk_Namespace_ID_TBL.mutex.synchronize{
if Tk_Namespace_ID_TBL.key?(ns)
Tk_Namespace_ID_TBL[ns]
else
ns
end
}
end
def parent
tk_call('namespace', 'parent', @fullname)

View file

@ -8,7 +8,11 @@ module TkOptionDB
extend Tk
TkCommandNames = ['option'.freeze].freeze
CmdClassID = ['CMD_CLASS'.freeze, '00000'.taint].freeze
(CmdClassID = ['CMD_CLASS'.freeze, '00000'.taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
module Priority
WidgetDefault = 20
@ -250,8 +254,10 @@ module TkOptionDB
def __create_new_class(klass, func, safe = 4, add = false, parent = nil)
if klass.kind_of?(TkWindow)
carrier = klass.path
CmdClassID.mutex.synchronize{
klass = CmdClassID.join(TkCore::INTERP._ip_id_)
CmdClassID[1].succ!
}
parent = nil # ignore parent
else
klass = klass.to_s if klass.kind_of?(Symbol)
@ -312,7 +318,7 @@ module TkOptionDB
:singleton_methods, :remove_const, :remove_method, :undef_method,
:to_s, :inspect, :display, :method, :methods, :respond_to?,
:instance_variable_get, :instance_variable_set, :instance_method,
:instance_eval, :instance_variables, :kind_of?, :is_a?,
:instance_eval, :instance_exec, :instance_variables, :kind_of?, :is_a?,
:private_methods, :protected_methods, :public_methods ].each{|m|
alias_method(m, :__null_method)
}
@ -362,7 +368,7 @@ module TkOptionDB
def new_proc_class_random(klass, func, safe = 4, add = false, &b)
eval_under_random_base(){
TkOption.new_proc_class(klass, func, safe, add, self, &b)
TkOptionDB.new_proc_class(klass, func, safe, add, self, &b)
}
end
module_function :new_proc_class_random

View file

@ -136,4 +136,8 @@ module TkPackage
def vsatisfies(version1, version2)
bool(tk_call('package', 'vsatisfies', version1, version2))
end
def prefer(setting = None)
tk_call('package', 'prefer', setting)
end
end

View file

@ -3,7 +3,7 @@
#
require 'tk'
class TkPanedWindow<TkWindow
class Tk::PanedWindow<TkWindow
TkCommandNames = ['panedwindow'.freeze].freeze
WidgetClassName = 'Panedwindow'.freeze
WidgetClassNames[WidgetClassName] = self
@ -229,4 +229,9 @@ class TkPanedWindow<TkWindow
list(tk_send_without_enc('panes'))
end
end
TkPanedwindow = TkPanedWindow
Tk::Panedwindow = Tk::PanedWindow
#TkPanedWindow = Tk::PanedWindow unless Object.const_defined? :TkPanedWindow
#TkPanedwindow = Tk::Panedwindow unless Object.const_defined? :TkPanedwindow
Tk.__set_toplevel_aliases__(:Tk, Tk::PanedWindow,
:TkPanedWindow, :TkPanedwindow)

View file

@ -4,7 +4,7 @@
require 'tk'
require 'tk/button'
class TkRadioButton<TkButton
class Tk::RadioButton<Tk::Button
TkCommandNames = ['radiobutton'.freeze].freeze
WidgetClassName = 'Radiobutton'.freeze
WidgetClassNames[WidgetClassName] = self
@ -63,4 +63,9 @@ class TkRadioButton<TkButton
end
end
end
TkRadiobutton = TkRadioButton
Tk::Radiobutton = Tk::RadioButton
#TkRadioButton = Tk::RadioButton unless Object.const_defined? :TkRadioButton
#TkRadiobutton = Tk::Radiobutton unless Object.const_defined? :TkRadiobutton
Tk.__set_toplevel_aliases__(:Tk, Tk::RadioButton,
:TkRadioButton, :TkRadiobutton)

View file

@ -5,7 +5,7 @@ require 'tk'
require 'tk/wm'
require 'tk/menuspec'
class TkRoot<TkWindow
class Tk::Root<TkWindow
include Wm
include TkMenuSpec
@ -14,28 +14,7 @@ class TkRoot<TkWindow
end
private :__methodcall_optkeys
=begin
ROOT = []
def TkRoot.new(keys=nil)
if ROOT[0]
Tk_WINDOWS["."] = ROOT[0]
return ROOT[0]
end
new = super(:without_creating=>true, :widgetname=>'.')
if keys # wm commands
keys.each{|k,v|
if v.kind_of? Array
new.send(k,*v)
else
new.send(k,v)
end
}
end
ROOT[0] = new
Tk_WINDOWS["."] = new
end
=end
def TkRoot.new(keys=nil, &b)
def Root.new(keys=nil, &b)
unless TkCore::INTERP.tk_windows['.']
TkCore::INTERP.tk_windows['.'] =
super(:without_creating=>true, :widgetname=>'.'){}
@ -62,7 +41,13 @@ class TkRoot<TkWindow
}
end
root.instance_eval(&b) if block_given?
if block_given?
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
root.instance_exec(root, &b)
else
root.instance_eval(&b)
end
end
root
end
@ -102,7 +87,9 @@ class TkRoot<TkWindow
self.menu
end
def TkRoot.destroy
def Root.destroy
TkCore::INTERP._invoke('destroy', '.')
end
end
TkRoot = Tk::Root unless Object.const_defined? :TkRoot

View file

@ -3,7 +3,7 @@
#
require 'tk'
class TkScale<TkWindow
class Tk::Scale<TkWindow
TkCommandNames = ['scale'.freeze].freeze
WidgetClassName = 'Scale'.freeze
WidgetClassNames[WidgetClassName] = self
@ -14,9 +14,24 @@ class TkScale<TkWindow
cmd = keys.delete('command')
keys['command'] = proc{|val| cmd.call(val.to_f)}
end
unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
#tk_call_without_enc('scale', @path, *hash_kv(keys, true))
tk_call_without_enc(self.class::TkCommandNames[0], @path,
*hash_kv(keys, true))
else
begin
tk_call_without_enc(self.class::TkCommandNames[0], @path,
*hash_kv(keys, true))
rescue
tk_call_without_enc(self.class::TkCommandNames[0], @path)
keys = __check_available_configure_options(keys)
unless keys.empty?
tk_call_without_enc('destroy', @path)
tk_call_without_enc(self.class::TkCommandNames[0], @path,
*hash_kv(keys, true))
end
end
end
else
#tk_call_without_enc('scale', @path)
tk_call_without_enc(self.class::TkCommandNames[0], @path)
@ -84,3 +99,6 @@ class TkScale<TkWindow
val
end
end
#TkScale = Tk::Scale unless Object.const_defined? :TkScale
Tk.__set_toplevel_aliases__(:Tk, Tk::Scale, :TkScale)

View file

@ -3,7 +3,7 @@
#
require 'tk'
class TkScrollbar<TkWindow
class Tk::Scrollbar<TkWindow
TkCommandNames = ['scrollbar'.freeze].freeze
WidgetClassName = 'Scrollbar'.freeze
WidgetClassNames[WidgetClassName] = self
@ -19,9 +19,24 @@ class TkScrollbar<TkWindow
}
if keys and keys != None
unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
#tk_call_without_enc('scrollbar', @path, *hash_kv(keys, true))
tk_call_without_enc(self.class::TkCommandNames[0], @path,
*hash_kv(keys, true))
else
begin
tk_call_without_enc(self.class::TkCommandNames[0], @path,
*hash_kv(keys, true))
rescue
tk_call_without_enc(self.class::TkCommandNames[0], @path)
keys = __check_available_configure_options(keys)
unless keys.empty?
tk_call_without_enc('destroy', @path)
tk_call_without_enc(self.class::TkCommandNames[0], @path,
*hash_kv(keys, true))
end
end
end
else
#tk_call_without_enc('scrollbar', @path)
tk_call_without_enc(self.class::TkCommandNames[0], @path)
@ -103,9 +118,33 @@ class TkScrollbar<TkWindow
def activate(element=None)
tk_send_without_enc('activate', element)
end
def moveto(fraction)
tk_send_without_enc('moveto', fraction)
self
end
class TkXScrollbar<TkScrollbar
def scroll(*args)
tk_send_without_enc('scroll', *args)
self
end
def scroll_units(num)
scroll(num, 'units')
self
end
def scroll_pages(num)
scroll(num, 'pages')
self
end
end
#TkScrollbar = Tk::Scrollbar unless Object.const_defined? :TkScrollbar
Tk.__set_toplevel_aliases__(:Tk, Tk::Scrollbar, :TkScrollbar)
class Tk::XScrollbar<Tk::Scrollbar
def create_self(keys)
keys = {} unless keys
keys['orient'] = 'horizontal'
@ -114,7 +153,11 @@ class TkXScrollbar<TkScrollbar
private :create_self
end
class TkYScrollbar<TkScrollbar
#TkXScrollbar = Tk::XScrollbar unless Object.const_defined? :TkXScrollbar
Tk.__set_toplevel_aliases__(:Tk, Tk::XScrollbar, :TkXScrollbar)
class Tk::YScrollbar<Tk::Scrollbar
def create_self(keys)
keys = {} unless keys
keys['orient'] = 'vertical'
@ -122,3 +165,6 @@ class TkYScrollbar<TkScrollbar
end
private :create_self
end
#TkYScrollbar = Tk::YScrollbar unless Object.const_defined? :TkYScrollbar
Tk.__set_toplevel_aliases__(:Tk, Tk::YScrollbar, :TkYScrollbar)

View file

@ -1,16 +1,19 @@
#
# tk/scrollbox.rb - Tk Listbox with Scrollbar
# as an example of Composite Widget
# $Date$
# by Yukihiro Matsumoto <matz@netlab.co.jp>
#
require 'tk'
require 'tk/listbox'
class TkScrollbox<TkListbox
class TkScrollbox<Tk::Listbox
include TkComposite
def initialize_composite(keys=nil)
#list = Tk::Listbox.new(@frame)
# -> use current TkListbox class
list = TkListbox.new(@frame)
#scroll = Tk::Scrollbar.new(@frame)
# -> use current TkScrollbar class
scroll = TkScrollbar.new(@frame)
@path = list.path

View file

@ -1,12 +1,11 @@
#
# tk/spinbox.rb - Tk spinbox classes
# $Date$
# by Yukihiro Matsumoto <matz@caelum.co.jp>
#
require 'tk'
require 'tk/entry'
class TkSpinbox<TkEntry
class Tk::Spinbox<Tk::Entry
TkCommandNames = ['spinbox'.freeze].freeze
WidgetClassName = 'Spinbox'.freeze
WidgetClassNames[WidgetClassName] = self
@ -38,6 +37,22 @@ class TkSpinbox<TkEntry
nil
]
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf|
if inf.kind_of?(Array)
inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
end
inf
}
PROC_TBL.map!{|inf|
if inf.kind_of?(Array)
inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
end
inf
}
_setup_subst_table(KEY_TBL, PROC_TBL);
def self.ret_val(val)
@ -97,3 +112,6 @@ class TkSpinbox<TkEntry
_fromUTF8(tk_send_without_enc('set', _get_eval_enc_str(str)))
end
end
#TkSpinbox = Tk::Spinbox unless Object.const_defined? :TkSpinbox
Tk.__set_toplevel_aliases__(:Tk, Tk::Spinbox, :TkSpinbox)

View file

@ -1,6 +1,5 @@
#
# tk/text.rb - Tk text classes
# $Date$
# by Yukihiro Matsumoto <matz@caelum.co.jp>
require 'tk'
require 'tk/itemfont'
@ -60,7 +59,7 @@ module TkTextTagConfig
private :itemconfiginfo, :current_itemconfiginfo
end
class TkText<TkTextWin
class Tk::Text<TkTextWin
ItemConfCMD = ['tag'.freeze, 'configure'.freeze].freeze
#include TkTreatTextTagFont
include TkTextTagConfig
@ -74,9 +73,9 @@ class TkText<TkTextWin
mod = mod.to_s
if mod =~ /^\s*[+-]?\d/
TkText::IndexString.new(String.new(id) << ' + ' << mod)
Tk::Text::IndexString.new(String.new(id) << ' + ' << mod)
else
TkText::IndexString.new(String.new(id) << ' ' << mod)
Tk::Text::IndexString.new(String.new(id) << ' ' << mod)
end
end
@ -85,20 +84,20 @@ class TkText<TkTextWin
mod = mod.to_s
if mod =~ /^\s*[+-]?\d/
TkText::IndexString.new(String.new(id) << ' - ' << mod)
Tk::Text::IndexString.new(String.new(id) << ' - ' << mod)
elsif mod =~ /^\s*[-]\s+(\d.*)$/
TkText::IndexString.new(String.new(id) << ' - -' << $1)
Tk::Text::IndexString.new(String.new(id) << ' - -' << $1)
else
TkText::IndexString.new(String.new(id) << ' ' << mod)
Tk::Text::IndexString.new(String.new(id) << ' ' << mod)
end
end
def chars(mod)
fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer)
if mod < 0
TkText::IndexString.new(String.new(id) << ' ' << mod.to_s << ' chars')
Tk::Text::IndexString.new(String.new(id) << ' ' << mod.to_s << ' chars')
else
TkText::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' chars')
Tk::Text::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' chars')
end
end
alias char chars
@ -107,9 +106,9 @@ class TkText<TkTextWin
# Tk8.5 feature
fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer)
if mod < 0
TkText::IndexString.new(String.new(id) << ' ' << mod.to_s << ' display chars')
Tk::Text::IndexString.new(String.new(id) << ' ' << mod.to_s << ' display chars')
else
TkText::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' display chars')
Tk::Text::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' display chars')
end
end
alias display_char display_chars
@ -118,9 +117,9 @@ class TkText<TkTextWin
# Tk8.5 feature
fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer)
if mod < 0
TkText::IndexString.new(String.new(id) << ' ' << mod.to_s << ' any chars')
Tk::Text::IndexString.new(String.new(id) << ' ' << mod.to_s << ' any chars')
else
TkText::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' any chars')
Tk::Text::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' any chars')
end
end
alias any_char any_chars
@ -129,9 +128,9 @@ class TkText<TkTextWin
# Tk8.5 feature
fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer)
if mod < 0
TkText::IndexString.new(String.new(id) << ' ' << mod.to_s << ' indices')
Tk::Text::IndexString.new(String.new(id) << ' ' << mod.to_s << ' indices')
else
TkText::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' indices')
Tk::Text::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' indices')
end
end
@ -139,9 +138,9 @@ class TkText<TkTextWin
# Tk8.5 feature
fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer)
if mod < 0
TkText::IndexString.new(String.new(id) << ' ' << mod.to_s << ' display indices')
Tk::Text::IndexString.new(String.new(id) << ' ' << mod.to_s << ' display indices')
else
TkText::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' display indices')
Tk::Text::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' display indices')
end
end
@ -149,18 +148,18 @@ class TkText<TkTextWin
# Tk8.5 feature
fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer)
if mod < 0
TkText::IndexString.new(String.new(id) << ' ' << mod.to_s << ' any indices')
Tk::Text::IndexString.new(String.new(id) << ' ' << mod.to_s << ' any indices')
else
TkText::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' any indices')
Tk::Text::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' any indices')
end
end
def lines(mod)
fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer)
if mod < 0
TkText::IndexString.new(String.new(id) << ' ' << mod.to_s << ' lines')
Tk::Text::IndexString.new(String.new(id) << ' ' << mod.to_s << ' lines')
else
TkText::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' lines')
Tk::Text::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' lines')
end
end
alias line lines
@ -169,9 +168,9 @@ class TkText<TkTextWin
# Tk8.5 feature
fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer)
if mod < 0
TkText::IndexString.new(String.new(id) << ' ' << mod.to_s << ' display_lines')
Tk::Text::IndexString.new(String.new(id) << ' ' << mod.to_s << ' display_lines')
else
TkText::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' display lines')
Tk::Text::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' display lines')
end
end
alias display_line display_lines
@ -180,43 +179,43 @@ class TkText<TkTextWin
# Tk8.5 feature
fail ArgumentError, 'expect Integer' unless mod.kind_of?(Integer)
if mod < 0
TkText::IndexString.new(String.new(id) << ' ' << mod.to_s << ' any_lines')
Tk::Text::IndexString.new(String.new(id) << ' ' << mod.to_s << ' any_lines')
else
TkText::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' any lines')
Tk::Text::IndexString.new(String.new(id) << ' + ' << mod.to_s << ' any lines')
end
end
alias any_line any_lines
def linestart
TkText::IndexString.new(String.new(id) << ' linestart')
Tk::Text::IndexString.new(String.new(id) << ' linestart')
end
def lineend
TkText::IndexString.new(String.new(id) << ' lineend')
Tk::Text::IndexString.new(String.new(id) << ' lineend')
end
def display_linestart
# Tk8.5 feature
TkText::IndexString.new(String.new(id) << ' display linestart')
Tk::Text::IndexString.new(String.new(id) << ' display linestart')
end
def display_lineend
# Tk8.5 feature
TkText::IndexString.new(String.new(id) << ' display lineend')
Tk::Text::IndexString.new(String.new(id) << ' display lineend')
end
def wordstart
TkText::IndexString.new(String.new(id) << ' wordstart')
Tk::Text::IndexString.new(String.new(id) << ' wordstart')
end
def wordend
TkText::IndexString.new(String.new(id) << ' wordend')
Tk::Text::IndexString.new(String.new(id) << ' wordend')
end
def display_wordstart
# Tk8.5 feature
TkText::IndexString.new(String.new(id) << ' display wordstart')
Tk::Text::IndexString.new(String.new(id) << ' display wordstart')
end
def display_wordend
# Tk8.5 feature
TkText::IndexString.new(String.new(id) << ' display wordend')
Tk::Text::IndexString.new(String.new(id) << ' display wordend')
end
end
@ -251,7 +250,11 @@ class TkText<TkTextWin
def self.new(*args, &block)
obj = super(*args){}
obj.init_instance_variable
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
obj.instance_exec(obj, &block) if defined? yield
else
obj.instance_eval(&block) if defined? yield
end
obj
end
@ -261,8 +264,12 @@ class TkText<TkTextWin
end
def __destroy_hook__
TkTextTag::TTagID_TBL.mutex.synchronize{
TkTextTag::TTagID_TBL.delete(@path)
}
TkTextTag::TMarkID_TBL.mutex.synchronize{
TkTextMark::TMarkID_TBL.delete(@path)
}
end
def create_self(keys)
@ -285,15 +292,15 @@ class TkText<TkTextWin
private :__strval_optkeys
def self.at(x, y)
TkText::IndexString.at(x, y)
Tk::Text::IndexString.at(x, y)
end
def at(x, y)
TkText::IndexString.at(x, y)
Tk::Text::IndexString.at(x, y)
end
def index(idx)
TkText::IndexString.new(tk_send_without_enc('index',
Tk::Text::IndexString.new(tk_send_without_enc('index',
_get_eval_enc_str(idx)))
end
@ -713,6 +720,7 @@ class TkText<TkTextWin
def tag_delete(*tags)
tk_send_without_enc('tag', 'delete',
*(tags.collect{|tag| _get_eval_enc_str(tag)}))
TkTextTag::TTagID_TBL.mutex.synchronize{
if TkTextTag::TTagID_TBL[@path]
tags.each{|tag|
if tag.kind_of?(TkTextTag)
@ -722,6 +730,7 @@ class TkText<TkTextWin
end
}
end
}
self
end
alias deltag tag_delete
@ -968,7 +977,7 @@ class TkText<TkTextWin
false, true)
r = []
while key=l.shift
r.push [TkText::IndexString.new(key), TkText::IndexString.new(l.shift)]
r.push [Tk::Text::IndexString.new(key), Tk::Text::IndexString.new(l.shift)]
end
r
end
@ -978,7 +987,7 @@ class TkText<TkTextWin
_get_eval_enc_str(tag),
_get_eval_enc_str(first),
_get_eval_enc_str(last))).collect{|idx|
TkText::IndexString.new(idx)
Tk::Text::IndexString.new(idx)
}
end
@ -987,7 +996,7 @@ class TkText<TkTextWin
_get_eval_enc_str(tag),
_get_eval_enc_str(first),
_get_eval_enc_str(last))).collect{|idx|
TkText::IndexString.new(idx)
Tk::Text::IndexString.new(idx)
}
end
@ -1183,6 +1192,11 @@ class TkText<TkTextWin
end
def _ktext_length(txt)
if TkCore::WITH_ENCODING ### Ruby 1.9 !!!!!!!!!!!!!
return txt.length
end
###########################
if $KCODE !~ /n/i
return txt.gsub(/[^\Wa-zA-Z_\d]/, ' ').length
end
@ -1232,7 +1246,7 @@ class TkText<TkTextWin
if ret == ""
nil
else
TkText::IndexString.new(ret)
Tk::Text::IndexString.new(ret)
end
end
@ -1267,7 +1281,7 @@ class TkText<TkTextWin
if ret == ""
nil
else
TkText::IndexString.new(ret)
Tk::Text::IndexString.new(ret)
end
end
@ -1456,10 +1470,10 @@ class TkText<TkTextWin
# retrieve index
idx = str.index(/ /, i)
if idx
result.push(TkText::IndexString.new(str[i..(idx-1)]))
result.push(Tk::Text::IndexString.new(str[i..(idx-1)]))
i = idx + 1
else
result.push(TkText::IndexString.new(str[i..-1]))
result.push(Tk::Text::IndexString.new(str[i..-1]))
break
end
end
@ -1527,13 +1541,17 @@ class TkText<TkTextWin
end
end
#TkText = Tk::Text unless Object.const_defined? :TkText
Tk.__set_toplevel_aliases__(:Tk, Tk::Text, :TkText)
#######################################
class TkText::Peer < TkText
class Tk::Text::Peer < Tk::Text
# Tk8.5 feature
def initialize(text, parent=nil, keys={})
unless text.kind_of?(TkText)
fail ArgumentError, "TkText is expected for 1st argument"
unless text.kind_of?(Tk::Text)
fail ArgumentError, "Tk::Text is expected for 1st argument"
end
@src_text = text
super(parent, keys)

View file

@ -5,11 +5,11 @@ require 'tk'
require 'tk/text'
class TkTextImage<TkObject
include TkText::IndexModMethods
include Tk::Text::IndexModMethods
def initialize(parent, index, keys)
#unless parent.kind_of?(TkText)
# fail ArgumentError, "expect TkText for 1st argument"
#unless parent.kind_of?(Tk::Text)
# fail ArgumentError, "expect Tk::Text for 1st argument"
#end
@t = parent
if index == 'end' || index == :end
@ -34,7 +34,7 @@ class TkTextImage<TkObject
end
def id
TkText::IndexString.new(@id)
Tk::Text::IndexString.new(@id)
end
def mark
@path
@ -80,3 +80,5 @@ class TkTextImage<TkObject
value
end
end
TktImage = TkTextImage

View file

@ -5,38 +5,54 @@ require 'tk'
require 'tk/text'
class TkTextMark<TkObject
include TkText::IndexModMethods
include Tk::Text::IndexModMethods
TMarkID_TBL = TkCore::INTERP.create_table
Tk_TextMark_ID = ['mark'.freeze, '00000'.taint].freeze
TkCore::INTERP.init_ip_env{ TMarkID_TBL.clear }
(Tk_TextMark_ID = ['mark'.freeze, '00000'.taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
TkCore::INTERP.init_ip_env{
TMarkID_TBL.mutex.synchronize{ TMarkID_TBL.clear }
}
def TkTextMark.id2obj(text, id)
tpath = text.path
return id unless TMarkID_TBL[tpath]
TMarkID_TBL.mutex.synchronize{
if TMarkID_TBL[tpath]
TMarkID_TBL[tpath][id]? TMarkID_TBL[tpath][id]: id
else
id
end
}
end
def initialize(parent, index)
#unless parent.kind_of?(TkText)
# fail ArgumentError, "expect TkText for 1st argument"
#unless parent.kind_of?(Tk::Text)
# fail ArgumentError, "expect Tk::Text for 1st argument"
#end
@parent = @t = parent
@tpath = parent.path
Tk_TextMark_ID.mutex.synchronize{
# @path = @id = Tk_TextMark_ID.join('')
@path = @id = Tk_TextMark_ID.join(TkCore::INTERP._ip_id_).freeze
Tk_TextMark_ID[1].succ!
}
TMarkID_TBL.mutex.synchronize{
TMarkID_TBL[@id] = self
TMarkID_TBL[@tpath] = {} unless TMarkID_TBL[@tpath]
TMarkID_TBL[@tpath][@id] = self
Tk_TextMark_ID[1].succ!
}
tk_call_without_enc(@t.path, 'mark', 'set', @id,
_get_eval_enc_str(index))
@t._addtag id, self
end
def id
TkText::IndexString.new(@id)
Tk::Text::IndexString.new(@id)
end
def exist?
@ -49,15 +65,15 @@ class TkTextMark<TkObject
end
=begin
# move to TkText::IndexModMethods module
# move to Tk::Text::IndexModMethods module
def +(mod)
return chars(mod) if mod.kind_of?(Numeric)
mod = mod.to_s
if mod =~ /^\s*[+-]?\d/
TkText::IndexString.new(@id + ' + ' + mod)
Tk::Text::IndexString.new(@id + ' + ' + mod)
else
TkText::IndexString.new(@id + ' ' + mod)
Tk::Text::IndexString.new(@id + ' ' + mod)
end
end
@ -66,11 +82,11 @@ class TkTextMark<TkObject
mod = mod.to_s
if mod =~ /^\s*[+-]?\d/
TkText::IndexString.new(@id + ' - ' + mod)
Tk::Text::IndexString.new(@id + ' - ' + mod)
elsif mod =~ /^\s*[-]\s+(\d.*)$/
TkText::IndexString.new(@id + ' - -' + $1)
Tk::Text::IndexString.new(@id + ' - -' + $1)
else
TkText::IndexString.new(@id + ' ' + mod)
Tk::Text::IndexString.new(@id + ' ' + mod)
end
end
=end
@ -121,46 +137,68 @@ class TkTextMark<TkObject
end
end
end
TktMark = TkTextMark
class TkTextNamedMark<TkTextMark
def self.new(parent, name, *args)
def self.new(parent, name, index=nil)
TMarkID_TBL.mutex.synchronize{
if TMarkID_TBL[parent.path] && TMarkID_TBL[parent.path][name]
return TMarkID_TBL[parent.path][name]
obj = TMarkID_TBL[parent.path][name]
else
super(parent, name, *args)
end
end
def initialize(parent, name, index=nil)
#unless parent.kind_of?(TkText)
# fail ArgumentError, "expect TkText for 1st argument"
#end
# super(parent, name, *args)
(obj = self.allocate).instance_eval{
@parent = @t = parent
@tpath = parent.path
@path = @id = name
TMarkID_TBL[@id] = self
TMarkID_TBL[@tpath] = {} unless TMarkID_TBL[@tpath]
TMarkID_TBL[@tpath][@id] = self unless TMarkID_TBL[@tpath][@id]
@t._addtag @id, self
}
obj
end
if obj && index
tk_call_without_enc(parent.path, 'mark', 'set', name,
_get_eval_enc_str(index))
end
obj
}
end
def initialize(parent, name, index=nil)
# dummy:: not called by 'new' method
#unless parent.kind_of?(Tk::Text)
# fail ArgumentError, "expect Tk::Text for 1st argument"
#end
@parent = @t = parent
@tpath = parent.path
@path = @id = name
tk_call_without_enc(@t.path, 'mark', 'set', @id,
_get_eval_enc_str(index)) if index
@t._addtag id, self
@t._addtag @id, self
end
end
TktNamedMark = TkTextNamedMark
class TkTextMarkInsert<TkTextNamedMark
def self.new(parent,*args)
super(parent, 'insert', *args)
end
end
TktMarkInsert = TkTextMarkInsert
class TkTextMarkCurrent<TkTextNamedMark
def self.new(parent,*args)
super(parent, 'current', *args)
end
end
TktMarkCurrent = TkTextMarkCurrent
class TkTextMarkAnchor<TkTextNamedMark
def self.new(parent,*args)
super(parent, 'anchor', *args)
end
end
TktMarkAnchor = TkTextMarkAnchor

View file

@ -7,17 +7,29 @@ require 'tk/tagfont'
class TkTextTag<TkObject
include TkTreatTagFont
include TkText::IndexModMethods
include Tk::Text::IndexModMethods
TTagID_TBL = TkCore::INTERP.create_table
Tk_TextTag_ID = ['tag'.freeze, '00000'.taint].freeze
TkCore::INTERP.init_ip_env{ TTagID_TBL.clear }
(Tk_TextTag_ID = ['tag'.freeze, '00000'.taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
TkCore::INTERP.init_ip_env{
TTagID_TBL.mutex.synchronize{ TTagID_TBL.clear }
}
def TkTextTag.id2obj(text, id)
tpath = text.path
return id unless TTagID_TBL[tpath]
TTagID_TBL.mutex.synchronize{
if TTagID_TBL[tpath]
TTagID_TBL[tpath][id]? TTagID_TBL[tpath][id]: id
else
id
end
}
end
def initialize(parent, *args)
@ -26,12 +38,16 @@ class TkTextTag<TkObject
#end
@parent = @t = parent
@tpath = parent.path
Tk_TextTag_ID.mutex.synchronize{
# @path = @id = Tk_TextTag_ID.join('')
@path = @id = Tk_TextTag_ID.join(TkCore::INTERP._ip_id_).freeze
# TTagID_TBL[@id] = self
Tk_TextTag_ID[1].succ!
}
TTagID_TBL.mutex.synchronize{
TTagID_TBL[@id] = self
TTagID_TBL[@tpath] = {} unless TTagID_TBL[@tpath]
TTagID_TBL[@tpath][@id] = self
Tk_TextTag_ID[1].succ!
}
#tk_call @t.path, "tag", "configure", @id, *hash_kv(keys)
if args != []
keys = args.pop
@ -47,7 +63,7 @@ class TkTextTag<TkObject
end
def id
TkText::IndexString.new(@id)
Tk::Text::IndexString.new(@id)
end
def exist?
@ -60,11 +76,11 @@ class TkTextTag<TkObject
end
def first
TkText::IndexString.new(@id + '.first')
Tk::Text::IndexString.new(@id + '.first')
end
def last
TkText::IndexString.new(@id + '.last')
Tk::Text::IndexString.new(@id + '.last')
end
def add(*indices)
@ -83,7 +99,7 @@ class TkTextTag<TkObject
l = tk_split_simplelist(tk_call_without_enc(@t.path, 'tag', 'ranges', @id))
r = []
while key=l.shift
r.push [TkText::IndexString.new(key), TkText::IndexString.new(l.shift)]
r.push [Tk::Text::IndexString.new(key), Tk::Text::IndexString.new(l.shift)]
end
r
end
@ -92,7 +108,7 @@ class TkTextTag<TkObject
simplelist(tk_call_without_enc(@t.path, 'tag', 'nextrange', @id,
_get_eval_enc_str(first),
_get_eval_enc_str(last))).collect{|idx|
TkText::IndexString.new(idx)
Tk::Text::IndexString.new(idx)
}
end
@ -100,7 +116,7 @@ class TkTextTag<TkObject
simplelist(tk_call_without_enc(@t.path, 'tag', 'prevrange', @id,
_get_eval_enc_str(first),
_get_eval_enc_str(last))).collect{|idx|
TkText::IndexString.new(idx)
Tk::Text::IndexString.new(idx)
}
end
@ -221,15 +237,34 @@ class TkTextTag<TkObject
def destroy
tk_call_without_enc(@t.path, 'tag', 'delete', @id)
TTagID_TBL.mutex.synchronize{
TTagID_TBL[@tpath].delete(@id) if TTagID_TBL[@tpath]
}
self
end
end
TktTag = TkTextTag
class TkTextNamedTag<TkTextTag
def self.new(parent, name, *args)
tagobj = nil
TTagID_TBL.mutex.synchronize{
if TTagID_TBL[parent.path] && TTagID_TBL[parent.path][name]
tagobj = TTagID_TBL[parent.path][name]
else
# super(parent, name, *args)
(tagobj = self.allocate).instance_eval{
@parent = @t = parent
@tpath = parent.path
@path = @id = name
TTagID_TBL[@id] = self
TTagID_TBL[@tpath] = {} unless TTagID_TBL[@tpath]
TTagID_TBL[@tpath][@id] = self unless TTagID_TBL[@tpath][@id]
@t._addtag @id, self
}
end
}
if args != []
keys = args.pop
if keys.kind_of?(Hash)
@ -240,21 +275,20 @@ class TkTextNamedTag<TkTextTag
tagobj.add(*args)
end
end
return tagobj
else
super(parent, name, *args)
end
tagobj
end
def initialize(parent, name, *args)
#unless parent.kind_of?(TkText)
# fail ArgumentError, "expect TkText for 1st argument"
# dummy:: not called by 'new' method
#unless parent.kind_of?(Tk::Text)
# fail ArgumentError, "expect Tk::Text for 1st argument"
#end
@parent = @t = parent
@tpath = parent.path
@path = @id = name
TTagID_TBL[@tpath] = {} unless TTagID_TBL[@tpath]
TTagID_TBL[@tpath][@id] = self unless TTagID_TBL[@tpath][@id]
#if mode
# tk_call @t.path, "addtag", @id, *args
#end
@ -268,12 +302,14 @@ class TkTextNamedTag<TkTextTag
add(*args)
end
end
@t._addtag id, self
@t._addtag @id, self
end
end
TktNamedTag = TkTextNamedTag
class TkTextTagSel<TkTextNamedTag
def self.new(parent, *args)
super(parent, 'sel', *args)
end
end
TktTagSel = TkTextTagSel

View file

@ -5,11 +5,11 @@ require 'tk'
require 'tk/text'
class TkTextWindow<TkObject
include TkText::IndexModMethods
include Tk::Text::IndexModMethods
def initialize(parent, index, keys = {})
#unless parent.kind_of?(TkText)
# fail ArgumentError, "expect TkText for 1st argument"
#unless parent.kind_of?(Tk::Text)
# fail ArgumentError, "expect Tk::Text for 1st argument"
#end
@t = parent
if index == 'end' || index == :end
@ -55,7 +55,7 @@ class TkTextWindow<TkObject
end
def id
TkText::IndexString.new(_epath(@id))
Tk::Text::IndexString.new(_epath(@id))
end
def mark
@path
@ -147,3 +147,5 @@ class TkTextWindow<TkObject
value
end
end
TktWindow = TkTextWindow

View file

@ -11,7 +11,12 @@ class TkTimer
TkCommandNames = ['after'.freeze].freeze
Tk_CBID = ['a'.freeze, '00000'.taint].freeze
(Tk_CBID = ['a'.freeze, '00000'.taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
Tk_CBTBL = {}.taint
TkCore::INTERP.add_tk_procs('rb_after', 'id', <<-'EOL')
@ -96,9 +101,9 @@ class TkTimer
return self
end
@after_script = "rb_after #{@id}"
@after_id = tk_call_without_enc('after', sleep, @after_script)
@current_args = args
@current_script = [sleep, @after_script]
@after_id = tk_call_without_enc('after', sleep, @after_script)
self
end
@ -138,9 +143,11 @@ class TkTimer
end
def initialize(*args, &b)
Tk_CBID.mutex.synchronize{
# @id = Tk_CBID.join('')
@id = Tk_CBID.join(TkCore::INTERP._ip_id_)
Tk_CBID[1].succ!
}
@wait_var = TkVariable.new(0)

View file

@ -5,7 +5,7 @@ require 'tk'
require 'tk/wm'
require 'tk/menuspec'
class TkToplevel<TkWindow
class Tk::Toplevel<TkWindow
include Wm
include TkMenuSpec
@ -117,9 +117,10 @@ class TkToplevel<TkWindow
end
if @classname.kind_of? TkBindTag
@db_class = @classname
@classname = @classname.id
keys['class'] = @classname = @classname.id
elsif @classname
@db_class = TkDatabaseClass.new(@classname)
keys['class'] = @classname
else
@db_class = self.class
@classname = @db_class::WidgetClassName
@ -165,9 +166,10 @@ class TkToplevel<TkWindow
end
if @classname.kind_of? TkBindTag
@db_class = @classname
@classname = @classname.id
keys['class'] = @classname = @classname.id
elsif @classname
@db_class = TkDatabaseClass.new(@classname)
keys['class'] = @classname
else
@db_class = self.class
@classname = @db_class::WidgetClassName
@ -255,3 +257,6 @@ class TkToplevel<TkWindow
end
end
end
#TkToplevel = Tk::Toplevel unless Object.const_defined? :TkToplevel
Tk.__set_toplevel_aliases__(:Tk, Tk::Toplevel, :TkToplevel)

View file

@ -249,6 +249,22 @@ class TkValidateCommand
nil
]
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf|
if inf.kind_of?(Array)
inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
end
inf
}
PROC_TBL.map!{|inf|
if inf.kind_of?(Array)
inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
end
inf
}
_setup_subst_table(KEY_TBL, PROC_TBL);
#

View file

@ -16,7 +16,18 @@ class TkVariable
#TkVar_ID_TBL = {}
TkVar_CB_TBL = TkCore::INTERP.create_table
TkVar_ID_TBL = TkCore::INTERP.create_table
Tk_VARIABLE_ID = ["v".freeze, "00000".taint].freeze
(Tk_VARIABLE_ID = ["v".freeze, "00000".taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
TkCore::INTERP.init_ip_env{
TkVar_CB_TBL.mutex.synchronize{ TkVar_CB_TBL.clear }
TkVar_ID_TBL.mutex.synchronize{ TkVar_ID_TBL.clear }
}
major, minor, type, type_name, patchlevel = TclTkLib.get_version
USE_OLD_TRACE_OPTION_STYLE = (major < 8) || (major == 8 && minor < 4)
#TkCore::INTERP.add_tk_procs('rb_var', 'args',
# "ruby [format \"TkVariable.callback %%Q!%s!\" $args]")
@ -44,10 +55,10 @@ TkCore::INTERP.add_tk_procs('rb_var', 'args', <<-'EOL')
def TkVariable.callback(id, name1, name2, op)
#name1,name2,op = tk_split_list(args)
#name1,name2,op = tk_split_simplelist(args)
if TkVar_CB_TBL[id]
if cb_obj = TkVar_CB_TBL[id]
#_get_eval_string(TkVar_CB_TBL[name1].trace_callback(name2,op))
begin
_get_eval_string(TkVar_CB_TBL[id].trace_callback(name2, op))
_get_eval_string(cb_obj.trace_callback(name2, op))
rescue SystemExit
exit(0)
rescue Interrupt
@ -59,7 +70,11 @@ TkCore::INTERP.add_tk_procs('rb_var', 'args', <<-'EOL')
"\n---< backtrace of Ruby side >-----\n" +
_toUTF8(e.backtrace.join("\n")) +
"\n---< backtrace of Tk side >-------"
if TkCore::WITH_ENCODING
msg.force_encoding('utf-8')
else
msg.instance_variable_set(:@encoding, 'utf-8')
end
rescue Exception
msg = e.class.inspect + ': ' + e.message + "\n" +
"\n---< backtrace of Ruby side >-----\n" +
@ -267,11 +282,15 @@ TkCore::INTERP.add_tk_procs('rb_var', 'args', <<-'EOL')
def initialize(val="", type=nil)
# @id = Tk_VARIABLE_ID.join('')
begin
Tk_VARIABLE_ID.mutex.synchronize{
@id = Tk_VARIABLE_ID.join(TkCore::INTERP._ip_id_)
Tk_VARIABLE_ID[1].succ!
}
end until INTERP._invoke_without_enc('info', 'globals', @id).empty?
TkVar_ID_TBL.mutex.synchronize{
TkVar_ID_TBL[@id] = self
}
@var = @id
@elem = nil
@ -1263,56 +1282,101 @@ end
end
end
def _check_trace_opt(opts)
if opts.kind_of?(Array)
opt_str = opts.map{|s| s.to_s}.join(' ')
else
opt_str = opts.to_s
end
fail ArgumentError, 'null trace option' if opt_str.empty?
if opt_str =~ /[^arwu\s]/
# new format (Tcl/Tk8.4+?)
if opts.kind_of?(Array)
opt_ary = opts.map{|opt| opt.to_s.strip}
else
opt_ary = opt_str.split(/\s+|\|/)
opt_ary.delete('')
end
if USE_OLD_TRACE_OPTION_STYLE
opt_ary.uniq.map{|opt|
case opt
when 'array'
'a'
when 'read'
'r'
when 'write'
'w'
when 'unset'
'u'
else
fail ArgumentError, "unsupported trace option '#{opt}' on Tcl/Tk#{Tk::TCL_PATCHLEVEL}"
end
}.join
else
opt_ary
end
else
# old format
opt_ary = opt_str.delete('^arwu').split(//).uniq
if USE_OLD_TRACE_OPTION_STYLE
opt_ary.join
else
opt_ary.map{|c|
case c
when 'a'
'array'
when 'r'
'read'
when 'w'
'write'
when 'u'
'unset'
end
}
end
end
end
private :_check_trace_opt
def trace(opts, cmd = Proc.new)
@trace_var = [] if @trace_var == nil
#opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('')
opts = opts.to_s
opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('')
@trace_var.unshift([opts,cmd])
opts = _check_trace_opt(opts)
(@trace_var ||= []).unshift([opts,cmd])
if @trace_opts == nil
TkVar_CB_TBL[@id] = self
@trace_opts = opts.dup
Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts,
'rb_var ' << @id)
=begin
if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION
# TCL_VERSION >= 8.4
Tk.tk_call_without_enc('trace', 'add', 'variable',
@id, @trace_opts, 'rb_var')
@trace_opts = opts
if USE_OLD_TRACE_OPTION_STYLE
Tk.tk_call_without_enc('trace', 'variable',
@id, @trace_opts, 'rb_var ' << @id)
else
# TCL_VERSION <= 8.3
Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts, 'rb_var')
Tk.tk_call_without_enc('trace', 'add', 'variable',
@id, @trace_opts, 'rb_var ' << @id)
end
=end
else
newopts = @trace_opts.dup
#opts.each_byte{|c| newopts += c.chr unless newopts.index(c)}
opts.each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)}
if USE_OLD_TRACE_OPTION_STYLE
opts.each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)}
if newopts != @trace_opts
Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts,
'rb_var ' << @id)
@trace_opts.replace(newopts)
Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts,
'rb_var ' << @id)
=begin
if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION
# TCL_VERSION >= 8.4
Tk.tk_call_without_enc('trace', 'remove', 'variable',
@id, @trace_opts, 'rb_var')
@trace_opts.replace(newopts)
Tk.tk_call_without_enc('trace', 'add', 'variable',
@id, @trace_opts, 'rb_var')
else
# TCL_VERSION <= 8.3
Tk.tk_call_without_enc('trace', 'vdelete',
@id, @trace_opts, 'rb_var')
@id, @trace_opts, 'rb_var ' << @id)
@trace_opts.replace(newopts)
Tk.tk_call_without_enc('trace', 'variable',
@id, @trace_opts, 'rb_var')
@id, @trace_opts, 'rb_var ' << @id)
end
=end
else
newopts |= opts
unless (newopts - @trace_opts).empty?
Tk.tk_call_without_enc('trace', 'remove', 'variable',
@id, @trace_opts, 'rb_var ' << @id)
@trace_opts.replace(newopts)
Tk.tk_call_without_enc('trace', 'add', 'variable',
@id, @trace_opts, 'rb_var ' << @id)
end
end
end
self
end
@ -1321,65 +1385,54 @@ end
fail(RuntimeError,
"invalid for a TkVariable which denotes an element of Tcl's array")
end
@trace_elem = {} if @trace_elem == nil
@trace_elem[elem] = [] if @trace_elem[elem] == nil
opts = opts.to_s
opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('')
@trace_elem[elem].unshift([opts,cmd])
opts = _check_trace_opt(opts)
((@trace_elem ||= {})[elem] ||= []).unshift([opts,cmd])
if @trace_opts == nil
TkVar_CB_TBL[@id] = self
@trace_opts = opts.dup
Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts,
'rb_var ' << @id)
=begin
if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION
# TCL_VERSION >= 8.4
@trace_opts = opts
if USE_OLD_TRACE_OPTION_STYLE
Tk.tk_call_without_enc('trace', 'add', 'variable',
@id, @trace_opts, 'rb_var')
@id, @trace_opts, 'rb_var ' << @id)
else
# TCL_VERSION <= 8.3
Tk.tk_call_without_enc('trace', 'variable',
@id, @trace_opts, 'rb_var')
@id, @trace_opts, 'rb_var ' << @id)
end
=end
else
newopts = @trace_opts.dup
# opts.each_byte{|c| newopts += c.chr unless newopts.index(c)}
opts.each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)}
if USE_OLD_TRACE_OPTION_STYLE
opts.each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)}
if newopts != @trace_opts
Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts,
'rb_var ' << @id)
@trace_opts.replace(newopts)
Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts,
'rb_var ' << @id)
=begin
if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION
# TCL_VERSION >= 8.4
Tk.tk_call_without_enc('trace', 'remove', 'variable',
@id, @trace_opts, 'rb_var')
@trace_opts.replace(newopts)
Tk.tk_call_without_enc('trace', 'add', 'variable',
@id, @trace_opts, 'rb_var')
else
# TCL_VERSION <= 8.3
Tk.tk_call_without_enc('trace', 'vdelete',
@id, @trace_opts, 'rb_var')
@id, @trace_opts, 'rb_var ' << @id)
@trace_opts.replace(newopts)
Tk.tk_call_without_enc('trace', 'variable',
@id, @trace_opts, 'rb_var')
@id, @trace_opts, 'rb_var ' << @id)
end
=end
else
newopts |= opts
unless (newopts - @trace_opts).empty?
Tk.tk_call_without_enc('trace', 'remove', 'variable',
@id, @trace_opts, 'rb_var ' << @id)
@trace_opts.replace(newopts)
Tk.tk_call_without_enc('trace', 'add', 'variable',
@id, @trace_opts, 'rb_var ' << @id)
end
end
end
self
end
def trace_vinfo
def trace_info
return [] unless @trace_var
@trace_var.dup
end
alias trace_vinfo trace_info
def _trace_vinfo_for_element(elem)
def trace_info_for_element(elem)
if @elem
fail(RuntimeError,
"invalid for a TkVariable which denotes an element of Tcl's array")
@ -1388,141 +1441,180 @@ end
return [] unless @trace_elem[elem]
@trace_elem[elem].dup
end
alias trace_vinfo_for_element trace_info_for_element
def trace_vdelete(opts,cmd)
def trace_remove(opts,cmd)
return self unless @trace_var.kind_of? Array
opts = opts.to_s
opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('')
opts = _check_trace_opt(opts)
idx = -1
if USE_OLD_TRACE_OPTION_STYLE
newopts = ''
@trace_var.each_with_index{|e, i|
if idx < 0 && e[0] == opts && e[1] == cmd
if idx < 0 && e[1] == cmd
diff = false
['a', 'r', 'w', 'u'].each{|c|
break if (diff = e[0].index(c) ^ opts.index(c))
}
unless diff
#find
idx = i
next
end
# e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)}
e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)}
end
e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)}
}
else
newopts = []
@trace_var.each_with_index{|e, i|
if idx < 0 && e[1] == cmd &&
e[0].size == opts.size && (e[0] - opts).empty?
# find
idx = i
next
end
newopts |= e[0]
}
end
if idx >= 0
@trace_var.delete_at(idx)
else
return self
end
@trace_elem.each{|elem|
(@trace_elem ||= {}).each{|elem|
@trace_elem[elem].each{|e|
# e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)}
e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)}
if USE_OLD_TRACE_OPTION_STYLE
e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)}
else
newopts |= e[0]
end
}
}
newopts = newopts.to_s
newopts = ['r','w','u'].find_all{|c| newopts.index(c)}.join('')
if newopts != @trace_opts
Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts,
'rb_var ' << @id)
=begin
if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION
# TCL_VERSION >= 8.4
Tk.tk_call_without_enc('trace', 'remove', 'variable',
@id, @trace_opts, 'rb_var')
else
# TCL_VERSION <= 8.3
if USE_OLD_TRACE_OPTION_STYLE
diff = false
@trace_opts.each_byte{|c| break if (diff = ! newopts.index(c))}
if diff
Tk.tk_call_without_enc('trace', 'vdelete',
@id, @trace_opts, 'rb_var')
end
=end
@id, @trace_opts, 'rb_var ' << @id)
@trace_opts.replace(newopts)
if @trace_opts != ''
Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts,
'rb_var ' << @id)
=begin
if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION
# TCL_VERSION >= 8.4
Tk.tk_call_without_enc('trace', 'add', 'variable',
@id, @trace_opts, 'rb_var')
else
# TCL_VERSION <= 8.3
unless @trace_opts.empty?
Tk.tk_call_without_enc('trace', 'variable',
@id, @trace_opts, 'rb_var')
@id, @trace_opts, 'rb_var ' << @id)
end
end
else
unless (@trace_opts - newopts).empty?
Tk.tk_call_without_enc('trace', 'remove', 'variable',
@id, @trace_opts, 'rb_var ' << @id)
@trace_opts.replace(newopts)
unless @trace_opts.empty?
Tk.tk_call_without_enc('trace', 'add', 'variable',
@id, @trace_opts, 'rb_var ' << @id)
end
=end
end
end
self
end
alias trace_delete trace_remove
alias trace_vdelete trace_remove
def trace_vdelete_for_element(elem,opts,cmd)
def trace_remove_for_element(elem,opts,cmd)
if @elem
fail(RuntimeError,
"invalid for a TkVariable which denotes an element of Tcl's array")
end
return self unless @trace_elem.kind_of? Hash
return self unless @trace_elem[elem].kind_of? Array
opts = opts.to_s
opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('')
opts = _check_trace_opt(opts)
idx = -1
if USE_OLD_TRACE_OPTION_STYLE
@trace_elem[elem].each_with_index{|e, i|
if idx < 0 && e[0] == opts && e[1] == cmd
if idx < 0 && e[1] == cmd
diff = false
['a', 'r', 'w', 'u'].each{|c|
break if (diff = e[0].index(c) ^ opts.index(c))
}
unless diff
#find
idx = i
next
end
end
}
else
@trace_elem[elem].each_with_index{|e, i|
if idx < 0 && e[1] == cmd &&
e[0].size == opts.size && (e[0] - opts).empty?
# find
idx = i
next
end
}
end
if idx >= 0
@trace_elem[elem].delete_at(idx)
else
return self
end
if USE_OLD_TRACE_OPTION_STYLE
newopts = ''
@trace_var.each{|e|
# e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)}
e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)}
e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)}
}
@trace_elem.each{|elem|
@trace_elem[elem].each{|e|
# e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)}
e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)}
e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)}
}
}
else
newopts = []
@trace_var.each{|e|
newopts |= e[0]
}
@trace_elem.each{|elem|
@trace_elem[elem].each{|e|
e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c.chr)}
}
}
end
newopts = newopts.to_s
newopts = ['r','w','u'].find_all{|c| newopts.index(c)}.join('')
if newopts != @trace_opts
Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts,
'rb_var ' << @id)
=begin
if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION
# TCL_VERSION >= 8.4
Tk.tk_call_without_enc('trace', 'remove', 'variable',
@id, @trace_opts, 'rb_var')
else
# TCL_VERSION <= 8.3
if USE_OLD_TRACE_OPTION_STYLE
diff = false
@trace_opts.each_byte{|c| break if (diff = ! newopts.index(c))}
if diff
Tk.tk_call_without_enc('trace', 'vdelete',
@id, @trace_opts, 'rb_var')
end
=end
@id, @trace_opts, 'rb_var ' << @id)
@trace_opts.replace(newopts)
if @trace_opts != ''
Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts,
'rb_var ' << @id)
=begin
if /^(8\.([4-9]|[1-9][0-9])|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION
# TCL_VERSION >= 8.4
Tk.tk_call_without_enc('trace', 'add', 'variable',
@id, @trace_opts, 'rb_var')
else
# TCL_VERSION <= 8.3
Tk.tk_call_without_enc('trace', 'variable', @id,
@trace_opts, 'rb_var')
unless @trace_opts.empty?
Tk.tk_call_without_enc('trace', 'variable',
@id, @trace_opts, 'rb_var ' << @id)
end
end
else
unless (@trace_opts - newopts).empty?
Tk.tk_call_without_enc('trace', 'remove', 'variable',
@id, @trace_opts, 'rb_var ' << @id)
@trace_opts.replace(newopts)
unless @trace_opts.empty?
Tk.tk_call_without_enc('trace', 'add', 'variable',
@id, @trace_opts, 'rb_var ' << @id)
end
=end
end
end
self
end
alias trace_delete_for_element trace_remove_for_element
alias trace_vdelete_for_element trace_remove_for_element
end
class TkVarAccess<TkVariable
@ -1532,12 +1624,23 @@ class TkVarAccess<TkVariable
return name
end
name = name.to_s
v = nil
TkVar_ID_TBL.mutex.synchronize{
if v = TkVar_ID_TBL[name]
v.value = args[0] unless args.empty?
return v
else
(v = self.allocate).instance_eval{
@id = name
TkVar_ID_TBL[@id] = self
@var = @id
}
end
}
super(name, *args)
v.instance_eval{ initialize(name, *args) }
v
end
def self.new_hash(name, *args)
@ -1549,27 +1652,38 @@ class TkVarAccess<TkVariable
return name
end
name = name.to_s
v = nil
TkVar_ID_TBL.mutex.synchronize{
if v = TkVar_ID_TBL[name]
unless v.is_hash?
fail ArgumentError, "already exist as a scalar variable"
end
v.value = args[0] unless args.empty?
return v
else
(v = self.allocate).instance_eval{
@id = name
TkVar_ID_TBL[@id] = self
@var = @id
}
end
}
INTERP._invoke_without_enc('global', name)
if args.empty? && INTERP._invoke_without_enc('array', 'exist', name) == '0'
self.new(name, {}) # force creating
v.instance_eval{ initialize(name, {}) } # force creating
else
self.new(name, *args)
v.instance_eval{ initialize(name, *args) }
end
v
end
def initialize(varname, val=nil)
@id = varname
TkVar_ID_TBL[@id] = self
# @id = varname
# TkVar_ID_TBL[@id] = self
@var = @id
# @var = @id
@elem = nil
@def_default = false

View file

@ -9,10 +9,17 @@ class TkVirtualEvent<TkObject
TkCommandNames = ['event'.freeze].freeze
TkVirtualEventID = ["VirtEvent".freeze, "00000".taint].freeze
(TkVirtualEventID = ["VirtEvent".freeze, "00000".taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
TkVirtualEventTBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{ TkVirtualEventTBL.clear }
TkCore::INTERP.init_ip_env{
TkVirtualEventTBL.mutex.synchronize{ TkVirtualEventTBL.clear }
}
class PreDefVirtEvent<self
def self.new(event, *sequences)
@ -21,22 +28,30 @@ class TkVirtualEvent<TkObject
elsif event !~ /^<.*>$/
event = '<' + event + '>'
end
TkVirtualEvent::TkVirtualEventTBL.mutex.synchronize{
if TkVirtualEvent::TkVirtualEventTBL.has_key?(event)
TkVirtualEvent::TkVirtualEventTBL[event]
else
super(event, *sequences)
# super(event, *sequences)
(obj = self.allocate).instance_eval{
initialize(event, *sequences)
TkVirtualEvent::TkVirtualEventTBL[@id] = self
}
end
}
end
def initialize(event, *sequences)
@path = @id = event
TkVirtualEvent::TkVirtualEventTBL[@id] = self
add(*sequences)
_add_sequences(sequences)
end
end
def TkVirtualEvent.getobj(event)
obj = nil
TkVirtualEventTBL.mutex.synchronize{
obj = TkVirtualEventTBL[event]
}
if obj
obj
else
@ -55,19 +70,31 @@ class TkVirtualEvent<TkObject
end
def initialize(*sequences)
TkVirtualEventID.mutex.synchronize{
# @path = @id = '<' + TkVirtualEventID.join('') + '>'
@path = @id = '<' + TkVirtualEventID.join(TkCore::INTERP._ip_id_) + '>'
TkVirtualEventID[1].succ!
add(*sequences)
}
_add_sequences(sequences)
end
def _add_sequences(seq_ary)
unless seq_ary.empty?
tk_call_without_enc('event', 'add', "<#{@id}>",
*(seq_ary.collect{|seq|
"<#{tk_event_sequence(seq)}>"
}) )
end
self
end
private :_add_sequences
def add(*sequences)
if sequences != []
tk_call_without_enc('event', 'add', "<#{@id}>",
*(sequences.collect{|seq|
"<#{tk_event_sequence(seq)}>"
}) )
_add_sequences(sequences)
TkVirtualEventTBL.mutex.synchronize{
TkVirtualEventTBL[@id] = self
}
end
self
end
@ -75,20 +102,26 @@ class TkVirtualEvent<TkObject
def delete(*sequences)
if sequences == []
tk_call_without_enc('event', 'delete', "<#{@id}>")
TkVirtualEventTBL.mutex.synchronize{
TkVirtualEventTBL.delete(@id)
}
else
tk_call_without_enc('event', 'delete', "<#{@id}>",
*(sequences.collect{|seq|
"<#{tk_event_sequence(seq)}>"
}) )
TkVirtualEventTBL.delete(@id) if info == []
if tk_call_without_enc('event','info',"<#{@id}>").empty?
TkVirtualEventTBL.mutex.synchronize{
TkVirtualEventTBL.delete(@id)
}
end
end
self
end
def info
tk_call_without_enc('event','info',"<#{@id}>").split(/\s+/).collect!{|seq|
l = seq.scan(/<*[^<>]+>*/).collect!{|subseq|
lst = seq.scan(/<*[^<>]+>*/).collect!{|subseq|
case (subseq)
when /^<<[^<>]+>>$/
TkVirtualEvent.getobj(subseq[1..-2])
@ -98,7 +131,7 @@ class TkVirtualEvent<TkObject
subseq.split('')
end
}.flatten
(l.size == 1) ? l[0] : l
(lst.size == 1) ? lst[0] : lst
}
end
end

View file

@ -7,9 +7,14 @@
#
require 'tk'
module TkWinDDE
module Tk::WinDDE
end
#TkWinDDE = Tk::WinDDE
Tk.__set_toplevel_aliases__(:Tk, Tk::WinDDE, :TkWinDDE)
module Tk::WinDDE
extend Tk
extend TkWinDDE
extend Tk::WinDDE
TkCommandNames = ['dde'.freeze].freeze
@ -85,9 +90,14 @@ module TkWinDDE
:poke, :request, :services, :eval
end
module TkWinRegistry
module Tk::WinRegistry
end
#TkWinRegistry = Tk::WinRegistry
Tk.__set_toplevel_aliases__(:Tk, Tk::WinRegistry, :TkWinRegistry)
module Tk::WinRegistry
extend Tk
extend TkWinRegistry
extend Tk::WinRegistry
TkCommandNames = ['registry'.freeze].freeze

View file

@ -5,273 +5,407 @@ require 'tk'
module Tk
module Wm
include TkComm
#include TkComm
extend TkCore
TkCommandNames = ['wm'.freeze].freeze
TOPLEVEL_METHODCALL_OPTKEYS = {}
def aspect(*args)
def Wm.aspect(win, *args)
if args.length == 0
list(tk_call_without_enc('wm', 'aspect', path))
list(tk_call_without_enc('wm', 'aspect', win.epath))
else
args = args[0] if args.length == 1 && args[0].kind_of?(Array)
tk_call('wm', 'aspect', path, *args)
self
tk_call('wm', 'aspect', win.epath, *args)
win
end
end
def aspect(*args)
Wm.aspect(self, *args)
end
alias wm_aspect aspect
TOPLEVEL_METHODCALL_OPTKEYS['aspect'] = 'aspect'
def attributes(slot=nil,value=None)
def Wm.attributes(win, slot=nil,value=TkComm::None)
if slot == nil
lst = tk_split_list(tk_call('wm', 'attributes', path))
lst = tk_split_list(tk_call('wm', 'attributes', win.epath))
info = {}
while key = lst.shift
info[key[1..-1]] = lst.shift
end
info
elsif slot.kind_of? Hash
tk_call('wm', 'attributes', path, *hash_kv(slot))
self
elsif value == None
tk_call('wm', 'attributes', path, "-#{slot}")
tk_call('wm', 'attributes', win.epath, *hash_kv(slot))
win
elsif value == TkComm::None
tk_call('wm', 'attributes', win.epath, "-#{slot}")
else
tk_call('wm', 'attributes', path, "-#{slot}", value)
self
tk_call('wm', 'attributes', win.epath, "-#{slot}", value)
win
end
end
def attributes(slot=nil,value=TkComm::None)
Wm.attributes(self, slot, value)
end
alias wm_attributes attributes
TOPLEVEL_METHODCALL_OPTKEYS['attributes'] = 'attributes'
def client(name=None)
if name == None
tk_call('wm', 'client', path)
def Wm.client(win, name=TkComm::None)
if name == TkComm::None
tk_call('wm', 'client', win.epath)
else
name = '' if name == nil
tk_call('wm', 'client', path, name)
self
tk_call('wm', 'client', win.epath, name)
win
end
end
def client(name=TkComm::None)
Wm.client(self, name)
end
alias wm_client client
TOPLEVEL_METHODCALL_OPTKEYS['client'] = 'client'
def colormapwindows(*args)
def Wm.colormapwindows(win, *args)
if args.size == 0
list(tk_call_without_enc('wm', 'colormapwindows', path))
list(tk_call_without_enc('wm', 'colormapwindows', win.epath))
else
args = args[0] if args.length == 1 && args[0].kind_of?(Array)
tk_call_without_enc('wm', 'colormapwindows', path, *args)
self
tk_call_without_enc('wm', 'colormapwindows', win.epath, *args)
win
end
end
def colormapwindows(*args)
Wm.colormapwindows(self, *args)
end
alias wm_colormapwindows colormapwindows
TOPLEVEL_METHODCALL_OPTKEYS['colormapwindows'] = 'colormapwindows'
def wm_command(value=nil)
def Wm.command(win, value=nil)
if value
tk_call('wm', 'command', path, value)
self
tk_call('wm', 'command', epath, value)
win
else
#procedure(tk_call('wm', 'command', path))
tk_call('wm', 'command', path)
#procedure(tk_call('wm', 'command', epath))
tk_call('wm', 'command', epath)
end
end
def wm_command(value=nil)
Wm.command(self, value)
end
TOPLEVEL_METHODCALL_OPTKEYS['wm_command'] = 'wm_command'
def deiconify(ex = true)
def Wm.deiconify(win, ex = true)
if ex
tk_call_without_enc('wm', 'deiconify', path)
tk_call_without_enc('wm', 'deiconify', win.epath)
else
self.iconify
Wm.iconify(win)
end
self
win
end
def deiconify(ex = true)
Wm.deiconify(self, ex)
end
alias wm_deiconify deiconify
def focusmodel(mode = nil)
def Wm.focusmodel(win, mode = nil)
if mode
tk_call_without_enc('wm', 'focusmodel', path, mode)
self
tk_call_without_enc('wm', 'focusmodel', win.epath, mode)
win
else
tk_call_without_enc('wm', 'focusmodel', path)
tk_call_without_enc('wm', 'focusmodel', win.epath)
end
end
def focusmodel(mode = nil)
Wm.focusmodel(self, mode)
end
alias wm_focusmodel focusmodel
TOPLEVEL_METHODCALL_OPTKEYS['focusmodel'] = 'focusmodel'
def frame
tk_call_without_enc('wm', 'frame', path)
def Wm.forget(win)
# Tcl/Tk 8.5+
# work with dockable frames
tk_call_without_enc('wm', 'forget', win.epath)
win
end
def wm_forget
Wm.forget(self)
end
def geometry(geom=nil)
def Wm.frame(win)
tk_call_without_enc('wm', 'frame', win.epath)
end
def frame
Wm.frame(self)
end
alias wm_frame frame
def Wm.geometry(win, geom=nil)
if geom
tk_call_without_enc('wm', 'geometry', path, geom)
self
tk_call_without_enc('wm', 'geometry', win.epath, geom)
win
else
tk_call_without_enc('wm', 'geometry', path)
tk_call_without_enc('wm', 'geometry', win.epath)
end
end
def geometry(geom=nil)
Wm.geometry(self, geom)
end
alias wm_geometry geometry
TOPLEVEL_METHODCALL_OPTKEYS['geometry'] = 'geometry'
def wm_grid(*args)
def Wm.grid(win, *args)
if args.size == 0
list(tk_call_without_enc('wm', 'grid', path))
list(tk_call_without_enc('wm', 'grid', win.epath))
else
args = args[0] if args.length == 1 && args[0].kind_of?(Array)
tk_call_without_enc('wm', 'grid', path, *args)
self
tk_call_without_enc('wm', 'grid', win.epath, *args)
win
end
end
def wm_grid(*args)
Wm.grid(self, *args)
end
TOPLEVEL_METHODCALL_OPTKEYS['wm_grid'] = 'wm_grid'
def group(leader = nil)
def Wm.group(win, leader = nil)
if leader
tk_call('wm', 'group', path, leader)
self
tk_call('wm', 'group', win.epath, leader)
win
else
window(tk_call('wm', 'group', path))
window(tk_call('wm', 'group', win.epath))
end
end
def group(leader = nil)
Wm.group(self, leader)
end
alias wm_group group
TOPLEVEL_METHODCALL_OPTKEYS['group'] = 'group'
def iconbitmap(bmp=nil)
def Wm.iconbitmap(win, bmp=nil)
if bmp
tk_call_without_enc('wm', 'iconbitmap', path, bmp)
self
tk_call_without_enc('wm', 'iconbitmap', win.epath, bmp)
win
else
image_obj(tk_call_without_enc('wm', 'iconbitmap', path))
image_obj(tk_call_without_enc('wm', 'iconbitmap', win.epath))
end
end
def iconbitmap(bmp=nil)
Wm.iconbitmap(self, bmp)
end
alias wm_iconbitmap iconbitmap
TOPLEVEL_METHODCALL_OPTKEYS['iconbitmap'] = 'iconbitmap'
def iconphoto(*imgs)
def Wm.iconphoto(win, *imgs)
if imgs.empty?
win.instance_eval{
@wm_iconphoto = nil unless defined? @wm_iconphoto
return @wm_iconphoto
}
end
imgs = imgs[0] if imgs.length == 1 && imgs[0].kind_of?(Array)
tk_call_without_enc('wm', 'iconphoto', path, *imgs)
@wm_iconphoto = imgs
self
tk_call_without_enc('wm', 'iconphoto', win.epath, *imgs)
win.instance_eval{ @wm_iconphoto = imgs }
win
end
def iconphoto(*imgs)
Wm.iconphoto(self, *imgs)
end
alias wm_iconphoto iconphoto
TOPLEVEL_METHODCALL_OPTKEYS['iconphoto'] = 'iconphoto'
def iconphoto_default(*imgs)
def Wm.iconphoto_default(win, *imgs)
imgs = imgs[0] if imgs.length == 1 && imgs[0].kind_of?(Array)
tk_call_without_enc('wm', 'iconphoto', path, '-default', *imgs)
self
tk_call_without_enc('wm', 'iconphoto', win.epath, '-default', *imgs)
win
end
def iconphoto_default(*imgs)
Wm.iconphoto_default(self, *imgs)
end
alias wm_iconphoto_default iconphoto_default
def iconify(ex = true)
def Wm.iconify(win, ex = true)
if ex
tk_call_without_enc('wm', 'iconify', path)
tk_call_without_enc('wm', 'iconify', win.epath)
else
self.deiconify
Wm.deiconify(win)
end
self
win
end
def iconify(ex = true)
Wm.iconify(self, ex)
end
alias wm_iconify iconify
def iconmask(bmp=nil)
def Wm.iconmask(win, bmp=nil)
if bmp
tk_call_without_enc('wm', 'iconmask', path, bmp)
self
tk_call_without_enc('wm', 'iconmask', win.epath, bmp)
win
else
image_obj(tk_call_without_enc('wm', 'iconmask', path))
image_obj(tk_call_without_enc('wm', 'iconmask', win.epath))
end
end
def iconmask(bmp=nil)
Wm.iconmask(self, bmp)
end
alias wm_iconmask iconmask
TOPLEVEL_METHODCALL_OPTKEYS['iconmask'] = 'iconmask'
def iconname(name=nil)
def Wm.iconname(win, name=nil)
if name
tk_call('wm', 'iconname', path, name)
self
tk_call('wm', 'iconname', win.epath, name)
win
else
tk_call('wm', 'iconname', path)
tk_call('wm', 'iconname', win.epath)
end
end
def iconname(name=nil)
Wm.iconname(self, name)
end
alias wm_iconname iconname
TOPLEVEL_METHODCALL_OPTKEYS['iconname'] = 'iconname'
def iconposition(*args)
def Wm.iconposition(win, *args)
if args.size == 0
list(tk_call_without_enc('wm', 'iconposition', path))
list(tk_call_without_enc('wm', 'iconposition', win.epath))
else
args = args[0] if args.length == 1 && args[0].kind_of?(Array)
tk_call_without_enc('wm', 'iconposition', path, *args)
self
tk_call_without_enc('wm', 'iconposition', win.epath, *args)
win
end
end
def iconposition(*args)
Wm.iconposition(self, *args)
end
alias wm_iconposition iconposition
TOPLEVEL_METHODCALL_OPTKEYS['iconposition'] = 'iconposition'
def iconwindow(win = nil)
if win
tk_call_without_enc('wm', 'iconwindow', path, win)
self
def Wm.iconwindow(win, iconwin = nil)
if iconwin
tk_call_without_enc('wm', 'iconwindow', win.epath, iconwin)
win
else
w = tk_call_without_enc('wm', 'iconwindow', path)
w = tk_call_without_enc('wm', 'iconwindow', win.epath)
(w == '')? nil: window(w)
end
end
def iconwindow(iconwin = nil)
Wm.iconwindow(self, iconwin)
end
alias wm_iconwindow iconwindow
TOPLEVEL_METHODCALL_OPTKEYS['iconwindow'] = 'iconwindow'
def maxsize(*args)
def Wm.manage(win)
# Tcl/Tk 8.5+ feature
tk_call_without_enc('wm', 'manage', win.epath)
win
end
def wm_manage
Wm.manage(self)
end
=begin
def Wm.manage(win, use_id = nil)
# Tcl/Tk 8.5+ feature
# --------------------------------------------------------------
# In the future release, I want to support to embed the 'win'
# into the container which has window-id 'use-id'.
# It may give users frexibility on controlling their GUI.
# However, it may be difficult for current Tcl/Tk (Tcl/Tk8.5.1),
# because it seems to require to modify Tcl/Tk's source code.
# --------------------------------------------------------------
if use_id
tk_call_without_enc('wm', 'manage', win.epath, '-use', use_id)
else
tk_call_without_enc('wm', 'manage', win.epath)
end
win
end
=end
def Wm.maxsize(win, *args)
if args.size == 0
list(tk_call_without_enc('wm', 'maxsize', path))
list(tk_call_without_enc('wm', 'maxsize', win.epath))
else
args = args[0] if args.length == 1 && args[0].kind_of?(Array)
tk_call_without_enc('wm', 'maxsize', path, *args)
self
tk_call_without_enc('wm', 'maxsize', win.epath, *args)
win
end
end
def maxsize(*args)
Wm.maxsize(self, *args)
end
alias wm_maxsize maxsize
TOPLEVEL_METHODCALL_OPTKEYS['maxsize'] = 'maxsize'
def minsize(*args)
def Wm.minsize(win, *args)
if args.size == 0
list(tk_call_without_enc('wm', 'minsize', path))
list(tk_call_without_enc('wm', 'minsize', win.epath))
else
args = args[0] if args.length == 1 && args[0].kind_of?(Array)
tk_call_without_enc('wm', 'minsize', path, *args)
self
tk_call_without_enc('wm', 'minsize', win.path, *args)
win
end
end
def minsize(*args)
Wm.minsize(self, *args)
end
alias wm_minsize minsize
TOPLEVEL_METHODCALL_OPTKEYS['minsize'] = 'minsize'
def overrideredirect(mode=None)
if mode == None
bool(tk_call_without_enc('wm', 'overrideredirect', path))
def Wm.overrideredirect(win, mode=TkComm::None)
if mode == TkComm::None
bool(tk_call_without_enc('wm', 'overrideredirect', win.epath))
else
tk_call_without_enc('wm', 'overrideredirect', path, mode)
self
tk_call_without_enc('wm', 'overrideredirect', win.epath, mode)
win
end
end
def overrideredirect(mode=TkComm::None)
Wm.overrideredirect(self, mode=TkComm::None)
end
alias wm_overrideredirect overrideredirect
TOPLEVEL_METHODCALL_OPTKEYS['overrideredirect'] = 'overrideredirect'
def positionfrom(who=None)
if who == None
r = tk_call_without_enc('wm', 'positionfrom', path)
def Wm.positionfrom(win, who=TkComm::None)
if who == TkComm::None
r = tk_call_without_enc('wm', 'positionfrom', win.epath)
(r == "")? nil: r
else
tk_call_without_enc('wm', 'positionfrom', path, who)
self
tk_call_without_enc('wm', 'positionfrom', win.epath, who)
win
end
end
def positionfrom(who=TkComm::None)
Wm.positionfrom(self, who)
end
alias wm_positionfrom positionfrom
TOPLEVEL_METHODCALL_OPTKEYS['positionfrom'] = 'positionfrom'
def protocol(name=nil, cmd=nil, &b)
def Wm.protocol(win, name=nil, cmd=nil, &b)
if cmd
tk_call_without_enc('wm', 'protocol', path, name, cmd)
self
tk_call_without_enc('wm', 'protocol', win.epath, name, cmd)
win
elsif b
tk_call_without_enc('wm', 'protocol', path, name, proc(&b))
self
tk_call_without_enc('wm', 'protocol', win.epath, name, proc(&b))
win
elsif name
result = tk_call_without_enc('wm', 'protocol', path, name)
result = tk_call_without_enc('wm', 'protocol', win.epath, name)
(result == "")? nil : tk_tcl2ruby(result)
else
tk_split_simplelist(tk_call_without_enc('wm', 'protocol', path))
tk_split_simplelist(tk_call_without_enc('wm', 'protocol', win.epath))
end
end
def protocol(name=nil, cmd=nil, &b)
Wm.protocol(self, name, cmd, &b)
end
alias wm_protocol protocol
def protocols(kv=nil)
def Wm.protocols(win, kv=nil)
unless kv
ret = {}
self.protocol.each{|name|
ret[name] = self.protocol(name)
Wm.protocol(win).each{|name|
ret[name] = Wm.protocol(win, name)
}
return ret
end
@ -279,82 +413,140 @@ module Tk
unless kv.kind_of?(Hash)
fail ArgumentError, 'expect a hash of protocol=>command'
end
kv.each{|k, v| self.protocol(k, v)}
self
kv.each{|k, v| Wm.protocol(win, k, v)}
win
end
def protocols(kv=nil)
Wm.protocols(self, kv)
end
alias wm_protocols protocols
TOPLEVEL_METHODCALL_OPTKEYS['protocols'] = 'protocols'
def resizable(*args)
def Wm.resizable(win, *args)
if args.length == 0
list(tk_call_without_enc('wm', 'resizable', path)).collect{|e| bool(e)}
list(tk_call_without_enc('wm', 'resizable', win.epath)).map!{|e| bool(e)}
else
args = args[0] if args.length == 1 && args[0].kind_of?(Array)
tk_call_without_enc('wm', 'resizable', path, *args)
self
tk_call_without_enc('wm', 'resizable', win.epath, *args)
win
end
end
def resizable(*args)
Wm.resizable(self, *args)
end
alias wm_resizable resizable
TOPLEVEL_METHODCALL_OPTKEYS['resizable'] = 'resizable'
def sizefrom(who=None)
if who == None
r = tk_call_without_enc('wm', 'sizefrom', path)
def Wm.sizefrom(win, who=TkComm::None)
if who == TkComm::None
r = tk_call_without_enc('wm', 'sizefrom', win.epath)
(r == "")? nil: r
else
tk_call_without_enc('wm', 'sizefrom', path, who)
self
tk_call_without_enc('wm', 'sizefrom', win.epath, who)
win
end
end
def sizefrom(who=TkComm::None)
Wm.sizefrom(self, who)
end
alias wm_sizefrom sizefrom
TOPLEVEL_METHODCALL_OPTKEYS['sizefrom'] = 'sizefrom'
def Wm.stackorder(win)
list(tk_call('wm', 'stackorder', win.epath))
end
def stackorder
list(tk_call('wm', 'stackorder', path))
Wm.stackorder(self)
end
alias wm_stackorder stackorder
def stackorder_isabove(win)
bool(tk_call('wm', 'stackorder', path, 'isabove', win))
def Wm.stackorder_isabove(win, target)
bool(tk_call('wm', 'stackorder', win.epath, 'isabove', target))
end
def stackorder_isbelow(win)
bool(tk_call('wm', 'stackorder', path, 'isbelow', win))
def Wm.stackorder_is_above(win, target)
Wm.stackorder_isabove(win, target)
end
def stackorder_isabove(target)
Wm.stackorder_isabove(self, target)
end
alias stackorder_is_above stackorder_isabove
alias wm_stackorder_isabove stackorder_isabove
alias wm_stackorder_is_above stackorder_isabove
def state(st=nil)
def Wm.stackorder_isbelow(win, target)
bool(tk_call('wm', 'stackorder', win.epath, 'isbelow', target))
end
def Wm.stackorder_is_below(win, target)
Wm.stackorder_isbelow(win, target)
end
def stackorder_isbelow(target)
Wm.stackorder_isbelow(self, target)
end
alias stackorder_is_below stackorder_isbelow
alias wm_stackorder_isbelow stackorder_isbelow
alias wm_stackorder_is_below stackorder_isbelow
def Wm.state(win, st=nil)
if st
tk_call_without_enc('wm', 'state', path, st)
self
tk_call_without_enc('wm', 'state', win.epath, st)
win
else
tk_call_without_enc('wm', 'state', path)
tk_call_without_enc('wm', 'state', win.epath)
end
end
def state(st=nil)
Wm.state(self, st)
end
alias wm_state state
TOPLEVEL_METHODCALL_OPTKEYS['state'] = 'state'
def title(str=nil)
def Wm.title(win, str=nil)
if str
tk_call('wm', 'title', path, str)
self
tk_call('wm', 'title', win.epath, str)
win
else
tk_call('wm', 'title', path)
tk_call('wm', 'title', win.epath)
end
end
def title(str=nil)
Wm.title(self, str)
end
alias wm_title title
TOPLEVEL_METHODCALL_OPTKEYS['title'] = 'title'
def transient(master=nil)
def Wm.transient(win, master=nil)
if master
tk_call_without_enc('wm', 'transient', path, master)
self
tk_call_without_enc('wm', 'transient', win.epath, master)
win
else
window(tk_call_without_enc('wm', 'transient', path))
window(tk_call_without_enc('wm', 'transient', win.epath))
end
end
def transient(master=nil)
Wm.transient(self, master)
end
alias wm_transient transient
TOPLEVEL_METHODCALL_OPTKEYS['transient'] = 'transient'
def withdraw(ex = true)
def Wm.withdraw(win, ex = true)
if ex
tk_call_without_enc('wm', 'withdraw', path)
tk_call_without_enc('wm', 'withdraw', win.epath)
else
self.deiconify
end
self
Wm.deiconify(win)
end
win
end
def withdraw(ex = true)
Wm.withdraw(self, ex)
end
alias wm_withdraw withdraw
end
module Wm_for_General
Wm.instance_methods.each{|m|
if (m = m.to_s) =~ /^wm_(.*)$/
eval "def #{m}(*args); Tk::Wm.#{$1}(self, *args); end"
end
}
end
end

View file

@ -83,7 +83,7 @@ BLT 2.4z http://sourceforge.net/projects/blt
TkTreeCtrl CVS/Hd(2005-12-02)
http://sourceforge.net/projects/tktreectrl ==> treectrl
Tile 0.7.8
Tile 0.8.0/8.5.1
http://sourceforge.net/projects/tktable ==> tile

View file

@ -13,7 +13,16 @@ module Tk::BLT
TkCommandNames = ['::blt::bitmap'.freeze].freeze
BITMAP_ID_TBL = TkCore::INTERP.create_table
BITMAP_ID = ['blt_bitmap_id'.freeze, '00000'.taint].freeze
(BITMAP_ID = ['blt_bitmap_id'.freeze, '00000'.taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
TkCore::INTERP.init_ip_env{
BITMAP_ID_TBL.mutex.synchronize{ BITMAP_ID_TBL.clear }
}
def self.data(name)
dat = tk_simple_list(tk_call('::blt::bitmap', 'data', name))
@ -64,9 +73,13 @@ module Tk::BLT
if name
@id = name
else
BITMAP_ID.mutex.synchronize{
@id = BITMAP_ID.join(TkCore::INTERP._ip_id_)
BITMAP_ID[1].succ!
}
BITMAP_ID_TBL.mutex.synchronize{
BITMAP_ID_TBL[@id] = self
}
end
@path = @id

View file

@ -19,7 +19,7 @@ module Tk::BLT
class Shield < TkWindow
def self.shield_path(win)
win = window(win) unless win.kind_of?(TkWindow)
if win.kind_of?(TkToplevel)
if win.kind_of?(Tk::Toplevel)
win.path + '._Busy'
else
win.path + '_Busy'

View file

@ -327,13 +327,24 @@ module Tk::BLT
#################
class Axis < TkObject
OBJ_ID = ['blt_chart_axis'.freeze, '00000'.taint].freeze
OBJ_TBL={}
(OBJ_ID = ['blt_chart_axis'.freeze, '00000'.taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
AxisID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{
AxisID_TBL.mutex.synchronize{ AxisID_TBL.clear }
}
def self.id2obj(chart, id)
cpath = chart.path
return id unless OBJ_TBL[cpath]
OBJ_TBL[cpath][id]? OBJ_TBL[cpath][id]: id
AxisID_TBL.mutex.synchronize{
return id unless AxisID_TBL[cpath]
AxisID_TBL[cpath][id]? AxisID_TBL[cpath][id]: id
}
end
def self.new(chart, axis=nil, keys={})
@ -341,12 +352,48 @@ module Tk::BLT
keys = axis
axis = nil
end
OBJ_TBL[chart.path] = {} unless OBJ_TBL[chart.path]
return OBJ_TBL[chart.path][axis] if axis && OBJ_TBL[chart.path][axis]
super(chart, axis, keys)
if keys
keys = _symbolkey2str(keys)
not_create = keys.delete('without_creating')
else
not_create = false
end
obj = nil
AxisID_TBL.mutex.synchronize{
chart_path = chart.path
AxisID_TBL[chart_path] ||= {}
if axis && AxisID_TBL[chart_path][axis]
obj = AxisID_TBL[chart_path][axis]
else
(obj = self.allocate).instance_eval{
if axis
@axis = @id = axis.to_s
else
OBJ_ID.mutex.synchronize{
@axis = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
OBJ_ID[1].succ!
}
end
@path = @id
@parent = @chart = chart
@cpath = @chart.path
Axis::AxisID_TBL[@cpath][@axis] = self
unless not_create
tk_call(@chart, 'axis', 'create', @axis, keys)
return obj
end
}
end
}
obj.configure(keys) if obj && ! keys.empty?
obj
end
def initialize(chart, axis=nil, keys={})
# dummy:: not called by 'new' method
if axis.kind_of?(Hash)
keys = axis
axis = nil
@ -354,13 +401,15 @@ module Tk::BLT
if axis
@axis = @id = axis.to_s
else
OBJ_ID.mutex.synchronize{
@axis = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
OBJ_ID[1].succ!
}
end
@path = @id
@parent = @chart = chart
@cpath = @chart.path
Axis::OBJ_TBL[@cpath][@axis] = self
# Axis::AxisID_TBL[@cpath][@axis] = self
keys = _symbolkey2str(keys)
unless keys.delete('without_creating')
# @chart.axis_create(@axis, keys)
@ -438,17 +487,34 @@ module Tk::BLT
#################
class Crosshairs < TkObject
OBJ_TBL={}
CrosshairsID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{
CrosshairsID_TBL.mutex.synchronize{ CrosshairsID_TBL.clear }
}
def self.new(chart, keys={})
return OBJ_TBL[chart.path] if OBJ_TBL[chart.path]
super(chart, keys)
obj = nil
CrosshairsID_TBL.mutex.synchronize{
unless (obj = CrosshairsID_TBL[chart.path])
(obj = self.allocate).instance_eval{
@parent = @chart = chart
@cpath = @chart.path
@path = @id = 'crosshairs'
Crosshairs::CrosshairsID_TBL[@cpath] = self
}
end
}
chart.crosshair_configure(keys) if obj && ! keys.empty?
obj
end
def initialize(chart, keys={})
# dummy:: not called by 'new' method
@parent = @chart = chart
@cpath = @chart.path
Crosshairs::OBJ_TBL[@cpath] = self
# Crosshairs::CrosshairsID_TBL[@cpath] = self
@chart.crosshair_configure(keys) unless keys.empty?
@path = @id = 'crosshairs'
end
@ -500,12 +566,18 @@ module Tk::BLT
ElementTypeName = 'element'
ElementTypeToClass = { ElementTypeName=>self }
ElementID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{ ElementID_TBL.clear }
TkCore::INTERP.init_ip_env{
ElementID_TBL.mutex.synchronize{ ElementID_TBL.clear }
}
OBJ_ID = ['blt_chart_element'.freeze, '00000'.taint].freeze
OBJ_TBL={}
(OBJ_ID = ['blt_chart_element'.freeze, '00000'.taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
def Element.type2class(type)
ElementTypeToClass[type]
@ -513,8 +585,10 @@ module Tk::BLT
def Element.id2obj(chart, id)
cpath = chart.path
return id unless OBJ_TBL[cpath]
OBJ_TBL[cpath][id]? OBJ_TBL[cpath][id]: id
ElementID_TBL.mutex.synchronize{
return id unless ElementID_TBL[cpath]
ElementID_TBL[cpath][id]? ElementID_TBL[cpath][id]: id
}
end
def self.new(chart, element=nil, keys={})
@ -522,14 +596,49 @@ module Tk::BLT
keys = element
element = nil
end
OBJ_TBL[chart.path] = {} unless OBJ_TBL[chart.path]
if element && OBJ_TBL[chart.path][element]
return OBJ_TBL[chart.path][element]
if keys
keys = _symbolkey2str(keys)
not_create = keys.delete('without_creating')
else
not_create = false
end
super(chart, element, keys)
obj = nil
ElementID_TBL.mutex.synchronize{
chart_path = chart.path
ElementID_TBL[chart_path] ||= {}
if element && ElementID_TBL[chart_path][element]
obj = ElementID_TBL[chart_path][element]
else
(obj = self.allocate).instance_eval{
if element
@element = @id = element.to_s
else
OBJ_ID.mutex.synchronize{
@element = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
OBJ_ID[1].succ!
}
end
@path = @id
@parent = @chart = chart
@cpath = @chart.path
@typename = self.class::ElementTypeName
Element::ElementID_TBL[@cpath][@element] = self
unless not_create
tk_call(@chart, @typename, 'create', @element, keys)
return obj
end
}
end
}
obj.configure(keys) if obj && ! keys.empty?
obj
end
def initialize(chart, element=nil, keys={})
# dummy:: not called by 'new' method
if element.kind_of?(Hash)
keys = element
element = nil
@ -537,14 +646,16 @@ module Tk::BLT
if element
@element = @id = element.to_s
else
OBJ_ID.mutex.synchronize{
@element = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
OBJ_ID[1].succ!
}
end
@path = @id
@parent = @chart = chart
@cpath = @chart.path
@typename = self.class::ElementTypeName
Element::OBJ_TBL[@cpath][@element] = self
# Element::ElementID_TBL[@cpath][@element] = self
keys = _symbolkey2str(keys)
unless keys.delete('without_creating')
# @chart.element_create(@element, keys)
@ -622,17 +733,33 @@ module Tk::BLT
#################
class GridLine < TkObject
OBJ_TBL={}
GridLineID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{
GridLineID_TBL.mutex.synchronize{ GridLineID_TBL.clear }
}
def self.new(chart, keys={})
return OBJ_TBL[chart.path] if OBJ_TBL[chart.path]
super(chart, keys)
obj = nil
GridLineID_TBL.mutex.synchronize{
unless (obj = GridLineID_TBL[chart.path])
(obj = self.allocate).instance_eval{
@parent = @chart = chart
@cpath = @chart.path
@path = @id = 'grid'
GridLine::GridLineID_TBL[@cpath] = self
}
end
}
chart.gridline_configure(keys) if obj && ! keys.empty?
obj
end
def initialize(chart, keys={})
# dummy:: not called by 'new' method
@parent = @chart = chart
@cpath = @chart.path
GridLine::OBJ_TBL[@cpath] = self
# GridLine::GridLineID_TBL[@cpath] = self
@chart.gridline_configure(keys) unless keys.empty?
@path = @id = 'grid'
end
@ -676,18 +803,35 @@ module Tk::BLT
#################
class Legend < TkObject
OBJ_TBL={}
LegendID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{
LegendID_TBL.mutex.synchronize{ LegendID_TBL.clear }
}
def self.new(chart, keys={})
return OBJ_TBL[chart.path] if OBJ_TBL[chart.path]
super(chart, keys)
obj = nil
LegenedID_TBL.mutex.synchronize{
unless (obj = LegenedID_TBL[chart.path])
(obj = self.allocate).instance_eval{
@parent = @chart = chart
@cpath = @chart.path
@path = @id = 'crosshairs'
Legend::LegenedID_TBL[@cpath] = self
}
end
}
chart.legend_configure(keys) if obj && ! keys.empty?
obj
end
def initialize(chart, keys={})
# dummy:: not called by 'new' method
@parent = @chart = chart
@cpath = @chart.path
Crosshairs::OBJ_TBL[@cpath] = self
@chart.crosshair_configure(keys) unless keys.empty?
# Legend::LegendID_TBL[@cpath] = self
@chart.legend_configure(keys) unless keys.empty?
@path = @id = 'legend'
end
@ -729,13 +873,24 @@ module Tk::BLT
#################
class Pen < TkObject
OBJ_ID = ['blt_chart_pen'.freeze, '00000'.taint].freeze
OBJ_TBL={}
(OBJ_ID = ['blt_chart_pen'.freeze, '00000'.taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
PenID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{
PenID_TBL.mutex.synchronize{ PenID_TBL.clear }
}
def self.id2obj(chart, id)
cpath = chart.path
return id unless OBJ_TBL[cpath]
OBJ_TBL[cpath][id]? OBJ_TBL[cpath][id]: id
PenID_TBL.mutex.synchronize{
return id unless PenID_TBL[cpath]
PenID_TBL[cpath][id]? PenID_TBL[cpath][id]: id
}
end
def self.new(chart, pen=nil, keys={})
@ -743,9 +898,43 @@ module Tk::BLT
keys = pen
pen = nil
end
OBJ_TBL[chart.path] = {} unless OBJ_TBL[chart.path]
return OBJ_TBL[chart.path][pen] if pen && OBJ_TBL[chart.path][pen]
super(chart, pen, keys)
if keys
keys = _symbolkey2str(keys)
not_create = keys.delete('without_creating')
else
not_create = false
end
obj = nil
PenID_TBL.mutex.synchronize{
chart_path = chart.path
PenID_TBL[chart_path] ||= {}
if pen && PenID_TBL[chart_path][pen]
obj = PenID_TBL[chart_path][pen]
else
(obj = self.allocate).instance_eval{
if pen
@pen = @id = pen.to_s
else
OBJ_ID.mutex.synchronize{
@pen = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
OBJ_ID[1].succ!
}
end
@path = @id
@parent = @chart = chart
@cpath = @chart.path
Pen::PenID_TBL[@cpath][@pen] = self
unless not_create
tk_call(@chart, 'pen', 'create', @pen, keys)
return obj
end
}
end
}
obj.configure(keys) if obj && ! keys.empty?
obj
end
def initialize(chart, pen=nil, keys={})
@ -756,13 +945,15 @@ module Tk::BLT
if pen
@pen = @id = pen.to_s
else
OBJ_ID.mutex.synchronize{
@pen = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze
OBJ_ID[1].succ!
}
end
@path = @id
@parent = @chart = chart
@cpath = @chart.path
Pen::OBJ_TBL[@cpath][@pen] = self
Pen::PenID_TBL[@cpath][@pen] = self
keys = _symbolkey2str(keys)
unless keys.delete('without_creating')
# @chart.pen_create(@pen, keys)
@ -805,17 +996,34 @@ module Tk::BLT
#################
class Postscript < TkObject
OBJ_TBL={}
PostscriptID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{
PostscriptID_TBL.mutex.synchronize{ PostscriptID_TBL.clear }
}
def self.new(chart, keys={})
return OBJ_TBL[chart.path] if OBJ_TBL[chart.path]
super(chart, keys)
obj = nil
PostscriptID_TBL.mutex.synchronize{
unless (obj = PostscriptID_TBL[chart.path])
(obj = self.allocate).instance_eval{
@parent = @chart = chart
@cpath = @chart.path
@path = @id = 'postscript'
Postscript::PostscriptID_TBL[@cpath] = self
}
end
}
chart.postscript_configure(keys) if obj && ! keys.empty?
obj
end
def initialize(chart, keys={})
# dummy:: not called by 'new' method
@parent = @chart = chart
@cpath = @chart.path
Postscript::OBJ_TBL[@cpath] = self
# Postscript::PostscriptID_TBL[@cpath] = self
@chart.postscript_configure(keys) unless keys.empty?
@path = @id = 'postscript'
end
@ -870,7 +1078,9 @@ module Tk::BLT
MarkerTypeToClass = {}
MarkerID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{ MarkerID_TBL.clear }
TkCore::INTERP.init_ip_env{
MarkerID_TBL.mutex.synchronize{ MarkerID_TBL.clear }
}
def Marker.type2class(type)
MarkerTypeToClass[type]
@ -878,8 +1088,13 @@ module Tk::BLT
def Marker.id2obj(chart, id)
cpath = chart.path
return id unless MarkerID_TBL[cpath]
MarkerID_TBL.mutex.synchronize{
if MarkerID_TBL[cpath]
MarkerID_TBL[cpath][id]? MarkerID_TBL[cpath][id]: id
else
id
end
}
end
def self._parse_create_args(keys)
@ -943,11 +1158,11 @@ module Tk::BLT
@parent = @chart = chart
@cpath = chart.path
@id = id
unless Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath]
Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath] = {}
end
Tk::BLT::PlotComponent::Marker::MarkerID_TBL.mutex.synchronize{
Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath] ||= {}
Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath][@id] = self
}
}
obj
end
@ -956,10 +1171,10 @@ module Tk::BLT
@cpath = parent.path
@path = @id = create_self(*args) # an integer number as 'item id'
unless Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath]
Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath] = {}
end
Tk::BLT::PlotComponent::Marker::MarkerID_TBL.mutex.synchronize{
Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath] ||= {}
Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath][@id] = self
}
end
def create_self(*args)
self.class.create(@chart, *args) # return an integer as 'item id'
@ -1037,14 +1252,14 @@ module Tk::BLT
#################
def __destroy_hook__
Axis::OBJ_TBL.delete(@path)
Crosshairs::OBJ_TBL.delete(@path)
Element::OBJ_TBL.delete(@path)
GridLine::OBJ_TBL.delete(@path)
Legend::OBJ_TBL.delete(@path)
Pen::OBJ_TBL.delete(@path)
Postscript::OBJ_TBL.delete(@path)
Marker::OBJ_TBL.delete(@path)
Axis::AxisID_TBL.delete(@path)
Crosshairs::CrosshairsID_TBL.delete(@path)
Element::ElementID_TBL.delete(@path)
GridLine::GridLineID_TBL.delete(@path)
Legend::LegendID_TBL.delete(@path)
Pen::PenID_TBL.delete(@path)
Postscript::PostscriptID_TBL.delete(@path)
Marker::MarkerID_TBL.delete(@path)
super()
end

View file

@ -81,6 +81,22 @@ module Tk::BLT
nil
]
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf|
if inf.kind_of?(Array)
inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
end
inf
}
PROC_TBL.map!{|inf|
if inf.kind_of?(Array)
inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
end
inf
}
_setup_subst_table(KEY_TBL, PROC_TBL)
def self.ret_val(val)
@ -107,6 +123,22 @@ module Tk::BLT
nil
]
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf|
if inf.kind_of?(Array)
inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
end
inf
}
PROC_TBL.map!{|inf|
if inf.kind_of?(Array)
inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
end
inf
}
_setup_subst_table(KEY_TBL, PROC_TBL)
def self.ret_val(val)
@ -145,6 +177,22 @@ module Tk::BLT
nil
]
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf|
if inf.kind_of?(Array)
inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
end
inf
}
PROC_TBL.map!{|inf|
if inf.kind_of?(Array)
inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
end
inf
}
_setup_subst_table(KEY_TBL, PROC_TBL)
end

View file

@ -14,7 +14,7 @@ module Tk::BLT
end
end
class TkCanvas
class Tk::Canvas
alias __BLT_EPS_item_strval_optkeys __item_strval_optkeys
def __item_strval_optkeys(id)
__BLT_EPS_item_strval_optkeys(id) + [

View file

@ -12,14 +12,26 @@ module Tk::BLT
include TkTreatItemFont
TabID_TBL = TkCore::INTERP.create_table
TabsetTab_ID = ['blt_tabset_tab'.freeze, '00000'.taint].freeze
TkCore::INTERP.init_ip_env{ TabID_TBL.clear }
(TabsetTab_ID = ['blt_tabset_tab'.freeze, '00000'.taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
TkCore::INTERP.init_ip_env{
TabID_TBL.mutex.synchronize{ TabID_TBL.clear }
}
def self.id2obj(tabset, id)
tpath = tabset.path
return id unless TabID_TBL[tpath]
TabID_TBL.mutex.synchronize{
if TabID_TBL[tpath]
TabID_TBL[tpath][id]? TabID_TBL[tpath]: id
else
id
end
}
end
def self.new(parent, pos=nil, name=nil, keys={})
@ -32,12 +44,20 @@ module Tk::BLT
keys = name
name = nil
end
obj = nil
TabID_TBL.mutex.synchronize{
if name && TabID_TBL[parent.path] && TabID_TBL[parent.path][name]
TabID_TBL[parent.path][name]
obj = TabID_TBL[parent.path][name]
obj.configure if keys && ! keys.empty?
else
super(parent, pos, name, keys)
(obj = self.allocate).instance_eval{
initialize(parent, pos, name, keys)
TabID_TBL[@tpath] = {} unless TabID_TBL[@tpath]
TabID_TBL[@tpath][@id] = self
}
end
}
obj
end
def initialize(parent, pos, name, keys)
@ -45,9 +65,6 @@ module Tk::BLT
@tpath = parent.path
if name
@path = @id = name
TabID_TBL[@tpath] = {} unless TabID_TBL[@tpath]
TabID_TBL[@tpath][@id] = self
unless (list(tk_call(@tpath, 'tab', 'names', @id)).empty?)
if pos
idx = tk_call(@tpath, 'index', '-name', @id)
@ -58,19 +75,19 @@ module Tk::BLT
end
end
tk_call(@tpath, 'tab', 'configure', @id, keys)
return
end
else
@path = @id = TabsetTab_ID.join(TkCore::INTERP._ip_id_)
TabID_TBL[@tpath] = {} unless TabID_TBL[@tpath]
TabID_TBL[@tpath][@id] = self
TabsetTab_ID[1].succ!
end
pos = 'end' unless pos
tk_call(@tpath, 'insert', pos, @id, keys)
end
else
TabsetTab_ID.mutex.synchronize{
@path = @id = TabsetTab_ID.join(TkCore::INTERP._ip_id_)
TabsetTab_ID[1].succ!
}
pos = 'end' unless pos
tk_call(@tpath, 'insert', pos, @id, keys)
end
end
#def bind(context, cmd=Proc.new, *args)
# @t.tab_bind(@id, context, cmd, *args)
@ -123,7 +140,9 @@ module Tk::BLT
def delete()
@t.delete(@id)
TabID_TBL.mutex.synchronize{
TabID_TBL[@tpath].delete(@id)
}
self
end
@ -184,7 +203,9 @@ module Tk::BLT
WidgetClassNames[WidgetClassName] = self
def __destroy_hook__
Tk::BLT::Tabset::Tab::TabID_TBL.mutex.synchronize{
Tk::BLT::Tabset::Tab::TabID_TBL.delete(@path)
}
end
########################################
@ -291,11 +312,15 @@ module Tk::BLT
def delete(first, last=None)
tk_send('delete', tagindex(first), tagindex(last))
if first.kind_of?(Tk::BLT::Tabset::Tab)
TabID_TBL.mutex.synchronize{
TabID_TBL[@path].delete(first.id)
}
end
# middle tabs of the range are unknown
if last.kind_of?(Tk::BLT::Tabset::Tab)
TabID_TBL.mutex.synchronize{
TabID_TBL[@path].delete(last.id)
}
end
self
end

View file

@ -9,7 +9,7 @@ require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
class Button < TkButton
class Button < Tk::Button
TkCommandNames = ['::blt::tile::button'.freeze].freeze
end
end

View file

@ -9,7 +9,7 @@ require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
class CheckButton < TkCheckButton
class CheckButton < Tk::CheckButton
TkCommandNames = ['::blt::tile::checkbutton'.freeze].freeze
end
Checkbutton = CheckButton

View file

@ -9,7 +9,7 @@ require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
class Frame < TkFrame
class Frame < Tk::Frame
TkCommandNames = ['::blt::tile::frame'.freeze].freeze
end
end

View file

@ -9,7 +9,7 @@ require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
class Label < TkLabel
class Label < Tk::Label
TkCommandNames = ['::blt::tile::label'.freeze].freeze
end
end

View file

@ -9,7 +9,7 @@ require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
class RadioButton < TkRadioButton
class RadioButton < Tk::RadioButton
TkCommandNames = ['::blt::tile::radiobutton'.freeze].freeze
end
Radiobutton = RadioButton

View file

@ -9,7 +9,7 @@ require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
class Scrollbar < TkScrollbar
class Scrollbar < Tk::Scrollbar
TkCommandNames = ['::blt::tile::scrollbar'.freeze].freeze
end
end

View file

@ -9,7 +9,7 @@ require 'tkextlib/blt/tile.rb'
module Tk::BLT
module Tile
class Toplevel < TkToplevel
class Toplevel < Tk::Toplevel
TkCommandNames = ['::blt::tile::toplevel'.freeze].freeze
end
end

View file

@ -14,51 +14,75 @@ module Tk::BLT
class Node < TkObject
TreeNodeID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{ TreeNodeID_TBL.clear }
TkCore::INTERP.init_ip_env{
TreeNodeID_TBL.mutex.synchronize{ TreeNodeID_TBL.clear }
}
def self.id2obj(tree, id)
tpath = tree.path
return id unless TreeNodeID_TBL[tpath]
TreeNodeID_TBL.mutex.synchronize{
if TreeNodeID_TBL[tpath]
if TreeNodeID_TBL[tpath][id]
TreeNodeID_TBL[tpath][id]
else
begin
self.new(tree, nil, 'node'=>Integer(id))
# self.new(tree, nil, 'node'=>Integer(id))
id = Integer(id)
if bool(tk_call(@tpath, 'exists', id))
(obj = self.allocate).instance_eval{
@parent = @tree = tree
@tpath = tpath
@path = @id = id
TreeNodeID_TBL[@tpath] = {} unless TreeNodeID_TBL[@tpath]
TreeNodeID_TBL[@tpath][@id] = self
}
obj
else
id
end
rescue
id
end
end
else
id
end
}
end
def self.new(tree, parent, keys={})
keys = _symbolkey2str(keys)
tpath = tree.path
TreeNodeID_TBL.mutex.synchronize{
TreeNodeID_TBL[tpath] ||= {}
if (id = keys['node']) && (obj = TreeNodeID_TBL[tpath][id])
keys.delete('node')
tk_call(tree.path, 'move', id, parent, keys) if parent
return obj
end
super(tree, parent, keys)
(obj = self.allocate).instance_eval{
initialize(tree, parent, keys)
TreeNodeID_TBL[tpath][@id] = self
}
obj
}
end
def initialize(tree, parent, keys={})
@parent = @tree = tree
@tpath = @parent.path
parent = tk_call(@tpath, 'root') unless parent
if (id = keys['node']) && bool(tk_call(@tpath, 'exists', id))
@path = @id = id
keys.delete('node')
tk_call(@tpath, 'move', @id, parent, keys) if parent
else
parent = tk_call(@tpath, 'root') unless parent
@path = @id = tk_call(@tpath, 'insert', parent, keys)
end
TreeNodeID_TBL[@tpath] = {} unless TreeNodeID_TBL[@tpath]
TreeNodeID_TBL[@tpath][@id] = self
end
def id
@ -243,18 +267,43 @@ module Tk::BLT
class Tag < TkObject
TreeTagID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{ TreeTagID_TBL.clear }
TreeTag_ID = ['blt_tree_tag'.freeze, '00000'.taint].freeze
TkCore::INTERP.init_ip_env{
TreeTagID_TBL.mutex.synchronize{ TreeTagID_TBL.clear }
}
(TreeTag_ID = ['blt_tree_tag'.freeze, '00000'.taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
def self.id2obj(tree, id)
tpath = tree.path
return id unless TreeTagID_TBL[tpath]
TreeTagID_TBL.mutex.synchronize{
if TreeTagID_TBL[tpath]
if TreeTagID_TBL[tpath][id]
TreeTagID_TBL[tpath][id]
else
self.new(tree, id)
begin
# self.new(tree, id)
(obj = self.allocate).instance_eval{
@parent = @tree = tree
@tpath = @parent.path
@path = @id = id.dup.freeze if id
TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath]
TreeTagID_TBL[@tpath][@id] = self
}
obj
rescue
id
end
end
else
id
end
}
end
def initialize(tree, tag_str = nil)
@parent = @tree = tree
@ -263,12 +312,15 @@ module Tk::BLT
if tag_str
@path = @id = tag_str.dup.freeze
else
TreeTag_ID.mutex.synchronize{
@path = @id = TreeTag_ID.join(TkCore::INTERP._ip_id_)
TreeTagID_TBL[@id] = self
TreeTag_ID[1].succ!
}
end
TreeTagID_TBL.mutex.synchronize{
TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath]
TreeTagID_TBL[@tpath][@id] = self
}
end
def id
@ -287,7 +339,9 @@ module Tk::BLT
def forget()
tk_call(@tpath, 'tag', 'forget', @id)
TreeTagID_TBL.mutex.synchronize{
TreeTagID_TBL[@tpath].delete(@id)
}
self
end
@ -312,44 +366,63 @@ module Tk::BLT
class Notify < TkObject
NotifyID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{ NotifyID_TBL.clear }
TkCore::INTERP.init_ip_env{
NotifyID_TBL.mutex.synchronize{ NotifyID_TBL.clear }
}
def self.id2obj(tree, id)
tpath = tree.path
return id unless NotifyID_TBL[tpath]
NotifyID_TBL.mutex.synchronize{
if NotifyID_TBL[tpath]
if NotifyID_TBL[tpath][id]
NotifyID_TBL[tpath][id]
else
begin
self.new([tree, id])
rescue
id
(obj = self.allocate).instance_eval{
@parent = @tree = tree
@tpath = @parent.path
@path = @id = id
NotifyID_TBL[@tpath] ||= {}
NotifyID_TBL[@tpath][@id] = self
}
obj
end
else
return id
end
}
end
def self.new(tree, *args, &b)
NotifyID_TBL.mutex.synchronize{
if tree.kind_of?(Array)
# not create
if obj = NotifyID_TBL[tree[0].path][tree[1]]
tpath = tree[0].path
NotifyID_TBL[tpath] ||= {}
unless (obj = NotifyID_TBL[tpath][tree[1]])
(NotifyID_TBL[tpath][tree[1]] =
obj = self.allocate).instance_eval{
@parent = @tree = tree[0]
@tpath = @parent.path
@path = @id = tree[1]
}
end
return obj
else
return super(false, tree[0], tree[1])
end
end
super(true, tree, *args, &b)
(obj = self.allocate).instance_eval{
initialize(tree, *args, &b)
NotifyID_TBL[@tpath] ||= {}
NotifyID_TBL[@tpath][@id] = self
}
return obj
}
end
def initialize(create, tree, *args, &b)
def initialize(tree, *args, &b)
@parent = @tree = tree
@tpath = @parent.path
unless create
@path = @id = args[0]
return
end
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
if TkComm._callback_entry?(args[0])
cmd = args.shift
@ -378,7 +451,9 @@ module Tk::BLT
def delete()
tk_call(@tpath, 'notify', 'delete', @id)
NotifyID_TBL[tpath].delete(@id)
NotifyID_TBL.mutex.synchronize{
NotifyID_TBL[@tpath].delete(@id)
}
self
end
@ -395,43 +470,68 @@ module Tk::BLT
class Trace < TkObject
TraceID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{ TraceID_TBL.clear }
TkCore::INTERP.init_ip_env{
TraceID_TBL.mutex.synchronize{ TraceID_TBL.clear }
}
def self.id2obj(tree, id)
tpath = tree.path
return id unless TraceID_TBL[tpath]
TraceID_TBL.mutex.synchronize{
if TraceID_TBL[tpath]
if TraceID_TBL[tpath][id]
TraceID_TBL[tpath][id]
else
begin
self.new([tree, id])
# self.new([tree, id])
(obj = self.allocate).instance_eval{
@parent = @tree = tree
@tpath = @parent.path
@path = @id = node # == traceID
TraceID_TBL[@tpath] ||= {}
TraceID_TBL[@tpath][@id] = self
}
obj
rescue
id
end
end
else
id
end
}
end
def self.new(tree, *args, &b)
TraceID_TBL.mutex.synchronize{
if tree.kind_of?(Array)
# not create
if obj = TraceID_TBL[tree[0].path][tree[1]]
return obj
else
return super(false, tree[0], tree[1])
end
end
super(true, tree, *args, &b)
end
def initialize(create, tree, node, key, opts, cmd=nil, &b)
tpath = tree[0].path
TraceID_TBL[tpath] ||= {}
unless (obj = TraceID_TBL[tpath][tree[1]])
(TraceID_TBL[tpath][tree[1]] =
obj = self.allocate).instance_eval{
@parent = @tree = tree
@tpath = @parent.path
unless create
@path = @id = node # == traceID
return
@path = @id = tree[1] # == traceID
}
end
return obj
end
# super(true, tree, *args, &b)
(obj = self.allocate).instance_eval{
initialize(tree, *args, &b)
TraceID_TBL[@tpath] ||= {}
TraceID_TBL[@tpath][@id] = self
}
return obj
}
end
def initialize(tree, node, key, opts, cmd=nil, &b)
@parent = @tree = tree
@tpath = @parent.path
if !cmd
if b
@ -459,7 +559,9 @@ module Tk::BLT
def delete()
tk_call(@tpath, 'trace', 'delete', @id)
TraceID_TBL.mutex.synchronize{
TraceID_TBL[tpath].delete(@id)
}
self
end
@ -475,7 +577,12 @@ module Tk::BLT
###################################
TreeID_TBL = TkCore::INTERP.create_table
Tree_ID = ['blt_tree'.freeze, '00000'.taint].freeze
(Tree_ID = ['blt_tree'.freeze, '00000'.taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
def __keyonly_optkeys
{
@ -498,7 +605,9 @@ module Tk::BLT
end
def self.id2obj(id)
TreeID_TBL.mutex.synchronize{
TreeID_TBL[id]? TreeID_TBL[id]: id
}
end
def self.names(pat = None)
@ -513,27 +622,45 @@ module Tk::BLT
end
def self.new(name = nil)
return TreeID_TBL[name] if name && TreeID_TBL[name]
super(name)
TreeID_TBL.mutex.synchronize{
if name && TreeID_TBL[name]
TreeID_TBL[name]
else
(obj = self.allocate).instance_eval{
initialize(name)
TreeID_TBL[@id] = self
}
obj
end
}
end
def initialzie(name = nil)
if name
@path = @id = name
else
Tree_ID.mutex.synchronize{
@path = @id = Tree_ID.join(TkCore::INTERP._ip_id_)
TreeID_TBL[@id] = self
Tree_ID[1].succ!
}
end
TreeID_TBL[@id] = self
tk_call('::blt::tree', 'create', @id)
end
def __destroy_hook__
Tk::BLT::Tree::Node::TreeNodeID_TBL.mutex.synchronize{
Tk::BLT::Tree::Node::TreeNodeID_TBL.delete(@path)
}
Tk::BLT::Tree::Tag::TreeTagID_TBL.mutex.synchronize{
Tk::BLT::Tree::Tag::TreeTagID_TBL.delete(@path)
}
Tk::BLT::Tree::Notify::NotifyID_TBL.mutex.synchronize{
Tk::BLT::Tree::Notify::NotifyID_TBL.delete(@path)
}
Tk::BLT::Tree::Trace::TraceID_TBL.mutex.synchronize{
Tk::BLT::Tree::Trace::TraceID_TBL.delete(@path)
}
end
def tagid(tag)
@ -592,6 +719,7 @@ module Tk::BLT
def delete(*nodes)
tk_call('::blt::tree', 'delete', *(nodes.collect{|node| tagid(node)}))
Tk::BLT::Tree::Node::TreeNodeID_TBL.mutex.synchronize{
nodes.each{|node|
if node.kind_of?(Tk::BLT::Tree::Node)
Tk::BLT::Tree::Node::TreeNodeID_TBL[@path].delete(node.id)
@ -599,6 +727,7 @@ module Tk::BLT
Tk::BLT::Tree::Node::TreeNodeID_TBL[@path].delete(node.to_s)
end
}
}
self
end
@ -728,7 +857,9 @@ module Tk::BLT
id.delete
else
tk_call(@path, 'notify', 'delete', id)
Tk::BLT::Tree::Notify::NotifyID_TBL.mutex.synchronize{
Tk::BLT::Tree::Notify::NotifyID_TBL[@path].delete(id.to_s)
}
end
self
end
@ -835,7 +966,9 @@ module Tk::BLT
def tag_forget(tag)
tag = tag.id if tag.kind_of?(Tk::BLT::Tree::Tag)
tk_call(@path, 'tag', 'forget', tag)
TreeTagID_TBL.mutex.synchronize{
TreeTagID_TBL[@path].delete(tag)
}
self
end
@ -889,7 +1022,9 @@ module Tk::BLT
def trace_delete(*args)
args = args.collect{|id| tagid(id)}
tk_call(@path, 'trace', 'delete', *args)
Tk::BLT::Tree::Trace::TraceID_TBL.mutex.synchronize{
args.each{|id| Tk::BLT::Tree::Trace::TraceID_TBL[@path].delete(id.to_s)}
}
self
end

View file

@ -239,6 +239,22 @@ class Tk::BLT::Treeview
nil
]
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf|
if inf.kind_of?(Array)
inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
end
inf
}
PROC_TBL.map!{|inf|
if inf.kind_of?(Array)
inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
end
inf
}
_setup_subst_table(KEY_TBL, PROC_TBL);
def self.ret_val(val)
@ -273,8 +289,12 @@ class Tk::BLT::Treeview
########################
def __destroy_hook__
Tk::BLT::Treeview::Node::TreeNodeID_TBL.mutex.synchronize{
Tk::BLT::Treeview::Node::TreeNodeID_TBL.delete(@path)
}
Tk::BLT::Treeview::Tag::TreeTagID_TBL.mutex.synchronize{
Tk::BLT::Treeview::Tag::TreeTagID_TBL.delete(@path)
}
end
def tagid(tag)
@ -472,6 +492,22 @@ class Tk::BLT::Treeview
nil
]
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf|
if inf.kind_of?(Array)
inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
end
inf
}
PROC_TBL.map!{|inf|
if inf.kind_of?(Array)
inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
end
inf
}
_setup_subst_table(KEY_TBL, PROC_TBL);
def self.ret_val(val)
@ -967,22 +1003,47 @@ class Tk::BLT::Treeview::Node < TkObject
include Tk::BLT::Treeview::TagOrID_Methods
TreeNodeID_TBL = TkCore::INTERP.create_table
TreeNode_ID = ['blt_treeview_node'.freeze, '00000'.taint].freeze
TkCore::INTERP.init_ip_env{ TreeNodeID_TBL.clear }
(TreeNode_ID = ['blt_treeview_node'.freeze, '00000'.taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
TkCore::INTERP.init_ip_env{
TreeNodeID_TBL.mutex.synchronize{ TreeNodeID_TBL.clear }
}
def self.id2obj(tree, id)
tpath = tree.path
return id unless TreeNodeID_TBL[tpath]
TreeNodeID_TBL.mutex.synchronize{
if TreeNodeID_TBL[tpath]
if TreeNodeID_TBL[tpath][id]
TreeNodeID_TBL[tpath][id]
else
begin
self.new(tree, nil, nil, 'node'=>Integer(id))
# self.new(tree, nil, nil, 'node'=>Integer(id))
unless (tk_call(@tpath, 'get', id)).empty?
id = Integer(id)
(obj = self.allocate).instance_eval{
@parent = @tree = tree
@tpath = @parent.path
@path = @id = id
TreeNodeID_TBL[@tpath] ||= {}
TreeNodeID_TBL[@tpath][@id] = self
}
obj
else
id
end
rescue
id
end
end
else
id
end
}
end
def self.new(tree, pos, parent=nil, keys={})
@ -994,13 +1055,21 @@ class Tk::BLT::Treeview::Node < TkObject
keys = _symbolkey2str(keys)
tpath = tree.path
TreeNodeID_TBL.mutex.synchronize{
TreeNodeID_TBL[tpath] ||= {}
if (id = keys['node']) && (obj = TreeNodeID_TBL[tpath][id])
keys.delete('node')
tk_call(tree.path, 'move', id, pos, parent) if parent
return obj
end
super(tree, pos, parent, keys)
#super(tree, pos, parent, keys)
(obj = self.allocate).instance_eval{
initialize(tree, pos, parent, keys)
TreeNodeID_TBL[tpath][@id] = self
}
obj
}
end
def initialize(tree, pos, parent, keys)
@ -1008,11 +1077,18 @@ class Tk::BLT::Treeview::Node < TkObject
@tpath = @parent.path
if (id = keys['node'])
# if tk_call(@tpath, 'get', id).empty?
# fail RuntimeError, "not exist the node '#{id}'"
# end
@path = @id = id
tk_call(@tpath, 'move', @id, pos, tagid(parent)) if parent
configure(keys) if keys && ! keys.empty?
else
name = nil
TreeNode_ID.mutex.synchronize{
name = TreeNode_ID.join(TkCore::INTERP._ip_id_).freeze
TreeNode_ID[1].succ!
}
at = keys.delete['at']
@ -1035,9 +1111,6 @@ class Tk::BLT::Treeview::Node < TkObject
end
@path = @id
end
TreeNodeID_TBL[@tpath] = {} unless TreeNodeID_TBL[@tpath]
TreeNodeID_TBL[@tpath][@id] = self
end
def id
@ -1051,37 +1124,66 @@ class Tk::BLT::Treeview::Tag < TkObject
include Tk::BLT::Treeview::TagOrID_Methods
TreeTagID_TBL = TkCore::INTERP.create_table
TreeTag_ID = ['blt_treeview_tag'.freeze, '00000'.taint].freeze
TkCore::INTERP.init_ip_env{ TreeTagID_TBL.clear }
(TreeTag_ID = ['blt_treeview_tag'.freeze, '00000'.taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
def self.id2obj(tree, id)
TkCore::INTERP.init_ip_env{
TreeTagID_TBL.mutex.synchronize{ TreeTagID_TBL.clear }
}
def self.id2obj(tree, name)
tpath = tree.path
return id unless TreeTagID_TBL[tpath]
if TreeTagID_TBL[tpath][id]
TreeTagID_TBL[tpath][id]
TreeTagID_TBL.mutex.synchronize{
if TreeTagID_TBL[tpath]
if TreeTagID_TBL[tpath][name]
TreeTagID_TBL[tpath][name]
else
#self.new(tree, name)
(obj = self.allocate).instance_eval{
@parent = @tree = tree
@tpath = @parent.path
@path = @id = name
TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath]
TreeTagID_TBL[@tpath][@id] = self
}
obj
end
else
begin
self.new(tree, nil, nil, 'name'=>Integer(id))
rescue
id
end
end
}
end
def self.new_by_name(tree, name, *ids)
if (obj = TreeTagID_TBL[tree.path][name])
return obj
TreeTagID_TBL.mutex.synchronize{
unless (obj = TreeTagID_TBL[tree.path][name])
(obj = self.allocate).instance_eval{
initialize(tree, name, ids)
TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath]
TreeTagID_TBL[@tpath][@id] = self
}
end
new([tree, name], ids)
obj
}
end
def self.new(tree, *ids)
TreeTagID_TBL.mutex.synchronize{
(obj = self.allocate).instance_eval{
if tree.kind_of?(Array)
super(tree[0], tree[1], ids)
initialize(tree[0], tree[1], ids)
else
super(tree, nil, ids)
initialize(tree, nil, ids)
end
TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath]
TreeTagID_TBL[@tpath][@id] = self
}
obj
}
end
def initialize(tree, name, ids)
@ -1091,13 +1193,12 @@ class Tk::BLT::Treeview::Tag < TkObject
if name
@path = @id = name
else
TreeTag_ID.mutex.synchronize{
@path = @id = TreeTag_ID.join(TkCore::INTERP._ip_id_).freeze
TreeTag_ID[1].succ!
}
end
TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath]
TreeTagID_TBL[@tpath][@id] = self
unless ids.empty?
tk_call(@tpath, 'tag', 'add', @id, *(ids.collect{|id| tagid(id)}))
end

View file

@ -23,7 +23,9 @@ module Tk::BLT
end
def self.names(pat=None)
simplelist(tk_call('::blt::vector', 'names', pat)).collect{|name|
list = simplelist(tk_call('::blt::vector', 'names', pat))
TkVar_ID_TBL.mutex.synchronize{
list.collect{|name|
if TkVar_ID_TBL[name]
TkVar_ID_TBL[name]
elsif name[0..1] == '::' && TkVar_ID_TBL[name[2..-1]]
@ -32,6 +34,7 @@ module Tk::BLT
name
end
}
}
end
####################################
@ -53,7 +56,9 @@ module Tk::BLT
"#auto", *hash_kv(keys))
end
TkVar_ID_TBL.mutex.synchronize{
TkVar_ID_TBL[@id] = self
}
@def_default = false
@default_val = nil
@ -221,13 +226,21 @@ module Tk::BLT
class VectorAccess < Vector
def self.new(name)
return TkVar_ID_TBL[name] if TkVar_ID_TBL[name]
super(name, size=nil, keys={})
TkVar_ID_TBL.mutex.synchronize{
if TkVar_ID_TBL[name]
TkVar_ID_TBL[name]
else
(obj = self.allocate).instance_eval{
initialize(name)
TkVar_ID_TBL[@id] = self
}
obj
end
}
end
def initialize(vec_name)
@id = vec_name
TkVar_ID_TBL[@id] = self
@def_default = false
@default_val = nil

View file

@ -13,12 +13,24 @@ module Tk::BLT
TkCommandNames = ['::blt::watch'.freeze].freeze
WATCH_ID_TBL = TkCore::INTERP.create_table
BLT_WATCH_ID = ['blt_watch_id'.freeze, '00000'.taint].freeze
(BLT_WATCH_ID = ['blt_watch_id'.freeze, '00000'.taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
TkCore::INTERP.init_ip_env{
WATCH_ID_TBL.mutex.synchronize{ WATCH_ID_TBL.clear }
}
def self.names(state = None)
tk_split_list(tk_call('::blt::watch', 'names', state)).collect{|name|
lst = tk_split_list(tk_call('::blt::watch', 'names', state))
WATCH_ID_TBL.mutex.synchronize{
lst.collect{|name|
WATCH_ID_TBL[name] || name
}
}
end
def __numval_optkeys
@ -45,13 +57,17 @@ module Tk::BLT
if name
@id = name.to_s
else
BLT_WATCH_ID.mutex.synchronize{
@id = BLT_WATCH_ID.join(TkCore::INTERP._ip_id_)
BLT_WATCH_ID[1].succ!
}
end
@path = @id
WATCH_ID_TBL.mutex.synchronize{
WATCH_ID_TBL[@id] = self
}
tk_call('::blt::watch', 'create', @id, *hash_kv(keys))
end

View file

@ -9,7 +9,7 @@ require 'tkextlib/bwidget.rb'
module Tk
module BWidget
class Button < TkButton
class Button < Tk::Button
end
end
end

View file

@ -31,7 +31,7 @@ class Tk::BWidget::ButtonBox
name = tagOrId[:name]
return index(name) unless name.empty?
end
if tagOrId.kind_of?(TkButton)
if tagOrId.kind_of?(Tk::Button)
return index(tagOrId[:text])
end
# index(tagOrId.to_s)
@ -40,7 +40,13 @@ class Tk::BWidget::ButtonBox
def add(keys={}, &b)
win = window(tk_send('add', *hash_kv(keys)))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end
@ -54,7 +60,7 @@ class Tk::BWidget::ButtonBox
name = idx[:name]
idx = name unless name.empty?
end
if idx.kind_of?(TkButton)
if idx.kind_of?(Tk::Button)
idx = idx[:text]
end
number(tk_send('index', idx.to_s))
@ -62,7 +68,13 @@ class Tk::BWidget::ButtonBox
def insert(idx, keys={}, &b)
win = window(tk_send('insert', tagid(idx), *hash_kv(keys)))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end

View file

@ -25,7 +25,13 @@ class Tk::BWidget::ComboBox
def get_listbox(&b)
win = window(tk_send_without_enc('getlistbox'))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end

View file

@ -103,7 +103,7 @@ class Tk::BWidget::Dialog
name = tagOrId[:name]
return index(name) unless name.empty?
end
if tagOrId.kind_of?(TkButton)
if tagOrId.kind_of?(Tk::Button)
return index(tagOrId[:text])
end
# index(tagOrId.to_s)
@ -112,19 +112,37 @@ class Tk::BWidget::Dialog
def add(keys={}, &b)
win = window(tk_send('add', *hash_kv(keys)))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end
def get_frame(&b)
win = window(tk_send('getframe'))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end
def get_buttonbox(&b)
win = window(@path + '.bbox')
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end

View file

@ -9,7 +9,7 @@ require 'tkextlib/bwidget.rb'
module Tk
module BWidget
class Entry < TkEntry
class Entry < Tk::Entry
end
end
end

View file

@ -9,7 +9,7 @@ require 'tkextlib/bwidget.rb'
module Tk
module BWidget
class Label < TkLabel
class Label < Tk::Label
end
end
end

View file

@ -11,7 +11,7 @@ require 'tkextlib/bwidget/entry'
module Tk
module BWidget
class LabelEntry < TkEntry
class LabelEntry < Tk::Entry
end
end
end

View file

@ -40,7 +40,13 @@ class Tk::BWidget::LabelFrame
end
def get_frame(&b)
win = window(tk_send_without_enc('getframe'))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end
end

View file

@ -211,14 +211,26 @@ class Tk::BWidget::ListBox::Item
include TkTreatTagFont
ListItem_TBL = TkCore::INTERP.create_table
ListItem_ID = ['bw:item'.freeze, '00000'.taint].freeze
TkCore::INTERP.init_ip_env{ ListItem_TBL.clear }
(ListItem_ID = ['bw:item'.freeze, '00000'.taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
TkCore::INTERP.init_ip_env{
ListItem_TBL.mutex.synchronize{ ListItem_TBL.clear }
}
def self.id2obj(lbox, id)
lpath = lbox.path
return id unless ListItem_TBL[lpath]
ListItem_TBL.mutex.synchronize{
if ListItem_TBL[lpath]
ListItem_TBL[lpath][id]? ListItem_TBL[lpath][id]: id
else
id
end
}
end
def initialize(lbox, *args)
@ -250,13 +262,17 @@ class Tk::BWidget::ListBox::Item
if keys.key?('itemname')
@path = @id = keys.delete('itemname')
else
ListItem_ID.mutex.synchronize{
@path = @id = ListItem_ID.join(TkCore::INTERP._ip_id_)
ListItem_ID[1].succ!
}
end
ListItem_TBL.mutex.synchronize{
ListItem_TBL[@id] = self
ListItem_TBL[@lpath] = {} unless ListItem_TBL[@lpath]
ListItem_TBL[@lpath][@id] = self
}
@listbox.insert(index, @id, keys)
end

View file

@ -41,37 +41,73 @@ class Tk::BWidget::MainFrame
def add_indicator(keys={}, &b)
win = window(tk_send('addindicator', *hash_kv(keys)))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end
def add_toolbar(&b)
win = window(tk_send('addtoolbar'))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end
def get_frame(&b)
win = window(tk_send('getframe'))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end
def get_indicator(idx, &b)
win = window(tk_send('getindicator', idx))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end
def get_menu(menu_id, &b)
win = window(tk_send('getmenu', menu_id))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end
def get_toolbar(idx, &b)
win = window(tk_send('gettoolbar', idx))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end

View file

@ -173,6 +173,9 @@ class Tk::BWidget::MessageDlg
end
def create
num_or_str(tk_call(self.class::TkCommandNames[0], @path, *hash_kv(@keys)))
# return the index of the pressed button, or nil if it is destroyed
ret = num_or_str(tk_call(self.class::TkCommandNames[0],
@path, *hash_kv(@keys)))
(ret < 0)? nil: ret
end
end

View file

@ -89,7 +89,13 @@ class Tk::BWidget::NoteBook
def add(page, &b)
win = window(tk_send('add', tagid(page)))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end
@ -105,7 +111,13 @@ class Tk::BWidget::NoteBook
def get_frame(page, &b)
win = window(tk_send('getframe', tagid(page)))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end
@ -115,7 +127,13 @@ class Tk::BWidget::NoteBook
def insert(index, page, keys={}, &b)
win = window(tk_send('insert', index, tagid(page), *hash_kv(keys)))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end

View file

@ -26,7 +26,13 @@ class Tk::BWidget::PagesManager
def add(page, &b)
win = window(tk_send('add', tagid(page)))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end
@ -42,7 +48,13 @@ class Tk::BWidget::PagesManager
def get_frame(page, &b)
win = window(tk_send('getframe', tagid(page)))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end

View file

@ -25,7 +25,13 @@ class Tk::BWidget::PanedWindow
def get_frame(idx, &b)
win = window(tk_send_without_enc('getframe', idx))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end
end

View file

@ -36,7 +36,13 @@ class Tk::BWidget::PanelFrame
def get_frame(&b)
win = window(tk_send_without_enc('getframe'))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end

View file

@ -51,4 +51,8 @@ class Tk::BWidget::ProgressDlg
def value= (val)
@keys['variable'].value = val
end
def create
window(tk_call(self.class::TkCommandNames[0], @path, *hash_kv(@keys)))
end
end

View file

@ -23,7 +23,13 @@ class Tk::BWidget::ScrollableFrame
def get_frame(&b)
win = window(tk_send_without_enc('getframe'))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end

View file

@ -21,7 +21,13 @@ class Tk::BWidget::ScrolledWindow
def get_frame(&b)
win = window(tk_send_without_enc('getframe'))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end

View file

@ -10,6 +10,11 @@ require 'tkextlib/bwidget/messagedlg'
module Tk
module BWidget
class SelectColor < Tk::BWidget::MessageDlg
class Dialog < Tk::BWidget::SelectColor
end
class Menubutton < Tk::Menubutton
end
MenuButton = Menubutton
end
end
end
@ -43,3 +48,26 @@ class Tk::BWidget::SelectColor
tk_call('SelectColor::setcolor', idx, color)
end
end
class Tk::BWidget::SelectColor::Dialog
def create_self(keys)
super(keys)
@keys['type'] = 'dialog'
end
def create
@keys['type'] = 'dialog' # 'dialog' type returns color
tk_call(Tk::BWidget::SelectColor::TkCommandNames[0],
@path, *hash_kv(@keys))
end
end
class Tk::BWidget::SelectColor::Menubutton
def create_self(keys)
keys = {} unless keys
keys = _symbolkey2str(keys)
keys['type'] = 'menubutton' # 'toolbar' type returns widget path
window(tk_call(Tk::BWidget::SelectColor::TkCommandNames[0],
@path, *hash_kv(keys)))
end
end

View file

@ -66,7 +66,7 @@ class Tk::BWidget::SelectFont::Dialog
end
def create
@keys['type'] = 'dialog'
@keys['type'] = 'dialog' # 'dialog' type returns font name
tk_call(Tk::BWidget::SelectFont::TkCommandNames[0], @path, *hash_kv(@keys))
end
end
@ -79,7 +79,8 @@ class Tk::BWidget::SelectFont::Toolbar
def create_self(keys)
keys = {} unless keys
keys = _symbolkey2str(keys)
keys['type'] = 'toolbar'
tk_call(Tk::BWidget::SelectFont::TkCommandNames[0], @path, *hash_kv(keys))
keys['type'] = 'toolbar' # 'toolbar' type returns widget path
window(tk_call(Tk::BWidget::SelectFont::TkCommandNames[0],
@path, *hash_kv(keys)))
end
end

View file

@ -10,7 +10,7 @@ require 'tkextlib/bwidget/entry'
module Tk
module BWidget
class SpinBox < TkEntry
class SpinBox < Tk::Entry
end
end
end

View file

@ -36,7 +36,13 @@ class Tk::BWidget::StatusBar
def get_frame(&b)
win = window(tk_send_without_enc('getframe'))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end

View file

@ -21,7 +21,13 @@ class Tk::BWidget::TitleFrame
def get_frame(&b)
win = window(tk_send_without_enc('getframe'))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end
end

View file

@ -263,14 +263,26 @@ class Tk::BWidget::Tree::Node
include TkTreatTagFont
TreeNode_TBL = TkCore::INTERP.create_table
TreeNode_ID = ['bw:node'.freeze, '00000'.taint].freeze
TkCore::INTERP.init_ip_env{ TreeNode_TBL.clear }
(TreeNode_ID = ['bw:node'.freeze, '00000'.taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
TkCore::INTERP.init_ip_env{
TreeNode_TBL.mutex.synchronize{ TreeNode_TBL.clear }
}
def self.id2obj(tree, id)
tpath = tree.path
return id unless TreeNode_TBL[tpath]
TreeNode_TBL.mutex.synchronize{
if TreeNode_TBL[tpath]
TreeNode_TBL[tpath][id]? TreeNode_TBL[tpath][id]: id
else
id
end
}
end
def initialize(tree, *args)
@ -311,13 +323,17 @@ class Tk::BWidget::Tree::Node
if keys.key?('nodename')
@path = @id = keys.delete('nodename')
else
TreeNode_ID.mutex.synchronize{
@path = @id = TreeNode_ID.join(TkCore::INTERP._ip_id_)
TreeNode_ID[1].succ!
}
end
TreeNode_TBL.mutex.synchronize{
TreeNode_TBL[@id] = self
TreeNode_TBL[@tpath] = {} unless TreeNode_TBL[@tpath]
TreeNode_TBL[@tpath][@id] = self
}
@tree.insert(index, parent, @id, keys)
end

View file

@ -43,7 +43,13 @@ module Tk::BWidget::Widget
def self.create(klass, path, rename=None, &b)
win = window(tk_call('Widget::create', klass, path, rename))
win.instance_eval(&b) if b
if b
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
win.instance_exec(self, &b)
else
win.instance_eval(&b)
end
end
win
end

View file

@ -40,16 +40,22 @@ module Tk
class ItclObject < TkObject
ITCL_CLASSNAME = ''.freeze
ITCL_OBJ_ID = ['itclobj'.freeze, '00000'.taint].freeze
(ITCL_OBJ_ID = ['itclobj'.freeze, '00000'.taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
ITCL_OBJ_TBL = {}.taint
def initialize(*args)
if (@klass = self.class::ITCL_CLASSNAME).empty?
fail RuntimeError, 'unknown itcl class (abstract class?)'
end
Tk::Itcl::ItclObject::ITCL_OBJ_ID.mutex.synchronize{
@id = Tk::Itcl::ItclObject::TCL_OBJ_ID.join(TkCore::INTERP._ip_id_)
@path = @id
Tk::Itcl::ItclObject::ITCL_OBJ_ID[1].succ!
}
@path = @id
end
def self.call_proc(name, *args)

View file

@ -145,9 +145,16 @@ module Tk
private :__config_cmd
ComponentID_TBL = TkCore::INTERP.create_table
Itk_Component_ID = ['itk:component'.freeze, '00000'.taint].freeze
TkCore::INTERP.init_ip_env{ ComponentID_TBL.clear }
(Itk_Component_ID = ['itk:component'.freeze, '00000'.taint]).instance_eval{
@mutex = Mutex.new
def mutex; @mutex; end
freeze
}
TkCore::INTERP.init_ip_env{
ComponentID_TBL.mutex.synchronize{ ComponentID_TBL.clear }
}
def self.id2obj(master, id)
if master.kind_of?(TkObject)
@ -155,8 +162,13 @@ module Tk
else
master = master.to_s
end
return id unless ComponentID_TBL.key?(master)
(ComponentID_TBL.key?(id))? ComponentID_TBL[master][id]: id
ComponentID_TBL.mutex.synchronize{
if ComponentID_TBL.key?(master)
(ComponentID_TBL[master].key?(id))? ComponentID_TBL[master][id]: id
else
id
end
}
end
def self.new(master, component=nil)
@ -171,10 +183,13 @@ module Tk
elsif component
component = component.to_s
else
Itk_Component_ID.mutex.synchronize{
component = Itk_Component_ID.join(TkCore::INTERP._ip_id_)
Itk_Component_ID[1].succ!
}
end
ComponentID_TBL.mutex.synchronize{
if ComponentID_TBL.key?(master)
if ComponentID_TBL[master].key?(component)
return ComponentID_TBL[master][component]
@ -182,6 +197,7 @@ module Tk
else
ComponentID_TBL[master] = {}
end
}
super(master, component)
end
@ -190,7 +206,9 @@ module Tk
@master = master
@component = component
ComponentID_TBL.mutex.synchronize{
ComponentID_TBL[@master][@component] = self
}
begin
@widget = window(tk_call(@master, 'component', @component))

View file

@ -45,6 +45,23 @@ class Tk::Iwidgets::Calendar
class ValidateArgs < TkUtil::CallbackSubst
KEY_TBL = [ [?d, ?s, :date], nil ]
PROC_TBL = [ [?s, TkComm.method(:string) ], nil ]
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf|
if inf.kind_of?(Array)
inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String)
end
inf
}
PROC_TBL.map!{|inf|
if inf.kind_of?(Array)
inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String)
end
inf
}
_setup_subst_table(KEY_TBL, PROC_TBL);
def self.ret_val(val)

Some files were not shown because too many files have changed in this diff Show more