当前位置: 首页>>代码示例>>Python>>正文


Python Qt.QTextCharFormat类代码示例

本文整理汇总了Python中PyQt5.Qt.QTextCharFormat的典型用法代码示例。如果您正苦于以下问题:Python QTextCharFormat类的具体用法?Python QTextCharFormat怎么用?Python QTextCharFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QTextCharFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

 def __init__(self, right=False, parent=None, show_open_in_editor=False):
     PlainTextEdit.__init__(self, parent)
     self.setFrameStyle(0)
     self.show_open_in_editor = show_open_in_editor
     self.side_margin = 0
     self.setContextMenuPolicy(Qt.CustomContextMenu)
     self.customContextMenuRequested.connect(self.show_context_menu)
     self.setFocusPolicy(Qt.NoFocus)
     self.right = right
     self.setReadOnly(True)
     self.setLineWrapMode(self.WidgetWidth)
     font = self.font()
     ff = tprefs['editor_font_family']
     if ff is None:
         ff = default_font_family()
     font.setFamily(ff)
     font.setPointSize(tprefs['editor_font_size'])
     self.setFont(font)
     self.calculate_metrics()
     self.setTabStopWidth(tprefs['editor_tab_stop_width'] * self.space_width)
     font = self.heading_font = QFont(self.font())
     font.setPointSize(int(tprefs['editor_font_size'] * 1.5))
     font.setBold(True)
     theme = get_theme(tprefs['editor_theme'])
     pal = self.palette()
     pal.setColor(pal.Base, theme_color(theme, 'Normal', 'bg'))
     pal.setColor(pal.AlternateBase, theme_color(theme, 'CursorLine', 'bg'))
     pal.setColor(pal.Text, theme_color(theme, 'Normal', 'fg'))
     pal.setColor(pal.Highlight, theme_color(theme, 'Visual', 'bg'))
     pal.setColor(pal.HighlightedText, theme_color(theme, 'Visual', 'fg'))
     self.setPalette(pal)
     self.viewport().setCursor(Qt.ArrowCursor)
     self.line_number_area = LineNumbers(self)
     self.blockCountChanged[int].connect(self.update_line_number_area_width)
     self.updateRequest.connect(self.update_line_number_area)
     self.line_number_palette = pal = QPalette()
     pal.setColor(pal.Base, theme_color(theme, 'LineNr', 'bg'))
     pal.setColor(pal.Text, theme_color(theme, 'LineNr', 'fg'))
     pal.setColor(pal.BrightText, theme_color(theme, 'LineNrC', 'fg'))
     self.line_number_map = LineNumberMap()
     self.search_header_pos = 0
     self.changes, self.headers, self.images = [], [], OrderedDict()
     self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff), self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
     self.diff_backgrounds = {
         'replace' : theme_color(theme, 'DiffReplace', 'bg'),
         'insert'  : theme_color(theme, 'DiffInsert', 'bg'),
         'delete'  : theme_color(theme, 'DiffDelete', 'bg'),
         'replacereplace': theme_color(theme, 'DiffReplaceReplace', 'bg'),
         'boundary': QBrush(theme_color(theme, 'Normal', 'fg'), Qt.Dense7Pattern),
     }
     self.diff_foregrounds = {
         'replace' : theme_color(theme, 'DiffReplace', 'fg'),
         'insert'  : theme_color(theme, 'DiffInsert', 'fg'),
         'delete'  : theme_color(theme, 'DiffDelete', 'fg'),
         'boundary': QColor(0, 0, 0, 0),
     }
     for x in ('replacereplace', 'insert', 'delete'):
         f = QTextCharFormat()
         f.setBackground(self.diff_backgrounds[x])
         setattr(self, '%s_format' % x, f)
开发者ID:MarioJC,项目名称:calibre,代码行数:60,代码来源:view.py

示例2: __init__

 def __init__( self, pattern, color, style ):
     if isinstance(pattern,basestring):
         self.pattern = re.compile(pattern)
     else:
         self.pattern=pattern
     charfmt = QTextCharFormat()
     brush = QBrush(color, style)
     charfmt.setForeground(brush)
     self.highlight = charfmt
开发者ID:besnef,项目名称:FanFicFare,代码行数:9,代码来源:basicinihighlighter.py

