1 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
3 # This file is part of Hooke.
5 # Hooke is free software: you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation, either
8 # version 3 of the License, or (at your option) any later version.
10 # Hooke is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with Hooke. If not, see
17 # <http://www.gnu.org/licenses/>.
22 #import xml.dom.minidom
24 class Playlists(wx.Panel):
26 def __init__(self, parent):
27 # Use the WANTS_CHARS style so the panel doesn't eat the Return key.
28 wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS|wx.NO_BORDER, size=(160, 200))
30 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)
31 imglist = wx.ImageList(16, 16, True, 2)
32 imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, wx.Size(16, 16)))
33 imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, wx.Size(16, 16)))
34 self.PlaylistsTree.AssignImageList(imglist)
35 self.PlaylistsTree.AddRoot('Playlists', 0)
36 self.PlaylistsTree.Bind(wx.EVT_RIGHT_DOWN , self.OnContextMenu)
40 sizer = wx.BoxSizer(wx.VERTICAL)
41 sizer.Add(self.PlaylistsTree, 1, wx.EXPAND)
45 #def add_playlist(self, files=[], name='Untitled'):
46 ##TODO: change cursor or progressbar (maybe in statusbar)
47 ##self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
49 #playlist = hookeplaylist.Playlist(self.drivers)
51 #playlist.append_curve_by_path(item)
52 #if playlist.count > 0:
55 #while playlist_name in self.Playlists:
56 #playlist_name = ''.join([name, str(count)])
58 #playlist.name = playlist_name
60 #self.AddToPlaylists(playlist)
62 #def FilterPlaylist(self, curves_to_keep=[]):
63 #playlist_active = self.GetActivePlaylist()
64 #playlist_new = Playlist(self.drivers)
65 #for curve_index in curves_to_keep:
66 #playlist_new.curves.append(playlist_active.curves[curve_index])
69 def GetActivePlaylist(self):
70 playlist_name = self.GetActivePlaylistName()
71 if playlist_name in self.playlists:
72 return self.playlists[playlist_name][0]
76 def GetActivePlaylistName(self):
77 #get the selected item from the tree
78 selected_item = self.PlaylistsTree.GetSelection()
79 #test if a playlist or a curve was double-clicked
80 if self.PlaylistsTree.ItemHasChildren(selected_item):
81 playlist_item = selected_item
83 #get the name of the playlist
84 playlist_item = self.PlaylistsTree.GetItemParent(selected_item)
85 #now we have a playlist
86 return self.PlaylistsTree.GetItemText(playlist_item)
88 def OnContextMenu(self, event):
89 hit_item, hit_flags = self.PlaylistsTree.HitTest(event.GetPosition())
90 if (hit_flags & wx.TREE_HITTEST_ONITEM) != 0:
91 self.PlaylistsTree.SelectItem(hit_item)
92 # only do this part the first time so the events are only bound once
94 # Yet another alternate way to do IDs. Some prefer them up top to
95 # avoid clutter, some prefer them close to the object of interest
97 if not hasattr(self, 'ID_popupAdd'):
98 self.ID_popupAdd = wx.NewId()
99 self.ID_popupClose = wx.NewId()
100 self.Bind(wx.EVT_MENU, self.OnPopupAdd, id=self.ID_popupAdd)
101 self.Bind(wx.EVT_MENU, self.OnPopupClose, id=self.ID_popupClose)
104 items = [['Add', self.ID_popupAdd] , ['Close', self.ID_popupClose]]
106 menu.Append(item[1], item[0])
107 # Popup the menu. If an item is selected then its handler
108 # will be called before PopupMenu returns.
112 def OnPopupAdd(self, event):
115 def OnPopupClose(self, event):
116 item = self.PlaylistsTree.GetSelection()
117 if self.PlaylistsTree.ItemHasChildren(item):
118 playlist_name = self.PlaylistsTree.GetItemText(item)
119 self.Parent.DeletePlotPage(playlist_name)
120 #del self.Playlists[playlist_name]
121 #TODO: delete playlist, close notebook tab
122 #self.Parent.AddToPlaylists()