SFDialogs.Dialog service

The Dialog service contributes to the management of dialogs created with the Basic Dialog Editor or dialogs created on-the-fly. Each instance of the current class represents a single dialog box displayed to the user.

tip

A dialog box can be displayed in modal or in non-modal modes.


In modal mode, the box is displayed and the execution of the macro process is suspended until one of the OK or Cancel buttons is pressed. In the meantime, user actions executed on the box can trigger specific actions.

In non-modal mode, the dialog box is "floating" on the user desktop and the execution of the macro process continues normally. A non-modal dialog closes when it is terminated with the Terminate() method or when the LibreOffice session ends. The window close button is inactive in non-modal dialogs.

A dialog box disappears from memory after its explicit termination.

tip

The SFDialogs.Dialog service is closely related to the SFDialogs.DialogControl service.


Service invocation and usage

Before using the Dialog service the ScriptForge library needs to be loaded or imported:

note

• As macros en Basic requiren que se cargue a biblioteca ScriptForge empregando a instrución seguinte:
GlobalScope.BasicLibraries.loadLibrary("ScriptForge")

• Os scripts en Python requiren unha importación do módulo scriptforge:
from scriptforge import CreateScriptService


The Dialog service is invoked through the CreateScriptService method. It requires three supplemental positional arguments to specify the dialog box to activate:

Container: "GlobalScope" for preinstalled libraries or a window name as defined by ScriptForge.UI service. Empty string "" default value stands for the current document.

Library: The case-sensitive name of a library contained in the container. Default value is "Standard".

DialogName: A case-sensitive string designating the dialog.

The examples below in Basic and Python display the dlgConsole dialog that belongs to the ScriptForge shared library:


      Dim oDlg As Object, lButton As Long
      Dim Container As String, Library As String, DialogName As String
      Set oDlg = CreateScriptService("SFDialogs.Dialog", "GlobalScope", "ScriptForge", "dlgConsole")
      '... controls initialization goes here...
      lButton = oDlg.Execute()
      'Default mode = Modal
      If lButton = oDlg.OKBUTTON Then
      '... Process controls and do what is needed here
      End If
      oDlg.Terminate()
  

Or using Python:


    dlg = CreateScriptService('SFDialogs.Dialog', 'GlobalScope', 'ScriptForge', 'dlgConsole')
    # ... controls initialization goes here...
    rc = dlg.Execute()
    # Default mode is Modal
    if rc == dlg.OKBUTTON:
        # ... Process controls and do what is needed here
    dlg.Terminate()
  
note

Use the string "GlobalScope" as the container argument when the dialog is stored either in My Macros & Dialogs or in Application Macros & Dialogs.


tip

The dialog service offers methods that create new controls dynamically in an existing dialog predefined with the Dialog Editor. A dialog is initialized with controls in the Dialog Editor and new controls can be added at run-time before or after the dialog Execute() statement.


The Dialog service can equally be invoked - through the CreateScriptService method - when creating dialogs on-the-fly. It requires two supplemental positional arguments after the name of the ad-hoc service "NewDialog":

DialogName: A case-sensitive string designating the dialog.

Place: Window location of the dialog being either :

All elements are expressed in Map AppFont units.


    Sub newDialog()
        Dim oDlg As Object
       oDlg = CreateScriptService("NewDialog", "myDialog1", Array(100,200, 40, 110))
       ' ...
    End Sub
  

Or using Python:


    def newDialog():
       dlg = CreateScriptService('NewDialog', 'myDialog1', (100,200, 40, 110))
       # ... Process controls and do what is needed
  

All properties and methods applicable to predefined dialogs are available for such new dialogs. In particular the series of CreateXXX() methods for the addition of new dialog controls.

Retrieving the Dialog instance that triggered a dialog event

An instance of the Dialog service can be retrieved via the SFDialogs.DialogEvent service, provided that the dialog was initiated with the Dialog service. In the example below, oDlg contains the Dialog instance that triggered the dialog event.


    Sub aDialogEventHander(ByRef poEvent As Object)
        Dim oDlg As Object
        Set oDlg = CreateScriptService("SFDialogs.DialogEvent", poEvent)
        ' ...
    End Sub
  

Or using Python:


    def control_event_handler(event: uno):
        dlg = CreateScriptService("SFDialogs.DialogEvent", event)
        # ...
  

Note that in the previous examples, the prefix "SFDialogs." may be omitted when deemed appropriate.

Handling exceptions in event handlers

When creating an event handler for dialog events it is good practice to handle errors inside the subroutine itself. For instance, suppose the event handler below is called when the mouse button is pressed in the dialog window.


    Sub OnMouseButtonPressed(ByRef oEvent As Object)
    On Local Error GoTo Catch
        Dim oDialog As Object
        oDialog = CreateScriptService("DialogEvent", oEvent)
        ' Process the event
        Exit Sub
    Catch:
        MsgBox SF_Exception.Description
        SF_Exception.Clear
    End Sub
  
tip

Call SF_Exception.Clear if you do not want the error to propagate after the dialog execution ended.


In Python use native try/except blocks for exception handling as shown below:


    def on_mouse_button_pressed(event=None):
        try:
            dlg = CreateScriptService("DialogEvent", event)
            # Process the event
        except Exception as e:
            # The object "bas" is an instance of the Basic service
            bas.MsgBox(str(e))
  

Propiedades

Nome

ReadOnly

Tipo

Descrición

OKBUTTON

Si

Integer

Value = 1. An OK button was pressed.

CANCELBUTTON

Si

Integer

Value = 0. A Cancel button was pressed.

Caption

No

String

Specify the title of the dialog.

Height

No

Long

Specify the height of the dialog box.

Modal

Si

Boolean

Specifies if the dialog box is currently in execution in modal mode.

Name

Si

String

The name of the dialog

Page

No

Integer

A dialog may have several pages that can be traversed by the user step by step. The Page property of the Dialog object defines which page of the dialog is active.

Visible

No

Boolean

Specify if the dialog box is visible on the desktop. By default it is not visible until the Execute() method is run and visible afterwards.

XDialogModel

Si

UNO
object

The UNO object representing the dialog model. Refer to XControlModel and UnoControlDialogModel in Application Programming Interface (API) documentation for detailed information.

XDialogView

Si

UNO
object

The UNO object representing the dialog view. Refer to XControl and UnoControlDialog in Application Programming Interface (API) documentation for detailed information.

Width

No

Long

Specify the width of the dialog box.


Event properties

On… properties return a URI string with the reference to the script triggered by the event. On… properties can be set programmatically.
Read its specification in the scripting framework URI specification.

Nome

Read/Write

Basic IDE Description

OnFocusGained

Si

Ao recibir o foco

OnFocusLost

Si

Ao perder o foco