# point.find_graph_coords(xvector, yvector)
# return point
#
-##PLAYLIST INTERACTION COMMANDS
-##-------------------------------
-# def do_genlist(self, folder=lh.hookeDir, filemask='*.*'):
-# '''
-# GENLIST
-# Generates a file playlist.
-# Note it doesn't *save* it: see savelist for this.
-#
-# If [input files] is a directory, it will use all files in the directory for playlist.
-# So:
-# genlist dir
-# genlist dir/
-# genlist dir/*.*
-#
-# are all equivalent syntax.
-# ------------
-# Syntax: genlist [input files]
-# '''
-# #args list is: input folder, file mask
-# if os.path.isdir(folder):
-# path = os.path.join(folder, filemask)
-# #expanding correctly the input list with the glob module :)
-# files = glob.glob(path)
-# files.sort()
-# #TODO: change cursor or progressbar (maybe in statusbar)
-# #self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
-# playlist = playlist.Playlist(self.drivers)
-# for item in files:
-# curve = playlist.append_curve_by_path(item)
-# plot = copy.deepcopy(curve.plots[0])
-# #add the 'raw' data
-# curve.add_data('raw', plot.vectors[0][0], plot.vectors[0][1], color=plot.colors[0], style='plot')
-# curve.add_data('raw', plot.vectors[1][0], plot.vectors[1][1], color=plot.colors[1], style='plot')
-# #apply all active plotmanipulators and add the 'manipulated' data
-# for plotmanipulator in self.plotmanipulators:
-# plot = plotmanipulator[1](plot, curve)
-# curve.set_data('manipulated', plot.vectors[0][0], plot.vectors[0][1], color=plot.colors[0], style='plot')
-# curve.add_data('manipulated', plot.vectors[1][0], plot.vectors[1][1], color=plot.colors[1], style='plot')
-# if playlist.count > 0:
-# playlist.name = self._GetUniquePlaylistName(os.path.basename(folder))
-# playlist.reset()
-# self.AddToPlaylists(playlist)
-# self.AppendToOutput(playlist.get_status_string())
-# else:
-# self.AppendToOutput(''.join(['Cannot find folder ', folder]))
-#
-# def do_loadlist(self, filename):
-# '''
-# LOADLIST
-# Loads a file playlist
-# -----------
-# Syntax: loadlist [playlist file]
-# '''
-# #TODO: check for duplicate playlists, ask the user for a unique name
-# #if self.playlist_name in self.playlists:
-#
-# #add hkp extension if necessary
-# if not filename.endswith('.hkp'):
-# filename = ''.join([filename, '.hkp'])
-# #prefix with 'hookeDir' if just a filename or a relative path
-# filename = lh.get_file_path(filename)
-# if os.path.isfile(filename):
-# #TODO: change cursor
-# #self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
-# playlist_new = playlist.Playlist(self.drivers)
-# playlist_new.load(filename)
-# if playlist_new.count > 0:
-# for curve in playlist_new.curves:
-# plot = copy.deepcopy(curve.plots[0])
-# for plotmanip in self.plotmanipulators:
-# #to_plot = plotmanip[1](to_plot, curve)
-# plot = plotmanip[1](plot, curve)
-# curve.set_data('manipulated', plot.vectors[0][0], plot.vectors[0][1], color=plot.colors[0], style='plot')
-# curve.add_data('manipulated', plot.vectors[1][0], plot.vectors[1][1], color=plot.colors[1], style='plot')
-# self.AddToPlaylists(playlist_new)
-# #else:
-# ##TODO: display dialog
-# self.AppendToOutput(playlist_new.get_status_string())
-# #TODO: change cursor
-# #self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
-# else:
-# #TODO: display dialog
-# self.AppendToOutput(''.join['File ', filename, ' not found.\n'])
-# pass
-#
-# def do_savelist(self, filename):
-# '''
-# SAVELIST
-# Saves the current file playlist on disk.
-# ------------
-# Syntax: savelist [filename]
-# '''
-#
-# #self.playlist_generics['pointer'] = self._GetActiveCurveIndex
-# pointer = self._GetActiveCurveIndex()
-# #autocomplete filename if not specified
-# if not filename.endswith('.hkp'):
-# filename = filename.join(['.hkp'])
-#
-# playlist = self.GetActivePlaylist()
-# playlist.set_XML()
-# playlist.save(filename)
#
##PLOT INTERACTION COMMANDS
##-------------------------------
playlist._index = 0
return playlist
+
class FilePlaylist (Playlist):
version = '0.1'
def __init__(self, drivers, name=None, path=None):
- if name == None and path != None:
- name = os.path.basename(path)
super(FilePlaylist, self).__init__(drivers, name)
- self.path = path
+ self.set_path(path)
self._digest = None
+ def set_path(self, path):
+ if not path.endswith('.hkp'):
+ path += '.hkp'
+ if name == None and path != None:
+ name = os.path.basename(path)
+
def is_saved(self):
return self.digest() == self._digest
def load(self, path=None):
"""Load a playlist from a file.
"""
- if path != None:
- self.path = path
- if self.name == None:
- self.name = os.path.basename(self.path)
- doc = xml.dom.minidom.parse(path)
+ self.set_path(path)
+ doc = xml.dom.minidom.parse(self.path)
return self._from_xml_doc(doc)
- def save(self, path):
+ def save(self, path=None):
"""Saves the playlist in a XML file.
"""
- f = file(path, 'w')
+ self.set_path(path)
+ f = file(self.path, 'w')
f.write(self.flatten())
f.close()
classes.
"""
+import glob
+
from ..playlist import FilePlaylist
from ..plugin import Builtin, Command, Argument
def commands(self):
return [NextCommand(), PreviousCommand(), JumpCommand(),
SaveCommand(), LoadCommand(),
- AddCommand(), RemoveCommand(), FilterCommand()]
+ AddCommand(), AddGlobCommand(),
+ RemoveCommand(), FilterCommand()]
class NextCommand (Command):
"""Move playlist to the next curve.
params['playlist'].append_curve_by_path(params['input'],
params['info'])
+class AddGlobCommand (Command):
+ """Add curves to a playlist with file globbing.
+
+ Adding lots of files one at a time can be tedious. With this
+ command you can use globs (`data/curves/*.dat`) to add curves
+ for all matching files at once.
+ """
+ def __init__(self):
+ super(AddCommand, self).__init__(
+ name='glob curves to playlist',
+ arguments=[
+ Argument(name='playlist', type='playlist', optional=False,
+ help="""
+:class:``hooke.plugin.playlist.Playlist`` to act on.
+""".strip()),
+ Argument(name='input', type='glob', optional=False,
+ help="""
+File name glob for the input :class:`hooke.curve.Curve`.
+""".strip()),
+ Argument(name='info', type='dict', optional=True,
+ help="""
+Additional information for the input :class:`hooke.curve.Curve`.
+""".strip()),
+ ],
+ help=self.__doc__)
+
+ def _run(inqueue, outqueue, params):
+ for path in sorted(glob.glob(params['input'])):
+ params['playlist'].append_curve_by_path(path, params['info'])
+
class RemoveCommand (Command):
"""Remove a curve from a playlist.
"""
class FilterCommand (Command):
"""Create a subset playlist via a selection function.
+
+ Removing lots of curves one at a time can be tedious. With this
+ command you can use a function `filter` to select the curves you
+ wish to keep.
"""
def __init__(self):
super(FilterCommand, self).__init__(
""".strip()),
Argument(name='filter', type='function', optional=False,
help="""
-Function returning `True` for "good" curves.
+Function returning `True` for "good" curves. `filter(curve) -> True/False`.
""".strip()),
],
help=self.__doc__)