本文整理汇总了Python中PyQt4.QtCore.QFile方法的典型用法代码示例。如果您正苦于以下问题:Python QtCore.QFile方法的具体用法?Python QtCore.QFile怎么用?Python QtCore.QFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore
的用法示例。
在下文中一共展示了QtCore.QFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: whoisqutrub
# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import QFile [as 别名]
def whoisqutrub(self):
RightToLeft=1;
msgBox=QtGui.QMessageBox(self.centralwidget);
msgBox.setWindowTitle(u"عن البرنامج");
data=QtCore.QFile("ar/projects.html");
if (data.open(QtCore.QFile.ReadOnly)):
textstream=QtCore.QTextStream(data);
textstream.setCodec("UTF-8");
text=textstream.readAll();
else:
text=u"لا يمكن فتح ملف المساعدة"
msgBox.setText(text);
msgBox.setLayoutDirection(RightToLeft);
msgBox.setStandardButtons(QtGui.QMessageBox.Ok);
msgBox.setDefaultButton(QtGui.QMessageBox.Ok);
msgBox.exec_();
示例2: about
# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import QFile [as 别名]
def about(self):
RightToLeft=1;
msgBox=QtGui.QMessageBox(self.centralwidget);
msgBox.setWindowTitle(u"عن البرنامج");
## msgBox.setTextFormat(QrCore.QRichText);
data=QtCore.QFile("ar/about.html");
if (data.open(QtCore.QFile.ReadOnly)):
textstream=QtCore.QTextStream(data);
textstream.setCodec("UTF-8");
text_about=textstream.readAll();
else:
# text=u"لا يمكن فتح ملف المساعدة"
text_about=u"""<h1>فكرة</h1>
"""
msgBox.setText(text_about);
msgBox.setLayoutDirection(RightToLeft);
msgBox.setStandardButtons(QtGui.QMessageBox.Ok);
msgBox.setIconPixmap(QtGui.QPixmap(os.path.join(PWD, "ar/images/logo.png")));
msgBox.setDefaultButton(QtGui.QMessageBox.Ok);
msgBox.exec_();
示例3: setDarkTheme
# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import QFile [as 别名]
def setDarkTheme(boolean):
if boolean:
qss = ''
ColorTheme.SELECTED = ColorTheme.DARK
Settings.setValue(Settings.COLORTHEME, 'darkorange')
# noinspection PyBroadException
try:
qfile = QFile(':qss/darkorange.qss')
if qfile.open(QIODevice.ReadOnly | QIODevice.Text):
qss = str(qfile.readAll())
qfile.close()
except:
qss = ''
pass
QtGui.QApplication.setStyle(ColorTheme.originalStyle)
QtGui.QApplication.setPalette(ColorTheme.originalPalette)
QtGui.QApplication.instance().setStyleSheet(qss)
示例4: rename_file
# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import QFile [as 别名]
def rename_file(self):
"""
Remane the existing instance file with Guuid from the mobile divice to conform with GeoODk naming
convention
:return:
"""
if isinstance(self.file, QFile):
dir_n, file_n = os.path.split(self.file_path)
os.chdir(dir_n)
if not file_n.startswith(UUID):
new_file_name = self.uuid_element()+".xml"
isrenamed = self.file.setFileName(new_file_name)
os.rename(file_n, new_file_name)
self.new_list.append(new_file_name)
return isrenamed
else:
self.new_list.append(self.file.fileName())
self.file.close()
else:
return
示例5: load
# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import QFile [as 别名]
def load(self, f):
if not QtCore.QFile.exists(f):
self.text_type = 'text'
return "File %s could not be found." % f
try:
file_handle = QtCore.QFile(f)
file_handle.open(QtCore.QFile.ReadOnly)
data = file_handle.readAll()
codec = QtCore.QTextCodec.codecForHtml(data)
return codec.toUnicode(data)
except:
self.text_type = 'text'
return 'Problem reading file %s' % f
示例6: getSize
# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import QFile [as 别名]
def getSize(layer):
"""Get layer size on disk"""
is_zip_file = False
file_path = layer.dataProvider().dataSourceUri()
if file_path.find('|') != -1:
file_path = file_path[0:file_path.find('|')]
if file_path.startswith('/vsizip/'):
file_path = file_path.replace('/vsizip/', '')
is_zip_file = True
_file = QFile(file_path)
file_info = QFileInfo(_file)
dirname = file_info.dir().absolutePath()
filename = file_info.completeBaseName()
size = 0
if layer.storageType() == 'ESRI Shapefile' and not is_zip_file:
for suffix in ['.shp', '.dbf', '.prj', '.shx']:
_file = QFile(os.path.join(dirname, filename + suffix))
file_info = QFileInfo(_file)
size = size + file_info.size()
elif layer.storageType() in ['GPX', 'GeoJSON', 'LIBKML'] or is_zip_file:
size = size + file_info.size()
return size
示例7: zipLayer
# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import QFile [as 别名]
def zipLayer(layer):
"""Compress layer to zip file"""
file_path = layer.dataProvider().dataSourceUri()
if file_path.find('|') != -1:
file_path = file_path[0:file_path.find('|')]
if file_path.startswith('/vsizip/'):
file_path = file_path.replace('/vsizip/', '')
if layer.storageType() in ['ESRI Shapefile', 'GPX', 'GeoJSON', 'LIBKML']:
return file_path
_file = QFile(file_path)
file_info = QFileInfo(_file)
dirname = file_info.dir().absolutePath()
filename = stripAccents(file_info.completeBaseName())
layername = stripAccents(layer.name())
tempdir = checkTempDir()
zip_path = os.path.join(tempdir, layername + '.zip')
zip_file = zipfile.ZipFile(zip_path, 'w')
if layer.storageType() == 'ESRI Shapefile':
for suffix in ['.shp', '.dbf', '.prj', '.shx']:
if os.path.exists(os.path.join(dirname, filename + suffix)):
zip_file.write(os.path.join(dirname, filename + suffix), layername + suffix, zipfile.ZIP_DEFLATED)
elif layer.storageType() == 'GeoJSON':
zip_file.write(file_path, layername + '.geojson', zipfile.ZIP_DEFLATED)
elif layer.storageType() == 'GPX':
zip_file.write(file_path, layername + '.gpx', zipfile.ZIP_DEFLATED)
elif layer.storageType() == 'LIBKML':
zip_file.write(file_path, layername + '.kml', zipfile.ZIP_DEFLATED)
else:
geo_json_name = os.path.join(tempfile.tempdir, layername)
error = QgsVectorFileWriter.writeAsVectorFormat(layer, geo_json_name, "utf-8", None, "GeoJSON")
if error == QgsVectorFileWriter.NoError:
zip_file.write(geo_json_name + '.geojson', layername + '.geojson', zipfile.ZIP_DEFLATED)
zip_file.close()
return zip_path
示例8: print_result
# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import QFile [as 别名]
def print_result(self):
if "HTML" in self.result:
data=QtCore.QFile("ar/style.css");
if (data.open(QtCore.QFile.ReadOnly)):
mySTYLE_SHEET=QtCore.QTextStream(data).readAll();
## text=unicode(text);
else:
mySTYLE_SHEET=u"""
body {
direction: rtl;
font-family: Traditional Arabic, "Times New Roman";
font-size: 16pt;
}
"""
document = QtGui.QTextDocument("")
document.setDefaultStyleSheet(mySTYLE_SHEET)
self.result["HTML"]=u"<html dir=rtl><body dir='rtl'>"+self.result["HTML"]+"</body></html>"
document.setHtml(self.result["HTML"]);
printer = QtGui.QPrinter()
dlg = QtGui.QPrintDialog(printer, self.centralwidget)
if dlg.exec_() != QtGui.QDialog.Accepted:
return
self.ResultVocalized.print_(printer)
else:
QtGui.QMessageBox.warning(self.centralwidget,U"خطأ",
u"لا شيء يمكن طبعه.")
示例9: manual
# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import QFile [as 别名]
def manual(self):
data=QtCore.QFile("ar/help_body.html");
if (data.open(QtCore.QFile.ReadOnly)):
textstream=QtCore.QTextStream(data);
textstream.setCodec("UTF-8");
text=textstream.readAll();
else:
text=u"لا يمكن فتح ملف المساعدة"
Dialog=QtGui.QDialog(self.centralwidget)
Dialog.setObjectName("Dialog")
Dialog.resize(480, 480)
Dialog.setWindowTitle(u'دليل الاستعمال')
gridLayout = QtGui.QGridLayout(Dialog)
gridLayout.setObjectName("gridLayout")
textBrowser = QtGui.QTextBrowser(Dialog)
textBrowser.setObjectName("textBrowser")
gridLayout.addWidget(textBrowser, 0, 0, 1, 1)
buttonBox = QtGui.QDialogButtonBox(Dialog)
buttonBox.setOrientation(QtCore.Qt.Horizontal)
buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok)
buttonBox.setObjectName("buttonBox")
gridLayout.addWidget(buttonBox, 1, 0, 1, 1)
QtCore.QObject.connect(buttonBox, QtCore.SIGNAL("accepted()"), Dialog.accept)
QtCore.QMetaObject.connectSlotsByName(Dialog)
text2=unicode(text)
textBrowser.setText(text2)
RightToLeft=1;
Dialog.setLayoutDirection(RightToLeft);
Dialog.show();
示例10: display_result_in_tab
# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import QFile [as 别名]
def display_result_in_tab(self):
if "HTML" in self.result:
#text="<html><body dir='rtl'>"+self.result["HTML"]+"</body></html>"
text=self.result["HTML"]
#print text.encode('utf8');
self.ResultVocalized.setPlainText(text)
#display help
filename="ar/help.html";
## print filename;
data=QtCore.QFile(filename);
if (data.open(QtCore.QFile.ReadOnly)):
textstream=QtCore.QTextStream(data);
textstream.setCodec("UTF-8");
text_help=textstream.readAll();
else:
# text=u"لا يمكن فتح ملف المساعدة"
text_help=u"""<h1>فكرة</h1>"""
#self.HelpVocalized.setText(text_help)
#show result /
self.TabVoice.show();
self.MainWindow.showMaximized();
self.TabVoice.setCurrentIndex(0);
# enable actions
self.AExport.setEnabled(True)
self.AFont.setEnabled(True)
self.ACopy.setEnabled(True)
self.APrint.setEnabled(True)
#self.APrintPreview.setEnabled(True)
#self.APagesetup.setEnabled(True)
self.AZoomIn.setEnabled(True)
self.AZoomOut.setEnabled(True)
self.centralwidget.update();
else:
QtGui.QMessageBox.warning(self.centralwidget,U"خطأ",
u"لا نتائج ")
示例11: QtLoadUI
# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import QFile [as 别名]
def QtLoadUI(uifile):
from PySide import QtUiTools
loader = QtUiTools.QUiLoader()
uif = QtCore.QFile(uifile)
uif.open(QtCore.QFile.ReadOnly)
result = loader.load(uif)
uif.close()
return result
示例12: set_dark_style
# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import QFile [as 别名]
def set_dark_style(onoff):
if (onoff):
stylefile = core.QFile("qstyle.qss")
stylefile.open(core.QFile.ReadOnly)
if qt5:
StyleSheet = str(stylefile.readAll())
else:
StyleSheet = core.QString(core.QLatin1String(stylefile.readAll()))
else:
StyleSheet = ""
app.setStyleSheet(StyleSheet)
示例13: load_css_for_widget
# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import QFile [as 别名]
def load_css_for_widget(widget, css_path, res_path=''):
'''
This method is used to set CSS styling for a given
widget from a given CSS file.
If a resource path is given, it will attempt to replace
{res_path} in the CSS with that path.
NOTE: It assumes only one {res_path} string will be on a single line.
'''
css = QtCore.QFile(css_path)
css.open(QtCore.QIODevice.ReadOnly)
if css.isOpen():
style_sheet = str(QtCore.QVariant(css.readAll()).toString())
if res_path:
style_sheet_to_format = style_sheet
style_sheet = ''
for line in style_sheet_to_format.splitlines():
try:
line = line.format(res_path=os.path.join(res_path, '').replace('\\', '/'))
except ValueError:
pass
except Exception:
debugger('[ERROR] Formatting CSS file {} failed on line "{}"'
.format(css_path, line))
style_sheet += line + '\n'
widget.setStyleSheet(style_sheet)
css.close()
示例14: set_document
# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import QFile [as 别名]
def set_document(self):
"""
:return:
"""
self.file = QFile(self.file_path)
if self.file.open(QIODevice.ReadOnly):
self.doc.setContent(self.file)
self.file.close()
示例15: _get_doc_element
# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import QFile [as 别名]
def _get_doc_element(self, config_file_name):
"""
Reads provided config file
:returns QDomDocument, QDomDocument.documentElement()
:rtype tuple
"""
config_file_path = os.path.join(
self.file_handler.localPath(),
config_file_name
)
config_file_path = QFile(config_file_path)
config_file = os.path.basename(config_file_name)
if self._check_config_file_exists(config_file):
doc = QDomDocument()
status, msg, line, col = doc.setContent(config_file_path)
if not status:
error_message = u'Configuration file cannot be loaded: {0}'.\
format(msg)
self.append_log(str(error_message))
raise ConfigurationException(error_message)
doc_element = doc.documentElement()
return doc, doc_element