Malte Skarupke schrieb:
> I'm trying to get the 3D Space Navigator
> (http://www.3dconnexion.com/) to work in Python. I quickly found a
> solution using comtypes on the 3DConnexion developer forum:
> http://www.3dconnexion.com/forum/viewtopic.php?t=984&start=30
>
> However that solution only works with comtypes version 0.2.1. Any
> newer version will result in the events not registering.
I've looked up the thread in the forum. A user codenamed 'kitsu' wrote:
Note that there is a error in the comtypes 0.3.2 GetEvents function which
causes it to miss all events. I've reported it to the mailing list, but
until it is fixed use comtypes 0.2.1.
I have not found the 'report' he mentions on the mailing list.
Dois the code snippet that he posted here
http://www.3dconnexion.com/forum/viewtopic.php?t=984&start=33
work with comtypes 0.2.1, and not with later comtypes?
> This is the output I get from the GetEvents() function when using
> version 0.2.1:
>
>
> Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
> (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import logging
> >>> logging.basicConfig(level=logging.DEBUG)
> >>> class EventHandler:
> ... def __getattr__(self, name):
> ... print name
> ...
> >>> from comtypes.client import *
> DEBUG:comtypes:CoInitializeEx(None, 2)
> >>> x = CreateObject("TDxInput.Device")
> DEBUG:comtypes.client:TDxInput.Device ->
> {82C5AB54-C92C-4D52-AAC5-27E25E22604C}
>
> DEBUG:comtypes.client:CoCreateInstance({82C5AB54-C92C-4D52-AAC5-27E25E22604C},
> clsctx=None, interface=None)
> INFO:comtypes.client:wrap()
> INFO:comtypes.client:Does implement IProvideClassInfo
> INFO:comtypes.client:Implements default interface from typeinfo 'comtypes.gen._7858B9E0_5793_4BE4_9B53_661D922790D2_0_1_0.ISimpleDevice'>
> INFO:comtypes.client:Final result is c2c080>
> >>> x.Connect()
> 0
> >>> test = GetEvents(x.sensor, EventHandler)
> INFO:comtypes.client:wrap_outparam()
> DEBUG:comtypes.client: using
> sinkinterface 'comtypes.gen._7858B9E0_5793_4BE4_9B53_661D922790D2_0_1_0._ISensorEvents'>
> DEBUG:comtypes.client:Start advise 'comtypes.gen._7858B9E0_5793_4BE4_9B53_661D922790D2_0_1_0._ISensorEvents'>
> DEBUG:comtypes._comobject: 0x00C12590>.QueryInterface({E6929A4A-6F41-46C6-9252-A8CC53472CB1}) -> S_OK
> DEBUG:comtypes._comobject:1 active COM objects: Added
>
> DEBUG:comtypes._comobject: 0x00C12590>.AddRef() -> 1
> DEBUG:comtypes.client:End advise 'comtypes.gen._7858B9E0_5793_4BE4_9B53_661D922790D2_0_1_0._ISensorEvents'>
> DEBUG:comtypes._comobject: 0x00C12590>.Release() -> 0
> DEBUG:comtypes._comobject:0 active COM objects: Removed
>
> >>>
>
>
>
> And this is the output I get when I use version 0.5.1:
>
>
> Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
> (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import logging
> >>> logging.basicConfig(level=logging.DEBUG)
> >>> from comtypes.client import *
> DEBUG:comtypes:CoInitializeEx(None, 2)
> >>> x = CreateObject("TDxInput.Device")
> DEBUG:comtypes.client:TDxInput.Device ->
> {82C5AB54-C92C-4D52-AAC5-27E25E22604C}
>
> DEBUG:comtypes.client:CoCreateInstance({82C5AB54-C92C-4D52-AAC5-27E25E22604C},
> clsctx=None, interface=None)
> DEBUG:comtypes.client:GetBestInterface( at c0e3f0>)
> DEBUG:comtypes.client:Does implement IProvideClassInfo
> DEBUG:comtypes.client:Default interface is
> {CB3BF65E-0816-482A-BB11-64AF1E837812}
> DEBUG:comtypes:Release
>
> DEBUG:comtypes.client._generate:GetModule(TLIBATTR(GUID={7858B9E0-5793-4BE4-9B53-661D922790D2},
> Version=1.0, LCID=0, FLags=0x8))
> DEBUG:comtypes.client:Implements default interface from typeinfo 'comtypes.gen._7858B9E0_5793_4BE4_9B53_661D922790D2_0_1_0.ISimpleDevice'>
> DEBUG:comtypes.client:Final result is ptr=0x9f3fc0 at c14d00>
> DEBUG:comtypes:Release c0ed00>
> DEBUG:comtypes:Release
> DEBUG:comtypes:Release
> DEBUG:comtypes:Release
> DEBUG:comtypes:Release
> >>> x.Connect()
> 0
> >>> test = ShowEvents(x.sensor)
> DEBUG:comtypes.client:wrap_outparam( c14d50>)
> DEBUG:comtypes.client._events:
> using sinkinterface 'comtypes.gen._7858B9E0_5793_4BE4_9B53_661D922790D2_0_1_0._ISensorEvents'>
> DEBUG:comtypes:Release a91530>
> # event found: _ISensorEvents_SensorInput
> DEBUG:comtypes.client._events:Start advise 'comtypes.gen._7858B9E0_5793_4BE4_9B53_661D922790D2_0_1_0._ISensorEvents'>
> DEBUG:comtypes._comobject: 0x00C52990>.QueryInterface({E6929A4A-6F41-46C6-9252-A8CC53472CB1}) -> S_OK
> DEBUG:comtypes._comobject:1 active COM objects: Added