aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDH42017-06-01 22:46:45 -0500
committerDH42017-06-01 22:46:45 -0500
commit7d8e9ab3b16546e91144e256e88f9f490abc7ec2 (patch)
treec314536d70adc85b12f40aeab62d4f20576d974a
parent30f2ea12df0ae732797bcc716de592e878262290 (diff)
Added aspect ratio scaling to preview area.
-rw-r--r--background.jpgbin0 -> 14782 bytes
-rw-r--r--main.py35
-rw-r--r--mainwindow.ui86
-rw-r--r--video_thread.py2
4 files changed, 55 insertions, 68 deletions
diff --git a/background.jpg b/background.jpg
new file mode 100644
index 0000000..f746432
--- /dev/null
+++ b/background.jpg
Binary files differ
diff --git a/main.py b/main.py
index 8bbbf08..f34cbee 100644
--- a/main.py
+++ b/main.py
@@ -3,7 +3,7 @@ from os.path import expanduser
from queue import Queue
from importlib import import_module
from PyQt4 import QtCore, QtGui, uic
-from PyQt4.QtCore import QSettings, QModelIndex
+from PyQt4.QtCore import QSettings, QModelIndex, Qt
from PyQt4.QtGui import QDesktopServices
import preview_thread, core, video_thread
@@ -107,6 +107,29 @@ class Command(QtCore.QObject):
self.settings.setValue("textColor", '%s,%s,%s' % self.textColor)
sys.exit(0)
'''
+
+class PreviewWindow(QtGui.QLabel):
+ def __init__(self, parent, img):
+ super(PreviewWindow, self).__init__()
+ self.parent = parent
+ self.setFrameStyle(QtGui.QFrame.StyledPanel)
+ self.pixmap = QtGui.QPixmap(img)
+
+ def paintEvent(self, event):
+ size = self.size()
+ painter = QtGui.QPainter(self)
+ point = QtCore.QPoint(0,0)
+ scaledPix = self.pixmap.scaled(size, Qt.KeepAspectRatio, transformMode = Qt.SmoothTransformation)
+ # start painting the label from left upper corner
+ point.setX((size.width() - scaledPix.width())/2)
+ point.setY((size.height() - scaledPix.height())/2)
+ #print point.x(), ' ', point.y()
+ painter.drawPixmap(point, scaledPix)
+
+ def changePixmap(self, img):
+ self.pixmap = QtGui.QPixmap(img)
+ self.repaint()
+
class Main(QtCore.QObject):
newTask = QtCore.pyqtSignal(str, list)
@@ -151,6 +174,9 @@ class Main(QtCore.QObject):
window.progressBar_createVideo.setValue(0)
window.pushButton_createVideo.clicked.connect(self.createAudioVisualisation)
window.setWindowTitle("Audio Visualizer")
+
+ self.previewWindow = PreviewWindow(self, r"background.jpg")
+ window.verticalLayout_previewWrapper.addWidget(self.previewWindow)
self.modules = self.findComponents()
for component in self.modules:
@@ -269,10 +295,7 @@ class Main(QtCore.QObject):
# self.processTask.emit()
def showPreviewImage(self, image):
- self._scaledPreviewImage = image
- self._previewPixmap = QtGui.QPixmap.fromImage(self._scaledPreviewImage)
-
- self.window.label_previewContainer.setPixmap(self._previewPixmap)
+ self.previewWindow.changePixmap(image)
def findComponents(self):
def findComponents():
@@ -548,7 +571,7 @@ if __name__ == "__main__":
topMargin = 0 if (dpi == 96) else int(10 * (dpi / 96))
window.resize(window.width() * (dpi / 96), window.height() * (dpi / 96))
- window.verticalLayout_2.setContentsMargins(0, topMargin, 0, 0)
+ #window.verticalLayout_2.setContentsMargins(0, topMargin, 0, 0)
main = Main(window)
diff --git a/mainwindow.ui b/mainwindow.ui
index 0dcce91..808073b 100644
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -27,75 +27,24 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
- <layout class="QVBoxLayout" name="verticalLayout_2">
+ <layout class="QVBoxLayout" name="verticalLayout_previewWrapper">
+ <property name="sizeConstraint">
+ <enum>QLayout::SetDefaultConstraint</enum>
+ </property>
<property name="topMargin">
<number>0</number>
</property>
<item>
- <spacer name="verticalSpacer_6">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeType">
- <enum>QSizePolicy::Minimum</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>0</width>
- <height>0</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QLabel" name="label_previewContainer">
- <property name="sizePolicy">
- <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="minimumSize">
- <size>
- <width>356</width>
- <height>280</height>
- </size>
- </property>
- <property name="sizeIncrement">
- <size>
- <width>0</width>
- <height>0</height>
- </size>
- </property>
- <property name="autoFillBackground">
- <bool>false</bool>
- </property>
- <property name="styleSheet">
- <string notr="true">background-color:rgba(255, 255, 255, 15);
-</string>
- </property>
- <property name="text">
- <string/>
- </property>
- <property name="scaledContents">
- <bool>true</bool>
- </property>
- <property name="alignment">
- <set>Qt::AlignCenter</set>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="verticalSpacer_5">
+ <spacer name="horizontalSpacer_previewSpacer">
<property name="orientation">
- <enum>Qt::Vertical</enum>
+ <enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
- <enum>QSizePolicy::Minimum</enum>
+ <enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
- <width>0</width>
+ <width>420</width>
<height>0</height>
</size>
</property>
@@ -105,16 +54,25 @@
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
+ <property name="sizeConstraint">
+ <enum>QLayout::SetMinimumSize</enum>
+ </property>
<property name="leftMargin">
<number>3</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
+ <property name="sizeConstraint">
+ <enum>QLayout::SetMinimumSize</enum>
+ </property>
<property name="leftMargin">
<number>3</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_16">
+ <property name="sizeConstraint">
+ <enum>QLayout::SetMinimumSize</enum>
+ </property>
<item>
<widget class="QPushButton" name="pushButton_openProject">
<property name="text">
@@ -141,10 +99,10 @@
<item>
<spacer name="verticalSpacer">
<property name="orientation">
- <enum>Qt::Vertical</enum>
+ <enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
- <enum>QSizePolicy::Fixed</enum>
+ <enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -218,6 +176,12 @@
<layout class="QHBoxLayout" name="horizontalLayout_15">
<item>
<widget class="QComboBox" name="comboBox_openPreset">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
<item>
<property name="text">
<string>Open Preset</string>
diff --git a/video_thread.py b/video_thread.py
index dee254a..a7c7ac6 100644
--- a/video_thread.py
+++ b/video_thread.py
@@ -63,7 +63,7 @@ class Worker(QtCore.QObject):
def previewDispatch(self):
while True:
i = self.previewQueue.get()
- if time.time() - self.lastPreview >= 0.05 or i[0] == 0:
+ if time.time() - self.lastPreview >= 0.06 or i[0] == 0:
self._image = ImageQt(i[1])
self.imageCreated.emit(QtGui.QImage(self._image))
self.lastPreview = time.time()