本文整理匯總了Python中PyQt5.QtCore.QTextCodec.codecForUtfText方法的典型用法代碼示例。如果您正苦於以下問題:Python QTextCodec.codecForUtfText方法的具體用法?Python QTextCodec.codecForUtfText怎麽用?Python QTextCodec.codecForUtfText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyQt5.QtCore.QTextCodec
的用法示例。
在下文中一共展示了QTextCodec.codecForUtfText方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: openFile
# 需要導入模塊: from PyQt5.QtCore import QTextCodec [as 別名]
# 或者: from PyQt5.QtCore.QTextCodec import codecForUtfText [as 別名]
def openFile(self):
filename, _ = QFileDialog.getOpenFileName(self, 'Open File',
os.getenv('HOME'))
if not filename:
return
fh = ''
if QFile.exists(filename):
fh = QFile(filename)
if not fh.open(QFile.ReadOnly):
QtGui.qApp.quit()
data = fh.readAll()
codec = QTextCodec.codecForUtfText(data)
unistr = codec.toUnicode(data)
tmp = ('Nopepad: %s' % filename)
self.setWindowTitle(tmp)
basename = QFileInfo(fh).baseName()
self.statusBar().showMessage('File \'%s\' loaded' % basename)
self.textEdit.setText(unistr)
示例2: on_load
# 需要導入模塊: from PyQt5.QtCore import QTextCodec [as 別名]
# 或者: from PyQt5.QtCore.QTextCodec import codecForUtfText [as 別名]
def on_load():
file = QFile(filename)
fileinfo = QFileInfo(file)
file.open(QFile.ReadOnly)
data = file.readAll()
codec = QTextCodec.codecForUtfText(data)
unistr = codec.toUnicode(data)
self.page().mainFrame().findFirstElement("#editor").setInnerXml(unistr)
self.page().mainFrame().evaluateJavaScript("init()")
suffix = fileinfo.suffix()
self.page().mainFrame().evaluateJavaScript("editor.getSession().setMode('%s');" % (
self.SUFIX_2_MODE[suffix] if suffix in self.SUFIX_2_MODE else self.SUFIX_2_MODE[None]
))
示例3: open
# 需要導入模塊: from PyQt5.QtCore import QTextCodec [as 別名]
# 或者: from PyQt5.QtCore.QTextCodec import codecForUtfText [as 別名]
def open(self, filename):
if not QFile.exists(filename):
return
file = QFile(filename)
file.open(QFile.ReadOnly)
data = file.readAll()
codec = QTextCodec.codecForUtfText(data)
unistr = codec.toUnicode(data)
self._set_window_title(filename)
self.webView.page().mainFrame().findFirstElement("#editor").setInnerXml(unistr)
self.webView.page().mainFrame().evaluateJavaScript("init()")
self._set_mode_by_filename(filename)