viewstate.py :  » Windows » pyExcelerator » pywin32-214 » com » win32comext » shell » demos » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Windows » pyExcelerator 
pyExcelerator » pywin32 214 » com » win32comext » shell » demos » 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)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.