LibreOffice 25.2 Súgó
The DialogControl service manages the controls belonging to a dialog defined with the Basic Dialog Editor. Each instance of the current service represents a single control within a dialog box.
The focus is set on getting and setting the values displayed by the controls of the dialog box. Formatting is accessible via the XControlModel and XControlView properties.
Note that the unique DialogControl.Value property content varies according to the control type.
Különös figyelmet fordítunk a fa vezérlőelemekre. Egy fát könnyen fel lehet tölteni, akár áganként, akár egyszerre több ággal. A fa vezérlőelem feltöltése történhet statikusan vagy dinamikusan.
The SFDialogs.DialogControl service is closely related to the SFDialogs.Dialog service.
Before using the DialogControl service the ScriptForge library needs to be loaded or imported:
The DialogControl service is invoked from an existing Dialog service instance through its Controls() method. The dialog must be initiated with the SFDialogs.Dialog service.
      Dim myDialog As Object, myControl As Object
      Set myDialog = CreateScriptService("SFDialogs.Dialog", "GlobalScope", myLibrary, DialogName)
      Set myControl = myDialog.Controls("myTextBox")
      myControl.Value = "Dialog started at " & Now()
      myDialog.Execute()
      ' ... process the controls actual values
      myDialog.Terminate()
   
     from time import localtime, strftime
     dlg = CreateScriptService('SFDialogs.Dialog', 'GlobalScope', lib_name, dlg_name)
     text = dlg.Controls('myTextBox')
     text.Value = "Dialog started at " + strftime("%a, %d %b %Y %H:%M:%S", localtime())
     dlg.Execute()
     # ... process the controls actual values
     dlg.Terminate()
   A DialogControl szolgáltatás egy példánya a SFDialogs.DialogEvent szolgáltatáson keresztül kérhető le, feltéve, hogy a párbeszédet a Dialog szolgáltatással kezdeményezték. Az alábbi példában az oControl tartalmazza a DialogControl példányt, amely a párbeszédeseményt kiváltotta.
      Sub aControlEventHandler(ByRef poEvent As Object)
          Dim oControl As Object
          Set oControl = CreateScriptService("SFDialogs.DialogEvent", poEvent)
          ' ...
      End Sub
  Vagy Python használatával:
     def control_event_handler(event: uno):
         oControl = CreateScriptService('SFDialogs.DialogEvent', event)
         # ...
  Note that in the previous examples, the prefix "SFDialogs." may be omitted when deemed appropriate.
When creating an event handler for control events it is good practice to handle errors inside the subroutine itself. For instance, suppose the event handler below is called when button is clicked.
    Sub OnButtonClicked(ByRef oEvent As Object)
    On Local Error GoTo Catch
        Dim oControl As Object
        oControl = CreateScriptService("DialogEvent", oEvent)
        ' Process the event
        Exit Sub
    Catch:
        MsgBox SF_Exception.Description
        SF_Exception.Clear
    End Sub
  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_button_clicked(event=None):
        try:
            oControl = CreateScriptService("DialogEvent", event)
            # Process the event
        except Exception as e:
            # The object "bas" below is an instance of the Basic service
            bas.MsgBox(str(e))
  The DialogControl service is available for these control types:
