From f209ba64061b1578eae30209ca40e427b5d36417 Mon Sep 17 00:00:00 2001 From: Nils <> Date: Mon, 13 Jul 2020 23:26:28 +0200 Subject: [PATCH] Set background colors to prevent transparent edit areas --- qtgui/pattern_grid.py | 56 +++++++++++++++++++++++-------------------- qtgui/songeditor.py | 33 +++++++++++++++---------- qtgui/timeline.py | 5 ++++ 3 files changed, 56 insertions(+), 38 deletions(-) diff --git a/qtgui/pattern_grid.py b/qtgui/pattern_grid.py index 1a3c71f..c74afd1 100644 --- a/qtgui/pattern_grid.py +++ b/qtgui/pattern_grid.py @@ -66,6 +66,10 @@ class PatternGrid(QtWidgets.QGraphicsScene): self._zoomFactor = 1 # no save. We don't keep a qt config. + #Set color, otherwise it will be transparent in window managers or wayland that want that. + self.backColor = QtGui.QColor(55, 61, 69) + self.setBackgroundBrush(self.backColor) + role = QtGui.QPalette.BrightText self.textColor = self.parentView.parentMainWindow.fPalBlue.color(role) self.labelColor = QtGui.QColor("black") #save for new step @@ -187,7 +191,7 @@ class PatternGrid(QtWidgets.QGraphicsScene): to trigger a redraw even during the track change. """ - if force or self.parentView.parentMainWindow.currentTrackId == exportDict["id"]: + if force or self.parentView.parentMainWindow.currentTrackId == exportDict["id"]: self.trackName.setText(exportDict["sequencerInterface"]["name"]) self.trackName.show() c = QtGui.QColor(exportDict["color"]) @@ -306,24 +310,24 @@ class PatternGrid(QtWidgets.QGraphicsScene): potentialStep = self.itemAt(event.scenePos().x(), event.scenePos().y(), self.parentView.transform()) potentialSteps = [st for st in self.items(event.scenePos()) if type(st) is Step] - + #An over-long active step is stacked before the actual step. We need to either find the lowest #or the one furthest to the right because active notes can't have negative duration if potentialSteps: potentialStep = max(potentialSteps, key=lambda ls: ls.column) else: - potentialStep = None - - listOfLabelsAndFunctions = [ - (QtCore.QCoreApplication.translate("EventContextMenu", "Invert Steps"), lambda: api.patternInvertSteps(trackId)), + potentialStep = None + + listOfLabelsAndFunctions = [ + (QtCore.QCoreApplication.translate("EventContextMenu", "Invert Steps"), lambda: api.patternInvertSteps(trackId)), (QtCore.QCoreApplication.translate("EventContextMenu", "All Steps On"), lambda: api.patternOnAllSteps(trackId)), (QtCore.QCoreApplication.translate("EventContextMenu", "All Steps Off"), lambda: api.patternOffAllSteps(trackId)), ] - - if potentialStep: - listOfLabelsAndFunctions.insert(0, (QtCore.QCoreApplication.translate("EventContextMenu", "Repeat to step {} incl. to fill Row").format(potentialStep.column+1), lambda: api.patternRowRepeatFromStep(trackId, potentialStep.row, potentialStep.column))) - listOfLabelsAndFunctions.insert(0, (QtCore.QCoreApplication.translate("EventContextMenu", "Clear Row"), lambda: api.patternClearRow(trackId, potentialStep.row))) - listOfLabelsAndFunctions.insert(0, (QtCore.QCoreApplication.translate("EventContextMenu", "Invert Row"), lambda: api.patternInvertRow(trackId, potentialStep.row))) + + if potentialStep: + listOfLabelsAndFunctions.insert(0, (QtCore.QCoreApplication.translate("EventContextMenu", "Repeat to step {} incl. to fill Row").format(potentialStep.column+1), lambda: api.patternRowRepeatFromStep(trackId, potentialStep.row, potentialStep.column))) + listOfLabelsAndFunctions.insert(0, (QtCore.QCoreApplication.translate("EventContextMenu", "Clear Row"), lambda: api.patternClearRow(trackId, potentialStep.row))) + listOfLabelsAndFunctions.insert(0, (QtCore.QCoreApplication.translate("EventContextMenu", "Invert Row"), lambda: api.patternInvertRow(trackId, potentialStep.row))) for text, function in listOfLabelsAndFunctions: if function is None: @@ -353,17 +357,17 @@ class PatternGrid(QtWidgets.QGraphicsScene): elif QtWidgets.QApplication.keyboardModifiers() == QtCore.Qt.AltModifier: potentialStep = self.itemAt(event.scenePos().x(), event.scenePos().y(), self.parentView.transform()) if type(potentialStep) is Step: - trackId = self.parentView.parentMainWindow.currentTrackId + trackId = self.parentView.parentMainWindow.currentTrackId if event.delta() > 0: - delta = 2 + delta = 2 else: delta = -2 - api.patternRowChangeVelocity(trackId, potentialStep.row, delta) + api.patternRowChangeVelocity(trackId, potentialStep.row, delta) self.showVelocities() #removed in self.keyReleaseEvent event.accept() else: event.ignore() - super().wheelEvent(event) + super().wheelEvent(event) else: event.ignore() super().wheelEvent(event) @@ -371,10 +375,10 @@ class PatternGrid(QtWidgets.QGraphicsScene): def keyReleaseEvent(self, event): """Complementary for wheelEvent with Alt to change row velocity. It is hard to detect the Alt key. We just brute force because there are not many - keyPresses in Patroneo at all.""" + keyPresses in Patroneo at all.""" self.hideVelocities() event.ignore() - super().keyReleaseEvent(event) + super().keyReleaseEvent(event) def _zoom(self, event): if 0.1 < self._zoomFactor < 5: @@ -764,13 +768,13 @@ class PitchWidget(QtWidgets.QGraphicsProxyWidget): def __init__(self, parentItem): super().__init__() self.parentItem = parentItem - self.spinBox = QtWidgets.QSpinBox() + self.spinBox = QtWidgets.QSpinBox() #self.spinBox.setFrame(True) self.spinBox.setMinimum(0) self.spinBox.setMaximum(127) self.spinBox.stepBy = self.stepBy #self.spinBox.setValue(0) #No init value. This is changed on active track callback - + widget = QtWidgets.QWidget() layout = QtWidgets.QHBoxLayout() @@ -789,7 +793,7 @@ class PitchWidget(QtWidgets.QGraphicsProxyWidget): self.setWidget(widget) - self.spinBox.wheelEvent = self.spinBoxMouseWheelEvent + self.spinBox.wheelEvent = self.spinBoxMouseWheelEvent self.spinBox.valueChanged.connect(self.spinBoxValueChanged) self.spinBox.editingFinished.connect(self.spinBoxEditingFinished) #self.spinBoxValueChanged() #Delay that. The engine Data is not ready yet. It will be sent by the callback @@ -807,7 +811,7 @@ class PitchWidget(QtWidgets.QGraphicsProxyWidget): exit() def spinBoxValueChanged(self): - self.label.setText(self.midiToNotename(self.spinBox.value())) + self.label.setText(self.midiToNotename(self.spinBox.value())) #self.parentItem.sendToEngine(callback=False) # results in a loop with callback, and in wrong data without. This is not the right place to implement immediate note feedback while editing is still going on. def spinBoxEditingFinished(self): @@ -827,13 +831,13 @@ class PitchWidget(QtWidgets.QGraphicsProxyWidget): def spinBoxMouseWheelEvent(self, event): """We cannot use spinBoxValueChanged to send mousewheel scrolling pitch changing directly to the engine while editing is still active. this results in signal loops and various - data corruptions. Fixing this would be far too much work. - You can either use the arrow keys and press enter, which triggers editingFinished. + data corruptions. Fixing this would be far too much work. + You can either use the arrow keys and press enter, which triggers editingFinished. But here we intercept the mousewheel directly.""" - event.ignore() + event.ignore() QtWidgets.QSpinBox.wheelEvent(self.spinBox, event) #this changes to the new text and therefore the new value. Call BEFORE sendToEngine self.parentItem.sendToEngine(callback=False) - #if event.angleDelta().y() > 0: #up + #if event.angleDelta().y() > 0: #up #else: #down @@ -868,7 +872,7 @@ class Playhead(QtWidgets.QGraphicsLineItem): class VelocityControls(QtWidgets.QWidget): def __init__(self, mainWindow, patternScene): super().__init__() - + self.parentScene = patternScene self.mainWindow = mainWindow diff --git a/qtgui/songeditor.py b/qtgui/songeditor.py index 0ce4a78..404a497 100644 --- a/qtgui/songeditor.py +++ b/qtgui/songeditor.py @@ -40,6 +40,10 @@ class SongEditor(QtWidgets.QGraphicsScene): super().__init__() self.parentView = parentView + #Set color, otherwise it will be transparent in window managers or wayland that want that. + self.backColor = QtGui.QColor(55, 61, 69) + self.setBackgroundBrush(self.backColor) + #Subitems self.playhead = Playhead(parentScene = self) self.addItem(self.playhead) @@ -323,11 +327,11 @@ class TrackStructure(QtWidgets.QGraphicsRectItem): position = self.scenePos2switchPosition(event.scenePos().x()) #measure number 0 based measuresPerGroup = self.parentScene.measuresPerGroupCache offset = position % measuresPerGroup - startMeasureForGroup = position - offset - endMeasureExclusive = startMeasureForGroup + measuresPerGroup - + startMeasureForGroup = position - offset + endMeasureExclusive = startMeasureForGroup + measuresPerGroup + listOfLabelsAndFunctions = [ - (QtCore.QCoreApplication.translate("SongStructure", "Insert empty group before this one").format(measuresPerGroup), lambda: api.insertSilence(howMany=measuresPerGroup, beforeMeasureNumber=startMeasureForGroup)), + (QtCore.QCoreApplication.translate("SongStructure", "Insert empty group before this one").format(measuresPerGroup), lambda: api.insertSilence(howMany=measuresPerGroup, beforeMeasureNumber=startMeasureForGroup)), (QtCore.QCoreApplication.translate("SongStructure", "Delete whole group").format(measuresPerGroup), lambda: api.deleteSwitches(howMany=measuresPerGroup, fromMeasureNumber=startMeasureForGroup)), (QtCore.QCoreApplication.translate("SongStructure", "Duplicate whole group including measures"), lambda: api.duplicateSwitchGroup(startMeasureForGroup, endMeasureExclusive)), (QtCore.QCoreApplication.translate("SongStructure", "Clear all group transpositions"), lambda: api.clearSwitchGroupTranspositions(startMeasureForGroup, endMeasureExclusive)), @@ -524,6 +528,11 @@ class TrackLabelEditor(QtWidgets.QGraphicsScene): self._cachedExportDictsInOrder = [] + #Set color, otherwise it will be transparent in window managers or wayland that want that. + self.backColor = QtGui.QColor(55, 61, 69) + self.backColor = QtGui.QColor(48, 53, 60) + self.setBackgroundBrush(self.backColor) + api.callbacks.numberOfTracksChanged.append(self.callback_numberOfTracksChanged) api.callbacks.trackMetaDataChanged.append(self.callback_trackMetaDataChanged) api.callbacks.exportCacheChanged.append(self.cacheExportDict) @@ -536,7 +545,7 @@ class TrackLabelEditor(QtWidgets.QGraphicsScene): """This is not for the initial track creation, only for later changes""" self.tracks[exportDict["id"]].update(exportDict) - def callback_numberOfTracksChanged(self, exportDictList): + def callback_numberOfTracksChanged(self, exportDictList): toDelete = set(self.tracks.keys()) self._cachedExportDictsInOrder = exportDictList @@ -603,13 +612,13 @@ class TrackLabelEditor(QtWidgets.QGraphicsScene): a.triggered.connect(function) #Add a submenu for merge/cop - + mergeMenu = menu.addMenu(QtCore.QCoreApplication.translate("TrackLabelContext", "Merge/Copy Measure-Structure from")) - + def createCopyMergeLambda(srcId): return lambda: api.trackMergeCopyFrom(srcId, exportDict["id"]) - - for sourceDict in self._cachedExportDictsInOrder: + + for sourceDict in self._cachedExportDictsInOrder: a = QtWidgets.QAction(sourceDict["sequencerInterface"]["name"], mergeMenu) mergeMenu.addAction(a) mergeCommand = createCopyMergeLambda(sourceDict["id"]) @@ -619,18 +628,18 @@ class TrackLabelEditor(QtWidgets.QGraphicsScene): #Add a submenu for pattern merge/copy copyMenu = menu.addMenu(QtCore.QCoreApplication.translate("TrackLabelContext", "Replace Pattern with")) - + def replacePatternWithLambda(srcId): return lambda: api.trackPatternReplaceFrom(srcId, exportDict["id"]) - for sourceDict in self._cachedExportDictsInOrder: + for sourceDict in self._cachedExportDictsInOrder: a = QtWidgets.QAction(sourceDict["sequencerInterface"]["name"], copyMenu) copyMenu.addAction(a) mergeCommand = replacePatternWithLambda(sourceDict["id"]) if sourceDict["id"] == exportDict["id"]: a.setEnabled(False) a.triggered.connect(mergeCommand) - + pos = QtGui.QCursor.pos() pos.setY(pos.y() + 5) self.parentView.parentMainWindow.setFocus() diff --git a/qtgui/timeline.py b/qtgui/timeline.py index 37d6dca..94ecdfd 100644 --- a/qtgui/timeline.py +++ b/qtgui/timeline.py @@ -33,6 +33,11 @@ class Timeline(QtWidgets.QGraphicsScene): self.parentView = parentView self.addItem(TimelineRect(parentScene=self)) + #Set color, otherwise it will be transparent in window managers or wayland that want that. + self.backColor = QtGui.QColor(55, 61, 69) + self.setBackgroundBrush(self.backColor) + + class TimelineRect(QtWidgets.QGraphicsRectItem): """Shows information about song progression.