• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sublime.find_resources函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sublime.find_resources函数的典型用法代码示例。如果您正苦于以下问题:Python find_resources函数的具体用法?Python find_resources怎么用?Python find_resources使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了find_resources函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_items

    def get_items():
        """Return a list of quick panel items for all color schemes.

        The values are the full path of each *.tmTheme.

        NOTE: Excludes color schemes manipulated by SublimeLinter as
              they are automatically created and used if required.
        """
        names = []
        values = []
        settings = sublime.load_settings("Theme-Switcher.sublime-settings")
        exclude_list = settings.get("colors_exclude") or []
        paths = sorted(
            sublime.find_resources("*.sublime-color-scheme") +
            sublime.find_resources("*.tmTheme"),
            key=lambda x: os.path.basename(x).lower())
        for path in paths:
            if not any(exclude in path for exclude in exclude_list):
                elems = path.split("/")
                # elems[1] package name
                # elems[-1] color scheme file name
                names.append(
                    [built_res_name(elems[-1]),    # title
                     "Package: " + elems[1]])      # description
                values.append(path)
        return [names, values]
开发者ID:chmln,项目名称:sublime-text-theme-switcher-menu,代码行数:26,代码来源:theme_switcher.py


示例2: get_all_syntax_files

def get_all_syntax_files():
    """ Find all sublime-syntax and tmLanguage files. """
    syntax_files = []
    if USE_ST_SYNTAX:
        syntax_files += sublime.find_resources("*.sublime-syntax")
    syntax_files += sublime.find_resources("*.tmLanguage")
    return syntax_files
开发者ID:GeoffreyBooth,项目名称:ApplySyntax,代码行数:7,代码来源:ApplySyntax.py


示例3: findSyntaxFilePaths

    def findSyntaxFilePaths(self, dropDuplicated=False):
        """
        @brief find the path of all syntax files

        @param dropDuplicated if True, for a syntax, only the highest priority resource will be returned

        @return list<string> the path of all syntax files
        """

        if dropDuplicated is False:
            syntaxFiles = []
            for syntaxFileExt in ST_LANGUAGES:
                syntaxFiles += sublime.find_resources('*'+syntaxFileExt)
        else:
            # key   = syntax resource path without extension
            # value = the corresponding extension
            # example: { 'Packages/Java/Java': '.sublime-syntax' }
            syntaxGriddle = {}
            for syntaxFileExt in ST_LANGUAGES:
                resources = sublime.find_resources('*'+syntaxFileExt)
                for resource in resources:
                    resourceName, resourceExt = os.path.splitext(resource)
                    if resourceName not in syntaxGriddle:
                        syntaxGriddle[resourceName] = resourceExt

            # combine a name and an extension back into a full path
            syntaxFiles = [n+e for n, e in syntaxGriddle.items()]

        return syntaxFiles
开发者ID:jfcherng,项目名称:Sublime-AutoSetSyntax,代码行数:29,代码来源:SyntaxMappings.py


示例4: set_syntax_by_host

    def set_syntax_by_host(host, view):
        """
        Sets the view's syntax by using the host_to_syntax for an lookup.
        """
        settings = sublime.load_settings('GhostText.sublime-settings')
        host_to_syntax = settings.get('host_to_syntax')

        syntax = None
        syntax_part = None
        for host_fragment in host_to_syntax:
            if host_fragment not in host:
                continue

            syntax_part = host_to_syntax[host_fragment]
            resources = sublime.find_resources('*{}'.format(syntax_part))

            if len(resources) > 0:
                syntax = resources[0]

        if syntax is not None:
            view.set_syntax_file(syntax)
        else:
            if syntax_part is not None:
                sublime.error_message('Syntax "{}" is not installed!'.format(syntax_part))

            default_syntax = settings.get('default_syntax', 'Markdown.tmLanguage')
            resources = sublime.find_resources('*{}'.format(default_syntax))

            if len(resources) > 0:
                view.set_syntax_file(resources[0])
            else:
                print('Default syntax "{}" is not installed!'.format(default_syntax))
开发者ID:infometrix,项目名称:GhostText-for-SublimeText,代码行数:32,代码来源:Utils.py


示例5: run

	def run(self):
		print ('ok')
		sublime.status_message("Indexing Color Schemes..")
		self.initial = sublime.load_settings("Preferences.sublime-settings").get('color_scheme')
		self.syntax = list(sorted(sublime.find_resources("*.tmTheme") + sublime.find_resources("*.sublime-syntax")))
		sublime.status_message("Found {0} color schemes in total".format(len(self.syntax)))
		self.display_list(self.syntax)
