the most simple way of saving dictionaries

This commit is contained in:
tassaron 2017-05-30 19:31:10 -04:00
parent 7240f25deb
commit ca7e8bdb0d
3 changed files with 35 additions and 10 deletions

View File

@ -3,6 +3,9 @@ from PyQt4 import QtGui
class Component:
def __str__(self):
return self.__doc__
def version(self):
return 1
def preFrameRender(self, **kwargs):
for kwarg, value in kwargs.items():
@ -54,4 +57,8 @@ class Component:
height = int(self.worker.core.settings.value('outputHeight'))
image = Image.new("RGBA", (width, height), (0,0,0,0))
return image
def version(self):
# change this number to identify new versions of your component
return 1
'''

View File

@ -32,11 +32,13 @@ class Component(__base__.Component):
self.visColor = self.RGBFromString(self.page.lineEdit_visColor.text())
self.parent.drawPreview()
def version(self):
return 1
def loadPreset(self, presetDict):
self.preFrameRender(**presetDict)
def savePreset(self):
return {}
return { 'layout' : self.page.comboBox_visLayout.currentIndex(),
'visColor' : self.page.lineEdit_visColor.text(),
}
def previewRender(self, previewWorker):
spectrum = numpy.fromfunction(lambda x: 0.008*(x-128)**2, (255,), dtype="int16")

30
main.py
View File

@ -179,9 +179,7 @@ class Main(QtCore.QObject):
self.window.pushButton_listMoveDown.clicked.connect(self.moveComponentDown)
self.window.pushButton_savePreset.clicked.connect(self.openSavePresetDialog)
self.window.comboBox_openPreset.currentIndexChanged.connect( \
lambda _: self.openPreset(self.window.comboBox_openPreset.currentIndex())
)
self.window.comboBox_openPreset.currentIndexChanged.connect(self.openPreset)
self.drawPreview()
@ -380,12 +378,30 @@ class Main(QtCore.QObject):
if not os.path.exists(dirname):
os.makedirs(dirname)
with open(os.path.join(dirname, filename), 'w') as f:
for itemset in saveValueStore.items():
f.write('%s=%s' % itemset)
f.write('%s' % repr(saveValueStore))
self.window.comboBox_openPreset.addItem(filename)
def openPreset(self, comboBoxIndex):
pass
def openPreset(self):
if self.window.comboBox_openPreset.currentIndex() < 1:
return
index = self.window.listWidget_componentList.currentRow()
if index == -1:
# no component selected
return
filename = self.window.comboBox_openPreset.itemText(self.window.comboBox_openPreset.currentIndex())
componentName = str(self.selectedComponents[index]).strip()
version = self.selectedComponents[index].version()
dirname = os.path.join(self.dataDir, 'presets', componentName, str(version))
filepath = os.path.join(dirname, filename)
if not os.path.exists(filepath):
self.window.comboBox_openPreset.removeItem(self.window.comboBox_openPreset.currentIndex())
return
with open(filepath, 'r') as f:
for line in f:
saveValueStore = eval(line.strip())
break
print(saveValueStore)
def LoadDefaultSettings(self):