author | Laurent Bessard |
Mon, 27 Aug 2012 22:13:43 +0200 | |
changeset 805 | c0f60c2a5a24 |
parent 748 | 5e69e2738957 |
child 1511 | 91538d0c242c |
permissions | -rwxr-xr-x |
371 | 1 |
|
2 |
class button: |
|
3 |
||
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
4 |
def __init__(self, parent, id, args): |
371 | 5 |
self.parent = parent |
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
6 |
self.id = id |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
7 |
self.back_elt = getSVGElementById(args.back_id) |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
8 |
self.sele_elt = getSVGElementById(args.sele_id) |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
9 |
self.toggle = args.toggle |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
10 |
self.active = args.active |
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
11 |
if args.state != undefined: |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
12 |
self.state = args.state |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
13 |
else: |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
14 |
self.state = False |
371 | 15 |
self.dragging = False |
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
16 |
if self.toggle: |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
17 |
self.up = not self.state |
371 | 18 |
else: |
19 |
self.up = True |
|
20 |
||
21 |
# Add event on each element of the button |
|
22 |
if self.active: |
|
23 |
self.back_elt.addEventListener("mouseup", self, False) |
|
24 |
self.back_elt.addEventListener("mousedown", self, False) |
|
25 |
self.back_elt.addEventListener("mouseover", self, False) |
|
26 |
self.back_elt.addEventListener("mouseout", self, False) |
|
27 |
||
28 |
self.sele_elt.addEventListener("mouseup", self, False) |
|
29 |
self.sele_elt.addEventListener("mousedown", self, False) |
|
30 |
self.sele_elt.addEventListener("mouseover", self, False) |
|
31 |
self.sele_elt.addEventListener("mouseout", self, False) |
|
32 |
||
33 |
blockSVGElementDrag(self.back_elt) |
|
34 |
blockSVGElementDrag(self.sele_elt) |
|
35 |
||
36 |
self.updateElements() |
|
37 |
||
38 |
# method to display the current state of interface |
|
39 |
def updateElements(self): |
|
40 |
if self.up: |
|
438 | 41 |
self.sele_elt.setAttribute("display", "none") |
42 |
self.back_elt.removeAttribute("display") |
|
371 | 43 |
else: |
438 | 44 |
self.sele_elt.removeAttribute("display") |
45 |
self.back_elt.setAttribute("display", "none") |
|
46 |
||
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
47 |
def updateValues(self, values): |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
48 |
if values.state != self.state: |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
49 |
self.state = values.state |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
50 |
self.up = not self.state |
748
5e69e2738957
fix svgui toggle buttons output, now reflect pressed state
Edouard Tisserant
parents:
728
diff
changeset
|
51 |
if self.toggle: |
5e69e2738957
fix svgui toggle buttons output, now reflect pressed state
Edouard Tisserant
parents:
728
diff
changeset
|
52 |
updateAttr(self.id, 'state', self.state) |
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
53 |
self.updateElements() |
371 | 54 |
|
55 |
def handleEvent(self, evt): |
|
56 |
# Quand le bouton de la souris est presse |
|
57 |
if evt.type == "mousedown": |
|
58 |
evt.stopPropagation() |
|
59 |
setCurrentObject(self) |
|
60 |
||
61 |
self.dragging = True |
|
62 |
||
63 |
if self.toggle: |
|
64 |
self.up = self.state |
|
65 |
else: |
|
66 |
self.up = False |
|
67 |
self.state = True |
|
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
68 |
updateAttr(self.id, 'state', self.state) |
371 | 69 |
self.updateElements() |
70 |
||
71 |
if isCurrentObject(self) and self.dragging: |
|
72 |
# Quand le bouton est survole |
|
73 |
if evt.type == "mouseover" and self.toggle: |
|
74 |
self.up = self.state |
|
75 |
self.updateElements() |
|
76 |
||
77 |
# Quand le curseur quitte la zone du bouton |
|
78 |
elif evt.type == "mouseout" and self.toggle: |
|
79 |
self.up = not self.state |
|
80 |
self.updateElements() |
|
81 |
||
82 |
# Quand le bouton de la souris est relache |
|
83 |
elif evt.type == "mouseup": |
|
84 |
evt.stopPropagation() |
|
85 |
if self.toggle and self.up == self.state: |
|
86 |
self.state = not self.state |
|
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
87 |
updateAttr(self.id, 'state', self.state) |
371 | 88 |
elif not self.toggle: |
89 |
self.up = True |
|
90 |
self.state = False |
|
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
91 |
updateAttr(self.id, 'state', self.state) |
371 | 92 |
self.updateElements() |
93 |
self.dragging = False |
|
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
94 |
|
371 | 95 |
class textControl: |
96 |
||
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
97 |
def __init__(self, parent, id, args): |
371 | 98 |
self.parent = parent |
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
99 |
self.id = id |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
100 |
self.back_elt = getSVGElementById(args.back_id) |
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
101 |
if args.text != undefined: |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
102 |
self.text = args.text |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
103 |
else: |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
104 |
self.text = "" |
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
105 |
self.updateElements() |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
106 |
|
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
107 |
def updateValues(self, values): |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
108 |
if values.text != self.value: |
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
109 |
self.text = values.text |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
110 |
updateAttr(self.id, 'text', self.text) |
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
111 |
self.updateElements() |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
112 |
|
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
113 |
def updateElements(self): |
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
114 |
self.back_elt.firstChild.firstChild.textContent = self.text |
371 | 115 |
|
116 |
def handleEvent(self, evt): |
|
117 |
pass |
|
748
5e69e2738957
fix svgui toggle buttons output, now reflect pressed state
Edouard Tisserant
parents:
728
diff
changeset
|
118 |
|
5e69e2738957
fix svgui toggle buttons output, now reflect pressed state
Edouard Tisserant
parents:
728
diff
changeset
|
119 |