source: sasview/guiframe/local_perspectives/plotting/2plotting.py @ 743d75c

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 743d75c was 743d75c, checked in by Gervaise Alina <gervyh@…>, 16 years ago

plotting 2 d

  • Property mode set to 100644
File size: 5.3 KB
Line 
1"""
2This software was developed by the University of Tennessee as part of the
3Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
4project funded by the US National Science Foundation.
5
6See the license text in license.txt
7
8copyright 2008, University of Tennessee
9"""
10
11
12import wx
13import sys
14#import pylab
15from sans.guicomm.events import EVT_NEW_PLOT
16
17
18class Plugin:
19    """
20        Plug-in class to be instantiated by the GUI manager
21    """
22   
23    def __init__(self):
24        """
25            Initialize the plug-in
26        """
27        ## Plug-in name
28        self.sub_menu = "Plotting"
29       
30        ## Reference to the parent window
31        self.parent = None
32       
33        ## List of panels for the simulation perspective (names)
34        self.perspective = []
35       
36        ## Plot panels
37        self.plot_panels = []
38       
39
40    def populate_menu(self, id, parent):
41        """
42            Create a 'Plot' menu to list the panels
43            available for displaying
44            @param id: next available unique ID for wx events
45            @param parent: parent window
46        """
47        self.menu = wx.Menu()
48        return [(id, self.menu, "Plot")]
49   
50       
51    def get_panels(self, parent):
52        """
53            Create and return a list of panel objects
54        """
55        ## Save a reference to the parent
56        self.parent = parent
57        # Connect to plotting events
58        self.parent.Bind(EVT_NEW_PLOT, self._on_plot_event)
59       
60        # We have no initial panels for this plug-in
61        return []
62   
63    def get_perspective(self):
64        """
65            Get the list of panel names for this perspective
66        """
67        return self.perspective
68   
69    def on_perspective(self, event):
70        """
71            Call back function for the perspective menu item.
72            We notify the parent window that the perspective
73            has changed.
74            @param event: menu event
75        """
76        self.parent.set_perspective(self.perspective)
77   
78    def post_init(self):
79        """
80            Post initialization call back to close the loose ends
81            [Somehow openGL needs this call]
82        """
83        pass
84   
85    def _on_show_panel(self, event):
86        print "_on_show_panel"
87   
88    def _on_plot_event(self, event):
89        """
90            A new plottable is being shipped to the plotting plug-in.
91            Check whether we have a panel to put in on, or create
92            a new one
93            @param event: EVT_NEW_PLOT event
94        """
95        # Check whether we already have a graph with the same units
96        # as the plottable we just received.
97        is_available = False
98        for panel in self.plot_panels:
99            if event.plot._xunit == panel.graph.prop["xunit_base"] \
100            and event.plot._yunit == panel.graph.prop["yunit_base"]:
101                if hasattr(event.plot, "group_id"):
102                    if not event.plot.group_id==None \
103                        and event.plot.group_id==panel.group_id:
104                        is_available = True
105                        panel._onEVT_1DREPLOT(event)
106                        self.parent.show_panel(panel.uid)
107                else:
108                    # Check that the plot panel has no group ID
109                    if panel.group_id==None:
110                        is_available = True
111                        panel._onEVT_1DREPLOT(event)
112                        self.parent.show_panel(panel.uid)
113       
114        # Create a new plot panel if none was available       
115        if not is_available:
116            if event.plot.__class__.__name__=='Data1D':
117                from DataPanel import View1DPanel1D
118                new_panel = View1DPanel1D(self.parent, -1, style=wx.RAISED_BORDER)
119            if event.plot.__class__.__name__=='Data2D':
120                from DataPanel import View1DPanel2D
121               
122                new_panel = View1DPanel2D(self.parent, -1,style=wx.RAISED_BORDER)
123            #if event.plot.__class__.__name__=='Theory2D':
124            else:
125                from DataPanel import View1DModelPanel2D
126                new_panel = View1DModelPanel2D(self.parent, -1, style=wx.RAISED_BORDER)
127            # Set group ID if available
128            group_id_str = ''
129            if hasattr(event.plot, "group_id"):
130                if not event.plot.group_id==None:
131                    new_panel.group_id = event.plot.group_id
132                    group_id_str = ' [%s]' % event.plot.group_id
133           
134            if hasattr(event, "title"):
135                new_panel.window_caption = event.title
136                new_panel.window_name = event.title
137                #new_panel.window_caption = event.title+group_id_str
138                #new_panel.window_name = event.title+group_id_str
139           
140            event_id = self.parent.popup_panel(new_panel)
141            self.menu.Append(event_id, new_panel.window_caption, 
142                             "Show %s plot panel" % new_panel.window_caption)
143            # Set UID to allow us to reference the panel later
144            new_panel.uid = event_id
145            # Ship the plottable to its panel
146            new_panel._onEVT_1DREPLOT(event)
147            self.plot_panels.append(new_panel)       
148           
149        return
150       
Note: See TracBrowser for help on using the repository browser.