Ejemplo n.º 1
0
 def addMergeCursor(self, cursor):
     """Only can add new cursors, if the cursor has selection then try to merge with others
     """
     firstCursor = not bool(self.cursors)
     if cursor.hasSelection():
         newCursor = None
         removeCursor = None
         new_begin, new_end = cursor.selectionStart(), cursor.selectionEnd()
         for c in self.cursors:
             c_begin, c_end = c.selectionStart(), c.selectionEnd()
             if c_begin <= new_begin <= new_end <= c_end:
                 return
             elif c_begin <= new_begin <= c_end:
                 # Extiende por detras
                 newCursor = QtGui.QTextCursor(self.editor.document())
                 if c.position() > new_begin:
                     newCursor.setPosition(c_begin)
                     newCursor.setPosition(new_end, QtGui.QTextCursor.KeepAnchor)
                 else:
                     newCursor.setPosition(new_end)
                     newCursor.setPosition(c.position(), QtGui.QTextCursor.KeepAnchor)
                 removeCursor = c
                 break
             elif c_begin <= new_end <= c_end:
                 #Extiende por el frente
                 newCursor = QtGui.QTextCursor(self.editor.document())
                 if c.position() < new_end:
                     newCursor.setPosition(c_end)
                     newCursor.setPosition(new_begin, QtGui.QTextCursor.KeepAnchor)
                 else:
                     newCursor.setPosition(new_begin)
                     newCursor.setPosition(c.position(), QtGui.QTextCursor.KeepAnchor)
                 removeCursor = c
                 break
             elif new_begin <= c_begin <= c_end <= new_end:
                 #Contiene al cursor
                 newCursor = cursor
                 removeCursor = c
                 break
         if newCursor is not None:
             self.cursors.remove(removeCursor)
             self.addMergeCursor(newCursor)
         else:
             position = bisect_key(self.cursors, cursor, lambda cursor: cursor.position())
             self.cursors.insert(position, cursor)
     else:
         for c in self.cursors:
             begin, end = c.selectionStart(), c.selectionEnd()
             if begin <= cursor.position() <= end:
                 return
         position = bisect_key(self.cursors, cursor, lambda cursor: cursor.position())
         self.cursors.insert(position, cursor)
     if firstCursor:
         #Ponemos el ultimo cursor agregado sin seleccion para que no moleste
         lastCursor = QtGui.QTextCursor(self.cursors[-1])
         lastCursor.clearSelection()
         self.editor.setTextCursor(lastCursor)
         self.editor.application.setOverrideCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
         self.editor.modeChanged.emit()
     self.highlightEditor()
Ejemplo n.º 2
0
 def on_sourceModel_rowsInserted(self, parent, start, end):
     for i in xrange(start, end + 1):
         sIndex = self.__sourceModel.index(i, 0, parent)
         if self.filterAcceptsRow(i, parent):
             position = bisect_key(self.__indexMap, sIndex, lambda index: self.comparableValue(index))
             self.beginInsertRows(QtCore.QModelIndex(), position, position)
             self.__indexMap.insert(position, sIndex)
             self.endInsertRows()
Ejemplo n.º 3
0
 def removeBreakCursor(self, cursor):
     #TODO: Hay cosas que se pueden simplificar pero hoy no me da el cerebro
     if cursor.hasSelection():
         newCursors = []
         removeCursor = None
         new_begin, new_end = cursor.selectionStart(), cursor.selectionEnd()
         for c in self.cursors:
             c_begin, c_end = c.selectionStart(), c.selectionEnd()
             if new_begin <= c_begin <= c_end <= new_end:
                 #Contiene al cursor, hay que quitarlo
                 removeCursor = c
                 break
             elif (c_begin < new_begin < new_end < c_end):
                 #Recortar
                 if c.position() < new_begin:
                     newCursors.append(
                         self.editor.newCursorAtPosition(new_begin, c_begin))
                     newCursors.append(
                         self.editor.newCursorAtPosition(c_end, new_end))    
                 else:
                     newCursors.append(
                         self.editor.newCursorAtPosition(c_begin, new_begin))
                     newCursors.append(
                         self.editor.newCursorAtPosition(new_end, c_end))
                 removeCursor = c
                 break
             elif c_begin <= new_begin <= c_end:
                 #Recorta por detras, quitar el actual y agregar uno con la seleccion mas chica
                 if c.position() > new_begin:
                     newCursors.append(
                         self.editor.newCursorAtPosition(c_begin, new_begin))
                 else:
                     newCursors.append(
                         self.editor.newCursorAtPosition(new_begin, c.position()))
                 removeCursor = c
                 break
             elif c_begin <= new_end <= c_end:
                 #Recorta por el frente, quitra el actual y agregar uno con la seleccion mas chica
                 if c.position() < new_end:
                     newCursors.append(
                         self.editor.newCursorAtPosition(c_end, new_end))
                 else:
                     newCursors.append(
                         self.editor.newCursorAtPosition(new_end, c.position()))
                 removeCursor = c
                 break
         if removeCursor is not None:
             self.cursors.remove(removeCursor)
         for cursors in newCursors:
             position = bisect_key(self.cursors, cursors, lambda cursor: cursor.position())
             self.cursors.insert(position, cursors)
     else:
         #Solo puedo quitar cursores que no tengan seleccion osea que sean un clic :)
         for c in self.cursors:
             begin, end = c.selectionStart(), c.selectionEnd()
             if not c.hasSelection() and c.position() == cursor.position():
                 self.cursors.remove(c)
                 break
