avoid renaming completer_, as add-ons depend on it

This commit is contained in:
Damien Elmes 2020-05-08 18:17:57 +10:00
parent c02716ccd8
commit 7078415405
2 changed files with 25 additions and 20 deletions

View File

@ -1,6 +1,8 @@
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from __future__ import annotations
import re
from aqt import gui_hooks
@ -8,6 +10,7 @@ from aqt.qt import *
class TagEdit(QLineEdit):
completer: Union[QCompleter, TagCompleter]
lostFocus = pyqtSignal()
@ -18,12 +21,12 @@ class TagEdit(QLineEdit):
self.model = QStringListModel()
self.type = type
if type == 0:
self.completer_ = TagCompleter(self.model, parent, self)
self.completer = TagCompleter(self.model, parent, self)
else:
self.completer_ = QCompleter(self.model, parent)
self.completer_.setCompletionMode(QCompleter.PopupCompletion)
self.completer_.setCaseSensitivity(Qt.CaseInsensitive)
self.setCompleter(self.completer_)
self.completer = QCompleter(self.model, parent)
self.completer.setCompletionMode(QCompleter.PopupCompletion)
self.completer.setCaseSensitivity(Qt.CaseInsensitive)
self.setCompleter(self.completer)
def setCol(self, col):
"Set the current col, updating list of available tags."
@ -40,26 +43,26 @@ class TagEdit(QLineEdit):
def keyPressEvent(self, evt):
if evt.key() in (Qt.Key_Up, Qt.Key_Down):
# show completer on arrow key up/down
if not self.completer_.popup().isVisible():
if not self.completer.popup().isVisible():
self.showCompleter()
return
if evt.key() == Qt.Key_Tab and evt.modifiers() & Qt.ControlModifier:
# select next completion
if not self.completer_.popup().isVisible():
if not self.completer.popup().isVisible():
self.showCompleter()
index = self.completer_.currentIndex()
self.completer_.popup().setCurrentIndex(index)
index = self.completer.currentIndex()
self.completer.popup().setCurrentIndex(index)
cur_row = index.row()
if not self.completer_.setCurrentRow(cur_row + 1):
self.completer_.setCurrentRow(0)
if not self.completer.setCurrentRow(cur_row + 1):
self.completer.setCurrentRow(0)
return
if evt.key() in (Qt.Key_Enter, Qt.Key_Return):
# apply first completion if no suggestion selected
selected_row = self.completer_.popup().currentIndex().row()
selected_row = self.completer.popup().currentIndex().row()
if selected_row == -1:
self.completer_.setCurrentRow(0)
index = self.completer_.currentIndex()
self.completer_.popup().setCurrentIndex(index)
self.completer.setCurrentRow(0)
index = self.completer.currentIndex()
self.completer.popup().setCurrentIndex(index)
self.hideCompleter()
QWidget.keyPressEvent(self, evt)
return
@ -80,18 +83,18 @@ class TagEdit(QLineEdit):
gui_hooks.tag_editor_did_process_key(self, evt)
def showCompleter(self):
self.completer_.setCompletionPrefix(self.text())
self.completer_.complete()
self.completer.setCompletionPrefix(self.text())
self.completer.complete()
def focusOutEvent(self, evt) -> None:
QLineEdit.focusOutEvent(self, evt)
self.lostFocus.emit() # type: ignore
self.completer_.popup().hide()
self.completer.popup().hide()
def hideCompleter(self):
if sip.isdeleted(self.completer_):
if sip.isdeleted(self.completer):
return
self.completer_.popup().hide()
self.completer.popup().hide()
class TagCompleter(QCompleter):

View File

@ -10,6 +10,8 @@ warn_unused_configs = True
[mypy-aqt.forms.*]
check_untyped_defs=false
[mypy-aqt.tagedit]
check_untyped_defs=true
[mypy-aqt.mpv]
ignore_errors=true
[mypy-win32file]