Browse Source

Add track title and filter option to track list widget

master
Nils 2 years ago
parent
commit
8a045e4201
  1. 1
      engine/api.py
  2. 2
      engine/items.py
  3. 2
      qtgui/mainwindow.py
  4. 71
      qtgui/tracklistwidget.py

1
engine/api.py

@ -706,6 +706,7 @@ def setTrackName(trId, nameString, initialInstrumentName, initialShortInstrument
trackObject.initialInstrumentName = initialInstrumentName
trackObject.initialShortInstrumentName = initialShortInstrumentName
callbacks._tracksChanged()
callbacks._setCursor() #cursor contains track name and thus needs updating
def setTrackUpbeat(trId, upbeatInTicks):
trackObject = session.data.trackById(trId)

2
engine/items.py

@ -2580,7 +2580,7 @@ class DynamicSignature(Item):
"tickindex" : trackState.tickindex,
"keyword" : self.keyword,
"midiBytes" : [],
"UIstring" : self.keyword,
"UIstring" : "Dyn: " + self.keyword,
}
def _lilypond(self, carryLilypondRanges):

2
qtgui/mainwindow.py

@ -106,7 +106,7 @@ class MainWindow(TemplateMainWindow):
#Set the splitter ratio.
self.scoreView.setMinimumSize(1, 1)
self.trackListWidget.setMinimumSize(1, 1)
self.scoreSplitter.setSizes([16, 1])
self.scoreSplitter.setSizes([8, 1])
#self.scoreSplitter.setSizes([MAX_QT_SIZE, 1])

71
qtgui/tracklistwidget.py

@ -32,7 +32,38 @@ import engine.api as api
class TrackListWidget(QtWidgets.QListWidget):
class TrackListWidget(QtWidgets.QWidget):
"""Small container wrapper for a title, checkboxes etc."""
def __init__(self, mainWindow, parentSplitter):
super().__init__(parentSplitter)
self.mainWindow = mainWindow
self.layout = QtWidgets.QVBoxLayout(self)
self.trackLabel = QtWidgets.QLabel("Hello")
self.showEverythingCheckBox = QtWidgets.QCheckBox(QtCore.QCoreApplication.translate("TrackListWidget", "Show Everything"))
self.showEverythingCheckBox.setChecked(True)
self.showEverythingCheckBox.toggled.connect(self.reactShowEverything)
self.realTrackListWidget = _TrackListWidget(mainWindow, self)
self.layout.addWidget(self.trackLabel)
self.layout.addWidget(self.showEverythingCheckBox)
self.layout.addWidget(self.realTrackListWidget, stretch=1)
api.callbacks.setCursor.append(self.setCursor)
def reactShowEverything(self, newState:bool):
self.realTrackListWidget.showEverything(newState)
def setCursor(self, c:dict):
self.trackLabel.setText( "<b>{}-{}</b>".format(c["trackIndex"]+1, c["trackName"]) )
class _TrackListWidget(QtWidgets.QListWidget):
"""The TrackListWidget holds all tracks as text-only variants with cursor access.
It will show one track at a time, the current one.
@ -45,24 +76,32 @@ class TrackListWidget(QtWidgets.QListWidget):
We recreate the items on track change.
"""
def __init__(self, mainWindow, parentSplitter):
def __init__(self, mainWindow, parentWidget):
super().__init__(parentSplitter)
super().__init__()
self.mainWindow = mainWindow
self._lastCurrentTrack = None
self._lastCurrentTrackId = None
self.tracks = {} # engineTrackId : engineExportData
self.itemPressed.connect(self._react_itemPressed)
self._showEverything = True
api.callbacks.tracksChanged.append(self.syncTracks)
api.callbacks.updateTrack.append(self.updateTrack)
api.callbacks.setCursor.append(self.setCursor)
def showEverything(self, state:bool):
"""Can be called externally to filter out the most common items.
The indexing and cursor will still work"""
self._showEverything = state
self.showTrack(self._lastCurrentTrackId)
def setCursor(self, cursorExportObject):
if not self._lastCurrentTrack == cursorExportObject["trackId"]:
self._lastCurrentTrack == cursorExportObject["trackId"]
if not self._lastCurrentTrackId == cursorExportObject["trackId"]:
self._lastCurrentTrackId = cursorExportObject["trackId"]
self.showTrack(cursorExportObject["trackId"])
self.blockSignals(True)
@ -73,7 +112,8 @@ class TrackListWidget(QtWidgets.QListWidget):
def _react_itemPressed(self, item):
"""This is gui->api cursor setting
It only happens when the mouse etc. actually pressed an item.
This list cannot be activated by cursor keys etc. directly. """
This list cannot be activated by cursor keys etc. directly.
"""
api.toPosition(self.currentRow()) #currentRow is calculated after we already are on the item.
@ -94,7 +134,7 @@ class TrackListWidget(QtWidgets.QListWidget):
return
self.tracks[trackId] = staticRepresentationList
if trackId == self._lastCurrentTrack:
if trackId == self._lastCurrentTrackId:
self.showTrack(trackId)
@ -106,6 +146,17 @@ class TrackListWidget(QtWidgets.QListWidget):
self.clear()
staticRepresentationList = self.tracks[trackId]
count = 0
for staticItem in staticRepresentationList:
self.addItem(staticItem["UIstring"])
filterTypes = set(("Chord", "Rest"))
if self._showEverything:
for staticItem in staticRepresentationList:
self.addItem(staticItem["UIstring"])
else: #Hide Chords and Rests. The indexing and cursor will still work
for staticItem in staticRepresentationList:
item = QtWidgets.QListWidgetItem(staticItem["UIstring"])
self.addItem(item)
if staticItem["type"] in filterTypes:
item.setHidden(True)
self.addItem("|") #Appending

Loading…
Cancel
Save