File: LayerView.py

package info (click to toggle)
pythoncad 0.1.35-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,536 kB
  • ctags: 4,286
  • sloc: python: 62,752; sh: 743; makefile: 39
file content (82 lines) | stat: -rw-r--r-- 3,438 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#
# Copyright (c) 2002-2004 Art Haas
#
# This file is part of PythonCAD.
# 
# PythonCAD is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# PythonCAD is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with PythonCAD; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# Subclass of NSOutlineView, used to diplay layers in image
#

from PythonCAD.Interface.Cocoa import Globals
import PythonCAD.Generic.layer
from AppKit import NSOutlineView, NSMenu, NSMenuItem

class LayerOutlineView(NSOutlineView):
    """ Subclass of NSOutlineView, used to display layers
    
The purpose of the subclass is primarily to allow custom
context menus for the layer items. 

    """
    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