wizards/source/scriptforge/python/scriptforge.py | 16 +++++++++------- wizards/source/scriptforge/python/scriptforge.pyi | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 10 deletions(-)
New commits: commit 0f74a4c2bf156f38e188e0a4271ba37cf688181d Author: Jean-Pierre Ledure <j...@ledure.be> AuthorDate: Mon Oct 14 13:31:20 2024 +0200 Commit: Jean-Pierre Ledure <j...@ledure.be> CommitDate: Tue Oct 15 11:00:38 2024 +0200 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 <j...@ledure.be> diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py index 0c96645df721..05a7fa557e74 100644 --- a/wizards/source/scriptforge/python/scriptforge.py +++ b/wizards/source/scriptforge/python/scriptforge.py @@ -108,7 +108,7 @@ class ScriptForge(object, metaclass = _Singleton): hostname = '' port = 0 pipe = '' - outsideprocess = False + remoteprocess = False componentcontext = None # com.sun.star.uno.XComponentContext scriptprovider = None # com.sun.star.script.provider.XScriptProvider @@ -163,7 +163,7 @@ class ScriptForge(object, metaclass = _Singleton): # Determine main pyuno entry points ScriptForge.componentcontext = self.ConnectToLOProcess(hostname, port, pipe) # com.sun.star.uno.XComponentContext - ScriptForge.outsideprocess = (port > 0 and len(hostname) > 0) or len(pipe) > 0 + ScriptForge.remoteprocess = (port > 0 and len(hostname) > 0) or len(pipe) > 0 ScriptForge.scriptprovider = self.ScriptProvider(ScriptForge.componentcontext) # ...script.provider.XScriptProvider # # Establish a list of the available services as a dictionary (servicename, serviceclass) @@ -1101,12 +1101,14 @@ class SFScriptForge: return self.ExecMethod(self.vbMethod, 'DebugPrint', param) @classmethod - def PythonShell(cls, variables = None): + def PythonShell(cls, variables = None, background = 0xFDF6E3, foreground = 0x657B83): """ Open an APSO python shell window - Thanks to its authors Hanya/Tsutomu Uchino/Hubert Lambert :param variables: Typical use PythonShell.({**globals(), **locals()}) to push the global and local dictionaries to the shell window + :param background: background color as an int + :param foreground: foreground color as an int """ if variables is None: variables = locals() @@ -1117,7 +1119,7 @@ class SFScriptForge: if len(ext.getPackageLocation(apso)) > 0: # APSO is available. However, PythonShell() is ignored in bridge mode # because APSO library is not in pythonpath - if ScriptForge.outsideprocess: + if ScriptForge.remoteprocess: return None # Directly derived from apso.oxt|python|scripts|tools.py$console # we need to load apso before import statement @@ -1126,7 +1128,7 @@ class SFScriptForge: from apso_utils import console kwargs = {'loc': variables} kwargs['loc'].setdefault('XSCRIPTCONTEXT', uno) - console(**kwargs) + console(BACKGROUND = background, FOREGROUND = foreground, **kwargs) # An interprocess call is necessary to allow a redirection of STDOUT and STDERR by APSO # Choice is a minimalist call to a Basic routine: no arguments, a few lines of code SFScriptForge.SF_Basic.GetGuiType() @@ -2197,7 +2199,7 @@ class SFDialogs: Transform positional and keyword arguments into positional only Add the XComponentContext as last argument """ - if ScriptForge.outsideprocess: + if ScriptForge.remoteprocess: return dialogname, place, ScriptForge.componentcontext else: return dialogname, place @@ -2369,7 +2371,7 @@ class SFDocuments: doctype = self.DocumentType if doctype in ('Calc', 'Writer', 'FormDocument', 'Draw', 'Impress'): # XStyles() DOES NOT WORK in bridged mode ?!? Works normally in direct mode. - if ScriptForge.outsideprocess: + if ScriptForge.remoteprocess: return None return self.ExecMethod(self.vbMethod + self.flgUno, 'XStyle', family, stylename) raise RuntimeError('The \'XStyle\' method is not applicable to {0} documents'.format(doctype)) diff --git a/wizards/source/scriptforge/python/scriptforge.pyi b/wizards/source/scriptforge/python/scriptforge.pyi index 0e5387a639ce..1685b3f7c155 100644 --- a/wizards/source/scriptforge/python/scriptforge.pyi +++ b/wizards/source/scriptforge/python/scriptforge.pyi @@ -837,7 +837,10 @@ class SFScriptForge: ... @classmethod - def PythonShell(cls, variables: dict = ...) -> None: + def PythonShell(cls, variables: dict = ..., + background: int = ..., + foreground: int = ... + ) -> None: """ Opens an APSO Python shell as a non-modal window. The Python script keeps running after the shell is opened. @@ -847,7 +850,13 @@ class SFScriptForge: passed on to the APSO Python shell. By default, all local variables are passed using Python's builtin ``locals()`` function. - Typical use: ``{**globals(), **locals()}`` + ``background``: the background color of the window as an integer value. Usually given + as a hexadecimal value, like 0xFFFFFF, or as the output of the ``basic.RGB()`` method. + + ``foreground``: the foreground color of the window as an integer value. + Note + Typical use + ``exc.PythonShell({**globals(), **locals()}, background = 0x0, foregound = 0xFFFFFF)`` """ ... @@ -5788,7 +5797,7 @@ class SFDocuments: def RemoveDuplicates(self, range: RANGE, - columns: Union[int | Sequence[int]], + columns: Union[int, Sequence[int]], header: bool = ..., casesensitive: bool = ..., mode: Literal["CLEAR", "COMPACT"] = ...,