def mousePressEvent(self, event): if event.button() == Qt.RightButton: # Rewrite the mouse event to a left button event so the cursor is # moved to the location of the pointer. event = QMouseEvent(QEvent.MouseButtonPress, event.pos(), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier) HintedTextEdit.mousePressEvent(self, event)
def __init__(self, parent=None): hint = u"Extended description..." HintedTextEdit.__init__(self, hint, parent) self.extra_actions = [] self.setMinimumSize(QtCore.QSize(1, 1)) self.action_emit_shift_tab = add_action(self, "Shift Tab", self.emit_shift_tab, "Shift+tab") self.installEventFilter(self)
def mousePressEvent(self, event): if event.button() == Qt.RightButton: # Rewrite the mouse event to a left button event so the cursor is # moved to the location of the pointer. event = QMouseEvent(QEvent.MouseButtonPress, event.pos(), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier) HintedTextEdit.mousePressEvent(self, event)
def __init__(self, parent=None): hint = N_('Extended description...') HintedTextEdit.__init__(self, hint, parent) self.extra_actions = [] self.setMinimumSize(QtCore.QSize(1, 1)) self.action_emit_leave = add_action(self, 'Shift Tab', self.emit_leave, 'Shift+tab') self.installEventFilter(self)
def __init__(self, parent=None): hint = u'Extended description...' HintedTextEdit.__init__(self, hint, parent) self.extra_actions = [] self.setMinimumSize(QtCore.QSize(1, 1)) self.action_emit_shift_tab = add_action(self, 'Shift Tab', self.emit_shift_tab, 'Shift+tab') self.installEventFilter(self)
def context_menu(self): popup_menu = HintedTextEdit.createStandardContextMenu(self) # Select the word under the cursor. cursor = self.textCursor() cursor.select(QTextCursor.WordUnderCursor) self.setTextCursor(cursor) # Check if the selected word is misspelled and offer spelling # suggestions if it is. spell_menu = None if self.textCursor().hasSelection(): text = unicode(self.textCursor().selectedText()) if not self.spellcheck.check(text): spell_menu = QMenu(N_('Spelling Suggestions')) for word in self.spellcheck.suggest(text): action = SpellAction(word, spell_menu) self.connect(action, SIGNAL('correct'), self.correct) spell_menu.addAction(action) # Only add the spelling suggests to the menu if there are # suggestions. if len(spell_menu.actions()) > 0: popup_menu.addSeparator() popup_menu.addMenu(spell_menu) return popup_menu, spell_menu
def context_menu(self): popup_menu = HintedTextEdit.createStandardContextMenu(self) # Select the word under the cursor. cursor = self.textCursor() cursor.select(QTextCursor.WordUnderCursor) self.setTextCursor(cursor) # Check if the selected word is misspelled and offer spelling # suggestions if it is. spell_menu = None if self.textCursor().hasSelection(): text = ustr(self.textCursor().selectedText()) if not self.spellcheck.check(text): spell_menu = QMenu(N_('Spelling Suggestions')) for word in self.spellcheck.suggest(text): action = SpellAction(word, spell_menu) self.connect(action, SIGNAL('correct'), self.correct) spell_menu.addAction(action) # Only add the spelling suggests to the menu if there are # suggestions. if len(spell_menu.actions()) > 0: popup_menu.addSeparator() popup_menu.addMenu(spell_menu) return popup_menu, spell_menu
def keyPressEvent(self, event): if event.key() == Qt.Key_Up: cursor = self.textCursor() position = cursor.position() if position == 0: # The cursor is at the beginning of the line. # If we have selection then simply reset the cursor. # Otherwise, emit a signal so that the parent can # change focus. if cursor.hasSelection(): cursor.setPosition(0) self.setTextCursor(cursor) else: self.emit_leave() event.accept() return text_before = unicode(self.toPlainText())[:position] lines_before = text_before.count('\n') if lines_before == 0: # If we're on the first line, but not at the # beginning, then move the cursor to the beginning # of the line. if event.modifiers() & Qt.ShiftModifier: mode = QtGui.QTextCursor.KeepAnchor else: mode = QtGui.QTextCursor.MoveAnchor cursor.setPosition(0, mode) self.setTextCursor(cursor) event.accept() return elif event.key() == Qt.Key_Down: cursor = self.textCursor() position = cursor.position() all_text = unicode(self.toPlainText()) text_after = all_text[position:] lines_after = text_after.count('\n') if lines_after == 0: if event.modifiers() & Qt.ShiftModifier: mode = QtGui.QTextCursor.KeepAnchor else: mode = QtGui.QTextCursor.MoveAnchor cursor.setPosition(len(all_text), mode) self.setTextCursor(cursor) event.accept() return HintedTextEdit.keyPressEvent(self, event)
def keyPressEvent(self, event): if event.key() == Qt.Key_Up: cursor = self.textCursor() position = cursor.position() if position == 0: # The cursor is at the beginning of the line. # If we have selection then simply reset the cursor. # Otherwise, emit a signal so that the parent can # change focus. if cursor.hasSelection(): cursor.setPosition(0) self.setTextCursor(cursor) else: self.emit_leave() event.accept() return text_before = unicode(self.toPlainText())[:position] lines_before = text_before.count('\n') if lines_before == 0: # If we're on the first line, but not at the # beginning, then move the cursor to the beginning # of the line. if event.modifiers() & Qt.ShiftModifier: mode = QtGui.QTextCursor.KeepAnchor else: mode = QtGui.QTextCursor.MoveAnchor cursor.setPosition(0, mode) self.setTextCursor(cursor) event.accept() return elif event.key() == Qt.Key_Down: cursor = self.textCursor() position = cursor.position() all_text = unicode(self.toPlainText()) text_after = all_text[position:] lines_after = text_after.count('\n') if lines_after == 0: if event.modifiers() & Qt.ShiftModifier: mode = QtGui.QTextCursor.KeepAnchor else: mode = QtGui.QTextCursor.MoveAnchor cursor.setPosition(len(all_text), mode) self.setTextCursor(cursor) event.accept() return HintedTextEdit.keyPressEvent(self, event)
def keyPressEvent(self, event): if event.key() == Qt.Key_Up: cursor = self.textCursor() position = cursor.position() if position == 0: if cursor.hasSelection(): cursor.setPosition(0) self.setTextCursor(cursor) else: self.emit_shift_tab() event.accept() return text_before = unicode(self.toPlainText())[:position] lines_before = text_before.count("\n") if lines_before == 0: if event.modifiers() & Qt.ShiftModifier: mode = QtGui.QTextCursor.KeepAnchor else: mode = QtGui.QTextCursor.MoveAnchor cursor.setPosition(0, mode) self.setTextCursor(cursor) event.accept() return elif event.key() == Qt.Key_Down: cursor = self.textCursor() position = cursor.position() all_text = unicode(self.toPlainText()) text_after = all_text[position:] lines_after = text_after.count("\n") if lines_after == 0: if event.modifiers() & Qt.ShiftModifier: mode = QtGui.QTextCursor.KeepAnchor else: mode = QtGui.QTextCursor.MoveAnchor cursor.setPosition(len(all_text), mode) self.setTextCursor(cursor) event.accept() return HintedTextEdit.keyPressEvent(self, event)
def keyPressEvent(self, event): if event.key() == Qt.Key_Up: cursor = self.textCursor() position = cursor.position() if position == 0: if cursor.hasSelection(): cursor.setPosition(0) self.setTextCursor(cursor) else: self.emit_shift_tab() event.accept() return text_before = unicode(self.toPlainText())[:position] lines_before = text_before.count('\n') if lines_before == 0: if event.modifiers() & Qt.ShiftModifier: mode = QtGui.QTextCursor.KeepAnchor else: mode = QtGui.QTextCursor.MoveAnchor cursor.setPosition(0, mode) self.setTextCursor(cursor) event.accept() return elif event.key() == Qt.Key_Down: cursor = self.textCursor() position = cursor.position() all_text = unicode(self.toPlainText()) text_after = all_text[position:] lines_after = text_after.count('\n') if lines_after == 0: if event.modifiers() & Qt.ShiftModifier: mode = QtGui.QTextCursor.KeepAnchor else: mode = QtGui.QTextCursor.MoveAnchor cursor.setPosition(len(all_text), mode) self.setTextCursor(cursor) event.accept() return HintedTextEdit.keyPressEvent(self, event)
def __init__(self, hint, parent=None): HintedTextEdit.__init__(self, hint, parent) # Default dictionary based on the current locale. self.spellcheck = NorvigSpellCheck() self.highlighter = Highlighter(self.document(), self.spellcheck)
def __init__(self, hint, parent=None): HintedTextEdit.__init__(self, hint, parent) # Default dictionary based on the current locale. self.spellcheck = NorvigSpellCheck() self.highlighter = Highlighter(self.document(), self.spellcheck)