Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#575 PyCTreeCtrl.SetItem crashes hard

closed-fixed
nobody
win32 (141)
5
2012-01-01
2011-12-19
kxroberto
No

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")

Discussion

  • kxroberto
    kxroberto
    2011-12-19

     
    Attachments
  • Roger Upole
    Roger Upole
    2012-01-01

    Fixed in win32util.cpp r4172

     
  • Roger Upole
    Roger Upole
    2012-01-01

    • status: open --> closed-fixed