source: orange/Orange/OrangeCanvas/scheme/annotations.py @ 11151:e1bfd808981c

Revision 11151:e1bfd808981c, 2.2 KB checked in by Ales Erjavec <ales.erjavec@…>, 18 months ago (diff)

Refactored user interactions (and implementing undo/redo).

Only annotation control point editing does not yet have undo/redo.

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    def set_geometry(self, (start_pos, end_pos)):
44        self.set_line(start_pos, end_pos)
45
46    def geometry(self):
47        return (self.start_pos, self.end_pos)
48
49    geometry = Property(tuple, fget=geometry, fset=set_geometry)
50
51
52class SchemeTextAnnotation(BaseSchemeAnnotation):
53    """Text annotation in the scheme.
54    """
55    text_changed = Signal(unicode)
56
57    def __init__(self, rect, text="", anchor=None, parent=None):
58        BaseSchemeAnnotation.__init__(self, parent)
59        self.__rect = rect
60        self.__text = text
61        self.__anchor = anchor
62
63    def set_rect(self, (x, y, w, h)):
64        rect = (x, y, w, h)
65        if self.__rect != rect:
66            self.__rect = rect
67            self.geometry_changed.emit()
68
69    def rect(self):
70        return self.__rect
71
72    rect = Property(tuple, fget=rect, fset=set_rect)
73
74    def set_geometry(self, rect):
75        self.set_rect(rect)
76
77    def geometry(self):
78        return self.rect
79
80    geometry = Property(tuple, fget=geometry, fset=set_geometry)
81
82    def set_text(self, text):
83        if self.__text != text:
84            self.__text = text
85            self.text_changed.emit(text)
86
87    def text(self):
88        return self.__text
89
90    text = Property(tuple, fget=text, fset=set_text)
Note: See TracBrowser for help on using the repository browser.