3 """Playlist panel for Hooke.
\r
8 class Playlist(wx.Panel):
\r
10 def __init__(self, parent):
\r
11 # Use the WANTS_CHARS style so the panel doesn't eat the Return key.
\r
12 wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS|wx.NO_BORDER, size=(160, 200))
\r
14 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
15 imglist = wx.ImageList(16, 16, True, 2)
\r
16 imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, wx.Size(16, 16)))
\r
17 imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, wx.Size(16, 16)))
\r
18 self.PlaylistsTree.AssignImageList(imglist)
\r
19 self.PlaylistsTree.AddRoot('Playlists', 0)
\r
20 self.PlaylistsTree.Bind(wx.EVT_RIGHT_DOWN , self.OnContextMenu)
\r
24 sizer = wx.BoxSizer(wx.VERTICAL)
\r
25 sizer.Add(self.PlaylistsTree, 1, wx.EXPAND)
\r
26 self.SetSizer(sizer)
\r
29 def OnContextMenu(self, event):
\r
30 hit_item, hit_flags = self.PlaylistsTree.HitTest(event.GetPosition())
\r
31 if (hit_flags & wx.TREE_HITTEST_ONITEM) != 0:
\r
32 self.PlaylistsTree.SelectItem(hit_item)
\r
33 # only do this part the first time so the events are only bound once
\r
34 # Yet another alternate way to do IDs. Some prefer them up top to
\r
35 # avoid clutter, some prefer them close to the object of interest
\r
37 if not hasattr(self, 'ID_popupAdd'):
\r
38 #self.ID_popupAdd = wx.NewId()
\r
39 self.ID_popupDelete = wx.NewId()
\r
40 #self.Bind(wx.EVT_MENU, self.OnPopupAdd, id=self.ID_popupAdd)
\r
41 self.Bind(wx.EVT_MENU, self.OnPopupDelete, id=self.ID_popupDelete)
\r
44 #items = [['Add', self.ID_popupAdd] , ['Delete', self.ID_popupDelete]]
\r
45 items = [['Delete', self.ID_popupDelete]]
\r
47 menu.Append(item[1], item[0])
\r
48 # Popup the menu. If an item is selected then its handler
\r
49 # will be called before PopupMenu returns.
\r
50 self.PopupMenu(menu)
\r
53 def OnPopupAdd(self, event):
\r
56 def OnPopupDelete(self, event):
\r
57 item = self.PlaylistsTree.GetSelection()
\r
58 playlist = self.Parent.GetActivePlaylist()
\r
59 if self.PlaylistsTree.ItemHasChildren(item):
\r
60 playlist_name = self.PlaylistsTree.GetItemText(item)
\r
61 notebook = self.Parent.plotNotebook
\r
62 index = self.Parent._GetPlaylistTab(playlist_name)
\r
63 notebook.SetSelection(index)
\r
64 notebook.DeletePage(notebook.GetSelection())
\r
65 self.Parent.DeleteFromPlaylists(playlist_name)
\r
67 if playlist is not None:
\r
68 if playlist.count == 1:
\r
69 notebook = self.Parent.plotNotebook
\r
70 index = self.Parent._GetPlaylistTab(playlist.name)
\r
71 notebook.SetSelection(index)
\r
72 notebook.DeletePage(notebook.GetSelection())
\r
73 self.Parent.DeleteFromPlaylists(playlist.name)
\r
75 file_name = self.PlaylistsTree.GetItemText(item)
\r
76 playlist.delete_file(file_name)
\r
77 self.PlaylistsTree.Delete(item)
\r
78 self.Parent.UpdatePlaylistsTreeSelection()
\r