Toggle Desig Mode in Macro; No Dispatch!

I am working on an exampe for Live LibreOffice Python UNO Examples that dynamically inserts a control into a cell when it gets focus. (Lets say a currency control for this inquiry).

When the sheet is in design mode and I insert control it works a expected.

  • Insert control.
  • toggle Design mode (turn off)

So, When the cell gets focus I have put the doc into design mode, insert control, Turn design mode back off.
If I don’t put into design mode first there are issues such as the spin buttons are not rendered.

I am using a dispatch command SwitchControlDesignMode to toggle design mode.
Is there another way?
I would like to avoid the user possibly putting into design mode and throwing the whole thing off.
Also I would really perfer not to use dispatch in this macro.

BTW: The control is removed when it looses focus.


oDoc.CurrentController.setFormDesignMode True

its python…so:

…setFormDesignMode( True )

And for LO Basic this is possible.
Out of habit, I write in VBA compatible syntax. :slightly_smiling_face:

I’m not sure if this is the right approach - it’s somehow too wasteful. Is it perhaps easier and more economical to keep one copy ready in a hidden state, if necessary, move it to the desired coordinates, make it visible, and hide it after use?
I’m also not sure that to create a control you need to do something with the development mode. Just make sure that development mode is currently disabled. Everything you do with your code is not related to the state of the user interface. If after creating the control you don’t see it, then perhaps you should just redraw this area of the screen?

Interesting, setFormDesignMode() states:

This is a convenience method. In the user interface, the design mode is coupled with the .uno:SwitchControlDesignMode

So it is the same as calling the dispatch.

Well I figured it out.
The solution it seems was to set hte control setDesignMode(False) on the control.
See: setDesignMode() in the API.

I did the tweak in OooDev so the example did not need to use the dispatch.

Working Example: Cell Controls

@JohnSUN I like your input. Perahps that would be a better approach. This is a demo and is intended to demonstrate one way to dynamically insert controls.

Thank you all for the help.