[python-win32] Creating python com objects

Alex Denham a1eio at hotmail.com
Fri Apr 25 11:53:04 CEST 2008


I've had a look at the example and i can't quite pick out what's being done differently other than pythoncom.WrapObject() is being called within a class and it's being called on the class it's in?
Or is it something to do with the arguments passed to wrap object?

Thanks for the help.
Alex

> From: rwupole at msn.com
> To: python-win32 at python.org
> Date: Thu, 24 Apr 2008 17:25:03 -0400
> Subject: [python-win32]  Creating python com objects
> 
> 
> Tim Golden wrote:
> > Alex Denham wrote:
> >>       Parameters
> >> 
> >> /pDataObj/ : *PyIDataObject **
> >>  
> >> How do i link the IDataObject to the IDragTarget?
> > 
> > I don't know that you can, if you're asking: how do I
> > find out where this is coming from?. I think the drag-drop
> > technique is endpoint-agnostic. (A high-sounding phrase I've
> > just invented).
> 
> Don't forget to trademark it !
> 
> > The most you can do is get hold of the data.
> > Again, I think.
> 
> This is correct, the IDataObject interface is provided by the object
> that's being dragged.  Unless you're also providing the dragged
> object the interface should be opaque.
> 
> > 
> > I'm out of my depth so I'm hoping that Roger or Mark
> > or other more knowledgeable people can chip in at this point
> > and help.
> > 
> > For the purposes of discussion, I attach below my test harness
> > code which creates a simple window and registers a simple
> > IDropTarget object against it.
> > 
> > Sorry to be no more help than this.
> > TJG
> > 
> > <code>
> > import os, sys
> > import win32gui
> > import win32con
> > import pythoncom
> > 
> > CLSID = '{89DD545A-2C83-4103-AFE3-6CEB7FF5ECA4}'
> > PROGID = "Tim.DropTarget"
> > DESC = "Drop target handler for Tim's app"
> > 
> > class DropTarget:
> >   _reg_clsid_ = CLSID
> >   _reg_progid_ = PROGID
> >   _reg_desc_ = DESC
> >   _public_methods_ = ['DragEnter', 'DragOver', 'DragLeave', 'Drop']
> >   _com_interfaces_ = [pythoncom.IID_IDropTarget]
> > 
> >   def DragEnter (self, data_object, key_state, point, effect):
> >        pass
> >   def DragOver (self, key_state, point, effect):
> >        pass
> >   def DragLeave (self):
> >        pass
> >   def Drop (self, data_object, key_state, point, effect):
> >        pass
> > 
> > def create_window ():
> >   def OnDestroy (hwnd, msg, wparam, lparam):
> >     win32gui.PostQuitMessage (0)
> > 
> >   wc = win32gui.WNDCLASS ()
> >   hinst = win32gui.GetModuleHandle(None)
> >   wc.lpszClassName = "DragDrop"
> >   wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW;
> >   wc.hCursor = win32gui.LoadCursor (0, win32con.IDC_ARROW)
> >   wc.hbrBackground = win32con.COLOR_WINDOW
> >   wc.lpfnWndProc = {win32con.WM_DESTROY : OnDestroy}
> >   classAtom = win32gui.RegisterClass (wc)
> >   style = win32con.WS_VISIBLE | \
> >     win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
> >   return win32gui.CreateWindow (
> >     classAtom,
> >     "Drag & Drop demo",
> >     style,
> >     0, 0, 100, 100,
> >     0, 0, hinst, None
> >   )
> > 
> > if __name__ == '__main__':
> >   pythoncom.OleInitialize ()
> >   drop_target = pythoncom.WrapObject (
> >     DropTarget,
> >     pythoncom.IID_IDropTarget,
> >     pythoncom.IID_IDropTarget
> >   )
> >   pythoncom.RegisterDragDrop (create_window (), drop_target)
> >   win32gui.PumpMessages ()
> > 
> > </code>
> 
> There's a little extra work you have to do for WrapObject to work locally.
> See \win32comext\authorization\demos\EditSecurity.py for an example.
> 
>         Roger
> 
> 
> 
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32

_________________________________________________________________
Be a superhero and win! Play the Iron Man Mashup Game 
http://www.ironmanmashup.co.uk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20080425/42884bcd/attachment.htm>


More information about the python-win32 mailing list