1 #!/usr/bin/env python
\r
6 Playlist panel for Hooke.
\r
8 Copyright 2009 by Dr. Rolf Schmidt (Concordia University, Canada)
\r
10 This program is released under the GNU General Public License version 2.
\r
15 class Playlists(wx.Panel):
\r
17 def __init__(self, parent):
\r
18 # Use the WANTS_CHARS style so the panel doesn't eat the Return key.
\r
19 wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS|wx.NO_BORDER, size=(160, 200))
\r
21 self.PlaylistsTree = wx.TreeCtrl(self, -1, wx.Point(0, 0), wx.Size(160, 250), wx.TR_DEFAULT_STYLE | wx.NO_BORDER | wx.TR_HIDE_ROOT)
\r
22 imglist = wx.ImageList(16, 16, True, 2)
\r
23 imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, wx.Size(16, 16)))
\r
24 imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, wx.Size(16, 16)))
\r
25 self.PlaylistsTree.AssignImageList(imglist)
\r
26 self.PlaylistsTree.AddRoot('Playlists', 0)
\r
27 self.PlaylistsTree.Bind(wx.EVT_RIGHT_DOWN , self.OnContextMenu)
\r
31 sizer = wx.BoxSizer(wx.VERTICAL)
\r
32 sizer.Add(self.PlaylistsTree, 1, wx.EXPAND)
\r
33 self.SetSizer(sizer)
\r
36 def OnContextMenu(self, event):
\r
37 hit_item, hit_flags = self.PlaylistsTree.HitTest(event.GetPosition())
\r
38 if (hit_flags & wx.TREE_HITTEST_ONITEM) != 0:
\r
39 self.PlaylistsTree.SelectItem(hit_item)
\r
40 # only do this part the first time so the events are only bound once
\r
41 # Yet another alternate way to do IDs. Some prefer them up top to
\r
42 # avoid clutter, some prefer them close to the object of interest
\r
44 if not hasattr(self, 'ID_popupAdd'):
\r
45 #self.ID_popupAdd = wx.NewId()
\r
46 self.ID_popupDelete = wx.NewId()
\r
47 #self.Bind(wx.EVT_MENU, self.OnPopupAdd, id=self.ID_popupAdd)
\r
48 self.Bind(wx.EVT_MENU, self.OnPopupDelete, id=self.ID_popupDelete)
\r
51 #items = [['Add', self.ID_popupAdd] , ['Delete', self.ID_popupDelete]]
\r
52 items = [['Delete', self.ID_popupDelete]]
\r
54 menu.Append(item[1], item[0])
\r
55 # Popup the menu. If an item is selected then its handler
\r
56 # will be called before PopupMenu returns.
\r
57 self.PopupMenu(menu)
\r
60 def OnPopupAdd(self, event):
\r
63 def OnPopupDelete(self, event):
\r
64 item = self.PlaylistsTree.GetSelection()
\r
65 playlist = self.Parent.GetActivePlaylist()
\r
66 if self.PlaylistsTree.ItemHasChildren(item):
\r
67 playlist_name = self.PlaylistsTree.GetItemText(item)
\r
68 notebook = self.Parent.plotNotebook
\r
69 index = self.Parent._GetPlaylistTab(playlist_name)
\r
70 notebook.SetSelection(index)
\r
71 notebook.DeletePage(notebook.GetSelection())
\r
72 self.Parent.DeleteFromPlaylists(playlist_name)
\r
74 if playlist is not None:
\r
75 if playlist.count == 1:
\r
76 notebook = self.Parent.plotNotebook
\r
77 index = self.Parent._GetPlaylistTab(playlist.name)
\r
78 notebook.SetSelection(index)
\r
79 notebook.DeletePage(notebook.GetSelection())
\r
80 self.Parent.DeleteFromPlaylists(playlist.name)
\r
82 file_name = self.PlaylistsTree.GetItemText(item)
\r
83 playlist.delete_file(file_name)
\r
84 self.PlaylistsTree.Delete(item)
\r
85 self.Parent.UpdatePlaylistsTreeSelection()
\r