| • Button | • FixedLine | • ListBox | • TableControl | 
| Név | Írásvédett | Típus | Alkalmazható a | Leírás | 
|---|---|---|---|---|
| Border | Igen | String | Button, … | The Border property refers to the surrounding of the control: "3D", "FLAT" or "NONE". | 
| Cancel | Nem | Boolean | Button | Specifies if a command button has or not the behaviour of a Cancel button. | 
| Caption | Nem | String | Button, CheckBox, FixedLine, FixedText, GroupBox, Hyperlink, RadioButton | Specifies the text associated with the control. | 
| ControlType | Igen | String | Minden | One of the types listed above. | 
| CurrentNode | Nem | UNO | TreeControl | The currently upmost node selected in the tree control. Refer to XmutableTreeNode in Application Programming Interface (API) documentation for detailed information. | 
| Default | Nem | Boolean | Button | Specifies whether a command button is the default (OK) button. | 
| Enabled | Nem | Boolean | Minden | Specifies if the control is accessible with the cursor. | 
| Format | Nem | String | DateField, TimeField, FormattedField (csak olvasható) | Specifies the format used to display dates and times. It must be one these strings: For dates: "Standard (short)", "Standard (short YY)", "Standard (short YYYY)", "Standard (long)", "DD/MM/YY", "MM/DD/YY", "YY/MM/DD", "DD/MM/YYYY", "MM/DD/YYYY" , "YYYY/MM/DD", "YY-MM-DD", "YYYY-MM-DD". For times: "24h short", "24h long", "12h short", "12h long". | 
| ListCount | Igen | Long | ComboBox, ListBox, TableControl | Specifies the number of rows in a ListBox, a ComboBox or a TableControl. | 
| ListIndex | Nem | Long | ComboBox, ListBox, TableControl | Specifies which item is selected in a ListBox, a ComboBox or a TableControl. | 
| Locked | Nem | Boolean | ComboBox, CurrencyField, DateField, FileControl, FormattedField, ListBox, NumericField, PatternField, TextField, TimeField | Specifies if the control is read-only. | 
| MultiSelect | Nem | Boolean | ListBox | Specifies whether a user can make multiple selections in a listbox. | 
| Name | Igen | String | Minden | The name of the control. | 
| Page | Nem | Integer | Minden | 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. The Page property of a control defines the page of the dialog on which the control is visible. | 
| Parent | Igen | Dialog | Minden | The parent SFDialogs.Dialog class object instance. | 
| Picture | Nem | String | Button, ImageControl | Specifies the file name containing a bitmap or other type of graphic to be displayed on the specified control. The filename must comply with the FileNaming attribute of the ScriptForge.FileSystem service. | 
| RootNode | Igen | UNO | TreeControl | An object representing the lowest root node (usually there is only one such root node). Refer to XmutableTreeNode in Application Programming Interface (API) documentation for detailed information. | 
| RowSource | Nem | Array of strings | ComboBox, ListBox | Specifies the data contained in a combobox or a listbox. | 
| TabIndex | Igen | Numeric | All | The TabIndex property specifies a control's place in the tab order in the dialog. | 
| Text | Igen | String | ComboBox, FileControl, FormattedField, PatternField, TextField | Gives access to the text being displayed by the control. | 
| TipText | Nem | String | Minden | Specifies the text that appears as a tooltip when you hold the mouse pointer over the control. | 
| TripleState | Nem | Boolean | CheckBox | Specifies if the checkbox control may appear dimmed (grayed) or not. | 
| URL | Nem | String | Hyperlink | The URL to open when the control is clicked. | 
| Value | Nem | Variant | Refer to Value property | |
| Visible | Nem | Boolean | Minden | Specifies if the control is hidden or visible. | 
| XControlModel | Igen | UNO | Minden | The UNO object representing the control model. Refer to XControlModel and UnoControlDialogModel in Application Programming Interface (API) documentation for detailed information. | 
| XControlView | Igen | UNO | Minden | The UNO object representing the control view. Refer to XControl and UnoControlDialog in Application Programming Interface (API) documentation for detailed information. | 
| XTreeDataModel | Igen | UNO | TreeControl | The UNO object representing the tree control data model. Refer to XMutableTreeDataModel in Application Programming Interface (API) documentation for detailed information. | 
| Vezérlőelem típusa | Típus | Leírás | 
|---|---|---|
| Button | Boolean | For toggle buttons only | 
| CheckBox | Logikai vagy egész | 0, False: not checked | 
| ComboBox | String | The selected value. The ListIndex property is an alternate option. | 
| CurrencyField | Szám | |
| DateField | Date | |
| FileControl | String | A file name formatted in accordance with the FileNaming property of the ScriptForge.FileSystem service | 
| FormattedField | Karakterlánc vagy szám | |
| ListBox | String or array of strings | The selected row(s) as a scalar or as an array depending on the MultiSelect attribute | 
| NumericField | Szám | |
| PatternField | String | |
| ProgressBar | Szám | Must be within the predefined bounds | 
| RadioButton | Boolean | Minden gombnak saját neve van. Összekapcsolódnak, ha TAB-pozícióik egybefüggőek. Ha egy rádiógomb True értékre van állítva, a többi kapcsolódó gomb automatikusan False értékre lesz állítva. | 
| ScrollBar | Szám | Must be within the predefined bounds | 
| TableControl | Array | One-dimensional array with the data of the currently selected row. | 
| TextField | String | The text appearing in the field | 
| TimeField | Date | 
There is no Value property for GroupBox, Hyperlink, ImageControl and TreeControl dialog controls.
| Név | Írásvédett | Description as labeled in the Basic IDE | 
|---|---|---|
| OnActionPerformed | Igen | Művelet végrehajtása | 
| OnAdjustmentValueChanged | Igen | Beállítás során | 
| OnFocusGained | Igen | Amikor a fókuszt megkapja | 
| OnFocusLost | Igen | Amikor a fókuszt elveszti | 
| OnItemStateChanged | Igen | Elem állapota változott | 
| 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 | Egérgomb lenyomása | 
| OnMouseReleased | Igen | Egérgomb elengedése | 
| OnNodeExpanded | Nem | (Not in Basic IDE) when the expansion button is pressed on a node in a tree control | 
| OnNodeSelected | Nem | (Not in Basic IDE) when a node in a tree control is selected | 
| OnTextChanged | Igen | Szöveg módosítva | 
| List of Methods in the DialogControl Service | ||
|---|---|---|
A fa vezérlő új csomópontjának létrehozása és visszaadása egy szülő csomópontnak alárendelt UNO objektumként. A részletes információkért lásd a XMutableTreeNode oldalt az alkalmazásprogramozási felület (API) dokumentációjában..
Ezt a metódust a párbeszédablak megjelenítése előtt lehet meghívni a kezdeti fa felépítéséhez. Meghívható egy párbeszédablakból vagy vezérlőeseményből is - az OnNodeExpanded esemény használatával - a fa dinamikus befejezéséhez.
svc.AddSubNode(parentnode: uno, displayvalue: str, opt datavalue: any): uno
parentnode: A node UNO object, of type com.sun.star.awt.tree.XMutableTreeNode.
displayvalue: The text appearing in the tree control box.
datavalue: Any value associated with the new node. datavalue may be a string, a number or a date. Omit the argument when not applicable.
LibreOffice Basic and Python examples pick up current document's myDialog dialog from Standard library.
      Dim oDlg As Object, myTree As Object, myNode As Object, theRoot As Object
      Set oDlg = CreateScriptService("Dialog",,, "myDialog")
      Set myTree = oDlg.Controls("myTreeControl")
      Set theRoot = myTree.CreateRoot("Tree top")
      Set myNode = myTree.AddSubNode(theRoot, "A branch ...")
   
     dlg = CreateScriptService('SFDialogs.Dialog', None, None, 'myDialog')
     tree = dlg.Controls('myTreeControl')
     root = tree.CreateRoot('Tree top')
     node = tree.AddSubNode(root, 'A branch ...')
   True értéket ad vissza, ha egy szülő-csomópontnak alárendelt alfa sikeresen beilleszthető a fa vezérlőelembe. Ha a szülő-csomópontnak már voltak gyermek-csomópontjai a metódus hívása előtt, ezek a gyermek-csomópontok törlődnek.
