Skip to content

Latest commit

 

History

History
66 lines (52 loc) · 1.94 KB

draw_form.rst

File metadata and controls

66 lines (52 loc) · 1.94 KB

Class DrawForm

Writer Form

Introduction

The DrawForm class is can manage a form for a Write document.

Adding Controls

This class has many methods for adding controls to the form. that start with insert_control_ for standard controls and insert_db_control_ for database controls.

Here is an example of adding a button to a form and adding an event handler for the button.

>>> from typing import Any
>>> from ooodev.draw import Draw, DrawDoc
>>> from ooodev.events.args.event_args import EventArgs
>>> from ooodev.form.controls import FormCtlButton
>>>
>>> doc =DrawDoc(Draw.create_draw_doc())
>>> doc.set_visible()
>>> draw_page = doc.slides[0]
>>> frm = draw_page.forms.add_form("MainForm")
>>> print(frm.name)
MainForm
>>> btn = frm.insert_control_button(x=10, y=10, width=40, height=10, label="Button Test")
>>> btn.add_event_action_performed(on_btn_action_preformed)
>>>
>>> def on_btn_action_preformed(
...     src: Any, event: EventArgs, control_src: FormCtlButton, *args, **kwargs
... ) -> None:
...     print(
...         f"Action Performed: '{control_src.model.Label}', Control Name: {control_src.name}"
...     )

Other Examples

An example can be found on Live LibreOffice Python UNO Examples. Example: Build Form.

Class Declaration

.. autoclass:: ooodev.draw.DrawForm
    :members:
    :undoc-members:
    :show-inheritance:
    :inherited-members: