Declaring COM-interfaces in Python?

Dan L. Pierson dan at control.com
Wed Dec 15 10:46:43 EST 1999


rurban at xarch.tu-graz.ac.at (Reini Urban) wrote:

> And dispinterfaces?

Here's a working example of a dispinterface implemented in Python:

class SymbolConflictHandler:
    '''COM object that implements the DIqsMergeProblem interface.
    This interface is used by IqsProgram::MergeClipData to report
errors in
    the merge that may be correctable by the client. '''

    # This member makes an instance of this class wrappable as a COM
object
    # using the default dispatch policy.
    _public_methods_ = [ 'SymbolConflict' ]

    error_dict = { LE_HRESULTS.QST_E_DUPLICATE_STEP : 'Duplicate step
name',
                   LE_HRESULTS.QST_E_DUPLICATE_NAME : 'Symbol name in
use',
                   LE_HRESULTS.QST_E_DUPLICATE_VALUE : \
                       'That value already has a name' }

    def SymbolConflict(self, Why, ClipName, ClipType, ClipValue,
ClipSpecial,
                       ExistName, ExistType, ExistValue,
ExistSpecial):
        if Why == LE_HRESULTS.QST_E_DUPLICATE_VALUE:
            return ExistName
        else:
            return self._PrefixSymbol(ClipName)

    def _PrefixSymbol(self, name):
        global _conflict_counter
        _conflict_counter = _conflict_counter + 1
        prefix = Registry.ProgramOptions.GetVal('Duplicate Symbol
Prefix')
        newName = '%s%d_%s' % (prefix, _conflict_counter, name)
        if len(newName) > 40:
            return newName[:39]
        else:
            return newName

Passing this to the client looks like:
        from win32com.server import util #, policy, dispatcher
        handler = util.wrap(SymbolConflictHandler())

        self.hFirst, self.hLast =
self.program.MergeClipData(self.pasteBin,
                                                             0,

self.refNode,

self.before,
                                                             handler)

It looks like Agent is forcing a bunch of bogus line breaks in here,
sorry.

Dan Pierson, Control Technology Corporation
dan at control.com



More information about the Python-list mailing list