"""
Simple Plot Frame : supporting only copy, print, scale
"""
import wx
from sas.guiframe.local_perspectives.plotting.Plotter2D import ModelPanel2D \
as PlotPanel
from sas.plottools.toolbar import NavigationToolBar
from sas.plottools.plottables import Graph
from sas.guiframe.utils import PanelMenu
[docs]class SimplePlotPanel(PlotPanel):
"""
PlotPanel for 1d and 2d
"""
_window_caption = 'Simple Plot'
def __init__(self, parent, id=-1, color = None,
dpi=None, style=wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs):
"""
Init
"""
PlotPanel.__init__(self, parent, id=id, style=style, **kwargs)
self.SetColor(wx.WHITE)
self.toolbar = NavigationToolBar(parent=self, canvas=self.canvas)
self.toolbar.Show(False)
self.scale = parent.scale
self.window_caption = self._window_caption
[docs] def draw(self):
"""
"""
self.resizing = False
self.canvas.set_resizing(self.resizing)
self.canvas.draw()
[docs] def on_grid_onoff(self, event):
"""
On grid on/off
"""
switch = (not self.grid_on)
self.onGridOnOff(switch)
[docs] def onLeftDown(self, event):
"""
left button down and ready to drag
"""
# Check that the LEFT button was pressed
if event.button == 1:
self.leftdown = True
ax = event.inaxes
if ax != None:
self.xInit, self.yInit = event.xdata, event.ydata
try:
pos_x = float(event.xdata) # / size_x
pos_y = float(event.ydata) # / size_y
pos_x = "%8.3g" % pos_x
pos_y = "%8.3g" % pos_y
self.position = str(pos_x), str(pos_y)
wx.PostEvent(self.parent, StatusEvent(status=self.position))
except:
self.position = None
def _OnReSize(self, event):
"""
On response of the resize of a panel, set axes_visiable False
"""
self.resizing = False
if self.x_size != None:
if self.x_size == self.GetSize():
self.canvas.set_resizing(self.resizing)
return
self.x_size = self.GetSize()
# Ready for another event
# Do not remove this Skip.
# Otherwise it will get runtime error on wx>=2.9.
event.Skip()
# set the resizing flag
self.canvas.set_resizing(self.resizing)
pos_x, pos_y = self.GetPositionTuple()
if pos_x != 0 and pos_y != 0:
self.size, _ = self.GetClientSizeTuple()
self.SetSizer(self.sizer)
[docs] def on_set_focus(self, event):
"""
By pass default boundary blue color drawing
"""
pass
[docs] def on_kill_focus(self, event):
"""
Reset the panel color
"""
pass
[docs] def show_plot(self, plot):
"""
Show the plot
"""
_yaxis, _yunit = plot.get_yaxis()
_xaxis, _xunit = plot.get_xaxis()
self.data = plot
self.plots[plot.name] = plot
# Axis scales
if plot.xtransform != None:
self.xLabel = plot.xtransform
if plot.ytransform != None:
self.yLabel = plot.ytransform
# Init graph
self.graph = Graph()
# Add plot: Handles both 1D and 2D
self.graph.add(self.data)
self.canvas.set_resizing(False)
if self.data.__class__.__name__ == 'Data2D':
self.data2D = plot
elif self.data.__class__.__name__ == 'Data1D':
self._onEVT_FUNC_PROPERTY(show=False)
# Axes
self.graph.xaxis(_xaxis, _xunit)
self.graph.yaxis(_yaxis, _yunit)
self.xaxis(_xaxis, _xunit)
self.yaxis(_yaxis, _yunit)
self.set_xscale(self.xscale)
self.set_yscale(self.yscale)
self.graph.render(self)
[docs]class PlotFrame(wx.Frame):
"""
Frame for simple plot
"""
def __init__(self, parent, id, title, scale='log_{10}',
size=wx.Size(550, 470)):
"""
comment
:param parent: parent panel/container
"""
# Initialize the Frame object
wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, size)
# Panel for 1D plot
self.parent = parent
self._mgr = None
self.menu_bar = None
self._default_save_location = None
self.scale = scale
self.plotpanel = SimplePlotPanel(self, -1)
self._build_menubar()
def _build_menubar(self):
"""
Build menubar
"""
tsize = (13, 13)
save_bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS, wx.ART_TOOLBAR,
tsize)
quit_bmp = wx.ArtProvider.GetBitmap(wx.ART_QUIT, wx.ART_TOOLBAR,
tsize)
print_bmp = wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_TOOLBAR,
tsize)
preview_bmp = wx.ArtProvider.GetBitmap(wx.ART_REPORT_VIEW, wx.ART_TOOLBAR,
tsize)
copy_bmp = wx.ArtProvider.GetBitmap(wx.ART_COPY, wx.ART_TOOLBAR,
tsize)
menu_bar = wx.MenuBar()
menu = wx.Menu()
id = wx.NewId()
item = wx.MenuItem(menu, id, "&Save Image")
item.SetBitmap(save_bmp)
menu.AppendItem(item)
wx.EVT_MENU(self, id, self.on_save_file)
id = wx.NewId()
item = wx.MenuItem(menu, id, "&Print Image")
item.SetBitmap(print_bmp)
menu.AppendItem(item)
wx.EVT_MENU(self, id, self.on_print_image)
id = wx.NewId()
item = wx.MenuItem(menu, id, "&Print Preview")
item.SetBitmap(preview_bmp)
menu.AppendItem(item)
wx.EVT_MENU(self, id, self.on_print_preview)
menu.AppendSeparator()
id = wx.NewId()
item = wx.MenuItem(menu, id, "&Quit")
item.SetBitmap(quit_bmp)
menu.AppendItem(item)
menu_bar.Append(menu, "&File")
wx.EVT_MENU(self, id, self.on_close)
menu_edit = wx.Menu()
id = wx.NewId()
item = wx.MenuItem(menu_edit, id, "&Copy")
item.SetBitmap(copy_bmp)
menu_edit.AppendItem(item)
wx.EVT_MENU(self, id, self.on_copy_image)
menu_bar.Append(menu_edit, "&Edit")
self.menu_bar = menu_bar
self.SetMenuBar(self.menu_bar)
[docs] def set_plot_unfocus(self):
"""
un focusing
"""
pass
[docs] def add_plot(self, plot):
"""
Add Image
"""
plotpanel = self.plotpanel
plotpanel.scale = self.scale
plotpanel.show_plot(plot)
[docs] def set_schedule_full_draw(self, panel, func):
"""
"""
self.plotpanel.resizing = False
[docs] def im_show(self, img):
"""
Show background image
:Param img: [imread(path) from matplotlib.pyplot]
"""
self.plotpanel.subplot.imshow(img)
[docs] def set_schedule(self, schedule=False):
"""
"""
#Not implemented
[docs] def on_save_file(self, event):
"""
Save image
"""
self.plotpanel.onSaveImage(event)
[docs] def on_print_image(self, event):
"""
Save image
"""
self.plotpanel.onPrint(event)
[docs] def on_print_preview(self, event):
"""
Save image
"""
self.plotpanel.onPrinterPreview(event)
[docs] def on_copy_image(self, event):
"""
Save image
"""
self.plotpanel.OnCopyFigureMenu(event)
[docs] def on_close(self, event):
"""
On Close
"""
try:
self.parent.set_scale2d(self.scale)
self.parent.on_panel_close(event)
except:
self.Destroy()