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