svc.AddSubTree(parentnode: uno, flattree: any, opt withdatavalue: bool): bool
parentnode: A node UNO object, of type com.sun.star.awt.tree.XMutableTreeNode.
flattree: kétdimenziós tömb a megjelenített értékeket tartalmazó oszlopok szerint rendezve. Ilyen tömböt a SFDatabases.Database szolgáltatáson alkalmazott GetRows metódus adhat ki. Ha egy megjelenítendő szöveget tartalmazó tömbelem Empty vagy Null, akkor nem jön létre új alcsomópont, és a sor többi része kihagyásra kerül.
      Flat tree    >>>>    Resulting subtree
      A1	B1	C1             |__   A1	
      A1	B1	C2                   |__   B1
      A1	B2	C3                         |__  C1
      A2	B3	C4                         |__  C2
      A2	B3	C5                   |__   B2
      A3	B4	C6                         |__  C3
                             |__   A2
                                   |__   B3
                                         |__  C4
                                         |__  C5
                             |__   A3
                                   |__   B4
                                         |__  C6
   withdatavalue: Ha False alapértelmezett értéket használunk, akkor a flattree minden oszlopa tartalmazza a fa vezérlőelemben megjelenítendő szöveget. Ha True, akkor a megjelenítendő szövegek (displayvalue) a 0, 2, 4, ... oszlopokban vannak, míg az adatértékek (datavalue) az 1, 3, 5, ... oszlopokban.
      Dim myTree As Object, theRoot As Object, oDb As Object, vData As Variant
      Set myTree = myDialog.Controls("myTreeControl")
      Set theRoot = myTree.CreateRoot("By product category")
      Set oDb = CreateScriptService("SFDatabases.Database", "/home/.../mydatabase.odb")
      vData = oDb.GetRows("SELECT [Category].[Name], [Category].[ID], [Product].[Name], [Product].[ID] " _
          & "FROM [Category], [Product] WHERE [Product].[CategoryID] = [Category].[ID] " _
          & "ORDER BY [Category].[Name], [Product].[Name]")
      myTree.AddSubTree(theRoot, vData, WithDataValue := True)
   
     SQL_STMT = "SELECT [Category].[Name], [Category].[ID], [Product].[Name], [Product].[ID] \
         FROM [Category], [Product] WHERE [Product].[CategoryID] = [Category].[ID] \
         ORDER BY [Category].[Name], [Product].[Name]"
     tree = dlg.Controls('myTreeControl')
     root = tree.CreateRoot('By Product category')
     db = CreateScriptService('SFDatabases.Database', '/home/.../mydatabase.odb')
     sub_tree = db.GetRows(SQL_STMT)
     tree.AddSubTree(root, sub_tree, withdatavalue=True)
   Returns a new root node of the tree control, as a node UNO object of type com.sun.star.awt.tree.XMutableTreeNode. The new tree root is inserted below pre-existing root nodes. A részletes információkért lásd a XMutableTreeNode oldalt az alkalmazásprogramozási felület (API) dokumentációjában.
