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