simple preferences window + table columns stretch with resize
This commit is contained in:
parent
20636cd081
commit
dd558bd498
2
DBA.py
2
DBA.py
@ -6,7 +6,7 @@ class DBAccess:
|
||||
config = ConfigParser()
|
||||
config.read('config.ini')
|
||||
if db_name is None:
|
||||
db_name = config.get('db', 'library')
|
||||
db_name = config.get('db', 'database')
|
||||
self._conn = sqlite3.connect(db_name)
|
||||
self._cursor = self._conn.cursor()
|
||||
|
||||
|
||||
47
components/PreferencesWindow.py
Normal file
47
components/PreferencesWindow.py
Normal file
@ -0,0 +1,47 @@
|
||||
from PyQt5.QtWidgets import QDialog, QVBoxLayout, QLabel, QLineEdit, QPushButton
|
||||
from PyQt5.QtGui import QFont
|
||||
import configparser
|
||||
|
||||
class PreferencesWindow(QDialog):
|
||||
def __init__(self, config):
|
||||
super(PreferencesWindow, self).__init__()
|
||||
self.setWindowTitle('Preferences')
|
||||
self.config = config
|
||||
layout = QVBoxLayout()
|
||||
|
||||
label = QLabel('Preferences Window')
|
||||
layout.addWidget(label)
|
||||
|
||||
# Labels & input fields
|
||||
self.input_fields = {}
|
||||
for category in self.config.sections():
|
||||
category_label = QLabel(f'{category}')
|
||||
category_label.setFont(QFont('', weight=QFont.Bold)) # bold category
|
||||
category_label.setStyleSheet("text-transform:uppercase;") # uppercase category
|
||||
layout.addWidget(category_label)
|
||||
for key in self.config[category]:
|
||||
label = QLabel(key)
|
||||
input_field = QLineEdit(self.config[category][key])
|
||||
layout.addWidget(label)
|
||||
layout.addWidget(input_field)
|
||||
self.input_fields[key] = input_field
|
||||
|
||||
# Save button
|
||||
save_button = QPushButton('Save')
|
||||
save_button.clicked.connect(self.save_preferences)
|
||||
layout.addWidget(save_button)
|
||||
self.setLayout(layout)
|
||||
|
||||
def save_preferences(self):
|
||||
# Upcate the config fields
|
||||
for key in self.input_fields:
|
||||
for category in self.config.sections():
|
||||
if key in self.config[category]:
|
||||
self.config[category][key] = self.input_fields[key].text()
|
||||
|
||||
# Write the config file
|
||||
with open('config.ini', 'w') as configfile:
|
||||
self.config.write(configfile)
|
||||
|
||||
self.close()
|
||||
|
||||
@ -1,2 +1,3 @@
|
||||
from .MusicTable import MusicTable
|
||||
from .AudioVisualizer import AudioVisualizer
|
||||
from .PreferencesWindow import PreferencesWindow
|
||||
|
||||
13
main.py
13
main.py
@ -1,6 +1,6 @@
|
||||
import DBA
|
||||
from ui import Ui_MainWindow
|
||||
from PyQt5.QtWidgets import QMainWindow, QApplication, QGraphicsScene
|
||||
from PyQt5.QtWidgets import QMainWindow, QApplication, QGraphicsScene, QHeaderView
|
||||
import qdarktheme
|
||||
from PyQt5.QtCore import QUrl, QTimer, QEvent, Qt, QRect
|
||||
from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent, QAudioProbe
|
||||
@ -8,6 +8,7 @@ from PyQt5.QtGui import QPixmap
|
||||
from utils import scan_for_music
|
||||
from utils import initialize_library_database
|
||||
from components import AudioVisualizer
|
||||
from components import PreferencesWindow
|
||||
from pyqtgraph import mkBrush
|
||||
import configparser
|
||||
|
||||
@ -78,10 +79,14 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
self.tableView.doubleClicked.connect(self.play_audio_file) # Double click to play song
|
||||
self.tableView.viewport().installEventFilter(self) # for drag & drop functionality
|
||||
# self.tableView.model.layoutChanged()
|
||||
### set column widths
|
||||
### set column widths
|
||||
table_view_column_widths = str(self.config['table']['column_widths']).split(',')
|
||||
for i in range(self.tableView.model.columnCount()):
|
||||
self.tableView.setColumnWidth(i, int(table_view_column_widths[i]))
|
||||
# dont extend last column past table view border
|
||||
self.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
||||
self.tableView.horizontalHeader().setStretchLastSection(False)
|
||||
|
||||
|
||||
def eventFilter(self, source, event):
|
||||
"""Handles events"""
|
||||
@ -212,8 +217,8 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
print('next')
|
||||
|
||||
def actionPreferencesClicked(self):
|
||||
print('preferences')
|
||||
|
||||
preferences_window = PreferencesWindow(self.config)
|
||||
preferences_window.exec_() # Display the preferences window modally
|
||||
def scan_libraries(self):
|
||||
scan_for_music()
|
||||
self.tableView.fetch_library()
|
||||
|
||||
8
ui.py
8
ui.py
@ -23,13 +23,15 @@ class Ui_MainWindow(object):
|
||||
self.hLayoutHead = QtWidgets.QHBoxLayout()
|
||||
self.hLayoutHead.setObjectName("hLayoutHead")
|
||||
self.vlayoutAlbumArt = QtWidgets.QVBoxLayout()
|
||||
self.vlayoutAlbumArt.setSizeConstraint(QtWidgets.QLayout.SetFixedSize)
|
||||
self.vlayoutAlbumArt.setObjectName("vlayoutAlbumArt")
|
||||
self.albumGraphicsView = QtWidgets.QGraphicsView(self.centralwidget)
|
||||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)
|
||||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
sizePolicy.setVerticalStretch(0)
|
||||
sizePolicy.setHeightForWidth(self.albumGraphicsView.sizePolicy().hasHeightForWidth())
|
||||
self.albumGraphicsView.setSizePolicy(sizePolicy)
|
||||
self.albumGraphicsView.setMinimumSize(QtCore.QSize(200, 200))
|
||||
self.albumGraphicsView.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
||||
self.albumGraphicsView.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
||||
self.albumGraphicsView.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustIgnored)
|
||||
@ -86,7 +88,7 @@ class Ui_MainWindow(object):
|
||||
self.PlotWidget.setObjectName("PlotWidget")
|
||||
self.vLayoutPlaybackVisuals.addWidget(self.PlotWidget)
|
||||
self.hLayoutHead.addLayout(self.vLayoutPlaybackVisuals)
|
||||
self.hLayoutHead.setStretch(0, 2)
|
||||
self.hLayoutHead.setStretch(0, 1)
|
||||
self.hLayoutHead.setStretch(1, 4)
|
||||
self.hLayoutHead.setStretch(2, 6)
|
||||
self.verticalLayout_3.addLayout(self.hLayoutHead)
|
||||
@ -94,7 +96,7 @@ class Ui_MainWindow(object):
|
||||
self.hLayoutMusicTable.setObjectName("hLayoutMusicTable")
|
||||
self.tableView = MusicTable(self.centralwidget)
|
||||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)
|
||||
sizePolicy.setHorizontalStretch(1)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
sizePolicy.setVerticalStretch(1)
|
||||
sizePolicy.setHeightForWidth(self.tableView.sizePolicy().hasHeightForWidth())
|
||||
self.tableView.setSizePolicy(sizePolicy)
|
||||
|
||||
15
ui.ui
15
ui.ui
@ -19,17 +19,26 @@
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="3,8,1,1">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="hLayoutHead" stretch="2,4,6">
|
||||
<layout class="QHBoxLayout" name="hLayoutHead" stretch="1,4,6">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="vlayoutAlbumArt">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetFixedSize</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QGraphicsView" name="albumGraphicsView">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>200</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
@ -141,7 +150,7 @@
|
||||
<widget class="MusicTable" name="tableView">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>1</horstretch>
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>1</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user