#
# Plot.py -- Plotting function for Ginga viewer.
#
# This is open-source software licensed under a BSD license.
# Please see the file LICENSE.txt for details.
#
import matplotlib
# GTK3Cairo backend is slow to redraw compared to GTK3Agg!
# matplotlib.use('GTK3Cairo')
# from matplotlib.backends.backend_gtk3cairo import (FigureCanvasGTK3Cairo
#                                                    as FigureCanvas)  # noqa
matplotlib.use('GTK3Agg')
from matplotlib.backends.backend_gtk3agg import (FigureCanvasGTK3Agg
                                                 as FigureCanvas)  # noqa
from ginga.gtk3w import Widgets  # noqa


class PlotWidget(Widgets.WidgetBase):

    def __init__(self, plot, width=500, height=500):
        super(PlotWidget, self).__init__()

        self.widget = FigureCanvas(plot.get_figure())
        self.plot = plot
        self.logger = plot.logger

        self.widget.set_size_request(width, height)
        self.widget.show_all()

    def set_plot(self, plot):
        self.plot = plot
        self.logger = plot.logger
        self.logger.debug("set_plot called")

    def configure_window(self, wd, ht):
        self.logger.debug("canvas resized to %dx%d" % (wd, ht))
        fig = self.plot.get_figure()
        fig.set_size_inches(float(wd) / fig.dpi, float(ht) / fig.dpi)

# END
