# Path: osrefl/loaders/reduction/cmapmenu.py
# class CMapMenu(wx.Menu):
#     """
#     Menu tree binding to a list of colormaps.
#     """
#     def __init__(self, window,
#                  mapper=None, canvas=None, callback=None):
#         """
#         Define a context menu for selecting colormaps.
# 
#         Need a window to use as the event handler.
#         If mapper is defined, it will be updated with the new colormap.
#         If canvas is defined, it will update on idle.
#         """
#         wx.Menu.__init__(self)
# 
#         # OS X needs 16x16 icons; Windows and Linux can be longer
#         bar_length = 32 if not sys.platform in ['darwin'] else 16
#         bar_height = 16
#         self.mapper,self.canvas,self.callback = mapper,canvas,callback
#         self.selected = None
#         self.mapid = {}
#         for name in grouped_colormaps():
#             if name is None:
#                 self.AppendSeparator()
#             else:
#                 item = wx.MenuItem(self, wx.ID_ANY, name)
#                 map = cm.get_cmap(name)
#                 icon = colorbar_bitmap(map,bar_length,thickness=bar_height)
#                 item.SetBitmap(icon)
#                 self.AppendItem(item)
#                 window.Bind(wx.EVT_MENU,
#                             event_callback(self._OnSelect, name=name),
#                             id=item.GetId())
# 
#     def _OnSelect(self, event, name=None):
#         """
#         When selected, record the name, update the mapper and invoke the
#         callback.
#         """
#         self.selected = name
#         if self.mapper:
#             self.mapper.set_cmap(cm.get_cmap(name))
#         if self.canvas:
#             self.canvas.draw_idle()
#         if self.callback:
#             self.callback(name)


from pylab import imshow,cm,colorbar,hot,show,xlabel,ylabel,connect, plot, figure, draw, axis, gcf,legend
from numpy import ones, sum, arange, transpose, log
from matplotlib.widgets import  RectangleSelector
from colormap import change_colormap
from matplotlib.axis import XAxis, YAxis
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas
from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg
from matplotlib.font_manager import fontManager, FontProperties
from matplotlib.image import FigureImage
from matplotlib.figure import Figure
from matplotlib.pyplot import figure, get_fignums
from zoom_colorbar import zoom_colorbar
from osrefl.loaders.reduction.cmapmenu import CMapMenu
from matplotlib.cm import get_cmap
        from matplotlib.ticker import FormatStrFormatter, ScalarFormatter
import matplotlib.colors as colors
import wx
import matplotlib.cbook as cbook
import matplotlib

    def set_new_lower_color_limit(self, evt = None):
        current_uplim = self.fig.im.get_clim()[1]
        current_lowlim = self.fig.im.get_clim()[0]
        dlg = wx.TextEntryDialog(None, "Change lower limit of color map (currently %f)" % current_lowlim, defaultValue = "%f" % current_lowlim)
        if dlg.ShowModal() == wx.ID_OK:
            new_val = dlg.GetValue()
            xlab = self.fig.cb.get_xlabel()
            ylab = self.fig.cb.get_ylabel()
            self.fig.im.set_clim((float(new_val), current_uplim))
            self.fig.cb.set_xlabel(xlab)
            self.fig.cb.set_ylabel(ylab)
            self.fig.canvas.draw()
        dlg.Destroy()

    def OnContext(self, evt):
        print self.show_sliceplots
        mpl_x = evt.X
        mpl_y = self.fig.canvas.GetSize()[1] - evt.Y
        mpl_mouseevent = matplotlib.backend_bases.MouseEvent('button_press_event', self.canvas, mpl_x, mpl_y, button = 3)

        if (mpl_mouseevent.inaxes == self.fig.ax):
            self.area_context(mpl_mouseevent, evt)
        elif ((mpl_mouseevent.inaxes == self.fig.sx or mpl_mouseevent.inaxes == self.fig.sz) and (self.show_sliceplots == True)):
            self.lineplot_context(mpl_mouseevent, evt)

    def area_context(self, mpl_mouseevent, evt):
        area_popup = wx.Menu()
        item1 = area_popup.Append(wx.ID_ANY,'&Grid on/off', 'Toggle grid lines')
        wx.EVT_MENU(self, item1.GetId(), self.OnGridToggle)

