LzQoS‖SFDialogs.Dialog service

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

tip

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


LVjBj‖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.

FFTSj‖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 LibreOfficeDev session ends. The window close button is inactive in non-modal dialogs.

GrpyR‖A dialog box disappears from memory after its explicit termination.

tip

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


CByHp‖Service invocation and usage

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

note

gF8D8‖• Basic macros require to load ScriptForge library using the following statement:
GlobalScope.BasicLibraries.loadLibrary("ScriptForge")

• Python scripts require an import from scriptforge module:
from scriptforge import CreateScriptService


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

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

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

FSp5N‖DialogName: A case-sensitive string designating the dialog.

r5vY5‖Below LibreOfficeDev Basic and Python examples are displaying the dlgConsole dialog that belongs to 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")
      mqjFF‖'... controls initialization goes here...
      lButton = oDlg.Execute()
      yn6sy‖'Default mode = Modal
      If lButton = oDlg.OKBUTTON Then
      h9a9G‖'... Process controls and do what is needed here
      End If
      oDlg.Terminate()
  

VD35X‖Or using Python:


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

eehkB‖Alternatively a Dialog instance can be retrieved via the SFDialogs.DialogEvent service, providing that the dialog was initiated with the Dialog service. DialogEvent returns the SFDialogs.Dialog service instance that triggered the event.


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

QBG5g‖with Python:


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

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

nXGkZ‖Properties

zVLEC‖Name

FBCFG‖ReadOnly

ByVDE‖Type

8AUBJ‖Description

OKBUTTON

iZZec‖Yes

Integer

av994‖Value = 1. An OK button was pressed.

CANCELBUTTON

GKcTG‖Yes

Integer

z4BZ4‖Value = 0. A Cancel button was pressed.

Caption

cThsX‖No

String

48bDT‖Specify the title of the dialog.

Height

2pjyZ‖No

Long

3Rypn‖Specify the height of the dialog box.

Modal

KD2zy‖Yes

Boolean

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

Name

sA5Nj‖Yes

String

JoAYu‖The name of the dialog

Page

jcbwB‖No

Integer

Tfrah‖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

FZG3n‖No

Boolean

3sRE5‖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

w6DwG‖Yes

UNO
object

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

XDialogView

YFYi4‖Yes

UNO
object

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

Width

S4DWL‖No

Long

G6Qsw‖Specify the width of the dialog box.


q8eyc‖Event properties

tn52Y‖Returns a URI string with the reference to the script triggered by the event. Read its specification in the scripting framework URI specification.

XCC7C‖Name

V3bin‖ReadOnly

uW85z‖Basic IDE Description

OnFocusGained

dFkbN‖Yes

aKBvg‖When receiving focus

OnFocusLost

4FBaJ‖Yes

8U7FZ‖When losing focus

OnKeyPressed

wBCKi‖Yes

CK5vU‖Key pressed

OnKeyReleased

gXJGu‖Yes

CJwi7‖Key released

OnMouseDragged

wS7GH‖Yes

GcDU7‖Mouse moved while key presses

OnMouseEntered

eUS49‖Yes

QrByH‖Mouse inside

OnMouseExited

CRGTF‖Yes

69s4B‖Mouse outside

OnMouseMoved

ojLRr‖Yes

XaS8A‖Mouse moved

OnMousePressed

MnMUF‖Yes

NtqPz‖Mouse button pressed

OnMouseReleased

czknv‖Yes

J2uzg‖Mouse button released


gTQjc‖Methods

Activate
Center
Controls

EndExecute
Execute
GetTextsFromL10N

Resize
Terminate


Activate

DiCyL‖Set the focus on the current Dialog instance. Return True if focusing was successful.

7QdPA‖This method is called from a dialog or control event, or when a dialog is displayed in non-modal mode.

FVEx2‖Syntax:

svc.Activate(): bool

EFSA4‖Example:


      Dim oDlg As Object
      Set oDlg = CreateScriptService(,, "myDialog")
      oDlg.Execute()
      ' ...
      oDlg.Activate()
   

