Example #1
0
    def doTextEdit(self, url, setCursor=False):
        """Process a textedit link and either highlight
           the corresponding source code or set the 
           cursor to it.
        """
        t = textedit.link(url)
        # Only process textedit links
        if not t:
            return False
        filename = util.normpath(t.filename)
        doc = self.document(filename, setCursor)
        if doc:
            cursor = QTextCursor(doc)
            b = doc.findBlockByNumber(t.line - 1)
            p = b.position() + t.column
            cursor.setPosition(p)
            cursors = pointandclick.positions(cursor)
            # Do highlighting if the document is active
            if cursors and doc == self.mainwindow().currentDocument():
                import viewhighlighter

                view = self.mainwindow().currentView()
                viewhighlighter.highlighter(view).highlight(self._highlightFormat, cursors, 2, 0)
            # set the cursor and bring the document to front
            if setCursor:
                mainwindow = self.mainwindow()
                mainwindow.setTextCursor(cursor)
                import widgets.blink

                widgets.blink.Blinker.blink_cursor(mainwindow.currentView())
                self.mainwindow().setCurrentDocument(doc)
                mainwindow.activateWindow()
                mainwindow.currentView().setFocus()
        return True
Example #2
0
 def hideWidget(self):
     view = self.currentView()
     if view:
         viewhighlighter.highlighter(view).clear("search")
         self.hide()
         layout = widgets.borderlayout.BorderLayout.get(view)
         layout.removeWidget(self)
Example #3
0
    def slotLinkHovered(self, page, link):
        """Called when the mouse hovers a link.
        
        If the links points to the current editor document, the token(s) it points
        at are highlighted using a transparent selection color.
        
        The highlight shows for a few seconds but disappears when the mouse moves
        off the link or when the link is clicked.
        
        """
        self.view.surface().highlight(self._highlightMusicFormat,
                                      [(page, link.linkArea().normalized())],
                                      2000)
        self._highlightRange = None
        cursor = self._links.cursor(link)
        if not cursor or cursor.document() != self.parent().mainwindow(
        ).currentDocument():
            return

        # highlight token(s) at this cursor
        cursors = pointandclick.positions(cursor)
        if cursors:
            view = self.parent().mainwindow().currentView()
            viewhighlighter.highlighter(view).highlight(
                self._highlightFormat, cursors, 2, 5000)
Example #4
0
 def doTextEdit(self, url, setCursor=False):
     """Process a textedit link and either highlight
        the corresponding source code or set the 
        cursor to it.
     """
     t = textedit.link(url)
     # Only process textedit links
     if not t:
         return False
     doc = self.document(t.filename, setCursor)
     if doc:
         cursor = QtGui.QTextCursor(doc)
         b = doc.findBlockByNumber(t.line - 1)
         p = b.position() + t.column
         cursor.setPosition(p)
         cursors = pointandclick.positions(cursor)
         # Do highlighting if the document is active
         if cursors and doc == self.mainwindow().currentDocument():
             import viewhighlighter
             view = self.mainwindow().currentView()
             viewhighlighter.highlighter(view).highlight(
                 self._highlightFormat, cursors, 2, 0)
         # set the cursor and bring the document to front
         if setCursor:
             mainwindow = self.mainwindow()
             mainwindow.setTextCursor(cursor)
             import widgets.blink
             widgets.blink.Blinker.blink_cursor(mainwindow.currentView())
             self.mainwindow().setCurrentDocument(doc)
             mainwindow.activateWindow()
             mainwindow.currentView().setFocus()
     return True
Example #5
0
 def slotReplace(self):
     view = self.currentView()
     if view and self._positions:
         positions = [c.position() for c in self._positions]
         index = bisect.bisect_left(positions, view.textCursor().position())
         if index >= len(positions):
             index = 0
         if self.doReplace(self._positions[index]):
             viewhighlighter.highlighter(view).highlight("search", self._positions, 1)
             if index < len(positions) - 1:
                 view.setTextCursor(self._positions[index+1])
             else:
                 view.setTextCursor(self._positions[0])
             view.ensureCursorVisible()
Example #6
0
 def slotReplaceAll(self):
     view = self.currentView()
     if view:
         replaced = False
         cursors = self._positions
         if view.textCursor().hasSelection():
             cursors = [cursor for cursor in cursors if cursortools.contains(view.textCursor(), cursor)]
         view.textCursor().beginEditBlock()
         for cursor in cursors:
             if self.doReplace(cursor):
                 replaced = True
         view.textCursor().endEditBlock()
         if replaced:
             viewhighlighter.highlighter(view).highlight("search", self._positions, 1)
Example #7
0
 def hover(self, url):
     """actions when user set mouse over link"""
     t = textedit.link(url)
     if t:
         doc = self.document(t.filename)
         if doc and doc == self.mainwindow().currentDocument():
             cursor = QtGui.QTextCursor(doc)
             b = doc.findBlockByNumber(t.line - 1)
             p = b.position() + t.column
             cursor.setPosition(p)
             cursors = pointandclick.positions(cursor)
             if cursors:
                 import viewhighlighter
                 view = self.mainwindow().currentView()
                 viewhighlighter.highlighter(view).highlight(self._highlightFormat, cursors, 2, 5000)
Example #8
0
    def slotLinkHovered(self, page, link):
        """Called when the mouse hovers a link.
        If the links points to the current editor document, the token(s) it points
        at are highlighted using a transparent selection color.
        The highlight shows for a few seconds but disappears when the mouse moves
        off the link or when the link is clicked.
        """
        self.view.surface().highlight(self._highlightMusicFormat,
            [(page, link.linkArea().normalized())], 2000)
        self._highlightRange = None
        cursor = self._links.cursor(link)
        if not cursor or cursor.document() != self.parent().mainwindow().currentDocument():
            return

        # highlight token(s) at this cursor
        cursors = pointandclick.positions(cursor)
        if cursors:
            view = self.parent().mainwindow().currentView()
            viewhighlighter.highlighter(view).highlight(self._highlightFormat, cursors, 2, 5000)
Example #9
0
 def checkMatches(self):
     # see if there are matches
     view = self.mainwindow().currentView()
     cursor = view.textCursor()
     block = cursor.block()
     column = cursor.position() - block.position()
     tokens = tokeniter.Runner(block)
     source = None
     for token in tokens.forward_line():
         if token.pos <= column <= token.end:
             if isinstance(token, ly.lex.MatchStart):
                 source, match, other = tokens.forward(), ly.lex.MatchStart, ly.lex.MatchEnd
                 break
             elif isinstance(token, ly.lex.MatchEnd):
                 source, match, other = tokens.backward(), ly.lex.MatchEnd, ly.lex.MatchStart
                 break
         elif token.pos > column:
             break
     if source:
         # we've found a matcher item
         cursor1 = tokens.cursor()
         nest = 0
         for token2 in source:
             if isinstance(token2, other) and token2.matchname == token.matchname:
                 if nest == 0:
                     # we've found the matching item!
                     cursor2 = tokens.cursor()
                     hl = viewhighlighter.highlighter(view)
                     hl.highlight("match", (cursor1, cursor2), 2, 1000)
                     return
                 else:
                     nest -= 1
             elif isinstance(token2, match) and token2.matchname == token.matchname:
                 nest += 1
     hl = viewhighlighter.highlighter(view)
     hl.clear("match")
Example #10
0
 def highlighter(self):
     return viewhighlighter.highlighter(self.view())
Example #11
0
 def highlightingOff(self, view=None):
     """Hide the current search result positions."""
     if view is None:
         view = self.currentView()
     if view:
         viewhighlighter.highlighter(view).clear("search")
Example #12
0
 def highlightingOn(self, view=None):
     if view is None:
         view = self.currentView()
     if view:
         viewhighlighter.highlighter(view).highlight("search", self._positions, 1)
Example #13
0
 def highlighter(self):
     return viewhighlighter.highlighter(self.view())
Example #14
0
 def highlightingOff(self, view=None):
     if view is None:
         view = self.currentView()
     if view:
         viewhighlighter.highlighter(view).clear("search")
