Python PyQt4.QtCore.QFile() Examples
The following are 22
code examples of PyQt4.QtCore.QFile().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
PyQt4.QtCore
, or try the search function
.
Example #1
Source File: appgui.py From mishkal with GNU General Public License v3.0 | 6 votes |
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_();
Example #2
Source File: appgui.py From mishkal with GNU General Public License v3.0 | 6 votes |
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_();
Example #3
Source File: uuid_extractor.py From stdm with GNU General Public License v2.0 | 6 votes |
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
Example #4
Source File: colortheme.py From pyqtggpo with GNU General Public License v2.0 | 6 votes |
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)
Example #5
Source File: pyeditor.py From Python_editor with The Unlicense | 5 votes |
def savetext(self, fileName): textout = self.codebox.text() file = QtCore.QFile(fileName) if file.open(QtCore.QIODevice.WriteOnly): QtCore.QTextStream(file) << textout else: QtGui.QMessageBox.information(self.vindu, "Unable to open file", file.errorString()) os.chdir(str(self.path))
Example #6
Source File: show_text_window.py From easygui_qt with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #7
Source File: pyeditor.py From Python_editor with The Unlicense | 5 votes |
def savetext(self, fileName): textout = self.codebox.text() file = QtCore.QFile(fileName) if file.open(QtCore.QIODevice.WriteOnly): QtCore.QTextStream(file) << textout else: QtGui.QMessageBox.information(self.vindu, "Unable to open file", file.errorString()) os.chdir(str(self.path))
Example #8
Source File: config_utils.py From stdm with GNU General Public License v2.0 | 5 votes |
def read_stc(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): self.document = QDomDocument() status, msg, line, col = self.document.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) self.doc_element = self.document.documentElement()
Example #9
Source File: config_file_updater.py From stdm with GNU General Public License v2.0 | 5 votes |
def _create_config_file(self, config_file_name): """ Method to create configuration file :param config_file_name: :return: """ self.progress.progress_message('Creating STDM 1.4 configuration file', '') self.config_file = QFile(os.path.join(self.file_handler.localPath(), config_file_name)) if not self.config_file.open(QIODevice.ReadWrite | QIODevice.Truncate | QIODevice.Text): title = QApplication.translate( 'ConfigurationFileUpdater', 'Configuration Upgrade Error' ) message = QApplication.translate( 'ConfigurationFileUpdater', 'Cannot write file {0}: \n {2}'.format( self.config_file.fileName(), self.config_file.errorString() ) ) QMessageBox.warning( self.iface.mainWindow(), title, message ) return
Example #10
Source File: config_file_updater.py From stdm with GNU General Public License v2.0 | 5 votes |
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
Example #11
Source File: uuid_extractor.py From stdm with GNU General Public License v2.0 | 5 votes |
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()
Example #12
Source File: utils.py From kano-burners with GNU General Public License v2.0 | 5 votes |
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()
Example #13
Source File: ddt4all.py From ddt4all with GNU General Public License v3.0 | 5 votes |
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)
Example #14
Source File: QtVariant.py From calfem-python with MIT License | 5 votes |
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
Example #15
Source File: appgui.py From mishkal with GNU General Public License v3.0 | 5 votes |
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"لا نتائج ")
Example #16
Source File: appgui.py From mishkal with GNU General Public License v3.0 | 5 votes |
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();
Example #17
Source File: appgui.py From mishkal with GNU General Public License v3.0 | 5 votes |
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"لا شيء يمكن طبعه.")
Example #18
Source File: Utils.py From qgis-cartodb with GNU General Public License v2.0 | 5 votes |
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
Example #19
Source File: Utils.py From qgis-cartodb with GNU General Public License v2.0 | 5 votes |
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
Example #20
Source File: __init__.py From nupic.studio with GNU General Public License v2.0 | 4 votes |
def saveConfig(): """ Saves the content from current program's configuration. """ fileName = os.path.join(Global.appPath, "nupic_studio.config") file = QtCore.QFile(fileName) file.open(QtCore.QIODevice.WriteOnly) xmlWriter = QtCore.QXmlStreamWriter(file) xmlWriter.setAutoFormatting(True) xmlWriter.writeStartDocument() xmlWriter.writeStartElement('Program') for view in Global.views: xmlWriter.writeStartElement('View') xmlWriter.writeAttribute('name', view.name) xmlWriter.writeAttribute('showBitsNone', str(view.showBitsNone)) xmlWriter.writeAttribute('showBitsActive', str(view.showBitsActive)) xmlWriter.writeAttribute('showBitsPredicted', str(view.showBitsPredicted)) xmlWriter.writeAttribute('showBitsFalselyPredicted', str(view.showBitsFalselyPredicted)) xmlWriter.writeAttribute('showCellsNone', str(view.showCellsNone)) xmlWriter.writeAttribute('showCellsLearning', str(view.showCellsLearning)) xmlWriter.writeAttribute('showCellsActive', str(view.showCellsActive)) xmlWriter.writeAttribute('showCellsPredicted', str(view.showCellsPredicted)) xmlWriter.writeAttribute('showCellsFalselyPredicted', str(view.showCellsFalselyPredicted)) xmlWriter.writeAttribute('showCellsInactive', str(view.showCellsInactive)) xmlWriter.writeAttribute('showProximalSegmentsNone', str(view.showProximalSegmentsNone)) xmlWriter.writeAttribute('showProximalSegmentsActive', str(view.showProximalSegmentsActive)) xmlWriter.writeAttribute('showProximalSegmentsPredicted', str(view.showProximalSegmentsPredicted)) xmlWriter.writeAttribute('showProximalSegmentsFalselyPredicted', str(view.showProximalSegmentsFalselyPredicted)) xmlWriter.writeAttribute('showProximalSynapsesNone', str(view.showProximalSynapsesNone)) xmlWriter.writeAttribute('showProximalSynapsesConnected', str(view.showProximalSynapsesConnected)) xmlWriter.writeAttribute('showProximalSynapsesActive', str(view.showProximalSynapsesActive)) xmlWriter.writeAttribute('showProximalSynapsesPredicted', str(view.showProximalSynapsesPredicted)) xmlWriter.writeAttribute('showProximalSynapsesFalselyPredicted', str(view.showProximalSynapsesFalselyPredicted)) xmlWriter.writeAttribute('showDistalSegmentsNone', str(view.showDistalSegmentsNone)) xmlWriter.writeAttribute('showDistalSegmentsActive', str(view.showDistalSegmentsActive)) xmlWriter.writeAttribute('showDistalSynapsesNone', str(view.showDistalSynapsesNone)) xmlWriter.writeAttribute('showDistalSynapsesConnected', str(view.showDistalSynapsesConnected)) xmlWriter.writeAttribute('showDistalSynapsesActive', str(view.showDistalSynapsesActive)) xmlWriter.writeEndElement() xmlWriter.writeEndElement() xmlWriter.writeEndDocument() file.close()
Example #21
Source File: __init__.py From nupic.studio with GNU General Public License v2.0 | 4 votes |
def loadConfig(): """ Loads the content from XML file to config the program. """ fileName = os.path.join(Global.appPath, "nupic_studio.config") file = QtCore.QFile(fileName) if (file.open(QtCore.QIODevice.ReadOnly)): xmlReader = QtCore.QXmlStreamReader() xmlReader.setDevice(file) while (not xmlReader.isEndDocument()): if xmlReader.isStartElement(): if xmlReader.name().toString() == 'View': view = View() view.name = Global.__getStringAttribute(xmlReader.attributes(), 'name') view.showBitsNone = Global.__getBooleanAttribute(xmlReader.attributes(), 'showBitsNone') view.showBitsActive = Global.__getBooleanAttribute(xmlReader.attributes(), 'showBitsActive') view.showBitsPredicted = Global.__getBooleanAttribute(xmlReader.attributes(), 'showBitsPredicted') view.showBitsFalselyPredicted = Global.__getBooleanAttribute(xmlReader.attributes(), 'showBitsFalselyPredicted') view.showCellsNone = Global.__getBooleanAttribute(xmlReader.attributes(), 'showCellsNone') view.showCellsLearning = Global.__getBooleanAttribute(xmlReader.attributes(), 'showCellsLearning') view.showCellsActive = Global.__getBooleanAttribute(xmlReader.attributes(), 'showCellsActive') view.showCellsPredicted = Global.__getBooleanAttribute(xmlReader.attributes(), 'showCellsPredicted') view.showCellsFalselyPredicted = Global.__getBooleanAttribute(xmlReader.attributes(), 'showCellsFalselyPredicted') view.showCellsInactive = Global.__getBooleanAttribute(xmlReader.attributes(), 'showCellsInactive') view.showProximalSegmentsNone = Global.__getBooleanAttribute(xmlReader.attributes(), 'showProximalSegmentsNone') view.showProximalSegmentsActive = Global.__getBooleanAttribute(xmlReader.attributes(), 'showProximalSegmentsActive') view.showProximalSegmentsPredicted = Global.__getBooleanAttribute(xmlReader.attributes(), 'showProximalSegmentsPredicted') view.showProximalSegmentsFalselyPredicted = Global.__getBooleanAttribute(xmlReader.attributes(), 'showProximalSegmentsFalselyPredicted') view.showProximalSynapsesNone = Global.__getBooleanAttribute(xmlReader.attributes(), 'showProximalSynapsesNone') view.showProximalSynapsesConnected = Global.__getBooleanAttribute(xmlReader.attributes(), 'showProximalSynapsesConnected') view.showProximalSynapsesActive = Global.__getBooleanAttribute(xmlReader.attributes(), 'showProximalSynapsesActive') view.showProximalSynapsesPredicted = Global.__getBooleanAttribute(xmlReader.attributes(), 'showProximalSynapsesPredicted') view.showProximalSynapsesFalselyPredicted = Global.__getBooleanAttribute(xmlReader.attributes(), 'showProximalSynapsesFalselyPredicted') view.showDistalSegmentsNone = Global.__getBooleanAttribute(xmlReader.attributes(), 'showDistalSegmentsNone') view.showDistalSegmentsActive = Global.__getBooleanAttribute(xmlReader.attributes(), 'showDistalSegmentsActive') view.showDistalSynapsesNone = Global.__getBooleanAttribute(xmlReader.attributes(), 'showDistalSynapsesNone') view.showDistalSynapsesConnected = Global.__getBooleanAttribute(xmlReader.attributes(), 'showDistalSynapsesConnected') view.showDistalSynapsesActive = Global.__getBooleanAttribute(xmlReader.attributes(), 'showDistalSynapsesActive') Global.views.append(view) xmlReader.readNext() if (xmlReader.hasError()): QtGui.QMessageBox.critical(None, "Critical", "Ocurred a XML error: " + xmlReader.errorString().data(), QtGui.QMessageBox.Ok | QtGui.QMessageBox.Default, QtGui.QMessageBox.NoButton) else: QtGui.QMessageBox.critical(None, "Critical", "Cannot read the config file!", QtGui.QMessageBox.Ok | QtGui.QMessageBox.Default, QtGui.QMessageBox.NoButton)
Example #22
Source File: template_updater.py From stdm with GNU General Public License v2.0 | 4 votes |
def get_template_element(self, path): """ Gets the template element. :param path: The path of the template :type path: String :return: QDomDocument, QDomDocument.documentElement() :rtype: Tuple """ config_file = os.path.join(path) config_file = QFile(config_file) if not config_file.open(QIODevice.ReadOnly): template = os.path.basename(path) self.prog.setLabelText( QApplication.translate( 'TemplateUpdater', 'Failed to update {}'.format( template ) ) ) error_title = QApplication.translate( 'TemplateContentReader', 'File Reading Error' ) error_message = QApplication.translate( 'TemplateContentReader', 'Failed to update {0}. ' 'Check the file permission of {0}'.format( template ) ) QMessageBox.critical( iface.mainWindow(), error_title, error_message ) return None doc = QDomDocument() status, msg, line, col = doc.setContent( config_file ) if not status: return None doc_element = doc.documentElement() return doc_element