Package library :: Package pyjamas :: Package ui :: Module ClickDelegatePanel
[hide private]
[frames] | no frames]

Source Code for Module library.pyjamas.ui.ClickDelegatePanel

 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   
19  from pyjamas.ui.Composite import Composite 
20  from pyjamas.ui import Event 
21  from pyjamas.ui import Focus 
22  from pyjamas.ui.SimplePanel import SimplePanel 
23  from pyjamas.ui import KeyboardListener 
24   
25 -class ClickDelegatePanel(Composite):
26
27 - def __init__(self, p, child, cDelegate, kDelegate) :
28 29 Composite.__init__(self) 30 31 self.clickDelegate = cDelegate 32 self.keyDelegate = kDelegate 33 34 self.focusablePanel = SimplePanel(Focus.createFocusable()) 35 self.focusablePanel.setWidget(child) 36 wrapperWidget = p.createTabTextWrapper() 37 if wrapperWidget is None: 38 self.initWidget(self.focusablePanel) 39 else : 40 wrapperWidget.setWidget(self.focusablePanel) 41 self.initWidget(wrapperWidget) 42 43 if hasattr(child, "addKeyboardListener"): 44 child.addKeyboardListener(kDelegate) 45 46 self.sinkEvents(Event.ONCLICK | Event.ONKEYDOWN)
47 48 # receive Label's onClick and pass it through, pretending it came from us
49 - def onClick(self, sender=None):
50 self.clickDelegate.onClick(sender)
51
52 - def getFocusablePanel(self):
53 return self.focusablePanel
54
55 - def onBrowserEvent(self, event) :
56 type = DOM.eventGetType(event) 57 if type == "click": 58 self.onClick(self) 59 60 elif type == "keydown": 61 modifiers = KeyboardListener.getKeyboardModifiers(event) 62 if hasattr(self.keyDelegate, "onKeyDown"): 63 self.keyDelegate.onKeyDown(self, DOM.eventGetKeyCode(event), 64 modifiers)
65 66 # TODO: sort out how to create or grab an element for 67 # Factory.createWidgetOnElement to work 68 #Factory.registerClass('pyjamas.ui.ClickDelegatePanel', 'ClickDelegatePanel', ClickDelegatePanel) 69