source: orange/Orange/OrangeCanvas/scheme/node.py @ 11419:719c8b4b6b69

Revision 11419:719c8b4b6b69, 4.8 KB checked in by Ales Erjavec <ales.erjavec@…>, 13 months ago (diff)

Fixed docstrings for scheme subpackage.

Line 
1"""
2===========
3Scheme Node
4===========
5
6"""
7
8from PyQt4.QtCore import QObject
9from PyQt4.QtCore import pyqtSignal as Signal
10from PyQt4.QtCore import pyqtProperty as Property
11
12
13class SchemeNode(QObject):
14    """
15    A node in a :class:`.Scheme`.
16
17    Parameters
18    ----------
19    description : :class:`WidgetDescription`
20        Node description instance.
21    title : str, optional
22        Node title string (if None `description.name` is used).
23    position : tuple
24        (x, y) tuple of floats for node position in a visual display.
25    properties : dict
26        Additional extra instance properties (settings, widget geometry, ...)
27    parent : :class:`QObject`
28        Parent object.
29
30    """
31
32    def __init__(self, description, title=None, position=None,
33                 properties=None, parent=None):
34        QObject.__init__(self, parent)
35        self.description = description
36
37        if title is None:
38            title = description.name
39
40        self.__title = title
41        self.__position = position or (0, 0)
42        self.__progress = -1
43        self.__processing_state = 0
44        self.properties = properties or {}
45
46    def input_channels(self):
47        """
48        Return a list of input channels (:class:`InputSignal`) for the node.
49        """
50        return list(self.description.inputs)
51
52    def output_channels(self):
53        """
54        Return a list of output channels (:class:`OutputSignal`) for the node.
55        """
56        return list(self.description.outputs)
57
58    def input_channel(self, name):
59        """
60        Return the input channel matching `name`. Raise a `ValueError`
61        if not found.
62
63        """
64        for channel in self.input_channels():
65            if channel.name == name:
66                return channel
67        raise ValueError("%r is not a valid input channel name for %r." % \
68                         (name, self.description.name))
69
70    def output_channel(self, name):
71        """
72        Return the output channel matching `name`. Raise an `ValueError`
73        if not found.
74
75        """
76        for channel in self.output_channels():
77            if channel.name == name:
78                return channel
79        raise ValueError("%r is not a valid output channel name for %r." % \
80                         (name, self.description.name))
81
82    #: The title of the node has changed
83    title_changed = Signal(unicode)
84
85    def set_title(self, title):
86        """
87        Set the node title.
88        """
89        if self.__title != title:
90            self.__title = unicode(title)
91            self.title_changed.emit(self.__title)
92
93    def title(self):
94        """
95        The node title.
96        """
97        return self.__title
98
99    title = Property(unicode, fset=set_title, fget=title)
100
101    #: Position of the node in the scheme has changed
102    position_changed = Signal(tuple)
103
104    def set_position(self, pos):
105        """
106        Set the position (``(x, y)`` tuple) of the node.
107        """
108        if self.__position != pos:
109            self.__position = pos
110            self.position_changed.emit(pos)
111
112    def position(self):
113        """
114        ``(x, y)`` tuple containing the position of the node in the scheme.
115        """
116        return self.__position
117
118    position = Property(tuple, fset=set_position, fget=position)
119
120    #: Node's progress value has changed.
121    progress_changed = Signal(float)
122
123    def set_progress(self, value):
124        """
125        Set the progress value.
126        """
127        if self.__progress != value:
128            self.__progress = value
129            self.progress_changed.emit(value)
130
131    def progress(self):
132        """
133        The current progress value. -1 if progress is not set.
134        """
135        return self.__progress
136
137    progress = Property(float, fset=set_progress, fget=progress)
138
139    #: Node's processing state has changed.
140    processing_state_changed = Signal(int)
141
142    def set_processing_state(self, state):
143        """
144        Set the node processing state.
145        """
146        if self.__processing_state != state:
147            self.__processing_state = state
148            self.processing_state_changed.emit(state)
149
150    def processing_state(self):
151        """
152        The node processing state, 0 for not processing, 1 the node is busy.
153        """
154        return self.__processing_state
155
156    processing_state = Property(int, fset=set_processing_state,
157                                fget=processing_state)
158
159    def set_tool_tip(self, tool_tip):
160        if self.__tool_tip != tool_tip:
161            self.__tool_tip = tool_tip
162
163    def tool_tip(self):
164        return self.__tool_tip
165
166    tool_tip = Property(str, fset=set_tool_tip,
167                        fget=tool_tip)
168
169    def __str__(self):
170        return u"SchemeNode(description_id=%s, title=%r, ...)" % \
171                (str(self.description.id), self.title)
172
173    def __repr__(self):
174        return str(self)
Note: See TracBrowser for help on using the repository browser.