Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, *args, **kwargs):
tree.Tree.__init__(self, *args, **kwargs)
COMObject.__init__(self)
RegisterDragDrop(self.handle, byref(self._com_pointers_[0][1]))
self.iml = comctl.ImageList(16, 16, ILC_COLOR32 | ILC_MASK, 0, 32)
self.iml.AddIconsFromModule("shell32.dll", 16, 16, LR_LOADMAP3DCOLORS)
self.iml.SetBkColor(gdi.CLR_NONE)
self.SetImageList(self.iml)
self.SetRedraw(0)
item = comctl.TVITEMEX()
item.text = "A root"
item.image = 17
item.selectedImage = 17
item.children = 1
hRoot = self.InsertItem(comctl.TVI_ROOT, comctl.TVI_ROOT, item)
for i in range(100):
## IDropSource:
def GiveFeedback(self, this, dwEffect):
#print "giveFeedback", dwEffect
return DRAGDROP_S_USEDEFAULTCURSORS
def QueryContinueDrag(self, this, fEscapePressed, grfKeyState):
#print "qcd", fEscapePressed, grfKeyState
if fEscapePressed:
return DRAGDROP_S_CANCEL
elif not (grfKeyState & MK_LBUTTON):
return DRAGDROP_S_DROP
else:
return S_OK
class Tree(tree.Tree, COMObject):
_com_interfaces_ = [IDropTarget]
_factory = Factory()
def __init__(self, *args, **kwargs):
tree.Tree.__init__(self, *args, **kwargs)
COMObject.__init__(self)
RegisterDragDrop(self.handle, byref(self._com_pointers_[0][1]))
self.iml = comctl.ImageList(16, 16, ILC_COLOR32 | ILC_MASK, 0, 32)
self.iml.AddIconsFromModule("shell32.dll", 16, 16, LR_LOADMAP3DCOLORS)
self.iml.SetBkColor(gdi.CLR_NONE)
self.SetImageList(self.iml)
self.SetRedraw(0)
item.image = 17
item.selectedImage = 17
item.children = 1
hRoot = self.InsertItem(comctl.TVI_ROOT, comctl.TVI_ROOT, item)
for i in range(100):
item.mask = 0
item.text = "A child %d" % i
item.image = 3
item.selectedImage = 4
hChild = self.InsertItem(hRoot, comctl.TVI_LAST, item)
self.SetRedraw(1)
def dispose(self):
RevokeDragDrop(self.handle)
class List(list.List, COMObject):
_com_interfaces_ = [IDropTarget]
_factory = Factory()
def __init__(self, *args, **kwargs):
list.List.__init__(self, *args, **kwargs)
COMObject.__init__(self)
RegisterDragDrop(self.handle, byref(self._com_pointers_[0][1]))
self.InsertColumns([("blaat", 100), ("col2", 150)])
self.SetRedraw(0)
for i in range(100):
self.InsertRow(i, ["blaat %d" % i, "blaat col2 %d" % i])
self.SetRedraw(1)
def dispose(self):
#accPropServer.py
#A part of NonVisual Desktop Access (NVDA)
#Copyright (C) 2017-2018 NV Access Limited, Derek Riemer, Babbage B.V.
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
"""Implementation of IAccProcServer, so that customization of a wx control can be done very fast."""
from logHandler import log
from comtypes.automation import VT_EMPTY
from comtypes import COMObject
from comInterfaces.Accessibility import IAccPropServer
class IAccPropServer_Impl(COMObject):
"""Base class for implementing a COM interface for AccPropServer.
Please override the _GetPropValue method, not GetPropValue.
GetPropValue wraps _getPropValue to catch and log exceptions (Which for some reason NVDA's logger misses when they occur in GetPropValue).
"""
_com_interfaces_ = [
IAccPropServer
]
def __init__(self, control, *args, **kwargs):
"""Initialize the instance of AccPropServer.
@param control: the WX control instance, so you can look up things in the _getPropValue method.
It's available on self.control.
@Type control: Subclass of wx.Window
"""
self.control = control
MATHTYPE_PROGID = "Equation.DSMT"
#comtypes COM interface definition for Powerpoint application object's events
class EApplication(IDispatch):
_iid_=comtypes.GUID('{914934C2-5A91-11CF-8700-00AA0060263B}')
_methods_=[]
_disp_methods_=[
comtypes.DISPMETHOD([comtypes.dispid(2001)],None,"WindowSelectionChange",
(['in'],ctypes.POINTER(IDispatch),'sel'),),
comtypes.DISPMETHOD([comtypes.dispid(2013)],None,"SlideShowNextSlide",
(['in'],ctypes.POINTER(IDispatch),'slideShowWindow'),),
]
#Our implementation of the EApplication COM interface to receive application events
class ppEApplicationSink(comtypes.COMObject):
_com_interfaces_=[EApplication,IDispatch]
def SlideShowNextSlide(self,slideShowWindow=None):
i=winUser.getGUIThreadInfo(0)
oldFocus=api.getFocusObject()
if not isinstance(oldFocus,SlideShowWindow) or i.hwndFocus!=oldFocus.windowHandle:
return
oldFocus.treeInterceptor.rootNVDAObject.handleSlideChange()
def WindowSelectionChange(self,sel):
i=winUser.getGUIThreadInfo(0)
oldFocus=api.getFocusObject()
if not isinstance(oldFocus,Window) or i.hwndFocus!=oldFocus.windowHandle:
return
if isinstance(oldFocus,DocumentWindow):
documentWindow=oldFocus
"""
HERE BE DRAGONS
"""
_user32 = windll.user32
_atl = windll.atl
# for some reason we have to set an offset for the height of ATL window in order for the vertical scrollbar to be fully
# visible
VERTICAL_SCROLLBAR_OFFSET = 20
NON_RESIZEABLE_OFFSET = 6
class UIHandler(COMObject):
_com_interfaces_ = [IDocHostUIHandler]
def __init__(self, *args, **kwargs):
COMObject.__init__(self, *args, **kwargs)
def ShowContextMenu(self, *args, **kwarg):
# Disable context menu
return False
def GetHostInfo(self, doc):
doc.contents.dwFlags |= 0x40000000
return hresult.S_OK
class BrowserView(object):
instance = None
def CreateEventReceiver(interface, handler):
class Sink(comtypes.COMObject):
_com_interfaces_ = [interface]
def _get_method_finder_(self, itf):
# Use a special MethodFinder that will first try 'self',
# then the sink.
return _SinkMethodFinder(self, handler)
sink = Sink()
# Since our Sink object doesn't have typeinfo, it needs a
# _dispimpl_ dictionary to dispatch events received via Invoke.
if issubclass(interface, comtypes.automation.IDispatch) \
and not hasattr(sink, "_dispimpl_"):
finder = sink._get_method_finder_(interface)
dispimpl = sink._dispimpl_ = {}
for m in interface._methods_:
_case_insensitive_ = True
_iid_ = GUID('{B196B288-BAB4-101A-B69C-00AA00341D07}')
IOleControl._methods_ = [
COMMETHOD([], HRESULT, 'GetControlInfo',
(['out'], POINTER(DWORD), 'pCI')), # should be CONTROLINFO but we don't use it
COMMETHOD([], HRESULT, 'OnMnemonic',
(['in'], POINTER(DWORD), 'pMsg')), # should be MSG but we don't use it
COMMETHOD([], HRESULT, 'OnAmbientPropertyChange',
(['in'], DWORD, 'dispID')), # should be DISPID but we don't use it
# ...
]
DISPID_AMBIENT_USERAGENT = -5513
class IESite(COMObject):
_com_interfaces_ = [IDispatch, IOleClientSite]
def IDispatch_Invoke(self, this, memid, riid, lcid, wFlags, pDispParams,
pVarResult, pExcepInfo, puArgErr):
if memid == DISPID_AMBIENT_USERAGENT and pVarResult:
pVarResult[0].value = USER_AGENT
return S_OK
_ieSite = IESite()
#
# here ends the COM nonsense for user-agent.
#
self.container = self.widgets.get_widget('drawingarea1')
self.container2 = self.widgets.get_widget('drawingarea2')
self.container.realize()
def LockServer(self, this, fLock):
if fLock:
comtypes.COMObject.__server__.Lock()
else:
comtypes.COMObject.__server__.Unlock()
return S_OK
"""
IAudioEndpointVolumeCallback.OnNotify() example.
The OnNotify() callback method gets called on volume change.
"""
from __future__ import print_function
from ctypes import POINTER, cast
from comtypes import CLSCTX_ALL, COMObject
from pycaw.pycaw import (AudioUtilities, IAudioEndpointVolume,
IAudioEndpointVolumeCallback)
class AudioEndpointVolumeCallback(COMObject):
_com_interfaces_ = [IAudioEndpointVolumeCallback]
def OnNotify(self, pNotify):
print('OnNotify callback')
def main():
devices = AudioUtilities.GetSpeakers()
interface = devices.Activate(
IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
volume = cast(interface, POINTER(IAudioEndpointVolume))
callback = AudioEndpointVolumeCallback()
volume.RegisterControlChangeNotify(callback)
for i in range(3):
volume.SetMute(0, None)
volume.SetMute(1, None)