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 TODO: All controls with draggable=True do not fire the OnFocus method
12 on single click. the control does not activate the OnFocus method.
13 Clicking the handle does fire OnFocus, however.
14
15 """
16
17 from pyjamas import Factory
18 from pyjamas import DOM
19 from pyjamas.ui import Focus
20 from pyjamas.ui.Control import Control
21
22
24
25 - def __init__(self, min_value, max_value, start_value=None, step=None,
26 **ka):
27
28 ka["StyleName"] = ka.get('StyleName', "gwt-VerticalSlider")
29
30
31 element = ka.pop('Element', None) or Focus.createFocusable()
32 DOM.setStyleAttribute(element, "position", "relative")
33 DOM.setStyleAttribute(element, "overflow", "hidden")
34
35 self.handle = DOM.createDiv()
36 DOM.appendChild(element, self.handle)
37
38 self.setHandleStyle("1px", "100%", "10px", "#808080")
39
40 Control.__init__(self, element, min_value, max_value, start_value,
41 step, **ka)
42
43 self.addClickListener(self)
44 self.addFocusListener(self)
45 self.addMouseListener(self)
46
57
60
65
66 - def moveControl(self, mouse_x, mouse_y, first_move=False):
67 handle_height = DOM.getIntAttribute(self.handle, "offsetHeight")
68 widget_height = self.getOffsetHeight()
69 height_range = widget_height - 10
70 relative_y = mouse_y - (handle_height / 2)
71 if relative_y < 0:
72 relative_y = 0
73 if relative_y >= height_range:
74 relative_y = height_range
75
76 relative_y = height_range - relative_y
77
78 val_diff = self.max_value - self.min_value
79 new_value = ((val_diff * relative_y) / height_range) + self.min_value
80 new_value = self.processValue(new_value)
81
82 self.setControlPos(new_value)
83 self.setValue(new_value)
84
86 widget_height = self.getOffsetHeight()
87 height_range = widget_height - 10
88 val_diff = self.max_value - self.min_value
89 relative_y = height_range * (value - self.min_value) / val_diff
90
91
92 if relative_y < 0:
93 relative_y = 0
94 if relative_y >= height_range:
95 relative_y = height_range
96
97 relative_y = height_range - relative_y
98
99
100 DOM.setStyleAttribute(self.handle, "top", "%dpx" % relative_y)
101 DOM.setStyleAttribute(self.handle, "position", "absolute")
102
103 Factory.registerClass('pyjamas.ui.VerticalSlider', 'VerticalSlider', VerticalSlider)
104