[b5ca223] | 1 | |
---|
| 2 | |
---|
| 3 | ################################################################################ |
---|
| 4 | #This software was developed by the University of Tennessee as part of the |
---|
| 5 | #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
| 6 | #project funded by the US National Science Foundation. |
---|
| 7 | # |
---|
| 8 | #See the license text in license.txt |
---|
| 9 | # |
---|
| 10 | #copyright 2008, University of Tennessee |
---|
| 11 | ################################################################################ |
---|
| 12 | |
---|
[03314e7] | 13 | |
---|
[a45037aa] | 14 | from sans.guiframe.events import PanelOnFocusEvent |
---|
| 15 | import wx |
---|
[b5ca223] | 16 | |
---|
| 17 | class PanelBase: |
---|
| 18 | """ |
---|
| 19 | Defines the API for a panels to work with |
---|
| 20 | the ViewerFrame toolbar and menu bar |
---|
| 21 | """ |
---|
| 22 | ## Internal nickname for the window, used by the AUI manager |
---|
[691643c] | 23 | #window_name = "default" |
---|
[b5ca223] | 24 | ## Name to appear on the window title bar |
---|
[691643c] | 25 | #window_caption = "Welcome panel" |
---|
[b5ca223] | 26 | ## Flag to tell the AUI manager to put this panel in the center pane |
---|
[75fbd17] | 27 | group_id = None |
---|
[df22224] | 28 | uid = None |
---|
[b5ca223] | 29 | |
---|
[a45037aa] | 30 | def __init__(self, parent=None): |
---|
[b5ca223] | 31 | """ |
---|
| 32 | Initialize some flag that Viewerframe used |
---|
| 33 | """ |
---|
[52725d6] | 34 | #panel manager |
---|
| 35 | self._manager = None |
---|
[03314e7] | 36 | self.parent = parent |
---|
[7bf9a8c] | 37 | if self.parent is not None and hasattr(self.parent, '_manager'): |
---|
| 38 | self._manager = self.parent._manager |
---|
[b5ca223] | 39 | self._print_flag = False |
---|
| 40 | self._undo_flag = False |
---|
| 41 | self._redo_flag = False |
---|
| 42 | self._preview_flag = False |
---|
| 43 | self._bookmark_flag = False |
---|
| 44 | self._zoom_in_flag = False |
---|
| 45 | self._zoom_out_flag = False |
---|
| 46 | self._zoom_flag = False |
---|
| 47 | self._save_flag = False |
---|
| 48 | self._drag_flag = False |
---|
| 49 | self._reset_flag = False |
---|
[03314e7] | 50 | self._has_changed = False |
---|
[c70eb7c] | 51 | self.group_id = None |
---|
[a45037aa] | 52 | self.Bind(wx.EVT_LEFT_DOWN, self.on_set_focus) |
---|
| 53 | self.Bind(wx.EVT_TEXT_ENTER, self.on_set_focus) |
---|
| 54 | self.Bind(wx.EVT_MIDDLE_DOWN, self.on_set_focus) |
---|
| 55 | self.Bind(wx.EVT_RIGHT_DOWN, self.on_set_focus) |
---|
[03314e7] | 56 | |
---|
[6f28e70] | 57 | def save_project(self, doc=None): |
---|
| 58 | """ |
---|
| 59 | return an xml node containing state of the panel |
---|
| 60 | that guiframe can write to file |
---|
| 61 | """ |
---|
| 62 | return None |
---|
| 63 | |
---|
[03314e7] | 64 | def has_changed(self): |
---|
| 65 | """ |
---|
| 66 | """ |
---|
| 67 | return self._has_changed |
---|
| 68 | |
---|
[f036c692] | 69 | def _set_print_flag(self, flag=True): |
---|
[b5ca223] | 70 | """ |
---|
| 71 | The derivative class sets the print flag value to indicate that it can |
---|
| 72 | be printed |
---|
| 73 | """ |
---|
[03314e7] | 74 | if flag == self._print_flag: |
---|
| 75 | self._has_changed = False |
---|
| 76 | return |
---|
| 77 | self._has_changed = True |
---|
[b5ca223] | 78 | self._print_flag = flag |
---|
[03314e7] | 79 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 80 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 81 | self._manager.parent.enable_print() |
---|
| 82 | |
---|
[b5ca223] | 83 | def get_print_flag(self): |
---|
| 84 | """ |
---|
| 85 | Get the print flag to update appropriately the tool bar |
---|
| 86 | """ |
---|
| 87 | return self._print_flag |
---|
| 88 | |
---|
[f036c692] | 89 | def _set_undo_flag(self, flag=True): |
---|
[b5ca223] | 90 | """ |
---|
| 91 | The derivative class sets the undo flag value to indicate that the |
---|
| 92 | current action done can be canceled |
---|
| 93 | """ |
---|
[03314e7] | 94 | if flag == self._undo_flag: |
---|
| 95 | self._has_changed = False |
---|
| 96 | return |
---|
| 97 | self._has_changed = True |
---|
[b5ca223] | 98 | self._undo_flag = flag |
---|
[03314e7] | 99 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 100 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 101 | self._manager.parent.enable_undo() |
---|
| 102 | |
---|
[b5ca223] | 103 | def get_undo_flag(self): |
---|
| 104 | """ |
---|
| 105 | Get the undo flag to update appropriately the tool bar |
---|
| 106 | """ |
---|
| 107 | return self._undo_flag |
---|
| 108 | |
---|
[f036c692] | 109 | def _set_redo_flag(self, flag=True): |
---|
[b5ca223] | 110 | """ |
---|
| 111 | The derivative class sets the redo flag value to indicate that the |
---|
| 112 | action done can be recovered |
---|
| 113 | """ |
---|
[03314e7] | 114 | if flag == self._redo_flag: |
---|
| 115 | self._has_changed = False |
---|
| 116 | return |
---|
| 117 | self._has_changed = True |
---|
[b5ca223] | 118 | self._redo_flag = flag |
---|
[03314e7] | 119 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 120 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 121 | self._manager.parent.enable_redo() |
---|
| 122 | |
---|
[b5ca223] | 123 | def get_redo_flag(self): |
---|
| 124 | """ |
---|
| 125 | Get the redo flag to update appropriately the tool bar |
---|
| 126 | """ |
---|
| 127 | return self._redo_flag |
---|
| 128 | |
---|
[f036c692] | 129 | def _set_zoomed_in_flag(self, flag=True): |
---|
[b5ca223] | 130 | """ |
---|
| 131 | The derivative class sets the zoom in flag value to indicate that it |
---|
| 132 | can be zoomed in |
---|
| 133 | """ |
---|
[03314e7] | 134 | if self._zoom_in_flag == flag: |
---|
| 135 | self._has_changed = False |
---|
| 136 | return |
---|
| 137 | self._has_changed = True |
---|
[b5ca223] | 138 | self._zoom_in_flag = flag |
---|
[03314e7] | 139 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 140 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 141 | self._manager.parent.enable_zoom_in() |
---|
| 142 | |
---|
[b5ca223] | 143 | def get_zoom_in_flag(self): |
---|
| 144 | """ |
---|
| 145 | Get the zoom in flag to update appropriately the tool bar |
---|
| 146 | """ |
---|
| 147 | return self._zoom_in_flag |
---|
| 148 | |
---|
[f036c692] | 149 | def _set_zoomed_out_flag(self, flag=True): |
---|
[b5ca223] | 150 | """ |
---|
| 151 | The derivative class sets the zoom out flag value to indicate that it |
---|
| 152 | can be zoomed out |
---|
| 153 | """ |
---|
[03314e7] | 154 | if self._zoom_out_flag == flag: |
---|
| 155 | self._has_changed = False |
---|
| 156 | return |
---|
| 157 | self._has_changed = True |
---|
[b5ca223] | 158 | self._zoom_out_flag = flag |
---|
[03314e7] | 159 | if self._manager is not None and self._manager.parent is not None: |
---|
[ecc85443] | 160 | self._manager.parent.panel_on_focus = self |
---|
[03314e7] | 161 | self._manager.parent.enable_zoom_out() |
---|
[b5ca223] | 162 | |
---|
| 163 | def get_zoom_out_flag(self): |
---|
| 164 | """ |
---|
| 165 | Get the zoom out flag to update appropriately the tool bar |
---|
| 166 | """ |
---|
| 167 | return self._zoom_out_flag |
---|
| 168 | |
---|
[f036c692] | 169 | def _set_zoom_flag(self, flag=True): |
---|
[b5ca223] | 170 | """ |
---|
| 171 | The derivative class sets the zoom flag value to indicate that it |
---|
| 172 | can be zoomed |
---|
| 173 | """ |
---|
[03314e7] | 174 | if flag == self._zoom_flag: |
---|
| 175 | self._has_changed = False |
---|
| 176 | return |
---|
| 177 | self._has_changed = True |
---|
[b5ca223] | 178 | self._zoom_flag = flag |
---|
[03314e7] | 179 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 180 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 181 | self._manager.parent.enable_zoom() |
---|
| 182 | |
---|
[b5ca223] | 183 | def get_zoom_flag(self): |
---|
| 184 | """ |
---|
| 185 | Get the zoom flag to update appropriately the tool bar |
---|
| 186 | """ |
---|
| 187 | return self._zoom_flag |
---|
| 188 | |
---|
[f036c692] | 189 | def _set_bookmark_flag(self, flag=True): |
---|
[b5ca223] | 190 | """ |
---|
| 191 | The derivative class sets the bookmark flag value to indicate that it |
---|
| 192 | can be bookmarked |
---|
| 193 | """ |
---|
[03314e7] | 194 | if flag == self._bookmark_flag: |
---|
| 195 | self._has_changed = False |
---|
| 196 | return |
---|
| 197 | self._has_changed = True |
---|
[b5ca223] | 198 | self._bookmark_flag = flag |
---|
[03314e7] | 199 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 200 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 201 | self._manager.parent.enable_bookmark() |
---|
[a45037aa] | 202 | |
---|
[b5ca223] | 203 | def get_bookmark_flag(self): |
---|
| 204 | """ |
---|
| 205 | Get the bookmark flag to update appropriately the tool bar |
---|
| 206 | """ |
---|
| 207 | return self._bookmark_flag |
---|
| 208 | |
---|
[f036c692] | 209 | def _set_preview_flag(self, flag=True): |
---|
[b5ca223] | 210 | """ |
---|
| 211 | The derivative class sets the preview flag value to indicate that it |
---|
| 212 | can be previewed |
---|
| 213 | """ |
---|
[03314e7] | 214 | if flag == self._preview_flag: |
---|
| 215 | self._has_changed = False |
---|
| 216 | return |
---|
| 217 | self._has_changed = True |
---|
[b5ca223] | 218 | self._preview_flag = flag |
---|
[03314e7] | 219 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 220 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 221 | self._manager.parent.enable_preview() |
---|
| 222 | |
---|
[b5ca223] | 223 | def get_preview_flag(self): |
---|
| 224 | """ |
---|
| 225 | Get the preview flag to update appropriately the tool bar |
---|
| 226 | """ |
---|
| 227 | return self._preview_flag |
---|
| 228 | |
---|
[f036c692] | 229 | def _set_save_flag(self, flag=True): |
---|
[b5ca223] | 230 | """ |
---|
| 231 | The derivative class sets the drag flag value to indicate that it |
---|
| 232 | can be saved |
---|
| 233 | """ |
---|
[03314e7] | 234 | if flag == self._save_flag: |
---|
| 235 | self._has_changed = False |
---|
| 236 | return |
---|
| 237 | self._has_changed = True |
---|
[b5ca223] | 238 | self._save_flag = flag |
---|
[03314e7] | 239 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 240 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 241 | self._manager.parent.enable_save() |
---|
[a45037aa] | 242 | |
---|
[b5ca223] | 243 | def get_save_flag(self): |
---|
| 244 | """ |
---|
| 245 | Get the save flag to update appropriately the tool bar |
---|
| 246 | """ |
---|
| 247 | return self._save_flag |
---|
| 248 | |
---|
[f036c692] | 249 | def _set_drag_flag(self, flag=True): |
---|
[b5ca223] | 250 | """ |
---|
| 251 | The derivative class sets the drag flag value to indicate that |
---|
| 252 | dragging motion is possible |
---|
| 253 | """ |
---|
[03314e7] | 254 | if self._drag_flag == flag: |
---|
| 255 | self._has_changed = False |
---|
| 256 | return |
---|
| 257 | self._has_changed = True |
---|
[b5ca223] | 258 | self._drag_flag = flag |
---|
[03314e7] | 259 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 260 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 261 | self._manager.parent.enable_drag() |
---|
[a45037aa] | 262 | |
---|
[b5ca223] | 263 | def get_drag_flag(self): |
---|
| 264 | """ |
---|
| 265 | Get the drag flag to update appropriately the tool bar |
---|
| 266 | """ |
---|
| 267 | return self._drag_flag |
---|
| 268 | |
---|
[f036c692] | 269 | def _set_reset_flag(self, flag=True): |
---|
[b5ca223] | 270 | """ |
---|
| 271 | The derivative class sets the reset flag value to indicate that it |
---|
| 272 | can be reset |
---|
| 273 | """ |
---|
[03314e7] | 274 | if self._reset_flag == flag: |
---|
| 275 | self._has_changed = False |
---|
| 276 | return |
---|
| 277 | self._has_changed = True |
---|
[b5ca223] | 278 | self._reset_flag = flag |
---|
[03314e7] | 279 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 280 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 281 | self._manager.parent.enable_reset() |
---|
[a45037aa] | 282 | |
---|
[b5ca223] | 283 | def get_reset_flag(self): |
---|
| 284 | """ |
---|
| 285 | Get the reset flag to update appropriately the tool bar |
---|
| 286 | """ |
---|
| 287 | return self._reset_flag |
---|
| 288 | |
---|
| 289 | def on_reset(self, event): |
---|
| 290 | """ |
---|
| 291 | The derivative class state is restored |
---|
| 292 | """ |
---|
| 293 | def on_drag(self, event): |
---|
| 294 | """ |
---|
| 295 | The derivative class allows dragging motion if implemented |
---|
| 296 | """ |
---|
| 297 | def on_preview(self, event): |
---|
| 298 | """ |
---|
| 299 | Display a printable version of the class derivative |
---|
| 300 | """ |
---|
| 301 | def on_save(self, event): |
---|
| 302 | """ |
---|
| 303 | The state of the derivative class is restored |
---|
| 304 | """ |
---|
| 305 | def on_redo(self, event): |
---|
| 306 | """ |
---|
| 307 | The previous action is restored if possible |
---|
| 308 | """ |
---|
| 309 | def on_undo(self, event): |
---|
| 310 | """ |
---|
| 311 | The current action is canceled |
---|
| 312 | """ |
---|
| 313 | def on_bookmark(self, event): |
---|
| 314 | """ |
---|
| 315 | The derivative class is on bookmark mode if implemented |
---|
| 316 | """ |
---|
| 317 | def on_zoom_in(self, event): |
---|
| 318 | """ |
---|
| 319 | The derivative class is on zoom in mode if implemented |
---|
| 320 | """ |
---|
| 321 | def on_zoom_out(self, event): |
---|
| 322 | """ |
---|
| 323 | The derivative class is on zoom out mode if implemented |
---|
| 324 | """ |
---|
| 325 | def on_zoom(self, event): |
---|
| 326 | """ |
---|
| 327 | The derivative class is on zoom mode (using pane) |
---|
| 328 | if zoom mode is implemented |
---|
| 329 | """ |
---|
[a45037aa] | 330 | def on_set_focus(self, event=None): |
---|
[b5ca223] | 331 | """ |
---|
| 332 | The derivative class is on focus if implemented |
---|
| 333 | """ |
---|
[a45037aa] | 334 | if self.parent is not None: |
---|
| 335 | wx.PostEvent(self.parent, PanelOnFocusEvent(panel=self)) |
---|
[f69b5830] | 336 | |
---|
| 337 | def on_kill_focus(self, event=None): |
---|
| 338 | """ |
---|
| 339 | The derivative class is on unfocus if implemented |
---|
| 340 | """ |
---|
| 341 | pass |
---|
| 342 | |
---|
[52725d6] | 343 | def get_data(self): |
---|
| 344 | """ |
---|
| 345 | return list of current data |
---|
| 346 | """ |
---|
| 347 | return |
---|
| 348 | |
---|
| 349 | def get_state(self): |
---|
| 350 | """ |
---|
| 351 | return the current state |
---|
| 352 | """ |
---|
| 353 | return |
---|
| 354 | |
---|
| 355 | def set_manager(self, manager): |
---|
| 356 | """ |
---|
| 357 | """ |
---|
| 358 | self._manager = manager |
---|
| 359 | |
---|
| 360 | def get_manager(self): |
---|
| 361 | """ |
---|
| 362 | """ |
---|
| 363 | return self._manager |
---|