'Redirect key presses from the popup to the widget'

def eventFilter(self, obj, e):

    widget = self.completer_widget()
    if ((widget is None) or sip.isdeleted(widget)):
        return False
    etype = e.type()
    if (obj is not self):
        return QObject.eventFilter(self, obj, e)
    if (etype == e.KeyPress):
        try:
            key = e.key()
        except AttributeError:
            return QObject.eventFilter(self, obj, e)
        if (key == Qt.Key_Escape):
            self.hide()
            e.accept()
            return True
        if ((key == Qt.Key_F4) and (e.modifiers() & Qt.AltModifier)):
            self.hide()
            e.accept()
            return True
        if (key in (Qt.Key_Enter, Qt.Key_Return)):
            idx = self.currentIndex()
            if idx.isValid():
                self.item_chosen(idx)
            self.hide()
            e.accept()
            return True
        if (key == Qt.Key_Tab):
            idx = self.currentIndex()
            if idx.isValid():
                self.item_chosen(idx)
                self.hide()
            elif (self.model().rowCount() > 0):
                self.next_match()
            e.accept()
            return True
        if (key in (Qt.Key_PageUp, Qt.Key_PageDown)):
            return False
        if (key in (Qt.Key_Up, Qt.Key_Down)):
            self.next_match(previous=(key == Qt.Key_Up))
            e.accept()
            return True
        widget.eat_focus_out = False
        widget.keyPressEvent(e)
        widget.eat_focus_out = True
        if (not widget.hasFocus()):
            self.hide()
        if e.isAccepted():
            return True
    elif (isosx and (etype == e.InputMethodQuery) and (e.queries() == (Qt.ImHints | Qt.ImEnabled)) and self.isVisible()):
        e.accept()
        return True
    elif ((etype == e.MouseButtonPress) and (not self.rect().contains(self.mapFromGlobal(e.globalPos())))):
        if isinstance(widget, QComboBox):
            opt = QStyleOptionComboBox()
            widget.initStyleOption(opt)
            sc = widget.style().hitTestComplexControl(QStyle.CC_ComboBox, opt, widget.mapFromGlobal(e.globalPos()), widget)
            if (sc == QStyle.SC_ComboBoxArrow):
                QTimer.singleShot(0, self.hide)
                e.accept()
                return True
        self.hide()
        e.accept()
        return True
    elif (etype in (e.InputMethod, e.ShortcutOverride)):
        QApplication.sendEvent(widget, e)
    return False
