[python-win32] Drag and drop of files (CF_HDROP)

mir amicitas amicitas at gmail.com
Sun Sep 21 22:36:02 CEST 2008


>
>
> Can you have a look at this thread from earlier this
> year to see if it helps to answer you question:
>
> http://mail.python.org/pipermail/python-win32/2008-April/007409.html
>
> TJG


Thanks Tim for sending along that thread.
This is close to what I need (and provides some useful information).  This
example however takes the data out of the STGMEDIUM object, rather than
putting the data into it.  In doing so the data object does not have to be
defined.

The relevant code from the example is:

   def Drop (self, data_object, key_state, point, effect):
     data = data_object.GetData ((15, None, 1, -1, 1))
     n_files = shell.DragQueryFileW (data.data_handle, -1)

     filenames = [
       shell.DragQueryFileW (data.data_handle, n_file) \
         for n_file in range (n_files)
     ]


So my question is how can I make the data object so that I can place it into
the data object.

Here is the snippet of code from my project showing what I want to do.

class TestDataObjectFile:
    _com_interfaces_ = [pythoncom.IID_IDataObject]
    _public_methods_ = IDataObject_Methods
    def __init__(self, file_path):
        global num_do_objects
        num_do_objects += 1
        self.file_path = file_path
        self.supported_fe = []

        cf = win32con.CF_HDROP
        fe = cf, None, pythoncom.DVASPECT_CONTENT, -1,
pythoncom.TYMED_HGLOBAL
        self.supported_fe.append(fe)

    def __del__(self):
        global num_do_objects
        num_do_objects -= 1

    def _query_interface_(self, iid):
        if iid==pythoncom.IID_IEnumFORMATETC:
            return NewEnum(self.supported_fe, iid=iid)

    def GetData(self, fe):
        print 'GetData'
        ret_stg = None
        cf, target, aspect, index, tymed  = fe

        print cf, win32con.CF_HDROP

        if aspect & pythoncom.DVASPECT_CONTENT and \
           tymed==pythoncom.TYMED_HGLOBAL:
            if cf == win32con.CF_HDROP:
                ret_stg = pythoncom.STGMEDIUM()


                ret_stg.set(pythoncom.TYMED_HGLOBAL, self.file_path)

        if ret_stg is None:
            print 'No ret_stg.'
            raise COMException(hresult=winerror.E_NOTIMPL)
        return ret_stg

    . . .

----

The point where I am stuck is the lines in getData:
ret_stg = pythoncom.STGMEDIUM()
ret_stg.set(pythoncom.TYMED_HGLOBAL, self.file_path)

The problem is that what needs to be placed into ret_stg is not the
file_names (as I have done above),  but a data structure.

So my question is how do I get the filenames into the data object?

Thanks again for your help with this.


- Novi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20080921/b6b0551e/attachment.htm>


More information about the python-win32 mailing list