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

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 f425805 was e4d790f, checked in by Jae Cho <jhjcho@…>, 13 years ago

model cb in data panel enabled by application menu too

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