示例3: highlightBlock

    def highlightBlock(self, text):
        if not self.dict:
            return

        format = QTextCharFormat()
        format.setUnderlineColor(Qt.red)
        format.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)

        for word_object in re.finditer(self.WORDS, text):
            if not self.dict.check(word_object.group()):
                self.setFormat(word_object.start(),
                    word_object.end() - word_object.start(), format)
开发者ID:correosdelbosque,项目名称:lector,代码行数:12,代码来源:spellchecker.py

示例4: parse_text_formatting

def parse_text_formatting(text):
    pos = 0
    tokens = []
    for m in re.finditer(r'</?([a-zA-Z1-6]+)/?>', text):
        q = text[pos:m.start()]
        if q:
            tokens.append((False, q))
        tokens.append((True, (m.group(1).lower(), '/' in m.group()[:2])))
        pos = m.end()
    if tokens:
        if text[pos:]:
            tokens.append((False, text[pos:]))
    else:
        tokens = [(False, text)]

    ranges, open_ranges, text = [], [], []
    offset = 0
    for is_tag, tok in tokens:
        if is_tag:
            tag, closing = tok
            if closing:
                if open_ranges:
                    r = open_ranges.pop()
                    r[-1] = offset - r[-2]
                    if r[-1] > 0:
                        ranges.append(r)
            else:
                if tag in {'b', 'strong', 'i', 'em'}:
                    open_ranges.append([tag, offset, -1])
        else:
            offset += len(tok.replace('&amp;', '&'))
            text.append(tok)
    text = ''.join(text)
    formats = []
    for tag, start, length in chain(ranges, open_ranges):
        fmt = QTextCharFormat()
        if tag in {'b', 'strong'}:
            fmt.setFontWeight(QFont.Bold)
        elif tag in {'i', 'em'}:
            fmt.setFontItalic(True)
        else:
            continue
        if length == -1:
            length = len(text) - start
        if length > 0:
            r = QTextLayout.FormatRange()
            r.format = fmt
            r.start, r.length = start, length
            formats.append(r)
    return text, formats
开发者ID:artbycrunk,项目名称:calibre,代码行数:50,代码来源:covers.py

示例5: __init__

 def __init__( self, pattern, color,
               weight=QFont.Normal,
               style=Qt.SolidPattern,
               blocknum=0):
     if isinstance(pattern,basestring):
         self.pattern = re.compile(pattern)
     else:
         self.pattern=pattern
     charfmt = QTextCharFormat()
     brush = QBrush(color, style)
     charfmt.setForeground(brush)
     charfmt.setFontWeight(weight)
     self.highlight = charfmt
     self.blocknum=blocknum
开发者ID:iceshipping,项目名称:FanFicFare,代码行数:14,代码来源:inihighlighter.py

示例6: __init__

    def __init__(self, controller):
        super().__init__()
        formc = QTextCharFormat()
        formc.setFontItalic(True)
        formc.setFontWeight(3)
        form = QTextBlockFormat()
        form.setLineHeight(200, 1)


        cur = self.textCursor()
        cur.insertText('', self.format_p)
        new_speech_signal = QObject()
        controller.speech.connect(self.new_speech_signal.emit)
        controller.speech.start()
        self.new_speech_signal.connect(cur.insertText)
开发者ID:aaronschif,项目名称:sp,代码行数:15,代码来源:__main__.py

示例7: setFontFamily

    def setFontFamily(self, family):
        """Override. Set font family."""

        undoState = self.isUndoRedoEnabled()
        self.setUndoRedoEnabled(False)
        mod = self.document().isModified()
        fmt = QTextCharFormat()
        fmt.setFontFamily(family)
        cursor = self.textCursor()
        self.selectAll()
        super().setFontFamily(family)
        cursor2 = self.textCursor()
        cursor2.clearSelection()
        self.setTextCursor(cursor2)
        self.setTextCursor(cursor)
        self.document().setModified(mod)
        self.setUndoRedoEnabled(undoState)
开发者ID:TwoManyHats,项目名称:GuiScannos,代码行数:17,代码来源:textpane.py

