-#import os\r
-#import os.path\r
-import wx\r
-#import xml.dom.minidom\r
-\r
-class Playlists(wx.Panel):\r
-\r
- def __init__(self, parent):\r
- # Use the WANTS_CHARS style so the panel doesn't eat the Return key.\r
- wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS|wx.NO_BORDER, size=(160, 200))\r
-\r
- 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
- imglist = wx.ImageList(16, 16, True, 2)\r
- imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, wx.Size(16, 16)))\r
- imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, wx.Size(16, 16)))\r
- self.PlaylistsTree.AssignImageList(imglist)\r
- self.PlaylistsTree.AddRoot('Playlists', 0)\r
- self.PlaylistsTree.Bind(wx.EVT_RIGHT_DOWN , self.OnContextMenu)\r
-\r
- self.Playlists = {}\r
-\r
- sizer = wx.BoxSizer(wx.VERTICAL)\r
- sizer.Add(self.PlaylistsTree, 1, wx.EXPAND)\r
- self.SetSizer(sizer)\r
- sizer.Fit(self)\r
-\r
- #def add_playlist(self, files=[], name='Untitled'):\r
- ##TODO: change cursor or progressbar (maybe in statusbar)\r
- ##self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))\r
- #if files:\r
- #playlist = hookeplaylist.Playlist(self.drivers)\r
- #for item in files:\r
- #playlist.add_curve(item)\r
- #if playlist.count > 0:\r
- #playlist_name = name\r
- #count = 1\r
- #while playlist_name in self.Playlists:\r
- #playlist_name = ''.join([name, str(count)])\r
- #count += 1\r
- #playlist.name = playlist_name\r
- #playlist.reset()\r
- #self.AddToPlaylists(playlist)\r
-\r
- #def FilterPlaylist(self, curves_to_keep=[]):\r
- #playlist_active = self.GetActivePlaylist()\r
- #playlist_new = Playlist(self.drivers)\r
- #for curve_index in curves_to_keep:\r
- #playlist_new.curves.append(playlist_active.curves[curve_index])\r
- #return playlist_new\r
-\r
- def GetActivePlaylist(self):\r
- playlist_name = self.GetActivePlaylistName()\r
- if playlist_name in self.playlists:\r
- return self.playlists[playlist_name][0]\r
- else:\r
- return None\r
-\r
- def GetActivePlaylistName(self):\r
- #get the selected item from the tree\r
- selected_item = self.PlaylistsTree.GetSelection()\r
- #test if a playlist or a curve was double-clicked\r
- if self.PlaylistsTree.ItemHasChildren(selected_item):\r
- playlist_item = selected_item\r
- else:\r
- #get the name of the playlist\r
- playlist_item = self.PlaylistsTree.GetItemParent(selected_item)\r
- #now we have a playlist\r
- return self.PlaylistsTree.GetItemText(playlist_item)\r
-\r
- def OnContextMenu(self, event):\r
- hit_item, hit_flags = self.PlaylistsTree.HitTest(event.GetPosition())\r
- if (hit_flags & wx.TREE_HITTEST_ONITEM) != 0:\r
- self.PlaylistsTree.SelectItem(hit_item)\r
- # only do this part the first time so the events are only bound once\r
- #\r
- # Yet another alternate way to do IDs. Some prefer them up top to\r
- # avoid clutter, some prefer them close to the object of interest\r
- # for clarity.\r
- if not hasattr(self, 'ID_popupAdd'):\r
- self.ID_popupAdd = wx.NewId()\r
- self.ID_popupClose = wx.NewId()\r
- self.Bind(wx.EVT_MENU, self.OnPopupAdd, id=self.ID_popupAdd)\r
- self.Bind(wx.EVT_MENU, self.OnPopupClose, id=self.ID_popupClose)\r
- # make a menu\r
- menu = wx.Menu()\r
- items = [['Add', self.ID_popupAdd] , ['Close', self.ID_popupClose]]\r
- for item in items:\r
- menu.Append(item[1], item[0])\r
- # Popup the menu. If an item is selected then its handler\r
- # will be called before PopupMenu returns.\r
- self.PopupMenu(menu)\r
- menu.Destroy()\r
-\r
- def OnPopupAdd(self, event):\r
- pass\r
-\r
- def OnPopupClose(self, event):\r
- item = self.PlaylistsTree.GetSelection()\r
- if self.PlaylistsTree.ItemHasChildren(item):\r
- playlist_name = self.PlaylistsTree.GetItemText(item)\r
- self.Parent.DeletePlotPage(playlist_name)\r
- #del self.Playlists[playlist_name]\r
- #TODO: delete playlist, close notebook tab\r
- #self.Parent.AddToPlaylists()\r
- else:\r
- pass\r
+# Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
+#
+# This file is part of Hooke.
+#
+# Hooke is free software: you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation, either
+# version 3 of the License, or (at your option) any later version.
+#
+# Hooke is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with Hooke. If not, see
+# <http://www.gnu.org/licenses/>.
+
+#import os
+#import os.path
+import wx
+#import xml.dom.minidom
+
+class Playlists(wx.Panel):
+
+ def __init__(self, parent):
+ # Use the WANTS_CHARS style so the panel doesn't eat the Return key.
+ wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS|wx.NO_BORDER, size=(160, 200))
+
+ 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)
+ imglist = wx.ImageList(16, 16, True, 2)
+ imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, wx.Size(16, 16)))
+ imglist.Add(wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, wx.Size(16, 16)))
+ self.PlaylistsTree.AssignImageList(imglist)
+ self.PlaylistsTree.AddRoot('Playlists', 0)
+ self.PlaylistsTree.Bind(wx.EVT_RIGHT_DOWN , self.OnContextMenu)
+
+ self.Playlists = {}
+
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ sizer.Add(self.PlaylistsTree, 1, wx.EXPAND)
+ self.SetSizer(sizer)
+ sizer.Fit(self)
+
+ #def add_playlist(self, files=[], name='Untitled'):
+ ##TODO: change cursor or progressbar (maybe in statusbar)
+ ##self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
+ #if files:
+ #playlist = hookeplaylist.Playlist(self.drivers)
+ #for item in files:
+ #playlist.append_curve_by_path(item)
+ #if playlist.count > 0:
+ #playlist_name = name
+ #count = 1
+ #while playlist_name in self.Playlists:
+ #playlist_name = ''.join([name, str(count)])
+ #count += 1
+ #playlist.name = playlist_name
+ #playlist.reset()
+ #self.AddToPlaylists(playlist)
+
+ #def FilterPlaylist(self, curves_to_keep=[]):
+ #playlist_active = self.GetActivePlaylist()
+ #playlist_new = Playlist(self.drivers)
+ #for curve_index in curves_to_keep:
+ #playlist_new.curves.append(playlist_active.curves[curve_index])
+ #return playlist_new
+
+ def GetActivePlaylist(self):
+ playlist_name = self.GetActivePlaylistName()
+ if playlist_name in self.playlists:
+ return self.playlists[playlist_name][0]
+ else:
+ return None
+
+ def GetActivePlaylistName(self):
+ #get the selected item from the tree
+ selected_item = self.PlaylistsTree.GetSelection()
+ #test if a playlist or a curve was double-clicked
+ if self.PlaylistsTree.ItemHasChildren(selected_item):
+ playlist_item = selected_item
+ else:
+ #get the name of the playlist
+ playlist_item = self.PlaylistsTree.GetItemParent(selected_item)
+ #now we have a playlist
+ return self.PlaylistsTree.GetItemText(playlist_item)
+
+ def OnContextMenu(self, event):
+ hit_item, hit_flags = self.PlaylistsTree.HitTest(event.GetPosition())
+ if (hit_flags & wx.TREE_HITTEST_ONITEM) != 0:
+ self.PlaylistsTree.SelectItem(hit_item)
+ # only do this part the first time so the events are only bound once
+ #
+ # Yet another alternate way to do IDs. Some prefer them up top to
+ # avoid clutter, some prefer them close to the object of interest
+ # for clarity.
+ if not hasattr(self, 'ID_popupAdd'):
+ self.ID_popupAdd = wx.NewId()
+ self.ID_popupClose = wx.NewId()
+ self.Bind(wx.EVT_MENU, self.OnPopupAdd, id=self.ID_popupAdd)
+ self.Bind(wx.EVT_MENU, self.OnPopupClose, id=self.ID_popupClose)
+ # make a menu
+ menu = wx.Menu()
+ items = [['Add', self.ID_popupAdd] , ['Close', self.ID_popupClose]]
+ for item in items:
+ menu.Append(item[1], item[0])
+ # Popup the menu. If an item is selected then its handler
+ # will be called before PopupMenu returns.
+ self.PopupMenu(menu)
+ menu.Destroy()
+
+ def OnPopupAdd(self, event):
+ pass
+
+ def OnPopupClose(self, event):
+ item = self.PlaylistsTree.GetSelection()
+ if self.PlaylistsTree.ItemHasChildren(item):
+ playlist_name = self.PlaylistsTree.GetItemText(item)
+ self.Parent.DeletePlotPage(playlist_name)
+ #del self.Playlists[playlist_name]
+ #TODO: delete playlist, close notebook tab
+ #self.Parent.AddToPlaylists()
+ else:
+ pass