calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / wizards / source / scriptforge / SF_PythonHelper.xba
blob99d9f86c610c6e563081d18505fecb957690f315
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <script:module xmlns:script="http://openoffice.org/2000/script" script:name="SF_PythonHelper" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
4 REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
5 REM === Full documentation is available on https://help.libreoffice.org/ ===
6 REM =======================================================================================================================
8 Option Compatible
9 Option Explicit
11 &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
12 &apos;&apos;&apos; SF_PythonHelper (aka Basic)
13 &apos;&apos;&apos; ===============
14 &apos;&apos;&apos; Singleton class implementing the &quot;ScriptForge.Basic&quot; service
15 &apos;&apos;&apos; Implemented as a usual Basic module
16 &apos;&apos;&apos;
17 &apos;&apos;&apos; The &quot;Basic&quot; service must be called ONLY from a PYTHON script
18 &apos;&apos;&apos; Service invocations: Next Python code lines are equivalent:
19 &apos;&apos;&apos; bas = CreateScriptService(&apos;ScriptForge.Basic&apos;)
20 &apos;&apos;&apos; bas = CreateScriptService(&apos;Basic&apos;)
21 &apos;&apos;&apos;
22 &apos;&apos;&apos; This service proposes a collection of methods to be executed in a Python context
23 &apos;&apos;&apos; to simulate the exact behaviour of the identical Basic builtin method.
24 &apos;&apos;&apos; Typical example:
25 &apos;&apos;&apos; bas.MsgBox(&apos;This has to be displayed in a message box&apos;)
26 &apos;&apos;&apos;
27 &apos;&apos;&apos; The service includes also an agnostic &quot;Python Dispatcher&quot; function.
28 &apos;&apos;&apos; It dispatches Python script requests to execute Basic services to the
29 &apos;&apos;&apos; appropriate properties and methods via dynamic call techniques
30 &apos;&apos;&apos;
31 &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
33 REM ================================================================== EXCEPTIONS
35 REM ============================================================ MODULE CONSTANTS
37 REM ===================================================== CONSTRUCTOR/DESTRUCTOR
39 REM -----------------------------------------------------------------------------
40 Public Function Dispose() As Variant
41 Set Dispose = Nothing
42 End Function &apos; ScriptForge.SF_PythonHelper Explicit destructor
44 REM ================================================================== PROPERTIES
46 REM -----------------------------------------------------------------------------
47 Property Get ObjectType As String
48 &apos;&apos;&apos; Only to enable object representation
49 ObjectType = &quot;SF_PythonHelper&quot;
50 End Property &apos; ScriptForge.SF_PythonHelper.ObjectType
52 REM -----------------------------------------------------------------------------
53 Property Get ServiceName As String
54 &apos;&apos;&apos; Internal use
55 ServiceName = &quot;ScriptForge.Basic&quot;
56 End Property &apos; ScriptForge.SF_PythonHelper.ServiceName
58 REM ============================================================== PUBLIC METHODS
60 REM -----------------------------------------------------------------------------
61 Public Function PyCDate(ByVal DateArg As Variant) As Variant
62 &apos;&apos;&apos; Convenient function to replicate CDate() in Python scripts
63 &apos;&apos;&apos; Args:
64 &apos;&apos;&apos; DateArg: a date as a string or as a double
65 &apos;&apos;&apos; Returns:
66 &apos;&apos;&apos; The converted date as a UNO DateTime structure
67 &apos;&apos;&apos; If the input argument could not be recognized as a date, return the argument unchanged
68 &apos;&apos;&apos; Example: (Python code)
69 &apos;&apos;&apos; a = bas.CDate(&apos;2021-02-18&apos;)
71 Dim vDate As Variant &apos; Return value
72 Const cstThisSub = &quot;Basic.CDate&quot;
73 Const cstSubArgs = &quot;datearg&quot;
75 On Local Error GoTo Catch
76 vDate = Null
78 Check:
79 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
81 Try:
82 vDate = CDate(DateArg)
84 Finally:
85 If VarType(vDate) = V_DATE Then PyCDate = CDateToUnoDateTime(vDate) Else PyCDate = DateArg
86 SF_Utils._ExitFunction(cstThisSub)
87 Exit Function
88 Catch:
89 On Local Error GoTo 0
90 GoTo Finally
91 End Function &apos; ScriptForge.SF_PythonHelper.PyCDate
93 REM -----------------------------------------------------------------------------
94 Public Function PyConvertFromUrl(ByVal FileName As Variant) As String
95 &apos;&apos;&apos; Convenient function to replicate ConvertFromUrl() in Python scripts
96 &apos;&apos;&apos; Args:
97 &apos;&apos;&apos; FileName: a string representing a file in URL format
98 &apos;&apos;&apos; Returns:
99 &apos;&apos;&apos; The same file name in native operating system notation
100 &apos;&apos;&apos; Example: (Python code)
101 &apos;&apos;&apos; a = bas.ConvertFromUrl(&apos;file:////boot.sys&apos;)
103 Dim sFileName As String &apos; Return value
104 Const cstThisSub = &quot;Basic.ConvertFromUrl&quot;
105 Const cstSubArgs = &quot;filename&quot;
107 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
108 sFileName = &quot;&quot;
110 Check:
111 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
113 Try:
114 sFileName = ConvertFromUrl(FileName)
116 Finally:
117 PyConvertFromUrl = sFileName
118 SF_Utils._ExitFunction(cstThisSub)
119 Exit Function
120 Catch:
121 GoTo Finally
122 End Function &apos; ScriptForge.SF_PythonHelper.PyConvertFromUrl
124 REM -----------------------------------------------------------------------------
125 Public Function PyConvertToUrl(ByVal FileName As Variant) As String
126 &apos;&apos;&apos; Convenient function to replicate ConvertToUrl() in Python scripts
127 &apos;&apos;&apos; Args:
128 &apos;&apos;&apos; FileName: a string representing a file in native operating system notation
129 &apos;&apos;&apos; Returns:
130 &apos;&apos;&apos; The same file name in URL format
131 &apos;&apos;&apos; Example: (Python code)
132 &apos;&apos;&apos; a = bas.ConvertToUrl(&apos;C:\boot.sys&apos;)
134 Dim sFileName As String &apos; Return value
135 Const cstThisSub = &quot;Basic.ConvertToUrl&quot;
136 Const cstSubArgs = &quot;filename&quot;
138 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
139 sFileName = &quot;&quot;
141 Check:
142 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
144 Try:
145 sFileName = ConvertToUrl(FileName)
147 Finally:
148 PyConvertToUrl = sFileName
149 SF_Utils._ExitFunction(cstThisSub)
150 Exit Function
151 Catch:
152 GoTo Finally
153 End Function &apos; ScriptForge.SF_PythonHelper.PyConvertToUrl
155 REM -----------------------------------------------------------------------------
156 Public Function PyCreateUnoService(ByVal UnoService As Variant) As Variant
157 &apos;&apos;&apos; Convenient function to replicate CreateUnoService() in Python scripts
158 &apos;&apos;&apos; Args:
159 &apos;&apos;&apos; UnoService: a string representing the service to create
160 &apos;&apos;&apos; Returns:
161 &apos;&apos;&apos; A UNO object
162 &apos;&apos;&apos; Example: (Python code)
163 &apos;&apos;&apos; a = bas.CreateUnoService(&apos;com.sun.star.i18n.CharacterClassification&apos;)
165 Dim vUno As Variant &apos; Return value
166 Const cstThisSub = &quot;Basic.CreateUnoService&quot;
167 Const cstSubArgs = &quot;unoservice&quot;
169 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
170 Set vUno = Nothing
172 Check:
173 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
175 Try:
176 Set vUno = CreateUnoService(UnoService)
178 Finally:
179 Set PyCreateUnoService = vUno
180 SF_Utils._ExitFunction(cstThisSub)
181 Exit Function
182 Catch:
183 GoTo Finally
184 End Function &apos; ScriptForge.SF_PythonHelper.PyCreateUnoService
186 REM -----------------------------------------------------------------------------
187 Public Function PyDateAdd(ByVal Add As Variant _
188 , ByVal Count As Variant _
189 , ByVal DateArg As Variant _
190 ) As Variant
191 &apos;&apos;&apos; Convenient function to replicate DateAdd() in Python scripts
192 &apos;&apos;&apos; Args:
193 &apos;&apos;&apos; Add: The unit to add
194 &apos;&apos;&apos; Count: how many times to add (might be negative)
195 &apos;&apos;&apos; DateArg: a date as a com.sun.star.util.DateTime UNO structure
196 &apos;&apos;&apos; Returns:
197 &apos;&apos;&apos; The new date as a string in iso format
198 &apos;&apos;&apos; Example: (Python code)
199 &apos;&apos;&apos; a = bas.DateAdd(&apos;d&apos;, 1, bas.Now()) &apos; Tomorrow
201 Dim vNewDate As Variant &apos; Return value
202 Dim vDate As Date &apos; Alias of DateArg
203 Const cstThisSub = &quot;Basic.DateAdd&quot;
204 Const cstSubArgs = &quot;add, count, datearg&quot;
206 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
207 vNewDate = &quot;&quot;
209 Check:
210 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
212 Try:
213 If VarType(DateArg) = V_OBJECT Then
214 vDate = CDateFromUnoDateTime(DateArg)
215 Else
216 vDate = SF_Utils._CStrToDate(DateArg)
217 End If
218 vNewDate = DateAdd(Add, Count, vDate)
220 Finally:
221 If VarType(vNewDate) = V_DATE Then PyDateAdd = CDateToUnoDateTime(vNewDate) Else PyDateAdd = vNewDate
222 SF_Utils._ExitFunction(cstThisSub)
223 Exit Function
224 Catch:
225 GoTo Finally
226 End Function &apos; ScriptForge.SF_PythonHelper.PyDateAdd
228 REM -----------------------------------------------------------------------------
229 Public Function PyDateDiff(ByVal Add As Variant _
230 , ByVal Date1 As Variant _
231 , ByVal Date2 As Variant _
232 , ByVal WeekStart As Variant _
233 , ByVal YearStart As Variant _
234 ) As Long
235 &apos;&apos;&apos; Convenient function to replicate DateDiff() in Python scripts
236 &apos;&apos;&apos; Args:
237 &apos;&apos;&apos; Add: The unit of the date interval
238 &apos;&apos;&apos; Date1, Date2: the two dates to be compared
239 &apos;&apos;&apos; WeekStart: the starting day of a week
240 &apos;&apos;&apos; YearStart: the starting week of a year
241 &apos;&apos;&apos; Returns:
242 &apos;&apos;&apos; The number of intervals expressed in Adds
243 &apos;&apos;&apos; Example: (Python code)
244 &apos;&apos;&apos; a = bas.DateDiff(&apos;d&apos;, bas.DateAdd(&apos;d&apos;, 1, bas.Now()), bas.Now()) &apos; -1 day
246 Dim lDiff As Long &apos; Return value
247 Dim vDate1 As Date &apos; Alias of Date1
248 Dim vDate2 As Date &apos; Alias of Date2
249 Const cstThisSub = &quot;Basic.DateDiff&quot;
250 Const cstSubArgs = &quot;add, date1, date2, [weekstart=1], [yearstart=1]&quot;
252 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
253 lDiff = 0
255 Check:
256 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
258 Try:
259 If VarType(Date1) = V_OBJECT Then
260 vDate1 = CDateFromUnoDateTime(Date1)
261 Else
262 vDate1 = SF_Utils._CStrToDate(Date1)
263 End If
264 If VarType(Date2) = V_OBJECT Then
265 vDate2 = CDateFromUnoDateTime(Date2)
266 Else
267 vDate2 = SF_Utils._CStrToDate(Date2)
268 End If
269 lDiff = DateDiff(Add, vDate1, vDate2, WeekStart, YearStart)
272 Finally:
273 PyDateDiff = lDiff
274 SF_Utils._ExitFunction(cstThisSub)
275 Exit Function
276 Catch:
277 GoTo Finally
278 End Function &apos; ScriptForge.SF_PythonHelper.PyDateDiff
280 REM -----------------------------------------------------------------------------
281 Public Function PyDatePart(ByVal Add As Variant _
282 , ByVal DateArg As Variant _
283 , ByVal WeekStart As Variant _
284 , ByVal YearStart As Variant _
285 ) As Long
286 &apos;&apos;&apos; Convenient function to replicate DatePart() in Python scripts
287 &apos;&apos;&apos; Args:
288 &apos;&apos;&apos; Add: The unit of the date interval
289 &apos;&apos;&apos; DateArg: The date from which to extract a part
290 &apos;&apos;&apos; WeekStart: the starting day of a week
291 &apos;&apos;&apos; YearStart: the starting week of a year
292 &apos;&apos;&apos; Returns:
293 &apos;&apos;&apos; The specified part of the date
294 &apos;&apos;&apos; Example: (Python code)
295 &apos;&apos;&apos; a = bas.DatePart(&apos;y&apos;, bas.Now()) &apos; day of year
297 Dim lPart As Long &apos; Return value
298 Dim vDate As Date &apos; Alias of DateArg
299 Const cstThisSub = &quot;Basic.DatePart&quot;
300 Const cstSubArgs = &quot;add, datearg, [weekstart=1], [yearstart=1]&quot;
302 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
303 lPart = 0
305 Check:
306 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
308 Try:
309 If VarType(DateArg) = V_OBJECT Then
310 vDate = CDateFromUnoDateTime(DateArg)
311 Else
312 vDate = SF_Utils._CStrToDate(DateArg)
313 End If
314 lPart = DatePart(Add, vDate, WeekStart, YearStart)
317 Finally:
318 PyDatePart = lPart
319 SF_Utils._ExitFunction(cstThisSub)
320 Exit Function
321 Catch:
322 GoTo Finally
323 End Function &apos; ScriptForge.SF_PythonHelper.PyDatePart
325 REM -----------------------------------------------------------------------------
326 Public Function PyDateValue(ByVal DateArg As Variant) As Variant
327 &apos;&apos;&apos; Convenient function to replicate DateValue() in Python scripts
328 &apos;&apos;&apos; Args:
329 &apos;&apos;&apos; DateArg: a date as a string
330 &apos;&apos;&apos; Returns:
331 &apos;&apos;&apos; The converted date as a UNO DateTime structure
332 &apos;&apos;&apos; Example: (Python code)
333 &apos;&apos;&apos; a = bas.DateValue(&apos;2021-02-18&apos;)
335 Dim vDate As Variant &apos; Return value
336 Const cstThisSub = &quot;Basic.DateValue&quot;
337 Const cstSubArgs = &quot;datearg&quot;
339 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
340 vDate = &quot;&quot;
342 Check:
343 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
345 Try:
346 vDate = DateValue(DateArg)
348 Finally:
349 If VarType(vDate) = V_DATE Then PyDateValue = CDateToUnoDateTime(vDate) Else PyDateValue = vDate
350 SF_Utils._ExitFunction(cstThisSub)
351 Exit Function
352 Catch:
353 GoTo Finally
354 End Function &apos; ScriptForge.SF_PythonHelper.PyDateValue
356 REM -----------------------------------------------------------------------------
357 Public Function PyFormat(ByVal Value As Variant _
358 , ByVal Pattern As Variant _
359 ) As String
360 &apos;&apos;&apos; Convenient function to replicate Format() in Python scripts
361 &apos;&apos;&apos; Args:
362 &apos;&apos;&apos; Value: a date or a number
363 &apos;&apos;&apos; Pattern: the format to apply
364 &apos;&apos;&apos; Returns:
365 &apos;&apos;&apos; The formatted value
366 &apos;&apos;&apos; Example: (Python code)
367 &apos;&apos;&apos; MsgBox bas.Format(6328.2, &apos;##,##0.00&apos;)
369 Dim sFormat As String &apos; Return value
370 Dim vValue As Variant &apos; Alias of Value
371 Const cstThisSub = &quot;Basic.Format&quot;
372 Const cstSubArgs = &quot;value, pattern&quot;
374 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
375 sFormat = &quot;&quot;
377 Check:
378 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
380 Try:
381 If VarType(Value) = V_OBJECT Then vValue = CDateFromUnoDateTime(Value) ELse vValue = Value
382 If IsEmpty(Pattern) Or Len(Pattern) = 0 Then sFormat = Str(vValue) Else sFormat = Format(vValue, Pattern)
385 Finally:
386 PyFormat = sFormat
387 SF_Utils._ExitFunction(cstThisSub)
388 Exit Function
389 Catch:
390 GoTo Finally
391 End Function &apos; ScriptForge.SF_PythonHelper.PyFormat
393 REM -----------------------------------------------------------------------------
394 Public Function PyGetGuiType() As Integer
395 &apos;&apos;&apos; Convenient function to replicate GetGuiType() in Python scripts
396 &apos;&apos;&apos; Args:
397 &apos;&apos;&apos; Returns:
398 &apos;&apos;&apos; The GetGuiType value
399 &apos;&apos;&apos; Example: (Python code)
400 &apos;&apos;&apos; MsgBox bas.GetGuiType()
402 Const cstThisSub = &quot;Basic.GetGuiType&quot;
403 Const cstSubArgs = &quot;&quot;
405 Check:
406 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
408 Try:
409 PyGetGuiType = GetGuiType()
412 Finally:
413 SF_Utils._ExitFunction(cstThisSub)
414 Exit Function
415 End Function &apos; ScriptForge.SF_PythonHelper.PyGetGuiType
417 REM -----------------------------------------------------------------------------
418 Public Function PyGetSystemTicks() As Long
419 &apos;&apos;&apos; Convenient function to replicate GetSystemTicks() in Python scripts
420 &apos;&apos;&apos; Args:
421 &apos;&apos;&apos; Returns:
422 &apos;&apos;&apos; The GetSystemTicks value
423 &apos;&apos;&apos; Example: (Python code)
424 &apos;&apos;&apos; MsgBox bas.GetSystemTicks()
426 Const cstThisSub = &quot;Basic.GetSystemTicks&quot;
427 Const cstSubArgs = &quot;&quot;
429 Check:
430 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
432 Try:
433 PyGetSystemTicks = GetSystemTicks()
436 Finally:
437 SF_Utils._ExitFunction(cstThisSub)
438 Exit Function
439 End Function &apos; ScriptForge.SF_PythonHelper.PyGetSystemTicks
441 REM -----------------------------------------------------------------------------
442 Public Function PyGlobalScope(ByVal Library As Variant) As Object
443 &apos;&apos;&apos; Convenient function to replicate GlobalScope() in Python scripts
444 &apos;&apos;&apos; Args:
445 &apos;&apos;&apos; Library: &quot;Basic&quot; or &quot;Dialog&quot;
446 &apos;&apos;&apos; Returns:
447 &apos;&apos;&apos; The GlobalScope value
448 &apos;&apos;&apos; Example: (Python code)
449 &apos;&apos;&apos; MsgBox bas.GlobalScope.BasicLibraries()
451 Const cstThisSub = &quot;Basic.GlobalScope.BasicLibraries&quot; &apos; or DialogLibraries
452 Const cstSubArgs = &quot;&quot;
454 Check:
455 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
457 Try:
458 Select Case Library
459 Case &quot;Basic&quot;
460 PyGlobalScope = GlobalScope.BasicLibraries()
461 Case &quot;Dialog&quot;
462 PyGlobalScope = GlobalScope.DialogLibraries()
463 Case Else
464 End Select
466 Finally:
467 SF_Utils._ExitFunction(cstThisSub)
468 Exit Function
469 End Function &apos; ScriptForge.SF_PythonHelper.PyGlobalScope
471 REM -----------------------------------------------------------------------------
472 Public Function PyInputBox(ByVal Msg As Variant _
473 , ByVal Title As Variant _
474 , ByVal Default As Variant _
475 , Optional ByVal XPosTwips As Variant _
476 , Optional ByVal YPosTwips As Variant _
477 ) As String
478 &apos;&apos;&apos; Convenient function to replicate InputBox() in Python scripts
479 &apos;&apos;&apos; Args:
480 &apos;&apos;&apos; Msg: String expression displayed as the message in the dialog box
481 &apos;&apos;&apos; Title: String expression displayed in the title bar of the dialog box
482 &apos;&apos;&apos; Default: String expression displayed in the text box as default if no other input is given
483 &apos;&apos;&apos; XPosTwips: Integer expression that specifies the horizontal position of the dialog
484 &apos;&apos;&apos; YPosTwips: Integer expression that specifies the vertical position of the dialog
485 &apos;&apos;&apos; If XPosTwips and YPosTwips are omitted, the dialog is centered on the screen
486 &apos;&apos;&apos; The position is specified in twips.
487 &apos;&apos;&apos; Returns:
488 &apos;&apos;&apos; The entered value or &quot;&quot; if the user pressed the Cancel button
489 &apos;&apos;&apos; Example: (Python code)
490 &apos;&apos;&apos; a = bas.InputBox (&apos;Please enter a phrase:&apos;, &apos;Dear User&apos;)
492 Dim sInput As String &apos; Return value
493 Const cstThisSub = &quot;Basic.InputBox&quot;
494 Const cstSubArgs = &quot;msg, [title=&apos;&apos;], [default=&apos;&apos;], [xpostwips], [ypostwips]&quot;
496 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
497 sInput = &quot;&quot;
499 Check:
500 If IsMissing(YPosTwips) Then YPosTwips = 1
501 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
503 Try:
504 If IsMissing(XPosTwips) Then
505 sInput = InputBox(Msg, Title, Default)
506 Else
507 sInput = InputBox(Msg, Title, Default, XPosTwips, YPosTwips)
508 End If
510 Finally:
511 PyInputBox = sInput
512 SF_Utils._ExitFunction(cstThisSub)
513 Exit Function
514 Catch:
515 GoTo Finally
516 End Function &apos; ScriptForge.SF_PythonHelper.PyInputBox
518 REM -----------------------------------------------------------------------------
519 Public Function PyMsgBox(ByVal Text As Variant _
520 , ByVal DialogType As Variant _
521 , ByVal DialogTitle As Variant _
522 ) As Integer
523 &apos;&apos;&apos; Convenient function to replicate MsgBox() in Python scripts
524 &apos;&apos;&apos; Args:
525 &apos;&apos;&apos; Text: String expression displayed as a message in the dialog box
526 &apos;&apos;&apos; DialogType: Any integer expression that defines the number and type of buttons or icons displayed
527 &apos;&apos;&apos; DialogTitle: String expression displayed in the title bar of the dialog
528 &apos;&apos;&apos; Returns:
529 &apos;&apos;&apos; The pressed button
530 &apos;&apos;&apos; Example: (Python code)
531 &apos;&apos;&apos; a = bas.MsgBox (&apos;Please press a button:&apos;, bas.MB_EXCLAMATION, &apos;Dear User&apos;)
533 Dim iMsg As Integer &apos; Return value
534 Const cstThisSub = &quot;Basic.MsgBox&quot;
535 Const cstSubArgs = &quot;text, [dialogtype=0], [dialogtitle]&quot;
537 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
538 iMsg = -1
540 Check:
541 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
543 Try:
544 iMsg = MsgBox(Text, DialogType, DialogTitle)
546 Finally:
547 PyMsgBox = iMsg
548 SF_Utils._ExitFunction(cstThisSub)
549 Exit Function
550 Catch:
551 GoTo Finally
552 End Function &apos; ScriptForge.SF_PythonHelper.PyMsgBox
554 REM ============================================================= PRIVATE METHODS
556 REM -----------------------------------------------------------------------------
557 Public Function _PythonDispatcher(ByRef BasicObject As Variant _
558 , ByVal CallType As Variant _
559 , ByVal Script As Variant _
560 , ParamArray Args() As Variant _
561 ) As Variant
562 &apos;&apos;&apos; Called from Python only
563 &apos;&apos;&apos; The method calls the method Script associated with the BasicObject class or module
564 &apos;&apos;&apos; with the given arguments
565 &apos;&apos;&apos; The invocation of the method can be a Property Get, Property Let or a usual call
566 &apos;&apos;&apos; NB: arguments and return values must not be 2D arrays
567 &apos;&apos;&apos; The implementation intends to be as AGNOSTIC as possible in terms of objects nature and methods called
568 &apos;&apos;&apos; Args:
569 &apos;&apos;&apos; BasicObject: a module or a class instance - May also be the reserved string: &quot;SF_Services&quot;
570 &apos;&apos;&apos; CallType: one of the constants applicable to a CallByName statement + optional protocol flags
571 &apos;&apos;&apos; Script: the name of the method or property
572 &apos;&apos;&apos; Args: the arguments to pass to the method. Input arguments can contain symbolic constants for Null, Missing, etc.
573 &apos;&apos;&apos; Returns:
574 &apos;&apos;&apos; A 1D array:
575 &apos;&apos;&apos; [0] The returned value - scalar, object or 1D array
576 &apos;&apos;&apos; [1] The VarType() of the returned value
577 &apos;&apos;&apos; Null, Empty and Nothing have different vartypes but return all None to Python
578 &apos;&apos;&apos; Additionally, when array:
579 &apos;&apos;&apos; [2] Number of dimensions in Basic
580 &apos;&apos;&apos; Additionally, when Basic object:
581 &apos;&apos;&apos; [2] Module (1), Class instance (2) or UNO (3)
582 &apos;&apos;&apos; [3] The object&apos;s ObjectType
583 &apos;&apos;&apos; [4] The object&apos;s service name
584 &apos;&apos;&apos; [5] The object&apos;s name
585 &apos;&apos;&apos; When an error occurs Python receives None as a scalar. This determines the occurrence of a failure
587 Dim vReturn As Variant &apos; The value returned by the invoked property or method
588 Dim vReturnArray As Variant &apos; Return value
589 Dim vBasicObject As Variant &apos; Alias of BasicObject to avoid &quot;Object reference not set&quot; error
590 Dim iNbArgs As Integer &apos; Number of valid input arguments
591 Dim vArg As Variant &apos; Alias for a single argument
592 Dim vArgs() As Variant &apos; Alias for Args()
593 Dim sScript As String &apos; Argument of ExecuteBasicScript()
594 Dim vParams As Variant &apos; Array of arguments to pass to a ParamArray
595 Dim sObjectType As String &apos; Alias of object.ObjectType
596 Dim sServiceName As String &apos; Alias of BasicObject.ServiceName
597 Dim bBasicClass As Boolean &apos; True when BasicObject is a class
598 Dim sLibrary As String &apos; Library where the object belongs to
599 Dim bUno As Boolean &apos; Return value is a UNO object
600 Dim oObjDesc As Object &apos; _ObjectDescriptor type
601 Dim iDims As Integer &apos; # of dims of vReturn
602 Dim sess As Object : Set sess = ScriptForge.SF_Session
603 Dim i As Long, j As Long
605 &apos; Conventional special input or output values
606 Const cstNoArgs = &quot;+++NOARGS+++&quot;, cstSymEmpty = &quot;+++EMPTY+++&quot;, cstSymNull = &quot;+++NULL+++&quot;, cstSymMissing = &quot;+++MISSING+++&quot;
608 &apos; https://support.office.com/en-us/article/CallByName-fonction-49ce9475-c315-4f13-8d35-e98cfe98729a
609 &apos; Determines the CallType
610 Const vbGet = 2, vbLet = 4, vbMethod = 1, vbSet = 8
611 &apos; Protocol flags
612 Const cstDateArg = 64 &apos; May contain a date argument
613 Const cstDateRet = 128 &apos; Return value can be a date
614 Const cstUno = 256 &apos; Return value can be a UNO object
615 Const cstArgArray = 512 &apos; Any argument can be a 2D array
616 Const cstRetArray = 1024 &apos; Return value can be an array
617 Const cstObject = 2048 &apos; 1st argument is a Basic object when numeric
618 Const cstHardCode = 4096 &apos; Method must not be executed with CallByName()
619 &apos; Object nature in returned array
620 Const objMODULE = 1, objCLASS = 2, objUNO = 3
622 Check:
623 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
624 _PythonDispatcher = Null
626 &apos; Ignore Null basic objects (Null = Null or Nothing)
627 If IsNull(BasicObject) Or IsEmpty(BasicObject) Then GoTo Catch
629 &apos; Reinterpret arguments one by one into vArgs, convert UNO date/times and conventional NoArgs/Empty/Null/Missing values
630 iNbArgs = -1
631 vArgs = Array()
633 If UBound(Args) &gt;= 0 Then
634 For i = 0 To UBound(Args)
635 vArg = Args(i)
636 &apos; Are there arguments ?
637 If i = 0 And VarType(vArg) = V_STRING Then
638 If vArg = cstNoArgs Then Exit For
639 End If
640 &apos; Is 1st argument a reference to a Basic object ?
641 If i = 0 And (( CallType And cstObject ) = cstObject) And SF_Utils._VarTypeExt(vArg) = V_NUMERIC Then
642 If vArg &lt; 0 Or Not IsArray(_SF_.PythonStorage) Then GoTo Catch
643 If vArg &gt; UBound(_SF_.PythonStorage) Then GoTo Catch
644 vArg = _SF_.PythonStorage(vArg)
645 &apos; Is argument a symbolic constant for Null, Empty, ... , or a date?
646 ElseIf VarType(vArg) = V_STRING Then
647 If Len(vArg) = 0 Then
648 ElseIf vArg = cstSymEmpty Then
649 vArg = Empty
650 ElseIf vArg = cstSymNull Then
651 vArg = Null
652 ElseIf vArg = cstSymMissing Then
653 Exit For &apos; Next arguments must be missing also
654 End If
655 ElseIf VarType(vArg) = V_OBJECT Then
656 If ( CallType And cstDateArg ) = cstDateArg Then vArg = CDateFromUnoDateTime(vArg)
657 End If
658 iNbArgs = iNbArgs + 1
660 ReDim Preserve vArgs(iNbArgs)
661 vArgs(iNbArgs) = vArg
662 Next i
663 End If
665 Try:
666 &apos; Dispatching strategy: based on next constraints
667 &apos; (1) Bug https://bugs.documentfoundation.org/show_bug.cgi?id=138155
668 &apos; The CallByName function fails when returning an array
669 &apos; (2) Python has tuples and tuple of tuples, not 2D arrays
670 &apos; (3) Passing 2D arrays through a script provider always transform it into a sequence of sequences
671 &apos; (4) The CallByName function takes exclusive control on the targeted object up to its exit
672 &apos; 1. Methods in usual modules are called by ExecuteBasicScript() except if they use a ParamArray
673 &apos; 2. Properties in any service are got and set with obj.GetProperty/SetProperty(...)
674 &apos; 3. Methods in class modules are invoked with CallByName
675 &apos; 4. Methods in class modules using a 2D array or returning arrays, or methods using ParamArray,
676 &apos;&apos;&apos; are hardcoded as exceptions or are not implemented
677 &apos; 5. Due to constraint (4), a predefined list of method calls must be hardcoded to avoid blocking use of CallByName
678 &apos; The concerned methods are flagged with cstHardCode
680 With _SF_
681 &apos; Initialize Python persistent storage at 1st call
682 If IsEmpty(.PythonStorage) Then ._InitPythonStorage()
683 &apos; Reset any error
684 ._Stackreset()
685 &apos; Set Python trigger to manage signatures in error messages
686 .TriggeredByPython = True
687 End With
689 Select case VarType(BasicObject)
690 Case V_STRING
691 &apos; Special entry for CreateScriptService()
692 vBasicObject = BasicObject
693 If vBasicObject = &quot;SF_Services&quot; Then
694 If UBound(vArgs) = 0 Then vParams = Array() Else vParams = SF_Array.Slice(vArgs, 1)
695 Select Case UBound(vParams)
696 Case -1 : vReturn = SF_Services.CreateScriptService(vArgs(0))
697 Case 0 : vReturn = SF_Services.CreateScriptService(vArgs(0), vParams(0))
698 Case 1 : vReturn = SF_Services.CreateScriptService(vArgs(0), vParams(0), vParams(1))
699 Case 2 : vReturn = SF_Services.CreateScriptService(vArgs(0), vParams(0), vParams(1), vParams(2))
700 Case 3 : vReturn = SF_Services.CreateScriptService(vArgs(0), vParams(0), vParams(1), vParams(2), vParams(3))
701 Case 4 : vReturn = SF_Services.CreateScriptService(vArgs(0), vParams(0), vParams(1), vParams(2), vParams(3), vParams(4))
702 End Select
703 End If
704 If VarType(vReturn) = V_OBJECT And Not IsNull(vReturn) Then
705 vBasicObject = vReturn
706 sObjectType = vBasicObject.ObjectType
707 bBasicClass = ( Left(sObjectType, 3) &lt;&gt; &quot;SF_&quot; )
708 End If
710 &apos; Implement dispatching strategy
711 Case V_INTEGER
712 If BasicObject &lt; 0 Or Not IsArray(_SF_.PythonStorage) Then GoTo Catch
713 If BasicObject &gt; UBound(_SF_.PythonStorage) Then GoTo Catch
714 vBasicObject = _SF_.PythonStorage(BasicObject)
715 sObjectType = vBasicObject.ObjectType
716 sServiceName = vBasicObject.ServiceName
718 &apos; Basic modules have type = &quot;SF_*&quot;
719 bBasicClass = ( Left(sObjectType, 3) &lt;&gt; &quot;SF_&quot; )
720 sLibrary = Split(sServiceName, &quot;.&quot;)(0)
722 &apos; Methods in standard modules returning/passing a date are hardcoded as exceptions
723 If Not bBasicClass And ((CallType And vbMethod) = vbMethod) _
724 And (((CallType And cstDateRet) = cstDateRet) Or ((CallType And cstDateArg) = cstDateArg)) Then
725 Select Case sServiceName
726 Case &quot;ScriptForge.FileSystem&quot;
727 If Script = &quot;GetFileModified&quot; Then vReturn = SF_FileSystem.GetFileModified(vArgs(0))
728 Case &quot;ScriptForge.Region&quot;
729 Select Case Script
730 Case &quot;DSTOffset&quot; : vReturn = SF_Region.DSTOffset(vArgs(0), vArgs(1), vArgs(2))
731 Case &quot;LocalDateTime&quot; : vReturn = SF_Region.LocalDateTime(vArgs(0), vArgs(1), vArgs(2))
732 Case &quot;UTCDateTime&quot; : vReturn = SF_Region.UTCDateTime(vArgs(0), vArgs(1), vArgs(2))
733 Case &quot;UTCNow&quot; : vReturn = SF_Region.UTCNow(vArgs(0), vArgs(1))
734 Case Else
735 End Select
736 End Select
738 &apos; Methods in usual modules using a 2D array or returning arrays are hardcoded as exceptions
739 ElseIf Not bBasicClass And _
740 (((CallType And vbMethod) + (CallType And cstArgArray)) = vbMethod + cstArgArray Or _
741 ((CallType And vbMethod) + (CallType And cstRetArray)) = vbMethod + cstRetArray) Then
742 &apos; Not service related
743 If Script = &quot;Methods&quot; Then
744 vReturn = vBasicObject.Methods()
745 ElseIf Script = &quot;Properties&quot; Then
746 vReturn = vBasicObject.Properties()
747 Else
748 Select Case sServiceName
749 Case &quot;ScriptForge.Array&quot;
750 If Script = &quot;ImportFromCSVFile&quot; Then vReturn = SF_Array.ImportFromCSVFile(vArgs(0), vArgs(1), vArgs(2), True)
751 End Select
752 End If
754 &apos; Methods in usual modules are called by ExecuteBasicScript() except if they use a ParamArray
755 ElseIf Not bBasicClass And (CallType And vbMethod) = vbMethod Then
756 sScript = sLibrary &amp; &quot;.&quot; &amp; sObjectType &amp; &quot;.&quot; &amp; Script
757 &apos; Force validation in targeted function, not in ExecuteBasicScript()
758 _SF_.StackLevel = -1
759 Select Case UBound(vArgs)
760 Case -1 : vReturn = sess.ExecuteBasicScript(, sScript)
761 Case 0 : vReturn = sess.ExecuteBasicScript(, sScript, vArgs(0))
762 Case 1 : vReturn = sess.ExecuteBasicScript(, sScript, vArgs(0), vArgs(1))
763 Case 2 : vReturn = sess.ExecuteBasicScript(, sScript, vArgs(0), vArgs(1), vArgs(2))
764 Case 3 : vReturn = sess.ExecuteBasicScript(, sScript, vArgs(0), vArgs(1), vArgs(2), vArgs(3))
765 Case 4 : vReturn = sess.ExecuteBasicScript(, sScript, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4))
766 Case 5 : vReturn = sess.ExecuteBasicScript(, sScript, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5))
767 Case 6 : vReturn = sess.ExecuteBasicScript(, sScript, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6))
768 Case 7 : vReturn = sess.ExecuteBasicScript(, sScript, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6), vArgs(7))
769 End Select
770 _SF_.StackLevel = 0
772 &apos; Properties in any service are got and set with obj.GetProperty/SetProperty(...)
773 ElseIf (CallType And vbGet) = vbGet Then &apos; In some cases (Calc ...) GetProperty may have an argument
774 If UBound(vArgs) &lt; 0 Then vReturn = vBasicObject.GetProperty(Script) Else vReturn = vBasicObject.GetProperty(Script, vArgs(0))
775 ElseIf (CallType And vbLet) = vbLet Then
776 vReturn = vBasicObject.SetProperty(Script, vArgs(0))
778 &apos; Methods in class modules using a 2D array or returning arrays are hardcoded as exceptions. Bug #138155
779 ElseIf ((CallType And vbMethod) + (CallType And cstArgArray)) = vbMethod + cstArgArray Or _
780 ((CallType And vbMethod) + (CallType And cstRetArray)) = vbMethod + cstRetArray Then
781 If Script = &quot;Methods&quot; Then
782 vReturn = vBasicObject.Methods()
783 ElseIf Script = &quot;Properties&quot; Then
784 vReturn = vBasicObject.Properties()
785 Else
786 Select Case sServiceName
787 Case &quot;SFDatabases.Database&quot;
788 If Script = &quot;GetRows&quot; Then vReturn = vBasicObject.GetRows(vArgs(0), vArgs(1), vArgs(2), vArgs(3))
789 Case &quot;SFDialogs.Dialog&quot;
790 If Script = &quot;Controls&quot; Then vReturn = vBasicObject.Controls(vArgs(0))
791 Case &quot;SFDialogs.DialogControl&quot;
792 If Script = &quot;SetTableData&quot; Then vReturn = vBasicObject.SetTableData(vArgs(0), vArgs(1), vArgs(2))
793 Case &quot;SFDocuments.Document&quot;
794 If Script = &quot;Forms&quot; Then vReturn = vBasicObject.Forms(vArgs(0))
795 Case &quot;SFDocuments.Base&quot;
796 Select Case Script
797 Case &quot;FormDocuments&quot; : vReturn = vBasicObject.FormDocuments()
798 Case &quot;Forms&quot; : vReturn = vBasicObject.Forms(vArgs(0), vArgs(1))
799 End Select
800 Case &quot;SFDocuments.Calc&quot;
801 Select Case Script
802 Case &quot;Charts&quot; : vReturn = vBasicObject.Charts(vArgs(0), vArgs(1))
803 Case &quot;Forms&quot; : vReturn = vBasicObject.Forms(vArgs(0), vArgs(1))
804 Case &quot;GetFormula&quot; : vReturn = vBasicObject.GetFormula(vArgs(0))
805 Case &quot;GetValue&quot; : vReturn = vBasicObject.GetValue(vArgs(0))
806 Case &quot;SetArray&quot; : vReturn = vBasicObject.SetArray(vArgs(0), vArgs(1))
807 Case &quot;SetFormula&quot; : vReturn = vBasicObject.SetFormula(vArgs(0), vArgs(1))
808 Case &quot;SetValue&quot; : vReturn = vBasicObject.SetValue(vArgs(0), vArgs(1))
809 End Select
810 Case &quot;SFDocuments.Form&quot;
811 Select Case Script
812 Case &quot;Controls&quot; : vReturn = vBasicObject.Controls(vArgs(0))
813 Case &quot;Subforms&quot; : vReturn = vBasicObject.Subforms(vArgs(0))
814 End Select
815 Case &quot;SFDocuments.FormControl&quot;
816 If Script = &quot;Controls&quot; Then vReturn = vBasicObject.Controls(vArgs(0))
817 End Select
818 End If
820 &apos; Methods in class modules may better not be executed with CallByName()
821 ElseIf bBasicClass And ((CallType And vbMethod) + (CallType And cstHardCode)) = vbMethod + cstHardCode Then
822 Select Case sServiceName
823 Case &quot;SFDialogs.Dialog&quot;
824 Select Case Script
825 Case &quot;Activate&quot; : vReturn = vBasicObject.Activate()
826 Case &quot;Center&quot;
827 If UBound(vArgs) &lt; 0 Then vReturn = vBasicObject.Center() Else vReturn = vBasicObject.Center(vArgs(0))
828 Case &quot;EndExecute&quot; : vReturn = vBasicObject.EndExecute(vArgs(0))
829 Case &quot;Execute&quot; : vReturn = vBasicObject.Execute(vArgs(0))
830 Case &quot;Resize&quot; : vReturn = vBasicObject.Resize(vArgs(0), vArgs(1), vArgs(2), vArgs(3))
831 End Select
832 End Select
834 &apos; Methods in class modules are invoked with CallByName
835 ElseIf bBasicClass And ((CallType And vbMethod) = vbMethod) Then
836 Select Case UBound(vArgs)
837 &apos; Dirty alternatives to process usual and ParamArray cases
838 &apos; But, up to ... how many ?
839 &apos; - The OFFSETADDRESSERROR has 12 arguments
840 &apos; - The &quot;.uno:DataSort&quot; command may have 14 property name-value pairs
841 Case -1 : vReturn = CallByName(vBasicObject, Script, vbMethod)
842 Case 0 : vReturn = CallByName(vBasicObject, Script, vbMethod, vArgs(0))
843 Case 1 : vReturn = CallByName(vBasicObject, Script, vbMethod, vArgs(0), vArgs(1))
844 Case 2 : vReturn = CallByName(vBasicObject, Script, vbMethod, vArgs(0), vArgs(1), vArgs(2))
845 Case 3 : vReturn = CallByName(vBasicObject, Script, vbMethod, vArgs(0), vArgs(1), vArgs(2), vArgs(3))
846 Case 4 : vReturn = CallByName(vBasicObject, Script, vbMethod, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4))
847 Case 5 : vReturn = CallByName(vBasicObject, Script, vbMethod, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5))
848 Case 6 : vReturn = CallByName(vBasicObject, Script, vbMethod, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6))
849 Case 7 : vReturn = CallByName(vBasicObject, Script, vbMethod, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6), vArgs(7))
850 Case 8 : vReturn = CallByName(vBasicObject, Script, vbMethod, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6), vArgs(7) _
851 , vArgs(8))
852 Case 9 : vReturn = CallByName(vBasicObject, Script, vbMethod, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6), vArgs(7) _
853 , vArgs(8), vArgs(9))
854 Case 10 : vReturn = CallByName(vBasicObject, Script, vbMethod, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6), vArgs(7) _
855 , vArgs(8), vArgs(9), vArgs(10))
856 Case 11 : vReturn = CallByName(vBasicObject, Script, vbMethod, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6), vArgs(7) _
857 , vArgs(8), vArgs(9), vArgs(10), vArgs(11))
858 Case 12, 13 : vReturn = CallByName(vBasicObject, Script, vbMethod, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6), vArgs(7) _
859 , vArgs(8), vArgs(9), vArgs(10), vArgs(11), vArgs(12))
860 Case 14, 15 : vReturn = CallByName(vBasicObject, Script, vbMethod, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6), vArgs(7) _
861 , vArgs(8), vArgs(9), vArgs(10), vArgs(11), vArgs(12), vArgs(13), vArgs(14))
862 Case 16, 17 : vReturn = CallByName(vBasicObject, Script, vbMethod, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6), vArgs(7) _
863 , vArgs(8), vArgs(9), vArgs(10), vArgs(11), vArgs(12), vArgs(13), vArgs(14), vArgs(15), vArgs(16))
864 Case 18, 19 : vReturn = CallByName(vBasicObject, Script, vbMethod, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6), vArgs(7) _
865 , vArgs(8), vArgs(9), vArgs(10), vArgs(11), vArgs(12), vArgs(13), vArgs(14), vArgs(15), vArgs(16), vArgs(17), vArgs(18))
866 Case 20, 21 : vReturn = CallByName(vBasicObject, Script, vbMethod, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6), vArgs(7) _
867 , vArgs(8), vArgs(9), vArgs(10), vArgs(11), vArgs(12), vArgs(13), vArgs(14), vArgs(15), vArgs(16), vArgs(17), vArgs(18) _
868 , vArgs(19), vArgs(20))
869 Case 22, 23 : vReturn = CallByName(vBasicObject, Script, vbMethod, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6), vArgs(7) _
870 , vArgs(8), vArgs(9), vArgs(10), vArgs(11), vArgs(12), vArgs(13), vArgs(14), vArgs(15), vArgs(16), vArgs(17), vArgs(18) _
871 , vArgs(19), vArgs(20), vArgs(21), vArgs(22))
872 Case 24, 25 : vReturn = CallByName(vBasicObject, Script, vbMethod, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6), vArgs(7) _
873 , vArgs(8), vArgs(9), vArgs(10), vArgs(11), vArgs(12), vArgs(13), vArgs(14), vArgs(15), vArgs(16), vArgs(17), vArgs(18) _
874 , vArgs(19), vArgs(20), vArgs(21), vArgs(22), vArgs(23), vArgs(24))
875 Case 26, 27 : vReturn = CallByName(vBasicObject, Script, vbMethod, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6), vArgs(7) _
876 , vArgs(8), vArgs(9), vArgs(10), vArgs(11), vArgs(12), vArgs(13), vArgs(14), vArgs(15), vArgs(16), vArgs(17), vArgs(18) _
877 , vArgs(19), vArgs(20), vArgs(21), vArgs(22), vArgs(23), vArgs(24), vArgs(25), vArgs(26))
878 Case &gt;= 28 : vReturn = CallByName(vBasicObject, Script, vbMethod, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6), vArgs(7) _
879 , vArgs(8), vArgs(9), vArgs(10), vArgs(11), vArgs(12), vArgs(13), vArgs(14), vArgs(15), vArgs(16), vArgs(17), vArgs(18) _
880 , vArgs(19), vArgs(20), vArgs(21), vArgs(22), vArgs(23), vArgs(24), vArgs(25), vArgs(26), vArgs(27), vArgs(28))
881 End Select
882 End If
884 &apos; Post processing
885 If Script = &quot;Dispose&quot; Then
886 &apos; Special case: Dispose() must update the cache for class objects created in Python scripts
887 Set _SF_.PythonStorage(BasicObject) = Nothing
888 End If
889 Case Else
890 End Select
892 &apos; Format the returned array
893 vReturnArray = Array()
894 &apos; Distinguish: Basic object
895 &apos; UNO object
896 &apos; Array
897 &apos; Scalar
898 If IsArray(vReturn) Then
899 ReDim vReturnArray(0 To 2)
900 iDims = SF_Array.CountDims(vReturn)
901 &apos; Replace dates by UNO format
902 If iDims = 1 Then
903 For i = LBound(vReturn) To UBound(vReturn)
904 If VarType(vReturn(i)) = V_DATE Then vReturn(i) = CDateToUnoDateTime(vReturn(i))
905 Next i
906 ElseIf iDims = 2 Then
907 For i = LBound(vReturn, 1) To UBound(vReturn, 1)
908 For j = LBound(vReturn, 2) To UBound(vReturn, 2)
909 If VarType(vReturn(i, j)) = V_DATE Then vReturn(i, j) = CDateToUnoDateTime(vReturn(i, j))
910 Next j
911 Next i
912 End If
913 vReturnArray(0) = vReturn &apos; 2D arrays are flattened by the script provider when returning to Python
914 vReturnArray(1) = VarType(vReturn)
915 vReturnArray(2) = iDims
916 ElseIf VarType(vReturn) = V_OBJECT And Not IsNull(vReturn) Then
917 &apos; Uno or not Uno ?
918 bUno = False
919 If (CallType And cstUno) = cstUno Then &apos; UNO considered only when pre-announced in CallType
920 Set oObjDesc = SF_Utils._VarTypeObj(vReturn)
921 bUno = ( oObjDesc.iVarType = V_UNOOBJECT )
922 End If
923 If bUno Then
924 ReDim vReturnArray(0 To 2)
925 Set vReturnArray(0) = vReturn
926 Else
927 ReDim vReturnArray(0 To 5)
928 vReturnArray(0) = _SF_._AddToPythonSTorage(vReturn)
929 End If
930 vReturnArray(1) = V_OBJECT
931 vReturnArray(2) = Iif(bUno, objUNO, Iif(bBasicClass, objCLASS, objMODULE))
932 If Not bUno Then
933 vReturnArray(3) = vReturn.ObjectType
934 vReturnArray(4) = vReturn.ServiceName
935 vReturnArray(5) = &quot;&quot;
936 If vReturn.ObjectType &lt;&gt; &quot;SF_CalcReference&quot; Then &apos; Calc references are implemented as a Type ... End Type data structure
937 If SF_Array.Contains(vReturn.Properties(), &quot;Name&quot;, SortOrder := &quot;ASC&quot;) Then vReturnArray(5) = vReturn.Name
938 End If
939 End If
940 Else &apos; Scalar or Nothing
941 ReDim vReturnArray(0 To 1)
942 If VarType(vReturn) = V_DATE Then vReturnArray(0) = CDateToUnoDateTime(vReturn) Else vReturnArray(0) = vReturn
943 vReturnArray(1) = VarType(vReturn)
944 End If
946 _PythonDispatcher = vReturnArray
948 Finally:
949 _SF_.TriggeredByPython = False &apos; Reset normal state
950 Exit Function
951 Catch:
952 GoTo Finally
953 End Function &apos; ScriptForge.SF_PythonHelper._PythonDispatcher
955 REM -----------------------------------------------------------------------------
956 Private Function _Repr() As String
957 &apos;&apos;&apos; Convert the Basic instance to a readable string, typically for debugging purposes (DebugPrint ...)
958 &apos;&apos;&apos; Args:
959 &apos;&apos;&apos; Return:
960 &apos;&apos;&apos; &quot;[PythonHelper]&quot;
962 _Repr = &quot;[PythonHelper]&quot;
964 End Function &apos; ScriptForge.SF_PythonHelper._Repr
966 REM ================================================= END OF SCRIPTFORGE.SF_PythonHelper
967 </script:module>