Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pixmapkeyboard.py 19KB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Pixmap Keyboard, a custom Qt widget
  4. # Copyright (C) 2011-2020 Filipe Coelho <falktx@falktx.com>
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License as
  8. # published by the Free Software Foundation; either version 2 of
  9. # the License, or any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # For a full copy of the GNU General Public License see the doc/GPL.txt file.
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Global)
  19. from PyQt5.QtCore import pyqtSignal, pyqtSlot, qCritical, Qt, QPointF, QRectF, QTimer, QSize
  20. from PyQt5.QtGui import QColor, QFont, QPainter, QPixmap
  21. from PyQt5.QtWidgets import QActionGroup, QMenu, QScrollArea, QWidget
  22. # ------------------------------------------------------------------------------------------------------------
  23. # Imports (Custom)
  24. from carla_shared import QSafeSettings
  25. # ------------------------------------------------------------------------------------------------------------
  26. kMidiKey2RectMapHorizontal = [
  27. QRectF(0, 0, 24, 57), # C
  28. QRectF(14, 0, 15, 33), # C#
  29. QRectF(24, 0, 24, 57), # D
  30. QRectF(42, 0, 15, 33), # D#
  31. QRectF(48, 0, 24, 57), # E
  32. QRectF(72, 0, 24, 57), # F
  33. QRectF(84, 0, 15, 33), # F#
  34. QRectF(96, 0, 24, 57), # G
  35. QRectF(112, 0, 15, 33), # G#
  36. QRectF(120, 0, 24, 57), # A
  37. QRectF(140, 0, 15, 33), # A#
  38. QRectF(144, 0, 24, 57), # B
  39. ]
  40. kMidiKey2RectMapVertical = [
  41. QRectF(0, 144, 57, 24), # C
  42. QRectF(0, 139, 33, 15), # C#
  43. QRectF(0, 120, 57, 24), # D
  44. QRectF(0, 111, 33, 15), # D#
  45. QRectF(0, 96, 57, 24), # E
  46. QRectF(0, 72, 57, 24), # F
  47. QRectF(0, 69, 33, 15), # F#
  48. QRectF(0, 48, 57, 24), # G
  49. QRectF(0, 41, 33, 15), # G#
  50. QRectF(0, 24, 57, 24), # A
  51. QRectF(0, 13, 33, 15), # A#
  52. QRectF(0, 0, 57, 24), # B
  53. ]
  54. kPcKeys_qwerty = [
  55. # 1st octave
  56. str(Qt.Key_Z),
  57. str(Qt.Key_S),
  58. str(Qt.Key_X),
  59. str(Qt.Key_D),
  60. str(Qt.Key_C),
  61. str(Qt.Key_V),
  62. str(Qt.Key_G),
  63. str(Qt.Key_B),
  64. str(Qt.Key_H),
  65. str(Qt.Key_N),
  66. str(Qt.Key_J),
  67. str(Qt.Key_M),
  68. # 2nd octave
  69. str(Qt.Key_Q),
  70. str(Qt.Key_2),
  71. str(Qt.Key_W),
  72. str(Qt.Key_3),
  73. str(Qt.Key_E),
  74. str(Qt.Key_R),
  75. str(Qt.Key_5),
  76. str(Qt.Key_T),
  77. str(Qt.Key_6),
  78. str(Qt.Key_Y),
  79. str(Qt.Key_7),
  80. str(Qt.Key_U),
  81. # 3rd octave
  82. str(Qt.Key_I),
  83. str(Qt.Key_9),
  84. str(Qt.Key_O),
  85. str(Qt.Key_0),
  86. str(Qt.Key_P),
  87. ]
  88. kPcKeys_qwertz = [
  89. # 1st octave
  90. str(Qt.Key_Y),
  91. str(Qt.Key_S),
  92. str(Qt.Key_X),
  93. str(Qt.Key_D),
  94. str(Qt.Key_C),
  95. str(Qt.Key_V),
  96. str(Qt.Key_G),
  97. str(Qt.Key_B),
  98. str(Qt.Key_H),
  99. str(Qt.Key_N),
  100. str(Qt.Key_J),
  101. str(Qt.Key_M),
  102. # 2nd octave
  103. str(Qt.Key_Q),
  104. str(Qt.Key_2),
  105. str(Qt.Key_W),
  106. str(Qt.Key_3),
  107. str(Qt.Key_E),
  108. str(Qt.Key_R),
  109. str(Qt.Key_5),
  110. str(Qt.Key_T),
  111. str(Qt.Key_6),
  112. str(Qt.Key_Z),
  113. str(Qt.Key_7),
  114. str(Qt.Key_U),
  115. # 3rd octave
  116. str(Qt.Key_I),
  117. str(Qt.Key_9),
  118. str(Qt.Key_O),
  119. str(Qt.Key_0),
  120. str(Qt.Key_P),
  121. ]
  122. kPcKeys_azerty = [
  123. # 1st octave
  124. str(Qt.Key_W),
  125. str(Qt.Key_S),
  126. str(Qt.Key_X),
  127. str(Qt.Key_D),
  128. str(Qt.Key_C),
  129. str(Qt.Key_V),
  130. str(Qt.Key_G),
  131. str(Qt.Key_B),
  132. str(Qt.Key_H),
  133. str(Qt.Key_N),
  134. str(Qt.Key_J),
  135. str(Qt.Key_Comma),
  136. # 2nd octave
  137. str(Qt.Key_A),
  138. str(Qt.Key_Eacute),
  139. str(Qt.Key_Z),
  140. str(Qt.Key_QuoteDbl),
  141. str(Qt.Key_E),
  142. str(Qt.Key_R),
  143. str(Qt.Key_ParenLeft),
  144. str(Qt.Key_T),
  145. str(Qt.Key_Minus),
  146. str(Qt.Key_Y),
  147. str(Qt.Key_Egrave),
  148. str(Qt.Key_U),
  149. # 3rd octave
  150. str(Qt.Key_I),
  151. str(Qt.Key_Ccedilla),
  152. str(Qt.Key_O),
  153. str(Qt.Key_Agrave),
  154. str(Qt.Key_P),
  155. ]
  156. kPcKeysLayouts = {
  157. 'qwerty': kPcKeys_qwerty,
  158. 'qwertz': kPcKeys_qwertz,
  159. 'azerty': kPcKeys_azerty,
  160. }
  161. kValidColors = ("Blue", "Green", "Orange", "Red")
  162. kBlackNotes = (1, 3, 6, 8, 10)
  163. # ------------------------------------------------------------------------------------------------------------
  164. # MIDI Keyboard, using a pixmap for painting
  165. class PixmapKeyboard(QWidget):
  166. # signals
  167. noteOn = pyqtSignal(int)
  168. noteOff = pyqtSignal(int)
  169. notesOn = pyqtSignal()
  170. notesOff = pyqtSignal()
  171. def __init__(self, parent):
  172. QWidget.__init__(self, parent)
  173. self.fEnabledKeys = []
  174. self.fLastMouseNote = -1
  175. self.fStartOctave = 0
  176. self.fPcKeybOffset = 2
  177. self.fInitalizing = True
  178. self.fFont = self.font()
  179. self.fFont.setFamily("Monospace")
  180. self.fFont.setPixelSize(12)
  181. self.fFont.setBold(True)
  182. self.fPixmapNormal = QPixmap(":/bitmaps/kbd_normal.png")
  183. self.fPixmapDown = QPixmap(":/bitmaps/kbd_down-blue.png")
  184. self.fHighlightColor = kValidColors[0]
  185. self.fkPcKeyLayout = "qwerty"
  186. self.fkPcKeys = kPcKeysLayouts["qwerty"]
  187. self.fKey2RectMap = kMidiKey2RectMapHorizontal
  188. self.fWidth = self.fPixmapNormal.width()
  189. self.fHeight = self.fPixmapNormal.height()
  190. self.setCursor(Qt.PointingHandCursor)
  191. self.setStartOctave(0)
  192. self.setOctaves(6)
  193. self.loadSettings()
  194. self.fInitalizing = False
  195. def saveSettings(self):
  196. if self.fInitalizing:
  197. return
  198. settings = QSafeSettings("falkTX", "CarlaKeyboard")
  199. settings.setValue("PcKeyboardLayout", self.fkPcKeyLayout)
  200. settings.setValue("PcKeyboardOffset", self.fPcKeybOffset)
  201. settings.setValue("HighlightColor", self.fHighlightColor)
  202. del settings
  203. def loadSettings(self):
  204. settings = QSafeSettings("falkTX", "CarlaKeyboard")
  205. self.setPcKeyboardLayout(settings.value("PcKeyboardLayout", self.fkPcKeyLayout, str))
  206. self.setPcKeyboardOffset(settings.value("PcKeyboardOffset", self.fPcKeybOffset, int))
  207. self.setColor(settings.value("HighlightColor", self.fHighlightColor, str))
  208. del settings
  209. def allNotesOff(self, sendSignal=True):
  210. self.fEnabledKeys = []
  211. if sendSignal:
  212. self.notesOff.emit()
  213. self.update()
  214. def sendNoteOn(self, note, sendSignal=True):
  215. if 0 <= note <= 127 and note not in self.fEnabledKeys:
  216. self.fEnabledKeys.append(note)
  217. if sendSignal:
  218. self.noteOn.emit(note)
  219. self.update()
  220. if len(self.fEnabledKeys) == 1:
  221. self.notesOn.emit()
  222. def sendNoteOff(self, note, sendSignal=True):
  223. if 0 <= note <= 127 and note in self.fEnabledKeys:
  224. self.fEnabledKeys.remove(note)
  225. if sendSignal:
  226. self.noteOff.emit(note)
  227. self.update()
  228. if len(self.fEnabledKeys) == 0:
  229. self.notesOff.emit()
  230. def setColor(self, color):
  231. if color not in kValidColors:
  232. return
  233. if self.fHighlightColor == color:
  234. return
  235. self.fHighlightColor = color
  236. self.fPixmapDown.load(":/bitmaps/kbd_down-{}.png".format(color.lower()))
  237. self.saveSettings()
  238. def setPcKeyboardLayout(self, layout):
  239. if layout not in kPcKeysLayouts.keys():
  240. return
  241. if self.fkPcKeyLayout == layout:
  242. return
  243. self.fkPcKeyLayout = layout
  244. self.fkPcKeys = kPcKeysLayouts[layout]
  245. self.saveSettings()
  246. def setPcKeyboardOffset(self, offset):
  247. if offset < 0:
  248. offset = 0
  249. elif offset > 9:
  250. offset = 9
  251. if self.fPcKeybOffset == offset:
  252. return
  253. self.fPcKeybOffset = offset
  254. self.saveSettings()
  255. def setOctaves(self, octaves):
  256. if octaves < 1:
  257. octaves = 1
  258. elif octaves > 10:
  259. octaves = 10
  260. self.fOctaves = octaves
  261. self.setMinimumSize(self.fWidth * self.fOctaves, self.fHeight)
  262. self.setMaximumSize(self.fWidth * self.fOctaves, self.fHeight)
  263. def setStartOctave(self, octave):
  264. if octave < 0:
  265. octave = 0
  266. elif octave > 9:
  267. octave = 9
  268. if self.fStartOctave == octave:
  269. return
  270. self.fStartOctave = octave
  271. self.update()
  272. def handleMousePos(self, pos):
  273. if pos.x() < 0 or pos.x() > self.fOctaves * self.fWidth:
  274. return
  275. octave = int(pos.x() / self.fWidth)
  276. keyPos = QPointF(pos.x() % self.fWidth, pos.y())
  277. if self.fKey2RectMap[1].contains(keyPos): # C#
  278. note = 1
  279. elif self.fKey2RectMap[ 3].contains(keyPos): # D#
  280. note = 3
  281. elif self.fKey2RectMap[ 6].contains(keyPos): # F#
  282. note = 6
  283. elif self.fKey2RectMap[ 8].contains(keyPos): # G#
  284. note = 8
  285. elif self.fKey2RectMap[10].contains(keyPos): # A#
  286. note = 10
  287. elif self.fKey2RectMap[ 0].contains(keyPos): # C
  288. note = 0
  289. elif self.fKey2RectMap[ 2].contains(keyPos): # D
  290. note = 2
  291. elif self.fKey2RectMap[ 4].contains(keyPos): # E
  292. note = 4
  293. elif self.fKey2RectMap[ 5].contains(keyPos): # F
  294. note = 5
  295. elif self.fKey2RectMap[ 7].contains(keyPos): # G
  296. note = 7
  297. elif self.fKey2RectMap[ 9].contains(keyPos): # A
  298. note = 9
  299. elif self.fKey2RectMap[11].contains(keyPos): # B
  300. note = 11
  301. else:
  302. note = -1
  303. if note != -1:
  304. note += (self.fStartOctave + octave) * 12
  305. if self.fLastMouseNote != note:
  306. self.sendNoteOff(self.fLastMouseNote)
  307. self.sendNoteOn(note)
  308. elif self.fLastMouseNote != -1:
  309. self.sendNoteOff(self.fLastMouseNote)
  310. self.fLastMouseNote = note
  311. def showOptions(self, event):
  312. event.accept()
  313. menu = QMenu()
  314. menu.addAction(self.tr("Note: restart carla to apply globally")).setEnabled(False)
  315. menu.addAction(self.tr("Color")).setSeparator(True)
  316. groupColor = QActionGroup(menu)
  317. groupLayout = QActionGroup(menu)
  318. actColors = []
  319. actLayouts = []
  320. menu.addAction(self.tr("Highlight color")).setSeparator(True)
  321. for color in kValidColors:
  322. act = menu.addAction(color)
  323. act.setActionGroup(groupColor)
  324. act.setCheckable(True)
  325. if self.fHighlightColor == color:
  326. act.setChecked(True)
  327. actColors.append(act)
  328. menu.addAction(self.tr("PC Keyboard layout")).setSeparator(True)
  329. for pcKeyLayout in kPcKeysLayouts.keys():
  330. act = menu.addAction(pcKeyLayout)
  331. act.setActionGroup(groupLayout)
  332. act.setCheckable(True)
  333. if self.fkPcKeyLayout == pcKeyLayout:
  334. act.setChecked(True)
  335. actLayouts.append(act)
  336. menu.addAction(self.tr("PC Keyboard base octave (%i)" % self.fPcKeybOffset)).setSeparator(True)
  337. actOctaveUp = menu.addAction(self.tr("Octave up"))
  338. actOctaveDown = menu.addAction(self.tr("Octave down"))
  339. if self.fPcKeybOffset == 0:
  340. actOctaveDown.setEnabled(False)
  341. actSelected = menu.exec_(event.screenPos().toPoint())
  342. if not actSelected:
  343. return
  344. if actSelected in actColors:
  345. return self.setColor(actSelected.text())
  346. if actSelected in actLayouts:
  347. return self.setPcKeyboardLayout(actSelected.text())
  348. if actSelected == actOctaveUp:
  349. return self.setPcKeyboardOffset(self.fPcKeybOffset + 1)
  350. if actSelected == actOctaveDown:
  351. return self.setPcKeyboardOffset(self.fPcKeybOffset - 1)
  352. def minimumSizeHint(self):
  353. return QSize(self.fWidth, self.fHeight)
  354. def sizeHint(self):
  355. return QSize(self.fWidth * self.fOctaves, self.fHeight)
  356. def keyPressEvent(self, event):
  357. if not event.isAutoRepeat():
  358. try:
  359. qKey = str(event.key())
  360. index = self.fkPcKeys.index(qKey)
  361. except:
  362. pass
  363. else:
  364. self.sendNoteOn(index+(self.fPcKeybOffset*12))
  365. QWidget.keyPressEvent(self, event)
  366. def keyReleaseEvent(self, event):
  367. if not event.isAutoRepeat():
  368. try:
  369. qKey = str(event.key())
  370. index = self.fkPcKeys.index(qKey)
  371. except:
  372. pass
  373. else:
  374. self.sendNoteOff(index+(self.fPcKeybOffset*12))
  375. QWidget.keyReleaseEvent(self, event)
  376. def mousePressEvent(self, event):
  377. if event.button() == Qt.RightButton:
  378. self.showOptions(event)
  379. else:
  380. self.fLastMouseNote = -1
  381. self.handleMousePos(event.pos())
  382. self.setFocus()
  383. QWidget.mousePressEvent(self, event)
  384. def mouseMoveEvent(self, event):
  385. if event.button() != Qt.RightButton:
  386. self.handleMousePos(event.pos())
  387. QWidget.mouseMoveEvent(self, event)
  388. def mouseReleaseEvent(self, event):
  389. if self.fLastMouseNote != -1:
  390. self.sendNoteOff(self.fLastMouseNote)
  391. self.fLastMouseNote = -1
  392. QWidget.mouseReleaseEvent(self, event)
  393. def paintEvent(self, event):
  394. painter = QPainter(self)
  395. event.accept()
  396. # -------------------------------------------------------------
  397. # Paint clean keys (as background)
  398. for octave in range(self.fOctaves):
  399. target = QRectF(self.fWidth * octave, 0, self.fWidth, self.fHeight)
  400. source = QRectF(0, 0, self.fWidth, self.fHeight)
  401. painter.drawPixmap(target, self.fPixmapNormal, source)
  402. if not self.isEnabled():
  403. painter.setBrush(QColor(0, 0, 0, 150))
  404. painter.setPen(QColor(0, 0, 0, 150))
  405. painter.drawRect(0, 0, self.width(), self.height())
  406. return
  407. # -------------------------------------------------------------
  408. # Paint (white) pressed keys
  409. paintedWhite = False
  410. for note in self.fEnabledKeys:
  411. pos = self._getRectFromMidiNote(note)
  412. if self._isNoteBlack(note):
  413. continue
  414. if note < 12:
  415. octave = 0
  416. elif note < 24:
  417. octave = 1
  418. elif note < 36:
  419. octave = 2
  420. elif note < 48:
  421. octave = 3
  422. elif note < 60:
  423. octave = 4
  424. elif note < 72:
  425. octave = 5
  426. elif note < 84:
  427. octave = 6
  428. elif note < 96:
  429. octave = 7
  430. elif note < 108:
  431. octave = 8
  432. elif note < 120:
  433. octave = 9
  434. elif note < 132:
  435. octave = 10
  436. else:
  437. # cannot paint this note
  438. continue
  439. octave -= self.fStartOctave
  440. target = QRectF(pos.x() + (self.fWidth * octave), 0, pos.width(), pos.height())
  441. source = QRectF(pos.x(), 0, pos.width(), pos.height())
  442. paintedWhite = True
  443. painter.drawPixmap(target, self.fPixmapDown, source)
  444. # -------------------------------------------------------------
  445. # Clear white keys border
  446. if paintedWhite:
  447. for octave in range(self.fOctaves):
  448. for note in kBlackNotes:
  449. pos = self._getRectFromMidiNote(note)
  450. target = QRectF(pos.x() + (self.fWidth * octave), 0, pos.width(), pos.height())
  451. source = QRectF(pos.x(), 0, pos.width(), pos.height())
  452. painter.drawPixmap(target, self.fPixmapNormal, source)
  453. # -------------------------------------------------------------
  454. # Paint (black) pressed keys
  455. for note in self.fEnabledKeys:
  456. pos = self._getRectFromMidiNote(note)
  457. if not self._isNoteBlack(note):
  458. continue
  459. if note < 12:
  460. octave = 0
  461. elif note < 24:
  462. octave = 1
  463. elif note < 36:
  464. octave = 2
  465. elif note < 48:
  466. octave = 3
  467. elif note < 60:
  468. octave = 4
  469. elif note < 72:
  470. octave = 5
  471. elif note < 84:
  472. octave = 6
  473. elif note < 96:
  474. octave = 7
  475. elif note < 108:
  476. octave = 8
  477. elif note < 120:
  478. octave = 9
  479. elif note < 132:
  480. octave = 10
  481. else:
  482. # cannot paint this note
  483. continue
  484. octave -= self.fStartOctave
  485. target = QRectF(pos.x() + (self.fWidth * octave), 0, pos.width(), pos.height())
  486. source = QRectF(pos.x(), 0, pos.width(), pos.height())
  487. painter.drawPixmap(target, self.fPixmapDown, source)
  488. # Paint C-number note info
  489. painter.setFont(self.fFont)
  490. painter.setPen(Qt.black)
  491. for i in range(self.fOctaves):
  492. octave = self.fStartOctave + i - 1
  493. painter.drawText(i * 168 + (4 if octave == -1 else 3),
  494. 35, 20, 20,
  495. Qt.AlignCenter,
  496. "C{}".format(octave))
  497. def _isNoteBlack(self, note):
  498. baseNote = note % 12
  499. return bool(baseNote in kBlackNotes)
  500. def _getRectFromMidiNote(self, note):
  501. baseNote = note % 12
  502. return self.fKey2RectMap[baseNote]
  503. # ------------------------------------------------------------------------------------------------------------
  504. # Horizontal scroll area for keyboard
  505. class PixmapKeyboardHArea(QScrollArea):
  506. def __init__(self, parent):
  507. QScrollArea.__init__(self, parent)
  508. self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
  509. self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
  510. self.keyboard = PixmapKeyboard(self)
  511. self.keyboard.setOctaves(10)
  512. self.setWidget(self.keyboard)
  513. self.setEnabled(False)
  514. self.setFixedHeight(int(self.keyboard.height() + self.horizontalScrollBar().height()/2 + 2))
  515. QTimer.singleShot(0, self.slot_initScrollbarValue)
  516. # FIXME use change event
  517. def setEnabled(self, yesNo):
  518. self.keyboard.setEnabled(yesNo)
  519. QScrollArea.setEnabled(self, yesNo)
  520. @pyqtSlot()
  521. def slot_initScrollbarValue(self):
  522. self.horizontalScrollBar().setValue(int(self.horizontalScrollBar().maximum()/2))
  523. # ------------------------------------------------------------------------------------------------------------
  524. # Main Testing
  525. if __name__ == '__main__':
  526. import sys
  527. from PyQt5.QtWidgets import QApplication
  528. import resources_rc
  529. app = QApplication(sys.argv)
  530. gui = PixmapKeyboard(None)
  531. gui.setEnabled(True)
  532. gui.show()
  533. sys.exit(app.exec_())