Commit Graph
63 Commits
Author SHA1 Message Date
Jean-Pierre Ledure 2821d29a87 ScriptForge (FileSystem) Manage ZIP archives
The FileSystem service provides simple
methods to manage compressed zip archives.

As an example, .odf and .oxt files being
formatted as such archives, massive or
punctual changes of file contents
with smart scripts can be facilitated.

New methods:
- IsZipFile(filename)
    returns True when filename is a valid
    zip file
- FilesInZip(filename, pattern)
    returns a list of archive members,
    optionally filtered with a Like pattern,
    stored in filename
- ExtractFromZip(filename, destination, source)
    stores the source file(s) found in the
    given ZIP file into a destination folder
- CompressToZip(filename, foldername, rootfolder)
    stores the content of folder, including
    its subfolders, into a zip archive,
    optionally under a root folder

The implementation is based on the python
zipfile standard library.

The methods area available both for Basic and
Python user scripts. For Python scripts, the
user is also free to use the native zipfile
library instead.

The user documentation shouid be updated
according to this commit.

Change-Id: I506a8583dc3fa38c7e05094562ade33f84a24747
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/211891
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
2026-10-07 14:26:54 +02:00
Andrea Gelmini cdca7e34ce Fix typo
Change-Id: Iee29feb8d794f4deadcf2b3d2afd0c8f2334f42b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/205264
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
Tested-by: Jenkins
2026-05-17 19:26:13 +02:00
Jean-Pierre Ledure d8f94b5a26 SctiptForge Python scripts and default pipe
Python scripts may run either
(1) inside the LO process, the usual mode
(2) as a client of a LO server
    using a pipe or a socket.
    The LO command is started with
    an "--accept" argument.

The benefit of (2) is the freedom to
choose his/her preferred IDE to edit
and debug the script. The drawback is the
reference to the pipe/socket in the
script source code.

APSO is the best (only ?) choice for debugging (1).

With this commit, when no reference is given
to a pipe or a socket in the user script,
ScriptForge tries a connection through the
default pipe 'PIPE2LIBREOFFICE'.
If the connection fails, mode (1) is assumed.

The benefit is that the same source code
can run without change in both (1) and (2)
modes.
The command to run LO must refer explicitly
to the default pipe when (2) is wanted.

The change has no effect on existing Python
scripts.

Change-Id: I3176f4744ffea5b387280e9364b3563483fd14f0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/205228
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2026-05-16 11:12:33 +02:00
Jean-Pierre Ledure d6b4eb14c3 ScriptForge Session.GetUnoProperty/GetPropertyByName()
Several changes:

- 2 new methods in the Session service:
    session.GetPropertyByName(basicobject,
        propertyname, [arg])
      for read access to properties of ScriptForge
      object instances.
      Argument is required for some Calc properties.
    session.GetUnoProperty(unoobject,
        propertyname)
      for read access to properties of UNO
      object instances.
  Those methods complement nicely the
  array.Map(), Filter() and Reduce() methods.

- The wording of trapped errors when
    session.ExecutePythonScript()
  fails has been reviewed to be distinct
  to that of
    session.ExecuteBasicScript()

- The source code of
    session.GetPDFExportOptions() was missplaced.

- A more accurate identification of ScriptForge
  object instances has been implemented in
    SF_Utils._VarTypeObj()
  (internal use only).

- Some fixed typos

The changes are applicable to Basic and Python
user scripts.

The new methods require an update of the user
documentation.

Change-Id: Ibbc0eecfe52a190eece66edadc14710a7fd6a106
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/205033
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2026-05-11 10:12:10 +02:00
Jean-Pierre Ledure 6f5a59a79b ScriptForge (UI) new EnterValue() method
The
   ui.EnterValue(...)
method displays a typed input box to the user
and returns the entered value as a scalar
of the requested type, or Empty/None
when the user cancels the box.

=> A single statement to interact with
   the user through a complex dialog box
   e.g. a listbox field of allowed values.

The box is centered on the active window.

