[Libreoffice-commits] core.git: wizards/source
Jean-Pierre Ledure (via logerrit)
logerrit at kemper.freedesktop.org
Fri Jun 4 08:22:32 UTC 2021
wizards/source/scriptforge/python/scriptforge.py | 52 +++++++++++++++++++++++
1 file changed, 52 insertions(+)
New commits:
commit 0dd002a5f1d8c67792dbbc788d3c888d8c000d6c
Author: Jean-Pierre Ledure <jp at ledure.be>
AuthorDate: Thu Jun 3 17:19:16 2021 +0200
Commit: Jean-Pierre Ledure <jp at ledure.be>
CommitDate: Fri Jun 4 10:21:54 2021 +0200
ScriptForge - (scriptforge.py) ThisComponent, ThisDatabaseDocument
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 at ledure.be>
Reviewed-by: Jean-Pierre Ledure <jp at ledure.be>
diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py
index c545fc5491c2..ef6c0d309c6e 100644
--- a/wizards/source/scriptforge/python/scriptforge.py
+++ b/wizards/source/scriptforge/python/scriptforge.py
@@ -784,6 +784,58 @@ class SFScriptForge:
return desktop
starDesktop, stardesktop = StarDesktop, StarDesktop
+ @property
+ def ThisComponent(self):
+ """
+ When the current component is the Basic IDE, the ThisComponent object returns
+ in Basic the component owning the currently run user script.
+ Above behaviour cannot be reproduced in Python.
+ :return: the current component or None when not a document
+ """
+ comp = self.StarDesktop.getCurrentComponent()
+ if comp is None:
+ return None
+ impl = comp.ImplementationName
+ if impl in ('com.sun.star.comp.basic.BasicIDE', 'com.sun.star.comp.sfx2.BackingComp'):
+ return None # None when Basic IDE or welcome screen
+ return comp
+ thisComponent, thiscomponent = ThisComponent, ThisComponent
+
+ @property
+ def ThisDatabaseDocument(self):
+ """
+ When the current component is the Basic IDE, the ThisDatabaseDocument object returns
+ in Basic the database owning the currently run user script.
+ Above behaviour cannot be reproduced in Python.
+ :return: the current Base (main) component or None when not a Base document or one of its subcomponents
+ """
+ comp = self.ThisComponent # Get the current component
+ if comp is None:
+ return None
+ #
+ sess = CreateScriptService('Session')
+ impl, ident = '', ''
+ if sess.HasUnoProperty(comp, 'ImplementationName'):
+ impl = comp.ImplementationName
+ if sess.HasUnoProperty(comp, 'Identifier'):
+ ident = comp.Identifier
+ #
+ targetimpl = 'com.sun.star.comp.dba.ODatabaseDocument'
+ if impl == targetimpl: # The current component is the main Base window
+ return comp
+ # Identify resp. form, table/query, table/query in edit mode, report, relations diagram
+ if impl == 'SwXTextDocument' and ident == 'com.sun.star.sdb.FormDesign' \
+ or impl == 'org.openoffice.comp.dbu.ODatasourceBrowser' \
+ or impl in ('org.openoffice.comp.dbu.OTableDesign', 'org.openoffice.comp.dbu.OQuertDesign') \
+ or impl == 'SwXTextDocument' and ident == 'com.sun.star.sdb.TextReportDesign' \
+ or impl == 'org.openoffice.comp.dbu.ORelationDesign':
+ db = comp.ScriptContainer
+ if sess.HasUnoProperty(db, 'ImplementationName'):
+ if db.ImplementationName == targetimpl:
+ return db
+ return None
+ thisDatabaseDocument, thisdatabasedocument = ThisDatabaseDocument, ThisDatabaseDocument
+
@classmethod
def Xray(cls, unoobject = None):
return cls.SIMPLEEXEC('XrayTool._main.xray', unoobject)
More information about the Libreoffice-commits
mailing list