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)
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
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')
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
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 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))
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
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)
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
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"
def cachePath(self): return QStandardPaths.writableLocation(QStandardPaths.CacheLocation)
def homePath(self): return QStandardPaths.writableLocation(QStandardPaths.HomeLocation)
def picturesPath(self): return QStandardPaths.writableLocation(QStandardPaths.PicturesLocation)
def musicPath(self): return QStandardPaths.writableLocation(QStandardPaths.MusicLocation)
def fontsPath(self): return QStandardPaths.writableLocation(QStandardPaths.FontsLocation)
def desktopPath(self): return QStandardPaths.writableLocation(QStandardPaths.DesktopLocation)
def _get_path(location): return QStandardPaths.writableLocation(location)
def genericCachePath(self): return QStandardPaths.writableLocation( QStandardPaths.GenericCacheLocation)
def genericDataPath(self): return QStandardPaths.writableLocation(QStandardPaths.GenericDataLocation)
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)
def configPath(self): return QStandardPaths.writableLocation(QStandardPaths.ConfigLocation)
def downloadPath(self): return QStandardPaths.writableLocation(QStandardPaths.DownloadLocation)
def genericConfigPath(self): return QStandardPaths.writableLocation(QStandardPaths.GenericConfigLocation)
def documentsPath(self): return QStandardPaths.writableLocation( QStandardPaths.DocumentsLocation)
def applicationsPath(self): return QStandardPaths.writableLocation( QStandardPaths.ApplicationsLocation)
def moviesPath(self): return QStandardPaths.writableLocation(QStandardPaths.MoviesLocation)
def documentsPath(self): return QStandardPaths.writableLocation(QStandardPaths.DocumentsLocation)
def applicationsPath(self): return QStandardPaths.writableLocation(QStandardPaths.ApplicationsLocation)
def genericDataPath(self): return QStandardPaths.writableLocation( QStandardPaths.GenericDataLocation)