本文整理汇总了Python中sublime.load_resource函数的典型用法代码示例。如果您正苦于以下问题:Python load_resource函数的具体用法?Python load_resource怎么用?Python load_resource使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load_resource函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: decodeEntity
def decodeEntity(xml, category='iso'):
global entities
if not isinstance(xml, str):
return xml
if entities[category]:
forward, reverse = entities[category]
else:
if category == 'iso':
forward = sublime.decode_value(sublime.load_resource('Packages/' + package_name + '/IsoEntities.json'))
elif category == 'html':
forward = sublime.decode_value(sublime.load_resource('Packages/' + package_name + '/HtmlEntities.json'))
reverse = dict((v, k) for k, v in forward.items())
entities[category] = (forward, reverse)
def parseEntity(match):
entity = match.group(1)
try:
if entity.isdigit():
return reverse[int(entity)]
else:
return chr(forward[entity])
except:
return match.group(0)
xml = re.sub('&([a-zA-Z0-9]+);', parseEntity, xml)
return xml
示例2: parseJSON
def parseJSON(self, package, name, ext):
if ST2:
path = os.path.join(sublime.packages_path(), package, name + '.' + ext)
if not os.path.isfile(path):
path = os.path.join(sublime.packages_path(), package, 'Default.' + ext)
if not os.path.isfile(path):
return None
return None
with codecs.open(path) as f:
content = self.removeComments(f.read())
if f is not None:
f.close()
try:
parsedJSON = json.loads(content, cls=ConcatJSONDecoder)
except (ValueError):
return None
return parsedJSON[0]
else:
try:
resource = sublime.load_resource('Packages/' + package + '/' + name + '.' + ext)
except (IOError):
try:
resource = sublime.load_resource('Packages/' + package + '/Default.' + ext)
except (IOError):
return None
return None
return sublime.decode_value(resource)
示例3: __init__
def __init__(self):
self.client_id = "141"
self.client_secret = "4*ic:5WfF;LxE534"
self.settings = tools.load_settings("LaTeXing", mendeley_oauth_token="", mendeley_internal_cite_key=False, mendeley_cite_key_pattern="{Author}{year}")
# Load map
self.map = sublime.decode_value(sublime.load_resource("Packages/LaTeXing/latexing/api/mendeley.map"))
# bibtex: zotero type
self.type_map = self.map["types"]
# bibtex: zotero field
self.field_map = self.map["fields"]
# Check for user maps
try:
self.user_map = sublime.decode_value(sublime.load_resource("Packages/User/LaTeXing/mendeley.map"))
self.type_map.update(self.user_map["types"] if "types" in self.user_map else {})
self.field_map.update(self.user_map["fields"] if "fields" in self.user_map else {})
except:
pass
self.status = "Ok"
self.items = []
self.items_no_key = {}
示例4: apply_syntax
def apply_syntax(self, syntax, view):
# print("Applying", syntax)
try:
sublime.load_resource(syntax)
except Exception:
print("Syntax file not found", syntax)
view.set_syntax_file(syntax)
示例5: get_code
def get_code(self, type, namespace, filename):
code = ''
file_name = "%s.tmpl" % type
isIOError = False
tmpl_dir = 'Packages/' + self.PACKAGE_NAME + '/' + self.TMLP_DIR + '/'
user_tmpl_dir = 'Packages/User/' + \
self.PACKAGE_NAME + '/' + self.TMLP_DIR + '/'
self.user_tmpl_path = os.path.join(user_tmpl_dir, file_name)
self.tmpl_path = os.path.join(tmpl_dir, file_name)
try:
code = sublime.load_resource(self.user_tmpl_path)
except IOError:
try:
code = sublime.load_resource(self.tmpl_path)
except IOError:
isIOError = True
if isIOError:
sublime.message_dialog('[Warning] No such file: ' + self.tmpl_path
+ ' or ' + self.user_tmpl_path)
code = code.replace('${namespace}', namespace)
code = code.replace('${classname}', filename)
return code
示例6: plugin_loaded
def plugin_loaded():
global settings
global KWDB
global SETTINGS_FILE
global INDENT_STYLE
global INDENT_STYLE_ALLMAN
global INDENT_STYLE_K_AND_R
SETTINGS_FILE = 'LSL.sublime-settings'
INDENT_STYLE = os.path.join(sublime.packages_path(), 'User', 'LSL_indent_style.tmPreferences')
INDENT_STYLE_ALLMAN = sublime.load_resource('Packages/LSL/metadata/LSL_indent_style.tmPreferences.allman')
INDENT_STYLE_K_AND_R = sublime.load_resource('Packages/LSL/metadata/LSL_indent_style.tmPreferences.k_and_r')
try:
settings = sublime.load_settings(SETTINGS_FILE)
except Exception as e:
print(e)
if not os.path.exists(INDENT_STYLE):
with open(INDENT_STYLE, mode='w', newline='\n') as file:
file.write(INDENT_STYLE_ALLMAN)
kwdbAsString = sublime.load_resource('Packages/LSL/other/kwdb/kwdb.xml')
KWDB = etree.fromstring(kwdbAsString)
示例7: set_syntax
def set_syntax(self, name):
# the default settings file uses / to separate the syntax name parts, but if the user
# is on windows, that might not work right. And if the user happens to be on Mac/Linux but
# is using rules that were written on windows, the same thing will happen. So let's
# be intelligent about this and replace / and \ with os.path.sep to get to
# a reasonable starting point
path = os.path.dirname(name)
name = os.path.basename(name)
if not path:
path = name
file_name = name + ".tmLanguage"
new_syntax = sublime_format_path("/".join(["Packages", path, file_name]))
current_syntax = self.view.settings().get("syntax")
# only set the syntax if it's different
if new_syntax != current_syntax:
# let's make sure it exists first!
try:
sublime.load_resource(new_syntax)
self.view.set_syntax_file(new_syntax)
log("Syntax set to " + name + " using " + new_syntax)
except:
log("Syntax file for " + name + " does not exist at " + new_syntax)
示例8: __init__
def __init__(self):
self.client_key = "40af22476e380eadfef5"
self.client_secret = "ec5cfba3fb9fb063d0d4"
self.settings = tools.load_settings("LaTeXing",
zotero_user_key="",
zotero_user_id="",
zotero_cite_key_pattern="{Author}{year}"
)
# Load map
self.map = sublime.decode_value(sublime.load_resource("Packages/LaTeXing/latexing/api/zotero.map"))
# bibtex: zotero type
self.type_map = self.map["types"]
# bibtex: zotero field
self.field_map = self.map["fields"]
# Check for user maps
try:
self.user_map = sublime.decode_value(sublime.load_resource("Packages/User/LaTeXing/zotero.map"))
self.type_map.update(self.user_map["types"] if "types" in self.user_map else {})
self.field_map.update(self.user_map["fields"] if "fields" in self.user_map else {})
except:
pass
self.status = "Ok"
self.items = []
self.items_no_key = {}
示例9: fixup_docs_action
def fixup_docs_action(self):
docs_path = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
'NeoVintageous/res/doc')
def set_utf8_encoding_save_and_close(view):
view.run_command('set_encoding', {'encoding': 'utf-8'})
view.run_command('save')
view.close()
for f in os.listdir(docs_path):
if f.endswith('.txt'):
resource = 'Packages/NeoVintageous/res/doc/%s' % f
try:
load_resource(resource)
except Exception as e:
print(' Error: ' + resource + ' ' + str(e))
file = packages_path() + '/NeoVintageous/res/doc/%s' % f
print(' Fixing resource encoding for \'{}\''.format(file))
view = self.window.open_file(file)
set_timeout_async(functools.partial(set_utf8_encoding_save_and_close, view), 200)
示例10: reload_settings
def reload_settings(self):
self.settings_default = sublime.decode_value(sublime.load_resource(from_package('Mediawiker.sublime-settings')))
self.settings = sublime.load_settings('Mediawiker.sublime-settings')
try:
self.settings_user = sublime.decode_value(sublime.load_resource(from_package('Mediawiker.sublime-settings', name='User')))
except IOError:
self.settings_user = {}
示例11: copy_filename_root_changed
def copy_filename_root_changed(self,root):
self.root_folder = root
self.saveRoot(root,
sublime.load_resource('Packages/FileActions/Side Bar.sublime-menu'),
os.path.join(sublime.packages_path(), 'User', 'FileActions', 'Side Bar.sublime-menu'))
self.saveRoot(root,
sublime.load_resource('Packages/FileActions/Context.sublime-menu'),
os.path.join(sublime.packages_path(), 'User', 'FileActions', 'Context.sublime-menu'))
示例12: run
def run(self, edit, view_name):
popup_max_width = 600
popup_max_height = 600
css = sublime.load_resource("Packages/GitSavvy/popups/style.css")
html = sublime.load_resource("Packages/GitSavvy/popups/" + view_name + ".html").format(
css=css, super_key=util.super_key
)
self.view.show_popup(html, 0, -1, popup_max_width, popup_max_height)
示例13: _plugin_loaded
def _plugin_loaded():
global PREVIEW_TEMPLATE, PAGINATION_TEMPLATE
root_path = "Packages/" + utils.get_plugin_name() + "/templates"
PREVIEW_TEMPLATE = sublime.load_resource(
root_path + "/method_preview.html"
).replace("\r", "")
PAGINATION_TEMPLATE = sublime.load_resource(root_path + "/pagination.html").replace(
"\r", ""
)
示例14: exists_resource
def exists_resource(resource_file_path):
if sublime.version() >= "3000":
try:
sublime.load_resource(resource_file_path)
return True
except:
return False
else:
filename = os.path.join(os.path.dirname(sublime.packages_path()), resource_file_path)
return os.path.isfile(filename)
示例15: _get_user_css
def _get_user_css():
"""Get user css."""
css = None
user_css = _get_setting('mdpopups.user_css', DEFAULT_USER_CSS)
try:
css = clean_css(sublime.load_resource(user_css))
except Exception:
css = clean_css(sublime.load_resource(DEFAULT_CSS))
return css if css else ''