Changeset 3222
- Timestamp:
- 06/30/07 06:30:06 (2 years ago)
- Files:
-
- trunk/dabo/dEvents.py (modified) (33 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dabo/dEvents.py
r3221 r3222 9 9 class dEvent(dObject): 10 10 """ Base class for Dabo events. 11 12 Event objects are instantiated in self.raiseEvent(), and passed to all 11 12 Event objects are instantiated in self.raiseEvent(), and passed to all 13 13 callbacks registered with self.bindEvent(). 14 15 User code can define custom events by simply subclassing Event and then 14 15 User code can define custom events by simply subclassing Event and then 16 16 using self.bindEvent() and self.raiseEvent() in your objects. 17 """ 17 """ 18 18 def __init__(self, eventObject, uiEvent=None, eventData=None, *args, **kwargs): 19 19 # Event objects get instantiated with every single event, so try 20 20 # to keep code to a minimum here. 21 21 #super(dEvent, self).__init__(*args, **kwargs) 22 22 23 23 self._eventObject = eventObject 24 24 self._uiEvent = uiEvent … … 27 27 self._continue = True 28 28 self._baseClass = dEvent 29 29 30 30 self._insertEventData() 31 31 if eventData: 32 32 self._eventData.update(eventData) 33 33 34 34 if dabo.eventLogging: 35 35 self._logEvent() 36 37 36 37 38 38 def appliesToClass(eventClass, objectClass): 39 39 """ Returns True if this event can be raised by the passed class. 40 40 41 41 Stub: subclass events need to override with appropriate logic. 42 42 """ 43 43 return False 44 44 appliesToClass = classmethod(appliesToClass) 45 46 45 46 47 47 def stop(self): 48 48 """Stop the event from being handled by other handlers. 49 49 50 50 This is an alternative to setting the Continue property to False. 51 51 """ 52 52 self.Continue = False 53 54 53 54 55 55 def _insertEventData(self): 56 56 """ Place ui-specific stuff into the ui-agnostic EventData dictionary.""" 57 eventData = {} 57 eventData = {} 58 58 nativeEvent = self._uiEvent 59 59 kwargs = self._kwargs 60 60 61 61 eventData["timestamp"] = time.localtime() 62 62 … … 69 69 # Each UI lib should implement getEventData() 70 70 uiEventData = dabo.ui.getEventData(nativeEvent) 71 71 72 72 for key in uiEventData.keys(): 73 73 eventData[key] = uiEventData[key] 74 75 self._eventData = eventData 76 77 74 75 self._eventData = eventData 76 77 78 78 def _logEvent(self): 79 79 """ Log the event if the event object's LogEvents property is set.""" 80 80 eventName = self.__class__.__name__ 81 81 82 82 try: 83 83 logEvents = self._eventObject._getLogEvents() … … 85 85 logEvents = [] 86 86 noLogEvents = [] 87 87 88 88 if len(logEvents) > 0 and logEvents[0].lower() == "all": 89 89 # If there are any events listed explicitly, those must not be … … 91 91 noLogEvents = logEvents[1:] 92 92 93 if eventName not in noLogEvents: 93 if eventName not in noLogEvents: 94 94 for logEventName in logEvents: 95 95 if logEventName.lower() == "all" or logEventName == eventName: 96 dabo.infoLog.write("dEvent Fired: %s %s" % 97 (self._eventObject.getAbsoluteName(), 96 dabo.infoLog.write("dEvent Fired: %s %s" % 97 (self._eventObject.getAbsoluteName(), 98 98 self.__class__.__name__,)) 99 99 break … … 105 105 raise AttributeError, "%s.%s object has no attribute %s." % ( 106 106 self.__class__.__module__, self.__class__.__name__, att) 107 108 107 108 109 109 def _getContinue(self): 110 110 return self._continue 111 111 112 112 def _setContinue(self, val): 113 113 self._continue = bool(val) 114 115 114 115 116 116 def _getEventObject(self): 117 117 return self._eventObject 118 118 119 119 def _setEventObject(self, obj): 120 120 self._eventObject = obj 121 122 121 122 123 123 def _getEventData(self): 124 124 return self._eventData 125 125 126 126 def _setEventData(self, dict): 127 127 self._eventData = dict 128 129 128 129 130 130 Continue = property(_getContinue, _setContinue, None, 131 _("""Specifies whether the event is allowed to continue 131 _("""Specifies whether the event is allowed to continue 132 132 on to the next handler. (bool)""")) 133 134 EventObject = property(_getEventObject, _setEventObject, None, 133 134 EventObject = property(_getEventObject, _setEventObject, None, 135 135 _("References the object that emitted the event. (obj)""")) 136 136 137 137 EventData = property(_getEventData, _setEventData, None, 138 _("""Dictionary of data name/value pairs associated 138 _("""Dictionary of data name/value pairs associated 139 139 with the event. (dict)""")) 140 140 141 # Eventually deprecate Event 141 # Eventually deprecate Event 142 142 Event=dEvent 143 143 … … 146 146 return issubclass(objectClass, dabo.biz.dBizobj) 147 147 appliesToClass = classmethod(appliesToClass) 148 149 148 149 150 150 class EditorEvent(dEvent): 151 151 def appliesToClass(eventClass, objectClass): 152 152 return issubclass(objectClass, dabo.ui.dEditor) 153 153 appliesToClass = classmethod(appliesToClass) 154 154 155 155 class GridEvent(dEvent): 156 156 def appliesToClass(eventClass, objectClass): 157 157 return issubclass(objectClass, dabo.ui.dGrid) 158 158 appliesToClass = classmethod(appliesToClass) 159 159 160 160 class KeyEvent(dEvent): 161 161 def appliesToClass(eventClass, objectClass): 162 162 return issubclass(objectClass, (dabo.ui.dPemMixin, dabo.dApp)) 163 163 appliesToClass = classmethod(appliesToClass) 164 165 164 165 166 166 class ListEvent(dEvent): 167 167 def appliesToClass(eventClass, objectClass): 168 168 return issubclass(objectClass, (dabo.ui.dListControl, dabo.ui.dListBox)) 169 169 appliesToClass = classmethod(appliesToClass) 170 170 171 171 172 172 class MenuEvent(dEvent): … … 175 175 dabo.ui.dMenuBar)) 176 176 appliesToClass = classmethod(appliesToClass) 177 177 178 178 179 179 class MouseEvent(dEvent): … … 181 181 return issubclass(objectClass, dabo.ui.dPemMixin) 182 182 appliesToClass = classmethod(appliesToClass) 183 183 184 184 185 185 class SashEvent(dEvent): … … 207 207 dabo.ui.dFormMain, dabo.ui.dDialog)) 208 208 appliesToClass = classmethod(appliesToClass) 209 209 210 210 211 211 class Close(dEvent): … … 215 215 dabo.ui.dDialog)) 216 216 appliesToClass = classmethod(appliesToClass) 217 218 217 218 219 219 class Create(dEvent): 220 220 """Occurs after the control or form is created.""" … … 222 222 return issubclass(objectClass, dabo.ui.dPemMixin) 223 223 appliesToClass = classmethod(appliesToClass) 224 225 224 225 226 226 class ChildBorn(dEvent): 227 227 """Occurs when a child control is created.""" … … 244 244 """ 245 245 pass 246 246 247 247 248 248 class Deactivate(dEvent): … … 252 252 dabo.ui.dFormMain, dabo.ui.dDialog)) 253 253 appliesToClass = classmethod(appliesToClass) 254 254 255 255 256 256 class Destroy(dEvent): … … 259 259 return issubclass(objectClass, dabo.ui.dPemMixin) 260 260 appliesToClass = classmethod(appliesToClass) 261 261 262 262 263 263 class FontPropertiesChanged(dEvent): … … 269 269 270 270 class Hit(dEvent): 271 """Occurs with the control's default event (button click, 271 """Occurs with the control's default event (button click, 272 272 listbox pick, checkbox, etc.) 273 273 """ … … 278 278 ui.dTimer, ui.dToggleButton, ui.dMenuItem)) 279 279 appliesToClass = classmethod(appliesToClass) 280 280 281 281 282 282 class Idle(dEvent): 283 283 """Occurs when the event loop has no active events to process. 284 285 This is a good place to put redraw or other such UI-intensive code, so that it 286 will only run when the application is otherwise not busy doing other (more 284 285 This is a good place to put redraw or other such UI-intensive code, so that it 286 will only run when the application is otherwise not busy doing other (more 287 287 important) things. 288 288 """ … … 290 290 return issubclass(objectClass, dabo.ui.dPemMixin) 291 291 appliesToClass = classmethod(appliesToClass) 292 292 293 293 294 294 class GotFocus(dEvent): … … 298 298 appliesToClass = classmethod(appliesToClass) 299 299 300 300 301 301 class KeyChar(KeyEvent): 302 """Occurs when a key is depressed and released on the 302 """Occurs when a key is depressed and released on the 303 303 focused control or form. 304 304 """ 305 305 pass 306 306 307 307 308 308 class KeyDown(KeyEvent): 309 309 """Occurs when any key is depressed on the focused control or form.""" 310 310 pass 311 311 312 312 313 313 class KeyUp(KeyEvent): … … 315 315 pass 316 316 317 317 318 318 class LostFocus(dEvent): 319 319 """Occurs when the control loses the focus.""" … … 347 347 return issubclass(objectClass, dabo.ui.dPemMixin) 348 348 appliesToClass = classmethod(appliesToClass) 349 350 349 350 351 351 class MouseEnter(MouseEvent): 352 352 """Occurs when the mouse pointer enters the form or control.""" 353 353 pass 354 355 356 class MouseLeave(MouseEvent): 354 355 356 class MouseLeave(MouseEvent): 357 357 """Occurs when the mouse pointer leaves the form or control.""" 358 358 pass … … 362 362 """Occurs when the mouse moves in the control.""" 363 363 pass 364 364 365 365 366 366 class MouseWheel(MouseEvent): 367 367 """Occurs when the user scrolls the mouse wheel.""" 368 368 pass 369 369 370 370 371 371 class MouseLeftDown(MouseEvent): 372 372 """Occurs when the mouse's left button is depressed on the control.""" 373 373 pass 374 374 375 375 376 376 class MouseLeftUp(MouseEvent): 377 377 """Occurs when the mouse's left button is released on the control.""" 378 378 pass 379 379 380 380 381 381 class MouseLeftClick(MouseEvent): 382 """Occurs when the mouse's left button is depressed 382 """Occurs when the mouse's left button is depressed 383 383 and released on the control. 384 384 """ 385 385 pass 386 386 387 387 388 388 class MouseLeftDoubleClick(MouseEvent): 389 389 """Occurs when the mouse's left button is double-clicked on the control.""" 390 390 pass 391 391 392 392 393 393 class MouseRightDown(MouseEvent): 394 394 """Occurs when the mouse's right button is depressed on the control.""" 395 395 pass 396 396 397 397 398 398 class MouseRightUp(MouseEvent): … … 402 402 403 403 class MouseRightClick(MouseEvent): 404 """Occurs when the mouse mouse's right button is depressed 404 """Occurs when the mouse mouse's right button is depressed 405 405 and released on the control. 406 406 """ 407 407 pass 408 408 409 409 410 410 class MouseRightDoubleClick(MouseEvent): 411 411 """Occurs when the mouse's right button is double-clicked on the control.""" 412 412 pass 413 413 414 414 415 415 class MouseMiddleDown(MouseEvent): 416 416 """Occurs when the mouse's middle button is depressed on the control.""" 417 417 pass 418 418 419 419 420 420 class MouseMiddleUp(MouseEvent): … … 428 428 """ 429 429 pass 430 430 431 431 432 432 class MouseMiddleDoubleClick(MouseEvent): 433 """Occurs when the mouse's middle button is double-clicked 433 """Occurs when the mouse's middle button is double-clicked 434 434 on the control. 435 435 """ 436 436 pass 437 438 437 438 439 439 class Paint(dEvent): 440 440 """Occurs when it is time to paint the control.""" … … 442 442 return issubclass(objectClass, dabo.ui.dPemMixin) 443 443 appliesToClass = classmethod(appliesToClass) 444 444 445 445 446 446 class PageChanged(dEvent): 447 447 """Occurs when a page in a pageframe-like control changes""" 448 448 def appliesToClass(eventClass, objectClass): 449 return issubclass(objectClass, (dabo.ui.dPageFrame, dabo.ui.dPageList, 449 return issubclass(objectClass, (dabo.ui.dPageFrame, dabo.ui.dPageList, 450 450 dabo.ui.dPageSelect, dabo.ui.dPageFrameNoTabs)) 451 451 appliesToClass = classmethod(appliesToClass) 452 452 453 453 454 454 class PageChanging(dEvent): 455 455 """Occurs when the current page in a pageframe-like control is about to change""" 456 456 def appliesToClass(eventClass, objectClass): 457 return issubclass(objectClass, (dabo.ui.dPageFrame, dabo.ui.dPageList, 457 return issubclass(objectClass, (dabo.ui.dPageFrame, dabo.ui.dPageList, 458 458 dabo.ui.dPageSelect, dabo.ui.dPageFrameNoTabs)) 459 459 appliesToClass = classmethod(appliesToClass) 460 460 461 461 462 462 class PageEnter(dEvent): … … 465 465 return issubclass(objectClass, dabo.ui.dPage) 466 466 appliesToClass = classmethod(appliesToClass) 467 467 468 468 469 469 class PageLeave(dEvent): … … 479 479 return issubclass(objectClass, dabo.ui.dPemMixin) 480 480 appliesToClass = classmethod(appliesToClass) 481 482 481 482 483 483 class FoldPanelChange(dEvent): 484 484 """Occurs when a panel in a dFoldPanelBar control is hidden or shown.""" … … 486 486 return issubclass(objectClass, (dabo.ui.dFoldPanelBar, dabo.ui.dFoldPanel)) 487 487 appliesToClass = classmethod(appliesToClass) 488 489 488 489 490 490 class FoldPanelCaptionClick(dEvent): 491 491 """Occurs when the caption bar of a dFoldPanel is clicked.""" … … 493 493 return issubclass(objectClass, (dabo.ui.dFoldPanelBar, dabo.ui.dFoldPanel)) 494 494 appliesToClass = classmethod(appliesToClass) 495 496 495 496 497 497 class RowNumChanged(DataEvent): 498 498 """Occurs when the cursor's row number has changed.""" 499 499 pass 500 500 501 501 502 502 class SashDoubleClick(SashEvent): 503 503 """Occurs when a user double-clicks on the sash of a splitter window.""" … … 523 523 """Occurs when the month on a calendar is changed.""" 524 524 pass 525 525 526 526 527 527 class CalendarYearChanged(CalendarEvent): … … 751 751 class DocumentationHint(EditorEvent): 752 752 """Occurs when the editor wants documentation information to change. 753 753 754 754 The IDE can bind to this to direct detailed documentation into a separate 755 755 window, likely replacing previous documentation. The user can choose how 756 756 to display that window, if at all. 757 757 758 758 Raise this event with three additional keyword arguments: 759 759 + shortDoc: a one-liner call tip 760 760 + longDoc: a multi-line call tip plus expanded documentation 761 761 + object: a reference to the object to be documented, in case 762 the listener wants to format additional information about 762 the listener wants to format additional information about 763 763 the object. 764 764 """ … … 774 774 """Occurs when the contents of the Editor are modified.""" 775 775 pass 776 776 777 777 778 778 class ValueChanged(dEvent): … … 783 783 return issubclass(objectClass, dabo.ui.dDataControlMixin) 784 784 appliesToClass = classmethod(appliesToClass) 785 785 786 786 787 787 class Update(dEvent):
