aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--components/__base__.py22
-rw-r--r--components/original.py13
-rw-r--r--components/text.py25
-rw-r--r--main.py46
4 files changed, 84 insertions, 22 deletions
diff --git a/components/__base__.py b/components/__base__.py
index 87440bb..05d5cb6 100644
--- a/components/__base__.py
+++ b/components/__base__.py
@@ -3,17 +3,23 @@ from PyQt4 import QtGui
class Component:
def __str__(self):
return self.__doc__
+
+ def version(self):
+ # change this number to identify new versions of a component
+ return 1
def preFrameRender(self, **kwargs):
- for kwarg, value in kwargs.items():
- exec('self.%s = value' % kwarg)
+ for item in kwargs.items():
+ exec('self.%s = %s' % item)
def pickColor(self):
color = QtGui.QColorDialog.getColor()
if color.isValid():
- RGBstring = '%s,%s,%s' % (str(color.red()), str(color.green()), str(color.blue()))
- btnStyle = "QPushButton { background-color : %s; outline: none; }" % color.name()
- return RGBstring, btnStyle
+ RGBstring = '%s,%s,%s' % (str(color.red()), str(color.green()), str(color.blue()))
+ btnStyle = "QPushButton { background-color : %s; outline: none; }" % color.name()
+ return RGBstring, btnStyle
+ else:
+ return None, None
def RGBFromString(self, string):
''' turns an RGB string like "255, 255, 255" into a tuple '''
@@ -54,4 +60,10 @@ class Component:
height = int(self.worker.core.settings.value('outputHeight'))
image = Image.new("RGBA", (width, height), (0,0,0,0))
return image
+
+ def loadPreset(self, presetDict):
+ # update widgets using a preset dict
+
+ def savePreset(self):
+ return {}
'''
diff --git a/components/original.py b/components/original.py
index 47e53b8..bebfdf2 100644
--- a/components/original.py
+++ b/components/original.py
@@ -32,11 +32,16 @@ class Component(__base__.Component):
self.visColor = self.RGBFromString(self.page.lineEdit_visColor.text())
self.parent.drawPreview()
- def version(self):
- return 1
+ def loadPreset(self, pr):
+ self.page.lineEdit_visColor.setText('%s,%s,%s' % pr['visColor'])
+ btnStyle = "QPushButton { background-color : %s; outline: none; }" % QColor(*pr['visColor']).name()
+ self.page.pushButton_visColor.setStyleSheet(btnStyle)
+ self.page.comboBox_visLayout.setCurrentIndex(pr['layout'])
def savePreset(self):
- return {}
+ return { 'layout' : self.layout,
+ 'visColor' : self.visColor,
+ }
def previewRender(self, previewWorker):
spectrum = numpy.fromfunction(lambda x: 0.008*(x-128)**2, (255,), dtype="int16")
@@ -59,6 +64,8 @@ class Component(__base__.Component):
def pickColor(self):
RGBstring, btnStyle = super().pickColor()
+ if not RGBstring:
+ return
self.page.lineEdit_visColor.setText(RGBstring)
self.page.pushButton_visColor.setStyleSheet(btnStyle)
diff --git a/components/text.py b/components/text.py
index c9359f2..23e65eb 100644
--- a/components/text.py
+++ b/components/text.py
@@ -53,9 +53,6 @@ class Component(__base__.Component):
self.page = page
return page
- def version(self):
- return 1
-
def update(self):
self.title = self.page.lineEdit_title.text()
self.alignment = self.page.comboBox_textAlign.currentIndex()
@@ -71,11 +68,27 @@ class Component(__base__.Component):
self.xPosition = self.xPosition - fm.width(self.title)/2
if self.alignment == 2: #Right
self.xPosition = self.xPosition - fm.width(self.title)
-
self.parent.drawPreview()
+
+ def loadPreset(self, pr):
+ self.page.lineEdit_title.setText(pr['title'])
+ self.page.spinBox_fontSize.setValue(pr['fontSize'])
+ self.page.spinBox_xTextAlign.setValue(pr['xPosition'])
+ self.page.spinBox_yTextAlign.setValue(pr['yPosition'])
+ self.page.comboBox_textAlign.setCurrentIndex(pr['alignment'])
+ self.page.lineEdit_textColor.setText('%s,%s,%s' % pr['textColor'])
+ btnStyle = "QPushButton { background-color : %s; outline: none; }" % QColor(*pr['textColor']).name()
+ self.page.pushButton_textColor.setStyleSheet(btnStyle)
def savePreset(self):
- return {}
+ return {
+ 'title' : self.title,
+ 'alignment' : self.alignment,
+ 'fontSize' : self.fontSize,
+ 'xPosition' : self.xPosition,
+ 'yPosition' : self.yPosition,
+ 'textColor' : self.textColor
+ }
def previewRender(self, previewWorker):
width = int(previewWorker.core.settings.value('outputWidth'))
@@ -117,5 +130,7 @@ class Component(__base__.Component):
def pickColor(self):
RGBstring, btnStyle = super().pickColor()
+ if not RGBstring:
+ return
self.page.lineEdit_textColor.setText(RGBstring)
self.page.pushButton_textColor.setStyleSheet(btnStyle)
diff --git a/main.py b/main.py
index 474ab29..d3fa52c 100644
--- a/main.py
+++ b/main.py
@@ -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()
@@ -379,14 +377,44 @@ class Main(QtCore.QObject):
dirname = os.path.join(self.dataDir, 'presets', componentName, str(version))
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)
+ filepath = os.path.join(dirname, filename)
+ if os.path.exists(filepath):
+ msg = QtGui.QMessageBox()
+ msg.setIcon(QtGui.QMessageBox.Warning)
+ msg.setText("%s already exists! Overwrite it?" % filename)
+ msg.setStandardButtons(QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel)
+ ch = msg.exec_()
+ if ch != 1024: # 1024 = OK
+ return
+ # remove old copies of the preset
+ for i in range(0, self.windowcomboBox_openPreset.count()):
+ if self.window.comboBox_openPreset.itemText(i) == filename:
+ self.window.comboBox_openPreset.removeItem(i)
+ with open(filepath, 'w') as f:
+ 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
+ self.selectedComponents[index].loadPreset(saveValueStore)
+ self.drawPreview()
def LoadDefaultSettings(self):
self.resolutions = [