示例#1
0
文件: run.py 项目: anshsrtv/envisage
def main(argv):
    """ Run the application.
    """
    logging.basicConfig(level=logging.WARNING)

    plugins = [CorePlugin(), TasksPlugin(), AttractorsPlugin()]
    app = AttractorsApplication(plugins=plugins)
    app.run()

    logging.shutdown()
示例#2
0
def main(argv):
    """ Run the application.
    """
    # Import here so that this script can be run from anywhere without
    # having to install the packages.
    from attractors.attractors_plugin import AttractorsPlugin
    from attractors.attractors_application import AttractorsApplication

    plugins = [CorePlugin(), TasksPlugin(), AttractorsPlugin()]
    app = AttractorsApplication(plugins=plugins)
    app.run()
示例#3
0
def main():
    """ Run the application. """

    # Create an application containing the appropriate plugins.
    application = Application(
        id="acme.motd",
        plugins=[CorePlugin(),
                 MOTDPlugin(),
                 SoftwareQuotesPlugin()],
    )

    # Run it!
    return application.run()
示例#4
0
    def test_dynamically_added_service_offer(self):
        """ dynamically added service offer """
        class IMyService(Interface):
            pass

        class PluginA(Plugin):
            id = "A"

            service_offers = List(contributes_to="envisage.service_offers")

            def _service_offers_default(self):
                """ Trait initializer. """

                service_offers = [
                    ServiceOffer(protocol=IMyService,
                                 factory=self._my_service_factory)
                ]

                return service_offers

            def _my_service_factory(self, **properties):
                """ Service factory. """

                return 42

        core = CorePlugin()
        a = PluginA()

        # Start off with just the core plugin.
        application = TestApplication(plugins=[core])
        application.start()

        # Make sure the service does not exist!
        service = application.get_service(IMyService)
        self.assertIsNone(service)

        # Make sure the service offer exists...
        extensions = application.get_extensions("envisage.service_offers")
        self.assertEqual(0, len(extensions))

        # Now add a plugin that contains a service offer.
        application.add_plugin(a)

        # Make sure the service offer exists...
        extensions = application.get_extensions("envisage.service_offers")
        self.assertEqual(1, len(extensions))

        # ... and that the core plugin responded to the new service offer and
        # published it in the service registry.
        service = application.get_service(IMyService)
        self.assertEqual(42, service)
示例#5
0
文件: run.py 项目: enthought/envisage
def main():
    """ Run the application. """

    # Create an application with the specified plugins.
    acmelab = Acmelab(plugins=[
        CorePlugin(),
        WorkbenchPlugin(),
        AcmeWorkbenchPlugin(),
    ])

    # Run it! This starts the application, starts the GUI event loop, and when
    # that terminates, stops the application.
    acmelab.run()

    return
示例#6
0
def main():
    """ Run the application. """
    # Import here so that this script can be run from anywhere without
    # having to install the packages.
    from acme.motd.motd_plugin import MOTDPlugin
    from acme.motd.software_quotes.software_quotes_plugin import (
        SoftwareQuotesPlugin, )
    # Create an application containing the appropriate plugins.
    application = Application(
        id="acme.motd",
        plugins=[CorePlugin(),
                 MOTDPlugin(),
                 SoftwareQuotesPlugin()],
    )

    # Run it!
    return application.run()
示例#7
0
def main():
    """ Run the application. """

    # Create an application with the specified plugins.
    lorenz_application = LorenzApplication(
        plugins=[
            CorePlugin(),
            WorkbenchPlugin(),
            LorenzPlugin(),
            LorenzUIPlugin(),
        ]
    )

    # Run it! This starts the application, starts the GUI event loop, and when
    # that terminates, stops the application.
    lorenz_application.run()

    return
示例#8
0
    def test_preferences(self):
        """ preferences """
        class PluginA(Plugin):
            id = "A"
            preferences = List(contributes_to="envisage.preferences")

            def _preferences_default(self):
                """ Trait initializer. """

                return ["file://" + resource_filename(PKG, "preferences.ini")]

        core = CorePlugin()
        a = PluginA()

        application = TestApplication(plugins=[core, a])
        application.run()

        # Make sure we can get one of the preferences.
        self.assertEqual("42", application.preferences.get("enthought.test.x"))
