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