Search code examples
pythonsublimetext3sublime-text-plugin

Is it possible to show image in Sublime Text 3 output panel?


I am writing a sublime text 3 plugin. I have an image (PNG format). I would like to load this image into Sublime Text 3 custom output panel, to show it as a preview. Does anyone have idea how to do this or is it even possible?


Solution

  • Seems that the output panel can only render unicode characters, making it impossible to put an image in there (maybe one day).

    Alternate solution

    As I said in my comment, you can divide the layout and use a tab to show the image, and maybe also a tab to show text if needed. I've made this simple example plugin and two screenshots:

    import sublime, sublime_plugin
    
    class Example(sublime_plugin.WindowCommand):
        def run(self):
            """Divide layout"""
            self.window.set_layout({
                "cols": [0.0, 0.4, 1.0],
                "rows": [0.0, 0.6, 1.0],
                "cells": [[0, 0, 2, 1], [0, 1, 1, 2], [1, 1, 2, 2]]
                })
    
            """Open image in group 1"""
            self.window.focus_group(1)
            self.window.open_file('/home/sergio/Escritorio/images/logo.png')
    
            """Show output/info in group 2"""
            self.window.focus_group(2)
            v = self.window.new_file()
            self.window.run_command('insert', {'characters': ("Plugin output:\n"
                "-Stackoverflow\n"
                "-is\n"
                "-very\n"
                "-cool\n"
                "-the\n"
                "-best\n"
                "-websites\n"
                "-of\n"
                "-the\n"
                "-world\n")})
            v.show_at_center(0)
    
            self.window.focus_group(0)
    

    Layout before:

    Layout before

    Layout after:

    Layout after

    Have in mind that this is a simple example, and it doesn't close the opened tabs, nor restore the layout, etc.