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 18 from pyjamas.ui.UIObject import UIObject 19 from pyjamas.ui import Event 20 from pyjamas.ui.ClickListener import ClickHandler 21 from pyjamas.ui.FocusListener import FocusHandler 22 from pyjamas.ui.KeyboardListener import KeyboardHandler 23 from pyjamas.ui.MouseListener import MouseHandler, MouseWheelHandler 24 from pyjamas.ui.InputListener import InputHandler 25 from pyjamas.ui.ChangeListener import ChangeHandler 26 from pyjamas.ui.DragHandler import DragHandler 27 from pyjamas.ui.DropHandler import DropHandler 2830 """ 31 Base class for most of the UI classes. This class provides basic services 32 used by any Widget, including management of parents and adding/removing the 33 event handler association with the DOM. 34 """153 154 Factory.registerClass('pyjamas.ui.Widget', 'Widget', Widget) 15536 self.attached = False 37 self.parent = None 38 self.layoutData = None 39 self.contextMenu = None 40 41 UIObject.__init__(self, **kwargs)42 4547 """Widgets are kept in a hierarchy, and widgets that have been added to a panel 48 will have a parent widget that contains them. This retrieves the containing 49 widget for this widget.""" 50 return self.parent5153 """Return whether or not this widget has been attached to the document.""" 54 return self.attached5557 self.contextMenu = menu 58 if menu is not None: 59 self.sinkEvents(Event.ONCONTEXTMENU) 60 else: 61 self.unsinkEvents(Event.ONCONTEXTMENU)6264 65 # farm out the event to convenience handlers. 66 # detect existence by checking for the listener lists of each 67 # type of handler. there's probably a better way to do this... 68 if hasattr(self, "_clickListeners"): 69 ClickHandler.onBrowserEvent(self, event) 70 if hasattr(self, "_keyboardListeners"): 71 KeyboardHandler.onBrowserEvent(self, event) 72 if hasattr(self, "_mouseListeners"): 73 MouseHandler.onBrowserEvent(self, event) 74 if hasattr(self, "_mouseWheelListeners"): 75 MouseWheelHandler.onBrowserEvent(self, event) 76 if hasattr(self, "_focusListeners"): 77 FocusHandler.onBrowserEvent(self, event) 78 if hasattr(self, "_dragListeners"): 79 DragHandler.onBrowserEvent(self, event) 80 if hasattr(self, "_changeListeners"): 81 ChangeHandler.onBrowserEvent(self, event) 82 if hasattr(self, "_inputListeners"): 83 InputHandler.onBrowserEvent(self, event) 84 if hasattr(self, "_dropListeners"): 85 DropHandler.onBrowserEvent(self, event) 86 87 if self.contextMenu is None: 88 return True 89 90 type = DOM.eventGetType(event) 91 if type == "contextmenu": 92 DOM.eventCancelBubble(event, True) 93 DOM.eventPreventDefault(event) 94 self.contextMenu.onContextMenu(self) 95 return False 96 97 return True98 101 104 107109 """Called when this widget has an element, and that element is on the document's 110 DOM tree, and we have a parent widget.""" 111 if self.isAttached(): 112 return 113 self.attached = True 114 DOM.setEventListener(self.getElement(), self) 115 self.doAttachChildren() 116 self.onLoad()117119 """Called when this widget is being removed from the DOM tree of the document.""" 120 if not self.isAttached(): 121 return 122 self.doDetachChildren() 123 self.attached = False 124 DOM.setEventListener(self.getElement(), None)125 128130 """Update the parent attribute. If the parent is currently attached to the DOM this 131 assumes we are being attached also and calls onAttach().""" 132 oldparent = self.parent 133 self.parent = parent 134 if parent is None: 135 if oldparent is not None and oldparent.attached: 136 self.onDetach() 137 elif parent.attached: 138 self.onAttach()139141 """Remove ourself from our parent. The parent widget will call setParent(None) on 142 us automatically""" 143 if hasattr(self.parent, "remove"): 144 self.parent.remove(self)145147 """Get the id attribute of the associated DOM element.""" 148 return DOM.getAttribute(self.getElement(), "id")149151 """Set the id attribute of the associated DOM element.""" 152 DOM.setAttribute(self.getElement(), "id", id)
Home | Trees | Indices | Help |
|
---|
http://epydoc.sourceforge.net |