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 <j...@ledure.be>
AuthorDate: Thu Jun 24 13:10:30 2021 +0200
Commit:     Jean-Pierre Ledure <j...@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 <j...@ledure.be>
    Tested-by: Jenkins
    Reviewed-by: Jean-Pierre Ledure <j...@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 = &quot;SF_Platform&quot;
 End Property   &apos;  ScriptForge.SF_Platform.ObjectType
 
-REM 
-----------------------------------------------------------------------------
-Property Get ServiceName As String
-&apos;&apos;&apos;     Internal use
-       ServiceName = &quot;ScriptForge.Platform&quot;
-End Property   &apos;  ScriptForge.SF_Platform.ServiceName
-
 REM 
-----------------------------------------------------------------------------
 Property Get OfficeVersion() As String
 &apos;&apos;&apos;     Returns the office software version in the form 
&apos;LibreOffice w.x.y.z (The Document Foundation)&apos;
@@ -141,6 +135,15 @@ Property Get OSVersion() As String
        OSVersion = _PropertyGet(&quot;OSVersion&quot;)
 End Property   &apos;  ScriptForge.SF_Platform.OSVersion (get)
 
+REM 
-----------------------------------------------------------------------------
+Property Get Printers() As Variant
+&apos;&apos;&apos;     Returns the list of available printers type as a 
zero-based array
+&apos;&apos;&apos;     The default printer is put in the 1st position in the 
list (index = 0)
+&apos;&apos;&apos;     Example:
+&apos;&apos;&apos;             MsgBox join(platform.Printers, &quot;,&quot;)
+       Printers = _PropertyGet(&quot;Printers&quot;)
+End Property   &apos;  ScriptForge.SF_Platform.Printers (get)
+
 REM 
-----------------------------------------------------------------------------
 Property Get Processor() As String
 &apos;&apos;&apos;     Returns the (real) processor name, e.g. 
&apos;amdk6&apos;. Might return the same value as Machine
@@ -157,6 +160,12 @@ Property Get PythonVersion() As String
        PythonVersion = _PropertyGet(&quot;PythonVersion&quot;)
 End Property   &apos;  ScriptForge.SF_Platform.PythonVersion (get)
 
+REM 
-----------------------------------------------------------------------------
+Property Get ServiceName As String
+&apos;&apos;&apos;     Internal use
+       ServiceName = &quot;ScriptForge.Platform&quot;
+End Property   &apos;  ScriptForge.SF_Platform.ServiceName
+
 REM ===================================================================== 
METHODS
 
 REM 
-----------------------------------------------------------------------------
@@ -216,6 +225,7 @@ Public Function Properties() As Variant
                                        , &quot;OSPlatform&quot; _
                                        , &quot;OSRelease&quot; _
                                        , &quot;OSVersion&quot; _
+                                       , &quot;Printers&quot; _
                                        , &quot;Processor&quot; _
                                        , &quot;PythonVersion&quot; _
                                        )
@@ -224,6 +234,43 @@ End Function       &apos;  
ScriptForge.SF_Platform.Properties
 
 REM =========================================================== PRIVATE 
FUNCTIONS
 
+REM 
-----------------------------------------------------------------------------
+Public Function _GetPrinters() as Variant
+&apos;&apos;&apos;     Returns the list of available printers.
+&apos;&apos;&apos;     The default printer is put in the 1st position (index = 
0)
+
+Dim oPrinterServer As Object           &apos;  com.sun.star.awt.PrinterServer
+Dim vPrinters As Variant                       &apos;  Array of printer names
+Dim sDefaultPrinter As String          &apos;  The default printer
+Dim lDefault As Long                           &apos;  Initial position of the 
default printer in the list
+
+       On Local Error GoTo Catch       &apos;  Prevent any error
+       vPrinters = Array()
+
+Try:
+       &apos;  Find printers
+       Set oPrinterServer = SF_Utils._GetUNOService(&quot;PrinterServer&quot;)
+       With oPrinterServer
+               vPrinters = .getPrinterNames()
+               sDefaultPrinter = .getDefaultPrinterName()
+       End With
+
+       &apos;  Put the default printer on top of the list
+       If Len(sDefaultPrinter) &gt; 0 Then
+               lDefault = SF_Array.IndexOf(vPrinters, sDefaultPrinter, 
CaseSensitive := True)
+               If lDefault &gt; 0 Then &apos;  Invert 2 printers
+                       vPrinters(lDefault) = vPrinters(0)
+                       vPrinters(0) = sDefaultPrinter
+               End If
+       End If
+
+Finally:
+       _GetPrinters() = vPrinters()
+       Exit Function
+Catch:
+       GoTo Finally
+End Function   &apos;  ScriptForge.SF_Platform._GetPrinters
+
 REM 
-----------------------------------------------------------------------------
 Public Function _GetProductName() as String
 &apos;&apos;&apos;     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                  &apos;  Operating system
 Dim oLocale As Object                  &apos;  com.sun.star.lang.Locale
+Dim oPrinterServer As Object   &apos;  com.sun.star.awt.PrinterServer
 
 Const cstPyHelper = &quot;$&quot; &amp; &quot;_SF_Platform&quot;
 Dim cstThisSub As String
@@ -293,6 +341,8 @@ Const cstSubArgs = &quot;&quot;
                                End Select
                        EndIf
                        _PropertyGet = sOSName
+               Case &quot;Printers&quot;
+                       _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       &apos; 
com.sun.star.frame.DispatchHelper
 Private TextSearch                     As Object       &apos; 
com.sun.star.util.TextSearch
 Private SearchOptions          As Object       &apos; 
com.sun.star.util.SearchOptions
 Private Locale                         As Object       &apos; 
com.sun.star.lang.Locale
+Private PrinterServer          As Object       &apos; 
com.sun.star.awt.PrinterServer
 Private CharacterClass         As Object       &apos; 
com.sun.star.i18n.CharacterClassification
 Private FileAccess                     As Object       &apos; 
com.sun.star.ucb.SimpleFileAccess
 Private FilterFactory          As Object       &apos; 
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(&quot;com.sun.star.util.PathSubstitution&quot;)
                                End If
                                Set _GetUNOService = .PathSubstitution
+                       Case &quot;PrinterServer&quot;
+                               If IsEmpty(.PrinterServer) Or 
IsNull(.PrinterServer) Then
+                                       Set .PrinterServer = 
CreateUnoService(&quot;com.sun.star.awt.PrinterServer&quot;)
+                               End If
+                               Set _GetUNOService = .PrinterServer
                        Case &quot;ScriptProvider&quot;
                                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
     # #########################################################################
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to