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

Source Code for Module library.pyjamas.ui.MouseInputControl

 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 MouseListener 
19  from pyjamas.ui.InputControl import InputControl 
20   
21   
22 -class MouseInputControl(InputControl):
23
24 - def __init__(self, min_value, max_value, start_value=None, step=None, 25 **kwargs):
26 27 if not kwargs.has_key("StyleName"): 28 kwargs['StyleName'] = "gwt-MouseInputControl" 29 InputControl.__init__(self, min_value, max_value, start_value, 30 step, **kwargs) 31 32 self.addMouseListener(self) 33 self.setDragable(True)
34
35 - def onFocus(self, sender):
36 self.addStyleName("gwt-MouseInputControl-focussed")
37
38 - def onLostFocus(self, sender):
39 self.removeStyleName("gwt-MouseInputControl-focussed") 40 self.dragging = False 41 DOM.releaseCapture(self.getElement())
42
43 - def moveControl(self, mouse_x, mouse_y, first_move=False):
44 height_range = 100.0 45 val_diff = self.max_value - self.min_value 46 if first_move: 47 # back-calculate value to offset so that control doesn't jump 48 value = self.value 49 self.height_offset = mouse_y - height_range + \ 50 (height_range * (value - self.min_value)) / val_diff 51 52 relative_y = mouse_y - self.height_offset 53 #widget_height = self.getOffsetHeight() 54 #relative_y = mouse_y - (widget_height / 2) - self.height_offset 55 if relative_y < 0: 56 relative_y = 0 57 if relative_y >= height_range: 58 relative_y = height_range 59 60 relative_y = height_range - relative_y # turn round (bottom to top) 61 62 new_value = ((val_diff * relative_y) / height_range) + self.min_value 63 new_value = self.processValue(new_value) 64 65 self.setControlPos(new_value) 66 self.setValue(new_value)
67 68 Factory.registerClass('pyjamas.ui.MouseInputControl', 'InputControl', InputControl) 69