From 8076c1d0945f2233f773690a29d14e9db84607cb Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 25 Jan 2018 14:51:18 +0100 Subject: Fix blinking in ImageWin. Also display the border according to the theme. --- poezio/windows/image.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/poezio/windows/image.py b/poezio/windows/image.py index aa9d9c3d..6077ef46 100644 --- a/poezio/windows/image.py +++ b/poezio/windows/image.py @@ -12,7 +12,7 @@ except ImportError: HAS_PIL = False from poezio.windows.base_wins import Win -from poezio.theming import to_curses_attr +from poezio.theming import get_theme, to_curses_attr from poezio.xhtml import _parse_css_color from poezio.config import config @@ -37,21 +37,29 @@ class ImageWin(Win): self._display_avatar(width, height) def refresh(self, data): - self._win.clear() - if data is None or not HAS_PIL: - self._image = None - self._display_border() - else: + self._win.erase() + if data is not None and HAS_PIL: image_file = BytesIO(data) - self._image = Image.open(image_file).convert('RGB') - self._display_avatar(self.width, self.height) + try: + image = Image.open(image_file) + except OSError: + self._display_border() + else: + self._image = image.convert('RGB') + self._display_avatar(self.width, self.height) + else: + self._display_border() self._refresh() def _display_border(self): + self._image = None + attribute = to_curses_attr(get_theme().COLOR_VERTICAL_SEPARATOR) + self._win.attron(attribute) self._win.border(curses.ACS_VLINE, curses.ACS_VLINE, curses.ACS_HLINE, curses.ACS_HLINE, curses.ACS_ULCORNER, curses.ACS_URCORNER, curses.ACS_LLCORNER, curses.ACS_LRCORNER) + self._win.attroff(attribute) @staticmethod def _compute_size(image_size, width: int, height: int): -- cgit v1.2.3