source: sasview/guiframe/local_perspectives/plotting/plotting.py @ 212417e

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

override a plot update —> model can be plotted with unik name

  • Property mode set to 100644
File size: 5.2 KB
RevLine 
[41d466f]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
[b06ef8c]14#import danse.common.plottools
15#from danse.common.plottools.PlotPanel import PlotPanel
16#from danse.common.plottools.plottables import Graph,Data1D
[41d466f]17from sans.guicomm.events import EVT_NEW_PLOT
[58eac5d]18from sans.guicomm.events import StatusEvent
[7764b41]19
[41d466f]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
42    def populate_menu(self, id, parent):
43        """
44            Create a 'Plot' menu to list the panels
45            available for displaying
46            @param id: next available unique ID for wx events
47            @param parent: parent window
48        """
49        self.menu = wx.Menu()
50        return [(id, self.menu, "Plot")]
51   
52       
53    def get_panels(self, parent):
54        """
55            Create and return a list of panel objects
56        """
57        ## Save a reference to the parent
58        self.parent = parent
59        # Connect to plotting events
60        self.parent.Bind(EVT_NEW_PLOT, self._on_plot_event)
61       
62        # We have no initial panels for this plug-in
63        return []
64   
65    def get_perspective(self):
66        """
67            Get the list of panel names for this perspective
68        """
69        return self.perspective
70   
71    def on_perspective(self, event):
72        """
73            Call back function for the perspective menu item.
74            We notify the parent window that the perspective
75            has changed.
76            @param event: menu event
77        """
78        self.parent.set_perspective(self.perspective)
79   
80    def post_init(self):
81        """
82            Post initialization call back to close the loose ends
83            [Somehow openGL needs this call]
84        """
85        pass
86   
87    def _on_show_panel(self, event):
88        print "_on_show_panel"
89   
90    def _on_plot_event(self, event):
91        """
92            A new plottable is being shipped to the plotting plug-in.
93            Check whether we have a panel to put in on, or create
94            a new one
95            @param event: EVT_NEW_PLOT event
96        """
97        # Check whether we already have a graph with the same units
98        # as the plottable we just received.
[ab8f936]99       
[41d466f]100        is_available = False
101        for panel in self.plot_panels:
[be72312c]102            if event.plot._xunit == panel.graph.prop["xunit_base"] \
103            and event.plot._yunit == panel.graph.prop["yunit_base"]:
[383189f9]104                if hasattr(event.plot, "group_id"):
105                    if not event.plot.group_id==None \
106                        and event.plot.group_id==panel.group_id:
107                        is_available = True
108                        panel._onEVT_1DREPLOT(event)
109                        self.parent.show_panel(panel.uid)
110                else:
111                    # Check that the plot panel has no group ID
112                    if panel.group_id==None:
113                        is_available = True
114                        panel._onEVT_1DREPLOT(event)
115                        self.parent.show_panel(panel.uid)
[41d466f]116       
117        # Create a new plot panel if none was available       
118        if not is_available:
[c4172272]119            if not hasattr(event.plot,'data'):
[1bf33c1]120                from Plotter1D import ModelPanel1D
121                new_panel = ModelPanel1D(self.parent, -1, style=wx.RAISED_BORDER)
[743d75c]122            else:
[1bf33c1]123                from Plotter2D import ModelPanel2D
124                new_panel = ModelPanel2D(self.parent, -1, data2d=event.plot,style=wx.RAISED_BORDER)
[383189f9]125            # Set group ID if available
126            group_id_str = ''
127            if hasattr(event.plot, "group_id"):
128                if not event.plot.group_id==None:
129                    new_panel.group_id = event.plot.group_id
130                    group_id_str = ' [%s]' % event.plot.group_id
131           
[41d466f]132            if hasattr(event, "title"):
133                new_panel.window_caption = event.title
134                new_panel.window_name = event.title
[383189f9]135                #new_panel.window_caption = event.title+group_id_str
136                #new_panel.window_name = event.title+group_id_str
[41d466f]137           
138            event_id = self.parent.popup_panel(new_panel)
139            self.menu.Append(event_id, new_panel.window_caption, 
140                             "Show %s plot panel" % new_panel.window_caption)
141            # Set UID to allow us to reference the panel later
142            new_panel.uid = event_id
143            # Ship the plottable to its panel
144            new_panel._onEVT_1DREPLOT(event)
145            self.plot_panels.append(new_panel)       
146           
147        return
148       
Note: See TracBrowser for help on using the repository browser.