source: sasview/guiframe/local_perspectives/plotting/plotting.py @ 8b6f489

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 8b6f489 was c70eb7c, checked in by Gervaise Alina <gervyh@…>, 14 years ago

working data_panel

  • 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 
79    def _on_plot_event(self, event):
80        """
81        A new plottable is being shipped to the plotting plug-in.
82        Check whether we have a panel to put in on, or create
83        a new one
84       
85        :param event: EVT_NEW_PLOT event
86       
87        """
88        if hasattr(event, 'remove'):
89            group_id = event.group_id
90            id = event.id
91            if group_id in self.new_plot_panels.keys():
92                panel = self.new_plot_panels[group_id]
93                panel.remove_data_by_id(id=id)
94            else:
95                msg = "Panel with GROUP_ID: %s canot be located" % str(group_id)
96                raise ValueError, msg
97            return
98        # Check whether we already have a graph with the same units
99        # as the plottable we just received.
100        data = event.plot
101       
102        group_id_list = data.group_id
103        group_id = None
104        if group_id_list:
105            group_id = group_id_list[len(group_id_list)-1]
106        if group_id in self.new_plot_panels.keys():
107            panel = self.new_plot_panels[group_id]
108            _, x_unit =  data.get_xaxis()
109            _, y_unit =  data.get_yaxis()
110           
111            if x_unit != panel.graph.prop["xunit"] \
112                or  y_unit != panel.graph.prop["yunit"]:
113                msg = "Cannot add %s" % str(data.name)
114                msg += " to panel %s\n" % str(panel.window_caption)
115                msg += "Please edit %s's units, labels" % str(data.name)
116                raise ValueError, msg
117            else:
118                panel.plot_data( data)
119                self.parent.show_panel(panel.uid)   
120        else:
121            # Create a new plot panel if none was available       
122            if issubclass(data.__class__, Data1D):
123                from Plotter1D import ModelPanel1D
124                ## get the data representation label of the data to plot
125                ## when even the user select "change scale"
126                xtransform = data.xtransform
127                ytransform = data.ytransform
128                ## create a plotpanel for 1D Data
129                new_panel = ModelPanel1D(self.parent, -1, xtransform=xtransform,
130                         ytransform=ytransform, style=wx.RAISED_BORDER)
131                new_panel.set_manager(self)
132                new_panel.group_id = group_id
133            elif issubclass(data.__class__, Data2D):
134                ##Create a new plotpanel for 2D data
135                from Plotter2D import ModelPanel2D
136                scale = data.scale
137                new_panel = ModelPanel2D(self.parent, id = -1,
138                                    data2d=event.plot, scale = scale, 
139                                    style=wx.RAISED_BORDER)
140                new_panel.set_manager(self)
141                new_panel.group_id = group_id
142            else:
143                msg = "Plotting received unexpected"
144                msg += " data type : %s" % str(data.__class__)
145                raise ValueError, msg
146            ## Set group ID if available
147            ## Assign data properties to the new create panel
148            title = data.title
149            new_panel.window_caption = title
150            new_panel.window_name = title
151            event_id = self.parent.popup_panel(new_panel)
152            #remove the default item in the menu
153            if len(self.new_plot_panels) == 0:
154                self.menu.RemoveItem(self.menu.FindItemByPosition(0))
155            self.menu.Append(event_id, new_panel.window_caption, 
156                             "Show %s plot panel" % new_panel.window_caption)
157            # Set UID to allow us to reference the panel later
158            new_panel.uid = event_id
159            # Ship the plottable to its panel
160            new_panel.plot_data(data)
161            self.plot_panels.append(new_panel)       
162            self.new_plot_panels[new_panel.group_id] = new_panel
163           
164        return
165   
Note: See TracBrowser for help on using the repository browser.