Enthought TraitsUI based Python IDE

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Enthought TraitsUI based Python IDE

Vishal
Hello,

Is there anyone working on a TraitsUI (Envisage) based Python IDE?

or is there anyone who has tried extending the basic 'charm' example?

Thanks and best regards,
Vishal Sapre

On Tue, Dec 14, 2010 at 9:15 PM, <[hidden email]> wrote:
Send Enthought-Dev mailing list submissions to
       [hidden email]

To subscribe or unsubscribe via the World Wide Web, visit
       https://mail.enthought.com/mailman/listinfo/enthought-dev
or, via email, send a message with subject or body 'help' to
       [hidden email]

You can reach the person managing the list at
       [hidden email]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Enthought-Dev digest..."


Today's Topics:

  1. EPD version for SUSE10.2 (Matthieu Brucher)
  2. Re: EPD version for SUSE10.2 (Ilan Schnell)
  3. Re: EPD version for SUSE10.2 (Matthieu Brucher)
  4. Re: Dynamically generated Enums [Serco No Marking] (Sam Wedge)
  5. Re: Dynamically generated Enums [Serco No Marking] (Robert Kern)


----------------------------------------------------------------------

Message: 1
Date: Tue, 14 Dec 2010 14:14:07 +0100
From: Matthieu Brucher <[hidden email]>
Subject: [Enthought-Dev] EPD version for SUSE10.2
To: [hidden email]
Message-ID:
       <[hidden email]>
Content-Type: text/plain; charset=ISO-8859-1

Hi,

I've downloaded the latest release from the repository, but I get a
floating exception when trying to install it on a SUSE10.2 (x86_64).
Is SUSE 10.2 still supported?

Matthieu
--
Information System Engineer, Ph.D.
Blog: http://matt.eifelle.com
LinkedIn: http://www.linkedin.com/in/matthieubrucher


------------------------------

Message: 2
Date: Tue, 14 Dec 2010 08:50:41 -0600
From: Ilan Schnell <[hidden email]>
Subject: Re: [Enthought-Dev] EPD version for SUSE10.2
To: [hidden email]
Message-ID:
       <[hidden email]>
Content-Type: text/plain; charset=UTF-8

What exactly is the traceback you are getting?  Did
you install epd-6.3-2-rh3-x86_64.sh or
epd-6.3-2-rh5-x86_64.sh?

- Ilan

On Tue, Dec 14, 2010 at 7:14 AM, Matthieu Brucher
<[hidden email]> wrote:
> Hi,
>
> I've downloaded the latest release from the repository, but I get a
> floating exception when trying to install it on a SUSE10.2 (x86_64).
> Is SUSE 10.2 still supported?
>
> Matthieu
> --
> Information System Engineer, Ph.D.
> Blog: http://matt.eifelle.com
> LinkedIn: http://www.linkedin.com/in/matthieubrucher
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>


------------------------------

Message: 3
Date: Tue, 14 Dec 2010 16:13:53 +0100
From: Matthieu Brucher <[hidden email]>
Subject: Re: [Enthought-Dev] EPD version for SUSE10.2
To: [hidden email]
Message-ID:
       <[hidden email]>
Content-Type: text/plain; charset=ISO-8859-1

I got a floating point exception when it ran enplace.
I've tried with rh3, it worked this time, so I guess there are a lot
of diffrences between SLES10.2 and SLESS 11 ;)

Thanks for the tip,

Matthieu

2010/12/14 Ilan Schnell <[hidden email]>:
> What exactly is the traceback you are getting? ?Did
> you install epd-6.3-2-rh3-x86_64.sh or
> epd-6.3-2-rh5-x86_64.sh?
>
> - Ilan
>
> On Tue, Dec 14, 2010 at 7:14 AM, Matthieu Brucher
> <[hidden email]> wrote:
>> Hi,
>>
>> I've downloaded the latest release from the repository, but I get a
>> floating exception when trying to install it on a SUSE10.2 (x86_64).
>> Is SUSE 10.2 still supported?
>>
>> Matthieu
>> --
>> Information System Engineer, Ph.D.
>> Blog: http://matt.eifelle.com
>> LinkedIn: http://www.linkedin.com/in/matthieubrucher
>> _______________________________________________
>> Enthought-Dev mailing list
>> [hidden email]
>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>



