Commits

Ronald Oussoren committed 9e8e215

- Updated CurrencyConverter, Todo and TableModel to use bundlebuilder and
NibClassBuilder.
- Remove some print statements in Todo
- Removed Lib/objc/builder.py because it is no longer used

Comments (0)

Files changed (22)

+2002-11-25 Ronald Oussoren <oussoren@cistron.nl>
+	* Examples/{TableModel, CurrencyConverter, Todo}:
+	  - Use NibClassBuilder module
+	  - Use bundlebuilder module
+	* Lib/objc/builder.py: Remove, no longer used
+
 2002-11-22 Ronald Oussoren <oussoren@cistron.nl>
 	* Examples/TableModel2/main.m: Set PYTHONPATH in the environment of
 	  the child

pyobjc/Examples/CurrencyConverter/CurrencyConverter.py

 import sys
 from Foundation import NSObject
-from AppKit import NSApplicationMain
+from AppKit import NSApplicationMain, NibClassBuilder
 from objc import *
-from nibwrapper import ConverterBase, ConverterControllerBase
 
-class Converter (ConverterBase):
+NibClassBuilder.extractClasses('MainMenu.nib')
+
+class Converter (NibClassBuilder.AutoBaseClass):
 	def convertAmount(self, amt, rate):
 		return amt*rate
 		
-class ConverterController (ConverterControllerBase):
+class ConverterController (NibClassBuilder.AutoBaseClass):
 
 	# First define the IB Outlets, the 'ivar' calls below define new
 	# instance variables in the objective-C class (e.g. visible

pyobjc/Examples/CurrencyConverter/buildapp.py

+# These modules are otherwise completely standalone, they don't need any
+# Mac- or PyObjC-specific stuff.
+#
+
+from bundlebuilder import buildapp 
+    
+buildapp(
+    mainprogram = "CurrencyConverter.py",
+    resources = ["English.lproj" ],
+    nibname = "MainMenu",
+)   
+

pyobjc/Examples/CurrencyConverter/nibwrapper.py

-# THIS FILE IS GENERATED. DO NOT EDIT!!!
-# Interface classes for using NIB files
-
-from objc import IBOutlet
-from Foundation import NSObject
-
-class ConverterBase (NSObject):
-	"Base class for class 'Converter'"
-	pass
-
-class ConverterControllerBase (NSObject):
-	"Base class for class 'ConverterController'"
-	converter = IBOutlet("converter")
-	totalField = IBOutlet("totalField")
-	rateField = IBOutlet("rateField")
-	dollarField = IBOutlet("dollarField")
-
-	def convert_(self, sender): pass
-
-

pyobjc/Examples/CurrencyConverter/setup-app.py

-#!/usr/bin/env pythonw
-"""
-Python script for building the applet.
-"""
-
-import objc.builder
-
-objc.builder.build_applet(
-	app_name= 'CurrencyConverterPY',
-	main_py = 'CurrencyConverter.py',
-	extra_files = ['English.lproj/MainMenu.nib'],
-	extra_src = ['nibwrapper.py'] )
-# NOTE: We'd like to use just 'English.lproj', but buildtools.py gets 
-# confused by that....

pyobjc/Examples/TableModel/setup-app.py

-#!/usr/bin/env pythonw
-"""
-Python script for building the applet.
-"""
-
-import objc.builder
-
-objc.builder.build_applet(
-	app_name= 'TableModelPY',
-	main_py = 'TableModel.py',
-	raw = 1,
-	extra_files = ['English.lproj'],
-	extra_src = ['nibwrapper.py'])

pyobjc/Examples/Todo/CalendarMatrix.py

 from Foundation import *
 from AppKit import *
 from objc import IBOutlet
-from nibwrapper import CalendarMatrixBase
+from AppKit.NibClassBuilder import AutoBaseClass
 
 gNumDaysInMonth = ( 0, 31, 28, 31, 30, 21, 30, 31, 31, 30, 31, 30, 31 )
 
 def isLeap(year):
 	return (((year % 4) == 0 and ((year % 100) != 0)) or (year % 400) == 0)
 
-class CalendarMatrix (CalendarMatrixBase):
+class CalendarMatrix (AutoBaseClass):
 	__slots__ = ('_selectedDay', '_startOffset')
 
 	def initWithFrame_(self, frameRect):

