Python PyQt5.QtGui.QTextCursor() Examples
The following are 16 code examples for showing how to use PyQt5.QtGui.QTextCursor(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
PyQt5.QtGui
, or try the search function
.
Example 1
Project: Lector Author: BasioMeusPuga File: contentwidgets.py License: GNU General Public License v3.0 | 6 votes |
def generate_page_positions(self): self.verticalScrollBar().setValue(0) cursorEnd = QtGui.QTextCursor(self.document()) cursorEnd.movePosition(QtGui.QTextCursor.End) self.page_cursors = [] while True: cursorTopLeft = self.cursorForPosition( self.viewport().rect().topLeft()) cursorBottomLeft = self.cursorForPosition( self.viewport().rect().bottomLeft()) cursorBottomRight = self.cursorForPosition( self.viewport().rect().bottomRight()) self.page_cursors.append( (cursorTopLeft.position(), cursorBottomRight.position())) self.move_to_cursor(cursorBottomRight) # TODO # See if this requires a failsafe per number of iterations if cursorEnd.position() == cursorBottomRight.position(): break
Example 2
Project: Lector Author: BasioMeusPuga File: contentwidgets.py License: GNU General Public License v3.0 | 6 votes |
def set_page(self, originalCursor): required_position = originalCursor.position() if self.text_mode == 'flow': page_start = required_position if self.text_mode == 'singlePage': for count, i in enumerate(self.page_cursors): if i[0] <= required_position < i[1]: page_start = i[0] self.page_number = count break cursorGoTo = QtGui.QTextCursor(self.document()) cursorGoTo.setPosition(page_start) self.move_to_cursor(cursorGoTo)
Example 3
Project: Lector Author: BasioMeusPuga File: contentwidgets.py License: GNU General Public License v3.0 | 6 votes |
def turn_page(self, direction): self.page_number += direction if self.page_number in (-1, self.document().pageCount()): self.page_number = 0 self.common_functions.change_chapter(direction) self.create_pages() else: try: page_start = self.page_cursors[self.page_number][0] cursorGoTo = QtGui.QTextCursor(self.document()) cursorGoTo.setPosition(page_start) self.move_to_cursor(cursorGoTo) self.set_top_line_cleanly() except IndexError: pass
Example 4
Project: dcc Author: amimo File: sourcewindow.py License: Apache License 2.0 | 5 votes |
def __init__(self, parent=None, lines=[]): super(SourceDocument, self).__init__(parent) self.parent = parent self.setDefaultFont(QtGui.QFont('Monaco', 9, QtGui.QFont.Light)) cursor = QtGui.QTextCursor(self) # position=0x0 self.binding = {} # save the cursor position before each interesting element for section, L in lines: for t in L: if t[0] in BINDINGS_NAMES: self.binding[cursor.position()] = t cursor.insertText(t[1])
Example 5
Project: dcc Author: amimo File: sourcewindow.py License: Apache License 2.0 | 5 votes |
def cursor_position_changed(self): """Used to detect when cursor change position and to auto select word underneath it""" log.debug("cursor_position_changed") cur = self.textCursor() log.debug(cur.position()) log.debug(cur.selectedText()) if len(cur.selectedText()) == 0: cur.select(QtGui.QTextCursor.WordUnderCursor) self.setTextCursor(cur) # log.debug("cursor: %s" % cur.selectedText())
Example 6
Project: Lector Author: BasioMeusPuga File: settingsdialog.py License: GNU General Public License v3.0 | 5 votes |
def format_preview(self): # Needed to clear the preview of annotation ickiness cursor = QtGui.QTextCursor() self.previewView.setTextCursor(cursor) self.previewView.setText('Vidistine nuper imagines moventes bonas?') profile_index = self.main_window.bookToolBar.profileBox.currentIndex() current_profile = self.main_window.bookToolBar.profileBox.itemData( profile_index, QtCore.Qt.UserRole) if not current_profile: return font = current_profile['font'] self.foreground = current_profile['foreground'] background = current_profile['background'] font_size = current_profile['font_size'] self.previewView.setStyleSheet( "QTextEdit {{font-family: {0}; font-size: {1}px; color: {2}; background-color: {3}}}".format( font, font_size, self.foreground.name(), background.name())) block_format = QtGui.QTextBlockFormat() block_format.setAlignment(QtCore.Qt.AlignVCenter | QtCore.Qt.AlignHCenter) cursor = self.previewView.textCursor() while True: old_position = cursor.position() cursor.mergeBlockFormat(block_format) cursor.movePosition(QtGui.QTextCursor.NextBlock, 0, 1) new_position = cursor.position() if old_position == new_position: break
Example 7
Project: Lector Author: BasioMeusPuga File: contentwidgets.py License: GNU General Public License v3.0 | 5 votes |
def clear_annotations(self): if not self.are_we_doing_images_only: cursor = self.pw.textCursor() cursor.setPosition(0) cursor.movePosition( QtGui.QTextCursor.End, QtGui.QTextCursor.KeepAnchor) previewCharFormat = QtGui.QTextCharFormat() previewCharFormat.setFontStyleStrategy( QtGui.QFont.PreferAntialias) cursor.setCharFormat(previewCharFormat) cursor.clearSelection() self.pw.setTextCursor(cursor)
Example 8
Project: MARA_Framework Author: xtiankisutsa File: sourcewindow.py License: GNU Lesser General Public License v3.0 | 5 votes |
def __init__(self, parent=None, lines=[]): super(SourceDocument, self).__init__(parent) self.parent = parent self.setDefaultFont(QtGui.QFont('Monaco', 9, QtGui.QFont.Light)) cursor = QtGui.QTextCursor(self) # position=0x0 self.binding = {} # save the cursor position before each interesting element for section, L in lines: for t in L: if t[0] in BINDINGS_NAMES: self.binding[cursor.position()] = t cursor.insertText(t[1])
Example 9
Project: MARA_Framework Author: xtiankisutsa File: sourcewindow.py License: GNU Lesser General Public License v3.0 | 5 votes |
def cursor_position_changed(self): '''Used to detect when cursor change position and to auto select word underneath it''' androconf.debug("cursor_position_changed") cur = self.textCursor() androconf.debug(cur.position()) androconf.debug(cur.selectedText()) if len(cur.selectedText()) == 0: cur.select(QtGui.QTextCursor.WordUnderCursor) self.setTextCursor(cur) #androconf.debug("cursor: %s" % cur.selectedText())
Example 10
Project: urh Author: jopohl File: TextEditProtocolView.py License: GNU General Public License v3.0 | 5 votes |
def textCursor(self) -> QTextCursor: return super().textCursor()
Example 11
Project: QualCoder Author: ccbogel File: code_text.py License: MIT License | 5 votes |
def move_to_next_search_text(self): """ Push button pressed to move to next search text position. """ self.search_index += 1 if self.search_index == len(self.search_indices): self.search_index = 0 cur = self.ui.textEdit.textCursor() next_result = self.search_indices[self.search_index] # next_result is a tuple containing a dictonary of {name, id, fullltext, memo, owner, date} and char position and search string length if self.filename is None or self.filename['id'] != next_result[0]['id']: self.view_file(next_result[0]) cur.setPosition(next_result[1]) cur.setPosition(cur.position() + next_result[2], QtGui.QTextCursor.KeepAnchor) self.ui.textEdit.setTextCursor(cur) self.ui.pushButton_search_results.setText(str(self.search_index + 1) + " / " + str(len(self.search_indices)))
Example 12
Project: QualCoder Author: ccbogel File: code_text.py License: MIT License | 5 votes |
def unlight(self): """ Remove all text highlighting from current file. """ if self.sourceText is None: return cursor = self.ui.textEdit.textCursor() cursor.setPosition(0, QtGui.QTextCursor.MoveAnchor) cursor.setPosition(len(self.sourceText) - 1, QtGui.QTextCursor.KeepAnchor) cursor.setCharFormat(QtGui.QTextCharFormat())
Example 13
Project: QualCoder Author: ccbogel File: code_text.py License: MIT License | 5 votes |
def highlight(self): """ Apply text highlighting to current file. If no colour has been assigned to a code, those coded text fragments are coloured gray. Each code text item contains: fid, date, pos0, pos1, seltext, cid, status, memo, name, owner. """ if self.sourceText is not None: fmt = QtGui.QTextCharFormat() cursor = self.ui.textEdit.textCursor() # Add coding highlights codes = {x['cid']:x for x in self.codes} for item in self.code_text: cursor.setPosition(int(item['pos0']), QtGui.QTextCursor.MoveAnchor) cursor.setPosition(int(item['pos1']), QtGui.QTextCursor.KeepAnchor) color = codes.get(item['cid'],{}).get('color',"#F8E0E0") # default light red fmt.setBackground(QtGui.QBrush(QtGui.QColor(color))) # Highlight codes with memos - these are italicised if item['memo'] is not None and item['memo'] != "": fmt.setFontItalic(True) else: fmt.setFontItalic(False) fmt.setFontWeight(QtGui.QFont.Normal) cursor.setCharFormat(fmt) # Add annotation marks - these are in bold for note in self.annotations: if len(self.filename.keys()) > 0: # will be zero if using autocode and no file is loaded if note['fid'] == self.filename['id']: cursor.setPosition(int(note['pos0']), QtGui.QTextCursor.MoveAnchor) cursor.setPosition(int(note['pos1']), QtGui.QTextCursor.KeepAnchor) formatB = QtGui.QTextCharFormat() formatB.setFontWeight(QtGui.QFont.Bold) cursor.mergeCharFormat(formatB)
Example 14
Project: QualCoder Author: ccbogel File: code_text.py License: MIT License | 5 votes |
def eventFilter(self, receiver, event): #QtGui.QToolTip.showText(QtGui.QCursor.pos(), tip) if event.type() == QtCore.QEvent.ToolTip: helpEvent = QHelpEvent(event) cursor = QtGui.QTextCursor() cursor = receiver.cursorForPosition(helpEvent.pos()) pos = cursor.position() receiver.setToolTip("") displayText = "" # Occasional None type error if self.code_text is None: #Call Base Class Method to Continue Normal Event Processing return super(ToolTip_EventFilter, self).eventFilter(receiver, event) for item in self.code_text: if item['pos0'] <= pos and item['pos1'] >= pos: if displayText == "": displayText = item['name'] else: # Can have multiple codes on same selected area try: displayText += "\n" + item['name'] except Exception as e: msg = "Codes ToolTipEventFilter " + str(e) + ". Possible key error: " msg += str(item) + "\n" + self.code_text logger.error(msg) if displayText != "": receiver.setToolTip(displayText) #Call Base Class Method to Continue Normal Event Processing return super(ToolTip_EventFilter, self).eventFilter(receiver, event)
Example 15
Project: QualCoder Author: ccbogel File: view_av.py License: MIT License | 5 votes |
def unlight(self): """ Remove all text highlighting from current file. """ if self.transcription is None or self.ui.textEdit.toPlainText() == "": return cursor = self.ui.textEdit.textCursor() cursor.setPosition(0, QtGui.QTextCursor.MoveAnchor) cursor.setPosition(len(self.transcription[1]) - 1, QtGui.QTextCursor.KeepAnchor) cursor.setCharFormat(QtGui.QTextCharFormat())
Example 16
Project: QualCoder Author: ccbogel File: view_av.py License: MIT License | 5 votes |
def eventFilter(self, receiver, event): #QtGui.QToolTip.showText(QtGui.QCursor.pos(), tip) if event.type() == QtCore.QEvent.ToolTip: helpEvent = QHelpEvent(event) cursor = QtGui.QTextCursor() cursor = receiver.cursorForPosition(helpEvent.pos()) pos = cursor.position() receiver.setToolTip("") text = "" # occasional None type error if self.code_text is None: #Call Base Class Method to Continue Normal Event Processing return super(ToolTip_EventFilter, self).eventFilter(receiver, event) for item in self.code_text: if item['pos0'] <= pos and item['pos1'] >= pos: #print(item) try: if text != "": text = text + "\n" text += item['name'] # += as can have multiple codes on same position if item['avid'] is not None: text += " [" + msecs_to_mins_and_secs(item['av_pos0']) text += " - " + msecs_to_mins_and_secs(item['av_pos1']) + "]" except Exception as e: msg = "Codes ToolTipEventFilter " + str(e) + ". Possible key error: " msg += str(item) + "\n" + str(self.code_text) logger.error(msg) if text != "": receiver.setToolTip(text) #Call Base Class Method to Continue Normal Event Processing return super(ToolTip_EventFilter, self).eventFilter(receiver, event)