本文整理汇总了Python中PyQt4.QtCore.QTextStream.setCodec方法的典型用法代码示例。如果您正苦于以下问题:Python QTextStream.setCodec方法的具体用法?Python QTextStream.setCodec怎么用?Python QTextStream.setCodec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QTextStream
的用法示例。
在下文中一共展示了QTextStream.setCodec方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
# 需要导入模块: from PyQt4.QtCore import QTextStream [as 别名]
# 或者: from PyQt4.QtCore.QTextStream import setCodec [as 别名]
def save(self, content, path=None):
"""
Write a temprorary file with .tnj extension and copy it over the
original one.
.nsf = Ninja Swap File
#FIXME: Where to locate addExtension, does not fit here
"""
new_path = False
if path:
self.attach_to_path(path)
new_path = True
save_path = self._file_path
if not save_path:
raise NinjaNoFileNameException("I am asked to write a "
"file but no one told me where")
swap_save_path = "%s.nsp" % save_path
# If we have a file system watcher, remove the file path
# from its watch list until we are done making changes.
if self.__watcher:
self.__watcher.removePath(save_path)
flags = QIODevice.WriteOnly | QIODevice.Truncate
f = QFile(swap_save_path)
if settings.use_platform_specific_eol():
flags |= QIODevice.Text
if not f.open(flags):
raise NinjaIOException(f.errorString())
stream = QTextStream(f)
encoding = get_file_encoding(content)
if encoding:
stream.setCodec(encoding)
encoded_stream = stream.codec().fromUnicode(content)
f.write(encoded_stream)
f.flush()
f.close()
#SIGNAL: Will save (temp, definitive) to warn folder to do something
self.emit(SIGNAL("willSave(QString, QString)"),
swap_save_path, save_path)
self.__mtime = os.path.getmtime(swap_save_path)
shutil.move(swap_save_path, save_path)
self.reset_state()
# If we have a file system watcher, add the saved path back
# to its watch list, otherwise create a watcher and start
# watching
if self.__watcher:
if new_path:
self.__watcher.removePath(self.__watcher.files()[0])
self.__watcher.addPath(self._file_path)
else:
self.__watcher.addPath(save_path)
else:
self.start_watching()
return self
示例2: save
# 需要导入模块: from PyQt4.QtCore import QTextStream [as 别名]
# 或者: from PyQt4.QtCore.QTextStream import setCodec [as 别名]
def save(self, new):
fh = QFile("tools/" + self.name + ".tool")
if new and fh.exists():
return False
if fh.open(QIODevice.WriteOnly):
stream = QTextStream(fh)
stream.setCodec(CODEC)
stream << ("<?xml version='1.0' encoding='%s'?>\n<!DOCTYPE TOOL>\n<TOOL\n" % CODEC)
stream << (
"TIPDIAM='%s'\nSYRDIAM='%s'\nPATHWIDTH='%s'\nPATHHEIGHT='%s'\nJOGSPEED='%s'\nSUCKBACK='%s'\nPUSHOUT='%s'\n"
"PATHSPEED='%s'\nPAUSEPATHS='%s'\nCLEARANCE='%s'\nDEPOSITIONRATE='%s'\n>"
% (
self.tipDiam,
self.syrDiam,
self.pathWidth,
self.pathHeight,
self.jogSpeed,
self.suckback,
self.pushout,
self.pathSpeed,
self.pausePaths,
self.clearance,
self.depRate,
)
)
stream << ("\n</TOOL>")
fh.close()
return True
示例3: save
# 需要导入模块: from PyQt4.QtCore import QTextStream [as 别名]
# 或者: from PyQt4.QtCore.QTextStream import setCodec [as 别名]
def save(self):
"""Hum ... just save ..."""
if self.filename.startswith("Unnamed"):
filename = self.parent().parent().parent().saveAsFile()
if not (filename == ''):
return
self.filename = filename
self.setWindowTitle( QFileInfo(self.filename).fileName())
exception = None
filehandle = None
try:
#Before FileSave plugin hook
for plugin in filter_plugins_by_capability('beforeFileSave',self.enabled_plugins):
plugin.do_beforeFileSave(self)
filehandle = QFile(self.filename)
if not filehandle.open( QIODevice.WriteOnly):
raise IOError, unicode(filehandle.errorString())
stream = QTextStream(filehandle)
stream.setCodec("UTF-8")
stream << self.toPlainText()
self.document().setModified(False)
RecentFiles().append(self.filename)
except (IOError, OSError), ioError:
exception = ioError
示例4: exportXml
# 需要导入模块: from PyQt4.QtCore import QTextStream [as 别名]
# 或者: from PyQt4.QtCore.QTextStream import setCodec [as 别名]
def exportXml(self, fname):
error = None
fh = None
try:
fh = QFile(fname)
if not fh.open(QIODevice.WriteOnly):
raise IOError(str(fh.errorString()))
stream = QTextStream(fh)
stream.setCodec(CODEC)
stream << ("<?xml version='1.0' encoding='{0}'?>\n"
"<!DOCTYPE MOVIES>\n"
"<MOVIES VERSION='1.0'>\n".format(CODEC))
for key, movie in self.__movies:
stream << ("<MOVIE YEAR='{0}' MINUTES='{1}' "
"ACQUIRED='{2}'>\n".format(movie.year,
movie.minutes,
movie.acquired.toString(Qt.ISODate))) \
<< "<TITLE>" << Qt.escape(movie.title) \
<< "</TITLE>\n<NOTES>"
if not movie.notes.isEmpty():
stream << "\n" << Qt.escape(
encodedNewlines(movie.notes))
stream << "\n</NOTES>\n</MOVIE>\n"
stream << "</MOVIES>\n"
except EnvironmentError as e:
error = "Failed to export: {0}".format(e)
finally:
if fh is not None:
fh.close()
if error is not None:
return False, error
self.__dirty = False
return True, "Exported {0} movie records to {1}".format(
len(self.__movies),
QFileInfo(fname).fileName())
示例5: saveQTextStream
# 需要导入模块: from PyQt4.QtCore import QTextStream [as 别名]
# 或者: from PyQt4.QtCore.QTextStream import setCodec [as 别名]
def saveQTextStream(self):
error = None
fh = None
try:
fh = QFile(self.__fname)
if not fh.open(QIODevice.WriteOnly):
raise IOError(str(fh.errorString()))
stream = QTextStream(fh)
stream.setCodec(CODEC)
for key, movie in self.__movies:
stream << "{{MOVIE}} " << movie.title << "\n" \
<< movie.year << " " << movie.minutes << " " \
<< movie.acquired.toString(Qt.ISODate) \
<< "\n{NOTES}"
if not movie.notes.isEmpty():
stream << "\n" << movie.notes
stream << "\n{{ENDMOVIE}}\n"
except EnvironmentError as e:
error = "Failed to save: {0}".format(e)
finally:
if fh is not None:
fh.close()
if error is not None:
return False, error
self.__dirty = False
return True, "Saved {0} movie records to {1}".format(
len(self.__movies),
QFileInfo(self.__fname).fileName())
示例6: save_file
# 需要导入模块: from PyQt4.QtCore import QTextStream [as 别名]
# 或者: from PyQt4.QtCore.QTextStream import setCodec [as 别名]
def save_file(self):
"""
Saving file to the path where getting from QFileDialog
"""
fileobject = None
if self.path is "":
self.path = QFileDialog.getSaveFileName(self,
"TextEditor",
self.tr("unnamed"))
try:
fileobject = QFile(self.path)
if not fileobject.open(QIODevice.WriteOnly):
raise IOError, unicode(fileobject.errorString())
textstream = QTextStream(fileobject)
textstream.setCodec("UTF-8")
textstream << self.textEdit.toPlainText()
self.textEdit.document().setModified(False)
self.setWindowTitle("%s - TextEditor" %
QFileInfo(self.path).fileName())
except (IOError, OSError), error:
QMessageBox.warning(self,
self.tr("TextEditor - Save Error"),
self.tr("Unable to save {0}:{1}".format(
self.path, error)))
self.path = ""
示例7: save
# 需要导入模块: from PyQt4.QtCore import QTextStream [as 别名]
# 或者: from PyQt4.QtCore.QTextStream import setCodec [as 别名]
def save(self):
if self.filename.startsWith("Unnamed"):
filename = QFileDialog.getSaveFileName(self,
"Text Editor -- Save File As", self.filename,
"Text files (*.txt *.*)")
if filename.isEmpty():
return
self.filename = filename
self.setWindowTitle(QFileInfo(self.filename).fileName())
exception = None
fh = None
try:
fh = QFile(self.filename)
if not fh.open(QIODevice.WriteOnly):
raise IOError(str(fh.errorString()))
stream = QTextStream(fh)
stream.setCodec("UTF-8")
stream << self.toPlainText()
self.document().setModified(False)
except EnvironmentError as e:
exception = e
finally:
if fh is not None:
fh.close()
if exception is not None:
raise exception
示例8: load
# 需要导入模块: from PyQt4.QtCore import QTextStream [as 别名]
# 或者: from PyQt4.QtCore.QTextStream import setCodec [as 别名]
def load(self):
exception = None
fh = None
try:
fh = QFile(self.filename)
if not fh.open(QIODevice.ReadOnly):
raise IOError, unicode(fh.errorString())
stream = QTextStream(fh)
stream.setCodec("UTF-8")
self.setPlainText(stream.readAll())
self.document().setModified(False)
except (IOError, OSError), e:
exception = e
示例9: save
# 需要导入模块: from PyQt4.QtCore import QTextStream [as 别名]
# 或者: from PyQt4.QtCore.QTextStream import setCodec [as 别名]
def save(self, content, path=None):
"""
Write a temprorary file with .tnj extension and copy it over the
original one.
.nsf = Ninja Swap File
#FIXME: Where to locate addExtension, does not fit here
"""
if path and self._file_path:
created_file = NFile(path).save(content)
self.emit(SIGNAL("savedAsNewFile(PyQt_PyObject, QString, QString)"),
created_file, self._file_path, path)
return created_file
elif path and not self._file_path:
self.attach_to_path(path)
save_path = self._file_path
if not save_path:
raise NinjaNoFileNameException("I am asked to write a "
"file but no one told me where")
swap_save_path = u"%s.nsp" % save_path
flags = QIODevice.WriteOnly | QIODevice.Truncate
f = QFile(swap_save_path)
if settings.use_platform_specific_eol():
flags |= QIODevice.Text
if not f.open(flags):
raise NinjaIOException(f.errorString())
stream = QTextStream(f)
encoding = get_file_encoding(content)
if encoding:
stream.setCodec(encoding)
encoded_stream = stream.codec().fromUnicode(content)
f.write(encoded_stream)
f.flush()
f.close()
#SIGNAL: Will save (temp, definitive) to warn folder to do something
self.emit(SIGNAL("willSave(QString, QString)"), swap_save_path,
save_path)
shutil.move(swap_save_path, save_path)
self.reset_state()
return self
示例10: load
# 需要导入模块: from PyQt4.QtCore import QTextStream [as 别名]
# 或者: from PyQt4.QtCore.QTextStream import setCodec [as 别名]
def load(self):
exception = None
fh = None
try:
fh = QFile(self.filename)
if not fh.open(QIODevice.ReadOnly):
raise IOError(str(fh.errorString()))
stream = QTextStream(fh)
stream.setCodec("UTF-8")
self.setPlainText(stream.readAll())
self.document().setModified(False)
except EnvironmentError as e:
exception = e
finally:
if fh is not None:
fh.close()
if exception is not None:
raise exception
示例11: __init__
# 需要导入模块: from PyQt4.QtCore import QTextStream [as 别名]
# 或者: from PyQt4.QtCore.QTextStream import setCodec [as 别名]
def __init__(self, parent=None ):
super(helpDisplay, self).__init__(parent)
# make page unmodifiable
self.page().setContentEditable(False)
# initialize settings
# Find out the nearest font to Palatino
qf = QFont()
qf.setStyleStrategy(QFont.PreferAntialias+QFont.PreferMatch)
qf.setStyleHint(QFont.Serif)
qf.setFamily(QString(u'Palatino'))
qfi = QFontInfo(qf)
# set the default font to that serif font
self.settings().setFontFamily(QWebSettings.StandardFont, qfi.family())
self.settings().setFontSize(QWebSettings.DefaultFontSize, 16)
self.settings().setFontSize(QWebSettings.MinimumFontSize, 6)
self.settings().setFontSize(QWebSettings.MinimumLogicalFontSize, 6)
self.textZoomFactor = 1.0
self.setTextSizeMultiplier(self.textZoomFactor)
self.settings().setAttribute(QWebSettings.JavascriptEnabled, False)
self.settings().setAttribute(QWebSettings.JavaEnabled, False)
self.settings().setAttribute(QWebSettings.PluginsEnabled, False)
self.settings().setAttribute(QWebSettings.ZoomTextOnly, True)
#self.settings().setAttribute(QWebSettings.SiteSpecificQuirksEnabled, False)
self.userFindText = QString()
# Look for pqHelp.html in the app folder and copy its text into
# a local buffer. If it isn't found, put a message there instead.
# We need to keep it in order to implement the "back" function.
helpPath = os.path.join(IMC.appBasePath,u'pqHelp.html')
helpFile = QFile(helpPath)
if not helpFile.exists():
self.HTMLstring = QString('''<p>Unable to locate pqHelp.html.</p>
<p>Looking in {0}'''.format(helpPath)
)
elif not helpFile.open(QIODevice.ReadOnly) :
self.HTMLstring = QString('''<p>Unable to open pqHelp.html.</p>
<p>Looking in {0}</p><p>Error code {1}</p>'''.format(helpPath,
helpFile.error())
)
else:
helpStream = QTextStream(helpFile)
helpStream.setCodec('ISO8859-1')
self.HTMLstring = helpStream.readAll()
self.setHtml(self.HTMLstring)
示例12: load
# 需要导入模块: from PyQt4.QtCore import QTextStream [as 别名]
# 或者: from PyQt4.QtCore.QTextStream import setCodec [as 别名]
def load(self):
"""Load ?"""
exception = None
filehandle = None
try:
filehandle = QFile(self.filename)
if not filehandle.open( QIODevice.ReadOnly):
raise IOError, unicode(filehandle.errorString())
stream = QTextStream(filehandle)
stream.setCodec("UTF-8")
QApplication.processEvents()
self.setPlainText(stream.readAll())
self.document().setModified(False)
self.setWindowTitle( QFileInfo(self.filename).fileName())
self.loadHighlighter(self.filename)
for plugin in filter_plugins_by_capability('afterFileOpen',self.enabled_plugins):
plugin.do_afterFileOpen(self)
except (IOError, OSError), error:
exception = error
示例13: func_Save_config
# 需要导入模块: from PyQt4.QtCore import QTextStream [as 别名]
# 或者: from PyQt4.QtCore.QTextStream import setCodec [as 别名]
def func_Save_config(self):
if (self.box_warn.isChecked()): conf_warn = "true"
else: conf_warn = "false"
if (self.box_1inst.isChecked()): conf_1inst = "true"
else: conf_1inst = "false"
if (self.box_systray.isChecked()): conf_systray = "true"
else: conf_systray = "false"
if (self.box_min.isChecked()): conf_min = "true"
else: conf_min = "false"
if (self.box_close.isChecked()): conf_close = "true"
else: conf_close = "false"
filename = QFile(os.getenv("HOME")+"/.qtsixa2/conf.xml")
if not filename.open(QIODevice.WriteOnly):
QMessageBox.critical(self, self.tr("QtSixA - Error"), self.tr("Cannot write QtSixA configuration file!"))
raise IOError, unicode(filename.errorString())
stream = QTextStream(filename)
stream.setCodec("UTF-8")
stream << ("<?xml version='1.0' encoding='UTF-8'?>\n"
"<!DOCTYPE QTSIXA>\n"
"<QTSIXA VERSION='1.5.0'>\n"
" <Configuration>\n"
" <Main>\n"
" <Show-Warnings>%s</Show-Warnings>\n"
" <Only-One-Instance>%s</Only-One-Instance>\n"
" </Main>\n"
" <Systray>\n"
" <Enable>%s</Enable>\n"
" <Start-Minimized>%s</Start-Minimized>\n"
" <Close-to-Tray>%s</Close-to-Tray>\n"
" </Systray>\n"
" </Configuration>\n"
"</QTSIXA>\n" % ( conf_warn, conf_1inst, conf_systray, conf_min, conf_close )
)
shared.Globals.show_warnings = self.box_warn.isChecked()
shared.Globals.only_one_instance = self.box_1inst.isChecked()
shared.Globals.systray_enabled = self.box_systray.isChecked()
shared.Globals.start_minimized = self.box_min.isChecked()
shared.Globals.close_to_tray = self.box_close.isChecked()
示例14: save
# 需要导入模块: from PyQt4.QtCore import QTextStream [as 别名]
# 或者: from PyQt4.QtCore.QTextStream import setCodec [as 别名]
def save(self, new):
fh = QFile('config/' + self.name + '.printer')
if new and fh.exists():
return False
if fh.open(QIODevice.WriteOnly):
stream = QTextStream(fh)
stream.setCodec(CODEC)
stream << ("<?xml version='1.0' encoding='%s'?>\n<!DOCTYPE PRINTER>\n<PRINTER\n" % CODEC)
stream << ("UPDATEPERIOD='%s'\nJOGSPEED='%s'\nMAXTOOLS='%s'\nTOOLLIMIT='%s'\nMAXACCEL='%s'\n"
"XMAX='%s'\nYMAX='%s'\nZMAX='%s'\n>\n" % (self.updatePeriod, self.jogSpeed, self.maxTools,
self.toolLimit, self.maxAccel, self.xMax, self.yMax, self.zMax))
now = self.base
stream << ("<BASE\nDIRECTION='%s'\nMOTOR='%s'\nRANGE='%s'\nLIMITS='%s'\nINCREMENT='%s'\n>\n"
% (now.direction, now.motor, now.arange, now.limits, now.increment))
stream << ("</BASE>\n")
now = self.x
stream << ("<XAXIS\nDIRECTION='%s'\nMOTOR='%s'\nRANGE='%s'\nLIMITS='%s'\nINCREMENT='%s'\n>\n"
% (now.direction, now.motor, now.arange, now.limits, now.increment))
stream << ("</XAXIS>\n")
now = self.y
stream << ("<YAXIS\nDIRECTION='%s'\nMOTOR='%s'\nRANGE='%s'\nLIMITS='%s'\nINCREMENT='%s'\n>\n"
% (now.direction, now.motor, now.arange, now.limits, now.increment))
stream << ("</YAXIS>\n")
now = self.z
stream << ("<ZAXIS\nDIRECTION='%s'\nMOTOR='%s'\nRANGE='%s'\nLIMITS='%s'\nINCREMENT='%s'\n>\n"
% (now.direction, now.motor, now.arange, now.limits, now.increment))
stream << ("</ZAXIS>\n")
now = self.u
stream << ("<UAXIS\nDIRECTION='%s'\nMOTOR='%s'\nRANGE='%s'\nLIMITS='%s'\nINCREMENT='%s'\n>\n"
% (now.direction, now.motor, now.arange, now.limits, now.increment))
stream << ("</UAXIS>\n")
if self.maxTools > 1:
now = self.v
stream << ("<VAXIS\nDIRECTION='%s'\nMOTOR='%s'\nRANGE='%s'\nLIMITS='%s'\nINCREMENT='%s'\n>\n"
% (now.direction, now.motor, now.arange, now.limits, now.increment))
stream << ("</VAXIS>\n")
stream << ("</PRINTER>\n")
fh.close()
return True
示例15: write_description_content
# 需要导入模块: from PyQt4.QtCore import QTextStream [as 别名]
# 或者: from PyQt4.QtCore.QTextStream import setCodec [as 别名]
def write_description_content(handle, data):
""" This function generates the xml content of the description
file.
"""
stream = QTextStream(handle)
stream.setCodec("UTF-8")
stream << ("<?xml version='1.0' encoding='UTF-8'?>\n"
"<sconcho>\n"
" <knittingSymbol>\n"
" <svgName>%s</svgName>\n"
" <category>%s</category>\n"
" <symbolName>%s</symbolName>\n"
" <symbolDescription>%s</symbolDescription>\n"
" <symbolWidth>%d</symbolWidth>\n"
" </knittingSymbol>\n"
"</sconcho>\n"
% (Qt.escape(data["svgName"]),
Qt.escape(data["category"]),
Qt.escape(data["name"]),
Qt.escape(data["description"]),
data["width"]))