[#3986] Re: Principle of least effort -- another Ruby virtue. — Andrew Hunt <andy@...>

> Principle of Least Effort.

14 messages 2000/07/14

[#4043] What are you using Ruby for? — Dave Thomas <Dave@...>

16 messages 2000/07/16

[#4139] Facilitating Ruby self-propagation with the rig-it autopolymorph application. — Conrad Schneiker <schneik@...>

Hi,

11 messages 2000/07/20

[ruby-talk:03957] Re: Tk PhotoImage options

From: matz@... (Yukihiro Matsumoto)
Date: 2000-07-13 04:25:53 UTC
List: ruby-talk #3957
Hi,

In message "[ruby-talk:03956] Tk PhotoImage options"
    on 00/07/13, Andrew Hunt <andy@toolshed.com> 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

In This Thread