[PyQt] question about dip models and dip io

Phil Thompson phil at riverbankcomputing.com
Thu Aug 5 09:57:31 BST 2010


On Wed, 4 Aug 2010 17:57:12 -0400, Darren Dale <dsdale24 at gmail.com> wrote:
> At the lab where I work, we generate ascii data files that contain an
> hierarchy of data. The hierarchy and the contents of the table can
> vary. I am trying to understand if it is possible to use dip to
> provide an interface to such data. I was thinking that each node in
> the hierarchy might be accessed via a dip Model, but I need to
> construct the Model based on the contents of the data file. I wondered
> how well this might integrate with dip's design, so I made a slight
> change to one of the tests in the dip test suite to experiment with
> dynamically specifying the attributes of a model:
> 
> 
> diff -r ae63e1237a24 test/tests/dip_io/test_xml.py
> --- a/test/tests/dip_io/test_xml.py	Mon Jul 26 09:20:08 2010 -0400
> +++ b/test/tests/dip_io/test_xml.py	Wed Aug 04 17:27:49 2010 -0400
> @@ -142,7 +142,9 @@
>          """ Test an Instance attribute. """
> 
>          class Klass(Model):
> -            attr = Instance(SubModel)
> +            #attr = Instance(SubModel)
> +            def __init__(self, attr=None):
> +                self.attr = attr
> 
>          storage = storage_factory()
> 
>         m_write = Klass(attr=SubModel())
> 
> 
> 
> However, after making this change, this test fails:
> 
> 
> ERROR: test_Instance (tests.dip_io.test_xml.TestModel)
> Test an Instance attribute.
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>   File "/Users/darren/Projects/dip/test/tests/dip_io/test_xml.py",
> line 156, in test_Instance
>     self.assertEquals(m_read.attr.value, m_write.attr.value)
> AttributeError: 'NoneType' object has no attribute 'value'

Adding new typed attributes to existing (statically defined) models isn't
currently supported, though it could be. An alternative approach would be
to create a new model type dynamically.

> We work on a lot of different kinds of projects, and the experiments
> are constantly changing. As a result, we are unfortunately very
> closely tied to the details of the storage format. Still, it would be
> nice to have an interface that can read one format, and write another.
> Is this possible to do this with dip, given my unusual circumstances?

Yes is the short answer, but I don't understand enough about your
particular requirements to suggest a specific approach. Also, as the
Roadmap states, proper support for import and export is in the works. It
will use the infrastructure that is already in place, but the higher level
APIs (and GUI interaction) still have to be designed.

Phil


More information about the PyQt mailing list