1) Error handling in the ExecuteCalcFunction()
function must be conditioned by the global
error handling.
True; display a user-friendly message
False: abort on the erroneous line
So far, an ambiguous error message was displayed
in both cases.
2) Above ambiguous error message was corrupted
by the detour to SF_Array.Prepend() method
in exc.RaiseFatal() and exc.RaiseAbort().
A simple workaround fixes the ambiguity
about the name of the faulty routine.
Change-Id: Iab38b48e6291e1960fc288696a7ebd18ffe8ebae
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175020
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
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>
Reference:
https://bugs.documentfoundation.org/show_bug.cgi?id=163219#c7
Everywhere the With block variable is defined
or redefined inside the With block, the Basic
code has been reviewed.
Found in
SFDatabases/SF_Database.xba/SetTransactionMode()
SFDocuments/SF_Document.xba/Styles()
ScriptForge/SF_Dictionary.xba/ImportFromPropertyValues()
ScriptForge/SF_UI.xba/SetStatusBar()
ScriptForge/SF_UI.xba/ShowProgressBar()
Most changes consist in isolating the With block
variable before the With block itself.
No functional change.
This solution is a workaround for the bug.
IT DOES NOT SOLVE THE ROOT CAUSE.
Change-Id: I48af29d3d9c8b1e36ef5a85c8cfe28f9639ae483
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174560
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
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>
To enhance the compatibility between
- sf dictionaries
- python dicts
- arrays of PropertyValues
it was necessary to propose the support
of case-sensitive keys, i.e. keys are
different if a case-sensitive comparison
finds them different.
So far only not case-sensitive keys
were supported.
This required a re-visit of the implementation
of the ScriptForge.SF_Dictionary service. So far
it was built upon a Basic Collection class which
differentiates keys not case-sensitively. The
new implementation uses sorted arrays.
The invocation of the service is now:
dict = CreateScriptService("Dictionary", True/False)
True means case-sensitive keys.
Default = False, which preserves the compatibility
with the past.
ScriptForge uses dictionaries internally in
several places. For each of them it has been
assessed if the new attribute was justified
or not. For most of the contexts, it was.
The functionality makes sense only for Basic
user scripts.
The documentation of the Dictionary page
should be revised according to the new invocation
syntax.
Change-Id: If1f695bcbf1673a2b71c1e41487b1781caab71c2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173044
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>
All arguments passed to ScriptForge methods
are checked for validity.
A.o. a string may be compared with a closed
list of allowed values.
The comparison may now optionally be made
with a
CaseSentitive As Boolean
parameter.
All occurrences where this check makes sense
were identified, inventoried and modified.
A True argument has been inserted where
appropriate.
Change-Id: I1a5cb7fb42618bc83fc8ec57c2727fc2a1bfcdb9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172530
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
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
SF_Array.Sort() of an empty array
returned prevously an "Index out of range"
error message.
From now on it returns correctly an empty array.
Change-Id: I7869a267c1ae160611fffd51838447d0f1539ac3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171866
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Many methods will require a "TextRange" as argument.
A textrange is a shortcut describing the scope
on which to apply the method.
Such a textrange corresponds either with a single
insertion point or with a (text) interval between
2 insertion points.
Multiple textranges are not supported in this context.
TextRange = a string containing one of next variants :
(names may be surrounded with single or double quotes)
"~" or "SELECTION" or "SEL" = current selection
(if multiple selections, its 1st component)
"BODY" = the main text of the actual document instance
"FRAME!name" = the text contained in a text frame
"BOOKMARK!name" = the given bookmark,
may be zero or more characters long
"FIELD!name" = a user text field
"SECTION!name" = the text contained in a section
"TABLE!name!cellrange" = a cell (cellrange = "B3")
"WORD+n" = n words after the current selection
"SENTENCE-n" = n sentences before the current selection
"PARAGRAPH" or "§" = the paragraph containing
the current selection (+0 is the default)
optionally combined with next control character:
"|": start or end of string
E.g.
"|~" = the point immediately before the current visible
selection (starting point)
"~|" = the point immediately after the current visible
selection (ending point)
"~", "|~|" = the full visible selection
Implemented properties in this commit:
Bookmarks
CurrentSelection
Fields
Frames
(More will follow)
Example: doc.CurrentSelection = "SECTION!sect01|"
=> the visible cursor is set at the end
of the given section
Change-Id: Ib2a2110e25b0a15cd95c782f6ba8b0db1052bf39
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171832
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
In Basic, any
On Error ...
statement resets the Err, Erl, Error$ system variables.
Most ScriptForge public interfaces contain such
a statement.
To enhance error handling in user scripts, the usual
interfaces expected in error handling routines
start (before the On Error statement) with the
capture of the actual system error status.
The concerned interfaces are:
- all methods in the Exception service
- the CreateScriptService() method to create
the Exception service
The functionality is particularly useful
to manage user script errors in events.
Only Basic scripts are concerned.
Change-Id: I602311ceedcafddd46481bdd9cc20d9946db3186
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171649
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Tests with non-modal dialogs and sleeping (time.sleep)
Python processes show a more fluid reactivity
when a
Wait 0
statement is inserted before returning to Python,
and this at a minimal cost.
Change-Id: I6d69d0e8f2970c7e4bf440fdfa11f2ad7593ac15
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171599
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
The RunApplication() method uses
- either the Shell() Basic built-in function
(only in asynchronous mode)
- or the com.sun.star.system.SystemShellExecute()
service
in this order.
The second is tried in case of failure of the first one.
Benefits:
- the method can start batch files or scripts
- broader than Shell(): giving a user file as argument
opens its application first based on the file suffix
- more robust error handling
Read discussion in tdf#160222.
This change could require a light revisit of the
sf_session help page.
Change-Id: I1fb4717db4b971bd62885ad0e38b7c08a8e6f434
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165218
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins