~ubuntu-branches/ubuntu/utopic/python-apptools/utopic

« back to all changes in this revision

Viewing changes to enthought/naming/ui/naming_node_manager.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2011-07-08 23:55:50 UTC
  • mfrom: (2.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20110708235550-yz5u79ubeo4dhyfx
Tags: 4.0.0-1
* New upstream release
* Update debian/watch file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#------------------------------------------------------------------------------
2
 
# Copyright (c) 2005, Enthought, Inc.
3
 
# All rights reserved.
4
 
5
 
# This software is provided without warranty under the terms of the BSD
6
 
# license included in enthought/LICENSE.txt and may be redistributed only
7
 
# under the conditions described in the aforementioned license.  The license
8
 
# is also available online at http://www.enthought.com/licenses/BSD.txt
9
 
# Thanks for using Enthought open source!
10
 
11
 
# Author: Enthought, Inc.
12
 
# Description: <Enthought naming package component>
13
 
#------------------------------------------------------------------------------
14
 
""" The node manager for a naming tree. """
15
 
 
16
 
 
17
 
# Enthought library imports.
18
 
from enthought.pyface.tree.api import NodeManager
19
 
 
20
 
 
21
 
class NamingNodeManager(NodeManager):
22
 
    """ The node manager for a naming tree. """
23
 
 
24
 
    ###########################################################################
25
 
    # 'NodeManager' interface.
26
 
    ###########################################################################
27
 
 
28
 
    def get_key(self, node):
29
 
        """ Generates a unique key for a node. """
30
 
 
31
 
        # fixme: This scheme does NOT allow the same object to be in the tree
32
 
        # in more than one place.
33
 
        return self._get_hash_value(node.obj)
34
 
 
35
 
    ###########################################################################
36
 
    # Private interface.
37
 
    ###########################################################################
38
 
 
39
 
    def _get_hash_value(self, obj):
40
 
        """ Returns a hash value for an object. """
41
 
 
42
 
        # We do it like this 'cos, for example, using id() on a string
43
 
        # doesn't give us what we want, but things like lists aren't
44
 
        # hashable, so we can't always use hash()).
45
 
        try:
46
 
            hash_value = hash(obj)
47
 
            
48
 
        except:
49
 
            hash_value = id(obj)
50
 
 
51
 
        return hash_value
52
 
    
53
 
##### EOF #####################################################################