source: sasview/guiframe/local_perspectives/plotting/plotting.py @ 340c2b3

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 340c2b3 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
RevLine 
[41d466f]1
2
3
[d955bf19]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################################################################################
[41d466f]13
14import wx
15import sys
16from sans.guicomm.events import EVT_NEW_PLOT
[58eac5d]17from sans.guicomm.events import StatusEvent
[8a7a21b]18
[7f84e22]19from sans.guiframe.plugin_base import PluginBase
[7764b41]20
[7f84e22]21class Plugin(PluginBase):
[41d466f]22    """
[d955bf19]23    Plug-in class to be instantiated by the GUI manager
[41d466f]24    """
25   
[7f84e22]26    def __init__(self, standalone=False):
27        PluginBase.__init__(self, name="Plotting", standalone=standalone)
28     
[41d466f]29        ## Plot panels
30        self.plot_panels = []
[54cc36a]31       
[41d466f]32    def populate_menu(self, id, parent):
33        """
[d955bf19]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       
[41d466f]40        """
41        self.menu = wx.Menu()
[2fc9243]42       
43        self.menu.Append(wx.NewId(), "No plot available", 
44                             "No plot available")
45        self.menu.FindItemByPosition(0).Enable(False)
[41d466f]46        return [(id, self.menu, "Plot")]
47   
48    def get_panels(self, parent):
49        """
[d955bf19]50        Create and return a list of panel objects
[41d466f]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 []
[54cc36a]58   
[41d466f]59    def _on_show_panel(self, event):
[6c0568b]60        """show plug-in panel"""
61        pass
62   
[41d466f]63    def _on_plot_event(self, event):
64        """
[d955bf19]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       
[41d466f]71        """
72        # Check whether we already have a graph with the same units
73        # as the plottable we just received.
[ab8f936]74       
[41d466f]75        is_available = False
76        for panel in self.plot_panels:
[be72312c]77            if event.plot._xunit == panel.graph.prop["xunit_base"] \
78            and event.plot._yunit == panel.graph.prop["yunit_base"]:
[383189f9]79                if hasattr(event.plot, "group_id"):
[6c0568b]80                    ## if same group_id used the same panel to plot
[32c0841]81                    if not event.plot.group_id == None \
82                        and event.plot.group_id == panel.group_id:
[383189f9]83                        is_available = True
84                        panel._onEVT_1DREPLOT(event)
[6c0568b]85                        self.parent.show_panel(panel.uid)   
[383189f9]86                else:
87                    # Check that the plot panel has no group ID
[6c0568b]88                    ## Use a panel with group_id ==None to plot
[32c0841]89                    if panel.group_id == None:
[383189f9]90                        is_available = True
91                        panel._onEVT_1DREPLOT(event)
92                        self.parent.show_panel(panel.uid)
[41d466f]93        # Create a new plot panel if none was available       
94        if not is_available:
[7fff5cd]95            #print"event.plot",hasattr(event.plot,'data')
[32c0841]96            if not hasattr(event.plot, 'data'):
[1bf33c1]97                from Plotter1D import ModelPanel1D
[6c0568b]98                ## get the data representation label of the data to plot
99                ## when even the user select "change scale"
[32c0841]100                if hasattr(event.plot, "xtransform"):
[ffd23b5]101                    xtransform = event.plot.xtransform
102                else:
[32c0841]103                    xtransform = None
[6c0568b]104                   
[32c0841]105                if hasattr(event.plot, "ytransform"):
106                    ytransform = event.plot.ytransform
[ffd23b5]107                else:
[32c0841]108                    ytransform = None
[6c0568b]109                ## create a plotpanel for 1D Data
[32c0841]110                new_panel = ModelPanel1D(self.parent, -1, xtransform=xtransform,
111                         ytransform=ytransform, style=wx.RAISED_BORDER)
[743d75c]112            else:
[6c0568b]113                ##Create a new plotpanel for 2D data
[1bf33c1]114                from Plotter2D import ModelPanel2D
[32c0841]115                new_panel = ModelPanel2D(self.parent, id = -1,
116                                    data2d=event.plot, style=wx.RAISED_BORDER)
[6c0568b]117            ## Set group ID if available
118            ## Assign data properties to the new create panel
[383189f9]119            group_id_str = ''
120            if hasattr(event.plot, "group_id"):
[32c0841]121                if not event.plot.group_id == None:
[383189f9]122                    new_panel.group_id = event.plot.group_id
123                    group_id_str = ' [%s]' % event.plot.group_id
[41d466f]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)
[2fc9243]128            #remove the default item in the menu
129            if len(self.plot_panels) == 0:
130                self.menu.RemoveItem(self.menu.FindItemByPosition(0))
[41d466f]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
[4e9583c]140       
Note: See TracBrowser for help on using the repository browser.