示例#9
0
    def test_unregister_service(self):
        """ Unregister a service which was registered on the application
        directly, not through the CorePlugin's extension point. CorePlugin
        should not do anything to interfere. """
        class IJunk(Interface):
            trash = Str()

        class Junk(HasTraits):
            trash = Str("garbage")

        some_junk = Junk()

        application = TestApplication(plugins=[CorePlugin()], )

        application.start()

        some_junk_id = application.register_service(IJunk, some_junk)
        application.unregister_service(some_junk_id)

        application.stop()
示例#10
0
    def running_app(self, plugins=None):
        """
        Returns a context manager that provides a running application.

        Parameters
        ----------
        plugins : list of Plugin, optional
            Plugins to use in the application, other than the CorePlugin
            (which is always included). If not given, an IPythonKernelPlugin
            is instantiated and used.
        """
        if plugins is None:
            plugins = [IPythonKernelPlugin(init_ipkernel=True)]

        app = Application(plugins=[CorePlugin()] + plugins, id="test")
        app.start()
        try:
            yield app
        finally:
            app.stop()
示例#11
0
    def test_unregister_service_offer(self):
        """ Unregister a service that is contributed to the
        "envisage.service_offers" extension point while the application is
        running.
        """
        class IJunk(Interface):
            trash = Str()

        class Junk(HasTraits):
            trash = Str("garbage")

        class PluginA(Plugin):
            # The Ids of the extension points that this plugin contributes to.
            SERVICE_OFFERS = "envisage.service_offers"

            service_offers = List(contributes_to=SERVICE_OFFERS)

            def _service_offers_default(self):

                a_service_offer = ServiceOffer(
                    protocol=IJunk,
                    factory=self._create_junk_service,
                )

                return [a_service_offer]

            def _create_junk_service(self):
                """ Factory method for the 'Junk' service. """

                return Junk()

            @on_trait_change("application:started")
            def _unregister_junk_service(self):
                # only 1 service is registered so it has service_id of 1
                self.application.unregister_service(1)

        application = TestApplication(plugins=[CorePlugin(), PluginA()], )

        # Run it!
        application.run()
示例#12
0
    def test_service_offers(self):
        """ service offers """
        class IMyService(Interface):
            pass

        class PluginA(Plugin):
            id = "A"

            service_offers = List(contributes_to="envisage.service_offers")

            def _service_offers_default(self):
                """ Trait initializer. """

                service_offers = [
                    ServiceOffer(protocol=IMyService,
                                 factory=self._my_service_factory)
                ]

                return service_offers

            def _my_service_factory(self, **properties):
                """ Service factory. """

                return 42

        core = CorePlugin()
        a = PluginA()

        application = TestApplication(plugins=[core, a])
        application.start()

        # Lookup the service.
        self.assertEqual(42, application.get_service(IMyService))

        # Stop the core plugin.
        application.stop_plugin(core)

        # Make sure th service has gone.
        self.assertEqual(None, application.get_service(IMyService))
示例#13
0
    def test_dynamically_added_preferences(self):
        """ dynamically added preferences """
        class PluginA(Plugin):
            id = "A"
            preferences = List(contributes_to="envisage.preferences")

            def _preferences_default(self):
                """ Trait initializer. """

                return ["file://" + resource_filename(PKG, "preferences.ini")]

        core = CorePlugin()
        a = PluginA()

        # Start with just the core plugin.
        application = TestApplication(plugins=[core])
        application.start()

        # Now add a plugin that contains a preference.
        application.add_plugin(a)

        # Make sure we can get one of the preferences.
        self.assertEqual("42", application.preferences.get("enthought.test.x"))
示例#14
0
            # Create windows from the default or saved application layout.
            self._create_windows()

            kernel = self.get_service(IPYTHON_KERNEL_PROTOCOL)
            kernel.init_ipkernel("qt4")

            app.connect(
                app,
                QtCore.SIGNAL("lastWindowClosed()"),
                app,
                QtCore.SLOT("quit()"),
            )
            app.aboutToQuit.connect(kernel.cleanup_consoles)

            gui.set_trait_later(self, "application_initialized", self)
            kernel.ipkernel.start()

        return started


if __name__ == "__main__":

    app = ExampleApplication(plugins=[
        CorePlugin(),
        ExamplePlugin(),
        IPythonKernelPlugin(),
        IPythonKernelUIPlugin(),
        TasksPlugin(),
    ])
    app.run()