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 |
---|
15 | from sans.guicomm.events import StatusEvent |
---|
16 | |
---|
17 | |
---|
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 = [] |
---|
38 | |
---|
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 | |
---|
48 | self.menu.Append(wx.NewId(), "No plot available", |
---|
49 | "No plot available") |
---|
50 | self.menu.FindItemByPosition(0).Enable(False) |
---|
51 | return [(id, self.menu, "Plot")] |
---|
52 | |
---|
53 | |
---|
54 | def get_panels(self, parent): |
---|
55 | """ |
---|
56 | Create and return a list of panel objects |
---|
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 | |
---|
64 | return [] |
---|
65 | |
---|
66 | |
---|
67 | def get_perspective(self): |
---|
68 | """ |
---|
69 | Get the list of panel names for this perspective |
---|
70 | """ |
---|
71 | return self.perspective |
---|
72 | |
---|
73 | def on_perspective(self, event): |
---|
74 | """ |
---|
75 | Call back function for the perspective menu item. |
---|
76 | We notify the parent window that the perspective |
---|
77 | has changed. |
---|
78 | @param event: menu event |
---|
79 | """ |
---|
80 | self.parent.set_perspective(self.perspective) |
---|
81 | |
---|
82 | def post_init(self): |
---|
83 | """ |
---|
84 | Post initialization call back to close the loose ends |
---|
85 | [Somehow openGL needs this call] |
---|
86 | """ |
---|
87 | pass |
---|
88 | |
---|
89 | |
---|
90 | def _on_show_panel(self, event): |
---|
91 | """show plug-in panel""" |
---|
92 | pass |
---|
93 | |
---|
94 | |
---|
95 | def _on_plot_event(self, event): |
---|
96 | """ |
---|
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 | @param event: EVT_NEW_PLOT event |
---|
101 | """ |
---|
102 | # Check whether we already have a graph with the same units |
---|
103 | # as the plottable we just received. |
---|
104 | |
---|
105 | is_available = False |
---|
106 | for panel in self.plot_panels: |
---|
107 | if event.plot._xunit == panel.graph.prop["xunit_base"] \ |
---|
108 | and event.plot._yunit == panel.graph.prop["yunit_base"]: |
---|
109 | if hasattr(event.plot, "group_id"): |
---|
110 | ## if same group_id used the same panel to plot |
---|
111 | if not event.plot.group_id==None \ |
---|
112 | and event.plot.group_id==panel.group_id: |
---|
113 | is_available = True |
---|
114 | |
---|
115 | panel._onEVT_1DREPLOT(event) |
---|
116 | self.parent.show_panel(panel.uid) |
---|
117 | else: |
---|
118 | # Check that the plot panel has no group ID |
---|
119 | ## Use a panel with group_id ==None to plot |
---|
120 | |
---|
121 | if panel.group_id==None: |
---|
122 | is_available = True |
---|
123 | panel._onEVT_1DREPLOT(event) |
---|
124 | self.parent.show_panel(panel.uid) |
---|
125 | |
---|
126 | # Create a new plot panel if none was available |
---|
127 | if not is_available: |
---|
128 | #print"event.plot",hasattr(event.plot,'data') |
---|
129 | if not hasattr(event.plot,'data'): |
---|
130 | from Plotter1D import ModelPanel1D |
---|
131 | ## get the data representation label of the data to plot |
---|
132 | ## when even the user select "change scale" |
---|
133 | if hasattr(event.plot,"xtransform"): |
---|
134 | xtransform = event.plot.xtransform |
---|
135 | else: |
---|
136 | xtransform =None |
---|
137 | |
---|
138 | if hasattr(event.plot,"ytransform"): |
---|
139 | ytransform= event.plot.ytransform |
---|
140 | else: |
---|
141 | ytransform=None |
---|
142 | ## create a plotpanel for 1D Data |
---|
143 | new_panel = ModelPanel1D(self.parent, -1,xtransform=xtransform, |
---|
144 | ytransform=ytransform, style=wx.RAISED_BORDER) |
---|
145 | |
---|
146 | else: |
---|
147 | ##Create a new plotpanel for 2D data |
---|
148 | from Plotter2D import ModelPanel2D |
---|
149 | new_panel = ModelPanel2D(self.parent, id = -1, data2d=event.plot,style=wx.RAISED_BORDER) |
---|
150 | |
---|
151 | ## Set group ID if available |
---|
152 | ## Assign data properties to the new create panel |
---|
153 | group_id_str = '' |
---|
154 | if hasattr(event.plot, "group_id"): |
---|
155 | if not event.plot.group_id==None: |
---|
156 | new_panel.group_id = event.plot.group_id |
---|
157 | group_id_str = ' [%s]' % event.plot.group_id |
---|
158 | |
---|
159 | if hasattr(event, "title"): |
---|
160 | new_panel.window_caption = event.title |
---|
161 | new_panel.window_name = event.title |
---|
162 | |
---|
163 | event_id = self.parent.popup_panel(new_panel) |
---|
164 | #remove the default item in the menu |
---|
165 | if len(self.plot_panels) == 0: |
---|
166 | self.menu.RemoveItem(self.menu.FindItemByPosition(0)) |
---|
167 | |
---|
168 | self.menu.Append(event_id, new_panel.window_caption, |
---|
169 | "Show %s plot panel" % new_panel.window_caption) |
---|
170 | # Set UID to allow us to reference the panel later |
---|
171 | new_panel.uid = event_id |
---|
172 | # Ship the plottable to its panel |
---|
173 | new_panel._onEVT_1DREPLOT(event) |
---|
174 | self.plot_panels.append(new_panel) |
---|
175 | |
---|
176 | return |
---|
177 | |
---|