[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 | |
---|
[79492222] | 14 | from sas.guiframe.events import PanelOnFocusEvent |
---|
| 15 | from sas.guiframe.events import EVT_NEW_BATCH |
---|
[a45037aa] | 16 | import wx |
---|
[b5ca223] | 17 | |
---|
| 18 | class PanelBase: |
---|
| 19 | """ |
---|
| 20 | Defines the API for a panels to work with |
---|
| 21 | the ViewerFrame toolbar and menu bar |
---|
| 22 | """ |
---|
| 23 | ## Internal nickname for the window, used by the AUI manager |
---|
[691643c] | 24 | #window_name = "default" |
---|
[b5ca223] | 25 | ## Name to appear on the window title bar |
---|
[691643c] | 26 | #window_caption = "Welcome panel" |
---|
[b5ca223] | 27 | ## Flag to tell the AUI manager to put this panel in the center pane |
---|
[75fbd17] | 28 | group_id = None |
---|
[df22224] | 29 | uid = None |
---|
[b5ca223] | 30 | |
---|
[a45037aa] | 31 | def __init__(self, parent=None): |
---|
[b5ca223] | 32 | """ |
---|
| 33 | Initialize some flag that Viewerframe used |
---|
| 34 | """ |
---|
[52725d6] | 35 | #panel manager |
---|
| 36 | self._manager = None |
---|
[03314e7] | 37 | self.parent = parent |
---|
[7bf9a8c] | 38 | if self.parent is not None and hasattr(self.parent, '_manager'): |
---|
| 39 | self._manager = self.parent._manager |
---|
[b5ca223] | 40 | self._print_flag = False |
---|
| 41 | self._undo_flag = False |
---|
| 42 | self._redo_flag = False |
---|
[07c8630] | 43 | self._copy_flag = False |
---|
| 44 | self._paste_flag = False |
---|
[b5ca223] | 45 | self._preview_flag = False |
---|
| 46 | self._bookmark_flag = False |
---|
| 47 | self._zoom_in_flag = False |
---|
| 48 | self._zoom_out_flag = False |
---|
| 49 | self._zoom_flag = False |
---|
| 50 | self._save_flag = False |
---|
| 51 | self._drag_flag = False |
---|
| 52 | self._reset_flag = False |
---|
[03314e7] | 53 | self._has_changed = False |
---|
[c958e30] | 54 | self.batch_on = False |
---|
[d03a356] | 55 | if self.parent is not None and hasattr(self.parent, "batch_on"): |
---|
| 56 | self.batch_on = self.parent.batch_on |
---|
| 57 | |
---|
[c70eb7c] | 58 | self.group_id = None |
---|
[ae84427] | 59 | self.help_string = '' |
---|
[225ed2d] | 60 | |
---|
[c958e30] | 61 | def on_batch_selection(self, event): |
---|
| 62 | """ |
---|
| 63 | :param event: contains parameter enable . when enable is set to True |
---|
| 64 | the application is in Batch mode |
---|
| 65 | else the application is default mode(single mode) |
---|
| 66 | """ |
---|
| 67 | self.batch_on = event.enable |
---|
[6f28e70] | 68 | def save_project(self, doc=None): |
---|
| 69 | """ |
---|
| 70 | return an xml node containing state of the panel |
---|
| 71 | that guiframe can write to file |
---|
| 72 | """ |
---|
| 73 | return None |
---|
| 74 | |
---|
[03314e7] | 75 | def has_changed(self): |
---|
| 76 | """ |
---|
| 77 | """ |
---|
| 78 | return self._has_changed |
---|
| 79 | |
---|
[f036c692] | 80 | def _set_print_flag(self, flag=True): |
---|
[b5ca223] | 81 | """ |
---|
| 82 | The derivative class sets the print flag value to indicate that it can |
---|
| 83 | be printed |
---|
| 84 | """ |
---|
[03314e7] | 85 | if flag == self._print_flag: |
---|
| 86 | self._has_changed = False |
---|
| 87 | return |
---|
| 88 | self._has_changed = True |
---|
[b5ca223] | 89 | self._print_flag = flag |
---|
[03314e7] | 90 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 91 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 92 | self._manager.parent.enable_print() |
---|
| 93 | |
---|
[b5ca223] | 94 | def get_print_flag(self): |
---|
| 95 | """ |
---|
| 96 | Get the print flag to update appropriately the tool bar |
---|
| 97 | """ |
---|
| 98 | return self._print_flag |
---|
| 99 | |
---|
[f036c692] | 100 | def _set_undo_flag(self, flag=True): |
---|
[b5ca223] | 101 | """ |
---|
| 102 | The derivative class sets the undo flag value to indicate that the |
---|
| 103 | current action done can be canceled |
---|
| 104 | """ |
---|
[03314e7] | 105 | if flag == self._undo_flag: |
---|
| 106 | self._has_changed = False |
---|
| 107 | return |
---|
| 108 | self._has_changed = True |
---|
[b5ca223] | 109 | self._undo_flag = flag |
---|
[03314e7] | 110 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 111 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 112 | self._manager.parent.enable_undo() |
---|
| 113 | |
---|
[b5ca223] | 114 | def get_undo_flag(self): |
---|
| 115 | """ |
---|
| 116 | Get the undo flag to update appropriately the tool bar |
---|
| 117 | """ |
---|
| 118 | return self._undo_flag |
---|
| 119 | |
---|
[f036c692] | 120 | def _set_redo_flag(self, flag=True): |
---|
[b5ca223] | 121 | """ |
---|
| 122 | The derivative class sets the redo flag value to indicate that the |
---|
| 123 | action done can be recovered |
---|
| 124 | """ |
---|
[03314e7] | 125 | if flag == self._redo_flag: |
---|
| 126 | self._has_changed = False |
---|
| 127 | return |
---|
| 128 | self._has_changed = True |
---|
[b5ca223] | 129 | self._redo_flag = flag |
---|
[03314e7] | 130 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 131 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 132 | self._manager.parent.enable_redo() |
---|
| 133 | |
---|
[b5ca223] | 134 | def get_redo_flag(self): |
---|
| 135 | """ |
---|
| 136 | Get the redo flag to update appropriately the tool bar |
---|
| 137 | """ |
---|
| 138 | return self._redo_flag |
---|
[07c8630] | 139 | |
---|
| 140 | def _set_copy_flag(self, flag=True): |
---|
| 141 | """ |
---|
| 142 | The derivative class sets the copy flag value to indicate that the |
---|
| 143 | action done can be recovered |
---|
| 144 | """ |
---|
| 145 | if flag == self._copy_flag: |
---|
| 146 | self._has_changed = False |
---|
| 147 | return |
---|
| 148 | self._has_changed = True |
---|
| 149 | self._copy_flag = flag |
---|
| 150 | if self._manager is not None and self._manager.parent is not None: |
---|
| 151 | self._manager.parent.cpanel_on_focus = self |
---|
| 152 | self._manager.parent.enable_copy() |
---|
| 153 | |
---|
| 154 | def get_copy_flag(self): |
---|
| 155 | """ |
---|
| 156 | Get the copy flag to update appropriately the tool bar |
---|
| 157 | """ |
---|
| 158 | return self._copy_flag |
---|
[b5ca223] | 159 | |
---|
[07c8630] | 160 | def _set_paste_flag(self, flag=True): |
---|
| 161 | """ |
---|
| 162 | The derivative class sets the paste flag value to indicate that the |
---|
| 163 | action done can be recovered |
---|
| 164 | """ |
---|
| 165 | if flag == self._paste_flag: |
---|
| 166 | self._has_changed = False |
---|
| 167 | return |
---|
| 168 | self._has_changed = True |
---|
| 169 | self._paste_flag = flag |
---|
| 170 | if self._manager is not None and self._manager.parent is not None: |
---|
| 171 | self._manager.parent.cpanel_on_focus = self |
---|
| 172 | self._manager.parent.enable_paste() |
---|
| 173 | |
---|
| 174 | def get_paste_flag(self): |
---|
| 175 | """ |
---|
| 176 | Get the copy flag to update appropriately the tool bar |
---|
| 177 | """ |
---|
| 178 | return self._copy_flag |
---|
| 179 | |
---|
[f036c692] | 180 | def _set_zoomed_in_flag(self, flag=True): |
---|
[b5ca223] | 181 | """ |
---|
| 182 | The derivative class sets the zoom in flag value to indicate that it |
---|
| 183 | can be zoomed in |
---|
| 184 | """ |
---|
[03314e7] | 185 | if self._zoom_in_flag == flag: |
---|
| 186 | self._has_changed = False |
---|
| 187 | return |
---|
| 188 | self._has_changed = True |
---|
[b5ca223] | 189 | self._zoom_in_flag = flag |
---|
[03314e7] | 190 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 191 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 192 | self._manager.parent.enable_zoom_in() |
---|
| 193 | |
---|
[b5ca223] | 194 | def get_zoom_in_flag(self): |
---|
| 195 | """ |
---|
| 196 | Get the zoom in flag to update appropriately the tool bar |
---|
| 197 | """ |
---|
| 198 | return self._zoom_in_flag |
---|
| 199 | |
---|
[f036c692] | 200 | def _set_zoomed_out_flag(self, flag=True): |
---|
[b5ca223] | 201 | """ |
---|
| 202 | The derivative class sets the zoom out flag value to indicate that it |
---|
| 203 | can be zoomed out |
---|
| 204 | """ |
---|
[03314e7] | 205 | if self._zoom_out_flag == flag: |
---|
| 206 | self._has_changed = False |
---|
| 207 | return |
---|
| 208 | self._has_changed = True |
---|
[b5ca223] | 209 | self._zoom_out_flag = flag |
---|
[03314e7] | 210 | if self._manager is not None and self._manager.parent is not None: |
---|
[ecc85443] | 211 | self._manager.parent.panel_on_focus = self |
---|
[03314e7] | 212 | self._manager.parent.enable_zoom_out() |
---|
[b5ca223] | 213 | |
---|
| 214 | def get_zoom_out_flag(self): |
---|
| 215 | """ |
---|
| 216 | Get the zoom out flag to update appropriately the tool bar |
---|
| 217 | """ |
---|
| 218 | return self._zoom_out_flag |
---|
| 219 | |
---|
[f036c692] | 220 | def _set_zoom_flag(self, flag=True): |
---|
[b5ca223] | 221 | """ |
---|
| 222 | The derivative class sets the zoom flag value to indicate that it |
---|
| 223 | can be zoomed |
---|
| 224 | """ |
---|
[03314e7] | 225 | if flag == self._zoom_flag: |
---|
| 226 | self._has_changed = False |
---|
| 227 | return |
---|
| 228 | self._has_changed = True |
---|
[b5ca223] | 229 | self._zoom_flag = flag |
---|
[03314e7] | 230 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 231 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 232 | self._manager.parent.enable_zoom() |
---|
| 233 | |
---|
[b5ca223] | 234 | def get_zoom_flag(self): |
---|
| 235 | """ |
---|
| 236 | Get the zoom flag to update appropriately the tool bar |
---|
| 237 | """ |
---|
| 238 | return self._zoom_flag |
---|
| 239 | |
---|
[f036c692] | 240 | def _set_bookmark_flag(self, flag=True): |
---|
[b5ca223] | 241 | """ |
---|
| 242 | The derivative class sets the bookmark flag value to indicate that it |
---|
| 243 | can be bookmarked |
---|
| 244 | """ |
---|
[03314e7] | 245 | if flag == self._bookmark_flag: |
---|
| 246 | self._has_changed = False |
---|
| 247 | return |
---|
| 248 | self._has_changed = True |
---|
[b5ca223] | 249 | self._bookmark_flag = flag |
---|
[03314e7] | 250 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 251 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 252 | self._manager.parent.enable_bookmark() |
---|
[a45037aa] | 253 | |
---|
[b5ca223] | 254 | def get_bookmark_flag(self): |
---|
| 255 | """ |
---|
| 256 | Get the bookmark flag to update appropriately the tool bar |
---|
| 257 | """ |
---|
| 258 | return self._bookmark_flag |
---|
| 259 | |
---|
[f036c692] | 260 | def _set_preview_flag(self, flag=True): |
---|
[b5ca223] | 261 | """ |
---|
| 262 | The derivative class sets the preview flag value to indicate that it |
---|
| 263 | can be previewed |
---|
| 264 | """ |
---|
[03314e7] | 265 | if flag == self._preview_flag: |
---|
| 266 | self._has_changed = False |
---|
| 267 | return |
---|
| 268 | self._has_changed = True |
---|
[b5ca223] | 269 | self._preview_flag = flag |
---|
[03314e7] | 270 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 271 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 272 | self._manager.parent.enable_preview() |
---|
| 273 | |
---|
[b5ca223] | 274 | def get_preview_flag(self): |
---|
| 275 | """ |
---|
| 276 | Get the preview flag to update appropriately the tool bar |
---|
| 277 | """ |
---|
| 278 | return self._preview_flag |
---|
| 279 | |
---|
[f036c692] | 280 | def _set_save_flag(self, flag=True): |
---|
[b5ca223] | 281 | """ |
---|
| 282 | The derivative class sets the drag flag value to indicate that it |
---|
| 283 | can be saved |
---|
| 284 | """ |
---|
[03314e7] | 285 | if flag == self._save_flag: |
---|
| 286 | self._has_changed = False |
---|
| 287 | return |
---|
| 288 | self._has_changed = True |
---|
[b5ca223] | 289 | self._save_flag = flag |
---|
[03314e7] | 290 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 291 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 292 | self._manager.parent.enable_save() |
---|
[a45037aa] | 293 | |
---|
[b5ca223] | 294 | def get_save_flag(self): |
---|
| 295 | """ |
---|
| 296 | Get the save flag to update appropriately the tool bar |
---|
| 297 | """ |
---|
| 298 | return self._save_flag |
---|
| 299 | |
---|
[f036c692] | 300 | def _set_drag_flag(self, flag=True): |
---|
[b5ca223] | 301 | """ |
---|
| 302 | The derivative class sets the drag flag value to indicate that |
---|
| 303 | dragging motion is possible |
---|
| 304 | """ |
---|
[03314e7] | 305 | if self._drag_flag == flag: |
---|
| 306 | self._has_changed = False |
---|
| 307 | return |
---|
| 308 | self._has_changed = True |
---|
[b5ca223] | 309 | self._drag_flag = flag |
---|
[03314e7] | 310 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 311 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 312 | self._manager.parent.enable_drag() |
---|
[a45037aa] | 313 | |
---|
[b5ca223] | 314 | def get_drag_flag(self): |
---|
| 315 | """ |
---|
| 316 | Get the drag flag to update appropriately the tool bar |
---|
| 317 | """ |
---|
| 318 | return self._drag_flag |
---|
| 319 | |
---|
[f036c692] | 320 | def _set_reset_flag(self, flag=True): |
---|
[b5ca223] | 321 | """ |
---|
| 322 | The derivative class sets the reset flag value to indicate that it |
---|
| 323 | can be reset |
---|
| 324 | """ |
---|
[03314e7] | 325 | if self._reset_flag == flag: |
---|
| 326 | self._has_changed = False |
---|
| 327 | return |
---|
| 328 | self._has_changed = True |
---|
[b5ca223] | 329 | self._reset_flag = flag |
---|
[03314e7] | 330 | if self._manager is not None and self._manager.parent is not None: |
---|
[0a2fdca] | 331 | self._manager.parent.cpanel_on_focus = self |
---|
[03314e7] | 332 | self._manager.parent.enable_reset() |
---|
[46cec6c] | 333 | |
---|
| 334 | def on_tap_focus(self): |
---|
| 335 | """ |
---|
| 336 | Update menu on clicking the panel tap |
---|
| 337 | """ |
---|
| 338 | #Implemented only on fitting note book |
---|
| 339 | pass |
---|
[a45037aa] | 340 | |
---|
[b5ca223] | 341 | def get_reset_flag(self): |
---|
| 342 | """ |
---|
| 343 | Get the reset flag to update appropriately the tool bar |
---|
| 344 | """ |
---|
| 345 | return self._reset_flag |
---|
| 346 | |
---|
| 347 | def on_reset(self, event): |
---|
| 348 | """ |
---|
| 349 | The derivative class state is restored |
---|
| 350 | """ |
---|
| 351 | def on_drag(self, event): |
---|
| 352 | """ |
---|
| 353 | The derivative class allows dragging motion if implemented |
---|
| 354 | """ |
---|
| 355 | def on_preview(self, event): |
---|
| 356 | """ |
---|
| 357 | Display a printable version of the class derivative |
---|
| 358 | """ |
---|
| 359 | def on_save(self, event): |
---|
| 360 | """ |
---|
| 361 | The state of the derivative class is restored |
---|
| 362 | """ |
---|
| 363 | def on_redo(self, event): |
---|
| 364 | """ |
---|
| 365 | The previous action is restored if possible |
---|
| 366 | """ |
---|
| 367 | def on_undo(self, event): |
---|
| 368 | """ |
---|
| 369 | The current action is canceled |
---|
| 370 | """ |
---|
[07c8630] | 371 | def on_copy(self, event): |
---|
| 372 | """ |
---|
| 373 | The copy action if possible |
---|
| 374 | """ |
---|
| 375 | def on_paste(self, event): |
---|
| 376 | """ |
---|
| 377 | The paste action if possible |
---|
| 378 | """ |
---|
[b5ca223] | 379 | def on_bookmark(self, event): |
---|
| 380 | """ |
---|
| 381 | The derivative class is on bookmark mode if implemented |
---|
| 382 | """ |
---|
| 383 | def on_zoom_in(self, event): |
---|
| 384 | """ |
---|
| 385 | The derivative class is on zoom in mode if implemented |
---|
| 386 | """ |
---|
| 387 | def on_zoom_out(self, event): |
---|
| 388 | """ |
---|
| 389 | The derivative class is on zoom out mode if implemented |
---|
| 390 | """ |
---|
| 391 | def on_zoom(self, event): |
---|
| 392 | """ |
---|
| 393 | The derivative class is on zoom mode (using pane) |
---|
| 394 | if zoom mode is implemented |
---|
| 395 | """ |
---|
[a45037aa] | 396 | def on_set_focus(self, event=None): |
---|
[b5ca223] | 397 | """ |
---|
| 398 | The derivative class is on focus if implemented |
---|
| 399 | """ |
---|
[a45037aa] | 400 | if self.parent is not None: |
---|
| 401 | wx.PostEvent(self.parent, PanelOnFocusEvent(panel=self)) |
---|
[f69b5830] | 402 | |
---|
| 403 | def on_kill_focus(self, event=None): |
---|
| 404 | """ |
---|
| 405 | The derivative class is on unfocus if implemented |
---|
| 406 | """ |
---|
| 407 | pass |
---|
| 408 | |
---|
[52725d6] | 409 | def get_data(self): |
---|
| 410 | """ |
---|
| 411 | return list of current data |
---|
| 412 | """ |
---|
| 413 | return |
---|
| 414 | |
---|
| 415 | def get_state(self): |
---|
| 416 | """ |
---|
| 417 | return the current state |
---|
| 418 | """ |
---|
| 419 | return |
---|
| 420 | |
---|
| 421 | def set_manager(self, manager): |
---|
| 422 | """ |
---|
| 423 | """ |
---|
| 424 | self._manager = manager |
---|
| 425 | |
---|
| 426 | def get_manager(self): |
---|
| 427 | """ |
---|
| 428 | """ |
---|
[ae84427] | 429 | return self._manager |
---|
| 430 | |
---|
| 431 | def get_frame(self): |
---|
| 432 | """ |
---|
| 433 | """ |
---|
| 434 | if self._manager == None: |
---|
| 435 | return None |
---|
| 436 | return self._manager.frame |
---|
| 437 | |
---|
| 438 | def on_close(self, event): |
---|
| 439 | """ |
---|
[663e988] | 440 | Close event. Hide the whole window. |
---|
[ae84427] | 441 | """ |
---|
[663e988] | 442 | parent = self.GetParent() |
---|
| 443 | if parent is not None: |
---|
| 444 | parent.Hide() |
---|
[ae84427] | 445 | |
---|