Changeset a07e72f in sasview
- Timestamp:
- Feb 28, 2011 2:07:14 PM (14 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:
- 243a8d4
- Parents:
- 6bbeacd4
- Files:
-
- 4 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/data_manager.py
r0348245 ra07e72f 23 23 from sans.guiframe.dataFitting import Data2D 24 24 25 import wx 26 25 27 class DataManager(object): 26 28 """ … … 77 79 new_plot.interactive = True 78 80 ## when 2 data have the same id override the 1 st plotted 79 new_plot.id = name81 new_plot.id = wx.NewId() 80 82 ##group_id specify on which panel to plot this data 81 new_plot.group_id = name83 new_plot.group_id = [wx.NewId()] 82 84 new_plot.is_data = True 83 85 new_plot.path = path … … 151 153 """ 152 154 """ 153 print "append theory", self.stored_data, data_id154 155 if data_id in self.stored_data: 155 156 data_state = self.stored_data[data_id] -
guiframe/events.py
r4e4d3bb ra07e72f 16 16 #slicer event 17 17 (SlicerEvent, EVT_SLICER) = wx.lib.newevent.NewEvent() 18 # event containinG A DICTIONARY OF NAME and errors of selected data19 (ErrorDataEvent, ERR_DATA) = wx.lib.newevent.NewEvent()20 18 ## event that that destroy a page associate with Data1D removed from the graph 21 19 (RemoveDataEvent, EVT_REMOVE_DATA) = wx.lib.newevent.NewEvent() -
guiframe/gui_manager.py
r4c0572f ra07e72f 431 431 Hide()) 432 432 433 def get_context_menu(self, graph=None):433 def get_context_menu(self, plotpanel=None): 434 434 """ 435 435 Get the context menu items made available … … 437 437 This function is used by the plotting module 438 438 """ 439 if plotpanel is None: 440 return 439 441 menu_list = [] 440 442 for item in self.plugins: 441 if hasattr(item, "get_context_menu"): 442 menu_list.extend(item.get_context_menu(graph)) 443 menu_list.extend(item.get_context_menu(plotpanel=plotpanel)) 443 444 return menu_list 444 445 -
guiframe/gui_style.py
r59a4a750 ra07e72f 33 33 PRINT_ID = wx.NewId() 34 34 CURRENT_APPLICATION = wx.NewId() 35 CURVE_SYMBOL_NUM = 13 35 36 36 37 class GUIFRAME_ICON: -
guiframe/local_perspectives/plotting/Plotter1D.py
ra45037aa ra07e72f 18 18 import numpy 19 19 import time 20 import danse.common.plottools 20 21 21 from danse.common.plottools.PlotPanel import PlotPanel 22 22 from danse.common.plottools.plottables import Graph … … 26 26 from sans.guiframe.events import NewPlotEvent 27 27 from sans.guiframe.events import SlicerEvent 28 from sans.guiframe.events import ErrorDataEvent29 28 from sans.guiframe.events import RemoveDataEvent 30 29 from sans.guiframe.events import PanelOnFocusEvent … … 32 31 from sans.guiframe.utils import PanelMenu 33 32 from sans.guiframe.dataFitting import Data1D 34 from sans.guiframe.dataFitting import Theory1D35 33 from sans.guiframe.panel_base import PanelBase 36 34 from binder import BindArtist … … 67 65 #context menu 68 66 self._slicerpop = None 69 self._menu_add_plot = None67 70 68 self._available_data = [] 71 69 self._menu_add_ids = [] 72 ## save errors dy for each data plotted 73 self.err_dy = {} 74 ## flag to determine if the hide or show context menu item should 75 ## be displayed 76 self.errors_hide = False 70 self._symbol_labels = self.get_symbol_label() 71 72 self.hide_menu = None 77 73 ## Unique ID (from gui_manager) 78 74 self.uid = None 79 ## Action IDs for internal call-backs 80 self.action_ids = {} 75 81 76 ## Default locations 82 77 self._default_save_location = os.getcwd() … … 86 81 self.graph.yaxis("\\rm{Intensity} ", "cm^{-1}") 87 82 self.graph.render(self) 88 #bind with event to contrst context menu 89 #self.parent.Bind(EVT_NEW_LOADED_DATA, self._add_new_plot) 90 91 def on_add_new_plot(self, event): 92 """ 93 """ 94 def _add_new_plot(self, event): 95 """ 96 Construct the context menu given available data 97 """ 98 self._available_data = event.data_to_add 83 84 def get_symbol_label(self): 85 """ 86 Associates label to symbol 87 """ 88 _labels = {} 89 i = 0 90 _labels['Points'] = i 91 i += 1 92 _labels['X '] = i 93 i += 1 94 _labels['Triangle Down'] = i 95 i += 1 96 _labels['Triangle Up'] = i 97 i += 1 98 _labels['Triangle Left'] = i 99 i += 1 100 _labels['Triangle Right'] = i 101 i += 1 102 _labels['Plus'] = i 103 i += 1 104 _labels['Square'] = i 105 i += 1 106 _labels['Thin Diamond'] = i 107 i += 1 108 _labels['Diamond'] = i 109 i += 1 110 _labels['Hexagon1'] = i 111 i += 1 112 _labels['Hexagon2'] = i 113 i += 1 114 _labels['Pentagon'] = i 115 i += 1 116 _labels['Curve'] = i 117 return _labels 118 99 119 100 def _fill_menu_add_plot(self):101 """102 """103 if self._menu_add_plot is not None:104 if self._available_data:105 for id in self._menu_add_ids:106 item = self._menu_add_plot.FindItemById(id)107 if item is None:108 for data in self._available_data:109 new_id = wx.NewId()110 hint = 'Add %s to this panel' % str(data.name)111 self._menu_add_plot.Append(new_id, str(data.name), hint)112 wx.EVT_MENU(self, id, self.on_add_new_plot)113 self._menu_add_ids.append(new_id)114 else:115 if item.GetLabel() == 'No Loaded Data':116 self._menu_add_plot.RemoveItem(item)117 118 120 def set_data(self, list=None): 119 121 """ … … 127 129 self.graph.reset() 128 130 self.plots = {} 129 self.action_ids = {}130 131 131 def _onEVT_1DREPLOT(self, event): 132 def remove_data_by_id(self, id): 133 """' 134 remove data from plot 135 """ 136 if id in self.plots.keys(): 137 data = self.plots[id] 138 self.graph.delete(data) 139 data_manager = self._manager.parent.get_data_manager() 140 data_list = data_manager.get_by_id(id_list=[id]) 141 data = data_list.values()[0].data 142 data.group_id.remove(self.group_id) 143 del self.plots[id] 144 145 self.graph.render(self) 146 self.subplot.figure.canvas.draw_idle() 147 if len(self.graph.plottables) == 0: 148 print "_onRemove: graph is empty must be destroyed" 149 150 else: 151 msg = "Attempt to remove an unexisting plot with ID %s " % str(id) 152 raise ValueError, msg 153 154 def plot_data(self, data): 132 155 """ 133 156 Data is ready to be displayed … … 135 158 :param event: data event 136 159 """ 137 #TODO: Check for existence of plot attribute 138 # Check whether this is a replot. If we ask for a replot 139 # and the plottable no longer exists, ignore the event. 140 if hasattr(event, "update") and event.update == True \ 141 and event.plot.name not in self.plots.keys(): 142 return 143 if hasattr(event, "reset"): 144 self._reset() 145 # Check whether the plottable is empty 146 is_empty = len(event.plot.x) == 0 147 148 is_new = True 149 if event.plot.name in self.plots.keys(): 150 # If the plottable is empty, just remove the plottable from the graph 151 if is_empty: 152 self.graph.delete(self.plots[event.plot.name]) 153 del self.plots[event.plot.name] 154 else: 155 # Check whether the class of plottable changed 156 if not event.plot.__class__ == self.plots[event.plot.name].__class__: 157 #overwrite a plottable using the same name 158 self.graph.delete(self.plots[event.plot.name]) 159 else: 160 # plottable is already draw on the panel 161 is_new = False 162 163 if not is_empty: 164 if is_new: 165 # a new plottable overwrites a plotted one using the same id 166 for plottable in self.plots.itervalues(): 167 if hasattr(event.plot, "id") and hasattr(plottable, "id"): 168 #remove the existing plot and same id and same name 169 if event.plot.id == plottable.id and \ 170 event.plot.name == plottable.name: 171 self.graph.delete(plottable) 172 173 self.plots[event.plot.name] = event.plot 174 self.graph.add(self.plots[event.plot.name]) 175 else: 176 #replot the graph 177 self.plots[event.plot.name].x = event.plot.x 178 self.plots[event.plot.name].y = event.plot.y 179 self.plots[event.plot.name].dy = event.plot.dy 180 if hasattr(event.plot, 'dx') and \ 181 hasattr(self.plots[event.plot.name], 'dx'): 182 self.plots[event.plot.name].dx = event.plot.dx 183 184 #TODO: Should re-factor this 185 ## for all added plot the option to hide error show be displayed first 186 #self.errors_hide = 0 187 ## Set axis labels 188 self.graph.xaxis(event.plot._xaxis, event.plot._xunit) 189 self.graph.yaxis(event.plot._yaxis, event.plot._yunit) 160 if data.id in self.plots.keys(): 161 #replace 162 self.graph.replace(data) 163 self.plots[data.id] = data 164 else: 165 self.plots[data.id] = data 166 self.graph.add(self.plots[data.id]) 167 168 x_label, x_unit = data.get_xaxis() 169 y_label, y_unit = data.get_yaxis() 170 self.graph.xaxis(x_unit, x_label) 171 self.graph.yaxis(y_unit, y_label) 190 172 ## Set the view scale for all plots 191 173 self._onEVT_FUNC_PROPERTY() … … 193 175 self.graph.render(self) 194 176 self.subplot.figure.canvas.draw_idle() 195 #if self.errors_hide: 196 # self._on_remove_errors(evt=None) 197 #else: 198 # self._on_add_errors( evt=None) 199 177 178 200 179 def onLeftDown(self,event): 201 180 """ … … 211 190 #post nd event to notify guiframe that this panel is on focus 212 191 wx.PostEvent(self.parent, PanelOnFocusEvent(panel=self)) 213 192 self._manager.set_panel_on_focus(self) 193 194 def _ontoggle_hide_error(self, event): 195 """ 196 Toggle error display to hide or show 197 """ 198 199 selected_plot = self.plots[self.graph.selected_plottable] 200 if self.hide_menu.GetText() == "Hide Error": 201 selected_plot.hide_error = True 202 else: 203 selected_plot.hide_error = False 204 ## increment graph color 205 self.graph.render(self) 206 self.subplot.figure.canvas.draw_idle() 207 214 208 def _onRemove(self, event): 215 209 """ … … 219 213 220 214 """ 221 selected_plot = self.plots[self.graph.selected_plottable]222 215 ## Check if there is a selected graph to remove 223 if not self.graph.selected_plottable == None and\ 224 self.graph.selected_plottable in self.plots.keys(): 225 color = self.graph.plottables[selected_plot] 216 if self.graph.selected_plottable in self.plots.keys(): 217 selected_plot = self.plots[self.graph.selected_plottable] 218 id = self.graph.selected_plottable 219 self.remove_data_by_id( id) 226 220 event = RemoveDataEvent(data=selected_plot) 227 221 wx.PostEvent(self.parent, event) 228 222 self.graph.delete(selected_plot) 229 223 del selected_plot 230 ## increment graph color 231 self.graph.color += color 232 self.graph.render(self) 233 self.subplot.figure.canvas.draw_idle() 234 224 235 225 def onContextMenu(self, event): 236 226 """ … … 253 243 self._slicerpop.Append(id, '&Print Preview', 'image preview for print') 254 244 wx.EVT_MENU(self, id, self.onPrinterPreview) 255 """ 256 #add plot 257 self._menu_add_plot = wx.Menu() 258 id = wx.NewId() 259 self._menu_add_plot.Append(id, '&No Loaded Data', 'Add new plot') 260 self._menu_add_plot.FindItemByPosition(0).Enable(False) 261 self._menu_add_ids.append(id) 262 263 self._slicerpop.AppendSubMenu(self._menu_add_plot, '&Add New Plot') 264 self._fill_menu_add_plot() 265 """ 245 246 symbol_menu = wx.Menu() 247 for label in self._symbol_labels: 248 id = wx.NewId() 249 symbol_menu.Append(id, str(label), str(label)) 250 wx.EVT_MENU(self, id, self.onChangeSymbol) 251 id = wx.NewId() 252 self._slicerpop.AppendMenu(id,'&Modify Symbol', symbol_menu) 266 253 self._slicerpop.AppendSeparator() 254 267 255 #add menu of other plugins 268 item_list = self.parent.get_context_menu(self .graph)256 item_list = self.parent.get_context_menu(self) 269 257 if (not item_list == None) and (not len(item_list) == 0): 270 258 for item in item_list: … … 275 263 except: 276 264 msg = "ModelPanel1D.onContextMenu: " 277 msg += "bad menu item %s" %sys.exc_value265 msg += "bad menu item %s" % sys.exc_value 278 266 wx.PostEvent(self.parent, StatusEvent(status=msg)) 279 267 pass 280 268 self._slicerpop.AppendSeparator() 281 269 id = wx.NewId() 282 self._menu_add_plot = wx.Menu()270 283 271 self._slicerpop.Append(id, '&Print image', 'Print image') 284 272 if self.graph.selected_plottable in self.plots: … … 287 275 name = plot.name 288 276 self._slicerpop.Append(id, "&Save points") 289 self.action_ids[str(id)] = plot290 277 wx.EVT_MENU(self, id, self._onSave) 291 278 id = wx.NewId() 292 279 self._slicerpop.Append(id, "Remove %s curve" % name) 293 self.action_ids[str(id)] = plot294 280 wx.EVT_MENU(self, id, self._onRemove) 281 id = wx.NewId() 282 self.hide_menu = self._slicerpop.Append(id, "Hide Error") 283 if plot.dy is not None or plot.dy != []: 284 if plot.hide_error : 285 self.hide_menu.SetText('Show Error') 286 else: 287 self.hide_menu.SetText('Hide Error') 288 else: 289 self.hide_menu.Disable() 290 wx.EVT_MENU(self, id, self._ontoggle_hide_error) 291 295 292 self._slicerpop.AppendSeparator() 296 293 # Option to hide 297 294 #TODO: implement functionality to hide a plottable (legend click) 298 if self.graph.selected_plottable in self.plots: 299 selected_plot = self.plots[self.graph.selected_plottable] 300 id = wx.NewId() 301 self._slicerpop.Append(id, '&Linear fit') 302 wx.EVT_MENU(self, id, self.onFitting) 303 self._slicerpop.AppendSeparator() 295 id = wx.NewId() 296 self._slicerpop.Append(id, '&Linear Fit') 297 wx.EVT_MENU(self, id, self.onFitting) 298 304 299 id = wx.NewId() 305 300 self._slicerpop.Append(id, '&Change scale') … … 311 306 pos = self.ScreenToClient(pos) 312 307 self.PopupMenu(self._slicerpop, pos) 313 314 def _on_remove_errors(self, evt): 315 """ 316 Save name and dy of data in dictionary self.err_dy 317 Create a new data1D with the same x, y 318 vector and dy with zeros. 319 post self.err_dy as event (ErrorDataEvent) for any object 320 which wants to reconstruct the initial data. 321 322 :param evt: Menu event 323 324 """ 325 if not self.graph.selected_plottable == None: 326 ## store existing dy 327 name =self.plots[self.graph.selected_plottable].name 328 dy = self.plots[self.graph.selected_plottable].dy 329 self.err_dy[name] = dy 330 ## Create a new dy for a new plottable 331 #import numpy 332 dy = numpy.zeros(len(self.plots[self.graph.selected_plottable].y)) 333 selected_plot = self.plots[self.graph.selected_plottable] 334 335 if selected_plot.__class__.__name__ == "Data1D": 336 # Make sure that we can pass a basic Data1D 337 dxl = None 338 dxw = None 339 if hasattr(selected_plot, "dxl"): 340 dxl = selected_plot.dxl 341 if hasattr(selected_plot, "dxw"): 342 dxw = selected_plot.dxw 343 new_plot = Data1D(x=selected_plot.x, y=selected_plot.y, 344 dx=selected_plot.dx, dy=dy) 345 new_plot.dxl = dxl 346 new_plot.dxw = dxw 347 else: 348 new_plot = Theory1D(x=selected_plot.x, 349 y=selected_plot.y, dy=dy) 350 new_plot.interactive = True 351 self.errors_hide = True 352 new_plot.name = self.plots[self.graph.selected_plottable].name 353 if hasattr(self.plots[self.graph.selected_plottable], "group_id"): 354 new_plot.group_id = self.plots[self.graph.selected_plottable].group_id 355 if hasattr(self.plots[self.graph.selected_plottable], "id"): 356 new_plot.id = self.plots[self.graph.selected_plottable].id 357 else: 358 new_plot.id = str(time.time()) 359 else: 360 new_plot.group_id = str(time.time()) 361 new_plot.id = str(time.time()) 362 label, unit = self.plots[self.graph.selected_plottable].get_xaxis() 363 new_plot.xaxis(label, unit) 364 label, unit = self.plots[self.graph.selected_plottable].get_yaxis() 365 new_plot.yaxis(label, unit) 366 ## save the color of the selected plottable before it is deleted 367 color = self.graph.plottables[self.plots[self.graph.selected_plottable]] 368 self.graph.delete(self.plots[self.graph.selected_plottable]) 369 ## add newly created plottable to the graph with the save color 370 self.graph.color += color 371 self.graph.add(new_plot, color) 372 ## transforming the view of the new data into the same of 373 #the previous data 374 self._onEVT_FUNC_PROPERTY() 375 ## save the plot 376 self.plots[self.graph.selected_plottable] = new_plot 377 ## Render the graph 378 self.graph.render(self) 379 self.subplot.figure.canvas.draw_idle() 380 event = ErrorDataEvent(err_dy=self.err_dy) 381 wx.PostEvent(self.parent, event) 382 383 def _on_add_errors(self, evt): 384 """ 385 create a new data1D witht the errors saved in self.err_dy 386 to show errors of the plot. 387 Compute reasonable errors for a data set without 388 errors and transorm the plottable to a Data1D 389 390 :param evt: Menu event 391 392 """ 393 if not self.graph.selected_plottable == None \ 394 and self.graph.selected_plottable in self.plots.keys(): 395 ##Reset the flag to display the hide option on the context menu 396 self.errors_hide = False 397 ## restore dy 398 length = len(self.plots[self.graph.selected_plottable].x) 399 dy = numpy.zeros(length) 400 selected_plot = self.plots[self.graph.selected_plottable] 401 try: 402 dy = self.err_dy[selected_plot.name] 403 except: 404 if hasattr(selected_plot, "dy"): 405 dy = selected_plot.dy 406 else: 407 dy = numpy.zeros(selected_plot.dy) 408 ## Create a new plottable data1D 409 if selected_plot.__class__.__name__ == "Data1D": 410 # Make sure that we can pass a basic Data1D 411 dxl = None 412 dxw = None 413 if hasattr(selected_plot, "dxl"): 414 dxl = selected_plot.dxl 415 if hasattr(selected_plot, "dxw"): 416 dxw = selected_plot.dxw 417 new_plot = Data1D(x=selected_plot.x, 418 y=selected_plot.y, 419 dx=selected_plot.dx, 420 dy=dy) 421 new_plot.dxl = dxl 422 new_plot.dxw = dxw 423 else: 424 ## Create a new plottable Theory1D 425 new_plot = Theory1D(x=selected_plot.x, y=selected_plot.y, dy=dy) 426 new_plot.interactive = True 427 new_plot.name = self.plots[self.graph.selected_plottable].name 428 if hasattr(self.plots[self.graph.selected_plottable], "group_id"): 429 new_plot.group_id = self.plots[self.graph.selected_plottable].group_id 430 if hasattr(self.plots[self.graph.selected_plottable],"id"): 431 new_plot.id = self.plots[self.graph.selected_plottable].id 432 else: 433 new_plot.id = str(time.time()) 434 else: 435 new_plot.group_id = str(time.time()) 436 new_plot.id = str(time.time()) 437 438 label, unit = self.plots[self.graph.selected_plottable].get_xaxis() 439 new_plot.xaxis(label, unit) 440 label, unit = self.plots[self.graph.selected_plottable].get_yaxis() 441 new_plot.yaxis(label, unit) 442 ## save the color of the selected plottable before it is deleted 443 color=self.graph.plottables[self.plots[self.graph.selected_plottable]] 444 self.graph.delete(self.plots[self.graph.selected_plottable]) 445 self.graph.color += color 446 ## add newly created plottable to the graph with the save color 447 self.graph.add(new_plot, color) 448 ## transforming the view of the new data into the same of 449 # the previous data 450 self._onEVT_FUNC_PROPERTY() 451 ## save the plot 452 self.plots[self.graph.selected_plottable]=new_plot 453 ## render the graph with its new content 454 self.graph.render(self) 455 self.subplot.figure.canvas.draw_idle() 456 457 308 309 def onChangeSymbol(self, event): 310 """ 311 """ 312 menu = event.GetEventObject() 313 id = event.GetId() 314 label = menu.GetLabel(id) 315 selected_plot = self.plots[self.graph.selected_plottable] 316 selected_plot.symbol = self._symbol_labels[label] 317 ## Set the view scale for all plots 318 self._onEVT_FUNC_PROPERTY() 319 ## render the graph 320 self.graph.render(self) 321 self.subplot.figure.canvas.draw_idle() 322 458 323 def _onsaveTXT(self, path): 459 324 """ … … 503 368 504 369 """ 505 id = str(evt.GetId()) 506 if id in self.action_ids: 370 371 path = None 372 wildcard = "Text files (*.txt)|*.txt|"\ 373 "CanSAS 1D files(*.xml)|*.xml" 374 dlg = wx.FileDialog(self, "Choose a file", 375 self._default_save_location, 376 "", wildcard , wx.SAVE) 377 378 if dlg.ShowModal() == wx.ID_OK: 379 path = dlg.GetPath() 380 mypath = os.path.basename(path) 507 381 508 path = None 509 wildcard = "Text files (*.txt)|*.txt|"\ 510 "CanSAS 1D files(*.xml)|*.xml" 511 dlg = wx.FileDialog(self, "Choose a file", 512 self._default_save_location, 513 "", wildcard , wx.SAVE) 514 515 if dlg.ShowModal() == wx.ID_OK: 516 path = dlg.GetPath() 517 mypath = os.path.basename(path) 518 519 #TODO: This is bad design. The DataLoader is designed 520 #to recognize extensions. 521 # It should be a simple matter of calling the . 522 #save(file, data, '.xml') method 523 # of the DataLoader.loader.Loader class. 524 from DataLoader.loader import Loader 525 #Instantiate a loader 526 loader = Loader() 527 data = self.plots[self.graph.selected_plottable] 528 format = ".txt" 529 if os.path.splitext(mypath)[1].lower() == format: 530 self._onsaveTXT( path) 531 format = ".xml" 532 if os.path.splitext(mypath)[1].lower() == format: 533 loader.save(path, data, format) 534 try: 535 self._default_save_location = os.path.dirname(path) 536 except: 537 pass 538 dlg.Destroy() 382 #TODO: This is bad design. The DataLoader is designed 383 #to recognize extensions. 384 # It should be a simple matter of calling the . 385 #save(file, data, '.xml') method 386 # of the DataLoader.loader.Loader class. 387 from DataLoader.loader import Loader 388 #Instantiate a loader 389 loader = Loader() 390 data = self.plots[self.graph.selected_plottable] 391 format = ".txt" 392 if os.path.splitext(mypath)[1].lower() == format: 393 self._onsaveTXT( path) 394 format = ".xml" 395 if os.path.splitext(mypath)[1].lower() == format: 396 loader.save(path, data, format) 397 try: 398 self._default_save_location = os.path.dirname(path) 399 except: 400 pass 401 dlg.Destroy() -
guiframe/local_perspectives/plotting/Plotter2D.py
red8ad21 ra07e72f 23 23 from sans.guiframe.events import StatusEvent 24 24 from sans.guiframe.events import NewPlotEvent 25 from sans.guiframe.events import PanelOnFocusEvent 25 26 from sans.guiframe.events import SlicerEvent 26 27 from sans.guiframe.utils import PanelMenu … … 122 123 self.default_zmax_ctl = self.zmax_2D 123 124 125 def onLeftDown(self, event): 126 """ 127 left button down and ready to drag 128 129 """ 130 # Check that the LEFT button was pressed 131 if event.button == 1: 132 self.leftdown = True 133 ax = event.inaxes 134 if ax != None: 135 self.xInit, self.yInit = event.xdata, event.ydata 136 self.plottable_selected(self.data2D.id) 137 138 self._manager.set_panel_on_focus(self) 139 wx.PostEvent(self.parent, PanelOnFocusEvent(panel=self)) 140 124 141 def add_toolbar(self): 125 142 """ … … 138 155 self.toolbar.update() 139 156 140 def _onEVT_1DREPLOT(self, event):157 def plot_data(self, data): 141 158 """ 142 159 Data is ready to be displayed … … 149 166 """ 150 167 ## Update self.data2d with the current plot 151 self.data2D = event.plot 152 153 #TODO: Check for existence of plot attribute 154 155 # Check whether this is a replot. If we ask for a replot 156 # and the plottable no longer exists, ignore the event. 157 if hasattr(event, "update") and event.update == True \ 158 and event.plot.name not in self.plots.keys(): 159 return 160 if hasattr(event, "reset"): 161 self._reset() 162 is_new = True 163 if event.plot.name in self.plots.keys(): 164 # Check whether the class of plottable changed 165 if not event.plot.__class__ == self.plots[event.plot.name].__class__: 166 #overwrite a plottable using the same name 167 self.graph.delete(self.plots[event.plot.name]) 168 else: 169 # plottable is already draw on the panel 170 is_new = False 171 172 if is_new: 173 # a new plottable overwrites a plotted one using the same id 174 for plottable in self.plots.itervalues(): 175 if hasattr(event.plot,"id"): 176 if event.plot.id == plottable.id: 177 self.graph.delete(plottable) 178 179 self.plots[event.plot.name] = event.plot 180 self.graph.add(self.plots[event.plot.name]) 168 self.data2D = data 169 if data.id in self.plots.keys(): 170 #replace 171 self.graph.replace(data) 172 self.plots[data.id] = data 181 173 else: 182 # Update the plottable with the new data 183 184 #TODO: we should have a method to do this, 185 # something along the lines of: 186 # plottable1.update_data_from_plottable(plottable2) 187 188 self.plots[event.plot.name].xmin = event.plot.xmin 189 self.plots[event.plot.name].xmax = event.plot.xmax 190 self.plots[event.plot.name].ymin = event.plot.ymin 191 self.plots[event.plot.name].ymax = event.plot.ymax 192 self.plots[event.plot.name].data = event.plot.data 193 self.plots[event.plot.name].qx_data = event.plot.qx_data 194 self.plots[event.plot.name].qy_data = event.plot.qy_data 195 self.plots[event.plot.name].err_data = event.plot.err_data 174 self.plots[data.id] = data 175 self.graph.add(self.plots[data.id]) 196 176 # update qmax with the new xmax of data plotted 197 self.qmax = event.plot.xmax177 self.qmax = data.xmax 198 178 199 179 self.slicer = None … … 204 184 #data2D: put 'Pixel (Number)' for axis title and unit in case of having no detector info and none in _units 205 185 if len(self.data2D.detector) < 1: 206 if len( event.plot._xunit) < 1 and len(event.plot._yunit) < 1:207 event.plot._xaxis = '\\rm{x}'208 event.plot._yaxis = '\\rm{y}'209 event.plot._xunit = 'pixel'210 event.plot._yunit = 'pixel'211 self.graph.xaxis( event.plot._xaxis, event.plot._xunit)212 self.graph.yaxis( event.plot._yaxis, event.plot._yunit)186 if len(data._xunit) < 1 and len(data._yunit) < 1: 187 data._xaxis = '\\rm{x}' 188 data._yaxis = '\\rm{y}' 189 data._xunit = 'pixel' 190 data._yunit = 'pixel' 191 self.graph.xaxis(data._xaxis, data._xunit) 192 self.graph.yaxis(data._yaxis, data._yunit) 213 193 self.graph.title(self.data2D.name) 214 194 self.graph.render(self) … … 252 232 if len(self.data2D.detector) == 1: 253 233 254 item_list = self.parent.get_context_menu(self .graph)234 item_list = self.parent.get_context_menu(self) 255 235 if (not item_list == None) and (not len(item_list) == 0): 256 236 for item in item_list: -
guiframe/local_perspectives/plotting/plotting.py
rbf4402c3 ra07e72f 17 17 from sans.guiframe.events import StatusEvent 18 18 from sans.guiframe.plugin_base import PluginBase 19 from sans.guiframe.dataFitting import Data1D 20 from sans.guiframe.dataFitting import Data2D 19 21 20 22 class Plugin(PluginBase): … … 28 30 ## Plot panels 29 31 self.plot_panels = [] 30 32 self.new_plot_panels = {} 33 self._panel_on_focus = None 34 35 def set_panel_on_focus(self, panel): 36 """ 37 """ 38 self._panel_on_focus = panel 39 31 40 def is_always_active(self): 32 41 """ … … 76 85 77 86 """ 87 if hasattr(event, 'remove'): 88 group_id = event.group_id 89 id = event.id 90 if group_id in self.new_plot_panels.keys(): 91 panel = self.new_plot_panels[group_id] 92 panel.remove_data_by_id(id=id) 93 else: 94 msg = "Panel with GROUP_ID: %s canot be located" % str(group_id) 95 raise ValueError, msg 96 return 78 97 # Check whether we already have a graph with the same units 79 98 # as the plottable we just received. 80 is_available = False 81 for panel in self.plot_panels: 82 if event.plot._xunit == panel.graph.prop["xunit_base"] \ 83 and event.plot._yunit == panel.graph.prop["yunit_base"]: 84 if hasattr(event.plot, "group_id"): 85 ## if same group_id used the same panel to plot 86 if not event.plot.group_id == None \ 87 and event.plot.group_id == panel.group_id: 88 is_available = True 89 panel._onEVT_1DREPLOT(event) 90 self.parent.show_panel(panel.uid) 91 else: 92 # Check that the plot panel has no group ID 93 ## Use a panel with group_id ==None to plot 94 if panel.group_id == None: 95 is_available = True 96 panel._onEVT_1DREPLOT(event) 97 self.parent.show_panel(panel.uid) 98 # Create a new plot panel if none was available 99 if not is_available: 100 #print"event.plot",hasattr(event.plot,'data') 101 if not hasattr(event.plot, 'data'): 99 data = event.plot 100 101 group_id_list = data.group_id 102 group_id = None 103 if group_id_list: 104 group_id = group_id_list[len(group_id_list)-1] 105 if group_id in self.new_plot_panels.keys(): 106 panel = self.new_plot_panels[group_id] 107 _, x_unit = data.get_xaxis() 108 _, y_unit = data.get_yaxis() 109 110 if x_unit != panel.graph.prop["xunit"] \ 111 or y_unit != panel.graph.prop["yunit"]: 112 msg = "Cannot add %s" % str(data.name) 113 msg += " to panel %s\n" % str(panel.window_caption) 114 msg += "Please edit %s's units, labels" % str(data.name) 115 raise ValueError, msg 116 else: 117 panel.plot_data( data) 118 self.parent.show_panel(panel.uid) 119 else: 120 # Create a new plot panel if none was available 121 if issubclass(data.__class__, Data1D): 102 122 from Plotter1D import ModelPanel1D 103 123 ## get the data representation label of the data to plot 104 124 ## when even the user select "change scale" 105 if hasattr(event.plot, "xtransform"): 106 xtransform = event.plot.xtransform 107 else: 108 xtransform = None 109 110 if hasattr(event.plot, "ytransform"): 111 ytransform = event.plot.ytransform 112 else: 113 ytransform = None 125 xtransform = data.xtransform 126 ytransform = data.ytransform 114 127 ## create a plotpanel for 1D Data 115 128 new_panel = ModelPanel1D(self.parent, -1, xtransform=xtransform, 116 129 ytransform=ytransform, style=wx.RAISED_BORDER) 117 else: 130 new_panel.set_manager(self) 131 new_panel.group_id = group_id 132 elif issubclass(data.__class__, Data2D): 118 133 ##Create a new plotpanel for 2D data 119 134 from Plotter2D import ModelPanel2D 120 if hasattr(event.plot, "scale"): 121 scale = event.plot.scale 122 else: 123 scale = 'log' 135 scale = data.scale 124 136 new_panel = ModelPanel2D(self.parent, id = -1, 125 137 data2d=event.plot, scale = scale, 126 138 style=wx.RAISED_BORDER) 139 new_panel.set_manager(self) 140 new_panel.group_id = group_id 141 else: 142 msg = "Plotting received unexpected" 143 msg += " data type : %s" % str(data.__class__) 144 raise ValueError, msg 127 145 ## Set group ID if available 128 146 ## Assign data properties to the new create panel 129 group_id_str = '' 130 if hasattr(event.plot, "group_id"): 131 if not event.plot.group_id == None: 132 new_panel.group_id = event.plot.group_id 133 group_id_str = ' [%s]' % event.plot.group_id 134 if hasattr(event, "title"): 135 new_panel.window_caption = event.title 136 new_panel.window_name = event.title 147 title = data.title 148 new_panel.window_caption = title 149 new_panel.window_name = title 137 150 event_id = self.parent.popup_panel(new_panel) 138 151 #remove the default item in the menu 139 if len(self. plot_panels) == 0:152 if len(self.new_plot_panels) == 0: 140 153 self.menu.RemoveItem(self.menu.FindItemByPosition(0)) 141 154 self.menu.Append(event_id, new_panel.window_caption, … … 144 157 new_panel.uid = event_id 145 158 # Ship the plottable to its panel 146 new_panel._onEVT_1DREPLOT(event) 147 self.plot_panels.append(new_panel) 159 new_panel.plot_data(data) 160 self.plot_panels.append(new_panel) 161 self.new_plot_panels[new_panel.group_id] = new_panel 148 162 149 163 return 150 164 -
guiframe/plugin_base.py
r03314e7 ra07e72f 143 143 144 144 145 def get_context_menu(self, graph=None):145 def get_context_menu(self, plotpanel=None): 146 146 """ 147 147 This method is optional. … … 151 151 chance to add a menu item to the context menu. 152 152 153 A ref to a Graphobject is passed so that you can153 A ref to a plotpanel object is passed so that you can 154 154 investigate the plot content and decide whether you 155 155 need to add items to the context menu. -
invariantview/perspectives/invariant/invariant.py
rcb69775 ra07e72f 18 18 import logging 19 19 20 from DataLoader.data_info import Data1D as LoaderData1D 21 from sans.guiframe.dataFitting import Theory1D 20 22 21 from sans.guiframe.dataFitting import Data1D 23 24 22 from sans.guiframe.events import NewPlotEvent 25 from sans.guiframe. events import ERR_DATA23 from sans.guiframe.gui_style import GUIFRAME_ID 26 24 from .invariant_state import Reader as reader 27 25 from DataLoader.loader import Loader 28 26 from .invariant_panel import InvariantPanel 29 #from sans.guiframe.events import EVT_INVSTATE_UPDATE30 31 27 from sans.guiframe.plugin_base import PluginBase 32 28 … … 80 76 ## Save a reference to the parent 81 77 self.parent = parent 82 #add error back to the data83 self.parent.Bind(ERR_DATA, self._on_data_error)84 #self.parent.Bind(EVT_INVSTATE_UPDATE, self.on_set_state_helper)85 86 78 self.invariant_panel = InvariantPanel(parent=self.parent) 87 79 self.invariant_panel.set_manager(manager=self) … … 96 88 return [self.invariant_panel] 97 89 98 def get_context_menu(self, graph=None):90 def get_context_menu(self, plotpanel=None): 99 91 """ 100 92 This method is optional. … … 117 109 :return: a list of menu items with call-back function 118 110 """ 119 self.graph =graph111 graph = plotpanel.graph 120 112 invariant_option = "Compute invariant" 121 113 invariant_hint = "Will displays the invariant panel for" 122 114 invariant_hint += " futher computation" 123 124 for item in self.graph.plottables: 125 if item.name == graph.selected_plottable : 126 if issubclass(item.__class__, LoaderData1D): 127 128 if item.name != "$I_{obs}(q)$" and \ 129 item.name != " $P_{fit}(r)$": 130 if hasattr(item, "group_id"): 131 return [[invariant_option, 132 invariant_hint, 115 116 if graph.selected_plottable not in plotpanel.plots: 117 return [] 118 data = plotpanel.plots[graph.selected_plottable] 119 120 if not issubclass(data.__class__, Data1D): 121 name = data.__class__.__name__ 122 msg = "Invariant use only Data1D got: [%s] " % str(name) 123 raise ValueError, msg 124 125 if data.name != "$I_{obs}(q)$" and data.name != " $P_{fit}(r)$": 126 return [[invariant_option, invariant_hint, 133 127 self._compute_invariant]] 134 return [] 135 136 def copy_data(self, item, dy=None): 137 """ 138 receive a data 1D and the list of errors on dy 139 and create a new data1D data 140 """ 141 id = None 142 if hasattr(item,"id"): 143 id = item.id 144 145 data = Data1D(x=item.x, y=item.y, dx=None, dy=None) 146 data.copy_from_datainfo(item) 147 item.clone_without_data(clone=data) 148 data.dy = dy 149 data.name = item.name 150 data.title = item.title 151 152 ## allow to highlight data when plotted 153 data.interactive = item.interactive 154 ## when 2 data have the same id override the 1 st plotted 155 data.id = id 156 data.group_id = item.group_id 157 return data 158 159 def _on_data_error(self, event): 160 """ 161 receives and event from plotting plu-gins to store the data name and 162 their errors of y coordinates for 1Data hide and show error 163 """ 164 self.err_dy = event.err_dy 165 128 return [] 129 166 130 def _compute_invariant(self, event): 167 131 """ … … 170 134 self.panel = event.GetEventObject() 171 135 Plugin.on_perspective(self, event=event) 172 for plottable in self.panel.graph.plottables: 173 if plottable.name == self.panel.graph.selected_plottable: 174 ## put the errors values back to the model if the errors 175 ## were hiden before sending them to the fit engine 176 if len(self.err_dy) > 0: 177 dy = plottable.dy 178 if plottable.name in self.err_dy.iterkeys(): 179 dy = self.err_dy[plottable.name] 180 data = self.copy_data(plottable, dy) 181 else: 182 data = plottable 183 self.compute_helper(data=data) 136 id = self.panel.graph.selected_plottable 137 data = self.panel.plots[self.panel.graph.selected_plottable] 138 if data is None: 139 return 140 if not issubclass(data.__class__, Data1D): 141 name = data.__class__.__name__ 142 msg = "Invariant use only Data1D got: [%s] " % str(name) 143 raise ValueError, msg 144 self.compute_helper(data=data) 184 145 185 146 def set_data(self, data_list): … … 187 148 receive a list of data and compute invariant 188 149 """ 150 data = None 189 151 if len(data_list) > 1: 190 152 msg = "invariant panel does not allow multiple data!\n" … … 194 156 if dlg.ShowModal() == wx.ID_OK: 195 157 data = dlg.get_data() 196 if issubclass(data.__class__, LoaderData1D):197 wx.PostEvent(self.parent, NewPlotEvent(plot=data_list[0],198 title=data_list[0].title))199 self.compute_helper(data_list[0])200 else:201 msg = "invariant cannot be computed for data of "202 msg += "type %s" % (data_list[0].__class__.__name__)203 wx.PostEvent(self.parent,204 StatusEvent(status=msg, info='error'))205 158 elif len(data_list) == 1: 206 if issubclass(data_list[0].__class__, LoaderData1D): 207 wx.PostEvent(self.parent, NewPlotEvent(plot=data_list[0], 208 title=data_list[0].title)) 209 self.compute_helper(data_list[0]) 210 else: 211 msg = "invariant cannot be computed for" 212 msg += " data of type %s" % (data_list[0].__class__.__name__) 213 wx.PostEvent(self.parent, 214 StatusEvent(status=msg, info='error')) 215 216 159 data = data_list[0] 160 if data is None: 161 return 162 if issubclass(data.__class__, Data1D): 163 wx.PostEvent(self.parent, NewPlotEvent(plot=data, 164 title=data.title)) 165 self.compute_helper(data) 166 else: 167 msg = "invariant cannot be computed for data of " 168 msg += "type %s" % (data.__class__.__name__) 169 wx.PostEvent(self.parent, 170 StatusEvent(status=msg, info='error')) 171 217 172 def clear_panel(self): 173 """ 174 """ 218 175 self.invariant_panel.clear_panel() 219 176 … … 311 268 #import copy 312 269 if data is None: 313 new_plot = Theory1D(x=[], y=[], dy=None) 270 id = str(self.__data.id) + name 271 self.__data.group_id 272 wx.PostEvent(self.parent, NewPlotEvent(id=id, 273 group_id=group_id, 274 remove=true)) 275 return 276 277 new_plot = Data1D(x=[], y=[], dy=None) 278 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 279 scale = self.invariant_panel.get_scale() 280 background = self.invariant_panel.get_background() 281 282 if scale != 0: 283 # Put back the sacle and bkg for plotting 284 data.y = (data.y + background)/scale 285 new_plot = Data1D(x=data.x, y=data.y, dy=None) 286 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 314 287 else: 315 scale = self.invariant_panel.get_scale() 316 background = self.invariant_panel.get_background() 317 318 if scale != 0: 319 # Put back the sacle and bkg for plotting 320 data.y = (data.y + background)/scale 321 new_plot = Theory1D(x=data.x, y=data.y, dy=None) 322 else: 323 msg = "Scale can not be zero." 324 raise ValueError, msg 325 288 msg = "Scale can not be zero." 289 raise ValueError, msg 290 if len(new_plot.x)== 0 : 291 return 292 326 293 new_plot.name = name 327 294 new_plot.xaxis(self.__data._xaxis, self.__data._xunit) 328 295 new_plot.yaxis(self.__data._yaxis, self.__data._yunit) 329 296 new_plot.group_id = self.__data.group_id 330 new_plot.id = s elf.__data.id+ name297 new_plot.id = str(self.__data.id) + name 331 298 new_plot.title = self.__data.title 332 299 # Save theory_data in a state -
invariantview/perspectives/invariant/invariant_panel.py
r97ec26b ra07e72f 364 364 name="Low-Q extrapolation") 365 365 except: 366 raise 366 367 self.inv_container.qstar_low = "ERROR" 367 368 self.inv_container.qstar_low_err = "ERROR" … … 393 394 name="High-Q extrapolation") 394 395 except: 396 raisee 395 397 self.inv_container.qstar_high = "ERROR" 396 398 self.inv_container.qstar_high_err = "ERROR" -
prview/perspectives/pr/inversion_state.py
r229da98 ra07e72f 17 17 from xml.dom.minidom import parse 18 18 from lxml import etree 19 import DataLoader 19 from sans.guiframe.dataFitting import Data1D 20 20 from DataLoader.readers.cansas_reader import Reader as CansasReader 21 21 from DataLoader.readers.cansas_reader import get_content … … 519 519 """ 520 520 if datainfo is None: 521 datainfo = Data Loader.data_info.Data1D(x=[], y=[])522 elif not issubclass(datainfo.__class__, Data Loader.data_info.Data1D):521 datainfo = Data1D(x=[], y=[]) 522 elif not issubclass(datainfo.__class__, Data1D): 523 523 msg = "The cansas writer expects a Data1D " 524 524 msg += "instance: %s" % str(datainfo.__class__.__name__) -
prview/perspectives/pr/pr.py
r229da98 ra07e72f 24 24 import pylab 25 25 from sans.guiframe.dataFitting import Data1D 26 from sans.guiframe.dataFitting import Theory1D27 26 from sans.guiframe.events import NewPlotEvent 28 from sans.guiframe.events import StatusEvent 29 27 from sans.guiframe.events import StatusEvent 28 from sans.guiframe.gui_style import GUIFRAME_ID 30 29 from sans.pr.invertor import Invertor 31 30 from DataLoader.loader import Loader 32 from DataLoader.data_info import Data1D as LoaderData1D 33 import DataLoader 31 34 32 from pr_widgets import load_error 35 33 from sans.guiframe.plugin_base import PluginBase … … 41 39 IQ_FIT_LABEL = r"$I_{fit}(q)$" 42 40 IQ_SMEARED_LABEL = r"$I_{smeared}(q)$" 43 44 #import wx.lib45 #(NewPrFileEvent, EVT_PR_FILE) = wx.lib.newevent.NewEvent()46 47 41 48 42 … … 103 97 104 98 # Associate the inversion state reader with .prv files 105 from DataLoader.loader import Loader106 99 from inversion_state import Reader 107 100 … … 166 159 self.control_panel.set_state(state) 167 160 except: 168 raise 169 #logging.error("prview.set_state: %s" % sys.exc_value) 161 logging.error("prview.set_state: %s" % sys.exc_value) 170 162 171 163 … … 188 180 """ 189 181 from sans.pr.invertor import Invertor 190 191 from danse.common.plottools import Data1D as PlotData1D192 from danse.common.plottools import Theory1D as Theory1D193 194 182 # Generate P(r) for sphere 195 183 radius = 60.0 … … 220 208 for i in range(len(out)): 221 209 print "%g +- %g" % (out[i], math.sqrt(cov[i][i])) 222 210 223 211 # Show input P(r) 224 new_plot = PlotData1D(pr.x, pr.y, dy=pr.err) 212 title = "Pr" 213 new_plot = Data1D(pr.x, pr.y, dy=pr.err) 225 214 new_plot.name = "P_{obs}(r)" 226 215 new_plot.xaxis("\\rm{r}", 'A') 227 216 new_plot.yaxis("\\rm{P(r)} ","cm^{-3}") 228 print "_fit_pr" 229 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Pr")) 217 group_id = "P_{obs}(r)" 218 if group_id not in new_plot.group_id: 219 new_plot.group_id.append(group_id) 220 new_plot.id = "P_{obs}(r)" 221 new_plot.title = title 222 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=title)) 230 223 231 224 # Show P(r) fit … … 239 232 """ 240 233 """ 241 from danse.common.plottools import Theory1D as PlotTheory1D242 234 # Show P(r) 243 235 y_true = numpy.zeros(len(x)) … … 251 243 252 244 # Show the theory P(r) 253 new_plot = PlotTheory1D(x, y_true) 245 new_plot = Data1D(x, y_true) 246 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 254 247 new_plot.name = "P_{true}(r)" 255 248 new_plot.xaxis("\\rm{r}", 'A') … … 272 265 """ 273 266 """ 274 from danse.common.plottools import Theory1D as PlotTheory1D275 276 267 qtemp = pr.x 277 268 if not q==None: … … 304 295 print "Error getting error", value, x[i] 305 296 306 new_plot = PlotTheory1D(x, y) 297 new_plot = Data1D(x, y) 298 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 307 299 new_plot.name = IQ_FIT_LABEL 308 300 new_plot.xaxis("\\rm{Q}", 'A^{-1}') 309 301 new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 310 311 302 title = "I(q)" 303 new_plot.title = title 304 312 305 # If we have a group ID, use it 313 306 if pr.info.has_key("plot_group_id"): 314 new_plot.group_id = pr.info["plot_group_id"] 315 title = pr.info["plot_group_id"] 316 307 if len( pr.info["plot_group_id"]) > 0: 308 index = len( pr.info["plot_group_id"]) - 1 309 new_plot.group_id.append( pr.info["plot_group_id"][index]) 310 new_plot.id = IQ_FIT_LABEL 311 #new_plot.group_id.append(2) 317 312 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=title)) 318 313 … … 331 326 print "Error getting error", value, x[i] 332 327 333 new_plot = Theory1D(x, y) 328 new_plot = Data1D(x, y) 329 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 334 330 new_plot.name = IQ_SMEARED_LABEL 335 331 new_plot.xaxis("\\rm{Q}", 'A^{-1}') … … 337 333 # If we have a group ID, use it 338 334 if pr.info.has_key("plot_group_id"): 339 new_plot.group_id = pr.info["plot_group_id"] 335 if len( pr.info["plot_group_id"]) > 0: 336 index = len( pr.info["plot_group_id"]) - 1 337 new_plot.group_id.append( pr.info["plot_group_id"][index]) 338 339 new_plot.id = IQ_SMEARED_LABEL 340 new_plot.title = title 341 #new_plot.group_id.append(2) 340 342 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=title)) 341 343 … … 359 361 """ 360 362 """ 361 from danse.common.plottools import Data1D as PlotData1D362 from danse.common.plottools import Theory1D as PlotTheory1D363 364 363 # Show P(r) 365 364 x = pylab.arange(0.0, pr.d_max, pr.d_max/self._pr_npts) … … 394 393 395 394 if cov2==None: 396 new_plot = PlotTheory1D(x, y) 395 new_plot = Data1D(x, y) 396 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 397 397 else: 398 new_plot = PlotData1D(x, y, dy=dy)398 new_plot = Data1D(x, y, dy=dy) 399 399 new_plot.name = PR_FIT_LABEL 400 400 new_plot.xaxis("\\rm{r}", 'A') 401 401 new_plot.yaxis("\\rm{P(r)} ","cm^{-3}") 402 402 new_plot.title = "P(r) fit" 403 new_plot.id = PR_FIT_LABEL 403 404 # Make sure that the plot is linear 404 405 new_plot.xtransform = "x" … … 563 564 return 0.0 564 565 565 def get_context_menu(self, graph=None):566 def get_context_menu(self, plotpanel=None): 566 567 """ 567 568 Get the context menu items available for P(r) … … 572 573 573 574 """ 575 graph = plotpanel.graph 574 576 # Look whether this Graph contains P(r) data 575 #if graph.selected_plottable==IQ_DATA_LABEL: 576 for item in graph.plottables: 577 if item.name == PR_FIT_LABEL: 578 #add_data_hint = "Load a data file and display it on this plot" 579 #["Add P(r) data",add_data_hint , self._on_add_data], 580 change_n_hint = "Change the number of" 581 change_n_hint += " points on the P(r) output" 582 change_n_label = "Change number of P(r) points" 583 m_list = [[change_n_label, change_n_hint , self._on_pr_npts]] 584 585 if self._scale_output_unity or self._normalize_output: 586 hint = "Let the output P(r) keep the scale of the data" 587 m_list.append(["Disable P(r) scaling", hint, 588 self._on_disable_scaling]) 589 if not self._scale_output_unity: 590 m_list.append(["Scale P_max(r) to unity", 591 "Scale P(r) so that its maximum is 1", 592 self._on_scale_unity]) 593 if not self._normalize_output: 594 m_list.append(["Normalize P(r) to unity", 595 "Normalize the integral of P(r) to 1", 596 self._on_normalize]) 597 598 return m_list 599 #return [["Add P(r) data", 600 #"Load a data file and display it on this plot", 601 # self._on_add_data], 602 # ["Change number of P(r) points", 603 # "Change the number of points on the P(r) output", 604 # self._on_pr_npts]] 605 606 elif item.name == graph.selected_plottable: 607 #TODO: we might want to check that the units are 608 # consistent with I(q) before allowing this menu item 609 if not self.standalone and \ 610 issubclass(item.__class__, DataLoader.data_info.Data1D): 611 return [["Compute P(r)", 577 if graph.selected_plottable not in plotpanel.plots: 578 return [] 579 item = plotpanel.plots[graph.selected_plottable] 580 if item.id == PR_FIT_LABEL: 581 #add_data_hint = "Load a data file and display it on this plot" 582 #["Add P(r) data",add_data_hint , self._on_add_data], 583 change_n_hint = "Change the number of" 584 change_n_hint += " points on the P(r) output" 585 change_n_label = "Change number of P(r) points" 586 m_list = [[change_n_label, change_n_hint , self._on_pr_npts]] 587 588 if self._scale_output_unity or self._normalize_output: 589 hint = "Let the output P(r) keep the scale of the data" 590 m_list.append(["Disable P(r) scaling", hint, 591 self._on_disable_scaling]) 592 if not self._scale_output_unity: 593 m_list.append(["Scale P_max(r) to unity", 594 "Scale P(r) so that its maximum is 1", 595 self._on_scale_unity]) 596 if not self._normalize_output: 597 m_list.append(["Normalize P(r) to unity", 598 "Normalize the integral of P(r) to 1", 599 self._on_normalize]) 600 601 return m_list 602 603 elif item.id in [PR_LOADED_LABEL, IQ_DATA_LABEL, IQ_FIT_LABEL, 604 IQ_SMEARED_LABEL]: 605 return [] 606 elif item.id == graph.selected_plottable: 607 if not self.standalone and issubclass(item.__class__, Data1D): 608 return [["Compute P(r)", 612 609 "Compute P(r) from distribution", 613 610 self._on_context_inversion]] … … 657 654 y = self._added_plots[plot].y/sum 658 655 659 new_plot = Theory1D(self._added_plots[plot].x, y) 656 new_plot = Data1D(self._added_plots[plot].x, y) 657 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 658 index = len(self._added_plots[plot].group_id) - 1 659 if group_id not in new_plot.group_id: 660 new_plot.group_id.append(group_id) 661 new_plot.id = self._added_plots[plot].id 662 new_plot.title = self._added_plots[plot].title 660 663 new_plot.name = self._added_plots[plot].name 661 664 new_plot.xaxis("\\rm{r}", 'A') … … 686 689 y = self._added_plots[plot].y/_max 687 690 688 new_plot = Theory1D(self._added_plots[plot].x, y) 691 new_plot = Data1D(self._added_plots[plot].x, y) 692 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 689 693 new_plot.name = self._added_plots[plot].name 690 694 new_plot.xaxis("\\rm{r}", 'A') … … 736 740 737 741 filename = os.path.basename(path) 738 739 #new_plot = Data1D(x, y, dy=err)740 new_plot = Theory1D(x, y)742 743 new_plot = Data1D(x, y) 744 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 741 745 new_plot.name = filename 742 746 new_plot.xaxis("\\rm{r}", 'A') … … 863 867 new_plot.xaxis("\\rm{Q}", 'A^{-1}') 864 868 new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 865 #new_plot.group_id = "test group" 869 if pr.info.has_key("plot_group_id"): 870 new_plot.group_id.append(pr.info["plot_group_id"]) 871 new_plot.id = IQ_DATA_LABEL 866 872 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Iq")) 867 873 … … 884 890 885 891 """ 886 print "show_data", data.name887 892 #if path is not None: 888 893 if data is not None: 889 894 try: 890 #pr = self._create_file_pr(path)891 895 pr = self._create_file_pr(data) 892 896 except: … … 902 906 903 907 # Make a plot of I(q) data 904 if self.pr.err==None: 905 new_plot = Theory1D(self.pr.x, self.pr.y) 908 if self.pr.err == None: 909 new_plot = Data1D(self.pr.x, self.pr.y) 910 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 906 911 else: 907 912 new_plot = Data1D(self.pr.x, self.pr.y, dy=self.pr.err) … … 910 915 new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 911 916 new_plot.interactive = True 912 #new_plot.group_id = "test group" 917 new_plot.group_id.append(IQ_DATA_LABEL) 918 new_plot.id = IQ_DATA_LABEL 919 new_plot.title = "I(q)" 913 920 wx.PostEvent(self.parent, 914 921 NewPlotEvent(plot=new_plot, title="I(q)", reset=reset)) 915 922 916 923 self.current_plottable = new_plot 917 self.current_plottable.group_id = IQ_DATA_LABEL918 919 920 924 # Get Q range 921 925 self.control_panel.q_min = self.pr.x.min() … … 1021 1025 # Keep track of the plot window title to ensure that 1022 1026 # we can overlay the plots 1023 if hasattr(self.current_plottable, "group_id"): 1027 if self.current_plottable.group_id: 1028 index = len(self.current_plottable.group_id) - 1 1029 group_id = self.current_plottable.group_id[index] 1024 1030 pr.info["plot_group_id"] = self.current_plottable.group_id 1025 1031 … … 1329 1335 if dlg.ShowModal() == wx.ID_OK: 1330 1336 data = dlg.get_data() 1331 if issubclass(data.__class__, LoaderData1D):1337 if issubclass(data.__class__, Data1D): 1332 1338 self.control_panel._change_file(evt=None, data=data) 1333 1339 else: … … 1337 1343 StatusEvent(status=msg, info='error')) 1338 1344 elif len(data_list) == 1: 1339 if issubclass(data_list[0].__class__, LoaderData1D):1345 if issubclass(data_list[0].__class__, Data1D): 1340 1346 self.control_panel._change_file(evt=None, data=data_list[0]) 1341 1347 else: -
prview/perspectives/pr/pr_widgets.py
raf91b68 ra07e72f 27 27 28 28 ## Set to True when the mouse is clicked while the whole string is selected 29 full_selection = False29 self.full_selection = False 30 30 ## Call back for EVT_SET_FOCUS events 31 31 _on_set_focus_callback = None -
sansview/sansview.py
r75fbd17 ra07e72f 74 74 self.gui.add_perspective(invariant_plug) 75 75 except: 76 logging.error("SansView: could not find Invariant plug-in module") 77 logging.error(sys.exc_value) 76 raise 77 #logging.error("SansView: could not find Invariant plug-in module") 78 #logging.error(sys.exc_value) 78 79 79 80 #Calculator perspective … … 85 86 logging.error("SansView: could not find Calculator plug-in module") 86 87 logging.error(sys.exc_value) 87 88 """ 88 89 # theory perspective 89 90 try: … … 93 94 except: 94 95 logging.error("SansView: could not find theory plug-in module") 95 logging.error(sys.exc_value) 96 logging.error(sys.exc_value) 97 """ 96 98 97 99 # Fitting perspective
Note: See TracChangeset
for help on using the changeset viewer.