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