source: sasview/guiframe/local_perspectives/plotting/plotting.py @ 015d109

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 015d109 was 7f84e22, checked in by Gervaise Alina <gervyh@…>, 14 years ago

make sure plugin plotting inheritate from pluginbase in guiframe

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