2024-12-20 18:02:59 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
2024-12-28 20:41:18 +01:00
|
|
|
from PyQt6.QtCore import Qt
|
2025-02-28 17:28:14 +01:00
|
|
|
from PyQt6.QtWidgets import QDockWidget, QFileDialog
|
2024-12-29 19:23:53 +01:00
|
|
|
from .ui.main_window import MainWindow
|
2024-12-20 18:02:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
class GUI:
|
2024-12-21 16:07:27 +01:00
|
|
|
def __init__(self, app):
|
|
|
|
self.app = app
|
|
|
|
|
2025-01-25 22:41:29 +01:00
|
|
|
self.dropped = []
|
|
|
|
|
2025-02-28 17:28:14 +01:00
|
|
|
self.window = MainWindow(app, self)
|
2025-01-25 15:14:20 +01:00
|
|
|
self.settings = self.window.settings
|
2025-01-25 16:02:03 +01:00
|
|
|
self.track_control = self.window.track_control
|
2025-02-20 18:06:29 +01:00
|
|
|
self.process_dock = self.window.process_dock
|
2025-02-21 17:26:47 +01:00
|
|
|
self.track_info = self.window.track_info
|
2024-12-20 18:02:59 +01:00
|
|
|
|
2025-02-03 14:08:19 +01:00
|
|
|
self.window.addDockWidget(Qt.DockWidgetArea.LeftDockWidgetArea, self.app.library.main_library_dock)
|
2024-12-28 20:41:18 +01:00
|
|
|
|
|
|
|
self.app.library.main_library_dock.setFeatures(
|
|
|
|
QDockWidget.DockWidgetFeature.DockWidgetMovable |
|
|
|
|
QDockWidget.DockWidgetFeature.DockWidgetFloatable
|
|
|
|
)
|
|
|
|
|
2024-12-23 17:12:21 +01:00
|
|
|
if self.app.settings.window_maximized:
|
|
|
|
self.window.showMaximized()
|
|
|
|
|
2025-02-28 17:28:14 +01:00
|
|
|
elif self.app.settings.window_size is not None:
|
2024-12-23 17:12:21 +01:00
|
|
|
self.window.resize(*self.app.settings.window_size)
|
|
|
|
|
2025-02-28 18:02:37 +01:00
|
|
|
self.audio_file_selector = QFileDialog(self.window, "Select Audio Files")
|
2025-02-28 17:28:14 +01:00
|
|
|
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.setViewMode(QFileDialog.ViewMode.List)
|
|
|
|
|
2025-02-28 18:02:37 +01:00
|
|
|
self.playlist_file_selector = QFileDialog(self.window, "Select Playlist")
|
|
|
|
self.playlist_file_selector.setFileMode(QFileDialog.FileMode.ExistingFile)
|
|
|
|
self.playlist_file_selector.setNameFilters(["Playlists (*.wbz.m3u *.m3u)", "Any (*)"])
|
|
|
|
self.playlist_file_selector.setViewMode(QFileDialog.ViewMode.List)
|
|
|
|
|
2024-12-21 16:07:27 +01:00
|
|
|
self.connect()
|
|
|
|
|
2024-12-21 19:00:06 +01:00
|
|
|
self.window.show()
|
|
|
|
|
2025-01-25 15:14:20 +01:00
|
|
|
self.settings.update_all()
|
|
|
|
|
2024-12-21 16:07:27 +01:00
|
|
|
def connect(self):
|
2025-01-25 20:45:43 +01:00
|
|
|
self.window.closeEvent = self.on_exit
|
|
|
|
|
|
|
|
def on_exit(self, event):
|
|
|
|
self.app.library.on_exit(event)
|
|
|
|
|
|
|
|
self.app.settings.window_size = (self.window.width(), self.window.height())
|
|
|
|
self.app.settings.window_maximized = self.window.isMaximized()
|
|
|
|
|
|
|
|
self.app.settings.save(self.app.utils.settings_location)
|
2024-12-21 19:00:06 +01:00
|
|
|
|
2025-01-25 15:14:20 +01:00
|
|
|
def on_settings_change(self, key, value):
|
|
|
|
self.settings.update_settings(key, value)
|
|
|
|
|
2025-01-25 16:02:03 +01:00
|
|
|
def on_track_change(self, previous_track, track):
|
|
|
|
self.track_control.on_track_change(previous_track, track)
|
2025-02-04 14:43:08 +01:00
|
|
|
|
|
|
|
for dock_id in self.app.player.current_playlist.views:
|
|
|
|
view = self.app.player.current_playlist.views[dock_id]
|
|
|
|
view.on_track_change(previous_track, track)
|
2025-01-25 16:02:03 +01:00
|
|
|
|
2025-02-20 18:55:01 +01:00
|
|
|
def on_background_job_start(self, job_name: str, description: str, steps: int=0, getter: any=None):
|
|
|
|
self.process_dock.job_started_signal.emit(job_name, description, steps, getter)
|
2025-02-03 14:08:19 +01:00
|
|
|
|
2025-02-20 19:17:44 +01:00
|
|
|
def on_background_job_stop(self, job_name: str):
|
|
|
|
self.process_dock.job_finished_signal.emit(job_name)
|
2025-02-03 14:08:19 +01:00
|
|
|
|
2025-02-21 17:26:47 +01:00
|
|
|
def on_playstate_update(self):
|
|
|
|
self.track_control.on_playstate_update()
|
|
|
|
self.track_info.update_info()
|
|
|
|
|
2025-02-28 17:28:14 +01:00
|
|
|
def select_audio_files(self):
|
|
|
|
if self.audio_file_selector.exec():
|
|
|
|
return self.audio_file_selector.selectedFiles()
|
|
|
|
|
2025-02-28 18:02:37 +01:00
|
|
|
def select_playlist_file(self):
|
|
|
|
if self.playlist_file_selector.exec():
|
|
|
|
return self.playlist_file_selector.selectedFiles()[0]
|
|
|
|
|
2025-02-28 17:28:14 +01:00
|
|
|
def open_tracks(self):
|
|
|
|
files = self.select_audio_files()
|
|
|
|
|
|
|
|
if files is not None and not files == []:
|
|
|
|
self.app.library.open_tracks(files)
|
|
|
|
|
|
|
|
def import_tracks(self):
|
|
|
|
self.open_tracks() # placeholder
|
|
|
|
|
2025-02-28 18:02:37 +01:00
|
|
|
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)
|
|
|
|
|