[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 |
---|
| 43 | |
---|
| 44 | ## List of panels that you would like to open in AUI windows |
---|
| 45 | # for your plug-in. This defines your plug-in "perspective" |
---|
| 46 | self.perspective = [] |
---|
| 47 | |
---|
[52b8b74] | 48 | def can_load_data(self): |
---|
| 49 | """ |
---|
| 50 | if return True, then call handler to laod data |
---|
| 51 | """ |
---|
| 52 | return False |
---|
| 53 | |
---|
| 54 | def use_data(self): |
---|
| 55 | """ |
---|
| 56 | return True if these plugin use data |
---|
| 57 | """ |
---|
| 58 | return True |
---|
| 59 | |
---|
| 60 | def load_data(self, event): |
---|
| 61 | """ |
---|
| 62 | Load data |
---|
| 63 | """ |
---|
| 64 | raise NotImplemented |
---|
| 65 | |
---|
| 66 | def load_folder(self, event): |
---|
| 67 | """ |
---|
| 68 | Load entire folder |
---|
| 69 | """ |
---|
| 70 | raise NotImplemented |
---|
| 71 | |
---|
[b7c7a1c] | 72 | def set_is_active(self, active=False): |
---|
| 73 | """ |
---|
| 74 | """ |
---|
| 75 | self._always_active = active |
---|
| 76 | |
---|
| 77 | def is_always_active(self): |
---|
| 78 | """ |
---|
| 79 | return True is this plugin is always active and it is local to guiframe |
---|
| 80 | even if the user is switching between perspectives |
---|
| 81 | """ |
---|
| 82 | return self._always_active |
---|
| 83 | |
---|
| 84 | def populate_file_menu(self): |
---|
| 85 | """ |
---|
| 86 | get a menu item and append it under file menu of the application |
---|
| 87 | return [[menu item name, menu_hint, menu handler]] |
---|
| 88 | """ |
---|
| 89 | return [] |
---|
[b5ca223] | 90 | |
---|
| 91 | def populate_menu(self, id, parent): |
---|
| 92 | """ |
---|
| 93 | Create and return the list of application menu |
---|
| 94 | items for the plug-in. |
---|
| 95 | |
---|
| 96 | :param id: deprecated. Un-used. |
---|
| 97 | :param parent: parent window |
---|
| 98 | |
---|
| 99 | :return: plug-in menu |
---|
| 100 | |
---|
| 101 | """ |
---|
| 102 | return [] |
---|
| 103 | |
---|
| 104 | def get_panels(self, parent): |
---|
| 105 | """ |
---|
| 106 | Create and return the list of wx.Panels for your plug-in. |
---|
| 107 | Define the plug-in perspective. |
---|
| 108 | |
---|
| 109 | Panels should inherit from DefaultPanel defined below, |
---|
| 110 | or should present the same interface. They must define |
---|
| 111 | "window_caption" and "window_name". |
---|
| 112 | |
---|
| 113 | :param parent: parent window |
---|
| 114 | |
---|
| 115 | :return: list of panels |
---|
| 116 | |
---|
| 117 | """ |
---|
| 118 | ## Save a reference to the parent |
---|
| 119 | self.parent = parent |
---|
| 120 | |
---|
| 121 | # Return the list of panels |
---|
| 122 | return [] |
---|
| 123 | |
---|
| 124 | def get_tools(self): |
---|
| 125 | """ |
---|
| 126 | Returns a set of menu entries for tools |
---|
| 127 | """ |
---|
| 128 | return [] |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | def get_context_menu(self, graph=None): |
---|
| 132 | """ |
---|
| 133 | This method is optional. |
---|
| 134 | |
---|
| 135 | When the context menu of a plot is rendered, the |
---|
| 136 | get_context_menu method will be called to give you a |
---|
| 137 | chance to add a menu item to the context menu. |
---|
| 138 | |
---|
| 139 | A ref to a Graph object is passed so that you can |
---|
| 140 | investigate the plot content and decide whether you |
---|
| 141 | need to add items to the context menu. |
---|
| 142 | |
---|
| 143 | This method returns a list of menu items. |
---|
| 144 | Each item is itself a list defining the text to |
---|
| 145 | appear in the menu, a tool-tip help text, and a |
---|
| 146 | call-back method. |
---|
| 147 | |
---|
| 148 | :param graph: the Graph object to which we attach the context menu |
---|
| 149 | |
---|
| 150 | :return: a list of menu items with call-back function |
---|
| 151 | |
---|
| 152 | """ |
---|
| 153 | return [] |
---|
| 154 | |
---|
| 155 | def get_perspective(self): |
---|
| 156 | """ |
---|
| 157 | Get the list of panel names for this perspective |
---|
| 158 | """ |
---|
| 159 | return self.perspective |
---|
| 160 | |
---|
| 161 | def on_perspective(self, event): |
---|
| 162 | """ |
---|
| 163 | Call back function for the perspective menu item. |
---|
| 164 | We notify the parent window that the perspective |
---|
| 165 | has changed. |
---|
| 166 | |
---|
| 167 | :param event: menu event |
---|
| 168 | |
---|
| 169 | """ |
---|
[f444b20] | 170 | self.parent.set_current_perspective(self) |
---|
[b5ca223] | 171 | self.parent.set_perspective(self.perspective) |
---|
| 172 | |
---|
| 173 | def post_init(self): |
---|
| 174 | """ |
---|
| 175 | Post initialization call back to close the loose ends |
---|
| 176 | """ |
---|
| 177 | pass |
---|
| 178 | |
---|
| 179 | def set_default_perspective(self): |
---|
| 180 | """ |
---|
| 181 | Call back method that True to notify the parent that the current plug-in |
---|
| 182 | can be set as default perspective. |
---|
| 183 | when returning False, the plug-in is not candidate for an automatic |
---|
| 184 | default perspective setting |
---|
| 185 | """ |
---|
[f444b20] | 186 | if self.standalone: |
---|
| 187 | return True |
---|
[b5ca223] | 188 | return False |
---|
[f444b20] | 189 | |
---|
| 190 | def set_data(self, data_list): |
---|
| 191 | """ |
---|
| 192 | receive a list of data and use it in the current perspective |
---|
| 193 | """ |
---|