[Libreoffice-commits] core.git: wizards/source
Jean-Pierre Ledure (via logerrit)
logerrit at kemper.freedesktop.org
Fri Jun 25 10:01:38 UTC 2021
wizards/source/scriptforge/SF_Platform.xba | 62 ++++++++++++++++++++---
wizards/source/scriptforge/SF_Root.xba | 2
wizards/source/scriptforge/SF_Utils.xba | 5 +
wizards/source/scriptforge/python/scriptforge.py | 7 ++
4 files changed, 69 insertions(+), 7 deletions(-)
New commits:
commit 28c3228cf81f4cd29ed5a26a944796197298d1ec
Author: Jean-Pierre Ledure <jp at ledure.be>
AuthorDate: Thu Jun 24 13:10:30 2021 +0200
Commit: Jean-Pierre Ledure <jp at ledure.be>
CommitDate: Fri Jun 25 12:00:57 2021 +0200
ScriptForge - (SF_Platform) new Printers property
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 at ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp at ledure.be>
diff --git a/wizards/source/scriptforge/SF_Platform.xba b/wizards/source/scriptforge/SF_Platform.xba
index 919a8901641d..5c2970823d05 100644
--- a/wizards/source/scriptforge/SF_Platform.xba
+++ b/wizards/source/scriptforge/SF_Platform.xba
@@ -95,12 +95,6 @@ Property Get ObjectType As String
ObjectType = "SF_Platform"
End Property ' ScriptForge.SF_Platform.ObjectType
-REM -----------------------------------------------------------------------------
-Property Get ServiceName As String
-''' Internal use
- ServiceName = "ScriptForge.Platform"
-End Property ' ScriptForge.SF_Platform.ServiceName
-
REM -----------------------------------------------------------------------------
Property Get OfficeVersion() As String
''' Returns the office software version in the form 'LibreOffice w.x.y.z (The Document Foundation)'
@@ -141,6 +135,15 @@ Property Get OSVersion() As String
OSVersion = _PropertyGet("OSVersion")
End Property ' ScriptForge.SF_Platform.OSVersion (get)
+REM -----------------------------------------------------------------------------
+Property Get Printers() As Variant
+''' Returns the list of available printers type as a zero-based array
+''' The default printer is put in the 1st position in the list (index = 0)
+''' Example:
+''' MsgBox join(platform.Printers, ",")
+ Printers = _PropertyGet("Printers")
+End Property ' ScriptForge.SF_Platform.Printers (get)
+
REM -----------------------------------------------------------------------------
Property Get Processor() As String
''' Returns the (real) processor name, e.g. 'amdk6'. Might return the same value as Machine
@@ -157,6 +160,12 @@ Property Get PythonVersion() As String
PythonVersion = _PropertyGet("PythonVersion")
End Property ' ScriptForge.SF_Platform.PythonVersion (get)
+REM -----------------------------------------------------------------------------
+Property Get ServiceName As String
+''' Internal use
+ ServiceName = "ScriptForge.Platform"
+End Property ' ScriptForge.SF_Platform.ServiceName
+
REM ===================================================================== METHODS
REM -----------------------------------------------------------------------------
@@ -216,6 +225,7 @@ Public Function Properties() As Variant
, "OSPlatform" _
, "OSRelease" _
, "OSVersion" _
+ , "Printers" _
, "Processor" _
, "PythonVersion" _
)
@@ -224,6 +234,43 @@ End Function ' ScriptForge.SF_Platform.Properties
REM =========================================================== PRIVATE FUNCTIONS
+REM -----------------------------------------------------------------------------
+Public Function _GetPrinters() as Variant
+''' Returns the list of available printers.
+''' The default printer is put in the 1st position (index = 0)
+
+Dim oPrinterServer As Object ' com.sun.star.awt.PrinterServer
+Dim vPrinters As Variant ' Array of printer names
+Dim sDefaultPrinter As String ' The default printer
+Dim lDefault As Long ' Initial position of the default printer in the list
+
+ On Local Error GoTo Catch ' Prevent any error
+ vPrinters = Array()
+
+Try:
+ ' Find printers
+ Set oPrinterServer = SF_Utils._GetUNOService("PrinterServer")
+ With oPrinterServer
+ vPrinters = .getPrinterNames()
+ sDefaultPrinter = .getDefaultPrinterName()
+ End With
+
+ ' Put the default printer on top of the list
+ If Len(sDefaultPrinter) > 0 Then
+ lDefault = SF_Array.IndexOf(vPrinters, sDefaultPrinter, CaseSensitive := True)
+ If lDefault > 0 Then ' Invert 2 printers
+ vPrinters(lDefault) = vPrinters(0)
+ vPrinters(0) = sDefaultPrinter
+ End If
+ End If
+
+Finally:
+ _GetPrinters() = vPrinters()
+ Exit Function
+Catch:
+ GoTo Finally
+End Function ' ScriptForge.SF_Platform._GetPrinters
+
REM -----------------------------------------------------------------------------
Public Function _GetProductName() as String
''' Returns Office product and version numbers found in configuration registry
@@ -260,6 +307,7 @@ Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant
Dim sOSName As String ' Operating system
Dim oLocale As Object ' com.sun.star.lang.Locale
+Dim oPrinterServer As Object ' com.sun.star.awt.PrinterServer
Const cstPyHelper = "$" & "_SF_Platform"
Dim cstThisSub As String
@@ -293,6 +341,8 @@ Const cstSubArgs = ""
End Select
EndIf
_PropertyGet = sOSName
+ Case "Printers"
+ _PropertyGet = _GetPrinters()
Case Else
_PropertyGet = Null
End Select
diff --git a/wizards/source/scriptforge/SF_Root.xba b/wizards/source/scriptforge/SF_Root.xba
index f553ab5f5889..6e89920a3c34 100644
--- a/wizards/source/scriptforge/SF_Root.xba
+++ b/wizards/source/scriptforge/SF_Root.xba
@@ -59,6 +59,7 @@ Private DispatchHelper As Object ' com.sun.star.frame.DispatchHelper
Private TextSearch As Object ' com.sun.star.util.TextSearch
Private SearchOptions As Object ' com.sun.star.util.SearchOptions
Private Locale As Object ' com.sun.star.lang.Locale
+Private PrinterServer As Object ' com.sun.star.awt.PrinterServer
Private CharacterClass As Object ' com.sun.star.i18n.CharacterClassification
Private FileAccess As Object ' com.sun.star.ucb.SimpleFileAccess
Private FilterFactory As Object ' com.sun.star.document.FilterFactory
@@ -116,6 +117,7 @@ Private Sub Class_Initialize()
Set TextSearch = Nothing
Set SearchOptions = Nothing
Set Locale = Nothing
+ Set PrinterServer = Nothing
Set CharacterClass = Nothing
Set FileAccess = Nothing
Set FilterFactory = Nothing
diff --git a/wizards/source/scriptforge/SF_Utils.xba b/wizards/source/scriptforge/SF_Utils.xba
index 3656b36448ed..be2a9fd91cc7 100644
--- a/wizards/source/scriptforge/SF_Utils.xba
+++ b/wizards/source/scriptforge/SF_Utils.xba
@@ -398,6 +398,11 @@ Dim vNodePath As Variant
Set .PathSubstitution = CreateUnoService("com.sun.star.util.PathSubstitution")
End If
Set _GetUNOService = .PathSubstitution
+ Case "PrinterServer"
+ If IsEmpty(.PrinterServer) Or IsNull(.PrinterServer) Then
+ Set .PrinterServer = CreateUnoService("com.sun.star.awt.PrinterServer")
+ End If
+ Set _GetUNOService = .PrinterServer
Case "ScriptProvider"
If IsMissing(pvArg) Then pvArg = SF_Session.SCRIPTISAPPLICATION
Select Case LCase(pvArg)
diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py
index 57a67a0c9c3d..33b98fc491f8 100644
--- a/wizards/source/scriptforge/python/scriptforge.py
+++ b/wizards/source/scriptforge/python/scriptforge.py
@@ -1194,7 +1194,8 @@ class SFScriptForge:
servicesynonyms = ('platform', 'scriptforge.platform')
serviceproperties = dict(Architecture = False, ComputerName = False, CPUCount = False, CurrentUser = False,
Locale = False, Machine = False, OfficeVersion = False, OSName = False,
- OSPlatform = False, OSRelease = False, OSVersion = False, Processor = False)
+ OSPlatform = False, OSRelease = False, OSVersion = False, Printers = False,
+ Processor = False, PythonVersion = False)
# Python helper functions
py = ScriptForge.pythonhelpermodule + '$' + '_SF_Platform'
@@ -1238,6 +1239,10 @@ class SFScriptForge:
def Processor(self):
return self.SIMPLEEXEC(self.py, 'Processor')
+ @property
+ def PythonVersion(self):
+ return self.SIMPLEEXEC(self.py, 'PythonVersion')
+
# #########################################################################
# SF_Session CLASS
# #########################################################################
More information about the Libreoffice-commits
mailing list