parent
15ec91e446
commit
0caf48919c
@ -574,6 +574,14 @@ class Tracks(Base):
|
||||
|
||||
return q.all()
|
||||
|
||||
@staticmethod
|
||||
def search_artists(session, text):
|
||||
return (
|
||||
session.query(Tracks)
|
||||
.filter(Tracks.artist.ilike(f"%{text}%"))
|
||||
.order_by(Tracks.title)
|
||||
).all()
|
||||
|
||||
@staticmethod
|
||||
def search_titles(session, text):
|
||||
return (
|
||||
|
||||
@ -744,12 +744,13 @@ class DbDialog(QDialog):
|
||||
self.session = session
|
||||
self.ui = Ui_Dialog()
|
||||
self.ui.setupUi(self)
|
||||
self.ui.searchString.textEdited.connect(self.chars_typed)
|
||||
self.ui.matchList.itemDoubleClicked.connect(self.double_click)
|
||||
self.ui.btnAdd.clicked.connect(self.add_selected)
|
||||
self.ui.btnAddClose.clicked.connect(self.add_selected_and_close)
|
||||
self.ui.btnClose.clicked.connect(self.close)
|
||||
self.ui.matchList.itemDoubleClicked.connect(self.double_click)
|
||||
self.ui.matchList.itemSelectionChanged.connect(self.selection_changed)
|
||||
self.ui.radioTitle.toggled.connect(self.radio_toggle)
|
||||
self.ui.searchString.textEdited.connect(self.chars_typed)
|
||||
|
||||
record = Settings.get_int(self.session, "dbdialog_width")
|
||||
width = record.f_int or 800
|
||||
@ -778,9 +779,21 @@ class DbDialog(QDialog):
|
||||
self.add_selected()
|
||||
self.close()
|
||||
|
||||
def radio_toggle(self):
|
||||
"""
|
||||
Handle switching between searching for artists and searching for
|
||||
titles
|
||||
"""
|
||||
|
||||
# Logic is handled already in chars_typed(), so just call that.
|
||||
self.chars_typed(self.ui.searchString.text())
|
||||
|
||||
def chars_typed(self, s):
|
||||
if len(s) > 0:
|
||||
matches = Tracks.search_titles(self.session, s)
|
||||
if self.ui.radioTitle.isChecked():
|
||||
matches = Tracks.search_titles(self.session, s)
|
||||
else:
|
||||
matches = Tracks.search_artists(self.session, s)
|
||||
self.ui.matchList.clear()
|
||||
if matches:
|
||||
for track in matches:
|
||||
|
||||
@ -6,15 +6,15 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>383</width>
|
||||
<height>270</height>
|
||||
<width>584</width>
|
||||
<height>377</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
@ -28,26 +28,36 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QListWidget" name="matchList"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="dbPath">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<item row="2" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<widget class="QRadioButton" name="radioTitle">
|
||||
<property name="text">
|
||||
<string>&Title</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioArtist">
|
||||
<property name="text">
|
||||
<string>&Artist</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>88</width>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
@ -79,6 +89,13 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="dbPath">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Form implementation generated from reading ui file 'app/ui/dlg_SearchDatabase.ui'
|
||||
# Form implementation generated from reading ui file 'ui/dlg_SearchDatabase.ui'
|
||||
#
|
||||
# Created by: PyQt5 UI code generator 5.15.4
|
||||
#
|
||||
@ -14,9 +14,9 @@ from PyQt5 import QtCore, QtGui, QtWidgets
|
||||
class Ui_Dialog(object):
|
||||
def setupUi(self, Dialog):
|
||||
Dialog.setObjectName("Dialog")
|
||||
Dialog.resize(383, 270)
|
||||
self.verticalLayout = QtWidgets.QVBoxLayout(Dialog)
|
||||
self.verticalLayout.setObjectName("verticalLayout")
|
||||
Dialog.resize(584, 377)
|
||||
self.gridLayout_2 = QtWidgets.QGridLayout(Dialog)
|
||||
self.gridLayout_2.setObjectName("gridLayout_2")
|
||||
self.gridLayout = QtWidgets.QGridLayout()
|
||||
self.gridLayout.setObjectName("gridLayout")
|
||||
self.label = QtWidgets.QLabel(Dialog)
|
||||
@ -25,17 +25,20 @@ class Ui_Dialog(object):
|
||||
self.searchString = QtWidgets.QLineEdit(Dialog)
|
||||
self.searchString.setObjectName("searchString")
|
||||
self.gridLayout.addWidget(self.searchString, 0, 1, 1, 1)
|
||||
self.verticalLayout.addLayout(self.gridLayout)
|
||||
self.gridLayout_2.addLayout(self.gridLayout, 0, 0, 1, 1)
|
||||
self.matchList = QtWidgets.QListWidget(Dialog)
|
||||
self.matchList.setObjectName("matchList")
|
||||
self.verticalLayout.addWidget(self.matchList)
|
||||
self.dbPath = QtWidgets.QLabel(Dialog)
|
||||
self.dbPath.setText("")
|
||||
self.dbPath.setObjectName("dbPath")
|
||||
self.verticalLayout.addWidget(self.dbPath)
|
||||
self.gridLayout_2.addWidget(self.matchList, 1, 0, 1, 1)
|
||||
self.horizontalLayout = QtWidgets.QHBoxLayout()
|
||||
self.horizontalLayout.setObjectName("horizontalLayout")
|
||||
spacerItem = QtWidgets.QSpacerItem(88, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
|
||||
self.radioTitle = QtWidgets.QRadioButton(Dialog)
|
||||
self.radioTitle.setChecked(True)
|
||||
self.radioTitle.setObjectName("radioTitle")
|
||||
self.horizontalLayout.addWidget(self.radioTitle)
|
||||
self.radioArtist = QtWidgets.QRadioButton(Dialog)
|
||||
self.radioArtist.setObjectName("radioArtist")
|
||||
self.horizontalLayout.addWidget(self.radioArtist)
|
||||
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
|
||||
self.horizontalLayout.addItem(spacerItem)
|
||||
self.btnAdd = QtWidgets.QPushButton(Dialog)
|
||||
self.btnAdd.setDefault(True)
|
||||
@ -47,7 +50,11 @@ class Ui_Dialog(object):
|
||||
self.btnClose = QtWidgets.QPushButton(Dialog)
|
||||
self.btnClose.setObjectName("btnClose")
|
||||
self.horizontalLayout.addWidget(self.btnClose)
|
||||
self.verticalLayout.addLayout(self.horizontalLayout)
|
||||
self.gridLayout_2.addLayout(self.horizontalLayout, 2, 0, 1, 1)
|
||||
self.dbPath = QtWidgets.QLabel(Dialog)
|
||||
self.dbPath.setText("")
|
||||
self.dbPath.setObjectName("dbPath")
|
||||
self.gridLayout_2.addWidget(self.dbPath, 3, 0, 1, 1)
|
||||
|
||||
self.retranslateUi(Dialog)
|
||||
QtCore.QMetaObject.connectSlotsByName(Dialog)
|
||||
@ -56,6 +63,8 @@ class Ui_Dialog(object):
|
||||
_translate = QtCore.QCoreApplication.translate
|
||||
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
|
||||
self.label.setText(_translate("Dialog", "Title:"))
|
||||
self.radioTitle.setText(_translate("Dialog", "&Title"))
|
||||
self.radioArtist.setText(_translate("Dialog", "&Artist"))
|
||||
self.btnAdd.setText(_translate("Dialog", "&Add"))
|
||||
self.btnAddClose.setText(_translate("Dialog", "A&dd and close"))
|
||||
self.btnClose.setText(_translate("Dialog", "&Close"))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user