source: sasview/sansguiframe/src/sans/guiframe/plugin_base.py @ 632adc4

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 632adc4 was 8c347a6, checked in by Gervaise Alina <gervyh@…>, 13 years ago

moving guiframe under sansguiframe

  • Property mode set to 100644
File size: 7.6 KB
Line 
1################################################################################
2#This software was developed by the University of Tennessee as part of the
3#Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
4#project funded by the US National Science Foundation.
5#
6#See the license text in license.txt
7#
8#copyright 2008, University of Tennessee
9################################################################################
10 
11class PluginBase:
12    """
13    This class defines the interface for a Plugin class
14    that can be used by the gui_manager.
15   
16    Plug-ins should be placed in a sub-directory called "perspectives".
17    For example, a plug-in called Foo should be place in "perspectives/Foo".
18    That directory contains at least two files:
19        perspectives/Foo/__init__.py contains two lines:
20       
21            PLUGIN_ID = "Foo plug-in 1.0"
22            from Foo import *
23           
24        perspectives/Foo/Foo.py contains the definition of the Plugin
25        class for the Foo plug-in. The interface of that Plugin class
26        should follow the interface of the class you are looking at.
27       
28    See dummyapp.py for a plugin example.
29    """
30   
31    def __init__(self, name="Test_plugin", standalone=True):
32        """
33            Abstract class for gui_manager Plugins.
34        """
35        # Define if the plugin is local to Viewerframe  and always active
36        self._always_active = False
37        ## Plug-in name. It will appear on the application menu.
38        self.sub_menu = name     
39        #standalone flag
40        self.standalone = standalone
41        ## Reference to the parent window. Filled by get_panels() below.
42        self.parent = None
43        #plugin state reader
44        self.state_reader = None 
45        self._extensions = ''
46        ## List of panels that you would like to open in AUI windows
47        #  for your plug-in. This defines your plug-in "perspective"
48        self.perspective = []
49        #flag to tell the current plugin that aaplication is in batch mode
50        self.batch_on = False
51       
52    def clear_panel(self):
53        """
54        clear all related panels
55        """
56    def get_extensions(self):
57        """
58        return state reader and its extensions
59        """
60        return self.state_reader, self._extensions
61   
62    def can_load_data(self):
63        """
64        if return True, then call handler to laod data
65        """
66        return False
67   
68    def use_data(self):
69        """
70        return True if these plugin use data
71        """
72        return True
73   
74    def is_in_use(self, data_id):
75        """
76        get a  data id a list of data name if data data is
77         currently used by the plugin and the name of the plugin
78       
79        data_name = 'None'
80        in_use = False
81        example [(data_name, self.sub_menu)]
82        """
83        return []
84   
85    def delete_data(self, data_id):
86        """
87        Delete all references of data which id are in data_list.
88        """
89       
90    def load_data(self, event):
91        """
92        Load  data
93        """
94        raise NotImplemented
95 
96    def load_folder(self, event):
97        """
98        Load entire folder
99        """
100        raise NotImplemented 
101   
102    def set_is_active(self, active=False):
103        """
104        """
105        self._always_active = active
106       
107    def is_always_active(self):
108        """
109        return True is this plugin is always active and it is local to guiframe
110        even if the user is switching between perspectives
111        """
112        return self._always_active
113   
114    def populate_file_menu(self):
115        """
116        Append menu item under file menu item of the frame
117        """
118        return []
119   
120    def populate_menu(self, parent):
121        """
122        Create and return the list of application menu
123        items for the plug-in.
124       
125        :param parent: parent window
126       
127        :return: plug-in menu
128       
129        """
130        return []
131   
132    def get_panels(self, parent):
133        """
134        Create and return the list of wx.Panels for your plug-in.
135        Define the plug-in perspective.
136       
137        Panels should inherit from DefaultPanel defined below,
138        or should present the same interface. They must define
139        "window_caption" and "window_name".
140       
141        :param parent: parent window
142       
143        :return: list of panels
144       
145        """
146        ## Save a reference to the parent
147        self.parent = parent
148       
149        # Return the list of panels
150        return []
151   
152 
153    def get_tools(self):
154        """
155        Returns a set of menu entries for tools
156        """
157        return []
158       
159   
160    def get_context_menu(self, plotpanel=None):
161        """
162        This method is optional.
163   
164        When the context menu of a plot is rendered, the
165        get_context_menu method will be called to give you a
166        chance to add a menu item to the context menu.
167       
168        A ref to a plotpanel object is passed so that you can
169        investigate the plot content and decide whether you
170        need to add items to the context menu. 
171       
172        This method returns a list of menu items.
173        Each item is itself a list defining the text to
174        appear in the menu, a tool-tip help text, and a
175        call-back method.
176       
177        :param graph: the Graph object to which we attach the context menu
178       
179        :return: a list of menu items with call-back function
180       
181        """
182        return []
183   
184    def get_perspective(self):
185        """
186        Get the list of panel names for this perspective
187        """
188        return self.perspective
189   
190    def on_perspective(self, event=None):
191        """
192        Call back function for the perspective menu item.
193        We notify the parent window that the perspective
194        has changed.
195       
196        :param event: menu event
197       
198        """
199        self.parent.set_current_perspective(self)
200        self.parent.set_perspective(self.perspective)
201       
202    def set_batch_selection(self, flag):
203        """
204        the plugin to its batch state if flag is True
205        """
206        self.batch_on = flag
207        self.on_batch_selection(self.batch_on)   
208   
209    def on_batch_selection(self, flag):
210        """
211        need to be overwritten by the derivated class
212        """
213   
214    def post_init(self):
215        """
216        Post initialization call back to close the loose ends
217        """
218        pass
219   
220    def set_default_perspective(self):
221        """
222       Call back method that True to notify the parent that the current plug-in
223       can be set as default  perspective.
224       when returning False, the plug-in is not candidate for an automatic
225       default perspective setting
226        """
227        if self.standalone:
228            return True
229        return False
230   
231    def set_state(self, state=None, datainfo=None):   
232        """
233        update state
234        """
235    def set_data(self, data_list=None):
236        """
237        receive a list of data and use it in the current perspective
238       
239        """
240    def set_theory(self, theory_list=None):
241        """
242        :param theory_list: list of information
243            related to available theory state
244        """
245        msg = "%s plugin: does not support import theory" % str(self.sub_menu)
246        raise ValueError, msg
247   
248    def on_set_state_helper(self, event):
249        """
250        update state
251        """
252   
Note: See TracBrowser for help on using the repository browser.