コード例 #1
0
 def onTimerMiddleButton(self):
     middleButton = windll.user32.GetKeyState(VK_MBUTTON)
     if self.middleButton != middleButton and (middleButton -
                                               (middleButton & 1)) != 0:
         x, y = GetCursorPos()
         hFore = windll.user32.GetForegroundWindow()
         hPoint = windll.user32.WindowFromPoint(x, y)
         if hPoint == hFore:
             hPoint = windll.user32.ChildWindowFromPoint(hFore, x, y)
         hSelf = self.windowHandle
         x0, y0, x1, y1 = GetWindowRect(hPoint)
         if x0 <= x <= x1 and y0 <= y <= y1 and hSelf == hFore:
             editor.grabFocus()
             pos = editor.positionFromPoint(x - x0, y - y0)
             iLineClick = editor.lineFromPosition(pos)
             iStart = editor.getSelectionStart()
             iEnd = editor.getSelectionEnd()
             iLineStart = editor.lineFromPosition(iStart)
             iLineEnd = editor.lineFromPosition(iEnd)
             if iStart != iEnd and iLineStart <= iLineClick <= iLineEnd:
                 self.runCodeAtCursor(moveCursor=False,
                                      onlyInsideCodeLines=True)
             elif 0 <= pos < editor.getLength():
                 self.runCodeAtCursor(moveCursor=False,
                                      nonSelectedLine=iLineClick,
                                      onlyInsideCodeLines=True)
     self.middleButton = middleButton
     threading.Timer(self.tTimerMiddleButton,
                     self.onTimerMiddleButton).start()
コード例 #2
0
def match_found(m):
    _m = m.span()
    if IGNORE_0_LENGTH_MATCHES and (_m[0] == _m[1]):
        return

    global IS_ODD
    global MATCH_POSITIONS
    global NO_MATCH_FOUND

    _match_positions = []
    if REPORT_MATCHES:
        console.show()
        editor.grabFocus()
        console.write('Match:{} = {}\n'.format(_m, editor1.getTextRange(*_m)))

    if m.lastindex > 0:
        editor1.setIndicatorCurrent(8)
        editor1.indicatorFillRange(m.span(0)[0], m.span(0)[1] - m.span(0)[0])
        _match_positions.append(m.span())
        for i in range(1, m.lastindex + 1):
            if (m.span(i)[0] != m.span(0)[0]) or (m.span(i)[1] != m.span(0)[1]):
                editor1.setIndicatorCurrent(9 if IS_ODD else 10)
                editor1.indicatorFillRange(m.span(i)[0], m.span(i)[1] - m.span(i)[0])

                IS_ODD = not IS_ODD
                if REPORT_MATCHES:
                    _textrange = editor1.getTextRange(*m.span(i)) if -1 not in m.span(i) else ''
                    console.write('  SubMatch:{} = {}\n'.format(m.span(i), _textrange))

    else:
        editor1.setIndicatorCurrent(9 if IS_ODD else 10)
        editor1.indicatorFillRange(_m[0], _m[1] - _m[0])

        IS_ODD = not IS_ODD
        _match_positions.append(m.span())

    MATCH_POSITIONS[CURRENT_BUFFER_ID].extend(_match_positions)

    NO_MATCH_FOUND = False