开发者ID:geekpradd,项目名称:Sublime-Color-Scheme-Cycler,代码行数:7,代码来源:color_scheme_cycler.py


示例6: _load_settings

    def _load_settings(self, on_loaded_once=None):
        """Load and merge settings and their comments from all base files.

        The idea is each package which wants to add a valid entry to the
        `Preferences.sublime-settings` file must provide such a file with all
        keys it wants to add. These keys and the associated comments above it
        are loaded into dictionaries and used to provide tooltips, completions
        and linting.
        """
        ignored_patterns = frozenset(("/User/", "/Preferences Editor/"))

        # TODO project settings include "Preferences",
        # but we don't have a syntax def for those yet
        l.debug("loading defaults and comments for %r", self.filename)
        start_time = time.time()
        resources = sublime.find_resources(self.filename)
        resources += sublime.find_resources(self.filename + "-hints")
        if self.filename == PREF_FILE:
            resources += sublime.find_resources(PREF_FILE_ALIAS)
        l.debug("found %d %r files", len(resources), self.filename)

        for resource in resources:
            if any(ignored in resource for ignored in ignored_patterns):
                l.debug("ignoring %r", resource)
                continue

            try:
                l.debug("parsing %r", resource)
                lines = sublime.load_resource(resource).splitlines()
                for key, value in self._parse_settings(lines).items():
                    # merge settings without overwriting existing ones
                    self.defaults.setdefault(key, value)
            except Exception as e:
                l.error("error parsing %r - %s%s",
                        resource, e.__class__.__name__, e.args)

        duration = time.time() - start_time
        l.debug("loading took %.3fs", duration)

        # include general settings if we're in a syntax-specific file
        is_syntax_specific = self._is_syntax_specific()
        if is_syntax_specific and not self.fallback_settings:
            self.fallback_settings = KnownSettings(PREF_FILE)
            # add fallbacks to the ChainMaps
            self.defaults.maps.append(self.fallback_settings.defaults)
            self.comments.maps.append(self.fallback_settings.comments)
            # these may be loaded later, so delay calling our own callbacks
            self.fallback_settings.add_on_loaded(self._has_loaded, once=True)
        else:
            if self.fallback_settings and not is_syntax_specific:
                # file was renamed, probably
                self.fallback_settings = None
                self.defaults.maps.pop()
                self.comments.maps.pop()
            self._has_loaded()
开发者ID:SublimeText,项目名称:PackageDev,代码行数:55,代码来源:known_settings.py


示例7: run

    def run(self):
        self.prefs = sublime.load_settings(self.PREFS_FILE)

        self.views = None

        self.current = self.prefs.get('color_scheme', self.DEFAULT_CS)

        show_legacy = sublime.load_settings(
            "Preferences.sublime-settings").get("show_legacy_color_schemes", False)

        initial_highlight = -1
        self.schemes = []
        names = []
        package_set = set()

        files = sublime.find_resources('*.tmTheme')
        trimmed_names = set()
        for f in files:
            name, ext = os.path.splitext(os.path.basename(f))
            trimmed_names.add(name)

        # Add all the sublime-color-scheme files, but not the overrides
        for f in sublime.find_resources('*.sublime-color-scheme'):
            name, ext = os.path.splitext(os.path.basename(f))
            if not name in trimmed_names:
                trimmed_names.add(name)
                files.append(f)

        for cs in files:
            if self.current and cs == self.current:
                initial_highlight = len(self.schemes)
            if len(cs.split('/', 2)) != 3:  # Not in a package
                continue
            pkg = os.path.dirname(cs)
            if pkg == "Packages/Color Scheme - Legacy" and not show_legacy:
                continue
            if pkg.startswith("Packages/"):
                pkg = pkg[len("Packages/"):]
            name, ext = os.path.splitext(os.path.basename(cs))
            self.schemes.append(cs)
            names.append([name, pkg])
            package_set.add(pkg)

        # Don't show the package name if all color schemes are in the same
        # package
        if len(package_set) == 1:
            names = [name for name, pkg in names]

        self.window.show_quick_panel(
            names,
            self.on_done,
            sublime.KEEP_OPEN_ON_FOCUS_LOST,
            initial_highlight,
            self.on_highlighted
        )
开发者ID:aziz,项目名称:sublime-history,代码行数:55,代码来源:ui.py