--
Information System Engineer, Ph.D.
Blog: http://matt.eifelle.com
LinkedIn: http://www.linkedin.com/in/matthieubrucher


------------------------------

Message: 4
Date: Tue, 14 Dec 2010 15:20:05 +0000
From: "Sam Wedge" <[hidden email]>
Subject: Re: [Enthought-Dev] Dynamically generated Enums [Serco No
       Marking]
To: <[hidden email]>
Message-ID: <[hidden email]>
Content-Type: text/plain; charset=US-ASCII

Thanks for your push in the right direction, Robert.

I have managed to link this in with what I want to do, but have hit a slight snag.

I have a dictionary of lists. When running the code below, there are several selection combo boxes on the screen. The first is a list of keys from my dictionary. The rest are lists containing the values associated with all the keys except the one selected by the first list. If a different key is selected, then the view updates and removes the currently selected key.

The snag is that the function listening for the trait change is in a separate class to the function that I want to execute should that change take place. I can get around this by explicitly referencing the instance of the class (mkv), but this feels messy and wrong, and causes an error when the code is run since mkv is not initiated until the interpreter begins running the code. Once going, it works as intended.

I changed Robert's code to put the KeyValue class within ManyKeyValues, as I felt that it belonged there (it will not be used by anything else and is integral to that particular display).

Essentially, this boils down to the interaction between two classes. We create an instance of ManyKeyValues. This instance creates multiple instances of KeyValue. How can a change in KeyValue change something in ManyKeyValues?

I appreciate your time.

Regards,

Sam

Code snippet below.


from enthought.traits.api import Enum, HasTraits, Instance, List, Str, Any
from enthought.traits.ui.api import Item, UItem, View, ListEditor, EnumEditor

class ManyKeyValues(HasTraits):
   '''Describes the overall view'''

   class KeyValue(HasTraits):
       '''Describes the view of the lists'''
       key = Str()
       value = Str()
       values = List(Str)

       traits_view = View(
           UItem('key', style='readonly'),
           UItem('value', editor=EnumEditor(name='values')),
       )

       def _value_changed(self):
           if self.key == 'List of Variables':
               mkv.change_display()


   key_list = List(Instance(KeyValue))
   key_values = List(Instance(KeyValue))

   traits_view = View(
       UItem('key_list' ,editor=ListEditor(style='custom',mutable=False)),
       UItem('key_values', editor=ListEditor(style='custom',mutable=False))
   )

   def __init__(self,variables):
       self.variables = variables
       keys = self.variables.keys()
       self.key_list = [self.KeyValue(key='List of Variables', value=keys[0],values=keys)]
       self.change_display()

   def change_display(self):
       key_values = []
       for key in self.variables.keys():
           if key != self.key_list[0].value:
               key_values.append(self.KeyValue(key=key, value=self.variables[key][0],values=list(set(self.variables[key]))))
       self.key_values = key_values


if __name__ == '__main__':
   data = {}
   data['one'] = ['1','2','3']
   data['two'] = ['a','b','c']
   data['three'] = ['foo','bar','baz']

   mkv = ManyKeyValues(data)
   mkv.configure_traits()




>>> Robert Kern <[hidden email]> 07/12/2010 18:26 >>>
On Tue, Dec 7, 2010 at 12:07 PM, Sam Wedge <[hidden email]> wrote:
> Hi,
>
> I have a dictionary which is populated from a csv file. The keys come from the first line of this file, while the data comes from the rest of the file. The result is a dictionary whose values are all lists.
>
> I am using this data with a TraitsUI display. I would like to display this data as a series of Enum instances, whose label is given by the dictionary key, and whose values are given by the list stored under that key. I can do this easily by coding each Enum in explicitly, but due to the ever-changing csv file structure, I require this to be done dynamically, perhaps by looping over the keys.
>
> Does anyone have any experience with doing this sort of thing? I can't see how to do it, as each Enum needs to be a variable in its own right, rather than a dictionary key.

