Compare commits
3 Commits
7d71e8ce64
...
f1796451ae
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f1796451ae | ||
|
|
5ba70c9c6f | ||
|
|
568dc1ef68 |
@ -2,12 +2,9 @@
|
||||
|
||||
from log import log
|
||||
# import argparse
|
||||
# import psutil
|
||||
import sys
|
||||
# import threading
|
||||
# import webbrowser
|
||||
#
|
||||
#
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
# from typing import Callable, Dict, List, Optional, Tuple
|
||||
#
|
||||
@ -78,38 +75,41 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
self.previous_track: Optional[TrackData] = None
|
||||
self.previous_track_position: Optional[int] = None
|
||||
|
||||
# self.set_main_window_size()
|
||||
self.set_main_window_size()
|
||||
self.lblSumPlaytime = QLabel("")
|
||||
self.statusbar.addPermanentWidget(self.lblSumPlaytime)
|
||||
# self.txtSearch = QLineEdit()
|
||||
# self.statusbar.addWidget(self.txtSearch)
|
||||
# self.txtSearch.setHidden(True)
|
||||
self.hide_played_tracks = False
|
||||
#
|
||||
self.splitter.setSizes([200, 200])
|
||||
|
||||
self.visible_playlist_tab: Callable[[], PlaylistTab] = \
|
||||
self.tabPlaylist.currentWidget
|
||||
|
||||
self._load_last_playlists()
|
||||
self.enable_play_next_controls()
|
||||
# self.check_audacity()
|
||||
self.timer.start(Config.TIMER_MS)
|
||||
self.connect_signals_slots()
|
||||
#
|
||||
# def set_main_window_size(self) -> None:
|
||||
# """Set size of window from database"""
|
||||
#
|
||||
# with Session() as session:
|
||||
# record = Settings.get_int_settings(session, "mainwindow_x")
|
||||
# x = record.f_int or 1
|
||||
# record = Settings.get_int_settings(session, "mainwindow_y")
|
||||
# y = record.f_int or 1
|
||||
# record = Settings.get_int_settings(session, "mainwindow_width")
|
||||
# width = record.f_int or 1599
|
||||
# record = Settings.get_int_settings(session, "mainwindow_height")
|
||||
# height = record.f_int or 981
|
||||
# self.setGeometry(x, y, width, height)
|
||||
# return
|
||||
|
||||
def set_main_window_size(self) -> None:
|
||||
"""Set size of window from database"""
|
||||
|
||||
with Session() as session:
|
||||
record = Settings.get_int_settings(session, "mainwindow_x")
|
||||
x = record.f_int or 1
|
||||
record = Settings.get_int_settings(session, "mainwindow_y")
|
||||
y = record.f_int or 1
|
||||
record = Settings.get_int_settings(session, "mainwindow_width")
|
||||
width = record.f_int or 1599
|
||||
record = Settings.get_int_settings(session, "mainwindow_height")
|
||||
height = record.f_int or 981
|
||||
self.setGeometry(x, y, width, height)
|
||||
record = Settings.get_int_settings(session, "splitter_top")
|
||||
splitter_top = record.f_int or 256
|
||||
record = Settings.get_int_settings(session, "splitter_bottom")
|
||||
splitter_bottom = record.f_int or 256
|
||||
self.splitter.setSizes([splitter_top, splitter_bottom])
|
||||
return
|
||||
#
|
||||
# @staticmethod
|
||||
# def print_current_database():
|
||||
@ -117,18 +117,6 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
# db = session.bind.engine.url.database
|
||||
# print(f"{db=}")
|
||||
#
|
||||
# @staticmethod
|
||||
# def check_audacity() -> None:
|
||||
# """Offer to run Audacity if not running"""
|
||||
#
|
||||
# if not Config.CHECK_AUDACITY_AT_STARTUP:
|
||||
# return
|
||||
#
|
||||
# if "audacity" in [i.name() for i in psutil.process_iter()]:
|
||||
# return
|
||||
#
|
||||
# if helpers.ask_yes_no("Audacity not running", "Start Audacity?"):
|
||||
# QProcess.startDetached(Config.AUDACITY_COMMAND, [])
|
||||
|
||||
def clear_selection(self) -> None:
|
||||
""" Clear selected row"""
|
||||
@ -695,27 +683,6 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
|
||||
idx = self.tabPlaylist.indexOf(widget)
|
||||
self.tabPlaylist.tabBar().setTabTextColor(idx, colour)
|
||||
#
|
||||
# def song_info_search(self) -> None:
|
||||
# """
|
||||
# Open browser tab for Wikipedia, searching for
|
||||
# the first that exists of:
|
||||
# - selected track
|
||||
# - next track
|
||||
# - current track
|
||||
# """
|
||||
#
|
||||
# title: Optional[str] = self.visible_playlist_tab().get_selected_title()
|
||||
# if not title:
|
||||
# if self.next_track:
|
||||
# title = self.next_track.title
|
||||
# if not title:
|
||||
# if self.current_track:
|
||||
# title = self.current_track.title
|
||||
# if title:
|
||||
# txt = urllib.parse.quote_plus(title)
|
||||
# url = Config.TAB_URL % txt
|
||||
# webbrowser.open(url, new=2)
|
||||
|
||||
def stop(self) -> None:
|
||||
"""Stop playing immediately"""
|
||||
|
||||
@ -15,7 +15,7 @@ from PyQt5.QtGui import (
|
||||
)
|
||||
from PyQt5.QtWidgets import (
|
||||
QAbstractItemView,
|
||||
# QApplication,
|
||||
QApplication,
|
||||
# QInputDialog,
|
||||
# QLineEdit,
|
||||
QMainWindow,
|
||||
@ -266,6 +266,9 @@ class PlaylistTab(QTableWidget):
|
||||
act_info.triggered.connect(
|
||||
lambda: self._info_row(track_id)
|
||||
)
|
||||
act_copypath = self.menu.addAction("Copy track path")
|
||||
act_copypath.triggered.connect(
|
||||
lambda: self._copy_path(row_number))
|
||||
|
||||
self.menu.addSeparator()
|
||||
|
||||
@ -715,19 +718,16 @@ class PlaylistTab(QTableWidget):
|
||||
|
||||
def save_playlist(self, session: Session) -> None:
|
||||
"""
|
||||
Save playlist to database
|
||||
All playlist rows have a PlaylistRows id. Check that that id points
|
||||
to this playlist (in case track has been moved from other) and that
|
||||
the row number is correct (in case tracks have been reordered).
|
||||
"""
|
||||
|
||||
# Iteratate through playlist and check that the row in each
|
||||
# playlist_row object is correct
|
||||
for row in range(self.rowCount()):
|
||||
plr = session.get(PlaylistRows, self._get_playlistrow_id(row))
|
||||
# Set the row number (even if it's already correct)
|
||||
if plr.row_number != row:
|
||||
log.debug(
|
||||
f"Updating PlaylistRow: {plr.row_number=}, {row=}"
|
||||
)
|
||||
# Set the row number and playlist id (even if correct)
|
||||
plr.row_number = row
|
||||
plr.playlist_id = self.playlist_id
|
||||
|
||||
# Any rows in the database with a row_number higher that the
|
||||
# current value of 'row' should not be there. Commit session
|
||||
@ -1140,24 +1140,27 @@ class PlaylistTab(QTableWidget):
|
||||
|
||||
assert self.menu
|
||||
self.menu.exec_(self.mapToGlobal(pos))
|
||||
#
|
||||
# def _copy_path(self, row: int) -> None:
|
||||
# """
|
||||
# If passed row is track row, copy the track path to the clipboard.
|
||||
# Otherwise, return None.
|
||||
# """
|
||||
#
|
||||
# log.debug(f"_copy_path({row})")
|
||||
#
|
||||
# if row in self._get_notes_rows():
|
||||
# return None
|
||||
#
|
||||
# with Session() as session:
|
||||
# track: Optional[Tracks] = self._get_row_track_object(row, session)
|
||||
# if track:
|
||||
# cb = QApplication.clipboard()
|
||||
# cb.clear(mode=cb.Clipboard)
|
||||
# cb.setText(track.path, mode=cb.Clipboard)
|
||||
|
||||
def _copy_path(self, row: int) -> None:
|
||||
"""
|
||||
If passed row has a track, copy the track path, single-quoted,
|
||||
to the clipboard. Otherwise, return None.
|
||||
"""
|
||||
|
||||
track_id = self._get_row_track_id(row)
|
||||
if track_id is None:
|
||||
return
|
||||
|
||||
with Session() as session:
|
||||
track = session.get(Tracks, track_id)
|
||||
if track:
|
||||
# Escape single quotes and spaces in name
|
||||
path = track.path
|
||||
pathq = path.replace("'", "\\'")
|
||||
pathqs = pathq.replace(" ", "\\ ")
|
||||
cb = QApplication.clipboard()
|
||||
cb.clear(mode=cb.Clipboard)
|
||||
cb.setText(pathqs, mode=cb.Clipboard)
|
||||
#
|
||||
# def _cell_changed(self, row: int, column: int) -> None:
|
||||
# """Called when cell content has changed"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user