source: orange/Orange/OrangeCanvas/scheme/node.py @ 11101:e5aa7c1c5b23

Revision 11101:e5aa7c1c5b23, 4.4 KB checked in by Ales Erjavec <ales.erjavec@…>, 19 months ago (diff)

Added scheme package, containing the scheme graph workflow data structure/model.

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