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
评论列表
文章目录