当前位置: 首页>>代码示例>>Python>>正文


Python sublime.Phantom方法代码示例

本文整理汇总了Python中sublime.Phantom方法的典型用法代码示例。如果您正苦于以下问题:Python sublime.Phantom方法的具体用法?Python sublime.Phantom怎么用?Python sublime.Phantom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sublime的用法示例。


在下文中一共展示了sublime.Phantom方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Phantom [as 别名]
def __init__(self, component: Union[span, div], view: sublime.View, region: sublime.Region, layout: int = sublime.LAYOUT_INLINE) -> None:
		super().__init__(component, view)
		self.cachedPhantom = None #type: Optional[sublime.Phantom]
		self.region = region
		self.layout = layout
		self.view = view

		self.set = sublime.PhantomSet(self.view)

		Phantom.id += 1

		# we use the region to track where we should place the new phantom so if text is inserted the phantom will be redrawn in the correct place
		self.region_id = 'phantom_{}'.format(Phantom.id)
		self.view.add_regions(self.region_id, [self.region], flags=sublime.DRAW_NO_FILL)
		self.update()
		_renderables_add.append(self) 
开发者ID:daveleroy,项目名称:sublime_debugger,代码行数:18,代码来源:render.py

示例2: show

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Phantom [as 别名]
def show(view, marker, as_phantom=False):
    "Displays Emmet abbreviation as a preview for given view"
    content = None
    buffer_id = view.buffer_id()

    try:
        content = format_snippet(marker.preview())
    except Exception as e:
        content = '<div class="error">%s</div>' % format_snippet(str(e))

    if content:
        if as_phantom:
            if buffer_id not in phantom_sets_by_buffer:
                phantom_set = sublime.PhantomSet(view, 'emmet')
                phantom_sets_by_buffer[buffer_id] = phantom_set
            else:
                phantom_set = phantom_sets_by_buffer[buffer_id]

            r = sublime.Region(marker.region.end(), marker.region.end())
            phantoms = [sublime.Phantom(r, phantom_content(content), sublime.LAYOUT_INLINE)]
            phantom_set.update(phantoms)
        elif not view.is_popup_visible() or previews_by_buffer.get(buffer_id, None) != marker.abbreviation:
            previews_by_buffer[buffer_id] = marker.abbreviation
            view.show_popup(popup_content(content), sublime.COOPERATE_WITH_AUTO_COMPLETE, marker.region.begin(), 400, 300) 
开发者ID:emmetio,项目名称:sublime-text-plugin,代码行数:26,代码来源:preview.py

示例3: handle_response

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Phantom [as 别名]
def handle_response(self, response: Optional[List[dict]]) -> None:
        color_infos = response if response else []
        phantoms = []
        for color_info in color_infos:
            color = color_info['color']
            red = color['red'] * 255
            green = color['green'] * 255
            blue = color['blue'] * 255
            alpha = color['alpha']

            content = """
            <style>html {{padding: 0}}</style>
            <div style='padding: 0.4em;
                        margin-top: 0.2em;
                        border: 1px solid color(var(--foreground) alpha(0.25));
                        background-color: rgba({}, {}, {}, {})'>
            </div>""".format(red, green, blue, alpha)

            range = Range.from_lsp(color_info['range'])
            region = range_to_region(range, self.view)

            phantoms.append(sublime.Phantom(region, content, sublime.LAYOUT_INLINE))

        self.phantom_set.update(phantoms) 
开发者ID:sublimelsp,项目名称:LSP,代码行数:26,代码来源:color.py

示例4: create_phantom

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Phantom [as 别名]
def create_phantom(self, view: sublime.View, diagnostic: Diagnostic) -> sublime.Phantom:
        region = range_to_region(diagnostic.range, view)
        line = "[{}] {}".format(diagnostic.source, diagnostic.message) if diagnostic.source else diagnostic.message
        message = "<p>" + "<br>".join(html.escape(line, quote=False) for line in line.splitlines()) + "</p>"

        additional_infos = "<br>".join([self.format_diagnostic_related_info(info) for info in diagnostic.related_info])
        severity = "error" if diagnostic.severity == DiagnosticSeverity.Error else "warning"
        content = message + "<p class='additional'>" + additional_infos + "</p>" if additional_infos else message
        markup = self.create_phantom_html(content, severity)
        return sublime.Phantom(
            region,
            markup,
            sublime.LAYOUT_BELOW,
            self.navigate
        )

    # TODO: share with hover? 
