source: sasview/guiframe/local_perspectives/plotting/plotting.py @ a93f525

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 a93f525 was 4e9583c, checked in by Gervaise Alina <gervyh@…>, 14 years ago

reverse guiframe

  • Property mode set to 100644
File size: 6.4 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   
95    def _on_plot_event(self, event):
96        """
97        A new plottable is being shipped to the plotting plug-in.
98        Check whether we have a panel to put in on, or create
99        a new one
100       
101        :param event: EVT_NEW_PLOT event
102       
103        """
104        # Check whether we already have a graph with the same units
105        # as the plottable we just received.
106       
107        is_available = False
108        for panel in self.plot_panels:
109            if event.plot._xunit == panel.graph.prop["xunit_base"] \
110            and event.plot._yunit == panel.graph.prop["yunit_base"]:
111                if hasattr(event.plot, "group_id"):
112                    ## if same group_id used the same panel to plot
113                    if not event.plot.group_id==None \
114                        and event.plot.group_id==panel.group_id:
115                        is_available = True
116                       
117                        panel._onEVT_1DREPLOT(event)
118                        self.parent.show_panel(panel.uid)   
119                else:
120                    # Check that the plot panel has no group ID
121                    ## Use a panel with group_id ==None to plot
122                   
123                    if panel.group_id==None:
124                        is_available = True
125                        panel._onEVT_1DREPLOT(event)
126                        self.parent.show_panel(panel.uid)
127       
128        # Create a new plot panel if none was available       
129        if not is_available:
130            #print"event.plot",hasattr(event.plot,'data')
131            if not hasattr(event.plot,'data'):
132                from Plotter1D import ModelPanel1D
133                ## get the data representation label of the data to plot
134                ## when even the user select "change scale"
135                if hasattr(event.plot,"xtransform"):
136                    xtransform = event.plot.xtransform
137                else:
138                    xtransform =None
139                   
140                if hasattr(event.plot,"ytransform"):
141                    ytransform=  event.plot.ytransform
142                else:
143                    ytransform=None
144                ## create a plotpanel for 1D Data
145                new_panel = ModelPanel1D(self.parent, -1,xtransform=xtransform,
146                                         ytransform=ytransform, style=wx.RAISED_BORDER)
147
148            else:
149                ##Create a new plotpanel for 2D data
150                from Plotter2D import ModelPanel2D
151                new_panel = ModelPanel2D(self.parent, id = -1, data2d=event.plot,style=wx.RAISED_BORDER)
152           
153            ## Set group ID if available
154            ## Assign data properties to the new create panel
155            group_id_str = ''
156            if hasattr(event.plot, "group_id"):
157                if not event.plot.group_id==None:
158                    new_panel.group_id = event.plot.group_id
159                    group_id_str = ' [%s]' % event.plot.group_id
160           
161            if hasattr(event, "title"):
162                new_panel.window_caption = event.title
163                new_panel.window_name = event.title
164               
165            event_id = self.parent.popup_panel(new_panel)
166            #remove the default item in the menu
167            if len(self.plot_panels) == 0:
168                self.menu.RemoveItem(self.menu.FindItemByPosition(0))
169               
170            self.menu.Append(event_id, new_panel.window_caption, 
171                             "Show %s plot panel" % new_panel.window_caption)
172            # Set UID to allow us to reference the panel later
173            new_panel.uid = event_id
174            # Ship the plottable to its panel
175            new_panel._onEVT_1DREPLOT(event)
176            self.plot_panels.append(new_panel)       
177           
178        return
179       
Note: See TracBrowser for help on using the repository browser.