source: sasview/guiframe/local_perspectives/plotting/plotting.py @ 1374fbe4

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 1374fbe4 was 50cbace, checked in by Gervaise Alina <gervyh@…>, 16 years ago

fixing 1 bug on plot2D model

  • Property mode set to 100644
File size: 5.8 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 danse.common.plottools
15#from danse.common.plottools.PlotPanel import PlotPanel
16#from danse.common.plottools.plottables import Graph,Data1D
17from sans.guicomm.events import EVT_NEW_PLOT
18from sans.guicomm.events import StatusEvent
19
20
21class Plugin:
22    """
23        Plug-in class to be instantiated by the GUI manager
24    """
25   
26    def __init__(self):
27        """
28            Initialize the plug-in
29        """
30        ## Plug-in name
31        self.sub_menu = "Plotting"
32       
33        ## Reference to the parent window
34        self.parent = None
35       
36        ## List of panels for the simulation perspective (names)
37        self.perspective = []
38       
39        ## Plot panels
40        self.plot_panels = []
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        # We have no initial panels for this plug-in
62       
63        return []
64   
65   
66    def get_perspective(self):
67        """
68            Get the list of panel names for this perspective
69        """
70        return self.perspective
71   
72    def on_perspective(self, event):
73        """
74            Call back function for the perspective menu item.
75            We notify the parent window that the perspective
76            has changed.
77            @param event: menu event
78        """
79        self.parent.set_perspective(self.perspective)
80   
81    def post_init(self):
82        """
83            Post initialization call back to close the loose ends
84            [Somehow openGL needs this call]
85        """
86        pass
87   
88    def _on_show_panel(self, event):
89        print "_on_show_panel"
90   
91    def _on_plot_event(self, event):
92        """
93            A new plottable is being shipped to the plotting plug-in.
94            Check whether we have a panel to put in on, or create
95            a new one
96            @param event: EVT_NEW_PLOT event
97        """
98        # Check whether we already have a graph with the same units
99        # as the plottable we just received.
100       
101        is_available = False
102        for panel in self.plot_panels:
103            if event.plot._xunit == panel.graph.prop["xunit_base"] \
104            and event.plot._yunit == panel.graph.prop["yunit_base"]:
105                if hasattr(event.plot, "group_id"):
106                    if not event.plot.group_id==None \
107                        and event.plot.group_id==panel.group_id:
108                        is_available = True
109                       
110                       
111                        panel._onEVT_1DREPLOT(event)
112                        self.parent.show_panel(panel.uid)
113                        print "went here for replottiing", event.plot.name
114                       
115                else:
116                    # Check that the plot panel has no group ID
117                    if panel.group_id==None:
118                        is_available = True
119                        panel._onEVT_1DREPLOT(event)
120                        self.parent.show_panel(panel.uid)
121       
122        # Create a new plot panel if none was available       
123        if not is_available:
124            if not hasattr(event.plot,'data'):
125                from Plotter1D import ModelPanel1D
126                if hasattr(event.plot,"xtransform"):
127                    print "went here"
128                    xtransform = event.plot.xtransform
129                else:
130                   
131                    xtransform =None
132                if hasattr(event.plot,"ytransform"):
133                    ytransform=  event.plot.ytransform
134                else:
135                    ytransform=None
136                new_panel = ModelPanel1D(self.parent, -1,xtransform=xtransform,
137                                         ytransform=ytransform, style=wx.RAISED_BORDER)
138            else:
139                from Plotter2D import ModelPanel2D
140                new_panel = ModelPanel2D(self.parent, -1, data2d=event.plot,style=wx.RAISED_BORDER)
141            # Set group ID if available
142            group_id_str = ''
143            if hasattr(event.plot, "group_id"):
144                if not event.plot.group_id==None:
145                    new_panel.group_id = event.plot.group_id
146                    group_id_str = ' [%s]' % event.plot.group_id
147           
148            if hasattr(event, "title"):
149                new_panel.window_caption = event.title
150                new_panel.window_name = event.title
151                #new_panel.window_caption = event.title+group_id_str
152                #new_panel.window_name = event.title+group_id_str
153           
154            event_id = self.parent.popup_panel(new_panel)
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._onEVT_1DREPLOT(event)
161            self.plot_panels.append(new_panel)       
162           
163        return
164       
Note: See TracBrowser for help on using the repository browser.