def outlineView_child_ofItem_(self, outlineView, itemIndex, item):
        """ NSOutlineViewDataSource method for layer view 

outlineView_child_ofItem_(outlineView, itemIndex, item)
        """
        _item = Globals.unwrap(item)
        if _item is None:
            return Globals.wrap(self.document().getImage().getTopLayer())
        _children = _item.getSublayers()
        return Globals.wrap(_children[itemIndex])
    def outlineView_child_ofItem_(self, outlineView, itemIndex, item):
        """ NSOutlineViewDataSource method for layer view 

outlineView_child_ofItem_(outlineView, itemIndex, item)
        """
        _item = Globals.unwrap(item)
        if _item is None:
            return Globals.wrap(self.document().getImage().getTopLayer())
        _children = _item.getSublayers()
        return Globals.wrap(_children[itemIndex])
 def ClearLayer_(self, sender):
     _layer = Globals.unwrap(sender.representedObject())
     if not isinstance(_layer, PythonCAD.Generic.layer.Layer):
         raise TypeError, "Invalid Layer: " + `_layer`
     _layer.clear()
     _doc = self.document()
     _doc.getDA().setNeedsDisplay_(True)
 def outlineView_willDisplayCell_forTableColumn_item_(self, ov, cell, tc, item):
     _layer = Globals.unwrap(item)
     if _layer.isVisible():
         _color = NSColor.blackColor()
     else:
         _color = NSColor.lightGrayColor()
     cell.setTextColor_(_color)  
 def ClearLayer_(self, sender):
     _layer = Globals.unwrap(sender.representedObject())
     if not isinstance(_layer, PythonCAD.Generic.layer.Layer):
         raise TypeError, "Invalid Layer: " + ` _layer `
     _layer.clear()
     _doc = self.document()
     _doc.getDA().setNeedsDisplay_(True)
 def outlineView_willDisplayCell_forTableColumn_item_(
         self, ov, cell, tc, item):
     _layer = Globals.unwrap(item)
     if _layer.isVisible():
         _color = NSColor.blackColor()
     else:
         _color = NSColor.lightGrayColor()
     cell.setTextColor_(_color)
 def outlineViewItemDidCollapse_(self, note):
     _doc = self.document()
     _active_layer = _doc.getImage().getActiveLayer()
     _ov = note.object()
     _row = _ov.rowForItem_(Globals.wrap(_active_layer))
     if -1 == _row:
         _item = note.userInfo()["NSObject"]
         _row = _ov.rowForItem_(_item)
         _ov.selectRow_byExtendingSelection_(_row, False)
    def outlineView_numberOfChildrenOfItem_(self, outlineView, item):
        """ NSOutlineViewDataSource method for layer view 

outlineView_numberOfChildrenOfItem_(outlineView, item)
        """
        _item = Globals.unwrap(item)
        if _item is None:
            return 1  # Top Layer item is first item in layer list
        return len(_item.getSublayers())
    def outlineView_isItemExpandable_(self, outlineView, item):
        """ NSOutlineViewDataSource method for layer view 

outlineView_isItemExpandable_(outlineView, item)
        """
        _item = Globals.unwrap(item)
        if _item is None:
            return True  # Top Layer item is always displayed
        return _item.hasSublayers()
 def outlineViewItemDidCollapse_(self, note):
     _doc = self.document()
     _active_layer = _doc.getImage().getActiveLayer()
     _ov = note.object()
     _row = _ov.rowForItem_(Globals.wrap(_active_layer))
     if -1 == _row:
         _item = note.userInfo()["NSObject"]
         _row = _ov.rowForItem_(_item)
         _ov.selectRow_byExtendingSelection_(_row, False)
 def outlineViewSelectionDidChange_(self, note):
     _ov = note.object()
     _index = _ov.selectedRow()
     if -1 != _index:
         _item = _ov.itemAtRow_(_index)
         _layer = Globals.unwrap(_item)
         _doc = self.document()
         _doc.getImage().setActiveLayer(_layer)
         _doc.getDA().setNeedsDisplay_(True)
 def outlineViewSelectionDidChange_(self, note):
     _ov = note.object()
     _index = _ov.selectedRow()
     if -1 != _index:
         _item = _ov.itemAtRow_(_index)
         _layer = Globals.unwrap(_item)
         _doc = self.document()
         _doc.getImage().setActiveLayer(_layer)
         _doc.getDA().setNeedsDisplay_(True)
    def outlineView_isItemExpandable_(self, outlineView, item):
        """ NSOutlineViewDataSource method for layer view 

outlineView_isItemExpandable_(outlineView, item)
        """
        _item = Globals.unwrap(item)
        if _item is None:
            return True # Top Layer item is always displayed
        return _item.hasSublayers()
    def outlineView_numberOfChildrenOfItem_(self, outlineView, item):
        """ NSOutlineViewDataSource method for layer view 

outlineView_numberOfChildrenOfItem_(outlineView, item)
        """
        _item = Globals.unwrap(item)
        if _item is None:
            return 1 # Top Layer item is first item in layer list
        return len(_item.getSublayers())
    def outlineView_objectValueForTableColumn_byItem_(self, ov, tc, item):
        """ NSOutlineViewDataSource method for layer view 

outlineView_objectValueForTableColumn_byItem_(outlineView, tableColumn, item)
        """
        if tc.identifier() != Globals.LayerColumnName:
            return None
        _item = Globals.unwrap(item)
        if _item is None:
            _item = self.document().getImage().getTopLayer()
        return _item.getName()
    def outlineView_setObjectValue_forTableColumn_byItem_(self, ov, val, tc, item):
        """ NSOutlineViewDataSource method for layer view
        
outlineView_setObjectValue_forTableColumn_byItem_(outlineView, value, tableColumn, item)
        """
        if tc.identifier() != Globals.LayerColumnName:
            return
        _layer = Globals.unwrap(item)
        if not isinstance(_layer, PythonCAD.Generic.layer.Layer):
            raise TypeError, "Invalid active Layer: " + `_layer`
        _layer.setName(val)
    def outlineView_objectValueForTableColumn_byItem_(self, ov, tc, item):
        """ NSOutlineViewDataSource method for layer view 

outlineView_objectValueForTableColumn_byItem_(outlineView, tableColumn, item)
        """
        if tc.identifier() != Globals.LayerColumnName:
            return None
        _item = Globals.unwrap(item)
        if _item is None:
            _item = self.document().getImage().getTopLayer()
        return _item.getName()
 def removed_child_event(self, obj, *args):
     """ Notification of deletion of a layer.  object is Image object,
     userinfo dict stores layer under key "layer", parent layer under
     key "parent"
     """
     _nq = NSNotificationQueue.defaultQueue()
     if len(args) != 2:
         raise ValueError, "Invalid number of items in deleted_layer_event"
     _info = {"layer" : args[0], "parent" : args[0].getParent()}
     _obj = Globals.wrap(obj)
     _note = NSNotification.notificationWithName_object_userInfo_(Globals.LayerDeletedNotification, _obj, _info)
     _nq.enqueueNotification_postingStyle_coalesceMask_forModes_(_note, NSPostASAP, NSNotificationNoCoalescing, None)
    def outlineView_setObjectValue_forTableColumn_byItem_(
            self, ov, val, tc, item):
        """ NSOutlineViewDataSource method for layer view
        
outlineView_setObjectValue_forTableColumn_byItem_(outlineView, value, tableColumn, item)
        """
        if tc.identifier() != Globals.LayerColumnName:
            return
        _layer = Globals.unwrap(item)
        if not isinstance(_layer, PythonCAD.Generic.layer.Layer):
            raise TypeError, "Invalid active Layer: " + ` _layer `
        _layer.setName(val)
 def layerChanged_(self, note):
     _doc = self.document()
     _doc.getDA().setNeedsDisplay_(True)
     _dict = note.userInfo()
     _parent = Globals.wrap(_dict["parent"])
     _ov = _doc.getOutlineView()
     _image = _doc.getImage()
     _l = _activeLayer = _image.getActiveLayer()
     #        _ov.reloadItem_reloadChildren_(_parent, True)
     _ov.reloadData()
     _topLayer = _image.getTopLayer()
     _stack = []
     while _l is not _topLayer:
         _l = _l.getParentLayer()
         _stack.append(_l)
     while len(_stack):
         _item = Globals.wrap(_stack.pop())
         _ov.expandItem_(_item)
     _al = Globals.wrap(_activeLayer)
     _row = _ov.rowForItem_(_al)
     _ov.selectRow_byExtendingSelection_(_row, False)
    def layerChanged_(self, note):
        _doc = self.document()
        _doc.getDA().setNeedsDisplay_(True)
        _dict = note.userInfo()
        _parent = Globals.wrap(_dict["parent"])
        _ov = _doc.getOutlineView()
        _image = _doc.getImage()
        _l = _activeLayer = _image.getActiveLayer()
