本文整理汇总了Python中PyQt5.QtCore.QByteArray.replace方法的典型用法代码示例。如果您正苦于以下问题:Python QByteArray.replace方法的具体用法?Python QByteArray.replace怎么用?Python QByteArray.replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QByteArray
的用法示例。
在下文中一共展示了QByteArray.replace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write
# 需要导入模块: from PyQt5.QtCore import QByteArray [as 别名]
# 或者: from PyQt5.QtCore.QByteArray import replace [as 别名]
def write(self, map, fileName):
# Check layer count and type
if (map.layerCount() != 1 or not map.layerAt(0).isTileLayer()) :
self.mError = self.tr("The map needs to have exactly one tile layer!")
return False
mapLayer = map.layerAt(0).asTileLayer()
# Check layer size
if (mapLayer.width() != 48 or mapLayer.height() != 48) :
self.mError = self.tr("The layer must have a size of 48 x 48 tiles!")
return False
# Create QByteArray and compress it
uncompressed = QByteArray(48 * 48, b'\x00')
width = mapLayer.width()
height = mapLayer.height()
for y in range(0, height):
for x in range(0, width):
tile = mapLayer.cellAt(x, y).tile
if tile:
# 'QByteArray' object does not support item assignment
uncompressed.replace(y * width + x, 1, bytes([tile.id()&0xff]))
compressed = compress(uncompressed, CompressionMethod.Gzip)
# Write QByteArray
file = QSaveFile(fileName)
if (not file.open(QIODevice.WriteOnly)) :
self.mError = self.tr("Could not open file for writing.")
return False
file.write(compressed)
if not file.commit():
self.mError = file.errorString()
return False
return True
示例2: __createSpeedDialPage
# 需要导入模块: from PyQt5.QtCore import QByteArray [as 别名]
# 或者: from PyQt5.QtCore.QByteArray import replace [as 别名]
def __createSpeedDialPage(self):
"""
Private method to create the Speeddial page.
@return prepared speeddial page (QByteArray)
"""
if self._speedDialPage is None:
htmlFile = QFile(":/html/speeddialPage.html")
htmlFile.open(QFile.ReadOnly)
html = bytes(htmlFile.readAll()).decode()
html = (
html.replace("@[email protected]", "qrc:icons/ericWeb16.png")
.replace("@[email protected]", "qrc:icons/plus.png")
.replace("@[email protected]", "qrc:icons/close.png")
.replace("@[email protected]", "qrc:icons/edit.png")
.replace("@[email protected]", "qrc:icons/reload.png")
.replace("@[email protected]", "qrc:icons/setting.png")
.replace("@[email protected]", "qrc:icons/loading.gif")
.replace("@[email protected]", "qrc:icons/box-border-small.png")
.replace("@[email protected]", "qrc:javascript/jquery.js")
.replace("@[email protected]", "qrc:javascript/jquery-ui.js")
.replace("@[email protected]", self.tr("Speed Dial"))
.replace("@[email protected]", self.tr("URL"))
.replace("@[email protected]", self.tr("Title"))
.replace("@[email protected]", self.tr("Apply"))
.replace("@[email protected]", self.tr("Close"))
.replace("@[email protected]", self.tr("New Page"))
.replace("@[email protected]", self.tr("Edit"))
.replace("@[email protected]", self.tr("Remove"))
.replace("@[email protected]", self.tr("Reload"))
.replace("@[email protected]",
self.tr("Are you sure to remove this speed dial?"))
.replace("@[email protected]",
self.tr("Load title from page"))
.replace("@[email protected]",
self.tr("Speed Dial Settings"))
.replace("@[email protected]", self.tr("Add New Page"))
.replace("@[email protected]",
self.tr("Maximum pages in a row:"))
.replace("@[email protected]", self.tr("Change size of pages:"))
)
self._speedDialPage = Utilities.html_uencode(html)
import Helpviewer.HelpWindow
html = QByteArray(self._speedDialPage.encode("utf-8"))
dial = Helpviewer.HelpWindow.HelpWindow.speedDial()
html.replace("@[email protected]", dial.initialScript().encode("utf-8"))
html.replace("@[email protected]", str(dial.pagesInRow()).encode("utf-8"))
html.replace("@[email protected]", str(dial.sdSize()).encode("utf-8"))
return html