summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2018-01-25 14:51:18 +0100
committerEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2018-01-25 14:51:18 +0100
commit8076c1d0945f2233f773690a29d14e9db84607cb (patch)
tree46e6795f45510d55fc1fba0a8d1f6931ea1b1301
parent5feb71870676d9e0a49c480d7cb5e60b1e4f5d28 (diff)
downloadpoezio-8076c1d0945f2233f773690a29d14e9db84607cb.tar.gz
poezio-8076c1d0945f2233f773690a29d14e9db84607cb.tar.bz2
poezio-8076c1d0945f2233f773690a29d14e9db84607cb.tar.xz
poezio-8076c1d0945f2233f773690a29d14e9db84607cb.zip
Fix blinking in ImageWin.
Also display the border according to the theme.
-rw-r--r--poezio/windows/image.py24
1 files 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):