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


Python QTextCharFormat.setAnchor方法代码示例

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


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

示例1: __post_execution_message

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setAnchor [as 别名]
 def __post_execution_message(self):
     """Print post execution message."""
     self.output.textCursor().insertText('\n\n')
     format_ = QTextCharFormat()
     format_.setAnchor(True)
     format_.setForeground(Qt.green)
     self.output.textCursor().insertText(
         _translate("RunWidget", "Post Execution Script Successfully executed."), format_)
开发者ID:Salmista-94,项目名称:Ninja_PyQt5,代码行数:10,代码来源:run_widget.py

示例2: process_error

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setAnchor [as 别名]
 def process_error(self, error):
     """Listen to the error signals from the running process."""
     self.lblInput.hide()
     self.input.hide()
     self._proc.kill()
     format_ = QTextCharFormat()
     format_.setAnchor(True)
     format_.setForeground(QBrush(QColor(resources.CUSTOM_SCHEME.get(
         "error-underline", resources.COLOR_SCHEME["error-underline"]))))
     if error == 0:
         self.output.textCursor().insertText(_translate("RunWidget", 'Failed to start'),
             format_)
     else:
         self.output.textCursor().insertText(
             (_translate("RunWidget", 'Error during execution, QProcess error: %d') % error),
             format_)
开发者ID:Salmista-94,项目名称:Ninja_PyQt5,代码行数:18,代码来源:run_widget.py

示例3: finish_execution

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setAnchor [as 别名]
 def finish_execution(self, exitCode, exitStatus):
     """Print a message and hide the input line when the execution ends."""
     self.lblInput.hide()
     self.input.hide()
     format_ = QTextCharFormat()
     format_.setAnchor(True)
     self.output.textCursor().insertText('\n\n')
     if exitStatus == QProcess.NormalExit:
         format_.setForeground(QBrush(QColor(resources.CUSTOM_SCHEME.get(
         "keyword", resources.COLOR_SCHEME["keyword"]))))
         self.output.textCursor().insertText(
             _translate("RunWidget", "Execution Successful!"), format_)
     else:
         format_.setForeground(QBrush(QColor(resources.CUSTOM_SCHEME.get(
         "error-underline", resources.COLOR_SCHEME["error-underline"]))))
         self.output.textCursor().insertText(
             _translate("RunWidget", "Execution Interrupted"), format_)
     self.output.textCursor().insertText('\n\n')
     self.__post_execution()
开发者ID:Salmista-94,项目名称:Ninja_PyQt5,代码行数:21,代码来源:run_widget.py

示例4: writeMessage

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setAnchor [as 别名]
    def writeMessage(self, message, type):
        """This writes both status and output messages to the log.

        For output messages also the correct encoding is re-applied:
        LilyPond writes filenames out in the system's filesystemencoding,
        while the messages are always written in UTF-8 encoding...

        """
        if type == job.STDERR:
            # find filenames in message:
            parts = iter(errors.message_re.split(message.encode('latin1')))
            msg = next(parts).decode('utf-8', 'replace')
            self.cursor.insertText(msg, self.textFormat(type))
            enc = sys.getfilesystemencoding()

            for url, path, line, col, msg in zip(*itertools.repeat(parts, 5)):
                url = url.decode(enc)
                path = path.decode(enc)
                msg = msg.decode('utf-8', 'replace')
                if self._rawView:
                    fmt = QTextCharFormat(self.textFormat(type))
                    display_url = url
                else:
                    fmt = QTextCharFormat(self.textFormat("link"))
                    display_url = os.path.basename(path)
                fmt.setAnchor(True)
                fmt.setAnchorHref(str(len(self._errors)))
                fmt.setToolTip(_("Click to edit this file"))

                pos = self.cursor.position()
                self.cursor.insertText(display_url, fmt)
                self.cursor.insertText(msg, self.textFormat(type))
                self._errors.append((pos, self.cursor.position(), url))
        else:
            if type == job.STDOUT:
                # we use backslashreplace because LilyPond sometimes seems to write
                # incorrect utf-8 to standard output in \displayMusic, \displayScheme
                # functions etc.
                message = message.encode('latin1').decode('utf-8', 'backslashreplace')
            super(LogWidget, self).writeMessage(message, type)
开发者ID:brownian,项目名称:frescobaldi,代码行数:42,代码来源:logwidget.py

示例5: loadFormats

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setAnchor [as 别名]

#.........这里部分代码省略.........
            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")

        inlineFormats = ['emphasis[role="highlight"]', 
                         'emphasis',
                         'code',
                         'link',
                         'olink']

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

            m = re.match(r'^(\S*?)(?:\[(.*)="(.*)"])?$', cssKey)
            selector = m.groups()

            charFmt = QTextCharFormat(pcharFmt)
            charFmt.setProperty(QTextFormat.UserProperty, selector)

            # TODO: better approach?
            if cssKey in ['link', 'olink']:
                charFmt.setAnchor(True)
            self.setCharFormatAttributes(cssRule, charFmt)

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

