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 Focus
19 from Control import Control
20
21
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-VerticalSlider"
29
30 if kwargs.has_key('Element'):
31
32 element = kwargs.pop('Element')
33 else:
34 element = Focus.createFocusable()
35 DOM.setStyleAttribute(element, "position", "relative")
36 DOM.setStyleAttribute(element, "overflow", "hidden")
37
38 self.handle = DOM.createDiv()
39 DOM.appendChild(element, self.handle)
40
41 self.setHandleStyle("1px", "100%", "10px", "#808080")
42
43 Control.__init__(self, element, min_value, max_value, start_value, step,
44 **kwargs)
45
46 self.addClickListener(self)
47 self.addFocusListener(self)
48 self.addMouseListener(self)
49
59
62
67
69 handle_height = DOM.getIntAttribute(self.handle, "offsetHeight")
70 widget_height = self.getOffsetHeight()
71 height_range = widget_height - 10
72 relative_y = mouse_y - (handle_height / 2)
73 if relative_y < 0:
74 relative_y = 0
75 if relative_y >= height_range:
76 relative_y = height_range
77
78 relative_y = height_range - relative_y
79
80 val_diff = self.max_value - self.min_value
81 new_value = ((val_diff * relative_y) / height_range) + self.min_value
82 new_value = self.processValue(new_value)
83
84 self.setControlPos(new_value)
85 self.setValue(new_value)
86
88 widget_height = self.getOffsetHeight()
89 height_range = widget_height - 10
90 val_diff = self.max_value - self.min_value
91 relative_y = height_range * (value - self.min_value) / val_diff
92
93
94 if relative_y < 0:
95 relative_y = 0
96 if relative_y >= height_range:
97 relative_y = height_range
98
99 relative_y = height_range - relative_y
100
101
102 DOM.setStyleAttribute(self.handle, "top", "%dpx" % relative_y)
103 DOM.setStyleAttribute(self.handle, "position", "absolute")
104
105 Factory.registerClass('pyjamas.ui.VerticalSlider', VerticalSlider)
106