Skip to content

Commit

Permalink
Advanced filtering for database (still limited).
Browse files Browse the repository at this point in the history
A custom widget has been added for advanced filtering.
Right now it only supports format and sample rate. And it is
still buggy...
  • Loading branch information
MaurizioB committed Dec 14, 2017
1 parent 0e00d39 commit aa2e332
Show file tree
Hide file tree
Showing 6 changed files with 513 additions and 21 deletions.
19 changes: 7 additions & 12 deletions samplebrowsesrc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,19 +442,14 @@ def __init__(self):
self.player.started.connect(self.waveScene.showPlayhead)

self.filterStackedLayout = QtWidgets.QStackedLayout()
self.filterStackedLayout.sizeHint = lambda: QtCore.QSize(10, 10)
self.filterStackedLayout.minimumSize = lambda: QtCore.QSize(10, 10)
self.filterStackedWidget.setLayout(self.filterStackedLayout)
self.browsePathLbl = EllipsisLabel()
self.filterStackedLayout.addWidget(self.browsePathLbl)
self.filterWidget = QtWidgets.QWidget()
self.filterWidget.setContentsMargins(0, 0, 0, 0)
self.filterWidget = MainFilterWidget()
self.filterWidget.filtersChanged.connect(self.dbProxyModel.setFilterData)
self.filterStackedLayout.addWidget(self.filterWidget)
filterLayout = QtWidgets.QHBoxLayout()
filterLayout.setContentsMargins(0, 0, 0, 0)
self.filterWidget.setLayout(filterLayout)
filterLayout.addWidget(QtWidgets.QLabel('Search'))
self.searchEdit = QtWidgets.QLineEdit()
self.searchEdit.textChanged.connect(self.searchDb)
filterLayout.addWidget(self.searchEdit)

self.audioInfoTabWidget.tagsApplied.connect(self.tagsApplied)

Expand Down Expand Up @@ -966,9 +961,6 @@ def browseDb(self, query=None, force=True):
self.sampleView.horizontalHeader().setSectionResizeMode(c, QtWidgets.QHeaderView.Fixed)
self.sampleView.resizeRowsToContents()

def searchDb(self, text):
self.dbProxyModel.setFilterRegExp(text)

def editTags(self, index):
if self.sampleView.model() != self.dbProxyModel or index.column() != tagsColumn:
return
Expand Down Expand Up @@ -1187,7 +1179,10 @@ def importSamplesWithTags(self, sampleList, tagIndex):

def toggleBrowser(self, index):
self.browserStackedLayout.setCurrentIndex(index)
self.filterStackedLayout.minimumSize = self.filterStackedLayout.itemAt(index).widget().minimumSizeHint
self.filterStackedLayout.setCurrentIndex(index)


if index == 0:
self.sampleView.setModel(self.browseModel)
self.browse()
Expand Down
49 changes: 48 additions & 1 deletion samplebrowsesrc/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,56 @@ def updateTags(self, index, _):


class SampleSortFilterProxyModel(QtCore.QSortFilterProxyModel):
def __init__(self, *args, **kwargs):
QtCore.QSortFilterProxyModel.__init__(self, *args, **kwargs)
self.currentFilterData = {}
self.currentTextFilter = ''

def itemFromIndex(self, index):
return self.sourceModel().itemFromIndex(self.mapToSource(index))

# self.dbProxyModel.setFilterRegExp(text)

def setFilterData(self, filterDataList):
self.currentFilterData = {}
for filterColumn, filterData in filterDataList:
if filterColumn == fileNameColumn:
self.currentTextFilter = filterData
continue
self.currentFilterData[filterColumn] = filterData
self.invalidateFilter()
print(self.currentFilterData)

def filterAcceptsRow(self, row, parent):
if not self.currentFilterData:
if not self.currentTextFilter:
return True
if self.currentTextFilter.lower() in self.sourceModel().item(row, fileNameColumn).text().lower():
return True
else:
for filterColumn, filterData in self.currentFilterData.items():
if isinstance(filterData, list):
for item in filterData:
if self.sourceModel().item(row, filterColumn).text().lower() == item.lower():
break
else:
return False
else:
value = float(self.sourceModel().item(row, filterColumn).text())
if filterData.greater:
greater, greaterEqual = filterData.greater
greater = float(greater)
if (greater > value) or (not greaterEqual and greater >= value):
return False
if filterData.less:
less, lessEqual = filterData.less
less = float(less)
if (less < value) or (not lessEqual and less <= value):
return False
if not self.currentTextFilter or self.currentTextFilter.lower() in self.sourceModel().item(row, fileNameColumn).text().lower():
return True
return False

# return QtCore.QSortFilterProxyModel.filterAcceptsRow(self, row, parent)

class MultiDirIterator(object):
def __init__(self, dirList, *args, **kwargs):
Expand Down
5 changes: 5 additions & 0 deletions samplebrowsesrc/constants.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from PyQt5 import QtCore
from collections import namedtuple
import soundfile

rangeData = namedtuple('rangeData', 'greater less')

availableFormats = tuple(f.lower() for f in soundfile.available_formats().keys())
availableExtensions = tuple('*.' + f for f in availableFormats)

sampleRatesList = (192000, 176400, 96000, 88200, 48000, 44100, 32000, 22050, 16000, 8000)

subtypesDict = {
'FLOAT': '32f',
'DOUBLE': '64f',
Expand Down
19 changes: 11 additions & 8 deletions samplebrowsesrc/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@
</property>
<widget class="QWidget" name="verticalLayoutWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="bottomMargin">
<number>6</number>
</property>
<item>
<widget class="SampleView" name="sampleView">
<property name="contextMenuPolicy">
Expand Down Expand Up @@ -261,12 +264,12 @@
<slot>setValue(int)</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>51</y>
<x>383</x>
<y>58</y>
</hint>
<hint type="destinationlabel">
<x>339</x>
<y>53</y>
<x>444</x>
<y>63</y>
</hint>
</hints>
</connection>
Expand All @@ -277,12 +280,12 @@
<slot>setValue(int)</slot>
<hints>
<hint type="sourcelabel">
<x>324</x>
<y>38</y>
<x>444</x>
<y>63</y>
</hint>
<hint type="destinationlabel">
<x>220</x>
<y>44</y>
<x>383</x>
<y>58</y>
</hint>
</hints>
</connection>
Expand Down
1 change: 1 addition & 0 deletions samplebrowsesrc/widgets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from samplebrowsesrc.widgets.sampleview import *
from samplebrowsesrc.widgets.searchfilter import *
from samplebrowsesrc.widgets.advsplitter import *
from samplebrowsesrc.widgets.tagseditor import *
from samplebrowsesrc.widgets.delegates import *
Expand Down
Loading

0 comments on commit aa2e332

Please sign in to comment.