Chip, and Programmers,

    This is the steps to get both clipboard data and files copied or cut; what 
is stored on the clipboard.
    The Python is easy to understand as I had stated before, the only 
difference is there no end statements because blocks of code are based on 
indentation. The start of the block is always the : character.
    Comments are either in # character for a single line and """ if multiple 
lines and must end with """.
    Loops and such have short cuts as do things like making arrays and 
dictionaries, [] or {} respectively.
In Python you import the code you need and easier than setting it up in C++ or 
Visual Basic.
    The def statement, in lower case only, is the calling of a function or 
procedure. There is no ending statement because all Python is indent sensitive, 
along with case sensitive.
  A function is used only if a return statement is inside the block of code and 
halts at that return statement.
NOTE:
   There is no declare of type, it is done when the program is run and errors 
happen if you mix types, so be careful when coding.
An error happens if you call a variable name before an assignment, because of 
above type error issues.
Variable type is assumed based on the first assignment to it. VB kind of does 
this.

Windows Machines Format: (I have others.)
import platform
import os
from win32com.shell import shell

#Below are code values which can be gotten on the MSN site or calling a method 
to get what is available.
CF_TEXT = 1  # Clipboard text.
CF_BITMAP = 2  # Clipboard Pitures
CF_METAFILEPICT = 3
CF_SYLK = 4
CF_DIF = 5
CF_TIFF = 6
CF_OEMTEXT = 7  # Clipboard text in tty, (line feed and return added.)
CF_DIB = 8
CF_PALETTE = 9
CF_PENDATA = 10
CF_RIFF = 11
CF_WAVE = 12
CF_UNICODETEXT = 13
CF_ENHMETAFILE = 14
CF_HDROP = 15  # Clipboard file list used in drag and drop, any file method.
CF_LOCALE = 16  # Needed if you want to change the country code/text format.
CF_MAX = 18
CF_OWNERDISPLAY = 128
CF_DSPTEXT = 129
CF_DSPBITMAP = 130
CF_DSPMETAFILEPICT = 131
CF_DSPENHMETAFILE = 142

#I pass in the type of operation code, text or file in the parms list
#This routine is used for pasting data only and you can have a calling 
procedure specifying which for what using the code inside the parm list.
#Such as: clipboard.paste( codeType) as the calling property.
def winGetClipboard( cf_codeType):
    "Fetch The Clipboard Data For Use, Such As A Paste Command."
    #Do you want file names?
    if cf_codeType == CF_HDROP:
        files = []  #Not needed, it is returned instead.
        return getPasteFiles (files)  # Return file list inside an array, 
including paths.
    else:
        # This is calling C++ code to open the clipboard and then closing it.
        ctypes.windll.user32.OpenClipboard(0)
        # Fetch the pointer for the text inside the clipboard.
        pcontents = ctypes.windll.user32.GetClipboardData( cf_codeType) # 1 is 
CF_TEXT
        data = ctypes.c_char_p(pcontents).value
        #ctypes.windll.kernel32.GlobalUnlock(pcontents)  #also not needed.
        ctypes.windll.user32.CloseClipboard()
        return data  # Standard text format.

def getPasteFiles( Files ):
    "Get File List and Below Are Value Descriptions."
    #Format For Calling user32 library from python:
    #ctypes.windll.user32. This is just an example and is commented out.
    #Insure desired format is there, and open clipboard.
    if ctypes.windll.user32.IsClipboardFormatAvailable( CF_HDROP):
        if ctypes.windll.user32.OpenClipboard(0):
            #Get handle to Dropped Filelist data, and number of files.
            hDrop = ctypes.windll.user32.GetClipboardData( CF_HDROP)
            num_files = shell.DragQueryFile(hDrop, -1)
            files= []
            for i in xrange(num_files):
                fpath= shell.DragQueryFile( hDrop, i)
                files.append(fpath)
            return files

Reply via email to