Store window size and location
This commit is contained in:
parent
a6de739c74
commit
8abf4caf4a
@ -3,19 +3,19 @@
|
||||
import vlc
|
||||
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.QtWidgets import QApplication, QDialog, QMainWindow
|
||||
from PyQt5.QtWidgets import QTableWidgetItem, QFileDialog, QListWidgetItem
|
||||
from threading import Timer
|
||||
from tinytag import TinyTag
|
||||
|
||||
from ui.main_window_ui import Ui_MainWindow
|
||||
from ui.dlg_search_database_ui import Ui_Dialog
|
||||
|
||||
from config import Config
|
||||
from model import Tracks
|
||||
from model import Settings, Tracks
|
||||
|
||||
|
||||
class RepeatedTimer:
|
||||
@ -44,48 +44,57 @@ class RepeatedTimer:
|
||||
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):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setupUi(self)
|
||||
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)
|
||||
self.playlist.setColumnWidth(1, 70)
|
||||
self.playlist.setColumnWidth(2, 381)
|
||||
self.playlist.setColumnWidth(3, 322)
|
||||
self.playlist.setColumnWidth(4, 78)
|
||||
self.playlist.setColumnWidth(5, 68)
|
||||
self.playlist.setColumnWidth(6, 47)
|
||||
self.playlist.setColumnWidth(7, 577)
|
||||
for column in range(self.playlist.columnCount()):
|
||||
name = f"playlist_col_{str(column)}_width"
|
||||
record = Settings.get_int(name)
|
||||
if record.f_int is not None:
|
||||
self.playlist.setColumnWidth(column, record.f_int)
|
||||
|
||||
def __del__(self):
|
||||
for column in range(self.playlist.columnCount()):
|
||||
print(f"Column {column}: {self.playlist.columnWidth(column)}")
|
||||
print(f"Window height: {self.height()} Window width: {self.width()}")
|
||||
name = f"playlist_col_{str(column)}_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):
|
||||
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)
|
||||
|
||||
def selectDatabase(self):
|
||||
def selectFromDatabase(self):
|
||||
dlg = DbDialog(self)
|
||||
dlg.exec()
|
||||
|
||||
@ -93,10 +102,11 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
if self.playlist.selectionModel().hasSelection():
|
||||
row = self.playlist.currentRow()
|
||||
track_id = int(self.playlist.item(row, 0).text())
|
||||
DEBUG(f"play_selected: track_id={track_id}")
|
||||
# TODO: get_path may raise exception
|
||||
track_path = Tracks.get_path(track_id)
|
||||
if track_path:
|
||||
INFO(f"play: {track_path}")
|
||||
DEBUG(f"play_selected: track_path={track_path}")
|
||||
player = vlc.MediaPlayer(track_path)
|
||||
player.play()
|
||||
|
||||
@ -121,6 +131,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
track is an instance of Track
|
||||
"""
|
||||
|
||||
DEBUG(f"add_to_playlist: track.id={track.id}")
|
||||
pl = self.playlist
|
||||
row = pl.rowCount()
|
||||
pl.insertRow(row)
|
||||
@ -143,13 +154,28 @@ class DbDialog(QDialog):
|
||||
super().__init__(parent)
|
||||
self.ui = Ui_Dialog()
|
||||
self.ui.setupUi(self)
|
||||
self.ui.lineEdit.textEdited.connect(self.chars_typed)
|
||||
self.ui.listWidget.itemDoubleClicked.connect(self.listdclick)
|
||||
self.ui.searchString.textEdited.connect(self.chars_typed)
|
||||
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):
|
||||
if len(s) >= 3:
|
||||
matches = Tracks.search_titles(s)
|
||||
self.ui.listWidget.clear()
|
||||
self.ui.matchList.clear()
|
||||
if matches:
|
||||
for track in matches:
|
||||
t = QListWidgetItem()
|
||||
@ -158,7 +184,7 @@ class DbDialog(QDialog):
|
||||
f"[{ms_to_mmss(track.duration)}]"
|
||||
)
|
||||
t.setData(Qt.UserRole, track.id)
|
||||
self.ui.listWidget.addItem(t)
|
||||
self.ui.matchList.addItem(t)
|
||||
|
||||
def listdclick(self, entry):
|
||||
track_id = entry.data(Qt.UserRole)
|
||||
@ -166,6 +192,20 @@ class DbDialog(QDialog):
|
||||
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():
|
||||
app = QApplication(sys.argv)
|
||||
win = Window()
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>383</width>
|
||||
<height>272</height>
|
||||
<height>270</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -26,12 +26,12 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
<widget class="QLineEdit" name="searchString"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="listWidget"/>
|
||||
<widget class="QListWidget" name="matchList"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user