author | Edouard Tisserant |
Tue, 09 Apr 2019 13:13:27 +0200 | |
changeset 2585 | fc6f441582cb |
parent 1872 | 866fb3ab8778 |
permissions | -rw-r--r-- |
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 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
25 |
|
1872
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1851
diff
changeset
|
26 |
# pylint: disable=old-style-class,undefined-variable |
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1851
diff
changeset
|
27 |
|
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1851
diff
changeset
|
28 |
|
371 | 29 |
class button: |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
30 |
|
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
31 |
def __init__(self, parent, id, args): |
371 | 32 |
self.parent = parent |
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
33 |
self.id = id |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
34 |
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
|
35 |
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
|
36 |
self.toggle = args.toggle |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
37 |
self.active = args.active |
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
38 |
if args.state != undefined: |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
39 |
self.state = args.state |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
40 |
else: |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
41 |
self.state = False |
371 | 42 |
self.dragging = False |
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
43 |
if self.toggle: |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
44 |
self.up = not self.state |
371 | 45 |
else: |
46 |
self.up = True |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
47 |
|
371 | 48 |
# Add event on each element of the button |
49 |
if self.active: |
|
50 |
self.back_elt.addEventListener("mouseup", self, False) |
|
51 |
self.back_elt.addEventListener("mousedown", self, False) |
|
52 |
self.back_elt.addEventListener("mouseover", self, False) |
|
53 |
self.back_elt.addEventListener("mouseout", self, False) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
54 |
|
371 | 55 |
self.sele_elt.addEventListener("mouseup", self, False) |
56 |
self.sele_elt.addEventListener("mousedown", self, False) |
|
57 |
self.sele_elt.addEventListener("mouseover", self, False) |
|
58 |
self.sele_elt.addEventListener("mouseout", self, False) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
59 |
|
371 | 60 |
blockSVGElementDrag(self.back_elt) |
61 |
blockSVGElementDrag(self.sele_elt) |
|
62 |
||
63 |
self.updateElements() |
|
64 |
||
65 |
# method to display the current state of interface |
|
66 |
def updateElements(self): |
|
67 |
if self.up: |
|
438 | 68 |
self.sele_elt.setAttribute("display", "none") |
69 |
self.back_elt.removeAttribute("display") |
|
371 | 70 |
else: |
438 | 71 |
self.sele_elt.removeAttribute("display") |
72 |
self.back_elt.setAttribute("display", "none") |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
73 |
|
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
74 |
def updateValues(self, values): |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
75 |
if values.state != self.state: |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
76 |
self.state = values.state |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
77 |
self.up = not self.state |
748
5e69e2738957
fix svgui toggle buttons output, now reflect pressed state
Edouard Tisserant
parents:
728
diff
changeset
|
78 |
if self.toggle: |
5e69e2738957
fix svgui toggle buttons output, now reflect pressed state
Edouard Tisserant
parents:
728
diff
changeset
|
79 |
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
|
80 |
self.updateElements() |
371 | 81 |
|
82 |
def handleEvent(self, evt): |
|
83 |
# Quand le bouton de la souris est presse |
|
84 |
if evt.type == "mousedown": |
|
85 |
evt.stopPropagation() |
|
86 |
setCurrentObject(self) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
87 |
|
371 | 88 |
self.dragging = True |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
89 |
|
371 | 90 |
if self.toggle: |
91 |
self.up = self.state |
|
92 |
else: |
|
93 |
self.up = False |
|
94 |
self.state = True |
|
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
95 |
updateAttr(self.id, 'state', self.state) |
371 | 96 |
self.updateElements() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
97 |
|
371 | 98 |
if isCurrentObject(self) and self.dragging: |
99 |
# Quand le bouton est survole |
|
100 |
if evt.type == "mouseover" and self.toggle: |
|
101 |
self.up = self.state |
|
102 |
self.updateElements() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
103 |
|
371 | 104 |
# Quand le curseur quitte la zone du bouton |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
105 |
elif evt.type == "mouseout" and self.toggle: |
371 | 106 |
self.up = not self.state |
107 |
self.updateElements() |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
108 |
|
371 | 109 |
# Quand le bouton de la souris est relache |
110 |
elif evt.type == "mouseup": |
|
111 |
evt.stopPropagation() |
|
112 |
if self.toggle and self.up == self.state: |
|
113 |
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
|
114 |
updateAttr(self.id, 'state', self.state) |
371 | 115 |
elif not self.toggle: |
116 |
self.up = True |
|
117 |
self.state = False |
|
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
118 |
updateAttr(self.id, 'state', self.state) |
371 | 119 |
self.updateElements() |
120 |
self.dragging = False |
|
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
121 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
122 |
|
371 | 123 |
class textControl: |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
124 |
|
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
125 |
def __init__(self, parent, id, args): |
371 | 126 |
self.parent = parent |
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
127 |
self.id = id |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
128 |
self.back_elt = getSVGElementById(args.back_id) |
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
129 |
if args.text != undefined: |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
130 |
self.text = args.text |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
131 |
else: |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
132 |
self.text = "" |
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
133 |
self.updateElements() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
134 |
|
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
135 |
def updateValues(self, values): |
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
136 |
if values.text != self.value: |
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
137 |
self.text = values.text |
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
138 |
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
|
139 |
self.updateElements() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
140 |
|
381
5c0f34a9ab00
Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents:
371
diff
changeset
|
141 |
def updateElements(self): |
389
bde723abfdfc
Bug wrong control state while refreshing interface fixed
laurent
parents:
381
diff
changeset
|
142 |
self.back_elt.firstChild.firstChild.textContent = self.text |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
143 |
|
371 | 144 |
def handleEvent(self, evt): |
145 |
pass |