# How to add a new widget type?

**URL:** <https://discuss.tryton.org/t/how-to-add-a-new-widget-type/3957>\
**Category:** Developer\
**Created:** [March 19, 2021, 9:13am UTC](https://discuss.tryton.org/t/how-to-add-a-new-widget-type/3957 "2021-03-19T09:13:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![htgoebel](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/htgoebel/32/1256_2.png) [@htgoebel](https://discuss.tryton.org/u/htgoebel)\
**Post date:** [March 19, 2021, 9:13am UTC](https://discuss.tryton.org/t/how-to-add-a-new-widget-type/3957/1 "2021-03-19T09:13:15Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![dave](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://discuss.tryton.org/u/dave)\
**Post date:** [March 19, 2021, 12:27pm UTC](https://discuss.tryton.org/t/how-to-add-a-new-widget-type/3957/2 "2021-03-19T12:27:00Z")

</div>

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?](https://discuss.tryton.org/t/how-to-made-plug-in-for-tryton-sao/3917)

For the desktop client you can add a plugin to into the [plugins](https://docs.tryton.org/projects/client-desktop/en/latest/usage.html?highlight=plugin#configuration-file) directory (there is a [translation plugin example](https://hg.tryton.org/tryton/file/0a1339c4ec24/tryton/plugins) 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 [Add document widget (#10173) · Issues · Tryton / Tryton · GitLab](https://bugs.tryton.org/issue10173).

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [March 19, 2021, 12:36pm UTC](https://discuss.tryton.org/t/how-to-add-a-new-widget-type/3957/3 "2021-03-19T12:36:31Z")

</div>

> [@dave](#):
>
> 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](https://bugs.tryton.org/issue10173).

Indeed `View.get_rng`must be extended to include the new widget name.

---

<div class="post-metadata">

**Author:** ![htgoebel](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/htgoebel/32/1256_2.png) [@htgoebel](https://discuss.tryton.org/u/htgoebel)\
**Post date:** [March 21, 2021, 10:29am UTC](https://discuss.tryton.org/t/how-to-add-a-new-widget-type/3957/4 "2021-03-21T10:29:12Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![dave](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://discuss.tryton.org/u/dave)\
**Post date:** [March 23, 2021, 10:10am UTC](https://discuss.tryton.org/t/how-to-add-a-new-widget-type/3957/5 "2021-03-23T10:10:23Z")

</div>

I think that is mostly right.

> [@htgoebel](#):
>
> This also requires to provide users with a custom version of the frozen desktop-client.

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.

---

<div class="post-metadata">

**Author:** ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)\
**Post date:** [April 22, 2021, 10:10am UTC](https://discuss.tryton.org/t/how-to-add-a-new-widget-type/3957/6 "2021-04-22T10:10:30Z")

</div>

Closed on April 22, 2021, 10:10am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
