Skip to content

Simple dialog boxes

sasa edited this page Apr 14, 2017 · 10 revisions

Provides a simple dialog boxes for interaction with a user:

  • make choices (SelectBox, OptionBox)
  • enter new data (TextBox, NumberBox, DateBox)
  • get paths (FolderPathBox, FilePathBox)
  • show information (MessageBox)
  • make a decision (ActionBox)

In script interactions are invoked by simple function calls.

Usage

  • Prepare
    • create project directory in LIBREOFFICE_PATH/4/user/Scripts/python/
    • copy config.ini in project directory and edit section to customize behavior (optional)
  • Write code
    • run unodit with parameter dialogs_create

        python3 ./unodit.py -m 'dialogs_create'
                            -d 'LIBREOFFICE_PATH/4/user/Scripts/python/TestLib'
                            -a 'Test_dialogs'
      
    • write your code in generated file Test_dialogs.py

  • Prepare extension files
    • run unodit with parameter dialogs_files

        python3 ./unodit.py -m 'dialogs_files'
                            -d 'LIBREOFFICE_PATH/4/user/Scripts/python/TestLib'
                            -a 'Test_dialogs'
      
    • change description.txt, title.txt and license.txt (optional)

  • Create extension
    • run unodit with parameter dialogs_oxt

        python3 ./unodit.py -m 'dialogs_oxt'
                            -d 'LIBREOFFICE_PATH/4/user/Scripts/python/TestLib'
                            -a 'Test_dialogs'                               
      
    • install extension Test_dialogs_Devel.oxt

Available options for parameter -m: 'dialogs_create', 'dialogs_files', 'dialogs_oxt', 'dialogs_all' 'dialogs_all' = all in one, use for testing

Directory structure and parameters

TestLib/
        src/
            Test_dialogs.py           dialogs_create
            pythonpath/
                simple_dialogs.py    ---------------       
        META-INF/
            manifest.xml
        description/
            description.txt           dialogs_files
            title.txt
        registration/
            license.txt
        Addons.xcu
        description.xml              --------------
        Test_dialogs_Devel.oxt        dialogs_oxt

Dialogs

All dialogs are defined in simple_dialogs.py. In order to use dialog eg. SelectBox in your script Test_dialogs.py import it:

from simple_dialogs import SelectBox

GUI operations are a simple a matter of invoking SelectBox functions with a few parameters

s = SelectBox(message="Select your favorite city", title="My choice", choices=["New York","London", "Paris", "Berlin"])
print(s)

Generate files with option 'dialogs_create' and read Test_dialogs.py for more information.

SelectBox

Usage: SelectBox(message="Select one item", title="SelectBox", choices=['a','b','c'])

Return: a string, or None

SelectBox

OptionBox

Usage: OptionBox(message="Select multiple items", title="OptionBox", choices=['a','b','c'])

Return: a tuple of selected items, or empty tuple

OptionBox

TextBox

Usage: TextBox(message="Enter your input", title="TextBox", text="")

Return: a string, or None

TextBox

NumberBox

Usage: NumberBox(message="Enter a number", title="NumberBox", default_value=0, min_=-10000, max_=10000, decimals=0)

Return: an integer/float or None

NumberBox

DateBox

Usage: DateBox(message="Date of birth", title="BirthDay")

Return: the selected date in format YYYYMMDD

DateBox

FolderPathBox

Usage: FolderPathBox(title='Get directory path')

Return: the path of a directory or an empty string

FolderPathBox

FilePathBox

Usage: FilePathBox(title='Get file path')

Return: the path of a file or an empty string

FilePathBox

MessageBox

Usage: MessageBox(message="Message", title="MessageBox")

MessageBox

ActionBox

Usage: ActionBox(message="Message", title="ActionBox")

Return: OK or NO or Cancel

ActionBox

Clone this wiki locally