Browse Source

GUI menu action to only view loaded instruments

master
Nils 2 years ago
parent
commit
fb130d9477
  1. 66
      qtgui/instrument.py
  2. 29
      qtgui/mainwindow.py

66
qtgui/instrument.py

@ -57,7 +57,6 @@ class InstrumentTreeController(object):
#self._cachedLastInstrumentStatus = {} # instrument idKey : status Dict #self._cachedLastInstrumentStatus = {} # instrument idKey : status Dict
#self.guiLibraries = {} # idKey : GuiLibrary #self.guiLibraries = {} # idKey : GuiLibrary
#self.guiInstruments = {} # idKey : GuiInstrument #self.guiInstruments = {} # idKey : GuiInstrument
self.currentlyNested = None #is the view nested in libraries or just all instruments?
self.headerLabels = [ self.headerLabels = [
@ -93,7 +92,13 @@ class InstrumentTreeController(object):
#self.treeWidget.setStyleSheet("QTreeWidget::item { border-bottom: 1px solid black;}") #sadly for all items. We want a line below top level items. #self.treeWidget.setStyleSheet("QTreeWidget::item { border-bottom: 1px solid black;}") #sadly for all items. We want a line below top level items.
if not "libraryIsExpanded" in api.session.guiSharedDataToSave: if "libraryIsExpanded" in api.session.guiSharedDataToSave:
#This is loaded from JSON, where keys MUST be strings. Our ids got converted into strings on save so we have to convert back to int here.
correctTypesDict = {}
for key, value in api.session.guiSharedDataToSave["libraryIsExpanded"].items():
correctTypesDict[int(key)] = value
api.session.guiSharedDataToSave["libraryIsExpanded"] = correctTypesDict
else:
api.session.guiSharedDataToSave["libraryIsExpanded"] = {} # libId : bool if expanded or not. Also used when switching from nested to flat and back. api.session.guiSharedDataToSave["libraryIsExpanded"] = {} # libId : bool if expanded or not. Also used when switching from nested to flat and back.
#Default values are used in self.buildTree #Default values are used in self.buildTree
@ -108,7 +113,6 @@ class InstrumentTreeController(object):
def itemExpandedOrCollapsed(self, libraryItem:QtWidgets.QTreeWidgetItem): def itemExpandedOrCollapsed(self, libraryItem:QtWidgets.QTreeWidgetItem):
#print (libraryItem.name, libraryItem.isExpanded())
api.session.guiSharedDataToSave["libraryIsExpanded"][libraryItem.id] = libraryItem.isExpanded() api.session.guiSharedDataToSave["libraryIsExpanded"][libraryItem.id] = libraryItem.isExpanded()
def itemSelectionChanged(self): def itemSelectionChanged(self):
@ -131,9 +135,13 @@ class InstrumentTreeController(object):
if type(item) is GuiInstrument: if type(item) is GuiInstrument:
api.auditionerInstrument(item.idKey) api.auditionerInstrument(item.idKey)
def isNested(self)->bool:
return self.parentMainWindow.ui.actionFlatNested.isChecked()
def isShowOnlyLoadedInstruments(self)->bool:
return self.parentMainWindow.ui.actionShowOnlyLoadedInstruments.isChecked()
def buildTree(self, data:dict, nested:bool=True): def buildTree(self, data:dict):
""" """
Create the tree. Can be called multiple times and it will re-create itself destructively. Create the tree. Can be called multiple times and it will re-create itself destructively.
If you call it with data, once at program start, data will get cached. If you call If you call it with data, once at program start, data will get cached. If you call
@ -199,7 +207,6 @@ class InstrumentTreeController(object):
self.treeWidget.clear() #will delete the C++ objects. We need to delete the PyQt objects ourselves, like so: self.treeWidget.clear() #will delete the C++ objects. We need to delete the PyQt objects ourselves, like so:
self.guiLibraries = {} # idKey : GuiLibrary self.guiLibraries = {} # idKey : GuiLibrary
self.guiInstruments = {} # idKey : GuiInstrument self.guiInstruments = {} # idKey : GuiInstrument
self.currentlyNested = nested
if data: if data:
self._cachedData = data self._cachedData = data
@ -207,7 +214,9 @@ class InstrumentTreeController(object):
assert self._cachedData assert self._cachedData
data = self._cachedData data = self._cachedData
self.currentlyNested = nested
nested = self.isNested()
showOnlyLoadedInstruments = self.isShowOnlyLoadedInstruments()
for libraryId, libraryDict in data.items(): for libraryId, libraryDict in data.items():
@ -219,30 +228,49 @@ class InstrumentTreeController(object):
parentLibraryWidget.setExpanded(api.session.guiSharedDataToSave["libraryIsExpanded"][libraryId]) #only possible after gi.init() was done and item inserted. parentLibraryWidget.setExpanded(api.session.guiSharedDataToSave["libraryIsExpanded"][libraryId]) #only possible after gi.init() was done and item inserted.
#parentLibraryWidget.setHidden(True) #only possible after insert #parentLibraryWidget.setHidden(True) #only possible after insert
atLeastOneVisible = False
for instrumentdId, instrumentDict in libraryDict.items(): for instrumentdId, instrumentDict in libraryDict.items():
if instrumentdId == "library": if instrumentdId == "library":
#Top level item was already created. Ignore here. #Top level item was already created. Ignore here.
pass continue
if showOnlyLoadedInstruments and instrumentDict["idKey"] in self._cachedLastInstrumentStatus and not self._cachedLastInstrumentStatus[instrumentDict["idKey"]]["state"]: #don't create if we only want to see enabled instrument
instrumentVisible = False
elif showOnlyLoadedInstruments and not instrumentDict["status"]["state"]:
instrumentVisible = False
else:
instrumentVisible = True
atLeastOneVisible = True
gi = GuiInstrument(parentTreeController=self, instrumentDict=instrumentDict)
if nested:
parentLibraryWidget.addChild(gi)
else: else:
gi = GuiInstrument(parentTreeController=self, instrumentDict=instrumentDict) self.treeWidget.addTopLevelItem(gi)
if nested: gi.injectWidgets() #only possible after gi.init() was done and item inserted.
parentLibraryWidget.addChild(gi) self.guiInstruments[instrumentDict["idKey"]] = gi
else: if instrumentDict["idKey"] in self._cachedLastInstrumentStatus:
self.treeWidget.addTopLevelItem(gi) gi.updateStatus(self._cachedLastInstrumentStatus[instrumentDict["idKey"]])
gi.injectWidgets() #only possible after gi.init() was done and item inserted. gi.setHidden(not instrumentVisible)
self.guiInstruments[instrumentDict["idKey"]] = gi
if instrumentDict["idKey"] in self._cachedLastInstrumentStatus: #If no instruments were added maybe the lib needs hiding because it is empty
gi.updateStatus(self._cachedLastInstrumentStatus[instrumentDict["idKey"]]) if showOnlyLoadedInstruments and nested and not atLeastOneVisible:
parentLibraryWidget.setHidden(True)
self._adjustColumnSize() self._adjustColumnSize()
def showOnlyLoadedInstruments(self, state:bool):
"""The logic is backwards. We receive state=True if instruments should be hidden"""
self.buildTree(data=None) #uses the menu state for everything except data
def setAllExpanded(self, state:bool): def setAllExpanded(self, state:bool):
"""We do not use the qt function collapseAll and expandAll because they do not trigger """We do not use the qt function collapseAll and expandAll because they do not trigger
the signal""" the signal"""
if self.currentlyNested: if self.isNested():
for libid, guiLib in self.guiLibraries.items(): for libid, guiLib in self.guiLibraries.items():
guiLib.setExpanded(state) #triggers signal which will trigger self.toggleNestedFlat guiLib.setExpanded(state)
def _adjustColumnSize(self): def _adjustColumnSize(self):
self.treeWidget.sortItems(self.sortByColumnValue, self.sortDescendingValue) self.treeWidget.sortItems(self.sortByColumnValue, self.sortDescendingValue)
@ -548,7 +576,7 @@ class GuiInstrument(QtWidgets.QTreeWidgetItem):
libId, instrId = instrumentDict[key] libId, instrId = instrumentDict[key]
zeros = int(instrumentDict["instrumentsInLibraryCount"]/10)+1 zeros = int(instrumentDict["instrumentsInLibraryCount"]/10)+1
instIdZFilled = str(instrId).zfill(zeros) instIdZFilled = str(instrId).zfill(zeros)
if self.parentTreeController.currentlyNested: if self.parentTreeController.isNested():
self.setText(index, instIdZFilled) self.setText(index, instIdZFilled)
else: #full id else: #full id
#self.setText(index, f"{libId}-{str(instrId).zfill(zeros)}") #self.setText(index, f"{libId}-{str(instrId).zfill(zeros)}")

29
qtgui/mainwindow.py

@ -145,14 +145,15 @@ class MainWindow(TemplateMainWindow):
self.pianoRollToggleVisibleAndRemember(settings.value("pianoRollVisible", type=bool)) self.pianoRollToggleVisibleAndRemember(settings.value("pianoRollVisible", type=bool))
if settings.contains("pianoVisible"): if settings.contains("pianoVisible"):
self.pianoToggleVisibleAndRemember(settings.value("pianoVisible", type=bool)) self.pianoToggleVisibleAndRemember(settings.value("pianoVisible", type=bool))
if settings.contains("instrumentTreeIsNested"):
self.ui.actionFlatNested.setChecked(settings.value("instrumentTreeIsNested", type=bool))
if settings.contains("showOnlyLoadedInstruments"):
self.ui.actionShowOnlyLoadedInstruments.setChecked(settings.value("showOnlyLoadedInstruments", type=bool))
self.start(additionalData) #This shows the GUI, or not, depends on the NSM gui save setting. We need to call that after the menu, otherwise the about dialog will block and then we get new menu entries, which looks strange. self.start(additionalData) #This shows the GUI, or not, depends on the NSM gui save setting. We need to call that after the menu, otherwise the about dialog will block and then we get new menu entries, which looks strange.
api.callbacks.rescanSampleDir.append(self.react_rescanSampleDir) #This only happens on actual, manually instructed rescanning through the api. We instruct this through our Rescan-Dialog. api.callbacks.rescanSampleDir.append(self.react_rescanSampleDir) #This only happens on actual, manually instructed rescanning through the api. We instruct this through our Rescan-Dialog.
if settings.contains("instrumentTreeIsNested"): #Only call after the instruments got parsed
self.toggleNestedFlatAndRemember(settings.value("instrumentTreeIsNested", type=bool))
#Statusbar will show possible actions, such as "use scrollwheel to transpose" #Statusbar will show possible actions, such as "use scrollwheel to transpose"
#self.statusBar().showMessage(QtCore.QCoreApplication.translate("Statusbar", "")) #self.statusBar().showMessage(QtCore.QCoreApplication.translate("Statusbar", ""))
self.statusBar().showMessage("") self.statusBar().showMessage("")
@ -174,6 +175,7 @@ class MainWindow(TemplateMainWindow):
self.menu.addMenuEntry("menuView", "actionExpandAll", QtCore.QCoreApplication.translate("Menu", "Expand all Libraries"), lambda: self.instrumentTreeController.setAllExpanded(True)) self.menu.addMenuEntry("menuView", "actionExpandAll", QtCore.QCoreApplication.translate("Menu", "Expand all Libraries"), lambda: self.instrumentTreeController.setAllExpanded(True))
self.menu.addMenuEntry("menuView", "actionCollapseAll", QtCore.QCoreApplication.translate("Menu", "Collapse all Libraries"), lambda: self.instrumentTreeController.setAllExpanded(False)) self.menu.addMenuEntry("menuView", "actionCollapseAll", QtCore.QCoreApplication.translate("Menu", "Collapse all Libraries"), lambda: self.instrumentTreeController.setAllExpanded(False))
self.menu.addMenuEntry("menuView", "actionShowOnlyLoadedInstruments", QtCore.QCoreApplication.translate("Menu", "Show only loaded instruments"), self.toggleShowOnlyLoadedInstrumentsAndRemember, checkable=True, startChecked=False) #function receives check state as automatic parameter
self.menu.addMenuEntry("menuView", "actionFlatNested", QtCore.QCoreApplication.translate("Menu", "Nested Instrument List"), self.toggleNestedFlatAndRemember, checkable=True, startChecked=True) #function receives check state as automatic parameter self.menu.addMenuEntry("menuView", "actionFlatNested", QtCore.QCoreApplication.translate("Menu", "Nested Instrument List"), self.toggleNestedFlatAndRemember, checkable=True, startChecked=True) #function receives check state as automatic parameter
self.menu.addMenuEntry("menuView", "actionPianoRollVisible", QtCore.QCoreApplication.translate("Menu", "Piano Roll"), self.pianoRollToggleVisibleAndRemember, shortcut="Ctrl+R", checkable=True, startChecked=True) #function receives check state as automatic parameter self.menu.addMenuEntry("menuView", "actionPianoRollVisible", QtCore.QCoreApplication.translate("Menu", "Piano Roll"), self.pianoRollToggleVisibleAndRemember, shortcut="Ctrl+R", checkable=True, startChecked=True) #function receives check state as automatic parameter
self.menu.addMenuEntry("menuView", "actionPianoVisible", QtCore.QCoreApplication.translate("Menu", "Piano"), self.pianoToggleVisibleAndRemember, shortcut="Ctrl+P", checkable=True, startChecked=True) #function receives check state as automatic parameter self.menu.addMenuEntry("menuView", "actionPianoVisible", QtCore.QCoreApplication.translate("Menu", "Piano"), self.pianoToggleVisibleAndRemember, shortcut="Ctrl+P", checkable=True, startChecked=True) #function receives check state as automatic parameter
@ -189,28 +191,41 @@ class MainWindow(TemplateMainWindow):
The program start happens without that and just sends data into a prepared but empty GUI.""" The program start happens without that and just sends data into a prepared but empty GUI."""
self.instrumentTreeController.reset() self.instrumentTreeController.reset()
def toggleShowOnlyLoadedInstrumentsAndRemember(self, state:bool):
"""
This function can only be called after the instrument tree has been build.
"""
self.ui.actionShowOnlyLoadedInstruments.setChecked(state) #if called from outside the menu, e.g. load
self.instrumentTreeController.buildTree(data=None) #with data=None it will used the cache data we received once, at startup. All other values use the menu check marks
settings = QtCore.QSettings("LaborejoSoftwareSuite", METADATA["shortName"])
settings.setValue("showOnlyLoadedInstruments", state)
def toggleNestedFlatAndRemember(self, state:bool): def toggleNestedFlatAndRemember(self, state:bool):
"""We receive state as automatic parameter from Qt from the calling menu action. """We receive state as automatic parameter from Qt from the calling menu action.
This function can only be called after the instrument tree has been build. This function can only be called after the instrument tree has been build.
instrumentTreeController.buildTree(data=None) relies on cached data. instrumentTreeController.buildTree(data=None) relies on cached data.
""" """
self.instrumentTreeController.buildTree(data=None, nested=state) #with data=None it will used the cache data we received once, at startup self.ui.actionFlatNested.setChecked(state) #if called from outside the menu, e.g. load
self.instrumentTreeController.buildTree(data=None) #with data=None it will used the cache data we received once, at startup. All other values use the menu check marks
settings = QtCore.QSettings("LaborejoSoftwareSuite", METADATA["shortName"]) settings = QtCore.QSettings("LaborejoSoftwareSuite", METADATA["shortName"])
settings.setValue("instrumentTreeIsNested", state) settings.setValue("instrumentTreeIsNested", state)
self.ui.actionFlatNested.setChecked(state) #if called from outside the menu, e.g. load
def pianoRollToggleVisibleAndRemember(self, state:bool): def pianoRollToggleVisibleAndRemember(self, state:bool):
self.ui.actionPianoRollVisible.setChecked(state) #if called from outside the menu, e.g. load
self.ui.verticalPianoFrame.setVisible(state) self.ui.verticalPianoFrame.setVisible(state)
settings = QtCore.QSettings("LaborejoSoftwareSuite", METADATA["shortName"]) settings = QtCore.QSettings("LaborejoSoftwareSuite", METADATA["shortName"])
settings.setValue("pianoRollVisible", state) settings.setValue("pianoRollVisible", state)
self.ui.actionPianoRollVisible.setChecked(state) #if called from outside the menu, e.g. load
def pianoToggleVisibleAndRemember(self, state:bool): def pianoToggleVisibleAndRemember(self, state:bool):
self.ui.actionPianoVisible.setChecked(state) #if called from outside the menu, e.g. load
self.ui.horizontalPianoFrame.setVisible(state) self.ui.horizontalPianoFrame.setVisible(state)
settings = QtCore.QSettings("LaborejoSoftwareSuite", METADATA["shortName"]) settings = QtCore.QSettings("LaborejoSoftwareSuite", METADATA["shortName"])
settings.setValue("pianoVisible", state) settings.setValue("pianoVisible", state)
self.ui.actionPianoVisible.setChecked(state) #if called from outside the menu, e.g. load
def selectedInstrumentChanged(self, instrumentStatus, instrumentData): def selectedInstrumentChanged(self, instrumentStatus, instrumentData):
"""We receive this from selectedinstrumentcontroller.py, when the user clicks on a GUI """We receive this from selectedinstrumentcontroller.py, when the user clicks on a GUI

Loading…
Cancel
Save