#! /usr/bin/env python3 # -*- coding: utf-8 -*- """ Copyright 2022, Nils Hilbricht, Germany ( https://www.hilbricht.net ) This file is part of the Laborejo Software Suite ( https://www.laborejo.org ), This application is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . """ import logging; logger = logging.getLogger(__name__); logger.info("import") #Standard Lib from pathlib import Path import os.path from os import makedirs #System Wide Modules from PyQt5 import QtCore, QtWidgets, QtGui #Template Moduiles from .designer.chooseDownloadDirectory import Ui_ChooseDownloadDirectory from .resources import * #has the translation #Client Modules import engine.api as api from engine.config import * #imports METADATA from qtgui.resources import * #Has the logo class ChooseDownloadDirectory(QtWidgets.QDialog): def __init__(self): super().__init__() #no parent, this is the top level window at this time. self.setModal(True) #block until closed self.ui = Ui_ChooseDownloadDirectory() self.ui.setupUi(self) settings = QtCore.QSettings("LaborejoSoftwareSuite", METADATA["shortName"]) if settings.contains("sampleDownloadDirectory"): self.ui.pathComboBox.insertItem(0, settings.value("sampleDownloadDirectory", type=str)) else: self.ui.pathComboBox.setCurrentText("") self.ui.buttonBox.accepted.connect(self.accept) self.ui.buttonBox.rejected.connect(self.reject) self.ui.openFileDialogButton.setText("") self.ui.openFileDialogButton.setIcon(self.style().standardIcon(getattr(QtWidgets.QStyle, "SP_DialogOpenButton"))) self.ui.openFileDialogButton.clicked.connect(self.requestPathFromDialog) self.exec() def requestPathFromDialog(self): if self.ui.pathComboBox.currentText() == "": startPath = str(Path.home()) else: startPath = self.ui.pathComboBox.currentText() dirname = QtWidgets.QFileDialog.getExistingDirectory(self, QtCore.QCoreApplication.translate("ChooseDownloadDirectory", "Choose Download Directory"), startPath, QtWidgets.QFileDialog.ShowDirsOnly|QtWidgets.QFileDialog.DontResolveSymlinks) if dirname: self.ui.pathComboBox.setCurrentText(dirname) def accept(self): self.path = self.ui.pathComboBox.currentText() #easy abstraction so that the caller does not need to know our widget name settings = QtCore.QSettings("LaborejoSoftwareSuite", METADATA["shortName"]) if not os.path.exists(self.path): try: makedirs(self.path) except: pass #file saving error logging is handled later #There is no guarantee that the dir really exists. but at this point the user is on its own. #It is allowed to use /dev/null after all settings.setValue("sampleDownloadDirectory", self.path) api.rescanSampleDirectory(self.path) super().accept() def reject(self): self.path = None super().reject()