In short, use a ListEditor on a List of instances which edit each
key-value pair.


from enthought.traits.api import Enum, HasTraits, Instance, List, Str
from enthought.traits.ui import api as tui


class KeyValue(HasTraits):
   key = Str()
   value = Str()
   values = List(Str)

   traits_view = tui.View(
       tui.UItem('key', style='readonly'),
       tui.UItem('value', editor=tui.EnumEditor(name='values')),
   )


class ManyKeyValues(HasTraits):
   key_values = List(Instance(KeyValue))

   traits_view = tui.View(
       tui.UItem('key_values', editor=tui.ListEditor(style='custom',
mutable=False)),
   )

   @classmethod
   def fromrows(cls, rows):
       key_values = []
       for row in rows:
           key_values.append(KeyValue(key=row[0], value=row[1],
values=row[1:]))
       return cls(key_values=key_values)

rows = [
   ['Key A', 'Value A1', 'Value A2'],
   ['Key B', 'Value B1', 'Value B2'],
   ['Key C', 'Value C1', 'Value C2', 'Value C3'],
   ['Key D', 'Value D1', 'Value D2', 'Value D3'],
]

if __name__ == '__main__':
   mkv = ManyKeyValues.fromrows(rows)
   mkv.configure_traits()

   print 'Selected Key/Value pairs:'
   for kv in mkv.key_values:
       print '%s: %s' % (kv.key, kv.value)



--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
 -- Umberto Eco
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________

*****Disclaimer************
This email and any attachments may contain confidential and/or
privileged material; it is for the intended addressee(s) only. If
you are not a named addressee, you must not use, retain or
disclose such information.

Serco cannot guarantee that the email or any attachments are free
from viruses.
The views expressed in this email are those of the originator and
do not necessarily represent the views of Serco.

Nothing in this email shall bind Serco in any contract or
obligation.

Please note that all email messages sent to Serco are subject to
monitoring / interception for lawful business purposes.

Serco Group plc.  Registered in England and Wales.  No: 2048608
Registered Office:  Serco House, 16 Bartley Wood Business Park,
Bartley Way, Hook, Hampshire, RG27 9UY, United Kingdom.
*****End Disclaimer********



------------------------------

Message: 5
Date: Tue, 14 Dec 2010 09:45:34 -0600
From: Robert Kern <[hidden email]>
Subject: Re: [Enthought-Dev] Dynamically generated Enums [Serco No
       Marking]
To: [hidden email]
Message-ID:
       <[hidden email]>
Content-Type: text/plain; charset="utf-8"

On Tue, Dec 14, 2010 at 9:20 AM, Sam Wedge <[hidden email]> wrote:
> Thanks for your push in the right direction, Robert.
>
> I have managed to link this in with what I want to do, but have hit a slight snag.
>
> I have a dictionary of lists. When running the code below, there are several selection combo boxes on the screen. The first is a list of keys from my dictionary. The rest are lists containing the values associated with all the keys except the one selected by the first list. If a different key is selected, then the view updates and removes the currently selected key.
>
> The snag is that the function listening for the trait change is in a separate class to the function that I want to execute should that change take place. I can get around this by explicitly referencing the instance of the class (mkv), but this feels messy and wrong, and causes an error when the code is run since mkv is not initiated until the interpreter begins running the code. Once going, it works as intended.
>
> I changed Robert's code to put the KeyValue class within ManyKeyValues, as I felt that it belonged there (it will not be used by anything else and is integral to that particular display).

Don't do that. Nesting classes just causes complications.

> Essentially, this boils down to the interaction between two classes. We create an instance of ManyKeyValues. This instance creates multiple instances of KeyValue. How can a change in KeyValue change something in ManyKeyValues?

