forked from Wobbl/Wobuzz
Added popup on import where the user can configure how the tracks get imported.
This commit is contained in:
parent
31b2e3bf41
commit
fd34476d00
12 changed files with 289 additions and 28 deletions
8
wobuzz/ui/custom_widgets/__init__.py
Normal file
8
wobuzz/ui/custom_widgets/__init__.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
|
||||
def __getattr__(name):
|
||||
match name:
|
||||
case "GroupBox":
|
||||
from .group_box import GroupBox
|
||||
return GroupBox
|
18
wobuzz/ui/custom_widgets/group_box.py
Normal file
18
wobuzz/ui/custom_widgets/group_box.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from PyQt6.QtCore import Qt
|
||||
from PyQt6.QtWidgets import QGroupBox, QSizePolicy
|
||||
|
||||
|
||||
class GroupBox(QGroupBox):
|
||||
"""
|
||||
Just a QGroupBox with some custom style I don't always want to rewrite.
|
||||
"""
|
||||
|
||||
def __init__(self, title, parent=None):
|
||||
super().__init__(title, parent)
|
||||
|
||||
self.setSizePolicy(QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Fixed)
|
||||
self.setAlignment(Qt.AlignmentFlag.AlignLeading | Qt.AlignmentFlag.AlignVCenter)
|
||||
|
||||
self.setStyleSheet("QGroupBox{font-weight: bold;}")
|
116
wobuzz/ui/library/import_dialog.py
Normal file
116
wobuzz/ui/library/import_dialog.py
Normal file
|
@ -0,0 +1,116 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from PyQt6.QtWidgets import (
|
||||
QWidget,
|
||||
QLabel,
|
||||
QDialog,
|
||||
QCheckBox,
|
||||
QLineEdit,
|
||||
QDialogButtonBox,
|
||||
QButtonGroup,
|
||||
QRadioButton,
|
||||
QVBoxLayout,
|
||||
QHBoxLayout,
|
||||
QFormLayout,
|
||||
QSizePolicy,
|
||||
)
|
||||
from PyQt6.QtCore import Qt
|
||||
|
||||
from ..custom_widgets import GroupBox
|
||||
|
||||
|
||||
class ImportDialog(QDialog):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.setWindowTitle("Import")
|
||||
|
||||
layout = QVBoxLayout(self)
|
||||
self.setLayout(layout)
|
||||
|
||||
self.tagging_section = GroupBox("Metadata And Tagging", self)
|
||||
self.tagging_section.layout = QFormLayout(self.tagging_section)
|
||||
self.tagging_section.setLayout(self.tagging_section.layout)
|
||||
layout.addWidget(self.tagging_section)
|
||||
|
||||
self.tagging_section.overwrite_metadata = QCheckBox(
|
||||
"Set custom metadata for all tracks (Leave property blank to keep the metadata from the audio file.)",
|
||||
self.tagging_section
|
||||
)
|
||||
self.tagging_section.layout.addRow(self.tagging_section.overwrite_metadata)
|
||||
|
||||
self.tagging_section.artist = QLineEdit(self.tagging_section)
|
||||
self.tagging_section.layout.addRow(" Artist: ", self.tagging_section.artist)
|
||||
self.tagging_section.artist.setPlaceholderText("Keep track artist")
|
||||
|
||||
self.tagging_section.album = QLineEdit(self.tagging_section)
|
||||
self.tagging_section.layout.addRow(" Album: ", self.tagging_section.album)
|
||||
self.tagging_section.album.setPlaceholderText("Keep track album")
|
||||
|
||||
self.tagging_section.genre = QLineEdit(self.tagging_section)
|
||||
self.tagging_section.layout.addRow(" Genre: ", self.tagging_section.genre)
|
||||
self.tagging_section.genre.setPlaceholderText("Keep track genre")
|
||||
|
||||
self.file_section = GroupBox("File Structure", self)
|
||||
self.file_section.layout = QFormLayout(self.file_section)
|
||||
self.file_section.setLayout(self.file_section.layout)
|
||||
layout.addWidget(self.file_section)
|
||||
|
||||
self.file_section.copy_type_description = QLabel("How should the tracks get put into the Wobuzz library?")
|
||||
self.file_section.layout.addRow(self.file_section.copy_type_description)
|
||||
|
||||
self.file_section.copy_type = QButtonGroup(self.file_section)
|
||||
|
||||
self.file_section.copy_type_symlink = QRadioButton("Create symlinks", self.file_section)
|
||||
self.file_section.copy_type_symlink.setChecked(True)
|
||||
self.file_section.copy_type.addButton(self.file_section.copy_type_symlink)
|
||||
self.file_section.layout.addWidget(self.file_section.copy_type_symlink)
|
||||
|
||||
self.file_section.copy_type_copy = QRadioButton("Copy tracks", self.file_section)
|
||||
self.file_section.copy_type.addButton(self.file_section.copy_type_copy)
|
||||
self.file_section.layout.addWidget(self.file_section.copy_type_copy)
|
||||
|
||||
self.file_section.copy_type_move = QRadioButton("Move tracks", self.file_section)
|
||||
self.file_section.copy_type.addButton(self.file_section.copy_type_move)
|
||||
self.file_section.layout.addWidget(self.file_section.copy_type_move)
|
||||
|
||||
# add expanding widget so the GroupBoxes aren't vertically centered
|
||||
spacer_widget = QWidget(self)
|
||||
spacer_widget.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
||||
layout.addWidget(spacer_widget)
|
||||
|
||||
dialog_buttons = QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
|
||||
|
||||
self.dialog_buttons = QDialogButtonBox(dialog_buttons)
|
||||
layout.addWidget(self.dialog_buttons)
|
||||
|
||||
self.reset_inputs()
|
||||
|
||||
self.tagging_section.overwrite_metadata.stateChanged.connect(self.overwrite_state_changed)
|
||||
self.dialog_buttons.accepted.connect(self.accept)
|
||||
self.dialog_buttons.rejected.connect(self.reject)
|
||||
|
||||
def exec(self):
|
||||
self.reset_inputs()
|
||||
|
||||
return super().exec()
|
||||
|
||||
def overwrite_state_changed(self, state: int):
|
||||
overwrite = state == 2
|
||||
|
||||
self.tagging_section.artist.setEnabled(overwrite)
|
||||
self.tagging_section.album.setEnabled(overwrite)
|
||||
self.tagging_section.genre.setEnabled(overwrite)
|
||||
|
||||
self.tagging_section.layout.setRowVisible(self.tagging_section.artist, overwrite)
|
||||
self.tagging_section.layout.setRowVisible(self.tagging_section.album, overwrite)
|
||||
self.tagging_section.layout.setRowVisible(self.tagging_section.genre, overwrite)
|
||||
|
||||
def reset_inputs(self):
|
||||
self.overwrite_state_changed(0)
|
||||
|
||||
self.tagging_section.artist.setText("")
|
||||
self.tagging_section.album.setText("")
|
||||
self.tagging_section.genre.setText("")
|
||||
|
||||
self.file_section.copy_type_symlink.setChecked(True)
|
|
@ -1,6 +1,9 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from PyQt6.QtWidgets import QFileDialog
|
||||
from PyQt6.QtWidgets import QDialog, QFileDialog
|
||||
|
||||
from .library.import_dialog import ImportDialog
|
||||
from ..types import Types
|
||||
|
||||
|
||||
class Popups:
|
||||
|
@ -12,7 +15,7 @@ class Popups:
|
|||
|
||||
self.audio_file_selector = QFileDialog(self.window, "Select Audio Files")
|
||||
self.audio_file_selector.setFileMode(QFileDialog.FileMode.ExistingFiles)
|
||||
self.audio_file_selector.setNameFilters(["Audio Files (*.flac *.wav *.mp3 *.ogg *.opus)", "Any (*)"])
|
||||
self.audio_file_selector.setNameFilters(["Audio Files (*.flac *.wav *.mp3 *.ogg *.opus *.m4a)", "Any (*)"])
|
||||
self.audio_file_selector.setViewMode(QFileDialog.ViewMode.List)
|
||||
|
||||
self.playlist_file_selector = QFileDialog(self.window, "Select Playlist")
|
||||
|
@ -20,6 +23,8 @@ class Popups:
|
|||
self.playlist_file_selector.setNameFilters(["Playlists (*.wbz.m3u *.m3u)", "Any (*)"])
|
||||
self.playlist_file_selector.setViewMode(QFileDialog.ViewMode.List)
|
||||
|
||||
self.import_dialog = ImportDialog()
|
||||
|
||||
self.window.open_track_action.triggered.connect(self.open_tracks)
|
||||
self.window.import_track_action.triggered.connect(self.import_tracks)
|
||||
self.window.open_playlist_action.triggered.connect(self.open_playlist)
|
||||
|
@ -39,11 +44,43 @@ class Popups:
|
|||
if files is not None and not files == []:
|
||||
self.app.library.open_tracks(files)
|
||||
|
||||
def get_import_options(self):
|
||||
import_options = Types.ImportOptions()
|
||||
|
||||
if self.import_dialog.tagging_section.overwrite_metadata.isChecked():
|
||||
artist = self.import_dialog.tagging_section.artist.text()
|
||||
album = self.import_dialog.tagging_section.album.text()
|
||||
genre = self.import_dialog.tagging_section.genre.text()
|
||||
|
||||
if not artist == "":
|
||||
import_options.artist = artist
|
||||
|
||||
if not album == "":
|
||||
import_options.album = album
|
||||
|
||||
if not genre == "":
|
||||
import_options.genre = genre
|
||||
|
||||
if self.import_dialog.file_section.copy_type_copy.isChecked():
|
||||
import_options.copy_type = Types.CopyType.copy
|
||||
|
||||
elif self.import_dialog.file_section.copy_type_move.isChecked():
|
||||
import_options.copy_type = Types.CopyType.move
|
||||
|
||||
return import_options
|
||||
|
||||
def import_tracks(self):
|
||||
files = self.select_audio_files()
|
||||
|
||||
if files is not None and not files == []:
|
||||
self.app.library.import_tracks(files)
|
||||
if files is None or files == []:
|
||||
return
|
||||
|
||||
if self.import_dialog.exec() == QDialog.rejected:
|
||||
return
|
||||
|
||||
import_options = self.get_import_options()
|
||||
|
||||
self.app.library.import_tracks(files, import_options)
|
||||
|
||||
def open_playlist(self):
|
||||
playlist_path = self.select_playlist_file()
|
||||
|
@ -54,5 +91,12 @@ class Popups:
|
|||
def import_playlist(self):
|
||||
playlist_path = self.select_playlist_file()
|
||||
|
||||
if playlist_path is not None and not playlist_path == "":
|
||||
self.app.library.import_playlist(playlist_path)
|
||||
if playlist_path is None or playlist_path == "":
|
||||
return
|
||||
|
||||
if self.import_dialog.exec() == QDialog.rejected:
|
||||
return
|
||||
|
||||
import_options = self.get_import_options()
|
||||
|
||||
self.app.library.import_playlist(playlist_path, import_options)
|
||||
|
|
|
@ -2,21 +2,18 @@
|
|||
|
||||
from PyQt6.QtCore import Qt
|
||||
from PyQt6.QtGui import QFont
|
||||
from PyQt6.QtWidgets import QGroupBox, QLabel, QSizePolicy, QFormLayout
|
||||
from PyQt6.QtWidgets import QLabel, QSizePolicy, QFormLayout
|
||||
|
||||
from ..custom_widgets import GroupBox
|
||||
|
||||
|
||||
class SubCategory(QGroupBox):
|
||||
class SubCategory(GroupBox):
|
||||
description_font = QFont()
|
||||
description_font.setPointSize(8)
|
||||
|
||||
def __init__(self, title: str, description: str=None, parent=None):
|
||||
super().__init__(title, parent)
|
||||
|
||||
self.setSizePolicy(QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Fixed)
|
||||
self.setAlignment(Qt.AlignmentFlag.AlignLeading | Qt.AlignmentFlag.AlignVCenter)
|
||||
|
||||
self.setStyleSheet("QGroupBox{font-weight: bold;}")
|
||||
|
||||
self.layout = QFormLayout()
|
||||
self.setLayout(self.layout)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue