本文整理汇总了Python中sublime.load_resource方法的典型用法代码示例。如果您正苦于以下问题:Python sublime.load_resource方法的具体用法?Python sublime.load_resource怎么用?Python sublime.load_resource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sublime
的用法示例。
在下文中一共展示了sublime.load_resource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_scheme_fix
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import load_resource [as 别名]
def generate_scheme_fix(old_scheme, new_scheme_path):
"""Appends background-correction XML to a color scheme file"""
from os.path import join
from re import sub
UUID_REGEX = '[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}'
with open(join(packages_path(),current_directory(),'background_fix.xml')) as f:
xml = f.read()
scheme_data = load_resource(old_scheme) # only valid for ST3 API!
insertion_point = scheme_data.rfind("</array>")
new_scheme_data = scheme_data[:insertion_point] + xml + scheme_data[insertion_point:]
def uuid_gen(args):
from uuid import uuid4
return str(uuid4())
new_scheme_data = sub(UUID_REGEX, uuid_gen, new_scheme_data)
with open(new_scheme_path, "wb") as f:
f.write(new_scheme_data.encode("utf-8"))
示例2: detect_free_vars
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import load_resource [as 别名]
def detect_free_vars(self, code):
dfv_path = tempfile.mkstemp(suffix=".R")[1]
data = sublime.load_resource("Packages/R-Box/box/detect_free_vars.R")
with open(dfv_path, 'w') as f:
f.write(data.replace("\r\n", "\n"))
f.close()
result = self.rscript(
file=dfv_path,
stdin_text=code
).strip()
try:
os.unlink(dfv_path)
except Exception:
pass
return [s.strip() for s in result.split("\n")] if result else []
示例3: show_read_only_doc_view
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import load_resource [as 别名]
def show_read_only_doc_view(view, content, name, syntaxes, point=0):
"""Helper for creating read-only scratch view.
"""
view.run_command('requester_replace_view_text', {'text': content, 'point': point})
view.set_read_only(True)
view.set_scratch(True)
view.set_name(name)
# attempts to set first valid syntax for view without showing error pop-up
for syntax in syntaxes:
try:
sublime.load_resource(syntax)
except:
pass
else:
view.set_syntax_file(syntax)
return
示例4: detect_free_vars
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import load_resource [as 别名]
def detect_free_vars(self, code):
dfv_path = tempfile.mkstemp(suffix=".R")[1]
data = sublime.load_resource("Packages/R-IDE/ride/commands/detect_free_vars.R")
with open(dfv_path, 'w') as f:
f.write(data.replace("\r\n", "\n"))
f.close()
result = R(
file=dfv_path,
stdin_text=code
).strip()
try:
os.unlink(dfv_path)
except Exception:
pass
return [s.strip() for s in result.split("\n")] if result else []
示例5: show_notification
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import load_resource [as 别名]
def show_notification(view: sublime.View, source: str, message_type: int, message: str, titles: List[str],
on_navigate: Callable, on_hide: Callable) -> None:
stylesheet = sublime.load_resource("Packages/LSP/notification.css")
contents = message_content(source, message_type, message, titles)
mdpopups.show_popup(
view,
contents,
css=stylesheet,
md=False,
location=-1,
wrapper_class='notification',
max_width=800,
max_height=800,
on_navigate=on_navigate,
on_hide=on_hide
)
示例6: try_apply_theme
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import load_resource [as 别名]
def try_apply_theme(view, theme_path, tries=0):
""" Safly apply new theme as color_scheme. """
try:
sublime.load_resource(theme_path)
except Exception:
if tries >= 8:
print(
'GitSavvy: The theme {} is not ready to load. Maybe restart to get colored '
'highlights.'.format(theme_path)
)
return
delay = (pow(2, tries) - 1) * 10
sublime.set_timeout_async(lambda: try_apply_theme(view, theme_path, tries + 1), delay)
return
view.settings().set("color_scheme", theme_path)
示例7: _get_user_css
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import load_resource [as 别名]
def _get_user_css():
"""Get user CSS."""
css = None
user_css = _get_setting('mdpopups.user_css', DEFAULT_USER_CSS)
if user_css == OLD_DEFAULT_CSS:
user_css = DEFAULT_CSS
try:
css = clean_css(sublime.load_resource(user_css))
except Exception:
pass
return css if css else ''
##############################
# Markdown parsing
##############################
示例8: read_css
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import load_resource [as 别名]
def read_css(self, css):
"""Read the CSS file."""
try:
var = copy.copy(self.variables)
var.update(
{
'is_phantom': self.css_type == PHANTOM,
'is_popup': self.css_type == POPUP,
'is_sheet': self.css_type == SHEET
}
)
if css == OLD_DEFAULT_CSS:
css = DEFAULT_CSS
return self.env.from_string(
clean_css(sublime.load_resource(css))
).render(var=var, plugin=self.plugin_vars)
except Exception:
return ''
示例9: formatPopup
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import load_resource [as 别名]
def formatPopup(self, content, symbol, can_back=False):
if not isinstance(content, str):
return
content = decodeEntity(content)
parser = PopupHTMLParser(symbol, language, can_back)
try:
parser.feed(content)
except FinishError:
pass
content = parser.output
content = '<style>'+sublime.load_resource('Packages/' + package_name + '/style.css') + \
'</style><div id="outer"><div id="container">' + content + "</div></div>"
content = re.sub('<strong><code>([A-Z_]+)</code></strong>', '<strong><code><a class="constant" href="constant.\\1">\\1</a></code></strong>', content)
return content
示例10: set_color_scheme
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import load_resource [as 别名]
def set_color_scheme(view):
"""
Set color scheme for view
"""
color_scheme = "Packages/TerminalView/TerminalView.hidden-tmTheme"
# Check if user color scheme exists
try:
sublime.load_resource("Packages/User/TerminalView.hidden-tmTheme")
color_scheme = "Packages/User/TerminalView.hidden-tmTheme"
except:
pass
if view.settings().get('color_scheme') != color_scheme:
view.settings().set('color_scheme', color_scheme)
示例11: run
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import load_resource [as 别名]
def run(self, edit):
COMMANDS_HELP = sublime.load_resource('Packages/FileBrowser/shortcuts.md') if ST3 else ''
if not COMMANDS_HELP:
dest = dirname(__file__)
shortcuts = join(dest if dest != '.' else join(sublime.packages_path(), 'FileBrowser'), "shortcuts.md")
COMMANDS_HELP = open(shortcuts, "r").read()
self.view.erase(edit, Region(0, self.view.size()))
self.view.insert(edit, 0, COMMANDS_HELP)
self.view.sel().clear()
self.view.set_read_only(True)
# OTHER #############################################################
示例12: package_python_version
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import load_resource [as 别名]
def package_python_version(package):
try:
version = sublime.load_resource("Packages/{}/.python-version".format(package))
except FileNotFoundError:
version = "3.3"
return version
示例13: read_config
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import load_resource [as 别名]
def read_config(package, key, default=None):
try:
context = sublime.load_resource(
"Packages/{}/.package_reloader.json".format(package))
value = sublime.decode_value(context).get(key, default)
except Exception:
value = default
return value
示例14: plugin_loaded
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import load_resource [as 别名]
def plugin_loaded():
if sys.version_info >= (3, 8):
APR33 = os.path.join(sublime.packages_path(), "AutomaticPackageReloader33")
if not os.path.exists(APR33):
os.makedirs(APR33)
data = sublime.load_resource("Packages/AutomaticPackageReloader/py33/package_reloader.py")
with open(os.path.join(APR33, "package_reloader.py"), 'w') as f:
f.write(data.replace("\r\n", "\n"))
with open(os.path.join(APR33, ".package_reloader.json"), 'w') as f:
f.write("{\"dependencies\" : [\"AutomaticPackageReloader\"]}")
示例15: package_python_version
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import load_resource [as 别名]
def package_python_version(self, package):
if sublime.version() < '4000':
return "3.3"
try:
version = sublime.load_resource("Packages/{}/.python-version".format(package))
except FileNotFoundError:
version = "3.3"
return version