ignore the key stroke if empty, otherwise accept

This commit is contained in:
Damien Elmes 2009-05-16 05:30:13 +09:00
parent 7541485e87
commit 26e7428f16

View file

@ -4,7 +4,7 @@
from PyQt4.QtGui import * from PyQt4.QtGui import *
from PyQt4.QtCore import * from PyQt4.QtCore import *
from anki.utils import parseTags, canonifyTags, joinTags from anki.utils import parseTags, canonifyTags, joinTags
import re import re, sys
class TagEdit(QLineEdit): class TagEdit(QLineEdit):
@ -36,14 +36,15 @@ class TagEdit(QLineEdit):
def keyPressEvent(self, evt): def keyPressEvent(self, evt):
if evt.key() in (Qt.Key_Enter, Qt.Key_Return): if evt.key() in (Qt.Key_Enter, Qt.Key_Return):
evt.ignore()
if not self.text(): if not self.text():
pass evt.ignore()
elif self.completer.completionCount():
self.setText(
self.completer.pathFromIndex(self.completer.popup().currentIndex()))
else: else:
self.setText(self.completer.completionPrefix()) evt.accept()
if self.completer.completionCount():
self.setText(
self.completer.pathFromIndex(self.completer.popup().currentIndex()))
else:
self.setText(self.completer.completionPrefix())
self.completer.popup().hide() self.completer.popup().hide()
return return
QLineEdit.keyPressEvent(self, evt) QLineEdit.keyPressEvent(self, evt)