Exemplo n.º 1
0
 def _get_default_directory(self):
     if not self._project_manager.filename:
         default_location = self._application_configuration.get_value('application.default_directory')
         if default_location and path.isdir(default_location):
             return default_location
         return QStandardPaths.writableLocation(QStandardPaths.DocumentsLocation)
     else:
         return path.dirname(self._project_manager.filename)
Exemplo n.º 2
0
def getSettingsFile():
    appPath = QStandardPaths.writableLocation(QStandardPaths.AppDataLocation)
    appDir = QDir(appPath)
    if not appDir.exists():
        logger.debug('Creating app directory')
        appDir.mkpath(appDir.absolutePath())
    else:
        logger.debug('App directory already exists')
    if appDir.setCurrent(appDir.absolutePath()):
        logger.debug('Changing cwd to app data directory')
    else:
        logger.debug('Changing cwd to app data directory failed')
    return QFile('settings.json')
Exemplo n.º 3
0
def local_socket_address():
    if getattr(local_socket_address, 'ADDRESS', None) is None:
        if iswindows:
            local_socket_address.ADDRESS = r'\\.\pipe\vise-local-server'
            try:
                user = get_windows_username()
            except Exception:
                user = None
            if user:
                user = user.replace(' ', '_')
                if user:
                    local_socket_address.ADDRESS += '-' + user[:100] + 'x'
        else:
            user = os.environ.get('USER', '')
            if not user:
                user = os.path.basename(os.path.expanduser('~'))
            rdir = QStandardPaths.writableLocation(
                QStandardPaths.RuntimeLocation
            ) or QStandardPaths.writableLocation(QStandardPaths.TempLocation)
            local_socket_address.ADDRESS = os.path.join(
                rdir, user + '-vise-local-server')
    return local_socket_address.ADDRESS
Exemplo n.º 4
0
    def init(self):
        from .MainApplication import MainApplication
        appDir = QCoreApplication.applicationDirPath()
        self._paths[self.AppData].extend(
            QStandardPaths.standardLocations(QStandardPaths.AppDataLocation))
        self._paths[self.Plugins].append(pathjoin(appDir, 'plugins'))
        for location in self._paths[self.AppData]:
            self.initAssertIn(location)
        if MainApplication.isTestModeEnabled():
            self._paths[self.Config].append(
                pathjoin(QDir().tempPath(), '%s-test' % const.APPNAME))
        else:
            self._paths[self.Config].append(
                QStandardPaths.writableLocation(
                    QStandardPaths.AppConfigLocation))

        self._paths[self.Profiles].append(
            pathjoin(self._paths[self.Config][0], 'profiles'))
        # We also allow to load data from Config path
        self.initAssertIn(self._paths[self.Config][0])

        # if PLUGIN_PATH is set, only load plugins from there
        pluginPath = environ.get('PLUGIN_PATH', '')
        if pluginPath:
            self._paths[self.Plugins] = [
                pluginPath,
            ]

        self._tmpdir = QTemporaryDir()
        self._paths[self.Temp].append(self._tmpdir.path())
        if not self._tmpdir.isValid():
            print('Failed to create temporary directory %s' %
                  self._tmpdir.path(),
                  file=stderr)

        self._paths[self.Cache].append(
            QStandardPaths.writableLocation(QStandardPaths.CacheLocation))
Exemplo n.º 5
0
def _get_cache_dir():
    if 'VISE_CACHE_DIRECTORY' in os.environ:
        return os.path.abspath(os.path.expanduser(os.environ['VISE_CACHE_DIRECTORY']))

    candidate = QStandardPaths.writableLocation(QStandardPaths.CacheLocation)
    if not candidate and not iswindows and not isosx:
        candidate = os.path.expanduser(os.environ.get('XDG_CACHE_HOME', u'~/.cache'))
    if not candidate:
        raise RuntimeError(
            'Failed to find path for application cache directory')
    ans = os.path.join(candidate, appname)
    try:
        os.makedirs(ans)
    except FileExistsError:
        pass
    return ans
Exemplo n.º 6
0
    def on_capture_clicked(self):
        img = self.web_view.grab()
        print(img)
        rect = QRect(0, 0, img.width(), self._line_count * 16)
        img = img.copy(rect)

        path = QStandardPaths.writableLocation(QStandardPaths.PicturesLocation)

        file_name, _ = QFileDialog.getSaveFileName(
            self, "Caption", path, "Image Files (*.png, *.jpg *.bmp)")
        if not file_name:
            return
        file_name, file_extension = os.path.splitext(file_name)
        if not file_extension:
            file_name += '.png'

        img.save(file_name)
Exemplo n.º 7
0
def local_socket_address():
    if getattr(local_socket_address, 'ADDRESS', None) is None:
        if iswindows:
            local_socket_address.ADDRESS = r'\\.\pipe\vise-local-server'
            try:
                user = get_windows_username()
            except Exception:
                user = None
            if user:
                user = user.replace(' ', '_')
                if user:
                    local_socket_address.ADDRESS += '-' + user[:100] + 'x'
        else:
            user = os.environ.get('USER', '')
            if not user:
                user = os.path.basename(os.path.expanduser('~'))
            rdir = QStandardPaths.writableLocation(QStandardPaths.RuntimeLocation) or QStandardPaths.writableLocation(QStandardPaths.TempLocation)
            local_socket_address.ADDRESS = os.path.join(rdir, user + '-vise-local-server')
    return local_socket_address.ADDRESS