pyobjc/Examples/Todo/InfoWindowController.py

 from AppKit import *
 from objc import selector, IBOutlet
 from ToDoDocument import *
-from nibwrapper import InfoWindowControllerBase
+from AppKit.NibClassBuilder import AutoBaseClass
 
 NOTIFY_TAG     = 0
 RESCHEDULE_TAG = 1
 
 _sharedInfoWindowController = None
 
-class InfoWindowController (InfoWindowControllerBase):
+class InfoWindowController (AutoBaseClass):
 
 	__slots__ = ('_inspectingDocument', )
 
 
 
 	def controlTextDidEndEditing_(self, notification):
-		print "controlTextDidEndEditing:", notification.description()
+		#print "controlTextDidEndEditing:", notification.description()
 		dueSecs = 0
 		theItem = self._inspectingDocument.selectedItem()
 		if theItem is None:
 			 	self.infoNotifyHour.intValue(),
 				self.infoNotifyMinute.intValue(),
 				self.infoNotifyAMPM.cellAtRow_column_(1,0).state())
-			print "New dueSecs: ", dueSecs
+			#print "New dueSecs: ", dueSecs
 			#theItem.setSecsUntilDue_(dueSecs)
 		elif notification.object() is self.infoNotifyOtherHours:
 			if self.infoNotifySwitchMatrix.selectedRow() == NotifyLengthOther:

pyobjc/Examples/Todo/SelectionNotifyMatrix.py

 from AppKit import *
 from Foundation import *
-from nibwrapper import SelectionNotifyMatrixBase
+from AppKit.NibClassBuilder import AutoBaseClass
 
 RowSelectedNotification = "RowSelectedNotification"
 
-class  SelectionNotifyMatrix (SelectionNotifyMatrixBase):
+class  SelectionNotifyMatrix (AutoBaseClass):
 	def mouseDown_(self, theEvent):
 		super(SelectionNotifyMatrix, self).mouseDown_(theEvent)
 
 		row = self.selectedRow()