开发者ID:sublimelsp,项目名称:LSP,代码行数:19,代码来源:diagnostics.py

示例5: display_previews

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Phantom [as 别名]
def display_previews(view, previews, pt=-1, current_index=0):
    global phantom_sets_by_buffer
    buffer_id = view.buffer_id()

    if (
        buffer_id in phantom_sets_by_buffer
        and pt != phantom_sets_by_buffer[buffer_id][1]
    ):
        return

    preview_html, preview_regions = generate_previews(previews, current_index)
    on_navigate = get_on_navigate(view, previews, current_index, pt)
    view.add_regions(
        "cfml_method_preview",
        merge_regions(preview_regions),
        "source",
        flags=sublime.DRAW_NO_FILL,
    )

    phantom_set = sublime.PhantomSet(view, "cfml_method_preview")
    phantom_sets_by_buffer[buffer_id] = (phantom_set, pt)
    phantom = sublime.Phantom(
        view.line(pt), preview_html, sublime.LAYOUT_BLOCK, on_navigate
    )
    phantom_set.update([phantom]) 
开发者ID:jcberquist,项目名称:sublimetext-cfml,代码行数:27,代码来源:method_preview.py

示例6: render

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Phantom [as 别名]
def render(self) -> bool:
		regions = self.view.get_regions(self.region_id)
		if regions and (super().render() or not self.cachedPhantom):
			self.cachedPhantom = sublime.Phantom(regions[0], self.html, self.layout, self.on_navigate)
			self.set.update([self.cachedPhantom])
			return True
		return False 
开发者ID:daveleroy,项目名称:sublime_debugger,代码行数:9,代码来源:render.py

示例7: show_tag_preview

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Phantom [as 别名]
def show_tag_preview(view: sublime.View, pt: int, text: str, dest: int):
    "Displays given tag preview at `pt` location"
    buffer_id = view.buffer_id()
    if buffer_id not in phantoms_by_buffer:
        phantom_set = sublime.PhantomSet(view, phantom_key)
        phantoms_by_buffer[buffer_id] = phantom_set
    else:
        phantom_set = phantoms_by_buffer[buffer_id]

    r = sublime.Region(pt, pt)
    nav = lambda href: go_to_pos(view, int(href))
    phantoms = [sublime.Phantom(r, phantom_content(text, dest), sublime.LAYOUT_INLINE, on_navigate=nav)]
    phantom_set.update(phantoms) 
开发者ID:emmetio,项目名称:sublime-text-plugin,代码行数:15,代码来源:go_to_tag_pair.py

示例8: mark

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Phantom [as 别名]
def mark(self, view: sublime.View):
        "Marks tracker in given view"
        scope = emmet.get_settings('marker_scope', 'region.accent')
        mark_opt = sublime.DRAW_SOLID_UNDERLINE | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE
        view.erase_regions(ABBR_REGION_ID)
        view.add_regions(ABBR_REGION_ID, [self.region], scope, '', mark_opt)
        if self.forced:
            phantoms = [sublime.Phantom(self.region, forced_indicator('⋮>'), sublime.LAYOUT_INLINE)]
            if not self.forced_indicator:
                self.forced_indicator = sublime.PhantomSet(view, ABBR_REGION_ID)
            self.forced_indicator.update(phantoms) 
开发者ID:emmetio,项目名称:sublime-text-plugin,代码行数:13,代码来源:tracker.py

示例9: mark

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Phantom [as 别名]
def mark(editor: sublime.View, tracker: AbbreviationTracker):
    "Marks tracker in given view"
    scope = get_settings('marker_scope', 'region.accent')
    mark_opt = sublime.DRAW_SOLID_UNDERLINE | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE
    editor.erase_regions(ABBR_REGION_ID)
    editor.add_regions(ABBR_REGION_ID, [tracker.region], scope, '', mark_opt)
    if isinstance(tracker, AbbreviationTrackerValid) and tracker.forced:
        phantoms = [
            sublime.Phantom(tracker.region, forced_indicator('⋮>'), sublime.LAYOUT_INLINE)
        ]

        key = editor.id()
        if key not in _forced_indicator:
            _forced_indicator[key] = sublime.PhantomSet(editor, ABBR_REGION_ID)
        _forced_indicator[key].update(phantoms) 
