author | edouard |
Tue, 22 Feb 2011 14:11:50 +0100 | |
changeset 577 | 04baf6607a44 |
parent 438 | 6d73b097efb5 |
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 |
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
51 |
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
|
52 |
self.updateElements() |
371 | 53 |
|
54 |
def handleEvent(self, evt): |
|
55 |
# Quand le bouton de la souris est presse |
|
56 |
if evt.type == "mousedown": |
|
57 |
evt.stopPropagation() |
|
58 |
setCurrentObject(self) |
|
59 |
||
60 |
self.dragging = True |
|
61 |
||
62 |
if self.toggle: |
|
63 |
self.up = self.state |
|
64 |
else: |
|
65 |
self.up = False |
|
66 |
self.state = True |
|
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
67 |
updateAttr(self.id, 'state', self.state) |
371 | 68 |
self.updateElements() |
69 |
||
70 |
if isCurrentObject(self) and self.dragging: |
|
71 |
# Quand le bouton est survole |
|
72 |
if evt.type == "mouseover" and self.toggle: |
|
73 |
self.up = self.state |
|
74 |
self.updateElements() |
|
75 |
||
76 |
# Quand le curseur quitte la zone du bouton |
|
77 |
elif evt.type == "mouseout" and self.toggle: |
|
78 |
self.up = not self.state |
|
79 |
self.updateElements() |
|
80 |
||
81 |
# Quand le bouton de la souris est relache |
|
82 |
elif evt.type == "mouseup": |
|
83 |
evt.stopPropagation() |
|
84 |
if self.toggle and self.up == self.state: |
|
85 |
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
|
86 |
updateAttr(self.id, 'state', self.state) |
371 | 87 |
elif not self.toggle: |
88 |
self.up = True |
|
89 |
self.state = False |
|
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
90 |
updateAttr(self.id, 'state', self.state) |
371 | 91 |
self.updateElements() |
92 |
self.dragging = False |
|
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
93 |
|
371 | 94 |
class textControl: |
95 |
||
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
96 |
def __init__(self, parent, id, args): |
371 | 97 |
self.parent = parent |
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
98 |
self.id = id |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
99 |
self.back_elt = getSVGElementById(args.back_id) |
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
100 |
if args.text != undefined: |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
101 |
self.text = args.text |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
102 |
else: |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
103 |
self.text = "" |
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
104 |
self.updateElements() |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
105 |
|
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
106 |
def updateValues(self, values): |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
107 |
if values.text != self.value: |
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
108 |
self.text = values.text |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
109 |
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
|
110 |
self.updateElements() |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
111 |
|
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
112 |
def updateElements(self): |
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
113 |
self.back_elt.firstChild.firstChild.textContent = self.text |
371 | 114 |
|
115 |
def handleEvent(self, evt): |
|
116 |
pass |
|
117 |