class FileBasedTextStream(QTextStream): def __init__(self, qfile): super().__init__(qfile) self.saved_file = qfile self.qfi = None # may never need this def rewind(self): self.flush() self.seek(0) def writeLine(self, str): self << str self << '\n' def open_mode(self): return self.saved_file.openMode() def fullpath(self): if self.qfi is None: self.qfi = QFileInfo(self.saved_file) return self.qfi.canonicalFilePath() def folderpath(self): if self.qfi is None: self.qfi = QFileInfo(self.saved_file) return self.qfi.canonicalPath() def filename(self): if self.qfi is None: self.qfi = QFileInfo(self.saved_file) return self.qfi.fileName() def basename(self): if self.qfi is None: self.qfi = QFileInfo(self.saved_file) return self.qfi.completeBaseName() def suffix(self): if self.qfi is None: self.qfi = QFileInfo(self.saved_file) return self.qfi.suffix()
def __saveFileName(self, directory): """ Private method to calculate a name for the file to download. @param directory name of the directory to store the file into (string) @return proposed filename and original filename (string, string) """ path = parseContentDisposition(self.__reply) info = QFileInfo(path) baseName = info.completeBaseName() endName = info.suffix() origName = baseName if endName: origName += '.' + endName name = directory + baseName if endName: name += '.' + endName if not self.__requestFilename: # do not overwrite, if the user is not being asked i = 1 while QFile.exists(name): # file exists already, don't overwrite name = directory + baseName + ('-{0:d}'.format(i)) if endName: name += '.' + endName i += 1 return name, origName
def outputFiles(self, map, fileName): result = [] # Extract file name without extension and path fileInfo = QFileInfo(fileName) base = fileInfo.completeBaseName() + "_" path = fileInfo.path() # Loop layers to calculate the path for the exported file for layer in map.layers(): if layer.layerType() != Layer.TileLayerType: continue # Get the output file name for this layer layerName = layer.name() layerFileName = base + layerName + ".csv" layerFilePath = QDir(path).filePath(layerFileName) result.append(layerFilePath) # If there was only one tile layer, there's no need to change the name # (also keeps behavior backwards compatible) if len(result) == 1: result[0] = fileName return result
def outputFiles(self, map, fileName): result = [] # Extract file name without extension and path fileInfo = QFileInfo(fileName) base = fileInfo.completeBaseName() + "_" path = fileInfo.path() # Loop layers to calculate the path for the exported file for layer in map.layers(): if layer.layerType() != Layer.TileLayerType: continue # Get the output file name for this layer layerName = layer.name() layerFileName = base + layerName + ".csv" layerFilePath = QDir(path).filePath(layerFileName) result.append(layerFilePath) # If there was only one tile layer, there's no need to change the name # (also keeps behavior backwards compatible) if len(result) == 1: result[0] = fileName return result
def importAudioFunction(self): #Model.aname, _ = QFileDialog.getOpenFileName(self, 'Open audio file', '../desktop','All audio files(*.mp3 *.wav)') #windows Model.aname, _ = QFileDialog.getOpenFileName( self, 'Open audio file', '..\desktop', 'All audio files(*.mp3 *.wav)') if Model.aname != '': Model.audioList.append(Model.aname) fi = QFileInfo(Model.aname) base = fi.completeBaseName() self.importAudioList(base)
def getDocumentTitle(self, baseName=False): if self.markup and not baseName: text = self.editBox.toPlainText() try: return self.markup.get_document_title(text) except Exception: self.p.printError() if self.fileName: fileinfo = QFileInfo(self.fileName) basename = fileinfo.completeBaseName() return (basename if basename else fileinfo.fileName()) return self.tr("New document")
def getDocumentTitle(self, baseName=False): if self.markup and not baseName: text = self.editBox.toPlainText() try: return self.markup.get_document_title(text) except Exception: self.p.printError() if self.fileName: fileinfo = QFileInfo(self.fileName) basename = fileinfo.completeBaseName() return (basename if basename else fileinfo.fileName()) return self.tr("New document")
def importFunction(self): #Model.fname, _ = QFileDialog.getOpenFileName(self, 'Open file', '../desktop','All files(*.jpeg *.mp4 *.mov);;Image files(*.jpeg);;Video Files(*.mp4 *.mov)') #windows Model.fname, _ = QFileDialog.getOpenFileName( self, 'Open file', '..\desktop', 'All files(*.jpeg *.mp4 *.mov);;Image files(*.jpeg);;Video Files(*.mp4 *.mov)' ) if Model.fname != '': Model.videoList.append(Model.fname) fi = QFileInfo(Model.fname) base = fi.completeBaseName() self.importBoxList(base)
class FileBasedTextStream(QTextStream): def __init__(self, qfile): super().__init__(qfile) self.saved_file = qfile self.qfi = None # may never need this def rewind(self): self.flush() self.seek(0) def writeLine(self, str): self << str self << '\n' def open_mode(self): return self.saved_file.openMode() def fullpath(self): if self.qfi is None: self.qfi = QFileInfo(self.saved_file) return self.qfi.canonicalFilePath() def folderpath(self): if self.qfi is None: self.qfi = QFileInfo(self.saved_file) return self.qfi.canonicalPath() def filename(self): if self.qfi is None: self.qfi = QFileInfo(self.saved_file) return self.qfi.fileName() def basename(self): if self.qfi is None: self.qfi = QFileInfo(self.saved_file) return self.qfi.completeBaseName() def suffix(self): if self.qfi is None: self.qfi = QFileInfo(self.saved_file) return self.qfi.suffix() def flush(self): super().flush() # make sure text buffer goes to device return self.device().flush() # do a real flush def show_error(self, action, parent): error_number = self.device().error() if error_number: # is not 0, no error error_string = self.device().errorString() msg_string = 'Error {} ({}) on {}'.format(error_number, error_string, action) warning_msg(msg_string, self.fullpath(), parent)
def addShapeToCanvas( shapefile_path ): file_info = QFileInfo( shapefile_path ) if file_info.exists(): layer_name = file_info.completeBaseName() else: return False vlayer_new = QgsVectorLayer( shapefile_path, layer_name, "ogr" ) if vlayer_new.isValid(): QgsProject.instance().addMapLayers( [vlayer_new] ) return True else: return False
def __init__(self, mapDocument, fileName, currentScale, parent=None): super().__init__(parent) self.mUi = None self.mCurrentScale = currentScale self.mMapDocument = mapDocument self.mUi = Ui_ExportAsImageDialog() self.mUi.setupUi(self) self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) saveButton = self.mUi.buttonBox.button(QDialogButtonBox.Save) saveButton.setText(self.tr("Export")) # Default to the last chosen location suggestion = adjustDir(self.mPath) # Suggest a nice name for the image if fileName != '': fileInfo = QFileInfo(fileName) path = fileInfo.path() baseName = fileInfo.completeBaseName() if suggestion == '': suggestion = adjustDir(path) suggestion += '/' suggestion += baseName suggestion += ".png" else: suggestion += '/' suggestion += "map.png" self.mUi.fileNameEdit.setText(suggestion) # Restore previously used settings s = preferences.Preferences.instance() visibleLayersOnly = s.boolValue(VISIBLE_ONLY_KEY, True) useCurrentScale = s.boolValue(CURRENT_SCALE_KEY, True) drawTileGrid = s.boolValue(DRAW_GRID_KEY, False) includeBackgroundColor = s.boolValue(INCLUDE_BACKGROUND_COLOR, False) self.mUi.visibleLayersOnly.setChecked(visibleLayersOnly) self.mUi.currentZoomLevel.setChecked(useCurrentScale) self.mUi.drawTileGrid.setChecked(drawTileGrid) self.mUi.includeBackgroundColor.setChecked(includeBackgroundColor) self.mUi.browseButton.clicked.connect(self.browse) self.mUi.fileNameEdit.textChanged.connect(self.updateAcceptEnabled) Utils.restoreGeometry(self)
def getDocumentTitle(self, baseName=False): markup = self.markups[self.ind] realTitle = '' if markup and not baseName: text = self.editBoxes[self.ind].toPlainText() try: realTitle = markup.get_document_title(text) except Exception: self.printError() if realTitle: return realTitle elif self.fileNames[self.ind]: fileinfo = QFileInfo(self.fileNames[self.ind]) basename = fileinfo.completeBaseName() return (basename if basename else fileinfo.fileName()) return self.tr("New document")
def getDocumentTitle(self, baseName=False): markup = self.markups[self.ind] realTitle = '' if markup and not baseName: text = self.editBoxes[self.ind].toPlainText() try: realTitle = markup.get_document_title(text) except Exception: self.printError() if realTitle: return realTitle elif self.fileNames[self.ind]: fileinfo = QFileInfo(self.fileNames[self.ind]) basename = fileinfo.completeBaseName() return (basename if basename else fileinfo.fileName()) return self.tr("New document")
def __saveFileName(self, directory): """ Private method to calculate a name for the file to download. @param directory name of the directory to store the file into (string) @return proposed filename and original filename (string, string) """ path = "" if self.__reply.hasRawHeader("Content-Disposition"): header = bytes(self.__reply.rawHeader("Content-Disposition"))\ .decode() if header: pos = header.find("filename=") if pos != -1: path = header[pos + 9:] if path.startswith('"') and path.endswith('"'): path = path[1:-1] if not path: path = self.__url.path() info = QFileInfo(path) baseName = info.completeBaseName() endName = info.suffix() if not baseName: baseName = "unnamed_download" origName = baseName if endName: origName += '.' + endName name = directory + baseName if endName: name += '.' + endName if not self.__requestFilename: # do not overwrite, if the user is not being asked i = 1 while QFile.exists(name): # file exists already, don't overwrite name = directory + baseName + ('-{0:d}'.format(i)) if endName: name += '.' + endName i += 1 return name, origName
def __saveFileName(self, directory): """ Private method to calculate a name for the file to download. @param directory name of the directory to store the file into (string) @return proposed filename and original filename (string, string) """ path = "" if self.__reply.hasRawHeader("Content-Disposition"): header = bytes(self.__reply.rawHeader("Content-Disposition"))\ .decode() if header: pos = header.find("filename=") if pos != -1: path = header[pos + 9:] if path.startswith('"') and path.endswith('"'): path = path[1:-1] if not path: path = self.__url.path() info = QFileInfo(path) baseName = info.completeBaseName() endName = info.suffix() if not baseName: baseName = "unnamed_download" origName = baseName if endName: origName += '.' + endName name = directory + baseName if endName: name += '.' + endName if not self.__requestFilename: # do not overwrite, if the user is not being asked i = 1 while QFile.exists(name): # file exists already, don't overwrite name = directory + baseName + ('-{0:d}'.format(i)) if endName: name += '.' + endName i += 1 return name, origName
def loadRasterfileToCanvas(prjpath, layerName): """Loads a raste to canvas.""" if isLayerLoaded(layerName): return True pathFilename=os.path.join(prjpath, layerName+".tif") file_info = QFileInfo(pathFilename) if file_info.exists(): layer_name = file_info.completeBaseName() else: message="Error loading raster"+pathFilename QMessageBox.critical(None, 'Error', message, QMessageBox.Ok) return False layeropts=QgsRasterLayer.LayerOptions(True) rlayer_new = QgsRasterLayer( pathFilename, layer_name, 'gdal', layeropts ) if rlayer_new.isValid(): QgsProject.instance().addMapLayer(rlayer_new) return True else: return False
class FileBasedTextStream(QTextStream): def __init__(self, qfile): super().__init__(qfile) self.saved_file = qfile self.qfi = None # may never need this def rewind(self): self.flush() self.seek(0) def writeLine(self, str): self << str self << '\n' def open_mode(self): return self.saved_file.openMode() def fullpath(self): if self.qfi is None: self.qfi = QFileInfo(self.saved_file) return self.qfi.canonicalFilePath() def folderpath(self): if self.qfi is None: self.qfi = QFileInfo(self.saved_file) return self.qfi.canonicalPath() def filename(self): if self.qfi is None: self.qfi = QFileInfo(self.saved_file) return self.qfi.fileName() def basename(self): if self.qfi is None: self.qfi = QFileInfo(self.saved_file) return self.qfi.completeBaseName() def suffix(self): if self.qfi is None: self.qfi = QFileInfo(self.saved_file) return self.qfi.suffix() def flush(self): super().flush() # make sure text buffer goes to device return self.device().flush() # do a real flush def show_error( self, action, parent ): error_number = self.device().error() if error_number : # is not 0, no error error_string = self.device().errorString() msg_string = 'Error {} ({}) on {}'.format( error_number, error_string, action ) warning_msg( msg_string, self.fullpath(), parent )
def __saveFileName(self, directory): """ Private method to calculate a name for the file to download. @param directory name of the directory to store the file into (string) @return proposed filename and original filename (string, string) """ path = self.__downloadItem.path() info = QFileInfo(path) baseName = info.completeBaseName() endName = info.suffix() origName = baseName if endName: origName += '.' + endName name = os.path.join(directory, baseName) if endName: name += '.' + endName return name, origName
def __init__(self, path, parent = None): super().__init__(parent) self.mPath = path self.mUi = Ui_NewTilesetDialog() self.mNameWasEdited = False self.mUi.setupUi(self) self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # Restore previously used settings s = preferences.Preferences.instance().settings() tilesetType = s.value(TYPE_KEY, 0) colorEnabled = bool(s.value(COLOR_ENABLED_KEY)) colorName = s.value(COLOR_KEY, '') if colorName == '': color = Qt.magenta else: color = QColor(colorName) spacing = s.value(SPACING_KEY, 0) margin = s.value(MARGIN_KEY, 0) self.mUi.tilesetType.setCurrentIndex(tilesetType) self.mUi.useTransparentColor.setChecked(colorEnabled) self.mUi.colorButton.setColor(color) self.mUi.spacing.setValue(spacing) self.mUi.margin.setValue(margin) self.mUi.browseButton.clicked.connect(self.browse) self.mUi.name.textEdited.connect(self.nameEdited) self.mUi.name.textChanged.connect(self.updateOkButton) self.mUi.image.textChanged.connect(self.updateOkButton) self.mUi.tilesetType.currentIndexChanged.connect(self.tilesetTypeChanged) # Set the image and name fields if the given path is a file fileInfo = QFileInfo(path) if (fileInfo.isFile()): self.mUi.image.setText(path) self.mUi.name.setText(fileInfo.completeBaseName()) self.mUi.imageGroupBox.setVisible(tilesetType == 0) self.updateOkButton()
def enregistrer(self): requete = "" savefile = "" self.cheminExport = "" # Récupération de l'ID et du sigle de l'espèce en cours dans la combobox wrecord = self.cmbEspece.model().record(self.cmbEspece.currentIndex()) wespeceId = wrecord.value(0) wespeceSigle = wrecord.value(1) # Écriture de la requête SQL en fonction de l'espèce choisi dans la liste déroulante requete = ( "SELECT DISTINCT operation.ope_code AS CODE, " + "station.sta_xl93_aval AS X, " + "station.sta_yl93_aval AS Y, " + "cours_eau.ceau_nom AS RIVIERE, " + "(masse_eau.meau_code || ' ; '::text) || masse_eau.meau_nom AS MASSEEAU, " + "contexte_pdpg.pdpg_nom AS PDPG, " + "ope_peche_elec.opep_date AS DATE, " + "motif_peche.mope_motif AS MOTIF, " + "condition_peche.cope_condition AS CONDITION, " + "ope_peche_elec.opep_nbre_anode AS NANODE, " + "ope_peche_elec.opep_longueur_prospec AS LONGUEUR, " + "ope_peche_elec.opep_profondeur_moy AS PROFONDEUR, " + "ope_peche_elec.opep_largeur_moy AS LARGEUR, " + "ope_peche_elec.opep_surf_peche AS SURFACE, " + "ope_peche_elec.opep_pente AS PENTE, " + "ope_peche_elec.opep_ntt_reel AS NTTREEL, " + "ope_peche_elec.opep_ntt AS NTT, " + "(ope_peche_elec.ipro_valeur || ' ; '::text) || ipr.ipr_correspondance AS IPR, " + "string_agg(espece.esp_sigle, ' ; '::text) AS ESPECE, " + "f_poisson_params.espe_densite AS VALDEN_" + wespeceSigle + ", " + "f_poisson_params.clde_val_correspond AS CLADEN_" + wespeceSigle + ", " + "f_poisson_params.espe_biomasse AS VALBIO_" + wespeceSigle + ", " + "f_poisson_params.clbi_val_correspond CLABIO_" + wespeceSigle + ", " + "ope_peche_elec.opep_geom " + "FROM data.masse_eau, " + "data.cours_eau, " + "data.station, " + "data.contexte_pdpg, " + "data.operation, " + "data.ope_peche_elec " + "JOIN data.motif_peche ON motif_peche.mope_id = ope_peche_elec.opep_mope_id " + "JOIN data.condition_peche ON condition_peche.cope_id = ope_peche_elec.opep_cope_id " + "JOIN data.ipr ON ipr.ipr_id = ope_peche_elec.opep_ipr_id " + "JOIN data.espece_peche ON espece_peche.espe_opep_id = ope_peche_elec.opep_id " + "JOIN data.espece ON espece_peche.espe_esp_id = espece.esp_id " + "FULL JOIN data.f_poisson_params(" + str(wespeceId) + ") f_poisson_params(ope_code, espe_biomasse, clbi_val_correspond, espe_densite, clde_val_correspond) ON f_poisson_params.ope_code = ope_peche_elec.opep_ope_code " + "WHERE station.sta_meau_code = masse_eau.meau_code AND " + "station.sta_ceau_id = cours_eau.ceau_id AND " + "station.sta_pdpg_id = contexte_pdpg.pdpg_id AND " + "operation.ope_sta_id = station.sta_id AND " + "operation.ope_code = ope_peche_elec.opep_ope_code " + "GROUP BY operation.ope_code, station.sta_xl93_aval, station.sta_yl93_aval, cours_eau.ceau_nom, ((masse_eau.meau_code || ' ; '::text) || masse_eau.meau_nom), contexte_pdpg.pdpg_nom, ope_peche_elec.opep_date, motif_peche.mope_motif, condition_peche.cope_condition, ope_peche_elec.opep_nbre_anode, ope_peche_elec.opep_longueur_prospec, ope_peche_elec.opep_profondeur_moy, ope_peche_elec.opep_largeur_moy, ope_peche_elec.opep_surf_peche, ope_peche_elec.opep_pente, ope_peche_elec.opep_ntt_reel, ope_peche_elec.opep_ntt, ((ope_peche_elec.ipro_valeur || ' ; '::text) || ipr.ipr_correspondance), f_poisson_params.espe_densite, f_poisson_params.clde_val_correspond, f_poisson_params.espe_biomasse, f_poisson_params.clbi_val_correspond, ope_peche_elec.opep_geom " + "ORDER BY cours_eau.ceau_nom ") # Récupération du chemin où enregistrer l'export savefile = QFileDialog.getSaveFileName(self, "Save File", "", u"ESRI Shapefile (*.shp)") if savefile != "": cheminExport = unicode(savefile) # Récupération du nom du fichier path = QFileInfo(cheminExport) filename = path.completeBaseName() if cheminExport != "": query = QSqlQuery(self.db) query.prepare(requete) # Exécution de la requête afin de vérifier sa validité if query.exec_(): # Création d'une ligne de commande DOS qui utilisera pgsql2shp pour créer un shapefile en fonction de la requête cmd = "cd C:\\Program Files\\PostgreSQL\\9.5\\bin & pgsql2shp.exe -f " + str( cheminExport ) + " -h " + self.host + " -u " + self.user + " -P " + self.password + " " + self.dbname + " \"" + requete + "\"" # Exécution de la ligne de commande (une fenêtre DOS s'ouvre le temps de l'exécution os.system(cmd) self.onReject() # Ajout du shape créé au caneva layer = self.iface.addVectorLayer(cheminExport, filename, "ogr") else: QMessageBox.critical(self, u"Erreur SQL", query.lastError().text(), QMessageBox.Ok)
def _write_qmake(self, py_version, required_ext, required_libraries, include_dir, python_library, standard_library_dir, source_dir, job_writer, opt, resource_names): """ Create the .pro file for qmake. """ project = self._project target_platform = self._target.platform.name f = self._create_file(self._build_dir + '/' + project.get_executable_basename() + '.pro') f.write('# Generated for {0} and Python v{1}.{2}.{3}.\n\n'.format( self._target.name, (py_version >> 16), (py_version >> 8) & 0xff, py_version & 0xff)) f.write('TEMPLATE = app\n') f.write('\n') # Configure the CONFIG and QT values that are project dependent. needs_cpp11 = False needs_gui = False qmake_qt4 = set() qmake_config4 = set() qmake_qt5 = set() qmake_config5 = set() for pyqt_m in project.pyqt_modules: metadata = self._get_pyqt_module_metadata(pyqt_m) if metadata.cpp11: needs_cpp11 = True if metadata.gui: needs_gui = True if self._is_targeted(metadata.targets): qmake_qt4.update(metadata.qt4) qmake_config4.update(metadata.config4) qmake_qt5.update(metadata.qt5) qmake_config5.update(metadata.config5) # Extract QT and CONFIG values that not version-specific. qmake_qt45 = qmake_qt4 & qmake_qt5 qmake_qt4 -= qmake_qt45 qmake_qt5 -= qmake_qt45 qmake_config45 = qmake_config4 & qmake_config5 qmake_config4 -= qmake_config45 qmake_config5 -= qmake_config45 # Generate QT. self._write_qt_config(f, 'QT', None, qmake_qt45) self._write_qt_config(f, 'QT', 4, qmake_qt4) self._write_qt_config(f, 'QT', 5, qmake_qt5) if not needs_gui: f.write('QT -= gui\n') # Generate CONFIG. config = ['warn_off'] if target_platform == 'win': if project.application_is_console or not needs_gui: config.append('console') if needs_cpp11: config.append('c++11') f.write('CONFIG += {0}\n'.format(' '.join(config))) if target_platform == 'macos': if not project.application_is_bundle: f.write('CONFIG -= app_bundle\n') self._write_qt_config(f, 'CONFIG', None, qmake_config45) self._write_qt_config(f, 'CONFIG', 4, qmake_config4) self._write_qt_config(f, 'CONFIG', 5, qmake_config5) # Modules can share sources so we need to make sure we don't include # them more than once. We might as well handle the other things in the # same way. used_qt = set() used_config = set() used_sources = set() used_defines = set() used_includepath = set() used_libs = set() used_inittab = set() used_dlls = set() # Handle any static PyQt modules. site_packages = standard_library_dir + '/site-packages' pyqt_version = 'PyQt5' if project.application_is_pyqt5 else 'PyQt4' for module in self._get_all_pyqt_modules(): # The uic module is pure Python. if module == 'uic': continue metadata = self._get_pyqt_module_metadata(module) if not self._is_targeted(metadata.targets): continue # The sip module is always needed (implicitly or explicitly) if we # have got this far. We handle it separately as it is in a # different directory. if module == 'sip': used_inittab.add(module) used_libs.add('-L' + site_packages) else: used_inittab.add(pyqt_version + '.' + module) used_libs.add('-L' + site_packages + '/' + pyqt_version) lib_name = '-l' + module if metadata.needs_suffix: # Qt4's qmake thinks -lQtCore etc. always refer to the Qt # libraries so PyQt4 creates static libraries with a suffix. lib_name += '_s' used_libs.add(lib_name) # Handle any other extension modules. for other_em in project.other_extension_modules: # If the name is scoped then the targets are the outer scopes for # the remaining values. value = self._get_scoped_value(other_em.name) if value is None: continue used_inittab.add(value) if other_em.qt != '': self._add_compound_scoped_values(used_qt, other_em.qt, False) if other_em.config != '': self._add_compound_scoped_values(used_config, other_em.config, False) if other_em.sources != '': self._add_compound_scoped_values(used_sources, other_em.sources, True) if other_em.defines != '': self._add_compound_scoped_values(used_defines, other_em.defines, False) if other_em.includepath != '': self._add_compound_scoped_values(used_includepath, other_em.includepath, True) if other_em.libs != '': self._add_compound_scoped_values(used_libs, other_em.libs, False) # Configure the target Python interpreter. if include_dir != '': used_includepath.add(include_dir) if python_library != '': fi = QFileInfo(python_library) py_lib_dir = fi.absolutePath() lib = fi.completeBaseName() # This is smart enough to translate the Python library as a UNIX .a # file to what Windows needs. if lib.startswith('lib'): lib = lib[3:] if '.' in lib and target_platform == 'win': lib = lib.replace('.', '') used_libs.add('-l' + lib) used_libs.add('-L' + py_lib_dir) else: py_lib_dir = None # Handle any standard library extension modules. for name, module in required_ext.items(): if not self._is_targeted(module.target): continue # See if the extension module should be disabled for a platform # because there are no external libraries to link against. skip_module = False for xlib in project.external_libraries.get(target_platform, ()): if xlib.name == module.xlib: if xlib.defines == '' and xlib.includepath == '' and xlib.libs == '': skip_module = True break if skip_module: continue used_inittab.add(name) for source in module.source: source = self._get_scoped_value(source) if source is not None: source = self._python_source_file(source_dir, source) used_sources.add(source) used_includepath.add(source_dir + '/Modules') if module.defines is not None: for define in module.defines: define = self._get_scoped_value(define) if define is not None: used_defines.add(define) if module.includepath is not None: for includepath in module.includepath: includepath = self._get_scoped_value(includepath) if includepath is not None: includepath = self._python_source_file( source_dir, includepath) used_includepath.add(includepath) if module.libs is not None: for lib in module.libs: lib = self._get_scoped_value(lib) if lib is not None: used_libs.add(lib) if module.pyd is not None and target_platform == 'win': used_dlls.add(module) if 'win' not in project.python_use_platform and target_platform == 'win': used_includepath.add(source_dir + '/PC') # Handle any required external libraries. android_extra_libs = [] external_libs = project.external_libraries.get(target_platform, []) for required_lib in required_libraries: defines = includepath = libs = '' for xlib in external_libs: if xlib.name == required_lib: defines = xlib.defines includepath = xlib.includepath libs = xlib.libs break else: # Use the defaults. for xlib in external_libraries_metadata: if xlib.name == required_lib: if target_platform not in project.python_use_platform: defines = xlib.defines includepath = xlib.includepath libs = xlib.get_libs(target_platform) break # Check the library is not disabled for this target. enabled = False if defines != '': self._add_compound_scoped_values(used_defines, defines, False) enabled = True if includepath != '': self._add_compound_scoped_values(used_includepath, includepath, True) enabled = True if libs != '': self._add_compound_scoped_values(used_libs, libs, False) enabled = True if enabled and target_platform == 'android': self._add_android_extra_libs(libs, android_extra_libs) # Specify any project-specific configuration. if used_qt: f.write('\n') self._write_used_values(f, used_qt, 'QT') if used_config: f.write('\n') self._write_used_values(f, used_config, 'CONFIG') # Specify the resource files. f.write('\n') f.write('RESOURCES = \\\n') f.write(' \\\n'.join( [' resources/{0}'.format(n) for n in resource_names])) f.write('\n') # Specify the defines. defines = [] headers = ['pyqtdeploy_version.h', 'frozen_bootstrap.h'] if py_version >= 0x030500: headers.append('frozen_bootstrap_external.h') if project.application_script != '': defines.append('PYQTDEPLOY_FROZEN_MAIN') headers.append('frozen_main.h') if opt: defines.append('PYQTDEPLOY_OPTIMIZED') if defines or used_defines: f.write('\n') if defines: f.write('DEFINES += {0}\n'.format(' '.join(defines))) self._write_used_values(f, used_defines, 'DEFINES') # Specify the include paths. if used_includepath: f.write('\n') self._write_used_values(f, used_includepath, 'INCLUDEPATH') # Specify the source files and header files. f.write('\n') f.write( 'SOURCES = pyqtdeploy_main.cpp pyqtdeploy_start.cpp pdytools_module.cpp\n' ) self._write_used_values(f, used_sources, 'SOURCES') self._write_main(py_version, used_inittab, used_defines) self._copy_lib_file('pyqtdeploy_start.cpp', self._build_dir) self._copy_lib_file('pdytools_module.cpp', self._build_dir) f.write('\n') f.write('HEADERS = {0}\n'.format(' '.join(headers))) # Specify the libraries. if used_libs: f.write('\n') self._write_used_values(f, used_libs, 'LIBS') # Add the library files to be added to an Android APK. if android_extra_libs and target_platform == 'android': f.write('\n') f.write('ANDROID_EXTRA_LIBS += %s\n' % ' '.join(android_extra_libs)) # If we are using the platform Python on Windows then copy in the # required DLLs if they can be found. if 'win' in project.python_use_platform and used_dlls and py_lib_dir is not None: self._copy_windows_dlls(py_version, py_lib_dir, used_dlls, f) # Add the project independent post-configuration stuff. self._write_embedded_lib_file('post_configuration.pro', f) # Add any application specific stuff. qmake_configuration = project.qmake_configuration.strip() if qmake_configuration != '': f.write('\n' + qmake_configuration + '\n') # All done. f.close()
def _generate_resource(self, resources_dir, required_py, standard_library_dir, job_writer, nr_resources): """ Generate the application resource. """ project = self._project self._create_directory(resources_dir) resource_contents = [] # Handle any application package. if project.application_package.name is not None: fi = QFileInfo( project.path_from_user(project.application_package.name)) package_src_dir = fi.canonicalFilePath() package_name = project.application_package.name if package_name != '': package_name = fi.completeBaseName() self._write_package(resource_contents, resources_dir, package_name, project.application_package, package_src_dir, job_writer) # Handle the Python standard library. self._write_stdlib_py(resource_contents, resources_dir, required_py, standard_library_dir, job_writer) # Handle any additional packages. for package in project.other_packages: self._write_package(resource_contents, resources_dir, '', package, project.path_from_user(package.name), job_writer) # Handle the PyQt package. if any([m for m in project.pyqt_modules if m != 'sip']): pyqt_subdir = 'PyQt5' if project.application_is_pyqt5 else 'PyQt4' pyqt_dst_dir = resources_dir + '/' + pyqt_subdir pyqt_src_dir = standard_library_dir + '/site-packages/' + pyqt_subdir self._create_directory(pyqt_dst_dir) self._freeze(job_writer, pyqt_dst_dir + '/__init__.pyo', pyqt_src_dir + '/__init__.py', pyqt_subdir + '/__init__.py') resource_contents.append(pyqt_subdir + '/__init__.pyo') # Handle the PyQt.uic package. if 'uic' in project.pyqt_modules: skip_dirs = ['__pycache__'] if project.python_target_version[0] == 3: skip_dirs.append('port_v2') else: skip_dirs.append('port_v3') def copy_freeze(src, dst): for skip in skip_dirs: if skip in src: break else: if dst.endswith('.py'): src = QDir.fromNativeSeparators(src) dst = QDir.fromNativeSeparators(dst) rel_dst = dst[len(resources_dir) + 1:] + 'o' self._freeze(job_writer, dst + 'o', src, rel_dst) resource_contents.append(rel_dst) shutil.copytree(QDir.toNativeSeparators(pyqt_src_dir + '/uic'), QDir.toNativeSeparators(pyqt_dst_dir + '/uic'), copy_function=copy_freeze) # Write the .qrc files. if nr_resources == 1: resource_names = [ self._write_resource(resources_dir, resource_contents) ] else: resource_names = [] nr_files = len(resource_contents) if nr_resources > nr_files: nr_resources = nr_files per_resource = (nr_files + nr_resources - 1) // nr_resources start = 0 for r in range(nr_resources): end = start + per_resource if end > nr_files: end = nr_files resource_names.append( self._write_resource(resources_dir, resource_contents[start:end], r)) start += per_resource return resource_names
def on_btnInfo_baseName2_clicked(self): self.__showBtnInfo(self.sender()) fileInfo = QFileInfo(self.ui.editFile.text()) text = fileInfo.completeBaseName() self.ui.textEdit.appendPlainText(text + "\n")
def _write_qmake(self, build_dir, required_ext, required_libraries, job_writer, opt, resource_names): """ Create the .pro file for qmake. """ project = self._project f = self._create_file(build_dir + '/' + project.get_executable_basename() + '.pro') f.write('TEMPLATE = app\n') # Configure the CONFIG and QT values that are project dependent. needs_cpp11 = False needs_gui = False qmake_qt4 = set() qmake_config4 = set() qmake_qt5 = set() qmake_config5 = set() for pyqt_m in project.pyqt_modules: metadata = self._get_pyqt_module_metadata(pyqt_m) if metadata.cpp11: needs_cpp11 = True if metadata.gui: needs_gui = True qmake_qt4.update(metadata.qt4) qmake_config4.update(metadata.config4) qmake_qt5.update(metadata.qt5) qmake_config5.update(metadata.config5) both_qt = qmake_qt4 & qmake_qt5 qmake_qt4 -= both_qt qmake_qt5 -= both_qt both_config = qmake_qt4 & qmake_qt5 qmake_config4 -= both_config qmake_config5 -= both_config both_config.add('warn_off') if project.application_is_console or not needs_gui: both_config.add('console') if needs_cpp11: both_config.add('c++11') f.write('\n') f.write('CONFIG += {0}\n'.format(' '.join(both_config))) if not project.application_is_bundle: f.write('CONFIG -= app_bundle\n') if not needs_gui: f.write('QT -= gui\n') if both_qt: f.write('QT += {0}\n'.format(' '.join(both_qt))) if qmake_config4 or qmake_qt4: f.write('\n') f.write('lessThan(QT_MAJOR_VERSION, 5) {\n') if qmake_config4: f.write(' CONFIG += {0}\n'.format(' '.join(qmake_config4))) if qmake_qt4: f.write(' QT += {0}\n'.format(' '.join(qmake_qt4))) f.write('}\n') if qmake_config5 or qmake_qt5: f.write('\n') f.write('greaterThan(QT_MAJOR_VERSION, 4) {\n') if qmake_config5: f.write(' CONFIG += {0}\n'.format(' '.join(qmake_config5))) if qmake_qt5: f.write(' QT += {0}\n'.format(' '.join(qmake_qt5))) f.write('}\n') # Modules can share sources so we need to make sure we don't include # them more than once. We might as well handle the other things in the # same way. used_sources = {} used_defines = {} used_includepath = {} used_libs = {} used_inittab = {} # Handle any static PyQt modules. if len(project.pyqt_modules) > 0: site_packages = project.path_from_user( project.python_target_stdlib_dir) + '/site-packages' pyqt_version = 'PyQt5' if project.application_is_pyqt5 else 'PyQt4' l_libs = [] for pyqt in self._get_all_pyqt_modules(): # The sip module is always needed (implicitly or explicitly) if # we have got this far. We handle it separately as it is in a # different directory. if pyqt == 'sip': continue # The uic module is pure Python. if pyqt == 'uic': continue self._add_value_for_scopes(used_inittab, pyqt_version + '.' + pyqt) lib_name = pyqt if self._get_pyqt_module_metadata(pyqt).needs_suffix: # Qt4's qmake thinks -lQtCore etc. always refer to the Qt # libraries so PyQt4 creates static libraries with a # suffix. lib_name += '_s' l_libs.append('-l' + lib_name) # Add the LIBS value for any PyQt modules to the global scope. if len(l_libs) > 0: self._add_value_for_scopes(used_libs, '-L{0}/{1} {2}'.format(site_packages, pyqt_version, ' '.join(l_libs))) # Add the sip module. self._add_value_for_scopes(used_inittab, 'sip') self._add_value_for_scopes(used_libs, '-L{0} -lsip'.format(site_packages)) # Handle any other extension modules. for other_em in project.other_extension_modules: scoped_values = self._parse_scoped_values(other_em.libs, False) for scope, values in scoped_values.items(): self._add_value_for_scopes(used_inittab, other_em.name, [scope]) self._add_value_set_for_scope(used_libs, values, scope) # Configure the target Python interpreter. if project.python_target_include_dir != '': self._add_value_for_scopes(used_includepath, project.path_from_user(project.python_target_include_dir)) if project.python_target_library != '': fi = QFileInfo(project.path_from_user( project.python_target_library)) lib_dir = fi.absolutePath() lib = fi.completeBaseName() # This is smart enough to translate the Python library as a UNIX .a # file to what Windows needs. if lib.startswith('lib'): lib = lib[3:] if '.' in lib: self._add_value_for_scopes(used_libs, '-L{0} -l{1}'.format(lib_dir, lib.replace('.', '')), ['win32']) self._add_value_for_scopes(used_libs, '-L{0} -l{1}'.format(lib_dir, lib), ['!win32']) else: self._add_value_for_scopes(used_libs, '-L{0} -l{1}'.format(lib_dir, lib)) # Handle any standard library extension modules. if len(required_ext) != 0: source_dir = project.path_from_user(project.python_source_dir) source_scopes = set() for name, module in required_ext.items(): # Get the list of all applicable scopes. module_scopes = self._stdlib_scopes(module.scope) if len(module_scopes) == 0: # The module is specific to a platform for which we are # using the python.org Python libraries so ignore it # completely. continue self._add_value_for_scopes(used_inittab, name, module_scopes) for source in module.source: scopes, source = self._get_scope_and_value(source, module_scopes) source = self._python_source_file(source_dir, source) self._add_value_for_scopes(used_sources, source, scopes) source_scopes.update(scopes) if module.defines is not None: for define in module.defines: scopes, define = self._get_scope_and_value(define, module_scopes) self._add_value_for_scopes(used_defines, define, scopes) if module.includepath is not None: for includepath in module.includepath: scopes, includepath = self._get_scope_and_value( includepath, module_scopes) includepath = self._python_source_file(source_dir, includepath) self._add_value_for_scopes(used_includepath, includepath, scopes) if module.libs is not None: for lib in module.libs: scopes, lib = self._get_scope_and_value(lib, module_scopes) self._add_value_for_scopes(used_libs, lib, scopes) self._add_value_for_scopes(used_includepath, source_dir + '/Modules', source_scopes) self._add_value_for_scopes(used_includepath, source_dir + '/PC', ['win32']) # Handle any required external libraries. for required_lib in required_libraries: for xlib in project.external_libraries: if xlib.name == required_lib: if xlib.defines != '': self._add_parsed_scoped_values(used_defines, xlib.defines, False) if xlib.includepath != '': self._add_parsed_scoped_values(used_includepath, xlib.includepath, True) if xlib.libs != '': self._add_parsed_scoped_values(used_libs, xlib.libs, False) break else: for xlib in external_libraries_metadata: if xlib.name == required_lib: scopes = self._stdlib_scopes() if len(scopes) != 0: for lib in xlib.libs.split(): self._add_value_for_scopes(used_libs, lib, scopes) break # Specify the resource files. f.write('\n') f.write('RESOURCES = \\\n') f.write(' \\\n'.join([' resources/{0}'.format(n) for n in resource_names])) f.write('\n') # Specify the source and header files. f.write('\n') f.write('SOURCES = pyqtdeploy_main.cpp pyqtdeploy_start.cpp pdytools_module.cpp\n') self._write_main(build_dir, used_inittab) self._copy_lib_file('pyqtdeploy_start.cpp', build_dir) self._copy_lib_file('pdytools_module.cpp', build_dir) headers = 'HEADERS = pyqtdeploy_version.h frozen_bootstrap.h' if project.application_script != '': f.write('DEFINES += PYQTDEPLOY_FROZEN_MAIN\n') headers += ' frozen_main.h' if opt: f.write('DEFINES += PYQTDEPLOY_OPTIMIZED\n') f.write(headers) f.write('\n') # Get the set of all scopes used. used_scopes = set(used_sources.keys()) used_scopes.update(used_defines.keys()) used_scopes.update(used_includepath.keys()) used_scopes.update(used_libs.keys()) # Write out grouped by scope. for scope in used_scopes: f.write('\n') if scope == '': prefix = '' tail = None elif scope.startswith('win32_'): # We could avoid the hardcoded handling by reverting to # defining appropriate CONFIG values in a pre_configuration.pro # file. prefix = ' ' f.write( 'win32 {\n %scontains(QMAKE_TARGET.arch, x86_64) {\n' % ('!' if scope == 'win32_x86' else '')) tail = ' }\n}\n' else: prefix = ' ' f.write('%s {\n' % scope) tail = '}\n' for defines in used_defines.get(scope, ()): f.write('{0}DEFINES += {1}\n'.format(prefix, defines)) for includepath in used_includepath.get(scope, ()): f.write('{0}INCLUDEPATH += {1}\n'.format(prefix, includepath)) for lib in used_libs.get(scope, ()): f.write('{0}LIBS += {1}\n'.format(prefix, lib)) for source in used_sources.get(scope, ()): f.write('{0}SOURCES += {1}\n'.format(prefix, source)) if tail is not None: f.write(tail) # Add the project independent post-configuration stuff. self._write_embedded_lib_file('post_configuration.pro', f) # Add any application specific stuff. qmake_configuration = project.qmake_configuration.strip() if qmake_configuration != '': f.write('\n' + qmake_configuration + '\n') # All done. f.close()
def _generate_resource(self, resources_dir, required_py, job_writer, nr_resources): """ Generate the application resource. """ project = self._project self._create_directory(resources_dir) resource_contents = [] # Handle any application package. if project.application_package.name is not None: fi = QFileInfo(project.path_from_user( project.application_package.name)) package_src_dir = fi.canonicalFilePath() package_name = project.application_package.name if package_name != '': package_name = fi.completeBaseName() self._write_package(resource_contents, resources_dir, package_name, project.application_package, package_src_dir, job_writer) # Handle the Python standard library. self._write_stdlib_py(resource_contents, resources_dir, required_py, job_writer) # Handle any additional packages. for package in project.other_packages: self._write_package(resource_contents, resources_dir, '', package, project.path_from_user(package.name), job_writer) # Handle the PyQt package. if len(project.pyqt_modules) != 0: pyqt_subdir = 'PyQt5' if project.application_is_pyqt5 else 'PyQt4' pyqt_dst_dir = resources_dir + '/' + pyqt_subdir pyqt_src_dir = project.path_from_user(project.python_target_stdlib_dir) + '/site-packages/' + pyqt_subdir self._create_directory(pyqt_dst_dir) self._freeze(job_writer, pyqt_dst_dir + '/__init__.pyo', pyqt_src_dir + '/__init__.py', pyqt_subdir + '/__init__.pyo') resource_contents.append(pyqt_subdir + '/__init__.pyo') # Handle the PyQt.uic package. if 'uic' in project.pyqt_modules: skip_dirs = ['__pycache__'] if project.python_target_version[0] == 3: skip_dirs.append('port_v2') else: skip_dirs.append('port_v3') def copy_freeze(src, dst): for skip in skip_dirs: if skip in src: break else: if dst.endswith('.py'): dst += 'o' src = QDir.fromNativeSeparators(src) dst = QDir.fromNativeSeparators(dst) rel_dst = dst[len(resources_dir) + 1:] self._freeze(job_writer, dst, src, rel_dst) resource_contents.append(rel_dst) shutil.copytree(QDir.toNativeSeparators(pyqt_src_dir + '/uic'), QDir.toNativeSeparators(pyqt_dst_dir + '/uic'), copy_function=copy_freeze) # Write the .qrc files. if nr_resources == 1: resource_names = [self._write_resource(resources_dir, resource_contents)] else: resource_names = [] nr_files = len(resource_contents) if nr_resources > nr_files: nr_resources = nr_files per_resource = (nr_files + nr_resources - 1) // nr_resources start = 0 for r in range(nr_resources): end = start + per_resource if end > nr_files: end = nr_files resource_names.append( self._write_resource(resources_dir, resource_contents[start:end], r)) start += per_resource return resource_names
def getBaseName(self): if self._fileName: fileinfo = QFileInfo(self._fileName) basename = fileinfo.completeBaseName() return (basename if basename else fileinfo.fileName()) return self.tr("New document")
def getBaseName(self): if self._fileName: fileinfo = QFileInfo(self._fileName) basename = fileinfo.completeBaseName() return basename if basename else fileinfo.fileName() return self.tr("New document")
def _write_qmake(self, py_version, build_dir, required_ext, required_libraries, include_dir, python_library, standard_library_dir, job_writer, opt, resource_names): """ Create the .pro file for qmake. """ project = self._project f = self._create_file(build_dir + '/' + project.get_executable_basename() + '.pro') f.write('TEMPLATE = app\n') # Configure the CONFIG and QT values that are project dependent. needs_cpp11 = False needs_gui = False qmake_qt4 = set() qmake_config4 = set() qmake_qt5 = set() qmake_config5 = set() for pyqt_m in project.pyqt_modules: metadata = self._get_pyqt_module_metadata(pyqt_m) if metadata.cpp11: needs_cpp11 = True if metadata.gui: needs_gui = True qmake_qt4.update(metadata.qt4) qmake_config4.update(metadata.config4) qmake_qt5.update(metadata.qt5) qmake_config5.update(metadata.config5) both_qt = qmake_qt4 & qmake_qt5 qmake_qt4 -= both_qt qmake_qt5 -= both_qt both_config = qmake_qt4 & qmake_qt5 qmake_config4 -= both_config qmake_config5 -= both_config both_config.add('warn_off') if project.application_is_console or not needs_gui: both_config.add('console') if needs_cpp11: both_config.add('c++11') f.write('\n') f.write('CONFIG += {0}\n'.format(' '.join(both_config))) if not project.application_is_bundle: f.write('CONFIG -= app_bundle\n') if not needs_gui: f.write('QT -= gui\n') if both_qt: f.write('QT += {0}\n'.format(' '.join(both_qt))) if qmake_config4 or qmake_qt4: f.write('\n') f.write('lessThan(QT_MAJOR_VERSION, 5) {\n') if qmake_config4: f.write(' CONFIG += {0}\n'.format(' '.join(qmake_config4))) if qmake_qt4: f.write(' QT += {0}\n'.format(' '.join(qmake_qt4))) f.write('}\n') if qmake_config5 or qmake_qt5: f.write('\n') f.write('greaterThan(QT_MAJOR_VERSION, 4) {\n') if qmake_config5: f.write(' CONFIG += {0}\n'.format(' '.join(qmake_config5))) if qmake_qt5: f.write(' QT += {0}\n'.format(' '.join(qmake_qt5))) f.write('}\n') # Modules can share sources so we need to make sure we don't include # them more than once. We might as well handle the other things in the # same way. used_qt = {} used_config = {} used_sources = {} used_defines = {} used_includepath = {} used_libs = {} used_inittab = {} used_dlls = {} # Handle any static PyQt modules. if len(project.pyqt_modules) > 0: site_packages = standard_library_dir + '/site-packages' pyqt_version = 'PyQt5' if project.application_is_pyqt5 else 'PyQt4' l_libs = [] for pyqt in self._get_all_pyqt_modules(): # The sip module is always needed (implicitly or explicitly) if # we have got this far. We handle it separately as it is in a # different directory. if pyqt == 'sip': continue # The uic module is pure Python. if pyqt == 'uic': continue self._add_value_for_scopes(used_inittab, pyqt_version + '.' + pyqt) lib_name = pyqt if self._get_pyqt_module_metadata(pyqt).needs_suffix: # Qt4's qmake thinks -lQtCore etc. always refer to the Qt # libraries so PyQt4 creates static libraries with a # suffix. lib_name += '_s' l_libs.append('-l' + lib_name) # Add the LIBS value for any PyQt modules to the global scope. if len(l_libs) > 0: self._add_value_for_scopes( used_libs, '-L{0}/{1} {2}'.format(site_packages, pyqt_version, ' '.join(l_libs))) # Add the sip module. self._add_value_for_scopes(used_inittab, 'sip') self._add_value_for_scopes(used_libs, '-L{0} -lsip'.format(site_packages)) # Handle any other extension modules. for other_em in project.other_extension_modules: scopes, value = self._get_scopes_and_value(other_em.name, ALL_SCOPES) self._add_value_for_scopes(used_inittab, value, scopes) if other_em.qt != '': self._add_parsed_scoped_values(used_qt, other_em.qt, False) if other_em.config != '': self._add_parsed_scoped_values(used_config, other_em.config, False) if other_em.sources != '': self._add_parsed_scoped_values(used_sources, other_em.sources, True) if other_em.defines != '': self._add_parsed_scoped_values(used_defines, other_em.defines, False) if other_em.includepath != '': self._add_parsed_scoped_values(used_includepath, other_em.includepath, True) if other_em.libs != '': self._add_parsed_scoped_values(used_libs, other_em.libs, False) # Configure the target Python interpreter. if include_dir != '': self._add_value_for_scopes(used_includepath, include_dir) if python_library != '': fi = QFileInfo(python_library) py_lib_dir = fi.absolutePath() lib = fi.completeBaseName() # This is smart enough to translate the Python library as a UNIX .a # file to what Windows needs. if lib.startswith('lib'): lib = lib[3:] if '.' in lib: self._add_value_for_scopes( used_libs, '-L{0} -l{1}'.format(py_lib_dir, lib.replace('.', '')), ['win32']) self._add_value_for_scopes( used_libs, '-L{0} -l{1}'.format(py_lib_dir, lib), ['!win32']) else: self._add_value_for_scopes( used_libs, '-L{0} -l{1}'.format(py_lib_dir, lib)) else: py_lib_dir = None # Handle any standard library extension modules. if len(required_ext) != 0: source_dir = project.path_from_user(project.python_source_dir) source_scopes = set() for name, module in required_ext.items(): # Get the list of all applicable scopes. module_scopes = self._stdlib_scopes(module.scope) if len(module_scopes) == 0: # The module is specific to a platform for which we are # using the python.org Python libraries so ignore it # completely. continue self._add_value_for_scopes(used_inittab, name, module_scopes) for source in module.source: scopes, source = self._get_scopes_and_value( source, module_scopes) source = self._python_source_file(source_dir, source) self._add_value_for_scopes(used_sources, source, scopes) source_scopes.update(scopes) if module.defines is not None: for define in module.defines: scopes, define = self._get_scopes_and_value( define, module_scopes) self._add_value_for_scopes(used_defines, define, scopes) if module.includepath is not None: for includepath in module.includepath: scopes, includepath = self._get_scopes_and_value( includepath, module_scopes) includepath = self._python_source_file( source_dir, includepath) self._add_value_for_scopes(used_includepath, includepath, scopes) if module.libs is not None: for lib in module.libs: scopes, lib = self._get_scopes_and_value( lib, module_scopes) self._add_value_for_scopes(used_libs, lib, scopes) if module.pyd is not None: self._add_value_for_scopes(used_dlls, module, ['win32']) self._add_value_for_scopes(used_includepath, source_dir + '/Modules', source_scopes) if 'win32' not in project.python_use_platform: self._add_value_for_scopes(used_includepath, source_dir + '/PC', ['win32']) # Handle any required external libraries. for required_lib in required_libraries: for xlib in project.external_libraries: if xlib.name == required_lib: if xlib.defines != '': self._add_parsed_scoped_values(used_defines, xlib.defines, False) if xlib.includepath != '': self._add_parsed_scoped_values(used_includepath, xlib.includepath, True) if xlib.libs != '': self._add_parsed_scoped_values(used_libs, xlib.libs, False) break else: for xlib in external_libraries_metadata: if xlib.name == required_lib: scopes = self._stdlib_scopes() if len(scopes) != 0: for lib in xlib.libs.split(): self._add_value_for_scopes( used_libs, lib, scopes) break # Specify the resource files. f.write('\n') f.write('RESOURCES = \\\n') f.write(' \\\n'.join( [' resources/{0}'.format(n) for n in resource_names])) f.write('\n') # Specify the source and header files. f.write('\n') f.write( 'SOURCES = pyqtdeploy_main.cpp pyqtdeploy_start.cpp pdytools_module.cpp\n' ) self._write_main(build_dir, used_inittab) self._copy_lib_file('pyqtdeploy_start.cpp', build_dir) self._copy_lib_file('pdytools_module.cpp', build_dir) self._copy_lib_file('pyqtdeploy_python.h', build_dir) defines = [] headers = [ 'pyqtdeploy_version.h', 'frozen_bootstrap.h', 'pyqtdeploy_python.h' ] if py_version >= 0x030500: headers.append('frozen_bootstrap_external.h') if project.application_script != '': defines.append('PYQTDEPLOY_FROZEN_MAIN') headers.append('frozen_main.h') if opt: defines.append('PYQTDEPLOY_OPTIMIZED') if len(defines) != 0: f.write('DEFINES += {0}\n'.format(' '.join(defines))) f.write('HEADERS = {0}\n'.format(' '.join(headers))) # Get the set of all scopes used. used_scopes = set(used_qt.keys()) used_scopes.update(used_config.keys()) used_scopes.update(used_sources.keys()) used_scopes.update(used_defines.keys()) used_scopes.update(used_includepath.keys()) used_scopes.update(used_libs.keys()) used_scopes.update(used_dlls.keys()) # Write out grouped by scope. for scope in used_scopes: f.write('\n') if scope == '': indent = '' tail = None elif scope.startswith('win32_'): # We could avoid the hardcoded handling by reverting to # defining appropriate CONFIG values in a pre_configuration.pro # file. indent = ' ' f.write( 'win32 {\n %scontains(QMAKE_TARGET.arch, x86_64) {\n' % ('!' if scope == 'win32_x86' else '')) tail = ' }\n}\n' else: indent = ' ' f.write('%s {\n' % scope) tail = '}\n' for qt in used_qt.get(scope, ()): f.write('{0}QT += {1}\n'.format(indent, qt)) for config in used_config.get(scope, ()): f.write('{0}CONFIG += {1}\n'.format(indent, config)) for defines in used_defines.get(scope, ()): f.write('{0}DEFINES += {1}\n'.format(indent, defines)) for includepath in used_includepath.get(scope, ()): f.write('{0}INCLUDEPATH += {1}\n'.format(indent, includepath)) for lib in used_libs.get(scope, ()): # A (strictly unnecessary) bit of pretty printing. if lib.startswith('"-framework') and lib.endswith('"'): lib = lib[1:-1] f.write('{0}LIBS += {1}\n'.format(indent, lib)) for source in used_sources.get(scope, ()): for ext, qmake_var in self._source_extensions.items(): if source.endswith(ext): break else: qmake_var = 'SOURCES' f.write('{0}{1} += {2}\n'.format(indent, qmake_var, source)) if tail is not None: f.write(tail) # If we are using the platform Python on Windows then copy in the # required DLLs if they can be found. if 'win32' in project.python_use_platform and used_dlls and py_lib_dir is not None: self._copy_windows_dlls(py_version, py_lib_dir, used_dlls['win32'], f) # Add the project independent post-configuration stuff. self._write_embedded_lib_file('post_configuration.pro', f) # Add any application specific stuff. qmake_configuration = project.qmake_configuration.strip() if qmake_configuration != '': f.write('\n' + qmake_configuration + '\n') # All done. f.close()