How to use highlight_regions method in Testify

Best Python code snippet using Testify_python

highlight_manager.py

Source:highlight_manager.py Github

copy

Full Screen

1import sublime2from .color_scheme_manager import *3from .minimal_region_set import *4class HighlightManager():5 def __init__(self, view, settings):6 self.view = view7 self.key_base = "regex_highlight_"8 self.settings = settings9 def highlight(self):10 color_dictionary, colors = self._get_highlight_dictionary()11 if self.settings.get("prompt_new_color_scheme"):12 color_scheme_manager = ColorSchemeManager("User/ColorScheme")13 color_scheme_manager.create_user_custom_theme(colors)14 self._highlight_regex(color_dictionary)15 def _get_highlight_dictionary(self):16 view = self.view17 settings = self.settings18 regex_list = settings.get("regex")19 region_set = MinimalRegionSet()20 region_dictionary = {}21 color_dictionary = {}22 colors = []23 self.solid_underline_regions = []24 self.squiggly_underline_regions = []25 self.stippled_underline_regions = []26 # Find all entries that match a pattern27 for obj in regex_list:28 if "syntax" in obj:29 applicable = False30 view_syntax = view.settings().get('syntax')31 if view_syntax:32 for syn in obj["syntax"]:33 if syn in view_syntax:34 applicable = True35 if not applicable:36 continue37 if "syntax_ignore" in obj:38 applicable = True39 view_syntax = view.settings().get('syntax')40 if view_syntax:41 for syn in obj["syntax_ignore"]:42 if syn in view_syntax:43 applicable = False44 if not applicable:45 continue46 if "pattern" in obj and len(obj["pattern"]) > 0:47 if "ignore_case" in obj and obj["ignore_case"]:48 regions = view.find_all(obj["pattern"], sublime.IGNORECASE)49 else:50 regions = view.find_all(obj["pattern"])51 elif "pattern_scope" in obj:52 regions = view.find_by_selector(obj["pattern_scope"])53 else:54 continue55 if "ignored_scopes" in obj:56 scope = obj["ignored_scopes"].lower();57 regions = [region for region in regions if len([sel_scope for sel_scope in view.scope_name(region.begin()).split() if sel_scope in scope]) == 0]58 if "color_scope" in obj:59 color = obj["color_scope"]60 elif "color" in obj:61 colors.append(obj["color"])62 color = "highlight.color." + obj["color"].upper()63 else:64 color = "entity.name.class"65 solid_underline = False66 squiggly_underline = False67 stippled_underline = False68 if "underline" in obj and obj["underline"]:69 solid_underline = True70 if int(sublime.version()) >= 3014:71 if "underline_style" in obj:72 if obj["underline_style"].lower() == "squiggly":73 squiggly_underline = True74 solid_underline = False75 elif obj["underline_style"].lower() == "stippled":76 stippled_underline = True77 solid_underline = False78 if len(regions) > 0:79 region_set.add_all(regions)80 for region in regions:81 if solid_underline:82 self.solid_underline_regions.append(region)83 elif squiggly_underline:84 self.squiggly_underline_regions.append(region)85 elif stippled_underline:86 self.stippled_underline_regions.append(region)87 region_dictionary[str(region)] = color88 # Create a dictionary of only the entries to be colored,89 # and their associated color90 regions = region_set.to_array()91 for region in regions:92 color = region_dictionary[str(region)]93 if color in color_dictionary:94 color_dictionary[color].append(region)95 else:96 color_dictionary[color] = [region]97 return color_dictionary, colors98 def _highlight_regex(self, color_dictionary):99 version = int(sublime.version())100 view = self.view101 key_base = self.key_base102 counter = 0103 for color, regions in color_dictionary.items():104 highlight_regions = []105 solid_underline_regions = []106 stippled_underline_regions = []107 squiggly_underline_regions = []108 for region in regions:109 if region in self.solid_underline_regions:110 if version < 3014:111 highlight_regions += self._underline(region)112 else:113 solid_underline_regions.append(region)114 elif region in self.squiggly_underline_regions:115 squiggly_underline_regions.append(region)116 elif region in self.stippled_underline_regions:117 stippled_underline_regions.append(region)118 else:119 highlight_regions.append(region)120 if len(highlight_regions) > 0:121 view.add_regions(key_base + str(counter),122 highlight_regions, color, "",123 sublime.DRAW_EMPTY_AS_OVERWRITE)124 counter += 1125 if version >= 3014:126 underline_standard = sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE127 if len(solid_underline_regions) > 0:128 view.add_regions(key_base + str(counter),129 solid_underline_regions, color, "",130 underline_standard | sublime.DRAW_SOLID_UNDERLINE)131 counter += 1132 if len(squiggly_underline_regions) > 0:133 view.add_regions(key_base + str(counter),134 squiggly_underline_regions, color, "",135 underline_standard | sublime.DRAW_SQUIGGLY_UNDERLINE)136 counter += 1137 if len(stippled_underline_regions) > 0:138 view.add_regions(key_base + str(counter),139 stippled_underline_regions, color, "",140 underline_standard | sublime.DRAW_STIPPLED_UNDERLINE)141 counter += 1142 def _underline(self, region):143 ret_regions = []144 begin = region.begin()145 end = region.end()146 while begin < end:147 ret_regions.append(sublime.Region(begin, begin))148 begin += 1149 return ret_regions150 def remove_highlight(self):151 view = self.view152 key_base = self.key_base153 counter = 0154 while True:155 temp = view.get_regions(key_base + str(counter))156 if len(temp) > 0:157 view.erase_regions(key_base + str(counter))158 counter += 1159 else:...

Full Screen

Full Screen

highlights.py

