QScintilla/TypingCompleters/CompleterBase.py

Wed, 02 Jan 2013 10:33:09 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 02 Jan 2013 10:33:09 +0100
branch
5_2_x
changeset 2303
0ed4ed026c16
parent 1509
c0b5e693b0eb
child 2525
8b507a9a2d40
child 2965
d133c7edd88a
child 3163
9f50365a0870
permissions
-rw-r--r--

Updated copyright for 2013.

# -*- coding: utf-8 -*-

# Copyright (c) 2007 - 2013 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a base class for all typing completers.

Typing completers are classes that implement some convenience actions,
that are performed while the user is typing (e.g. insert ')' when the
user types '(').
"""

from PyQt4.QtCore import QObject


class CompleterBase(QObject):
    """
    Class implementing the base class for all completers.
    """
    def __init__(self, editor, parent=None):
        """
        Constructor
        
        @param editor reference to the editor object (QScintilla.Editor)
        @param parent reference to the parent object (QObject)
            If parent is None, we set the editor as the parent.
        """
        if parent is None:
            parent = editor
        
        super().__init__(parent)
        
        self.editor = editor
        self.enabled = False
    
    def setEnabled(self, enable):
        """
        Public slot to set the enabled state.
        
        @param enabled flag indicating the new state (boolean)
        """
        if enable:
            if not self.enabled:
                self.editor.SCN_CHARADDED.connect(self.charAdded)
        else:
            if self.enabled:
                self.editor.SCN_CHARADDED.disconnect(self.charAdded)
        self.enabled = enable
    
    def isEnabled(self):
        """
        Public method to get the enabled state.
        """
        return self.enabled
    
    def charAdded(self, charNumber):
        """
        Public slot called to handle the user entering a character.
        
        Note 1: this slot must be overridden by subclasses implementing the
        specific behavior for the language.
        
        Note 2: charNumber can be greater than 255 because the editor is
        in UTF-8 mode by default.
        
        @param charNumber value of the character entered (integer)
        """
        pass    # just do nothing
    
    def readSettings(self):
        """
        Public slot called to reread the configuration parameters.
        
        Note: this slot should be overridden by subclasses having
        configurable parameters.
        """
        pass    # just do nothing

eric ide

mercurial