Browse Source

gui context menu for libraries to un/load all instruments

master
Nils 2 years ago
parent
commit
cc600d9514
  1. 12
      engine/api.py
  2. 36
      qtgui/instrument.py

12
engine/api.py

@ -233,6 +233,18 @@ def unloadAllInstrumentSamples():
callbacks._instrumentStatusChanged(*instrument.idKey) #Needs to be here to have incremental updates in the gui.
callbacks._dataChanged()
def loadLibraryInstrumentSamples(libId):
"""Convenience function like loadAllInstrumentSamples or loadInstrumentSamples for the whole
lib"""
for instrumentId in session.data.libraries[libId].instruments.keys():
idKey = (libId, instrumentId)
loadInstrumentSamples(idKey) #all callbacks are triggered there
def unloadLibraryInstrumentSamples(libId):
for instrumentId in session.data.libraries[libId].instruments.keys():
idKey = (libId, instrumentId)
unloadInstrumentSamples(idKey) #all callbacks are triggered there
def unloadInstrumentSamples(idKey:tuple):
instrument = _instr(idKey)
if instrument.enabled:

36
qtgui/instrument.py

@ -291,13 +291,16 @@ class InstrumentTreeController(object):
gi.activity() #We only do a quick flash here. No need for velocity, pitch or note-off
def contextMenu(self, qpoint):
def contextMenu(self, qpoint): #strange that this is not an event but a qpoint
item = self.treeWidget.itemAt(qpoint)
if not type(item) is GuiInstrument: #and not GuiLibrary
if not item:
return
elif not item.state:
elif type(item) is GuiLibrary:
item.contextMenu(qpoint)
elif type(item) is GuiInstrument and not item.state:
return
else:
else: #GuiInstrument and item.state
assert item.state
externalPort = nestedJackPortsMenu() #returns None or clientAndPortString
if externalPort: #None or ClientPortString
api.connectInstrumentPort(item.idKey, externalPort)
@ -331,6 +334,31 @@ class GuiLibrary(QtWidgets.QTreeWidgetItem):
icon = parentTreeController.parentMainWindow.style().standardIcon(getattr(QtWidgets.QStyle, "SP_DirIcon"))
self.setIcon(COLUMNS.index("name"), icon)
def contextMenu(self, qpoint):
"""This isn't the qt function, but we call this from self.parentTreeController.
Logically it makes sense to have it here though"""
menu = QtWidgets.QMenu()
listOfLabelsAndFunctions = [
(QtCore.QCoreApplication.translate("GuiLibraryContextMenu", "Load whole Library"), lambda: api.loadLibraryInstrumentSamples(self.id)),
(QtCore.QCoreApplication.translate("GuiLibraryContextMenu", "Unload whole Library"), lambda: api.unloadLibraryInstrumentSamples(self.id)),
]
for text, function in listOfLabelsAndFunctions:
if function is None:
l = QtWidgets.QLabel(text)
l.setAlignment(QtCore.Qt.AlignCenter)
a = QtWidgets.QWidgetAction(menu)
a.setDefaultWidget(l)
menu.addAction(a)
else:
a = QtWidgets.QAction(text, menu)
menu.addAction(a)
a.triggered.connect(function)
pos = QtGui.QCursor.pos()
pos.setY(pos.y() + 5)
menu.exec_(pos)
class GuiInstrument(QtWidgets.QTreeWidgetItem):

Loading…
Cancel
Save