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

Source Code for Module pyjamas.ui.InputControl

 1  """ Control Widgets.  Presently comprises a Vertical Slider and derivatives. 
 2   
 3      HorizontalSlider and HorizontalSlider2 added by Bill Winder 
 4      AreaSlider and AreaSlider2 added by Bill Winder 
 5   
 6      Copyright (C) 2008, 2009, 2010 Luke Kenneth Casson Leighton <lkcl@lkcl.net> 
 7      Copyright (C) 2010 - Cedric Gestes <gestes@aldebaran-robotics.com> 
 8      Copyright (C) 2009, 2010 - Bill Winder <wgwinder@gmail.com> 
 9   
10   
11      To do: All controls with draggable=True do not fire the OnFocus methon on single click. 
12      the control does not activate the OnFocus method. Clicking the handle does fire OnFocus, however. 
13   
14  """ 
15   
16  from pyjamas import Factory 
17  from pyjamas import DOM 
18  from pyjamas.ui import KeyboardListener 
19  from pyjamas.ui.TextBox import TextBox 
20  from pyjamas.ui.Control import Control 
21   
22   
23 -class InputControl(Control):
24
25 - def __init__(self, min_value, max_value, start_value=None, step=None, 26 **kwargs):
27 28 if not kwargs.has_key("StyleName"): 29 kwargs['StyleName'] = "gwt-InputControl" 30 self.input = TextBox() 31 self.input.addKeyboardListener(self) 32 #element = DOM.createDiv() 33 if kwargs.has_key('Element'): 34 # XXX FIXME: unlikely to work! 35 element = kwargs.pop('Element') 36 else: 37 element = self.input.getElement() # YUK!!! 38 Control.__init__(self, element, min_value, max_value, start_value, step, 39 **kwargs) 40 41 self.addClickListener(self) 42 self.addFocusListener(self) 43 self.addKeyboardListener(self)
44
45 - def onFocus(self, sender):
46 self.addStyleName("gwt-InputControl-focussed")
47
48 - def onLostFocus(self, sender):
49 self.removeStyleName("gwt-InputControl-focussed")
50
51 - def setControlPos(self, value):
52 53 self.input.setText(value)
54
55 - def onKeyPress(self, sender, keycode, modifiers):
56 if keycode == KeyboardListener.KEY_ENTER: 57 DOM.eventPreventDefault(DOM.eventGetCurrentEvent()) 58 txt = self.input.getText() 59 if not txt: 60 return 61 new_value = float(txt) 62 new_value = self.processValue(new_value) 63 self.setControlPos(new_value) 64 self.setValue(new_value) 65 else: 66 Control.onKeyPress(self, sender, keycode, modifiers)
67 68 Factory.registerClass('pyjamas.ui.InputControl', 'InputControl', InputControl) 69