Re: [Pyobjc-dev] PyShellView?
Brought to you by:
ronaldoussoren
From: Dinu G. <gh...@da...> - 2003-07-02 08:31:05
|
I wrote: > Sounds good to me! You may want to sniff into the following maybe: > > > http://developer.apple.com/samplecode/Sample_Code/Cocoa/ > TextViewDelegate.htm > > Have fun, Big fun, indeed!! The following conversion to PyObjC using an outlet named 'committedLength' of type id in IB just crashes: #------------------------------------------------------------------ # # MyAppDelegate.py # PyTextViewDelegate # from objc import YES, NO from Foundation import NSObject from AppKit import NSColor, NSApplicationDelegate from PyObjCTools import NibClassBuilder # create ObjC classes as defined in MainMenu.nib NibClassBuilder.extractClasses("MainMenu") class MyAppDelegate(NibClassBuilder.AutoBaseClass, NSApplicationDelegate): def awakeFromNib(self): "Set our committedLength outlet to the right start value." self.committedLength = 0 def textView_shouldChangeTextInRange_replacementString_(self, textView, charRange, replString): "Allow editing only after the previously committed text." return charRange[0] >= self.committedLength #------------------------------------------------------------------ But after using an instance variable 'cl' locally defined in awakeFromNib everything works fine and I get the following code working as the ObjC-counterpart: #------------------------------------------------------------------ # # MyAppDelegate.py # PyTextViewDelegate # from objc import YES, NO from Foundation import NSObject from AppKit import NSColor, NSApplicationDelegate from PyObjCTools import NibClassBuilder # create ObjC classes as defined in MainMenu.nib NibClassBuilder.extractClasses("MainMenu") class MyAppDelegate(NibClassBuilder.AutoBaseClass, NSApplicationDelegate): def awakeFromNib(self): "Set our committedLength outlet to the right start value." # self.committedLength = 0 self.cl = 0 def textView_shouldChangeTextInRange_replacementString_(self, textView, charRange, replString): "Allow editing only after the previously committed text." return charRange[0] >= self.cl def textView_doCommandBySelector_(self, textView, commandSelector): "When return is entered, record and color the newly committed text." retval = NO if commandSelector == "insertNewline:": textLength = len(textView.string()) if textLength > self.cl: textView.setSelectedRange_((textLength, 0)) textView.insertText_("\n") col = NSColor.redColor() r = (self.cl, textLength - self.cl) textView.setTextColor_range_(col, r) textLength += 1 self.cl = textLength retval = YES return retval #------------------------------------------------------------------ Nothing to do with using the NSTextViewDelegate - tried it, makes no difference! Pretty strange to me... Dinu -- Dinu C. Gherman ...................................................................... "We're concerned about AIDS inside our White House - make no mistake about it." (George W. Bush, 7 Feb. 2001) |