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

View file

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