source: sasview/guiframe/local_perspectives/plotting/plotting.py @ 3658abed

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 3658abed was 32c0841, checked in by Gervaise Alina <gervyh@…>, 14 years ago

working on pylint

  • Property mode set to 100644
File size: 6.3 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.guicomm.events import EVT_NEW_PLOT
17from sans.guicomm.events import StatusEvent
18
19
20class Plugin:
21    """
22    Plug-in class to be instantiated by the GUI manager
23    """
24   
25    def __init__(self):
26        """
27        Initialize the plug-in
28        """
29        ## Plug-in name
30        self.sub_menu = "Plotting"
31       
32        ## Reference to the parent window
33        self.parent = None
34       
35        ## List of panels for the simulation perspective (names)
36        self.perspective = []
37       
38        ## Plot panels
39        self.plot_panels = []
40       
41    def populate_menu(self, id, parent):
42        """
43        Create a 'Plot' menu to list the panels
44        available for displaying
45       
46        :param id: next available unique ID for wx events
47        :param parent: parent window
48       
49        """
50        self.menu = wx.Menu()
51       
52        self.menu.Append(wx.NewId(), "No plot available", 
53                             "No plot available")
54        self.menu.FindItemByPosition(0).Enable(False)
55        return [(id, self.menu, "Plot")]
56   
57    def get_panels(self, parent):
58        """
59        Create and return a list of panel objects
60        """
61        ## Save a reference to the parent
62        self.parent = parent
63        # Connect to plotting events
64        self.parent.Bind(EVT_NEW_PLOT, self._on_plot_event)
65        # We have no initial panels for this plug-in
66        return []
67   
68    def get_perspective(self):
69        """
70        Get the list of panel names for this perspective
71        """
72        return self.perspective
73   
74    def on_perspective(self, event):
75        """
76            Call back function for the perspective menu item.
77            We notify the parent window that the perspective
78            has changed.
79            @param event: menu event
80        """
81        self.parent.set_perspective(self.perspective)
82   
83    def post_init(self):
84        """
85        Post initialization call back to close the loose ends
86        [Somehow openGL needs this call]
87        """
88        pass
89   
90    def _on_show_panel(self, event):
91        """show plug-in panel"""
92        pass
93   
94    def _on_plot_event(self, event):
95        """
96        A new plottable is being shipped to the plotting plug-in.
97        Check whether we have a panel to put in on, or create
98        a new one
99       
100        :param event: EVT_NEW_PLOT event
101       
102        """
103        # Check whether we already have a graph with the same units
104        # as the plottable we just received.
105       
106        is_available = False
107        for panel in self.plot_panels:
108            if event.plot._xunit == panel.graph.prop["xunit_base"] \
109            and event.plot._yunit == panel.graph.prop["yunit_base"]:
110                if hasattr(event.plot, "group_id"):
111                    ## if same group_id used the same panel to plot
112                    if not event.plot.group_id == None \
113                        and event.plot.group_id == panel.group_id:
114                        is_available = True
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                    if panel.group_id == None:
121                        is_available = True
122                        panel._onEVT_1DREPLOT(event)
123                        self.parent.show_panel(panel.uid)
124        # Create a new plot panel if none was available       
125        if not is_available:
126            #print"event.plot",hasattr(event.plot,'data')
127            if not hasattr(event.plot, 'data'):
128                from Plotter1D import ModelPanel1D
129                ## get the data representation label of the data to plot
130                ## when even the user select "change scale"
131                if hasattr(event.plot, "xtransform"):
132                    xtransform = event.plot.xtransform
133                else:
134                    xtransform = None
135                   
136                if hasattr(event.plot, "ytransform"):
137                    ytransform = event.plot.ytransform
138                else:
139                    ytransform = None
140                ## create a plotpanel for 1D Data
141                new_panel = ModelPanel1D(self.parent, -1, xtransform=xtransform,
142                         ytransform=ytransform, style=wx.RAISED_BORDER)
143            else:
144                ##Create a new plotpanel for 2D data
145                from Plotter2D import ModelPanel2D
146                new_panel = ModelPanel2D(self.parent, id = -1,
147                                    data2d=event.plot, style=wx.RAISED_BORDER)
148            ## Set group ID if available
149            ## Assign data properties to the new create panel
150            group_id_str = ''
151            if hasattr(event.plot, "group_id"):
152                if not event.plot.group_id == None:
153                    new_panel.group_id = event.plot.group_id
154                    group_id_str = ' [%s]' % event.plot.group_id
155            if hasattr(event, "title"):
156                new_panel.window_caption = event.title
157                new_panel.window_name = event.title
158            event_id = self.parent.popup_panel(new_panel)
159            #remove the default item in the menu
160            if len(self.plot_panels) == 0:
161                self.menu.RemoveItem(self.menu.FindItemByPosition(0))
162            self.menu.Append(event_id, new_panel.window_caption, 
163                             "Show %s plot panel" % new_panel.window_caption)
164            # Set UID to allow us to reference the panel later
165            new_panel.uid = event_id
166            # Ship the plottable to its panel
167            new_panel._onEVT_1DREPLOT(event)
168            self.plot_panels.append(new_panel)       
169           
170        return
171       
Note: See TracBrowser for help on using the repository browser.