示例8: find_tooltip_themes

    def find_tooltip_themes(self):
        """
        Find all SublimeLinter.tooltip-theme resources.

        For each found resource, if it doesn't match one of the patterns
        from the "tooltip_theme_excludes" setting, return the base name
        of resource and info on whether the theme is a standard theme
        or a user theme, as well as whether it is colorized.

        The list of paths to the resources is appended to self.themes.

        """

        self.themes = []
        settings = []
        tooltip_themes = sublime.find_resources('*.tooltip-theme')
        excludes = persist.settings.get('tooltip_theme_excludes', [])

        for theme in tooltip_themes:
            exclude = False
            parent = os.path.dirname(theme)
            htmls = sublime.find_resources('*.html')

            if '{}/tooltip.html'.format(parent) not in htmls:
                continue

            # Now see if the theme name is in tooltip_theme_excludes
            name = os.path.splitext(os.path.basename(theme))[0]

            for pattern in excludes:
                if fnmatch(name, pattern):
                    exclude = True
                    break

            if exclude:
                continue

            self.themes.append(theme)

            std_theme = theme.startswith('Packages/SublimeLinter/tooltip-themes/')

            settings.append([
                name,
                'SublimeLinter theme' if std_theme else 'User theme'
            ])

        # Sort self.themes and settings in parallel using the zip trick
        settings, self.themes = zip(*sorted(zip(settings, self.themes)))

        # zip returns tuples, convert back to lists
        settings = list(settings)
        self.themes = list(self.themes)

        return settings
开发者ID:EnTeQuAk,项目名称:dotfiles,代码行数:54,代码来源:commands.py


示例9: set_syntax

	def set_syntax(self, syntax):

		langs = sublime.find_resources('*language')
		langs += sublime.find_resources('*sublime-syntax')
		new_syntax = next((s for s in langs if syntax[0] in s), None)
		print('new syntax is ' + new_syntax)

		if new_syntax != self.syn:
			# let's make sure it exists first!
			# if os.path.exists(new_syntax_path):
			self.view.set_syntax_file(new_syntax)
			print('Syntax set to ' + syntax[0] + ' using ' + new_syntax)
开发者ID:mralexgray,项目名称:GuessSyntax,代码行数:12,代码来源:guess_syntax.py


示例10: validate_skin

def validate_skin(skin_data, fallback_theme=None, fallback_colors=None):
    """Check skin integrity and return the boolean result.

    For a skin to be valid at least 'color_scheme' or 'theme' must exist.
    If one of both values is invalid, it may be replaced with a fallback value.
    Otherwise SublimeText's behavior when loading the skin is unpredictable.

    SublimeLinter automatically creates and applies patched color schemes if
    they doesn't contain linter icon scopes. To ensure not to break this
    feature this function ensures not to apply such a hacked color scheme
    directly so SublimeLinter can do his job correctly.

    Arguments:
        skin_data (dict):
            JSON object with all settings to apply for the skin.
        fallback_theme (string):
            A valid theme name to inject into skin_data, if skin_data does not
            contain a valid one.
        fallback_colors (string):
            A valid color_scheme path to inject into skin_data, if skin_data
            does not contain a valid one.
    """
    # check theme file
    theme_name = skin_data[PREF].get("theme")
    theme_ok = theme_name and sublime.find_resources(theme_name)
    # check color scheme
    color_scheme_ok = False
    color_scheme_name = skin_data[PREF].get("color_scheme")
    if color_scheme_name:
        path, tail = os.path.split(color_scheme_name)
        name = tail.replace(" (SL)", "")
        color_schemes = sublime.find_resources(name)
        if color_schemes:
            # Try to find the exact path from *.skins file
            resource_path = "/".join((path, name))
            for found in color_schemes:
                if found == resource_path:
                    color_scheme_ok = True
                    break
            # Use the first found color scheme which matches 'name'
            if not color_scheme_ok:
                skin_data[PREF]["color_scheme"] = color_schemes[0]
                color_scheme_ok = True
    valid = theme_ok or color_scheme_ok
    if valid:
        if fallback_theme and not theme_ok:
            skin_data[PREF]["theme"] = fallback_theme
        if fallback_colors and not color_scheme_ok:
            skin_data[PREF]["color_scheme"] = fallback_colors
    return valid
开发者ID:deathaxe,项目名称:sublime-skins,代码行数:50,代码来源:skins.py


示例11: find_syntax_files

 def find_syntax_files(self):
     # ST3
     if hasattr(sublime, 'find_resources'):
         for f in sublime.find_resources("*.tmLanguage"):
             yield f
         for f in sublime.find_resources("*.sublime-syntax"):
             yield f
     else:
         for root, dirs, files in os.walk(sublime.packages_path()):
             for f in files:
                 if f.endswith(".tmLanguage") or f.endswith("*.sublime-syntax"):
                     langfile = os.path.relpath(os.path.join(root, f), sublime.packages_path())
                     # ST2 (as of build 2181) requires unix/MSYS style paths for the 'syntax' view setting
                     yield os.path.join('Packages', langfile).replace("\\", "/")
开发者ID:kleopatra999,项目名称:STEmacsModelines,代码行数:14,代码来源:EmacsModelines.py


示例12: on_ignored_packages_change

	def on_ignored_packages_change():
		the_theme = Themr.get_theme()
		if sublime.find_resources(the_theme):
			Themr.theme = the_theme
		else:
			Themr.set_theme('Default.sublime-theme')
			sublime.status_message('Theme disabled. Reverting to Default.sublime-theme')
开发者ID:andreystarkov,项目名称:sublime2-frontend,代码行数:7,代码来源:themr.py


示例13: on_theme_change

	def on_theme_change():
		the_theme = Themr.get_theme()
		if sublime.find_resources(the_theme):
			Themr.theme = the_theme
		else:
			Themr.set_theme(Themr.theme)
			sublime.status_message('Theme not found. Reverting to ' + Themr.theme)
开发者ID:andreystarkov,项目名称:sublime2-frontend,代码行数:7,代码来源:themr.py


示例14: plugin_loaded

def plugin_loaded():
	print('themr ready')

	def on_theme_change():
		the_theme = Themr.get_theme()
		if sublime.find_resources(the_theme):
			Themr.theme = the_theme
		else:
			Themr.set_theme(Themr.theme)
			sublime.status_message('Theme not found. Reverting to ' + Themr.theme)

	def on_ignored_packages_change():
		the_theme = Themr.get_theme()
		if sublime.find_resources(the_theme):
			Themr.theme = the_theme
		else:
			Themr.set_theme('Default.sublime-theme')
			sublime.status_message('Theme disabled. Reverting to Default.sublime-theme')

	preferences = sublime.load_settings('Preferences.sublime-settings')

	preferences.add_on_change('theme', on_theme_change)
	preferences.add_on_change('ignored_packages', on_ignored_packages_change)

	the_theme = Themr.get_theme()
	if sublime.find_resources(the_theme):
		Themr.theme = the_theme
	else:
		Themr.set_theme('Default.sublime-theme')
		sublime.status_message('Theme not found. Reverting to Default.sublime-theme')
开发者ID:andreystarkov,项目名称:sublime2-frontend,代码行数:30,代码来源:themr.py


示例15: syntax_testing

    def syntax_testing(self, stream, package):
        total_assertions = 0
        failed_assertions = 0

        try:
            tests = sublime.find_resources("syntax_test*")
            if package != "__all__":
                tests = [t for t in tests if t.startswith("Packages/%s/" % package)]

            # remove UnitTesting syntax_tests
            tests = [t for t in tests if not t.startswith("Packages/UnitTesting/")]

            if not tests:
                raise RuntimeError("No syntax_test files are found in %s!" % package)
            for t in tests:
                assertions, test_output_lines = sublime_api.run_syntax_test(t)
                total_assertions += assertions
                if len(test_output_lines) > 0:
                    failed_assertions += len(test_output_lines)
                    for line in test_output_lines:
                        stream.write(line + "\n")
            if failed_assertions > 0:
                stream.write("FAILED: %d of %d assertions in %d files failed\n" %
                             (failed_assertions, total_assertions, len(tests)))
            else:
                stream.write("Success: %d assertions in %s files passed\n" %
                             (total_assertions, len(tests)))
                stream.write("OK\n")
        except Exception as e:
            if not stream.closed:
                stream.write("ERROR: %s\n" % e)

        stream.write("\n")
        stream.write(DONE_MESSAGE)
        stream.close()
开发者ID:randy3k,项目名称:UnitTesting,代码行数:35,代码来源:test_syntax.py


