[41d466f] | 1 | |
---|
| 2 | |
---|
| 3 | |
---|
[d955bf19] | 4 | ################################################################################ |
---|
| 5 | #This software was developed by the University of Tennessee as part of the |
---|
| 6 | #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
| 7 | #project funded by the US National Science Foundation. |
---|
| 8 | # |
---|
| 9 | #See the license text in license.txt |
---|
| 10 | # |
---|
| 11 | #copyright 2008, University of Tennessee |
---|
| 12 | ################################################################################ |
---|
[41d466f] | 13 | |
---|
| 14 | import wx |
---|
| 15 | import sys |
---|
[f444b20] | 16 | from sans.guiframe.events import EVT_NEW_PLOT |
---|
| 17 | from sans.guiframe.events import StatusEvent |
---|
[7f84e22] | 18 | from sans.guiframe.plugin_base import PluginBase |
---|
[7764b41] | 19 | |
---|
[7f84e22] | 20 | class Plugin(PluginBase): |
---|
[41d466f] | 21 | """ |
---|
[d955bf19] | 22 | Plug-in class to be instantiated by the GUI manager |
---|
[41d466f] | 23 | """ |
---|
| 24 | |
---|
[7f84e22] | 25 | def __init__(self, standalone=False): |
---|
| 26 | PluginBase.__init__(self, name="Plotting", standalone=standalone) |
---|
| 27 | |
---|
[41d466f] | 28 | ## Plot panels |
---|
| 29 | self.plot_panels = [] |
---|
[54cc36a] | 30 | |
---|
[b7c7a1c] | 31 | def is_always_active(self): |
---|
| 32 | """ |
---|
| 33 | return True is this plugin is always active even if the user is |
---|
| 34 | switching between perspectives |
---|
| 35 | """ |
---|
| 36 | return True |
---|
| 37 | |
---|
[41d466f] | 38 | def populate_menu(self, id, parent): |
---|
| 39 | """ |
---|
[d955bf19] | 40 | Create a 'Plot' menu to list the panels |
---|
| 41 | available for displaying |
---|
| 42 | |
---|
| 43 | :param id: next available unique ID for wx events |
---|
| 44 | :param parent: parent window |
---|
| 45 | |
---|
[41d466f] | 46 | """ |
---|
| 47 | self.menu = wx.Menu() |
---|
[2fc9243] | 48 | |
---|
| 49 | self.menu.Append(wx.NewId(), "No plot available", |
---|
| 50 | "No plot available") |
---|
| 51 | self.menu.FindItemByPosition(0).Enable(False) |
---|
[41d466f] | 52 | return [(id, self.menu, "Plot")] |
---|
| 53 | |
---|
| 54 | def get_panels(self, parent): |
---|
| 55 | """ |
---|
[d955bf19] | 56 | Create and return a list of panel objects |
---|
[41d466f] | 57 | """ |
---|
| 58 | ## Save a reference to the parent |
---|
| 59 | self.parent = parent |
---|
| 60 | # Connect to plotting events |
---|
| 61 | self.parent.Bind(EVT_NEW_PLOT, self._on_plot_event) |
---|
| 62 | # We have no initial panels for this plug-in |
---|
| 63 | return [] |
---|
[54cc36a] | 64 | |
---|
[41d466f] | 65 | def _on_show_panel(self, event): |
---|
[6c0568b] | 66 | """show plug-in panel""" |
---|
| 67 | pass |
---|
| 68 | |
---|
[41d466f] | 69 | def _on_plot_event(self, event): |
---|
| 70 | """ |
---|
[d955bf19] | 71 | A new plottable is being shipped to the plotting plug-in. |
---|
| 72 | Check whether we have a panel to put in on, or create |
---|
| 73 | a new one |
---|
| 74 | |
---|
| 75 | :param event: EVT_NEW_PLOT event |
---|
| 76 | |
---|
[41d466f] | 77 | """ |
---|
| 78 | # Check whether we already have a graph with the same units |
---|
| 79 | # as the plottable we just received. |
---|
| 80 | is_available = False |
---|
| 81 | for panel in self.plot_panels: |
---|
[be72312c] | 82 | if event.plot._xunit == panel.graph.prop["xunit_base"] \ |
---|
| 83 | and event.plot._yunit == panel.graph.prop["yunit_base"]: |
---|
[383189f9] | 84 | if hasattr(event.plot, "group_id"): |
---|
[6c0568b] | 85 | ## if same group_id used the same panel to plot |
---|
[32c0841] | 86 | if not event.plot.group_id == None \ |
---|
| 87 | and event.plot.group_id == panel.group_id: |
---|
[383189f9] | 88 | is_available = True |
---|
| 89 | panel._onEVT_1DREPLOT(event) |
---|
[6c0568b] | 90 | self.parent.show_panel(panel.uid) |
---|
[383189f9] | 91 | else: |
---|
| 92 | # Check that the plot panel has no group ID |
---|
[6c0568b] | 93 | ## Use a panel with group_id ==None to plot |
---|
[32c0841] | 94 | if panel.group_id == None: |
---|
[383189f9] | 95 | is_available = True |
---|
| 96 | panel._onEVT_1DREPLOT(event) |
---|
| 97 | self.parent.show_panel(panel.uid) |
---|
[41d466f] | 98 | # Create a new plot panel if none was available |
---|
| 99 | if not is_available: |
---|
[7fff5cd] | 100 | #print"event.plot",hasattr(event.plot,'data') |
---|
[32c0841] | 101 | if not hasattr(event.plot, 'data'): |
---|
[1bf33c1] | 102 | from Plotter1D import ModelPanel1D |
---|
[6c0568b] | 103 | ## get the data representation label of the data to plot |
---|
| 104 | ## when even the user select "change scale" |
---|
[32c0841] | 105 | if hasattr(event.plot, "xtransform"): |
---|
[ffd23b5] | 106 | xtransform = event.plot.xtransform |
---|
| 107 | else: |
---|
[32c0841] | 108 | xtransform = None |
---|
[6c0568b] | 109 | |
---|
[32c0841] | 110 | if hasattr(event.plot, "ytransform"): |
---|
| 111 | ytransform = event.plot.ytransform |
---|
[ffd23b5] | 112 | else: |
---|
[32c0841] | 113 | ytransform = None |
---|
[6c0568b] | 114 | ## create a plotpanel for 1D Data |
---|
[32c0841] | 115 | new_panel = ModelPanel1D(self.parent, -1, xtransform=xtransform, |
---|
| 116 | ytransform=ytransform, style=wx.RAISED_BORDER) |
---|
[743d75c] | 117 | else: |
---|
[6c0568b] | 118 | ##Create a new plotpanel for 2D data |
---|
[1bf33c1] | 119 | from Plotter2D import ModelPanel2D |
---|
[d0ecb36] | 120 | if hasattr(event.plot, "scale"): |
---|
| 121 | scale = event.plot.scale |
---|
| 122 | else: |
---|
| 123 | scale = 'log' |
---|
[32c0841] | 124 | new_panel = ModelPanel2D(self.parent, id = -1, |
---|
[d0ecb36] | 125 | data2d=event.plot, scale = scale, |
---|
| 126 | style=wx.RAISED_BORDER) |
---|
[6c0568b] | 127 | ## Set group ID if available |
---|
| 128 | ## Assign data properties to the new create panel |
---|
[383189f9] | 129 | group_id_str = '' |
---|
| 130 | if hasattr(event.plot, "group_id"): |
---|
[32c0841] | 131 | if not event.plot.group_id == None: |
---|
[383189f9] | 132 | new_panel.group_id = event.plot.group_id |
---|
| 133 | group_id_str = ' [%s]' % event.plot.group_id |
---|
[41d466f] | 134 | if hasattr(event, "title"): |
---|
| 135 | new_panel.window_caption = event.title |
---|
| 136 | new_panel.window_name = event.title |
---|
| 137 | event_id = self.parent.popup_panel(new_panel) |
---|
[2fc9243] | 138 | #remove the default item in the menu |
---|
| 139 | if len(self.plot_panels) == 0: |
---|
| 140 | self.menu.RemoveItem(self.menu.FindItemByPosition(0)) |
---|
[41d466f] | 141 | self.menu.Append(event_id, new_panel.window_caption, |
---|
| 142 | "Show %s plot panel" % new_panel.window_caption) |
---|
| 143 | # Set UID to allow us to reference the panel later |
---|
| 144 | new_panel.uid = event_id |
---|
| 145 | # Ship the plottable to its panel |
---|
| 146 | new_panel._onEVT_1DREPLOT(event) |
---|
| 147 | self.plot_panels.append(new_panel) |
---|
| 148 | |
---|
| 149 | return |
---|
[4e9583c] | 150 | |
---|