Python sublime.load_binary_resource() Examples

The following are 8 code examples of sublime.load_binary_resource(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sublime , or try the search function .
Example #1
Source File: bbcode.py    From SublimeKSP with GNU General Public License v3.0 6 votes vote down vote up
def run(self, *args, **kwargs):
        view = sublime.active_window().active_view()

        #settings = sublime.load_settings('KSP.sublime-settings')
        #scheme_file = settings.get('color_scheme', 'Packages/SublimeKSP/KScript Light.tmTheme')
        scheme_file = 'Packages/SublimeKSP/KScript Light.tmTheme'
        plist = readPlistFromBytes(sublime.load_binary_resource(scheme_file))

        result = ['[pre]']
        start, end = view.sel()[0].a, view.sel()[0].b
        if start == end:
            start, end = 0, view.size()
        for a, b, scopes in get_ranges(view.scope_name(i) for i in range(start, end)):
            result.append(self.apply_style(scopes, plist, view.substr(sublime.Region(start+a, start+b))))
        result.append('[/pre]')
        sublime.set_clipboard(''.join(result)) 
Example #2
Source File: file.py    From GitSavvy with MIT License 6 votes vote down vote up
def handle_tm_language_files():
    # type: () -> None
    syntax_files = sublime.find_resources("*.tmLanguage")
    for syntax_file in syntax_files:
        try:
            resource = sublime.load_binary_resource(syntax_file)
        except Exception:
            print("GitSavvy: could not load {}".format(syntax_file))
            continue

        try:
            extensions = plistlib.readPlistFromBytes(resource).get("fileTypes", [])
        except Exception:
            print("GitSavvy: could not parse {}".format(syntax_file))
            continue

        for extension in extensions:
            syntax_file_map[extension].append(syntax_file) 
Example #3
Source File: minihtml.py    From sublimetext-cfml with MIT License 6 votes vote down vote up
def get_color_scheme(view=None):
    if int(sublime.version()) > 3153:
        return view.style()

    setting = sublime.load_settings("Preferences.sublime-settings").get("color_scheme")
    color_scheme_bytes = sublime.load_binary_resource(setting)
    color_scheme = {"scopes": []}
    for setting in plistlib.readPlistFromBytes(color_scheme_bytes)["settings"]:
        if "scope" in setting:
            this_scope = {"scope": setting["scope"], "style": {}}
            for key in ["foreground", "background"]:
                if key in setting["settings"]:
                    this_scope["style"][key] = setting["settings"][key]
            for key in ["italic", "bold"]:
                this_scope["style"][key] = (
                    "fontStyle" in setting["settings"]
                    and key in setting["settings"]["fontStyle"].lower()
                )
            color_scheme["scopes"].append(this_scope)
        elif "settings" in setting:
            for key in ["foreground", "background"]:
                if key in setting["settings"]:
                    color_scheme[key] = setting["settings"][key]
    return color_scheme 
Example #4
Source File: image.py    From sublime_debugger with MIT License 5 votes vote down vote up
def _data_image_png_b64_png_from_resource(path: str) -> str:
	png_data = sublime.load_binary_resource(path)
	return "data:image/png;base64,{}".format(base64.b64encode(png_data).decode('ascii')) 
Example #5
Source File: __init__.py    From sublime-markdown-popups with MIT License 5 votes vote down vote up
def tint(img, color, opacity=255, height=None, width=None):
    """Tint the image."""

    if isinstance(img, str):
        try:
            img = sublime.load_binary_resource(img)
        except Exception:
            _log('Could not open binary file!')
            _debug(traceback.format_exc(), ERROR)
            return ''
    return imagetint.tint(img, color, opacity, height, width) 
Example #6
Source File: __init__.py    From sublime-markdown-popups with MIT License 5 votes vote down vote up
def tint_raw(img, color, opacity=255):
    """Tint the image."""

    if isinstance(img, str):
        try:
            img = sublime.load_binary_resource(img)
        except Exception:
            _log('Could not open binary file!')
            _debug(traceback.format_exc(), ERROR)
            return ''
    return imagetint.tint_raw(img, color, opacity) 
Example #7
Source File: st_color_scheme_matcher.py    From sublime-markdown-popups with MIT License 5 votes vote down vote up
def __init__(self, scheme_file, color_filter=None):
        """Initialize."""
        if color_filter is None:
            color_filter = self.filter
        self.color_scheme = scheme_file.replace('\\', '/')
        self.scheme_file = path.basename(self.color_scheme)

        if NEW_SCHEMES and scheme_file.endswith(('.sublime-color-scheme', '.hidden-color-scheme')):
            self.legacy = False
            self.scheme_obj = {
                'variables': {},
                GLOBAL_OPTIONS: {},
                'rules': []
            }
        else:
            try:
                content = sublime.load_binary_resource(sublime_format_path(self.color_scheme))
            except IOError:
                # Fallback if file was created manually and not yet found in resources
                with open(packages_path(self.color_scheme), 'rb') as f:
                    content = f.read()
            self.legacy = True
            self.convert_format(readPlistFromBytes(XML_COMMENT_RE.sub(b'', content)))
        self.overrides = []
        if NEW_SCHEMES:
            self.merge_overrides()
        self.scheme_file = scheme_file
        self.matched = {}
        self.variables = {}
        self.parse_scheme()
        self.scheme_obj = color_filter(self.scheme_obj)
        self.setup_matcher() 
Example #8
Source File: st_code_highlight.py    From sublime-markdown-popups with MIT License 4 votes vote down vote up
def set_view(self, src, lang):
        """Setup view for conversion."""

        # Get the output panel
        self.view = sublime.active_window().create_output_panel('mdpopups', unlisted=True)
        # Let all plugins no to leave this view alone
        self.view.settings().set('is_widget', True)
        # Don't translate anything.
        self.view.settings().set("translate_tabs_to_spaces", False)
        # Don't mess with my indenting Sublime!
        self.view.settings().set("auto_indent", False)
        # Insert into the view
        self.view.run_command('insert', {'characters': src})
        # Setup the proper syntax
        lang = lang.lower()
        user_map = sublime.load_settings('Preferences.sublime-settings').get('mdpopups.sublime_user_lang_map', {})
        keys = set(list(user_map.keys()) + list(lang_map.keys()))
        loaded = False
        for key in keys:
            v = lang_map.get(key, (tuple(), tuple()))
            user_v = user_map.get(key, (tuple(), tuple()))
            if lang in (tuple(user_v[0]) + v[0]):
                for l in (tuple(user_v[1]) + v[1]):
                    for ext in ST_LANGUAGES:
                        sytnax_file = 'Packages/%s%s' % (l, ext)
                        try:
                            sublime.load_binary_resource(sytnax_file)
                        except Exception:
                            continue
                        self.view.set_syntax_file(sytnax_file)
                        loaded = True
                        break
                    if loaded:
                        break
            if loaded:
                break
        if not loaded:
            # Default to plain text
            for ext in ST_LANGUAGES:
                # Just in case text one day switches to 'sublime-syntax'
                sytnax_file = 'Packages/Plain text%s' % ext
                try:
                    sublime.load_binary_resource(sytnax_file)
                except Exception:
                    continue
                self.view.set_syntax_file(sytnax_file)