Merged my unitary FFT wrappers (FFT_tools) as hooke.util.fft.
[hooke.git] / hooke / ui / gui / hookeplaylist.py
1 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
2 #
3 # This file is part of Hooke.
4 #
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.
9 #
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.
14 #
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/>.
18
19 #import os
20 #import os.path
21 import wx
22 #import xml.dom.minidom
23
24 class Playlists(wx.Panel):
25
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))
29
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)
37
38         self.Playlists = {}
39
40         sizer = wx.BoxSizer(wx.VERTICAL)
41         sizer.Add(self.PlaylistsTree, 1, wx.EXPAND)
42         self.SetSizer(sizer)
43         sizer.Fit(self)
44
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))
48         #if files:
49             #playlist = hookeplaylist.Playlist(self.drivers)
50             #for item in files:
51                 #playlist.append_curve_by_path(item)
52         #if playlist.count > 0:
53             #playlist_name = name
54             #count = 1
55             #while playlist_name in self.Playlists:
56                 #playlist_name = ''.join([name, str(count)])
57                 #count += 1
58             #playlist.name = playlist_name
59             #playlist.reset()
60             #self.AddToPlaylists(playlist)
61
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])
67         #return playlist_new
68
69     def GetActivePlaylist(self):
70         playlist_name = self.GetActivePlaylistName()
71         if playlist_name in self.playlists:
72             return self.playlists[playlist_name][0]
73         else:
74             return None
75
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
82         else:
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)
87
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
93             #
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
96             # for clarity.
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)
102             # make a menu
103             menu = wx.Menu()
104             items = [['Add', self.ID_popupAdd] , ['Close', self.ID_popupClose]]
105             for item in items:
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.
109             self.PopupMenu(menu)
110             menu.Destroy()
111
112     def OnPopupAdd(self, event):
113         pass
114
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()
123         else:
124             pass