Translation

python_handler.xhp N0677 help.text
English Joqhs
Context English Latvian Actions
python_examples.xhp
hd_id201901031407
help.text
<variable id="pythonexamples2"><link href="text/sbasic/python/python_examples.xhp" name="python examples">Python programming examples</link></variable>
python_handler.xhp
tit
help.text
Creating A Dialog Handler
python_handler.xhp
N0664
help.text
<bookmark_value>Basic;Dialog Handler</bookmark_value> <bookmark_value>Python;Dialog Handler</bookmark_value> <bookmark_value>Access2Base;dlgTrace</bookmark_value> <bookmark_value>Access2Base;_DumpToFile</bookmark_value> <bookmark_value>API;DialogProvider2</bookmark_value> <bookmark_value>API;XDialogEventHandler</bookmark_value>
python_handler.xhp
N0665
help.text
<variable id="pythonhandler_h1"><link href="text/sbasic/python/python_handler.xhp" name="Creating a Dialog Handler">Creating a Dialog Handler</link></variable>
python_handler.xhp
N0666
help.text
Next to <link href="text/sbasic/shared/01040000.xhp" name="Assigning macros to events">assigning macros to events</link> or <link href="text/sbasic/basic/python/python_listener" name="creating event listeners">creating event listeners</link>, one can use dialog handlers, whose principle is to define UNO keywords, or methods, that are mapped to events to watch for. The event handler is responsible for executing methods using the <literal>vnd.sun.star.UNO:<method_name></literal> protocol. Unlike listeners that require to define all supported methods, even if unused, dialog handlers require only two methods on top of intended control hook scripts.
python_handler.xhp
N0667
help.text
The advantages of this approach are:
python_handler.xhp
N0668
help.text
It packs the code that handles event-driven macros,
python_handler.xhp
N0669
help.text
it decorrelates events from macros names which facilitates maintenance or updates, in particular when moving macros or modules.
python_handler.xhp
N0670
help.text
This mechanism is illustrated herewith for Basic and Python languages using an imported copy of <literal>Access2Base</literal> <literal>dlgTrace</literal> dialog. Exception handling and localisation are omitted for clarity.
python_handler.xhp
N0671
help.text
Assigning Dialog methods
python_handler.xhp
N0672
help.text
Export <literal>Access2Base</literal> <literal>dlgTrace</literal> dialog and import it into <literal>MyLib</literal> application library.
python_handler.xhp
N0673
help.text
Inside the control properties pane of the <link href="text/sbasic/guide/create_dialog.xhp" name="Dialog Editor">Dialog Editor</link>, use the Events tab to replace macro assignments by component assignments, and type in the intended method names:
python_handler.xhp
N0674
help.text
Set <literal>Dump to file</literal> dialog button component method name to <literal>_dump2File</literal>
python_handler.xhp
N0675
help.text
Optionally define <literal>txtTracelog</literal> key pressed and mouse button pressed events component method names as <literal>_openHelp</literal>
python_handler.xhp
N0676
help.text
Optionally define <literal>Ok</literal> button receiving focus event component method name as <literal>onOkHasfocus</literal>
python_handler.xhp
N0677
help.text
Events assigned actions should mention the <literal>vnd.sun.star.UNO:</literal> protocol.
python_handler.xhp
N0678
help.text
Creating the handler
python_handler.xhp
N0679
help.text
<literal>createDialogWithHandler</literal> method of <link href="https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1awt_1_1DialogProvider2.html" name="com.sun.star.awt.DialogProvider2">com.sun.star.awt.DialogProvider2</link> service is used to set the dialog and its handler. The handler is responsible for implementing <link href="https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1awt_1_1XDialogEventHandler.html" name="com.sun.star.awt.XDialogEventHandler">com.sun.star.awt.XDialogEventHandler</link> interface.
python_handler.xhp
N0680
help.text
All component method names must be explicitly declared when using a dialog handler.
python_handler.xhp
N0681
help.text
With Python
python_handler.xhp
N0682
help.text
In this example the dialog is located on the computer.
python_handler.xhp
N0692
help.text
""" Access2Base Console Handler """
python_handler.xhp
N0693
help.text
''' adapted from « Créer un dialogue avec gestionnaire d'événements » by JM Zambon
python_handler.xhp
N0716
help.text
""" Create a Dialog from its location """
python_handler.xhp
N0729
help.text
''' Ugly MsgBox '''
python_handler.xhp
N0740
help.text
As expected, <literal>onOkHasFocus</literal> missing method throws an exception.
python_handler.xhp
N0741
help.text
Refer to <link href="text/sbasic/python/python_2_basic.xhp" name="Python calls to %PRODUCTNAME Basic">Python calls to %PRODUCTNAME Basic</link> page for <literal>getBasicScript</literal> routine description and for details about cross-language scripting execution.
python_handler.xhp
N0742
help.text
With %PRODUCTNAME Basic
python_handler.xhp
N0743
help.text
In this example the dialog is embedded in a document, and can equally be located on the computer.
python_handler.xhp
N0751
help.text
dp.Initialize(Array(ThisComponent)) ' if doc-embedded dialog
python_handler.xhp
N0958c
help.text
method As String) As Boolean

Loading…

No matching activity found.
Browse all component changes

Glossary

English Latvian
No related strings found in the glossary.

String information

Context
python_handler.xhp
N0677
help.text
Source string description
Joqhs
Source string location
python_handler.xhp
String age
3 years ago
Source string age
3 years ago
Translation file
lv/helpcontent2/source/text/sbasic/python.po, string 151