Changeset 199

Show
Ignore:
Timestamp:
04/26/08 11:28:19 (9 months ago)
Author:
tal
Message:
Vanilla Cleanup Phase 1:

Prior to this checkin, various objects had private attributes that defined the NS class that they should use. For example, List defined _tableViewClass. Subclasses that wished to add custom behavior to the NS classes had to override these private attributes. This was not a nice API. I've now made these attributes public with names like nsTableViewClass. If you overrode these attributes in your objects, you need to update your code. I've made it so that your code will still work, but you will get DeprecationWarnings.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • packages/vanilla/trunk/Lib/vanilla/vanillaBase.py

    r168 r199  
    1717 
    1818    def _setupView(self, classOrName, posSize, callback=None): 
     19        self._testForDeprecatedAttributes() 
    1920        cls = getNSSubclass(classOrName) 
    2021        self._nsObject = cls(self) 
     
    2627        if hasattr(self, "_target"): 
    2728            self._target.callback = None 
     29 
     30    def _testForDeprecatedAttributes(self): 
     31        pass 
    2832 
    2933    def _setCallback(self, callback): 
  • packages/vanilla/trunk/Lib/vanilla/vanillaButton.py

    r170 r199  
    4747    """ 
    4848 
    49     _nsBezelStyle = NSRoundedBezelStyle 
    50     _nsButtonType = NSMomentaryPushInButton 
     49    nsBezelStyle = NSRoundedBezelStyle 
     50    nsButtonType = NSMomentaryPushInButton 
    5151    _frameAdjustments = { 
    5252        'mini': (-1, -2, 2, 2), 
     
    7777        self._setSizeStyle(sizeStyle) 
    7878        self._nsObject.setTitle_(title) 
    79         self._nsObject.setBezelStyle_(self._nsBezelStyle) 
    80         self._nsObject.setButtonType_(self._nsButtonType) 
     79        self._nsObject.setBezelStyle_(self.nsBezelStyle) 
     80        self._nsObject.setButtonType_(self.nsButtonType) 
     81 
     82    def _testForDeprecatedAttributes(self): 
     83        super(Button, self)._testForDeprecatedAttributes() 
     84        from warnings import warn 
     85        if hasattr(self, "_nsBezelStyle"): 
     86            warn(DeprecationWarning("The _nsBezelStyle attribute is deprecated. Use the nsBezelStyle attribute.")) 
     87            self.nsBezelStyle = self._nsBezelStyle 
     88        if hasattr(self, "_nsButtonType"): 
     89            warn(DeprecationWarning("The _nsButtonType attribute is deprecated. Use the nsButtonType attribute.")) 
     90            self.nsButtonType = self._nsButtonType 
    8191 
    8292    def getNSButton(self): 
     
    139149    """ 
    140150     
    141     _nsBezelStyle = NSShadowlessSquareBezelStyle 
     151    nsBezelStyle = NSShadowlessSquareBezelStyle 
    142152    _frameAdjustments = None 
    143153     
     
    292302    """ 
    293303 
    294     _nsBezelStyle = NSHelpButtonBezelStyle 
     304    nsBezelStyle = NSHelpButtonBezelStyle 
    295305    _frameAdjustments = { 
    296306        'regular': (0, -3, 0, 3), 
  • packages/vanilla/trunk/Lib/vanilla/vanillaCheckBox.py

    r1 r199  
    1313class _CheckBoxStandardBuild(Button): 
    1414 
    15     _nsButtonType = NSSwitchButton 
     15    nsButtonType = NSSwitchButton 
    1616    _frameAdjustments = { 
    1717        'mini': (-4, -4, 6, 8), 
     
    5050class _CheckBoxManualBuildButton(Button): 
    5151     
    52     _nsButtonType = NSSwitchButton 
     52    nsButtonType = NSSwitchButton 
    5353    _frameAdjustments = { 
    5454        'regular': (-2, -3, 4, 4), 
     
    7070class _CheckBoxManualBuildTextButton(Button): 
    7171     
    72     _nsBezelStyle = NSShadowlessSquareBezelStyle 
     72    nsBezelStyle = NSShadowlessSquareBezelStyle 
    7373    _frameAdjustments = None 
    7474     
  • packages/vanilla/trunk/Lib/vanilla/vanillaEditText.py

    r1 r199  
    3838    """ 
    3939     
    40     _textFieldClass = NSTextField 
     40    nsTextFieldClass = NSTextField 
    4141 
    4242    def __init__(self, posSize, text="", callback=None, continuous=True, readOnly=False, formatter=None, placeholder=None, sizeStyle="regular"): 
     
    6969        # 
    7070        self._continuous = continuous 
    71         self._setupView(self._textFieldClass, posSize, callback) 
     71        self._setupView(self.nsTextFieldClass, posSize, callback) 
    7272        self._posSize = posSize 
    7373        # 
     
    8484        if placeholder: 
    8585            cell.setPlaceholderString_(placeholder) 
     86 
     87    def _testForDeprecatedAttributes(self): 
     88        super(EditText, self)._testForDeprecatedAttributes() 
     89        from warnings import warn 
     90        if hasattr(self, "_textFieldClass"): 
     91            warn(DeprecationWarning("The _textFieldClass attribute is deprecated. Use the nsTextFieldClass attribute.")) 
     92            self.nsTextFieldClass = self._textFieldClass 
    8693 
    8794    def getNSTextField(self): 
     
    142149    """ 
    143150 
    144     _textFieldClass = NSSecureTextField 
     151    nsTextFieldClass = NSSecureTextField 
    145152 
  • packages/vanilla/trunk/Lib/vanilla/vanillaGradientButton.py

    r170 r199  
    44class GradientButton(ImageButton): 
    55 
    6     _nsBezelStyle = NSSmallSquareBezelStyle 
     6    nsBezelStyle = NSSmallSquareBezelStyle 
    77 
  • packages/vanilla/trunk/Lib/vanilla/vanillaList.py

    r198 r199  
    256256    """ 
    257257 
    258     _scrollViewClass = NSScrollView 
    259     _tableViewClass = _VanillaTableViewSubclass 
    260     _arrayControllerClass = _VanillaArrayController 
    261     _arrayControllerObserverClass = _VanillaArrayControllerObserver 
     258    nsScrollViewClass = NSScrollView 
     259    nsTableViewClass = _VanillaTableViewSubclass 
     260    nsArrayControllerClass = _VanillaArrayController 
     261    nsArrayControllerObserverClass = _VanillaArrayControllerObserver 
    262262 
    263263    def __init__(self, posSize, items, dataSource=None, columnDescriptions=None, showColumnTitles=True, 
     
    349349        self._posSize = posSize 
    350350        self._enableDelete = enableDelete 
    351         self._nsObject = getNSSubclass(self._scrollViewClass)(self) 
     351        self._nsObject = getNSSubclass(self.nsScrollViewClass)(self) 
    352352        self._nsObject.setAutohidesScrollers_(autohidesScrollers) 
    353353        self._nsObject.setHasHorizontalScroller_(True) 
     
    357357        self._setAutosizingFromPosSize(posSize) 
    358358        # add a table view to the scroll view 
    359         self._tableView = getNSSubclass(self._tableViewClass)(self) 
     359        self._tableView = getNSSubclass(self.nsTableViewClass)(self) 
    360360        self._nsObject.setDocumentView_(self._tableView) 
    361361        # set up an observer that will be called by the bindings when a cell is edited 
    362362        self._editCallback = editCallback 
    363         self._editObserver = self._arrayControllerObserverClass.alloc().init() 
     363        self._editObserver = self.nsArrayControllerObserverClass.alloc().init() 
    364364        if editCallback is not None: 
    365365            self._editObserver._targetMethod = self._edit # circular reference to be killed in _breakCycles 
     
    369369            items = NSMutableArray.arrayWithArray_(items) 
    370370            # set up an array controller 
    371             self._arrayController = self._arrayControllerClass.alloc().initWithContent_(items) 
     371            self._arrayController = self.nsArrayControllerClass.alloc().initWithContent_(items) 
    372372            self._arrayController.setSelectsInsertedObjects_(False) 
    373373            self._arrayController.setAvoidsEmptySelection_(not allowsEmptySelection) 
     
    415415        if selectionCallback is not None: 
    416416            self._selectionCallback = selectionCallback 
    417             self._selectionObserver = self._arrayControllerObserverClass.alloc().init() 
     417            self._selectionObserver = self.nsArrayControllerObserverClass.alloc().init() 
    418418            self._arrayController.addObserver_forKeyPath_options_context_(self._selectionObserver, 'selectionIndexes', NSKeyValueObservingOptionNew, 0) 
    419419            self._selectionObserver._targetMethod = self._selection # circular reference to be killed in _breakCycles 
     
    448448        # set the drag data 
    449449        self._dragSettings = dragSettings 
    450      
     450 
     451    def _testForDeprecatedAttributes(self): 
     452        super(List, self)._testForDeprecatedAttributes() 
     453        from warnings import warn 
     454        if hasattr(self, "_scrollViewClass"): 
     455            warn(DeprecationWarning("The _scrollViewClass attribute is deprecated. Use the nsScrollViewClass attribute.")) 
     456            self.nsScrollViewClass = self._scrollViewClass 
     457        if hasattr(self, "_tableViewClass"): 
     458            warn(DeprecationWarning("The _tableViewClass attribute is deprecated. Use the nsTableViewClass attribute.")) 
     459            self.nsTableViewClass = self._tableViewClass 
     460        if hasattr(self, "_arrayControllerClass"): 
     461            warn(DeprecationWarning("The _arrayControllerClass attribute is deprecated. Use the nsArrayControllerClass attribute.")) 
     462            self.nsArrayControllerClass = self._arrayControllerClass 
     463        if hasattr(self, "_arrayControllerObserverClass"): 
     464            warn(DeprecationWarning("The _arrayControllerObserverClass attribute is deprecated. Use the nsArrayControllerObserverClass attribute.")) 
     465            self.nsArrayControllerObserverClass = self._arrayControllerObserverClass 
     466 
    451467    def getNSScrollView(self): 
    452468        """ 
  • packages/vanilla/trunk/Lib/vanilla/vanillaRadioGroup.py

    r1 r199  
    2626    """ 
    2727 
    28     _cellClass = NSButtonCell 
     28    nsCellClass = NSButtonCell 
    2929 
    3030    def __init__(self, posSize, titles, isVertical=True, callback=None, sizeStyle="regular"): 
     
    4848        matrix = self._nsObject 
    4949        matrix.setMode_(NSRadioModeMatrix) 
    50         matrix.setCellClass_(self._cellClass) 
     50        matrix.setCellClass_(self.nsCellClass) 
    5151        # XXX! this does not work for vertical radio groups! 
    5252        matrix.setAutosizesCells_(True) 
     
    7979            cell.setFont_(font) 
    8080 
     81    def _testForDeprecatedAttributes(self): 
     82        super(RadioGroup, self)._testForDeprecatedAttributes() 
     83        from warnings import warn 
     84        if hasattr(self, "_cellClass"): 
     85            warn(DeprecationWarning("The _cellClass attribute is deprecated. Use the nsCellClass attribute.")) 
     86            self.nsCellClass = self._cellClass 
     87 
    8188    def getNSMatrix(self): 
    8289        """ 
  • packages/vanilla/trunk/Lib/vanilla/vanillaScrollView.py

    r1 r199  
    3131    """ 
    3232 
    33     _scrollViewClass = NSScrollView 
     33    nsScrollViewClass = NSScrollView 
    3434 
    3535    def __init__(self, posSize, nsView, hasHorizontalScroller=True, hasVerticalScroller=True, 
     
    4848        *backgroundColor* A _NSColor_ object representing the background color of the scroll view. 
    4949        """ 
    50         self._setupView(self._scrollViewClass, posSize) 
     50        self._setupView(self.nsScrollViewClass, posSize) 
    5151        if clipView is not None: 
    5252            self._nsObject.setContentView_(clipView) 
     
    5858        if backgroundColor: 
    5959            self._nsObject.setBackgroundColor_(backgroundColor) 
    60      
     60 
     61    def _testForDeprecatedAttributes(self): 
     62        super(ScrollView, self)._testForDeprecatedAttributes() 
     63        from warnings import warn 
     64        if hasattr(self, "_scrollViewClass"): 
     65            warn(DeprecationWarning("The _scrollViewClass attribute is deprecated. Use the nsScrollViewClass attribute.")) 
     66            self.nsScrollViewClass = self._scrollViewClass 
     67 
    6168    def getNSScrollView(self): 
    6269        """ 
  • packages/vanilla/trunk/Lib/vanilla/vanillaTextEditor.py

    r166 r199  
    3434    """ 
    3535 
    36     _textViewClass = NSTextView 
     36    nsTextViewClass = NSTextView 
    3737 
    3838    def __init__(self, posSize, text="", callback=None, readOnly=False, checksSpelling=False): 
     
    5353        self._nsObject.setBorderType_(NSBezelBorder) 
    5454        self._nsObject.setDrawsBackground_(True) 
    55         self._textView = getNSSubclass(self._textViewClass)(self) 
     55        self._textView = getNSSubclass(self.nsTextViewClass)(self) 
    5656        self._textView.setAllowsUndo_(True) 
    5757        self._textView.setString_(text) 
     
    6363        self._setCallback(callback) 
    6464        self._setAutosizingFromPosSize(posSize) 
     65 
     66    def _testForDeprecatedAttributes(self): 
     67        super(TextEditor, self)._testForDeprecatedAttributes() 
     68        from warnings import warn 
     69        if hasattr(self, "_textViewClass"): 
     70            warn(DeprecationWarning("The _textViewClass attribute is deprecated. Use the nsTextViewClass attribute.")) 
     71            self.nsTextViewClass = self._textViewClass 
    6572 
    6673    def getNSScrollView(self): 
  • packages/vanilla/trunk/Lib/vanilla/vanillaWindows.py

    r155 r199  
    4141        return cls.alloc().init() 
    4242 
    43     _nsWindowStyleMask = NSTitledWindowMask 
     43    nsWindowStyleMask = NSTitledWindowMask 
    4444    # use the unified title and toolbar in 10.4+ 
    4545    try: 
    46         _nsWindowStyleMask |= NSUnifiedTitleAndToolbarWindowMask 
     46        nsWindowStyleMask |= NSUnifiedTitleAndToolbarWindowMask 
    4747    except NameError: 
    4848        pass 
    49     _nsWindowClass = NSWindow 
    50     _nsWindowLevel = NSNormalWindowLevel 
     49    nsWindowClass = NSWindow 
     50    nsWindowLevel = NSNormalWindowLevel 
    5151 
    5252    def __init__(self, posSize, title="", minSize=None, maxSize=None, textured=False, 
     
    7171        *initiallyVisible* Boolean value representing if the window will be initially visible. Default is True. If False, you can show the window later by calling window.show(). 
    7272        """ 
    73         mask = self._nsWindowStyleMask 
     73        mask = self.nsWindowStyleMask 
    7474        if closable: 
    7575            mask = mask | NSClosableWindowMask 
     
    9090            cascade = False 
    9191        frame = _calcFrame(NSScreen.mainScreen().visibleFrame(), ((l, t), (w, h))) 
    92         self._window = self._nsWindowClass.alloc().initWithContentRect_styleMask_backing_defer_( 
     92        self._window = self.nsWindowClass.alloc().initWithContentRect_styleMask_backing_defer_( 
    9393            frame, mask, NSBackingStoreBuffered, False) 
    9494        if autosaveName is not None: 
     
    104104            self._window.setMaxSize_(maxSize) 
    105105        self._window.setTitle_(title) 
    106         self._window.setLevel_(self._nsWindowLevel) 
     106        self._window.setLevel_(self.nsWindowLevel) 
    107107        self._window.setReleasedWhenClosed_(False) 
    108108        self._window.setDelegate_(self) 
    109109        self._bindings = {} 
    110110        self._initiallyVisible = initiallyVisible 
     111 
     112    def _testForDeprecatedAttributes(self): 
     113        from warnings import warn 
     114        if hasattr(self, "_nsWindowStyleMask"): 
     115            warn(DeprecationWarning("The _nsWindowStyleMask attribute is deprecated. Use the nsWindowStyleMask attribute.")) 
     116            self.nsWindowStyleMask = self._nsWindowStyleMask 
     117        if hasattr(self, "_nsWindowClass"): 
     118            warn(DeprecationWarning("The _nsWindowClass attribute is deprecated. Use the nsWindowClass attribute.")) 
     119            self.nsWindowClass = self._nsWindowClass 
     120        if hasattr(self, "_nsWindowLevel"): 
     121            warn(DeprecationWarning("The _nsWindowLevel attribute is deprecated. Use the nsWindowLevel attribute.")) 
     122            self.nsWindowLevel = self._nsWindowLevel 
    111123 
    112124    def _cascade(self): 
     
    589601    """ 
    590602 
    591     _nsWindowStyleMask = NSTitledWindowMask | NSUtilityWindowMask 
    592     _nsWindowClass = NSPanel 
    593     _nsWindowLevel = NSFloatingWindowLevel 
     603    nsWindowStyleMask = NSTitledWindowMask | NSUtilityWindowMask 
     604    nsWindowClass = NSPanel 
     605    nsWindowLevel = NSFloatingWindowLevel 
    594606 
    595607    def __init__(self, posSize, title="", minSize=None, maxSize=None,