Browse Source

show first block name in track list widget

master
Nils 2 years ago
parent
commit
d012ca9ed1
  1. 32
      qtgui/tracklistwidget.py

32
qtgui/tracklistwidget.py

@ -54,8 +54,8 @@ class TrackListWidget(QtWidgets.QWidget):
self.realTrackListWidget = _TrackListWidget(mainWindow, self)
self.layout.addWidget(self.trackLabel)
self.layout.addWidget(self.showEverythingCheckBox)
self.layout.addWidget(self.soloPlaybackCheckbox)
self.layout.addWidget(self.showEverythingCheckBox)
self.layout.addWidget(self.realTrackListWidget, stretch=1)
api.callbacks.setCursor.append(self.callback_setCursor)
@ -95,6 +95,8 @@ class _TrackListWidget(QtWidgets.QListWidget):
self.mainWindow = mainWindow
self._lastCurrentTrackId = None
self._firstBlockNames = {} # engineTrackId : string
self.tracks = {} # engineTrackId : engineExportData
self.itemPressed.connect(self._react_itemPressed)
@ -104,6 +106,7 @@ class _TrackListWidget(QtWidgets.QListWidget):
api.callbacks.tracksChanged.append(self.syncTracks)
api.callbacks.updateTrack.append(self.updateTrack)
api.callbacks.setCursor.append(self.setCursor)
api.callbacks.updateBlockTrack.append(self.updateBlockList) #to get the block names
def showEverything(self, state:bool):
@ -118,7 +121,7 @@ class _TrackListWidget(QtWidgets.QListWidget):
self.showTrack(cursorExportObject["trackId"])
self.blockSignals(True)
self.setCurrentRow(cursorExportObject["position"])
self.setCurrentRow(cursorExportObject["position"]+1) #+1 offset for the initial block name
self.blockSignals(False)
@ -127,7 +130,11 @@ class _TrackListWidget(QtWidgets.QListWidget):
It only happens when the mouse etc. actually pressed an item.
This list cannot be activated by cursor keys etc. directly.
"""
api.toPosition(self.currentRow()) #currentRow is calculated after we already are on the item.
i = self.currentRow() #currentRow is calculated after we already are on the item.
if i > 0:
i -= 1 #-1 because we have the artificial first block item that the engine didn't send us
api.toPosition(i)
def syncTracks(self, listOfStaticTrackRepresentations):
"""Handles the number of tracks and track meta-data changes,
@ -137,29 +144,38 @@ class _TrackListWidget(QtWidgets.QListWidget):
if not trackExportObject["id"] in self.tracks:
self.tracks[trackExportObject["id"]] = None
def updateBlockList(self, trackId, listOfBlockExportDicts):
"""This comes in for every small item change. But only per track.
Blocknames in our list are done by using the artificial block end markers, but the first block does not have that.
We store this for self.showTrack
"""
self._firstBlockNames[trackId] = listOfBlockExportDicts[0]["name"]
#updateTrack callback arrives before updateBlockTrack.
#We need both, but we also need to update the first item directly after a name change
if trackId == self._lastCurrentTrackId:
self.item(0).setText("== " + self._firstBlockNames[trackId] )
def updateTrack(self, trackId, staticRepresentationList):
"""Callback: The content of a single track has changed"""
if not trackId in self.tracks:
#hidden track. But this can still happen through the data editor
return
self.tracks[trackId] = staticRepresentationList
if trackId == self._lastCurrentTrackId:
self.showTrack(trackId)
def showTrack(self, trackId):
"""Cursor moved to a different track.
This is essentially destroy-and-recreate in Qt """
self.clear()
staticRepresentationList = self.tracks[trackId]
count = 0
filterTypes = set(("Chord", "Rest"))
#Block entries are done with BlockEndMarker, but there is no for the first.
self.addItem("== " + self._firstBlockNames[self._lastCurrentTrackId])
filterTypes = set(("Chord", "Rest"))
if self._showEverything:
for staticItem in staticRepresentationList:
self.addItem(staticItem["UIstring"])

Loading…
Cancel
Save