SFDialogs.Dialog service

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

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


Modális módban a doboz megjelenik, és a makrófolyamat végrehajtása felfüggesztésre kerül, amíg az OK vagy a Mégse gombok valamelyikét meg nem nyomja. Eközben a dobozon végrehajtott felhasználói műveletek meghatározott műveleteket indíthatnak el.

Nem modális módban a párbeszédablak "lebeg" a felhasználói asztalon, és a makrófolyamat végrehajtása normálisan folytatódik. A nem-modális párbeszédablak bezárul, amikor a Terminate() metódussal befejezésre kerül vagy a Collabora Office munkamenet befejeződik. A nem modális párbeszédpanelekben az ablak bezárása gomb nem aktív.

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

The Dialog service is invoked through the CreateScriptService method. It requires three 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.

Below Collabora Office 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")
      '... 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()
  

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
  

with Python:


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

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

Tulajdonságok

Név

Írásvédett

Típus

Leírás

OKBUTTON

Igen

Integer

Value = 1. An OK button was pressed.

CANCELBUTTON

Igen

Integer

Value = 0. A Cancel button was pressed.

Caption

Nem

String

Specify the title of the dialog.

Height

Nem

Long

Specify the height of the dialog box.

Modal

Igen

Boolean

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

Name

Igen

String

The name of the dialog

Page

Nem

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

Nem

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

Igen

UNO
object

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

XDialogView

Igen

UNO
object

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

Width

Nem

Long

Specify the width of the dialog box.


Esemény tulajdonságai

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

Név

Írásvédett

Basic IDE Description

OnFocusGained

Igen

When receiving focus

OnFocusLost

Igen

When losing focus

OnKeyPressed

Igen

Billentyű lenyomva

OnKeyReleased

Igen

Billentyű felengedve

OnMouseDragged

Igen

Mouse moved while key presses

OnMouseEntered

Igen

Egér belül

OnMouseExited

Igen

Egér kívül

OnMouseMoved

Igen

Egér mozdult

OnMousePressed

Igen

Mouse button pressed

OnMouseReleased

Igen

Mouse button released


Metódusok

Activate
Controls

EndExecute
Execute

GetTextsFromL10N
Terminate


Activate

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

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

Szintaxis:

svc.Activate(): bool

Példa:


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

Python and Collabora Office Basic examples both assume that the dialog is stored in current document's Standard library.


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

Controls

Return either:

Szintaxis:

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

svc.Controls(controlname: str): svc

Paraméterek:

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

Példa:


      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

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

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

Szintaxis:

svc.EndExecute(returnvalue: int)

Paraméterek:

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

Példa:

Using Collabora Office 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
   

Python használatával:


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

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


Execute

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

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

Szintaxis:

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

Paraméterek:

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

Példa:

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
   

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

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

The method returns True if successful.

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

Szintaxis:

svc.GetTextsFromL10N(l10n: svc): bool

Paraméterek:

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

Példa:

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

In Basic

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

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

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


Terminate

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

Szintaxis:

svc.Terminate(): bool

Példa:

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.

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


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

Pythonnal:


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

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.


Támogasson minket!