1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: Bind a new key 2# Where your project will look for your data (for instance, images and ui 3# files). By default, this is ../data, relative your trunk layout 4# pylint: disable=deprecated-module 5import optparse 6 7__ulauncher_data_directory__ = '../data/' 8__license__ = 'GPL-3' 9__version__ = '5.14.2' 10 11import os 12from uuid import uuid4 13from time import time 14from functools import lru_cache 15 16from gettext import gettext 17from xdg.BaseDirectory import xdg_config_home, xdg_cache_home, xdg_data_dirs, xdg_data_home 18 19 20DATA_DIR = os.path.join(xdg_data_home, 'ulauncher') 21# Use ulauncher_cache dir because of the WebKit bug 22# https://bugs.webkit.org/show_bug.cgi?id=151646 23CACHE_DIR = os.path.join(xdg_cache_home, 'ulauncher_cache') 24CONFIG_DIR = os.path.join(xdg_config_home, 'ulauncher') 25SETTINGS_FILE_PATH = os.path.join(CONFIG_DIR, 'settings.json') 26# spec: https://specifications.freedesktop.org/menu-spec/latest/ar01s02.html 27DESKTOP_DIRS = list(filter(os.path.exists, [os.path.join(dir, "applications") for dir in xdg_data_dirs])) 28EXTENSIONS_DIR = os.path.join(DATA_DIR, 'extensions') 29EXT_PREFERENCES_DIR = os.path.join(CONFIG_DIR, 'ext_preferences') 30ULAUNCHER_APP_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) 31 32 33class ProjectPathNotFoundError(Exception): 34 """Raised when we can't find the project directory.""" 35 36 37def get_data_file(*path_segments): 38 """Get the full path to a data file. 39 40 :returns: path to a file underneath the data directory (as defined by :func:`get_data_path`). 41 Equivalent to :code:`os.path.join(get_data_path(),*path_segments)`. 42 """ 43 return os.path.join(get_data_path(), *path_segments) 44 45 46def get_data_path(): 47 """Retrieve ulauncher data path 48 49 This path is by default `<ulauncher_path>/../data/` in trunk 50 and `/usr/share/ulauncher` in an installed version but this path 51 is specified at installation time. 52 """ 53 54 # Get pathname absolute or relative. 55 path = os.path.join( 56 os.path.dirname(__file__), __ulauncher_data_directory__) 57 58 abs_data_path = os.path.abspath(path) 59 if not os.path.exists(abs_data_path): 60 raise ProjectPathNotFoundError(abs_data_path) 61 62 return abs_data_path 63 64 65@lru_cache() 66def get_options(): 67 """Support for command line options""" 68 parser = optparse.OptionParser(version="%%prog %s" % get_version()) 69 parser.add_option( 70 "-v", "--verbose", action="count", dest="verbose", 71 help=gettext("Show debug messages")) 72 parser.add_option( 73 "--hide-window", action="store_true", 74 help=gettext("Hide window upon application startup")) 75 parser.add_option( 76 "--no-extensions", action="store_true", 77 help=gettext("Do not run extensions")) 78 parser.add_option( 79 "--no-window-shadow", action="store_true", 80 help=gettext("Removes window shadow. On DEs without a compositor this solves issue with a black border")) 81 parser.add_option( 82 "--dev", action="store_true", 83 help=gettext("Enables context menu in the Preferences UI")) 84 (options, _) = parser.parse_args() 85 86 return options 87 88 89def get_default_shortcuts(): 90 google = { 91 "id": str(uuid4()), 92 "name": "Google Search", 93 "keyword": "g", 94 "cmd": "https://google.com/search?q=%s", 95 "icon": get_data_file('media/google-search-icon.png'), 96 "is_default_search": True, 97 "run_without_argument": False, 98 "added": time() 99 } 100 stackoverflow = { 101 "id": str(uuid4()), 102 "name": "Stack Overflow", 103 "keyword": "so", 104 "cmd": "https://stackoverflow.com/search?q=%s", 105 "icon": get_data_file('media/stackoverflow-icon.svg'), 106 "is_default_search": True, 107 "run_without_argument": False, 108 "added": time() 109 } 110 wikipedia = { 111 "id": str(uuid4()), 112 "name": "Wikipedia", 113 "keyword": "wiki", 114 "cmd": "https://en.wikipedia.org/wiki/%s", 115 "icon": get_data_file('media/wikipedia-icon.png'), 116 "is_default_search": True, 117 "run_without_argument": False, 118 "added": time() 119 } 120 121 return { 122 google['id']: google, 123 stackoverflow['id']: stackoverflow, 124 wikipedia['id']: wikipedia, 125 } 126 127 128def get_version(): 129 return __version__ 130