From: matz@... (Yukihiro Matsumoto) Date: 2000-07-13T13:25:53+09:00 Subject: [ruby-talk:03957] Re: Tk PhotoImage options Hi, In message "[ruby-talk:03956] Tk PhotoImage options" on 00/07/13, Andrew Hunt writes: | |Hi all, | |I'm trying to write a simple Ruby/Tk app that displays a GIF file |using TkPhotoImage. The GIF needs to be scaled down to a particular |size, as a "thumbnail." | |The Tk doc says TkPhotoImage->copy can take an option of 'shrink', 'subsample', |'to' and 'from' and yet *none* of these seem to work with Ruby/Tk. | |Given: | | new_img = TkPhotoImage.new('file'=> filename) | image_widget.copy(new_img, 'subsample' => "8 8") | |I get the error message: | | tk.rb:548: in '_invoke': unrecognized option "-subsample 8 8 ": | must be -from, -shrink, -subsample, -to, or -zoom | |I've tried "8,8", "8", nil, '', and a few other combos, but it just |doesn't seem to like it. With the following patch, image_widget.copy(new_img, 'subsample' => [8 8]) would work. --- /usr/lib/ruby/1.4/tk.rb Tue May 9 13:50:41 2000 +++ /tmp/tk.rb Thu Jul 13 13:20:08 2000 @@ -219,6 +219,17 @@ end private :_get_eval_string + def ruby2tcl(v) + if v.kind_of?(Hash) + v = hash_kv(v) + v.flatten! + v.collect{|e|ruby2tcl(e)} + else + _get_eval_string(v) + end + end + private :ruby2tcl + Tk_IDs = [0, 0] # [0]-cmdid, [1]-winid def _curr_cmd_id id = format("c%.4d", Tk_IDs[0]) @@ -526,7 +537,7 @@ def tk_call(*args) print args.join(" "), "\n" if $DEBUG - args.filter {|x|_get_eval_string(x)} + args.filter {|x|ruby2tcl(x)} args.compact! args.flatten! begin