Problems with Drag and Drop between Notebooks contained in a Multisash Window

I am trying to enable the dragging and dropping of notebook pages between notebooks contained in a multisash window. The mechanism I have set up seems to work when the destination notebook contains one or more pages. However, an empty notebook doesn’t appear to be recognized as a valid drop target. Does anyone know if this behavior was intended by the author? If so, is their anyone out there that knows a way around this problem. I am running wxPython 2.4 on Windows XP Service Pack 1. I have attached an example below.

Thanks,

Jenna

import cPickle
import os
import wx
from wx.py import dispatcher
from wx.lib import multisash

class NotebookPage(wx.Panel):
def init(self, parent, data=None):
wx.Panel.init(self, parent, id=-1, pos=wx.Point(), size=wx.Size(),
style=wx.CLIP_CHILDREN|wx.NO_FULL_REPAINT_ON_RESIZE)
self.data = data
def GetData(self):
return self.data
def SetData(self, data):
self.data = data

class MainFrameSashNotebook(wx.Notebook):
def init(self, parent):
“”“Create MainFrameSashNotebook instance.”""
wx.Notebook.init(self, parent, id=-1, pos=wx.Point(), size=wx.Size(),
style=wx.CLIP_CHILDREN|wx.NO_FULL_REPAINT_ON_RESIZE)

    dropTarget = SashNotebookPageDropTarget(self)
    self.SetDropTarget(dropTarget)

wx.EVT_MOTION(self, self.OnMotion)

    dispatcher.send(signal='OnNewNotebook', sender=self, notebook=self)

def __del__(self):
    """Destructor, dispatches message to indicating its destruction"""
    dispatcher.send(signal='OnDestroyNotebook', sender=self, notebook=self)
    wx.Notebook.__del__()

def OnMotion(self, event):
    if  event.LeftIsDown() and event.ShiftDown() and event.Dragging():
        self.StartDragOperation()

else:
event.Skip()

def StartDragOperation(self):
    index = self.GetSelection()
    page = self.GetPage(index)
    page.Hide()
    pageTitle = self.GetPageText(index)
   
    notebookPageDataObject = wx.CustomDataObject(wx.CustomDataFormat('SashNotebookPage'))
    pageData = page.GetData(), pageTitle
    pickledPageData = cPickle.dumps(pageData, 1)
    notebookPageDataObject.SetData(pickledPageData)
   
     drop

Source =
wx.DropSource(self)
dropSource.SetData(notebookPageDataObject)
result = dropSource.DoDragDrop(wx.Drag_DefaultMove)
if result == wx.DragMove:
self.RemovePage(index)
self.Refresh()

class SashNotebookPageDropTarget(wx.PyDropTarget):
def init(self, targetNotebook):
wx.PyDropTarget.init(self)

    self.targetNotebook = targetNotebook
    self.data = wx.CustomDataObject(wx.CustomDataFormat('SashNotebookPage'))
    self.SetDataObject(self.data)
def OnData(self, x, y, d):
    """ copy the data from the drag source to our data object """
    if self.GetData():
        pickledPageData = self.data.GetData()
         pageData =

cPickle.loads(pickledPageData)
page = NotebookPage(self.targetNotebook, pageData[0])
self.targetNotebook.AddPage(page=page, text=pageData[1])
self.targetNotebook.Refresh()
return d

class MainFrameSash(multisash.MultiSash):
def init(self, *_args,**_kwargs):
“”“Create MainFrameSash instance.”""
apply(multisash.MultiSash.init,(self,) + _args,_kwargs)

self.notebooks = []

    dispatcher.connect(receiver=self.OnNewNotebook,
                            signal='OnNewNotebook')
    dispatcher.connect(receiver=self.OnDestroyNotebook,
                            signal='OnDestroyNotebook')

self.SetDefaultChildClass(MainFrameSashNotebook)

    self.NewPage()
   
def NewPage(self, pane=0):
    page = NotebookPage(self, 'Test Data')
    if pane == 0:
        self.AddPageToNotebook(page, 'Test Page')
    else:
        notebook = self.notebooks[pane]
        self.AddPageToNotebook(page, 'Test Page', notebook)

def OnNewNotebook(self, notebook):
“”“Adds notebook to notebooks list”""
self.notebooks.append(notebook)

def OnDestroyNotebook(self, notebook):
    """Remove notebook from notebooks list"""
    self.notebooks.remove(notebook)

def GetDefaultNotebook(self):
    """Return the default SashNotebook"""
    return self.notebooks[0]

def AddPageToNotebook(self, page, text, notebook=None):
    """Add directories page to main notebook"""
     if not

notebook:
notebook = self.GetDefaultNotebook()

    notebook.AddPage(page=page, text=text, select=True)
    page.SetFocus()

ID_FILE_NEW_PAGE_IN_FIRST_PANE = wx.NewId()
ID_FILE_NEW_PAGE_IN_SECOND_PANE = wx.NewId()

class MainFrame(wx.Frame):
def init(self, parent):
“”“Create MainFrame instance.”""
wx.Frame.init(self, style=wx.DEFAULT_FRAME_STYLE, name=’’,
parent=parent,
title=‘Test’,
pos=wx.Point(-1, -1),
id=wx.NewId(),
size=wx.Size(-1, -1))

     self

.sash =
MainFrameSash(self,-1)
self.sash.SetFocus()

    m = self.fileMenu = wx.Menu()
    m.Append(ID_FILE_NEW_PAGE_IN_FIRST_PANE, '&New Page In First Pane',
             'New Page In First Pane')
            
    wx.EVT_MENU(self, ID_FILE_NEW_PAGE_IN_FIRST_PANE, self.OnFileNewPageFirstPane)
   
    m.Append(ID_FILE_NEW_PAGE_IN_SECOND_PANE, '&New Page In Second Pane',
           &nbsp

;
‘New Page In Second Pane’)

    wx.EVT_MENU(self, ID_FILE_NEW_PAGE_IN_SECOND_PANE, self.OnFileNewPageSecondPane)
   
   
    b = self.menuBar = wx.MenuBar()
    b.Append(self.fileMenu, '&File')
    self.SetMenuBar(b)
            
def OnFileNewPageFirstPane(self, event):
    """Creates a new page."""
    self.sash.NewPage()
   
 def OnFileNewPageSecondPane(self,

event):
“”“Creates a new page.”""
self.sash.NewPage(1)

class MyApp(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
self.main = MainFrame(None)
self.main.Show()
self.SetTopWindow(self.main)
return True

def main():
application = MyApp(0)
application.MainLoop()

if name == ‘main’:
main()

···

Do you Yahoo!?

Win 1 of 4,000 free domain names from Yahoo! Enter now.

Jenna Louis wrote:

I am trying to enable the dragging and dropping of notebook pages between notebooks contained in a multisash window. The mechanism I have set up seems to work when the destination notebook contains one or more pages. However, an empty notebook doesn't appear to be recognized as a valid drop target. Does anyone know if this behavior was intended by the author?

It looks like the native notebook is only making the drop target available on the tabs, and not any other part of the notebook, probably because there are other component windows involved there.

If so, is their anyone out there that knows a way around this problem.

Other than always having at least one tab, no.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!