Example #1
0
File: base.py Project: Pyke75/ga
 def __duplicate_line_or_selection(self, after_current_line=True):
     """Duplicate current line or selected text"""
     cursor = self.textCursor()
     cursor.beginEditBlock()
     orig_sel = start_pos, end_pos = (cursor.selectionStart(),
                                      cursor.selectionEnd())
     if unicode(cursor.selectedText()):
         cursor.setPosition(end_pos)
         # Check if end_pos is at the start of a block: if so, starting
         # changes from the previous block
         cursor.movePosition(QTextCursor.StartOfBlock,
                             QTextCursor.KeepAnchor)
         if not unicode(cursor.selectedText()):
             cursor.movePosition(QTextCursor.PreviousBlock)
             end_pos = cursor.position()
         
     cursor.setPosition(start_pos)
     cursor.movePosition(QTextCursor.StartOfBlock)
     while cursor.position() <= end_pos:
         cursor.movePosition(QTextCursor.EndOfBlock, QTextCursor.KeepAnchor)
         if cursor.atEnd():
             cursor_temp = QTextCursor(cursor)
             cursor_temp.clearSelection()
             cursor_temp.insertText(self.get_line_separator())
             break
         cursor.movePosition(QTextCursor.NextBlock, QTextCursor.KeepAnchor)            
     text = cursor.selectedText()
     cursor.clearSelection()
     
     if not after_current_line:
         # Moving cursor before current line/selected text
         cursor.setPosition(start_pos)
         cursor.movePosition(QTextCursor.StartOfBlock)
         orig_sel = (orig_sel[0]+len(text), orig_sel[1]+len(text))
     
     cursor.insertText(text)
     cursor.endEditBlock()
     cursor.setPosition(orig_sel[0])
     cursor.setPosition(orig_sel[1], QTextCursor.KeepAnchor)
     self.setTextCursor(cursor)
Example #2
0
File: base.py Project: jsantoul/ga
 def show_calltip(self,
                  title,
                  text,
                  color='#2D62FF',
                  at_line=None,
                  at_position=None):
     """Show calltip"""
     if text is None or len(text) == 0:
         return
     # Saving cursor position:
     if at_position is None:
         at_position = self.get_position('cursor')
     self.calltip_position = at_position
     # Preparing text:
     weight = 'bold' if self.calltip_font.bold() else 'normal'
     size = self.calltip_font.pointSize()
     family = self.calltip_font.family()
     format1 = '<div style=\'font-size: %spt; color: %s\'>' % (size, color)
     format2 = '<hr><div style=\'font-family: "%s"; font-size: %spt; font-weight: %s\'>' % (
         family, size, weight)
     if isinstance(text, list):
         text = "\n    ".join(text)
     text = text.replace('\n', '<br>')
     if len(text) > self.calltip_size:
         text = text[:self.calltip_size] + " ..."
     tiptext = format1 + ('<b>%s</b></div>' % title) \
               + format2 + text + "</div>"
     # Showing tooltip at cursor position:
     cx, cy = self.get_coordinates('cursor')
     if at_line is not None:
         cx = 5
         cursor = QTextCursor(self.document().findBlockByNumber(at_line -
                                                                1))
         cy = self.cursorRect(cursor).top()
     point = self.mapToGlobal(QPoint(cx, cy))
     point.setX(point.x() + self.get_linenumberarea_width())
     QToolTip.showText(point, tiptext)
Example #3
0
File: base.py Project: jsantoul/ga
    def __duplicate_line_or_selection(self, after_current_line=True):
        """Duplicate current line or selected text"""
        cursor = self.textCursor()
        cursor.beginEditBlock()
        orig_sel = start_pos, end_pos = (cursor.selectionStart(),
                                         cursor.selectionEnd())
        if unicode(cursor.selectedText()):
            cursor.setPosition(end_pos)
            # Check if end_pos is at the start of a block: if so, starting
            # changes from the previous block
            cursor.movePosition(QTextCursor.StartOfBlock,
                                QTextCursor.KeepAnchor)
            if not unicode(cursor.selectedText()):
                cursor.movePosition(QTextCursor.PreviousBlock)
                end_pos = cursor.position()

        cursor.setPosition(start_pos)
        cursor.movePosition(QTextCursor.StartOfBlock)
        while cursor.position() <= end_pos:
            cursor.movePosition(QTextCursor.EndOfBlock, QTextCursor.KeepAnchor)
            if cursor.atEnd():
                cursor_temp = QTextCursor(cursor)
                cursor_temp.clearSelection()
                cursor_temp.insertText(self.get_line_separator())
                break
            cursor.movePosition(QTextCursor.NextBlock, QTextCursor.KeepAnchor)
        text = cursor.selectedText()
        cursor.clearSelection()

        if not after_current_line:
            # Moving cursor before current line/selected text
            cursor.setPosition(start_pos)
            cursor.movePosition(QTextCursor.StartOfBlock)
            orig_sel = (orig_sel[0] + len(text), orig_sel[1] + len(text))

        cursor.insertText(text)
        cursor.endEditBlock()
        cursor.setPosition(orig_sel[0])
        cursor.setPosition(orig_sel[1], QTextCursor.KeepAnchor)
        self.setTextCursor(cursor)
Example #4
0
File: mixins.py Project: Pyke75/ga
 def _is_separator(cursor):
     cursor0 = QTextCursor(cursor)
     cursor0.select(QTextCursor.BlockUnderCursor)
     text = unicode(cursor0.selectedText())
     return len(text.strip()) == 0 or text.lstrip()[0] == '#'