home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2512 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.8 KB  |  61 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import time
  6. import win32gui
  7. import win32con
  8. import win32api
  9. import win32file
  10. import win32gui_struct
  11. import winnt
  12. GUID_DEVINTERFACE_USB_DEVICE = '{A5DCBF10-6530-11D2-901F-00C04FB951ED}'
  13.  
  14. def OnDeviceChange(hwnd, msg, wp, lp):
  15.     info = win32gui_struct.UnpackDEV_BROADCAST(lp)
  16.     print 'Device change notification:', wp, info
  17.     if wp == win32con.DBT_DEVICEQUERYREMOVE and info.devicetype == win32con.DBT_DEVTYP_HANDLE:
  18.         print 'Device being removed - closing handle'
  19.         win32file.CloseHandle(info.handle)
  20.         win32gui.UnregisterDeviceNotification(info.hdevnotify)
  21.     
  22.     return True
  23.  
  24.  
  25. def TestDeviceNotifications(dir_names):
  26.     wc = win32gui.WNDCLASS()
  27.     wc.lpszClassName = 'test_devicenotify'
  28.     wc.style = win32con.CS_GLOBALCLASS | win32con.CS_VREDRAW | win32con.CS_HREDRAW
  29.     wc.hbrBackground = win32con.COLOR_WINDOW + 1
  30.     wc.lpfnWndProc = {
  31.         win32con.WM_DEVICECHANGE: OnDeviceChange }
  32.     class_atom = win32gui.RegisterClass(wc)
  33.     hwnd = win32gui.CreateWindow(wc.lpszClassName, 'Testing some devices', win32con.WS_CAPTION, 100, 100, 900, 900, 0, 0, 0, None)
  34.     hdevs = []
  35.     filter = win32gui_struct.PackDEV_BROADCAST_DEVICEINTERFACE(GUID_DEVINTERFACE_USB_DEVICE)
  36.     hdev = win32gui.RegisterDeviceNotification(hwnd, filter, win32con.DEVICE_NOTIFY_WINDOW_HANDLE)
  37.     hdevs.append(hdev)
  38.     for d in dir_names:
  39.         hdir = win32file.CreateFile(d, winnt.FILE_LIST_DIRECTORY, winnt.FILE_SHARE_READ | winnt.FILE_SHARE_WRITE | winnt.FILE_SHARE_DELETE, None, win32con.OPEN_EXISTING, win32con.FILE_FLAG_BACKUP_SEMANTICS | win32con.FILE_FLAG_OVERLAPPED, None)
  40.         filter = win32gui_struct.PackDEV_BROADCAST_HANDLE(hdir)
  41.         hdev = win32gui.RegisterDeviceNotification(hwnd, filter, win32con.DEVICE_NOTIFY_WINDOW_HANDLE)
  42.         hdevs.append(hdev)
  43.     
  44.     print 'Watching', len(hdevs), 'handles - press Ctrl+C to terminate, or'
  45.     print 'add and remove some USB devices...'
  46.     if not dir_names:
  47.         print '(Note you can also pass paths to watch on the command-line - eg,'
  48.         print 'pass the root of an inserted USB stick to see events specific to'
  49.         print 'that volume)'
  50.     
  51.     while None:
  52.         time.sleep(0.01)
  53.         continue
  54.         win32gui.DestroyWindow(hwnd)
  55.         win32gui.UnregisterClass(wc.lpszClassName, None)
  56.         return None
  57.  
  58. if __name__ == '__main__':
  59.     TestDeviceNotifications(sys.argv[1:])
  60.  
  61.