Example #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)
Example #2
0
    def tryExec(self):
        if not self._settings:
            return False

        exec_ = self._settings.value('TryExec')
        if not exec_:
            return True
        if QStandardPaths.findExecutable(exec_):
            return True
        return False
Example #3
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')
Example #4
0
    def _initResourcePaths(self):
        resourcePaths = []
        resourcePaths.append(path.dirname(__file__))

        resourcePaths.extend(QStandardPaths.standardLocations(
            QStandardPaths.AppLocalDataLocation))

        # For when we're running from the dev tree
        resourcePaths.append(path.abspath(path.curdir))
        resourcePaths.append(path.join(path.abspath(path.curdir), 'resources'))
        resourcePaths.append(path.join(path.abspath(path.curdir), 'doc'))

        return resourcePaths
Example #5
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
Example #6
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))
Example #7
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
Example #8
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)
Example #9
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
Example #10
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
    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"
Example #12
0
 def cachePath(self):
     return QStandardPaths.writableLocation(QStandardPaths.CacheLocation)
Example #13
0
 def homePath(self):
     return QStandardPaths.writableLocation(QStandardPaths.HomeLocation)
Example #14
0
 def picturesPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.PicturesLocation)
Example #15
0
 def musicPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.MusicLocation)
Example #16
0
 def fontsPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.FontsLocation)
Example #17
0
 def desktopPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.DesktopLocation)
 def cachePath(self):
     return QStandardPaths.writableLocation(QStandardPaths.CacheLocation)
 def homePath(self):
     return QStandardPaths.writableLocation(QStandardPaths.HomeLocation)
 def picturesPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.PicturesLocation)
Example #21
0
def _get_path(location):
    return QStandardPaths.writableLocation(location)
Example #22
0
 def genericCachePath(self):
     return QStandardPaths.writableLocation(
         QStandardPaths.GenericCacheLocation)
 def genericDataPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.GenericDataLocation)
Example #24
0
 def genericConfigPath(self):
     return QStandardPaths.writableLocation(
         QStandardPaths.GenericConfigLocation)
 def tempPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.TempLocation)
 def genericCachePath(self):
     return QStandardPaths.writableLocation(QStandardPaths.GenericCacheLocation)
 def dataPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.DataLocation)
 def runtimePath(self):
     return QStandardPaths.writableLocation(QStandardPaths.RuntimeLocation)
Example #29
0
 def configPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.ConfigLocation)
 def configPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.ConfigLocation)
Example #31
0
 def downloadPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.DownloadLocation)
 def genericConfigPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.GenericConfigLocation)
Example #33
0
 def documentsPath(self):
     return QStandardPaths.writableLocation(
         QStandardPaths.DocumentsLocation)
 def downloadPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.DownloadLocation)
Example #35
0
 def applicationsPath(self):
     return QStandardPaths.writableLocation(
         QStandardPaths.ApplicationsLocation)
 def desktopPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.DesktopLocation)
Example #37
0
 def moviesPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.MoviesLocation)
 def documentsPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.DocumentsLocation)
Example #39
0
 def tempPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.TempLocation)
 def fontsPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.FontsLocation)
Example #41
0
 def dataPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.DataLocation)
 def applicationsPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.ApplicationsLocation)
Example #43
0
 def genericDataPath(self):
     return QStandardPaths.writableLocation(
         QStandardPaths.GenericDataLocation)
 def musicPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.MusicLocation)
Example #45
0
 def runtimePath(self):
     return QStandardPaths.writableLocation(QStandardPaths.RuntimeLocation)
 def moviesPath(self):
     return QStandardPaths.writableLocation(QStandardPaths.MoviesLocation)