mailr10392 - /branches/bieri_gui/data/data_classes.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on January 26, 2010 - 17:19:
Author: bugman
Date: Tue Jan 26 17:19:41 2010
New Revision: 10392

URL: http://svn.gna.org/viewcvs/relax?rev=10392&view=rev
Log:
Created the RelaxListType class.

This generic list type with XML support will be used for storing the GUI info.


Modified:
    branches/bieri_gui/data/data_classes.py

Modified: branches/bieri_gui/data/data_classes.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/bieri_gui/data/data_classes.py?rev=10392&r1=10391&r2=10392&view=diff
==============================================================================
--- branches/bieri_gui/data/data_classes.py (original)
+++ branches/bieri_gui/data/data_classes.py Tue Jan 26 17:19:41 2010
@@ -1,6 +1,6 @@
 
###############################################################################
 #                                                                            
 #
-# Copyright (C) 2003-2004, 2006-2008 Edward d'Auvergne                       
 #
+# Copyright (C) 2003-2004, 2006-2010 Edward d'Auvergne                       
 #
 #                                                                            
 #
 # This file is part of the program relax.                                    
 #
 #                                                                            
 #
@@ -20,12 +20,15 @@
 #                                                                            
 #
 
###############################################################################
 
+# Module docstring.
+"""Basic objects used to build the relax data store."""
+
 # Python module imports.
 from re import search
 
+# relax module imports.
+from relax_xml import fill_object_contents, xml_to_object
 
-# Empty data container.
-#######################
 
 class Element(object):
     """Empty data container."""
@@ -73,3 +76,79 @@
 
         # The Element container is empty.
         return True
+
+
+
+class RelaxListType(ListType): 
+    """An empty list type container."""
+
+    def __init__(self):
+        """Initialise some class variables."""
+
+        # Execute the base class __init__() method.
+        super(RelaxListType, self).__init__()
+
+        # Some generic initial names.
+        self.list_name = 'relax_list'
+        self.list_desc = 'relax list container'
+        self.element_name = 'relax_list_element'
+        self.element_desc = 'relax container'
+
+        # Blacklisted objects.
+        self.blacklist = []
+
+
+    def from_xml(self, super_node):
+        """Recreate the data structure from the XML node.
+
+        @param super_node:     The XML nodes.
+        @type super_node:      xml.dom.minicompat.Element instance
+        """
+
+        # Recreate all the data structures.
+        xml_to_object(super_node, self, blacklist=self.blacklist)
+
+        # Get the individual elements.
+        nodes = super_node.getElementsByTagName(self.element_name)
+
+        # Loop over the child nodes.
+        for node in nodes:
+            # Add the data container.
+            self.add_item(node.getAttribute('name'))
+
+            # Recreate all the other data structures.
+            xml_to_object(node, self[-1])
+
+
+    def to_xml(self, doc, element):
+        """Create an XML element for the list data structure.
+
+        @param doc:     The XML document object.
+        @type doc:      xml.dom.minidom.Document instance
+        @param element: The element to add the list data structure XML 
element to.
+        @type element:  XML element object
+        """
+
+        # Create the element and add it to the higher level element.
+        list_element = doc.createElement(self.list_name)
+        element.appendChild(list_element)
+
+        # Set the list attributes.
+        list_element.setAttribute('desc', self.desc)
+
+        # Add all simple python objects within the PipeContainer to the pipe 
element.
+        fill_object_contents(doc, list_element, object=self, 
blacklist=list(self.__class__.__dict__.keys() + list.__dict__.keys()))
+
+        # Loop over the list.
+        for i in xrange(len(self)):
+            # Create an XML element for each container.
+            element = doc.createElement(self.element_name)
+            list_element.appendChild(element)
+            element.setAttribute('index', repr(i))
+            element.setAttribute('desc', self.element_desc)
+
+            # Add all simple python objects within the PipeContainer to the 
pipe element.
+            fill_object_contents(doc, element, object=self[i], 
blacklist=list(self[i].__class__.__dict__.keys()))
+
+
+




Related Messages


Powered by MHonArc, Updated Tue Jan 26 17:40:02 2010