Skip to content

Commit

Permalink
Merge pull request #363 from astrofrog/fix-vispy-dev
Browse files Browse the repository at this point in the history
Fix compatibility with developer version of vispy
  • Loading branch information
astrofrog authored Nov 24, 2020
2 parents 2062488 + 6b12e0a commit 939c436
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
51 changes: 42 additions & 9 deletions glue_vispy_viewers/compat/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from vispy.gloo import (TextureAtlas, IndexBuffer, VertexBuffer)
from vispy.gloo import context
from vispy.gloo.wrappers import _check_valid
from vispy.ext.six import string_types
from vispy.util.fonts import _load_glyph
from vispy.visuals.transforms import STTransform
from vispy.color import ColorArray
Expand Down Expand Up @@ -75,7 +74,7 @@ def slop(self):
return self._spread // self.ratio

def __getitem__(self, char):
if not (isinstance(char, string_types) and len(char) == 1):
if not (isinstance(char, str) and len(char) == 1):
raise TypeError('index must be a 1-character string')
if char not in self._glyphs:
self._load_char(char)
Expand All @@ -89,7 +88,7 @@ def _load_char(self, char):
char : str
A single character to be represented.
"""
assert isinstance(char, string_types) and len(char) == 1
assert isinstance(char, str) and len(char) == 1
assert char not in self._glyphs
# load new glyph data from font
_load_glyph(self._font, char, self._glyphs)
Expand Down Expand Up @@ -126,7 +125,7 @@ class FontManager(object):
# or let TextureFont use a TextureAtlas for each context
def __init__(self, method='cpu'):
self._fonts = {}
if not isinstance(method, string_types) or \
if not isinstance(method, str) or \
method not in ('cpu', 'gpu'):
raise ValueError('method must be "cpu" or "gpu", got %s (%s)'
% (method, type(method)))
Expand Down Expand Up @@ -414,7 +413,10 @@ def __init__(self, text=None, color='black', bold=False,
# Init font handling stuff
# _font_manager is a temporary solution to use global mananger
self._font_manager = font_manager or FontManager(method=method)
self._font = self._font_manager.get_font(face, bold, italic)
self._face = face
self._bold = bold
self._italic = italic
self._update_font()
self._vertices = None
self._color_vbo = None
self._anchors = (anchor_x, anchor_y)
Expand All @@ -438,7 +440,7 @@ def text(self):
@text.setter
def text(self, text):
if isinstance(text, list):
assert all(isinstance(t, string_types) for t in text)
assert all(isinstance(t, str) for t in text)
if text is None:
text = []
self._text = text
Expand Down Expand Up @@ -519,7 +521,7 @@ def _prepare_draw(self, view):
return False
if self._vertices is None:
text = self.text
if isinstance(text, string_types):
if isinstance(text, str):
text = [text]
n_char = sum(len(t) for t in text)
# we delay creating vertices because it requires a context,
Expand All @@ -539,7 +541,7 @@ def _prepare_draw(self, view):
if self._pos_changed:
# now we promote pos to the proper shape (attribute)
text = self.text
if not isinstance(text, string_types):
if not isinstance(text, str):
repeats = [4 * len(t) for t in text]
text = ''.join(text)
else:
Expand Down Expand Up @@ -567,7 +569,7 @@ def _prepare_draw(self, view):
if self._color_changed:
# now we promote color to the proper shape (varying)
text = self.text
if not isinstance(text, string_types):
if not isinstance(text, str):
repeats = [4 * len(t) for t in text]
text = ''.join(text)
else:
Expand Down Expand Up @@ -606,6 +608,37 @@ def _prepare_transforms(self, view):
def _compute_bounds(self, axis, view):
return self._pos[:, axis].min(), self._pos[:, axis].max()

@property
def face(self):
return self._face

@face.setter
def face(self, value):
self._face = value
self._update_font()

@property
def bold(self):
return self._bold

@bold.setter
def bold(self, value):
self._bold = value
self._update_font()

@property
def italic(self):
return self._italic

@italic.setter
def italic(self, value):
self._italic = value
self._update_font()

def _update_font(self):
self._font = self._font_manager.get_font(self._face, self._bold, self._italic)
self.update()


class SDFRendererCPU(object):
"""Render SDFs using the CPU."""
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ changedir =
deps =
PyQt5==5.14
dev: glue-core @ git+https://github.com/glue-viz/glue
dev: vispy @ git+https://github.com/vispy/vispy
extras =
test: test
commands =
Expand Down

0 comments on commit 939c436

Please sign in to comment.