Re: [Zope3-dev] RFC: CustomWidgetFactory and widgets having different __init__ signature
Johan Carlsson wrote: Anywhere I can read up on what's happening with this issue/bug? - The class attribute of the widget-directive can handle a custom factory or a widget class. - The __call__ method of custom widget factory (zope.app.form.CustomWidgetFactory) invokes collection, choice and regular fields correctly (respection specific signatures) - Custom widget sequence factory (zope.app.form.CustomSequenceWidgetFactory) is deprecated because it does not satisfy the IViewFactory interface. Use the CustomWidgetFactory instead. Regards, Dominik begin:vcard fn:Dominik Huber n:Huber;Dominik email;internet:[EMAIL PROTECTED] tel;work:++41 56 534 77 30 x-mozilla-html:FALSE version:2.1 end:vcard ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] RFC: CustomWidgetFactory and widgets having different __init__ signature
Dominik Huber wrote: Johan Carlsson wrote: Anywhere I can read up on what's happening with this issue/bug? - The class attribute of the widget-directive can handle a custom factory or a widget class. - The __call__ method of custom widget factory (zope.app.form.CustomWidgetFactory) invokes collection, choice and regular fields correctly (respection specific signatures) - Custom widget sequence factory (zope.app.form.CustomSequenceWidgetFactory) is deprecated because it does not satisfy the IViewFactory interface. Use the CustomWidgetFactory instead. This is in the trunk right? /Johan -- Johan Carlsson Tel: + 46 8 31 24 94 Colliberty Mob: + 46 70 558 25 24 Torsgatan 72Email: [EMAIL PROTECTED] SE-113 37 STOCKHOLM ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] RFC: CustomWidgetFactory and widgets having different __init__ signature
Johan Carlsson wrote: Dominik Huber wrote: Johan Carlsson wrote: Anywhere I can read up on what's happening with this issue/bug? - The class attribute of the widget-directive can handle a custom factory or a widget class. - The __call__ method of custom widget factory (zope.app.form.CustomWidgetFactory) invokes collection, choice and regular fields correctly (respection specific signatures) - Custom widget sequence factory (zope.app.form.CustomSequenceWidgetFactory) is deprecated because it does not satisfy the IViewFactory interface. Use the CustomWidgetFactory instead. This is in the trunk right? /Johan Yup. -- Dominik Huber Perse Engineering GmbH Jurastrasse 9a CH-5406 Baden E-Mail: [EMAIL PROTECTED] Telefon: ++41 56 534 7730 begin:vcard fn:Dominik Huber n:Huber;Dominik email;internet:[EMAIL PROTECTED] tel;work:++41 56 534 77 30 x-mozilla-html:FALSE version:2.1 end:vcard ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re[2]: [Zope3-dev] RFC: CustomWidgetFactory and widgets having different __init__ signature
Hello Dominik, Your solution looks good. I would propose, that we still mark the widgets with different __init__ signatures with something to be able to wrap them into different factories in metaconfigure.py to make like a bit easier. What I have in mind: itemswidgets.py: class ItemsWidgetBase(TranslationHook, SimpleInputWidget): Convenience base class for widgets displaying items/choices. implements(IMultiWidgetMarker) metaconfigure.py: if IMultiWidgetMarker.implementedBy(class_): wrapped = CustomSequenceWidgetFactory(class_) #and so on with the different signatures else: wrapped = CustomWidgetFactory(class_) self._widgets[field+'_widget'] = wrapped DH Are you fixing issue 451? Otherwise, I could do it this weekend. Anyway I can't do it directly, because I don't have SVN access. I think I'll sit here, so if you need any help... One additional small thing is: Index: Y:/zope/svn_zope3/src/zope/app/form/browser/metaconfigure.py === --- Y:/zope/svn_zope3/src/zope/app/form/browser/metaconfigure.py (revision 40192) +++ Y:/zope/svn_zope3/src/zope/app/form/browser/metaconfigure.py (working copy) @@ -84,7 +87,11 @@ # attribute. This can be used to override some of the # presentational attributes of the widget implementation. class_ = self._default_widget_factory -self._widgets[field+'_widget'] = CustomWidgetFactory(class_, **attrs) +if IViewFactory.providedBy(class_): +#don't wrap a factory into a factory +self._widgets[field+'_widget'] = class_ +else: +self._widgets[field+'_widget'] = CustomWidgetFactory(class_, **attrs) def _processWidgets(self): if self._widgets: -- Best regards, Adammailto:[EMAIL PROTECTED] -- Quote of the day: Death is life's way of telling you you've been fired. ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] RFC: CustomWidgetFactory and widgets having different __init__ signature
Dominik Huber wrote: Hi Adam DH Are you fixing issue 451? Otherwise, I could do it this weekend. Anyway I can't do it directly, because I don't have SVN access. I think I'll sit here, so if you need any help... Thanks for your inputs! I will do that this weekend. Regards, Dominik Anywhere I can read up on what's happening with this issue/bug? Regards, Johan -- Johan Carlsson Tel: + 46 8 31 24 94 Colliberty Mob: + 46 70 558 25 24 Torsgatan 72Email: [EMAIL PROTECTED] SE-113 37 STOCKHOLM ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] RFC: CustomWidgetFactory and widgets having different __init__ signature
Dominik Huber wrote: Johan Carlsson wrote: Anywhere I can read up on what's happening with this issue/bug? Regards, Johan NotYetError ;) I have to dig into the subject this weekend, but I have to sort the partial solutions first. Ok, looking forward for any progress :-) /Johan -- Johan Carlsson Tel: + 46 8 31 24 94 Colliberty Mob: + 46 70 558 25 24 Torsgatan 72Email: [EMAIL PROTECTED] SE-113 37 STOCKHOLM ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] RFC: CustomWidgetFactory and widgets having different __init__ signature
Adam Groszer wrote: As I'm digging through zope.app.form.browser to fix the CustomWidgetFactory collector issue, I found the following: IWidget has no __init__ defined class Widget(object): def __init__(self, context, request): class ItemsWidgetBase(TranslationHook, SimpleInputWidget): def __init__(self, field, vocabulary, request): class ItemsEditWidgetBase(SingleDataHelper, ItemsWidgetBase): def __init__(self, field, vocabulary, request): class ObjectWidget(BrowserWidget, InputWidget): def __init__(self, context, request, factory, **kw): class SequenceWidget(BrowserWidget, InputWidget): def __init__(self, context, field, request, subwidget=None): class SequenceDisplayWidget(DisplayWidget): def __init__(self, context, field, request, subwidget=None): class SourceDisplayWidget(zope.app.form.Widget): def __init__(self, field, source, request): class SourceInputWidget(zope.app.form.InputWidget): def __init__(self, field, source, request): class SourceSelectWidget(zope.app.form.browser.SelectWidget): def __init__(self, field, source, request): CustomWidgetFactory fails on these different signatures. This affects the ZCML browser:widget field=... class=.../. Simple widgets will work, widgets with different signatures of course not. class CustomWidgetFactory(object): implements(IViewFactory) def __call__(self, context, request): class CustomSequenceWidgetFactory(object): implements(IViewFactory) def __call__(self, context, field, request): In fact, CustomSequenceWidgetFactory violates the IViewFactory interface with the different __call__ signature. That causes setUpWidget to fail. I'm wondering if this worked for anyone anytime. No, the widget stuff was broken long time ago. Phillip did some fixes within a branch, but this branch got deleted during the last repository cleaned up. I'm not shure which change the widget-refactoring will bring, that was the reason why I never was digging deeper. (svn://svn.zope.org/repos/main/Zope3/branches/f12gsprint-widget). Now I'm stuck a little bit. How does a good solution look like? My half-baked solution was up to today for Itemswidgets (which caused the error for me) to mark it with a different interface and look for that in CustomWidgetFactory and pass different arguments. Now I'm not so sure that this is the right one. The current solution does not covers ObjectWidgets. My solutions are half-baked too, but maybe we can collect them to get an overview (see attached file). The problem can be split in two parts: 1. __call__ with different signatures 2. creation/customization of widgets using the setattr(instance, name, value) Regards, Dominik from zope.component.interfaces import IViewFactory from zope.interface import implements from zope.schema.interfaces import IChoice, ICollection class CustomWidgetFactory(object): Custom Widget Factory. implements(IViewFactory) def __init__(self, widget_factory, *args, **kw): self._widget_factory = widget_factory self.args = args self.kw = kw def _create(self, args): instance = self._widget_factory(*args) for name, value in self.kw.items(): setattr(instance, name, value) return instance def __call__(self, context, request): return self._create((context, request) + self.args) class CustomSequenceWidgetFactory(CustomWidgetFactory): Custom sequence widget factory. def __call__(self, context, request): if not ICollection.providedBy(context): raise TypeError, Provided field does not provide ICollection. args = (context, context.value_type, request) + self.args return self._create(args) class CustomVocabularyWidgetFactory(CustomWidgetFactory): Custom vocabulary widget factory. def __call__(self, context, request): if not IChoice.providedBy(context): raise TypeError, Provided field does not provide ICollection. args = (context, context.vocabulary, request) + self.args return self._create(args) class TemplateWidgetFactory(CustomWidgetFactory): The view kw attribute is called like a ViewPageTemplateFile. def _create(self, args): instance = self._widget_factory(*args) for name, value in self.kw.items(): if name is 'view': setattr(instance, name, value(instance, instance.request)) else: setattr(instance, name, value) return instance class TemplateSequenceWidgetFactory(CustomSequenceWidgetFactory): The view kw attribute is called like a ViewPageTemplateFile. def _create(self, args): instance = self._widget_factory(*args) for name, value in self.kw.items(): if name is 'view': setattr(instance, name, value(instance, instance.request)) else: setattr(instance, name, value) return instance begin:vcard