2 Copyright 2008, 2009 Free Software Foundation, Inc.
3 This file is part of GNU Radio
5 GNU Radio Companion is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 GNU Radio Companion is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 class Element(object):
22 def __init__(self, parent=None):
25 ##################################################
26 # Element Validation API
27 ##################################################
30 Validate this element and call validate on all children.
31 Call this base method before adding error messages in the subclass.
33 self._error_messages = list()
34 for child in self.get_children(): child.validate()
38 Is this element valid?
39 @return true when the element is enabled and has no error messages
41 return not self.get_error_messages() or not self.get_enabled()
43 def add_error_message(self, msg):
45 Add an error message to the list of errors.
46 @param msg the error message string
48 self._error_messages.append(msg)
50 def get_error_messages(self):
52 Get the list of error messages from this element and all of its children.
53 Cleverly indent the children error messages for printing purposes.
54 @return a list of error message strings
56 error_messages = list(self._error_messages) #make a copy
57 for child in self.get_children():
58 for msg in child.get_error_messages():
59 error_messages.append("%s:\n\t%s"%(child, msg.replace("\n", "\n\t")))
64 Rewrite this element and call rewrite on all children.
65 Call this base method before rewriting the element.
67 for child in self.get_children(): child.rewrite()
69 def get_enabled(self): return True
71 ##############################################
73 ##############################################
74 def get_parent(self): return self._parent
75 def get_children(self): return list()
77 ##############################################
78 ## Type testing methods
79 ##############################################
80 def is_element(self): return True
81 def is_platform(self): return False
82 def is_flow_graph(self): return False
83 def is_connection(self): return False
84 def is_block(self): return False
85 def is_source(self): return False
86 def is_sink(self): return False
87 def is_port(self): return False
88 def is_param(self): return False