Ronald Oussoren avatar Ronald Oussoren committed 8133c32

Make sure examples also work with Python 2.2

Comments (0)

Files changed (11)

pyobjc/Doc/coding-style.html

 <li>Add appropriate ReST style fields to the top of the document as comments:<pre>
 # Author: David Goodger
 # Contact: goodger@users.sourceforge.net
-# Revision: $Revision: 1.1 $
-# Date: $Date: 2003/04/06 17:59:37 $
+# Revision: $Revision: 1.2 $
+# Date: $Date: 2003/04/06 18:33:52 $
 # Copyright: This module has been placed in the public domain.
 </pre>
 </li>

pyobjc/Examples/Todo/CalendarMatrix.py

 from Foundation import *
 from AppKit import *
-from objc import IBOutlet
+from objc import IBOutlet, YES, NO
 from PyObjCTools.NibClassBuilder import AutoBaseClass
 
 gNumDaysInMonth = ( 0, 31, 28, 31, 30, 21, 30, 31, 31, 30, 31, 30, 31 )
                 if val:
                     val.setTag_(count)
                 count += 1
-        #cell.release() # is this needed?
 
         self._selectedDay = NSCalendarDate.dateWithYear_month_day_hour_minute_second_timeZone_(
                 now.yearOfCommonEra(), 
                 0, 
                 0, 
                 0, 
-                NSTimeZone.localTimeZone()) #.retain()
+                NSTimeZone.localTimeZone())
         return self
 
 
 
             if i < self._startOffset or i >= (daysInMonth + self._startOffset):
                 # blank out unused cells in the matrix
-                cell.setBordered_(False)
-                cell.setEnabled_(False)
+                cell.setBordered_(NO)
+                cell.setEnabled_(NO)
                 cell.setTitle_("")
-                cell.setCellAttribute_to_(NSCellHighlighted, False)
+                cell.setCellAttribute_to_(NSCellHighlighted, NO)
             else:
                 # Fill in valid days in the matrix
-                cell.setBordered_(True)
-                cell.setEnabled_(True)
+                cell.setBordered_(YES)
+                cell.setEnabled_(YES)
                 cell.setFont_(NSFont.systemFontOfSize_(12))
                 cell.setTitle_(str(dayLabel))
                 dayLabel += 1
-                cell.setCellAttribute_to_(NSCellHighlighted, False)
+                cell.setCellAttribute_to_(NSCellHighlighted, NO)
 
         self.selectCellWithTag_(selDate.dayOfMonth() + self._startOffset - 1)
         self.highlightTodayIfVisible()
             aCell = self.cellWithTag_(
                 now.dayOfMonth() + self._startOffset - 1)
             aCell.setHighlightsBy_(NSMomentaryChangeButton)
-            aCell.setCellAttribute_to_(NSCellHighlighted, True)
+            aCell.setCellAttribute_to_(NSCellHighlighted, YES)
 
     def awakeFromNib(self):
         self.setTarget_(self)
         self.setAction_('choseDay:')
-        self.setAutosizesCells_(True)
+        self.setAutosizesCells_(YES)
         self.refreshCalendar()
         self.choseDay_(self)
 

pyobjc/Examples/Todo/InfoWindowController.py

 from AppKit import *
-from objc import selector, IBOutlet
+from objc import selector, IBOutlet, NO
 from ToDoDocument import *
 from PyObjCTools.NibClassBuilder import AutoBaseClass
 
     def windowDidLoad(self):
     	NSWindowController.windowDidLoad(self) 
 
-    	#self.dump_outlets()
-
+        # XXX: The calls to retain may not be necessary.
     	self.notifyView.retain()
     	self.notifyView.removeFromSuperview()
 
 
 
     def __del__(self): # dealloc
-    	#self.notifyView.release()
-    	#self.reschedView.release()
-    	#self.notesView.release()
     	
     	NSNotificationCenter.defaultCenter().removeObserver_(self)
 
 
     for i in range(rows):
     	cell = matrix.cellAtRow_column_(i, 0)
-    	if cell: cell.setState_(False)
+    	if cell: cell.setState_(NO)

pyobjc/Examples/Todo/ToDoCell.py

     	self.setAlignment_(NSRightTextAlignment)
 
     	self._doneImage = NSImage.imageNamed_("DoneMark")
-    	#if self._doneImage:
-    	#	self._doneImage.retain()
     	self._deferredImage = NSImage.imageNamed_("DeferredMark")
-    	#if self._deferredImage:
-    	#	self._deferredImage.retain()
     	return self
 
     def setTriState_(self, newState):
     	signature="v@:{NSPoint=ff}{NSPoint=ff}@c")
 
     def setTimeDue_(self, newTime):
