svgui/svguilib.py
author Edouard Tisserant
Thu, 12 Jun 2014 18:15:04 +0200
changeset 1419 d6adca8b6697
parent 748 5e69e2738957
child 1511 91538d0c242c
permissions -rwxr-xr-x
Updated tests/python : added derivated return type function declaration+call and re-enabled refrences to global FB interfaces
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
748
5e69e2738957 fix svgui toggle buttons output, now reflect pressed state
Edouard Tisserant
parents: 728
diff changeset
    51
            if self.toggle:
5e69e2738957 fix svgui toggle buttons output, now reflect pressed state
Edouard Tisserant
parents: 728
diff changeset
    52
                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
    53
            self.updateElements()
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    54
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    55
    def handleEvent(self, evt):
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    56
        # Quand le bouton de la souris est presse
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    57
        if evt.type == "mousedown":
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    58
            evt.stopPropagation()
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    59
            setCurrentObject(self)
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    60
            
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    61
            self.dragging = True
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    62
            
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    63
            if self.toggle:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    64
                self.up = self.state
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    65
            else:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    66
                self.up = False
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    67
                self.state = True
381
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    68
                updateAttr(self.id, 'state', self.state)
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    69
            self.updateElements()
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    70
        
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    71
        if isCurrentObject(self) and self.dragging:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    72
            # Quand le bouton est survole
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    73
            if evt.type == "mouseover" and self.toggle:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    74
                self.up = self.state
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    75
                self.updateElements()
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    76
            
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    77
            # Quand le curseur quitte la zone du bouton
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    78
            elif evt.type == "mouseout" and self.toggle:       
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    79
                self.up = not self.state
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    80
                self.updateElements()
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    81
            
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    82
            # Quand le bouton de la souris est relache
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    83
            elif evt.type == "mouseup":
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    84
                evt.stopPropagation()
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    85
                if self.toggle and self.up == self.state:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    86
                    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
    87
                    updateAttr(self.id, 'state', self.state)
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    88
                elif not self.toggle:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    89
                    self.up = True
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    90
                    self.state = False
381
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    91
                    updateAttr(self.id, 'state', self.state)
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    92
                    self.updateElements()
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    93
                self.dragging = False
389
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
    94
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    95
class textControl:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    96
    
381
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    97
    def __init__(self, parent, id, args):
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    98
        self.parent = parent
381
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
    99
        self.id = id
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
   100
        self.back_elt = getSVGElementById(args.back_id)
389
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
   101
        if args.text != undefined:
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
   102
            self.text = args.text
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
   103
        else:
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
   104
            self.text = ""
381
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
   105
        self.updateElements()
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
   106
    
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
   107
    def updateValues(self, values):
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
   108
        if values.text != self.value:
389
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
   109
            self.text = values.text
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
   110
            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
   111
            self.updateElements()
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
   112
    
5c0f34a9ab00 Improving support for svgui, separating setting end getting attributes functions from creating function.
laurent
parents: 371
diff changeset
   113
    def updateElements(self):
389
bde723abfdfc Bug wrong control state while refreshing interface fixed
laurent
parents: 381
diff changeset
   114
        self.back_elt.firstChild.firstChild.textContent = self.text
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
   115
    
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
   116
    def handleEvent(self, evt):
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
   117
        pass
748
5e69e2738957 fix svgui toggle buttons output, now reflect pressed state
Edouard Tisserant
parents: 728
diff changeset
   118
    
5e69e2738957 fix svgui toggle buttons output, now reflect pressed state
Edouard Tisserant
parents: 728
diff changeset
   119