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=
"Python" script:
language=
"StarBasic">
4 REM =======================================================================================================================
5 REM === The Access2Base library is a part of the LibreOffice project. ===
6 REM === Full documentation is available on http://www.access2base.com ===
7 REM =======================================================================================================================
12 REM -----------------------------------------------------------------------------------------------------------------------
13 Public Sub DebugPrint(ParamArray pvArgs() As Variant)
15 'Print arguments unconditionally in console
16 'Arguments are separated by a TAB (simulated by spaces)
17 'Some pvArgs might be missing: a TAB is still generated
19 Dim vVarTypes() As Variant, i As Integer
21 On Local Error Goto Exit_Sub
' Never interrupt processing
22 Utils._SetCalledSub(
"DebugPrint
")
23 vVarTypes = Utils._AddNumeric(Array(vbEmpty, vbNull, vbDate, vbString, vbBoolean, vbObject, vbVariant, vbByte, vbArray + vbByte))
25 If UBound(pvArgs)
>=
0 Then
26 For i =
0 To UBound(pvArgs)
27 If Not Utils._CheckArgument(pvArgs(i), i +
1, vVarTypes(), , False) Then pvArgs(i) =
"[TYPE?]
"
31 Dim sOutput As String, sArg As String
32 sOutput =
""
33 For i =
0 To UBound(pvArgs)
34 sArg = Replace(Utils._CStr(pvArgs(i), _A2B_.DebugPrintShort),
"\;
",
";
")
35 ' Add argument to output
39 sOutput = sOutput
& Space(cstTab - (Len(sOutput) Mod cstTab))
& sArg
43 TraceLog(TRACEANY, sOutput, False)
46 Utils._ResetCalledSub(
"DebugPrint
")
48 End Sub
' DebugPrint V0.9
.5
50 REM -----------------------------------------------------------------------------------------------------------------------
51 REM --- PYTHON WRAPPERS ---
52 REM -----------------------------------------------------------------------------------------------------------------------
54 REM -----------------------------------------------------------------------------------------------------------------------
55 Public Function PythonEventsWrapper(Optional poEvent As Variant) As Variant
56 ' Python wrapper when Application.Events() method is invoked
57 ' The ParamArray mechanism empties UNO objects when they are member of the arguments list
58 ' As a workaround, the Application.Events function is executed directly
60 If _ErrorHandler() Then On Local Error GoTo Exit_Function
' Do never interrupt
61 PythonEventsWrapper = Null
63 Dim vReturn As Variant, vArray As Variant
66 vReturn = Application.Events(poEvent)
67 vArray = Array(cstObject, _A2B_.AddPython(vReturn), vReturn._Type)
69 PythonEventsWrapper = vArray
73 End Function
' PythonEventsWrapper V6.4
75 REM -----------------------------------------------------------------------------------------------------------------------
76 Public Function PythonWrapper(ByVal pvCallType As Variant _
77 , ByVal pvObject As Variant _
78 , ByVal pvScript As Variant _
79 , ParamArray pvArgs() As Variant _
81 ' Called from Python to apply
82 ' - on object with entry pvObject in PythonCache
83 ' Conventionally: -
1 = Application
85 ' - a script pvScript which type is described by pvCallType
86 ' - with arguments pvArgs(
0)... (max.
8 for object methods)
87 ' The value returned by the method/property is encapsulated in an array
88 ' [
0] =
> 0 = scalar or array returned by the method
89 ' =
> 1 = basic object returned by the method
90 ' =
> 2 = a null value
91 ' [
1] =
> the object reference or the returned value (complemented with arguments passed by reference, if any) or Null
92 ' [
2] =
> the object type or Null
93 ' [
3] =
> the object name, if any
94 ' or, when pvCallType == vbUNO, as the UNO object returned by the property
96 Dim vReturn As Variant, vArray As Variant
97 Dim vObject As Variant, sScript As String, sModule As String
98 Dim i As Integer, iNbArgs As Integer, vArg As Variant, vArgs() As Variant
100 Const cstApplication = -
1, cstDoCmd = -
2
101 Const cstScalar =
0, cstObject =
1, cstNull =
2, cstUNO =
3
103 'Conventional special values
104 Const cstNoArgs =
"+++NOARGS+++
", cstSymEmpty =
"+++EMPTY+++
", cstSymNull =
"+++NULL+++
", cstSymMissing =
"+++MISSING+++
"
106 'https://support.office.com/en-us/article/CallByName-fonction-
49ce9475-c315-
4f13-
8d35-e98cfe98729a
107 'Determines the pvCallType
108 Const vbGet =
2, vbLet =
4, vbMethod =
1, vbSet =
8, vbUNO =
16
110 If _ErrorHandler() Then On Local Error GoTo Error_Function
113 'Reinterpret arguments one by one into vArgs, examine iso-dates and conventional NoArgs/Empty/Null values
116 If UBound(pvArgs)
>=
0 Then
117 For i =
0 To UBound(pvArgs)
119 If i =
0 And VarType(vArg) = vbString Then
120 If vArg = cstNoArgs Then Exit For
122 If VarType(vArg) = vbString Then
123 If vArg = cstSymEmpty Then
125 ElseIf vArg = cstSymNull Then
127 ElseIf vArg = cstSymMissing Then
128 Exit For
' Next arguments must be missing also
133 iNbArgs = iNbArgs +
1
134 ReDim Preserve vArgs(iNbArgs)
135 vArgs(iNbArgs) = vArg
140 Select Case pvObject
' Always numeric
142 sModule =
"Application
"
144 Case
"AllDialogs
" : If iNbArgs
< 0 Then vReturn = Application.AllDialogs() Else vReturn = Application.AllDialogs(vArgs(
0))
145 Case
"AllForms
" : If iNbArgs
< 0 Then vReturn = Application.AllForms() Else vReturn = Application.AllForms(vArgs(
0))
146 Case
"AllModules
" : If iNbArgs
< 0 Then vReturn = Application.AllModules() Else vReturn = Application.AllModules(vArgs(
0))
147 Case
"CloseConnection
"
148 vReturn = Application.CloseConnection()
149 Case
"CommandBars
" : If iNbArgs
< 0 Then vReturn = Application.CommandBars() Else vReturn = Application.CommandBars(vArgs(
0))
150 Case
"CurrentDb
" : vReturn = Application.CurrentDb()
151 Case
"CurrentUser
" : vReturn = Application.CurrentUser()
152 Case
"DAvg
" : vReturn = Application.DAvg(vArgs(
0), vArgs(
1), vArgs(
2))
153 Case
"DCount
" : vReturn = Application.DCount(vArgs(
0), vArgs(
1), vArgs(
2))
154 Case
"DLookup
" : vReturn = Application.DLookup(vArgs(
0), vArgs(
1), vArgs(
2), vArgs(
3))
155 Case
"DMax
" : vReturn = Application.DMax(vArgs(
0), vArgs(
1), vArgs(
2))
156 Case
"DMin
" : vReturn = Application.DMin(vArgs(
0), vArgs(
1), vArgs(
2))
157 Case
"DStDev
" : vReturn = Application.DStDev(vArgs(
0), vArgs(
1), vArgs(
2))
158 Case
"DStDevP
" : vReturn = Application.DStDevP(vArgs(
0), vArgs(
1), vArgs(
2))
159 Case
"DSum
" : vReturn = Application.DSum(vArgs(
0), vArgs(
1), vArgs(
2))
160 Case
"DVar
" : vReturn = Application.DVar(vArgs(
0), vArgs(
1), vArgs(
2))
161 Case
"DVarP
" : vReturn = Application.DVarP(vArgs(
0), vArgs(
1), vArgs(
2))
162 Case
"Forms
" : If iNbArgs
< 0 Then vReturn = Application.Forms() Else vReturn = Application.Forms(vArgs(
0))
163 Case
"getObject
" : vReturn = Application.getObject(vArgs(
0))
164 Case
"getValue
" : vReturn = Application.getValue(vArgs(
0))
165 Case
"HtmlEncode
" : vReturn = Application.HtmlEncode(vArgs(
0), vArgs(
1))
166 Case
"OpenDatabase
" : vReturn = Application.OpenDatabase(vArgs(
0), vArgs(
1), vArgs(
2), vArgs(
3))
167 Case
"ProductCode
" : vReturn = Application.ProductCode()
168 Case
"setValue
" : vReturn = Application.setValue(vArgs(
0), vArgs(
1))
169 Case
"SysCmd
" : vReturn = Application.SysCmd(vArgs(
0), vArgs(
1), vARgs(
2))
170 Case
"TempVars
" : If iNbArgs
< 0 Then vReturn = Application.TempVars() Else vReturn = Application.TempVars(vArgs(
0))
171 Case
"Version
" : vReturn = Application.Version()
176 sModule =
"DoCmd
"
178 Case
"ApplyFilter
" : vReturn = DoCmd.ApplyFilter(vArgs(
0), vArgs(
1), vArgs(
2))
179 Case
"Close
" : vReturn = DoCmd.mClose(vArgs(
0), vArgs(
1), vArgs(
2))
180 Case
"CopyObject
" : vReturn = DoCmd.CopyObject(vArgs(
0), vArgs(
1), vArgs(
2), vArgs(
3))
181 Case
"FindNext
" : vReturn = DoCmd.FindNext()
182 Case
"FindRecord
" : vReturn = DoCmd.FindRecord(vArgs(
0), vArgs(
1), vArgs(
2), vArgs(
3), vArgs(
4), vArgs(
5), vArgs(
6))
183 Case
"GetHiddenAttribute
"
184 vReturn = DoCmd.GetHiddenAttribute(vArgs(
0), vArgs(
1))
185 Case
"GoToControl
" : vReturn = DoCmd.GoToControl(vArgs(
0))
186 Case
"GoToRecord
" : vReturn = DoCmd.GoToRecord(vArgs(
0), vArgs(
1), vArgs(
2), vArgs(
3))
187 Case
"Maximize
" : vReturn = DoCmd.Maximize()
188 Case
"Minimize
" : vReturn = DoCmd.Minimize()
189 Case
"MoveSize
" : vReturn = DoCmd.MoveSize(vArgs(
0), vArgs(
1), vArgs(
2), vArgs(
3))
190 Case
"OpenForm
" : vReturn = DoCmd.OpenForm(vArgs(
0), vArgs(
1), vArgs(
2), vArgs(
3), vArgs(
4), vArgs(
5), vArgs(
6))
191 Case
"OpenQuery
" : vReturn = DoCmd.OpenQuery(vArgs(
0), vArgs(
1), vArgs(
2))
192 Case
"OpenReport
" : vReturn = DoCmd.OpenReport(vArgs(
0), vArgs(
1))
193 Case
"OpenSQL
" : vReturn = DoCmd.OpenSQL(vArgs(
0), vArgs(
1))
194 Case
"OpenTable
" : vReturn = DoCmd.OpenTable(vArgs(
0), vArgs(
1), vArgs(
2))
195 Case
"OutputTo
" : vReturn = DoCmd.OutputTo(vArgs(
0), vArgs(
1), vArgs(
2), vArgs(
3), vArgs(
4), vArgs(
5), vArgs(
6), vArgs(
7))
196 Case
"Quit
" : _A2B_.CalledSub =
"Quit
" : GoTo Error_Action
197 Case
"RunApp
" : vReturn = DoCmd.RunApp(vArgs(
0))
198 Case
"RunCommand
" : vReturn = DoCmd.RunCommand(vArgs(
0))
199 Case
"RunSQL
" : vReturn = DoCmd.RunSQL(vArgs(
0), vArgs(
1))
200 Case
"SelectObject
" : vReturn = DoCmd.SelectObject(vArgs(
0), vArgs(
1), vArgs(
2))
201 Case
"SendObject
" : vReturn = DoCmd.SendObject(vArgs(
0), vArgs(
1), vArgs(
2), vArgs(
3), vArgs(
4), vArgs(
5), vArgs(
6), vArgs(
7), vArgs(
8), vArgs(
9))
202 Case
"SetHiddenAttribute
"
203 vReturn = DoCmd.SetHiddenAttribute(vArgs(
0), vArgs(
1), vArgs(
2))
204 Case
"SetOrderBy
" : vReturn = DoCmd.SetOrderBy(vArgs(
0), vArgs(
1))
205 Case
"ShowAllRecords
"
206 vReturn = DoCmd.ShowAllRecords()
211 ' Locate targeted object
212 If pvObject
> UBound(_A2B_.PythonCache) Or pvObject
< 0 Then GoTo Error_Object
213 Set vObject = _A2B_.PythonCache(pvObject)
214 If IsNull(vObject) Then
215 If pvScript =
"Dispose
" Then GoTo Exit_Function Else GoTo Error_Object
219 sModule = vObject._Type
222 If vObject._Type =
"COLLECTION
" And vObject._CollType = COLLTABLEDEFS Then vArgs = Array(_A2B_.PythonCache(vArgs(
0)))
223 Case
"Close
"
224 sSCript =
"mClose
"
225 Case
"Type
"
226 sScript =
"pType
"
229 ' Execute method
230 Select Case UBound(vArgs)
' Dirty but ... CallByName does not support an array of arguments or return values
232 If pvCallType = vbUNO Then
234 Select Case sScript
' List all properties that should be called directly (UNO)
235 Case
"BoundField
" : vReturn = .BoundField
236 Case
"Column
" : vReturn = .Column
237 Case
"Connection
" : vReturn = .Connection
238 case
"ContainerWindow
" : vReturn = .ContainerWindow
239 Case
"ControlModel
" : vReturn = .ControlModel
240 Case
"ControlView
" : vReturn = .ControlView
241 Case
"DatabaseForm
" : vReturn = .DatabaseForm
242 Case
"Document
" : vReturn = .Document
243 Case
"FormsCollection
" : vReturn = .FormsCollection
244 Case
"LabelControl
" : vReturn = .LabelControl
245 Case
"MetaData
" : vReturn = .MetaData
246 Case
"ParentComponent
" : vReturn = .ParentComponent
247 Case
"Query
" : vReturn = .Query
248 Case
"RowSet
" : vReturn = .RowSet
249 Case
"Table
" : vReturn = .Table
250 Case
"UnoDialog
" : vReturn = .UnoDialog
254 ElseIf sScript =
"ItemData
" Then
' List all properties that should be called directly (arrays not supported by CallByName)
255 vReturn = vObject.ItemData
256 ElseIf sScript =
"LinkChildFields
" Then
257 vReturn = vObject.LinkChildFields
258 ElseIf sScript =
"LinkMasterFields
" Then
259 vReturn = vObject.LinkMasterFields
260 ElseIf sScript =
"OpenArgs
" Then
261 vReturn = vObject.OpenArgs
262 ElseIf sScript =
"Selected
" Then
263 vReturn = vObject.Selected
264 ElseIf sScript =
"Value
" Then
265 vReturn = vObject.Value
267 vReturn = CallByName(vObject, sScript, pvCallType)
271 Case
"AppendChunk
" ' Arg is a vector, not supported by CallByName
272 vReturn = vObject.GetChunk(vArgs(
0), vArgs(
1))
273 Case
"GetRows
" ' Returns an array, not supported by CallByName
274 vReturn = vObject.GetRows(vArgs(
0), True)
' Force iso dates
276 vReturn = CallByName(vObject, sScript, pvCallType, vArgs(
0))
280 Case
"GetChunk
" ' Returns a vector, not supported by CallByName
281 vReturn = vObject.GetChunk(vArgs(
0), vArgs(
1))
283 vReturn = CallByName(vObject, sScript, pvCallType, vArgs(
0), vArgs(
1))
285 Case
2 : vReturn = CallByName(vObject, sScript, pvCallType, vArgs(
0), vArgs(
1), vArgs(
2))
286 Case
3 : vReturn = CallByName(vObject, sScript, pvCallType, vArgs(
0), vArgs(
1), vArgs(
2), vArgs(
3))
287 Case
4 : vReturn = CallByName(vObject, sScript, pvCallType, vArgs(
0), vArgs(
1), vArgs(
2), vArgs(
3), vArgs(
4))
288 Case
5 : vReturn = CallByName(vObject, sScript, pvCallType, vArgs(
0), vArgs(
1), vArgs(
2), vArgs(
3), vArgs(
4), vArgs(
5))
289 Case
6 : vReturn = CallByName(vObject, sScript, pvCallType, vArgs(
0), vArgs(
1), vArgs(
2), vArgs(
3), vArgs(
4), vArgs(
5), vArgs(
6))
290 Case
7 : vReturn = CallByName(vObject, sScript, pvCallType, vArgs(
0), vArgs(
1), vArgs(
2), vArgs(
3), vArgs(
4), vArgs(
5), vArgs(
6), vArgs(
7))
292 ' Postprocessing
294 Case
"Close
",
"Dispose
",
"Terminate
"
295 Set _A2B_.PythonCache(pvObject) = Nothing
296 Case
"Move
",
"MoveFirst
",
"MoveLast
",
"MoveNext
",
"MovePrevious
" ' Pass the new BOF, EOF values (binary format)
297 If vObject._Type =
"RECORDSET
" Then
298 vReturn = (Iif(vObject.BOF,
1,
0) *
2 + Iif(vObject.EOF,
1,
0)) * Iif(vReturn,
1, -
1)
300 Case
"Find
" ' Store in array the arguments passed by reference
301 If vObject._Type =
"MODULE
" And vReturn = True Then
302 vReturn = Array(vReturn, vArgs(
1), vArgs(
2), vArgs(
3), vArgs(
4))
304 Case
"ProcOfLine
" ' Store in array the arguments passed by reference
305 vReturn = Array(vReturn, vArgs(
1))
310 ' Structure the returned array
311 If pvCallType = vbUNO Then
314 If IsNull(vReturn) Then
315 vArray = Array(cstNull, Null, Null)
316 ElseIf IsObject(vReturn) Then
317 Select Case vReturn._Type
318 Case
"COLLECTION
",
"COMMANDBARCONTROL
",
"EVENT
"
319 vArray = Array(cstObject, _A2B_.AddPython(vReturn), vReturn._Type)
321 vArray = Array(cstObject, _A2B_.AddPython(vReturn), vReturn._Type, vReturn.Name)
324 If VarType(vReturn) = vbDate Then
325 vArray = Array(cstScalar, _CStr(vReturn), Null)
326 ElseIf VarType(vReturn) = vbBigint Then
' Could happen for big integer database fields
327 vArray = Array(cstScalar, CLng(vReturn), Null)
329 vArray = Array(cstScalar, vReturn, Null)
334 PythonWrapper = vArray
339 TraceError(TRACEABORT, Err,
"PythonWrapper
", Erl)
342 TraceError(TRACEFATAL, ERROBJECTNOTFOUND,
"Python Wrapper (
" & pvScript
& ")
",
0, , Array(_GetLabel(
"OBJECT
"),
"#
" & pvObject))
345 TraceError(TRACEFATAL, ERRACTION, Utils._CalledSub(),
0)
348 TraceError(TRACEFATAL, ERRPROCEDURENOTFOUND,
"Python Wrapper
",
0, , Array(pvScript, sModule))
350 End Function
' PythonWrapper V6.4
352 REM -----------------------------------------------------------------------------------------------------------------------
353 REM --- PYTHON HELPER FUNCTIONS ---
354 REM -----------------------------------------------------------------------------------------------------------------------
356 REM -----------------------------------------------------------------------------------------------------------------------
357 Public Function PyConvertFromUrl(ByVal pvFile As Variant) As String
358 ' Convenient function to have common conversions of filenames from/to url notations both in Python and Basic
360 On Local Error GoTo Exit_Function
361 PyConvertFromUrl =
""
362 If Not Utils._CheckArgument(pvFile,
1, vbString) Then Goto Exit_Function
364 PyConvertFromUrl = ConvertFromUrl(pvFile)
368 End Function
' PyConvertFromUrl V6.4
370 REM -----------------------------------------------------------------------------------------------------------------------
371 Public Function PyConvertToUrl(ByVal pvFile As Variant) As String
372 ' Convenient function to have common conversions of filenames from/to url notations both in Python and Basic
374 On Local Error GoTo Exit_Function
375 PyConvertToUrl =
""
376 If Not Utils._CheckArgument(pvFile,
1, vbString) Then Goto Exit_Function
378 PyConvertToUrl = ConvertToUrl(pvFile)
382 End Function
' PyConvertToUrl V6.4
384 REM -----------------------------------------------------------------------------------------------------------------------
385 Public Function PyCreateUnoService(ByVal pvService As Variant) As Variant
386 ' Convenient function to create a UNO service in Python
388 On Local Error GoTo Exit_Function
389 Set PyCreateUnoService = Nothing
390 If Not Utils._CheckArgument(pvService,
1, vbString) Then Goto Exit_Function
392 Set PyCreateUnoService = CreateUnoService(pvService)
396 End Function
' PyCreateUnoService V6.4
398 REM -----------------------------------------------------------------------------------------------------------------------
399 Public Function PyDateAdd(ByVal pvAdd As Variant _
400 , ByVal pvCount As Variant _
401 , ByVal pvDate As Variant _
403 ' Convenient shortcut to useful and easy-to-use Basic date functions
405 Dim vDate As Variant, vNewDate As Variant
406 On Local Error GoTo Exit_Function
409 If Not Utils._CheckArgument(pvAdd,
1, vbString) Then Goto Exit_Function
410 If Not Utils._CheckArgument(pvCount,
2, Utils._AddNumeric()) Then Goto Exit_Function
411 If Not Utils._CheckArgument(pvDate,
3, vbString) Then Goto Exit_Function
413 vDate = _CDate(pvDate)
414 vNewDate = DateAdd(pvAdd, pvCount, vDate)
415 If VarType(vNewDate) = vbDate Then PyDateAdd = _CStr(vNewDate) Else PyDateAdd = vNewDate
419 End Function
' PyDateAdd V6.4
421 REM -----------------------------------------------------------------------------------------------------------------------
422 Public Function PyDateDiff(ByVal pvAdd As Variant _
423 , ByVal pvDate1 As Variant _
424 , ByVal pvDate2 As Variant _
425 , ByVal pvWeekStart As Variant _
426 , ByVal pvYearStart As Variant _
428 ' Convenient shortcut to useful and easy-to-use Basic date functions
430 Dim vDate1 As Variant, vDate2 As Variant
431 On Local Error GoTo Exit_Function
434 If Not Utils._CheckArgument(pvAdd,
1, vbString) Then Goto Exit_Function
435 If Not Utils._CheckArgument(pvDate1,
2, vbString) Then Goto Exit_Function
436 If Not Utils._CheckArgument(pvDate2,
3, vbString) Then Goto Exit_Function
437 If Not Utils._CheckArgument(pvWeekStart,
4, Utils._AddNumeric()) Then Goto Exit_Function
438 If Not Utils._CheckArgument(pvWeekStart,
5, Utils._AddNumeric()) Then Goto Exit_Function
440 vDate1 = _CDate(pvDate1)
441 vDate2 = _CDate(pvDate2)
442 PyDateDiff = DateDiff(pvAdd, vDate1, vDate2, pvWeekStart, pvYearStart)
446 End Function
' PyDateDiff V6.4
448 REM -----------------------------------------------------------------------------------------------------------------------
449 Public Function PyDatePart(ByVal pvAdd As Variant _
450 , ByVal pvDate As Variant _
451 , ByVal pvWeekStart As Variant _
452 , ByVal pvYearStart As Variant _
454 ' Convenient shortcut to useful and easy-to-use Basic date functions
457 On Local Error GoTo Exit_Function
460 If Not Utils._CheckArgument(pvAdd,
1, vbString) Then Goto Exit_Function
461 If Not Utils._CheckArgument(pvDate,
2, vbString) Then Goto Exit_Function
462 If Not Utils._CheckArgument(pvWeekStart,
3, Utils._AddNumeric()) Then Goto Exit_Function
463 If Not Utils._CheckArgument(pvWeekStart,
4, Utils._AddNumeric()) Then Goto Exit_Function
465 vDate = _CDate(pvDate)
466 PyDatePart = DatePart(pvAdd, vDate, pvWeekStart, pvYearStart)
470 End Function
' PyDatePart V6.4
472 REM -----------------------------------------------------------------------------------------------------------------------
473 Public Function PyDateValue(ByVal pvDate As Variant) As Variant
474 ' Convenient shortcut to useful and easy-to-use Basic date functions
477 On Local Error GoTo Exit_Function
479 If Not Utils._CheckArgument(pvDate,
1, vbString) Then Goto Exit_Function
481 vDate = DateValue(pvDate)
482 If VarType(vDate) = vbDate Then PyDateValue = _CStr(vDate) Else PyDateValue = vDate
486 End Function
' PyDateValue V6.4
488 REM -----------------------------------------------------------------------------------------------------------------------
489 Public Function PyFormat(ByVal pvValue As Variant, pvFormat As Variant) As String
490 ' Convenient function to format numbers or dates
492 On Local Error GoTo Exit_Function
493 PyFormat =
""
494 If Not Utils._CheckArgument(pvValue,
1, Utils._AddNumeric(vbString)) Then Goto Exit_Function
495 pvValue = _CDate(pvValue)
496 If IsEmpty(pvFormat) Then
497 PyFormat = Str(pvValue)
499 If Not Utils._CheckArgument(pvFormat,
2, vbString) Then Goto Exit_Function
500 PyFormat = Format(pvValue, pvFormat)
505 End Function
' PyFormat V6.4
507 REM -----------------------------------------------------------------------------------------------------------------------
508 Public Function PyGetGUIType() As Variant
510 PyGetGUIType = GetGUIType()
512 End Function
' PyGetGUIType V6.4
514 REM -----------------------------------------------------------------------------------------------------------------------
515 Public Function PyGetSystemTicks() As Variant
517 PyGetSystemTicks = GetSystemTicks()
519 End Function
' PyGetSystemTicks V6.4
521 REM -----------------------------------------------------------------------------------------------------------------------
522 Public Function PyGlobalScope(ByVal pvLib As Variant) As Variant
525 Case
"Basic
"
526 PyGlobalScope = GlobalScope.BasicLibraries()
527 Case
"Dialog
"
528 PyGlobalScope = GlobalScope.DialogLibraries()
532 End Function
' PyGlobalScope V6.4
534 REM -----------------------------------------------------------------------------------------------------------------------
535 Public Function PyInputBox(ByVal pvText As Variant _
536 , ByVal pvTitle As Variant _
537 , ByVal pvDefault As Variant _
538 , ByVal pvXPos As Variant _
539 , ByVal pvYPos As Variant _
541 ' Convenient function to open input box from Python
543 On Local Error GoTo Exit_Function
546 If Not Utils._CheckArgument(pvText,
1, vbString) Then Goto Exit_Function
547 If IsEmpty(pvTitle) Then pvTitle =
""
548 If Not Utils._CheckArgument(pvTitle,
2, vbString) Then Goto Exit_Function
549 If IsEmpty(pvDefault) Then pvDefault =
""
550 If Not Utils._CheckArgument(pvDefault,
3, vbString) Then Goto Exit_Function
552 If IsEmpty(pvXPos) Or IsEmpty(pvYPos) Then
553 PyInputBox = InputBox(pvText, pvTitle, pvDefault)
555 If Not Utils._CheckArgument(pvXPos,
4, Utils._AddNumeric()) Then Goto Exit_Function
556 If Not Utils._CheckArgument(pvYPos,
5, Utils._AddNumeric()) Then Goto Exit_Function
557 PyInputBox = InputBox(pvText, pvTitle, pvDefault, pvXPos, pvYPos)
562 End Function
' PyInputBox V6.4
.0
564 REM -----------------------------------------------------------------------------------------------------------------------
565 Public Function PyMsgBox(ByVal pvText As Variant _
566 , ByVal pvType As Variant _
567 , ByVal pvDialogTitle As Variant _
569 ' Convenient function to open message box from Python
571 On Local Error GoTo Exit_Function
574 If Not Utils._CheckArgument(pvText,
1, vbString) Then Goto Exit_Function
575 If IsEmpty(pvType) Then pvType =
0
576 If Not Utils._CheckArgument(pvType,
2, Utils._AddNumeric()) Then Goto Exit_Function
577 If IsEmpty(pvDialogTitle) Then
578 PyMsgBox = MsgBox(pvText, pvType)
580 If Not Utils._CheckArgument(pvDialogTitle,
3, vbString) Then Goto Exit_Function
581 PyMsgBox = MsgBox(pvText, pvType, pvDialogTitle)
586 End Function
' PyMsgBox V6.4
.0
588 REM -----------------------------------------------------------------------------------------------------------------------
589 Public Function PyTimer() As Long
590 ' Convenient function to call Timer from Python
594 End Function
' PyTimer V6.4
596 REM -----------------------------------------------------------------------------------------------------------------------
597 REM --- PRIVATE FUNCTIONS ---
598 REM -----------------------------------------------------------------------------------------------------------------------
600 REM -----------------------------------------------------------------------------------------------------------------------
601 Private Function _CDate(ByVal pvValue As Variant) As Variant
602 ' Return a Date type if iso date, otherwise return input
604 Dim vValue As Variant
606 If VarType(pvValue) = vbString Then
607 If pvValue
<> "" And IsDate(pvValue) Then vValue = CDate(pvValue)
' IsDate(
"") gives True !?