1 # -*- coding: utf-8 -*-
3 # Copyright 2012-2020 Jean-Pierre LEDURE
5 # =====================================================================================================================
6 # === The Access2Base library is a part of the LibreOffice project. ===
7 # === Full documentation is available on http://www.access2base.com ===
8 # =====================================================================================================================
10 # Access2Base is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 # Access2Base is free software; you can redistribute it and/or modify it under the terms of either (at your option):
16 # 1) The Mozilla Public License, v. 2.0. If a copy of the MPL was not
17 # distributed with this file, you can obtain one at http://mozilla.org/MPL/2.0/ .
19 # 2) The GNU Lesser General Public License as published by
20 # the Free Software Foundation, either version 3 of the License, or
21 # (at your option) any later version. If a copy of the LGPL was not
22 # distributed with this file, see http://www.gnu.org/licenses/ .
25 The access2base.py module implements an interface between Python (user) scripts and the Access2Base Basic library.
28 from access2base import *
29 Additionally, if Python and LibreOffice are started in separate processes:
30 If LibreOffice started from console ... (example for Linux)
31 ./soffice --accept='socket,host=localhost,port=2019;urp;'
32 then insert next statement
33 A2BConnect(hostname = 'localhost', port = 2019)
35 Specific documentation about Access2Base and Python:
36 http://www.access2base.com/access2base.html#%5B%5BAccess2Base%20and%20Python%5D%5D
42 from platform
import system
as _opsys
43 import datetime
, os
, sys
, traceback
45 _LIBRARY
= '' # Should be 'Access2Base' or 'Access2BaseDev'
46 _VERSION
= '7.4' # Actual version number
47 _WRAPPERMODULE
= 'Python' # Module name in the Access2Base library containing Python interfaces
50 _vbGet
, _vbLet
, _vbMethod
, _vbSet
, _vbUNO
= 2, 4, 1, 8, 16
53 class _Singleton(type):
55 A Singleton design pattern
56 Credits: « Python in a Nutshell » by Alex Martelli, O'Reilly
59 def __call__(cls
, *args
, **kwargs
):
60 if cls
not in cls
.instances
:
61 cls
.instances
[cls
] = super(_Singleton
, cls
).__call
__(*args
, **kwargs
)
62 return cls
.instances
[cls
]
65 class acConstants(object, metaclass
= _Singleton
):
67 VBA constants used in the Access2Base API.
68 Values derived from MSAccess, except when conflicts
70 # Python special constants (used in the protocol between Python and Basic)
71 # -----------------------------------------------------------------
74 Missing
= '+++MISSING+++'
75 FromIsoFormat
= '%Y-%m-%d %H:%M:%S' # To be used with datetime.datetime.strptime()
78 # -----------------------------------------------------------------
84 # -----------------------------------------------------------------
90 # -----------------------------------------------------------------
93 acFormPropertySettings
= -1
97 # -----------------------------------------------------------------
103 # -----------------------------------------------------------------
109 # -----------------------------------------------------------------
116 # Unexisting in MS/Access
118 acDatabaseWindow
= 102
121 # Subtype if acDocument
124 docImpress
= "Impress"
129 # -----------------------------------------------------------------
136 # -----------------------------------------------------------------
157 # -----------------------------------------------------------------
158 vbOKOnly
= 0 # OK button only (default)
159 vbOKCancel
= 1 # OK and Cancel buttons
160 vbAbortRetryIgnore
= 2 # Abort, Retry, and Ignore buttons
161 vbYesNoCancel
= 3 # Yes, No, and Cancel buttons
162 vbYesNo
= 4 # Yes and No buttons
163 vbRetryCancel
= 5 # Retry and Cancel buttons
164 vbCritical
= 16 # Critical message
165 vbQuestion
= 32 # Warning query
166 vbExclamation
= 48 # Warning message
167 vbInformation
= 64 # Information message
168 vbDefaultButton1
= 128 # First button is default (default) (VBA: 0)
169 vbDefaultButton2
= 256 # Second button is default
170 vbDefaultButton3
= 512 # Third button is default
171 vbApplicationModal
= 0 # Application modal message box (default)
172 # MsgBox Return Values
173 # -----------------------------------------------------------------
174 vbOK
= 1 # OK button pressed
175 vbCancel
= 2 # Cancel button pressed
176 vbAbort
= 3 # Abort button pressed
177 vbRetry
= 4 # Retry button pressed
178 vbIgnore
= 5 # Ignore button pressed
179 vbYes
= 6 # Yes button pressed
180 vbNo
= 7 # No button pressed
182 # Dialogs Return Values
183 # ------------------------------------------------------------------
184 dlgOK
= 1 # OK button pressed
185 dlgCancel
= 0 # Cancel button pressed
188 # -----------------------------------------------------------------
196 acFixedLine
= 24 # FREE ENTRY (USEFUL IN DIALOGS)
199 acFormattedField
= 1 # FREE ENTRY TAKEN TO NOT CONFUSE WITH acTextField
211 acProgressBar
= 23 # FREE ENTRY (USEFUL IN DIALOGS)
222 # -----------------------------------------------------------------
231 # -----------------------------------------------------------------
242 # -----------------------------------------------------------------
243 acActiveDataObject
= -1
247 acDataStoredProcedure
= 9
251 # -----------------------------------------------------------------
257 # -----------------------------------------------------------------
258 acCmdAboutMicrosoftAccess
= 35
259 acCmdAboutOpenOffice
= 35
260 acCmdAboutLibreOffice
= 35
261 acCmdVisualBasicEditor
= 525
262 acCmdBringToFront
= 52
264 acCmdToolbarsCustomize
= 165
265 acCmdChangeToCommandButton
= 501
266 acCmdChangeToCheckBox
= 231
267 acCmdChangeToComboBox
= 230
268 acCmdChangeToTextBox
= 227
269 acCmdChangeToLabel
= 228
270 acCmdChangeToImage
= 234
271 acCmdChangeToListBox
= 229
272 acCmdChangeToOptionButton
= 233
275 acCmdCreateRelationship
= 150
277 acCmdDatabaseProperties
= 256
280 acCmdDesignView
= 183
282 acCmdNewObjectForm
= 136
283 acCmdNewObjectTable
= 134
284 acCmdNewObjectView
= 350
285 acCmdOpenDatabase
= 25
286 acCmdNewObjectQuery
= 135
287 acCmdShowAllRelationships
= 149
288 acCmdNewObjectReport
= 137
290 acCmdRemoveTable
= 84
293 acCmdDeleteRecord
= 223
294 acCmdApplyFilterSort
= 93
297 acCmdInsertHyperlink
= 259
298 acCmdMaximumRecords
= 508
299 acCmdObjectBrowser
= 200
301 acCmdPasteSpecial
= 64
303 acCmdPrintPreview
= 54
308 acCmdRemoveFilterSort
= 144
312 acCmdSelectAllRecords
= 109
314 acCmdSortDescending
= 164
315 acCmdSortAscending
= 163
317 acCmdDatasheetView
= 282
318 acCmdZoomSelection
= 371
321 # -----------------------------------------------------------------
329 # -----------------------------------------------------------------
336 # -----------------------------------------------------------------
340 # -----------------------------------------------------------------
341 acFormatPDF
= "writer_pdf_Export"
342 acFormatODT
= "writer8"
343 acFormatDOC
= "MS Word 97"
344 acFormatHTML
= "HTML"
345 acFormatODS
= "calc8"
346 acFormatXLS
= "MS Excel 97"
347 acFormatXLSX
= "Calc MS Excel 2007 XML"
348 acFormatTXT
= "Text - txt - csv (StarCalc)"
351 # -----------------------------------------------------------------
352 acExportQualityPrint
= 0
353 acExportQualityScreen
= 1
356 # -----------------------------------------------------------------
357 acSysCmdAccessDir
= 9
358 acSysCmdAccessVer
= 7
359 acSysCmdClearHelpTopic
= 11
360 acSysCmdClearStatus
= 5
361 acSysCmdGetObjectState
= 10
362 acSysCmdGetWorkgroupFile
= 13
364 acSysCmdInitMeter
= 1
366 acSysCmdRemoveMeter
= 3
368 acSysCmdSetStatus
= 4
369 acSysCmdUpdateMeter
= 2
372 # -----------------------------------------------------------------
386 dbLongBinary
= 11 # (OLE Object)
396 # Attributes property
397 # -----------------------------------------------------------------
401 dbHyperlinkField
= 32768
403 dbUpdatableField
= 32
407 # -----------------------------------------------------------------
408 dbOpenForwardOnly
= 8
409 dbSQLPassThrough
= 64
413 # -----------------------------------------------------------------
418 dbQMakeTable
= 128 # 80
420 dbQSetOperation
= 8 # 128
421 dbQSQLPassThrough
= 1 # 112
425 # -----------------------------------------------------------------
431 # -----------------------------------------------------------------
432 msoBarTypeNormal
= 0 # Usual toolbar
433 msoBarTypeMenuBar
= 1 # Menu bar
434 msoBarTypePopup
= 2 # Shortcut menu
435 msoBarTypeStatusBar
= 11 # Status bar
436 msoBarTypeFloater
= 12 # Floating window
438 msoControlButton
= 1 # Command button
439 msoControlPopup
= 10 # Popup, submenu
442 # -----------------------------------------------------------------
447 if _opsys
== 'Windows': return chr(13) + chr(10)
450 vbNewLine
= _NewLine()
454 # -----------------------------------------------------------------
458 # (Module) procedure types
459 # -----------------------------------------------------------------
460 vbext_pk_Get
= 1 # A Property Get procedure
461 vbext_pk_Let
= 2 # A Property Let procedure
462 vbext_pk_Proc
= 0 # A Sub or Function procedure
463 vbext_pk_Set
= 3 # A Property Set procedure
466 COMPONENTCONTEXT
, DESKTOP
, SCRIPTPROVIDER
, THISDATABASEDOCUMENT
= None, None, None, None
468 def _ErrorHandler(type, value
, tb
):
470 Is the function to be set as new sys.excepthook to bypass the standard error handler
471 Derived from https://stackoverflow.com/questions/31949760/how-to-limit-python-traceback-to-specific-files
472 Handler removes traces pointing to methods located in access2base.py when error is due to a user programming error
473 sys.excepthook = _ErrorHandler
477 def check_file(name
):
478 return 'access2base.py' not in name
480 show
= (fs
for fs
in traceback
.extract_tb(tb
) if check_file(fs
.filename
))
481 fmt
= traceback
.format_list(show
) + traceback
.format_exception_only(type, value
)
482 print(''.join(fmt
), end
= '', file = sys
.stderr
)
483 # Reset to standard handler
484 sys
.excepthook
= sys
.__excepthook
__
487 def A2BConnect(hostname
= '', port
= 0):
489 To be called explicitly by user scripts when Python process runs outside the LibreOffice process.
490 LibreOffice started as (Linux):
491 ./soffice --accept='socket,host=localhost,port=xxxx;urp;'
492 Otherwise called implicitly by the current module without arguments
493 Initializes COMPONENTCONTEXT, SCRIPTPROVIDER and DESKTOP
494 :param hostname: probably 'localhost' or ''
495 :param port: port number or 0
498 global XSCRIPTCONTEXT
, COMPONENTCONTEXT
, DESKTOP
, SCRIPTPROVIDER
499 # Determine COMPONENTCONTEXT, via socket or inside LibreOffice
500 if len(hostname
) > 0 and port
> 0: # Explicit connection request via socket
501 # Code derived from Bridge.py by Alain H. Romedenne
502 local_context
= XSCRIPTCONTEXT
.getComponentContext()
503 resolver
= local_context
.ServiceManager
.createInstanceWithContext(
504 'com.sun.star.bridge.UnoUrlResolver', local_context
)
506 conn
= 'socket,host=%s,port=%d' % (hostname
, port
)
507 connection_url
= 'uno:%s;urp;StarOffice.ComponentContext' % conn
508 established_context
= resolver
.resolve(connection_url
)
509 except Exception: # thrown when LibreOffice specified instance isn't started
510 raise ConnectionError('Connection to LibreOffice failed (host = ' + hostname
+ ', port = ' + str(port
) + ')')
511 COMPONENTCONTEXT
= established_context
513 elif len(hostname
) == 0 and port
== 0: # Usual interactive mode
514 COMPONENTCONTEXT
= XSCRIPTCONTEXT
.getComponentContext()
515 DESKTOP
= COMPONENTCONTEXT
.ServiceManager
.createInstanceWithContext( 'com.sun.star.frame.Desktop', COMPONENTCONTEXT
)
517 raise SystemExit('The invocation of A2BConnect() has invalid arguments')
518 # Determine SCRIPTPROVIDER
519 servicemanager
= COMPONENTCONTEXT
.ServiceManager
520 masterscript
= servicemanager
.createInstanceWithContext("com.sun.star.script.provider.MasterScriptProviderFactory", COMPONENTCONTEXT
)
521 SCRIPTPROVIDER
= masterscript
.createScriptProvider("")
522 Script
= _A2B
.xScript('TraceLog', 'Trace') # Don't use invokeMethod() to force reset of error stack
523 Script
.invoke(('===>', 'Python wrapper loaded V.' + _VERSION
, False), (), ())
527 class _A2B(object, metaclass
= _Singleton
):
529 Collection of helper functions implementing the protocol between Python and Basic
530 Read comments in PythonWrapper Basic function
534 def BasicObject(cls
, objectname
):
535 objs
= {'COLLECTION': _Collection
536 , 'COMMANDBAR': _CommandBar
537 , 'COMMANDBARCONTROL': _CommandBarControl
538 , 'CONTROL': _Control
539 , 'DATABASE': _Database
545 , 'OPTIONGROUP': _OptionGroup
546 , 'PROPERTY': _Property
547 , 'QUERYDEF': _QueryDef
548 , 'RECORDSET': _Recordset
549 , 'SUBFORM': _SubForm
550 , 'TABLEDEF': _TableDef
551 , 'TEMPVAR': _TempVar
553 return objs
[objectname
]
556 def xScript(cls
, script
, module
):
558 At first call checks the existence of the Access2Base library
559 Initializes _LIBRARY with the found library name
560 First and next calls execute the given script in the given module of the _LIBRARY library
561 The script and module are presumed to exist
562 :param script: name of script
563 :param module: name of module
564 :return: the script object. NB: the execution is done with the invoke() method applied on the returned object
569 return 'vnd.sun.star.script:' + lib
+ '.' + module
+ '.' + script
+ '?language=Basic&location=application'
571 # Check the availability of the Access2Base library
572 for lib
in ('Access2BaseDev', 'Access2Base'):
575 Script
= SCRIPTPROVIDER
.getScript(sScript(lib
))
580 raise SystemExit('Access2Base basic library not found')
582 Script
= SCRIPTPROVIDER
.getScript(sScript(_LIBRARY
))
586 def A2BErrorCode(cls
):
588 Return the Access2Base error stack as a tuple
591 2 => short error message
592 3 => long error message
594 Script
= cls
.xScript('TraceErrorCode', 'Trace')
595 return Script
.invoke((), (), ())[0]
598 def invokeMethod(cls
, script
, module
, *args
):
600 Direct call to a named script/module pair with their arguments
601 If the arguments do not match their definition at the Basic side, a TypeError is raised
602 :param script: name of script
603 :param module: name of module
604 :param args: list of arguments to be passed to the script
605 :return: the value returned by the script execution
607 if COMPONENTCONTEXT
== None: A2BConnect() # Connection from inside LibreOffice is done at first API invocation
608 Script
= cls
.xScript(script
, module
)
610 Returned
= Script
.invoke((args
), (), ())[0]
612 raise TypeError("Access2Base error: method '" + script
+ "' in Basic module '" + module
+ "' call error. Check its arguments.")
615 if cls
.VerifyNoError(): return None
619 def invokeWrapper(cls
, action
, basic
, script
, *args
):
621 Call the Basic wrapper to invite it to execute the proposed action on a Basic object
622 If the arguments do not match their definition at the Basic side, a TypeError is raised
623 After execution, a check is done if the execution has raised an error within Basic
624 If yes, a TypeError is raised
625 :param action: Property Get, Property Let, Property Set, invoke Method or return UNO object
626 :param basic: the reference of the Basic object, i.e. the index in the array caching the addresses of the objects
627 conventionally Application = -1 and DoCmd = -2
628 :param script: the property or method name
629 :param args: the arguments of the method, if any
630 :return: the value returned by the execution of the Basic routine
632 if COMPONENTCONTEXT
== None: A2BConnect() # Connection from inside LibreOffice is done at first API invocation
633 # Intercept special call to Application.Events()
634 if basic
== Application
.basicmodule
and script
== 'Events':
635 Script
= cls
.xScript('PythonEventsWrapper', _WRAPPERMODULE
)
636 Returned
= Script
.invoke((args
[0],), (), ())
638 Script
= cls
.xScript('PythonWrapper', _WRAPPERMODULE
)
639 NoArgs
= '+++NOARGS+++' # Conventional notation for properties/methods without arguments
641 args
= (action
,) + (basic
,) + (script
,) + (NoArgs
,)
643 args
= (action
,) + (basic
,) + (script
,) + args
645 Returned
= Script
.invoke((args
), (), ())
647 raise TypeError("Access2Base error: method '" + script
+ "' call error. Check its arguments.")
649 if isinstance(Returned
[0], tuple):
650 # Is returned value a reference to a basic object, a scalar or a UNO object ?
651 if len(Returned
[0]) in (3, 4):
652 if Returned
[0][0] == 0: # scalar
653 return Returned
[0][1]
654 elif Returned
[0][0] == 1: # reference to objects cache
655 basicobject
= cls
.BasicObject(Returned
[0][2])
656 if len(Returned
[0]) == 3:
657 return basicobject(Returned
[0][1], Returned
[0][2])
659 return basicobject(Returned
[0][1], Returned
[0][2], Returned
[0][3])
660 elif Returned
[0][0] == 2: # Null value
662 else: # Should not happen
666 elif Returned
[0] == None:
667 if cls
.VerifyNoError(): return None
668 else: # Should not happen
672 def VerifyNoError(cls
):
673 # has Access2Base generated an error ?
674 errorstack
= cls
.A2BErrorCode() # 0 = code, 1 = severity, 2 = short text, 3 = long text
675 if errorstack
[1] in ('ERROR', 'FATAL', 'ABORT'):
676 raise TypeError('Access2Base error: ' + errorstack
[3])
680 class Application(object, metaclass
= _Singleton
):
681 """ Collection of methods located in the Application (Basic) module """
682 W
= _A2B
.invokeWrapper
686 def AllDialogs(cls
, dialog
= acConstants
.Missing
):
687 return cls
.W(_vbMethod
, cls
.basicmodule
, 'AllDialogs', dialog
)
689 def AllForms(cls
, form
= acConstants
.Missing
):
690 return cls
.W(_vbMethod
, cls
.basicmodule
, 'AllForms', form
)
692 def AllModules(cls
, module
= acConstants
.Missing
):
693 return cls
.W(_vbMethod
, cls
.basicmodule
, 'AllModules', module
)
695 def CloseConnection(cls
):
696 return cls
.W(_vbMethod
, cls
.basicmodule
, 'CloseConnection')
698 def CommandBars(cls
, bar
= acConstants
.Missing
):
699 return cls
.W(_vbMethod
, cls
.basicmodule
, 'CommandBars', bar
)
702 return cls
.W(_vbMethod
, cls
.basicmodule
, 'CurrentDb')
704 def CurrentUser(cls
):
705 return cls
.W(_vbMethod
, cls
.basicmodule
, 'CurrentUser')
707 def DAvg(cls
, expression
, domain
, criteria
= ''):
708 return cls
.W(_vbMethod
, cls
.basicmodule
, 'DAvg', expression
, domain
, criteria
)
710 def DCount(cls
, expression
, domain
, criteria
= ''):
711 return cls
.W(_vbMethod
, cls
.basicmodule
, 'DCount', expression
, domain
, criteria
)
713 def DLookup(cls
, expression
, domain
, criteria
= '', orderclause
= ''):
714 return cls
.W(_vbMethod
, cls
.basicmodule
, 'DLookup', expression
, domain
, criteria
, orderclause
)
716 def DMax(cls
, expression
, domain
, criteria
= ''):
717 return cls
.W(_vbMethod
, cls
.basicmodule
, 'DMax', expression
, domain
, criteria
)
719 def DMin(cls
, expression
, domain
, criteria
= ''):
720 return cls
.W(_vbMethod
, cls
.basicmodule
, 'DMin', expression
, domain
, criteria
)
722 def DStDev(cls
, expression
, domain
, criteria
= ''):
723 return cls
.W(_vbMethod
, cls
.basicmodule
, 'DStDev', expression
, domain
, criteria
)
725 def DStDevP(cls
, expression
, domain
, criteria
= ''):
726 return cls
.W(_vbMethod
, cls
.basicmodule
, 'DStDevP', expression
, domain
, criteria
)
728 def DSum(cls
, expression
, domain
, criteria
= ''):
729 return cls
.W(_vbMethod
, cls
.basicmodule
, 'DSum', expression
, domain
, criteria
)
731 def DVar(cls
, expression
, domain
, criteria
= ''):
732 return cls
.W(_vbMethod
, cls
.basicmodule
, 'DVar', expression
, domain
, criteria
)
734 def DVarP(cls
, expression
, domain
, criteria
= ''):
735 return cls
.W(_vbMethod
, cls
.basicmodule
, 'DVarP', expression
, domain
, criteria
)
737 def Events(cls
, event
):
738 return cls
.W(_vbMethod
, cls
.basicmodule
, 'Events', event
)
740 def Forms(cls
, form
= acConstants
.Missing
):
741 return cls
.W(_vbMethod
, cls
.basicmodule
, 'Forms', form
)
743 def getObject(cls
, shortcut
):
744 return cls
.W(_vbMethod
, cls
.basicmodule
, 'getObject', shortcut
)
745 GetObject
= getObject
747 def getValue(cls
, shortcut
):
748 return cls
.W(_vbMethod
, cls
.basicmodule
, 'getValue', shortcut
)
751 def HtmlEncode(cls
, string
, length
= 0):
752 return cls
.W(_vbMethod
, cls
.basicmodule
, 'HtmlEncode', string
, length
)
754 def OpenConnection(cls
, thisdatabasedocument
= acConstants
.Missing
):
755 global THISDATABASEDOCUMENT
756 if COMPONENTCONTEXT
== None: A2BConnect() # Connection from inside LibreOffice is done at first API invocation
758 THISDATABASEDOCUMENT
= DESKTOP
.getCurrentComponent()
759 return _A2B
.invokeMethod('OpenConnection', 'Application', THISDATABASEDOCUMENT
)
761 def OpenDatabase(cls
, connectionstring
, username
= '', password
= '', readonly
= False):
762 return cls
.W(_vbMethod
, cls
.basicmodule
, 'OpenDatabase', connectionstring
, username
763 , password
, readonly
)
765 def ProductCode(cls
):
766 return cls
.W(_vbMethod
, cls
.basicmodule
, 'ProductCode')
768 def setValue(cls
, shortcut
, value
):
769 return cls
.W(_vbMethod
, cls
.basicmodule
, 'setValue', shortcut
, value
)
772 def SysCmd(cls
, action
, text
= '', value
= -1):
773 return cls
.W(_vbMethod
, cls
.basicmodule
, 'SysCmd', action
, text
, value
)
775 def TempVars(cls
, var
= acConstants
.Missing
):
776 return cls
.W(_vbMethod
, cls
.basicmodule
, 'TempVars', var
)
779 return cls
.W(_vbMethod
, cls
.basicmodule
, 'Version')
782 class DoCmd(object, metaclass
= _Singleton
):
783 """ Collection of methods located in the DoCmd (Basic) module """
784 W
= _A2B
.invokeWrapper
788 def ApplyFilter(cls
, filter = '', sqlwhere
= '', controlname
= ''):
789 return cls
.W(_vbMethod
, cls
.basicmodule
, 'ApplyFilter', filter, sqlwhere
, controlname
)
791 def Close(cls
, objecttype
, objectname
, save
= acConstants
.acSavePrompt
):
792 return cls
.W(_vbMethod
, cls
.basicmodule
, 'Close', objecttype
, objectname
, save
)
794 def CopyObject(cls
, sourcedatabase
, newname
, sourceobjecttype
, sourceobjectname
): # 1st argument must be set
795 return cls
.W(_vbMethod
, cls
.basicmodule
, 'CopyObject', sourcedatabase
, newname
, sourceobjecttype
799 return cls
.W(_vbMethod
, cls
.basicmodule
, 'FindNext')
801 def FindRecord(cls
, findwhat
, match
= acConstants
.acEntire
, matchcase
= False, search
= acConstants
.acSearchAll
802 , searchasformatted
= False, onlycurrentfield
= acConstants
.acCurrent
, findfirst
= True):
803 return cls
.W(_vbMethod
, cls
.basicmodule
, 'FindRecord', findwhat
, match
, matchcase
, search
804 , searchasformatted
, onlycurrentfield
, findfirst
)
806 def GetHiddenAttribute(cls
, objecttype
, objectname
= ''):
807 return cls
.W(_vbMethod
, cls
.basicmodule
, 'GetHiddenAttribute', objecttype
, objectname
)
809 def GoToControl(cls
, controlname
):
810 return cls
.W(_vbMethod
, cls
.basicmodule
, 'GoToControl', controlname
)
812 def GoToRecord(cls
, objecttype
= acConstants
.acActiveDataObject
, objectname
= '', record
= acConstants
.acNext
814 return cls
.W(_vbMethod
, cls
.basicmodule
, 'GoToRecord', objecttype
, objectname
, record
, offset
)
817 return cls
.W(_vbMethod
, cls
.basicmodule
, 'Maximize')
820 return cls
.W(_vbMethod
, cls
.basicmodule
, 'Minimize')
822 def MoveSize(cls
, left
= -1, top
= -1, width
= -1, height
= -1):
823 return cls
.W(_vbMethod
, cls
.basicmodule
, 'MoveSize', left
, top
, width
, height
)
825 def OpenForm(cls
, formname
, view
= acConstants
.acNormal
, filter = '', wherecondition
= ''
826 , datamode
= acConstants
.acFormEdit
, windowmode
= acConstants
.acWindowNormal
, openargs
= ''):
827 return cls
.W(_vbMethod
, cls
.basicmodule
, 'OpenForm', formname
, view
, filter, wherecondition
828 , datamode
, windowmode
, openargs
)
830 def OpenQuery(cls
, queryname
, view
= acConstants
.acNormal
, datamode
= acConstants
.acEdit
):
831 return cls
.W(_vbMethod
, cls
.basicmodule
, 'OpenQuery', queryname
, view
, datamode
)
833 def OpenReport(cls
, queryname
, view
= acConstants
.acNormal
):
834 return cls
.W(_vbMethod
, cls
.basicmodule
, 'OpenReport', queryname
, view
)
836 def OpenSQL(cls
, sql
, option
= -1):
837 return cls
.W(_vbMethod
, cls
.basicmodule
, 'OpenSQL', sql
, option
)
839 def OpenTable(cls
, tablename
, view
= acConstants
.acNormal
, datamode
= acConstants
.acEdit
):
840 return cls
.W(_vbMethod
, cls
.basicmodule
, 'OpenTable', tablename
, view
, datamode
)
842 def OutputTo(cls
, objecttype
, objectname
= '', outputformat
= '', outputfile
= '', autostart
= False, templatefile
= ''
843 , encoding
= acConstants
.acUTF8Encoding
, quality
= acConstants
.acExportQualityPrint
):
844 if objecttype
== acConstants
.acOutputForm
: encoding
= 0
845 return cls
.W(_vbMethod
, cls
.basicmodule
, 'OutputTo', objecttype
, objectname
, outputformat
846 , outputfile
, autostart
, templatefile
, encoding
, quality
)
849 return cls
.W(_vbMethod
, cls
.basicmodule
, 'Quit')
851 def RunApp(cls
, commandline
):
852 return cls
.W(_vbMethod
, cls
.basicmodule
, 'RunApp', commandline
)
854 def RunCommand(cls
, command
):
855 return cls
.W(_vbMethod
, cls
.basicmodule
, 'RunCommand', command
)
857 def RunSQL(cls
, SQL
, option
= -1):
858 return cls
.W(_vbMethod
, cls
.basicmodule
, 'RunSQL', SQL
, option
)
860 def SelectObject(cls
, objecttype
, objectname
= '', indatabasewindow
= False):
861 return cls
.W(_vbMethod
, cls
.basicmodule
, 'SelectObject', objecttype
, objectname
, indatabasewindow
)
863 def SendObject(cls
, objecttype
= acConstants
.acSendNoObject
, objectname
= '', outputformat
= '', to
= '', cc
= ''
864 , bcc
= '', subject
= '', messagetext
= '', editmessage
= True, templatefile
= ''):
865 return cls
.W(_vbMethod
, cls
.basicmodule
, 'SendObject', objecttype
, objectname
, outputformat
, to
, cc
866 , bcc
, subject
, messagetext
, editmessage
, templatefile
)
868 def SetHiddenAttribute(cls
, objecttype
, objectname
= '', hidden
= True):
869 return cls
.W(_vbMethod
, cls
.basicmodule
, 'SetHiddenAttribute', objecttype
, objectname
, hidden
)
871 def SetOrderBy(cls
, orderby
= '', controlname
= ''):
872 return cls
.W(_vbMethod
, cls
.basicmodule
, 'SetOrderBy', orderby
, controlname
)
874 def ShowAllRecords(cls
):
875 return cls
.W(_vbMethod
, cls
.basicmodule
, 'ShowAllRecords')
878 class Basic(object, metaclass
= _Singleton
):
879 """ Collection of helper functions having the same behaviour as their Basic counterparts """
880 M
= _A2B
.invokeMethod
883 def ConvertFromUrl(cls
, url
):
884 return cls
.M('PyConvertFromUrl', _WRAPPERMODULE
, url
)
887 def ConvertToUrl(cls
, file):
888 return cls
.M('PyConvertToUrl', _WRAPPERMODULE
, file)
891 def CreateUnoService(cls
, servicename
):
892 return cls
.M('PyCreateUnoService', _WRAPPERMODULE
, servicename
)
895 def DateAdd(cls
, add
, count
, datearg
):
896 if isinstance(datearg
, datetime
.datetime
): datearg
= datearg
.isoformat()
897 dateadd
= cls
.M('PyDateAdd', _WRAPPERMODULE
, add
, count
, datearg
)
898 return datetime
.datetime
.strptime(dateadd
, acConstants
.FromIsoFormat
)
901 def DateDiff(cls
, add
, date1
, date2
, weekstart
= 1, yearstart
= 1):
902 if isinstance(date1
, datetime
.datetime
): date1
= date1
.isoformat()
903 if isinstance(date2
, datetime
.datetime
): date2
= date2
.isoformat()
904 return cls
.M('PyDateDiff', _WRAPPERMODULE
, add
, date1
, date2
, weekstart
, yearstart
)
907 def DatePart(cls
, add
, datearg
, weekstart
= 1, yearstart
= 1):
908 if isinstance(datearg
, datetime
.datetime
): datearg
= datearg
.isoformat()
909 return cls
.M('PyDatePart', _WRAPPERMODULE
, add
, datearg
, weekstart
, yearstart
)
912 def DateValue(cls
, datestring
):
913 datevalue
= cls
.M('PyDateValue', _WRAPPERMODULE
, datestring
)
914 return datetime
.datetime
.strptime(datevalue
, acConstants
.FromIsoFormat
)
917 def Format(cls
, value
, format
= None):
918 if isinstance(value
, (datetime
.datetime
, datetime
.date
, datetime
.time
, )):
919 value
= value
.isoformat()
920 return cls
.M('PyFormat', _WRAPPERMODULE
, value
, format
)
924 return cls
.M('PyGetGUIType', _WRAPPERMODULE
)
927 def GetPathSeparator():
931 def GetSystemTicks(cls
):
932 return cls
.M('PyGetSystemTicks', _WRAPPERMODULE
)
935 def MsgBox(cls
, text
, type = None, dialogtitle
= None):
936 return cls
.M('PyMsgBox', _WRAPPERMODULE
, text
, type, dialogtitle
)
938 class GlobalScope(object, metaclass
= _Singleton
):
940 def BasicLibraries(cls
):
941 return Basic
.M('PyGlobalScope', _WRAPPERMODULE
, 'Basic')
943 def DialogLibraries(self
):
944 return Basic
.M('PyGlobalScope', _WRAPPERMODULE
, 'Dialog')
947 def InputBox(cls
, text
, title
= None, default
= None, xpos
= None, ypos
= None):
948 return cls
.M('PyInputBox', _WRAPPERMODULE
, text
, title
, default
, xpos
, ypos
)
952 return datetime
.datetime
.now()
955 def RGB(red
, green
, blue
):
956 return int('%02x%02x%02x' % (red
, green
, blue
), 16)
960 return cls
.M('PyTimer', _WRAPPERMODULE
)
964 xrayscript
= 'vnd.sun.star.script:XrayTool._Main.Xray?language=Basic&location=application'
965 xScript
= SCRIPTPROVIDER
.getScript(xrayscript
)
966 xScript
.invoke((myObject
,), (), ())
970 class _BasicObject(object):
972 Parent class of Basic objects
973 Each subclass is identified by its classProperties:
974 dictionary with keys = allowed properties, value = True if editable or False
975 Each instance is identified by its
976 - reference in the cache managed by Basic
977 - type ('DATABASE', 'COLLECTION', ...)
978 - name (form, control, ... name) - may be blank
979 Properties are got and set following next strategy:
980 1. Property names are controlled strictly ('Value' and not 'value')
981 2. Getting a property value for the first time is always done via a Basic call
982 3. Next occurrences are fetched from the Python dictionary of the instance if the property is read-only, otherwise via a Basic call
983 4. Methods output might force the deletion of a property from the dictionary ('MoveNext' changes 'BOF' and 'EOF' properties)
984 5. Setting a property value is done via a Basic call, except if self.internal == True
986 W
= _A2B
.invokeWrapper
987 internal_attributes
= ('objectreference', 'objecttype', 'name', 'internal')
989 def __init__(self
, reference
= -1, objtype
= None, name
= ''):
990 self
.objectreference
= reference
# reference in the cache managed by Basic
991 self
.objecttype
= objtype
# ('DATABASE', 'COLLECTION', ...)
992 self
.name
= name
# '' when no name
993 self
.internal
= False # True to exceptionally allow assigning a new value to a read-only property
994 self
.localProperties
= ()
996 def __getattr__(self
, name
):
997 if name
in ('classProperties', 'localProperties'):
999 elif name
in self
.classProperties
:
1000 # Get Property from Basic
1001 return self
.W(_vbGet
, self
.objectreference
, name
)
1002 # Usual attributes getter
1003 return super(_BasicObject
, self
).__getattribute
__(name
)
1005 def __setattr__(self
, name
, value
):
1006 if name
in ('classProperties', 'localProperties'):
1008 elif name
in self
.classProperties
:
1009 if self
.internal
: # internal = True forces property setting even if property is read-only
1011 elif self
.classProperties
[name
] == True: # True == Editable
1012 self
.W(_vbLet
, self
.objectreference
, name
, value
)
1014 raise AttributeError("type object '" + self
.objecttype
+ "' has no editable attribute '" + name
+ "'")
1015 elif name
[0:2] == '__' or name
in self
.internal_attributes
or name
in self
.localProperties
:
1018 raise AttributeError("type object '" + self
.objecttype
+ "' has no attribute '" + name
+ "'")
1019 object.__setattr
__(self
, name
, value
)
1023 repr = "Basic object (type='" + self
.objecttype
+ "', index=" + str(self
.objectreference
)
1024 if len(self
.name
) > 0: repr += ", name='" + self
.name
+ "'"
1027 def _Reset(self
, propertyname
, basicreturn
= None):
1028 """ force new value or erase properties from dictionary (done to optimize calls to Basic scripts) """
1029 if propertyname
in ('BOF', 'EOF'):
1030 # After a Move method invocation on a Recordset object, BOF or EOF likely to be got soon
1031 if isinstance(basicreturn
, int):
1032 self
.internal
= True
1033 # f.i. basicreturn = 0b10 means: BOF = True, EOF = False
1034 self
.BOF
= basicreturn
in (2, 3, -2, -3)
1035 self
.EOF
= basicreturn
in (1, 3, -1, -3)
1036 self
.internal
= False
1037 return ( basicreturn
>= 0 )
1039 # Suppress possibly invalid property values: e.g. RecordCount after Delete applied on Recordset object
1040 if property in self
.__dict
__:
1041 del(self
.propertyname
)
1045 def Name(self
): return self
.name
1047 def ObjectType(self
): return self
.objecttype
1050 return self
.W(_vbMethod
, self
.objectreference
, 'Dispose')
1051 def getProperty(self
, propertyname
, index
= acConstants
.Missing
):
1052 return self
.W(_vbMethod
, self
.objectreference
, 'getProperty', propertyname
, index
)
1053 GetProperty
= getProperty
1054 def hasProperty(self
, propertyname
):
1055 return propertyname
in tuple(self
.classProperties
.keys())
1056 HasProperty
= hasProperty
1057 def Properties(self
, index
= acConstants
.Missing
):
1058 return self
.W(_vbMethod
, self
.objectreference
, 'Properties', index
)
1059 def setProperty(self
, propertyname
, value
, index
= acConstants
.Missing
):
1060 if self
.hasProperty(propertyname
):
1061 if self
.W(_vbMethod
, self
.objectreference
, 'setProperty', propertyname
, value
, index
):
1062 return self
.__setattr
__(propertyname
, value
)
1063 raise AttributeError("type object '" + self
.objecttype
+ "' has no editable attribute '" + propertyname
+ "'")
1064 SetProperty
= setProperty
1067 class _Collection(_BasicObject
):
1068 """ Collection object built as a Python iterator """
1069 classProperties
= dict(Count
= False)
1070 def __init__(self
, reference
= -1, objtype
= None):
1071 super().__init
__(reference
, objtype
)
1072 self
.localProperties
= ('count', 'index')
1073 self
.count
= self
.Count
1079 if self
.index
>= self
.count
:
1081 next
= self
.Item(self
.index
)
1082 self
.index
= self
.index
+ 1
1087 def Add(self
, table
, value
= acConstants
.Missing
):
1088 if isinstance(table
, _BasicObject
): # Add method applied to a TABLEDEFS collection
1089 return self
.W(_vbMethod
, self
.objectreference
, 'Add', table
.objectreference
)
1090 else: # Add method applied to a TEMPVARS collection
1091 add
= self
.W(_vbMethod
, self
.objectreference
, 'Add', table
, value
)
1092 self
.count
= self
.Count
1094 def Delete(self
, name
):
1095 return self
.W(_vbMethod
, self
.objectreference
, 'Delete', name
)
1096 def Item(self
, index
):
1097 return self
.W(_vbMethod
, self
.objectreference
, 'Item', index
)
1098 def Remove(self
, tempvarname
):
1099 remove
= self
.W(_vbMethod
, self
.objectreference
, 'Remove', tempvarname
)
1100 self
.count
= self
.Count
1102 def RemoveAll(self
):
1103 remove
= self
.W(_vbMethod
, self
.objectreference
, 'RemoveAll')
1104 self
.count
= self
.Count
1108 class _CommandBar(_BasicObject
):
1109 classProperties
= dict(BuiltIn
= False, Parent
= False, Visible
= True)
1111 def CommandBarControls(self
, index
= acConstants
.Missing
):
1112 return self
.W(_vbMethod
, self
.objectreference
, 'CommandBarControls', index
)
1114 return self
.W(_vbMethod
, self
.objectreference
, 'Reset')
1117 class _CommandBarControl(_BasicObject
):
1118 classProperties
= dict(BeginGroup
= False, BuiltIn
= False, Caption
= True, Index
= False, OnAction
= True
1119 , Parent
= False, TooltipText
= True, Type
= False, Visible
= True)
1122 return self
.W(_vbMethod
, self
.objectreference
, 'Execute')
1125 class _Control(_BasicObject
):
1126 classProperties
= dict(BackColor
= True, BorderColor
= True, BorderStyle
= True, Cancel
= True, Caption
= True
1127 , ControlSource
= False, ControlTipText
= True, ControlType
= False, Default
= True
1128 , DefaultValue
= True, Enabled
= True, FontBold
= True, FontItalic
= True, FontName
= True
1129 , FontSize
= True, FontUnderline
= True, FontWeight
= True, ForeColor
= True, Form
= False
1130 , Format
= True, ItemData
= False, ListCount
= False, ListIndex
= True, Locked
= True, MultiSelect
= True
1131 , OnActionPerformed
= True, OnAdjustmentValueChanged
= True, OnApproveAction
= True
1132 , OnApproveReset
= True, OnApproveUpdate
= True, OnChanged
= True, OnErrorOccurred
= True
1133 , OnFocusGained
= True, OnFocusLost
= True, OnItemStateChanged
= True, OnKeyPressed
= True
1134 , OnKeyReleased
= True, OnMouseDragged
= True, OnMouseEntered
= True, OnMouseExited
= True
1135 , OnMouseMoved
= True, OnMousePressed
= True, OnMouseReleased
= True, OnResetted
= True, OnTextChanged
= True
1136 , OnUpdated
= True, OptionValue
= False, Page
= False, Parent
= False, Picture
= True, Required
= True
1137 , RowSource
= True, RowSourceType
= True, Selected
= True, SelLength
= True, SelStart
= True, SelText
= True
1138 , SubType
= False, TabIndex
= True, TabStop
= True, Tag
= True, Text
= False, TextAlign
= True
1139 , TripleState
= True, Value
= True, Visible
= True
1143 def BoundField(self
): return self
.W(_vbUNO
, self
.objectreference
, 'BoundField')
1145 def ControlModel(self
): return self
.W(_vbUNO
, self
.objectreference
, 'ControlModel')
1147 def ControlView(self
): return self
.W(_vbUNO
, self
.objectreference
, 'ControlView')
1149 def LabelControl(self
): return self
.W(_vbUNO
, self
.objectreference
, 'LabelControl')
1151 def AddItem(self
, value
, index
= -1):
1152 basicreturn
= self
.W(_vbMethod
, self
.objectreference
, 'AddItem', value
, index
)
1153 self
._Reset
('ItemData')
1154 self
._Reset
('ListCount')
1156 def Controls(self
, index
= acConstants
.Missing
):
1157 return self
.W(_vbMethod
, self
.objectreference
, 'Controls', index
)
1158 # Overrides method in parent class: list of properties is strongly control type dependent
1159 def hasProperty(self
, propertyname
):
1160 return self
.W(_vbMethod
, self
.objectreference
, 'hasProperty', propertyname
)
1161 HasProperty
= hasProperty
1162 def RemoveItem(self
, index
):
1163 basicreturn
= self
.W(_vbMethod
, self
.objectreference
, 'RemoveItem', index
)
1164 self
._Reset
('ItemData')
1165 self
._Reset
('ListCount')
1168 return self
.W(_vbMethod
, self
.objectreference
, 'Requery')
1169 def SetSelected(self
, value
, index
):
1170 return self
.W(_vbMethod
, self
.objectreference
, 'SetSelected', value
, index
)
1172 return self
.W(_vbMethod
, self
.objectreference
, 'SetFocus')
1175 class _Database(_BasicObject
):
1176 classProperties
= dict(Connect
= False, OnCreate
= True
1177 , OnFocus
= True, OnLoad
= True, OnLoadFinished
= True, OnModifyChanged
= True, OnNew
= True
1178 , OnPrepareUnload
= True, OnPrepareViewClosing
= True, OnSave
= True, OnSaveAs
= True
1179 , OnSaveAsDone
= True, OnSaveAsFailed
= True, OnSaveDone
= True, OnSaveFailed
= True
1180 , OnSubComponentClosed
= True, OnSubComponentOpened
= True, OnTitleChanged
= True, OnUnfocus
= True
1181 , OnUnload
= True, OnViewClosed
= True, OnViewCreated
= True, Version
= False
1185 def Connection(self
): return self
.W(_vbUNO
, self
.objectreference
, 'Connection')
1187 def Document(self
): return self
.W(_vbUNO
, self
.objectreference
, 'Document')
1189 def MetaData(self
): return self
.W(_vbUNO
, self
.objectreference
, 'MetaData')
1192 return self
.W(_vbMethod
, self
.objectreference
, 'Close')
1193 def CloseAllRecordsets(self
):
1194 return self
.W(_vbMethod
, self
.objectreference
, 'CloseAllRecordsets')
1195 def CreateQueryDef(self
, name
, sqltext
, option
= -1):
1196 return self
.W(_vbMethod
, self
.objectreference
, 'CreateQueryDef', name
, sqltext
, option
)
1197 def CreateTableDef(self
, name
):
1198 return self
.W(_vbMethod
, self
.objectreference
, 'CreateTableDef', name
)
1199 def DAvg(self
, expression
, domain
, criteria
= ''):
1200 return self
.W(_vbMethod
, self
.objectreference
, 'DAvg', expression
, domain
, criteria
)
1201 def DCount(self
, expression
, domain
, criteria
= ''):
1202 return self
.W(_vbMethod
, self
.objectreference
, 'DCount', expression
, domain
, criteria
)
1203 def DLookup(self
, expression
, domain
, criteria
= '', orderclause
= ''):
1204 return self
.W(_vbMethod
, self
.objectreference
, 'DLookup', expression
, domain
, criteria
, orderclause
)
1205 def DMax(self
, expression
, domain
, criteria
= ''):
1206 return self
.W(_vbMethod
, self
.objectreference
, 'DMax', expression
, domain
, criteria
)
1207 def DMin(self
, expression
, domain
, criteria
= ''):
1208 return self
.W(_vbMethod
, self
.objectreference
, 'DMin', expression
, domain
, criteria
)
1209 def DStDev(self
, expression
, domain
, criteria
= ''):
1210 return self
.W(_vbMethod
, self
.objectreference
, 'DStDev', expression
, domain
, criteria
)
1211 def DStDevP(self
, expression
, domain
, criteria
= ''):
1212 return self
.W(_vbMethod
, self
.objectreference
, 'DStDevP', expression
, domain
, criteria
)
1213 def DVar(self
, expression
, domain
, criteria
= ''):
1214 return self
.W(_vbMethod
, self
.objectreference
, 'DVar', expression
, domain
, criteria
)
1215 def DVarP(self
, expression
, domain
, criteria
= ''):
1216 return self
.W(_vbMethod
, self
.objectreference
, 'DVarP', expression
, domain
, criteria
)
1217 def OpenRecordset(self
, source
, type = -1, option
= -1, lockedit
= -1):
1218 return self
.W(_vbMethod
, self
.objectreference
, 'OpenRecordset', source
, type, option
, lockedit
)
1219 def OpenSQL(self
, SQL
, option
= -1):
1220 return self
.W(_vbMethod
, self
.objectreference
, 'OpenSQL', SQL
, option
)
1221 def OutputTo(self
, objecttype
, objectname
= '', outputformat
= '', outputfile
= '', autostart
= False, templatefile
= ''
1222 , encoding
= acConstants
.acUTF8Encoding
, quality
= acConstants
.acExportQualityPrint
):
1223 if objecttype
== acConstants
.acOutputForm
: encoding
= 0
1224 return self
.W(_vbMethod
, self
.objectreference
, 'OutputTo', objecttype
, objectname
, outputformat
, outputfile
1225 , autostart
, templatefile
, encoding
, quality
)
1226 def QueryDefs(self
, index
= acConstants
.Missing
):
1227 return self
.W(_vbMethod
, self
.objectreference
, 'QueryDefs', index
)
1228 def Recordsets(self
, index
= acConstants
.Missing
):
1229 return self
.W(_vbMethod
, self
.objectreference
, 'Recordsets', index
)
1230 def RunSQL(self
, SQL
, option
= -1):
1231 return self
.W(_vbMethod
, self
.objectreference
, 'RunSQL', SQL
, option
)
1232 def TableDefs(self
, index
= acConstants
.Missing
):
1233 return self
.W(_vbMethod
, self
.objectreference
, 'TableDefs', index
)
1236 class _Dialog(_BasicObject
):
1237 classProperties
= dict(Caption
= True, Height
= True, IsLoaded
= False, OnFocusGained
= True
1238 , OnFocusLost
= True, OnKeyPressed
= True, OnKeyReleased
= True, OnMouseDragged
= True
1239 , OnMouseEntered
= True, OnMouseExited
= True, OnMouseMoved
= True, OnMousePressed
= True
1240 , OnMouseReleased
= True, Page
= True, Parent
= False, Visible
= True, Width
= True
1244 def UnoDialog(self
): return self
.W(_vbUNO
, self
.objectreference
, 'UnoDialog')
1246 def EndExecute(self
, returnvalue
):
1247 return self
.W(_vbMethod
, self
.objectreference
, 'EndExecute', returnvalue
)
1249 return self
.W(_vbMethod
, self
.objectreference
, 'Execute')
1250 def Move(self
, left
= -1, top
= -1, width
= -1, height
= -1):
1251 return self
.W(_vbMethod
, self
.objectreference
, 'Move', left
, top
, width
, height
)
1252 def OptionGroup(self
, groupname
):
1253 return self
.W(_vbMethod
, self
.objectreference
, 'OptionGroup', groupname
)
1255 return self
.W(_vbMethod
, self
.objectreference
, 'Start')
1256 def Terminate(self
):
1257 return self
.W(_vbMethod
, self
.objectreference
, 'Terminate')
1259 class _Event(_BasicObject
):
1260 classProperties
= dict(ButtonLeft
= False, ButtonMiddle
= False, ButtonRight
= False, ClickCount
= False
1261 , ContextShortcut
= False, EventName
= False, EventType
= False, FocusChangeTemporary
= False
1262 , KeyAlt
= False, KeyChar
= False, KeyCode
= False, KeyCtrl
= False, KeyFunction
= False, KeyShift
= False
1263 , Recommendation
= False, RowChangeAction
= False, Source
= False, SubComponentName
= False
1264 , SubComponentType
= False, XPos
= False, YPos
= False
1268 class _Field(_BasicObject
):
1269 classProperties
= dict(DataType
= False, DataUpdatable
= False, DbType
= False, DefaultValue
= True
1270 , Description
= True, FieldSize
= False, Size
= False, Source
= False
1271 , SourceField
= False, SourceTable
= False, TypeName
= False, Value
= True
1275 def Column(self
): return self
.W(_vbUNO
, self
.objectreference
, 'Column')
1277 def AppendChunk(self
, value
):
1278 return self
.W(_vbMethod
, self
.objectreference
, 'AppendChunk', value
)
1279 def GetChunk(self
, offset
, numbytes
):
1280 return self
.W(_vbMethod
, self
.objectreference
, 'GetChunk', offset
, numbytes
)
1281 def ReadAllBytes(self
, file):
1282 return self
.W(_vbMethod
, self
.objectreference
, 'ReadAllBytes', file)
1283 def ReadAllText(self
, file):
1284 return self
.W(_vbMethod
, self
.objectreference
, 'ReadAllText', file)
1285 def WriteAllBytes(self
, file):
1286 return self
.W(_vbMethod
, self
.objectreference
, 'WriteAllBytes', file)
1287 def WriteAllText(self
, file):
1288 return self
.W(_vbMethod
, self
.objectreference
, 'WriteAllText', file)
1291 class _Form(_BasicObject
):
1292 classProperties
= dict(AllowAdditions
= True, AllowDeletions
= True, AllowEdits
= True, Bookmark
= True
1293 , Caption
= True, CurrentRecord
= True, Filter
= True, FilterOn
= True, Height
= True
1294 , IsLoaded
= False, OnApproveCursorMove
= True, OnApproveParameter
= True, OnApproveReset
= True
1295 , OnApproveRowChange
= True, OnApproveSubmit
= True, OnConfirmDelete
= True, OnCursorMoved
= True
1296 , OnErrorOccurred
= True, OnLoaded
= True, OnReloaded
= True, OnReloading
= True, OnResetted
= True
1297 , OnRowChanged
= True, OnUnloaded
= True, OnUnloading
= True, OpenArgs
= False, OrderBy
= True
1298 , OrderByOn
= True, Parent
= False, Recordset
= False, RecordSource
= True, Visible
= True
1303 def Component(self
): return self
.W(_vbUNO
, self
.objectreference
, 'Component')
1305 def ContainerWindow(self
): return self
.W(_vbUNO
, self
.objectreference
, 'ContainerWindow')
1307 def DatabaseForm(self
): return self
.W(_vbUNO
, self
.objectreference
, 'DatabaseForm')
1310 return self
.W(_vbMethod
, self
.objectreference
, 'Close')
1311 def Controls(self
, index
= acConstants
.Missing
):
1312 return self
.W(_vbMethod
, self
.objectreference
, 'Controls', index
)
1313 def Move(self
, left
= -1, top
= -1, width
= -1, height
= -1):
1314 return self
.W(_vbMethod
, self
.objectreference
, 'Move', left
, top
, width
, height
)
1315 def OptionGroup(self
, groupname
):
1316 return self
.W(_vbMethod
, self
.objectreference
, 'OptionGroup', groupname
)
1318 return self
.W(_vbMethod
, self
.objectreference
, 'Refresh')
1320 return self
.W(_vbMethod
, self
.objectreference
, 'Requery')
1322 return self
.W(_vbMethod
, self
.objectreference
, 'SetFocus')
1325 class _Module(_BasicObject
):
1326 classProperties
= dict(CountOfDeclarationLines
= False, CountOfLines
= False, Type
= False)
1328 def __init__(self
, reference
= -1, objtype
= None, name
= ''):
1329 super().__init
__(reference
, objtype
, name
)
1330 self
.localProperties
= ('startline', 'startcolumn', 'endline', 'endcolumn', 'prockind')
1332 def Find(self
, target
, startline
, startcolumn
, endline
, endcolumn
, wholeword
= False
1333 , matchcase
= False, patternsearch
= False):
1334 Returned
= self
.W(_vbMethod
, self
.objectreference
, 'Find', target
, startline
, startcolumn
, endline
1335 , endcolumn
, wholeword
, matchcase
, patternsearch
)
1336 if isinstance(Returned
, tuple):
1337 if Returned
[0] == True and len(Returned
) == 5:
1338 self
.startline
= Returned
[1]
1339 self
.startcolumn
= Returned
[2]
1340 self
.endline
= Returned
[3]
1341 self
.endcolumn
= Returned
[4]
1344 def Lines(self
, line
, numlines
):
1345 return self
.W(_vbMethod
, self
.objectreference
, 'Lines', line
, numlines
)
1346 def ProcBodyLine(self
, procname
, prockind
):
1347 return self
.W(_vbMethod
, self
.objectreference
, 'ProcBodyLine', procname
, prockind
)
1348 def ProcCountLines(self
, procname
, prockind
):
1349 return self
.W(_vbMethod
, self
.objectreference
, 'ProcCountLines', procname
, prockind
)
1350 def ProcOfLine(self
, line
, prockind
):
1351 Returned
= self
.W(_vbMethod
, self
.objectreference
, 'ProcOfLine', line
, prockind
)
1352 if isinstance(Returned
, tuple):
1353 if len(Returned
) == 2:
1354 self
.prockind
= Returned
[1]
1357 def ProcStartLine(self
, procname
, prockind
):
1358 return self
.W(_vbMethod
, self
.objectreference
, 'ProcStartLine', procname
, prockind
)
1361 class _OptionGroup(_BasicObject
):
1362 classProperties
= dict(Count
= False, Value
= True)
1364 def Controls(self
, index
= acConstants
.Missing
):
1365 return self
.W(_vbMethod
, self
.objectreference
, 'Controls', index
)
1368 class _Property(_BasicObject
):
1369 classProperties
= dict(Value
= True)
1372 class _QueryDef(_BasicObject
):
1373 classProperties
= dict(SQL
= True, Type
= False)
1376 def Query(self
): return self
.W(_vbUNO
, self
.objectreference
, 'Query')
1378 def Execute(self
, options
= acConstants
.Missing
):
1379 return self
.W(_vbMethod
, self
.objectreference
, 'Execute', options
)
1380 def Fields(self
, index
= acConstants
.Missing
):
1381 return self
.W(_vbMethod
, self
.objectreference
, 'Fields', index
)
1382 def OpenRecordset(self
, type = -1, option
= -1, lockedit
= -1):
1383 return self
.W(_vbMethod
, self
.objectreference
, 'OpenRecordset', type, option
, lockedit
)
1386 class _Recordset(_BasicObject
):
1387 classProperties
= dict(AbsolutePosition
= True, BOF
= False, Bookmark
= True, Bookmarkable
= False
1388 , EditMode
= False, EOF
= False, Filter
= True, RecordCount
= False
1392 def RowSet(self
): return self
.W(_vbUNO
, self
.objectreference
, 'RowSet')
1395 return self
.W(_vbMethod
, self
.objectreference
, 'AddNew')
1396 def CancelUpdate(self
):
1397 return self
.W(_vbMethod
, self
.objectreference
, 'CancelUpdate')
1399 return self
.W(_vbMethod
, self
.objectreference
, 'Clone')
1401 return self
.W(_vbMethod
, self
.objectreference
, 'Close')
1403 return self
._Reset
('RecordCount',self
.W(_vbMethod
, self
.objectreference
, 'Delete'))
1405 return self
.W(_vbMethod
, self
.objectreference
, 'Edit')
1406 def Fields(self
, index
= acConstants
.Missing
):
1407 return self
.W(_vbMethod
, self
.objectreference
, 'Fields', index
)
1408 def GetRows(self
, numrows
):
1409 return self
.W(_vbMethod
, self
.objectreference
, 'GetRows', numrows
)
1410 def Move(self
, rows
, startbookmark
= acConstants
.Missing
):
1411 return self
._Reset
('BOF', self
.W(_vbMethod
, self
.objectreference
, 'Move', rows
, startbookmark
))
1412 def MoveFirst(self
):
1413 return self
._Reset
('BOF', self
.W(_vbMethod
, self
.objectreference
, 'MoveFirst'))
1415 return self
._Reset
('BOF', self
.W(_vbMethod
, self
.objectreference
, 'MoveLast'))
1417 return self
._Reset
('BOF', self
.W(_vbMethod
, self
.objectreference
, 'MoveNext'))
1418 def MovePrevious(self
):
1419 return self
._Reset
('BOF', self
.W(_vbMethod
, self
.objectreference
, 'MovePrevious'))
1420 def OpenRecordset(self
, type = -1, option
= -1, lockedit
= -1):
1421 return self
.W(_vbMethod
, self
.objectreference
, 'OpenRecordset', type, option
, lockedit
)
1423 return self
._Reset
('RecordCount',self
.W(_vbMethod
, self
.objectreference
, 'Update'))
1426 class _SubForm(_Form
):
1427 classProperties
= dict(AllowAdditions
= True, AllowDeletions
= True, AllowEdits
= True, CurrentRecord
= True
1428 , Filter
= True, FilterOn
= True, LinkChildFields
= False, LinkMasterFields
= False
1429 , OnApproveCursorMove
= True, OnApproveParameter
= True, OnApproveReset
= True
1430 , OnApproveRowChange
= True, OnApproveSubmit
= True, OnConfirmDelete
= True, OnCursorMoved
= True
1431 , OnErrorOccurred
= True, OnLoaded
= True, OnReloaded
= True, OnReloading
= True, OnResetted
= True
1432 , OnRowChanged
= True, OnUnloaded
= True, OnUnloading
= True, OrderBy
= True
1433 , OrderByOn
= True, Parent
= False, Recordset
= False, RecordSource
= True, Visible
= True
1437 raise AttributeError("type object 'SubForm' has no method 'SetFocus'")
1440 class _TableDef(_BasicObject
):
1441 classProperties
= dict()
1444 def Table(self
): return self
.W(_vbUNO
, self
.objectreference
, 'Table')
1446 def CreateField(self
, name
, type, size
= 0, attributes
= 0):
1447 return self
.W(_vbMethod
, self
.objectreference
, 'CreateField', name
, type, size
, attributes
)
1448 def Fields(self
, index
= acConstants
.Missing
):
1449 return self
.W(_vbMethod
, self
.objectreference
, 'Fields', index
)
1450 def OpenRecordset(self
, type = -1, option
= -1, lockedit
= -1):
1451 return self
.W(_vbMethod
, self
.objectreference
, 'OpenRecordset', type, option
, lockedit
)
1454 class _TempVar(_BasicObject
):
1455 classProperties
= dict(Value
= True)
1458 Set of directly callable error handling methods
1460 def DebugPrint(*args
):
1463 if isinstance(arg
, _BasicObject
):
1464 arg
= ('[' + arg
.objecttype
+ '] ' + arg
.name
).rstrip()
1465 dargs
= dargs
+ (arg
,)
1466 return _A2B
.invokeMethod('DebugPrint', _WRAPPERMODULE
, *dargs
)
1467 def TraceConsole(): return _A2B
.invokeMethod('TraceConsole', 'Trace')
1468 def TraceError(tracelevel
, errorcode
, errorprocedure
, errorline
):
1469 return _A2B
.invokeMethod('TraceError', 'Trace', tracelevel
, errorcode
, errorprocedure
, errorline
)
1470 def TraceLevel(newtracelevel
= 'ERROR'): return _A2B
.invokeMethod('TraceLevel', 'Trace', newtracelevel
)
1471 def TraceLog(tracelevel
, text
, messagebox
= True):
1472 return _A2B
.invokeMethod('TraceLog', 'Trace', tracelevel
, text
, messagebox
)