### special formats
        charFmt = QTextCharFormat()
        cssRule = self.simpleLookup(styleSheet, 'searchMarker')
        self.setCharFormatAttributes(cssRule, charFmt)
        self.formats[('searchMarker', None, None)] = Format(None, charFmt)
开发者ID:afester,项目名称:CodeSamples,代码行数:104,代码来源:FormatManager.py

示例6: OutputWidget

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setAnchor [as 别名]
class OutputWidget(QPlainTextEdit):

    def __init__(self, parent):
        super(OutputWidget, self).__init__(parent)
        self._parent = parent
        self.setReadOnly(True)
        self.maxValue = 0
        self.actualValue = 0
        #traceback pattern
        self.patLink = re.compile(r'(\s)*File "(.*?)", line \d.+')
        #formats
        font = QFont(settings.FONT_FAMILY, settings.FONT_SIZE)
        self.plain_format = QTextCharFormat()
        self.plain_format.setFont(font)
        self.plain_format.setForeground(QBrush(QColor(
            resources.CUSTOM_SCHEME.get("editor-text",
            resources.COLOR_SCHEME["editor-text"]))))
        self.error_format = QTextCharFormat()
        self.error_format.setFont(font)
        self.error_format.setAnchor(True)
        self.error_format.setFontUnderline(True)
        self.error_format.setUnderlineStyle(QTextCharFormat.SingleUnderline)
        self.error_format.setUnderlineColor(Qt.red)
        self.error_format.setForeground(Qt.blue)
        self.error_format.setToolTip(_translate("OutputWidget", "Click to show the source"))

        self.blockCountChanged[int].connect(self._scroll_area)

        css = 'QPlainTextEdit {color: %s; background-color: %s;' \
            'selection-color: %s; selection-background-color: %s;}' \
            % (resources.CUSTOM_SCHEME.get('editor-text',
            resources.COLOR_SCHEME['editor-text']),
            resources.CUSTOM_SCHEME.get('editor-background',
                resources.COLOR_SCHEME['editor-background']),
            resources.CUSTOM_SCHEME.get('editor-selection-color',
                resources.COLOR_SCHEME['editor-selection-color']),
            resources.CUSTOM_SCHEME.get('editor-selection-background',
                resources.COLOR_SCHEME['editor-selection-background']))
        self.setStyleSheet(css)

    def _scroll_area(self):
        """When new text is added to the widget, move the scroll to the end."""
        if self.actualValue == self.maxValue:
            self.moveCursor(QTextCursor.End)

    def mousePressEvent(self, event):
        """
        When the execution fail, allow to press the links in the traceback,
        to go to the line when the error occur.
        """
        QPlainTextEdit.mousePressEvent(self, event)
        self.go_to_error(event)

    def _refresh_output(self):
        """Read the output buffer from the process and append the text."""
        #we should decode the bytes!
        currentProcess = self._parent.currentProcess
        text = currentProcess.readAllStandardOutput().data().decode('utf8')
        verticalScroll = self.verticalScrollBar()
        self.actualValue = verticalScroll.value()
        self.maxValue = verticalScroll.maximum()
        self.textCursor().insertText(text, self.plain_format)

    def _refresh_error(self):
        """Read the error buffer from the process and append the text."""
        #we should decode the bytes!
        cursor = self.textCursor()
        currentProcess = self._parent.currentProcess
        text = currentProcess.readAllStandardError().data().decode('utf8')
        text_lines = text.split('\n')
        verticalScroll = self.verticalScrollBar()
        self.actualValue = verticalScroll.value()
        self.maxValue = verticalScroll.maximum()
        for t in text_lines:
            cursor.insertBlock()
            if self.patLink.match(t):
                cursor.insertText(t, self.error_format)
            else:
                cursor.insertText(t, self.plain_format)

    def go_to_error(self, event):
        """Resolve the link and take the user to the error line."""
        cursor = self.cursorForPosition(event.pos())
        text = cursor.block().text()
        if self.patLink.match(text):
            file_path, lineno = self._parse_traceback(text)
            main = main_container.MainContainer()
            main.open_file(file_path)
            main.editor_jump_to_line(lineno=int(lineno) - 1)

    def _parse_traceback(self, text):
        """
        Parse a line of python traceback and returns
        a tuple with (file_name, lineno)
        """
        file_word_index = text.find('File')
        comma_min_index = text.find(',')
        comma_max_index = text.rfind(',')
        file_name = text[file_word_index + 6:comma_min_index - 1]
        lineno = text[comma_min_index + 7:comma_max_index]
#.........这里部分代码省略.........
开发者ID:Salmista-94,项目名称:Ninja_PyQt5,代码行数:103,代码来源:run_widget.py


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