def __get_sqlite_name(self) -> str: """Create the name for the SqliteDB. Therefor combine the Qt Application Defs: QStandardPaths.DataLocation + QtCoreApplication.applicationName + .sqlite3 * *on Mac is this* `~/Library/Application Support/io.jmuelbert.github/jmbde/jmbde.sqlite3` * *on Linux this* `~/.local/share/<APPNAME>/jmbde.sqlite3` * *on Windows is this* `C:/Users/<USER>/AppData/Local/<APPNAME>/jmbde.sqlite3` Returns: The connection string fot the sqlite database. """ db_data_path = QStandardPaths.writableLocation( QStandardPaths.DataLocation) self.log.info("The Database: {}".format(db_data_path)) write_dir = QDir(db_data_path) if not write_dir.mkpath("."): self.log.error("Failed to create writable directory") if not write_dir.exists(): write_dir.mkpath(db_data_path) # Ensure that we have a writable location on all devices. filename = "{}/{}.sqlite3".format(write_dir.absolutePath(), QCoreApplication.applicationName()) return filename
def savePackageAs(self): fileName = QFileDialog.getSaveFileName(self, "Save File", "/Packages/", "Packages (*.ezpak)")[0] if fileName != "": myDir = QDir() myDir.mkpath(fileName) for file in self.uselistmodel.metadataList: QFile.copy(file, fileName + "/" + file.split("/")[-1]) oldtemplate = open(self.templateFilePath, 'r') oldtemplatelist = oldtemplate.readline() filetype = oldtemplate.readline() oldtemplate.readline() oldlist = oldtemplate.readline() oldtree = oldtemplate.readline() oldtemplate.close() with open(fileName + "/" + self.currentTemplate, 'w') as outfile: outfile.write(oldtemplatelist) outfile.write(filetype) json.dump(self.editableKeys, outfile) outfile.write("\n") outfile.write(oldlist) outfile.write(oldtree) with open(fileName + "/" + self.currentTemplate + "pak", 'w') as outfile: json.dump(fileName + "/" + self.currentTemplate, outfile) outfile.write("\n") json.dump(self.ui.otherDataFileLineEdit.text(), outfile) outfile.write("\n") json.dump(self.uselistmodel.metadataList, outfile)
def saveToFile(self, fileName): dir_path = os.path.dirname(os.path.realpath(fileName)) dir = QDir('/') dir.mkpath(dir_path) file = QSaveFile(fileName) if file.open(QFile.WriteOnly): out = QTextStream(file) for sample in self.recordedSamples: out << sample.toCSV() << '\n' file.commit() self.recordedSamples = list() else: print('ERROR: failed to open file') print(file.error())
def saveToFile(self, fileName): # ensure that path exists dir_path = os.path.dirname(os.path.realpath(fileName)) dir = QDir('/') dir.mkpath(dir_path) file = QSaveFile(fileName) if file.open(QFile.WriteOnly): out = QTextStream(file) for sample in self.recorded_samples: out << sample.toCSV() << '\n' file.commit() del self.recorded_samples[:] self.recordingProgress.emit(0, self.max_samples) else: self.logger.error('Failed to open file') self.logger.error(file.error())
def connectToDatabase(): database = QSqlDatabase.database() if not database.isValid(): database = QSqlDatabase.addDatabase("QSQLITE") if not database.isValid(): logger.error("Cannot add database") writeDir = QDir() # writeDir = QStandardPaths.writableLocation(QStandardPaths.AppDataLocation) if not writeDir.mkpath("."): logger.error("Failed to create writable directory") # Ensure that we have a writable location on all devices fileName = writeDir.absolutePath() + "/chat-database.sqlite3" database.setDatabaseName(fileName) # open() will create the SQLite database if it doesn't exist if not database.open(): logger.error("Cannot open database") QFile.remove(fileName)
def connectToDatabase(logger): database = QSqlDatabase.database() if not database.isValid(): database = QSqlDatabase.addDatabase('QSQLITE') if not database.isValid(): logger.error('Cannot add database') write_dir = QDir() if not write_dir.mkpath('.'): logger.error('Failed to create writable directory') # Ensure that we have a writable location on all devices. filename = '{}/chat-database.sqlite3'.format(write_dir.absolutePath()) # When using the SQLite driver, open() will create the SQLite database if it doesn't exist. database.setDatabaseName(filename) if not database.open(): logger.error('Cannot open database') QFile.remove(filename)
if __name__ == "__main__": logger.info("Application started") import sys from src.controllers.maincontroller import MainController app = QApplication(sys.argv) qss = "qt_design/stylesheet.qss" with open(qss, "r") as fh: app.setStyleSheet(fh.read()) app.setApplicationName("CSCreator") data_location = QStandardPaths.writableLocation( QStandardPaths.AppDataLocation) data_dir = QDir(data_location) if not data_dir.exists(): data_dir.mkpath(data_location) if not data_dir.exists("importers"): data_dir.mkdir("importers") if os.environ.get("DEBUG") is not None: copytree("src/data/importers", os.path.join(data_location, "importers")) main_controller = MainController() main_view = main_controller.get_window() main_view.show() sys.exit(app.exec_())