示例8: setFontPointSize

    def setFontPointSize(self, pointSize):
        """Override. Set font size."""

        pointSize = float(pointSize)
        if pointSize > 0:
            undoState = self.isUndoRedoEnabled()
            self.setUndoRedoEnabled(False)
            mod = self.document().isModified()
            fmt = QTextCharFormat()
            fmt.setFontPointSize(pointSize)
            cursor = self.textCursor()
            self.selectAll()
            super().setFontPointSize(pointSize)
            cursor2 = self.textCursor()
            cursor2.clearSelection()
            self.setTextCursor(cursor2)
            self.setTextCursor(cursor)
            self.document().setModified(mod)
            self.setUndoRedoEnabled(undoState)
开发者ID:TwoManyHats,项目名称:GuiScannos,代码行数:19,代码来源:textpane.py

示例9: check_spelling

 def check_spelling(text, tlen, fmt, locale, sfmt, store_locale):
     split_ans = []
     ppos = 0
     r, a = dictionaries.recognized, split_ans.append
     for start, length in split_into_words_and_positions(text, lang=locale.langcode):
         if start > ppos:
             a((start - ppos, fmt))
         ppos = start + length
         recognized = r(text[start:ppos], locale)
         if recognized:
             a((length, fmt))
         else:
             if store_locale:
                 s = QTextCharFormat(sfmt)
                 s.setProperty(SPELL_LOCALE_PROPERTY, locale)
                 a((length, s))
             else:
                 a((length, sfmt))
     if ppos < tlen:
         a((tlen - ppos, fmt))
     return split_ans
开发者ID:davidfor,项目名称:calibre,代码行数:21,代码来源:html.py

示例10: process_text

def process_text(state, text, nbsp_format, spell_format, user_data):
    ans = []
    fmt = None
    if state.is_bold or state.is_italic:
        fmt = syntax_text_char_format()
        if state.is_bold:
            fmt.setFontWeight(QFont.Bold)
        if state.is_italic:
            fmt.setFontItalic(True)
    last = 0
    for m in nbsp_pat.finditer(text):
        ans.extend([(m.start() - last, fmt), (m.end() - m.start(), nbsp_format)])
        last = m.end()
    if not ans:
        ans = [(len(text), fmt)]
    elif last < len(text):
        ans.append((len(text) - last, fmt))

    if do_spell_check and state.tags and user_data.tag_ok_for_spell(state.tags[-1].name):
        split_ans = []
        locale = state.current_lang or dictionaries.default_locale
        sfmt = QTextCharFormat(spell_format)
        if fmt is not None:
            sfmt.merge(fmt)

        tpos = 0
        for tlen, fmt in ans:
            if fmt is nbsp_format:
                split_ans.append((tlen, fmt))
            else:
                split_ans.extend(
                    check_spelling(text[tpos : tpos + tlen], tlen, fmt, locale, sfmt, store_locale.enabled)
                )

            tpos += tlen
        ans = split_ans

    return ans
开发者ID:GaryMMugford,项目名称:calibre,代码行数:38,代码来源:html.py

示例11: initializeFormats

    def initializeFormats(self):
        Config = self.Config
        Config["fontfamily"] = "monospace"
        for name, color, bold, italic in (
                ("normal", "#000000", False, False),
                ("keyword", "#000080", True, False),
                ("builtin", "#0000A0", False, False),
                ("comment", "#007F00", False, True),
                ("string", "#808000", False, False),
                ("number", "#924900", False, False),
                ("lparen", "#000000", True, True),
                ("rparen", "#000000", True, True)):
            Config["%sfontcolor" % name] = color
            Config["%sfontbold" % name] = bold
            Config["%sfontitalic" % name] = italic
        baseFormat = QTextCharFormat()
        baseFormat.setFontFamily(Config["fontfamily"])
        Config["fontsize"] = gprefs['gpm_template_editor_font_size']
        baseFormat.setFontPointSize(Config["fontsize"])

        for name in ("normal", "keyword", "builtin", "comment",
                     "string", "number", "lparen", "rparen"):
            format = QTextCharFormat(baseFormat)
            format.setForeground(QColor(Config["%sfontcolor" % name]))
            if Config["%sfontbold" % name]:
                format.setFontWeight(QFont.Bold)
            format.setFontItalic(Config["%sfontitalic" % name])
            self.Formats[name] = format
开发者ID:AEliu,项目名称:calibre,代码行数:28,代码来源:template_dialog.py

