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