Re: [Pyobjc-dev] problem saving as rtfd
Brought to you by:
ronaldoussoren
From: chris <por...@ya...> - 2003-05-12 09:06:44
|
Now I am getting this on the console and a complete app crash: *** -[NSFileWrapper writeToFile:atomically:]: selector not recognized Traceback (most recent call last): File "/Users/c/SecretText/build/SecretText.app/Contents/Resources/__main__.py", line 20, in ? sys.exit(AppKit.NSApplicationMain(sys.argv)) ValueError: NSInvalidArgumentException - *** -[NSFileWrapper writeToFile:atomically:]: selector not recognized Stepping through the code in the terminal the NSFileWrapper comes back fine but it looks like it has "writeToFile_atomically_updateFilenames_" rather than "writeToFile_atomically_" hence the collapse. This is the current code: else: length = len(self.text.string()) store = self.text.textStorage() cyphertext = store.RTFDFileWrapperFromRange_documentAttributes_((0,length),None) #output the cyphertext to a file return cyphertext Chris --- Marcel Weiher <ma...@me...> wrote: > > > plaintext = "" > > cyphertext = NSData.alloc() > > Minor nit: you shouldn't really have a partly > initialized instance > flying around. > > > #if the plaintext was manually encrypted > then > > it needs no further encryption > > #in fact further encryption could be > harmful > > if self.encrypted == NO and > > self.saveSwitch.state() == 1: > > #edited out as this code isn't running > > #at this time. > > else: > > length = len(self.text.string()) > > > > > cyphertext.initWithBytes_length(self.text.RTFDFromRange_((0,length)),le > > > ngth) > > That's the problem right here: > > > 1. RTFDFromRange already returns an NSData, and what > you are doing is > initializing a second NSData object with the pointer > of the NSData > *object*. > > 2. RTFDFromRange is "an RTFD stream corresponding to > the characters and > attributes within aRange". This is a pasteboard > representation an not > something you can directly/usefully save as a file. > > > So, what you need is > -RTFDFileWrapperFromRange:documentAttributes: , > which returns a file-wrapper object that you can > save. > > More can be found in the fine documentation: > NSAttributedString > class reference + some concept docs "RTF Files and > Attributed Strings", > referenced from the NSAttributedString class > reference. > > Marcel > > -- > Marcel Weiher Metaobject Software Technologies > ma...@me... www.metaobject.com > Metaprogramming for the Graphic Arts. HOM, IDEAs, > MetaAd etc. > __________________________________ Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. http://search.yahoo.com |