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