开发者ID:emmetio,项目名称:sublime-text-plugin,代码行数:17,代码来源:abbreviation.py

示例10: _update_preview

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Phantom [as 别名]
def _update_preview(self, markdown_view):
        # if the buffer id is 0, that means that the markdown_view has been closed
        # This check is needed since a this function is used as a callback for when images
        # are loaded from the internet (ie. it could finish loading *after* the user
        # closes the markdown_view)
        if time.time() - self.last_update < DELAY / 1000:
            return

        if markdown_view.buffer_id() == 0:
            return

        self.last_update = time.time()

        total_region = sublime.Region(0, markdown_view.size())
        markdown = markdown_view.substr(total_region)

        preview_view = markdown_view.window().active_view_in_group(1)
        viewport_width = preview_view.viewport_extent()[0]

        basepath = os.path.dirname(markdown_view.file_name())
        html = markdown2html(
            markdown,
            basepath,
            partial(self._update_preview, markdown_view),
            resources,
            viewport_width,
        )

        self.phantom_sets[markdown_view.id()].update(
            [
                sublime.Phantom(
                    sublime.Region(0),
                    html,
                    sublime.LAYOUT_BLOCK,
                    lambda href: sublime.run_command("open_url", {"url": href}),
                )
            ]
        ) 
开发者ID:math2001,项目名称:MarkdownLivePreview,代码行数:40,代码来源:MarkdownLivePreview.py

示例11: run

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Phantom [as 别名]
def run(self, edit):
        if not view_is_suitable(self.view):
            return

        phantoms = []
        self.view.erase_phantoms("git-blame")
        # Before adding the phantom, see if the current phantom that is displayed is at the same spot at the selection
        if self.phantom_set.phantoms:
            phantom_exists = self.view.line(self.view.sel()[0]) == self.view.line(
                self.phantom_set.phantoms[0].region
            )
            if phantom_exists:
                self.phantom_set.update(phantoms)
                return

        for region in self.view.sel():
            line = self.view.line(region)
            (row, col) = self.view.rowcol(region.begin())
            full_path = self.view.file_name()

            try:
                blame_output = self.get_blame(int(row) + 1, full_path)
            except Exception as e:
                communicate_error(e)
                return

            sha, user, date, time = self.parse_blame(blame_output)

            phantom = sublime.Phantom(
                line,
                blame_phantom_html_template.format(
                    css=blame_phantom_css, sha=sha, user=user, date=date, time=time
                ),
                sublime.LAYOUT_BLOCK,
                self.on_phantom_close,
            )
            phantoms.append(phantom)
        self.phantom_set.update(phantoms) 
开发者ID:frou,项目名称:st3-gitblame,代码行数:40,代码来源:blame.py

示例12: show_preview

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Phantom [as 别名]
def show_preview(self, view: sublime.View, as_phantom=None):
        "Displays expanded preview of abbreviation in current tracker in given view"
        if not emmet.get_settings('abbreviation_preview', True):
            return

        content = None

        if as_phantom is None:
            # By default, display preview for CSS abbreviation as phantom to not
            # interfere with default autocomplete popup
            as_phantom = self.config and self.config['type'] == 'stylesheet'

        if not self.abbreviation:
            # No parsed abbreviation: empty region
            pass
        if 'error' in self.abbreviation:
            # Display error snippet
            err = self.abbreviation['error']
            snippet = html.escape( re.sub(r'\s+at\s\d+$', '', err['message']), False)
            content = '<div class="error pointer">%s</div><div class="error message">%s</div>' % (err['pointer'], snippet)
        elif self.forced or as_phantom or not self.abbreviation['simple']:
            snippet = self.abbreviation['preview']
            if self.config['type'] != 'stylesheet':
                if syntax.is_html(self.config['syntax']):
                    snippet = html_highlight.highlight(snippet)
                else:
                    snippet = html.escape(snippet, False)
                content = '<div class="markup-preview">%s</div>' % format_snippet(snippet)
            else:
                content = format_snippet(snippet)

        if not content:
            self.hide_preview(view)
            return

        if as_phantom:
            if not self._phantom_preview:
                self._phantom_preview = sublime.PhantomSet(view, ABBR_PREVIEW_ID)

            r = sublime.Region(self.region.end(), self.region.end())
            phantoms = [sublime.Phantom(r, preview_phantom_html(content), sublime.LAYOUT_INLINE)]
            self._phantom_preview.update(phantoms)
        else:
            self._has_popup_preview = True
            view.show_popup(
                preview_popup_html(content),
                flags=sublime.COOPERATE_WITH_AUTO_COMPLETE,
                location=self.region.begin(),
                max_width=400,
                max_height=300) 
