def __init__(self, file_path, *args):
     super().__init__(*args)
     self.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled
                   | Qt.ItemIsDragEnabled)
     self.setData(TreeWidgetType.SONG, CustomDataRole.ITEMTYPE)
     info = QFileInfo(file_path)
     self.setData(
         TreeWidgetItemData(TreeWidgetType.SONG,
                            song_path=file_path,
                            song_dir=info.path(),
                            song_file=info.fileName()),
         CustomDataRole.ITEMDATA)
예제 #2
0
 def write_bookmarks(self):
     if not self._modified:
         return
     dir_path = _config_dir()
     native_dir_path = QDir.toNativeSeparators(dir_path)
     dir = QFileInfo(dir_path)
     if not dir.isDir():
         print('Creating {}...'.format(native_dir_path))
         if not QDir(dir.absolutePath()).mkpath(dir.fileName()):
             warnings.warn('Cannot create {}.'.format(native_dir_path),
                           RuntimeWarning)
             return
     serialized_model = _serialize_model(self._model, dir_path)
     bookmark_file_name = os.path.join(native_dir_path, _bookmark_file)
     print('Writing {}...'.format(bookmark_file_name))
     with open(bookmark_file_name, 'w') as bookmark_file:
         jsons.dump(serialized_model, bookmark_file, indent=4)
예제 #3
0
 def addAlbum(self, dir_path: str):
     songs = []
     for file_path in files_in_directory(dir_path):
         info = QFileInfo(file_path)
         if not info.isReadable():
             logging.warning("File {} is not readable".format(file_path))
             continue
         if info.isDir():
             self.addAlbum(file_path)
         elif file_is_audio(file_path):
             item = self._create_song_item(file_path)
             item.setText(info.fileName())
             songs.append(item)
     if len(songs) > 0:
         album_item = self._create_album_item(dir_path, songs)
         album_item.setText(dir_path)
         self.addTopLevelItem(album_item)
예제 #4
0
 def __init__(self, file_path, *args):
     super().__init__(*args)
     self.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled
                   | Qt.ItemIsDragEnabled)
     self.setData(TreeWidgetType.SONG, CustomDataRole.ITEMTYPE)
     info = QFileInfo(file_path)
     self.setData(
         TreeWidgetItemData(
             TreeWidgetType.SONG,
             song_path=file_path,
             song_dir=info.path(),
             song_file=info.fileName(),
         ),
         CustomDataRole.ITEMDATA,
     )
     # set acodec to copy by default,
     # overridden when concatenating
     self.set("audioCodec", "copy")