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
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
Version numbers are modified from 25.8 to 26.2.
No effect on actual user scripts,
no documentation update.
Change-Id: I19a6711d43a5641cdb8e00ba59fff8285a9e9120
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188912
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
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>
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
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
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
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
The latest version of APSO (1.4.4) introduces
a new positional argument in the
def console():
in apso_utile.py, named 'prettyprint'.
The def is used in
SF_Exception.PythonShell()
The absence of the argument caused
an exception/regression.
The actual patch makes above method compatible
with latest and previous versions of APSO.
No impact on user scripts.
No impact on user documentation.
Change-Id: I0a90112d441bba550b330925742e5021665ecee6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183265
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
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
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
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
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>
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
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
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
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
Hard-coded version numbers are modified
from 25.2 to 25.8.
Many changes in po files due to the alphabetical
sequence of keys after the introduction of the
new "case-sensitive" keys feature.
Before this the dict.Keys() method delivered
the keys as an array in the order of creation.
No effect on actual user scripts.
Change-Id: Iee0c48eca22d17ad892278398c9125912b8b2b3c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180120
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
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>
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>
Introduction of a
ScriptForge.outsideprocess
property: when True the actual mode
is via socket or via pipe.
The property is for internal use only.
Once set it cannot be changed anymore.
Previous statements similar to
if ScriptForge.port > 0:
which returned True when socket mode
are replaced by a broader
if ScriptForge.outsideprocess:
No effect on user scripts.
Change-Id: Ice0efd8c2ab9925511fc8c6889cab714fd208ba1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174874
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
To facilitate the debugging of the
ScriptForge Basic code called by the
python scripts, 2 methods have been
added to the ScriptForge() class:
- initializeRoot(force = False)
Initialize the global scriptforge
data structure.
- When force = False, only when
not yet done.
- When force = True, reinitialize it
whatever its status.
- errorHandling(standard = True)
Determine how errors in the ScriptForge
Basic code are handled. Either
- the standard mode, i.e. display a "crash" message
to the user
- the debugging mode, i.e. the execution stops
on the line causing the error
Example (cfr. tdf#162962)
from scriptforge import CreateScriptService, ScriptForge
sf = ScriptForge()
sf.errorHandling(False)
def testSF():
srv = CreateScriptService("Calc")
g_exportedScripts = (testSF,)
Change-Id: I25d7d8e36e71d95ff8a04191bb8344794886d69e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173458
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
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>
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>
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
Since
https://gerrit.libreoffice.org/c/core/+/172600
a better categorization of properties
has been done between 4 distinct levels.
The SF_Platform and SF_TextStream services
still needed an update to avoid
redundancy on some of their properties.
A choice had to be made, either:
- put them in the serviceproperties dict
- or define them explicitly with @Property
Not both, for clarity.
Change-Id: I787c7e57235622abf5deb5c7fd42c4c28aa82ec8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172863
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Several minor changes
- comments
- 'cls' used where relevant i.o. class name
- dynamic getting/setting properties reviewed
- SF_Platform properties:
set level = 1 i.o. 0 when returned
by PythonHelper module
Change-Id: I4e9877bc16efd340dc14693833c032c998329b6e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172836
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
When considering next python user script:
a = CreateScriptService(...)
a.prop = ...
print(a.prop)
print(a.prop)
so far, the evaluation of a.prop was done
either once or twice depending on
- a parameter of the class a is an instance of
- the read-only status of prop (True/False)
Now the recomputation of the expression
depends on a parameter of prop which can take
one of next values:
0: prop is read-only and not re-evaluated
1: prop is read-only but re-evaluated
f.i. because a user action can change its value
2: prop is editable and not re-evaluated
f.i. because it can be changed only by code
3: prop is editable and always re-evaluated
The change will decrease the number of useless
and more costly recomputations of properties.
Change-Id: I11412a58772147dab2e6b9b06c31477135932603
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172600
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
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
Python typing hints may be stored either
- inside the original .py source file
- in a separate .pyi source file (aka. STUB).
Choice is made to create a new scriptforge.pyi file
- to allow hiding the private functions
- to specialize each module: technical doc
vs. user doc
- to allow potential later translation
- to minimize the impact at run-time:
stubs are active only during code edition.
The new scriptforge.pyi module
- provides the static type checking of all the public
interfaces (methods/properties) of the ScriptForge API.
- when the user uses an IDE like PyCharm or VSCode,
(s)he might benefit from the typing hints provided
by the signatures and docstrings stored
in the module.
Visually, while editing a user script:
- hovering an object instance, a method or a property
displays its detailed description
- a "." after an object instance displays a drop-down
box listing all available interfaces
- brackets after a method-name start code-completion
by displaying its arguments.
Limitations: SF supports ProperCase, lowercase and
camelCase naming for methods and properties.
Only ProperCase is described in scriptforge.pyi.
Extending to the other 2 notations would be easy
but would also overload needlessly the drop-down lists.
The effective code (scriptforge.py) is completed
with a series of importable variable types,
corresponding roughly with the available service
instance names in uppercase. Example
from scriptforge import CALC, RANGE
def userfct(c: CALC, r: RANGE) -> RANGE:
r1: RANGE = "A1:K10"
Objective: enrich the signatures in user scripts
and benefit from the same hints when the variable
types cannot be derived from the context.
The help documentation should be complemented
with the actual additional feature.
Change-Id: I6c39939a3cdbed94828e9449cd691fe15c24c923
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164867
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Transactions are managed by next UNO properties:
XConnection.AutoCommit
XConnection.TransactionIsolation
(They seem very easy to use but, in practice,
are not easy at all)
Usually all transactions are in auto-commit mode,
that means, a commit takes place after each
single SQL command.
Switching auto-commit off means however that
the connection needs to be of type "ISOLATED"
and not of the default type "SHARED".
=> The usual shared connection must be closed.
As a consequence, all rowsets/resultsets linked
to the shared connection need to be closed as well.
=> Additionally the buffers must be emptied (flushed)
to make committed data visible in the Base user
interface.
All above aspects and constraints are managed in the
database.SetTransactionMode(transactionmode)
database.Commit()
database.Rollback()
methods transparently for the user scripts.
The [transactionmode] argument has as value one of
the TransactionIsolation constants.
Without argument, database.SetTransactionMode()
restores the automatic mode.
The manual transaction mode is available for both
Basic and Python scripts.
Its implementation will require an update of the
documentation about the Database service.
Change-Id: I214bd91a1744d6d24609bc5efc987152c6e946c9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159867
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
The
database.GetRows()
dataset.GetRows()
methods return an array of data collected
in a database table or query.
When a column has the type DATE, the transmission
of their values through the Basic-Python bridge
require them to be converted upfront to UNO
DateTime structures.
The later conversion from UNO DateTime to the python
datetime.datetime structure has been added with
this patch.
No impact on Basic scripts.
The documentation does not need to be changed.
Change-Id: I7a6533aff70d2d1402bfc3f057b65a4940148cc4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159348
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
A dataset represents a set of tabular data
stored/produced by a database.
To use datasets, the database instance must exist
but the Base document may not be open.
A Dataset instance is create either with
- the (new) database.CreateDataset() method
- from an existing dataset with the (new)
dataset.CreateDataset() method.
The proposed API supports next main purposes:
- browse for- and backward thru the dataset to get its content
- update any record with new values
- create new records or delete some.
In summary, the AKA "CRUD" operations
(create, read, update, delete).
The originality of the proposed API is the use
of a dense syntax to make insertions and updates
easy and readable:
Example:
(BASIC)
Dim newID As Long
newID = dataset.Insert("LastName", "Doe", "FirstName", "John")
' ... is equivalent to:
Dim dict As Object, newID As Long
Set dict = CreateScriptService("ScriptForge.Dictionary")
dict.Add("LastName", "Doe")
dict.Add("FirstName", "John")
newID = dataset.Insert(dict)
(PYTHON) - next statements are equivalent
newid = dataset.Insert('LastName', 'Doe', 'FirstName', 'John')
newid = dataset.Insert({'LastName': 'Doe', 'FirstName': 'John'})
newid = dataset.Insert(dict(LastName = 'Doe', FirstName = 'John'))
newid = dataset.Insert(LastName = 'Doe', FirstName = 'John')
You will notice that the returned value is the AutoValue primery
key (when it exists) which makes it reuse as a foreign key
immediate.
The API is fully available both in Basic and Python user scripts.
The new service will require its inclusion in the user documentation.
Change-Id: I4f834c4234e5b96ec8fddfffbad791ecf31899df
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159325
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Introduction of new properties and methods:
- StyleFamilies
List of available style families
All document types except Base
- XStyle(family, stylename)
UNO representation of given style
All document types except Base
- Styles(family, [namepattern, used, userdefined,
parentstyle, category)
A list of styles matching the given criteria
All document types except Base
- DeleteStyles(family, styleslist)
Suppress the user-defined styles in the list
All document types except Base and FormDocument
- ImportStylesFromFile(filename, families, overwrite)
Load styles from a closed file
Calc and Writer only
Example: to delete unused styles:
a = doc.Styles("ParagraphStyles", used := False)
doc.DeleteStyles("ParagraphStyles", a)
All functionalities are available from Basic and
Python scripts.
Documentation has to be completed.
Change-Id: I2533c14912257b58feb42bb11ff9d151c7b9531a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157563
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
The XDocumentSettings property returns a
com.sun.star.XXX.DocumentSettings
UNO object.
XXX = sheet, text, drawing or presentation
It gives access to a bunch of UNO internal
properties, specific to the document(s type.
The property is available in Basic and Python
user scripts.
An update of the SF_Document service help
page is required.
Change-Id: I9d6db473c91ac5b1814def9cd100e874aa5490cd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156475
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Incremental changes had made the code in
SF_PythonHelper.xba
scriptforge.py
(which manage the protocol between the Python
user scripts and the ScriptForge services
implemented in Basic) less readable and efficient.
Next features have been reviewed:
- dict instances may be passed as arguments
and returned. Conversions are done on-th-fly.
- dates may be passed as arguments
and returned. Conversions are done on-th-fly.
The lists of hardcoded methods have been removed.
- 2D arrays in standard modules may be passed
as arguments and returned. Conversions are done
on-th-fly. The lists of hardcoded methods have
been removed.
- The hardcoded list of methods requiring a post-
processing has been reduced.
- Methods in standard modules, when not returning
an array, are also executed with CallByName().
- The unused 'localProperties' attribute in Python
services has been removed.
- Flags about arrays in standard modules have been
adapted in
filesystem.Files()
filesystem.SubFolders()
session.UnoMethods()
session.UnoProperties()
string.SplitNotQuoted()
string.Wrap()
ui.Documents()
- The platform.UserData property became a usual
property.
Dictionaries are admitted as arguments and return
values. As a consquence next functions are supported
in Python as well:
session.GetPDFExportOpetions()
session.SetPDFExportOptions()
document, calc, writer.CustomProperties
document, calc, writer.DocumentProperties
These changes require an update of the help pages.
Non-regression tests were run with success. All changes
are transparent for existing scripts.
Change-Id: Iae7a1f5090c590209cd3cb2314c919c44736eba9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155860
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
The UserData property lists the content of the
"User Data" oage of the Options dialog.
The content is returned:
- in Basic: in a SF_Dictionary instance
- in Python: in a dict[] instance.
The list of the available keys is:
city, company, country, email, encryptionkey,
encrypttoself, fax, firstname, homephone,
initials, lastname, officephone, position,
postalcode, signingkey, state, street, title
Many are different from the UNO/priginal values
to make them more user understandable.
This commit will require an update of the SF_Platform
help page.
Both Basic and Python user scripts are supported.
Change-Id: If645579ee9109a1b8180da5a5f3a71979bb5ca59
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155024
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
In the FileSystem service, the
- SubFolders()
- Files()
methods receive an optional argument
IncludeSubfolders (Boolean).
That argument determines whether or not only
the given FolderName is explored or also its subfolders
up to the bottom of the folders structure.
The argument must be used with caution as the number
of returned folders or files may increase rapidly.
anThis could consume excessive process time.
This patch will require an update of the
help page about the filesystem service.
The new argument is available both for Basic and Python
user scripts.
Change-Id: Id2a96cd63cb51f8681f20a203a711b47a636fc3a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154763
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
1. The SF_Document services (document, base, calc,
formdocument, writer) receive a new FileSystem
property that returns the "root" of the
component's file structure under the format:
"vnd.sun.star.tdoc:/XXX"
XXX being the document's identifier.
The implementation does not use the RuntimeUID
(UNO property of the OfficeDocument service) which
is optional and, f.i. not present for Base documents.
Instead the
css.frame.TransientDocumentsDocumentContentFactory
service is used.
2. The SF_FileSystem and SF_TextStream modules have been
reviewed to support the new context.
Next restrictions have been met:
- The FileNaming property is always cnsidered as 'URL'
- CompareFiles() is not applicable
- GetFileLen() always returns zero
- HashFile() is not applicable
- Normalize() always returns the input string unchanged
- PickFile() is not applicable
- PickFolder() is not applicable
Additionally,
- CreatetextFile()
- OpenTextFile() in write or append modes
copy or initialize the file in a temporary storage
and write it back in the document when it is being closed.
The process is transparent for the user.
3. The GetTempName() method accepts an option
Extension
argument, for better convenience.
The new functionalities are available in Basic and Python.
Changes require an update of the help documentation.
Change-Id: Ibf8dd9983656923cf6ab43d9f48398dc4d1e6307
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154443
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Duplicate an existing control of any type
in the actual dialog.
The duplicated control is left unchanged.
The new control can be relocated.
Args:
SourceName: the name of the control to duplicate
ControlName: the name of the new control.
It must not exist yet.
Left, Top: the coordinates of the new control
expressed in "Map AppFont" units.
Returns:
an instance of the SF_DialogControl class or Nothing
The method is available from Basic and Python user scripts
This change will require an update of the SF_Dialog help page.
Change-Id: I5c2a5404a14ad60b2d4df2ac7eabbf0ddd843170
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152333
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Set the tabulation index f a series of controls.
The sequence of controls are given as an array
of control names from the first to the last.
Next controls will not be accessible (anymore ?)
via the TAB key if >=1 of next conditions is met:
- if they are not in the given list
- if their type is FixedLine, GroupBox or ProgressBar
- if the control is disabled
Args:
TabsList: an array of valid control names in the order of tabulation.
Start: the tab index to be assigned to the 1st control in the list. Default = 1.
Increment: the difference between 2 successive tab indexes. Default = 1.
Returns:
True when successful.
The method is available from Basic and Python user scripts
This change will require an update of the SF_Dialog help page.
Change-Id: Ie854227691c4e182b49a521b1285deaa4de3d1ff
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152166
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
A dialog service is returned by next statement
dialog = CreateScriptService("newdialog", dialogname, place)
All properties and methods applicable to predefined
dialogs are available for such new dialogs.
In particular the series of CreateXXX() methods for the addition
of ne dialog controls.
The functionality is available from Basic and Python user
scripts.
An update of the SFDialogs.SF_Dialog help page is required.
A display rendering unstability (flickerings, delays, ..) has
been observed when (all conditions must be met)
- the user script is run from Python
- from inside the LibreOffice process
- the dialog is non-modal
Change-Id: Id3f311cd04497fd79712ce712bdb2724b5caa861
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152071
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
The dialog service hosts now a bunch of methods
to create new controls dynamically in an existing
dialog predefined in the Basic IDE.
In other words, a dialog is initialized with controls
in the Basic IDE. New controls can be added at run-time
before or after the Execute() statement.
All the new methods have in common their first 2 arguments:
ControlName
Place: an (X, Y, Width, Height) array
or a com.sun.star.awt.Rectangle
New methods:
CreateButton(..., toggle, push)
CreateCheckBox(..., multiline)
CreateComboBox(..., border, dropdown, linecount)
CreateCurrencyField(..., border, spinbutton, minvalue,
maxvalue, increment, accuracy)
CreateDateField(..., border, dropdown, mindate, maxdate)
CreateFileControl(..., border)
CreateFixedLine(..., orientation)
CreateFixedText(..., border, multiline, align, verticalalign)
CreateFormattedField(..., border, spinbutton, minvalue,
maxvalue)
CreateGroupBox(...)
CreateImageControl(..., border, scale)
CreateListBox(..., border, dropdown, linecount, multiselect)
CreateNumericField(..., border, spinbutton, minvalue,
maxvalue, increment, accuracy)
CreatePatternField(..., border, editmask, literalmask)
CreateProgressBar(..., border, minvalue, maxvalue)
CreateRadioButton(..., multiline)
CreateScrollBar(..., orientation, border, minvalue, maxvalue)
CreateTableControl(..., border, rowheaders, columnheaders,
scrollbars, gridlines)
CreateTextField(..., border, multiline, maximumlength,
passwordcharacter)
CreateTimeField(..., border, mintime, maxtime)
CreateTreeControl(..., border)
All the methods return a SF_DialogControl instance.
The arguments have bben chosen based on functionality
rather than on layout. After the creatio of the control,
most properties and methods relevant to SF_DialogControl
objects are applicable. Also the XControlModel property
might contribute to layout refinements.
Other changes:
- The SF_DialogControl class receives next updatable
properties: Border and TabIndex
- The dialogcontrol.SetTableData() receives an
additional argument: rowheaderwidth
- The dialogcontrol.Resize() method without arguments
resizes the control to its "preferred size", a size
adjusted depending on its actual content
All the new functionalities are callable from both
Basic and Python user scripts.
Described changes will require a serios review of the
Dialog and DialogControl help pages.
Change-Id: I654eeae5456527bf14b1f4b43f04d176bbd830b6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151896
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins