示例#1
0
 def setMarkers(self,
                iLineStart,
                iLineEnd,
                block=None,
                iMarker=None,
                bufferID=None,
                startAnimation=True):
     '''Set markers at the beginning and end of the executed
     code block, to show the user which part is actually executed
     and if the code is still running or finished or if errors
     occurred.'''
     if block:
         lineHasCode = [
             len(line) > 0 and not (line.isspace() or line.startswith('#'))
             for line in block.splitlines()
         ]
         linesWithCode = [i for i, c in enumerate(lineHasCode) if c]
         iLineEnd = iLineStart + linesWithCode[-1]
         iLineStart = iLineStart + linesWithCode[0]
     nMarkedLines = iLineEnd - iLineStart + 1
     markerIDs = []
     if bufferID is None:
         bufferID = notepad.getCurrentBufferID()
     self.hideMarkers(bufferID)
     if nMarkedLines <= 4:
         for iLine in range(nMarkedLines):
             markerIDs.append(editor.markerAdd(iLineStart + iLine, iMarker))
     else:
         markerIDs.append(editor.markerAdd(iLineStart, iMarker))
         markerIDs.append(editor.markerAdd(iLineStart + 1, iMarker + 1))
         markerIDs.append(editor.markerAdd(iLineEnd, iMarker))
         markerIDs.append(editor.markerAdd(iLineEnd - 1, iMarker + 2))
     self.markers[bufferID] = markerIDs
     if startAnimation and iMarker == self.m_active:
         self.onMarkerTimer(init=True)
示例#2
0
def toggle_bookmark(current_line):
    current_marker_mask = editor.markerGet(current_line)
    if (current_marker_mask
            & NPP_MARK_BOOKMARK_MASK) == NPP_MARK_BOOKMARK_MASK:
        editor.markerDelete(current_line, NPP_MARK_BOOKMARK)
    else:
        editor.markerAdd(current_line, NPP_MARK_BOOKMARK)
示例#3
0
 def test_scintillawrapper_int_int_int(self):
     editor.write('line 1\r\nline 2\r\nline 3\r\nline 4\r\n')
     handle = editor.markerAdd(2, 1)
     self.assertNotEqual(handle, -1)  # markerAdd() returns -1 if the line number is invalid or out of memory
     editor.insertText(0, 'inserted line 1\r\n')
     newLineNumber = editor.markerLineFromHandle(handle)
     self.assertEqual(newLineNumber, 3)
示例#4
0
    def test_scintillawrapper_int_int_void(self):
        editor.write('One\r\nTwo\r\nThree\r\nFour')

        handle = editor.markerAdd(3, 4)  # Add marker 4 at line 3

        beforeMoveMarker = editor.markerGet(3)
        editor.insertText(0, 'Add a line\r\n')
        afterMove3 = editor.markerGet(3)
        afterMove4 = editor.markerGet(4)
        lineNumber = editor.markerLineFromHandle(handle)

        self.assertEqual(beforeMoveMarker & 0x10, 0x10)  # marker 4 is 0x10, and there could be other markers on the line
        self.assertEqual(afterMove3 & 0x10, 0)           # after the insert, line 3 should not contain the marker
        self.assertEqual(afterMove4 & 0x10, 0x10)        # it should be on line 4
        self.assertEqual(lineNumber, 4)                  # The lineNumber obtained from the handle, should also be 4
示例#5
0
def main():
    if editor.getSelectionEmpty():
        # user hasn't selected anything, hide cursor line
        start_line = end_line = editor.lineFromPosition(editor.getCurrentPos())
    else:
        start_line, end_line = editor.getUserLineSelection()

    total_number_less_one_line = editor.getLineCount() - 1  # zero-based

    # recalculate which lines to hide as first and last line cannot be hide
    start_line = start_line if start_line > 0 else 1
    end_line = end_line if total_number_less_one_line > end_line else end_line - 1

    # calculate at which lines marker need to be placed
    marker_start_line = start_line - 1 if start_line > 0 else start_line
    marker_end_line = end_line + 1 if end_line < total_number_less_one_line else end_line

    # recalculate in case that marker(start/end)lines are not visible
    # either because they are part of a folding tree or already hidden
    while not editor.getLineVisible(marker_start_line):
        marker_start_line -= 1

    if not editor.getLineVisible(marker_end_line):
        visible_line = editor.visibleFromDocLine(marker_end_line)
        marker_end_line = editor.docLineFromVisible(visible_line)

    # check if there is already a marker set at those lines
    marker_at_marker_start_line = editor.markerGet(marker_start_line)
    marker_at_marker_end_line = editor.markerGet(marker_end_line)

    marker_already_set = False
    if (marker_at_marker_start_line
            & MARK_HIDELINESBEGIN_MASK) == MARK_HIDELINESBEGIN_MASK:
        marker_type = 'start'
        marker_already_set = True

    elif (marker_at_marker_end_line
          & MARK_HIDELINESEND_MASK) == MARK_HIDELINESEND_MASK:
        marker_type = 'end'
        marker_already_set = True

    # already markers set - inform user
    if marker_already_set:

        if EXTEND_AUTOMATICALLY is False:
            answer = notepad.messageBox((
                'There can only be one {} marker per line\r\n'
                'Should it be extended instead?\r\n'
                "If it shouldn't, it doesn't do anything").format(marker_type),
                                        'Info!', 4)

        if EXTEND_AUTOMATICALLY or answer == MESSAGEBOXFLAGS.RESULTYES:
            if marker_type == 'start':
                _matching_marker_line = find_correspondig_marker(
                    marker_start_line, MARK_HIDELINESEND_MASK)
                _start_marker_line_to_delete = marker_start_line
                _end_marker_line_to_delete = _matching_marker_line
            else:
                _matching_marker_line = find_correspondig_marker(
                    marker_end_line, MARK_HIDELINESBEGIN_MASK)
                _start_marker_line_to_delete = _matching_marker_line
                _end_marker_line_to_delete = marker_end_line

            editor.markerDelete(_start_marker_line_to_delete,
                                MARK_HIDELINESBEGIN)
            editor.markerDelete(_start_marker_line_to_delete,
                                MARK_HIDELINESUNDERLINE)
            editor.markerDelete(_end_marker_line_to_delete, MARK_HIDELINESEND)

        else:
            return

    editor.hideLines(start_line, end_line)
    editor.markerAdd(marker_start_line, MARK_HIDELINESBEGIN)
    editor.markerAdd(marker_start_line, MARK_HIDELINESUNDERLINE)
    editor.markerAdd(marker_end_line, MARK_HIDELINESEND)
    editor.gotoLine(marker_start_line)