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