source: orange/Orange/OrangeCanvas/scheme/annotations.py @ 11111:8b86d1ff9919

Revision 11111:8b86d1ff9919, 1.8 KB checked in by Ales Erjavec <ales.erjavec@…>, 18 months ago (diff)

Fixed scheme's annotation signal signatures and added tests.

Line 
1"""
2Scheme Annotations
3
4"""
5
6from PyQt4.QtCore import QObject
7from PyQt4.QtCore import pyqtSignal as Signal
8from PyQt4.QtCore import pyqtProperty as Property
9
10
11class BaseSchemeAnnotation(QObject):
12    """Base class for scheme annotations.
13    """
14    geometry_changed = Signal()
15
16
17class SchemeArrowAnnotation(BaseSchemeAnnotation):
18    """An arrow annotation in the scheme.
19    """
20
21    def __init__(self, start_pos, end_pos, anchor=None, parent=None):
22        BaseSchemeAnnotation.__init__(self, parent)
23        self.__start_pos = start_pos
24        self.__end_pos = end_pos
25        self.__anchor = anchor
26
27    def set_line(self, start_pos, end_pos):
28        if self.__start_pos != start_pos or self.__end_pos != end_pos:
29            self.__start_pos = start_pos
30            self.__end_pos = end_pos
31            self.geometry_changed.emit()
32
33    def start_pos(self):
34        return self.__start_pos
35
36    start_pos = Property(tuple, fget=start_pos)
37
38    def end_pos(self):
39        return self.__end_pos
40
41    end_pos = Property(tuple, fget=end_pos)
42
43
44class SchemeTextAnnotation(BaseSchemeAnnotation):
45    """Text annotation in the scheme.
46    """
47    text_changed = Signal(unicode)
48
49    def __init__(self, rect, text="", anchor=None, parent=None):
50        BaseSchemeAnnotation.__init__(self, parent)
51        self.__rect = rect
52        self.__text = text
53        self.__anchor = anchor
54
55    def set_rect(self, (x, y, w, h)):
56        rect = (x, y, w, h)
57        if self.__rect != rect:
58            self.__rect = rect
59            self.geometry_changed.emit()
60
61    def rect(self):
62        return self.__rect
63
64    rect = Property(tuple, fget=rect, fset=set_rect)
65
66    def set_text(self, text):
67        if self.__text != text:
68            self.__text = text
69            self.text_changed.emit(text)
70
71    def text(self):
72        return self.__text
73
74    text = Property(tuple, fget=text, fset=set_text)
Note: See TracBrowser for help on using the repository browser.