[Grok-dev] grokcore.component in non-web application
rlacko at gratex.com
Wed Dec 3 11:29:27 EST 2008
Thank you very mutch for explanation
I will try that and report back my experiences
My english is poor, but if i have success and my application will work i will write some simple howtos or post working source code
From: grok-dev-bounces at zope.org [mailto:grok-dev-bounces at zope.org] On Behalf Of Martijn Faassen
Sent: Wednesday, December 03, 2008 5:16 PM
To: grok-dev at zope.org
Subject: Re: [Grok-dev] grokcore.component in non-web application
Lacko Roman wrote:
> In past project I used grok framework to build my web application, and I
> must say I was impressed.
We're very happy to hear that!
> Zope's Component Architecture (ZCA) was exactly the missing future in my
> python world J
> Now I'm developing some desktop applications (one using wxPython,
> another with Mozilla+PyXPCOM extensions) and I definitely want to use
> ZCA, grokcore.component seems to be the perfect choice.
> But I have some questions about using ZCA, especially howto use
> Component Registries.
> My question is: is there some examples of using ZCA/grokcore.component
> outside of zope server ?
I'll give you a code example. Perhaps you can contribute a document for
grok.zope.org (or the grokcore.component documentation) so that others
can find out how to do it.
You make your python project depend on grokcore.component in its
setup.py. This should pull in the right dependencies already.
Then in your own code:
from zope.configuration import xmlconfig
This will try to process the 'configure.zcml' file in the package
'mypackage' (which should be your project's Python package). This code
should run at startup time of your application.
In configure.zcml, place the following
<include package="grokcore.component" file="meta.zcml" />
<grok:grok package="." />
This will first make sure that grokcore.component is registered (through
the include of its 'meta.zcml', and then will grok your own package,
looking for anything that subclasses from grokcore.component's base
components (such as grokcore.component.Adapter).
So now you can start using grokcore.component.Adapter and the like in
your codebase and it should work.
If you have multiple packages, you would have your main package do an
'include' of all its dependencies. Or you could look at z3c.autoinclude
which can do it for you based on the dependencies listed in setup.py -
that should result in a configure.zcml that you shouldn't have to modify
> I understand that components are registered when modules are groked, and
> that there are methods like grok.testing.grok/ grok.testing.grok_component
> But I don't exactly now when and how to use them.
The grokcore.component.testing.grok function allows you to Grok
individual classes and instances within your tests. If you want to know
more I'll look for examples too.
I hope this works for you!
Grok-dev mailing list
Grok-dev at zope.org
More information about the Grok-dev