(Slightly off topic.)<div><br></div><div>I am a language guy, so I love looking at other languages for cool features.  You&#39;re looking for a way to chain a bunch of method calls together, a la jQuery.  It turns out that Dart recently added a feature called method cascades that solve this problem:</div>
<div><br></div><div><div style="color:rgb(68,68,68);font-family:&#39;Open Sans&#39;;font-size:14px;line-height:19px;background-color:rgb(255,255,255)"><span style="font-family:&#39;Courier New&#39;,Courier,monospace">myTokenTable</span></div>
<div style="color:rgb(68,68,68);font-family:&#39;Open Sans&#39;;font-size:14px;line-height:19px;background-color:rgb(255,255,255)"><span style="font-family:&#39;Courier New&#39;,Courier,monospace">  ..add(&quot;aToken&quot;);</span></div>
<div style="color:rgb(68,68,68);font-family:&#39;Open Sans&#39;;font-size:14px;line-height:19px;background-color:rgb(255,255,255)"><span style="font-family:&#39;Courier New&#39;,Courier,monospace">  ..add(&quot;anotherToken&quot;);</span></div>
<div style="color:rgb(68,68,68);font-family:&#39;Open Sans&#39;;font-size:14px;line-height:19px;background-color:rgb(255,255,255)"><span style="font-family:&#39;Courier New&#39;,Courier,monospace">  ..add(&quot;theUmpteenthToken&quot;);</span></div>
<div style="color:rgb(68,68,68);font-family:&#39;Open Sans&#39;;font-size:14px;line-height:19px;background-color:rgb(255,255,255)"><span style="font-family:&#39;Courier New&#39;,Courier,monospace">  ..setTitle(&quot;foo&quot;);</span></div>
<div style="color:rgb(68,68,68);font-family:&#39;Open Sans&#39;;font-size:14px;line-height:19px;background-color:rgb(255,255,255)"><span style="font-family:&#39;Courier New&#39;,Courier,monospace">  ..setBackgroundColor(&quot;green&quot;);</span></div>
<div style="color:rgb(68,68,68);font-size:14px;line-height:19px;background-color:rgb(255,255,255)"><span style="background-color:transparent"><br></span></div><div style="background-color:rgb(255,255,255)"><span style="background-color:transparent;font-size:14px;line-height:19px"><font color="#444444"><a href="http://news.dartlang.org/2012/02/method-cascades-in-dart-posted-by-gilad.html">http://news.dartlang.org/2012/02/method-cascades-in-dart-posted-by-gilad.html</a></font></span></div>
<div style="background-color:rgb(255,255,255)"><span style="background-color:transparent;font-size:14px;line-height:19px"><font color="#444444"><br></font></span></div><div style="color:rgb(68,68,68);font-size:14px;line-height:19px;background-color:rgb(255,255,255)">
<span style="background-color:transparent">I&#39;m not encouraging you to switch to Dart; I just think it&#39;s interesting.</span></div><div style="color:rgb(68,68,68);font-size:14px;line-height:19px;background-color:rgb(255,255,255)">
<span style="background-color:transparent"><br></span></div><div style="color:rgb(68,68,68);font-size:14px;line-height:19px;background-color:rgb(255,255,255)"><span style="background-color:transparent">-jj</span></div><div style="color:rgb(68,68,68);font-size:14px;line-height:19px;background-color:rgb(255,255,255)">
<span style="background-color:transparent"><br></span></div><div style="color:rgb(68,68,68);font-size:14px;line-height:19px;background-color:rgb(255,255,255)"><span style="background-color:transparent">On Thu, Jun 14, 2012 at 9:53 PM, Ian Zimmerman </span><span dir="ltr" style="background-color:transparent">&lt;<a href="mailto:itz@buug.org" target="_blank">itz@buug.org</a>&gt;</span><span style="background-color:transparent"> wrote:</span></div>
<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
I am writing some code using the cairo drawing library, or rather the<br>
pycairo binding to it.  Unfortunately I sense a bit of API misdesign<br>
with the binding.  To draw into a context ctx which I obtained somewhat<br>
like this:<br>
<br>
import cairo as C<br>
<br>
ctx = C.Context(surface)<br>
<br>
I am supposed to write a series of calls like this:<br>
<br>
ctx.set_source_rgb(1.0, 1.0, 1.0)<br>
ctx.rectangle(0.0, 0.0, float(rw), float(rh))<br>
ctx.fill()<br>
ctx.scale(sx, sy)<br>
<br>
... and it piles up.  Each of these methods returns None, whilst it<br>
should conceivably return self, adding a lot of convenience:<br>
<br>
ctx.set_source_rgb(1.0, 1.0, 1.0).rectangle(0.0, 0.0, float(rw), float(rh)).fill()<br>
<br>
I would like to write a wrapper class around Context to enable this<br>
usage, but I don&#39;t know how to do that sanely.  Sure, I could do this:<br>
<br>
class ContextWrapper(object):<br>
<br>
      def __init__(self, surface):<br>
          self.ctx = C.Context(surface)<br>
<br>
      def fill(self):<br>
          self.ctx.fill()<br>
          return self<br>
<br>
      def scale(self, sx, sy):<br>
          self.ctx.scale(sx, sy)<br>
          return self<br>
<br>
          ...<br>
<br>
but then I have to wrap each method explicitly, or at least each method<br>
I use.  I don&#39;t consider that sane.<br>
<br>
Is there a trick I am missing, perhaps using __dict__ or __getattr__ by<br>
which I could wrap all the methods wholesale?<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Ian Zimmerman<br>
gpg public key: 1024D/C6FF61AD<br>
fingerprint: 66DC D68F 5C1B 4D71 2EE5  BD03 8A00 786C C6FF 61AD<br>
<a href="http://www.gravatar.com/avatar/c66875cda51109f76c6312f4d4743d1e.png" target="_blank">http://www.gravatar.com/avatar/c66875cda51109f76c6312f4d4743d1e.png</a><br>
Rule 420: All persons more than eight miles high to leave the court.<br>
_______________________________________________<br>
Baypiggies mailing list<br>
<a href="mailto:Baypiggies@python.org">Baypiggies@python.org</a><br>
To change your subscription options or unsubscribe:<br>
<a href="http://mail.python.org/mailman/listinfo/baypiggies" target="_blank">http://mail.python.org/mailman/listinfo/baypiggies</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>In this life we cannot do great things. We can only do small things with great love. -- Mother Teresa<br>
</div>