[Pyobjc-dev] Re: Fwd: NSString.drawAtPoint_withAttributes_()
Brought to you by:
ronaldoussoren
From: Just v. R. <ju...@le...> - 2003-09-12 20:10:06
|
Dinu Gherman wrote: > in order to use print some text on an NSView I found out I need to do > first this to have access to the drawAtPoint_withAttributes_() which > is defined in some NSStringAddition category or so of AppKit: > > from Foundation import NSString > from AppKit import * > > First question is: how to do this without importing *? "import AppKit" should suffice. In fact, as long as AppKit has been imported _somewhere_ in your app before you call this, the category should be loaded. This should be pretty much automatic, as you can't draw without AppKit being around to begin with. > Then I get some string like this (not sure if a Python string would > magically do as well): > > s = NSString.stringWith...(...) > > but when calling > > s.drawAtPoint_withAttributes_((x, y), {...}) > > I get this error: > > AttributeError: 'objc.pyobjc_unicode' object has no attribute > 'drawAtPoint_withAttributes_' > > Has anybody tried writing a string that way to a view before? Is > this a bug? I'm on PyObjC 1.0b1. Not a bug, a feature. NStrings are presented to Python as a subclass of "unicode", the pyobjc_unicode class. You can do what you want in two ways: 1) Access the method through the class: NSString.drawAtPoint_withAttributes_(s, (x, y), {...}) 2) Use the pyobjc_unicode.nsstring() method: s.nsstring().drawAtPoint_withAttributes_((x, y), {...}) Just |