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. 67
      qtgui/tracklistwidget.py

1
engine/api.py

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

2
engine/items.py

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

2
qtgui/mainwindow.py

@ -106,7 +106,7 @@ class MainWindow(TemplateMainWindow):
#Set the splitter ratio. #Set the splitter ratio.
self.scoreView.setMinimumSize(1, 1) self.scoreView.setMinimumSize(1, 1)
self.trackListWidget.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]) #self.scoreSplitter.setSizes([MAX_QT_SIZE, 1])

67
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. """The TrackListWidget holds all tracks as text-only variants with cursor access.
It will show one track at a time, the current one. 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. 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.mainWindow = mainWindow
self._lastCurrentTrack = None self._lastCurrentTrackId = None
self.tracks = {} # engineTrackId : engineExportData self.tracks = {} # engineTrackId : engineExportData
self.itemPressed.connect(self._react_itemPressed) self.itemPressed.connect(self._react_itemPressed)
self._showEverything = True
api.callbacks.tracksChanged.append(self.syncTracks) api.callbacks.tracksChanged.append(self.syncTracks)
api.callbacks.updateTrack.append(self.updateTrack) api.callbacks.updateTrack.append(self.updateTrack)
api.callbacks.setCursor.append(self.setCursor) 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): def setCursor(self, cursorExportObject):
if not self._lastCurrentTrack == cursorExportObject["trackId"]: if not self._lastCurrentTrackId == cursorExportObject["trackId"]:
self._lastCurrentTrack == cursorExportObject["trackId"] self._lastCurrentTrackId = cursorExportObject["trackId"]
self.showTrack(cursorExportObject["trackId"]) self.showTrack(cursorExportObject["trackId"])
self.blockSignals(True) self.blockSignals(True)
@ -73,7 +112,8 @@ class TrackListWidget(QtWidgets.QListWidget):
def _react_itemPressed(self, item): def _react_itemPressed(self, item):
"""This is gui->api cursor setting """This is gui->api cursor setting
It only happens when the mouse etc. actually pressed an item. 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. api.toPosition(self.currentRow()) #currentRow is calculated after we already are on the item.
@ -94,7 +134,7 @@ class TrackListWidget(QtWidgets.QListWidget):
return return
self.tracks[trackId] = staticRepresentationList self.tracks[trackId] = staticRepresentationList
if trackId == self._lastCurrentTrack: if trackId == self._lastCurrentTrackId:
self.showTrack(trackId) self.showTrack(trackId)
@ -106,6 +146,17 @@ class TrackListWidget(QtWidgets.QListWidget):
self.clear() self.clear()
staticRepresentationList = self.tracks[trackId] staticRepresentationList = self.tracks[trackId]
count = 0 count = 0
filterTypes = set(("Chord", "Rest"))
if self._showEverything:
for staticItem in staticRepresentationList: for staticItem in staticRepresentationList:
self.addItem(staticItem["UIstring"]) 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 self.addItem("|") #Appending

Loading…
Cancel
Save