source: sasview/src/sas/sasgui/guiframe/plugin_base.py @ eca66a1

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 eca66a1 was d85c194, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 9 years ago

Remaining modules refactored

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