Re: [Pyobjc-dev] Three issues with PyObjC under Snow Leopard
Brought to you by:
ronaldoussoren
|
From: David E. <dav...@gm...> - 2009-10-06 15:42:21
|
Great, thanks! I very much appreciate your finding the bug in the
code, but I suspect your advice to make exceptions verbose will be
more useful in the long run. This app is actually more of a test for a
larger app that I care more about that also broke when I moved to Snow
Leopard (and that I'd happy to share once I get working again — it
manages BibTeX databases — but due to the size of the code I didn't
want to even hint that anyone else try debugging). So with the verbose
exceptions in hand I can have some hope of finding out what's wrong
with that one, too, assuming it isn't just the same thing.
I've copied the setup.py I was using below, in answer to your other
email requesting it — I had a partial plist copied from the text one
in my xcode project (was intending to copy of the plist entries
eventually until I got stuck), so perhaps something in there is
confusing py2app.
"""
Script for building LaTeX Unicodifier
D. Eppstein, October 2009
Usage:
python setup.py py2app
"""
from distutils.core import setup
import py2app
plist = {
'CFBundleDevelopmentRegion': 'English',
'CFBundleExecutable': 'LaTeX Unicodifier',
'CFBundleIconFile': 'LaTeX Unicodifier.icns',
}
setup(
app = ['Latex.py', 'LaTeX_Unicodifier.py'],
data_files = ['English.lproj', 'LaTeX Unicodifier.icns'],
options = { 'py2app': {'plist': plist} }
)
On Tue, Oct 6, 2009 at 6:04 AM, Ronald Oussoren <ron...@ma...> wrote:
>
> On 5 Oct, 2009, at 5:59, David Eppstein wrote:
>>
>> (2) I have some apps I wrote using pyobjc under Leopard that broke
>> when I moved to Snow Leopard. The simplest is the one in
>> http://www.ics.uci.edu/~eppstein/LaTeX_Unicodifier.dmg.gz (that's the
>> app bundle but because it's Python the source is inside, and is quite
>> short). I don't want to ask anyone to debug my code for me, but I'm at
>> a bit of a loss: when I run it (either the app as I built it for 10.5,
>> or the same xcode project recompiled for a 10.6 intel target) I get a
>> mysterious message "10/4/09 8:28:13 PM LaTeX Unicodifier[13914]
>> <type
>> 'exceptions.TypeError'>: Need 0 arguments, got 1" on the console and
>> it doesn't work: the UI appears, cmd-Q quits, but the actual app
>> that's supposed to be running the UI isn't there. I imagine that
>> somewhere there's a method that needs a signature and doesn't have
>> one, or something simple like that, but I can't seem to figure out how
>> to get xcode to show me who's raising the uncaught exception...
>
> There is an easy way to find the source of the exception: add
> 'objc.setVerbose(1)' to your 'main.py' file, just after the import of
> 'objc'. This will print exception tracebacks whenever exceptions cross the
> Python<->ObjC boundary.
>
> The problem is in the class Transformer, and in particular in the way you
> call the superclass initializer. Your code currently is:
>
> class Transformer (NSFormatter):
> def initWithSource_target_(self, source, target):
> self = NSFormatter.init(self)
> ...
>
> This is bad style, and furthermore doesn't work in 10.6 because
> 'NSFormatter.init' refers to the init method of the NSTransformer class
> (that is the classmethod '+init'). It happens to work in 10.5 because
> NSFormatter (or NSObject) doesn't have a +init method there.
>
> The right way to call a superclass method is using the super() function:
>
> class Transformer(NSFormatter):
>
> def initWithSource_target_(self,source,target):
> self = super(Transformer, self).init()
> if self is None:
> return None
>
> The call to super() isn't very pretty, but is the standard Python way of
> calling superclass methods in new-style classes. In Python 3.x the interface
> was cleaned up ("self = super().init()"), but until PyObjC supports Python
> 3.x we'll have to live with the current syntax.
>
> BTW. According to Apple the tests for 'self is None' is necesary, the
> superclass init might fail and return None.
>
> Ronald
>
>
|