From 300551c499d4f608433001477fe87936fbe8a4ba Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 21 Aug 2010 10:37:21 -0400 Subject: [PATCH] Add hooke.playlist.Playlists for better playlist serialization. --- hooke/hooke.py | 2 +- hooke/playlist.py | 19 ++++++++++++++++++- hooke/plugin/tutorial.py | 6 +++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/hooke/hooke.py b/hooke/hooke.py index 98f3649..d40be70 100644 --- a/hooke/hooke.py +++ b/hooke/hooke.py @@ -92,7 +92,7 @@ class Hooke (object): self.load_drivers() self.load_ui() self.engine = engine.CommandEngine() - self.playlists = playlist.NoteIndexList() + self.playlists = playlist.Playlists() def load_log(self): config_file = StringIO.StringIO() diff --git a/hooke/playlist.py b/hooke/playlist.py index fdebc40..473e736 100644 --- a/hooke/playlist.py +++ b/hooke/playlist.py @@ -98,8 +98,9 @@ class NoteIndexList (list): return state def _assert_clean_state(self, owner, state): - return for k,v in state.items(): + if k == 'drivers': # HACK. Need better driver serialization. + continue try: yaml.safe_dump((k,v)) except RepresenterError, e: @@ -520,3 +521,19 @@ class FilePlaylist (Playlist): curve.set_hooke(hooke) if identify == True: curve.identify(self.drivers) + + +class Playlists (NoteIndexList): + """A :class:`NoteIndexList` of :class:`FilePlaylist`\s. + """ + def __init__(self, *arg, **kwargs): + super(Playlists, self).__init__(*arg, **kwargs) + + def _item_getstate(self, item): + assert isinstance(item, FilePlaylist), type(item) + return item.__getstate__() + + def _item_setstate(self, state): + item = FilePlaylist(drivers=[]) + item.__setstate__(state) + return item diff --git a/hooke/plugin/tutorial.py b/hooke/plugin/tutorial.py index 26ef38e..ecc9af5 100644 --- a/hooke/plugin/tutorial.py +++ b/hooke/plugin/tutorial.py @@ -231,9 +231,9 @@ class HookeInfoCommand (Command): # loading curves. outqueue.put('drivers: %s' % ', '.join([driver.name for driver in hooke.drivers])) - # hooke.playlists contains a - # :class:`hooke.playlist.NoteIndexList` of - # :class:`hooke.playlist.Playlist`\s. Each playlist may + # hooke.playlists is a + # :class:`hooke.playlist.Playlists` instance full of + # :class:`hooke.playlist.FilePlaylist`\s. Each playlist may # contain several :class:`hooke.curve.Curve`\s representing a # grouped collection of data. playlist = hooke.playlists.current() -- 2.26.2