basic image component

This commit is contained in:
tassaron 2017-06-03 22:58:40 -04:00
parent 5480b20d40
commit cfb8e17b63
5 changed files with 82 additions and 31 deletions

View File

@ -57,12 +57,19 @@ class Component(__base__.Component):
r,g,b = self.color1
return Image.new("RGBA", (width, height), (r, g, b, 255))
def loadPreset(self, presetDict):
# update widgets using a preset dict
pass
def loadPreset(self, pr):
self.page.lineEdit_color1.setText('%s,%s,%s' % pr['color1'])
self.page.lineEdit_color2.setText('%s,%s,%s' % pr['color2'])
btnStyle = "QPushButton { background-color : %s; outline: none; }" % QColor(*pr['color1']).name()
self.page.pushButton_color1.setStyleSheet(btnStyle)
btnStyle = "QPushButton { background-color : %s; outline: none; }" % QColor(*pr['color2']).name()
self.page.pushButton_color2.setStyleSheet(btnStyle)
def savePreset(self):
return {}
return {
'color1' : self.color1,
'color2' : self.color2,
}
def pickColor(self, num):
RGBstring, btnStyle = super().pickColor()

View File

@ -7,12 +7,20 @@ class Component(__base__.Component):
'''Image'''
def widget(self, parent):
self.parent = parent
self.settings = parent.settings
page = uic.loadUi(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'image.ui'))
self.imagePath = ''
self.x = 0
self.y = 0
page.lineEdit_image.textChanged.connect(self.update)
page.pushButton_image.clicked.connect(self.pickImage)
self.page = page
return page
def update(self):
# read widget values
self.imagePath = self.page.lineEdit_image.text()
self.parent.drawPreview()
def previewRender(self, previewWorker):
@ -26,17 +34,33 @@ class Component(__base__.Component):
return self.drawFrame(width, height)
def drawFrame(self, width, height):
return Image.new("RGBA", (width, height), (0,0,0,255))
frame = Image.new("RGBA", (width, height), (0,0,0,0))
if self.imagePath and os.path.exists(self.imagePath):
image = Image.open(self.imagePath)
if image.size != (width, height):
image = image.resize((width, height), Image.ANTIALIAS)
frame.paste(image)
return frame
def loadPreset(self, presetDict):
# update widgets using a preset dict
pass
def loadPreset(self, pr):
self.page.lineEdit_image.setText(pr['image'])
def savePreset(self):
return {}
return {
'image' : self.imagePath,
}
def cancel(self):
self.canceled = True
def reset(self):
self.canceled = False
def pickImage(self):
imgDir = self.settings.value("backgroundDir", os.path.expanduser("~"))
filename = QtGui.QFileDialog.getOpenFileName(self.page,
"Choose Image", imgDir, "Image Files (*.jpg *.png)")
if filename:
self.settings.setValue("backgroundDir", os.path.dirname(filename))
self.page.lineEdit_image.setText(filename)
self.update()

View File

@ -41,20 +41,17 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_color1">
<widget class="QLineEdit" name="lineEdit_image">
<property name="minimumSize">
<size>
<width>1</width>
<height>0</height>
</size>
</property>
<property name="maxLength">
<number>12</number>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_color1">
<widget class="QPushButton" name="pushButton_image">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -114,7 +111,7 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox_y">
<widget class="QSpinBox" name="spinBox_x">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -146,7 +143,7 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox_x">
<widget class="QSpinBox" name="spinBox_y">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>

View File

@ -7,12 +7,20 @@ class Component(__base__.Component):
'''Video'''
def widget(self, parent):
self.parent = parent
self.settings = parent.settings
page = uic.loadUi(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'video.ui'))
self.videoPath = ''
self.x = 0
self.y = 0
page.lineEdit_video.textChanged.connect(self.update)
page.pushButton_video.clicked.connect(self.pickVideo)
self.page = page
return page
def update(self):
# read widget values
self.videoPath = self.page.lineEdit_video.text()
self.parent.drawPreview()
def previewRender(self, previewWorker):
@ -26,17 +34,35 @@ class Component(__base__.Component):
return self.drawFrame(width, height)
def drawFrame(self, width, height):
return Image.new("RGBA", (width, height), (0,0,0,255))
frame = Image.new("RGBA", (width, height), (0,0,0,0))
'''
if self.imagePath and os.path.exists(self.imagePath):
image = Image.open(self.imagePath)
if image.size != (width, height):
image = image.resize((width, height), Image.ANTIALIAS)
frame.paste(image)
'''
return frame
def loadPreset(self, presetDict):
# update widgets using a preset dict
pass
def loadPreset(self, pr):
self.page.lineEdit_video.setText(pr['video'])
def savePreset(self):
return {}
return {
'video' : self.videoPath,
}
def cancel(self):
self.canceled = True
def reset(self):
self.canceled = False
def pickVideo(self):
imgDir = self.settings.value("backgroundDir", os.path.expanduser("~"))
filename = QtGui.QFileDialog.getOpenFileName(self.page,
"Choose Video", imgDir, "Video Files (*.mp4)")
if filename:
self.settings.setValue("backgroundDir", os.path.dirname(filename))
self.page.lineEdit_video.setText(filename)
self.update()

View File

@ -41,20 +41,17 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_color1">
<widget class="QLineEdit" name="lineEdit_video">
<property name="minimumSize">
<size>
<width>1</width>
<height>0</height>
</size>
</property>
<property name="maxLength">
<number>12</number>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_color1">
<widget class="QPushButton" name="pushButton_video">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -114,7 +111,7 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox_y">
<widget class="QSpinBox" name="spinBox_x_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -146,7 +143,7 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox_x">
<widget class="QSpinBox" name="spinBox_y">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -183,7 +180,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QCheckBox" name="checkBox">
<widget class="QCheckBox" name="checkBox_loop">
<property name="text">
<string>Loop</string>
</property>