-    	#if newTime:
-    		#print "setTimeDue", newTime.description()
-    	#else:
-    		#print "setTimeDue None" 
-
-    	#if self._timeDue:
-    	#	self._timeDue.autorelease()
     	if newTime:
     		self._timeDue = newTime
-    		#newTime.retain()
     		self.setTitle_(self._timeDue.descriptionWithCalendarFormat_timeZone_locale_("%I:%M %p", NSTimeZone.localTimeZone(), None))
     	else:
     		self._timeDue = None

pyobjc/Examples/Todo/ToDoDocument.py

 from AppKit import *
 from Foundation import *
-from objc import IBOutlet
+from objc import IBOutlet, NO
 from ToDoCell import *
 from ToDoItem import *
 from SelectionNotifyMatrix import *
 
     def __del__(self): # dealloc in Objective-C code
 
-    	#if self._activeDays:
-    	#	self._activeDays.release()
-    	#if self._currentItems:
-    	#	self._currentItems.release()
-
     	NSNotificationCenter.defaultCenter().removeObserver_(self)
 
     def selectedItem(self):
     		aCell.setTarget_(self)
     		aCell.setAction_('itemStatusClicked:')
     		self.statusList.putCell_atRow_column_(aCell, index, 0)
-    		#aCell.release()
     	
     	if self._dataFromFile:
     		self.loadDocWithData_(self._dataFromFile)
-    		#self._dataFromFile.release()
     		self._dataFromFile = None
     	else:
     		self.loadDocWithData_(None)
     			NSTimeZone.defaultTimeZone(), 
     			None))
 
-    def initDataModelWithDictionary_(self, dict):
-    	#if self._activeDays:
-    	#	self._activeDays.autorelease()
-
-    	if dict:
-    		self._activeDays = dict # .retain()
+    def initDataModelWithDictionary_(self, aDict):
+    	if aDict:
+    		self._activeDays = aDict
     	else:
     		self._activeDays = NSMutableDictionary.alloc().init()
 
     	self.setCurrentItems_(self._activeDays.objectForKey_(date))
 
     def setCurrentItems_(self, newItems):
-    	#if self._currentItems:
-    	#	self._currentItems.autorelease()
-
     	if newItems:
     		self._currentItems = newItems.mutableCopy()
     	else:
     	elif newName != "":
     		newItem = ToDoItem.alloc().initWithName_andDate_(newName, self.calendar.selectedDay())
     		self._currentItems.replaceObjectAtIndex_withObject_(row, newItem)
-    		#newItem.release()
 
     	self._selectedItem = self._currentItems.objectAtIndex_(row)
 
     	if selfcalendar:
     		self.loadDocWithData_(data)
     	else:
-    		self._dataFromFile = data #.retain()
+    		self._dataFromFile = data
 
     	return 1
 
     				self,
     				'itemTimerFired:',
     				anItem,
-    				False)
+    				NO)
     		anItem.setTimer_(aTimer)
     	else:
     		anItem.setTimer_(None)

pyobjc/Examples/Todo/ToDoItem.py

     	self._timer = None
 
     	if not aName:
-    		#self.release()
     		return None
 
     	self.setItemName_(aName)
     	return self
 
     def __del__(self): # dealloc
-    	#if self._itemName: self._itemName.release()
-    	#if self._day: self._day.release()
-    	#if self._notes: self._notes.release()
     	if self._notes: 
     		self._timer.invalidate()
-    		#self._timer.release()
 
     def setDay_(self, newDay):
-    	self._day = newDay #.retain()
+    	self._day = newDay
 
     def day(self):
     	return self._day
     def setTimer_(self, newTimer):
     	if self._timer:
     		self._timer.invalidate()
-    		#self._timer.autorelease()
 
     	if newTimer:
-    		self._timer = newTimer #.retain()
+    		self._timer = newTimer
     	else:
     		self._timer = None
 

pyobjc/Examples/Todo/buildapp.py

 import os
 
 from bundlebuilder import buildapp 
-from plistlib import Plist 
+from plistlib import Plist, Dict
     
 images = [ os.path.join('Images', fn) for fn in os.listdir('Images') if fn.lower().endswith('.tiff') ]
 icons = [ os.path.join('Icons', fn) for fn in os.listdir('Icons') if fn.lower().endswith('.icns') ]
 src = [ fn for fn in os.listdir('.') if fn.endswith('.py') and fn not in ('main.py', 'setup-app.py') ]
 
