Changeset c039589 in sasview for src/sas/guiframe/local_perspectives/plotting/plotting.py
- Timestamp:
- Mar 5, 2015 4:37:00 PM (10 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- b40ad40
- Parents:
- 090e07e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/guiframe/local_perspectives/plotting/plotting.py
rb9dbd6b rc039589 5 5 #This software was developed by the University of Tennessee as part of the 6 6 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 7 #project funded by the US National Science Foundation. 7 #project funded by the US National Science Foundation. 8 8 # 9 9 #See the license text in license.txt … … 16 16 from sas.guiframe.events import EVT_NEW_PLOT 17 17 from sas.guiframe.events import EVT_PLOT_QRANGE 18 from sas.guiframe.events import StatusEvent19 18 from sas.guiframe.events import DeletePlotPanelEvent 20 19 from sas.guiframe.plugin_base import PluginBase … … 25 24 DEFAULT_MENU_ITEM_ID = wx.NewId() 26 25 27 IS_WIN = True 28 if sys.platform.count("win32") ==0:26 IS_WIN = True 27 if sys.platform.count("win32") == 0: 29 28 if int(str(wx.__version__).split('.')[0]) == 2: 30 29 if int(str(wx.__version__).split('.')[1]) < 9: … … 36 35 Plug-in class to be instantiated by the GUI manager 37 36 """ 38 37 39 38 def __init__(self, standalone=False): 40 39 PluginBase.__init__(self, name="Plotting", standalone=standalone) 41 40 42 41 ## Plot panels 43 42 self.plot_panels = {} … … 47 46 self.menu = None 48 47 49 48 50 49 def set_panel_on_focus(self, panel): 51 50 """ 52 51 """ 53 52 self._panel_on_focus = panel 54 53 55 54 def is_always_active(self): 56 55 """ 57 return True is this plugin is always active even if the user is 56 return True is this plugin is always active even if the user is 58 57 switching between perspectives 59 58 """ 60 59 return True 61 60 62 61 def populate_menu(self, parent): 63 62 """ 64 63 Create a 'Plot' menu to list the panels 65 64 available for displaying 66 65 67 66 :param id: next available unique ID for wx events 68 67 :param parent: parent window 69 68 70 69 """ 71 70 return [] 72 """ 73 self.menu = wx.Menu() 74 self.menu.Append(DEFAULT_MENU_ITEM_ID, DEFAULT_MENU_ITEM_LABEL, 75 "No graph available") 76 self.menu.FindItemByPosition(0).Enable(False) 77 return [(self.menu, "Show")] 78 """ 79 71 80 72 def get_panels(self, parent): 81 73 """ … … 89 81 # We have no initial panels for this plug-in 90 82 return [] 91 92 def _on_plot_qrange(self, event= 83 84 def _on_plot_qrange(self, event=None): 93 85 """ 94 86 On Qmin Qmax vertical line event … … 103 95 return 104 96 panel.on_plot_qrange(event) 105 97 106 98 def _on_show_panel(self, event): 107 99 """show plug-in panel""" 108 100 pass 109 101 110 102 def remove_plot(self, group_id, id): 111 103 """ 112 104 remove plot of ID = id from a panel of group ID =group_id 113 105 """ 114 106 115 107 if group_id in self.plot_panels.keys(): 116 108 panel = self.plot_panels[group_id] 117 109 panel.remove_data_by_id(id=id) 118 110 119 111 return True 120 112 return False 121 113 122 114 def clear_panel(self): 123 115 """ … … 129 121 self.hide_panel(group_id) 130 122 self.plot_panels = {} 131 123 132 124 def clear_panel_by_id(self, group_id): 133 125 """ … … 141 133 return True 142 134 return False 143 135 144 136 def hide_panel(self, group_id): 145 137 """ … … 148 140 # Not implemeted 149 141 return False 150 142 151 143 def create_panel_helper(self, new_panel, data, group_id, title=None): 152 144 """ … … 167 159 new_panel.uid = event_id 168 160 # Ship the plottable to its panel 169 wx.CallAfter(new_panel.plot_data, data) 161 wx.CallAfter(new_panel.plot_data, data) 170 162 #new_panel.canvas.set_resizing(new_panel.resizing) 171 163 self.plot_panels[new_panel.group_id] = new_panel 172 173 # Set Graph menu and help string 174 self.help_string = ' Graph: ' 175 for plot in new_panel.plots.itervalues(): 176 help_string += (' ' + plot.label + ';') 177 #self.menu.AppendCheckItem(event_id, new_panel.window_caption, 178 # helpString) 179 #self.menu.Check(event_id, IS_WIN) 180 #wx.EVT_MENU(self.parent, event_id, self._on_check_menu) 181 182 164 183 165 def create_1d_panel(self, data, group_id): 184 166 """ 185 167 """ 186 # Create a new plot panel if none was available 168 # Create a new plot panel if none was available 187 169 if issubclass(data.__class__, Data1D): 188 170 from Plotter1D import ModelPanel1D … … 194 176 win = MDIFrame(self.parent, None, 'None', (100, 200)) 195 177 new_panel = ModelPanel1D(win, -1, xtransform=xtransform, 196 ytransform=ytransform, style=wx.RAISED_BORDER)178 ytransform=ytransform, style=wx.RAISED_BORDER) 197 179 win.set_panel(new_panel) 198 180 win.Show(False) … … 200 182 #win.Show(True) 201 183 return new_panel 202 184 203 185 msg = "1D Panel of group ID %s could not be created" % str(group_id) 204 186 raise ValueError, msg 205 187 206 188 def create_2d_panel(self, data, group_id): 207 189 """ … … 213 195 win = MDIFrame(self.parent, None, 'None', (200, 150)) 214 196 win.Show(False) 215 new_panel = ModelPanel2D(win, id =-1,216 data2d=data, scale = scale,217 style=wx.RAISED_BORDER)197 new_panel = ModelPanel2D(win, id=-1, 198 data2d=data, scale=scale, 199 style=wx.RAISED_BORDER) 218 200 win.set_panel(new_panel) 219 201 new_panel.frame = win 220 #win.Show(True)221 202 return new_panel 222 203 msg = "2D Panel of group ID %s could not be created" % str(group_id) 223 204 raise ValueError, msg 224 205 225 206 def update_panel(self, data, panel): 226 207 """ … … 228 209 """ 229 210 # Check whether we already have a graph with the same units 230 # as the plottable we just received. 231 _, x_unit = 232 _, y_unit = 211 # as the plottable we just received. 212 _, x_unit = data.get_xaxis() 213 _, y_unit = data.get_yaxis() 233 214 flag_x = (panel.graph.prop["xunit"] is not None) and \ 234 215 (panel.graph.prop["xunit"].strip() != "") and\ … … 237 218 (panel.graph.prop["yunit"].strip() != "") and\ 238 219 (y_unit != panel.graph.prop["yunit"]) and False 239 if (flag_x and flag_y):220 if flag_x and flag_y: 240 221 msg = "Cannot add %s" % str(data.name) 241 222 msg += " to panel %s\n" % str(panel.window_caption) … … 253 234 panel = self.plot_panels[group_id] 254 235 uid = panel.uid 255 wx.PostEvent(self.parent, 236 wx.PostEvent(self.parent, 256 237 DeletePlotPanelEvent(name=panel.window_caption, 257 caption=panel.window_caption)) 258 #remove menu item 259 #self.delete_menu_item(panel.window_caption, panel.uid) 238 caption=panel.window_caption)) 260 239 del self.plot_panels[group_id] 261 240 if uid in self.parent.plot_panels.keys(): … … 265 244 266 245 return False 267 246 268 247 def _on_plot_event(self, event): 269 248 """ … … 271 250 Check whether we have a panel to put in on, or create 272 251 a new one 273 252 274 253 :param event: EVT_NEW_PLOT event 275 254 276 255 """ 277 256 action_check = False … … 285 264 #remove data from panel 286 265 if action_string == 'remove': 287 id = event.id 288 return self.remove_plot(group_id, id) 266 return self.remove_plot(group_id, event.id) 289 267 if action_string == 'hide': 290 268 return self.hide_panel(group_id) … … 295 273 if action_string == "clear": 296 274 return self.clear_panel_by_id(group_id) 297 298 if not hasattr(event, 'plot'): 275 276 if not hasattr(event, 'plot'): 299 277 return 300 278 title = None 301 279 if hasattr(event, 'title'): 302 title = 'Graph' #event.title280 title = 'Graph' #event.title 303 281 data = event.plot 304 group_id = data.group_id 282 group_id = data.group_id 305 283 if group_id in self.plot_panels.keys(): 306 284 if action_check: 307 285 # Check if the plot already exist. if it does, do nothing. 308 286 if data.id in self.plot_panels[group_id].plots.keys(): 309 return 310 #update a panel graph 287 return 288 #update a panel graph 311 289 panel = self.plot_panels[group_id] 312 290 self.update_panel(data, panel) … … 331 309 p_plot.group_id = group_id 332 310 return 333 311 334 312 new_panel = self.create_2d_panel(data, group_id) 335 self.create_panel_helper(new_panel, data, group_id, title) 313 self.create_panel_helper(new_panel, data, group_id, title) 336 314 return 337 frame.Show(True)
Note: See TracChangeset
for help on using the changeset viewer.