<?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/2008/processing-playground</id>
    <title type="html"><![CDATA[Processing Playground]]></title>
    <updated>2008-06-10T14:02:58Z</updated>
    <published>2008-06-10T14:02:57Z</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/2008/06/10/processing-playground/feed" thr:count="2"  />
    <link rel="alternate" href="http://livingcode.org/2008/06/10/processing-playground" />
    <category scheme="http://livingcode.org" term="Python" />
    <summary type="html"><![CDATA[
There is a lot of interesting stuff happening in Javascript land these days, even to the point of other languages targetting the browser as a runtime, but running on top of Javascript.  You can run Scheme right in the browser, and by now everyone has probably heard of Objective-J (open-source coming soon), an Objective-C-like [...]]]></summary>
      <content type="html" xml:base="http://livingcode.org/2008/06/10/processing-playground"><![CDATA[<p><a href='http://livingcode.org/2008/processing-playground/kudzu-3/' rel='attachment wp-att-93' title='Kudzu 3'><img src='http://livingcode.org/wp-content/uploads/2008/06/kudzu3_forweb.png' alt='Kudzu 3' /></a></p>
<p>There is a lot of interesting stuff happening in Javascript land these days, even to the point of other languages targetting the browser as a runtime, but running on top of Javascript.  You can run <a href="http://www.bluishcoder.co.nz/jsscheme/">Scheme</a> right in the browser, and by now everyone has probably heard of Objective-J (open-source <a href="http://objective-j.org/">coming soon</a>), an Objective-C-like language used by 280 North to create their <a href="http://280slides.com/">280 Slides</a> web application, inspired by Apple&#8217;s Keynote.</p>
<p>Since my last post <a href="http://livingcode.org/2008/processing-critters">about Processing</a>, John Resig managed to port most of Processing to Javascript, so it is easier than ever to get started.  Now instead of having to download the Java-based runtime, you can create Processing animations in your browser, within the limitations that it only targets very recent, beta browsers (Firefox 3, Opera 9.5, WebKit nightlies, no version of IE) and that not all of Processing is supported (no 3D, for instance, and my example from the earlier post does not run).  Still, it is interesting and a lot of fun to play with.  My seven-year-old son is fascinated with computer programming and looking to move beyond <a href="http://scratch.mit.edu/">Scratch</a>, so as part of that I stuck all the basic examples from Mr. Resig&#8217;s site into one page, with a menu to select them, and a button to run them.  And I made them editable.  You can write entirely new code too, of course, but the examples can help for getting started.  I hope folks enjoy it.</p>
<p><a href="http://livingcode.org/project/processing/#sine_wave">Processing Playground</a></p>
<p>Of course, what my kids really want is a version of Scratch that we can extend to add some more features of our own.  Scratch has been open-sourced, so we could possibly extend it, but it is built on Squeak Smalltalk, and I&#8217;ve never been very good at Smalltalk.  Instead, I am porting it to Javascript.  It is still in the early stages, but I&#8217;m making steady progress in my hour or so I have to code each evening, and my kids are eager to use it, so they keep me motivated and focussed.</p>
]]></content>
        </entry>
    <entry>
    <id>http://livingcode.org/2006/back-to-the-drawing-board</id>
    <title type="html"><![CDATA[Back to the Drawing Board]]></title>
    <updated>2008-01-16T07:02:55Z</updated>
    <published>2006-11-14T06:59:01Z</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/2006/11/13/back-to-the-drawing-board/feed" thr:count="0"  />
    <link rel="alternate" href="http://livingcode.org/2006/11/13/back-to-the-drawing-board" />
    <category scheme="http://livingcode.org" term="Python" />
    <summary type="html"><![CDATA[Well, I&#8217;ve been promising this off and on here in my intermittent blog, but I&#8217;ve had the code up on Google code hosting for some time now, my kids have tested out the latest version, I&#8217;ve fixed some bugs introduced when PyObjC switched from distutils to setuptools. It is still pretty raw, unpolished, unoptimized, but [...]]]></summary>
      <content type="html" xml:base="http://livingcode.org/2006/11/13/back-to-the-drawing-board"><![CDATA[<p>Well, I&#8217;ve been promising this off and on here in my intermittent blog, but I&#8217;ve had the code up on Google code hosting for some time now, my kids have tested out the latest version, I&#8217;ve fixed some bugs introduced when PyObjC switched from distutils to setuptools. It is still pretty raw, unpolished, unoptimized, but I&#8217;m ready to let the world see it and let me know what they think.</p>
<p>Current features of Drawing Board:</p>
<ul>
<li>Freehand sketching: This is the main point of the software</li>
<li>Onion-skinning: See previous frame dimmed behind current frame</li>
<li>Create new frames: Either blank, or containing a copy of the current frame. Copied frames include the entire undo stack for the frame, so you can copy, and then undo a portion of the frame</li>
<li>Change colours and line sizes</li>
<li>Change the opacity of the window (this is a hack to allow you to trace images until I get image backgrounds implemented)</li>
<li>Scale and translate the frame</li>
<li>Remove current frame (not undo-able)</li>
<li>Export as SVG</li>
<li>Export frame as PNG or JPEG (PNG includes alpha for any area not drawn)</li>
</ul>
<p>There is basic file handling, which may be useful as example code for learning Cocoa programming using Python. I&#8217;m still working at adding drawing tools besides freehand drawing, and I have ideas for a lot of other things, but the main idea is to keep the program from getting in your way&#8211;to keep as close to possible as sketching with a pencil on paper, but to make the process of creating simple animations easier.</p>
<p>Two features that are pretty close, and are important to the goal of the project, are export as Flash and export as Quicktime. Those will be coming sooner, rather than later.</p>
<p>The project page is at <a href="http://livingcode.org/project/drawingboard">http://livingcode.org/project/drawingboard</a> and you can find links there to the binary download, the source repository, and the bug/feature tracker. I&#8217;ve also set up Google groups for the Living Code projects: <a href="http://groups.google.com/group/livingcode-users">http://groups.google.com/group/livingcode-users</a> and <a href="http://groups.google.com/group/livingcode-developer">http://groups.google.com/group/livingcode-developer</a> for ongoing discussions.</p>
<p>A few people have seen me demo this program at the Vancouver Python Workshop and at Bar Camp Vancouver and expressed an interest, so I hope it can be of use, both in learning to program OS X with Python, and for creating animations. Please let me know what you find useful and what could be improved!</p>
]]></content>
        </entry>
    <entry>
    <id>http://livingcode.org/2006/screencast-in-cocoa-python</id>
    <title type="html"><![CDATA[Screencast in Cocoa (Python)]]></title>
    <updated>2008-01-23T06:31:12Z</updated>
    <published>2006-03-11T03:58:06Z</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/2006/03/10/screencast-in-cocoa-python/feed" thr:count="0"  />
    <link rel="alternate" href="http://livingcode.org/2006/03/10/screencast-in-cocoa-python" />
    <category scheme="http://livingcode.org" term="Python" />
    <summary type="html"><![CDATA[I noticed that jwz is trying to take a screenshot in Cocoa and having trouble. I&#8217;m happy to see that he&#8217;s porting his awesome collection of screensavers to OS X, that&#8217;s great news. As for taking screen shots, I&#8217;m amazed it is as hard as it seems to be&#8211;heck even the new Nokia Series 60 [...]]]></summary>
      <content type="html" xml:base="http://livingcode.org/2006/03/10/screencast-in-cocoa-python"><![CDATA[<p>I noticed that jwz is trying to <a href="http://jwz.livejournal.com/608233.html">take a screenshot</a> in Cocoa and having trouble. I&#8217;m happy to see that he&#8217;s porting his awesome collection of screensavers to OS X, that&#8217;s great news. As for taking screen shots, I&#8217;m amazed it is as hard as it seems to be&#8211;heck even the new Nokia Series 60 give you the ability to take screeenshots from Python now. In any case, here is a method that works for me under PyObjC. It assumes it is part of a Cocoa object and that you&#8217;ve done a from <span class="code">AppKit import *</span> already. Since I can&#8217;t comment on jwz&#8217;s blog (whether it&#8217;s because I don&#8217;t use LiveJournal or because I do use Safari, I don&#8217;t know), I&#8217;ll post it here instead.</p>
<pre>def screenShot(self):
    rect = NSScreen.mainScreen().frame()
    image = NSImage.alloc().initWithSize_((rect.size.width, rect.size.height))
    window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
        rect,
        NSBorderlessWindowMask,
        NSBackingStoreNonretained,
        False)
    view = NSView.alloc().initWithFrame_(rect)
    window.setLevel_(NSScreenSaverWindowLevel + 100)
    window.setHasShadow_(False)
    window.setAlphaValue_(0.0)
    window.setContentView_(view)
    window.orderFront_(self)
    view.lockFocus()
    screenRep= NSBitmapImageRep.alloc().initWithFocusedViewRect_(rect)
    image.addRepresentation_(screenRep)
    view.unlockFocus()
    window.orderOut_(self)
    window.close()
    return image</pre>
<p>I cribbed this several months ago from some example Cocoa code, but forgot to make a note of where I got it. If anyone recognizes this pattern, please let me know so I can attribute it.</p>
<p>[Update 2006-03-10]</p>
<p>Nils Soffer pointed out:</p>
<blockquote>
<pre>A simpler solution:</pre>
<pre>
try:</pre>
<pre>    screenshot = 'screenshort.pdf'</pre>
<pre>    os.system('screencapture -i %s' % screenshot)</pre>
<pre>    image = NSImage.alloc().initWithContentsOfFile_(screenshot)</pre>
<pre>finally:</pre>
<pre>    os.remove(screenshot)</pre>
<p>:-)</p></blockquote>
<p>Which reminds me, you can also use the command-line <span class="code">screencapture -c</span> to go to the clipboard instead of a file.  This might be faster, but I haven&#8217;t tested it yet.  I still think there should be a Cocoa method to grab the underlying framebuffer of the screen. Besides the <span class="code">-c</span> flag to send the image to the clipboard there is also a <span class="code">-C</span> flag to capture the cursor as well.</p>
<p>[Update 2008-01-22]</p>
<p>Digging through old mail as I move this entry from my custom blog setup to Wordpress, I found where I got this code from originally. It&#8217;s from the Irate Scotsman&#8217;s <a href="http://mattgemmell.com/source">Screen Sharing </a>code.  Thanks, Matt!</p>
]]></content>
        </entry>
    <entry>
    <id>http://livingcode.org/2006/silent-blog</id>
    <title type="html"><![CDATA[Silent Blog]]></title>
    <updated>2008-01-23T06:33:11Z</updated>
    <published>2006-03-04T06:31:15Z</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/2006/03/03/silent-blog/feed" thr:count="0"  />
    <link rel="alternate" href="http://livingcode.org/2006/03/03/silent-blog" />
    <category scheme="http://livingcode.org" term="Python" />
    <summary type="html"><![CDATA[Yes, I&#8217;ve been quiet for awhile. No, I&#8217;m not going to apologize, and I wish more bloggers would stop apologizing when they take time off. One of the great things about Atom/RSS feeds is that I can keep up with blogs that are posted to infrequently, which includes some of my favorites. Don&#8217;t feel like [...]]]></summary>
      <content type="html" xml:base="http://livingcode.org/2006/03/03/silent-blog"><![CDATA[<p>Yes, I&#8217;ve been quiet for awhile. No, I&#8217;m not going to apologize, and I wish more bloggers would stop apologizing when they take time off. One of the great things about Atom/RSS feeds is that I can keep up with blogs that are posted to infrequently, which includes some of my favorites. Don&#8217;t feel like you need to post all the time&#8211;we&#8217;ve all got plenty of other things to read!</p>
<p>My quiet time is going to continue for a bit longer, but while I won&#8217;t apologize, I will at least explain. Here&#8217;s what I&#8217;m doing instead with the couple of hours I have between putting the kids to bed and going to bed myself.</p>
<ul>
<li>Writing the OS X version of the file uploader for The Conversation Network. At some point this will be made public, and the idea is to open source it. I&#8217;ll be sure to point that out when it happens. It&#8217;s been really great to have this opportunity to work with Doug Kaye and the rest of the gang from ITConversations, after being an admirer (and consumer) of their work for some time.</li>
<li>Attended the Northern Voice and Moose Camp conference, where I was fortunate enough to co-moderate a session on community and blogs with Nancy White</li>
<li>Writing my own weblog software. Blogger has a better interface than manilasites, but that&#8217;s not saying much. I&#8217;m also trying to port my old content from manilasites, plus my pre-blog-era work, plus my paper journal. All of this will be hosted at livingcode.org in the near future.</li>
<li>Writing more articles for IBM developerWorks, I hope to have more to say about that Real Soon Now</li>
<li>Generally organizing the livingcode site better, getting projects their own pages, putting code into SVN. Trying to use Sourceforge was a huge failure, their interface is just too crufty and they still don&#8217;t support Subversion. But Dreamhost (where livingcode.org is hosted) does support Subversion now, so I&#8217;m going to be moving all my public code over there.</li>
<li>I wrote a screensaver using PyObjC which I&#8217;m hoping to get included in their distribution as an example, but I need to do some refactoring first (in the time leftover from other projects). I want to write that up too, it was pretty interesting to work on.</li>
<li>I periodically take a stab at porting VPython to the Aqua environment. I have some ideas for this (some of them probably heretical to the VPython folks), but need time to work on them. Notice a pattern emerging?</li>
<li>Porting Apple&#8217;s Sketch demo application from ObjectiveC to PyObjC.</li>
<li>Several of these things are just precursors to DrawingBoard, my animation program for kids. I really, really want to be working on that, but need to get some of the smaller projects finished and out of my head so I can concentrate.</li>
<li>Exploring programming environments for my kids. My nine-year-old daughter and I will try competing in the PyWeek game challenge later this month.</li>
<li>I&#8217;m sure I&#8217;ve forgotten several significant things.</li>
</ul>
<p>More news as it happens.</p>
]]></content>
        </entry>
    <entry>
    <id>http://livingcode.org/2005/slides-up</id>
    <title type="html"><![CDATA[Slides up]]></title>
    <updated>2008-01-25T06:25:56Z</updated>
    <published>2005-02-11T06:13:12Z</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/2005/02/10/slides-up/feed" thr:count="0"  />
    <link rel="alternate" href="http://livingcode.org/2005/02/10/slides-up" />
    <category scheme="http://livingcode.org" term="Python" />
    <summary type="html"><![CDATA[After much delay, my slides are finally up from the VanPyZ talk last week.
Using Python and Cocoa on OS X 
Again I&#8217;m using Eric Meyer&#8217;s S5 tool for HTML slides, but it still ends up being a large download because it includes a completely unneccesary quicktime movie. My daughter and I have been playing with [...]]]></summary>
      <content type="html" xml:base="http://livingcode.org/2005/02/10/slides-up"><![CDATA[<p>After much delay, my slides are finally up from the VanPyZ talk last week.</p>
<p><a href="http://livingcode.org/slides/cocoa.html">Using Python and Cocoa on OS X </a></p>
<p>Again I&#8217;m using Eric Meyer&#8217;s S5 tool for HTML slides, but it still ends up being a large download because it includes a completely unneccesary quicktime movie. My daughter and I have been playing with iStopMotion and this was one of our first forays into claymation.</p>
<p>The reason it&#8217;s in the slideshow, is that movie making is now completely accessible to an eight-year-old, and I want to writing games and other programs equally accessible to her.</p>
<p>Still a ways to go&#8230;</p>
]]></content>
        </entry>
    <entry>
    <id>http://livingcode.org/2004/slides-and-code-posted</id>
    <title type="html"><![CDATA[Slides and code posted]]></title>
    <updated>2008-01-26T05:02:41Z</updated>
    <published>2004-12-19T04:30:23Z</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/12/18/slides-and-code-posted/feed" thr:count="0"  />
    <link rel="alternate" href="http://livingcode.org/2004/12/18/slides-and-code-posted" />
    <category scheme="http://livingcode.org" term="Python" />
    <summary type="html"><![CDATA[My talk at VanX last night was a success. Not many people showed (too close to Xmas), but the ones who did seemed to enjoy my presentation on Cocoa, Python, and Renaissance. Gerald was a great host, SchemaSoft provided a good (and convenient!) venue, Paul came to show support, and BlastRadius (my employer) sponsored the [...]]]></summary>
      <content type="html" xml:base="http://livingcode.org/2004/12/18/slides-and-code-posted"><![CDATA[<p>My talk at <a href="http://vanx.org/">VanX</a> last night was a success. Not many people showed (too close to Xmas), but the ones who did seemed to enjoy my presentation on Cocoa, Python, and Renaissance. Gerald was a great host, <a href="http://schemasoft.com/">SchemaSoft</a> provided a good (and convenient!) venue, <a href="http://prescod.net/">Paul</a> came to show support, and <a href="http://blastradius.com/">BlastRadius</a> (my employer) sponsored the snacks. After we went to Mira in Yaletown for beers and tech talk, had the whole place to ourselves, and a musician playing Flamenco guitar, then I walked across the bridge to home. A great end to a great evening.</p>
<p>I&#8217;ve posted my slides at <a href="http://livingcode.org/slides/renaissance.html">livingcode.org/slides/renaissance.html</a> using Eric Meyer&#8217;s neat S5 tool to put the whole slideshow into one HTML file.</p>
<p>I&#8217;ve also built a new .dmg containing all the source code and built, runnable examples (seven of them now), although they&#8217;re not all fully functional yet. More example gsmarkup to view, improved setup scripts, and they all have icons now. The file is <a href="http://sourceforge.net/project/showfiles.php?group_id=19654">examples 2004-12-17</a> on SourceForge.</p>
<p>I&#8217;ve been working hard to put this all together, which hasn&#8217;t left much time for posting, but I will have a lot more to say real soon now.</p>
]]></content>
        </entry>
    <entry>
    <id>http://livingcode.org/2004/52</id>
    <title type="html"><![CDATA[Small Nerd Example Chapter 2]]></title>
    <updated>2008-01-26T05:57:29Z</updated>
    <published>2004-11-06T05:32:58Z</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/05/52/feed" thr:count="0"  />
    <link rel="alternate" href="http://livingcode.org/2004/11/05/52" />
    <category scheme="http://livingcode.org" term="Python" />
    <summary type="html"><![CDATA[Aaron Hillegass&#8217; book, &#8220;Cocoa Programmig for Mac OS X&#8221; is a great way to learn Cocoa, Objective-C and Interface Builder, and I highly recommend you buy it to understand OS X programming (of course, you&#8217;ll be buying the new, improved Second Edition, and I&#8217;m working off the first edition here, so things may not completely [...]]]></summary>
      <content type="html" xml:base="http://livingcode.org/2004/11/05/52"><![CDATA[<p>Aaron Hillegass&#8217; book, &#8220;Cocoa Programmig for Mac OS X&#8221; is a great way to learn Cocoa, Objective-C and Interface Builder, and I highly recommend you buy it to understand OS X programming (of course, you&#8217;ll be buying the new, improved Second Edition, and I&#8217;m working off the first edition here, so things may not completely match up). In order to demonstrate how compact, yet readable, Renaissance + Python can be, I&#8217;m going to convert the example programs from this book. Aaron&#8217;s company is called Big Nerd Ranch, and I was trying to find something to show which postings were examples from the book, so readers can follow along, but without implying in any way that Aaron has approved of these conversions in any way, so I&#8217;m going to call them the Small Nerd Examples (The small nerd being me).</p>
<p>Note that while you are developing, it is inconvenient to have to build the project every time you touch a file, so you can use <span class="code">python setup.py py2app &#8211;alias</span> to build it once, then you can edit your files normally and the changes will be reflected when you run your application. Just remember to re-run this when you add a new file, and to re-run it without the alias flag when you&#8217;re building any version to be distributed.</p>
<p>Like the previous example, Hello World, this one contains four files. The setup.py file will look radically similar to the Hello World version. The program itself is simple: A window with two buttons, one which seeds the random number generator with the current time, and another which generates and displays a random number between 1 and 100 in a text field.</p>
<p><strong>MainMenu.gsmarkup </strong></p>
<pre class="code">&lt;?xml version="1.0"?&gt;</pre>
<pre class="code">&lt;!DOCTYPE gsmarkup&gt;</pre>
<pre class="code">&lt;gsmarkup&gt;</pre>
<pre class="code">    &lt;objects&gt;</pre>
<pre class="code">        &lt;menu type="main"&gt;</pre>
<pre class="code">            &lt;menu title="ch02" type="apple"&gt;</pre>
<pre class="code">                &lt;menuItem title="About ch02" action="orderFrontStandardAboutPanel:"/&gt;</pre>
<pre class="code">                &lt;menuSeparator/&gt;</pre>
<pre class="code">                &lt;menu title="Services" type="services"/&gt;</pre>
<pre class="code">                &lt;menuSeparator/&gt;</pre>
<pre class="code">                &lt;menuItem title="Hide ch02" action="hide:" key="h"/&gt;</pre>
<pre class="code">                &lt;menuItem title="Hide Others" action="hideOtherApplications:"/&gt;</pre>
<pre class="code">                &lt;menuItem title="Show All" action="unhideAllApplications:"/&gt;</pre>
<pre class="code">                &lt;menuSeparator/&gt;</pre>
<pre class="code">                &lt;menuItem title="Quit ch02" action="terminate:" key="q"/&gt;</pre>
<pre class="code">            &lt;/menu&gt;</pre>
<pre class="code">            &lt;menu title="Window" type="windows"&gt;</pre>
<pre class="code">                &lt;menuItem title="Minimize Window"</pre>
<pre class="code">                    action="performMiniaturize:" key="m"/&gt;</pre>
<pre class="code">                &lt;menuSeparator/&gt;</pre>
<pre class="code">                &lt;menuItem title="Bring All to Front"</pre>
<pre class="code">                    action="arrangeInFront:"/&gt;</pre>
<pre class="code">            &lt;/menu&gt;</pre>
<pre class="code">            &lt;/menu&gt;</pre>
<pre class="code">                &lt;menu title="Help" type="help"&gt;</pre>
<pre class="code">                &lt;menuItem title="ch02 Help" keys="?"/&gt;</pre>
<pre class="code">        &lt;/menu&gt;</pre>
<pre class="code">    &lt;/objects&gt;</pre>
<pre class="code">&lt;/gsmarkup&gt;</pre>
<p><strong>MainWindow.gsmarkup</strong></p>
<pre class="code">&lt;?xml version="1.0"?&gt;</pre>
<pre class="code">&lt;!DOCTYPE gsmarkup&gt;</pre>
<pre class="code">&lt;gsmarkup&gt;</pre>
<pre class="code">    &lt;objects&gt;</pre>
<pre class="code">        &lt;window delegate="#NSOwner" resizable="no"&gt;</pre>
<pre class="code">            &lt;vbox&gt;</pre>
<pre class="code">                &lt;button target="#NSOwner" action="seed"</pre>
<pre class="code">                    title="Seed random number generator with time"/&gt;</pre>
<pre class="code">                &lt;button target="#NSOwner" action="generate"</pre>
<pre class="code">                    title="Generate random number"/&gt;</pre>
<pre class="code">                &lt;textField editable="no" id="text" align="center"/&gt;</pre>
<pre class="code">            &lt;/vbox&gt;</pre>
<pre class="code">        &lt;/window&gt;</pre>
<pre class="code">    &lt;/objects&gt;</pre>
<pre class="code">    &lt;connectors&gt;</pre>
<pre class="code">        &lt;outlet source="#NSOwner" target="text" key="outputNum"/&gt;</pre>
<pre class="code">    &lt;/connectors&gt;</pre>
<pre class="code">&lt;/gsmarkup&gt;</pre>
<p><strong>ch02.py </strong></p>
<pre class="code">'''</pre>
<pre class="code">Hillegass Example, Ch. 02</pre>
<pre class="code">'''</pre>
<pre class="code">from Foundation import *</pre>
<pre class="code">from AppKit import *</pre>
<pre class="code">from Renaissance import *</pre>
<pre class="code">import random</pre>
<pre class="code">class AppDelegate(NSObject):</pre>
<pre class="code">    outputNum = None</pre>
<pre class="code"></pre>
<pre class="code">    def windowWillClose_(self, notification):</pre>
<pre class="code">        NSApp().terminate_(self)</pre>
<pre class="code"></pre>
<pre class="code">    def quit_(self, notification):</pre>
<pre class="code">        NSApp().terminate_(self)</pre>
<pre class="code"></pre>
<pre class="code">    def close_(self, notification):</pre>
<pre class="code">        NSApp().terminate_(self)</pre>
<pre class="code"></pre>
<pre class="code">    def applicationDidFinishLaunching_(self, notification):</pre>
<pre class="code">        NSBundle.loadGSMarkupNamed_owner_('MainWindow', self)</pre>
<pre class="code"></pre>
<pre class="code">    def seed(self):</pre>
<pre class="code">        random.seed()</pre>
<pre class="code"></pre>
<pre class="code">    def generate(self):</pre>
<pre class="code">        self.outputNum.setStringValue_(str(random.randint(1,100)))</pre>
<pre class="code"></pre>
<pre class="code">def main():</pre>
<pre class="code">    app = NSApplication.sharedApplication()</pre>
<pre class="code">    delegate = AppDelegate.alloc().init()</pre>
<pre class="code">    app.setDelegate_(delegate)</pre>
<pre class="code">    NSBundle.loadGSMarkupNamed_owner_('MainMenu', delegate)</pre>
<pre class="code">    NSApp().run()</pre>
<pre class="code">if __name__ == '__main__': main()</pre>
<p><strong>setup.py </strong></p>
<pre class="code">'''</pre>
<pre class="code">Run with:</pre>
<pre class="code">% python setup.py py2app</pre>
<pre class="code">or</pre>
<pre class="code">% python setup.py py2app --alias # while developing</pre>
<pre class="code">'''</pre>
<pre class="code">from distutils.core import setup</pre>
<pre class="code">import py2app</pre>
<pre class="code">setup(</pre>
<pre class="code">    data_files = ['MainMenu.gsmarkup', 'MainWindow.gsmarkup'],</pre>
<pre class="code">    app = ['ch02.py'],</pre>
<pre class="code">)</pre>
<p>OK, this time out we&#8217;ve got about 52 lines of XML markup and 44 lines of Python. Of course, the program doesn&#8217;t really do much more than Hello World, but we&#8217;re getting somewhere. If anyone has questions about the code, or want more explanatory text around the Renaissance markup, please let me know in the comments or by email.</p>
]]></content>
        </entry>
  </feed>
