Ejemplo n.º 1
0
 def create(self, *args, **kwargs):
     kwargs.setdefault("timeout", self.timeout)
     point = kwargs.pop("point", None)
     notification = self._notification(*args, **kwargs)
     notification.aboutToClose.connect(self._remove_notification)
     notification.contentChanged.connect(self._fix_positions)
     self.notifications.insert(0, notification)
     if point is not None:
         move_widget(notification, point)
     else:
         self._fix_positions()
     return notification
Ejemplo n.º 2
0
    def complete(self, completions, completion_prefix=None, automatic=True):
        if not self.isVisible():
            self.clear()

        hashes = set()
        for comp, txt, mt, ico, tip in self._map_completions(completions):
            _hash = hash(mt)
            if _hash in self._match_hashes:
                continue
            item = QtWidgets.QListWidgetItem(txt, self)
            item.setData(QtCore.Qt.MatchRole, mt)
            if ico is not None:
                item.setIcon(ico)
            if tip is not None:
                item.setToolTip(tip)
            hashes.add(hash(mt))
            self.addItem(item)
            self._completions.append(comp)
        self._match_hashes.update(hashes)

        if len(self._completions) == 0:
            return

        if len(self._completions) == 1 and not automatic:
            self.__insert_completion(0)
            return

        self.resize(self.sizeHint())
        self.setCurrentRow(0)

        QtWidgets.QApplication.processEvents(QtCore.QEventLoop.ExcludeUserInputEvents)
        self.show()
        self.setFocus()
        self.raise_()
        
        cursor_rect = self.textedit.cursorRect()
        top_left = self.textedit.mapToGlobal(cursor_rect.topLeft())
        bottom_right = self.textedit.mapToGlobal(cursor_rect.bottomRight())

        move_widget(self, QtCore.QRect(top_left, bottom_right))
        
        if completion_prefix is not None:
            # When initialized, if completion text is not empty, we need 
            # to update the displayed list:
            self.setCompletionPrefix(completion_prefix)