我正在写一个 sublime text 3 插件。我有一张图片(PNG 格式)。我想将此图像加载到 Sublime Text 3 自定义输出面板中,以将其显示为预览。有谁知道如何做到这一点,甚至可能吗?
最佳答案
似乎输出面板只能呈现 unicode 字符,因此无法将图像放在那里(也许有一天)。
替代解决方案
正如我在评论中所说,您可以划分布局并使用选项卡来显示图像,如果需要,还可以使用选项卡来显示文本。我制作了这个简单的示例插件和两个屏幕截图:
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)
之前的布局:
之后的布局:
请记住,这是一个简单的示例,它不会关闭打开的选项卡,也不会恢复布局等。
关于python - 是否可以在 Sublime Text 3 输出面板中显示图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30520381/