|
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
-
- # DISTRHO Notes Plugin
- # Copyright (C) 2012-2013 Filipe Coelho <falktx@falktx.com>
- #
- # This program is free software; you can redistribute it and/or
- # modify it under the terms of the GNU General Public License as
- # published by the Free Software Foundation; either version 2 of
- # the License, or any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # For a full copy of the GNU General Public License see the GPL.txt file
-
- # ------------------------------------------------------------------------------------------------------------
- # Imports (Global)
-
- from numpy import rint
- from sys import argv, exit
-
- from PyQt4.QtCore import pyqtSlot
- from PyQt4.QtGui import QApplication, QGridLayout, QLabel, QPushButton, QTextEdit, QWidget
-
- # -----------------------------------------------------------------------
- # Imports (ExternalUI)
-
- from carla_style import CarlaApplication
- from externalui import ExternalUI
- from paramspinbox import ParamSpinBox
-
- import resources_rc
-
- # -----------------------------------------------------------------------
- # External UI
-
- class DistrhoUINotes(QWidget, ExternalUI):
- def __init__(self):
- QWidget.__init__(self, None)
- ExternalUI.__init__(self)
-
- self.fCurPage = 1
- self.fSaveSizeNowChecker = -1
- self.fSaveTextNowChecker = -1
- self.fNotes = ["" for x in range(100)]
-
- self.fTextEdit = QTextEdit(self)
- self.fButton = QPushButton(self)
- self.fProgressBar = ParamSpinBox(self)
- self.fSpacer = QLabel(self)
- self.fGridLayout = QGridLayout(self)
-
- self.fButton.setCheckable(True)
- self.fButton.setChecked(True)
- self.fButton.setText("Edit")
- self.fButton.setFixedSize(self.fButton.minimumSizeHint())
-
- self.fProgressBar.setMinimum(1.0)
- self.fProgressBar.setMaximum(100.0)
- self.fProgressBar.setValue(1.0)
- self.fProgressBar.setStep(1.0)
- self.fProgressBar.setStepSmall(1.0)
- self.fProgressBar.setStepLarge(10.0)
-
- self.fSpacer.setText("")
- self.fSpacer.setFixedSize(5, 5)
-
- self.fTextEdit.setReadOnly(False)
-
- self.setLayout(self.fGridLayout)
- self.fGridLayout.addWidget(self.fTextEdit, 0, 0, 1, 3)
- self.fGridLayout.addWidget(self.fButton, 1, 0, 1, 1)
- self.fGridLayout.addWidget(self.fProgressBar, 1, 1, 1, 1)
- self.fGridLayout.addWidget(self.fSpacer, 1, 2, 1, 1)
- self.fGridLayout.setContentsMargins(0, 0, 0, 0)
-
- self.fButton.clicked.connect(self.slot_buttonClicked)
- self.fProgressBar.valueChanged.connect(self.slot_progressBarValueChanged)
- self.fTextEdit.textChanged.connect(self.slot_textChanged)
-
- self.resize(300, 200)
- self.setWindowTitle(self.fUiName)
-
- self.fIdleTimer = self.startTimer(50)
-
- self.showUiIfTesting()
-
- def saveCurrentTextState(self):
- pageKey = "pageText %i" % self.fCurPage
- pageValue = self.fTextEdit.toPlainText()
-
- if pageValue != self.fNotes[self.fCurPage-1]:
- self.fNotes[self.fCurPage-1] = pageValue
- self.d_setState(pageKey, pageValue)
-
- # -------------------------------------------------------------------
-
- @pyqtSlot(bool)
- def slot_buttonClicked(self, click):
- readOnly = not click
- self.fTextEdit.setReadOnly(readOnly)
- self.d_setState("readOnly", "yes" if readOnly else "no")
-
- @pyqtSlot(float)
- def slot_progressBarValueChanged(self, value):
- value = rint(value)
-
- if self.fCurPage == int(value):
- return
-
- # maybe save current text before changing page
- if self.fSaveTextNowChecker >= 0 and value >= 1.0 and value <= 100.0:
- self.saveCurrentTextState()
- self.fSaveTextNowChecker = -1
-
- # change current page
- self.d_parameterChanged(0, value)
-
- # tell host about this change
- self.d_setParameterValue(0, value)
-
- @pyqtSlot()
- def slot_textChanged(self):
- self.fSaveTextNowChecker = 0
-
- # -------------------------------------------------------------------
- # DSP Callbacks
-
- def d_parameterChanged(self, index, value):
- if index != 0:
- return
-
- nextCurPage = int(value)
-
- if nextCurPage != self.fCurPage and nextCurPage >= 1 and nextCurPage <= 100:
- self.saveCurrentTextState()
- self.fCurPage = nextCurPage
-
- self.fTextEdit.setPlainText(self.fNotes[self.fCurPage-1])
- self.fProgressBar.setValue(self.fCurPage)
- self.fProgressBar.update()
-
- def d_stateChanged(self, key, value):
- if key == "guiWidth":
- try:
- width = int(value)
- except:
- width = 0
-
- if width > 0:
- self.resize(width, self.height())
-
- elif key == "guiHeight":
- try:
- height = int(value)
- except:
- height = 0
-
- if height > 0:
- self.resize(self.width(), height)
-
- elif key.startswith("pageText #"):
- try:
- pageIndex = int(key.replace("pageText #",""))
- except:
- pageIndex = 0
-
- if pageIndex >= 1 and pageIndex <= 100:
- self.fNotes[pageIndex-1] = value
-
- if pageIndex == self.fCurPage:
- self.fTextEdit.setPlainText(self.fNotes[pageIndex-1])
-
- elif key == "readOnly":
- readOnly = (value == "yes")
- self.fButton.setChecked(not readOnly)
- self.fTextEdit.setReadOnly(readOnly)
-
- # -------------------------------------------------------------------
- # ExternalUI Callbacks
-
- def d_uiShow(self):
- self.show()
-
- def d_uiHide(self):
- self.hide()
-
- def d_uiQuit(self):
- self.close()
- app.quit()
-
- def d_uiTitleChanged(self, uiTitle):
- self.setWindowTitle(uiTitle)
-
- # -------------------------------------------------------------------
- # Qt events
-
- def resizeEvent(self, event):
- self.fSaveSizeNowChecker = 0
- QWidget.resizeEvent(self, event)
-
- def timerEvent(self, event):
- if event.timerId() == self.fIdleTimer:
- if self.fSaveSizeNowChecker == 11:
- self.d_setState("guiWidth", str(self.width()))
- self.d_setState("guiHeight", str(self.height()))
- self.fSaveSizeNowChecker = -1
- elif self.fSaveSizeNowChecker >= 0:
- self.fSaveSizeNowChecker += 1
-
- if self.fSaveTextNowChecker == 11:
- self.saveCurrentTextState()
- self.fSaveTextNowChecker = -1
- elif self.fSaveTextNowChecker >= 0:
- self.fSaveTextNowChecker += 1
-
- if not self.idleExternalUI():
- self.d_uiQuit()
-
- QWidget.timerEvent(self, event)
-
- def closeEvent(self, event):
- self.closeExternalUI()
- QWidget.closeEvent(self, event)
-
- #--------------- main ------------------
- if __name__ == '__main__':
- app = CarlaApplication()
- #app...
- gui = DistrhoUINotes()
- exit(app.exec_())
|