示例#1
0
class BasePlot(_chaco.DataView):

    # Copy from chaco.plot
    # The title of the plot.
    title = _traits.Property()

    # Use delegates to expose the other PlotLabel attributes of the plot title
    title_text = _traits.Delegate("_title", prefix="text", modify=True)

    # The PlotLabel object that contains the title.
    _title = _traits.Instance(_chaco.PlotLabel)

    def __init__(self, *args, **kwargs):
        super(BasePlot, self).__init__(*args, **kwargs)
        self._init_title()

    def _init_title(self):
        self._title = _chaco.PlotLabel(font="swiss 16",
                                       visible=False,
                                       overlay_position="top",
                                       component=self)

    def __title_changed(self, old, new):
        self._overlay_change_helper(old, new)

    def _set_title(self, text):
        self._title.text = text
        if text.strip() != "":
            self._title.visible = True
        else:
            self._title.visible = False

    def _get_title(self):
        return self._title.text

    def get_plot_name(self):
        return self.plot_data.display_name

    def export_image(self, fname, size=sz_plot_img):
        """Save plot as png image."""
        # self.outer_bounds = list(size)
        # self.do_layout(force=True)
        gc = _chaco.PlotGraphicsContext(self.outer_bounds)
        gc.render_component(self)
        gc.save(fname, file_format=None)
示例#2
0
                         Range(0, 255, default[2]),
                         cols=3), **metadata)


# Special cases for the FileName and FilePrefix
vtk_file_name = traits.Trait(None, None, traits.Str, str, editor=FileEditor)
vtk_file_prefix = traits.Trait(None,
                               None,
                               traits.Str,
                               str,
                               editor=(FileEditor, {
                                   'truncate_ext': True
                               }))

# The Property class traits are delegated in the Actors.
vtk_property_delegate = traits.Delegate('property', modify=True)

_DISABLE_UPDATE = False


@contextmanager
def global_disable_update():
    '''Disable updating any traits automatically due to changes in VTK.

    Specifically, do not auto-update *any* objects due to the firing of a
    ModifiedEvent from within VTK. This basically can call `update_traits` on
    the object which can in turn fire off other callbacks.

    Use this sparingly when you REALLY need to disable updates.

    '''