@ -33,7 +33,7 @@ from template.qtgui.helper import ToggleSwitch,FancySwitch
import engine . api as api
COLUMNS = ( " state " , " id-k ey " , " mixSend " , " name " , " loaded " , " group " , " tags " ) #Loaded = Variant
COLUMNS = ( " state " , " idK ey " , " mixSend " , " name " , " loaded " , " group " , " tags " ) #Loaded = Variant
class InstrumentTreeController ( object ) :
@ -56,8 +56,8 @@ class InstrumentTreeController(object):
#Includes:
#self._cachedData = None
#self._cachedLastInstrumentStatus = {} # instrument idKey : status Dict
#self.guiLibraries = {} # id-k ey : GuiLibrary
#self.guiInstruments = {} # id-k ey : GuiInstrument
#self.guiLibraries = {} # idK ey : GuiLibrary
#self.guiInstruments = {} # idK ey : GuiInstrument
self . currentlyNested = None #is the view nested in libraries or just all instruments?
@ -102,8 +102,8 @@ class InstrumentTreeController(object):
self . _cachedData = None
self . _cachedLastInstrumentStatus = { } # instrument idKey : status Dict
#The next two will delete all children through the garbage collector.
self . guiLibraries = { } # id-k ey : GuiLibrary
self . guiInstruments = { } # id-k ey : GuiInstrument
self . guiLibraries = { } # idK ey : GuiLibrary
self . guiInstruments = { } # idK ey : GuiInstrument
def itemExpandedOrCollapsed ( self , libraryItem : QtWidgets . QTreeWidgetItem ) :
@ -149,7 +149,7 @@ class InstrumentTreeController(object):
{ ' 0 ' : { ' 0 ' : { ' group ' : ' strings ' ,
' id ' : ' 0 ' ,
' id-k ey ' : ( ' 0 ' , ' 0 ' ) ,
' idK ey ' : ( ' 0 ' , ' 0 ' ) ,
' license ' : ' https://unlicense.org/ ' ,
' name ' : ' Sine Wave ' ,
' tags ' : [ ' sine ' , ' basic ' ] ,
@ -157,7 +157,7 @@ class InstrumentTreeController(object):
' vendor ' : ' Test entry to provide more vendor information ' } ,
' 1 ' : { ' group ' : ' strings ' ,
' id ' : ' 1 ' ,
' id-k ey ' : ( ' 0 ' , ' 1 ' ) ,
' idK ey ' : ( ' 0 ' , ' 1 ' ) ,
' license ' : ' ' ,
' name ' : ' Square Wave ' ,
' tags ' : [ ' square ' , ' basic ' ] ,
@ -165,7 +165,7 @@ class InstrumentTreeController(object):
' vendor ' : ' ' } ,
' 2 ' : { ' group ' : ' brass ' ,
' id ' : ' 2 ' ,
' id-k ey ' : ( ' 0 ' , ' 2 ' ) ,
' idK ey ' : ( ' 0 ' , ' 2 ' ) ,
' license ' : ' ' ,
' name ' : ' Saw Wave ' ,
' tags ' : [ ' saw ' , ' basic ' ] ,
@ -173,7 +173,7 @@ class InstrumentTreeController(object):
' vendor ' : ' ' } ,
' 3 ' : { ' group ' : ' ' ,
' id ' : ' 3 ' ,
' id-k ey ' : ( ' 0 ' , ' 3 ' ) ,
' idK ey ' : ( ' 0 ' , ' 3 ' ) ,
' license ' : ' ' ,
' name ' : ' Triangle Wave ' ,
' tags ' : [ ' triangle ' , ' complex ' ] ,
@ -196,8 +196,8 @@ class InstrumentTreeController(object):
"""
#Reset everything except our cached data.
self . treeWidget . clear ( ) #will delete the C++ objects. We need to delete the PyQt objects ourselves, like so:
self . guiLibraries = { } # id-k ey : GuiLibrary
self . guiInstruments = { } # id-k ey : GuiInstrument
self . guiLibraries = { } # idK ey : GuiLibrary
self . guiInstruments = { } # idK ey : GuiInstrument
self . currentlyNested = nested
if data :
@ -235,9 +235,9 @@ class InstrumentTreeController(object):
else :
self . treeWidget . addTopLevelItem ( gi )
gi . injectWidgets ( ) #only possible after gi.init() was done and item inserted.
self . guiInstruments [ instrumentDict [ " id-k ey " ] ] = gi
if instrumentDict [ " id-k ey " ] in self . _cachedLastInstrumentStatus :
gi . updateStatus ( self . _cachedLastInstrumentStatus [ instrumentDict [ " id-k ey " ] ] )
self . guiInstruments [ instrumentDict [ " idK ey " ] ] = gi
if instrumentDict [ " idK ey " ] in self . _cachedLastInstrumentStatus :
gi . updateStatus ( self . _cachedLastInstrumentStatus [ instrumentDict [ " idK ey " ] ] )
self . _adjustColumnSize ( )
@ -266,12 +266,12 @@ class InstrumentTreeController(object):
def react_instrumentStatusChanged ( self , instrumentStatus : dict ) :
self . parentMainWindow . qtApp . restoreOverrideCursor ( ) #Sometimes the instrument was loaded with a cursor animation
gi = self . guiInstruments [ instrumentStatus [ " id-k ey " ] ]
gi = self . guiInstruments [ instrumentStatus [ " idK ey " ] ]
gi . updateStatus ( instrumentStatus )
self . _adjustColumnSize ( )
#We also cache the last status, as we cache the initial data. This way we can delete and recreate TreeItems without requesting new status data from the engine
self . _cachedLastInstrumentStatus [ instrumentStatus [ " id-k ey " ] ] = instrumentStatus
self . _cachedLastInstrumentStatus [ instrumentStatus [ " idK ey " ] ] = instrumentStatus
def react_startLoadingSamples ( self , idKey : tuple ) :
""" Will be overriden by instrument status change / variant chosen """
@ -300,8 +300,8 @@ class GuiLibrary(QtWidgets.QTreeWidgetItem):
self . name = libraryDict [ " name " ]
#No dynamic data here. Everything gets created once.
#self.setText(COLUMNS.index("id-k ey"), str(libraryDict["id"]).zfill(leadingZeroesForZfill))
self . setData ( COLUMNS . index ( " id-k ey " ) , 0 , int ( libraryDict [ " id " ] ) ) #set data allows sorting by actual numbers. 0 is the data role, which is just "display text".
#self.setText(COLUMNS.index("idK ey"), str(libraryDict["id"]).zfill(leadingZeroesForZfill))
self . setData ( COLUMNS . index ( " idK ey " ) , 0 , int ( libraryDict [ " id " ] ) ) #set data allows sorting by actual numbers. 0 is the data role, which is just "display text".
self . setText ( COLUMNS . index ( " name " ) , str ( libraryDict [ " name " ] ) )
self . setText ( COLUMNS . index ( " tags " ) , str ( libraryDict [ " description " ] ) [ : 42 ] + " … " )
@ -337,9 +337,9 @@ class GuiInstrument(QtWidgets.QTreeWidgetItem):
def __init__ ( self , parentTreeController , instrumentDict ) :
GuiInstrument . allItems [ instrumentDict [ " id-k ey " ] ] = self
GuiInstrument . allItems [ instrumentDict [ " idK ey " ] ] = self
self . parentTreeController = parentTreeController
self . idKey = instrumentDict [ " id-k ey " ]
self . idKey = instrumentDict [ " idK ey " ]
#Start with empty columns. We fill in later in _writeColumns
super ( ) . __init__ ( [ ] , type = 1000 ) #type 0 is default qt type. 1000 is subclassed user type)
@ -350,7 +350,7 @@ class GuiInstrument(QtWidgets.QTreeWidgetItem):
#nameColumnIndex = self.columns.index("prettyName")
#self.setText(nameColumnIndex, "hello")
self . setTextAlignment ( self . columns . index ( " id-k ey " ) , QtCore . Qt . AlignHCenter )
self . setTextAlignment ( self . columns . index ( " idK ey " ) , QtCore . Qt . AlignHCenter )
self . state = None #by self.update...
self . instrumentDict = None
@ -512,7 +512,7 @@ class GuiInstrument(QtWidgets.QTreeWidgetItem):
t = " , " . join ( instrumentDict [ key ] )
self . setText ( index , t )
elif key == " id-k ey " : #tuple
elif key == " idK ey " : #tuple
libId , instrId = instrumentDict [ key ]
zeros = int ( instrumentDict [ " instrumentsInLibraryCount " ] / 10 ) + 1
instIdZFilled = str ( instrId ) . zfill ( zeros )