source: sasview/src/sas/guiframe/plugin_base.py @ 96423f8

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 96423f8 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
RevLine 
[0fa825c]1"""
2Defines the interface for a Plugin class that can be used by the gui_manager.
3"""
4
[51f14603]5################################################################################
6#This software was developed by the University of Tennessee as part of the
7#Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
[0fa825c]8#project funded by the US National Science Foundation.
[51f14603]9#
10#See the license text in license.txt
11#
12#copyright 2008, University of Tennessee
13################################################################################
[0fa825c]14
[373d4ee]15class PluginBase(object):
[51f14603]16    """
17    This class defines the interface for a Plugin class
18    that can be used by the gui_manager.
[0fa825c]19
[51f14603]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: ::
[0fa825c]25
[51f14603]26        PLUGIN_ID = "Foo plug-in 1.0"
27        from Foo import *
[0fa825c]28
[51f14603]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.
[0fa825c]32
[51f14603]33    See dummyapp.py for a plugin example.
34    """
[0fa825c]35
[51f14603]36    def __init__(self, name="Test_plugin", standalone=True):
37        """
[373d4ee]38        Abstract class for gui_manager Plugins.
[51f14603]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.
[0fa825c]43        self.sub_menu = name
[51f14603]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
[0fa825c]50        self.state_reader = None
[51f14603]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()
[0fa825c]61
[51f14603]62    def get_batch_capable(self):
63        """
64        Check if the plugin has a batch capability
65        """
66        return False
[0fa825c]67
[51f14603]68    def add_color(self, color, id):
69        """
70        Adds color to a plugin
71        """
[0fa825c]72
[51f14603]73    def clear_panel(self):
74        """
75        clear all related panels
76        """
[0fa825c]77
[51f14603]78    def get_extensions(self):
79        """
80        return state reader and its extensions
81        """
82        return self.state_reader, self._extensions
[0fa825c]83
[51f14603]84    def can_load_data(self):
85        """
86        if return True, then call handler to laod data
87        """
88        return False
[0fa825c]89
[51f14603]90    def use_data(self):
91        """
92        return True if these plugin use data
93        """
94        return True
[0fa825c]95
[51f14603]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
[0fa825c]100
[51f14603]101        data_name = 'None'
102        in_use = False
103        example [(data_name, self.sub_menu)]
104        """
105        return []
[0fa825c]106
[51f14603]107    def delete_data(self, data_id):
108        """
109        Delete all references of data which id are in data_list.
110        """
[0fa825c]111
[51f14603]112    def load_data(self, event):
113        """
114        Load  data
115        """
116        raise NotImplementedError
[0fa825c]117
[51f14603]118    def load_folder(self, event):
119        """
120        Load entire folder
121        """
122        raise NotImplementedError
[0fa825c]123
[51f14603]124    def set_is_active(self, active=False):
125        """
[0fa825c]126        Set if the perspective is always active
[51f14603]127        """
128        self._always_active = active
[0fa825c]129
[51f14603]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
[0fa825c]136
[51f14603]137    def populate_file_menu(self):
138        """
139        Append menu item under file menu item of the frame
140        """
141        return []
[0fa825c]142
[51f14603]143    def populate_menu(self, parent):
144        """
145        Create and return the list of application menu
146        items for the plug-in.
[0fa825c]147
[51f14603]148        :param parent: parent window
[0fa825c]149
[51f14603]150        :return: plug-in menu
[0fa825c]151
[51f14603]152        """
153        return []
[0fa825c]154
[51f14603]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)
[0fa825c]168
[51f14603]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.
[0fa825c]173
[51f14603]174        Panels should inherit from DefaultPanel defined below,
175        or should present the same interface. They must define
176        "window_caption" and "window_name".
[0fa825c]177
[51f14603]178        :param parent: parent window
[0fa825c]179
[51f14603]180        :return: list of panels
[0fa825c]181
[51f14603]182        """
183        ## Save a reference to the parent
184        self.parent = parent
[0fa825c]185
[51f14603]186        # Return the list of panels
187        return []
[0fa825c]188
[51f14603]189    def get_tools(self):
190        """
191        Returns a set of menu entries for tools
192        """
193        return []
[0fa825c]194
[51f14603]195    def get_context_menu(self, plotpanel=None):
196        """
197        This method is optional.
[0fa825c]198
199        When the context menu of a plot is rendered, the
200        get_context_menu method will be called to give you a
[51f14603]201        chance to add a menu item to the context menu.
[0fa825c]202
[51f14603]203        A ref to a plotpanel object is passed so that you can
204        investigate the plot content and decide whether you
[0fa825c]205        need to add items to the context menu.
206
[51f14603]207        This method returns a list of menu items.
[0fa825c]208        Each item is itself a list defining the text to
[51f14603]209        appear in the menu, a tool-tip help text, and a
210        call-back method.
[0fa825c]211
[51f14603]212        :param graph: the Graph object to which we attach the context menu
[0fa825c]213
[51f14603]214        :return: a list of menu items with call-back function
215        """
216        return []
[0fa825c]217
[51f14603]218    def get_perspective(self):
219        """
220        Get the list of panel names for this perspective
221        """
222        return self.perspective
[0fa825c]223
[51f14603]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.
[0fa825c]229
[51f14603]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)
[0fa825c]239
[51f14603]240        if self.frame != None:
241            if old_frame != None:
242                pos_x, pos_y = old_frame.GetPositionTuple()
[0fa825c]243                self.frame.SetPosition((pos_x, pos_y))
[51f14603]244            if not self.frame.IsShown():
245                self.frame.Show(True)
[0fa825c]246
[51f14603]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
[0fa825c]252        self.on_batch_selection(self.batch_on)
253
[51f14603]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
[0fa825c]264
[51f14603]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.
[0fa825c]269       when returning False, the plug-in is not candidate for an automatic
[51f14603]270       default perspective setting
271        """
272        if self.standalone:
273            return True
274        return False
[0fa825c]275
[51f14603]276    def set_state(self, state=None, datainfo=None):   
277        """
278        update state
279        """
[0fa825c]280
[51f14603]281    def set_data(self, data_list=None):
282        """
283        receive a list of data and use it in the current perspective
284        """
[0fa825c]285
[51f14603]286    def set_theory(self, theory_list=None):
287        """
[0fa825c]288        :param theory_list: list of information
[51f14603]289            related to available theory state
290        """
291        msg = "%s plugin: does not support import theory" % str(self.sub_menu)
[0fa825c]292        raise ValueError, msg
293
[51f14603]294    def on_set_state_helper(self, event):
295        """
296        update state
297        """
[0fa825c]298
Note: See TracBrowser for help on using the repository browser.