def Drop (self, data_object, key_state, point, effect): child_point = wrapped (win32gui.ScreenToClient, self.hwnd, point) child_hwnd = wrapped (win32gui.ChildWindowFromPoint, self.hwnd, child_point) data = data_object.GetData (self._data_format) n_files = shell.DragQueryFileW (data.data_handle, -1) if n_files: SendMessage ( child_hwnd, win32con.WM_SETTEXT, None, utils.string_as_pointer (shell.DragQueryFileW (data.data_handle, 0).encode (ENCODING)) )
def Drop(self, data_object, key_state, point, effect): global text_list try: data_object.QueryGetData(self.data_format) data = data_object.GetData(self.data_format) n_files = shell.DragQueryFileW(data.data_handle, -1) text_list = [] for n in range(min(n_files, 20)): text = shell.DragQueryFileW(data.data_handle, n) text_list.append(text) except pywintypes.com_error: text_list = ["Unsupported data format"]
def get_explorer_files( hwndOfExplorer = 0, selectedOnly = False ): print("Getting the list of files") paths = [] # Create instance of IShellWindows (I couldn't find a constant in pywin32) CLSID_IShellWindows = "{9BA05972-F6A8-11CF-A442-00A0C90A8F39}" shellwindows = win32com.client.Dispatch(CLSID_IShellWindows) # Loop over all currently open Explorer windows for window in shellwindows: # Skip windows we are not interested in. if hwndOfExplorer != 0 and hwndOfExplorer != window.HWnd: continue # Get IServiceProvider interface SP = window._oleobj_.QueryInterface( pythoncom.IID_IServiceProvider ) # Query the IServiceProvider for IShellBrowser shBrowser = SP.QueryService( shell.SID_STopLevelBrowser, shell.IID_IShellBrowser ) # Get the active IShellView object shView = shBrowser.QueryActiveShellView() # Get an IDataObject that contains the items of the view (either only selected or all). aspect = shellcon.SVGIO_SELECTION if selectedOnly else shellcon.SVGIO_ALLVIEW items = shView.GetItemObject( aspect, pythoncom.IID_IDataObject ) # Get the paths in drag-n-drop clipboard format. We don't actually use # the clipboard, but this format makes it easy to extract the file paths. # Use CFSTR_SHELLIDLIST instead of CF_HDROP if you want to get ITEMIDLIST # (aka PIDL) format, but you can't use the simple DragQueryFileW() API then. data = items.GetData(( win32con.CF_HDROP, None, pythoncom.DVASPECT_CONTENT, -1, pythoncom.TYMED_HGLOBAL )) # Use drag-n-drop API to extract the individual paths. numPaths = shell.DragQueryFileW( data.data_handle, -1 ) paths.extend([ shell.DragQueryFileW( data.data_handle, i ) \ for i in range( numPaths ) ]) if hwndOfExplorer != 0: break print("Sending the path of the file") engine.say("Which file do you wish to open ?") engine.runAndWait() engine.say("Mention the number of the file on the list, after the beep") engine.runAndWait() winsound.Beep(frequency, duration) recognizer.adjust_for_ambient_noise(source) audio = recognizer.listen(source,timeout=5,phrase_time_limit=6) engine.say("You just said :"+recognizer.recognize_google(audio)) engine.runAndWait() openfile(int(recognizer.recognize_google(audio)),paths)
def Drop(self, data_object, key_state, point, effect): child_point = wrapped(win32gui.ScreenToClient, self.hwnd, point) child_hwnd = wrapped(win32gui.ChildWindowFromPoint, self.hwnd, child_point) data = data_object.GetData(self._data_format) n_files = shell.DragQueryFileW(data.data_handle, -1) if n_files: files_string = shell.DragQueryFileW(data.data_handle, 0) print(type(files_string), files_string) address, _ = win32gui.PyGetBufferAddressAndLen( files_string.encode("mbcs")) #~ pointer_to_string = utils.string_as_pointer(files_string) SendMessage( child_hwnd, win32con.WM_SETTEXT, None, win32gui.PyGetBufferAddressAndLen( memoryview(files_string.encode("mbcs")))[0])
def _getDropFileList(self, stgMedium): rval = [] hDropInfo = stgMedium.data_handle nFiles = win32api.DragQueryFile(hDropInfo) try: for iFile in range(0, nFiles): filepath = shell.DragQueryFileW(hDropInfo, iFile) filepath = os.path.abspath(filepath) fileExists = os.path.exists(filepath) if fileExists: rval.append(filepath) finally: win32api.DragFinish(hDropInfo) return rval