source: sasview/guiframe/local_perspectives/plotting/plotting.py @ 22b3fe1

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 22b3fe1 was a07e72f, checked in by Gervaise Alina <gervyh@…>, 13 years ago

remove other type of data into sansview

  • Property mode set to 100644
File size: 6.2 KB
Line 
1
2
3
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################################################################################
13
14import wx
15import sys
16from sans.guiframe.events import EVT_NEW_PLOT
17from sans.guiframe.events import StatusEvent
18from sans.guiframe.plugin_base import PluginBase
19from sans.guiframe.dataFitting import Data1D
20from sans.guiframe.dataFitting import Data2D
21
22class Plugin(PluginBase):
23    """
24    Plug-in class to be instantiated by the GUI manager
25    """
26   
27    def __init__(self, standalone=False):
28        PluginBase.__init__(self, name="Plotting", standalone=standalone)
29     
30        ## Plot panels
31        self.plot_panels = []
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       
40    def is_always_active(self):
41        """
42        return True is this plugin is always active even if the user is
43        switching between perspectives
44        """
45        return True
46   
47    def populate_menu(self, parent):
48        """
49        Create a 'Plot' menu to list the panels
50        available for displaying
51       
52        :param id: next available unique ID for wx events
53        :param parent: parent window
54       
55        """
56        self.menu = wx.Menu()
57       
58        self.menu.Append(wx.NewId(), "No plot available", 
59                             "No plot available")
60        self.menu.FindItemByPosition(0).Enable(False)
61        return [(self.menu, "Plot")]
62   
63    def get_panels(self, parent):
64        """
65        Create and return a list of panel objects
66        """
67        ## Save a reference to the parent
68        self.parent = parent
69        # Connect to plotting events
70        self.parent.Bind(EVT_NEW_PLOT, self._on_plot_event)
71        # We have no initial panels for this plug-in
72        return []
73   
74    def _on_show_panel(self, event):
75        """show plug-in panel"""
76        pass
77   
78    def _on_plot_event(self, event):
79        """
80        A new plottable is being shipped to the plotting plug-in.
81        Check whether we have a panel to put in on, or create
82        a new one
83       
84        :param event: EVT_NEW_PLOT event
85       
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
97        # Check whether we already have a graph with the same units
98        # as the plottable we just received.
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):
122                from Plotter1D import ModelPanel1D
123                ## get the data representation label of the data to plot
124                ## when even the user select "change scale"
125                xtransform = data.xtransform
126                ytransform = data.ytransform
127                ## create a plotpanel for 1D Data
128                new_panel = ModelPanel1D(self.parent, -1, xtransform=xtransform,
129                         ytransform=ytransform, style=wx.RAISED_BORDER)
130                new_panel.set_manager(self)
131                new_panel.group_id = group_id
132            elif issubclass(data.__class__, Data2D):
133                ##Create a new plotpanel for 2D data
134                from Plotter2D import ModelPanel2D
135                scale = data.scale
136                new_panel = ModelPanel2D(self.parent, id = -1,
137                                    data2d=event.plot, scale = scale, 
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
145            ## Set group ID if available
146            ## Assign data properties to the new create panel
147            title = data.title
148            new_panel.window_caption = title
149            new_panel.window_name = title
150            event_id = self.parent.popup_panel(new_panel)
151            #remove the default item in the menu
152            if len(self.new_plot_panels) == 0:
153                self.menu.RemoveItem(self.menu.FindItemByPosition(0))
154            self.menu.Append(event_id, new_panel.window_caption, 
155                             "Show %s plot panel" % new_panel.window_caption)
156            # Set UID to allow us to reference the panel later
157            new_panel.uid = event_id
158            # Ship the plottable to its 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
162           
163        return
164   
Note: See TracBrowser for help on using the repository browser.