#        _ov.reloadItem_reloadChildren_(_parent, True)
        _ov.reloadData()
        _topLayer = _image.getTopLayer()
        _stack = []
        while _l is not _topLayer:
            _l = _l.getParentLayer()
            _stack.append(_l)
        while len(_stack):
            _item = Globals.wrap(_stack.pop())
            _ov.expandItem_(_item)
        _al = Globals.wrap(_activeLayer)
        _row = _ov.rowForItem_(_al)
        _ov.selectRow_byExtendingSelection_(_row, False)
 def deleted_object_event(self, obj, *args):
     """ Notification of point, line, etc. removed from a layer.
     object is Image object, userinfo dict stores object
     under key "item", layer it was removed from under "layer"
     """
     _nq = NSNotificationQueue.defaultQueue()
     if len(args) != 2:
         raise ValueError, "Invalid number of items in deleted_object_event"
     _info = {"layer" : args[0], "item": args[1]}
     _obj = Globals.wrap(obj)
     _note = NSNotification.notificationWithName_object_userInfo_("deleted_object", _obj, _info)
     _nq.enqueueNotification_postingStyle_coalesceMask_forModes_(_note, NSPostASAP, NSNotificationNoCoalescing, None)
 def ShowChildLayers_(self, sender):
     _layer = Globals.unwrap(sender.representedObject())
     if not isinstance(_layer, PythonCAD.Generic.layer.Layer):
         raise TypeError, "Invalid Layer: " + ` _layer `
     _children = _layer.getSublayers()
     while (len(_children)):
         _child = _children.pop()
         _child.show()
         if _child.hasSublayers():
             _children = _children + _child.getSublayers()
     _doc = self.document()
     _doc.getDA().setNeedsDisplay_(True)
     _doc.getOutlineView().setNeedsDisplay_(True)
 def ShowChildLayers_(self, sender):
     _layer = Globals.unwrap(sender.representedObject())
     if not isinstance(_layer, PythonCAD.Generic.layer.Layer):
         raise TypeError, "Invalid Layer: " + `_layer`
     _children = _layer.getSublayers()
     while(len(_children)):
         _child = _children.pop()
         _child.show()
         if _child.hasSublayers():
             _children = _children + _child.getSublayers()
     _doc = self.document()
     _doc.getDA().setNeedsDisplay_(True)
     _doc.getOutlineView().setNeedsDisplay_(True)
