From 3ca633b890706c4f5892a179389b8389b5022dc0 Mon Sep 17 00:00:00 2001 From: nagai Date: Mon, 23 May 2011 22:37:44 +0000 Subject: * ext/tk/lib/tk.rb: fail to start Tk.mainloop (exit immediately) on some environment (reported on [ruby-talk:381444]). * ext/tk/lib/tk/canvas.rb: support creating a canvas item object from an item ID number. * ext/tk/lib/tk/image.rb: import documents which are pull-requested. [Ruby 1.9 - Feature #4595] * ext/tk/lib/tk/extconf.rb: search directories for 64bit library (e.g. /usr/lib64), add some new configure options (see README.tcltklib), and bug fix. * ext/tk/lib/tk/README.tcltklib: modify docs for some new configure options. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31717 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/lib/tk.rb | 38 ++++++++++++-- ext/tk/lib/tk/canvas.rb | 25 ++++++++++ ext/tk/lib/tk/image.rb | 128 ++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 183 insertions(+), 8 deletions(-) (limited to 'ext/tk/lib') diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index 0fd8cfdb20..574ebf328b 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -1248,6 +1248,9 @@ module TkCore raise e end + interp.mainloop_abort_on_exception = true + Thread.current.instance_variable_set("@interp", interp) + status = [nil] def status.value self[0] @@ -1283,19 +1286,23 @@ proc __startup_rbtk_mainloop__ {args} { } set __initial_state_of_rubytk__ 1 trace add variable __initial_state_of_rubytk__ unset __startup_rbtk_mainloop__ + +# complete initializing +ruby {TkCore::INTERP_THREAD[:interp] = TkCore::INTERP_THREAD.instance_variable_get('@interp')} EOS begin begin #TclTkLib.mainloop_abort_on_exception = false #Thread.current[:status].value = TclTkLib.mainloop(true) - interp.mainloop_abort_on_exception = true - Thread.current[:interp] = interp + #interp.mainloop_abort_on_exception = true + #Thread.current[:interp] = interp Thread.current[:status].value = interp.mainloop(true) rescue SystemExit=>e Thread.current[:status].value = e rescue Exception=>e Thread.current[:status].value = e + p e if $DEBUG retry if interp.has_mainwindow? ensure INTERP_MUTEX.synchronize{ INTERP_ROOT_CHECK.broadcast } @@ -1312,12 +1319,20 @@ EOS end } + # check a Tcl/Tk interpreter is initialized until INTERP_THREAD[:interp] - Thread.pass + # Thread.pass + INTERP_THREAD.run end + # INTERP_THREAD.run raise INTERP_THREAD[:interp] if INTERP_THREAD[:interp].kind_of? Exception + # check an eventloop is running + while INTERP_THREAD.alive? && TclTkLib.mainloop_thread?.nil? + INTERP_THREAD.run + end + INTERP = INTERP_THREAD[:interp] INTERP_THREAD_STATUS = INTERP_THREAD[:status] @@ -1328,6 +1343,9 @@ EOS INTERP_THREAD.kill end } + + # (for safety's sake) force the eventloop to run + INTERP_THREAD.run end def INTERP.__getip @@ -1857,6 +1875,11 @@ EOS begin TclTkLib.set_eventloop_window_mode(true) + + # force run the eventloop + TkCore::INTERP._eval_without_enc('update') + TkCore::INTERP._eval_without_enc('catch {set __initial_state_of_rubytk__}') + INTERP_THREAD.run if check_root INTERP_MUTEX.synchronize{ INTERP_ROOT_CHECK.wait(INTERP_MUTEX) @@ -1867,8 +1890,15 @@ EOS end } else - INTERP_THREAD.value + # INTERP_THREAD.value + begin + INTERP_THREAD.value + rescue Exception => e + raise e + end end + rescue Exception => e + raise e ensure TclTkLib.set_eventloop_window_mode(false) end diff --git a/ext/tk/lib/tk/canvas.rb b/ext/tk/lib/tk/canvas.rb index f0cb755bd7..7d3d71675c 100644 --- a/ext/tk/lib/tk/canvas.rb +++ b/ext/tk/lib/tk/canvas.rb @@ -85,6 +85,7 @@ class Tk::Canvas 200, :width => 300) + # + # === Create an image from a file + # + # image = TkPhotoImage.new(:file: => 'my_image.gif') + # + # == Options + # Photos support the following options: + # * :data + # Specifies the contents of the image as a string. + # * :format + # Specifies the name of the file format for the data. + # * :file + # Gives the name of a file that is to be read to supply data for the image. + # * :gamma + # Specifies that the colors allocated for displaying this image in a window + # should be corrected for a non-linear display with the specified gamma + # exponent value. + # * height + # Specifies the height of the image, in pixels. This option is useful + # primarily in situations where the user wishes to build up the contents of + # the image piece by piece. A value of zero (the default) allows the image + # to expand or shrink vertically to fit the data stored in it. + # * palette + # Specifies the resolution of the color cube to be allocated for displaying + # this image. + # * width + # Specifies the width of the image, in pixels. This option is useful + # primarily in situations where the user wishes to build up the contents of + # the image piece by piece. A value of zero (the default) allows the image + # to expand or shrink horizontally to fit the data stored in it. def initialize(*args) @type = 'photo' super(*args) end + # Blank the image; that is, set the entire image to have no data, so it will + # be displayed as transparent, and the background of whatever window it is + # displayed in will show through. def blank tk_send_without_enc('blank') self @@ -164,6 +207,10 @@ class TkPhotoImageimage was created: + # puts image.cget :file def cget(option) unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__ cget_strict(option) @@ -182,6 +229,51 @@ class TkPhotoImageoverlay is set, + # the old contents of the destination image are visible, as if the source + # image were printed on a piece of transparent film and placed over the + # top of the destination. When a compositing rule of set is set, + # the old contents of the destination image are discarded and the source + # image is used as-is. The default compositing rule is overlay. def copy(src, *opts) if opts.size == 0 tk_send('copy', src) @@ -201,11 +293,35 @@ class TkPhotoImagestate is true, and makes + # that pixel opaque otherwise. + def set_transparency(x, y, state) + tk_send('transparency', 'set', x, y, state) self end -- cgit v1.2.3