dgaberscek@2944: // widget_button.ysl2 dgaberscek@2944: Edouard@3024: template "widget[@type='Button']", mode="widget_class"{ usveticic@3009: || usveticic@3009: class ButtonWidget extends Widget{ usveticic@3009: frequency = 5; usveticic@3009: state = 0; usveticic@3056: plc_lock = false; usveticic@3009: active_style = undefined; usveticic@3009: inactive_style = undefined; usveticic@3009: usveticic@3056: dispatch(value) { usveticic@3056: if(value){ usveticic@3056: this.button_release(); usveticic@3056: } usveticic@3056: } usveticic@3056: usveticic@3009: on_mouse_down(evt) { usveticic@3009: if (this.active_style && this.inactive_style) { usveticic@3009: this.active_elt.setAttribute("style", this.active_style); usveticic@3009: this.inactive_elt.setAttribute("style", "display:none"); usveticic@3009: } Edouard@3018: this.apply_hmi_value(0, 1); usveticic@3056: this.plc_lock = false; usveticic@3009: } usveticic@3009: usveticic@3009: on_mouse_up(evt) { usveticic@3056: this.button_release(); usveticic@3056: } usveticic@3056: usveticic@3056: button_release(){ usveticic@3056: if(!this.plc_lock){ usveticic@3056: this.plc_lock = true; usveticic@3056: } usveticic@3056: else{ usveticic@3056: if (this.active_style && this.inactive_style) { usveticic@3056: this.active_elt.setAttribute("style", "display:none"); usveticic@3056: this.inactive_elt.setAttribute("style", this.inactive_style); usveticic@3056: } usveticic@3056: this.apply_hmi_value(0, 0); usveticic@3056: } usveticic@3009: } usveticic@3009: usveticic@3009: init() { usveticic@3009: this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined; usveticic@3009: this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined; usveticic@3009: usveticic@3009: if (this.active_style && this.inactive_style) { usveticic@3009: this.active_elt.setAttribute("style", "display:none"); usveticic@3009: this.inactive_elt.setAttribute("style", this.inactive_style); usveticic@3009: } usveticic@3009: Edouard@3018: this.element.setAttribute("onmousedown", "hmi_widgets["+this.element_id+"].on_mouse_down(evt)"); Edouard@3018: this.element.setAttribute("onmouseup", "hmi_widgets["+this.element_id+"].on_mouse_up(evt)"); usveticic@3009: } usveticic@3009: } usveticic@3009: || Edouard@3024: } usveticic@3009: usveticic@3009: dgaberscek@2976: template "widget[@type='Button']", mode="widget_defs" { dgaberscek@2976: param "hmi_element"; dgaberscek@2976: optional_labels("active inactive"); usveticic@3009: |, edouard@3000: }