Python sublime 模块,LAYOUT_BLOCK 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用sublime.LAYOUT_BLOCK

项目:Sublime-minihtml-Preview    作者:ehuss    | 项目源码 | 文件源码
def on_modified_async(self):
        output_id = self.view.settings().get('minihtml_preview_output_view_id')
        output_view = next(view for view in self.view.window().views()
            if view.id() == output_id)
        content = self.view.substr(sublime.Region(0, self.view.size()))

        buffer_id = output_view.buffer_id()
        if buffer_id in self.phantom_sets:
            ps = self.phantom_sets[buffer_id]
        else:
            ps = sublime.PhantomSet(output_view, 'minihtml_preview_phantom')
            self.phantom_sets[buffer_id] = ps

        p = sublime.Phantom(sublime.Region(0), content,
                            sublime.LAYOUT_BLOCK, _on_navigate)
        ps.update([p])
项目:MarkdownLivePreview    作者:math2001    | 项目源码 | 文件源码
def show_html(md_view, preview):
    global windows_phantom_set
    html = markdown2html(get_view_content(md_view), os.path.dirname(md_view.file_name()), md_view.settings().get('color_scheme'))

    phantom_set = windows_phantom_set.setdefault(preview.window().id(),
                                             sublime.PhantomSet(preview, 'markdown_live_preview'))
    phantom_set.update([sublime.Phantom(sublime.Region(0), html, sublime.LAYOUT_BLOCK,
                                    lambda href: sublime.run_command('open_url', {'url': href}))])

    # lambda href: sublime.run_command('open_url', {'url': href})
    # get the "ratio" of the markdown view's position.
    # 0 < y < 1
    y = md_view.text_to_layout(md_view.sel()[0].begin())[1] / md_view.layout_extent()[1]
    # set the vector (position) for the preview
    vector = [0, y * preview.layout_extent()[1]]
    # remove half of the viewport_extent.y to center it on the screen (verticaly)
    vector[1] -= preview.viewport_extent()[1] / 2
    # make sure the minimum is 0
    vector[1] = 0 if vector[1] < 0 else vector[1]
    # the hide the first line
    vector[1] += preview.line_height()
    preview.set_viewport_position(vector, animate=False)
项目:imagepaste    作者:robinchenyu    | 项目源码 | 文件源码
def run(self, edit):
        print("run phantom")
        view = self.view
        dirname = os.path.dirname(__file__)
        for tp, line in self.get_line():
            m=re.search(r'!\[([^\]]*)\]\(([^)]*)\)', line)
            if m:
                name, file1 = m.group(1), m.group(2)
                message = ""
                file2 = os.path.join(os.path.dirname(view.file_name()), file1)
                # print("%s = %s" % (name, file1))
                region = tp

                command = ['/usr/bin/python3', os.path.join(dirname, 'bin/imageutil.py'), 'size']
                command.append(file2)

                out = self.run_command(" ".join(command))
                widthstr, heightstr = out.split(',')
                # with Image.open(file2) as im:
                # print("file: %s with size: %d %d" % (file1, im.width, im.height))
                message = '''<body>
                <img width="%s" height="%s" src="file://%s"></img>
                </body>''' % (widthstr, heightstr, file2)
                if len(name) == 0:
                    name = file1

        # phantom = sublime.Phantom(region, messag e, sublime.LAYOUT_BLOCK)
                print("message %s" % message)
                if not self.displayed:
                    self.view.add_phantom(name, region, message, sublime.LAYOUT_BLOCK)
                else:
                    self.view.erase_phantoms(name)
        # self.phantom_set.update([phantom])
        # view.show_popup('<img src="file://c://msys64/home/chenyu/diary/diary/diary8.jpg">')
        self.displayed = not self.displayed
项目:RemoteTree    作者:deNULL    | 项目源码 | 文件源码
def rebuild_phantom(self):
        html = '''<body id="tree">
<style>
    body {
        font-size: 12px;
        line-height: 16px;
    }
    .file a, .dir a {
        display: block;
        padding-left: 4px;
    }
    .dir a {
        padding-top: 1px;
        padding-bottom: 2px;
    }
    .dir a {
        text-decoration: none;
    }
    .file.active {
        background-color: color(var(--background) blend(var(--foreground) 80%));
        border-radius: 3px;
    }
    .file span {
        font-size: 7px; 
    }
    .file a {
        text-decoration: none;
        color: var(--foreground);
    }
</style>''' + ''.join(self.render_subtree(self.tree, [])) + '</body>'
        self.phantom = sublime.Phantom(sublime.Region(0), html, sublime.LAYOUT_BLOCK, on_navigate=self.on_click)
        self.phantom_set.update([self.phantom])
项目:QuickEdit    作者:gamcoh    | 项目源码 | 文件源码
def formatCodeVar(self):
        reportHtml = '<div class="var">'
        reportHtml += '<p class="files"><em>in this file, at line : </em><a href="line-{line}">{line}</a></p>'.format(line=self.varsFound['line'])

        # format the code for a better syntax coloration
        reportHtmlContent = re.sub('(\$|=|new|->)', '<p class="monokai_red">\g<1></p>', self.varsFound['code'])
        reportHtmlContent = re.sub('(class)(;|,)', '<p class="monokai_blue">\g<1></p>\g<2>', reportHtmlContent)
        reportHtmlContent = re.sub('(\[| |=|>)([0-9]+)(\]| |;|,)', '\g<1><p class="monokai_int">\g<2></p>\g<3>', reportHtmlContent)
        # print(reportHtmlContent)

        reportHtml += reportHtmlContent
        reportHtml += '</div>'

        # load the font
        settings = sublime.load_settings('Preferences.sublime-settings')
        font = ''
        if settings.has('font_face'):
            font = '"%s",' % settings.get('font_face')

        # getting the errors that occured during the execution
        htmlErrors = ''
        if self.QuickEditSetting.get('show_errors'):
            for e in self.aErrors:
                htmlErrors += '<p class="error">• %s</p>' % e

            # if errors were found 
            if htmlErrors:
                htmlErrors = '<div class="panel panel-error mt20"><div class="panel-header">Errors that occured during the search</div><div class="panel-body">{errors}</div></div>'.format(errors=htmlErrors)

        # load css, and html ui
        css = sublime.load_resource('Packages/QuickEdit/resources/ui.css').replace('@@font', font)
        html = sublime.load_resource('Packages/QuickEdit/resources/report.html').format(css=css, html=reportHtml, errors=htmlErrors)

        self.view.erase_phantoms('quick_edit')
        self.view.add_phantom("quick_edit", self.view.sel()[0], html, sublime.LAYOUT_BLOCK, self.click)

    ########################################################################
    # format the code for the functions
    ########################################################################
项目:QuickEdit    作者:gamcoh    | 项目源码 | 文件源码
def formatCodeFunction(self):
        try:
            reportHtml = '<div class="function">'
            reportHtml += '<p class="files"><em>in this file, at line : </em><a href="line-{line}">{line}</a></p>'.format(line=self.functionFound['line'])

            # format the code for a better syntax coloration
            reportHtmlContent = re.sub('(private|public|protected)', '<p class="monokai_red">\g<1></p>', self.functionFound['code'])
            reportHtmlContent = re.sub('(function)', '<p class="monokai_blue"><em>\g<1></em></p>', reportHtmlContent)
            reportHtmlContent = re.sub('(function</em></p> )([a-zA-Z0-9_]+)( ?\()', '\g<1><p class="monokai_green">\g<2></p>\g<3>', reportHtmlContent)
            reportHtmlContent = re.sub('(function</em></p> <p class="monokai_green">[a-zA-Z0-9_]+</p>\()(.*)(\))', '\g<1><p class="monokai_params"><em>\g<2></em></p>\g<3>', reportHtmlContent)
            reportHtmlContent = re.sub('(\{.*)(\$)(.*\})', '\g<1><p class="monokai_red"><em>\g<2></em></p>\g<3>', reportHtmlContent)
            reportHtmlContent = re.sub('(\{.*)(->)(.*\})', '\g<1><p class="monokai_red"><em>\g<2></em></p>\g<3>', reportHtmlContent)
            reportHtmlContent = re.sub('(\{.*)(return)(.*\})', '\g<1><p class="monokai_red"><em>\g<2></em></p>\g<3>', reportHtmlContent)

            reportHtml += reportHtmlContent
            reportHtml += '</div>'
        except AttributeError:
            print('[Errno 2] Function not found')

        # load the font
        settings = sublime.load_settings('Preferences.sublime-settings')
        font = ''
        if settings.has('font_face'):
            font = '"%s",' % settings.get('font_face')

        # getting the errors that occured during the execution
        htmlErrors = ''
        if self.QuickEditSetting.get('show_errors'):
            for e in self.aErrors:
                htmlErrors += '<p class="error">• %s</p>' % e

            # if errors were found 
            if htmlErrors:
                htmlErrors = '<div class="panel panel-error mt20"><div class="panel-header">Errors that occured during the search</div><div class="panel-body">{errors}</div></div>'.format(errors=htmlErrors)

        # load css, and html ui
        css = sublime.load_resource('Packages/QuickEdit/resources/ui.css').replace('@@font', font)
        html = sublime.load_resource('Packages/QuickEdit/resources/report.html').format(css=css, html=reportHtml, errors=htmlErrors)

        self.view.erase_phantoms('quick_edit')
        self.view.add_phantom("quick_edit", self.view.sel()[0], html, sublime.LAYOUT_BLOCK, self.click)


    ########################################################################
    # format the css code in order to show 
    # it in a phantom report modal
    ########################################################################