# Path: osrefl/loaders/reduction/cmapmenu.py
# class CMapMenu(wx.Menu):
#     """
#     Menu tree binding to a list of colormaps.
#     """
#     def __init__(self, window,
#                  mapper=None, canvas=None, callback=None):
#         """
#         Define a context menu for selecting colormaps.
# 
#         Need a window to use as the event handler.
#         If mapper is defined, it will be updated with the new colormap.
#         If canvas is defined, it will update on idle.
#         """
#         wx.Menu.__init__(self)
# 
#         # OS X needs 16x16 icons; Windows and Linux can be longer
#         bar_length = 32 if not sys.platform in ['darwin'] else 16
#         bar_height = 16
#         self.mapper,self.canvas,self.callback = mapper,canvas,callback
#         self.selected = None
#         self.mapid = {}
#         for name in grouped_colormaps():
#             if name is None:
#                 self.AppendSeparator()
#             else:
#                 item = wx.MenuItem(self, wx.ID_ANY, name)
#                 map = cm.get_cmap(name)
#                 icon = colorbar_bitmap(map,bar_length,thickness=bar_height)
#                 item.SetBitmap(icon)
#                 self.AppendItem(item)
#                 window.Bind(wx.EVT_MENU,
#                             event_callback(self._OnSelect, name=name),
#                             id=item.GetId())
# 
#     def _OnSelect(self, event, name=None):
#         """
#         When selected, record the name, update the mapper and invoke the
#         callback.
#         """
#         self.selected = name
#         if self.mapper:
#             self.mapper.set_cmap(cm.get_cmap(name))
#         if self.canvas:
#             self.canvas.draw_idle()
#         if self.callback:
#             self.callback(name)


# Path: osrefl/viewers/plot_2d.py
from pylab import imshow,cm,colorbar,hot,show,xlabel,ylabel,connect, plot, figure, draw, axis, gcf,legend
from numpy import ones, sum, arange, transpose, log
from matplotlib.widgets import  RectangleSelector
from colormap import change_colormap
from matplotlib.axis import XAxis, YAxis
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas
from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg
from matplotlib.font_manager import fontManager, FontProperties
from matplotlib.image import FigureImage
from matplotlib.figure import Figure
from matplotlib.pyplot import figure, get_fignums
from zoom_colorbar import zoom_colorbar
from osrefl.loaders.reduction.cmapmenu import CMapMenu
from matplotlib.cm import get_cmap
        from matplotlib.ticker import FormatStrFormatter, ScalarFormatter
import matplotlib.colors as colors
import wx
import matplotlib.cbook as cbook
import matplotlib


    def set_new_lower_color_limit(self, evt = None):
        current_uplim = self.fig.im.get_clim()[1]
        current_lowlim = self.fig.im.get_clim()[0]
        dlg = wx.TextEntryDialog(None, "Change lower limit of color map (currently %f)" % current_lowlim, defaultValue = "%f" % current_lowlim)
        if dlg.ShowModal() == wx.ID_OK:
            new_val = dlg.GetValue()
            xlab = self.fig.cb.get_xlabel()
            ylab = self.fig.cb.get_ylabel()
            self.fig.im.set_clim((float(new_val), current_uplim))
            self.fig.cb.set_xlabel(xlab)
            self.fig.cb.set_ylabel(ylab)
            self.fig.canvas.draw()
        dlg.Destroy()

    def OnContext(self, evt):
        print self.show_sliceplots
        mpl_x = evt.X
        mpl_y = self.fig.canvas.GetSize()[1] - evt.Y
        mpl_mouseevent = matplotlib.backend_bases.MouseEvent('button_press_event', self.canvas, mpl_x, mpl_y, button = 3)

        if (mpl_mouseevent.inaxes == self.fig.ax):
            self.area_context(mpl_mouseevent, evt)
        elif ((mpl_mouseevent.inaxes == self.fig.sx or mpl_mouseevent.inaxes == self.fig.sz) and (self.show_sliceplots == True)):
            self.lineplot_context(mpl_mouseevent, evt)

    def area_context(self, mpl_mouseevent, evt):
        area_popup = wx.Menu()
        item1 = area_popup.Append(wx.ID_ANY,'&Grid on/off', 'Toggle grid lines')
        wx.EVT_MENU(self, item1.GetId(), self.OnGridToggle)

        cmapmenu = CMapMenu(self, callback = self.OnColormap, mapper=self.mapper, canvas=self.canvas)