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