<s> import win32gui <EOL> import win32con <EOL> import struct <EOL> import array <EOL> import commctrl <EOL> import pywintypes <EOL> def UnpackWMNOTIFY ( lparam ) : <EOL> format = "<STR_LIT>" <EOL> buf = win32gui . PyMakeBuffer ( struct . calcsize ( format ) , lparam ) <EOL> hwndFrom , idFrom , code = struct . unpack ( format , buf ) <EOL> return hwndFrom , idFrom , code <EOL> menuitem_fmt = '<STR_LIT>' <EOL> def PackMENUITEMINFO ( fType = None , fState = None , wID = None , hSubMenu = None , <EOL> hbmpChecked = None , hbmpUnchecked = None , dwItemData = None , <EOL> text = None , hbmpItem = None , dwTypeData = None ) : <EOL> extras = [ ] <EOL> assert dwItemData is None or dwTypeData is None , "<STR_LIT>" <EOL> if dwTypeData is not None : <EOL> import warnings <EOL> warnings . warn ( "<STR_LIT>" ) <EOL> if dwItemData is None : <EOL> dwItemData = dwTypeData or <NUM_LIT:0> <EOL> fMask = <NUM_LIT:0> <EOL> if fType is None : fType = <NUM_LIT:0> <EOL> else : fMask |= win32con . MIIM_FTYPE <EOL> if fState is None : fState = <NUM_LIT:0> <EOL> else : fMask |= win32con . MIIM_STATE <EOL> if wID is None : wID = <NUM_LIT:0> <EOL> else : fMask |= win32con . MIIM_ID <EOL> if hSubMenu is None : hSubMenu = <NUM_LIT:0> <EOL> else : fMask |= win32con . MIIM_SUBMENU <EOL> if hbmpChecked is None : <EOL> assert hbmpUnchecked is None , "<STR_LIT>" <EOL> hbmpChecked = hbmpUnchecked = <NUM_LIT:0> <EOL> else : <EOL> assert hbmpUnchecked is not None , "<STR_LIT>" <EOL> fMask |= win32con . MIIM_CHECKMARKS <EOL> if dwItemData is None : dwItemData = <NUM_LIT:0> <EOL> else : fMask |= win32con . MIIM_DATA <EOL> if hbmpItem is None : hbmpItem = <NUM_LIT:0> <EOL> else : fMask |= win32con . MIIM_BITMAP <EOL> if text is not None : <EOL> fMask |= win32con . MIIM_STRING <EOL> if isinstance ( text , unicode ) : <EOL> text = text . encode ( "<STR_LIT>" ) <EOL> str_buf = array . array ( "<STR_LIT:c>" , text + '<STR_LIT>' ) <EOL> cch = len ( str_buf ) <EOL> lptext = str_buf . buffer_info ( ) [ <NUM_LIT:0> ] <EOL> extras . append ( str_buf ) <EOL> else : <EOL> lptext = <NUM_LIT:0> <EOL> cch = <NUM_LIT:0> <EOL> item = struct . pack ( <EOL> menuitem_fmt , <EOL> struct . calcsize ( menuitem_fmt ) , <EOL> fMask , <EOL> fType , <EOL> fState , <EOL> wID , <EOL> long ( hSubMenu ) , <EOL> long ( hbmpChecked ) , <EOL> long ( hbmpUnchecked ) , <EOL> dwItemData , <EOL> lptext , <EOL> cch , <EOL> long ( hbmpItem ) <EOL> ) <EOL> return array . array ( "<STR_LIT:c>" , item ) , extras <EOL> def UnpackMENUITEMINFO ( s ) : <EOL> ( cb , <EOL> fMask , <EOL> fType , <EOL> fState , <EOL> wID , <EOL> hSubMenu , <EOL> hbmpChecked , <EOL> hbmpUnchecked , <EOL> dwItemData , <EOL> lptext , <EOL> cch , <EOL> hbmpItem ) = struct . unpack ( menuitem_fmt , s ) <EOL> assert cb == len ( s ) <EOL> if fMask & win32con . MIIM_FTYPE == <NUM_LIT:0> : fType = None <EOL> if fMask & win32con . MIIM_STATE == <NUM_LIT:0> : fState = None <EOL> if fMask & win32con . MIIM_ID == <NUM_LIT:0> : wID = None <EOL> if fMask & win32con . MIIM_SUBMENU == <NUM_LIT:0> : hSubMenu = None <EOL> if fMask & win32con . MIIM_CHECKMARKS == <NUM_LIT:0> : hbmpChecked = hbmpUnchecked = None <EOL> if fMask & win32con . MIIM_DATA == <NUM_LIT:0> : dwItemData = None <EOL> if fMask & win32con . MIIM_BITMAP == <NUM_LIT:0> : hbmpItem = None <EOL> if fMask & win32con . MIIM_STRING : <EOL> text = win32gui . PyGetString ( lptext , cch ) <EOL> else : <EOL> text = None <EOL> return fType , fState , wID , hSubMenu , hbmpChecked , hbmpUnchecked , dwItemData , text , hbmpItem <EOL> def EmptyMENUITEMINFO ( mask = None , text_buf_size = <NUM_LIT> ) : <EOL> extra = [ ] <EOL> if mask is None : <EOL> 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 <EOL> if mask & win32con . MIIM_STRING : <EOL> text_buffer = array . array ( "<STR_LIT:c>" , "<STR_LIT>" * text_buf_size ) <EOL> extra . append ( text_buffer ) <EOL> text_addr , text_len = text_buffer . buffer_info ( ) <EOL> else : <EOL> text_addr = text_len = <NUM_LIT:0> <EOL> buf = struct . pack ( <EOL> menuitem_fmt , <EOL> struct . calcsize ( menuitem_fmt ) , <EOL> mask , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> text_addr , <EOL> text_len , <EOL> <NUM_LIT:0> , <EOL> ) <EOL> return array . array ( "<STR_LIT:c>" , buf ) , extra <EOL> menuinfo_fmt = '<STR_LIT>' <EOL> def PackMENUINFO ( dwStyle = None , cyMax = None , <EOL> hbrBack = None , dwContextHelpID = None , dwMenuData = None , <EOL> fMask = <NUM_LIT:0> ) : <EOL> if dwStyle is None : dwStyle = <NUM_LIT:0> <EOL> else : fMask |= win32con . MIM_STYLE <EOL> if cyMax is None : cyMax = <NUM_LIT:0> <EOL> else : fMask |= win32con . MIM_MAXHEIGHT <EOL> if hbrBack is None : hbrBack = <NUM_LIT:0> <EOL> else : fMask |= win32con . MIM_BACKGROUND <EOL> if dwContextHelpID is None : dwContextHelpID = <NUM_LIT:0> <EOL> else : fMask |= win32con . MIM_HELPID <EOL> if dwMenuData is None : dwMenuData = <NUM_LIT:0> <EOL> else : fMask |= win32con . MIM_MENUDATA <EOL> item = struct . pack ( <EOL> menuinfo_fmt , <EOL> struct . calcsize ( menuinfo_fmt ) , <EOL> fMask , <EOL> dwStyle , <EOL> cyMax , <EOL> hbrBack , <EOL> dwContextHelpID , <EOL> dwMenuData ) <EOL> return array . array ( "<STR_LIT:c>" , item ) <EOL> def UnpackMENUINFO ( s ) : <EOL> ( cb , <EOL> fMask , <EOL> dwStyle , <EOL> cyMax , <EOL> hbrBack , <EOL> dwContextHelpID , <EOL> dwMenuData ) = struct . unpack ( menuinfo_fmt , s ) <EOL> assert cb == len ( s ) <EOL> if fMask & win32con . MIM_STYLE == <NUM_LIT:0> : dwStyle = None <EOL> if fMask & win32con . MIM_MAXHEIGHT == <NUM_LIT:0> : cyMax = None <EOL> if fMask & win32con . MIM_BACKGROUND == <NUM_LIT:0> : hbrBack = None <EOL> if fMask & win32con . MIM_HELPID == <NUM_LIT:0> : dwContextHelpID = None <EOL> if fMask & win32con . MIM_MENUDATA == <NUM_LIT:0> : dwMenuData = None <EOL> return dwStyle , cyMax , hbrBack , dwContextHelpID , dwMenuData <EOL> def EmptyMENUINFO ( mask = None ) : <EOL> if mask is None : <EOL> mask = win32con . MIM_STYLE | win32con . MIM_MAXHEIGHT | win32con . MIM_BACKGROUND | win32con . MIM_HELPID | win32con . MIM_MENUDATA <EOL> buf = struct . pack ( <EOL> menuinfo_fmt , <EOL> struct . calcsize ( menuinfo_fmt ) , <EOL> mask , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> ) <EOL> return array . array ( "<STR_LIT:c>" , buf ) <EOL> def _GetMaskAndVal ( val , default , mask , flag ) : <EOL> if val is None : <EOL> return mask , default <EOL> else : <EOL> if flag is not None : <EOL> mask |= flag <EOL> return mask , val <EOL> def PackTVINSERTSTRUCT ( parent , insertAfter , tvitem ) : <EOL> tvitem_buf , extra = PackTVITEM ( * tvitem ) <EOL> tvitem_buf = tvitem_buf . tostring ( ) <EOL> format = "<STR_LIT>" % len ( tvitem_buf ) <EOL> return struct . pack ( format , parent , insertAfter , tvitem_buf ) , extra <EOL> def PackTVITEM ( hitem , state , stateMask , text , image , selimage , citems , param ) : <EOL> extra = [ ] <EOL> mask = <NUM_LIT:0> <EOL> mask , hitem = _GetMaskAndVal ( hitem , <NUM_LIT:0> , mask , commctrl . TVIF_HANDLE ) <EOL> mask , state = _GetMaskAndVal ( state , <NUM_LIT:0> , mask , commctrl . TVIF_STATE ) <EOL> if not mask & commctrl . TVIF_STATE : <EOL> stateMask = <NUM_LIT:0> <EOL> mask , text = _GetMaskAndVal ( text , None , mask , commctrl . TVIF_TEXT ) <EOL> mask , image = _GetMaskAndVal ( image , <NUM_LIT:0> , mask , commctrl . TVIF_IMAGE ) <EOL> mask , selimage = _GetMaskAndVal ( selimage , <NUM_LIT:0> , mask , commctrl . TVIF_SELECTEDIMAGE ) <EOL> mask , citems = _GetMaskAndVal ( citems , <NUM_LIT:0> , mask , commctrl . TVIF_CHILDREN ) <EOL> mask , param = _GetMaskAndVal ( param , <NUM_LIT:0> , mask , commctrl . TVIF_PARAM ) <EOL> if text is None : <EOL> text_addr = text_len = <NUM_LIT:0> <EOL> else : <EOL> if isinstance ( text , unicode ) : <EOL> text = text . encode ( "<STR_LIT>" ) <EOL> text_buffer = array . array ( "<STR_LIT:c>" , text + "<STR_LIT>" ) <EOL> extra . append ( text_buffer ) <EOL> text_addr , text_len = text_buffer . buffer_info ( ) <EOL> format = "<STR_LIT>" <EOL> buf = struct . pack ( format , <EOL> mask , hitem , <EOL> state , stateMask , <EOL> text_addr , text_len , <EOL> image , selimage , <EOL> citems , param ) <EOL> return array . array ( "<STR_LIT:c>" , buf ) , extra <EOL> def EmptyTVITEM ( hitem , mask = None , text_buf_size = <NUM_LIT> ) : <EOL> extra = [ ] <EOL> if mask is None : <EOL> mask = commctrl . TVIF_HANDLE | commctrl . TVIF_STATE | commctrl . TVIF_TEXT | commctrl . TVIF_IMAGE | commctrl . TVIF_SELECTEDIMAGE | commctrl . TVIF_CHILDREN | commctrl . TVIF_PARAM <EOL> if mask & commctrl . TVIF_TEXT : <EOL> text_buffer = array . array ( "<STR_LIT:c>" , "<STR_LIT>" * text_buf_size ) <EOL> extra . append ( text_buffer ) <EOL> text_addr , text_len = text_buffer . buffer_info ( ) <EOL> else : <EOL> text_addr = text_len = <NUM_LIT:0> <EOL> format = "<STR_LIT>" <EOL> buf = struct . pack ( format , <EOL> mask , hitem , <EOL> <NUM_LIT:0> , <NUM_LIT:0> , <EOL> text_addr , text_len , <EOL> <NUM_LIT:0> , <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> return array . array ( "<STR_LIT:c>" , buf ) , extra <EOL> def UnpackTVITEM ( buffer ) : <EOL> item_mask , item_hItem , item_state , item_stateMask , item_textptr , item_cchText , item_image , item_selimage , item_cChildren , item_param = struct . unpack ( "<STR_LIT>" , buffer ) <EOL> if not ( item_mask & commctrl . TVIF_TEXT ) : item_textptr = item_cchText = None <EOL> if not ( item_mask & commctrl . TVIF_CHILDREN ) : item_cChildren = None <EOL> if not ( item_mask & commctrl . TVIF_IMAGE ) : item_image = None <EOL> if not ( item_mask & commctrl . TVIF_PARAM ) : item_param = None <EOL> if not ( item_mask & commctrl . TVIF_SELECTEDIMAGE ) : item_selimage = None <EOL> if not ( item_mask & commctrl . TVIF_STATE ) : item_state = item_stateMask = None <EOL> if item_textptr : <EOL> text = win32gui . PyGetString ( item_textptr ) <EOL> else : <EOL> text = None <EOL> return item_hItem , item_state , item_stateMask , text , item_image , item_selimage , item_cChildren , item_param <EOL> def UnpackTVNOTIFY ( lparam ) : <EOL> format = "<STR_LIT>" <EOL> buf = win32gui . PyMakeBuffer ( struct . calcsize ( format ) , lparam ) <EOL> hwndFrom , id , code , action , buf_old , buf_new = struct . unpack ( format , buf ) <EOL> item_old = UnpackTVITEM ( buf_old ) <EOL> item_new = UnpackTVITEM ( buf_new ) <EOL> return hwndFrom , id , code , action , item_old , item_new <EOL> def UnpackTVDISPINFO ( lparam ) : <EOL> format = "<STR_LIT>" <EOL> buf = win32gui . PyMakeBuffer ( struct . calcsize ( format ) , lparam ) <EOL> hwndFrom , id , code , buf_item = struct . unpack ( format , buf ) <EOL> item = UnpackTVITEM ( buf_item ) <EOL> return hwndFrom , id , code , item <EOL> def PackLVITEM ( item = None , subItem = None , state = None , stateMask = None , text = None , image = None , param = None , indent = None ) : <EOL> extra = [ ] <EOL> mask = <NUM_LIT:0> <EOL> if item is None : item = <NUM_LIT:0> <EOL> if subItem is None : subItem = <NUM_LIT:0> <EOL> if state is None : <EOL> state = <NUM_LIT:0> <EOL> stateMask = <NUM_LIT:0> <EOL> else : <EOL> mask |= commctrl . LVIF_STATE <EOL> if stateMask is None : stateMask = state <EOL> if image is None : image = <NUM_LIT:0> <EOL> else : mask |= commctrl . LVIF_IMAGE <EOL> if param is None : param = <NUM_LIT:0> <EOL> else : mask |= commctrl . LVIF_PARAM <EOL> if indent is None : indent = <NUM_LIT:0> <EOL> else : mask |= commctrl . LVIF_INDENT <EOL> if text is None : <EOL> text_addr = text_len = <NUM_LIT:0> <EOL> else : <EOL> mask |= commctrl . LVIF_TEXT <EOL> if isinstance ( text , unicode ) : <EOL> text = text . encode ( "<STR_LIT>" ) <EOL> text_buffer = array . array ( "<STR_LIT:c>" , text + "<STR_LIT>" ) <EOL> extra . append ( text_buffer ) <EOL> text_addr , text_len = text_buffer . buffer_info ( ) <EOL> format = "<STR_LIT>" <EOL> buf = struct . pack ( format , <EOL> mask , item , subItem , <EOL> state , stateMask , <EOL> text_addr , text_len , <EOL> image , param , indent ) <EOL> return array . array ( "<STR_LIT:c>" , buf ) , extra <EOL> def UnpackLVITEM ( buffer ) : <EOL> item_mask , item_item , item_subItem , item_state , item_stateMask , item_textptr , item_cchText , item_image , item_param , item_indent = struct . unpack ( "<STR_LIT>" , buffer ) <EOL> if not ( item_mask & commctrl . LVIF_TEXT ) : item_textptr = item_cchText = None <EOL> if not ( item_mask & commctrl . LVIF_IMAGE ) : item_image = None <EOL> if not ( item_mask & commctrl . LVIF_PARAM ) : item_param = None <EOL> if not ( item_mask & commctrl . LVIF_INDENT ) : item_indent = None <EOL> if not ( item_mask & commctrl . LVIF_STATE ) : item_state = item_stateMask = None <EOL> if item_textptr : <EOL> text = win32gui . PyGetString ( item_textptr ) <EOL> else : <EOL> text = None <EOL> return item_item , item_subItem , item_state , item_stateMask , text , item_image , item_param , item_indent <EOL> def UnpackLVDISPINFO ( lparam ) : <EOL> format = "<STR_LIT>" <EOL> buf = win32gui . PyMakeBuffer ( struct . calcsize ( format ) , lparam ) <EOL> hwndFrom , id , code , buf_item = struct . unpack ( format , buf ) <EOL> item = UnpackLVITEM ( buf_item ) <EOL> return hwndFrom , id , code , item <EOL> def UnpackLVNOTIFY ( lparam ) : <EOL> format = "<STR_LIT>" <EOL> buf = win32gui . PyMakeBuffer ( struct . calcsize ( format ) , lparam ) <EOL> hwndFrom , id , code , item , subitem , newstate , oldstate , changed , pt_x , pt_y , lparam = struct . unpack ( format , buf ) <EOL> return hwndFrom , id , code , item , subitem , newstate , oldstate , changed , ( pt_x , pt_y ) , lparam <EOL> def EmptyLVITEM ( item , subitem , mask = None , text_buf_size = <NUM_LIT> ) : <EOL> extra = [ ] <EOL> if mask is None : <EOL> mask = commctrl . LVIF_IMAGE | commctrl . LVIF_INDENT | commctrl . LVIF_TEXT | commctrl . LVIF_PARAM | commctrl . LVIF_STATE <EOL> if mask & commctrl . LVIF_TEXT : <EOL> text_buffer = array . array ( "<STR_LIT:c>" , "<STR_LIT>" * text_buf_size ) <EOL> extra . append ( text_buffer ) <EOL> text_addr , text_len = text_buffer . buffer_info ( ) <EOL> else : <EOL> text_addr = text_len = <NUM_LIT:0> <EOL> format = "<STR_LIT>" <EOL> buf = struct . pack ( format , <EOL> mask , item , subitem , <EOL> <NUM_LIT:0> , <NUM_LIT:0> , <EOL> text_addr , text_len , <EOL> <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> return array . array ( "<STR_LIT:c>" , buf ) , extra <EOL> def PackLVCOLUMN ( fmt = None , cx = None , text = None , subItem = None , image = None , order = None ) : <EOL> extra = [ ] <EOL> mask = <NUM_LIT:0> <EOL> mask , fmt = _GetMaskAndVal ( fmt , <NUM_LIT:0> , mask , commctrl . LVCF_FMT ) <EOL> mask , cx = _GetMaskAndVal ( cx , <NUM_LIT:0> , mask , commctrl . LVCF_WIDTH ) <EOL> mask , text = _GetMaskAndVal ( text , None , mask , commctrl . LVCF_TEXT ) <EOL> mask , subItem = _GetMaskAndVal ( subItem , <NUM_LIT:0> , mask , commctrl . LVCF_SUBITEM ) <EOL> mask , image = _GetMaskAndVal ( image , <NUM_LIT:0> , mask , commctrl . LVCF_IMAGE ) <EOL> mask , order = _GetMaskAndVal ( order , <NUM_LIT:0> , mask , commctrl . LVCF_ORDER ) <EOL> if text is None : <EOL> text_addr = text_len = <NUM_LIT:0> <EOL> else : <EOL> if isinstance ( text , unicode ) : <EOL> text = text . encode ( "<STR_LIT>" ) <EOL> text_buffer = array . array ( "<STR_LIT:c>" , text + "<STR_LIT>" ) <EOL> extra . append ( text_buffer ) <EOL> text_addr , text_len = text_buffer . buffer_info ( ) <EOL> format = "<STR_LIT>" <EOL> buf = struct . pack ( format , <EOL> mask , fmt , cx , <EOL> text_addr , text_len , <EOL> subItem , image , order ) <EOL> return array . array ( "<STR_LIT:c>" , buf ) , extra <EOL> def UnpackLVCOLUMN ( lparam ) : <EOL> format = "<STR_LIT>" <EOL> mask , fmt , cx , text_addr , text_size , subItem , image , order = struct . unpack ( format , lparam ) <EOL> if not ( mask & commctrl . LVCF_FMT ) : fmt = None <EOL> if not ( mask & commctrl . LVCF_WIDTH ) : cx = None <EOL> if not ( mask & commctrl . LVCF_TEXT ) : text_addr = text_size = None <EOL> if not ( mask & commctrl . LVCF_SUBITEM ) : subItem = None <EOL> if not ( mask & commctrl . LVCF_IMAGE ) : image = None <EOL> if not ( mask & commctrl . LVCF_ORDER ) : order = None <EOL> if text_addr : <EOL> text = win32gui . PyGetString ( text_addr ) <EOL> else : <EOL> text = None <EOL> return fmt , cx , text , subItem , image , order <EOL> def EmptyLVCOLUMN ( mask = None , text_buf_size = <NUM_LIT> ) : <EOL> extra = [ ] <EOL> if mask is None : <EOL> mask = commctrl . LVCF_FMT | commctrl . LVCF_WIDTH | commctrl . LVCF_TEXT | commctrl . LVCF_SUBITEM | commctrl . LVCF_IMAGE | commctrl . LVCF_ORDER <EOL> if mask & commctrl . LVCF_TEXT : <EOL> text_buffer = array . array ( "<STR_LIT:c>" , "<STR_LIT>" * text_buf_size ) <EOL> extra . append ( text_buffer ) <EOL> text_addr , text_len = text_buffer . buffer_info ( ) <EOL> else : <EOL> text_addr = text_len = <NUM_LIT:0> <EOL> format = "<STR_LIT>" <EOL> buf = struct . pack ( format , <EOL> mask , <NUM_LIT:0> , <NUM_LIT:0> , <EOL> text_addr , text_len , <EOL> <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> return array . array ( "<STR_LIT:c>" , buf ) , extra <EOL> def PackLVHITTEST ( pt ) : <EOL> format = "<STR_LIT>" <EOL> buf = struct . pack ( format , <EOL> pt [ <NUM_LIT:0> ] , pt [ <NUM_LIT:1> ] , <EOL> <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> return array . array ( "<STR_LIT:c>" , buf ) , None <EOL> def UnpackLVHITTEST ( buf ) : <EOL> format = "<STR_LIT>" <EOL> x , y , flags , item , subitem = struct . unpack ( format , buf ) <EOL> return ( x , y ) , flags , item , subitem <EOL> def PackHDITEM ( cxy = None , text = None , hbm = None , fmt = None , <EOL> param = None , image = None , order = None ) : <EOL> extra = [ ] <EOL> mask = <NUM_LIT:0> <EOL> mask , cxy = _GetMaskAndVal ( cxy , <NUM_LIT:0> , mask , commctrl . HDI_HEIGHT ) <EOL> mask , text = _GetMaskAndVal ( text , None , mask , commctrl . LVCF_TEXT ) <EOL> mask , hbm = _GetMaskAndVal ( hbm , <NUM_LIT:0> , mask , commctrl . HDI_BITMAP ) <EOL> mask , fmt = _GetMaskAndVal ( fmt , <NUM_LIT:0> , mask , commctrl . HDI_FORMAT ) <EOL> mask , param = _GetMaskAndVal ( param , <NUM_LIT:0> , mask , commctrl . HDI_LPARAM ) <EOL> mask , image = _GetMaskAndVal ( image , <NUM_LIT:0> , mask , commctrl . HDI_IMAGE ) <EOL> mask , order = _GetMaskAndVal ( order , <NUM_LIT:0> , mask , commctrl . HDI_ORDER ) <EOL> if text is None : <EOL> text_addr = text_len = <NUM_LIT:0> <EOL> else : <EOL> if isinstance ( text , unicode ) : <EOL> text = text . encode ( "<STR_LIT>" ) <EOL> text_buffer = array . array ( "<STR_LIT:c>" , text + "<STR_LIT>" ) <EOL> extra . append ( text_buffer ) <EOL> text_addr , text_len = text_buffer . buffer_info ( ) <EOL> format = "<STR_LIT>" <EOL> buf = struct . pack ( format , <EOL> mask , cxy , text_addr , hbm , text_len , <EOL> fmt , param , image , order , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> return array . array ( "<STR_LIT:c>" , buf ) , extra <EOL> def PackDEV_BROADCAST ( devicetype , rest_fmt , rest_data , extra_data = '<STR_LIT>' ) : <EOL> extra_data += '<STR_LIT>' * ( <NUM_LIT:4> - len ( extra_data ) % <NUM_LIT:4> ) <EOL> format = "<STR_LIT>" + rest_fmt <EOL> full_size = struct . calcsize ( format ) + len ( extra_data ) <EOL> data = ( full_size , devicetype , <NUM_LIT:0> ) + rest_data <EOL> return struct . pack ( format , * data ) + extra_data <EOL> def PackDEV_BROADCAST_HANDLE ( handle , hdevnotify = <NUM_LIT:0> , guid = "<STR_LIT>" * <NUM_LIT:16> , name_offset = <NUM_LIT:0> , data = "<STR_LIT>" ) : <EOL> return PackDEV_BROADCAST ( win32con . DBT_DEVTYP_HANDLE , "<STR_LIT>" , <EOL> ( long ( handle ) , long ( hdevnotify ) , str ( buffer ( guid ) ) , name_offset ) , <EOL> data ) <EOL> def PackDEV_BROADCAST_DEVICEINTERFACE ( classguid , name = "<STR_LIT>" ) : <EOL> rest_fmt = "<STR_LIT>" % len ( name ) <EOL> rest_data = ( str ( buffer ( pywintypes . IID ( classguid ) ) ) , name ) <EOL> return PackDEV_BROADCAST ( win32con . DBT_DEVTYP_DEVICEINTERFACE , rest_fmt , rest_data ) <EOL> class DEV_BROADCAST_INFO : <EOL> def __init__ ( self , devicetype , ** kw ) : <EOL> self . devicetype = devicetype <EOL> self . __dict__ . update ( kw ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" + str ( self . __dict__ ) <EOL> def UnpackDEV_BROADCAST ( lparam ) : <EOL> if lparam == <NUM_LIT:0> : <EOL> return None <EOL> hdr_size = struct . calcsize ( "<STR_LIT>" ) <EOL> hdr_buf = win32gui . PyMakeBuffer ( hdr_size , lparam ) <EOL> size , devtype , reserved = struct . unpack ( "<STR_LIT>" , hdr_buf ) <EOL> rest = win32gui . PyMakeBuffer ( size - hdr_size , lparam + hdr_size ) <EOL> extra = x = { } <EOL> if devtype == win32con . DBT_DEVTYP_HANDLE : <EOL> fmt = "<STR_LIT>" <EOL> x [ '<STR_LIT>' ] , x [ '<STR_LIT>' ] , guid_bytes , x [ '<STR_LIT>' ] = struct . unpack ( fmt , rest [ : struct . calcsize ( fmt ) ] ) <EOL> x [ '<STR_LIT>' ] = pywintypes . IID ( guid_bytes , True ) <EOL> elif devtype == win32con . DBT_DEVTYP_DEVICEINTERFACE : <EOL> x [ '<STR_LIT>' ] = pywintypes . IID ( rest [ : <NUM_LIT:16> ] , <NUM_LIT:1> ) <EOL> name = rest [ <NUM_LIT:16> : ] <EOL> if '<STR_LIT>' in name : <EOL> name = name . split ( '<STR_LIT>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> x [ '<STR_LIT:name>' ] = name <EOL> elif devtype == win32con . DBT_DEVTYP_VOLUME : <EOL> x [ '<STR_LIT>' ] , x [ '<STR_LIT>' ] = struct . unpack ( "<STR_LIT>" , rest [ : struct . calcsize ( "<STR_LIT>" ) ] ) <EOL> else : <EOL> raise NotImplementedError ( "<STR_LIT>" % ( devtype , ) ) <EOL> return DEV_BROADCAST_INFO ( devtype , ** extra ) </s>
