home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Calibre / calibre-0.8.18.msi / file_262 / win32gui_struct.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-09-09  |  18.2 KB  |  536 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.7)
  3.  
  4. import sys
  5. import win32gui
  6. import win32con
  7. import struct
  8. import array
  9. import commctrl
  10. import pywintypes
  11. if win32gui.UNICODE:
  12.     
  13.     def _make_text_buffer(text):
  14.         if not isinstance(text, unicode):
  15.             raise TypeError('MENUITEMINFO text must be unicode')
  16.         data = (text + '\x00').encode('unicode-internal')
  17.         return array.array('b', data)
  18.  
  19. else:
  20.     
  21.     def _make_text_buffer(text):
  22.         if isinstance(text, unicode):
  23.             text = text.encode('mbcs')
  24.         return array.array('b', text + '\x00')
  25.  
  26.  
  27. def _make_empty_text_buffer(cch):
  28.     return _make_text_buffer('\x00' * cch)
  29.  
  30. if sys.version_info < (3, 0):
  31.     
  32.     def _make_memory(ob):
  33.         return str(buffer(ob))
  34.  
  35.     
  36.     def _make_bytes(sval):
  37.         return sval
  38.  
  39. else:
  40.     
  41.     def _make_memory(ob):
  42.         return bytes(memoryview(ob))
  43.  
  44.     
  45.     def _make_bytes(sval):
  46.         return sval.encode('ascii')
  47.  
  48.  
  49. def UnpackWMNOTIFY(lparam):
  50.     format = 'iii'
  51.     buf = win32gui.PyGetMemory(lparam, struct.calcsize(format))
  52.     (hwndFrom, idFrom, code) = struct.unpack(format, buf)
  53.     return (hwndFrom, idFrom, code)
  54.  
  55. _menuiteminfo_fmt = '5i5PiP'
  56.  
  57. def PackMENUITEMINFO(fType = None, fState = None, wID = None, hSubMenu = None, hbmpChecked = None, hbmpUnchecked = None, dwItemData = None, text = None, hbmpItem = None, dwTypeData = None):
  58.     extras = []
  59.     if dwTypeData is not None:
  60.         import warnings
  61.         warnings.warn('PackMENUITEMINFO: please use dwItemData instead of dwTypeData')
  62.     if dwItemData is None:
  63.         if not dwTypeData:
  64.             pass
  65.         dwItemData = 0
  66.     fMask = 0
  67.     if fType is None:
  68.         fType = 0
  69.     else:
  70.         fMask |= win32con.MIIM_FTYPE
  71.     if fState is None:
  72.         fState = 0
  73.     else:
  74.         fMask |= win32con.MIIM_STATE
  75.     if wID is None:
  76.         wID = 0
  77.     else:
  78.         fMask |= win32con.MIIM_ID
  79.     if hSubMenu is None:
  80.         hSubMenu = 0
  81.     else:
  82.         fMask |= win32con.MIIM_SUBMENU
  83.     if hbmpChecked is None:
  84.         hbmpChecked = hbmpUnchecked = 0
  85.     else:
  86.         fMask |= win32con.MIIM_CHECKMARKS
  87.     if dwItemData is None:
  88.         dwItemData = 0
  89.     else:
  90.         fMask |= win32con.MIIM_DATA
  91.     if hbmpItem is None:
  92.         hbmpItem = 0
  93.     else:
  94.         fMask |= win32con.MIIM_BITMAP
  95.     if text is not None:
  96.         fMask |= win32con.MIIM_STRING
  97.         str_buf = _make_text_buffer(text)
  98.         cch = len(text)
  99.         lptext = str_buf.buffer_info()[0]
  100.         extras.append(str_buf)
  101.     else:
  102.         lptext = 0
  103.         cch = 0
  104.     item = struct.pack(_menuiteminfo_fmt, struct.calcsize(_menuiteminfo_fmt), fMask, fType, fState, wID, long(hSubMenu), long(hbmpChecked), long(hbmpUnchecked), dwItemData, lptext, cch, long(hbmpItem))
  105.     return (array.array('b', item), extras)
  106.  
  107.  
  108. def UnpackMENUITEMINFO(s):
  109.     (cb, fMask, fType, fState, wID, hSubMenu, hbmpChecked, hbmpUnchecked, dwItemData, lptext, cch, hbmpItem) = struct.unpack(_menuiteminfo_fmt, s)
  110.     if fMask & win32con.MIIM_FTYPE == 0:
  111.         fType = None
  112.     if fMask & win32con.MIIM_STATE == 0:
  113.         fState = None
  114.     if fMask & win32con.MIIM_ID == 0:
  115.         wID = None
  116.     if fMask & win32con.MIIM_SUBMENU == 0:
  117.         hSubMenu = None
  118.     if fMask & win32con.MIIM_CHECKMARKS == 0:
  119.         hbmpChecked = None
  120.         hbmpUnchecked = None
  121.     if fMask & win32con.MIIM_DATA == 0:
  122.         dwItemData = None
  123.     if fMask & win32con.MIIM_BITMAP == 0:
  124.         hbmpItem = None
  125.     if fMask & win32con.MIIM_STRING:
  126.         text = win32gui.PyGetString(lptext, cch)
  127.     else:
  128.         text = None
  129.     return (fType, fState, wID, hSubMenu, hbmpChecked, hbmpUnchecked, dwItemData, text, hbmpItem)
  130.  
  131.  
  132. def EmptyMENUITEMINFO(mask = None, text_buf_size = 512):
  133.     extra = []
  134.     if mask is None:
  135.         mask = win32con.MIIM_BITMAP | win32con.MIIM_CHECKMARKS | win32con.MIIM_DATA | win32con.MIIM_FTYPE | win32con.MIIM_ID | win32con.MIIM_STATE | win32con.MIIM_STRING | win32con.MIIM_SUBMENU
  136.     if mask & win32con.MIIM_STRING:
  137.         text_buffer = _make_empty_text_buffer(text_buf_size)
  138.         extra.append(text_buffer)
  139.         (text_addr, _) = text_buffer.buffer_info()
  140.     else:
  141.         text_addr = text_buf_size = 0
  142.     buf = struct.pack(_menuiteminfo_fmt, struct.calcsize(_menuiteminfo_fmt), mask, 0, 0, 0, 0, 0, 0, 0, text_addr, text_buf_size, 0)
  143.     return (array.array('b', buf), extra)
  144.  
  145. _menuinfo_fmt = 'iiiiPiP'
  146.  
  147. def PackMENUINFO(dwStyle = None, cyMax = None, hbrBack = None, dwContextHelpID = None, dwMenuData = None, fMask = 0):
  148.     if dwStyle is None:
  149.         dwStyle = 0
  150.     else:
  151.         fMask |= win32con.MIM_STYLE
  152.     if cyMax is None:
  153.         cyMax = 0
  154.     else:
  155.         fMask |= win32con.MIM_MAXHEIGHT
  156.     if hbrBack is None:
  157.         hbrBack = 0
  158.     else:
  159.         fMask |= win32con.MIM_BACKGROUND
  160.     if dwContextHelpID is None:
  161.         dwContextHelpID = 0
  162.     else:
  163.         fMask |= win32con.MIM_HELPID
  164.     if dwMenuData is None:
  165.         dwMenuData = 0
  166.     else:
  167.         fMask |= win32con.MIM_MENUDATA
  168.     item = struct.pack(_menuinfo_fmt, struct.calcsize(_menuinfo_fmt), fMask, dwStyle, cyMax, hbrBack, dwContextHelpID, dwMenuData)
  169.     return array.array('b', item)
  170.  
  171.  
  172. def UnpackMENUINFO(s):
  173.     (cb, fMask, dwStyle, cyMax, hbrBack, dwContextHelpID, dwMenuData) = struct.unpack(_menuinfo_fmt, s)
  174.     if fMask & win32con.MIM_STYLE == 0:
  175.         dwStyle = None
  176.     if fMask & win32con.MIM_MAXHEIGHT == 0:
  177.         cyMax = None
  178.     if fMask & win32con.MIM_BACKGROUND == 0:
  179.         hbrBack = None
  180.     if fMask & win32con.MIM_HELPID == 0:
  181.         dwContextHelpID = None
  182.     if fMask & win32con.MIM_MENUDATA == 0:
  183.         dwMenuData = None
  184.     return (dwStyle, cyMax, hbrBack, dwContextHelpID, dwMenuData)
  185.  
  186.  
  187. def EmptyMENUINFO(mask = None):
  188.     if mask is None:
  189.         mask = win32con.MIM_STYLE | win32con.MIM_MAXHEIGHT | win32con.MIM_BACKGROUND | win32con.MIM_HELPID | win32con.MIM_MENUDATA
  190.     buf = struct.pack(_menuinfo_fmt, struct.calcsize(_menuinfo_fmt), mask, 0, 0, 0, 0, 0)
  191.     return array.array('b', buf)
  192.  
  193.  
  194. def _GetMaskAndVal(val, default, mask, flag):
  195.     if val is None:
  196.         return (mask, default)
  197.     if None is not None:
  198.         mask |= flag
  199.     return (mask, val)
  200.  
  201.  
  202. def PackTVINSERTSTRUCT(parent, insertAfter, tvitem):
  203.     (tvitem_buf, extra) = PackTVITEM(*tvitem)
  204.     tvitem_buf = tvitem_buf.tostring()
  205.     format = 'ii%ds' % len(tvitem_buf)
  206.     return (struct.pack(format, parent, insertAfter, tvitem_buf), extra)
  207.  
  208.  
  209. def PackTVITEM(hitem, state, stateMask, text, image, selimage, citems, param):
  210.     extra = []
  211.     mask = 0
  212.     (mask, hitem) = _GetMaskAndVal(hitem, 0, mask, commctrl.TVIF_HANDLE)
  213.     (mask, state) = _GetMaskAndVal(state, 0, mask, commctrl.TVIF_STATE)
  214.     if not mask & commctrl.TVIF_STATE:
  215.         stateMask = 0
  216.     (mask, text) = _GetMaskAndVal(text, None, mask, commctrl.TVIF_TEXT)
  217.     (mask, image) = _GetMaskAndVal(image, 0, mask, commctrl.TVIF_IMAGE)
  218.     (mask, selimage) = _GetMaskAndVal(selimage, 0, mask, commctrl.TVIF_SELECTEDIMAGE)
  219.     (mask, citems) = _GetMaskAndVal(citems, 0, mask, commctrl.TVIF_CHILDREN)
  220.     (mask, param) = _GetMaskAndVal(param, 0, mask, commctrl.TVIF_PARAM)
  221.     if text is None:
  222.         text_addr = text_len = 0
  223.     else:
  224.         text_buffer = _make_text_buffer(text)
  225.         text_len = len(text)
  226.         extra.append(text_buffer)
  227.         (text_addr, _) = text_buffer.buffer_info()
  228.     format = 'iiiiiiiiii'
  229.     buf = struct.pack(format, mask, hitem, state, stateMask, text_addr, text_len, image, selimage, citems, param)
  230.     return (array.array('b', buf), extra)
  231.  
  232.  
  233. def EmptyTVITEM(hitem, mask = None, text_buf_size = 512):
  234.     extra = []
  235.     if mask is None:
  236.         mask = commctrl.TVIF_HANDLE | commctrl.TVIF_STATE | commctrl.TVIF_TEXT | commctrl.TVIF_IMAGE | commctrl.TVIF_SELECTEDIMAGE | commctrl.TVIF_CHILDREN | commctrl.TVIF_PARAM
  237.     if mask & commctrl.TVIF_TEXT:
  238.         text_buffer = _make_empty_text_buffer(text_buf_size)
  239.         extra.append(text_buffer)
  240.         (text_addr, _) = text_buffer.buffer_info()
  241.     else:
  242.         text_addr = text_buf_size = 0
  243.     format = 'iiiiiiiiii'
  244.     buf = struct.pack(format, mask, hitem, 0, 0, text_addr, text_buf_size, 0, 0, 0, 0)
  245.     return (array.array('b', buf), extra)
  246.  
  247.  
  248. def UnpackTVITEM(buffer):
  249.     (item_mask, item_hItem, item_state, item_stateMask, item_textptr, item_cchText, item_image, item_selimage, item_cChildren, item_param) = struct.unpack('10i', buffer)
  250.     if not item_mask & commctrl.TVIF_TEXT:
  251.         item_textptr = None
  252.         item_cchText = None
  253.     if not item_mask & commctrl.TVIF_CHILDREN:
  254.         item_cChildren = None
  255.     if not item_mask & commctrl.TVIF_IMAGE:
  256.         item_image = None
  257.     if not item_mask & commctrl.TVIF_PARAM:
  258.         item_param = None
  259.     if not item_mask & commctrl.TVIF_SELECTEDIMAGE:
  260.         item_selimage = None
  261.     if not item_mask & commctrl.TVIF_STATE:
  262.         item_state = None
  263.         item_stateMask = None
  264.     if item_textptr:
  265.         text = win32gui.PyGetString(item_textptr)
  266.     else:
  267.         text = None
  268.     return (item_hItem, item_state, item_stateMask, text, item_image, item_selimage, item_cChildren, item_param)
  269.  
  270.  
  271. def UnpackTVNOTIFY(lparam):
  272.     format = 'iiii40s40s'
  273.     buf = win32gui.PyGetMemory(lparam, struct.calcsize(format))
  274.     (hwndFrom, id, code, action, buf_old, buf_new) = struct.unpack(format, buf)
  275.     item_old = UnpackTVITEM(buf_old)
  276.     item_new = UnpackTVITEM(buf_new)
  277.     return (hwndFrom, id, code, action, item_old, item_new)
  278.  
  279.  
  280. def UnpackTVDISPINFO(lparam):
  281.     format = 'iii40s'
  282.     buf = win32gui.PyGetMemory(lparam, struct.calcsize(format))
  283.     (hwndFrom, id, code, buf_item) = struct.unpack(format, buf)
  284.     item = UnpackTVITEM(buf_item)
  285.     return (hwndFrom, id, code, item)
  286.  
  287.  
  288. def PackLVITEM(item = None, subItem = None, state = None, stateMask = None, text = None, image = None, param = None, indent = None):
  289.     extra = []
  290.     mask = 0
  291.     if item is None:
  292.         item = 0
  293.     if subItem is None:
  294.         subItem = 0
  295.     if state is None:
  296.         state = 0
  297.         stateMask = 0
  298.     else:
  299.         mask |= commctrl.LVIF_STATE
  300.         if stateMask is None:
  301.             stateMask = state
  302.     if image is None:
  303.         image = 0
  304.     else:
  305.         mask |= commctrl.LVIF_IMAGE
  306.     if param is None:
  307.         param = 0
  308.     else:
  309.         mask |= commctrl.LVIF_PARAM
  310.     if indent is None:
  311.         indent = 0
  312.     else:
  313.         mask |= commctrl.LVIF_INDENT
  314.     if text is None:
  315.         text_addr = text_len = 0
  316.     else:
  317.         mask |= commctrl.LVIF_TEXT
  318.         text_buffer = _make_text_buffer(text)
  319.         text_len = len(text)
  320.         extra.append(text_buffer)
  321.         (text_addr, _) = text_buffer.buffer_info()
  322.     format = 'iiiiiiiiii'
  323.     buf = struct.pack(format, mask, item, subItem, state, stateMask, text_addr, text_len, image, param, indent)
  324.     return (array.array('b', buf), extra)
  325.  
  326.  
  327. def UnpackLVITEM(buffer):
  328.     (item_mask, item_item, item_subItem, item_state, item_stateMask, item_textptr, item_cchText, item_image, item_param, item_indent) = struct.unpack('10i', buffer)
  329.     if not item_mask & commctrl.LVIF_TEXT:
  330.         item_textptr = None
  331.         item_cchText = None
  332.     if not item_mask & commctrl.LVIF_IMAGE:
  333.         item_image = None
  334.     if not item_mask & commctrl.LVIF_PARAM:
  335.         item_param = None
  336.     if not item_mask & commctrl.LVIF_INDENT:
  337.         item_indent = None
  338.     if not item_mask & commctrl.LVIF_STATE:
  339.         item_state = None
  340.         item_stateMask = None
  341.     if item_textptr:
  342.         text = win32gui.PyGetString(item_textptr)
  343.     else:
  344.         text = None
  345.     return (item_item, item_subItem, item_state, item_stateMask, text, item_image, item_param, item_indent)
  346.  
  347.  
  348. def UnpackLVDISPINFO(lparam):
  349.     format = 'iii40s'
  350.     buf = win32gui.PyGetMemory(lparam, struct.calcsize(format))
  351.     (hwndFrom, id, code, buf_item) = struct.unpack(format, buf)
  352.     item = UnpackLVITEM(buf_item)
  353.     return (hwndFrom, id, code, item)
  354.  
  355.  
  356. def UnpackLVNOTIFY(lparam):
  357.     format = '3i8i'
  358.     buf = win32gui.PyGetMemory(lparam, struct.calcsize(format))
  359.     (hwndFrom, id, code, item, subitem, newstate, oldstate, changed, pt_x, pt_y, lparam) = struct.unpack(format, buf)
  360.     return (hwndFrom, id, code, item, subitem, newstate, oldstate, changed, (pt_x, pt_y), lparam)
  361.  
  362.  
  363. def EmptyLVITEM(item, subitem, mask = None, text_buf_size = 512):
  364.     extra = []
  365.     if mask is None:
  366.         mask = commctrl.LVIF_IMAGE | commctrl.LVIF_INDENT | commctrl.LVIF_TEXT | commctrl.LVIF_PARAM | commctrl.LVIF_STATE
  367.     if mask & commctrl.LVIF_TEXT:
  368.         text_buffer = _make_empty_text_buffer(text_buf_size)
  369.         extra.append(text_buffer)
  370.         (text_addr, _) = text_buffer.buffer_info()
  371.     else:
  372.         text_addr = text_buf_size = 0
  373.     format = 'iiiiiiiiii'
  374.     buf = struct.pack(format, mask, item, subitem, 0, 0, text_addr, text_buf_size, 0, 0, 0)
  375.     return (array.array('b', buf), extra)
  376.  
  377.  
  378. def PackLVCOLUMN(fmt = None, cx = None, text = None, subItem = None, image = None, order = None):
  379.     extra = []
  380.     mask = 0
  381.     (mask, fmt) = _GetMaskAndVal(fmt, 0, mask, commctrl.LVCF_FMT)
  382.     (mask, cx) = _GetMaskAndVal(cx, 0, mask, commctrl.LVCF_WIDTH)
  383.     (mask, text) = _GetMaskAndVal(text, None, mask, commctrl.LVCF_TEXT)
  384.     (mask, subItem) = _GetMaskAndVal(subItem, 0, mask, commctrl.LVCF_SUBITEM)
  385.     (mask, image) = _GetMaskAndVal(image, 0, mask, commctrl.LVCF_IMAGE)
  386.     (mask, order) = _GetMaskAndVal(order, 0, mask, commctrl.LVCF_ORDER)
  387.     if text is None:
  388.         text_addr = text_len = 0
  389.     else:
  390.         text_buffer = _make_text_buffer(text)
  391.         extra.append(text_buffer)
  392.         (text_addr, _) = text_buffer.buffer_info()
  393.         text_len = len(text)
  394.     format = 'iiiiiiii'
  395.     buf = struct.pack(format, mask, fmt, cx, text_addr, text_len, subItem, image, order)
  396.     return (array.array('b', buf), extra)
  397.  
  398.  
  399. def UnpackLVCOLUMN(lparam):
  400.     format = 'iiiiiiii'
  401.     (mask, fmt, cx, text_addr, text_size, subItem, image, order) = struct.unpack(format, lparam)
  402.     if not mask & commctrl.LVCF_FMT:
  403.         fmt = None
  404.     if not mask & commctrl.LVCF_WIDTH:
  405.         cx = None
  406.     if not mask & commctrl.LVCF_TEXT:
  407.         text_addr = None
  408.         text_size = None
  409.     if not mask & commctrl.LVCF_SUBITEM:
  410.         subItem = None
  411.     if not mask & commctrl.LVCF_IMAGE:
  412.         image = None
  413.     if not mask & commctrl.LVCF_ORDER:
  414.         order = None
  415.     if text_addr:
  416.         text = win32gui.PyGetString(text_addr)
  417.     else:
  418.         text = None
  419.     return (fmt, cx, text, subItem, image, order)
  420.  
  421.  
  422. def EmptyLVCOLUMN(mask = None, text_buf_size = 512):
  423.     extra = []
  424.     if mask is None:
  425.         mask = commctrl.LVCF_FMT | commctrl.LVCF_WIDTH | commctrl.LVCF_TEXT | commctrl.LVCF_SUBITEM | commctrl.LVCF_IMAGE | commctrl.LVCF_ORDER
  426.     if mask & commctrl.LVCF_TEXT:
  427.         text_buffer = _make_empty_text_buffer(text_buf_size)
  428.         extra.append(text_buffer)
  429.         (text_addr, _) = text_buffer.buffer_info()
  430.     else:
  431.         text_addr = text_buf_size = 0
  432.     format = 'iiiiiiii'
  433.     buf = struct.pack(format, mask, 0, 0, text_addr, text_buf_size, 0, 0, 0)
  434.     return (array.array('b', buf), extra)
  435.  
  436.  
  437. def PackLVHITTEST(pt):
  438.     format = 'iiiii'
  439.     buf = struct.pack(format, pt[0], pt[1], 0, 0, 0)
  440.     return (array.array('b', buf), None)
  441.  
  442.  
  443. def UnpackLVHITTEST(buf):
  444.     format = 'iiiii'
  445.     (x, y, flags, item, subitem) = struct.unpack(format, buf)
  446.     return ((x, y), flags, item, subitem)
  447.  
  448.  
  449. def PackHDITEM(cxy = None, text = None, hbm = None, fmt = None, param = None, image = None, order = None):
  450.     extra = []
  451.     mask = 0
  452.     (mask, cxy) = _GetMaskAndVal(cxy, 0, mask, commctrl.HDI_HEIGHT)
  453.     (mask, text) = _GetMaskAndVal(text, None, mask, commctrl.LVCF_TEXT)
  454.     (mask, hbm) = _GetMaskAndVal(hbm, 0, mask, commctrl.HDI_BITMAP)
  455.     (mask, fmt) = _GetMaskAndVal(fmt, 0, mask, commctrl.HDI_FORMAT)
  456.     (mask, param) = _GetMaskAndVal(param, 0, mask, commctrl.HDI_LPARAM)
  457.     (mask, image) = _GetMaskAndVal(image, 0, mask, commctrl.HDI_IMAGE)
  458.     (mask, order) = _GetMaskAndVal(order, 0, mask, commctrl.HDI_ORDER)
  459.     if text is None:
  460.         text_addr = text_len = 0
  461.     else:
  462.         text_buffer = _make_text_buffer(text)
  463.         extra.append(text_buffer)
  464.         (text_addr, _) = text_buffer.buffer_info()
  465.         text_len = len(text)
  466.     format = 'iiiiiiiiiii'
  467.     buf = struct.pack(format, mask, cxy, text_addr, hbm, text_len, fmt, param, image, order, 0, 0)
  468.     return (array.array('b', buf), extra)
  469.  
  470.  
  471. def PackDEV_BROADCAST(devicetype, rest_fmt, rest_data, extra_data = _make_bytes('')):
  472.     extra_data += _make_bytes('\x00' * (4 - len(extra_data) % 4))
  473.     format = 'iii' + rest_fmt
  474.     full_size = struct.calcsize(format) + len(extra_data)
  475.     data = (full_size, devicetype, 0) + rest_data
  476.     return struct.pack(format, *data) + extra_data
  477.  
  478.  
  479. def PackDEV_BROADCAST_HANDLE(handle, hdevnotify = 0, guid = _make_bytes('\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), name_offset = 0, data = _make_bytes('\x00')):
  480.     return PackDEV_BROADCAST(win32con.DBT_DEVTYP_HANDLE, 'PP16sl', (long(handle), long(hdevnotify), _make_memory(guid), name_offset), data)
  481.  
  482.  
  483. def PackDEV_BROADCAST_VOLUME(unitmask, flags):
  484.     return PackDEV_BROADCAST(win32con.DBT_DEVTYP_VOLUME, 'II', (unitmask, flags))
  485.  
  486.  
  487. def PackDEV_BROADCAST_DEVICEINTERFACE(classguid, name = ''):
  488.     if win32gui.UNICODE:
  489.         if not isinstance(name, unicode):
  490.             raise TypeError('Must provide unicode for the name')
  491.         name = name.encode('unicode-internal')
  492.     elif isinstance(name, unicode):
  493.         name = name.encode('mbcs')
  494.     rest_fmt = '16s%ds' % len(name)
  495.     rest_data = (_make_memory(pywintypes.IID(classguid)), name)
  496.     return PackDEV_BROADCAST(win32con.DBT_DEVTYP_DEVICEINTERFACE, rest_fmt, rest_data)
  497.  
  498.  
  499. class DEV_BROADCAST_INFO:
  500.     
  501.     def __init__(self, devicetype, **kw):
  502.         self.devicetype = devicetype
  503.         self.__dict__.update(kw)
  504.  
  505.     
  506.     def __str__(self):
  507.         return 'DEV_BROADCAST_INFO:' + str(self.__dict__)
  508.  
  509.  
  510.  
  511. def UnpackDEV_BROADCAST(lparam):
  512.     if lparam == 0:
  513.         return None
  514.     hdr_format = None
  515.     hdr_size = struct.calcsize(hdr_format)
  516.     hdr_buf = win32gui.PyGetMemory(lparam, hdr_size)
  517.     (size, devtype, reserved) = struct.unpack('iii', hdr_buf)
  518.     buf = win32gui.PyGetMemory(lparam, size)
  519.     extra = x = { }
  520.     if devtype == win32con.DBT_DEVTYP_HANDLE:
  521.         fmt = hdr_format + 'PP16sl'
  522.         (_, _, _, x['handle'], x['hdevnotify'], guid_bytes, x['nameoffset']) = struct.unpack(fmt, buf[:struct.calcsize(fmt)])
  523.         x['eventguid'] = pywintypes.IID(guid_bytes, True)
  524.     elif devtype == win32con.DBT_DEVTYP_DEVICEINTERFACE:
  525.         fmt = hdr_format + '16s'
  526.         (_, _, _, guid_bytes) = struct.unpack(fmt, buf[:struct.calcsize(fmt)])
  527.         x['classguid'] = pywintypes.IID(guid_bytes, True)
  528.         x['name'] = win32gui.PyGetString(lparam + struct.calcsize(fmt))
  529.     elif devtype == win32con.DBT_DEVTYP_VOLUME:
  530.         fmt = hdr_format + 'II'
  531.         (_, _, _, x['unitmask'], x['flags']) = struct.unpack(fmt, buf[:struct.calcsize(fmt)])
  532.     else:
  533.         raise NotImplementedError('unknown device type %d' % (devtype,))
  534.     return None(devtype, **extra)
  535.  
  536.