[pywin32-bugs] [ pywin32-Bugs-3462537 ] PyCTreeCtrl.SetItem crashes hard
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: SourceForge.net <no...@so...> - 2011-12-19 21:20:33
|
Bugs item #3462537, was opened at 2011-12-19 13:20 Message generated for change (Tracker Item Submitted) made by kxroberto You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=3462537&group_id=78018 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: win32 Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: kxroberto (kxroberto) Assigned to: Nobody/Anonymous (nobody) Summary: PyCTreeCtrl.SetItem crashes hard Initial Comment: app crash with request to report to MS. Reproducible by this minimal app with various python (2) versions. attached as file too. When using the ctypes variant for .SetItem (indicated below) it doesn't crash. ###################################################################### ## ## Exposes the PyCTreeCtrl.SetItem hard crash bug in build216 ## (was probably already in build214) ## As soon as you click on a Folder with no subfolder, GetSubList wants ## to set cChildren to 0 to remove the '+'/expandable sign from the branch ## , then crash: #Exception Info: #Code: 0xc0000005 #Address: 0x1e7aa3c5 #AppName: pythonwin.exe AppVer: 2.6.216.0 ModName: pywintypes26.dll #ModVer: 2.6.216.0 Offset: 0000a3c5 ## ## note: the ctypes version of .SetItem (shown below) doesn't crash ## ###################################################################### import os, sys, re, time, traceback import win32con, win32ui, win32api, commctrl import win32gui from pywin.mfc import dialog,window from pywin.tools import hierlist #import ext debug = 1 # directory listbox # This has obvious limitations - doesnt track subdirs, etc. Demonstrates # simple use of Python code for querying the tree as needed. # Only use strings, and lists of strings (from curdir()) class DirHierList(hierlist.HierList): def __init__(self, root, listBoxID = win32ui.IDC_LIST1): self.item2handle = {} self.noexpands = {} hierlist.HierList.__init__(self, root, win32ui.IDB_HIERFOLDERS, listBoxID) def GetText(self, item): return os.path.basename(item) def AddItem(self, parentHandle, item, hInsertAfter = commctrl.TVI_LAST): hitem = hierlist.HierList.AddItem(self, parentHandle, item, hInsertAfter) self.item2handle[item] = hitem return hitem def GetSubList(self, item): print "GetSubList", item if os.path.isdir(item): ret = [os.path.join(item, fname) for fname in os.listdir(item) if os.path.isdir(os.path.join(item, fname))] else: ret = None if not ret: # learn, which items have no sub folders / '+' (cChildren>0) can be removed self.noexpands[item] = 1 h = self.item2handle.get(item) if h: tup = self.GetItem(h) if debug: print "GetSubList", tup, tup.__class__ tup = list(tup) tup[6] = 0 #[6] int : cChildren : Number of child items. tup = tuple(tup) self.SetItem(tup) # <=========== CRASH ! # the c-types version doesn't crash: ## tvi = ext.TV_GetItem(self.hwnd, h) ## if debug:print "GetSubList", tvi.cChildren, tvi.pszText ## tvi.cChildren = 0 ## tvi.mask = commctrl.TVIF_CHILDREN # tvi.mask = -1 ALSO NO CRASH ## ext.TV_SetItem(self.hwnd, tvi) return ret def IsExpandable(self, item): if os.path.isdir(item) and not item in self.noexpands: return 1 return 0 def GetSelectedBitmapColumn(self, item): return self.GetBitmapColumn(item)+6 # Use different color for selection if __name__ == "__main__": testList2 = DirHierList("c:\\temp") dlg = hierlist.HierDialog('hier list test',testList2) dlg.CreateWindow() ##dlg.hierList.GetSubList("C:\\temp\\bin") ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=3462537&group_id=78018 |