Ejemplo n.º 4
0
 def on_sourceModel_rowsInserted(self, parent, start, end):
     for i in xrange(start, end + 1):
         sIndex = self.__sourceModel.index(i, 0, parent)
         if self.filterAcceptsRow(i, parent):
             position = bisect_key(
                 self.__indexMap, sIndex,
                 lambda index: self.comparableValue(index))
             self.beginInsertRows(QtCore.QModelIndex(), position, position)
             self.__indexMap.insert(position, sIndex)
             self.endInsertRows()
Ejemplo n.º 5
0
 def on_sourceModel_dataChanged(self, topLeft, bottomRight):
     #Cambiaron los datos tengo que ponerlos en funcion del comparableValue
     if topLeft in self.__indexMap:
         self.beginRemoveRows(QtCore.QModelIndex(), self.__indexMap.index(topLeft), self.__indexMap.index(topLeft))
         self.__indexMap.remove(topLeft)
         self.endRemoveRows()
         position = bisect_key(self.__indexMap, topLeft, lambda index: self.comparableValue(index))
         self.beginInsertRows(QtCore.QModelIndex(), position, position)
         self.__indexMap.insert(position, topLeft)
         self.endInsertRows()
Ejemplo n.º 6
0
 def toggleBookmark(self, cursor):
     if cursor in self.bookmarks:
         index = self.bookmarks.index(cursor)
         self.beginRemoveRows(QtCore.QModelIndex(), index, index)
         self.bookmarks.remove(cursor)
         self.endRemoveRows()
     else:
         position = bisect_key(self.bookmarks, cursor, lambda cursor: cursor.position())
         self.beginInsertRows(QtCore.QModelIndex(), position, position)
         self.bookmarks.insert(position, cursor)
         self.endInsertRows()
Ejemplo n.º 7
0
 def on_sourceModel_dataChanged(self, topLeft, bottomRight):
     #Cambiaron los datos tengo que ponerlos en funcion del comparableValue
     if topLeft in self.__indexMap:
         self.beginRemoveRows(QtCore.QModelIndex(),
                              self.__indexMap.index(topLeft),
                              self.__indexMap.index(topLeft))
         self.__indexMap.remove(topLeft)
         self.endRemoveRows()
         position = bisect_key(self.__indexMap, topLeft,
                               lambda index: self.comparableValue(index))
         self.beginInsertRows(QtCore.QModelIndex(), position, position)
         self.__indexMap.insert(position, topLeft)
         self.endInsertRows()
Ejemplo n.º 8
0
 def appendTheme(self, theme):
     index = bisect_key(self.themes, theme, lambda t: t.name)
     self.beginInsertRows(QtCore.QModelIndex(), index, index)
     self.themes.insert(index, theme)
     self.endInsertRows()
Ejemplo n.º 9
0
 def removeBreakCursor(self, cursor):
     #TODO: Hay cosas que se pueden simplificar pero hoy no me da el cerebro
     if cursor.hasSelection():
         newCursors = []
         removeCursor = None
         new_begin, new_end = cursor.selectionStart(), cursor.selectionEnd()
         for c in self.cursors:
             c_begin, c_end = c.selectionStart(), c.selectionEnd()
             if new_begin <= c_begin <= c_end <= new_end:
                 #Contiene al cursor, hay que quitarlo
                 removeCursor = c
                 break
             elif (c_begin < new_begin < new_end < c_end):
                 #Recortar
                 newCursor = QtGui.QTextCursor(self.editor.document())
                 if c.position() < new_begin:
                     newCursor.setPosition(new_begin)
                     newCursor.setPosition(c_begin,
                                           QtGui.QTextCursor.KeepAnchor)
                     newCursors.append(newCursor)
                     newCursor = QtGui.QTextCursor(self.editor.document())
                     newCursor.setPosition(c_end)
                     newCursor.setPosition(new_end,
                                           QtGui.QTextCursor.KeepAnchor)
                     newCursors.append(newCursor)
                 else:
                     newCursor.setPosition(c_begin)
                     newCursor.setPosition(new_begin,
                                           QtGui.QTextCursor.KeepAnchor)
                     newCursors.append(newCursor)
                     newCursor = QtGui.QTextCursor(self.editor.document())
                     newCursor.setPosition(new_end)
                     newCursor.setPosition(c_end,
                                           QtGui.QTextCursor.KeepAnchor)
                     newCursors.append(newCursor)
                 removeCursor = c
                 break
             elif c_begin <= new_begin <= c_end:
                 #Recorta por detras, quitar el actual y agregar uno con la seleccion mas chica
                 newCursor = QtGui.QTextCursor(self.editor.document())
                 if c.position() > new_begin:
                     newCursor.setPosition(c_begin)
                     newCursor.setPosition(new_begin,
                                           QtGui.QTextCursor.KeepAnchor)
                 else:
                     newCursor.setPosition(new_begin)
                     newCursor.setPosition(c.position(),
                                           QtGui.QTextCursor.KeepAnchor)
                 newCursors.append(newCursor)
                 removeCursor = c
                 break
             elif c_begin <= new_end <= c_end:
                 #Recorta por el frente, quitra el actual y agregar uno con la seleccion mas chica
                 newCursor = QtGui.QTextCursor(self.editor.document())
                 if c.position() < new_end:
                     newCursor.setPosition(c_end)
                     newCursor.setPosition(new_end,
                                           QtGui.QTextCursor.KeepAnchor)
                 else:
                     newCursor.setPosition(new_end)
                     newCursor.setPosition(c.position(),
                                           QtGui.QTextCursor.KeepAnchor)
                 newCursors.append(newCursor)
                 removeCursor = c
                 break
         if removeCursor is not None:
             self.cursors.remove(removeCursor)
         for cursors in newCursors:
             position = bisect_key(self.cursors, cursors,
                                   lambda cursor: cursor.position())
             self.cursors.insert(position, cursors)
     else:
         #Solo puedo quitar cursores que no tengan seleccion osea que sean un clic :)
         for c in self.cursors:
             begin, end = c.selectionStart(), c.selectionEnd()
             if not c.hasSelection() and c.position() == cursor.position():
                 self.cursors.remove(c)
                 break
     self.highlightEditor()
