Added aspect ratio scaling to preview area.
This commit is contained in:
parent
30f2ea12df
commit
7d8e9ab3b1
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
35
main.py
35
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)
|
||||
|
||||
|
|
|
@ -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">
|
||||
<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>
|
||||
<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">
|
||||
<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>
|
||||
<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>
|
||||
|
|
|
@ -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()
|
||||
|
|
Reference in New Issue