File: control.py

package info (click to toggle)
python-pyqtlet2 0.9.3-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,672 kB
  • sloc: python: 997; javascript: 88; makefile: 18; sh: 14
file content (59 lines) | stat: -rw-r--r-- 1,340 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import json
import logging
import os
import time

from qtpy.QtCore import Slot, Signal
from ..core import Evented

class Control(Evented):

    # controlId is a static variable shared between all controls
    # It is used to give unique names to controls
    controlId = 0
    # addedToMap and removedFromMap are signals for controls to
    # know when they're added and removed from maps
    addedToMap = Signal()
    removedFromMap = Signal()

    @property
    def map(self):
        return self._map

    @map.setter
    def map(self, map_):
        self._map = map_
        if map_ is None:
            self.removedFromMap.emit()
        else:
            self.addedToMap.emit()

    @property
    def jsName(self):
        return self._controlName

    @property
    def controlName(self):
        return self._controlName

    @controlName.setter
    def controlName(self, name):
        self._controlName = name

    def __init__(self):
        super().__init__()
        self._map = None
        self._controlName = self._getNewControlName()

    def addTo(self, map_):
        map_.addControl(self)
        return self

    def removeFrom(self, map_):
        map_.removeControl(self)

    def _getNewControlName(self):
        controlName = 'c{}'.format(self.controlId)
        Control.controlId += 1
        return controlName