From 825b7af6e30deaf85646ce93507d8cb5a0b426ae Mon Sep 17 00:00:00 2001 From: tassaron Date: Sat, 3 Jun 2017 20:39:32 -0400 Subject: start of background replacement components --- components/image.ui | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 components/image.ui (limited to 'components/image.ui') diff --git a/components/image.ui b/components/image.ui new file mode 100644 index 0000000..6a24370 --- /dev/null +++ b/components/image.ui @@ -0,0 +1,200 @@ + + + Form + + + + 0 + 0 + 586 + 197 + + + + Form + + + + + + 4 + + + + + + + + 0 + 0 + + + + + 31 + 0 + + + + Image + + + + + + + + 1 + 0 + + + + 12 + + + + + + + + 0 + 0 + + + + + 1 + 0 + + + + + 32 + 32 + + + + ... + + + + 32 + 32 + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 5 + 20 + + + + + + + + + 0 + 0 + + + + X + + + + + + + + 0 + 0 + + + + + 80 + 16777215 + + + + 999999999 + + + + + + + + 0 + 0 + + + + Y + + + + + + + + 0 + 0 + + + + + 80 + 16777215 + + + + + 0 + 0 + + + + 0 + + + 999999999 + + + 0 + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + -- cgit v1.2.3 From cfb8e17b6362719ca736997a23a939bec4975e70 Mon Sep 17 00:00:00 2001 From: tassaron Date: Sat, 3 Jun 2017 22:58:40 -0400 Subject: basic image component --- components/color.py | 15 +++++++++++---- components/image.py | 36 ++++++++++++++++++++++++++++++------ components/image.ui | 11 ++++------- components/video.py | 38 ++++++++++++++++++++++++++++++++------ components/video.ui | 13 +++++-------- 5 files changed, 82 insertions(+), 31 deletions(-) (limited to 'components/image.ui') diff --git a/components/color.py b/components/color.py index d86470c..ae818e2 100644 --- a/components/color.py +++ b/components/color.py @@ -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() diff --git a/components/image.py b/components/image.py index 3176d7c..021bb9e 100644 --- a/components/image.py +++ b/components/image.py @@ -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() diff --git a/components/image.ui b/components/image.ui index 6a24370..3cd5b1b 100644 --- a/components/image.ui +++ b/components/image.ui @@ -41,20 +41,17 @@ - + 1 0 - - 12 - - + 0 @@ -114,7 +111,7 @@ - + 0 @@ -146,7 +143,7 @@ - + 0 diff --git a/components/video.py b/components/video.py index 1365f34..561e40b 100644 --- a/components/video.py +++ b/components/video.py @@ -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() diff --git a/components/video.ui b/components/video.ui index 73697f3..6a01368 100644 --- a/components/video.ui +++ b/components/video.ui @@ -41,20 +41,17 @@ - + 1 0 - - 12 - - + 0 @@ -114,7 +111,7 @@ - + 0 @@ -146,7 +143,7 @@ - + 0 @@ -183,7 +180,7 @@ - + Loop -- cgit v1.2.3