Browse Source

update template

master
Nils 4 years ago
parent
commit
10ac90be38
  1. 81
      template/qtgui/chooseSessionDirectory.py

81
template/qtgui/chooseSessionDirectory.py

@ -41,75 +41,80 @@ from qtgui.resources import * #Has the logo
class ChooseSessionDirectory(QtWidgets.QDialog):
def __init__(self, qtApp):
def __init__(self, qtApp):
language = QtCore.QLocale().languageToString(QtCore.QLocale().language())
logger.info("{}: Language set to {}".format(METADATA["name"], language))
if language in METADATA["supportedLanguages"]:
templateTranslator = QtCore.QTranslator()
templateTranslator.load(METADATA["supportedLanguages"][language], ":/template/translations/") #colon to make it a resource URL
qtApp.installTranslator(templateTranslator)
language = QtCore.QLocale().languageToString(QtCore.QLocale().language())
logger.info("{}: Language set to {}".format(METADATA["name"], language))
if language in METADATA["supportedLanguages"]:
templateTranslator = QtCore.QTranslator()
templateTranslator.load(METADATA["supportedLanguages"][language], ":/template/translations/") #colon to make it a resource URL
qtApp.installTranslator(templateTranslator)
super().__init__() #no parent, this is the top level window at this time.
self.qtApp = qtApp
self.setModal(True) #block until closed
self.ui = Ui_TemplateChooseSessionDirectory()
self.ui.setupUi(self)
self.ui = Ui_TemplateChooseSessionDirectory()
self.ui.setupUi(self)
copyright = f"""{METADATA["author"]} ({METADATA["year"]})"""
name = f"""{METADATA["name"]} ver. {METADATA["version"]}"""
aboutText = "\n".join([name, copyright ,METADATA["url"]])
self.ui.aboutLabel.setText(aboutText)
#Image: 300x151
#Image: 300x151
aboutLogoPixmap = QtGui.QPixmap(":aboutlogo.png")
pixmap_scaled = aboutLogoPixmap.scaled(self.ui.goldenratioLabel.size(), QtCore.Qt.KeepAspectRatio)
self.ui.goldenratioLabel.setPixmap(pixmap_scaled)
message = QtCore.QCoreApplication.translate("TemplateChooseSessionDirectory", "Please choose a directory for your session files. It is recommended to start through Argodejo/New Session Manager instead.")
self.ui.goldenratioLabel.setPixmap(pixmap_scaled)
message = QtCore.QCoreApplication.translate("TemplateChooseSessionDirectory", "Please choose a directory for your session files. It is recommended to start through Argodejo/New Session Manager instead.")
self.ui.label.setText(message)
settings = QtCore.QSettings("LaborejoSoftwareSuite", METADATA["shortName"])
settings = QtCore.QSettings("LaborejoSoftwareSuite", METADATA["shortName"])
self.recentDirList = []
if settings.contains("recentDirectoriesWithouNSM"):
self.recentDirList = settings.value("recentDirectoriesWithouNSM", type=list)[-5:]
if settings.contains("recentDirectoriesWithouNSM"):
self.recentDirList = settings.value("recentDirectoriesWithouNSM", type=list)[-5:]
#remember self.recentDirList for later saving
self.ui.pathComboBox.insertItems(0, reversed(self.recentDirList))
else:
self.ui.pathComboBox.setCurrentText(gettempdir())
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):
dirname = QtWidgets.QFileDialog.getExistingDirectory(self, QtCore.QCoreApplication.translate("TemplateChooseSessionDirectory", "Choose Session Directory"), str(Path.home()))
self.ui.openFileDialogButton.clicked.connect(self.requestPathFromDialog)
self.exec()
def requestPathFromDialog(self):
if self.ui.pathComboBox.currentText() == gettempdir():
startPath = str(Path.home())
else:
startPath = self.ui.pathComboBox.currentText()
dirname = QtWidgets.QFileDialog.getExistingDirectory(self, QtCore.QCoreApplication.translate("TemplateChooseSessionDirectory", "Choose Session Directory"), startPath)
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):
settings = QtCore.QSettings("LaborejoSoftwareSuite", METADATA["shortName"])
if not os.path.exists(self.path):
try:
makedirs(self.path)
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.
#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
if not self.path in self.recentDirList:
self.recentDirList.append(self.path)
settings.setValue("recentDirectoriesWithouNSM", self.recentDirList)
super().accept()
self.recentDirList.append(self.path)
settings.setValue("recentDirectoriesWithouNSM", self.recentDirList)
super().accept()
def reject(self):
self.path = None
super().reject()

Loading…
Cancel
Save