[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 |
---|
[07c8630] | 42 | self._copy_flag = False |
---|
| 43 | self._paste_flag = False |
---|
[b5ca223] | 44 | self._preview_flag = False |
---|
| 45 | self._bookmark_flag = False |
---|
| 46 | self._zoom_in_flag = False |
---|
| 47 | self._zoom_out_flag = False |
---|
| 48 | self._zoom_flag = False |
---|
| 49 | self._save_flag = False |
---|
| 50 | self._drag_flag = False |
---|
| 51 | self._reset_flag = False |
---|
[03314e7] | 52 | self._has_changed = False |
---|
[c70eb7c] | 53 | self.group_id = None |
---|
[a45037aa] | 54 | self.Bind(wx.EVT_LEFT_DOWN, self.on_set_focus) |
---|
| 55 | self.Bind(wx.EVT_TEXT_ENTER, self.on_set_focus) |
---|
| 56 | self.Bind(wx.EVT_MIDDLE_DOWN, self.on_set_focus) |
---|
| 57 | self.Bind(wx.EVT_RIGHT_DOWN, self.on_set_focus) |
---|
[03314e7] | 58 | |
---|
[6f28e70] | 59 | def save_project(self, doc=None): |
---|
| 60 | """ |
---|
| 61 | return an xml node containing state of the panel |
---|
| 62 | that guiframe can write to file |
---|
| 63 | """ |
---|
| 64 | return None |
---|
| 65 | |
---|
[03314e7] | 66 | def has_changed(self): |
---|
| 67 | """ |
---|
| 68 | """ |
---|
| 69 | return self._has_changed |
---|
| 70 | |
---|
[f036c692] | 71 | def _set_print_flag(self, flag=True): |
---|
[b5ca223] | 72 | """ |
---|
| 73 | The derivative class sets the print flag value to indicate that it can |
---|
| 74 | be printed |
---|
| 75 | """ |
---|
[03314e7] | 76 | if flag == self._print_flag: |
---|
| 77 | self._has_changed = False |
---|
| 78 | return |
---|
| 79 | self._has_changed = True |
---|
[b5ca223] | 80 | self._print_flag = flag |
---|
[03314e7] | 81 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 82 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 83 | self._manager.parent.enable_print() |
---|
| 84 | |
---|
[b5ca223] | 85 | def get_print_flag(self): |
---|
| 86 | """ |
---|
| 87 | Get the print flag to update appropriately the tool bar |
---|
| 88 | """ |
---|
| 89 | return self._print_flag |
---|
| 90 | |
---|
[f036c692] | 91 | def _set_undo_flag(self, flag=True): |
---|
[b5ca223] | 92 | """ |
---|
| 93 | The derivative class sets the undo flag value to indicate that the |
---|
| 94 | current action done can be canceled |
---|
| 95 | """ |
---|
[03314e7] | 96 | if flag == self._undo_flag: |
---|
| 97 | self._has_changed = False |
---|
| 98 | return |
---|
| 99 | self._has_changed = True |
---|
[b5ca223] | 100 | self._undo_flag = flag |
---|
[03314e7] | 101 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 102 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 103 | self._manager.parent.enable_undo() |
---|
| 104 | |
---|
[b5ca223] | 105 | def get_undo_flag(self): |
---|
| 106 | """ |
---|
| 107 | Get the undo flag to update appropriately the tool bar |
---|
| 108 | """ |
---|
| 109 | return self._undo_flag |
---|
| 110 | |
---|
[f036c692] | 111 | def _set_redo_flag(self, flag=True): |
---|
[b5ca223] | 112 | """ |
---|
| 113 | The derivative class sets the redo flag value to indicate that the |
---|
| 114 | action done can be recovered |
---|
| 115 | """ |
---|
[03314e7] | 116 | if flag == self._redo_flag: |
---|
| 117 | self._has_changed = False |
---|
| 118 | return |
---|
| 119 | self._has_changed = True |
---|
[b5ca223] | 120 | self._redo_flag = flag |
---|
[03314e7] | 121 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 122 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 123 | self._manager.parent.enable_redo() |
---|
| 124 | |
---|
[b5ca223] | 125 | def get_redo_flag(self): |
---|
| 126 | """ |
---|
| 127 | Get the redo flag to update appropriately the tool bar |
---|
| 128 | """ |
---|
| 129 | return self._redo_flag |
---|
[07c8630] | 130 | |
---|
| 131 | def _set_copy_flag(self, flag=True): |
---|
| 132 | """ |
---|
| 133 | The derivative class sets the copy flag value to indicate that the |
---|
| 134 | action done can be recovered |
---|
| 135 | """ |
---|
| 136 | if flag == self._copy_flag: |
---|
| 137 | self._has_changed = False |
---|
| 138 | return |
---|
| 139 | self._has_changed = True |
---|
| 140 | self._copy_flag = flag |
---|
| 141 | if self._manager is not None and self._manager.parent is not None: |
---|
| 142 | self._manager.parent.cpanel_on_focus = self |
---|
| 143 | self._manager.parent.enable_copy() |
---|
| 144 | |
---|
| 145 | def get_copy_flag(self): |
---|
| 146 | """ |
---|
| 147 | Get the copy flag to update appropriately the tool bar |
---|
| 148 | """ |
---|
| 149 | return self._copy_flag |
---|
[b5ca223] | 150 | |
---|
[07c8630] | 151 | def _set_paste_flag(self, flag=True): |
---|
| 152 | """ |
---|
| 153 | The derivative class sets the paste flag value to indicate that the |
---|
| 154 | action done can be recovered |
---|
| 155 | """ |
---|
| 156 | if flag == self._paste_flag: |
---|
| 157 | self._has_changed = False |
---|
| 158 | return |
---|
| 159 | self._has_changed = True |
---|
| 160 | self._paste_flag = flag |
---|
| 161 | if self._manager is not None and self._manager.parent is not None: |
---|
| 162 | self._manager.parent.cpanel_on_focus = self |
---|
| 163 | self._manager.parent.enable_paste() |
---|
| 164 | |
---|
| 165 | def get_paste_flag(self): |
---|
| 166 | """ |
---|
| 167 | Get the copy flag to update appropriately the tool bar |
---|
| 168 | """ |
---|
| 169 | return self._copy_flag |
---|
| 170 | |
---|
[f036c692] | 171 | def _set_zoomed_in_flag(self, flag=True): |
---|
[b5ca223] | 172 | """ |
---|
| 173 | The derivative class sets the zoom in flag value to indicate that it |
---|
| 174 | can be zoomed in |
---|
| 175 | """ |
---|
[03314e7] | 176 | if self._zoom_in_flag == flag: |
---|
| 177 | self._has_changed = False |
---|
| 178 | return |
---|
| 179 | self._has_changed = True |
---|
[b5ca223] | 180 | self._zoom_in_flag = flag |
---|
[03314e7] | 181 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 182 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 183 | self._manager.parent.enable_zoom_in() |
---|
| 184 | |
---|
[b5ca223] | 185 | def get_zoom_in_flag(self): |
---|
| 186 | """ |
---|
| 187 | Get the zoom in flag to update appropriately the tool bar |
---|
| 188 | """ |
---|
| 189 | return self._zoom_in_flag |
---|
| 190 | |
---|
[f036c692] | 191 | def _set_zoomed_out_flag(self, flag=True): |
---|
[b5ca223] | 192 | """ |
---|
| 193 | The derivative class sets the zoom out flag value to indicate that it |
---|
| 194 | can be zoomed out |
---|
| 195 | """ |
---|
[03314e7] | 196 | if self._zoom_out_flag == flag: |
---|
| 197 | self._has_changed = False |
---|
| 198 | return |
---|
| 199 | self._has_changed = True |
---|
[b5ca223] | 200 | self._zoom_out_flag = flag |
---|
[03314e7] | 201 | if self._manager is not None and self._manager.parent is not None: |
---|
[ecc85443] | 202 | self._manager.parent.panel_on_focus = self |
---|
[03314e7] | 203 | self._manager.parent.enable_zoom_out() |
---|
[b5ca223] | 204 | |
---|
| 205 | def get_zoom_out_flag(self): |
---|
| 206 | """ |
---|
| 207 | Get the zoom out flag to update appropriately the tool bar |
---|
| 208 | """ |
---|
| 209 | return self._zoom_out_flag |
---|
| 210 | |
---|
[f036c692] | 211 | def _set_zoom_flag(self, flag=True): |
---|
[b5ca223] | 212 | """ |
---|
| 213 | The derivative class sets the zoom flag value to indicate that it |
---|
| 214 | can be zoomed |
---|
| 215 | """ |
---|
[03314e7] | 216 | if flag == self._zoom_flag: |
---|
| 217 | self._has_changed = False |
---|
| 218 | return |
---|
| 219 | self._has_changed = True |
---|
[b5ca223] | 220 | self._zoom_flag = flag |
---|
[03314e7] | 221 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 222 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 223 | self._manager.parent.enable_zoom() |
---|
| 224 | |
---|
[b5ca223] | 225 | def get_zoom_flag(self): |
---|
| 226 | """ |
---|
| 227 | Get the zoom flag to update appropriately the tool bar |
---|
| 228 | """ |
---|
| 229 | return self._zoom_flag |
---|
| 230 | |
---|
[f036c692] | 231 | def _set_bookmark_flag(self, flag=True): |
---|
[b5ca223] | 232 | """ |
---|
| 233 | The derivative class sets the bookmark flag value to indicate that it |
---|
| 234 | can be bookmarked |
---|
| 235 | """ |
---|
[03314e7] | 236 | if flag == self._bookmark_flag: |
---|
| 237 | self._has_changed = False |
---|
| 238 | return |
---|
| 239 | self._has_changed = True |
---|
[b5ca223] | 240 | self._bookmark_flag = flag |
---|
[03314e7] | 241 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 242 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 243 | self._manager.parent.enable_bookmark() |
---|
[a45037aa] | 244 | |
---|
[b5ca223] | 245 | def get_bookmark_flag(self): |
---|
| 246 | """ |
---|
| 247 | Get the bookmark flag to update appropriately the tool bar |
---|
| 248 | """ |
---|
| 249 | return self._bookmark_flag |
---|
| 250 | |
---|
[f036c692] | 251 | def _set_preview_flag(self, flag=True): |
---|
[b5ca223] | 252 | """ |
---|
| 253 | The derivative class sets the preview flag value to indicate that it |
---|
| 254 | can be previewed |
---|
| 255 | """ |
---|
[03314e7] | 256 | if flag == self._preview_flag: |
---|
| 257 | self._has_changed = False |
---|
| 258 | return |
---|
| 259 | self._has_changed = True |
---|
[b5ca223] | 260 | self._preview_flag = flag |
---|
[03314e7] | 261 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 262 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 263 | self._manager.parent.enable_preview() |
---|
| 264 | |
---|
[b5ca223] | 265 | def get_preview_flag(self): |
---|
| 266 | """ |
---|
| 267 | Get the preview flag to update appropriately the tool bar |
---|
| 268 | """ |
---|
| 269 | return self._preview_flag |
---|
| 270 | |
---|
[f036c692] | 271 | def _set_save_flag(self, flag=True): |
---|
[b5ca223] | 272 | """ |
---|
| 273 | The derivative class sets the drag flag value to indicate that it |
---|
| 274 | can be saved |
---|
| 275 | """ |
---|
[03314e7] | 276 | if flag == self._save_flag: |
---|
| 277 | self._has_changed = False |
---|
| 278 | return |
---|
| 279 | self._has_changed = True |
---|
[b5ca223] | 280 | self._save_flag = flag |
---|
[03314e7] | 281 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 282 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 283 | self._manager.parent.enable_save() |
---|
[a45037aa] | 284 | |
---|
[b5ca223] | 285 | def get_save_flag(self): |
---|
| 286 | """ |
---|
| 287 | Get the save flag to update appropriately the tool bar |
---|
| 288 | """ |
---|
| 289 | return self._save_flag |
---|
| 290 | |
---|
[f036c692] | 291 | def _set_drag_flag(self, flag=True): |
---|
[b5ca223] | 292 | """ |
---|
| 293 | The derivative class sets the drag flag value to indicate that |
---|
| 294 | dragging motion is possible |
---|
| 295 | """ |
---|
[03314e7] | 296 | if self._drag_flag == flag: |
---|
| 297 | self._has_changed = False |
---|
| 298 | return |
---|
| 299 | self._has_changed = True |
---|
[b5ca223] | 300 | self._drag_flag = flag |
---|
[03314e7] | 301 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 302 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 303 | self._manager.parent.enable_drag() |
---|
[a45037aa] | 304 | |
---|
[b5ca223] | 305 | def get_drag_flag(self): |
---|
| 306 | """ |
---|
| 307 | Get the drag flag to update appropriately the tool bar |
---|
| 308 | """ |
---|
| 309 | return self._drag_flag |
---|
| 310 | |
---|
[f036c692] | 311 | def _set_reset_flag(self, flag=True): |
---|
[b5ca223] | 312 | """ |
---|
| 313 | The derivative class sets the reset flag value to indicate that it |
---|
| 314 | can be reset |
---|
| 315 | """ |
---|
[03314e7] | 316 | if self._reset_flag == flag: |
---|
| 317 | self._has_changed = False |
---|
| 318 | return |
---|
| 319 | self._has_changed = True |
---|
[b5ca223] | 320 | self._reset_flag = flag |
---|
[03314e7] | 321 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 322 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 323 | self._manager.parent.enable_reset() |
---|
[a45037aa] | 324 | |
---|
[b5ca223] | 325 | def get_reset_flag(self): |
---|
| 326 | """ |
---|
| 327 | Get the reset flag to update appropriately the tool bar |
---|
| 328 | """ |
---|
| 329 | return self._reset_flag |
---|
| 330 | |
---|
| 331 | def on_reset(self, event): |
---|
| 332 | """ |
---|
| 333 | The derivative class state is restored |
---|
| 334 | """ |
---|
| 335 | def on_drag(self, event): |
---|
| 336 | """ |
---|
| 337 | The derivative class allows dragging motion if implemented |
---|
| 338 | """ |
---|
| 339 | def on_preview(self, event): |
---|
| 340 | """ |
---|
| 341 | Display a printable version of the class derivative |
---|
| 342 | """ |
---|
| 343 | def on_save(self, event): |
---|
| 344 | """ |
---|
| 345 | The state of the derivative class is restored |
---|
| 346 | """ |
---|
| 347 | def on_redo(self, event): |
---|
| 348 | """ |
---|
| 349 | The previous action is restored if possible |
---|
| 350 | """ |
---|
| 351 | def on_undo(self, event): |
---|
| 352 | """ |
---|
| 353 | The current action is canceled |
---|
| 354 | """ |
---|
[07c8630] | 355 | def on_copy(self, event): |
---|
| 356 | """ |
---|
| 357 | The copy action if possible |
---|
| 358 | """ |
---|
| 359 | def on_paste(self, event): |
---|
| 360 | """ |
---|
| 361 | The paste action if possible |
---|
| 362 | """ |
---|
[b5ca223] | 363 | def on_bookmark(self, event): |
---|
| 364 | """ |
---|
| 365 | The derivative class is on bookmark mode if implemented |
---|
| 366 | """ |
---|
| 367 | def on_zoom_in(self, event): |
---|
| 368 | """ |
---|
| 369 | The derivative class is on zoom in mode if implemented |
---|
| 370 | """ |
---|
| 371 | def on_zoom_out(self, event): |
---|
| 372 | """ |
---|
| 373 | The derivative class is on zoom out mode if implemented |
---|
| 374 | """ |
---|
| 375 | def on_zoom(self, event): |
---|
| 376 | """ |
---|
| 377 | The derivative class is on zoom mode (using pane) |
---|
| 378 | if zoom mode is implemented |
---|
| 379 | """ |
---|
[a45037aa] | 380 | def on_set_focus(self, event=None): |
---|
[b5ca223] | 381 | """ |
---|
| 382 | The derivative class is on focus if implemented |
---|
| 383 | """ |
---|
[a45037aa] | 384 | if self.parent is not None: |
---|
| 385 | wx.PostEvent(self.parent, PanelOnFocusEvent(panel=self)) |
---|
[f69b5830] | 386 | |
---|
| 387 | def on_kill_focus(self, event=None): |
---|
| 388 | """ |
---|
| 389 | The derivative class is on unfocus if implemented |
---|
| 390 | """ |
---|
| 391 | pass |
---|
| 392 | |
---|
[52725d6] | 393 | def get_data(self): |
---|
| 394 | """ |
---|
| 395 | return list of current data |
---|
| 396 | """ |
---|
| 397 | return |
---|
| 398 | |
---|
| 399 | def get_state(self): |
---|
| 400 | """ |
---|
| 401 | return the current state |
---|
| 402 | """ |
---|
| 403 | return |
---|
| 404 | |
---|
| 405 | def set_manager(self, manager): |
---|
| 406 | """ |
---|
| 407 | """ |
---|
| 408 | self._manager = manager |
---|
| 409 | |
---|
| 410 | def get_manager(self): |
---|
| 411 | """ |
---|
| 412 | """ |
---|
| 413 | return self._manager |
---|