Update of /cvsroot/pywin32/pywin32/Pythonwin/pywin/tools
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv24802/Pythonwin/pywin/tools
Modified Files:
browseProjects.py browser.py hierlist.py regpy.py
Log Message:
Various modernizations to .py code via the py3k branch.
Index: regpy.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/pywin/tools/regpy.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** regpy.py 1 Sep 1999 23:33:57 -0000 1.1
--- regpy.py 14 Nov 2008 00:22:25 -0000 1.2
***************
*** 52,53 ****
--- 52,56 ----
ps.AddPage(RegistryPage())
ps.DoModal()
+
+ if __name__=='__main__':
+ t()
Index: hierlist.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/pywin/tools/hierlist.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** hierlist.py 2 Oct 2008 13:03:55 -0000 1.8
--- hierlist.py 14 Nov 2008 00:22:25 -0000 1.9
***************
*** 14,18 ****
# to provide maximum flexibility (but with extra work).
!
import win32ui
import win32con
--- 14,18 ----
# to provide maximum flexibility (but with extra work).
! import sys
import win32ui
import win32con
***************
*** 49,53 ****
class HierList(object.Object):
def __init__(self, root, bitmapID = win32ui.IDB_HIERFOLDERS, listBoxId = None, bitmapMask = None): # used to create object.
! self.list = None
self.bitmapID = bitmapID
self.root = root
--- 49,53 ----
class HierList(object.Object):
def __init__(self, root, bitmapID = win32ui.IDB_HIERFOLDERS, listBoxId = None, bitmapMask = None): # used to create object.
! self.listControl = None
self.bitmapID = bitmapID
self.root = root
***************
*** 57,61 ****
self.bitmapMask = bitmapMask
def __getattr__(self, attr):
! l = self.__dict__['list']
if l is not None:
return getattr(l, attr)
--- 57,61 ----
self.bitmapMask = bitmapMask
def __getattr__(self, attr):
! l = self.__dict__['listControl']
if l is not None:
return getattr(l, attr)
***************
*** 63,67 ****
return self.itemHandleMap[handle]
def SetStyle(self, newStyle):
! hwnd = self.list.GetSafeHwnd()
style = win32api.GetWindowLong(hwnd, win32con.GWL_STYLE);
win32api.SetWindowLong(hwnd, win32con.GWL_STYLE, (style | newStyle) )
--- 63,67 ----
return self.itemHandleMap[handle]
def SetStyle(self, newStyle):
! hwnd = self.listControl.GetSafeHwnd()
style = win32api.GetWindowLong(hwnd, win32con.GWL_STYLE);
win32api.SetWindowLong(hwnd, win32con.GWL_STYLE, (style | newStyle) )
***************
*** 77,90 ****
if listControl is None:
if self.listBoxId is None: self.listBoxId = win32ui.IDC_LIST1
! self.list = parent.GetDlgItem(self.listBoxId)
else:
! self.list = listControl
lbid = listControl.GetDlgCtrlID()
assert self.listBoxId is None or self.listBoxId == lbid, "An invalid listbox control ID has been specified (specified as %s, but exists as %s)" % (self.listBoxId, lbid)
self.listBoxId = lbid
! self.list.SetImageList(self.imageList, commctrl.LVSIL_NORMAL)
# self.list.AttachObject(self)
! parent.HookNotify(self.OnTreeItemExpanding, commctrl.TVN_ITEMEXPANDING)
! parent.HookNotify(self.OnTreeItemSelChanged, commctrl.TVN_SELCHANGED)
parent.HookNotify(self.OnTreeItemDoubleClick, commctrl.NM_DBLCLK)
self.notify_parent = parent
--- 77,97 ----
if listControl is None:
if self.listBoxId is None: self.listBoxId = win32ui.IDC_LIST1
! self.listControl = parent.GetDlgItem(self.listBoxId)
else:
! self.listControl = listControl
lbid = listControl.GetDlgCtrlID()
assert self.listBoxId is None or self.listBoxId == lbid, "An invalid listbox control ID has been specified (specified as %s, but exists as %s)" % (self.listBoxId, lbid)
self.listBoxId = lbid
! self.listControl.SetImageList(self.imageList, commctrl.LVSIL_NORMAL)
# self.list.AttachObject(self)
!
! ## ??? Need a better way to do this - either some way to detect if it's compiled with UNICODE
! ## defined, and/or a way to switch the constants based on UNICODE ???
! if sys.version_info[0] < 3:
! parent.HookNotify(self.OnTreeItemExpanding, commctrl.TVN_ITEMEXPANDINGA)
! parent.HookNotify(self.OnTreeItemSelChanged, commctrl.TVN_SELCHANGEDA)
! else:
! parent.HookNotify(self.OnTreeItemExpanding, commctrl.TVN_ITEMEXPANDINGW)
! parent.HookNotify(self.OnTreeItemSelChanged, commctrl.TVN_SELCHANGEDW)
parent.HookNotify(self.OnTreeItemDoubleClick, commctrl.NM_DBLCLK)
self.notify_parent = parent
***************
*** 94,98 ****
def DeleteAllItems(self):
! self.list.DeleteAllItems()
self.root = None
self.itemHandleMap = {}
--- 101,105 ----
def DeleteAllItems(self):
! self.listControl.DeleteAllItems()
self.root = None
self.itemHandleMap = {}
***************
*** 102,110 ****
# Dont want notifies as we kill the list.
parent = self.notify_parent # GetParentFrame()
! parent.HookNotify(None, commctrl.TVN_ITEMEXPANDING)
! parent.HookNotify(None, commctrl.TVN_SELCHANGED)
parent.HookNotify(None, commctrl.NM_DBLCLK)
self.DeleteAllItems()
! self.list = None
self.notify_parent = None # Break a possible cycle
--- 109,122 ----
# Dont want notifies as we kill the list.
parent = self.notify_parent # GetParentFrame()
! if sys.version_info[0] < 3:
! parent.HookNotify(None, commctrl.TVN_ITEMEXPANDINGA)
! parent.HookNotify(None, commctrl.TVN_SELCHANGEDA)
! else:
! parent.HookNotify(None, commctrl.TVN_ITEMEXPANDINGW)
! parent.HookNotify(None, commctrl.TVN_SELCHANGEDW)
parent.HookNotify(None, commctrl.NM_DBLCLK)
+
self.DeleteAllItems()
! self.listControl = None
self.notify_parent = None # Break a possible cycle
***************
*** 112,116 ****
(hwndFrom, idFrom, code) = info
if idFrom != self.listBoxId: return None
! item = self.itemHandleMap[self.list.GetSelectedItem()]
self.TakeDefaultAction(item)
return 1
--- 124,128 ----
(hwndFrom, idFrom, code) = info
if idFrom != self.listBoxId: return None
! item = self.itemHandleMap[self.listControl.GetSelectedItem()]
self.TakeDefaultAction(item)
return 1
***************
*** 121,125 ****
action, itemOld, itemNew, pt = extra
itemHandle = itemNew[0]
! if not self.filledItemHandlesMap.has_key(itemHandle):
item = self.itemHandleMap[itemHandle]
self.AddSubList(itemHandle, self.GetSubList(item))
--- 133,137 ----
action, itemOld, itemNew, pt = extra
itemHandle = itemNew[0]
! if itemHandle not in self.filledItemHandlesMap:
item = self.itemHandleMap[itemHandle]
self.AddSubList(itemHandle, self.GetSubList(item))
***************
*** 149,155 ****
bitmapSel = self.GetSelectedBitmapColumn(item)
if bitmapSel is None: bitmapSel = bitmapCol
! if type(text) is unicode:
! text = text.encode("mbcs")
! hitem = self.list.InsertItem(parentHandle, hInsertAfter, (None, None, None, text, bitmapCol, bitmapSel, cItems, 0))
self.itemHandleMap[hitem] = item
return hitem
--- 161,167 ----
bitmapSel = self.GetSelectedBitmapColumn(item)
if bitmapSel is None: bitmapSel = bitmapCol
! ## if type(text) is str:
! ## text = text.encode("mbcs")
! hitem = self.listControl.InsertItem(parentHandle, hInsertAfter, (None, None, None, text, bitmapCol, bitmapSel, cItems, 0))
self.itemHandleMap[hitem] = item
return hitem
***************
*** 158,165 ****
ret = []
try:
! handle = self.list.GetChildItem(handle)
while 1:
ret.append(handle)
! handle = self.list.GetNextItem(handle, commctrl.TVGN_NEXT)
except win32ui.error:
# out of children
--- 170,177 ----
ret = []
try:
! handle = self.listControl.GetChildItem(handle)
while 1:
ret.append(handle)
! handle = self.listControl.GetNextItem(handle, commctrl.TVGN_NEXT)
except win32ui.error:
# out of children
***************
*** 173,182 ****
# (ie, the selected item, expanded items, etc)
if hparent is None: hparent = commctrl.TVI_ROOT
! if not self.filledItemHandlesMap.has_key(hparent):
# This item has never been expanded, so no refresh can possibly be required.
return
root_item = self.itemHandleMap[hparent]
old_handles = self._GetChildHandles(hparent)
! old_items = map( self.ItemFromHandle, old_handles )
new_items = self.GetSubList(root_item)
# Now an inefficient technique for synching the items.
--- 185,194 ----
# (ie, the selected item, expanded items, etc)
if hparent is None: hparent = commctrl.TVI_ROOT
! if hparent not in self.filledItemHandlesMap:
# This item has never been expanded, so no refresh can possibly be required.
return
root_item = self.itemHandleMap[hparent]
old_handles = self._GetChildHandles(hparent)
! old_items = list(map( self.ItemFromHandle, old_handles ))
new_items = self.GetSubList(root_item)
# Now an inefficient technique for synching the items.
***************
*** 201,205 ****
# And recursively refresh iold
hold = old_handles[iold]
! if self.filledItemHandlesMap.has_key(hold):
self.Refresh(hold)
else:
--- 213,217 ----
# And recursively refresh iold
hold = old_handles[iold]
! if hold in self.filledItemHandlesMap:
self.Refresh(hold)
else:
***************
*** 210,216 ****
for hchild in self._GetChildHandles(hdelete):
del self.itemHandleMap[hchild]
! if self.filledItemHandlesMap.has_key(hchild):
del self.filledItemHandlesMap[hchild]
! self.list.DeleteItem(hdelete)
hAfter = old_handles[iold]
# Fill any remaining new items:
--- 222,228 ----
for hchild in self._GetChildHandles(hdelete):
del self.itemHandleMap[hchild]
! if hchild in self.filledItemHandlesMap:
del self.filledItemHandlesMap[hchild]
! self.listControl.DeleteItem(hdelete)
hAfter = old_handles[iold]
# Fill any remaining new items:
***************
*** 219,223 ****
self.AddItem(hparent, newItem)
def AcceptRoot(self, root):
! self.list.DeleteAllItems()
self.itemHandleMap = {commctrl.TVI_ROOT : root}
self.filledItemHandlesMap = {commctrl.TVI_ROOT : root}
--- 231,235 ----
self.AddItem(hparent, newItem)
def AcceptRoot(self, root):
! self.listControl.DeleteAllItems()
self.itemHandleMap = {commctrl.TVI_ROOT : root}
self.filledItemHandlesMap = {commctrl.TVI_ROOT : root}
***************
*** 237,241 ****
def CheckChangedChildren(self):
! return self.list.CheckChangedChildren()
def GetText(self,item):
return GetItemText(item)
--- 249,253 ----
def CheckChangedChildren(self):
! return self.listControl.CheckChangedChildren()
def GetText(self,item):
return GetItemText(item)
Index: browser.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/pywin/tools/browser.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** browser.py 9 Aug 2008 16:47:08 -0000 1.10
--- browser.py 14 Nov 2008 00:22:25 -0000 1.11
***************
*** 66,70 ****
ret = []
try:
! for (key, ob) in self.myobject.__dict__.items():
if key not in special_names:
ret.append(MakeHLI( ob, key ) )
--- 66,70 ----
ret = []
try:
! for (key, ob) in self.myobject.__dict__.iteritems():
if key not in special_names:
ret.append(MakeHLI( ob, key ) )
***************
*** 95,99 ****
return 1
try:
! for key in self.myobject.__dict__.keys():
if key not in special_names:
return 1
--- 95,99 ----
return 1
try:
! for key in self.myobject.__dict__.iterkeys():
if key not in special_names:
return 1
***************
*** 243,247 ****
def GetSubList(self):
ret = []
! keys = self.myobject.keys()
keys.sort()
for key in keys:
--- 243,247 ----
def GetSubList(self):
ret = []
! keys = list(self.myobject.keys())
keys.sort()
for key in keys:
***************
*** 365,369 ****
root = MakeHLI (ob, 'root')
if not root.IsExpandable():
! raise TypeError, "Browse() argument must have __dict__ attribute, or be a Browser supported type"
dlg = dynamic_browser (root)
--- 365,369 ----
root = MakeHLI (ob, 'root')
if not root.IsExpandable():
! raise TypeError("Browse() argument must have __dict__ attribute, or be a Browser supported type")
dlg = dynamic_browser (root)
***************
*** 398,402 ****
self.SetTitle("Browser: " + root.name)
def OnOpenDocument (self, name):
! raise TypeError, "This template can not open files"
return 0
--- 398,402 ----
self.SetTitle("Browser: " + root.name)
def OnOpenDocument (self, name):
! raise TypeError("This template can not open files")
return 0
***************
*** 423,427 ****
root = MakeHLI(ob, repr(ob))
if not root.IsExpandable():
! raise TypeError, "Browse() argument must have __dict__ attribute, or be a Browser supported type"
template.OpenObject(root)
--- 423,427 ----
root = MakeHLI(ob, repr(ob))
if not root.IsExpandable():
! raise TypeError("Browse() argument must have __dict__ attribute, or be a Browser supported type")
template.OpenObject(root)
Index: browseProjects.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/Pythonwin/pywin/tools/browseProjects.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** browseProjects.py 1 Oct 2008 14:44:53 -0000 1.4
--- browseProjects.py 14 Nov 2008 00:22:25 -0000 1.5
***************
*** 57,61 ****
for c in self.super:
ret.append(HLICLBRClass(c, " (Parent class)"))
! for meth, lineno in self.methods.items():
ret.append(HLICLBRMethod(meth, self.file, lineno, " (method)"))
return ret
--- 57,61 ----
for c in self.super:
ret.append(HLICLBRClass(c, " (Parent class)"))
! for meth, lineno in self.methods.iteritems():
ret.append(HLICLBRMethod(meth, self.file, lineno, " (method)"))
return ret
***************
*** 104,108 ****
if data:
ret = []
! for item in data.values():
if item.__class__ != pyclbr.Class: # ie, it is a pyclbr Function instance (only introduced post 1.5.2)
ret.append(HLICLBRFunction( item, " (function)" ) )
--- 104,108 ----
if data:
ret = []
! for item in data.itervalues():
if item.__class__ != pyclbr.Class: # ie, it is a pyclbr Function instance (only introduced post 1.5.2)
ret.append(HLICLBRFunction( item, " (function)" ) )
***************
*** 166,170 ****
ret = MakePathSubList(pathList[0])
else:
! ret = map( HLIDirectoryItem, pathList )
return ret
--- 166,170 ----
ret = MakePathSubList(pathList[0])
else:
! ret = list(map( HLIDirectoryItem, pathList ))
return ret
|