|
22 | 22 | import warnings |
23 | 23 | import json |
24 | 24 | import threading |
25 | | -from subprocess import Popen, PIPE |
| 25 | +from subprocess import Popen, PIPE, run |
| 26 | +import time |
26 | 27 | from collections import defaultdict |
27 | 28 |
|
28 | 29 | import termios |
@@ -779,3 +780,39 @@ def quit(self): |
779 | 780 | self.process.communicate() |
780 | 781 | finally: |
781 | 782 | timer_kill.cancel() |
| 783 | + |
| 784 | + |
| 785 | +@register_image_displayer("imv") |
| 786 | +class IMVImageDisplayer(ImageDisplayer): |
| 787 | + """Implementation of ImageDisplayer using imv |
| 788 | + add following line into rc.conf to make it work |
| 789 | + set preview_images_method imv |
| 790 | + """ |
| 791 | + is_initialized = False |
| 792 | + |
| 793 | + def __init__(self): |
| 794 | + self.process = None |
| 795 | + |
| 796 | + def initialize(self): |
| 797 | + """ start imv """ |
| 798 | + if (self.is_initialized and self.process.poll() is None |
| 799 | + and not self.process.stdin.closed): |
| 800 | + return |
| 801 | + |
| 802 | + self.process = Popen(['imv'], cwd=self.working_dir, stdin=PIPE, universal_newlines=True) |
| 803 | + self.is_initialized = True |
| 804 | + sleep(5) |
| 805 | + |
| 806 | + def draw(self, path, start_x, start_y, width, height): |
| 807 | + self.initialize() |
| 808 | + run(['imv-msg',str(self.process.pid),'close']) |
| 809 | + run(['imv-msg',str(self.process.pid),'open',path]) |
| 810 | + |
| 811 | + |
| 812 | + def clear(self, start_x, start_y, width, height): |
| 813 | + self.initialize() |
| 814 | + run(['imv-msg',str(self.process.pid),'close']) |
| 815 | + |
| 816 | + def quit(self): |
| 817 | + if self.is_initialized and self.process.poll() is None: |
| 818 | + self.process.terminate() |
0 commit comments