Envisage ExtensionPoint between Plugin and Application

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

Envisage ExtensionPoint between Plugin and Application

Henk van der Laak (GMail)
Hi all,

Learning ETS, the hard way.

I want a plugin to contribute to an extension point in its application,
but no luck.

Why does the code below fail to print "Hello" ?

Thanks for any pointers,
Henk.


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

from envisage.api import Application, ExtensionPoint, Plugin
from traits.api import List, Str


class MyApplication(Application):
     greetings = ExtensionPoint(List(Str), id='greetings')


class MyPlugin(Plugin):
     greetings = List(["Hello"], contributes_to='greetings')


if __name__ == '__main__':
     application = MyApplication(id='greeter', plugins=[MyPlugin()])

     application.run()

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

Re: Envisage ExtensionPoint between Plugin and Application

Martin Chilvers
Hi Henk,

On 01/04/2013 16:10, Henk van der Laak (GMail) wrote:
> I want a plugin to contribute to an extension point in its application,
> but no luck.
>
> Why does the code below fail to print "Hello" ?

Because the application itself doesn't offer extension points, only
plugins do that (the application is really just a container for the
plugins).

> Thanks for any pointers,

Try something along these lines:-

from envisage.api import Application, ExtensionPoint, Plugin
from traits.api import List, Str


class MyApplication(Application):
     def start(self):
         super(MyApplication, self).start()
         print [greeting for greeting in self.get_extensions('greetings')]

class GreetingsPlugin(Plugin):
      greetings = ExtensionPoint(List(Str), id='greetings')

class MyPlugin(Plugin):
      greetings = List(["Hello"], contributes_to='greetings')


if __name__ == '__main__':
      application = MyApplication(
          id='greeter', plugins=[GreetingsPlugin(), MyPlugin()]
      )
      application.run()

Martin

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