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

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 fb3f9af was 373d4ee, checked in by Paul Kienzle <pkienzle@…>, 10 years ago

code cleanup for fit panel

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