-		print "mouseDown_", theEvent, row
+		#print "mouseDown_", theEvent, row
 		if row != -1:
 			NSNotificationCenter.defaultCenter(
 				).postNotificationName_object_userInfo_(

pyobjc/Examples/Todo/ToDoCell.py

 	def updateImage(self):
 
 		if self._triState == NOT_DONE:
-			print "NO IMAGE"
+			#print "NO IMAGE"
 			self.setImage_(None)
 		elif self._triState == DONE:
-			print "DONE IMAGE"
+			#print "DONE IMAGE"
 			self.setImage_(self._doneImage)
 		elif self._triState == DEFERRED:
-			print "DEFERRED IMAGE"
+			#print "DEFERRED IMAGE"
 			self.setImage_(self._deferredImage)
 
 		self.controlView().updateCell_(self)
 	
 	def startTrackingAt_inView_(self, startPoint, controlView):
-		print "startTracking:", startPoint, controlView
+		#print "startTracking:", startPoint, controlView
 		return 1
 	startTrackingAt_inView_ = selector(
 		startTrackingAt_inView_, signature="c@:{NSPoint=ff}@")
 
 	def stopTracking_at_inView_mouseIsUp_(self, lastPoint, stopPoint, controlView, flag):
-		print "stopTracking:", lastPoint, stopPoint, controlView, flag, self.triState()
+		#print "stopTracking:", lastPoint, stopPoint, controlView, flag, self.triState()
 		if flag:
 			self.setTriState_(self.triState() + 1)
 	stopTracking_at_inView_mouseIsUp_ = selector(
 		signature="v@:{NSPoint=ff}{NSPoint=ff}@c")
 
 	def setTimeDue_(self, newTime):
-		if newTime:
-			print "setTimeDue", newTime.description()
-		else:
-			print "setTimeDue None" 
+		#if newTime:
+			#print "setTimeDue", newTime.description()
+		#else:
+			#print "setTimeDue None" 
 
 		if self._timeDue:
 			self._timeDue.autorelease()

pyobjc/Examples/Todo/ToDoDocument.py

 from ToDoCell import *
 from ToDoItem import *
 from SelectionNotifyMatrix import *
-from nibwrapper import ToDoDocumentBase
+from AppKit.NibClassBuilder import AutoBaseClass
 
 ToDoItemChangedNotification = "ToDoItemChangedNotification"
 
-class  ToDoDocument (ToDoDocumentBase):
+class  ToDoDocument (AutoBaseClass):
 
 	__slots__ = ('_dataFromFile', '_activeDays', '_currentItems', '_selectedItem', '_selectedItemEdited')
 
 		row = notification.object().selectedRow()
 
 		if row == -1:
-			print 'No rowSelected?'
+			#print 'No rowSelected?'
 			return 
 
 		self._selectedItem = self._currentItems.objectAtIndex_(row)
 						if elapsed > 0:
 							self.setTimerForItem_(anItem)
 						else:
-							print "Past due"
+							#print "Past due"
 							NSBeep()
 							NSRunAlertPanel("To Do", "%s on %s is past due!"%(
 									anItem.itemName(),
 				thisItem = self._currentItems.objectAtIndex_(i)
 			else:
 				thisItem = None
-			print ">>> object %d is %s %s"%(i, thisItem, isinstance(thisItem, ToDoItem))
+			#print ">>> object %d is %s %s"%(i, thisItem, isinstance(thisItem, ToDoItem))
 
 			if isinstance(thisItem, ToDoItem):
 				if thisItem.secsUntilDue():
 		if self._activeDays:
 			self.setCurrentItems_(self._activeDays.objectForKey_(date))
 		else:
-			print "calenderMatrix:didChangeToDate: -> no _activeDays"
+			#print "calenderMatrix:didChangeToDate: -> no _activeDays"
+                        pass
+
 		self.dayLabel.setStringValue_(
 			date.descriptionWithCalendarFormat_timeZone_locale_(
 			"To Do on %a %B %d %Y", NSTimeZone.defaultTimeZone(),
 			anItem.setTimer_(None)
 
 	def itemTimerFired_(self, timer):
-		print "Timer fired for ", timer
+		#print "Timer fired for ", timer
 		anItem = timer.userInfo()
 		dueDate = anItem.day().addTimeInterval_(anItem.secsUntilDue())
 

pyobjc/Examples/Todo/TodoAppDelegate.py

 from Foundation import NSObject
 from InfoWindowController import InfoWindowController
-from nibwrapper import ToDoAppDelegateBase
+from AppKit.NibClassBuilder import AutoBaseClass
 
-class ToDoAppDelegate (ToDoAppDelegateBase):
+class ToDoAppDelegate (AutoBaseClass):
 	def showInfo_(self, sender):
 		InfoWindowController.sharedInfoWindowController().showWindow_(sender)

pyobjc/Examples/Todo/buildapp.py

+# These modules are otherwise completely standalone, they don't need any
+# Mac- or PyObjC-specific stuff.
+#
+import os
+
+from bundlebuilder import buildapp 
+from plistlib import Plist 
+    
+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') ]
+
+buildapp(
+    name = "ToDo", 
+    mainprogram = "main.py",
+    resources = ["English.lproj" ] + images + icons + src,
+    nibname = "MainMenu",
+    plist = Plist.fromFile('Info.plist'),
+)   

pyobjc/Examples/Todo/buildpyapp.sh

-#!/bin/sh
-set -x
-PP=/Library/Frameworks/Python.framework/Versions/Current
-pythonw ${PP}/Mac/scripts/BuildApplet.py -r -o TodoPY --extra English.lproj/MainMenu.nib main.py
-
-CpMac -r English.lproj TodoPY.app/Contents/Resources
-cp *.py TodoPY.app/Contents/Resources
-cp Images/*.tiff TodoPY.app/Contents/Resources
-
-cp Images/LeftArrow.tiff  TodoPY.app/Contents/Resources/DoneMark.tiff
-cp Images/RightArrow.tiff  TodoPY.app/Contents/Resources/DeferredMark.tiff
-cp Images/*.tiff TodoPY.app/Contents/Resources
-cp Icons/*.icns TodoPY.app/Contents/Resources
-cp Info.plist TodoPY.app/Contents

pyobjc/Examples/Todo/main.py

 import sys
 import os
-path = [ os.path.split(sys.argv[0])[0] ]
-print path
-path.extend(sys.path)
-sys.path = path
 import objc
 from AppKit import *
+from AppKit.NibClassBuilder import extractClasses
+
+extractClasses('MainMenu')
+extractClasses('ToDoDocument')
+extractClasses('ToDoInfoWindow')
 
 # Import all submodules,  to make sure all 
 # classes are known to the runtime
 import ToDoItem
 import TodoAppDelegate
 
-print objc.lookUpClass('ToDoDocument')
-
 NSApplicationMain(sys.argv)

pyobjc/Examples/Todo/nibwrapper.py

-# THIS FILE IS GENERATED. DO NOT EDIT!!!
-# Interface classes for using NIB files
-
-from objc import IBOutlet
-from Foundation import NSObject
-from AppKit import NSDocument, NSMatrix, NSWindowController
-
-class ToDoAppDelegateBase (NSObject):
-	"Base class for class 'ToDoAppDelegate'"
-	def showInfo_(self, sender): pass
-
-
-class ToDoDocumentBase (NSDocument):
-	"Base class for class 'ToDoDocument'"
-	calendar = IBOutlet("calendar")
-	itemList = IBOutlet("itemList")
-	dayLabel = IBOutlet("dayLabel")
-	statusList = IBOutlet("statusList")
-
-	def itemStatusClicked_(self, sender): pass
-
-
-class InfoWindowControllerBase (NSWindowController):
-	"Base class for class 'InfoWindowController'"
-	infoWindowViews = IBOutlet("infoWindowViews")
-	infoItem = IBOutlet("infoItem")
-	reschedView = IBOutlet("reschedView")
-	infoNotifyMinute = IBOutlet("infoNotifyMinute")
-	infoPopUp = IBOutlet("infoPopUp")
-	infoNotifyOtherHours = IBOutlet("infoNotifyOtherHours")
-	notesView = IBOutlet("notesView")
-	dummyView = IBOutlet("dummyView")
-	infoNotifyHour = IBOutlet("infoNotifyHour")
-	infoDate = IBOutlet("infoDate")
-	notifyView = IBOutlet("notifyView")
-	infoSchedMatrix = IBOutlet("infoSchedMatrix")
-	infoSchedDate = IBOutlet("infoSchedDate")
-	infoSchedComplete = IBOutlet("infoSchedComplete")
-	infoNotifyAMPM = IBOutlet("infoNotifyAMPM")
-	infoNotifySwitchMatrix = IBOutlet("infoNotifySwitchMatrix")
-	infoNotes = IBOutlet("infoNotes")
-
-	def swapInfoWindowView_(self, sender): pass
-
-	def switchClicked_(self, sender): pass
-
-
-class CalendarMatrixBase (NSMatrix):
-	"Base class for class 'CalendarMatrix'"
-	monthName = IBOutlet("monthName")
-	lastMonthButton = IBOutlet("lastMonthButton")
-	nextMonthButton = IBOutlet("nextMonthButton")
-
-	def choseDay_(self, sender): pass
-
-	def monthChanged_(self, sender): pass
-
-
-class SelectionNotifyMatrixBase (NSMatrix):
-	"Base class for class 'SelectionNotifyMatrix'"
-	pass
-

pyobjc/Examples/Todo/setup-app.py

-#!/usr/bin/env pythonw
-"""
-Python script for building the applet.
-"""
-
-import objc.builder
-import os
-
-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') ]
-
-objc.builder.build_applet(
-	app_name= 'ToDo',
-	main_py = 'main.py',
-	extra_src = [ fn for fn in os.listdir('.') if fn.endswith('.py') and fn not in ('main.py', 'setup-app.py') ],
-	info_plist = 'Info.plist',
-	raw=False,
-	extra_files = ['English.lproj' ] + images + icons 
-)

pyobjc/Examples/iClass/datasource.py

 from Foundation import NSObject, NSBundle
-from AppKit import NSOutlineViewDataSource, NSTableDataSource
+from AppKit import NSOutlineViewDataSource, NSTableDataSource, NibClassBuilder
+from AppKit.NibClassBuilder import AutoBaseClass
 from objc import selector, getClassList, objc_object, IBOutlet
-from nibwrapper import  ClassesDataSourceBase
 
 WRAPPED={}
 class Wrapper (NSObject):
 			framework = framework[:-len('.framework')]
 	return framework
 
-class ClassesDataSource (ClassesDataSourceBase, NSOutlineViewDataSource, NSTableDataSource):
+class ClassesDataSource (AutoBaseClass, NSOutlineViewDataSource, NSTableDataSource):
 	__slots__ = ('_classList', '_classTree', '_methodInfo')
 
 	def clearClassInfo(self):

pyobjc/Examples/iClass/main.py

 """
 """
-from AppKit import NSApplicationMain
+from AppKit import NSApplicationMain, NibClassBuilder
 from Foundation import NSBundle
 import sys
 import os
 
-print sys.path	
+NibClassBuilder.extractClasses('MainMenu.nib')
+
 import datasource
 
-print datasource.ClassesDataSource
-
-print "Starting NSApplicationMain"
 NSApplicationMain(sys.argv)
-print "done"

pyobjc/Examples/iClass/nibwrapper.py

-# THIS FILE IS GENERATED. DO NOT EDIT!!!
-# Interface classes for using NIB files
-
-from objc import IBOutlet
-from Foundation import NSObject
-
-class ClassesDataSourceBase (NSObject):
-	"Base class for class 'ClassesDataSource'"
-	classLabel = IBOutlet("classLabel")
-	classTable = IBOutlet("classTable")
-	searchBox = IBOutlet("searchBox")
-	frameworkLabel = IBOutlet("frameworkLabel")
-	methodTable = IBOutlet("methodTable")
-	window = IBOutlet("window")
-
-	def selectClass_(self, sender): pass
-
-	def searchClass_(self, sender): pass
-
-

pyobjc/Examples/iClass/setup-app.py

-#!/usr/bin/env pythonw
-"""
-Python script for building the applet.
-"""
-
-import objc.builder
-
-objc.builder.build_applet(
-	app_name= 'iClass',
-	main_py = 'main.py',
-	raw = True,
-	extra_src = ['datasource.py', 'nibwrapper.py'],
-	extra_files = ['English.lproj'])

pyobjc/Lib/objc/builder.py

-"""
-Utility module that helps with building a module.
-
-Usage:
-    import objc.builder
-
-    objc.builder.build_applet('myapp', 'main.py', ['mod1.py' ... ],
-        [ 'English.lproj', ...])
-
-TODO: 
-* the same module should contain function for replacing/enhancing the 
-  Info.plist in the generated application.
-* Add compiled version of the extra sources, instead of the sources themselves
-* Add interface to use the python-starter trick as used by the Interface Builder
-  project.
-"""
-
-import buildtools
-import shutil
-import os
-
-try:
-    getattr(__builtins__, 'True')
-except AttributeError:
-    True=1
-    False=0
-
-def build_applet(app_name,
-        main_py, 
-        extra_src = [], 
-        extra_files = [], 
-        raw=False, 
-        resource_file=None,
-        info_plist=None):
-    """
-    Build an applet. 
-    """
-
-    def dirname(path):
-        r = os.path.split(path)[0]
-        if not r:
-            return '.'
-        else:
-            return r
-
-    # Basic argument checks
-    assert isinstance(app_name, str)
-    assert os.path.exists(dirname(app_name))
-    assert isinstance(main_py, str)
-    assert os.path.exists(main_py)
-    assert isinstance(extra_src, (list, tuple))
-    assert reduce(lambda x, y: x and y, 
-        [ os.path.exists(x) for x in extra_src ], True)
-    assert isinstance(extra_files, list) or isinstance(extra_files, tuple)
-    assert reduce(lambda x, y: x and y, 
-        [ os.path.exists(x) for x in extra_files ], True)
-    assert isinstance(raw, int)
-    assert (resource_file is None) or (
-        isinstance(resource_file, str) and 
-        os.path.exists(resource_file))
-    
-    assert (info_plist is None) or isinstance(info_plist, str)
-
-    template  = buildtools.findtemplate()
-    
-    others = extra_src[:]
-    others.extend(extra_files)
-
-    # remove the output if it already exists
-    if os.path.exists(app_name + '.app'):
-        shutil.rmtree(app_name + '.app')
-
-    buildtools.process(template, main_py, app_name, 1,
-        rsrcname = resource_file, others = others,
-        raw = raw, progress = None)
-
-    if info_plist:
-        shutil.copyfile(info_plist,
-            os.path.join(app_name + '.app', 
-                'Contents', 'Info.plist'))
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.