source: sasview/src/sas/guiframe/plugin_base.py @ b9a5f0e

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 b9a5f0e was 79492222, checked in by krzywon, 10 years ago

Changed the file and folder names to remove all SANS references.

  • Property mode set to 100644
File size: 8.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
20    1. perspectives/Foo/__init__.py contains two lines: ::
21       
22        PLUGIN_ID = "Foo plug-in 1.0"
23        from Foo import *
24           
25    2. perspectives/Foo/Foo.py contains the definition of the Plugin
26       class for the Foo plug-in. The interface of that Plugin class
27       should follow the interface of the class you are looking at.
28       
29    See dummyapp.py for a plugin example.
30    """
31   
32    def __init__(self, name="Test_plugin", standalone=True):
33        """
34            Abstract class for gui_manager Plugins.
35        """
36        # Define if the plugin is local to Viewerframe  and always active
37        self._always_active = False
38        ## Plug-in name. It will appear on the application menu.
39        self.sub_menu = name     
40        #standalone flag
41        self.standalone = standalone
42        ## Reference to the parent window. Filled by get_panels() below.
43        self.parent = None
44        self.frame = None
45        #plugin state reader
46        self.state_reader = None 
47        self._extensions = ''
48        ## List of panels that you would like to open in AUI windows
49        #  for your plug-in. This defines your plug-in "perspective"
50        self.perspective = []
51        #flag to tell the current plugin that aaplication is in batch mode
52        self.batch_on = False
53        #properties for color and ID of a specific plugin..
54        self.color = None
55        self.id = -1
56        self.batch_capable = self.get_batch_capable()
57   
58    def get_batch_capable(self):
59        """
60        Check if the plugin has a batch capability
61        """
62        return False
63         
64    def add_color(self, color, id):
65        """
66        Adds color to a plugin
67        """
68       
69    def clear_panel(self):
70        """
71        clear all related panels
72        """
73    def get_extensions(self):
74        """
75        return state reader and its extensions
76        """
77        return self.state_reader, self._extensions
78   
79    def can_load_data(self):
80        """
81        if return True, then call handler to laod data
82        """
83        return False
84   
85    def use_data(self):
86        """
87        return True if these plugin use data
88        """
89        return True
90   
91    def is_in_use(self, data_id):
92        """
93        get a  data id a list of data name if data data is
94         currently used by the plugin and the name of the plugin
95       
96        data_name = 'None'
97        in_use = False
98        example [(data_name, self.sub_menu)]
99        """
100        return []
101   
102    def delete_data(self, data_id):
103        """
104        Delete all references of data which id are in data_list.
105        """
106       
107    def load_data(self, event):
108        """
109        Load  data
110        """
111        raise NotImplementedError
112 
113    def load_folder(self, event):
114        """
115        Load entire folder
116        """
117        raise NotImplementedError
118   
119    def set_is_active(self, active=False):
120        """
121        """
122        self._always_active = active
123       
124    def is_always_active(self):
125        """
126        return True is this plugin is always active and it is local to guiframe
127        even if the user is switching between perspectives
128        """
129        return self._always_active
130   
131    def populate_file_menu(self):
132        """
133        Append menu item under file menu item of the frame
134        """
135        return []
136   
137    def populate_menu(self, parent):
138        """
139        Create and return the list of application menu
140        items for the plug-in.
141       
142        :param parent: parent window
143       
144        :return: plug-in menu
145       
146        """
147        return []
148   
149    def get_frame(self):
150        """
151        Returns MDIChildFrame
152        """
153        return self.frame
154
155    def _frame_set_helper(self):
156        """
157        Sets default frame config
158        """
159        if self.frame != None:
160            self.frame.EnableCloseButton(False)
161            self.frame.Show(False)
162   
163    def get_panels(self, parent):
164        """
165        Create and return the list of wx.Panels for your plug-in.
166        Define the plug-in perspective.
167       
168        Panels should inherit from DefaultPanel defined below,
169        or should present the same interface. They must define
170        "window_caption" and "window_name".
171       
172        :param parent: parent window
173       
174        :return: list of panels
175       
176        """
177        ## Save a reference to the parent
178        self.parent = parent
179       
180        # Return the list of panels
181        return []
182   
183 
184    def get_tools(self):
185        """
186        Returns a set of menu entries for tools
187        """
188        return []
189       
190   
191    def get_context_menu(self, plotpanel=None):
192        """
193        This method is optional.
194   
195        When the context menu of a plot is rendered, the
196        get_context_menu method will be called to give you a
197        chance to add a menu item to the context menu.
198       
199        A ref to a plotpanel object is passed so that you can
200        investigate the plot content and decide whether you
201        need to add items to the context menu. 
202       
203        This method returns a list of menu items.
204        Each item is itself a list defining the text to
205        appear in the menu, a tool-tip help text, and a
206        call-back method.
207       
208        :param graph: the Graph object to which we attach the context menu
209       
210        :return: a list of menu items with call-back function
211       
212        """
213        return []
214   
215    def get_perspective(self):
216        """
217        Get the list of panel names for this perspective
218        """
219        return self.perspective
220   
221    def on_perspective(self, event=None):
222        """
223        Call back function for the perspective menu item.
224        We notify the parent window that the perspective
225        has changed.
226       
227        :param event: menu event
228       
229        """
230        old_frame = None
231        tool_height = self.parent.get_toolbar_height()
232        old_persp = self.parent.get_current_perspective()
233        if old_persp != None:
234            old_frame = old_persp.get_frame()
235        self.parent.check_multimode(self)
236        self.parent.set_current_perspective(self)
237        self.parent.set_perspective(self.perspective)
238       
239        if self.frame != None:
240            if old_frame != None:
241                pos_x, pos_y = old_frame.GetPositionTuple()
242                self.frame.SetPosition((pos_x, pos_y - tool_height))
243            if not self.frame.IsShown():
244                self.frame.Show(True)
245       
246       
247    def set_batch_selection(self, flag):
248        """
249        the plugin to its batch state if flag is True
250        """
251        self.batch_on = flag
252        self.on_batch_selection(self.batch_on)   
253   
254    def on_batch_selection(self, flag):
255        """
256        need to be overwritten by the derivated class
257        """
258   
259    def post_init(self):
260        """
261        Post initialization call back to close the loose ends
262        """
263        pass
264   
265    def set_default_perspective(self):
266        """
267       Call back method that True to notify the parent that the current plug-in
268       can be set as default  perspective.
269       when returning False, the plug-in is not candidate for an automatic
270       default perspective setting
271        """
272        if self.standalone:
273            return True
274        return False
275   
276    def set_state(self, state=None, datainfo=None):   
277        """
278        update state
279        """
280    def set_data(self, data_list=None):
281        """
282        receive a list of data and use it in the current perspective
283       
284        """
285    def set_theory(self, theory_list=None):
286        """
287        :param theory_list: list of information
288            related to available theory state
289        """
290        msg = "%s plugin: does not support import theory" % str(self.sub_menu)
291        raise ValueError, msg
292   
293    def on_set_state_helper(self, event):
294        """
295        update state
296        """
297   
Note: See TracBrowser for help on using the repository browser.