author | laurent |
Tue, 01 Sep 2009 10:45:07 +0200 | |
changeset 385 | 49cd52914a6f |
parent 381 | 5c0f34a9ab00 |
child 389 | bde723abfdfc |
permissions | -rw-r--r-- |
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 |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
11 |
self.state = False |
371 | 12 |
self.dragging = False |
13 |
if toggle: |
|
14 |
self.up = not state |
|
15 |
else: |
|
16 |
self.up = True |
|
17 |
||
18 |
# Add event on each element of the button |
|
19 |
if self.active: |
|
20 |
self.back_elt.addEventListener("mouseup", self, False) |
|
21 |
self.back_elt.addEventListener("mousedown", self, False) |
|
22 |
self.back_elt.addEventListener("mouseover", self, False) |
|
23 |
self.back_elt.addEventListener("mouseout", self, False) |
|
24 |
||
25 |
self.sele_elt.addEventListener("mouseup", self, False) |
|
26 |
self.sele_elt.addEventListener("mousedown", self, False) |
|
27 |
self.sele_elt.addEventListener("mouseover", self, False) |
|
28 |
self.sele_elt.addEventListener("mouseout", self, False) |
|
29 |
||
30 |
blockSVGElementDrag(self.back_elt) |
|
31 |
blockSVGElementDrag(self.sele_elt) |
|
32 |
||
33 |
self.updateElements() |
|
34 |
||
35 |
# method to display the current state of interface |
|
36 |
def updateElements(self): |
|
37 |
if self.up: |
|
38 |
self.sele_elt.setAttribute("visibility", "hidden") |
|
39 |
self.back_elt.setAttribute("visibility", "visible") |
|
40 |
else: |
|
41 |
self.sele_elt.setAttribute("visibility", "visible") |
|
42 |
self.back_elt.setAttribute("visibility", "hidden") |
|
43 |
||
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
44 |
def updateValues(self, values): |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
45 |
if values.state != self.state: |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
46 |
self.state = values.state |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
47 |
self.up = not self.state |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
48 |
self.updateElements() |
371 | 49 |
|
50 |
def handleEvent(self, evt): |
|
51 |
# Quand le bouton de la souris est presse |
|
52 |
if evt.type == "mousedown": |
|
53 |
evt.stopPropagation() |
|
54 |
setCurrentObject(self) |
|
55 |
||
56 |
self.dragging = True |
|
57 |
||
58 |
if self.toggle: |
|
59 |
self.up = self.state |
|
60 |
else: |
|
61 |
self.up = False |
|
62 |
self.state = True |
|
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
63 |
updateAttr(self.id, 'state', self.state) |
371 | 64 |
self.updateElements() |
65 |
||
66 |
if isCurrentObject(self) and self.dragging: |
|
67 |
# Quand le bouton est survole |
|
68 |
if evt.type == "mouseover" and self.toggle: |
|
69 |
self.up = self.state |
|
70 |
self.updateElements() |
|
71 |
||
72 |
# Quand le curseur quitte la zone du bouton |
|
73 |
elif evt.type == "mouseout" and self.toggle: |
|
74 |
self.up = not self.state |
|
75 |
self.updateElements() |
|
76 |
||
77 |
# Quand le bouton de la souris est relache |
|
78 |
elif evt.type == "mouseup": |
|
79 |
evt.stopPropagation() |
|
80 |
if self.toggle and self.up == self.state: |
|
81 |
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
|
82 |
updateAttr(self.id, 'state', self.state) |
371 | 83 |
elif not self.toggle: |
84 |
self.up = True |
|
85 |
self.state = False |
|
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 |
self.updateElements() |
88 |
self.dragging = False |
|
89 |
||
90 |
class textControl: |
|
91 |
||
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
92 |
def __init__(self, parent, id, args): |
371 | 93 |
self.parent = parent |
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
94 |
self.id = id |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
95 |
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
|
96 |
self.value = "" |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
97 |
self.updateElements() |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
98 |
|
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
99 |
def updateValues(self, values): |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
100 |
if values.text != self.value: |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
101 |
self.value = values.text |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
102 |
self.updateElements() |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
103 |
|
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
104 |
def updateElements(self): |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
105 |
self.back_elt.firstChild.firstChild.textContent = self.value |
371 | 106 |
|
107 |
def handleEvent(self, evt): |
|
108 |
pass |
|
109 |