summaryrefslogtreecommitdiff
path: root/grc/base/Element.py
diff options
context:
space:
mode:
authorJohnathan Corgan2009-09-09 17:38:27 -0700
committerJohnathan Corgan2009-09-09 17:38:27 -0700
commit7f3dc5c263a55d1a992d28d374fc7acc9ebe412b (patch)
tree61f23680cb4c3a8a83dbf947868e0340725856c3 /grc/base/Element.py
parent3c8af34f675eadd64b5fc3f0065793f3b3ff47f0 (diff)
parentb8f69ad7ba49aa85239f6de611ddfd040344f66b (diff)
downloadgnuradio-7f3dc5c263a55d1a992d28d374fc7acc9ebe412b.tar.gz
gnuradio-7f3dc5c263a55d1a992d28d374fc7acc9ebe412b.tar.bz2
gnuradio-7f3dc5c263a55d1a992d28d374fc7acc9ebe412b.zip
Merge branch 'grc' of http://gnuradio.org/git/jblum into master
* 'grc' of http://gnuradio.org/git/jblum: use show signal to perform initial gui update Fixed the usrp and usrp2 probe scripts to work with the new gui param api. propsdialog tweaks more code cleanup for properties dialog Rework the params/properties dialog and param gui class: renamed params dialog to props dialog remove unused imports, copyright date update, tweak Created recursive create labels and shapes method for gui element. replaced dict[rot] storage of areas and lines with a single list for the current rotation standardized the Element inheritance __init__ usage in gui better error msg for empty statements Implement a recursive validation api in the base Element class.
Diffstat (limited to 'grc/base/Element.py')
-rw-r--r--grc/base/Element.py48
1 files changed, 43 insertions, 5 deletions
diff --git a/grc/base/Element.py b/grc/base/Element.py
index 43cee886c..e77e7ce08 100644
--- a/grc/base/Element.py
+++ b/grc/base/Element.py
@@ -25,16 +25,54 @@ class Element(object):
##################################################
# Element Validation API
##################################################
- def validate(self): self._error_messages = list()
- def is_valid(self): return not self.get_error_messages() or not self.get_enabled()
- def add_error_message(self, msg): self._error_messages.append(msg)
- def get_error_messages(self): return self._error_messages
+ def validate(self):
+ """
+ Validate this element and call validate on all children.
+ Call this base method before adding error messages in the subclass.
+ """
+ self._error_messages = list()
+ for child in self.get_children(): child.validate()
- def rewrite(self): pass
+ def is_valid(self):
+ """
+ Is this element valid?
+ @return true when the element is enabled and has no error messages
+ """
+ return not self.get_error_messages() or not self.get_enabled()
+
+ def add_error_message(self, msg):
+ """
+ Add an error message to the list of errors.
+ @param msg the error message string
+ """
+ self._error_messages.append(msg)
+
+ def get_error_messages(self):
+ """
+ Get the list of error messages from this element and all of its children.
+ Cleverly indent the children error messages for printing purposes.
+ @return a list of error message strings
+ """
+ error_messages = list(self._error_messages) #make a copy
+ for child in self.get_children():
+ for msg in child.get_error_messages():
+ error_messages.append("%s:\n\t%s"%(child, msg.replace("\n", "\n\t")))
+ return error_messages
+
+ def rewrite(self):
+ """
+ Rewrite this element and call rewrite on all children.
+ Call this base method before rewriting the element.
+ """
+ for child in self.get_children(): child.rewrite()
def get_enabled(self): return True
+ ##############################################
+ ## Tree-like API
+ ##############################################
def get_parent(self): return self._parent
+ def get_children(self): return list()
##############################################
## Type testing methods