Saving and Opening Playlists

This is an easy one. Basically we serialize the ‘contents’ list in our playlist object.


self.ui.saveButton.clicked.connect(self.saveButton_clicked)
self.ui.openButton.clicked.connect(self.openButton_clicked)

def saveButton_clicked(self):
 dialog = QtGui.QFileDialog(self)
 fname, _ = dialog.getSaveFileName(self, 'Save Playlist',filter=self.tr("Tubeplayer Lists (*.tpl)"))
 if fname is not None and fname != '':
   if not fname.endswith('.tpl'):
     fname = ''.join([fname, '.tpl'])
   f = open(fname, 'w')
   cPickle.Pickler(f, cPickle.HIGHEST_PROTOCOL).dump(self.play_list.contents)
   f.close()

def openButton_clicked(self):
  dialog = QtGui.QFileDialog(self)
  fname, _ = dialog.getOpenFileName(self, 'Open Playlist',filter=self.tr("Tubeplayer Lists (*.tpl)"))
  if fname is not None and fname != '':
    f = open(fname, 'r')
    self.play_list.contents = cPickle.Unpickler(f).load()
    f.close()
    self.play_list.reset()

Back to Contents

Advertisements
This entry was posted in PySide, Python, TubePlayer and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s