summaryrefslogtreecommitdiff
path: root/wizards
diff options
context:
space:
mode:
authorJean-Pierre Ledure <jp@ledure.be>2021-06-24 13:10:30 +0200
committerJean-Pierre Ledure <jp@ledure.be>2021-06-25 12:00:57 +0200
commit28c3228cf81f4cd29ed5a26a944796197298d1ec (patch)
treea53fe6e122b3ba9df556d417cd5f33715b3ca91a /wizards
parent8383175bd3c714c163eac40a00b1e8277d4d5307 (diff)
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@ledure.be> Tested-by: Jenkins Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Diffstat (limited to 'wizards')
-rw-r--r--wizards/source/scriptforge/SF_Platform.xba62
-rw-r--r--wizards/source/scriptforge/SF_Root.xba2
-rw-r--r--wizards/source/scriptforge/SF_Utils.xba5
-rw-r--r--wizards/source/scriptforge/python/scriptforge.py7
4 files changed, 69 insertions, 7 deletions
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
@@ -96,12 +96,6 @@ Property Get ObjectType As String
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;
&apos;&apos;&apos; Example:
@@ -142,6 +136,15 @@ Property Get OSVersion() As String
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
&apos;&apos;&apos; Example:
@@ -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; _
)
@@ -225,6 +235,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
&apos;&apos;&apos; Derived from the Tools library
@@ -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
# #########################################################################