From bff24bcf3a0057e940b395b95aeb48c499ad125a Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 15 Sep 2018 03:43:25 +0200 Subject: [PATCH] Cleanup pixmapkeyboard code, less hardcoded bits Now easier to add more layouts --- source/frontend/widgets/pixmapkeyboard.py | 40 +++++++++++------------ 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/source/frontend/widgets/pixmapkeyboard.py b/source/frontend/widgets/pixmapkeyboard.py index 9393fe6bde..2365a34d39 100644 --- a/source/frontend/widgets/pixmapkeyboard.py +++ b/source/frontend/widgets/pixmapkeyboard.py @@ -176,6 +176,8 @@ 'azerty': kPcKeys_azerty, } +kValidColors = ("Blue", "Green", "Orange", "Red") + kBlackNotes = (1, 3, 6, 8, 10) # ------------------------------------------------------------------------------------------------------------ @@ -204,7 +206,7 @@ def __init__(self, parent): self.fPixmapNormal = QPixmap(":/bitmaps/kbd_normal.png") self.fPixmapDown = QPixmap(":/bitmaps/kbd_down-blue.png") - self.fHighlightColor = "Blue" + self.fHighlightColor = kValidColors[0] self.fkPcKeyLayout = "qwerty" self.fkPcKeys = kPcKeysLayouts["qwerty"] @@ -233,9 +235,9 @@ def saveSettings(self): def loadSettings(self): settings = QSettings("falkTX", "CarlaKeyboard") - self.setPcKeyboardLayout(settings.value("PcKeyboardLayout", "qwerty", type=str)) - self.setPcKeyboardOffset(settings.value("PcKeyboardOffset", 2, type=int)) - self.setColor(settings.value("HighlightColor", "Blue", type=str)) + self.setPcKeyboardLayout(settings.value("PcKeyboardLayout", self.fkPcKeyLayout, type=str)) + self.setPcKeyboardOffset(settings.value("PcKeyboardOffset", self.fPcKeybOffset, type=int)) + self.setColor(settings.value("HighlightColor", self.fHighlightColor, type=str)) del settings def allNotesOff(self, sendSignal=True): @@ -271,7 +273,7 @@ def sendNoteOff(self, note, sendSignal=True): self.notesOff.emit() def setColor(self, color): - if color not in ("Blue", "Green", "Orange", "Red"): + if color not in kValidColors: return if self.fHighlightColor == color: @@ -379,28 +381,24 @@ def showOptions(self, event): menu.addAction("Note: restart carla to apply globally").setEnabled(False) menu.addSeparator() - menuColor = QMenu("Highlight color", menu) - actColorBlue = menuColor.addAction("Blue") - actColorGreen = menuColor.addAction("Green") - actColorOrange = menuColor.addAction("Orange") - actColorRed = menuColor.addAction("Red") - actColors = (actColorBlue, actColorGreen, actColorOrange, actColorRed) + menuColor = QMenu("Highlight color", menu) + menuLayout = QMenu("PC Keyboard layout", menu) + actColors = [] + actLayouts = [] - for act in actColors: + for color in kValidColors: + act = menuColor.addAction(color) act.setCheckable(True) - if self.fHighlightColor == act.text(): + if self.fHighlightColor == color: act.setChecked(True) + actColors.append(act) - menuLayout = QMenu("PC Keyboard layout", menu) - actLayout_qwerty = menuLayout.addAction("qwerty") - actLayout_qwertz = menuLayout.addAction("qwertz") - actLayout_azerty = menuLayout.addAction("azerty") - actLayouts = (actLayout_qwerty, actLayout_qwertz, actLayout_azerty) - - for act in actLayouts: + for pcKeyLayout in kPcKeysLayouts.keys(): + act = menuLayout.addAction(pcKeyLayout) act.setCheckable(True) - if self.fkPcKeyLayout == act.text(): + if self.fkPcKeyLayout == pcKeyLayout: act.setChecked(True) + actLayouts.append(act) menu.addMenu(menuColor) menu.addMenu(menuLayout)