This method may be called before displaying the dialog box to build the initial tree. It may also be called from a dialog or control event to complete the tree dynamically.
svc.CreateRoot(displayvalue: str, opt datavalue: any): uno
displayvalue: The text appearing in the tree control box.
      Dim myTree As Object, myNode As Object
      Set myTree = myDialog.Controls("myTreeControl")
      Set myNode = myTree.CreateRoot("Tree starts here ...")
   
     tree = dlg.Controls('myTreeControl')
     node = tree.CreateRoot('Tree starts here ...')
   Végigjárja a fát, és a gyökérből kiindulva rekurzív módon megkeresi a bizonyos kritériumoknak megfelelő csomópontot. Vagy - 1 egyezés elegendő - a megjelenítési értéke megegyezik a displayvalue mintával, vagy az adatértéke megegyezik a datavalue mintával. Az összehasonlítások lehetnek nagy- és kisbetű-érzékenyek vagy nem. Az első megfelelő előfordulást egy com.sun.star.awt.tree.XMutableTreeNode típusú UNO-objektumként kapjuk vissza. A részletes információkért lásd a XMutableTreeNode oldalt az alkalmazásprogramozási felület (API) dokumentációjában.
When not found, the method returns Nothing, to be tested with the IsNull() builtin function.
This method may be called before displaying the dialog box to build the initial tree. It may also be called from a dialog or control event.
svc.FindNode(displayvalue: str = '', opt datavalue: any, casesensitive = False): uno
One argument out of displayvalue or datavalue must be specified. If both present, one match is sufficient to select the node.
displayvalue: The pattern to be matched. Refer to SF_String.IsLike() method for the list of possible wildcards. When equal to the zero-length string (default), this display value is not searched for.
casesensitive: Default value is False
      Dim myTree As Object, myNode As Object
      Set myTree = myDialog.Controls("myTreeControl")
      Set myNode = myTree.FindNode("*Sophie*", CaseSensitive := True)
   
     tree = dlg.Controls('myTreeControl')
     node = FindNode('*Sophie*', casesensitive=True)
     if node is None:
         # ...
   Move the top-left corner of a dialog control to new coordinates and/or modify its dimensions. Return True if resizing was successful.
svc.Resize(opt Left: int, opt Top: int, opt Width: int, opt Height: int): bool
Minden távolságot Map AppFont egységek-ben fejezünk ki, és a szülő párbeszédablak bal felső sarkától mérjük. Argumentumok nélkül a metódus átméretezi a vezérlőelemet a "preferált méretre", amely méret a tényleges tartalomtól függően módosul. A hiányzó argumentumok változatlanul maradnak.
Left: The horizontal distance from the top-left corner
Top: The vertical distance from the top-left corner
Width: the horizontal width of the rectangle containing the control
Height: the vertical height of the rectangle containing the control
      Dim oControl As Object
      Set oDlg = CreateScriptService("SFDialogs.Dialog",,, "myDialog")
      Set oControl = oDlg.Controls("thisControl")
      oControl.Resize(100, 200, Height:=6000) ' Width is unchanged
    
      dlg = CreateScriptService('Dialog', None, None, 'myDialog')
      ctrl = dlg.Controls('thisControl')
      ctrl.Resize(300, 200, 1500)  # Height is unchanged
    Set the focus on the control. Return True if focusing was successful.
This method is often called from a dialog or control event.
svc.SetFocus(): bool
      Dim oControl As Object
      Set oDlg = CreateScriptService("SFDialogs.Dialog",,, "myDialog")
      Set oControl = oDlg.Controls("thisControl")
      oControl.SetFocus()
    
      dlg = CreateScriptService('Dialog', None, None, 'myDialog')
      ctrl = dlg.Controls('thisControl')
      ctrl.SetFocus()
    Fills a TableControl with the given data. All preexisting data is cleared before inserting the new data passed as argument.