Ejemplo n.º 10
0
 def addMergeCursor(self, cursor):
     """Only can add new cursors, if the cursor has selection then try to merge with others
     """
     firstCursor = not bool(self.cursors)
     if cursor.hasSelection():
         newCursor = None
         removeCursor = None
         new_begin, new_end = cursor.selectionStart(), cursor.selectionEnd()
         for c in self.cursors:
             c_begin, c_end = c.selectionStart(), c.selectionEnd()
             if c_begin <= new_begin <= new_end <= c_end:
                 return
             elif c_begin <= new_begin <= c_end:
                 # Extiende por detras
                 newCursor = QtGui.QTextCursor(self.editor.document())
                 if c.position() > new_begin:
                     newCursor.setPosition(c_begin)
                     newCursor.setPosition(new_end,
                                           QtGui.QTextCursor.KeepAnchor)
                 else:
                     newCursor.setPosition(new_end)
                     newCursor.setPosition(c.position(),
                                           QtGui.QTextCursor.KeepAnchor)
                 removeCursor = c
                 break
             elif c_begin <= new_end <= c_end:
                 #Extiende por el frente
                 newCursor = QtGui.QTextCursor(self.editor.document())
                 if c.position() < new_end:
                     newCursor.setPosition(c_end)
                     newCursor.setPosition(new_begin,
                                           QtGui.QTextCursor.KeepAnchor)
                 else:
                     newCursor.setPosition(new_begin)
                     newCursor.setPosition(c.position(),
                                           QtGui.QTextCursor.KeepAnchor)
                 removeCursor = c
                 break
             elif new_begin <= c_begin <= c_end <= new_end:
                 #Contiene al cursor
                 newCursor = cursor
                 removeCursor = c
                 break
         if newCursor is not None:
             self.cursors.remove(removeCursor)
             self.addMergeCursor(newCursor)
         else:
             position = bisect_key(self.cursors, cursor,
                                   lambda cursor: cursor.position())
             self.cursors.insert(position, cursor)
     else:
         for c in self.cursors:
             begin, end = c.selectionStart(), c.selectionEnd()
             if begin <= cursor.position() <= end:
                 return
         position = bisect_key(self.cursors, cursor,
                               lambda cursor: cursor.position())
         self.cursors.insert(position, cursor)
     if firstCursor:
         #Ponemos el ultimo cursor agregado sin seleccion para que no moleste
         lastCursor = QtGui.QTextCursor(self.cursors[-1])
         lastCursor.clearSelection()
         self.editor.setTextCursor(lastCursor)
         self.editor.application.setOverrideCursor(
             QtGui.QCursor(QtCore.Qt.ArrowCursor))
         self.editor.modeChanged.emit()
     self.highlightEditor()
Ejemplo n.º 11
0
 def previousBookmark(self, cursor):
     if self.bookmarks:
         position = bisect_key(self.bookmarks, cursor, lambda cursor: cursor.position()) % len(self.bookmarks)
         return self.bookmarks[position - (cursor in self.bookmarks and 2 or 1)]
Ejemplo n.º 12
0
 def nextBookmark(self, cursor):
     if self.bookmarks:
         position = bisect_key(self.bookmarks, cursor, lambda cursor: cursor.position()) % len(self.bookmarks)
         return self.bookmarks[position]
Ejemplo n.º 13
0
 def appendTheme(self, theme):
     index = bisect_key(self.themes, theme, lambda t: t.name)
     self.beginInsertRows(QtCore.QModelIndex(), index, index)
     self.themes.insert(index, theme)
     self.endInsertRows()