Exemplo n.º 8
0
def _get_config_dir():
    if 'VISE_CONFIG_DIRECTORY' in os.environ:
        return os.path.abspath(os.path.expanduser(os.environ['VISE_CONFIG_DIRECTORY']))

    candidate = QStandardPaths.writableLocation(QStandardPaths.ConfigLocation)
    if not candidate:
        if isosx:
            candidate = os.path.expanduser('~/Library/Preferences')
        elif not iswindows:
            candidate = os.path.expanduser(os.environ.get('XDG_CONFIG_HOME', u'~/.config'))
    if not candidate:
        raise RuntimeError(
            'Failed to find path for application config directory')
    ans = os.path.join(candidate, appname)
    try:
        os.makedirs(ans)
    except FileExistsError:
        pass
    return ans
Exemplo n.º 9
0
    def loadSettings(self):
        settings = Settings()
        settings.beginGroup("DownloadManager")
        self._downloadPath = settings.value("defaultDownloadPath", '')
        self._lastDownloadPath = settings.value(
            "lastDownloadPath",
            QStandardPaths.writableLocation(QStandardPaths.DownloadLocation))
        self._closeOnFinish = settings.value("CloseManagerOnFinish", False)
        self._useNativeDialog = settings.value(
            "useNativeDialog", const.DEFAULT_DOWNLOAD_USE_NATIVE_DIALOG)

        self._useExternalManager = settings.value("UseExternalManager", False)
        self._externalExecutable = settings.value("ExternalManagerExecutable",
                                                  '')
        self._externalArguments = settings.value("ExternalManagerArguments",
                                                 '')
        settings.endGroup()

        if "%d" not in self._externalArguments:
            self._externalArguments += " %d"
Exemplo n.º 10
0
 def fontsPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.FontsLocation)
Exemplo n.º 11
0
 def musicPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.MusicLocation)
Exemplo n.º 12
0
 def genericConfigPath(self):
     return QStandardPaths.writableLocation(
         QStandardPaths.GenericConfigLocation)
Exemplo n.º 13
0
 def desktopPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.DesktopLocation)
Exemplo n.º 14
0
 def cachePath(self):
     return QStandardPaths.writableLocation(QStandardPaths.CacheLocation)
Exemplo n.º 15
0
 def homePath(self):
     return QStandardPaths.writableLocation(QStandardPaths.HomeLocation)
Exemplo n.º 16
0
def _get_path(location):
    return QStandardPaths.writableLocation(location)
Exemplo n.º 17
0
 def cachePath(self):
     return QStandardPaths.writableLocation(QStandardPaths.CacheLocation)
Exemplo n.º 18
0
 def picturesPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.PicturesLocation)
Exemplo n.º 19
0
 def homePath(self):
     return QStandardPaths.writableLocation(QStandardPaths.HomeLocation)
Exemplo n.º 20
0
 def genericDataPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.GenericDataLocation)
Exemplo n.º 21
0
 def genericCachePath(self):
     return QStandardPaths.writableLocation(
         QStandardPaths.GenericCacheLocation)
Exemplo n.º 22
0
 def genericCachePath(self):
     return QStandardPaths.writableLocation(QStandardPaths.GenericCacheLocation)
Exemplo n.º 23
0
 def tempPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.TempLocation)
Exemplo n.º 24
0
 def runtimePath(self):
     return QStandardPaths.writableLocation(QStandardPaths.RuntimeLocation)
Exemplo n.º 25
0
 def dataPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.DataLocation)
Exemplo n.º 26
0
 def configPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.ConfigLocation)
Exemplo n.º 27
0
 def configPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.ConfigLocation)
Exemplo n.º 28
0
 def genericConfigPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.GenericConfigLocation)
Exemplo n.º 29
0
 def downloadPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.DownloadLocation)
Exemplo n.º 30
0
 def downloadPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.DownloadLocation)
Exemplo n.º 31
0
 def documentsPath(self):
     return QStandardPaths.writableLocation(
         QStandardPaths.DocumentsLocation)
Exemplo n.º 32
0
 def desktopPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.DesktopLocation)
Exemplo n.º 33
0
 def applicationsPath(self):
     return QStandardPaths.writableLocation(
         QStandardPaths.ApplicationsLocation)
Exemplo n.º 34
0
 def documentsPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.DocumentsLocation)
Exemplo n.º 35
0
 def moviesPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.MoviesLocation)
Exemplo n.º 36
0
 def fontsPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.FontsLocation)
Exemplo n.º 37
0
 def tempPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.TempLocation)
Exemplo n.º 38
0
 def applicationsPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.ApplicationsLocation)
Exemplo n.º 39
0
 def dataPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.DataLocation)
Exemplo n.º 40
0
 def musicPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.MusicLocation)
Exemplo n.º 41
0
 def genericDataPath(self):
     return QStandardPaths.writableLocation(
         QStandardPaths.GenericDataLocation)
Exemplo n.º 42
0
 def moviesPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.MoviesLocation)
Exemplo n.º 43
0
 def runtimePath(self):
     return QStandardPaths.writableLocation(QStandardPaths.RuntimeLocation)
Exemplo n.º 44
0
 def picturesPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.PicturesLocation)