Hello-
I'm trying to implement a subclass of listbook where the user can use
drag-and-drop to reorder the items in the list. I was pleasantly
surprised that this was fairly easy to do in Linux, but when I run it
on Windows XP, the dragged item is always inserted at the end of the
list. I've checked that the indices that I'm passing to InsertPage are
correct.
Is this a problem, or something I've overlooked? I may have to roll my
own anyway (it's for graphical layers (with associated control
panels), so reordering is very important) since I'll probably need
checkboxes, but for a first pass, I was hoping to use ListBook.
Anyway, here is the method which does the reordering
def _handle_drop(self, x, y, text):
dst_idx, flags = self.HitTest((x,y))
print "Index of drop:", dst_idx
if dst_idx == wx.NOT_FOUND:
if flags & wx.LIST_HITTEST_NOWHERE:
dst_idx = self.GetItemCount()
else:
return
src_idx = int(text) # I pass the index of the dragged item as
a string
if src_idx == dst_idx:
return
src_page = self.GetPage(src_idx)
src_text = self.GetPageText(src_idx)
self.InsertPage(dst_idx, src_page, src_text, select = True)
#Delete the duplicate page. If dst_idx<src_idx, need to delete
src_idx+1
if src_idx<dst_idx:
self.RemovePage(src_idx)
else:
self.RemovePage(src_idx + 1)
print "Inserting :%s: at %d" % (text, dst_idx)
Thanks,
-matt