[pywin32-checkins] pywin32/com/win32comext/shell/demos viewstate.py,NONE,1.1
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Roger U. <ru...@us...> - 2005-05-16 07:54:13
|
Update of /cvsroot/pywin32/pywin32/com/win32comext/shell/demos In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11604/com/win32comext/shell/demos Added Files: viewstate.py Log Message: Demo for SHGetViewStatePropertyBag --- NEW FILE: viewstate.py --- """ Demonstrates how to propagate a folder's view state to all its subfolders The format of the ColInfo stream is apparently undocumented, but it can be read raw from one folder and copied to another's view state. """ from win32com.shell import shell, shellcon import pythoncom import os, sys template_folder=os.path.split(sys.executable)[0] print 'Template folder:', template_folder template_pidl=shell.SHILCreateFromPath(template_folder,0)[0] template_pb=shell.SHGetViewStatePropertyBag(template_pidl, "Shell", shellcon.SHGVSPB_FOLDERNODEFAULTS, pythoncom.IID_IPropertyBag) # Column info has to be read as a stream # This may blow up if folder has never been opened in Explorer and has no ColInfo yet template_iunk=template_pb.Read('ColInfo',pythoncom.VT_UNKNOWN) template_stream=template_iunk.QueryInterface(pythoncom.IID_IStream) streamsize=template_stream.Stat()[2] template_colinfo=template_stream.Read(streamsize) def update_colinfo(not_used, dir_name, fnames): for fname in fnames: full_fname=os.path.join(dir_name,fname) if os.path.isdir(full_fname): print full_fname pidl=shell.SHILCreateFromPath(full_fname,0)[0] pb=shell.SHGetViewStatePropertyBag(pidl, "Shell", shellcon.SHGVSPB_FOLDERNODEFAULTS, pythoncom.IID_IPropertyBag) ## not all folders already have column info, and we're replacing it anyway pb.Write('ColInfo', template_stream) iunk=pb.Read('ColInfo',pythoncom.VT_UNKNOWN) s=iunk.QueryInterface(pythoncom.IID_IStream) s.Write(template_colinfo) s=None ## attribute names read from registry, can't find any way to enumerate IPropertyBag for attr in ('Address','Buttons','Col','Vid','WFlags','FFlags','Sort','SortDir','ShowCmd','FolderType','Mode','Rev'): pb.Write(attr, template_pb.Read(attr)) pb=None os.path.walk(template_folder,update_colinfo,None) |