示例16: load_schemes

	def load_schemes(self):
		scheme_paths = []
		favorites = self.get_favorites()

		try: # use find_resources() first for ST3.
			scheme_paths = sublime.find_resources('*.tmTheme')

		except: # fallback to walk() for ST2
			# Load the paths for schemes contained in zipped .sublime-package files.
			for root, dirs, files in os.walk(sublime.installed_packages_path()):
				for package in (package for package in files if package.endswith('.sublime-package')):
					zf = zipfile.ZipFile(os.path.join(sublime.installed_packages_path(), package))
					for filename in (filename for filename in zf.namelist() if filename.endswith('.tmTheme')):
						filepath = os.path.join(root, package, filename).replace(sublime.installed_packages_path(), 'Packages').replace('.sublime-package', '').replace('\\', '/')
						scheme_paths.append(filepath)

			# Load the paths for schemes contained in folders.
			for root, dirs, files in os.walk(sublime.packages_path()):
				for filename in (filename for filename in files if filename.endswith('.tmTheme')):
					filepath = os.path.join(root, filename).replace(sublime.packages_path(), 'Packages').replace('\\', '/')
					scheme_paths.append(filepath)

		scheme_paths = self.filter_scheme_list(scheme_paths)

		# Given the paths of all the color schemes, add in the information for
		# the pretty-printed name and whether or not it's been favorited.
		schemes = []
		for scheme_path in scheme_paths:
			scheme_name = self.filter_scheme_name(scheme_path)
			is_favorite = ''
			if scheme_path in favorites: is_favorite = u'   \u2605' # Put a pretty star icon next to favorited schemes. :)
			schemes.append([scheme_name, scheme_path, is_favorite])

		schemes.sort(key=lambda s: s[0].lower())
		return schemes
开发者ID:SyntaxColoring,项目名称:Schemr,代码行数:35,代码来源:schemr.py


示例17: get_language_files

def get_language_files(ignored_packages, *paths):
    r'''
    Get a list of language files respecting ignored packages.
    '''

    paths = list(paths)
    tml_files = []
    tml_files.extend(sublime.find_resources('*.tmLanguage'))

    for path in paths:
        for dir, dirs, files in os.walk(path):
            # TODO: be sure that not tmLanguage from disabled package is taken
            for fn in files:
                if fn.endswith('.tmLanguage'):
                    tml_files.append(os.path.join(dir, fn))

    R = re.compile("Packages[\\/]([^\\/]+)[\\/]")
    result = []
    for f in tml_files:
        m = R.search(f)
        if m:
            if m.group(1) not in ignored_packages:
                result.append(f)

    return result
开发者ID:klorenz,项目名称:Vintageous,代码行数:25,代码来源:modelines.py


示例18: get_theme

def get_theme(obj, default=None):
    """
    Get the theme for the theme object.

    See if ST2 or ST3 variant is avaliable,
    if not use the standard theme format.
    """

    special = "@st3" if ST3 else "@st2"
    theme = obj.get("theme", None)
    if theme is None:
        theme = default
    elif ST3:
        parts = os.path.splitext(theme)
        special_theme = parts[0] + special + parts[1]
        resources = sublime.find_resources(special_theme)
        for r in resources:
            if r == "Packages/Theme - Aprosopo/%s" % special_theme:
                theme = special_theme
                break
    else:
        parts = os.path.splitext(theme)
        special_theme = parts[0] + special + parts[1]
        pkgs = sublime.packages_path()
        resource = os.path.join(pkgs, "Theme - Aprosopo", special_theme)
        if os.path.exists(resource):
            theme = special_theme

    return theme
开发者ID:qingniaotonghua,项目名称:Aprosopo,代码行数:29,代码来源:set_theme.py


示例19: get_installed

def get_installed(logging=True):
    if logging:
        log("Getting installed themes")

    theme_resources = sublime.find_resources("*.sublime-theme")
    all_themes_ordered = OrderedDict([])
    installed_themes = {}

    for res in theme_resources:
        package = re.sub(PATTERN, "", res)
        all_themes_ordered[package] = []

    for res in theme_resources:
        package = re.sub(PATTERN, "", res)
        theme = os.path.basename(res)

        all_themes_ordered[package].append(theme)

    for k in all_themes_ordered.keys():
        value = all_themes_ordered[k]
        is_addon = False
        is_patch = True if k == settings.OVERLAY_ROOT else False

        for v in installed_themes.values():
            if set(value).issubset(set(v)):
                is_addon = True

        if not (is_addon or is_patch):
            installed_themes[k] = value

    if logging:
        dump(installed_themes)

    return installed_themes
开发者ID:bofm,项目名称:sublime-a-file-icon,代码行数:34,代码来源:themes.py


示例20: on_load

 def on_load(self, view):
     if not requirements_file(view):
         return
     syntax_file = "Packages/requirementstxt/requirementstxt.tmLanguage"
     if hasattr(sublime, "find_resources"):
         syntax_file = sublime.find_resources("requirementstxt.tmLanguage")[0]
     view.set_syntax_file(syntax_file)
开发者ID:playpauseandstop,项目名称:requirementstxt,代码行数:7,代码来源:requirements.py



注:本文中的sublime.find_resources函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sublime.get_clipboard函数代码示例发布时间:2022-05-27
下一篇:
Python sublime.expand_variables函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap