How to use the enable.font_metrics_provider.font_metrics_provider function in enable

To help you get started, we’ve selected a few enable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github enthought / chaco / chaco / plot_label.py View on Github external
outside = True
            if "inside" in orientation:
                tmp = orientation.split()
                tmp.remove("inside")
                orientation = tmp[0]
                outside = False
            elif "outside" in orientation:
                tmp = orientation.split()
                tmp.remove("outside")
                orientation = tmp[0]

            if orientation in ("left", "right"):
                self.y = self.component.y
                self.height = self.component.height
                if not outside:
                    gc = font_metrics_provider()
                    self.width = self._label.get_bounding_box(gc)[0]
                if orientation == "left":
                    if outside:
                        self.x = self.component.outer_x
                        self.width = self.component.padding_left
                    else:
                        self.outer_x = self.component.x
                elif orientation == "right":
                    if outside:
                        self.x = self.component.x2 + 1
                        self.width = self.component.padding_right
                    else:
                        self.x = self.component.x2 - self.outer_width
            elif orientation in ("bottom", "top"):
                self.x = self.component.x
                self.width = self.component.width
github enthought / chaco / chaco / plot_label.py View on Github external
def get_preferred_size(self):
        """ Returns the label's preferred size.

        Overrides PlotComponent.
        """
        dummy_gc = font_metrics_provider()
        size = self._label.get_bounding_box(dummy_gc)
        return size
github NMGRL / pychron / pychron / pipeline / plot / overlays / spectrum.py View on Github external
def _get_plateau_label(self, x1, x2, y):

        if self.layout_needed or not self.plateau_label:
            p = self.plateau_label
        else:
            comp = self.component
            x = x1 + (x2 - x1) * 0.5

            dummy_gc = font_metrics_provider()
            l = Label(text=self.info_txt)
            w, h = l.get_bounding_box(dummy_gc)

            xa = x + w / 2.
            hjustify = 'center'
            if xa > comp.x2:
                d = xa - comp.x2
                x -= d
            elif x - w / 2. < comp.x:
                x = comp.x + 5
                hjustify = 'left'

            x = max(comp.x, x)
            p = PlotLabel(text=self.info_txt,
                          font=self.label_font,
                          # font='modern {}'.format(self.label_font_size),
github enthought / chaco / chaco / tooltip.py View on Github external
def __font_metrics_provider_default(self):
        return font_metrics_provider()
github enthought / enable / enable / tools / toolbars / viewport_toolbar.py View on Github external
def _do_layout(self, component=None):
        if component is None:
            component = self.component

        if component is not None:
            self.x = component.x
            # FIXME: Adding 2 to the self.y because there is a tiny gap
            # at the top of the toolbar where components from the block
            # canvas show through.
            self.y = component.y2 - self.toolbar_height + 2
            self.height = self.toolbar_height
            self.width = component.width

        metrics = font_metrics_provider()
        if self.order == "right-to-left":
            last_button_position = self.width - self.button_spacing
            for b in self.components:
                x, y, w, h = metrics.get_text_extent(b.label)
                b.width = w + 2*b.label_padding
                b.x = last_button_position - b.width
                b.y = self.button_vposition
                last_button_position -= b.width + self.button_spacing*2
        else:
            last_button_position = 0
            for b in self.components:
                x, y, w, h = metrics.get_text_extent(b.label)
                b.width = w + 2*b.label_padding
                b.x = self.button_spacing + last_button_position
                b.y = self.button_vposition
                last_button_position += b.width + self.button_spacing*2
github enthought / chaco / chaco / scales_tick_generator.py View on Github external
def get_ticks_and_labels(self, data_low, data_high, bounds_low, bounds_high,
                             orientation = "h"):
        # TODO: add support for Interval
        # TODO: add support for vertical labels
        metrics = font_metrics_provider()
        if self.font is not None and hasattr(metrics, "set_font"):
            metrics.set_font(self.font)
        test_str = "0123456789-+"
        charsize = metrics.get_full_text_extent(test_str)[0] / len(test_str)
        numchars = (bounds_high - bounds_low) / charsize
        tmp = zip(*self.scale.labels(data_low, data_high, numlabels=8, char_width=numchars))
        # Check to make sure we actually have labels/ticks to show before
        # unpacking the return tuple into (tick_array, labels).
        if len(tmp) == 0:
            return array([]), []
        else:
            return array(tmp[0]), tmp[1]
github enthought / enable / enable / text_field.py View on Github external
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
github enthought / chaco / chaco / plot_label.py View on Github external
if outside:
                        self.x = self.component.outer_x
                        self.width = self.component.padding_left
                    else:
                        self.outer_x = self.component.x
                elif orientation == "right":
                    if outside:
                        self.x = self.component.x2 + 1
                        self.width = self.component.padding_right
                    else:
                        self.x = self.component.x2 - self.outer_width
            elif orientation in ("bottom", "top"):
                self.x = self.component.x
                self.width = self.component.width
                if not outside:
                    gc = font_metrics_provider()
                    self.height = self._label.get_bounding_box(gc)[1]
                if orientation == "bottom":
                    if outside:
                        self.y = self.component.outer_y
                        self.height = self.component.padding_bottom
                    else:
                        self.outer_y = self.component.y
                elif orientation == "top":
                    if outside:
                        self.y = self.component.y2 + 1
                        self.height = self.component.padding_top
                    else:
                        self.y = self.component.y2 - self.outer_height
            else:
                # Leave the position alone
                pass
github NMGRL / pychron / pychron / graph / explicit_legend.py View on Github external
# Create the labels
        labels = [self._create_label(text) for text in label_names]

        # For the legend title
        if self.title_at_top:
            labels.insert(0, self._create_label(self.title))
            label_names.insert(0, 'Legend Label')
            visible_plots.insert(0, None)
        else:
            labels.append(self._create_label(self.title))
            label_names.append(self.title)
            visible_plots.append(None)

        # We need a dummy GC in order to get font metrics
        dummy_gc = font_metrics_provider()
        label_sizes = array([label.get_width_height(dummy_gc) for label in labels])

        if len(label_sizes) > 0:
            max_label_width = max(label_sizes[:, 0])
            total_label_height = sum(label_sizes[:, 1]) + (len(label_sizes) - 1) * self.line_spacing
        else:
            max_label_width = 0
            total_label_height = 0

        legend_width = max_label_width + self.icon_spacing + self.icon_bounds[0] \
                       + self.hpadding + 2 * self.border_padding
        legend_height = total_label_height + self.vpadding + 2 * self.border_padding

        self._cached_labels = labels
        self._cached_label_sizes = label_sizes
        self._cached_label_positions = zeros_like(label_sizes)