项目:QuickEdit    作者:gamcoh    | 项目源码 | 文件源码
def formatCode(self):
        reportHtml=""
        for code in self.stylesFound:
            # adding the file name
            if code['file'] == 'self':
                reportHtml += '<p class="files"><em>in this file</em>, at line : <a href="line-{line}">{line}</a></p>'.format(line=code['line'])
            else:
                reportHtml += '<p class="files"><em>in %s</em></p>' % (code['file'])

            reportHtml += code['code']

        # no css style were found
        if not reportHtml:
            self.aErrors.append('Could not find any css style')

        # put minihtml tag and class name 
        # in order to stylize the css
        reportHtml = re.sub(r'\n|\t', '', reportHtml)

        # found all the pre-brackets code
        pre_brackets = re.findall(r'([#a-zA-Z0-9_. ]+)(\s?){', reportHtml)
        for r in pre_brackets:
            # for all the pre-brackets code we search for tag names, id,
            # and class name in order to format them
            formattedCode = re.sub(r'([#a-zA-Z0-9_.-]+)', '<p class="tagName">\g<1></p>', r[0])
            formattedCode = re.sub(r'<p class="tagName">(\.[a-zA-Z0-9_.-]+)<\/p>', '<p class="className">\g<1></p>', formattedCode)
            formattedCode = re.sub(r'<p class="tagName">(#[#a-zA-Z0-9_-]+)<\/p>', '<p class="idName">\g<1></p>', formattedCode)
            reportHtml = re.sub(r[0], formattedCode, reportHtml)

        reportHtml = re.sub(r'}', '<p class="className"><b>}</b></p>', reportHtml)
        reportHtml = re.sub(r'([a-zA-Z_-]+): ([a-zA-Z0-9_-]+);', '<p class="attributs"><em>\g<1></em>: <b>\g<2></b>;</p>', reportHtml)

        # load the font
        settings = sublime.load_settings('Preferences.sublime-settings')
        font = ''
        if settings.has('font_face'):
            font = '"%s",' % settings.get('font_face')

        # getting the errors that occured during the execution
        htmlErrors = ''
        if self.QuickEditSetting.get('show_errors'):
            for e in self.aErrors:
                htmlErrors += '<p class="error">• %s</p>' % e

            # if errors were found 
            if htmlErrors:
                htmlErrors = '<div class="panel panel-error mt20"><div class="panel-header">Errors that occured during the search</div><div class="panel-body">{errors}</div></div>'.format(errors=htmlErrors)

        # load css, and html ui
        css = sublime.load_resource('Packages/QuickEdit/resources/ui.css').replace('@@font', font)
        html = sublime.load_resource('Packages/QuickEdit/resources/report.html').format(css=css, html=reportHtml, errors=htmlErrors)

        self.view.erase_phantoms('quick_edit')
        self.view.add_phantom("quick_edit", self.view.sel()[0], html, sublime.LAYOUT_BLOCK, self.click)


    # when the user click on one of the phantom action