Amikor a TableControl hozzáadódik a párbeszédablakhoz, a Basic IDE segítségével meghatározható, hogy az oszlop- és sorfejlécek megjelenjenek-e a táblázatban. Ha a TableControl rendelkezik oszlop- és/vagy sorfejléccel, akkor a megadott adattömb első oszlopát és/vagy sorát használja a rendszer a táblázatfejlécek címkéjeként.
This method returns True when successful.
svc.SetTableData(dataarray: any[0..*, 0..*], widths: int[0..*], alignments: str, RowHeaderWidth = 10): bool
dataarray: A táblázatba beírandó adatok, amelyeket Basicben tömbök tömbjeként, Pythonban tuplek tuplejeként ábrázolnak. Az adatoknak tartalmazniuk kell az oszlop- és sorfejléceket, ha azokat a TableControl meg kívánja jeleníteni.
szélességek: Az egyes oszlopok relatív szélességét tartalmazó tömb. Más szóval, widths = (1, 2) azt jelenti, hogy a második oszlop kétszer olyan széles, mint az első. Ha a tömb értékeinek száma kisebb, mint a táblázat oszlopainak száma, akkor a tömb utolsó értékét használjuk a fennmaradó oszlopok szélességének meghatározására.
igazítások: Az igazítást minden oszlopban egy karakterláncként határozza meg, amelyben minden karakter lehet "L" (balra), "C" (középre), "R" (jobbra) vagy " " (szóköz, alapértelmezett, ami karakterláncok esetén balrát, számértékek esetén jobbrát jelent). Ha a karakterlánc hossza rövidebb, mint a táblázat oszlopainak száma, akkor a karakterlánc utolsó karaktere szolgál a fennmaradó oszlopok igazításának meghatározására.
RowHeaderWidth: width of the row header column expressed in Map AppFont units. Default = 10. The argument is ignored when the TableControl has no row header.
The following example assumes that the dialog myDialog has a TableControl named Grid1 with "Show row header" and "Show column header" properties set to "Yes".
     Dim myDialog As Object, oTable As Object, tableData As Variant
     myDialog = CreateScriptService("Dialog", "GlobalScope", "Standard", "myDialog")
     oTable = myDialog.Controls("Grid1")
     tableData = Array("Column A", "Column B", "Column C")
     tableData = SF_Array.AppendRow(tableData, Array("Row 1", 1, 2))
     tableData = SF_Array.AppendRow(tableData, Array("Row 2", 3, 4))
     tableData = SF_Array.AppendRow(tableData, Array("Row 3", 5, 6))
     vAlignments = "LCC"
     vWidths = Array(2, 1, 1)
     oTable.SetTableData(tableData, vWidths, vAlignments)
     myDialog.Execute()
   A Value tulajdonság a táblázat kiválasztott sorát adja vissza. Ha nincs kijelölt sor, akkor egy üres Array objektumot kapunk vissza. A következő kódrészlet azt mutatja be, hogyan teszteljük, hogy van-e kiválasztott sor a táblázatban.
     rowValues = oTable.Value
     If UBound(rowValues) < 0 Then
         MsgBox "No row selected."
     Else
         MsgBox "Row " & oTable.ListIndex & " is selected."
     End If
   
     dlg = CreateScriptService("Dialog", "GlobalScope", "Standard", "myDialog")
     table_control = dlg.Controls("Grid1")
     table_data = (("Column A", "Column B", "Column C"),
                   ("Row 1", 1, 2),
                   ("Row 2", 3, 4),
                   ("Row 3", 5, 6))
     alignments = "LCC"
     widths = (100, 50, 50)
     table_control.SetTableData(table_data, widths, alignments)
     dlg.Execute()
   
     bas = CreateScriptService("Basic")
     row_values = table_control.Value
     if len(row_values) == 0:
         bas.MsgBox("No row selected.")
     else:
         bas.MsgBox(f"Row {table_control.ListIndex} is selected.")
   Add a new line at the end of a multiline text field. A newline character will be inserted when appropriate. The method returns True when successful.
An error is raised if the actual control is not of the type TextField or is not multiline.
svc.WriteLine(opt line: str): bool
Line: The string to insert. Default is an empty line.
      Dim oDlg As Object, oControl As Object
      Set oDlg = CreateScriptService("SFDialogs.Dialog",,, "myDialog")
      Set oControl = oDlg.Controls("thisControl")
      oControl.WriteLine("a new line")
   
     dlg = CreateScriptService('SFDialogs.Dialog', None, None, 'myDialog')
     ctrl = dlg.Controls('thisControl')
     ctr.WriteLine("a new line")