def __init__(self, **traits): # This will be overriden if 'text' is provided as a trait, but it # must be initialized if not self._text = [ [] ] # Initialize internal tracking variables self.reset() super(TextField, self).__init__(**traits) if self.metrics is None: self.metrics = font_metrics_provider() # Initialize border/bg colors self.__style_changed() # If this can't be editted and no width has been set, make sure # that is wide enough to display the text. if not self.can_edit and self.width == 0: x, y, width, height = self.metrics.get_text_extent(self.text) offset = 2*self._style.text_offset self.width = width + offset
def _compute_cell_sizes(self): if not self._cache_valid: gc = font_metrics_provider() max_w = 0 max_h = 0 min_l = 0 min_d = 0 for text in self.string_array.ravel(): gc.set_font(self.font) l, d, w, h = gc.get_text_extent(text) if -l+w > max_w: max_w = -l+w if -d+h > max_h: max_h = -d+h if l < min_l: min_l = l if d < min_d: min_d = d self._cached_cell_size = (max_w, max_h) self._text_offset = array([-min_l, -min_d]) self._cache_valid = True return