uoBhE‖Python and LibreOfficeDev Basic examples both assume that the dialog is stored in current document's Standard library.


     dlg = CreateScriptService(,,'myDialog')
     dlg.Execute()
     # ...
     dlg.Activate()
   

Center

7VrwE‖Centers the current dialog instance in the middle of a parent window. Without arguments, the method centers the dialog in the middle of the current window.

xEJEH‖Returns True when successful.

FVEx2‖Syntax:

svc.Center(opt Parent: obj): bool

WADQ4‖Parameters:

Woksx‖Parent: An optional object that can be either …

EFSA4‖Example:

3aa4B‖In Basic

     Sub TriggerEvent(oEvent As Object)
         Dim oDialog1 As Object, oDialog2 As Object, lExec As Long
     DsXey‖    Set oDialog1 = CreateScriptService("DialogEvent", oEvent) ' The dialog that caused the event
     ELfAf‖    Set oDialog2 = CreateScriptService("Dialog", ...) ' Open a second dialog
         oDialog2.Center(oDialog1)
         lExec = oDialog2.Execute()
         Select Case lExec
             ...
     End Sub
  
BenDd‖In Python

     def triggerEvent(event: uno):
     kpm9b‖  dlg1 = CreateScriptService('DialogEvent.Dialog', event)  # The dialog having caused the event
     vDqFX‖  dlg2 = CreateScriptService('Dialog', ...)  # Open a second dialog
       dlg2.Center(dlg1)
       rc = dlg2.Execute()
       if rc is False:
         # ...
   

Controls

4qLn9‖Return either:

FVEx2‖Syntax:

svc.Controls(): str[0..*]

svc.Controls(controlname: str): svc

WADQ4‖Parameters:

AEAHd‖ControlName : A valid control name as a case-sensitive string. If absent, the list of control names is returned as a zero-based array.

EFSA4‖Example:


      Dim myDialog As Object, myList As Variant, myControl As Object
      Set myDialog = CreateScriptService("SFDialogs.Dialog", , "Standard", "Dialog1")
      myList = myDialog.Controls()
      Set myControl = myDialog.Controls("myTextBox")
   

     dlg = CreateScriptService('SFDialogs.Dialog','', 'Standard', 'Dialog1')
     ctrls = dlg.Controls()
     ctrl = dlg.Controls('myTextBox')
   

EndExecute

j8x9C‖Ends the display of a modal dialog and gives back the argument as return value for the current Execute() running action.

gjvwy‖EndExecute() is usually contained in the processing of a macro triggered by a dialog or control event.

FVEx2‖Syntax:

svc.EndExecute(returnvalue: int)

WADQ4‖Parameters:

yukGC‖returnvalue: The value passed to the running Execute() method.

EFSA4‖Example:

ABome‖Using LibreOfficeDev Basic:


      Sub OnEvent(poEvent As com.sun.star.lang.EventObject)
          Dim oDlg As Object
          Set oDlg = CreateScriptService("SFDialogs.DialogEvent", poEvent)
          oDlg.EndExecute(ReturnValue := 25)
      End Sub
   

EtAN6‖Using Python:


     from com.sun.star.lang import EventObject
     def on_event(event: EventObject):
         dlg = CreateScriptService("SFDialogs.DialogEvent", event)
         dlg.EndExecute(25)
   
tip

ML9Mz‖Above com.sun.star.lang.EventObject mentions are optional. Such annotations help identify LibreOfficeDev Application Programming Interface (API).


Execute

FD9fr‖Display the dialog box and, when modal, wait for its termination by the user. The returned value is either:

eBFXT‖For non-modal dialog boxes the method always returns 0 and the execution of the macro continues.

FVEx2‖Syntax:

svc.Execute(modal: bool = True): int

WADQ4‖Parameters:

Ej2iF‖modal: False when non-modal dialog. Default = True.

EFSA4‖Example:

fGatm‖In this Basic example myDialog dialog is stored in current document's Standard library.


      Dim oDlg As Object, lReturn As Long
      Set oDlg = CreateScriptService("SFDialogs.Dialog", , , "myDialog")
      lReturn = oDlg.Execute(Modal := False)
      Select Case lReturn
          ' ...
      End Select
   

ouEVN‖This Python code displays DlgConvert modal dialog from Euro shared Basic library.


     dlg = CreateScriptService("SFDialogs.Dialog", 'GlobalScope', 'Euro', "DlgConvert")
     rc = dlg.Execute()
     if rc == dlg.CANCELBUTTON:
         # ...
   

GetTextsFromL10N

HU6Jv‖Replaces all fixed text strings in a dialog by their translated versions based on a L10N service instance. This method translates the following strings:

JixXU‖The method returns True if successful.

v5Zt5‖To create a list of translatable strings in a dialog use the AddTextsFromDialog method from the L10N service.

FVEx2‖Syntax:

svc.GetTextsFromL10N(l10n: svc): bool

WADQ4‖Parameters:

ECNVg‖l10n: A L10N service instance from which translated strings will be retrieved.

EFSA4‖Example:

MeJAT‖The following example loads translated strings and applies them to the dialog "MyDialog".

3aa4B‖In Basic

     oDlg = CreateScriptService("Dialog", "GlobalScope", "Standard", "MyDialog")
     myPO = CreateScriptService("L10N", "/home/user/po_files/")
     oDlg.GetTextsFromL10N(myPO)
     oDlg.Execute()
   
BenDd‖In Python

     dlg = CreateScriptService("Dialog", "GlobalScope", "Standard", "MyDialog")
     myPO = CreateScriptService("L10N", "/home/user/po_files/")
     dlg.GetTextsFromL10N(myPO)
     dlg.Execute()
   
tip

p3KMX‖Read the L10N service help page to learn more about how PO and POT files are handled.


Resize

mA4Nm‖Moves the topleft corner of a dialog to new coordinates and/or modify its dimensions. All distances are expressed in 1/100 mm. Without arguments, the method resets the initial dimensions. Return True if the resize was successful.

FVEx2‖Syntax:

svc.Resize(opt Left: num, opt Top: num, opt Width: num, opt Height: num): bool

WADQ4‖Parameters:

XRdLE‖Left: the horizontal distance from the top-left corner

FcTcU‖Top: the vertical distance from the top-left corner

uX7ps‖Width: the width of the rectangle containing the dialog

ApqA8‖Height: the height of the rectangle containing the dialog

H4CtP‖Negative or missing arguments are left unchanged

EFSA4‖Example:

3aa4B‖In Basic

     guvaM‖oDialog.Resize(1000, 2000, Height := 6000) ' Width is not changed
   
BenDd‖In Python

pEVvm‖With Python:


     gBerj‖oDialog.Resize(1000, 2000, Height = 6000)  # Width is not changed
   

Terminate

ARCGg‖Terminate the Dialog service for the current instance. Return True if the termination was successful.

FVEx2‖Syntax:

svc.Terminate(): bool

EFSA4‖Example:

CgAYf‖Below Basic and Python examples open DlgConsole and dlgTrace non-modal dialogs. They are respectively stored in ScriptForge and Access2Base shared libraries. Dialog close buttons are disabled and explicit termination is performed at the end of a running process.

W3W3Y‖In this example a button in DlgConsole is substituting inhibited window closing:

3aa4B‖In Basic

     oDlg = CreateScriptService("SFDialogs.Dialog","GlobalScope","ScriptForge","DlgConsole")
     oDlg.Execute(modal:=False)
     Wait 5000
     oDlg.Terminate()
   

7z7hg‖With Python:

BenDd‖In Python

     from time import sleep
     dlg = CreateScriptService('SFDialogs.Dialog',"GlobalScope",'Access2Base',"dlgTrace")
     dlg.Execute(modal=False)
     sleep 5
     dlg.Terminate()
   
warning

uzETY‖All ScriptForge Basic routines or identifiers that are prefixed with an underscore character "_" are reserved for internal use. They are not meant be used in Basic macros or Python scripts.