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