The arguments (all are optional) :
   prompt: the message appearing above the input field
      Escape chars (\n \t) are interpreted correctly
   valuetype: determines the type of the input field
      and of the returned value, either
         STRING, PASSWORD -> str
         BOOL, INTEGER, FLOAT -> bool, int, float
         DATE, TIME, DATETIME -> datetime
         COMBO, LIST, RADIO -> str
   default: the initial value
   title: the header of the dialog
   choices: the list of valid values
      (COMBO, LIST and RADIO only)
   format: the format of numeric and date values

Example (Python):
   destination = ui.EnterValue(("What is your next destination ?", "LIST",
                      choices = ("Belgium", "Brazil", "France", "Mexico"),
                      default = "France",
                      title = "This text is in the titlebar")

The box is sized based on the arguments.

The function is available both in Basic
and Python user scripts.

The user documentation should be adapted accordingly.

Change-Id: I7c3f02f597ba5990c5f5a8548fb4f07699cda358
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199194
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2026-02-12 10:01:37 +01:00
Andrea Gelmini 3846a3b02c Fix typo
Change-Id: I0faf22d000d08806662cf7e958896b967961ed0e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193980
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
Tested-by: Julien Nabet <serval2412@yahoo.fr>
2025-11-14 13:09:33 +01:00
Jean-Pierre Ledure 2a3eb41c03 ScriptForge (SFDocuments) new Shape service
The new "Shape" service is focused on
the description of shapes/images/drawing
objects stored in documents.
In the actual release only shapes
in Calc sheets are considered.

A Shape instance is created from either:
-  calc.CreateShapeFromFile(shapename, imagefile,
                            range, aslink)
   => the shape is loaded in the sheet and
      anchored to the given range.
      The shape may or not be embedded in the
      document.
-  calc.Shapes(sheetname, shapename)

Next methods are available:
-  shape.Anchor(anchortype, cell)
   => define the anchor type and the cell
      to which the shape has to be anchored.
-  shape.ExportToFile(filename, imagetype, overwrite)
   => save the shape as an image file
      to a specified location.
-  shape.Pick()
   => select the shape (NB "Select" is a reserved
      word in Basic, hence "Pick")
-  shape.Resize(xpos, ypos, width, height)
   => change position and/or size.
-  shape.Rotate(angle, pivot)
   => rotate the shape using a given
      pivot point (x, y) with a given angle.

The shape.XShape property gives a direct
access to its com.sun.star.drawing.XShape
UNO representation.

The pre-existing SF_Chart service is
functionally unchanged. However it is
now implemented as a subclass of the
new SF_Shape service.
Compatibility with previous releases
is preserved.

The implementation required a few changes
in the error messages. Hence also in
their translations.

All the functions are available for both
Basic and Python user scripts.

The documentation should include:
- a revision of the Calc and Chart help pages
- the creation of an additional Shape page

Change-Id: Ib67f5e755e3112961aadeffc3188b2cdf9aca613
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193906
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
2025-11-13 10:04:58 +01:00
Jean-Pierre Ledure f6b4cee785 ScriptForge (Calc) ColorizeRange() clean colors
The ColorizeRange() method accepts next
arguments:

- TargetRange : the cell or the range as a string
    in which cells should be re-colorizeed
- Foreground: the foreground color as the output
    of the RGB() function
- Background: the background color as the output
    of the RGB() function
- FilterFormula: a Calc formula to select
    among the given TargetRange which cells,
    rows or columns should affected
- FilterScope: "CELL", "ROW" or "COLUMN"

So far, negative values for Foreground and
Background were ignored.
Now, they reset the colors to their default
values.

This is valid for Basic and Python user scripts.
The documentation should be updated
accordingly.

Change-Id: Ie7722365bcacb1ebe82dc1fc226ed047483143dd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191969
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
2025-10-06 18:01:21 +02:00
Jean-Pierre Ledure d8c75e9bda ScriptForge (Sharedmemory) review StoreValue() signature
Thanks to commit
  https://gerrit.libreoffice.org/c/core/+/190931
  (Extend Python-Basic gateway for objects)
a signature with an object instance as argument
is allowed in any position, i.o. the 1st only.

This is applicable to
  sharedmemory.StoreValue(value, variablename)
Indeed, 'value' may be such an object instance.

The signature becomes now
  sharedmemory.StoreValue(variablename, value)
which is more intuitive.

No impact on user scripts <= 25.8

Documentation should take both commits
into account.

Change-Id: I1a07cd740fc9dcba1077932bba0f69735a7bc647
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190979
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
2025-09-17 16:44:26 +02:00
Andrea Gelmini ef4d044ee1 Fix typo
Change-Id: I77c1c2bce39f2a96d52b2ac594682682163bd976
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190450
Tested-by: Jenkins
Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
2025-09-01 04:47:24 +02:00
Jean-Pierre Ledure 3f34264bc6 ScriptForge - Upgrade python stub file
Concerned file:
  scriptforge.pyi
(python stub having no impact on script
execution, only on script edition with
advanced IDE's like PyCharm and VSCode).

Guided by
  https://typing.python.org/en/latest/guides/modernizing.html#generics-in-the-typing-module
Older typing features are superseded
by more modern alternatives,
which are recommended to use.

Applicable changes:
>= Python 3.9
  typing.Dict => dict
  typing.List => list - replaced by tuple
  typing.Tuple => tuple
  typing.Sequence => collections.abc.Sequence
                     replaced by tuple
>= Python 3.10
  typing.Optional => | None
  typing.Union => | (pipe operator)

This makes the source more readable
and, also, a bit shorter.

No impact on user scripts.
Documentation unchanged.

Change-Id: I856d01660c5c3e1c3f0a0c2cca756fa0cbfd9a4a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190362
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2025-08-29 15:54:45 +02:00
Jean-Pierre Ledure e79a47409f ScriptForge - new SharedMemory service
Singleton class implementing the
  "ScriptForge.SharedMemory"
service. Implemented as a usual Basic module.

Contains the mechanisms to manage persistent memory storage
across Basic and/or Python scripts.

When a script stops running, all the variables it uses vanish,
except Basic Global variables, which stay in memory until
the end of the LibreOffice session.

However event-driven scripting can often benefit from having
variables still being available when the next script is
triggered, probably due to a user action.

The SharedMemory service implements interfaces allowing
to store both BASIC and PYTHON variables in persistent storage,
and to retrieve them later from either BASIC or PYTHON scripts
interchangeably.

The use of the Basic Global statement is more efficient
than the actual service and should be preferred when the variables
are created and retrieved in basic scripts only.

The supported variable types are:
 * Scalar or tuple combining:
  - int, within the bounds of the Basic Long type
  - float, within the bounds of the Basic Double type
  - str
  - bool
  - None
 * datetime.datetime
 * UNO object
 * ScriptForge class instance

Example:
  Sub CreateDoc()
    ui = CreateScriptService("UI")
    doc = ui.CreateDocument("Calc")
    store = CreateScriptService("SharedMemory")
    store.StoreValue(doc, "actualdocument")
  ...

  def UpdateDoc():
    store = CreateScriptService("SharedMemory")
    doc = store.ReadValue("actualdocument")
    ...

The service is available both for Basic and Python scripts.
The actual commit requires the creation of an additional
Help page.

Change-Id: Id53994be5105206c16659f769338261b3dde2d3a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190174
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2025-08-25 16:24:31 +02:00
Jean-Pierre Ledure e72f7d6dd3 ScriptForge new session.GetRangeFromCalc method
The
   GetRangeFromCalc(filename: str, range: str)
method (stored in the Session service)
reads the values contained in the given
range located in the given Calc file.

The file does not need to be open. This
makes this shortcut particularly useful.

The content of the range is returned either
- as a scalar for a single cell
- as a 1D-array or a tuple when the range
  is contained in a single row or column
- as a 2D-array or a tuple of tuples for
  a rectangular range of adjacent cells.

Clean error management is included in the code.

The method is available for Basic and Python
user scripts.

The user documentation needs to be updated.

Change-Id: I39cd218f0bf3a6a21e3ada42826069eeee451c6e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189000
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2025-08-06 14:34:55 +02:00
Jean-Pierre Ledure 92494fbbec ScriptForge (Basic) new Wait() method
Constructions (Python) like
    import time
    while some_event is False:
        time.sleep(1)
watching for some_event becoming True
have the drawback to freeze the LibreOffice
user interface.

While next (Basic) snippet
    Do While Not some_event
        Wait(1000)
does not.

The Python example prevents for waiting for events
that require user input,f.i. entering a value
in a cell.

The here proposed alternative is (Python):
    basic = CreateScriptService('Basic')
    while some_event is False:
        basic.Wait(1000)
This works smoothly.
The Wait() method executes in the background
a Basic Wait statement.

This impacts only Python user scripts.
The change requires an update of the user
documentation.

Change-Id: Idb73907a5e27cf288310e306fb41c0aba9c8a388
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185137
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
2025-05-10 16:07:43 +02:00
Jean-Pierre Ledure b7e84bec01 ScriptForge (Calc) new DefineName() method
Introduction of

1. the DefinedNames property
   Returns the full sorted list of all
   named ranges in the document.
   The names defined in a single sheet
   are qualified with the sheet name.

2. the DefineName() method
     calc.DefineName(definedname, value [,sheetname])
   Define a new name in the worksheet, at global
   or sheet level. If the name existed already,
   it is overwritten without warning.
   The Value of the new name may be a range,
   a scalar value or a formula.
   When a range, the top-left cell is set
   as reference cell.
   After creation, the new name can be used
   in formulaes.

The functions are available both for Basic
and Python user scripts.

The documentation will need an update.

Change-Id: I184e97b734a57ecba2e8a8eae583050116f40296
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184963
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2025-05-06 14:31:56 +02:00
Jean-Pierre Ledure 11d8753e03 ScriptForge (UI) extend scope of CreateBaseDocument
The
    ui.CreateBaseDocument()
method accepted so far to create Base documents
either embedding HSQLDB or FIREBIRD databases
or linked to a Cals spreadsheet.

It is now extended to make the new Base document
finding its datasource in an external Firebird
database file.

The previous signature
    ui.CreateBaseDocument(FileName, EmbeddedDatabase,
        CalcFileName)
is replaced by
    ui.CreateBaseDocument(FileName, EmbeddedDatabase,
        DataFileName, CalcFileName)
=> The CalcFileName argument is deprecated. When present,
   it is copied to DataFileName.
The EmbeddedDatabase argument may take next values:
    HSQLDB (default), FIREBIRD, FIREBIRD_EXTERNAL or CALC.

The change is valid for both Basic and Python scripts.
The documentation should be upgraded.

Change-Id: I5daf418f50739baca6be899eb1444d1b99cf89aa
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184935
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2025-05-04 10:18:48 +02:00
Jean-Pierre Ledure 9671c73922 ScriptForge (FileSystem) Title arg for PickFolder()
Only Windows implements the Description
property of the FolderPicker by displaying
it in the dialog's header. Otherwise it
is ignored.

This commit harmonizes the behaviour
among all environments, including Linux.

The previous signature:
   fs.PickFolder(defaultdirectory, freetext)
is replaced by:
   fs.PickFolder(defaultdirectory, title, freetext)

The 'freetext' parameter is kept for backward
compatibility. It becomes obsolete. When present,
and 'title' is absent, its content is pushed
to the dialog's title.

The change is valid both for Basic and Python scripts.
The documentation should be updated accordingly.

Change-Id: I888ee4afa5046212081bbdedc849147ebda1a3bf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184719
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2025-04-28 16:56:28 +02:00
Jean-Pierre Ledure c8d2751a90 ScriptForge (SF_Exception) Return codes
So far, an exception raised in a user script
and detected by ScriptForge gave next behaviour:
- an error message was displayed to the user (1)
- the same error message was recorded in the
  console (2)
- the execution of the script was stopped (3)

The actual commit introduces 4 new properties
in the SF_Exception service.
Next two boolean properties may optionally
change above behaviour:
  exception.ReportScriptErrors (default = True)
  exception.StopWhenError (default = True)
They may change resp. behaviours (1) and (3).
Note that behaviour (2) is preserved anyway.
Their values are set until they are set
again or until the LO session expires.

When StopWhenError is set to False, next two
properties allow to test the success of the
last call to the ScriptForge API and to
define an appropriate action, including the
continuation of the process:
  exception.ReturnCode
  exception.ReturnCodeDescription

Example:
    exc = CreateScriptService("Exception")
    fs = CreateScriptService("FileSystem")
    exc.ReportScriptErrors = False
    exc.StopWhenError = False
    fs.OpenTextFile("/aaa/bbb")
    if exc.ReturnCode = "UNKNOWNFILEERROR":
        ...

The test on the return code must precede any
next call to any ScriptForge API entry.

The list of the available return codes is
listed in the SF_Exception.xba source code.

These changes are applicable both for Basic
and Python user scripts.
The user documentation should be reviewed.

Change-Id: I6d274e54ee37702f244e729ea5c9d1751b69abec
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183486
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2025-03-30 11:12:08 +02:00
Jean-Pierre Ledure 2cb150fd2d ScriptForge (Platform) new UntitledPrefix property
Returns the prefix used to name new documents
(in English = "Untitled ").

Improves the portability of scripts by making
them more language-agnostic.

Available for Basic and Python scripts.
The user documentation should be updated.

Change-Id: Ie3c06e25fdc30fc1c3c775ef6ebbcee1d9cd77cd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183134
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2025-03-20 11:48:09 +01:00
Jean-Pierre Ledure 0658c51d63 ScriptForge (Dialog) new ImportControl() method
The
  ImportControl()
method copies a control stored in a dialog
to the actual dialog.
Like in:
  dlg1 = CreateScriptService("Dialog", ...)
  dlg2 = CreateScriptService("NewDialog", ...)
  dlg2.ImportControl(dlg1, "thiscontrol", ...)

The additional arguments contribute to optionally:
- renaming the new control
- storing the new control in a specific page
- repositioning the control (offsetx and offsety args)
- including the OnEventxxx properties

One goal is to help defining individual smaller
dialogs in the IDE and inserting them in a larger
one, keeping them in separate pages.

The function works for Basic and Python user scripts.
The user documentation will have to be updated.

Change-Id: I6155f58d2e8706b73fc5f72c070bb8230cdd17ee
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182865
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2025-03-13 14:48:00 +01:00
Jean-Pierre Ledure 05d2701e3b ScriptForge (Dialogs) add the TabPageContainer control
TabPageContainer-type controls are not supported
by the Basic IDE, while they are visually
attractive.

The current commit proposes the insertion
of such a control by code
  dialog.CreateTabPageContainer(..., tabheaders, ...)
where tabheaders is simply an array of strings.

The originality of the approach is here to make
the link with dialog pages very easy:
  OnTabSelected: define the script to trigger
                 when a tab is selected
  Value: get or set the actual tab

Additionally, the TabPageContainer control is
associated with the SetPageManager() method.

Example on
https://gitlab.com/LibreOfficiant/scriptforge/-/snippets/4823173

The function is available for Basic and Python user scripts.

The documentation will need to be updated accordingly.

Change-Id: I7a1644344cad5f3739055f7e1eec69310ffa019c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182697
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2025-03-10 11:07:23 +01:00
Andrea Gelmini b96c634d31 Fix typo
Change-Id: I4a956e71e54051da58ef75e936106ba21bf501d8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181894
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
Tested-by: Jenkins
2025-02-19 18:39:42 +01:00
Jean-Pierre Ledure ec71ff69fe ScriptForge (SF_Calc) formatting methods
So far only the SetCellStyle() method
provided means to modify cell formats.

The actual patch introduces next methods
to apply simple and common formats. For
other options use the XCellRange
UNO interface.

- calc.AlignRange(targetrange,alignment,...)
- calc.BorderRange(targetrange,borders,...)
- calc.ColorizeRange(targetrange,foreground,background,...)
- calc.DecorateFont(targetrange,fontname,fontsize,
         decoration,...)
- calc.FormatRange(targetrange,numberformat,locale,...)

Extra arguments ("...") are:
  FilterFormula: a Calc formula to select cells
  FilterScope; CELL, ROW or COLUMN
to allow a kind of static conditional formats.

All methods are applicable to Basic and Python
user scripts.

This change will require an update of the
user documentation.

Change-Id: Ic824aebd763f2b55364c2c0bea17430f32512742
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181854
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
2025-02-19 10:59:24 +01:00
Jean-Pierre Ledure 970ad633e4 ScriptForge (SFDocuments) new MenuHeaders property
The %enuHeaders property returns,
as an array/tuple of strings the list
of the menus present in the menubar.

This is a helper for the CreateMenu()
method:
- check if the menu exists already to
  avoid duplicates
- ease the choice of the Before argument

The property is applicable to next classes:
- Document, and its subclasses
  Base, Calc, Writer, FormDocument
- Datasheet

The property is made available to Basic
and Python user scripts.

This new property will require an update
of the user documentation/help

Change-Id: Ia14daf6c58973e06d576b350e416eb178f70feb3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181065
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2025-02-04 10:16:01 +01:00
Jean-Pierre Ledure ca1dca4f1d ScriptForge (ContextMenu) new RemoveAllItems() method
The contextmenu service handles the context
menus stored in a document. So far, it
provided only the AddItem() method to add
new items at the bottom of the menu.

The new method allows to forget the preconfigured
menu and to replace it completely.

Example: associate next Sub with the
         on-right-click event of sheet 'Sheet1'
         => The custom menu appears when
            right-clicking in column C, otherwise
            normal behaviour
  Sub OnRightClick1(Optional XRange)
       ' Xrange is a com.sun.star.table.XCellRange
  Dim calc, menu, bColumn
  Set calc = CreateScriptService("Calc", ThisComponent)
  Set menu = calc.ContextMenus("cell")
  menu.RemoveAllItems()
  bColumn =  ( Len(calc.Intersect("Sheet1.$C:$C", _
             XRange.AbsoluteName)) > 0 )
  If bColumn Then
      menu.AddItem("A", Script := "vnd.sun.star.script:...&location=document")
      ...
  End If
  menu.Activate(bColumn)
  End Sub

The function is available both for Basic and Python user scripts.
The user documentation will have to be reviewed.

Change-Id: I84ee8724bf99c37397a19d729133cc4686a63980
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180520
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2025-01-21 09:30:57 +01:00
Jean-Pierre Ledure 1032ba1214 ScriptForge (SF_Calc new Intersect() method
The
    calc.Intersect(range1, range2) method
computes the common area as a string
which is a sub-range of both input ranges.
It returns an empty string when the
sub-range is empty.

Potential use case: customizing a popup
or context menu depending on the presence
of the selected cell in a given area.

In addition, the A1Style() method returns
the sheetname in the output string only
when it is an explicit argument.

Changes are applicable both for Basic and
Python scripts.

They require an update of the user documentation.

Change-Id: I920fc8bee6dace9ceed263a0570b4c0197bc8cb8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180479
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2025-01-19 16:43:49 +01:00
Jean-Pierre Ledure b86e078d79 ScriptForge (SF_Calc new XRectangle property
The
   XReetangle(rangename)
property returns a com.sun.star.awt.Rectangle
structure describing the coordinates (in pixels)
on the screen where the given range is
located.

This opens the door to effective interactivity
in calc sheets with the use of popup menus.

Example:
   r = calc.XRectangle("B2")
   menu = CreateScriptService("PopupMenu", , _
           X := r.X + r.Width/2, Y := r.Y + r.Height/2)
initializes a popup menu centered on the given
cell.

The property exists in Basic and Python.
The SF_Calc help page should be updated
according to the actual patch.

Change-Id: I2a97c5c7b5bf84d36a2aab5e4b822e30c9d53d8e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180140
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2025-01-12 16:15:38 +01:00
Andrea Gelmini bce744550d Fix typo
Change-Id: I0b9be4ea10c3837007158771fde46ad70e5c52a8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177785
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2024-12-05 16:11:06 +01:00
Jean-Pierre Ledure d28fcb3e26 ScriptForge (SF_Session) enhance ExecuteCalcFunction
The ExecuteCalcFunction() method is a wrapper
of the
   com.sun.star.sheet.FunctionAccess::callFunction()
method.

This method accepts a broad variety of arguments
- scalars: numeric and strings only
- data arrays (= arrays os arrays)
- 2D arrays (1D arrays give errors)
- com.sun.star.table.XCellRange objects
depending on the called function and its
execution or not as an "array function".

The actual commit makes that the arguments passed to
   session.ExecuteCalcFunction()
are checked as formally correct: scalars are filtered
as numeric or strings, dates and booleans are converted,
arrays are reshaped to 2D where necessary.

The actual change facilitates, as an example,
the use of complex array functions like XLOOKUP,
a powerful search engine on large data sets.

The implemented functionalities are valid in Basic
and Python.

The help documentation might be completed with
additional examples.

Change-Id: I6bba1e21828ef09c5c6f0463cbcfa1f5df695073
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177744
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
2024-12-04 10:21:45 +01:00
Jean-Pierre Ledure e74b731c80 scriptforge.pyi - Fix typo
Change-Id: I993e30d3d228c639a69007a846b46f420f9297b3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175097
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
2024-10-18 13:38:18 +02:00
Andrea Gelmini 85e4167c64 Fix typo
Change-Id: I2d58d52d5f331ae9b3f3c4d3dc91d86c075c2a39
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174968
Tested-by: Jenkins
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
2024-10-15 19:29:14 +02:00
Jean-Pierre Ledure 0f74a4c2bf scriptforge.py Color args in exception.PythonShell()
The
   exception.PythonShell()
method opens the APSO console.

It receives 2 additional arguments
   background
   foreground
which specify the back- and foreground colors
of the window to open as a Python console.

Typical use of the method:
   exc.PythonShell({**globals(), **locals()}, \
       background = 0x0, foregound = 0xFFFFFF)
opens the shell with all existing variables
loaded and with white characters on a black
background.

The default values are those set in APSO:
   background = 0xFDF6E3
   foreground = 0x657B83
No impact on existing scripts.

The current change requires to be completed with
the addition of the 2 arguments in the
adequate help page.

Additonal minor changes
- typo in scriptforge.pyi
- 'outsideprocess' replaced by 'remoteprocess'

Change-Id: I9b1be123f049aa39bd0d814b6dd63fcc4f4ea310
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174897
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
2024-10-15 11:00:38 +02:00
Jean-Pierre Ledure 74b79b7ac1 scriptforge.pyi - Typo
Change-Id: Ieff7ec790c457b1f4f67544d3f300fc68723d5aa
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174393
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2024-10-02 17:53:55 +02:00
Jean-Pierre Ledure 0419b8c8f9 scriptforge.py Connect via pipe
Python scripts using ScriptForge start like:
   from scriptforge import CreateScriptService, \
           ScriptForge
   ScriptForge(...)		(*)
   sv = CreateScriptService(...)

The (*) statement has next syntaxes: either
   (1)   ScriptForge()
   (2)   ScriptForge(host: str = ..., port: int = ...)
   (3)   ScriptForge(pipe: str = ...)

Syntax (1) is implicit at the first invocation of
CreateScriptService() without a former call to
ScriptForge()

Syntax (2) exists in previous versions.

This commit implements syntax (3) to connect a Python
process to a LO process on the same system via a pipe
mechanism.

The change impacts only Python scripts.

The documentation should be upgraded to include
the new functionality.

Change-Id: I50457b6fffc8c9d6a9ad5c5289de1c363c6680e3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173252
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
2024-09-13 15:04:17 +02:00
Jean-Pierre Ledure 609a6dc2df ScriptForge New IsAlive property
When a document is closed inadvertently
by the user during a macro run, or between
two macros triggered by events, the actual
behaviour is an error message and a stop
of the execution of the macro.

As this can be counter-productive, the macro
may test at any moment if everything is ok
with the
   IsAlive As Boolean (True = OK)
property applied on next service instances:
   Document
   Base
   Calc
   FormDocument
   Writer
   Datasheet
   Dialog

The functionality is available both for
Basic and Python user scripts.

The user documentation should be completed
accordingly.

Change-Id: I0b055dacc06c9da70c611dbb4e7bf841160168fd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172970
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
2024-09-08 14:25:35 +02:00
Jean-Pierre Ledure d2d14c36d1 ScriptForge (Database) DMin, DMax return strings or dates
Python only:

Reset a flag in SF_Database.DMin and DMax methods
to allow dates to be returned.

Review typing hints to accept strings and dates

Integration of remarks from Microsoft/VSCode
about minor syntax issues in scriptforge.pyi
(syntax was accepted by PyCharm).
Now, syntax commonly accepted by both IDE's.

Change-Id: I752d9f1d7a5293222d81748f8fb2e8f46f4317de
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172912
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2024-09-05 15:21:53 +02:00
Jean-Pierre Ledure 8a4ee0fb39 ScriptForge (SFWidgets) new ContextMenu service
Complete a predefined context menu with new items
placed at its bottom.

A context menu is obtained by a right-click
on several areas of a document. Each area has
its own context menu.
Each component model has its own set of context menus.

A context menu is usually predefined at
LibreOffice installation. Customization is done
statically with the Tools + Customize dialog.
The actual new service provides a mean
to make temporary additions at the bottom of a
context menu. Those changes are lost when
the document is closed.

The name of a context menu is the last component
of the resource URL:
   "private:resource/popupmenu/the-name-here"

Context menu items are either usual items or
line separators. Checkboxes or radio buttons
are not supported.
Items run a command or a script when clicked.

The service implements 2 methods:
   AddItem() adds an entry in the menu hierarchy
   Activate() shows or hides the added entries

A context menu can be defined from both Basic
and Python user scripts.

An update of the documentation is required.

Change-Id: Id77f1f2565d75e36c09b13972330d0f83b3f1db4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172355
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2024-08-24 18:29:12 +02:00
Andrea Gelmini 55bf8a21d0 Fix typo
Change-Id: I67c1591af46b530c3cbf46b0871d863a5c0aec24
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164907
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2024-03-16 19:51:03 +01:00
Andrea Gelmini 08750535c5 Fix typo
Change-Id: Ie04b3b3a96b2d4651b6dc477215f29a48c1be4c5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164901
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2024-03-16 19:50:47 +01:00
Andrea Gelmini a0d5d8d165 Fix typo
Change-Id: I1264c4594bbedf7398816552795e33c489ef2863
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164902
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2024-03-16 19:50:27 +01:00
Andrea Gelmini 3764ae10f8 Fix typo
Change-Id: I8c5c281897c53afb456b63c5f3838059bd1887d3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164912
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2024-03-16 19:49:54 +01:00
Andrea Gelmini 42a01a525b Fix typo
Change-Id: Iac27e35e92ec8f481d0d6ba71c87f72e10a99ffb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164910
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2024-03-16 19:49:23 +01:00
Andrea Gelmini 5569de72d7 Fix typo
Change-Id: I07c180c9b659950fa0ecc4bf8ca26f2d133a393c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164913
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2024-03-16 19:48:44 +01:00
Andrea Gelmini da7c50f6f7 Fix typo
Change-Id: I0db6ac0b9edfd6953d668dd0949c692630665a2f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164915
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
2024-03-16 19:47:34 +01:00
Andrea Gelmini 66567a0bcd Fix typo
Change-Id: I3620d218898a91293d57611d4dcf062f75045892
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164897
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Julien Nabet <serval2412@yahoo.fr>
2024-03-16 19:47:17 +01:00
Andrea Gelmini c1215a2e08 Fix typo
Change-Id: I0a68811af1f5b9d32f453592ec357fa694747d35
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164909
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Julien Nabet <serval2412@yahoo.fr>
2024-03-16 19:46:56 +01:00
Andrea Gelmini b360a2b64f Fix typo
Change-Id: Ibb07cca05ef733932326ceb29aa3fd1cd1e969d4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164896
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Julien Nabet <serval2412@yahoo.fr>
2024-03-16 19:46:34 +01:00
Andrea Gelmini 3f9a557813 Fix typo
Change-Id: Id099d4e9471415d572f7eac56e70d20cbae8e577
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164906
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Julien Nabet <serval2412@yahoo.fr>
2024-03-16 19:46:08 +01:00
Andrea Gelmini 7abfe574e2 Fix typo
Change-Id: I42521b965da582e00e4fa9186bb5de3ea3defd4f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164905
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Julien Nabet <serval2412@yahoo.fr>
2024-03-16 19:45:46 +01:00
Andrea Gelmini d7d37ac32c Fix typo
Change-Id: I2e38b46435d927fe4fe8d656c92e7a75a5771ba1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164911
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Julien Nabet <serval2412@yahoo.fr>
2024-03-16 19:45:20 +01:00