In this case (and most others) you should just make the ManyKeyValues
instance listen to the trait change events on the KeyValue instance.

Of course, a more straightforward approach is to not use a KeyValue
(much less a *list* of 1 KeyValue) for the selection of the primary
key that you use to derive the list of KeyValues. Just use an
EnumEditor directly on ManyKeyValues. However, in my example, I have
left key_list as a (single!) KeyValue to show you how to listen to
trait changes on children.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
? -- Umberto Eco
-------------- next part --------------
A non-text attachment was scrubbed...
Name: key_values.py
Type: application/octet-stream
Size: 1723 bytes
Desc: not available
Url : http://mail.enthought.com/pipermail/enthought-dev/attachments/20101214/569ec4d6/attachment.obj

------------------------------

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev


End of Enthought-Dev Digest, Vol 76, Issue 29
*********************************************



--
Thanks and best regards,
Vishal Sapre

---
"So say...Day by day, in every way, I am getting better, better and better !!!"
"A Strong and Positive attitude creates more miracles than anything else. Because...Life is 10% how you make it, and 90% how you take it"
"Diamond is another piece of coal that did well under pressure”
"May we do good and not evil. May we find forgiveness for ourself and forgive others. May we share freely, never taking more than we give."

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Enthought TraitsUI based Python IDE

bryce hendrix-2
On Tue, Dec 14, 2010 at 12:03 PM, Vishal <[hidden email]> wrote:
Hello,

Is there anyone working on a TraitsUI (Envisage) based Python IDE?

or is there anyone who has tried extending the basic 'charm' example?


Vishal,

Not that I am aware of. I do recommend, if anyone is working on one, or is wanting to start, that they use the Qt based editor we wrote & lives in pyface. The CodeEditor is okay for simple things, but a nice IDE will eventually require features that are not exposed currently to the CodeEditor. This is the approach the ReST editor took, and it didn't prove to be much more complicated than using the CodeEditor.

Bryce

 

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Enthought TraitsUI based Python IDE

Richard Lincoln
In reply to this post by Vishal
I started one about a year and a half ago called Puddle (its safe to
view an Eclipse of the Sun in the reflection in a Puddle ;^).

http://pypi.python.org/pypi/Puddle

I also tried writing plug-ins that would extend it for editing
Graphviz Dot files.

http://pypi.python.org/pypi/Godot

The plan is to revisit it once I have TraitsBackendPyjamas working.

https://github.com/rwl/traitsbackendpyjamas

The new DirectFB support for the Python Webkit DOM Project should make
it pretty snappy.

http://www.gnu.org/software/pythonwebkit

I was thinking of trying to construct the UIs using PyJSGlade XML and
passing it to the Pyjamas Builder class so that it could eventually be
used with PyJS to create Traits based web apps.

Hopefully it'll be ready in time to catch the Eclipse community when
Oracle finally kills Java ;^).

Richard

On 14 December 2010 18:03, Vishal <[hidden email]> wrote:

