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


Python QTextCharFormat.setProperty方法代码示例

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


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

示例1: textFormat

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setProperty [as 别名]
    def textFormat(self, name):
        """(Internal) Returns a QTextCharFormat setup according to the preferences.

        For bookmarks and the current line, FullWidthSelection is automatically enabled.

        """
        f = QTextCharFormat()
        f.setBackground(self._baseColors[name])
        if name in ('current', 'mark', 'error'):
            f.setProperty(QTextFormat.FullWidthSelection, True)
        return f
开发者ID:19joho66,项目名称:frescobaldi,代码行数:13,代码来源:viewhighlighter.py

示例2: logformats

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setProperty [as 别名]
    def logformats(self):
        """Returns a dictionary with QTextCharFormats for the different types of messages.

        Besides the STDOUT, STDERR, NEUTRAL, FAILURE and SUCCESS formats there is also
        a "link" format, that looks basically the same as the output formats, but blueish
        and underlined, to make parts of the output (e.g. filenames) look clickable.

        """
        textColor = QApplication.palette().color(QPalette.WindowText)
        successColor = qutil.addcolor(textColor, 0, 128, 0) # more green
        failureColor = qutil.addcolor(textColor, 128, 0, 0) # more red
        linkColor    = qutil.addcolor(textColor, 0, 0, 128) # more blue
        stdoutColor  = qutil.addcolor(textColor, 64, 64, 0) # more purple

        s = QSettings()
        s.beginGroup("log")
        outputFont = QFont(s.value("fontfamily", "monospace", str))
        outputFont.setPointSizeF(s.value("fontsize", 9.0, float))

        output = QTextCharFormat()
        output.setFont(outputFont)
        # enable zooming the log font size
        output.setProperty(QTextFormat.FontSizeAdjustment, 0)

        stdout = QTextCharFormat(output)
        stdout.setForeground(stdoutColor)

        stderr = QTextCharFormat(output)
        link   = QTextCharFormat(output)
        link.setForeground(linkColor)
        link.setFontUnderline(True)

        status = QTextCharFormat()
        status.setFontWeight(QFont.Bold)

        neutral = QTextCharFormat(status)

        success = QTextCharFormat(status)
        success.setForeground(successColor)

        failure = QTextCharFormat(status)
        failure.setForeground(failureColor)

        return {
            job.STDOUT: stdout,
            job.STDERR: stderr,
            job.NEUTRAL: neutral,
            job.SUCCESS: success,
            job.FAILURE: failure,
            'link': link,
        }
开发者ID:brownian,项目名称:frescobaldi,代码行数:53,代码来源:log.py

示例3: insertImage

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setProperty [as 别名]
    def insertImage(self, image):
        cursor = self.textCursor()

        page = self.parent().page
        fileName = page.saveImage(image)        # returns the file name inside the page's directory
        
        imageObject = ImageObject()
        imagePath = os.path.join(page.getPageDir(), fileName)
        imageObject.setName(imagePath)

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

        # Make sure that the image is also part of the page
        page.save()
开发者ID:afester,项目名称:CodeSamples,代码行数:19,代码来源:StylableTextEdit.py

示例4: insertFormula

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setProperty [as 别名]
    def insertFormula(self):
        cursor = self.textCursor()

        mathFormula = MathFormulaObject()
        mathFormula.setFormula('f(x) := ...')
        mathFormula.renderFormula()

        mathObjectFormat = QTextCharFormat()
        mathObjectFormat.setObjectType(QTextFormat.UserObject + 1)
        mathObjectFormat.setVerticalAlignment(QTextCharFormat.AlignMiddle)
        mathObjectFormat.setProperty(QTextFormat.UserProperty + 1, mathFormula)
        cursor.insertText('\ufffc', mathObjectFormat);

        if self.selectedObject is not None:
            self.selectedObject.setSelected(False)
        self.selectedObject = mathFormula
        self.selectedObject.setSelected(True)
        self.viewport().update()
        self.objectSelectionChanged.emit()
开发者ID:afester,项目名称:CodeSamples,代码行数:21,代码来源:StylableTextEdit.py

示例5: insertTextObject

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setProperty [as 别名]
    def insertTextObject(self):
        fileName = self.fileNameLineEdit.text()
        file = QFile(fileName)

        if not file.open(QIODevice.ReadOnly):
            QMessageBox.warning(self, "Error Opening File",
                    "Could not open '%s'" % fileName)

        svgData = file.readAll()

        svgCharFormat = QTextCharFormat()
        svgCharFormat.setObjectType(Window.SvgTextFormat)
        svgCharFormat.setProperty(Window.SvgData, svgData)

        try:
            # Python v2.
            orc = unichr(0xfffc)
        except NameError:
            # Python v3.
            orc = chr(0xfffc)

        cursor = self.textEdit.textCursor()
        cursor.insertText(orc, svgCharFormat)
        self.textEdit.setTextCursor(cursor)
开发者ID:Axel-Erfurt,项目名称:pyqt5,代码行数:26,代码来源:textobject.py

示例6: loadFormats

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setProperty [as 别名]
    def loadFormats(self):
        self.formats = {}

        stylesCSS = pkg_resources.resource_string(data.__name__, 'styles.css')
        print("styles.css file: {}".format(stylesCSS))
        styleSheet = cssutils.parseString(stylesCSS)

        blockFormats = ['title[level="1"]', 
                        'title[level="2"]', 
                        'title[level="3"]', 
                        'para',
                        'tip',
                        'warning',
                        'blockquote',
                        'programlisting[language="java"]',
                        'programlisting[language="cpp"]',
                        'programlisting[language="xml"]',
                        'programlisting[language="sql"]',
                        'programlisting[language="python"]',
                        'programlisting[language="bash"]',
                        'screen']

        for cssKey in blockFormats:
            cssRule = self.simpleLookup(styleSheet, cssKey)

            # get the selector as a tuple of class and one attribute selector
            # (Can be extended later, but currently sufficient)
            m = re.match(r'^(\S*?)(?:\[(.*)="(.*)"])?$', cssKey)
            selector = m.groups()

            blockFmt = QTextBlockFormat()
            blockFmt.setProperty(QTextFormat.UserProperty, selector)

            value = self.getIntValue(cssRule, 'margin-top')
            if value:
                blockFmt.setTopMargin(value)
            value = self.getIntValue(cssRule, 'margin-right')
            if value:
                blockFmt.setRightMargin(value)
            value = self.getIntValue(cssRule, 'margin-bottom')
            if value:
                blockFmt.setBottomMargin(value)
            value = self.getIntValue(cssRule, 'margin-left')
            if value:
                blockFmt.setLeftMargin(value)
            value = self.getColorValue(cssRule, 'background-color')
            if value:
                blockFmt.setBackground(value)

            charFmt = QTextCharFormat()
            self.setCharFormatAttributes(cssRule, charFmt)

            fmt = Format(blockFmt, charFmt)
            value = self.getStringValue(cssRule, 'white-space')
            if value and value == 'pre':
                fmt.isPre = True
            self.formats[selector] = fmt

### List formats

        listFormats = ['itemizedlist[level="1"]',
                       'itemizedlist[level="2"]',
                       'itemizedlist[level="3"]', 
                       'itemizedlist[level="4"]',
                       'orderedlist[level="1"]',
                       'orderedlist[level="2"]' ,
                       'orderedlist[level="3"]',
                       'orderedlist[level="4"]'] 
        for cssKey in listFormats:
            cssRule = self.simpleLookup(styleSheet, cssKey)

            indent = 0
            m = re.match(r'^(\S*?)(?:\[(.*)="(.*)"])?$', cssKey)
            selector = m.groups()
            if selector[1] == 'level':
                indent = int(selector[2])

            listFmt = QTextListFormat()
            listFmt.setProperty(QTextFormat.UserProperty, selector)
            listFmt.setIndent(indent)

            value = self.getStringValue(cssRule, 'list-style-type')
            if value:
                if value == 'disc':
                    listFmt.setStyle(QTextListFormat.ListDisc)
                elif value == 'circle':
                    listFmt.setStyle(QTextListFormat.ListCircle)
                elif value == 'square':
                    listFmt.setStyle(QTextListFormat.ListSquare)
                elif value == 'decimal':
                    listFmt.setStyle(QTextListFormat.ListDecimal)

            self.formats[selector] = Format(None, None, listFmt)

### Inline formats

        # Base format (?????)
        pcharFmt = QTextCharFormat()
        pcharFmt.setFontPointSize(10)
        pcharFmt.setFontFamily("Sans")
#.........这里部分代码省略.........
开发者ID:afester,项目名称:CodeSamples,代码行数:103,代码来源:FormatManager.py

示例7: EditView

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setProperty [as 别名]
class EditView( QWidget ):
    def __init__(self, my_book, focusser, parent=None):
        # Initialize our superclass(es)
        super().__init__(parent)
        # Save the link to our book and the focus function
        self.my_book = my_book
        self.focusser = focusser # function to call on focus-in
        # Save access to the document itself
        self.document = my_book.get_edit_model()
        # Save access to the word list and page data
        self.word_model = my_book.get_word_model()
        self.page_model = my_book.get_page_model()
        # Initialize highlighting switches and create the highlighter.
        self.highlighter = HighLighter(self,my_book)
        self.scanno_check = False
        self.spelling_check = False
        #
        # Take our UI setup out of line. self._uic creates and
        # initializes all the sub-widgets under self. :
        #     .Editor - the QPlainTextEditor
        #     .DocName - QLabel for the document filename
        #     .Folio - QLabel for the current folio value
        #     .ImageFilename - QLineEdit for the current image filename
        #     .LineNumber - QLineEdit for the line number
        #     .ColNumber - QLabel for the cursor column
        # Signals from these widgets are hooked up below.
        #
        self._uic()
        # Connect the editor to the document.
        self.Editor.setDocument(self.document)
        # Set up mechanism for a current-line highlight and a find-range
        # highlight. See set_find_range, clear_find_range, _set_colors
        # and _cursor_moved.
        self.last_text_block = None # to know when cursor moves to new line
        self.current_line_sel = QTextEdit.ExtraSelection()
        self.current_line_fmt = QTextCharFormat() # see _set_colors
        self.current_line_fmt.setProperty(QTextFormat.FullWidthSelection, True)
        self.range_sel = QTextEdit.ExtraSelection()
        self.range_sel.cursor = QTextCursor(self.document) # null cursor
        self.range_fmt = QTextCharFormat() # see _set_colors
        self.range_fmt.setProperty(QTextCharFormat.FullWidthSelection, True)
        self.extra_sel_list = [self.range_sel, self.current_line_sel]
        # Sign up to get a signal on a change in font choice
        fonts.notify_me(self.font_change)
        # Fake that signal to set the fonts of our widgets.
        self.one_line_height = 0 # updated in font_change
        self.font_change(False)
        # Sign up to get a signal on a change of color preferences.
        colors.notify_me(self._set_colors)
        # Fake the signal to set up widgets. This sets .scanno_format,
        # .spelling_format, .current_line_sel, .range_sel, .norm_style and
        # .mod_style.
        self._set_colors()
        # Put the document name in our widget
        self.DocName.setText(self.my_book.get_book_name())
        # Set the cursor shape to IBeam -- no idea why this supposed default
        # inherited from QTextEdit, doesn't happen. But it doesn't.
        # self.Editor.viewport().setCursor(Qt.IBeamCursor)
        # Connect the Editor's modificationChanged signal to our slot.
        self.Editor.modificationChanged.connect(self.mod_change_signal)
        # Connect the returnPressed signal of the LineNumber widget
        # to our go to line method.
        self.LineNumber.returnPressed.connect(self._line_number_enter)
        # Connect returnPressed of the ImageFilename widget to our slot.
        self.ImageFilename.returnPressed.connect(self._image_enter)
        # Connect the Editor's cursorPositionChanged signal to our slot
        self.Editor.cursorPositionChanged.connect(self._cursor_moved)
        # Fill in the line and column number by faking that signal
        self._cursor_moved()
        # Create and install our context menu
        self.context_menu = self._make_context_menu()
        self.setContextMenuPolicy(Qt.DefaultContextMenu)

        # End of __init__()

    # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    #                 INTERNAL METHODS

    # Set up text formats for the current line, spellcheck words
    # and for scanno words. Done in a method because this has to be
    # redone when the colorsChanged signal happens.
    def _set_colors(self):
        self.scanno_format = colors.get_scanno_format()
        self.spelling_format = colors.get_spelling_format()
        self.current_line_fmt.setBackground(colors.get_current_line_brush())
        self.current_line_sel.format = QTextCharFormat(self.current_line_fmt)
        self.range_fmt.setBackground(colors.get_find_range_brush())
        self.range_sel.format = QTextCharFormat(self.range_fmt)
        self.norm_style = 'color:Black;font-weight:normal;'
        self.mod_style = 'color:' + colors.get_modified_color().name() + ';font-weight:bold;'
        # Fake the mod-change signal to update the document name color
        self.mod_change_signal(self.document.isModified())

    # Slot to receive the modificationChanged signal from the document.
    # Also called from the book when metadata changes state.
    # Change the color of the DocName to match.
    def mod_change_signal(self,bool):
        self.DocName.setStyleSheet(self.mod_style if self.my_book.get_save_needed() else self.norm_style)

    # This slot receives the ReturnPressed signal from the LineNumber field.
