From cbbb7876155cdb057b0d779cb8ab7bc1f31116b0 Mon Sep 17 00:00:00 2001 From: tassaron Date: Thu, 13 Jul 2017 21:59:23 -0400 Subject: components automatically drawPreview & save currentPreset this makes a Component easier to program. also more comments --- src/component.py | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'src/component.py') diff --git a/src/component.py b/src/component.py index eea82d7..2b297d1 100644 --- a/src/component.py +++ b/src/component.py @@ -24,7 +24,9 @@ class Component(QtCore.QObject): return self.__doc__ def version(self): - # change this number to identify new versions of a component + ''' + Change this number to identify new versions of a component + ''' return 1 def properties(self): @@ -42,15 +44,22 @@ class Component(QtCore.QObject): return def cancel(self): - # please stop any lengthy process in response to this variable + ''' + Stop any lengthy process in response to this variable + ''' self.canceled = True def reset(self): self.canceled = False def update(self): - self.modified.emit(self.compPos, self.savePreset()) - # read your widget values, then call super().update() + ''' + Read your widget values from self.page, then call super().update() + ''' + self.parent.drawPreview() + saveValueStore = self.savePreset() + saveValueStore['preset'] = self.currentPreset + self.modified.emit(self.compPos, saveValueStore) def loadPreset(self, presetDict, presetName): ''' @@ -72,8 +81,8 @@ class Component(QtCore.QObject): Use the latter two signals to update the MainWindow if needed for a long initialization procedure (i.e., for a visualizer) ''' - for var, value in kwargs.items(): - exec('self.%s = value' % var) + for key, value in kwargs.items(): + setattr(self, key, value) def command(self, arg): ''' @@ -143,16 +152,11 @@ class Component(QtCore.QObject): def widget(self, parent): self.parent = parent - page = uic.loadUi(os.path.join( - os.path.dirname(os.path.realpath(__file__)), 'example.ui')) + page = self.loadUi('example.ui') # --- connect widget signals here --- self.page = page return page - def update(self): - self.parent.drawPreview() - super().update() - def previewRender(self, previewWorker): width = int(previewWorker.core.settings.value('outputWidth')) height = int(previewWorker.core.settings.value('outputHeight')) @@ -170,8 +174,12 @@ class Component(QtCore.QObject): def audio(self): \''' - Return audio to mix into master as a string (path to audio file), - or an object that returns raw audio data [future feature]. + Return audio to mix into master as a tuple with two elements: + The first element can be: + - A string (path to audio file), + - Or an object that returns audio data through a pipe + The second element must be a dictionary of ffmpeg parameters + to apply to the input stream. \''' @classmethod -- cgit v1.2.3