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


Python QTextDocument.toPlainText方法代码示例

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


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

示例1: htmlToPlainText

# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import toPlainText [as 别名]
def htmlToPlainText(text):
    RICH_PREFIX = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" '\
                  '"http://www.w3.org/TR/REC-html40/strict.dtd">'
    if text.startswith(RICH_PREFIX):
        document = QTextDocument()
        document.setHtml(text)
        text = document.toPlainText()

    return text
开发者ID:OpenNumismat,项目名称:open-numismat,代码行数:11,代码来源:Converters.py

示例2: TestIndentation

# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import toPlainText [as 别名]
class TestIndentation(unittest.TestCase):
	def setUp(self):
		self.document = QTextDocument()
		self.document.setPlainText('foo\nbar\nbaz')
		self.settings = SettingsMock()

	def test_indentMore(self):
		cursor = QTextCursor(self.document)
		cursor.setPosition(4)
		documentIndentMore(self.document, cursor, self.settings)
		self.assertEqual('foo\n    bar\nbaz',
		                 self.document.toPlainText())
		cursor.setPosition(3)
		documentIndentMore(self.document, cursor, self.settings)
		self.assertEqual('foo \n    bar\nbaz',
		                 self.document.toPlainText())

	def test_indentMoreWithTabs(self):
		cursor = QTextCursor(self.document)
		self.settings.tabInsertsSpaces = False
		documentIndentMore(self.document, cursor, self.settings)
		self.assertEqual('\tfoo\nbar\nbaz', self.document.toPlainText())

	def test_indentMoreWithSelection(self):
		cursor = QTextCursor(self.document)
		cursor.setPosition(1)
		cursor.setPosition(6, QTextCursor.KeepAnchor)
		self.assertEqual('oo\u2029ba', # \u2029 is paragraph separator
		                 cursor.selectedText())
		documentIndentMore(self.document, cursor, self.settings)
		self.assertEqual('    foo\n    bar\nbaz',
		                 self.document.toPlainText())

	def test_indentLess(self):
		self.document.setPlainText('        foo')
		cursor = QTextCursor(self.document)
		cursor.setPosition(10)
		documentIndentLess(self.document, cursor, self.settings)
		self.assertEqual('    foo', self.document.toPlainText())
		documentIndentLess(self.document, cursor, self.settings)
		self.assertEqual('foo', self.document.toPlainText())

	def test_indentLessWithSelection(self):
		self.document.setPlainText('    foo\n    bar\nbaz')
		cursor = QTextCursor(self.document)
		cursor.setPosition(5)
		cursor.setPosition(11, QTextCursor.KeepAnchor)
		documentIndentLess(self.document, cursor, self.settings)
		self.assertEqual('foo\nbar\nbaz', self.document.toPlainText())
开发者ID:liyongming1982,项目名称:retext,代码行数:51,代码来源:test_editor.py

示例3: formatText

# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import toPlainText [as 别名]
    def formatText(self, text, _type):

        if not text:
            return text

            # if _type == "t2t":
            # text = self.runT2T(text)

            # elif _type == "txt":
            # text = text.replace("\n", "<br>")

        elif _type == "html":
            doc = QTextDocument()
            doc.setHtml(text)
            text = doc.toPlainText()
            # text = self.htmlBody(text)

        return text
开发者ID:TenKeyAngle,项目名称:manuskript,代码行数:20,代码来源:odt.py

示例4: forecastdata

# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import toPlainText [as 别名]
    def forecastdata(self):
        '''Forecast for the next 6 days'''
        # Some times server sends less data
        doc = QTextDocument()
        periods = 7
        fetched_file_periods = (len(self.tree.xpath('//time')))
        if fetched_file_periods < periods:
            periods = fetched_file_periods
            logging.warn('Reduce forecast for the next 6 days to {0}'.format(
                periods-1))
        for d in range(1, periods):
            date_list = self.tree[4][d].get('day').split('-')
            day_of_week = str(datetime.date(
                int(date_list[0]), int(date_list[1]),
                int(date_list[2])).weekday())
            label = QLabel('' + self.days_dico[day_of_week] + '')
            label.setToolTip(self.tree[4][d].get('day'))
            label.setAlignment(Qt.AlignHCenter)
            self.forecast_days_layout.addWidget(label)
            mlabel = QLabel(
                '<font color=grey>' + '{0:.0f}'.format(float(
                    self.tree[4][d][4].get('min'))) + '°<br/>' +
                '{0:.0f}'.format(float(self.tree[4][d][4].get('max'))) +
                '°</font>')
            mlabel.setAlignment(Qt.AlignHCenter)
            mlabel.setToolTip(self.tr('Min Max Temperature of the day'))
            self.forecast_minmax_layout.addWidget(mlabel)
            self.icon_list.append(self.tree[4][d][0].get('var'))  # icon
            weather_cond = self.tree[4][d][0].get('name')
            try:
                weather_cond = self.conditions[self.tree[4][d][0].get(
                    'number')]
            except:
                logging.warn('Cannot find localisation string for :' +
                             weather_cond)
                pass
            try:
                doc.setHtml(self.precipitation_label.text())
                precipitation_label = doc.toPlainText() + ': '
                precipitation_type = self.tree[4][d][1].get('type')
                precipitation_type = self.precipitation[precipitation_type] + ' '
                precipitation_value = self.tree[4][d][1].get('value')
                rain_unit = ' mm'
                if self.speed_unit == ' mph ':
                    rain_unit = ' inch'
                    precipitation_value = str(float(precipitation_value) / 25.4) + ' '
                    precipitation_value = "{0:.2f}".format(float(precipitation_value))
                else:
                    precipitation_value = "{0:.1f}".format(float(precipitation_value))
                weather_cond += ('\n' + precipitation_label + precipitation_type +
                                 precipitation_value + rain_unit)
            except:
                pass
            doc.setHtml(self.wind_label.text())
            wind = doc.toPlainText() + ': '
            try:
                wind_direction = self.wind_direction[self.tree[4][d][2].get('code')]
            except:
                wind_direction = ''
            wind_speed = '{0:.1f}'.format(float(self.tree[4][d][3].get('mps')))
            weather_cond += '\n' + wind + wind_speed + self.speed_unit + wind_direction
            doc.setHtml(self.pressure_label.text())
            pressure_label = doc.toPlainText() + ': '
            pressure = '{0:.1f}'.format(float(self.tree[4][d][5].get('value')))
            weather_cond += '\n' + pressure_label + pressure + ' hPa'
            humidity = self.tree[4][d][6].get('value')
            doc.setHtml(self.humidity_label.text())
            humidity_label = doc.toPlainText() + ': '
            weather_cond += '\n' + humidity_label + humidity + ' %'
            clouds = self.tree[4][d][7].get('all')
            doc.setHtml(self.clouds_label.text())
            clouds_label = doc.toPlainText() + ': '
            weather_cond += '\n' + clouds_label + clouds + ' %'

            self.forecast_weather_list.append(weather_cond)
开发者ID:pmattern,项目名称:meteo-qt,代码行数:77,代码来源:overview.py


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