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