+infoPlist = Plist(
+    NSHelpFile='',
+    CFBundleShortVersionString='To Do v1', 
+    CFBundleSignature='????',
+    CFBundleInfoDictionaryVersion='6.0',
+    CFBundleIconFile='ToDoApp.icns',
+    NSMainNibFile='MainMenu',
+    CFBundleGetInfoString='To Do v1',
+    CFBundleIdentifier='com.apple.ToDo', 
+    CFBundleDocumentTypes=[
+        Dict(
+            CFBundleTypeName='To Do list', 
+            CFBundleTypeRole='Editor',
+            NSDocumentClass='ToDoDocument',
+            CFBundleTypeIconFile='ToDoDoc.icns',
+            CFBundleTypeExtensions=['ToDo'],
+            CFBundleTypeOSTypes=['ToDo'],
+        ),
+    ],
+    CFBundleDevelopmentRegion='English',
+    CFBundleExecutable='python',
+    CFBundleName='To Do',
+    CFBundlePackageType='APPL',
+    NSPrincipalClass='NSApplication',
+    CFBundleVersion='0.1')
+
 buildapp(
     name = "ToDo", 
     mainprogram = "main.py",
     resources = ["English.lproj" ] + images + icons + src,
     nibname = "MainMenu",
-    plist = Plist.fromFile('Info.plist'),
+    #plist = Plist.fromFile('Info.plist'),
+    plist = infoPlist
 )   

pyobjc/Examples/using-nscoder.py

 print 4
 archiver.encodeObject_(MyObject.alloc().init())
 print 5
-result = data.writeToFile_atomically_("archive.bin", True)
+result = data.writeToFile_atomically_("archive.bin", objc.YES)
 print 6
 
 del archiver

pyobjc/Install.html

 applications.</p>
 <h2><a name="project-templates">Project Templates</a></h2>
 <p>The <code><span>Project</span> <span>Templates</span></code> directory contains project templates for
-project builder.  Currently, there is one project builder template;  a
-Cocoa-Python Application project template.   When installed, this adds
-a project to Project Builder's project menu that allows new Cocoa
-applications implemented entirely in Python to be created from within
-Project Builder (in the same fashion as any other project).</p>
-<p>To install, simply copy the project template into the Project Builder
-project templates directory (or create a symlink).</p>
+project builder.  These have to be copied to
+<code><span>/Developer/ProjectBuilder</span> <span>Extras/Project</span> <span>Templates/Application</span></code> before
+they are useable from Project Builder.</p>
+<p>There are three templates available:</p>
+<ul>
+<li>Cocoa-Python Application<p>A project created from this template is designed to implement standalone,
+pure-Python, applications that are compatible with Apple's build of Python as
+well as all other builds of python that support PyObjC.</p>
+<p>When building the 'install' target, the resulting application wrapper will
+included the PyObjC module and can be launched on any stock OS X 10.2 system
+without requiring PyObjC to be preinstalled.</p>
+</li>
+<li>Cocoa-Python-ObjC Application<p>A project created from this template includes an embedded framework project
+into which all compiled (Objective-C) code can be placed.  Upon launch, 
+the application automatically dynamically loads the embedded framework 
+containing the compiled code.</p>
+<p>Each Framework's Resources directory is automatically added to sys.path.</p>
+</li>
+<li>Cocoa-Python Document-based Application<p>This template works like the Cocoa-Python Application template in that it
+is compatible with the Apple build of Python.   It creates an application 
+that uses Cocoa's Multiple Document Architecture in the same fashion as the
+default Cocoa Document-based Application supplied with Project Builder.</p>
+</li>
+</ul>
 <p>More information on project templates can be found in the Project
 Builder documentation and/or release notes.</p>
 </body>

pyobjc/Install.txt

 
 * Cocoa-Python Document-based Application
 
-  This template works like the `Cocoa-Python Application`_ template in that it
+  This template works like the Cocoa-Python Application template in that it
   is compatible with the Apple build of Python.   It creates an application 
   that uses Cocoa's Multiple Document Architecture in the same fashion as the
   default Cocoa Document-based Application supplied with Project Builder. 

pyobjc/ReadMe.html

 </head>
 <body>
 <h2>Welcome to PyObjC</h2>
-<!-- :authors: Ronald Oussoren, Bill Bumgarner -->
 <p>The PyObjC package provides the glue needed to interface the Python interpreter with the Objective-C language. At its core is the <code><span>objc</span></code> module makes 
 Objective-C objects and classes available as first-class Python citizens, it is 
 not only possible to use Objective-C objects but you can also subclass 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.