コード例 #3
0
def match_found(m):
    _m = m.span()
    if IGNORE_0_LENGTH_MATCHES and (_m[0] == _m[1]):
        return

    global IS_ODD
    global MATCH_POSITIONS
    global NO_MATCH_FOUND

    _match_positions = []
    if REPORT_MATCHES:
        console.show()
        editor.grabFocus()
        console.write('Match:{} = {}\n'.format(_m, editor1.getTextRange(*_m)))

    if m.lastindex > 0:
        editor1.setIndicatorCurrent(8)
        editor1.indicatorFillRange(m.span(0)[0], m.span(0)[1] - m.span(0)[0])
        _match_positions.append(m.span())
        for i in range(1, m.lastindex + 1):
            if (m.span(i)[0] != m.span(0)[0]) or (m.span(i)[1] != m.span(0)[1]):
                editor1.setIndicatorCurrent(9 if IS_ODD else 10)
                editor1.indicatorFillRange(m.span(i)[0], m.span(i)[1] - m.span(i)[0])

                IS_ODD = not IS_ODD
                if REPORT_MATCHES:
                    _textrange = editor1.getTextRange(*m.span(i)) if -1 not in m.span(i) else ''
                    console.write('  SubMatch:{} = {}\n'.format(m.span(i), _textrange))

    else:
        editor1.setIndicatorCurrent(9 if IS_ODD else 10)
        editor1.indicatorFillRange(_m[0], _m[1] - _m[0])

        IS_ODD = not IS_ODD
        _match_positions.append(m.span())

    MATCH_POSITIONS[CURRENT_BUFFER_ID].extend(_match_positions)

    NO_MATCH_FOUND = False
コード例 #4
0
    def __init__(self,
                 externalPython=None,
                 matplotlib_eventHandler=True,
                 cellHighlight=True,
                 popupForUnselectedVariable=True,
                 popupForSelectedExpression=False,
                 mouseDwellTime=200):
        '''Initializes PyPadPlusPlus to prepare Notepad++
        for interactive Python development'''
        console.show()
        editor.grabFocus()
        self.windowHandle = windll.user32.GetForegroundWindow()

        sys.stdout = PseudoFileOut(Npp.console.write)
        sys.stderr = PseudoFileOut(Npp.console.writeError)
        sys.stdout.outp = PseudoFileOut(Npp.console.write)

        self.matplotlib_eventHandler = matplotlib_eventHandler
        self.matplotlib_enabled = False
        self.popupForUnselectedVariable = popupForUnselectedVariable
        self.popupForSelectedExpression = popupForSelectedExpression
        self.mouseDwellTime = mouseDwellTime

        self.externalPython = bool(externalPython)
        if self.externalPython:
            from . import pyPadHost
            self.interp = pyPadHost.interpreter(externalPython,
                                                outBuffer=self.outBuffer)
        else:
            from . import pyPadClient
            self.interp = pyPadClient.interpreter()

        if cellHighlight:
            self.lexer = EnhancedPythonLexer()
            self.lexer.main()
        else:
            self.lexer = None

        self.thread = None
        self.threadMarker = None
        self.bufferActive = 1
        self.delayedMarker = False
        self.activeCalltip = None
        editor.setTargetStart(0)
        self.specialMarkers = None
        self.bufferMarkerAction = {}
        self.lastActiveBufferID = -1

        # Marker
        self.markerWidth = 3
        editor.setMarginWidthN(3, self.markerWidth)
        editor.setMarginMaskN(3, (256 + 128 + 64) * (1 + 2**3 + 2**6))
        self.markers = {}
        self.m_active, self.m_error, self.m_finish = [
            6 + 3 * i for i in [0, 1, 2]
        ]
        self.preCalculateMarkers()
        for iMarker in self.m_active, self.m_error, self.m_finish:
            self.drawMarker(iMarker)

        self.setCallbacks()

        editor.callTipSetBack((255, 255, 225))
        editor.autoCSetSeparator(ord('\t'))
        editor.autoCSetIgnoreCase(False)
        editor.autoCSetCaseInsensitiveBehaviour(False)
        editor.autoCSetCancelAtStart(False)
        editor.autoCSetDropRestOfWord(False)

        console.clear()
        console.editor.setReadOnly(0)

        self.tTimerFlush = 0.15
        self.tTimerMiddleButton = 0.1
        self.middleButton = 0

        self.bufferActive = 0
        self.onTimerFlush(
        )  # start periodic timer to check output of subprocess
        self.onTimerMiddleButton(
        )  # start periodic timer to check state of middleButton