def get_installed():
log.message('Getting installed themes')
installed_res = sublime.find_resources(THEMES)
installed_themes = {}
for ires in installed_res:
installed_themes.setdefault(os.path.basename(os.path.dirname(ires)),
[]).append(os.path.basename(ires))
if PATCHES in installed_themes:
del installed_themes[PATCHES]
log.value(installed_themes)
return installed_themes
python类find_resources()的实例源码
def get_supported():
log.message('Getting supported themes')
installed_res = sublime.find_resources(THEMES)
supported_res = sublime.find_resources(SUPPORTED_THEMES)
supported = {}
for sres in supported_res:
pkg = os.path.basename(os.path.dirname(sres))
for ires in installed_res:
if pkg in ires:
supported.setdefault(pkg, []).append(os.path.basename(ires))
log.value(supported)
return supported
def get_customizable():
log("Getting the list of theme packages with customization support")
installed_themes = get_installed(logging=False)
customizable_themes = []
theme_res = sublime.find_resources(".supports-a-file-icon-customization")
for res in theme_res:
pkg = re.sub(PATTERN, "", res)
if pkg in installed_themes:
customizable_themes.append(pkg)
dump(customizable_themes)
return customizable_themes
def on_post_save(self, view):
file_path = view.file_name()
if not file_path.endswith(".py"):
return
file_base = os.path.basename(file_path)
if os.sep == "\\":
file_path = file_path.replace("\\", "/")
file_res = "Packages" + file_path[
file_path.find("/" + settings.PACKAGE_NAME):
]
if file_res in sublime.find_resources(file_base):
reload_plugin()
def get_missing(theme_package):
missing_icons = []
all_icons = sublime.find_resources("*.png")
package_icons = json.loads(sublime.load_resource("Packages/" +
settings.PACKAGE_NAME +
"/common/icons.json"))
theme_icons_path = get_path(theme_package)
theme_icons = [
os.path.basename(os.path.splitext(i)[0])
for i in all_icons if i.startswith(theme_icons_path)
]
for icon in package_icons:
if icon not in theme_icons:
missing_icons.append(icon)
return missing_icons
def collect_package_data(self):
block = DataBlock('Package data')
_, packages, _ = next(os.walk(sublime.packages_path()))
packages = list(packages)
_, _, files = next(os.walk(sublime.installed_packages_path()))
suffix = '.sublime-package'
files = [f[:-len(suffix)] for f in files if f.endswith(suffix)]
ignored_packages = sublime.load_settings('Preferences.sublime-settings').get('ignored_packages', [])
block.items.append(DataItem('installed packages', json.dumps(files)))
block.items.append(DataItem('packages', json.dumps(packages)))
block.items.append(DataItem('ignored packages', json.dumps(ignored_packages)))
if sublime.find_resources('Package Control.sublime-settings'):
pc_packages = sublime.load_settings('Package Control.sublime-settings').get('installed_packages', [])
block.items.append(DataItem('packages managed by Package Control', json.dumps(pc_packages)))
self.elements.append(block)
def scan_packages(help_list=None):
"""
Find all packages with a help index and load it, returning a dictionary of
the packages found. If a partial help dictionary is passed, only packages
it does not contain will be added.
"""
help_list = dict() if help_list is None else help_list
for index_file in sublime.find_resources("hyperhelp.json"):
pkg_name = path.split(index_file)[0].split("/")[1]
if pkg_name not in help_list:
result = _load_index(pkg_name, index_file)
if result is not None:
help_list[result.package] = result
return help_list
def get_installed_themes():
installed_res = sublime.find_resources('*.sublime-theme')
installed_themes = {}
for ires in installed_res:
installed_themes.setdefault(os.path.basename(os.path.dirname(ires)),
[]).append(os.path.basename(ires))
if 'zpatches' in installed_themes:
del installed_themes['zpatches']
return installed_themes
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
def get_path(package_name):
package_path = "Packages/" + package_name
for res in sublime.find_resources("file_type_default.png"):
if res.startswith(package_path):
return os.path.dirname(res)
return False
def initialize_ProgressBar( self, view ):
#??? Text ???#
self.popUp_Label_InProgress = "PROGRESS:"
self.popUp_Label_Complete = "COMPLETE!"
#??? Progress Tracking ???#
self.maxPercent = 100
self.updateFrequency = 50 # In Milliseconds
#??? Dimensions ???#
self.popupWidth = 500
self.popupMaxHeight = 500
self.progressBar_Height = 21
#??? Colors ???#
self.progressBar_Incomplete_Color = "#0B121A"
self.progressBar_Complete_Color = "#57BB80"
self.progressBar_Progress_Color = "#5A91BC"
self.progressBar_BorderColor = "#000000"
self.popupCSS = sublime.load_resource( sublime.find_resources( "ProgressBarDemo_ProgressBar.css" )[ 0 ] )
self.progressBar_Width = int( float( self.popupWidth * 0.8 ) )
self.progressPercent = 0
mdpopups.show_popup(
view, # view
"", # content
True, # markdown
self.popupCSS, # css
0, # flags
-1, # location
self.popupWidth, # width
self.popupMaxHeight # height
)
def __init__(self, window, data_key, command, working_dir, title=None, syntax=None, panel=False, console=None, target=None):
self.target = target
if target == 'point' and console is None:
console = window.active_view()
# If a panel has been requested then create one and show it,
# otherwise create a new buffer, and set its caption:
#
if console is not None:
self.console = console
else:
if panel is True:
self.console = window.get_output_panel('ShellCommand')
window.run_command('show_panel', {'panel': 'output.ShellCommand'})
else:
self.console = window.new_file()
caption = title if title else '*ShellCommand Output*'
self.console.set_name(caption)
# Indicate that this buffer is a scratch buffer:
#
self.console.set_scratch(True)
self.console.set_read_only(True)
# Set the syntax for the output:
#
if syntax is not None:
resources = sublime.find_resources(syntax + '.tmLanguage')
self.console.set_syntax_file(resources[0])
# Set a flag on the view that we can use in key bindings:
#
settings = self.console.settings()
settings.set(data_key, True)
# Also, save the command and working directory for later,
# since we may need to refresh the panel/window:
#
data = {
'command': command,
'working_dir': working_dir
}
settings.set(data_key + '_data', data)