Source:highlights.py Github

copy

Full Screen

1from coolbox.utilities import (2 opener, ReadBed,3 Interval, IntervalTree,4 rgb2hex,5 get_logger, GenomeRange,6 to_gr7)8from .base import Coverage9log = get_logger(__name__)10class _Highlights(object):11 DEFAULT_COLOR = '#ff5d0f'12 def fetch_data(self, gr: GenomeRange, **kwargs):13 gr = to_gr(gr)14 if gr.chrom not in list(self.interval_tree):15 gr.change_chrom_names()16 return [17 (region.begin, region.end, region.data)18 for region in sorted(19 self.interval_tree[gr.chrom][gr.start - 10000 : gr.end + 10000]20 )21 ]22 def plot(self, ax, gr: GenomeRange, **kwargs):23 regions = self.fetch_data(gr, **kwargs)24 for (start, end, color) in regions:25 if self.properties['color'] != 'bed_rgb':26 color = self.properties['color']27 if type(color) is not str:28 color = rgb2hex(*color)29 ax.axvspan(start, end, color=color, alpha=self.properties['alpha'])30 if self.properties['border_line'] == 'yes':31 # plot border line32 ymin, ymax = ax.get_ylim()33 ax.vlines([start, end], ymin, ymax,34 linestyle=self.properties['border_line_style'],35 linewidth=self.properties['border_line_width'],36 color=self.properties['border_line_color'],37 alpha=self.properties['border_line_alpha'])38class HighLightsFromFile(Coverage, _Highlights):39 """40 High light regions coverage, read the regions from the file.41 Parameters42 ----------43 file_ : str44 Path to the file.45 color : str, optional46 High light region color,47 use 'bed_rgb' for specify color from the file, default 'bed_rgb'.48 alpha : float, optional49 High light region alpha value, default 0.1.50 border_line : bool, optional51 Plot border line or not, default True.52 border_line_style : str, optional53 Border line style, default 'dashed'.54 border_line_width : float, optional55 Border line width, default 1.0.56 border_line_color : str, optional57 Border line color, default '#000000'58 border_line_alpha : float, optional59 Border line alpha value, default 0.860 name : str, optional61 The name of thr Coverage.62 """63 def __init__(self, file_, **kwargs):64 properties_dict = {65 "file": file_,66 "color": "bed_rgb",67 "alpha": 0.1,68 "border_line": True,69 "border_line_style": "dashed",70 "border_line_width": 0,71 "border_line_color": "#000000",72 "border_line_alpha": 0.8,73 }74 properties_dict.update(kwargs)75 super().__init__(properties_dict)76 self.interval_tree = self.__process_bed()77 def __process_bed(self):78 bed = ReadBed(opener(self.properties['file']))79 if self.properties['color'] == 'bed_rgb' and bed.file_type not in ['bed12', 'bed9']:80 log.warning("*WARNING* Color set to 'bed_rgb', but bed file does not have the rgb field. The color has "81 "been set to {}".format(HighLights.DEFAULT_COLOR))82 self.properties['color'] = HighLights.DEFAULT_COLOR83 interval_tree = {}84 for intval in bed:85 if intval.chromosome not in interval_tree:86 interval_tree[intval.chromosome] = IntervalTree()87 if self.properties['color'] == 'bed_rgb':88 color = intval.rgb89 else:90 color = self.properties['color']91 interval_tree[intval.chromosome].add(Interval(intval.start, intval.end, color))92 return interval_tree93class HighLights(Coverage, _Highlights):94 """95 High light region.96 Parameters97 ----------98 highlight_regions : list of {str, tuple}99 A list of regions for highlights, region can be expressed as a tuple or string.100 region tuple like:101 [('chr1', 100000, 120000), ('chr2', 130000, 150000)]102 region string format: `chr:start-end` like:103 ['chr1:100000-120000', 'chr2:130000-150000'].104 color : str, optional105 High light region color, default HighLights.DEFAULT_COLOR.106 alpha : float, optional107 High light region alpha value, default 0.5108 border_line : bool, optional109 Plot border line or not, default True.110 border_line_style : str, optional111 Border line style, default 'dashed'112 border_line_width : float, optional113 Border line width, default 1.0114 border_line_color : str, optional115 Border line color, default '#000000'116 border_line_alpha : float, optional117 Border line alpha value, default 0.8118 name : str, optional119 The name of thr Coverage.120 """121 DEFAULT_COLOR = "#ff9c9c"122 def __init__(self, highlight_regions, **kwargs):123 if not isinstance(highlight_regions, list):124 highlight_regions = [highlight_regions]125 properties_dict = {126 "highlight_regions": highlight_regions,127 "color": HighLights.DEFAULT_COLOR,128 "alpha": 0.25,129 "border_line": True,130 "border_line_style": "dashed",131 "border_line_width": 0,132 "border_line_color": "#000000",133 "border_line_alpha": 0.8,134 }135 properties_dict.update(kwargs)136 super().__init__(properties_dict)137 self.interval_tree = self.__intervaltree_from_list(self.properties['highlight_regions'])138 # TODO may be duplicate of vlines's method139 def __intervaltree_from_list(self, region_list):140 from intervaltree import IntervalTree141 itree = {}142 for r in region_list:143 if isinstance(r, str):144 grange = GenomeRange(r)145 elif isinstance(r, tuple):146 grange = GenomeRange(r[0], r[1], r[2])147 elif isinstance(r, GenomeRange):148 grange = r149 else:150 raise ValueError("position must be a tuple or string.")151 chr_ = grange.chrom152 itree.setdefault(chr_, IntervalTree())153 itree[chr_][grange.start:grange.end + 1] = grange...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testify automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful