How to store the reference of a dictionary element ?

John Roth johnroth at ameritech.net
Thu Dec 19 08:21:00 EST 2002


"Alfredo P. Ricafort" <alpot at mylinuxsite.com> wrote in message
news:mailman.1040272046.3141.python-list at python.org...
> On Wed, 2002-12-18 at 06:36, Bengt Richter wrote:
>
> > I tried to understand "what you are *really* trying do do"(tm) but
> couldn't ;-)
> > If you would define your requirements independently of preconceived
> implementation
> > ideas, I suspect people would be able to help better.
> >
>
> I'm not exactly sure if you are really replying to this thread. But
just
> in case you are, and if you curious on what I am trying to do, then
here
> it is:
>
> I am writing a wxPython program and I am trying to create a class that
> is somewhat similar to the menu_item_factory of GTK+.  The structure
of
> the INPUT data to the class is like this:
>
> inputData=( (path,attribute1,attribute2,....),....)
>
> for example:
>    inputData=(
>        ('/&File',               'text','text'....),
>        ('/File/&New',           'text','text'....),
>        ('/File/New/&Folder',    'text','text'..),
>        ('/File/New/&Directory', 'text','text'..),
>        ('/&Edit',               'text','text'..)
>    )
>
> When this input is pass on to the class, it will be broken down to a
new
> structure that the program can easily manipulate. The OUTPUT structure
> will be somewhat like this:
>
>   outputData={'menuKey':[attribute1,attribute2,{submenu}],..}
>
> In our example above, the outcome will be like this:
>
>   outputData={'File':['text','text',
>                       {'New':['text','text',
>                               {'Folder':['text','text',None],
>                                'Directory:['text','text',None]
>                              ]
>                      ],
>               'Edit':['text','text',None]
>               }
>
> But I realized that for this type of structure, where the submenus
could
> be n level deep, I will have difficulty searching for a particular
> element in the dictionary.  Instead, I am thinking of changing the
> structure to just 1 level like this:
>
> In Python:
> ----------
> (1)
>
>
inputData={'parentKey':[attribute1,attribute2,ptrToChild1,ptrToChild2...
],
'child1Key':[attribute1,attribute2,ptrToGrandChild1....]
>            'child2Key':[attribute1,attribute2,None]
>            'grandchild1Key':[attribute1,attribute2,None]
>           ..}
>
>      OR
>
> (2) inputData= {'parentKey':[attribute1,attribute2,None],
>                   'child1Key':[attribute1,attribute2,ptrToParent]
>                   'child2Key':[attribute1,attribute2,ptrToParent]
>                   'grandchildKey':[attribute1,attribute2,ptrToChild1]
>                  ..}
>
> (2) In C
> --------
>    struct inputData {
>           struct inputData *parent;
>           char * path;
>           char * attribute1;
>           char * attribute2;
>    }
>
>
> What I was hoping for is to store the reference(not the value) of the
> parent or the child. So if I where to use (2) as my structure and say:
>
>    parent=inputData['child1Key'][2]
>
> then I would end up with the reference to the 'parentKey' element.  At
> the same time I can use
>
>    inputData.has_key(key)
>
> to search for a particular key.
>
>
> Hope this clear things up.

I think it does. What occurs to me off the top is that you're
looking at the wrong data representation. I'd try to build
menu objects, and let them handle the relationships.

The other question to ponder is: what's the benefit of
trying to make the interface to wxWindows' menus look
like the interface to GTK+ menus?

John Roth

>
> AL
>
>
>





More information about the Python-list mailing list