Example #25
0
 def deleted_object_event(self, obj, *args):
     """ Notification of point, line, etc. removed from a layer.
     object is Image object, userinfo dict stores object
     under key "item", layer it was removed from under "layer"
     """
     _nq = NSNotificationQueue.defaultQueue()
     if len(args) != 2:
         raise ValueError, "Invalid number of items in deleted_object_event"
     _info = {"layer": args[0], "item": args[1]}
     _obj = Globals.wrap(obj)
     _note = NSNotification.notificationWithName_object_userInfo_(
         "deleted_object", _obj, _info)
     _nq.enqueueNotification_postingStyle_coalesceMask_forModes_(
         _note, NSPostASAP, NSNotificationNoCoalescing, None)
Example #26
0
 def added_child_event(self, obj, *args):
     """ Notification of new layer added to drawing.
     object is Image object, userinfo dict stores new layer
     under key "layer", parent layer under key "parent"
     """
     _nq = NSNotificationQueue.defaultQueue()
     if len(args) != 2:
         raise ValueError, "Invalid number of new items in added_layer_event"
     _info = {"layer": args[0], "parent": args[0].getParent()}
     _obj = Globals.wrap(obj)
     _note = NSNotification.notificationWithName_object_userInfo_(
         Globals.LayerAddedNotification, _obj, _info)
     _nq.enqueueNotification_postingStyle_coalesceMask_forModes_(
         _note, NSPostASAP, NSNotificationNoCoalescing, None)
    def menuForEvent_(self, event):
        _point = self.convertPoint_fromView_(event.locationInWindow(), None)
        _index = self.rowAtPoint_(_point)
        if -1 == _index:
            return None

        if not self.isRowSelected_(_index):
            self.selectRow_byExtendingSelection_(_index, False)

        _item = self.itemAtRow_(_index)
        _layer = Globals.unwrap(_item)
        if not isinstance(_layer, PythonCAD.Generic.layer.Layer):
            raise TypeError, "Invalid Layer: " + `_layer`
        
        _menu = NSMenu.alloc().initWithTitle_("Context")
        _menuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Rename", "EditLayerName:", "")
        _menu.addItem_(_menuItem)
        if _layer.isVisible():
            _menuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Hide", "HideLayer:", "")
        else:
            _menuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Show", "ShowLayer:", "")            
        _menuItem.setRepresentedObject_(_item)
        _menu.addItem_(_menuItem)
        _menuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Add Child Layer", "AddChildLayer:", "")
        _menuItem.setRepresentedObject_(_item)
        _menu.addItem_(_menuItem)
        _menuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Clear", "ClearLayer:", "")
        _menuItem.setRepresentedObject_(_item)
        _menu.addItem_(_menuItem)
        if _layer.hasChildren():
            _menuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Hide Children", "HideChildLayers:", "")
            _menuItem.setRepresentedObject_(_item)
            _menu.insertItem_atIndex_(_menuItem, 3)
            _menuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Show Children", "ShowChildLayers:", "")
            _menuItem.setRepresentedObject_(_item)
            _menu.insertItem_atIndex_(_menuItem, 4)
        elif _layer.getParentLayer() is not None:
            _menuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Delete", "DeleteLayer:", "")
            _menuItem.setRepresentedObject_(_item)
            _menu.addItem_(_menuItem)
        return _menu
            
        
        


        
            
            
    def menuForEvent_(self, event):
        _point = self.convertPoint_fromView_(event.locationInWindow(), None)
        _index = self.rowAtPoint_(_point)
        if -1 == _index:
            return None

        if not self.isRowSelected_(_index):
            self.selectRow_byExtendingSelection_(_index, False)

        _item = self.itemAtRow_(_index)
        _layer = Globals.unwrap(_item)
        if not isinstance(_layer, PythonCAD.Generic.layer.Layer):
            raise TypeError, "Invalid Layer: " + `_layer`
        
        _menu = NSMenu.alloc().initWithTitle_("Context")
        _menuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Rename", "EditLayerName:", "")
        _menu.addItem_(_menuItem)
        if _layer.isVisible():
            _menuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Hide", "HideLayer:", "")
        else:
            _menuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Show", "ShowLayer:", "")            
        _menuItem.setRepresentedObject_(_item)
        _menu.addItem_(_menuItem)
        _menuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Add Child Layer", "AddChildLayer:", "")
        _menuItem.setRepresentedObject_(_item)
        _menu.addItem_(_menuItem)
        _menuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Clear", "ClearLayer:", "")
        _menuItem.setRepresentedObject_(_item)
        _menu.addItem_(_menuItem)
        if _layer.hasChildren():
            _menuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Hide Children", "HideChildLayers:", "")
            _menuItem.setRepresentedObject_(_item)
            _menu.insertItem_atIndex_(_menuItem, 3)
            _menuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Show Children", "ShowChildLayers:", "")
            _menuItem.setRepresentedObject_(_item)
            _menu.insertItem_atIndex_(_menuItem, 4)
        elif _layer.getParentLayer() is not None:
            _menuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Delete", "DeleteLayer:", "")
            _menuItem.setRepresentedObject_(_item)
            _menu.addItem_(_menuItem)
        return _menu
 def windowDidLoad(self):
     _doc = self.document()
     _sv = _doc.getSplitView()
     _ov = _doc.getOutlineView()
     _text = _doc.getEntry()
     _win = self.window()
     _text.setDelegate_(self)
     _sv.setDelegate_(self)
     _win.setDelegate_(self)
     _win.setFrameUsingName_(WinFrameName)
     _ov.setDataSource_(self)
     _ov.setDelegate_(self)
     _ov.sizeLastColumnToFit()
     _ov.setAutoresizesOutlineColumn_(True)
     _da = _doc.getDA()
     _scrv = _da.enclosingScrollView()
     _scrvSize = _scrv.contentSize()
     _scrv.setCopiesOnScroll_(False)
     _da.setFrameSize_(_scrvSize)
     #
     # ensure selected layer is active
     #
     _item = _ov.itemAtRow_(0)
     _ov.expandItem_expandChildren_(_item, True)
     _endRow = _ov.numberOfRows() - 1
     _ov.selectRow_byExtendingSelection_(_endRow, False)
     _ov.selectRow_byExtendingSelection_(0, False)
     #
     # Register for notifications of changes to the document
     #
     _img = _doc.getImage()
     _obj = Globals.wrap(_img)
     _nc = NSNotificationCenter.defaultCenter()
     _nc.addObserver_selector_name_object_(self, "layerChanged:",
                                           LayerAddedNotification, _obj)
     _nc.addObserver_selector_name_object_(self, "layerChanged:",
                                           LayerDeletedNotification, _obj)
     _nc.addObserver_selector_name_object_(self, "toolChanged:",
                                           ToolChangedNotification, _doc)
 def windowDidLoad(self):
     _doc = self.document()
     _sv = _doc.getSplitView()
     _ov = _doc.getOutlineView()
     _text = _doc.getEntry()
     _win = self.window()
     _text.setDelegate_(self)
     _sv.setDelegate_(self)
     _win.setDelegate_(self)
     _win.setFrameUsingName_(WinFrameName)
     _ov.setDataSource_(self)
     _ov.setDelegate_(self)
     _ov.sizeLastColumnToFit()
     _ov.setAutoresizesOutlineColumn_(True)
     _da = _doc.getDA()
     _scrv = _da.enclosingScrollView()
     _scrvSize = _scrv.contentSize()
     _scrv.setCopiesOnScroll_(False)
     _da.setFrameSize_(_scrvSize)
     #
     # ensure selected layer is active
     #
     _item = _ov.itemAtRow_(0)
     _ov.expandItem_expandChildren_(_item, True)
     _endRow = _ov.numberOfRows() - 1
     _ov.selectRow_byExtendingSelection_(_endRow, False)
     _ov.selectRow_byExtendingSelection_(0, False)
     #
     # Register for notifications of changes to the document
     #
     _img = _doc.getImage()
     _obj = Globals.wrap(_img)
     _nc = NSNotificationCenter.defaultCenter()
     _nc.addObserver_selector_name_object_(self, "layerChanged:", LayerAddedNotification, _obj)
     _nc.addObserver_selector_name_object_(self, "layerChanged:", LayerDeletedNotification, _obj)
     _nc.addObserver_selector_name_object_(self, "toolChanged:", ToolChangedNotification, _doc)
 def DeleteLayer_(self, sender):
     _layer = Globals.unwrap(sender.representedObject())
     if not isinstance(_layer, PythonCAD.Generic.layer.Layer):
         raise TypeError, "Invalid Layer: " + `_layer`
     _doc = self.document()
     _doc.delLayer(_layer)
 def DeleteLayer_(self, sender):
     _layer = Globals.unwrap(sender.representedObject())
     if not isinstance(_layer, PythonCAD.Generic.layer.Layer):
         raise TypeError, "Invalid Layer: " + ` _layer `
     _doc = self.document()
     _doc.delLayer(_layer)