While developing a new version of
ScriptForgeHelper.py
the dev should be sure to invoke the new version
instead of the standard version shipped with its
LO release.
This can be done now by setting
- in Python a specific ScriptForge class property
ScriptForge.pythonhelpermodule2 = 'user#QA/ScriptForgeHelper.py'
- in Basic a specific property of the root class
_SF_.PythonHelper2 = "QA/ScriptForgeHelper.py"
both in the test script
Testing a new version of scriptforge.py can be configured
entirely from the test script by inserting next statements
import sys
sys.path.reverse()
sys.path.append('/home/jean-pierre/.config/libreoffice/4/user/Scripts/python/QA')
sys.path.reverse()
Change-Id: Iab6db518932e9dde9030b7e5bbe00a50dee31840
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118171
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
The SF_Platform.Printers property returns the list of
available printers as a zero-based array.
The default printer is put in the 1st position of the
list (index = [0]).
The property is available in Basic and Python.
Change-Id: I3f02b1b5e37aa9866491d9285683fc45d17fb664
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117776
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Syntax of CreateBaseDocument() becomes
FileName, [EmbeddedDatabase=HSQLDB|FIREBIRD|CALC],
[RegistrationName=""], [CalcFileName]
Only when EmbedddedDatabase = "CALC", the new argument CalcFileName
represents the file containing the tables as Calc sheets.
The file must exist or an error is raised.
Example:
Dim myBase As Object, myCalcBase As Object
Set myBase = ui.CreateBaseDocument("C:\Databases\MyBaseFile.odb", "FIREBIRD")
Set myCalcBase = ui.CreateBaseDocument("C:\Databases\MyCalcBaseFile.odb", _
"CALC", , "C:\Databases\MyCalcFile.ods")
Both Basic and Python are supported.
Change-Id: I9912b110dcec12fe451a47abb61ab143fb543b94
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117665
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
For Python scripts only:
the CreateScriptService() method accepts now both positional
(as before) and keyword arguments.
The impacted services are:
- database
- dialog
- document
- base
- calc
Done with the ReviewServiceArgs() class method that returns the
input arguments as a tuple in the correct sequence. This method
is inserted in each of the impacted service definitions.
Change-Id: I545ca5ef0a4e7946d598eed07a2122885e4f864a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117387
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Addition to the Basic service for Python scripts
of 2 Basic builtin objects:
- ThisComponent
returning the current component
- ThisDatabaseDocument
returning the main Base component when a subcomponent is active
Both are implemented as properties of SF_Basic.
The behaviour can be slightly different versus native Basic when
the Basic IDE is involved. Read comments in code.
Change-Id: I5d59b0ae0bae026f9b7e4c1d7068e84958aab56d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116674
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
The CDate() method replicates in Python the behavior of the Basic
builtin function with the same name, except that it returns
its unique input argument when it could not be recognized as
a valid date, while Basic raises an DataType error.
The method is introduced to make it easy to Python devs to
convert numbers stored in Calc cells and representing dates
to their corresponding datetime.datetime instance.
Change-Id: Ifd8fbd4bf7a97bf6b91cf481c09d75ec14159916
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115989
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Previous behavior:
After a PythonShell() statement that opened the APSO shell console,
subsequent print() statements executed in the same macro
run were not displayed in the console.
They were only from a next macro run.
Solution:
Force a brief suspension of the Python process by inserting
a call to a Basic routine (IPC) immediately after the launch
of the shell console.
Result: The redirection of STDOUT and STDERR happens normally inside
the APSO code, as expected.
Change-Id: Ifbf267a898d45a97c346f0f3ea824edd4e6045ff
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115930
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
CreateScriptService() does not accept keyword arguments.
In Basic positional arguments may be skipped, not in Python.
This makes
CreateScriptSevice('Dialog', '', '', 'myDialog')
rather inelegant.
Only for the Dialog service, None is accepted as default value
i.o. '' for the Container and Library arguments.
Change-Id: Ib96e23373140264c7100f174c7704ed32351f124
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115629
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
In the SFDialogs.SF_Dialog class:
- Fix the comments describing the behaviour of non-modal dialogs
- Add the OKBUTTON and CANCELBUTTON definitions
Change-Id: I2d3abc1c610b0c60949987feb1a9d66e21abfdc1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115152
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Strings in CSV file recognized as dates are passed via
their ISO format, not in the default com.sun.star.util.DateTime
format. This required a fix in Basic ImportFromCSVFile().
Errors in user scripts can be announced to users from Python
with the same interface as from Basic: SF_Exception.RaiseFatal().
Error messages become translatable.
Used by SF_Exception.PythonShell(), display of APSO console,
when the APSO extension is not present.
Addition of the PYTHONSHELL error message in the po files.
Review of typos.
Change-Id: I52a19faa3773904bd37505fee780d517436485f2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115032
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
In replacement of the ISO format, to avoid any
misinterpretation of strings containing accidentally
a date,
from now on, dates are exchanged between Basic and Python
as com.sun.star.util.DateTime structures.
The year boundaries are [1900 - 9999].
The code managing the Python-Basic protocol has been changed
on both sides.
The Basic service receives the
- CDateFromUnoDateTime()
- CDateToUnoDateTime()
methods, equivalent with their Basic homonyms.
Change-Id: Ib6ded20c24ff71d3349d242f72bd7b88f69a2661
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114815
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
The PythonShell() method invokes the console() method
of the APSO extension.
It accepts 1 argument, which is a dictionary of variables
that the user wants transferred to the console to become part
of the Python context there.
Typical usage:
exc.PythonShell( {**globals(), **locals()} )
Subsequent print() statements executed in the user script
are displayed in the console.
An (untranslated - english) error message is raised when
the APSO extension is not installed.
Change-Id: I1b620bc041e1293234ddfd789e0ce8892dc87169
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114561
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
A number of methods were defined implicitly as
instance methods.
Where apropriate they are replaced by class methods:
- insertion of the @classmethod decorator
- self replaced with cls
1 line in SF_PythonHelper.xba uncommented:
it was so far commented in for debugging
Change-Id: Ie8c3dd740f0129511295877ef947b1db35475c48
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114440
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
New classes to manage Basic dialogs and their controls from
Python.
The use of UNO interfaces has been reviewed in Basic:
replacement of
CreateUnoDialog()
by
XDialogProvider.createDialog()
The latter allows to run dialogs in non-modal mode.
SF_UI.ShowProgressBar() and SF_Console() have been reviewed
to incorporate the XSCRIPTCONTEXT shipped with Python
Now the console and the progress bar are able to run
in non-modal mode.
Change-Id: I49b09aa41ee6f50e6d205f44fc329f91bce76beb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114296
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
New class to run from Python DDL + DML SQL commands
on databases embedded in or connected to Base documents.
GetRows() is hardcoded as an exception (cfr. bug #138155) in
_PythonDispatcher() - SF_PythonHelper.xba
to be able to return 2D arrays to Python.
Fix returned empty arrays in the Basic-Python engine:
the standard bridge ignores them and returns a null byte
sequence instead of an empty tuple.
Change-Id: I336ea0b585b759b998af0871d25bfd384a2e66ae
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113953
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
New class to manage controls in forms and subforms
from Python, essentially thru the use of Properties
Required a review of SF_FormControl.Getproperty()
Indeed, the IDE debugger computes all the properties
of a Basic object when expanded in the watch window.
This can cause errors.
This class makes use of default values for properties
when irrelevant for the actual control type
Error were detected on date/time conversions of date/timefield
controls and corrected.
SF_String etc shortcuts have been removed (see previous commit)
because not applicable in every scenario.
The only entry point to the API from a user Python script
is via CreateScriptService().
Change-Id: Ia87c7281c3fcf39ab0c3528f00114c9b1e067bcf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113920
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Completion of the SFDocuments.SF_Base
and addition of the SFDocuments.SF_Form classes
Config of properties and methods
Some methods require an hardcoded processing in
_PythonDispatcher() - SF_PythonHelper.xba
because they potentially may return arrays (cfr. bug #138155)
Addition of SF_String etc shortcuts in Python
for compatibility with Basic
Change-Id: Id9852c214618e863b2fdf60aa5f80e36b3547a36
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113739
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
To make the access to services more close to Python habits
and to better attract Basic users to Python, the convention
for attributes naming has been defined as:
- property names may be ProperCased, camelCased or lowercased
- method names may be ProperCased, camelCased or lowercased
Their arguments are always lowercased
In documentation examples, the camelCased notation will be privileged
Synonyms for properties and methods are computed
with a generic function: SCriptForge.SetAttributeSynonyms()
The generic getter and setter have been reviewed accordingly.
Method synonyms are NOT HARDCODED anymore.
Change-Id: I528820fe195d6b67e02035e589deee2b61c056ba
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113666
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Changes in the Basic-Python engine:
- arguments of methods may be 2D arrays
- 1st argument of method may be a Basic object
- properties starting with 'X' may contain UNO objects
- GetProperty may contain 1 argument
Calc class is a subclass of the Document class in Python
(in Basic it is simulated)
A CalcReference class is also created to contain
Range and Sheet objects
Many comments have been reviewed for consistency in SF_Calc,
SF_Form and SF_FormControl.xba
Conversion to DataArrays is improved to process input
arrays of arrays. Date conversions are supported.
Change-Id: Id6254d668ec981b00555e7e277c4d31982c00092
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113568
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Full support of the session class methods from Python
The InvokeSimpleScript() python method has been
extended to support broader scopes (extensions and user documents)
and ParamArray arguments in Basic.
Indeed the SF_Session.ExecuteBasicScript() and
SF_Session.ExecuteCalcFunction() require a varying number
of arguments.
No regression found in unit tests
Change-Id: I0899bc6535b00340ed82b46336d60a7bb23b2098
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113154
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Only a subset of the available methods is implemented:
HashStr, IsADate, IsEmail, IsFileName, IsIBAN,
IsIPv4, IsLike, IsSheetName, IsUrl,
SplitNotQuoted, Wrap
The other methods are better replaced by Python builtin
functions.
The flgDateArg flag has been introduced to distinguish
a date argument passed as a string that does not require
conversion from a date passed in iso-format that
requires a conversion to a Basic variable of type Date
Change-Id: I80f7e816dfeaee793862f3c3d35488da7c573c8f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113002
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
The signatures of standard Basic built-in functions were
derived from the Help documentation.
They appeared to be inexact.
They now comply with
core/basic/source/runtime/stdobj.cxx
Change-Id: I343fb553f5fad5236d75f6b72910714d47b6a289
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112669
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
The SF_Array (Basic) class is highly redundant with the
Python tuple/list classes.
Hence only 1 method is implemented in Python:
ImportFromCSVFile()
to have the same csv files imported identically
in both environments.
The returned value is a tuple of tuples.
Restriction: dates are recognized but converted to their ISO format.
Up to the user to interpret them correctly.
Change-Id: I6611964a8083a9d7c6f9622b2aef64fe8b1491ea
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112585
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
The SF_Exception class is not intended to replace or complement
the builtin Python exception handling.
Hence it implements only a subset of the corresponding
Basic service.
- no properties: they are fully related to Basic error trapping
- next methods are available: Console, ConsoleClear, ConsoleToFile,
DebugPrint and RaiseFatal (reserved for internal use)
Restriction: Console() does not work in non-modal mode.
DebugPrint formats its messages by using the repr() builtin method.
DebugPrint outputs from Basic or from Python are mixed within
the same console.
The other methods call their Basic counterpart.
A new method has been added both in Python and Basic: DebugDisplay
It combines DebugPrint with a display in a message box of the
arguments.
Change-Id: Iba94ab951b95b409c881ac17560476d6e9bc2fc2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112570
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
To make the access to services more close to Python habits
and to better attract Basic users to Python, the convention
for attributes naming has been enhanced:
- property names may be ProperCased, camelCased or lowercased
- method names may be ProperCased, camelCased or lowercased
Their arguments are always lowercased
In documentation examples, the camelCased notation will be privileged
Synonyms for properties are managed with generic functions.
The generic getter and setter has been reviewed accordingly.
Method synonyms are hardcoded.
The management of synonyms for servicenames have also been
reviewed to be defined in each class i.o. centrally and hardcoded
in CreateScriptService()
Change-Id: Id8d3181118b1e61937e2412109bd0d1eedd6f5e6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112470
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Addition of SF_Platform class
Most properties are provided by a direct call to
ScriptForgeHelper.py
Others result from an interaction with the Basic-Python machinery
Addition of STarDesktop() method in the SF_Basic class
Change-Id: If1c03fe8e0ad36b6a665c8c44b477eca7cbc24bc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112393
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Addition of SF_FileSystem and SF_TextStream classes
Machinery tuning:
- freeze a predefined list of standard modules
in the python persistent storage
- error management reviewed to mimic Basic behaviour on wrong
arguments
Standard modules are predefined in scriptforge.py as well
Both lists must be synchronized on a hardcoded entry number
Basic has minor revisions:
- complex boolean expressions return -1 and 0 to Python
i.o. True and False => Add a CBool() function
- [User]TemplatesFolder properties of FileSystem omitted the final "/"
Change-Id: Ice138de956f5f87269557cdb3db023849081b99d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112199
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Python scripts can now invoke usual Basic builtin functions
Example:
from ScriptForge import CreateScriptService
bas = CreateScriptService('Basic')
bas.MsgBox('This is the text to be displayed', bas.MB_ICONEXCLAMATION)
Python scripts can use most ScriptForge services written in Basic
Example:
from scriptforge import CreateScriptService
FSO = CreateScriptService('FileSystem')
a = FSO.BuildPath('/tmp', 'xyz')
Syntax and semantic are as close as possible to the Basic syntax
Implemented are a SFServices class and its subclasses representing each
a ScriptForge service and where the interfaces are defined (properties,
methods and arguments)
Their execution goes through the "machinery", i.e. a set of python
and basic routines that manage the call from the python process to
the appropriate service in an as much agnostic and generic way
Only a limited set of services are implemented so far: SF_FileSystem
(partially) and SF_Timer: they served as prototypes and initial tests
Change-Id: I0b383b59359c12710e7165139e498cca5a7856bb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111971
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>