components automatically drawPreview & save currentPreset
this makes a Component easier to program. also more comments
This commit is contained in:
parent
d7b678f66d
commit
cbbb787615
|
@ -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
|
||||
|
|
|
@ -110,7 +110,6 @@ class Component(Component):
|
|||
self.page.pushButton_color2.setEnabled(False)
|
||||
self.page.fillWidget.setCurrentIndex(self.fillType)
|
||||
|
||||
self.parent.drawPreview()
|
||||
super().update()
|
||||
|
||||
def previewRender(self, previewWorker):
|
||||
|
|
|
@ -38,7 +38,7 @@ class Component(Component):
|
|||
self.yPosition = self.page.spinBox_y.value()
|
||||
self.stretched = self.page.checkBox_stretch.isChecked()
|
||||
self.mirror = self.page.checkBox_mirror.isChecked()
|
||||
self.parent.drawPreview()
|
||||
|
||||
super().update()
|
||||
|
||||
def previewRender(self, previewWorker):
|
||||
|
|
|
@ -51,7 +51,7 @@ class Component(Component):
|
|||
self.visColor = self.RGBFromString(self.page.lineEdit_visColor.text())
|
||||
self.scale = self.page.spinBox_scale.value()
|
||||
self.y = self.page.spinBox_y.value()
|
||||
self.parent.drawPreview()
|
||||
|
||||
super().update()
|
||||
|
||||
def loadPreset(self, pr, presetName=None):
|
||||
|
|
|
@ -69,7 +69,6 @@ class Component(Component):
|
|||
|
||||
def savePreset(self):
|
||||
return {
|
||||
'preset': self.currentPreset,
|
||||
'sound': self.sound,
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ class Component(Component):
|
|||
btnStyle = "QPushButton { background-color : %s; outline: none; }" \
|
||||
% QColor(*self.textColor).name()
|
||||
self.page.pushButton_textColor.setStyleSheet(btnStyle)
|
||||
self.parent.drawPreview()
|
||||
|
||||
super().update()
|
||||
|
||||
def getXY(self):
|
||||
|
|
|
@ -140,7 +140,7 @@ class Component(Component):
|
|||
self.scale = self.page.spinBox_scale.value()
|
||||
self.xPosition = self.page.spinBox_x.value()
|
||||
self.yPosition = self.page.spinBox_y.value()
|
||||
self.parent.drawPreview()
|
||||
|
||||
super().update()
|
||||
|
||||
def previewRender(self, previewWorker):
|
||||
|
|
|
@ -414,6 +414,7 @@ class Core:
|
|||
f.write('[Components]\n')
|
||||
for comp in self.selectedComponents:
|
||||
saveValueStore = comp.savePreset()
|
||||
saveValueStore['preset'] = comp.currentPreset
|
||||
f.write('%s\n' % str(comp))
|
||||
f.write('%s\n' % str(comp.version()))
|
||||
f.write('%s\n' % toolkit.presetToString(saveValueStore))
|
||||
|
|
|
@ -160,6 +160,7 @@ class PresetManager(QtWidgets.QDialog):
|
|||
selectedComponents[index].currentPreset = newName
|
||||
saveValueStore = \
|
||||
selectedComponents[index].savePreset()
|
||||
saveValueStore['preset'] = newName
|
||||
componentName = str(selectedComponents[index]).strip()
|
||||
vers = selectedComponents[index].version()
|
||||
self.createNewPreset(
|
||||
|
|
Reference in New Issue