Example #15
0
 def slotSearchChanged(self):
     self.updatePositions()
     viewhighlighter.highlighter(self.currentView()).highlight("search", self._positions, 1)
Example #16
0
 def slotLinkHovered(self, page, link):
     """Called when the mouse hovers a link.
     
     If the links points to the current editor document, the token(s) it points
     at are highlighted using a transparent selection color.
     
     The highlight shows for a few seconds but disappears when the mouse moves
     off the link or when the link is clicked.
     
     """
     self.view.surface().highlight(self._highlightMusicFormat,
         [(page, link.linkArea().normalized())], 2000)
     self._highlightRange = None
     cursor = self._links.cursor(link)
     if not cursor or cursor.document() != self.parent().mainwindow().currentDocument():
         return
     
     # highlight token(s) at this cursor
     source = tokeniter.Source.fromCursor(cursor, True)
     for token in source.tokens:
         break
     else:
         return
     
     cur = source.cursor(token, end=0)
     cursors = [cur]
     
     # some heuristic to find the relevant range(s) the linked grob represents
     if isinstance(token, ly.lex.lilypond.Direction):
         # a _, - or ^ is found; find the next token
         for token in source:
             if not isinstance(token, (ly.lex.Space, ly.lex.Comment)):
                 break
     end = token.end + source.block.position()
     if token == '\\markup':
         # find the end of the markup expression
         depth = source.state.depth()
         for token in source:
             if source.state.depth() < depth:
                 end = token.end + source.block.position()
                 break
     elif token == '"':
         # find the end of the string
         for token in source:
             if isinstance(token, ly.lex.StringEnd):
                 end = token.end + source.block.position()
                 break
     elif isinstance(token, ly.lex.MatchStart):
         # find the end of slur, beam. ligature, phrasing slur, etc.
         name = token.matchname
         nest = 1
         for token in source:
             if isinstance(token, ly.lex.MatchEnd) and token.matchname == name:
                 nest -= 1
                 if nest == 0:
                     cursors.append(source.cursor(token))
                     break
             elif isinstance(token, ly.lex.MatchStart) and token.matchname == name:
                 nest += 1
                 
     cur.setPosition(end, QTextCursor.KeepAnchor)
     
     view = self.parent().mainwindow().currentView()
     viewhighlighter.highlighter(view).highlight(self._highlightFormat, cursors, 2, 5000)
Example #17
0
 def leave(self, url):
     """actions when user moves mouse off link"""
     import viewhighlighter
     view = self.mainwindow().currentView()
     viewhighlighter.highlighter(view).clear(self._highlightFormat)
Example #18
0
 def slotLinkLeft(self):
     """Called when the mouse moves off a previously highlighted link."""
     self.clearHighlighting()
     view = self.parent().mainwindow().currentView()
     viewhighlighter.highlighter(view).clear(self._highlightFormat)
Example #19
0
 def highlightingOff(self, view=None):
     if view is None:
         view = self.currentView()
     if view:
         viewhighlighter.highlighter(view).clear("search")
Example #20
0
 def slotLinkLeft(self):
     """Called when the mouse moves off a previously highlighted link."""
     self.clearHighlighting()
     view = self.parent().mainwindow().currentView()
     viewhighlighter.highlighter(view).clear(self._highlightFormat)
Example #21
0
 def highlightingOn(self, view=None):
     """Show the current search result positions."""
     if view is None:
         view = self.currentView()
     if view:
         viewhighlighter.highlighter(view).highlight("search", self._positions, 1)
Example #22
0
 def unHighlight(self):
     import viewhighlighter
     view = self.mainwindow().currentView()
     viewhighlighter.highlighter(view).clear(self._highlightFormat)
Example #23
0
    def unHighlight(self):
        import viewhighlighter

        view = self.mainwindow().currentView()
        viewhighlighter.highlighter(view).clear(self._highlightFormat)
Example #24
0
 def highlightingOn(self, view=None):
     if view is None:
         view = self.currentView()
     if view:
         viewhighlighter.highlighter(view).highlight(
             "search", self._positions, 1)