[quote=ātitoā]
[quote=āC0D312ā]I still want to do some more playing around with the icons. For now, hereās an HTML ātagā icon: cl.ly/2M1x0e2g141X1Y1I1B3z
Might want to change it later, but thatās it so far.[/quote]
Looks good, Maybe we can add yet another package āGutterIconsā and collect there some nice similar polished icons for the different sizes and possible OS.
Providing an APi or something to use the icons, then other packages use these (if they whish) and the overall application will feel better.
Like 4 different linters using the same icons for displaying errors.[/quote]
I was just goofing around, but if someone else wanted to use gutter icons I coded a simple script called fancy_regions.py
[code]import sublime
from glob import glob
from os.path import exists, normpath, join, basename
REGION_STYLES = {
āsolidā: 0,
ānoneā: sublime.HIDDEN,
āoutlineā: sublime.DRAW_OUTLINED,
āunderlineā: sublime.DRAW_EMPTY_AS_OVERWRITE
}
class FancyRegions(object):
def init(self, view):
self.view = view
self.__icon_path = āFancyRegions/iconsā
self.__icons = ]
self.__icons_cached = False
def erase_regions(self, key):
"""
Erase regions
"""
self.view.erase_regions(key)
def add_outline_regions(self, key, regions, scope="text", icon="none", flags=0):
"""
Add outline regions
"""
self.add_regions(key=key, regions=regions, scope=scope, style="outline", flags=flags)
def add_underline_regions(self, key, regions, scope="text", icon="none", flags=0):
"""
Add underline regions
"""
self.add_regions(key=key, regions=regions, scope=scope, style="underline", flags=flags)
def add_hidden_regions(self, key, regions, scope="text", icon="none", flags=0):
"""
Add hidden regions
"""
self.add_regions(key=key, regions=regions, scope=scope, style="none", flags=flags)
def add_solid_regions(self, key, regions, scope="text", icon="none", flags=0):
"""
Add solid regions
"""
self.add_regions(key=key, regions=regions, scope=scope, style="solid", flags=flags)
def add_regions(self, key, regions, scope='text', style="solid", icon="none", flags=0):
"""
Add regions with defined styling to a view
"""
# Default flag settings
options = 0
# Check style type
if style in REGION_STYLES:
options |= REGION_STYLES[style]
# Convert regions suitable for underlining if style underline
if style == "underline":
regions = self.__underline(regions)
# Set additional flags if given
if flags:
options |= flags
# If icon is defined and exists, set the icon path
icon_path = ""
if icon != "" and icon != "none":
if self.view.line_height() < 16:
icon += "_small"
if exists(normpath(join(sublime.packages_path(), self.__icon_path, icon + ".png"))):
icon_path = "../%s/%s" % (self.__icon_path, icon)
# Apply region(s)
self.view.add_regions(
key,
regions,
scope,
icon_path,
options
)
@property
def icons(self):
"""
Get list of available icons in current icon path
"""
if self.__icons_cached:
return self.__icons:]
else:
if not self.index_icons():
return self.__icons:]
else:
return ]
@property
def icon_path(self):
"""
Return current path to icons (relative to Packages)
"""
return self.__icon_path
@icon_path.setter
def icon_path(self, path):
"""
Set current path to icons (relative to Packages)
"""
file_path = path.replace('\\', '/').strip('/')
full_path = normpath(join(sublime.packages_path(), file_path))
if exists(full_path):
self.__icon_path = file_path
self.index_icons()
def index_icons(self):
"""
Search for icons in current icon path and store results
"""
errors = False
self.__icons = ]
file_path = normpath(join(sublime.packages_path(), self.__icon_path))
if exists(file_path):
self.__icons = [basename(png).rstrip(".png") for png in glob(file_path + "/*.png")]
self.__icons_cached = True
else:
self.__icons = ]
self.__icons_cached = False
errors = True
return errors
def __underline(self, regions):
"""
Convert regions to individual empty regions for underlining
"""
new_regions = ]
for region in regions:
start = region.begin()
end = region.end()
while start < end:
new_regions.append(sublime.Region(start))
start += 1
return new_regions
[/code]
Allows you to do stuff like this: lets say you wanted to create an underlined region with the default scope and a custom icon found in the custom icon folder.
[code]
import sublime
from fancy_regions import FancyRegions
fancy = FancyRegions(sublime.active_window().active_view())
region_list = [sublime.Region(0, 6)]
fancy.add_underline_regions(ātest_regionā, region_list, icon=āsome_iconā)[/code]
It does common region types like solid, outline, underline, and it handles all of the custom icon stuff. You can even request a list of icons in the custom icon folder.
I could put this in a repository, but I am just not sure if anyone would actually use it or not. But I was just fooling around.