Changeset 0fa825c in sasview for src/sas/guiframe/plugin_base.py
- Timestamp:
- Apr 2, 2015 2:29:59 PM (10 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 7b1f4e3
- Parents:
- 3d250da3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/guiframe/plugin_base.py
r79492222 r0fa825c 1 """ 2 Defines the interface for a Plugin class that can be used by the gui_manager. 3 """ 4 1 5 ################################################################################ 2 6 #This software was developed by the University of Tennessee as part of the 3 7 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 4 #project funded by the US National Science Foundation. 8 #project funded by the US National Science Foundation. 5 9 # 6 10 #See the license text in license.txt … … 8 12 #copyright 2008, University of Tennessee 9 13 ################################################################################ 10 14 11 15 class PluginBase: 12 16 """ 13 17 This class defines the interface for a Plugin class 14 18 that can be used by the gui_manager. 15 19 16 20 Plug-ins should be placed in a sub-directory called "perspectives". 17 21 For example, a plug-in called Foo should be place in "perspectives/Foo". … … 19 23 20 24 1. perspectives/Foo/__init__.py contains two lines: :: 21 25 22 26 PLUGIN_ID = "Foo plug-in 1.0" 23 27 from Foo import * 24 28 25 29 2. perspectives/Foo/Foo.py contains the definition of the Plugin 26 30 class for the Foo plug-in. The interface of that Plugin class 27 31 should follow the interface of the class you are looking at. 28 32 29 33 See dummyapp.py for a plugin example. 30 34 """ 31 35 32 36 def __init__(self, name="Test_plugin", standalone=True): 33 37 """ … … 37 41 self._always_active = False 38 42 ## Plug-in name. It will appear on the application menu. 39 self.sub_menu = name 43 self.sub_menu = name 40 44 #standalone flag 41 45 self.standalone = standalone … … 44 48 self.frame = None 45 49 #plugin state reader 46 self.state_reader = None 50 self.state_reader = None 47 51 self._extensions = '' 48 52 ## List of panels that you would like to open in AUI windows … … 55 59 self.id = -1 56 60 self.batch_capable = self.get_batch_capable() 57 61 58 62 def get_batch_capable(self): 59 63 """ … … 61 65 """ 62 66 return False 63 67 64 68 def add_color(self, color, id): 65 69 """ 66 70 Adds color to a plugin 67 71 """ 68 72 69 73 def clear_panel(self): 70 74 """ 71 75 clear all related panels 72 76 """ 77 73 78 def get_extensions(self): 74 79 """ … … 76 81 """ 77 82 return self.state_reader, self._extensions 78 83 79 84 def can_load_data(self): 80 85 """ … … 82 87 """ 83 88 return False 84 89 85 90 def use_data(self): 86 91 """ … … 88 93 """ 89 94 return True 90 95 91 96 def is_in_use(self, data_id): 92 97 """ 93 98 get a data id a list of data name if data data is 94 99 currently used by the plugin and the name of the plugin 95 100 96 101 data_name = 'None' 97 102 in_use = False … … 99 104 """ 100 105 return [] 101 106 102 107 def delete_data(self, data_id): 103 108 """ 104 109 Delete all references of data which id are in data_list. 105 110 """ 106 111 107 112 def load_data(self, event): 108 113 """ … … 110 115 """ 111 116 raise NotImplementedError 112 117 113 118 def load_folder(self, event): 114 119 """ … … 116 121 """ 117 122 raise NotImplementedError 118 123 119 124 def set_is_active(self, active=False): 120 125 """ 126 Set if the perspective is always active 121 127 """ 122 128 self._always_active = active 123 129 124 130 def is_always_active(self): 125 131 """ … … 128 134 """ 129 135 return self._always_active 130 136 131 137 def populate_file_menu(self): 132 138 """ … … 134 140 """ 135 141 return [] 136 142 137 143 def populate_menu(self, parent): 138 144 """ 139 145 Create and return the list of application menu 140 146 items for the plug-in. 141 147 142 148 :param parent: parent window 143 149 144 150 :return: plug-in menu 145 146 """ 147 return [] 148 151 152 """ 153 return [] 154 149 155 def get_frame(self): 150 156 """ … … 160 166 self.frame.EnableCloseButton(False) 161 167 self.frame.Show(False) 162 168 163 169 def get_panels(self, parent): 164 170 """ 165 171 Create and return the list of wx.Panels for your plug-in. 166 172 Define the plug-in perspective. 167 173 168 174 Panels should inherit from DefaultPanel defined below, 169 175 or should present the same interface. They must define 170 176 "window_caption" and "window_name". 171 177 172 178 :param parent: parent window 173 179 174 180 :return: list of panels 175 181 176 182 """ 177 183 ## Save a reference to the parent 178 184 self.parent = parent 179 185 180 186 # Return the list of panels 181 187 return [] 182 183 188 184 189 def get_tools(self): 185 190 """ … … 187 192 """ 188 193 return [] 189 190 194 191 195 def get_context_menu(self, plotpanel=None): 192 196 """ 193 197 This method is optional. 194 195 When the context menu of a plot is rendered, the 196 get_context_menu method will be called to give you a 198 199 When the context menu of a plot is rendered, the 200 get_context_menu method will be called to give you a 197 201 chance to add a menu item to the context menu. 198 202 199 203 A ref to a plotpanel object is passed so that you can 200 204 investigate the plot content and decide whether you 201 need to add items to the context menu. 202 205 need to add items to the context menu. 206 203 207 This method returns a list of menu items. 204 Each item is itself a list defining the text to 208 Each item is itself a list defining the text to 205 209 appear in the menu, a tool-tip help text, and a 206 210 call-back method. 207 211 208 212 :param graph: the Graph object to which we attach the context menu 209 213 210 214 :return: a list of menu items with call-back function 211 212 """ 213 return [] 214 215 """ 216 return [] 217 215 218 def get_perspective(self): 216 219 """ … … 218 221 """ 219 222 return self.perspective 220 223 221 224 def on_perspective(self, event=None): 222 225 """ … … 224 227 We notify the parent window that the perspective 225 228 has changed. 226 229 227 230 :param event: menu event 228 229 231 """ 230 232 old_frame = None 231 tool_height = self.parent.get_toolbar_height()232 233 old_persp = self.parent.get_current_perspective() 233 234 if old_persp != None: … … 236 237 self.parent.set_current_perspective(self) 237 238 self.parent.set_perspective(self.perspective) 238 239 239 240 if self.frame != None: 240 241 if old_frame != None: 241 242 pos_x, pos_y = old_frame.GetPositionTuple() 242 self.frame.SetPosition((pos_x, pos_y - tool_height))243 self.frame.SetPosition((pos_x, pos_y)) 243 244 if not self.frame.IsShown(): 244 245 self.frame.Show(True) 245 246 246 247 247 def set_batch_selection(self, flag): 248 248 """ … … 250 250 """ 251 251 self.batch_on = flag 252 self.on_batch_selection(self.batch_on) 253 252 self.on_batch_selection(self.batch_on) 253 254 254 def on_batch_selection(self, flag): 255 255 """ … … 262 262 """ 263 263 pass 264 264 265 265 def set_default_perspective(self): 266 266 """ 267 267 Call back method that True to notify the parent that the current plug-in 268 268 can be set as default perspective. 269 when returning False, the plug-in is not candidate for an automatic 269 when returning False, the plug-in is not candidate for an automatic 270 270 default perspective setting 271 271 """ … … 273 273 return True 274 274 return False 275 275 276 276 def set_state(self, state=None, datainfo=None): 277 277 """ 278 278 update state 279 279 """ 280 280 281 def set_data(self, data_list=None): 281 282 """ 282 283 receive a list of data and use it in the current perspective 283 284 """ 284 """ 285 285 286 def set_theory(self, theory_list=None): 286 287 """ 287 :param theory_list: list of information 288 :param theory_list: list of information 288 289 related to available theory state 289 290 """ 290 291 msg = "%s plugin: does not support import theory" % str(self.sub_menu) 291 raise ValueError, msg 292 292 raise ValueError, msg 293 293 294 def on_set_state_helper(self, event): 294 295 """ 295 296 update state 296 297 """ 297 298
Note: See TracChangeset
for help on using the changeset viewer.