开发者ID:emmetio,项目名称:sublime-text-plugin,代码行数:52,代码来源:tracker.py

示例13: run

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Phantom [as 别名]
def run(self, edit):
        if not view_is_suitable(self.view):
            return

        self.view.erase_phantoms(PHANTOM_KEY_ALL)
        phantoms = []

        # If they are currently shown, toggle them off and return.
        if self.view.settings().get(SETTING_PHANTOM_ALL_DISPLAYED, False):
            self.phantom_set.update(phantoms)
            self.view.settings().set(SETTING_PHANTOM_ALL_DISPLAYED, False)
            return

        try:
            blame_output = self.get_blame(self.view.file_name())
        except Exception as e:
            communicate_error(e)
            return

        for l in blame_output.splitlines():
            parsed = self.parse_blame(l)
            if not parsed:
                continue

            sha, author, date, time, line_number = parsed

            line_point = self.get_line_point(line_number - 1)
            phantom = sublime.Phantom(
                line_point,
                blame_all_phantom_html_template.format(
                    css=blame_all_phantom_css,
                    sha=sha,
                    user=self.format_name(author),
                    date=date,
                    time=time,
                ),
                sublime.LAYOUT_INLINE,
                self.on_phantom_close,
            )
            phantoms.append(phantom)

        self.phantom_set.update(phantoms)
        self.view.settings().set(SETTING_PHANTOM_ALL_DISPLAYED, True)
        # Bring the phantoms into view without the user needing to manually scroll left.
        self.view.set_viewport_position((0.0, self.view.viewport_position()[1])) 
开发者ID:frou,项目名称:st3-gitblame,代码行数:47,代码来源:blame_all.py

示例14: update

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Phantom [as 别名]
def update(self, new_phantoms):
        """Update the list of phantoms that exist in the text buffer with their current location."""

        regions = query_phantoms(self.view, [p.id for p in self.phantoms])
        for i in range(len(regions)):
            self.phantoms[i].region = regions[i]

        count = 0
        for p in new_phantoms:
            if not isinstance(p, Phantom):
                # Convert sublime.Phantom to mdpopups.Phantom
                p = Phantom(
                    p.region, p.content, p.layout,
                    md=False, css=None, on_navigate=p.on_navigate, wrapper_class=None,
                    template_vars=None, template_env_options=None, nl2br=False,
                    allow_code_wrap=False
                )
                new_phantoms[count] = p
            try:
                # Phantom already exists, copy the id from the current one
                idx = self.phantoms.index(p)
                p.id = self.phantoms[idx].id
            except ValueError:
                p.id = add_phantom(
                    self.view,
                    self.key,
                    p.region,
                    p.content,
                    p.layout,
                    p.md,
                    p.css,
                    p.on_navigate,
                    p.wrapper_class,
                    p.template_vars,
                    p.template_env_options,
                    p.nl2br,
                    p.allow_code_wrap
                )
            count += 1

        for p in self.phantoms:
            # if the region is -1, then it's already been deleted, no need to call erase
            if p not in new_phantoms and p.region != sublime.Region(-1):
                erase_phantom_by_id(self.view, p.id)

        self.phantoms = new_phantoms 
开发者ID:facelessuser,项目名称:sublime-markdown-popups,代码行数:48,代码来源:__init__.py


注:本文中的sublime.Phantom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。