示例#1
0
 def __on_textEdited(self, text):
     patt = QRegExp("(^|\W)" + text)
     patt.setCaseSensitivity(False)
     self.__suggestPage.setFilterRegExp(patt)
     self.__pages.setCurrentPage(self.__suggestPage)
     self.__selectFirstIndex()
     UsageStatistics.set_last_search_query(text)
示例#2
0
    def popup(self, pos=None, searchText=""):
        """
        Popup the menu at `pos` (in screen coordinates). 'Search' text field
        is initialized with `searchText` if provided.

        """
        if pos is None:
            pos = QPoint()

        self.__clearCurrentItems()

        self.__search.setText(searchText)
        patt = QRegExp("(^|\W)"+searchText)
        patt.setCaseSensitivity(False)
        self.__suggestPage.setFilterRegExp(patt)

        self.ensurePolished()

        if self.testAttribute(Qt.WA_Resized) and self.sizeGripEnabled():
            size = self.size()
        else:
            size = self.sizeHint()

        desktop = QApplication.desktop()
        screen_geom = desktop.availableGeometry(pos)

        # Adjust the size to fit inside the screen.
        if size.height() > screen_geom.height():
            size.setHeight(screen_geom.height())
        if size.width() > screen_geom.width():
            size.setWidth(screen_geom.width())

        geom = QRect(pos, size)

        if geom.top() < screen_geom.top():
            geom.setTop(screen_geom.top())

        if geom.left() < screen_geom.left():
            geom.setLeft(screen_geom.left())

        bottom_margin = screen_geom.bottom() - geom.bottom()
        right_margin = screen_geom.right() - geom.right()
        if bottom_margin < 0:
            # Falls over the bottom of the screen, move it up.
            geom.translate(0, bottom_margin)

        # TODO: right to left locale
        if right_margin < 0:
            # Falls over the right screen edge, move the menu to the
            # other side of pos.
            geom.translate(-size.width(), 0)

        self.setGeometry(geom)

        self.show()

        if searchText:
            self.setFocusProxy(self.__search)
        else:
            self.setFocusProxy(None)
示例#3
0
 def _filter_table_variables(self):
     regex = QRegExp(self.filter_string)
     # If the user explicitly types different cases, we assume they know
     # what they are searching for and account for letter case in filter
     different_case = (
         any(c.islower() for c in self.filter_string) and
         any(c.isupper() for c in self.filter_string)
     )
     if not different_case:
         regex.setCaseSensitivity(Qt.CaseInsensitive)
示例#4
0
    def highlightBlock(self, text):
        for pattern, format in self.rules:
            exp = QRegExp(pattern)
            index = exp.indexIn(text)
            while index >= 0:
                length = exp.matchedLength()
                if exp.captureCount() > 0:
                    self.setFormat(exp.pos(1), len(str(exp.cap(1))), format)
                else:
                    self.setFormat(exp.pos(0), len(str(exp.cap(0))), format)
                index = exp.indexIn(text, index + length)

        # Multi line strings
        start = self.multilineStart
        end = self.multilineEnd

        self.setCurrentBlockState(0)
        startIndex, skip = 0, 0
        if self.previousBlockState() != 1:
            startIndex, skip = start.indexIn(text), 3
        while startIndex >= 0:
            endIndex = end.indexIn(text, startIndex + skip)
            if endIndex == -1:
                self.setCurrentBlockState(1)
                commentLen = len(text) - startIndex
            else:
                commentLen = endIndex - startIndex + 3
            self.setFormat(startIndex, commentLen, self.stringFormat)
            startIndex, skip = (start.indexIn(text,
                                              startIndex + commentLen + 3),
                                3)
示例#5
0
 def createStrings(self):
     stringFormat = QTextCharFormat()
     stringFormat.setForeground(Qt.darkGreen)
     self.highlightingRules.append((QRegExp('\'.*\''), stringFormat))
     self.highlightingRules.append((QRegExp('\".*\"'), stringFormat))
 def __on_textEdited(self, text):
     patt = QRegExp("(^|\W)" + text)
     patt.setCaseSensitivity(False)
     self.__suggestPage.setFilterRegExp(patt)
     self.__pages.setCurrentPage(self.__suggestPage)
 def add_datetime(contents):
     le = add_textual(contents)
     le.setValidator(QRegExpValidator(QRegExp(TimeVariable.REGEX)))
     return le
示例#8
0
 def __on_textEdited(self, text):
     patt = QRegExp("(^|\W)" + text)
     patt.setCaseSensitivity(False)
     self.__suggestPage.setFilterRegExp(patt)
     self.__pages.setCurrentPage(self.__suggestPage)