~ubuntu-branches/ubuntu/raring/wxwidgets2.8/raring

« back to all changes in this revision

Viewing changes to wxPython/wx/tools/Editra/src/autocomp/completer.py

  • Committer: Package Import Robot
  • Author(s): Stéphane Graber
  • Date: 2012-01-07 13:59:25 UTC
  • mfrom: (1.1.9) (5.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20120107135925-2601miy9ullcon9j
Tags: 2.8.12.1-6ubuntu1
* Resync from Debian, changes that were kept:
  - debian/rules: re-enable mediactrl. This allows libwx_gtk2u_media-2.8 to be
    built, as this is required by some applications (LP: #632984)
  - debian/control: Build-dep on libxt-dev for mediactrl.
  - Patches
    + fix-bashism-in-example
* Add conflict on python-wxgtk2.8 (<< 2.8.12.1-6ubuntu1~) to python-wxversion
  to guarantee upgrade ordering when moving from pycentral to dh_python2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
"""
15
15
 
16
16
__author__ = "Cody Precord <cprecord@editra.org>"
17
 
__svnid__ = "$Id: completer.py 63531 2010-02-21 15:48:53Z CJP $"
18
 
__revision__ = "$Revision: 63531 $"
 
17
__svnid__ = "$Id: completer.py 67701 2011-05-04 20:50:14Z CJP $"
 
18
__revision__ = "$Revision: 67701 $"
19
19
 
20
20
__all__ = [ 'TYPE_FUNCTION', 'TYPE_METHOD', 'TYPE_CLASS', 'TYPE_ATTRIBUTE',
21
21
            'TYPE_VARIABLE', 'TYPE_ELEMENT', 'TYPE_PROPERTY', 'TYPE_UNKNOWN',
44
44
    Symbol hash is based on symbol NAME
45
45
    
46
46
    """
47
 
    def __init__(self, name, type):
 
47
    # we create lots of these so use slots as a performance tweak
 
48
    __slots__ = ('_name', '_type')
 
49
 
 
50
    def __init__(self, name, symtype):
48
51
        """ Constructor
49
 
        @param Name: Symbol name
50
 
        @param Type: Symbol type, one of the TYPE_FUNCTION ... TYPE_UNKNOWN range
 
52
        @param name: Symbol name
 
53
        @param symtype: Symbol type, one of the TYPE_FUNCTION ... TYPE_UNKNOWN range
51
54
        
52
55
        """
53
 
        object.__init__(self)
 
56
        super(Symbol, self).__init__()
54
57
 
55
58
        # Attributes
56
 
        self.__name = unicode(name)
57
 
        self.__type = type
 
59
        self._name = unicode(name)
 
60
        self._type = symtype
58
61
    
59
62
    def __eq__(self, other):
60
 
        return (self.__name == other.__name)
 
63
        return (self.Name == other.Name)
61
64
 
62
65
    def __lt__(self, other):
63
 
        return (self.__name < other.__name)
 
66
        return (self.Name < other.Name)
64
67
 
65
68
    def __le__(self, other):
66
 
        return (self.__name <= other.__name)
 
69
        return (self.Name <= other.Name)
67
70
 
68
71
    def __ne__(self, other):
69
 
        return (self.__name != other.__name)
 
72
        return (self.Name != other.Name)
70
73
 
71
74
    def __gt__(self, other):
72
 
        return (self.__name > other.__name)
 
75
        return (self.Name > other.Name)
73
76
 
74
77
    def __ge__(self, other):
75
 
        return (self.__name >= other.__name)
 
78
        return (self.Name >= other.Name)
76
79
 
77
80
    # TODO: this task should probably be delegated to the ui
78
81
    def __str__(self):
79
 
        if self.__type != TYPE_UNKNOWN:
80
 
            return u'?'.join([self.__name, unicode(self.__type)])
 
82
        if self.Type != TYPE_UNKNOWN:
 
83
            return u'?'.join([self.Name, unicode(self.Type)])
81
84
        else:
82
85
            return self.Name
83
86
 
84
87
    def __hash__(self):
85
 
        return self.__name.__hash__()
86
 
    
87
 
    @property
88
 
    def Name(self):
89
 
        return self.__name
 
88
        return hash(self.Name)
90
89
 
91
 
    @property
92
 
    def Type(self):
93
 
        return self.__type
 
90
    Name = property(lambda self: self._name,
 
91
                    lambda self, n: setattr(self, '_name', n))
 
92
    Type = property(lambda self: self._type,
 
93
                    lambda self, t: setattr(self, '_type', t))
94
94
 
95
95
#--------------------------------------------------------------------------#
96
96
 
108
108
class BaseCompleter(object):
109
109
    """Base Autocomp provider class"""
110
110
    def __init__(self, parent):
111
 
        """Initializes the autocompletion service
 
111
        """Initializes the auto-completion service
112
112
        @param parent: parent of this service object
113
113
 
114
114
        """
115
 
        object.__init__(self)
 
115
        super(BaseCompleter, self).__init__()
116
116
 
117
117
        # Attributes
118
118
        self._buffer = parent
139
139
 
140
140
    def GetCallTip(self, command):
141
141
        """Returns the calltip string for a command
142
 
        @param command: command to get callip for (string)
 
142
        @param command: command to get calltip for (string)
143
143
        @return: string
144
144
 
145
145
        """
163
163
        """
164
164
        return self._autocomp_keys
165
165
 
166
 
    def IsCallTipEvent(self, evt):
167
 
        """Should a calltip be shown for the given key combo"""
168
 
        if evt.ControlDown() and evt.GetKeyCode() == ord('9'):
169
 
            return True
170
 
        return False
171
 
 
172
 
    def IsAutoCompEvent(self, evt):
173
 
        """Is it a key combination that should allow completions to be shown
174
 
        @param evt: wx.KeyEvent
175
 
        @return: bool
176
 
        @todo: this shoud probably be handled in edstc
177
 
 
178
 
        """
179
 
        if evt.ControlDown() and evt.GetKeyCode() == wx.WXK_SPACE:
180
 
            return True
181
 
        return False
182
 
 
183
166
    def SetAutoCompKeys(self, key_list):
184
167
        """Set the keys to provide completions on
185
168
        @param key_list: List of key codes
286
269
        if buff is not None:
287
270
            if buff.IsString(cpos) or buff.IsComment(cpos):
288
271
                rval = False
289
 
 
290
272
        return rval