laurent@371: laurent@371: class button: laurent@371: 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 laurent@371: 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) laurent@371: 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) laurent@371: 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") laurent@438: 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) laurent@371: laurent@371: self.dragging = True laurent@371: 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() laurent@371: 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() laurent@371: laurent@371: # Quand le curseur quitte la zone du bouton laurent@371: elif evt.type == "mouseout" and self.toggle: laurent@371: self.up = not self.state laurent@371: self.updateElements() laurent@371: 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: laurent@371: class textControl: laurent@371: 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() laurent@381: 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() laurent@381: laurent@381: def updateElements(self): laurent@389: self.back_elt.firstChild.firstChild.textContent = self.text laurent@371: laurent@371: def handleEvent(self, evt): laurent@371: pass Edouard@748: Edouard@748: