6 Playlist commands for Hooke.
8 Copyright 2010 by Dr. Rolf Schmidt (Concordia University, Canada)
10 This program is released under the GNU General Public License version 2.
13 import lib.libhooke as lh
15 wxversion.select(lh.WX_GOOD)
21 from lib.playlist import Playlist
23 class playlistCommands(object):
25 Playlist commands to generate, save and load lists of force curves
31 def do_genlist(self, filemask='', folder=''):
34 Generates a file playlist.
35 Note it doesn't *save* it: see savelist for this.
37 If [input files] is a directory, it will use all files in the directory for playlist.
43 are all equivalent syntax.
45 Syntax: genlist [input files]
48 filemask = self.GetStringFromConfig('playlist', 'genlist', 'filemask')
50 folder = self.GetStringFromConfig('playlist', 'genlist', 'folder')
51 if os.path.isdir(folder):
52 path = os.path.join(folder, filemask)
53 #expanding correctly the input list with the glob module :)
54 files = glob.glob(path)
57 for file_to_add in files:
58 playlist.add_file(file_to_add)
59 if playlist.count > 0:
60 playlist.name = self._GetUniquePlaylistName(os.path.basename(folder))
62 self.AddToPlaylists(playlist)
63 self.AppendToOutput('Playlist generated.')
64 self.AppendToOutput(playlist.get_status_string())
66 self.AppendToOutput(''.join(['Cannot find folder ', folder]))
68 def do_loadlist(self, filename=''):
73 Syntax: loadlist [playlist file]
75 #TODO: check for duplicate playlists, ask the user for a unique name
76 #if self.playlist_name in self.playlists:
80 filename = self.GetStringFromConfig('playlist', 'loadlist', 'filename')
82 #add hkp extension if necessary
83 if not filename.endswith('.hkp'):
84 filename = ''.join([filename, '.hkp'])
85 #prefix with 'hookeDir' if just a filename or a relative path
86 filename = lh.get_file_path(filename)
87 if os.path.isfile(filename):
89 playlist_new = Playlist(filename)
90 if playlist_new.count > 0:
91 self.AppendToOutput('Playlist loaded.')
92 self.AddToPlaylists(playlist_new)
93 self.AppendToOutput(playlist_new.get_status_string())
95 message = ''.join(['The file ', filename, ' does not contain any valid curve information.'])
96 dialog = wx.MessageDialog(None, message, 'Info', wx.OK)
99 message = ''.join(['File ', filename, ' not found.'])
100 dialog = wx.MessageDialog(None, message, 'Info', wx.OK)
103 def do_savelist(self, filename=''):
106 Saves the current file playlist on disk.
108 Syntax: savelist [filename]
112 filename = self.GetStringFromConfig('playlist', 'savelist', 'filename')
114 #autocomplete filename if not specified
115 if not filename.endswith('.hkp'):
116 filename = filename.join(['.hkp'])
118 playlist = self.GetActivePlaylist()
120 playlist.save(filename)
121 self.AppendToOutput('Playlist saved.')
123 self.AppendToOutput('Playlist could not be saved.')