andrej@1511: #!/usr/bin/env python andrej@1511: # -*- coding: utf-8 -*- andrej@1511: andrej@1511: # This file is part of Beremiz, a Integrated Development Environment for andrej@1511: # programming IEC 61131-3 automates supporting plcopen standard and CanFestival. andrej@1511: # andrej@1511: # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD andrej@1511: # andrej@1511: # See COPYING file for copyrights details. andrej@1511: # andrej@1511: # This program is free software; you can redistribute it and/or andrej@1511: # modify it under the terms of the GNU General Public License andrej@1511: # as published by the Free Software Foundation; either version 2 andrej@1511: # of the License, or (at your option) any later version. andrej@1511: # andrej@1511: # This program is distributed in the hope that it will be useful, andrej@1511: # but WITHOUT ANY WARRANTY; without even the implied warranty of andrej@1511: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrej@1511: # GNU General Public License for more details. andrej@1511: # andrej@1511: # You should have received a copy of the GNU General Public License andrej@1511: # along with this program; if not, write to the Free Software andrej@1511: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. laurent@371: andrej@1736: andrej@1872: # pylint: disable=old-style-class,undefined-variable andrej@1872: andrej@1872: laurent@371: class button: andrej@1730: laurent@381: def __init__(self, parent, id, args): laurent@371: self.parent = parent laurent@381: self.id = id laurent@381: self.back_elt = getSVGElementById(args.back_id) laurent@381: self.sele_elt = getSVGElementById(args.sele_id) laurent@381: self.toggle = args.toggle laurent@381: self.active = args.active laurent@389: if args.state != undefined: laurent@389: self.state = args.state laurent@389: else: laurent@389: self.state = False laurent@371: self.dragging = False laurent@389: if self.toggle: laurent@389: self.up = not self.state laurent@371: else: laurent@371: self.up = True andrej@1730: laurent@371: # Add event on each element of the button laurent@371: if self.active: laurent@371: self.back_elt.addEventListener("mouseup", self, False) laurent@371: self.back_elt.addEventListener("mousedown", self, False) laurent@371: self.back_elt.addEventListener("mouseover", self, False) laurent@371: self.back_elt.addEventListener("mouseout", self, False) andrej@1730: laurent@371: self.sele_elt.addEventListener("mouseup", self, False) laurent@371: self.sele_elt.addEventListener("mousedown", self, False) laurent@371: self.sele_elt.addEventListener("mouseover", self, False) laurent@371: self.sele_elt.addEventListener("mouseout", self, False) andrej@1730: laurent@371: blockSVGElementDrag(self.back_elt) laurent@371: blockSVGElementDrag(self.sele_elt) laurent@371: laurent@371: self.updateElements() laurent@371: laurent@371: # method to display the current state of interface laurent@371: def updateElements(self): laurent@371: if self.up: laurent@438: self.sele_elt.setAttribute("display", "none") laurent@438: self.back_elt.removeAttribute("display") laurent@371: else: laurent@438: self.sele_elt.removeAttribute("display") laurent@438: self.back_elt.setAttribute("display", "none") andrej@1730: laurent@381: def updateValues(self, values): laurent@381: if values.state != self.state: laurent@381: self.state = values.state laurent@381: self.up = not self.state Edouard@748: if self.toggle: Edouard@748: updateAttr(self.id, 'state', self.state) laurent@381: self.updateElements() laurent@371: laurent@371: def handleEvent(self, evt): laurent@371: # Quand le bouton de la souris est presse laurent@371: if evt.type == "mousedown": laurent@371: evt.stopPropagation() laurent@371: setCurrentObject(self) andrej@1730: laurent@371: self.dragging = True andrej@1730: laurent@371: if self.toggle: laurent@371: self.up = self.state laurent@371: else: laurent@371: self.up = False laurent@371: self.state = True laurent@381: updateAttr(self.id, 'state', self.state) laurent@371: self.updateElements() andrej@1730: laurent@371: if isCurrentObject(self) and self.dragging: laurent@371: # Quand le bouton est survole laurent@371: if evt.type == "mouseover" and self.toggle: laurent@371: self.up = self.state laurent@371: self.updateElements() andrej@1730: laurent@371: # Quand le curseur quitte la zone du bouton andrej@1730: elif evt.type == "mouseout" and self.toggle: laurent@371: self.up = not self.state laurent@371: self.updateElements() andrej@1730: laurent@371: # Quand le bouton de la souris est relache laurent@371: elif evt.type == "mouseup": laurent@371: evt.stopPropagation() laurent@371: if self.toggle and self.up == self.state: laurent@371: self.state = not self.state laurent@381: updateAttr(self.id, 'state', self.state) laurent@371: elif not self.toggle: laurent@371: self.up = True laurent@371: self.state = False laurent@381: updateAttr(self.id, 'state', self.state) laurent@371: self.updateElements() laurent@371: self.dragging = False laurent@389: andrej@1736: laurent@371: class textControl: andrej@1730: laurent@381: def __init__(self, parent, id, args): laurent@371: self.parent = parent laurent@381: self.id = id laurent@381: self.back_elt = getSVGElementById(args.back_id) laurent@389: if args.text != undefined: laurent@389: self.text = args.text laurent@389: else: laurent@389: self.text = "" laurent@381: self.updateElements() andrej@1730: laurent@381: def updateValues(self, values): laurent@381: if values.text != self.value: laurent@389: self.text = values.text laurent@389: updateAttr(self.id, 'text', self.text) laurent@381: self.updateElements() andrej@1730: laurent@381: def updateElements(self): laurent@389: self.back_elt.firstChild.firstChild.textContent = self.text andrej@1730: laurent@371: def handleEvent(self, evt): laurent@371: pass