> Hello,
> Is there anyone working on a TraitsUI (Envisage) based Python IDE?
> or is there anyone who has tried extending the basic 'charm' example?
> Thanks and best regards,
> Vishal Sapre
>
> On Tue, Dec 14, 2010 at 9:15 PM, <[hidden email]>
> wrote:
>>
>> Send Enthought-Dev mailing list submissions to
>>        [hidden email]
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>>        https://mail.enthought.com/mailman/listinfo/enthought-dev
>> or, via email, send a message with subject or body 'help' to
>>        [hidden email]
>>
>> You can reach the person managing the list at
>>        [hidden email]
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of Enthought-Dev digest..."
>>
>>
>> Today's Topics:
>>
>>   1. EPD version for SUSE10.2 (Matthieu Brucher)
>>   2. Re: EPD version for SUSE10.2 (Ilan Schnell)
>>   3. Re: EPD version for SUSE10.2 (Matthieu Brucher)
>>   4. Re: Dynamically generated Enums [Serco No Marking] (Sam Wedge)
>>   5. Re: Dynamically generated Enums [Serco No Marking] (Robert Kern)
>>
>>
>> ----------------------------------------------------------------------
>>
>> Message: 1
>> Date: Tue, 14 Dec 2010 14:14:07 +0100
>> From: Matthieu Brucher <[hidden email]>
>> Subject: [Enthought-Dev] EPD version for SUSE10.2
>> To: [hidden email]
>> Message-ID:
>>        <[hidden email]>
>> Content-Type: text/plain; charset=ISO-8859-1
>>
>> Hi,
>>
>> I've downloaded the latest release from the repository, but I get a
>> floating exception when trying to install it on a SUSE10.2 (x86_64).
>> Is SUSE 10.2 still supported?
>>
>> Matthieu
>> --
>> Information System Engineer, Ph.D.
>> Blog: http://matt.eifelle.com
>> LinkedIn: http://www.linkedin.com/in/matthieubrucher
>>
>>
>> ------------------------------
>>
>> Message: 2
>> Date: Tue, 14 Dec 2010 08:50:41 -0600
>> From: Ilan Schnell <[hidden email]>
>> Subject: Re: [Enthought-Dev] EPD version for SUSE10.2
>> To: [hidden email]
>> Message-ID:
>>        <[hidden email]>
>> Content-Type: text/plain; charset=UTF-8
>>
>> What exactly is the traceback you are getting?  Did
>> you install epd-6.3-2-rh3-x86_64.sh or
>> epd-6.3-2-rh5-x86_64.sh?
>>
>> - Ilan
>>
>> On Tue, Dec 14, 2010 at 7:14 AM, Matthieu Brucher
>> <[hidden email]> wrote:
>> > Hi,
>> >
>> > I've downloaded the latest release from the repository, but I get a
>> > floating exception when trying to install it on a SUSE10.2 (x86_64).
>> > Is SUSE 10.2 still supported?
>> >
>> > Matthieu
>> > --
>> > Information System Engineer, Ph.D.
>> > Blog: http://matt.eifelle.com
>> > LinkedIn: http://www.linkedin.com/in/matthieubrucher
>> > _______________________________________________
>> > Enthought-Dev mailing list
>> > [hidden email]
>> > https://mail.enthought.com/mailman/listinfo/enthought-dev
>> >
>>
>>
>> ------------------------------
>>
>> Message: 3
>> Date: Tue, 14 Dec 2010 16:13:53 +0100
>> From: Matthieu Brucher <[hidden email]>
>> Subject: Re: [Enthought-Dev] EPD version for SUSE10.2
>> To: [hidden email]
>> Message-ID:
>>        <[hidden email]>
>> Content-Type: text/plain; charset=ISO-8859-1
>>
>> I got a floating point exception when it ran enplace.
>> I've tried with rh3, it worked this time, so I guess there are a lot
>> of diffrences between SLES10.2 and SLESS 11 ;)
>>
>> Thanks for the tip,
>>
>> Matthieu
>>
>> 2010/12/14 Ilan Schnell <[hidden email]>:
>> > What exactly is the traceback you are getting? ?Did
>> > you install epd-6.3-2-rh3-x86_64.sh or
>> > epd-6.3-2-rh5-x86_64.sh?
>> >
>> > - Ilan
>> >
>> > On Tue, Dec 14, 2010 at 7:14 AM, Matthieu Brucher
>> > <[hidden email]> wrote:
>> >> Hi,
>> >>
>> >> I've downloaded the latest release from the repository, but I get a
>> >> floating exception when trying to install it on a SUSE10.2 (x86_64).
>> >> Is SUSE 10.2 still supported?
>> >>
>> >> Matthieu
>> >> --
>> >> Information System Engineer, Ph.D.
>> >> Blog: http://matt.eifelle.com
>> >> LinkedIn: http://www.linkedin.com/in/matthieubrucher
>> >> _______________________________________________
>> >> Enthought-Dev mailing list
>> >> [hidden email]
>> >> https://mail.enthought.com/mailman/listinfo/enthought-dev
>> >>
>> > _______________________________________________
>> > Enthought-Dev mailing list
>> > [hidden email]
>> > https://mail.enthought.com/mailman/listinfo/enthought-dev
>> >
>>
>>
>>
>> --
>> Information System Engineer, Ph.D.
>> Blog: http://matt.eifelle.com
>> LinkedIn: http://www.linkedin.com/in/matthieubrucher
>>
>>
>> ------------------------------
>>
>> Message: 4
>> Date: Tue, 14 Dec 2010 15:20:05 +0000
>> From: "Sam Wedge" <[hidden email]>
>> Subject: Re: [Enthought-Dev] Dynamically generated Enums [Serco No
>>        Marking]
>> To: <[hidden email]>
>> Message-ID: <[hidden email]>
>> Content-Type: text/plain; charset=US-ASCII
>>
>> Thanks for your push in the right direction, Robert.
>>
>> I have managed to link this in with what I want to do, but have hit a
>> slight snag.
>>
>> I have a dictionary of lists. When running the code below, there are
>> several selection combo boxes on the screen. The first is a list of keys
>> from my dictionary. The rest are lists containing the values associated with
>> all the keys except the one selected by the first list. If a different key
>> is selected, then the view updates and removes the currently selected key.
>>
>> The snag is that the function listening for the trait change is in a
>> separate class to the function that I want to execute should that change
>> take place. I can get around this by explicitly referencing the instance of
>> the class (mkv), but this feels messy and wrong, and causes an error when
>> the code is run since mkv is not initiated until the interpreter begins
>> running the code. Once going, it works as intended.
>>
>> I changed Robert's code to put the KeyValue class within ManyKeyValues, as
>> I felt that it belonged there (it will not be used by anything else and is
>> integral to that particular display).
>>
>> Essentially, this boils down to the interaction between two classes. We
>> create an instance of ManyKeyValues. This instance creates multiple
>> instances of KeyValue. How can a change in KeyValue change something in
>> ManyKeyValues?
>>
>> I appreciate your time.
>>
>> Regards,
>>
>> Sam
>>
>> Code snippet below.
>>
>>
>> from enthought.traits.api import Enum, HasTraits, Instance, List, Str, Any
>> from enthought.traits.ui.api import Item, UItem, View, ListEditor,
>> EnumEditor
>>
>> class ManyKeyValues(HasTraits):
>>    '''Describes the overall view'''
>>
>>    class KeyValue(HasTraits):
>>        '''Describes the view of the lists'''
>>        key = Str()
>>        value = Str()
>>        values = List(Str)
>>
>>        traits_view = View(
>>            UItem('key', style='readonly'),
>>            UItem('value', editor=EnumEditor(name='values')),
>>        )
>>
>>        def _value_changed(self):
>>            if self.key == 'List of Variables':
>>                mkv.change_display()
>>
>>
>>    key_list = List(Instance(KeyValue))
>>    key_values = List(Instance(KeyValue))
>>
>>    traits_view = View(
>>        UItem('key_list' ,editor=ListEditor(style='custom',mutable=False)),
>>        UItem('key_values',
>> editor=ListEditor(style='custom',mutable=False))
>>    )
>>
>>    def __init__(self,variables):
>>        self.variables = variables
>>        keys = self.variables.keys()
>>        self.key_list = [self.KeyValue(key='List of Variables',
>> value=keys[0],values=keys)]
>>        self.change_display()
>>
>>    def change_display(self):
>>        key_values = []
>>        for key in self.variables.keys():
>>            if key != self.key_list[0].value:
>>                key_values.append(self.KeyValue(key=key,
>> value=self.variables[key][0],values=list(set(self.variables[key]))))
>>        self.key_values = key_values
>>
>>
>> if __name__ == '__main__':
>>    data = {}
>>    data['one'] = ['1','2','3']
>>    data['two'] = ['a','b','c']
>>    data['three'] = ['foo','bar','baz']
>>
>>    mkv = ManyKeyValues(data)
>>    mkv.configure_traits()
>>
>>
>>
>>
>> >>> Robert Kern <[hidden email]> 07/12/2010 18:26 >>>
>> On Tue, Dec 7, 2010 at 12:07 PM, Sam Wedge <[hidden email]> wrote:
>> > Hi,
>> >
>> > I have a dictionary which is populated from a csv file. The keys come
>> > from the first line of this file, while the data comes from the rest of the
>> > file. The result is a dictionary whose values are all lists.
>> >
>> > I am using this data with a TraitsUI display. I would like to display
>> > this data as a series of Enum instances, whose label is given by the
>> > dictionary key, and whose values are given by the list stored under that
>> > key. I can do this easily by coding each Enum in explicitly, but due to the
>> > ever-changing csv file structure, I require this to be done dynamically,
>> > perhaps by looping over the keys.
>> >
>> > Does anyone have any experience with doing this sort of thing? I can't
>> > see how to do it, as each Enum needs to be a variable in its own right,
>> > rather than a dictionary key.
>>
>> In short, use a ListEditor on a List of instances which edit each
>> key-value pair.
>>
>>
>> from enthought.traits.api import Enum, HasTraits, Instance, List, Str
>> from enthought.traits.ui import api as tui
>>
>>
>> class KeyValue(HasTraits):
>>    key = Str()
>>    value = Str()
>>    values = List(Str)
>>
>>    traits_view = tui.View(
>>        tui.UItem('key', style='readonly'),
>>        tui.UItem('value', editor=tui.EnumEditor(name='values')),
>>    )
>>
>>
>> class ManyKeyValues(HasTraits):
>>    key_values = List(Instance(KeyValue))
>>
>>    traits_view = tui.View(
>>        tui.UItem('key_values', editor=tui.ListEditor(style='custom',
>> mutable=False)),
>>    )
>>
>>    @classmethod
>>    def fromrows(cls, rows):
>>        key_values = []
>>        for row in rows:
>>            key_values.append(KeyValue(key=row[0], value=row[1],
>> values=row[1:]))
>>        return cls(key_values=key_values)
>>
>> rows = [
>>    ['Key A', 'Value A1', 'Value A2'],
>>    ['Key B', 'Value B1', 'Value B2'],
>>    ['Key C', 'Value C1', 'Value C2', 'Value C3'],
>>    ['Key D', 'Value D1', 'Value D2', 'Value D3'],
>> ]
>>
>> if __name__ == '__main__':
>>    mkv = ManyKeyValues.fromrows(rows)
>>    mkv.configure_traits()
>>
>>    print 'Selected Key/Value pairs:'
>>    for kv in mkv.key_values:
>>        print '%s: %s' % (kv.key, kv.value)
>>
>>
>>
>> --
>> Robert Kern
>>
>> "I have come to believe that the whole world is an enigma, a harmless
>> enigma that is made terrible by our own mad attempt to interpret it as
>> though it had an underlying truth."
>>  -- Umberto Eco
>> _______________________________________________
>> Enthought-Dev mailing list
>> [hidden email]
>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>>
>> ______________________________________________________________________
>> This email has been scanned by the MessageLabs Email Security System.
>> For more information please visit http://www.messagelabs.com/email
>> ______________________________________________________________________
>>
>> *****Disclaimer************
>> This email and any attachments may contain confidential and/or
>> privileged material; it is for the intended addressee(s) only. If
>> you are not a named addressee, you must not use, retain or
>> disclose such information.
>>
>> Serco cannot guarantee that the email or any attachments are free
>> from viruses.
>> The views expressed in this email are those of the originator and
>> do not necessarily represent the views of Serco.
>>
>> Nothing in this email shall bind Serco in any contract or
>> obligation.
>>
>> Please note that all email messages sent to Serco are subject to
>> monitoring / interception for lawful business purposes.
>>
>> Serco Group plc.  Registered in England and Wales.  No: 2048608
>> Registered Office:  Serco House, 16 Bartley Wood Business Park,
>> Bartley Way, Hook, Hampshire, RG27 9UY, United Kingdom.
>> *****End Disclaimer********
>>
>>
>>
>> ------------------------------
>>
>> Message: 5
>> Date: Tue, 14 Dec 2010 09:45:34 -0600
>> From: Robert Kern <[hidden email]>
>> Subject: Re: [Enthought-Dev] Dynamically generated Enums [Serco No
>>        Marking]
>> To: [hidden email]
>> Message-ID:
>>        <[hidden email]>
>> Content-Type: text/plain; charset="utf-8"
>>
>> On Tue, Dec 14, 2010 at 9:20 AM, Sam Wedge <[hidden email]> wrote:
>> > Thanks for your push in the right direction, Robert.
>> >
>> > I have managed to link this in with what I want to do, but have hit a
>> > slight snag.
>> >
>> > I have a dictionary of lists. When running the code below, there are
>> > several selection combo boxes on the screen. The first is a list of keys
>> > from my dictionary. The rest are lists containing the values associated with
>> > all the keys except the one selected by the first list. If a different key
>> > is selected, then the view updates and removes the currently selected key.
>> >
>> > The snag is that the function listening for the trait change is in a
>> > separate class to the function that I want to execute should that change
>> > take place. I can get around this by explicitly referencing the instance of
>> > the class (mkv), but this feels messy and wrong, and causes an error when
>> > the code is run since mkv is not initiated until the interpreter begins
>> > running the code. Once going, it works as intended.
>> >
>> > I changed Robert's code to put the KeyValue class within ManyKeyValues,
>> > as I felt that it belonged there (it will not be used by anything else and
>> > is integral to that particular display).
>>
>> Don't do that. Nesting classes just causes complications.
>>
>> > Essentially, this boils down to the interaction between two classes. We
>> > create an instance of ManyKeyValues. This instance creates multiple
>> > instances of KeyValue. How can a change in KeyValue change something in
>> > ManyKeyValues?
>>
>> In this case (and most others) you should just make the ManyKeyValues
>> instance listen to the trait change events on the KeyValue instance.
>>
>> Of course, a more straightforward approach is to not use a KeyValue
>> (much less a *list* of 1 KeyValue) for the selection of the primary
>> key that you use to derive the list of KeyValues. Just use an
>> EnumEditor directly on ManyKeyValues. However, in my example, I have
>> left key_list as a (single!) KeyValue to show you how to listen to
>> trait changes on children.
>>
>> --
>> Robert Kern
>>
>> "I have come to believe that the whole world is an enigma, a harmless
>> enigma that is made terrible by our own mad attempt to interpret it as
>> though it had an underlying truth."
>> ? -- Umberto Eco
>> -------------- next part --------------
>> A non-text attachment was scrubbed...
>> Name: key_values.py
>> Type: application/octet-stream
>> Size: 1723 bytes
>> Desc: not available
>> Url :
>> http://mail.enthought.com/pipermail/enthought-dev/attachments/20101214/569ec4d6/attachment.obj
>>
>> ------------------------------
>>
>> _______________________________________________
>> Enthought-Dev mailing list
>> [hidden email]
>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>>
>>
>> End of Enthought-Dev Digest, Vol 76, Issue 29
>> *********************************************
>
>
>
> --
> Thanks and best regards,
> Vishal Sapre
>
> ---
> "So say...Day by day, in every way, I am getting better, better and better
> !!!"
> "A Strong and Positive attitude creates more miracles than anything else.
> Because...Life is 10% how you make it, and 90% how you take it"
> "Diamond is another piece of coal that did well under pressure”
> "May we do good and not evil. May we find forgiveness for ourself and
> forgive others. May we share freely, never taking more than we give."
>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev