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

Source Code for Module library.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  import pyjd 
16  from pyjamas import DOM 
17  from __pyjamas__ import JS 
18   
19  if not pyjd.is_desktop: 
20      JS(""" 
21      var focusHandler = null; 
22      """) 
23   
24 -def ensureFocusHandler():
25 pass
26
27 -def createFocusHandler():
28 pass
29
30 -def createFocusable0():
31 pass
32
33 -def blur(elem):
34 elem.blur()
35
36 -def createFocusable():
37 e = DOM.createDiv() 38 e.tabIndex = 0 39 return e
40
41 -def focus(elem):
42 elem.focus()
43
44 -def getTabIndex(elem):
45 return elem.tabIndex
46
47 -def setAccessKey(elem, key):
48 elem.accessKey = key
49
50 -def setTabIndex(elem, index):
51 elem.tabIndex = index
52 53
54 -class FocusMixin:
55
56 - def getTabIndex(self):
57 return getTabIndex(self.getElement())
58
59 - def setAccessKey(self, key):
60 setAccessKey(self.getElement(), key)
61
62 - def setFocus(self, focused):
63 if (focused): 64 focus(self.getElement()) 65 else: 66 blur(self.getElement())
67
68 - def setTabIndex(self, index):
69 setTabIndex(self.getElement(), index)
70
71 - def isEnabled(self):
72 try: 73 return not DOM.getBooleanAttribute(self.getElement(), "disabled") 74 except TypeError: 75 return True 76 except AttributeError: 77 return True
78
79 - def setEnabled(self, enabled):
80 DOM.setBooleanAttribute(self.getElement(), "disabled", not enabled)
81
82 - def isReadonly(self):
83 try: 84 return not DOM.getBooleanAttribute(self.getElement(), "readOnly") 85 except TypeError: 86 return True 87 except AttributeError: 88 return True
89
90 - def setReadonly(self, readonly):
91 DOM.setBooleanAttribute(self.getElement(), "readOnly", readonly)
92