4 #import xml.dom.minidom
6 class Playlists(wx.Panel):
8 def __init__(self, parent):
9 # Use the WANTS_CHARS style so the panel doesn't eat the Return key.
10 wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS|wx.NO_BORDER, size=(160, 200))
12 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)
13 imglist = wx.ImageList(16, 16, True, 2)
14 imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, wx.Size(16, 16)))
15 imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, wx.Size(16, 16)))
16 self.PlaylistsTree.AssignImageList(imglist)
17 self.PlaylistsTree.AddRoot('Playlists', 0)
18 self.PlaylistsTree.Bind(wx.EVT_RIGHT_DOWN , self.OnContextMenu)
22 sizer = wx.BoxSizer(wx.VERTICAL)
23 sizer.Add(self.PlaylistsTree, 1, wx.EXPAND)
27 #def add_playlist(self, files=[], name='Untitled'):
28 ##TODO: change cursor or progressbar (maybe in statusbar)
29 ##self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
31 #playlist = hookeplaylist.Playlist(self.drivers)
33 #playlist.append_curve_by_path(item)
34 #if playlist.count > 0:
37 #while playlist_name in self.Playlists:
38 #playlist_name = ''.join([name, str(count)])
40 #playlist.name = playlist_name
42 #self.AddToPlaylists(playlist)
44 #def FilterPlaylist(self, curves_to_keep=[]):
45 #playlist_active = self.GetActivePlaylist()
46 #playlist_new = Playlist(self.drivers)
47 #for curve_index in curves_to_keep:
48 #playlist_new.curves.append(playlist_active.curves[curve_index])
51 def GetActivePlaylist(self):
52 playlist_name = self.GetActivePlaylistName()
53 if playlist_name in self.playlists:
54 return self.playlists[playlist_name][0]
58 def GetActivePlaylistName(self):
59 #get the selected item from the tree
60 selected_item = self.PlaylistsTree.GetSelection()
61 #test if a playlist or a curve was double-clicked
62 if self.PlaylistsTree.ItemHasChildren(selected_item):
63 playlist_item = selected_item
65 #get the name of the playlist
66 playlist_item = self.PlaylistsTree.GetItemParent(selected_item)
67 #now we have a playlist
68 return self.PlaylistsTree.GetItemText(playlist_item)
70 def OnContextMenu(self, event):
71 hit_item, hit_flags = self.PlaylistsTree.HitTest(event.GetPosition())
72 if (hit_flags & wx.TREE_HITTEST_ONITEM) != 0:
73 self.PlaylistsTree.SelectItem(hit_item)
74 # only do this part the first time so the events are only bound once
76 # Yet another alternate way to do IDs. Some prefer them up top to
77 # avoid clutter, some prefer them close to the object of interest
79 if not hasattr(self, 'ID_popupAdd'):
80 self.ID_popupAdd = wx.NewId()
81 self.ID_popupClose = wx.NewId()
82 self.Bind(wx.EVT_MENU, self.OnPopupAdd, id=self.ID_popupAdd)
83 self.Bind(wx.EVT_MENU, self.OnPopupClose, id=self.ID_popupClose)
86 items = [['Add', self.ID_popupAdd] , ['Close', self.ID_popupClose]]
88 menu.Append(item[1], item[0])
89 # Popup the menu. If an item is selected then its handler
90 # will be called before PopupMenu returns.
94 def OnPopupAdd(self, event):
97 def OnPopupClose(self, event):
98 item = self.PlaylistsTree.GetSelection()
99 if self.PlaylistsTree.ItemHasChildren(item):
100 playlist_name = self.PlaylistsTree.GetItemText(item)
101 self.Parent.DeletePlotPage(playlist_name)
102 #del self.Playlists[playlist_name]
103 #TODO: delete playlist, close notebook tab
104 #self.Parent.AddToPlaylists()