plugins/python/modules/svgui/svguilib.py
author edouard
Tue, 22 Feb 2011 14:11:50 +0100
changeset 577 04baf6607a44
parent 438 6d73b097efb5
permissions -rwxr-xr-x
LPC : Completed initial debug support
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     1
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     2
class button:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     3
    
381
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
     4
    def __init__(self, parent, id, args):
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     5
        self.parent = parent
381
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
     6
        self.id = id
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
     7
        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
     8
        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
     9
        self.toggle = args.toggle
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    10
        self.active = args.active
389
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
    11
        if args.state != undefined:
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
    12
            self.state = args.state
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
    13
        else:
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
    14
            self.state = False
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    15
        self.dragging = False
389
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
    16
        if self.toggle:
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
    17
            self.up = not self.state
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    18
        else:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    19
            self.up = True
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    20
        
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    21
        # Add event on each element of the button
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    22
        if self.active:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    23
            self.back_elt.addEventListener("mouseup", self, False)
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    24
            self.back_elt.addEventListener("mousedown", self, False)
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    25
            self.back_elt.addEventListener("mouseover", self, False)
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    26
            self.back_elt.addEventListener("mouseout", self, False)
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    27
            
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    28
            self.sele_elt.addEventListener("mouseup", self, False)
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    29
            self.sele_elt.addEventListener("mousedown", self, False)
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    30
            self.sele_elt.addEventListener("mouseover", self, False)
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    31
            self.sele_elt.addEventListener("mouseout", self, False)
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    32
        
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    33
        blockSVGElementDrag(self.back_elt)
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    34
        blockSVGElementDrag(self.sele_elt)
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    35
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    36
        self.updateElements()
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    37
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    38
    # method to display the current state of interface
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    39
    def updateElements(self):
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    40
        if self.up:
438
6d73b097efb5 Bug when trying to hide SVG elements fixed
laurent
parents: 389
diff changeset
    41
            self.sele_elt.setAttribute("display", "none")
6d73b097efb5 Bug when trying to hide SVG elements fixed
laurent
parents: 389
diff changeset
    42
            self.back_elt.removeAttribute("display")
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    43
        else:
438
6d73b097efb5 Bug when trying to hide SVG elements fixed
laurent
parents: 389
diff changeset
    44
            self.sele_elt.removeAttribute("display")
6d73b097efb5 Bug when trying to hide SVG elements fixed
laurent
parents: 389
diff changeset
    45
            self.back_elt.setAttribute("display", "none")
6d73b097efb5 Bug when trying to hide SVG elements fixed
laurent
parents: 389
diff changeset
    46
            
381
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    47
    def updateValues(self, values):
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    48
        if values.state != self.state:
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    49
            self.state = values.state
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    50
            self.up = not self.state
389
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
    51
            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
    52
            self.updateElements()
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    53
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    54
    def handleEvent(self, evt):
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    55
        # Quand le bouton de la souris est presse
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    56
        if evt.type == "mousedown":
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    57
            evt.stopPropagation()
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    58
            setCurrentObject(self)
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    59
            
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    60
            self.dragging = True
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    61
            
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    62
            if self.toggle:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    63
                self.up = self.state
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    64
            else:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    65
                self.up = False
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    66
                self.state = True
381
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    67
                updateAttr(self.id, 'state', self.state)
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    68
            self.updateElements()
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    69
        
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    70
        if isCurrentObject(self) and self.dragging:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    71
            # Quand le bouton est survole
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    72
            if evt.type == "mouseover" and self.toggle:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    73
                self.up = self.state
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    74
                self.updateElements()
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    75
            
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    76
            # Quand le curseur quitte la zone du bouton
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    77
            elif evt.type == "mouseout" and self.toggle:       
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    78
                self.up = not self.state
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    79
                self.updateElements()
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    80
            
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    81
            # Quand le bouton de la souris est relache
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    82
            elif evt.type == "mouseup":
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    83
                evt.stopPropagation()
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    84
                if self.toggle and self.up == self.state:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    85
                    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
    86
                    updateAttr(self.id, 'state', self.state)
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    87
                elif not self.toggle:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    88
                    self.up = True
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    89
                    self.state = False
381
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    90
                    updateAttr(self.id, 'state', self.state)
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    91
                    self.updateElements()
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    92
                self.dragging = False
389
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
    93
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    94
class textControl:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    95
    
381
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    96
    def __init__(self, parent, id, args):
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    97
        self.parent = parent
381
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    98
        self.id = id
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    99
        self.back_elt = getSVGElementById(args.back_id)
389
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
   100
        if args.text != undefined:
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
   101
            self.text = args.text
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
   102
        else:
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
   103
            self.text = ""
381
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
   104
        self.updateElements()
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
   105
    
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
   106
    def updateValues(self, values):
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
   107
        if values.text != self.value:
389
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
   108
            self.text = values.text
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
   109
            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
   110
            self.updateElements()
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
   111
    
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
   112
    def updateElements(self):
389
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
   113
        self.back_elt.firstChild.firstChild.textContent = self.text
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
   114
    
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
   115
    def handleEvent(self, evt):
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
   116
        pass
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
   117