Home | Trees | Indices | Help |
|
---|
|
1 # Copyright 2006 James Tauber and contributors 2 # Copyright (C) 2009 Luke Kenneth Casson Leighton <lkcl@lkcl.net> 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 from pyjamas import DOM 16 from pyjamas import Factory 17 from pyjamas import log 18 19 from UIObject import UIObject 20 from pyjamas.ui import Event 21 from ClickListener import ClickHandler 22 from FocusListener import FocusHandler 23 from KeyboardListener import KeyboardHandler 24 from MouseListener import MouseHandler 2527 """ 28 Base class for most of the UI classes. This class provides basic services 29 used by any Widget, including management of parents and adding/removing the 30 event handler association with the DOM. 31 """140 141 Factory.registerClass('pyjamas.ui.Widget', Widget) 14233 self.attached = False 34 self.parent = None 35 self.layoutData = None 36 self.contextMenu = None 37 38 UIObject.__init__(self, **kwargs)39 4244 """Widgets are kept in a hierarchy, and widgets that have been added to a panel 45 will have a parent widget that contains them. This retrieves the containing 46 widget for this widget.""" 47 return self.parent4850 """Return whether or not this widget has been attached to the document.""" 51 return self.attached5254 self.contextMenu = menu 55 if menu: 56 self.sinkEvents(Event.ONCONTEXTMENU) 57 else: 58 self.unsinkEvents(Event.ONCONTEXTMENU)5961 62 # farm out the event to convenience handlers. 63 # detect existence by checking for the listener lists of each 64 # type of handler. there's probably a better way to do this... 65 if hasattr(self, "_clickListeners"): 66 ClickHandler.onBrowserEvent(self, event) 67 if hasattr(self, "_keyboardListeners"): 68 KeyboardHandler.onBrowserEvent(self, event) 69 if hasattr(self, "_mouseListeners"): 70 MouseHandler.onBrowserEvent(self, event) 71 if hasattr(self, "_focusListeners"): 72 FocusHandler.onBrowserEvent(self, event) 73 74 if self.contextMenu is None: 75 return True 76 77 type = DOM.eventGetType(event) 78 if type == "contextmenu": 79 DOM.eventCancelBubble(event, True) 80 DOM.eventPreventDefault(event) 81 self.contextMenu.onContextMenu(self) 82 return False 83 84 return True85 88 91 9496 """Called when this widget has an element, and that element is on the document's 97 DOM tree, and we have a parent widget.""" 98 if self.isAttached(): 99 return 100 self.attached = True 101 DOM.setEventListener(self.getElement(), self) 102 self.doAttachChildren() 103 self.onLoad()104106 """Called when this widget is being removed from the DOM tree of the document.""" 107 if not self.isAttached(): 108 return 109 self.doDetachChildren() 110 self.attached = False 111 DOM.setEventListener(self.getElement(), None)112 115117 """Update the parent attribute. If the parent is currently attached to the DOM this 118 assumes we are being attached also and calls onAttach().""" 119 oldparent = self.parent 120 self.parent = parent 121 if parent is None: 122 if oldparent is not None and oldparent.attached: 123 self.onDetach() 124 elif parent.attached: 125 self.onAttach()126128 """Remove ourself from our parent. The parent widget will call setParent(None) on 129 us automatically""" 130 if hasattr(self.parent, "remove"): 131 self.parent.remove(self)132134 """Get the id attribute of the associated DOM element.""" 135 return DOM.getAttribute(self.getElement(), "id")136138 """Set the id attribute of the associated DOM element.""" 139 DOM.setAttribute(self.getElement(), "id", id)
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Wed Jun 16 12:42:32 2010 | http://epydoc.sourceforge.net |