How to add a new widget type?

Asking for my colleague who is in charge of front-ends:

Image we would need to implement another widget type. Both the Gtk and the Web client look quite monolithic in this area. Is there some way to “plug-in” the widget into the existing clients?

(He has a specific widget type in mind, Anyhow this is a general question.)

Yes, I think that should be possible.

You would need to attach to / update the correct parts of the clients.

For the web client you do this by adding some javascript to a custom.js: How to made plug-in for Tryton SAO?

For the desktop client you can add a plugin to into the plugins directory (there is a translation plugin example in the tryton source code).

You would also need to define the new widget in trytond so it could be used in the views, something along the lines of Issue 10173: Add document widget - Tryton issue tracker.

Indeed View.get_rngmust be extended to include the new widget name.

2 Likes

Thanks so far. Do I understand this correctly?

  1. Create a plugin for the desktop-client, which adds the new widget to tryton/gui/window/view_form/view/form.py.
    This also requires to provide users with a custom version of the frozen desktop-client.
  2. Create a plugin for SAO, which adds the new widget-view to Sao.View.FormXMLViewParser.WIDGETS (in sao/src/view/form.js)
  3. Provide a patched version of trytond/ir/ui/form.rng (and eventually tree.rng) which adds the name of the new widget type.
  4. Add a module to trytond, which monkey-patches ir.ui.view.View.get_rng() to read the patched files.

(As an alternative to (3) and (4), ir.ui.view.View.get_rng() could be monkey-patched to patch form.rng and tree.rng on the fly while reading.)

I think that is mostly right.

That is one way of doing it, but you should be able to do it without creating a custom version of the desktop client. It should be possible to add the plugin separately for each user by putting it in the plugins folder in the user’s desktop client configuration directory.