<?xml version="1.0" encoding="UTF-8"?><feed
  xmlns="http://www.w3.org/2005/Atom"
  xmlns:thr="http://purl.org/syndication/thread/1.0"
  xml:lang="en"
  >
  <id>http://livingcode.org/feed/atom</id>
  <updated>2009-11-13T19:33:25Z</updated>
  <title type="text">Living Code</title>
  <subtitle type="text">Programming for the Fun of It</subtitle>
  <link rel="self" type="application/atom+xml" href="http://livingcode.org/feed" />
  <link rel="alternate" href="http://livingcode.org" />
  <rights type="text">Copyright 2009</rights>
  <generator uri="http://wordpress.org/" version="2.8.6">WordPress</generator>
      <entry>
    <id>http://livingcode.org/2004/oblique-strategies</id>
    <title type="html"><![CDATA[Oblique Strategies]]></title>
    <updated>2008-01-26T05:13:58Z</updated>
    <published>2004-11-25T05:02:43Z</published>
    <author>
      <name>Dethe</name>
      <email>delza@livingcode.org</email>
<uri>http://livingcode.org/</uri>    </author>
    <link rel="replies" type="application/atom+xml" href="http://livingcode.org/2004/11/24/oblique-strategies/feed" thr:count="0"  />
    <link rel="alternate" href="http://livingcode.org/2004/11/24/oblique-strategies" />
    <category scheme="http://livingcode.org" term="Python" />
    <summary type="html"><![CDATA[Today&#8217;s Example is a simple, but full application. Our setup file is getting more complicated as we give the app a custom icon and a name which isn&#8217;t taken from the main python file. We&#8217;re finally using the menus for more than just default behaviors. We&#8217;re loading in resources at runtime. We&#8217;re adding a custom [...]]]></summary>
      <content type="html" xml:base="http://livingcode.org/2004/11/24/oblique-strategies"><![CDATA[<p>Today&#8217;s Example is a simple, but full application. Our setup file is getting more complicated as we give the app a custom icon and a name which isn&#8217;t taken from the main python file. We&#8217;re finally using the menus for more than just default behaviors. We&#8217;re loading in resources at runtime. We&#8217;re adding a custom About box. And we&#8217;re taking advantage of Python standard libraries from within a Cocoa program. One icon file + 224 lines of python, XML, and HTML.</p>
<p>Some years ago Brian Eno and Peter Schmidt created a deck of cards for brainstorming your way through artistic blocks. Each card had one idea, and they were called Oblique Strategies. The Whole Earth Review published a list of some of the strategies, the decks went through several editions, and there were quite a number of programs written to simulate drawing a card from the deck. The <a href="http://www.rtqe.net/ObliqueStrategies/">Oblique Strategies Web Site</a> has more details. You can buy the deck from <a href="http://www.enoshop.co.uk/">Brian Eno&#8217;s site</a>. And a group called curvedspace created a nice<a href="http://www.curvedspace.org/software/oblique.html"> OS X version</a> which you can download for free from their site.</p>
<p>The curvedspace app is so nice, in fact, that we&#8217;re going to slavishly imitate it. There are only a couple of problems with it. First, you can&#8217;t add your own quotes and sayings to the mix. Second, it&#8217;s free, but not open source, so you can&#8217;t patch it to allow you to add your own quotes. Tonight&#8217;s example will build a version identical to the curvedspace tool, but which allows you to choose from among several quote files, not just the Oblique Strategies. A future exercise will be to allow the user to customize it with new quotes from within the running application.</p>
<p>Since there&#8217;s quite a bit more code, and by reader request, this example is contained on a downloadable .dmg file. The file contains both the finished, runnable application, and all the source code. I&#8217;ll just be describing highlights of what&#8217;s different from earlier examples. You can download it all <a href="http://prdownloads.sourceforge.net/livingcode/ObliqueStrategies.dmg?download">here</a>.</p>
<p>What&#8217;s new? First of all, the <span class="code">setup.py</span> defines a plist resource inline to map some of the application features. This gives the application a name (&#8221;Oblique Strategies&#8221; rather than picking up &#8220;oblique&#8221; from the python file, and sets up some info for the About box. The setup call is a little more complex too, including English.lproj (which holds our icon) and Credits.html (which is the content of our About box), and passing in the plist we defined.</p>
<p>In the <span class="code">MainMenu.gsmarkup</span> we have added a bunch of menu items to the File menu, to allow the user to pick a quotation file. What&#8217;s interesting is that we&#8217;ve implemented &#8216;About Oblique Strategies&#8217; and Edit-&gt;Copy, but those menu items didn&#8217;t have to change.</p>
<p>In <span class="code">oblique.py</span>, the main script, we implement a subclass of NSWindow called TexturedWindow. This is to work around a limitation of the current version of Renaissance, which doesn&#8217;t support so-called Metal windows (because GNUstep doesn&#8217;t have them). Nicola has fixed this in CVS, so it will be in the next release, but in the meantime it is a simple class (4 lines of code) and we use the <span class="code">instanceOf</span> attribute of <span class="code">&lt;window /&gt;</span> to call our subclass in the <span class="code">MainWindow.gsmarkup</span>.</p>
<p>Our AppDelegate is similar to earlier examples, but has grown a couple of methods. The <span class="code">change()</span> method is called by our one button to select another quotation at random from the selected file (or a random file if you like). The <span class="code">chooseFile_(</span>) method checks to see which menu item called it, and based on the menu item, selects the file for future calls to <span class="code">change()</span>. There is one support function, <span class="code">getQuote(filename)</span> which uses Python standard file manipulation and the random module to pick a quote (much less verbose than doing this from Objective-C).</p>
<p>All that&#8217;s left are the quote files. These are simple text files with short quotations, one to a line. If a quote requires newlines, they can be embedded with &#8216;<span class="code">\n</span>&#8216;. The included files have quotes from Martin Fowler&#8217;s book &#8220;Refactoring,&#8221; the book &#8220;The Pragmatic Programmer,&#8221; the Magic 8-Ball, Jenny Holzer&#8217;s Truisms, and more. Enjoy!</p>
]]></content>
        </entry>
  </feed>
