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

Source Code for Module pyjamas.ui.Focus

 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 JS 
17   
18 -def blur(elem):
19 elem.blur()
20
21 -def createFocusable():
22 e = DOM.createDiv() 23 e.tabIndex = 0 24 return e
25
26 -def focus(elem):
27 elem.focus()
28
29 -def getTabIndex(elem):
30 return elem.tabIndex
31
32 -def setAccessKey(elem, key):
33 elem.accessKey = key
34
35 -def setTabIndex(elem, index):
36 elem.tabIndex = index
37 38
39 -class FocusMixin:
40
41 - def getTabIndex(self):
42 return getTabIndex(self.getElement())
43
44 - def setAccessKey(self, key):
45 setAccessKey(self.getElement(), key)
46
47 - def setFocus(self, focused):
48 if (focused): 49 focus(self.getElement()) 50 else: 51 blur(self.getElement())
52
53 - def setTabIndex(self, index):
54 setTabIndex(self.getElement(), index)
55
56 - def isEnabled(self):
57 try: 58 return not DOM.getBooleanAttribute(self.getElement(), "disabled") 59 except TypeError: 60 return True 61 except AttributeError: 62 return True
63
64 - def setEnabled(self, enabled):
65 DOM.setBooleanAttribute(self.getElement(), "disabled", not enabled)
66
67 - def isReadonly(self):
68 try: 69 return not DOM.getBooleanAttribute(self.getElement(), "readOnly") 70 except TypeError: 71 return True 72 except AttributeError: 73 return True
74
75 - def setReadonly(self, readonly):
76 DOM.setBooleanAttribute(self.getElement(), "readOnly", readonly)
77