Macros/ScriptForge/Multi-pageDialogExample
Appearance
< Macros | ScriptForge
TDF LibreOffice Document Liberation Project Community Blogs Weblate Nextcloud Redmine Ask LibreOffice Donate
How to manage a multi-pages dialog
Authored by Jean-Pierre Ledure.
Use a listbox and/or a combo box and/or a tabbed interface and/or wizard buttons to display a single page from a multi-pages dialog.

How to run it in BASIC
Create a new document.
- Open the Basic IDE
- Select the first available blank module
- Copy and paste the Basic code
- Run Main()
How to run it in Python
Create a new document.
- Run APSO
- Create a new module, call it 'Module1'
- Copy and paste the Python code below
- Save and run the Main() method
Code
REM SCRIPTFORGE WIKI EXAMPLE
REM How to manage multiple pages ?
REM Minimal required version: LibreOffice 7.6
REM Used services
REM Dialog, DialogControl
Option Explicit
Public dialog As Object ' The SFDialogs.Dialog object
'*******************************************************************
'* Run the demo below
'*******************************************************************
Sub Main(Optional event As Object)
GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
SetupDialog()
SetupPageManager()
dialog.Execute()
dialog.Terminate()
End Sub
'*******************************************************************
'* Specific demo code
'*******************************************************************
Sub SetupPageManager()
' Define which controls in the dialog are responsible for switching pages
dialog.SetPageManager( _
pilotcontrols := "PageList,PageCombo,PageRadio1", _
tabcontrols := "PageButton1,PageButton2,PageButton3,PageButton4", _
wizardcontrols := "BackButton,NextButton", _
lastpage := 4)
End Sub
'*******************************************************************
'* May be defined with the Basic IDE
'*******************************************************************
Sub SetupDialog()
' Build from scratch the example dialog and its controls
Dim control As Object ' A SFDialogs.DialogControl object
Dim i As Integer, s As String
Set dialog = CreateScriptService("NewDialog", "PageManager", Array(160, 90, 380, 120))
dialog.Caption = "Page Manager"
With dialog
' The close button
Set control = .CreateButton("CloseButton", place := Array(340, 10, 30, 10), push := "OK")
control.Caption = "Close"
' The listbox
Set control = .CreateListBox("PageList", place := Array(10, 10, 60, 40), dropdown := False)
control.RowSource = Array("Page 1", "Page 2", "Page 3", "Page 4")
control.ListIndex = 0
' The combo box
Set control = .CreateComboBox("PageCombo", place := Array(10, 50, 60, 12), dropdown := True)
control.RowSource = Array("Page 1", "Page 2", "Page 3", "Page 4")
control.ListIndex = 0
' The radio buttons
Set control = .CreateGroupBox("PageGroup", place := Array(10, control.Y + control.Height + 4, 60, 45))
For i = 1 To 4
Set control = .CreateRadioButton("PageRadio" & i, place := Array(12, control.Y + Iif(i = 1, 0, control.Height) + 2, 60, 8))
control.Caption = "Page " & i
If i = 1 Then control.Value = True
Next i
' The tabs simulated by toggle buttons
For i = 1 To 4
Set control = .CreateButton("PageButton" & i, place := Array(100 + 40 * (i - 1), 10, 40, 10), toggle := True)
control.Caption = "Page " & i
If i = 1 Then control.Value = True ' Push 1st button down
Next i
' The wizard buttons
For Each s In Array("Back", "Next")
Set control = .CreateButton(s & "Button", place := Array(100 + Iif(s = "Back", 0, 45), 100, 32, 8))
control.Caption = s
Next s
' The page contents
For i = 1 To 4
Set control = .CreateFixedText("Page" & i, place := Array(160 + i * 10, 20 + i * 10, 150, 40))
control.Caption = "Page " & i
control.XControlModel.FontHeight = 32 ' Font size
control.XControlModel.FontWeight = 150.0 ' Bold
' Define which controls belong tof each page
control.Page = i
Next i
' Important are the tabs set on the radio buttons : they must be contiguous to make them synced
.OrderTabs(tabslist := Array( "PageList", "PageCombo", _
"PageRadio1", "PageRadio2", "PageRadio3", "PageRadio4", _
"PageButton1", "PageButton2", "PageButton3", "PageButton4", _
"BackButton", "NextButton", _
"CloseButton"))
End With
End Sub
# coding: utf-8
from __future__ import unicode_literals
### SCRIPTFORGE WIKI EXAMPLE
### How to maname a multi-pages dialog ?
### Minimal required version: LibreOffice 7,6
### Used services
### Dialog, DialogControl
from scriptforge import CreateScriptService
# *******************************************************************
# * Run the demo below
# *******************************************************************
def Main(event = None):
# dialog The SFDialogs.Dialog object
dialog = SetupDialog()
SetupPageManager(dialog)
dialog.Execute()
dialog.Terminate()
# *******************************************************************
# * Specific demo code
# *******************************************************************
def SetupPageManager(dialog):
# Define which controls in the dialog are responsible for switching pages
dialog.SetPageManager(
pilotcontrols = 'PageList,PageCombo,PageRadio1',
tabcontrols = 'PageButton1,PageButton2,PageButton3,PageButton4',
wizardcontrols = 'BackButton,NextButton',
lastpage = 4)
# *******************************************************************
# * May be defined with the Basic IDE
# *******************************************************************
def SetupDialog():
# Build from scratch the example dialog and its controls
# dialog The SFDialogs.Dialog object
# control A SFDialogs.DialogControl object
# i, s Loop variables
dialog = CreateScriptService('NewDialog', 'PageManager', (160, 90, 380, 120))
dialog.Caption = 'Page Manager'
# The close button
control = dialog.CreateButton('CloseButton', place = (340, 10, 30, 10), push = 'OK')
control.Caption = 'Close'
# The listbox
control = dialog.CreateListBox('PageList', place = (10, 10, 60, 40), dropdown = False)
control.RowSource = ('Page 1', 'Page 2', 'Page 3', 'Page 4')
control.ListIndex = 0
# The combo box
control = dialog.CreateComboBox('PageCombo', place = (10, 50, 60, 12), dropdown = True)
control.RowSource = ('Page 1', 'Page 2', 'Page 3', 'Page 4')
control.ListIndex = 0
# The radio buttons
control = dialog.CreateGroupBox('PageGroup', place = (10, control.Y + control.Height + 4, 60, 45))
for i in range(1, 5):
control = dialog.CreateRadioButton('PageRadio' + str(i),
place = (12, control.Y + (0 if i == 1 else control.Height) + 2, 60, 8))
control.Caption = 'Page ' + str(i)
if i == 1:
control.Value = True
# The tabs simulated by toggle buttons
for i in range(1, 5):
control = dialog.CreateButton('PageButton' + str(i), place = (100 + 40 * (i - 1), 10, 40, 10), toggle = True)
control.Caption = 'Page ' + str(i)
if i == 1:
control.Value = True # Push 1st button down
# The wizard buttons
for s in ('Back', 'Next'):
control = dialog.CreateButton(s + 'Button', place = (100 + (0 if s == 'Back' else 45), 100, 32, 8))
control.Caption = s
# The page contents
for i in range(1, 5):
control = dialog.CreateFixedText('Page' + str(i), place = (160 + i * 10, 20 + i * 10, 150, 40))
control.Caption = 'Page ' + str(i)
control.XControlModel.FontHeight = 32 # Font size
control.XControlModel.FontWeight = 150.0 # Bold
control.Page = i
# Important are the tabs set on the radio buttons : they must be contiguous to make them synced
dialog.OrderTabs(tabslist = ('PageList',
'PageCombo',
'PageRadio1', 'PageRadio2', 'PageRadio3', 'PageRadio4',
'PageButton1', 'PageButton2', 'PageButton3', 'PageButton4',
'BackButton', 'NextButton',
'CloseButton'))
return dialog
g_exportedScripts = (Main,)
if __name__ == '__main__':
Main()