[Pyobjc-dev] Nib loading [was: Altered classes]
Brought to you by:
ronaldoussoren
|
From: Steven D. M. <sd...@mi...> - 2001-05-12 01:53:21
|
[ Jon Harald also asked me directly about Nibs.
You might want to subscribe to the pyobjc-dev mailing list
at sourceforge, where we're discussion some of these problems.
The short answer is that pyobjc isn't quite ready for prime-time
AppKit apps yet -- there are a couple of important features that either
don't work correctly, or we haven't figured out how to get them to
work. We're also considering writing off this version as an experiment
(it's pretty ancient both in it's objc and it's python features) and
starting over with a better design. You're not going to get a useful
AppKit GUI app writting this path, but you're likely to learn quite
a bit about objective-C and Python internals and runtime if you
stick around. ]
Here is the **Jython** version of a program which sort-of-works:
It is able to load the nib file from the Temperature Converter
java tutorial or the Currency Converter objective-c tutorial.
( With a few less errors/warnings written to the terminal running
the Java app I believe. )
It loads and instatiates the window from the Nib file, and all
of the default behaviour, but none of the special behavior works.
(i.e. You can move the window around, enter text, tab to next
field, but clicking convert button for example, does nothing.)
----
from com.apple.cocoa.foundation import *
from com.apple.cocoa.application import *
MyApp = None
_pools = []
tpath = './TempConverter/build/TempConverter.app'
cpath = './CurrencyConverter/build/CurrencyConverter.app'
def xxx():
print NSBundle.allFrameworks()
def Pool():
global _pools
tmp = NSAutoreleasePool.push()
_pools.append(tmp)
return tmp
def App():
global MyApp
MyApp = NSApplication.sharedApplication()
return MyApp
def Bundle( path=cpath ):
return NSBundle.bundleWithPath( path )
xxx()
pool = Pool()
myapp = App()
bndl = Bundle()
nib = NSApplication.loadNibFromBundle( bndl, 'MainMenu', myapp )
if __name__ == '__main__' : myapp.run()
----
Note that the Java AppKit API has
NSApplication.loadNibFromBundle( bundle, name, owner )
The bundle is created with a path, and the Nib is inside that bundle.
In objective C, the equivalent methods are NSBundle additions, not
NSApplication methods. ( Java doesn't have categories -- I assume
that is one of the reasons for the change. Objective-C can load
additional methods for an already defined class, and AppKit adds
several methods to several existing Foundation classess. ):
+ loadNibFile:externalNameTable:withZone:
+ loadNibNamed:owner:
- loadNibFile:externalNameTable:withZone:
(That's NSBundle.loadNibFile_externalNameTable_withZone_() in Python.)
+loadNibNamed:owner: just expects a nib file name, not a full path.
It looks in the mainBundle, which for my python turns out to be
"/usr/local/bin" . So that one doesn't work.
For the others: I think I've tried both the class and instance methods.
Neither works -- I get a number back which I haven't been able to
interpret as any meaningful error code.
The class method takes a complete pathname -- the instance method,
I think, wants only a name and has a default search path.
I've been passing an empty dictionary. ( Maybe this has to be
filled for it to work -- I was hoping, as with the Jython code,
to get at least partial results without it.)
I've been getting the zone from the zone method of my NSApp instance.
I'm not absolutely positive I've tried all the possible likely
legal combinations.
BTW: A lot of the other docs on Nib loading are missing ("To Be
Determined" )
I'm not at all experienced in doing this from objective-C --
I think I ought to give it a try that way and make sure that
I can figure out the correct combination without the worry
of the python-objc bridge getting in the way. Then, translate
that working code to Python.
This is not "official" work (although, if it could be made to
work, I could more easily justify the time -- it's a chicken
and egg management problem! ;-) -- so it's fighting for my
limited spare time and intermittently hacking on it hasn't
made for sustained progress!
-- Steve Majewski
|