source: orange/Orange/OrangeCanvas/scheme/annotations.py @ 11200:a0771d72047e

Revision 11200:a0771d72047e, 2.9 KB checked in by Ales Erjavec <ales.erjavec@…>, 17 months ago (diff)

Added color and font properties to SchemeAnnotation items.

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    color_changed = Signal(unicode)
22
23    def __init__(self, start_pos, end_pos, color="red", anchor=None,
24                 parent=None):
25        BaseSchemeAnnotation.__init__(self, parent)
26        self.__start_pos = start_pos
27        self.__end_pos = end_pos
28        self.__color = color
29        self.__anchor = anchor
30
31    def set_line(self, start_pos, end_pos):
32        if self.__start_pos != start_pos or self.__end_pos != end_pos:
33            self.__start_pos = start_pos
34            self.__end_pos = end_pos
35            self.geometry_changed.emit()
36
37    def start_pos(self):
38        return self.__start_pos
39
40    start_pos = Property(tuple, fget=start_pos)
41
42    def end_pos(self):
43        return self.__end_pos
44
45    end_pos = Property(tuple, fget=end_pos)
46
47    def set_geometry(self, (start_pos, end_pos)):
48        self.set_line(start_pos, end_pos)
49
50    def geometry(self):
51        return (self.start_pos, self.end_pos)
52
53    geometry = Property(tuple, fget=geometry, fset=set_geometry)
54
55    def set_color(self, color):
56        if self.__color != color:
57            self.__color = color
58            self.color_changed.emit(color)
59
60    def color(self):
61        return self.__color
62
63    color = Property(unicode, fget=color, fset=set_color)
64
65
66class SchemeTextAnnotation(BaseSchemeAnnotation):
67    """Text annotation in the scheme.
68    """
69    text_changed = Signal(unicode)
70    font_changed = Signal(unicode)
71
72    def __init__(self, rect, text="", font="", anchor=None, parent=None):
73        BaseSchemeAnnotation.__init__(self, parent)
74        self.__rect = rect
75        self.__text = text
76        self.__font = font
77        self.__anchor = anchor
78
79    def set_rect(self, (x, y, w, h)):
80        rect = (x, y, w, h)
81        if self.__rect != rect:
82            self.__rect = rect
83            self.geometry_changed.emit()
84
85    def rect(self):
86        return self.__rect
87
88    rect = Property(tuple, fget=rect, fset=set_rect)
89
90    def set_geometry(self, rect):
91        self.set_rect(rect)
92
93    def geometry(self):
94        return self.rect
95
96    geometry = Property(tuple, fget=geometry, fset=set_geometry)
97
98    def set_text(self, text):
99        if self.__text != text:
100            self.__text = text
101            self.text_changed.emit(text)
102
103    def text(self):
104        return self.__text
105
106    text = Property(tuple, fget=text, fset=set_text)
107
108    def set_font(self, font):
109        if self.__font != font:
110            self.__font = font
111            self.font_changed.emit(font)
112
113    def font(self):
114        return self.__font
115
116    font = Property(unicode, fget=font, fset=set_font)
Note: See TracBrowser for help on using the repository browser.