author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Tue, 13 Sep 2016 21:42:11 +0300 | |
changeset 1533 | aca8f43483e9 |
parent 1511 | 91538d0c242c |
child 1730 | 64d8f52bc8c8 |
permissions | -rwxr-xr-x |
1511
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
1 |
#!/usr/bin/env python |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
3 |
|
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
6 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
8 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
10 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
11 |
# This program is free software; you can redistribute it and/or |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
12 |
# modify it under the terms of the GNU General Public License |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
13 |
# as published by the Free Software Foundation; either version 2 |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
15 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
16 |
# This program is distributed in the hope that it will be useful, |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
19 |
# GNU General Public License for more details. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
20 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
21 |
# You should have received a copy of the GNU General Public License |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
22 |
# along with this program; if not, write to the Free Software |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
748
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
371 | 24 |
|
25 |
class button: |
|
26 |
||
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
27 |
def __init__(self, parent, id, args): |
371 | 28 |
self.parent = parent |
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
29 |
self.id = id |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
30 |
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
|
31 |
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
|
32 |
self.toggle = args.toggle |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
33 |
self.active = args.active |
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
34 |
if args.state != undefined: |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
35 |
self.state = args.state |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
36 |
else: |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
37 |
self.state = False |
371 | 38 |
self.dragging = False |
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
39 |
if self.toggle: |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
40 |
self.up = not self.state |
371 | 41 |
else: |
42 |
self.up = True |
|
43 |
||
44 |
# Add event on each element of the button |
|
45 |
if self.active: |
|
46 |
self.back_elt.addEventListener("mouseup", self, False) |
|
47 |
self.back_elt.addEventListener("mousedown", self, False) |
|
48 |
self.back_elt.addEventListener("mouseover", self, False) |
|
49 |
self.back_elt.addEventListener("mouseout", self, False) |
|
50 |
||
51 |
self.sele_elt.addEventListener("mouseup", self, False) |
|
52 |
self.sele_elt.addEventListener("mousedown", self, False) |
|
53 |
self.sele_elt.addEventListener("mouseover", self, False) |
|
54 |
self.sele_elt.addEventListener("mouseout", self, False) |
|
55 |
||
56 |
blockSVGElementDrag(self.back_elt) |
|
57 |
blockSVGElementDrag(self.sele_elt) |
|
58 |
||
59 |
self.updateElements() |
|
60 |
||
61 |
# method to display the current state of interface |
|
62 |
def updateElements(self): |
|
63 |
if self.up: |
|
438 | 64 |
self.sele_elt.setAttribute("display", "none") |
65 |
self.back_elt.removeAttribute("display") |
|
371 | 66 |
else: |
438 | 67 |
self.sele_elt.removeAttribute("display") |
68 |
self.back_elt.setAttribute("display", "none") |
|
69 |
||
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
70 |
def updateValues(self, values): |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
71 |
if values.state != self.state: |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
72 |
self.state = values.state |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
73 |
self.up = not self.state |
748
5e69e2738957
fix svgui toggle buttons output, now reflect pressed state
Edouard Tisserant
parents:
728
diff
changeset
|
74 |
if self.toggle: |
5e69e2738957
fix svgui toggle buttons output, now reflect pressed state
Edouard Tisserant
parents:
728
diff
changeset
|
75 |
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
|
76 |
self.updateElements() |
371 | 77 |
|
78 |
def handleEvent(self, evt): |
|
79 |
# Quand le bouton de la souris est presse |
|
80 |
if evt.type == "mousedown": |
|
81 |
evt.stopPropagation() |
|
82 |
setCurrentObject(self) |
|
83 |
||
84 |
self.dragging = True |
|
85 |
||
86 |
if self.toggle: |
|
87 |
self.up = self.state |
|
88 |
else: |
|
89 |
self.up = False |
|
90 |
self.state = True |
|
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 |
||
94 |
if isCurrentObject(self) and self.dragging: |
|
95 |
# Quand le bouton est survole |
|
96 |
if evt.type == "mouseover" and self.toggle: |
|
97 |
self.up = self.state |
|
98 |
self.updateElements() |
|
99 |
||
100 |
# Quand le curseur quitte la zone du bouton |
|
101 |
elif evt.type == "mouseout" and self.toggle: |
|
102 |
self.up = not self.state |
|
103 |
self.updateElements() |
|
104 |
||
105 |
# Quand le bouton de la souris est relache |
|
106 |
elif evt.type == "mouseup": |
|
107 |
evt.stopPropagation() |
|
108 |
if self.toggle and self.up == self.state: |
|
109 |
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
|
110 |
updateAttr(self.id, 'state', self.state) |
371 | 111 |
elif not self.toggle: |
112 |
self.up = True |
|
113 |
self.state = False |
|
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
114 |
updateAttr(self.id, 'state', self.state) |
371 | 115 |
self.updateElements() |
116 |
self.dragging = False |
|
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
117 |
|
371 | 118 |
class textControl: |
119 |
||
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
120 |
def __init__(self, parent, id, args): |
371 | 121 |
self.parent = parent |
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
122 |
self.id = id |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
123 |
self.back_elt = getSVGElementById(args.back_id) |
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
124 |
if args.text != undefined: |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
125 |
self.text = args.text |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
126 |
else: |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
127 |
self.text = "" |
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
128 |
self.updateElements() |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
129 |
|
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
130 |
def updateValues(self, values): |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
131 |
if values.text != self.value: |
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
132 |
self.text = values.text |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
133 |
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
|
134 |
self.updateElements() |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
135 |
|
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
136 |
def updateElements(self): |
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
137 |
self.back_elt.firstChild.firstChild.textContent = self.text |
371 | 138 |
|
139 |
def handleEvent(self, evt): |
|
140 |
pass |
|
748
5e69e2738957
fix svgui toggle buttons output, now reflect pressed state
Edouard Tisserant
parents:
728
diff
changeset
|
141 |
|
5e69e2738957
fix svgui toggle buttons output, now reflect pressed state
Edouard Tisserant
parents:
728
diff
changeset
|
142 |