示例#1
0
 def addBackgroundImage(self):
     lastDirectory = self.mw.welcome.getLastAccessedDirectory()
     """File dialog that request an existing file. For opening an image."""
     filename = QFileDialog.getOpenFileName(
         self, self.tr("Open Image"), lastDirectory,
         self.tr("Image files (*.jpg; *.jpeg; *.png)"))[0]
     if filename:
         try:
             px = QPixmap()
             valid = px.load(filename)
             del px
             if valid:
                 shutil.copy(filename,
                             writablePath("resources/backgrounds"))
                 return os.path.basename(filename)
             else:
                 QMessageBox.warning(
                     self, self.tr("Error"),
                     self.tr("Unable to load selected file"))
         except Exception as e:
             QMessageBox.warning(
                 self, self.tr("Error"),
                 self.tr("Unable to add selected image:\n{}").format(
                     str(e)))
     return None
示例#2
0
    def newTheme(self):
        path = writablePath("resources/themes")
        name = self.tr("newtheme")
        if os.path.exists(os.path.join(path, "{}.theme".format(name))):
            i = 1
            while os.path.exists(os.path.join(path, "{}_{}.theme".format(name, i))):
                i += 1
            name = os.path.join(path, "{}_{}.theme".format(name, i))
        else:
            name = os.path.join(path, "{}.theme".format(name))

        settings = QSettings(name, QSettings.IniFormat)
        settings.setValue("Name", self.tr("New theme"))
        settings.sync()

        self.populatesThemesList()
示例#3
0
    def newTheme(self):
        path = writablePath("resources/themes")
        name = self.tr("newtheme")
        if os.path.exists(os.path.join(path, "{}.theme".format(name))):
            i = 1
            while os.path.exists(os.path.join(path, "{}_{}.theme".format(name, i))):
                i += 1
            name = os.path.join(path, "{}_{}.theme".format(name, i))
        else:
            name = os.path.join(path, "{}.theme".format(name))

        settings = QSettings(name, QSettings.IniFormat)
        settings.setValue("Name", self.tr("New theme"))
        settings.sync()

        self.populatesThemesList()
示例#4
0
    def addBackgroundImage(self):
        lastDirectory = self.mw.welcome.getLastAccessedDirectory()

        """File dialog that request an existing file. For opening an image."""
        filename = QFileDialog.getOpenFileName(self,
                                               self.tr("Open Image"),
                                               lastDirectory,
                                               self.tr("Image files (*.jpg; *.jpeg; *.png)"))[0]
        if filename:
            try:
                px = QPixmap()
                valid = px.load(filename)
                del px
                if valid:
                    shutil.copy(filename, writablePath("resources/backgrounds"))
                    return os.path.basename(filename)
                else:
                    QMessageBox.warning(self, self.tr("Error"),
                                        self.tr("Unable to load selected file"))
            except Exception as e:
                QMessageBox.warning(self, self.tr("Error"),
                                    self.tr("Unable to add selected image:\n{}").format(str(e)))
        return None
示例#5
0
def getDefaultLogFile():
    """Returns a filename to log to inside {datadir}/logs/.

    It also prunes old logs so that we do not hog disk space excessively over time.
    """
    # Ensure logs directory exists.
    logsPath = os.path.join(writablePath(), "logs")
    os.makedirs(logsPath, exist_ok=True)
    # Prune irrelevant log files. They are only kept for 35 days.
    try:  # Guard against os.scandir() in the name of paranoia.
        now = time.time()
        with os.scandir(logsPath) as it:
            for f in it:
                try:  # Avoid triggering outer try-except inside loop.
                    if f.is_dir():
                        continue  # If a subdirectory exists for whatever reason, don't touch it.
                    if (now - f.stat().st_ctime) // (24 * 3600) >= 35:
                        os.remove(f)
                except OSError:
                    continue  # Fail silently, but make sure we check other files.
    except OSError:
        pass  # Fail silently. Don't explode and prevent Manuskript from starting.
    return os.path.join(logsPath, "%Y-%m-%d_%H-%M-%S_manuskript#%#.log")
示例#6
0
 def getResourcesPath(cls):
     path = os.path.join(writablePath(), "resources", "dictionaries",
                         cls.getLibraryName())
     if not os.path.exists(path):
         os.makedirs(path)
     return path
示例#7
0
 def getSettingsPath(self):
     return os.path.join(writablePath(), "exporter.ini")