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

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 1c153e9 was 47ead24, checked in by Jessica Tumarkin <jtumarki@…>, 13 years ago

Added color properties to plugin

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