示例12: addNode

    def addNode(self, node):
        if type(node) == Paragraph:
            self.paraFormat = self.formatManager.getFormat(node.style)

            # NOTE: "The block char format is the format used when inserting 
            #        text at the beginning of an empty block."
            #       See also below.
            self.cursor.insertBlock(self.paraFormat.getBlockFormat(), self.paraFormat.getCharFormat())
            # self.cursor.insertFragment(QTextDocumentFragment.fromPlainText(''))

            if self.listLevel > 0:
                # TODO: use list style from list node - requires a stack, though ...
                listStyle = ('itemizedlist', 'level', str(self.listLevel))
                newList = self.cursor.createList(self.formatManager.getFormat(listStyle).getListFormat())
            for n in node.children:
                self.addNode(n)

        elif type(node) == List:
            self.listLevel += 1
            for n in node.children:
                self.addNode(n)
            self.listLevel -= 1

        elif type(node) is ImageFragment:
            imageObject = ImageObject()
            imagePath = os.path.join(self.contentPath, node.image)
            imageObject.setName(imagePath)

            imageObjectFormat = QTextCharFormat()
            imageObjectFormat.setObjectType(QTextFormat.UserObject + 1)
            imageObjectFormat.setProperty(QTextFormat.UserProperty + 1, imageObject)
            self.cursor.insertText('\ufffc', imageObjectFormat);

        elif type(node) is MathFragment:
            mathFormula = MathFormulaObject()
            mathFormula.setFormula(node.text)
            mathFormula.image = node.image #  renderFormula()

            mathObjectFormat = QTextCharFormat()
            mathObjectFormat.setObjectType(QTextFormat.UserObject + 1)
            mathObjectFormat.setVerticalAlignment(QTextCharFormat.AlignMiddle)
            mathObjectFormat.setProperty(QTextFormat.UserProperty + 1, mathFormula)
            self.cursor.insertText('\ufffc', mathObjectFormat);
        elif type(node) is TextFragment:
            text = node.text.replace('\n', '\u2028')
            if node.href is not None:
                fmt = self.formatManager.getFormat(('link', None, None))   # TODO!
                charFmt = fmt.getCharFormat()
                charFmt.setAnchorHref(node.href)
                self.cursor.insertText(text, charFmt)
            else:
                # "The block char format is the format used when inserting text at the beginning of an empty block.
                # Hence, the block char format is only useful for the first fragment -
                # once a fragment is inserted with a different style, and afterwards
                # another fragment is inserted with no specific style, we need to reset
                # the char format to the block's char format explicitly!
    
                if node.style is not None:
                    fmt = self.formatManager.getFormat(node.style)
                else:
                    fmt = self.paraFormat

                self.cursor.insertText(text, fmt.getCharFormat())
开发者ID:afester,项目名称:CodeSamples,代码行数:63,代码来源:StylableTextModel.py

示例13: syntax_text_char_format

def syntax_text_char_format(*args):
    ans = QTextCharFormat(*args)
    ans.setProperty(SYNTAX_PROPERTY, True)
    return ans
开发者ID:j-howell,项目名称:calibre,代码行数:4,代码来源:__init__.py

示例14: initializeFormats

    def initializeFormats(cls):
        if cls.Formats:
            return
        baseFormat = QTextCharFormat()
        baseFormat.setFontFamily('monospace')
        baseFormat.setFontPointSize(11)
        for name, color, bold, italic in (
                ("normal", "#000000", False, False),
                ("keyword", "#000080", True, False),
                ("builtin", "#0000A0", False, False),
                ("constant", "#0000C0", False, False),
                ("decorator", "#0000E0", False, False),
                ("comment", "#007F00", False, True),
                ("string", "#808000", False, False),
                ("number", "#924900", False, False),
                ("error", "#FF0000", False, False),
                ("pyqt", "#50621A", False, False)):

            format = QTextCharFormat(baseFormat)
            format.setForeground(QColor(color))
            if bold:
                format.setFontWeight(QFont.Bold)
            format.setFontItalic(italic)
            cls.Formats[name] = format
开发者ID:JimmXinu,项目名称:calibre,代码行数:24,代码来源:widgets.py

示例15: spell_property

 def spell_property(sfmt, locale):
     s = QTextCharFormat(sfmt)
     s.setProperty(SPELL_LOCALE_PROPERTY, locale)
     return s
开发者ID:davidfor,项目名称:calibre,代码行数:4,代码来源:html.py


注:本文中的PyQt5.Qt.QTextCharFormat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。