diff --git a/source/frontend/carla_widgets.py b/source/frontend/carla_widgets.py index 136268467e..d5a4873a22 100755 --- a/source/frontend/carla_widgets.py +++ b/source/frontend/carla_widgets.py @@ -7,6 +7,11 @@ from abc import abstractmethod +import markdown + +import subprocess +import shlex + # ------------------------------------------------------------------------------------------------------------ # Imports (PyQt) @@ -14,7 +19,7 @@ if qt_config == 5: from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QByteArray - from PyQt5.QtGui import QCursor, QIcon, QPalette, QPixmap + from PyQt5.QtGui import QCursor, QIcon, QPalette, QPixmap, QFont from PyQt5.QtWidgets import ( QDialog, QFileDialog, @@ -24,10 +29,13 @@ QScrollArea, QVBoxLayout, QWidget, + QGraphicsScene, + QGraphicsTextItem, + QGraphicsView, ) elif qt_config == 6: from PyQt6.QtCore import pyqtSignal, pyqtSlot, Qt, QByteArray - from PyQt6.QtGui import QCursor, QIcon, QPalette, QPixmap + from PyQt6.QtGui import QCursor, QIcon, QPalette, QPixmap, QFont from PyQt6.QtWidgets import ( QDialog, QFileDialog, @@ -37,6 +45,9 @@ QScrollArea, QVBoxLayout, QWidget, + QGraphicsScene, + QGraphicsTextItem, + QGraphicsView, ) # ------------------------------------------------------------------------------------------------------------ @@ -1111,6 +1122,10 @@ def reloadParameters(self): self.ui.tabWidget.currentWidget().verticalScrollBar().setValue(scrollVal) def reloadPrograms(self): + +# jpka: That's wrong place fot it of course, please move to correct one. + self._createDescriptionWidgets(self.tr("Description")) + # Programs self.ui.cb_programs.blockSignals(True) self.ui.cb_programs.clear() @@ -1808,6 +1823,92 @@ def _updateParameterValues(self): #------------------------------------------------------------------ + def _createDescriptionWidgets(self, tabPageName): + if self.fPluginInfo['type'] not in (PLUGIN_INTERNAL, PLUGIN_LV2, PLUGIN_SF2): + return + +# jpka: To be filled from 'rdfs:comment' FIXME + strDescrFlatMdHtml = "To be filled from rdfs:comment. Test **bold** & _italic_ markdown." + # This one converts to html, i.e. 'unmarkdown's. + strDescrHtml = markdown.markdown(strDescrFlatMdHtml) + + realPluginName = self.fPluginInfo['name'] or "(none)" + + if self.fPluginInfo['type'] == PLUGIN_LV2: + strTemp = self.fPluginInfo['label'] + strURI = '' + strTemp + '' + + elif self.fPluginInfo['type'] == PLUGIN_SF2: + strURI = '' + self.fPluginInfo['maker'] + ' using ' +\ + '' + self.fPluginInfo['label'] + ' sound font' + +# if with autodetection of sf2dump: +# jpka: This adds 'libgig' dependency for 'sf2dump'. +# jpka: To be filled with real .sf2 filename, line below is tests only. FIXME + strSoundFontFile = '/usr/share/sounds/sf2/' + realPluginName + '.sf2' + strCmd = 'sf2dump ' + strSoundFontFile + result = subprocess.run(shlex.split + (f'sh -c "set -o pipefail ; timeout 0.2 ' + strCmd +\ + ' | sed /Samples/q"'), + stdout=subprocess.PIPE) + ret = result.returncode + + strCmdHt = ' ' + strCmd + ' ' + + if (ret == 0): + if MACOS: +# jpka: Please check it. FIXME + strEOL = '\r' + elif WINDOWS: +# jpka: Please check it. FIXME + strEOL = '\r\n' + else: + strEOL = '\n' + strResult = result.stdout.decode('utf-8')\ + .replace('\t', ' • ')\ + .replace(strEOL, '
') +\ + 'Please use ' + strCmdHt + ' for full info.' + else: + strResult = 'Err ' + str(ret) + ' while run ' + strCmdHt + ' .' + + strDescrHtml = strResult +# if no sf2dump: + # strDescrHtml = "(No sf2dump support, sorry.)" + + else: + strURI = "Carla Internal Plugin" + + if self.host.get_program_count(self.fPluginId) == 0: + strLoadState = "" + else: + strLoadState = '

'\ + 'Note: This plugin collected some presets for you.
'\ + 'Use Edit tab, then Load State button.
' + + scene = QGraphicsScene(self) + text = QGraphicsTextItem("",None) + text.setTextInteractionFlags(Qt.TextSelectableByMouse) +# jpka: Should be like this, but not work. FIXME +# text.setTextWidth(self.ui.tabWidget.geometry().width()); +# text.setTextWidth(self.ui.tabWidget.tabs.geometry().width()); +# text.setTextWidth(self.ui.tabWidget.widget(1).geometry().width()); +# text.setTextWidth(self.ui.tabWidget.size().width()); + text.setTextWidth(600); +# text.setFont(QFont("Arial, 16")) # NOTE: All Qt sizes are in Pt; real px~=4/3Pt. + text.setHtml('' +\ + '

' + realPluginName + '


' +\ + strURI + '

' +\ + '
' + strDescrHtml + '
' +\ + strLoadState +\ + ''); + + scene.addItem(text) + view = QGraphicsView(scene, self) + + self.ui.tabWidget.addTab(view, tabPageName) + + #------------------------------------------------------------------ + def testTimer(self): self.fIdleTimerId = self.startTimer(50)