Indicator signals

Catch the mouseclick!

Catching indicator mouseclicks is very similar to catching hotspot mouseclicks. We’ll go through the steps to catch a mouseclick:

Step 1: Connect the signal to the slot

Your editor fires the signal indicatorClicked anytime the user clicks on an indicator, and indicatorReleased at the end. It doesn’t matter which indicator he clicked on. These signals are sort of ‘global’ for the editor as a whole.
You need to connect the signal to a slot. A slot is just a Python function which you want to get called everytime the signal fires. This is how you do it:




Step 2: Implement the function (the slot)

The slots some_function and other_function should each have three parameters:
some_function(self, line, index, keys)

  • line
    The line on which the indicator was clicked.
  • index
    The index (column) on which the indicator was clicked.
  • keys
    The key modifiers (Ctrl, Alt, …) that were active during the click. These can be or’ed

Here is an example:

    def some_function(self, line, index, keys):
        print("indicator clicked in line '{}', index '{}'".format(line, index))

    def other_function(self, line, index, keys):
        print("indicator released in line '{}', index '{}'".format(line, index))

So far, so good. Apart from some subtle syntactic differences, catching a mousclick on an indicator is quite similar to catching a mouseclick on a hotspot. But we’ll see in the next paragraph that indicators offer an awesome feature which is not available in the hotspot-mechanism!

Adding a value to an indicator when clicked

Indicators (more precisely: indicated-text) have the ability to store an integer value that can be retrieved when the text is clicked. We already touched this subject on the previous page. We discussed the (old-fashioned) way to apply an indicator on some text:

# Tell the editor which indicator-style to use
# (pass it the indicator-style ID number)
self.__editor.SendScintilla(QsciScintilla.SCI_SETINDICATORCURRENT, indicator_number)

# Assign a value to the text you're going to indicate
self.__editor.SendScintilla(QsciScintilla.SCI_SETINDICATORVALUE, value)

# Now apply the indicator-style on the chosen text
self.__editor.SendScintilla(QsciScintilla.SCI_INDICATORFILLRANGE, start_pos, nr_of_chars)

Now to retrieve that value, you should implement your slot function like so:

    def some_function(self, line, index, keys):
        # Retrieve absolute position
        position = self.__editor.positionFromLineIndex(line, index)
        # Retrieve given value
        value = self.__editor.SendScintilla(QsciScintilla.INDICATORVALUEAT,
                                            indicator_nr, position)

        print("indicator clicked in line '{}', 
        index '{}', value '{}'".format(line, index, value))

You can set different values for the same indicator-style. Just before using the SCI_INDICATORFILLRANGE to apply the indicator on some text, change the value with SCI_SETINDICATORVALUE.