Store window size and location
This commit is contained in:
parent
a6de739c74
commit
8abf4caf4a
@ -3,19 +3,19 @@
|
|||||||
import vlc
|
import vlc
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from log import INFO, ERROR, DEBUG
|
from log import DEBUG
|
||||||
|
# from log import INFO, ERROR, DEBUG
|
||||||
|
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt
|
||||||
from PyQt5.QtWidgets import QApplication, QDialog, QMainWindow
|
from PyQt5.QtWidgets import QApplication, QDialog, QMainWindow
|
||||||
from PyQt5.QtWidgets import QTableWidgetItem, QFileDialog, QListWidgetItem
|
from PyQt5.QtWidgets import QTableWidgetItem, QFileDialog, QListWidgetItem
|
||||||
from threading import Timer
|
from threading import Timer
|
||||||
from tinytag import TinyTag
|
|
||||||
|
|
||||||
from ui.main_window_ui import Ui_MainWindow
|
from ui.main_window_ui import Ui_MainWindow
|
||||||
from ui.dlg_search_database_ui import Ui_Dialog
|
from ui.dlg_search_database_ui import Ui_Dialog
|
||||||
|
|
||||||
from config import Config
|
from config import Config
|
||||||
from model import Tracks
|
from model import Settings, Tracks
|
||||||
|
|
||||||
|
|
||||||
class RepeatedTimer:
|
class RepeatedTimer:
|
||||||
@ -44,48 +44,57 @@ class RepeatedTimer:
|
|||||||
self.is_running = False
|
self.is_running = False
|
||||||
|
|
||||||
|
|
||||||
def ms_to_mmss(ms, decimals=0):
|
|
||||||
if not ms:
|
|
||||||
return "-"
|
|
||||||
if ms < 0:
|
|
||||||
sign = "-"
|
|
||||||
else:
|
|
||||||
sign = ""
|
|
||||||
|
|
||||||
minutes, remainder = divmod(ms, 60 * 1000)
|
|
||||||
seconds = remainder / 1000
|
|
||||||
|
|
||||||
return f"{sign}{minutes:.0f}:{seconds:02.{decimals}f}"
|
|
||||||
|
|
||||||
|
|
||||||
class Window(QMainWindow, Ui_MainWindow):
|
class Window(QMainWindow, Ui_MainWindow):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
self.connectSignalsSlots()
|
self.connectSignalsSlots()
|
||||||
|
|
||||||
self.resize(1599, 981)
|
record = Settings.get_int("mainwindow_x")
|
||||||
|
x = record.f_int or 1
|
||||||
|
record = Settings.get_int("mainwindow_y")
|
||||||
|
y = record.f_int or 1
|
||||||
|
record = Settings.get_int("mainwindow_width")
|
||||||
|
width = record.f_int or 1599
|
||||||
|
record = Settings.get_int("mainwindow_height")
|
||||||
|
height = record.f_int or 981
|
||||||
|
self.setGeometry(x, y, width, height)
|
||||||
|
|
||||||
self.playlist.setColumnWidth(0, 0)
|
for column in range(self.playlist.columnCount()):
|
||||||
self.playlist.setColumnWidth(1, 70)
|
name = f"playlist_col_{str(column)}_width"
|
||||||
self.playlist.setColumnWidth(2, 381)
|
record = Settings.get_int(name)
|
||||||
self.playlist.setColumnWidth(3, 322)
|
if record.f_int is not None:
|
||||||
self.playlist.setColumnWidth(4, 78)
|
self.playlist.setColumnWidth(column, record.f_int)
|
||||||
self.playlist.setColumnWidth(5, 68)
|
|
||||||
self.playlist.setColumnWidth(6, 47)
|
|
||||||
self.playlist.setColumnWidth(7, 577)
|
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
for column in range(self.playlist.columnCount()):
|
for column in range(self.playlist.columnCount()):
|
||||||
print(f"Column {column}: {self.playlist.columnWidth(column)}")
|
name = f"playlist_col_{str(column)}_width"
|
||||||
print(f"Window height: {self.height()} Window width: {self.width()}")
|
record = Settings.get_int(name)
|
||||||
|
if record.f_int != self.playlist.columnWidth(column):
|
||||||
|
record.update({'f_int': self.playlist.columnWidth(column)})
|
||||||
|
|
||||||
|
record = Settings.get_int("mainwindow_height")
|
||||||
|
if record.f_int != self.height():
|
||||||
|
record.update({'f_int': self.height()})
|
||||||
|
|
||||||
|
record = Settings.get_int("mainwindow_width")
|
||||||
|
if record.f_int != self.width():
|
||||||
|
record.update({'f_int': self.width()})
|
||||||
|
|
||||||
|
record = Settings.get_int("mainwindow_x")
|
||||||
|
if record.f_int != self.x():
|
||||||
|
record.update({'f_int': self.x()})
|
||||||
|
|
||||||
|
record = Settings.get_int("mainwindow_y")
|
||||||
|
if record.f_int != self.y():
|
||||||
|
record.update({'f_int': self.y()})
|
||||||
|
|
||||||
def connectSignalsSlots(self):
|
def connectSignalsSlots(self):
|
||||||
self.fileButton.clicked.connect(self.selectFile)
|
self.fileButton.clicked.connect(self.selectFile)
|
||||||
self.databaseButton.clicked.connect(self.selectDatabase)
|
self.databaseButton.clicked.connect(self.selectFromDatabase)
|
||||||
self.actionPlay_selected.triggered.connect(self.play_selected)
|
self.actionPlay_selected.triggered.connect(self.play_selected)
|
||||||
|
|
||||||
def selectDatabase(self):
|
def selectFromDatabase(self):
|
||||||
dlg = DbDialog(self)
|
dlg = DbDialog(self)
|
||||||
dlg.exec()
|
dlg.exec()
|
||||||
|
|
||||||
@ -93,10 +102,11 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
if self.playlist.selectionModel().hasSelection():
|
if self.playlist.selectionModel().hasSelection():
|
||||||
row = self.playlist.currentRow()
|
row = self.playlist.currentRow()
|
||||||
track_id = int(self.playlist.item(row, 0).text())
|
track_id = int(self.playlist.item(row, 0).text())
|
||||||
|
DEBUG(f"play_selected: track_id={track_id}")
|
||||||
# TODO: get_path may raise exception
|
# TODO: get_path may raise exception
|
||||||
track_path = Tracks.get_path(track_id)
|
track_path = Tracks.get_path(track_id)
|
||||||
if track_path:
|
if track_path:
|
||||||
INFO(f"play: {track_path}")
|
DEBUG(f"play_selected: track_path={track_path}")
|
||||||
player = vlc.MediaPlayer(track_path)
|
player = vlc.MediaPlayer(track_path)
|
||||||
player.play()
|
player.play()
|
||||||
|
|
||||||
@ -121,6 +131,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
track is an instance of Track
|
track is an instance of Track
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
DEBUG(f"add_to_playlist: track.id={track.id}")
|
||||||
pl = self.playlist
|
pl = self.playlist
|
||||||
row = pl.rowCount()
|
row = pl.rowCount()
|
||||||
pl.insertRow(row)
|
pl.insertRow(row)
|
||||||
@ -143,13 +154,28 @@ class DbDialog(QDialog):
|
|||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.ui = Ui_Dialog()
|
self.ui = Ui_Dialog()
|
||||||
self.ui.setupUi(self)
|
self.ui.setupUi(self)
|
||||||
self.ui.lineEdit.textEdited.connect(self.chars_typed)
|
self.ui.searchString.textEdited.connect(self.chars_typed)
|
||||||
self.ui.listWidget.itemDoubleClicked.connect(self.listdclick)
|
self.ui.matchList.itemDoubleClicked.connect(self.listdclick)
|
||||||
|
|
||||||
|
record = Settings.get_int("dbdialog_width")
|
||||||
|
width = record.f_int or 800
|
||||||
|
record = Settings.get_int("dbdialog_height")
|
||||||
|
height = record.f_int or 600
|
||||||
|
self.resize(width, height)
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
record = Settings.get_int("dbdialog_height")
|
||||||
|
if record.f_int != self.height():
|
||||||
|
record.update({'f_int': self.height()})
|
||||||
|
|
||||||
|
record = Settings.get_int("dbdialog_width")
|
||||||
|
if record.f_int != self.width():
|
||||||
|
record.update({'f_int': self.width()})
|
||||||
|
|
||||||
def chars_typed(self, s):
|
def chars_typed(self, s):
|
||||||
if len(s) >= 3:
|
if len(s) >= 3:
|
||||||
matches = Tracks.search_titles(s)
|
matches = Tracks.search_titles(s)
|
||||||
self.ui.listWidget.clear()
|
self.ui.matchList.clear()
|
||||||
if matches:
|
if matches:
|
||||||
for track in matches:
|
for track in matches:
|
||||||
t = QListWidgetItem()
|
t = QListWidgetItem()
|
||||||
@ -158,7 +184,7 @@ class DbDialog(QDialog):
|
|||||||
f"[{ms_to_mmss(track.duration)}]"
|
f"[{ms_to_mmss(track.duration)}]"
|
||||||
)
|
)
|
||||||
t.setData(Qt.UserRole, track.id)
|
t.setData(Qt.UserRole, track.id)
|
||||||
self.ui.listWidget.addItem(t)
|
self.ui.matchList.addItem(t)
|
||||||
|
|
||||||
def listdclick(self, entry):
|
def listdclick(self, entry):
|
||||||
track_id = entry.data(Qt.UserRole)
|
track_id = entry.data(Qt.UserRole)
|
||||||
@ -166,6 +192,20 @@ class DbDialog(QDialog):
|
|||||||
self.parent().add_to_playlist(track)
|
self.parent().add_to_playlist(track)
|
||||||
|
|
||||||
|
|
||||||
|
def ms_to_mmss(ms, decimals=0):
|
||||||
|
if not ms:
|
||||||
|
return "-"
|
||||||
|
if ms < 0:
|
||||||
|
sign = "-"
|
||||||
|
else:
|
||||||
|
sign = ""
|
||||||
|
|
||||||
|
minutes, remainder = divmod(ms, 60 * 1000)
|
||||||
|
seconds = remainder / 1000
|
||||||
|
|
||||||
|
return f"{sign}{minutes:.0f}:{seconds:02.{decimals}f}"
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
win = Window()
|
win = Window()
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>383</width>
|
<width>383</width>
|
||||||
<height>272</height>
|
<height>270</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -26,12 +26,12 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QLineEdit" name="lineEdit"/>
|
<widget class="QLineEdit" name="searchString"/>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QListWidget" name="listWidget"/>
|
<widget class="QListWidget" name="matchList"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
|||||||
@ -34,6 +34,8 @@ Playlist management
|
|||||||
Clear selection
|
Clear selection
|
||||||
Track volume analysis
|
Track volume analysis
|
||||||
Open track in Audacity
|
Open track in Audacity
|
||||||
|
Wikipedia for song title
|
||||||
|
Song facts for song title
|
||||||
Display
|
Display
|
||||||
Remember window size
|
Remember window size
|
||||||
Remember dialog size
|
Remember dialog size
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user