#    This file is part of pyPeline.
#
#    pyPeline is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    pyPeline is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Foobar; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

# Matthieu Brucher
# Last Change : 2007-05-15 18:30

import wx

class PypelineBookPage(wx.ListCtrl):
  """
  A custom List Control
  """
  def __init__(self, *arg, **kw):
    wx.ListCtrl.__init__(self, *arg, **kw)
    self.name = kw['name']
    self.Bind(wx.EVT_LIST_BEGIN_DRAG, self.onDragInit)
    self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onSelected)
    self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.onDeselected)
    self.selected = []

  def onDragInit(self, event):
    """
    Start drag action
    """
    text = ['/'.join((self.name, self.GetItem(id).GetText())) for id in self.selected]
    print text
    data = wx.PyTextDataObject()
    data.SetText(str(text))
    dropSource = wx.DropSource(self)
    dropSource.SetData(data)
    res = dropSource.DoDragDrop(flags=wx.Drag_CopyOnly)

  def onSelected(self, event):
    self.selected.append(event.GetIndex())
    print self.selected
    event.Skip()

  def onDeselected(self, event):
    self.selected.remove(event.GetIndex())
    event.Skip()

if __name__ == "__main__":
  import sys
  class TestApp(wx.App):
    def OnInit(self):
      self.frame = wx.Frame(parent=None)
      note = wx.Notebook(self.frame, style = wx.BOTTOM)
      listCtrl = PypelineBookPage(note, name="", style = wx.LC_ICON|wx.LC_AUTOARRANGE)
      iconsList = wx.ImageList(48, 48, True)
      img = wx.Bitmap("test.png", wx.BITMAP_TYPE_PNG)
      iconsList.Add(img)
      listCtrl.AssignImageList(iconsList, wx.IMAGE_LIST_NORMAL)
      listCtrl.InsertImageStringItem(sys.maxint, 'test1', 0)
      listCtrl.InsertImageStringItem(sys.maxint, 'test2', 0)
      note.AddPage(listCtrl, "test")
      self.frame.Show()
      self.SetTopWindow(self.frame)
      return True
  app = TestApp(redirect=True)
  app.MainLoop()