#.........这里部分代码省略.........
开发者ID:B-Rich,项目名称:PPQT2,代码行数:103,代码来源:editview.py

示例8: ViewHighlighter

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setProperty [as 别名]
class ViewHighlighter(plugin.Plugin, gadgets.arbitraryhighlighter.ArbitraryHighlighter):
    def __init__(self, view):
        # no need to call the plugin __init__ method
        gadgets.arbitraryhighlighter.ArbitraryHighlighter.__init__(self, view)
        self._cursorFormat = QTextCharFormat()
        self._cursorFormat.setProperty(QTextFormat.FullWidthSelection, True)
        app.settingsChanged.connect(self.readSettings)
        self.readSettings()
        bookmarks.bookmarks(view.document()).marksChanged.connect(self.updateMarkedLines)
        self.updateMarkedLines()
        view.cursorPositionChanged.connect(self.updateCursor)
        view.installEventFilter(self)

    def updateMarkedLines(self):
        """Called when something changes in the bookmarks."""
        for type, marks in bookmarks.bookmarks(self.parent().document()).marks().items():
            self.highlight(type, marks, -1)

    def eventFilter(self, view, ev):
        if ev.type() in (QEvent.FocusIn, QEvent.FocusOut):
            self.updateCursor(view)
        return False

    def updateCursor(self, view=None):
        """Called when the textCursor has moved. Highlights the current line.

        If view is None (the default), our parent() is assumed to be the
        view. The eventFilter() method calls us with the view, this is
        done because the event filter is sometimes called very late in
        the destructor phase, when our parent is possibly not valid
        anymore.

        """
        if view is None:
            view = self.parent()
        # sometimes in the destruction phase, view is a generic QWidget...
        try:
            cursor = view.textCursor()
        except AttributeError:
            return
        # highlight current line
        cursor.clearSelection()
        color = QColor(self._baseColors['current'])
        color.setAlpha(200 if view.hasFocus() else 100)
        self._cursorFormat.setBackground(color)
        self.highlight(self._cursorFormat, [cursor], 0)

    def readSettings(self):
        data = textformats.formatData('editor')
        self._baseColors = data.baseColors
        self.updateCursor()
        self.reload()

    def textFormat(self, name):
        """(Internal) Returns a QTextCharFormat setup according to the preferences.

        For bookmarks and the current line, FullWidthSelection is automatically enabled.

        """
        f = QTextCharFormat()
        f.setBackground(self._baseColors[name])
        if name in ('current', 'mark', 'error'):
            f.setProperty(QTextFormat.FullWidthSelection, True)
        return f
开发者ID:19joho66,项目名称:frescobaldi,代码行数:66,代码来源:viewhighlighter.py


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