combined toolkit.py & frame.py into toolkit package

This commit is contained in:
tassaron 2017-07-17 22:07:33 -04:00
parent aa464632c6
commit b1713d38fa
15 changed files with 58 additions and 49 deletions

View File

@ -15,7 +15,7 @@ Dependencies
------------ ------------
Python 3.4, FFmpeg 3.3, PyQt5, Pillow-SIMD, NumPy Python 3.4, FFmpeg 3.3, PyQt5, Pillow-SIMD, NumPy
**Note:** Pillow may be used as a drop-in replacement for Pillow-SIMD if problems are encountered installing. However this will result in much slower video export times. For help troubleshooting installation problems, the * For any problems with installing Pillow-SIMD, see the [Pillow installation guide](http://pillow.readthedocs.io/en/3.1.x/installation.html). **Note:** Pillow may be used as a drop-in replacement for Pillow-SIMD if problems are encountered installing. However this will result in much slower video export times. For help installing Pillow-SIMD, see the [Pillow installation guide](http://pillow.readthedocs.io/en/3.1.x/installation.html).
Installation Installation
------------ ------------

View File

@ -1,3 +1,5 @@
# Allows for launching with python3 -m avpython
from avpython.main import main from avpython.main import main
main() main()

View File

@ -112,37 +112,6 @@ class Component(QtCore.QObject):
def commandHelp(self): def commandHelp(self):
'''Print help text for this Component's commandline arguments''' '''Print help text for this Component's commandline arguments'''
def pickColor(self):
'''
Use color picker to get color input from the user,
and return this as an RGB string and QPushButton stylesheet.
In a subclass apply stylesheet to any color selection widgets
'''
dialog = QtWidgets.QColorDialog()
dialog.setOption(QtWidgets.QColorDialog.ShowAlphaChannel, True)
color = dialog.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
else:
return None, None
def RGBFromString(self, string):
'''Turns an RGB string like "255, 255, 255" into a tuple'''
try:
tup = tuple([int(i) for i in string.split(',')])
if len(tup) != 3:
raise ValueError
for i in tup:
if i > 255 or i < 0:
raise ValueError
return tup
except:
return (255, 255, 255)
def loadUi(self, filename): def loadUi(self, filename):
return uic.loadUi(os.path.join(self.core.componentsPath, filename)) return uic.loadUi(os.path.join(self.core.componentsPath, filename))

View File

@ -5,7 +5,8 @@ from PIL.ImageQt import ImageQt
import os import os
from component import Component from component import Component
from frame import BlankFrame, FloodFrame, FramePainter, PaintColor from toolkit.frame import BlankFrame, FloodFrame, FramePainter, PaintColor
from toolkit import rgbFromString, pickColor
class Component(Component): class Component(Component):
@ -76,8 +77,8 @@ class Component(Component):
return page return page
def update(self): def update(self):
self.color1 = self.RGBFromString(self.page.lineEdit_color1.text()) self.color1 = rgbFromString(self.page.lineEdit_color1.text())
self.color2 = self.RGBFromString(self.page.lineEdit_color2.text()) self.color2 = rgbFromString(self.page.lineEdit_color2.text())
self.x = self.page.spinBox_x.value() self.x = self.page.spinBox_x.value()
self.y = self.page.spinBox_y.value() self.y = self.page.spinBox_y.value()
self.sizeWidth = self.page.spinBox_width.value() self.sizeWidth = self.page.spinBox_width.value()
@ -229,7 +230,7 @@ class Component(Component):
} }
def pickColor(self, num): def pickColor(self, num):
RGBstring, btnStyle = super().pickColor() RGBstring, btnStyle = pickColor()
if not RGBstring: if not RGBstring:
return return
if num == 1: if num == 1:

View File

@ -3,7 +3,7 @@ from PyQt5 import QtGui, QtCore, QtWidgets
import os import os
from component import Component from component import Component
from frame import BlankFrame from toolkit.frame import BlankFrame
class Component(Component): class Component(Component):

View File

@ -7,7 +7,8 @@ import time
from copy import copy from copy import copy
from component import Component from component import Component
from frame import BlankFrame from toolkit.frame import BlankFrame
from toolkit import rgbFromString, pickColor
class Component(Component): class Component(Component):
@ -48,7 +49,7 @@ class Component(Component):
def update(self): def update(self):
self.layout = self.page.comboBox_visLayout.currentIndex() self.layout = self.page.comboBox_visLayout.currentIndex()
self.visColor = self.RGBFromString(self.page.lineEdit_visColor.text()) self.visColor = rgbFromString(self.page.lineEdit_visColor.text())
self.scale = self.page.spinBox_scale.value() self.scale = self.page.spinBox_scale.value()
self.y = self.page.spinBox_y.value() self.y = self.page.spinBox_y.value()
@ -116,7 +117,7 @@ class Component(Component):
self.visColor, self.layout) self.visColor, self.layout)
def pickColor(self): def pickColor(self):
RGBstring, btnStyle = super().pickColor() RGBstring, btnStyle = pickColor()
if not RGBstring: if not RGBstring:
return return
self.page.lineEdit_visColor.setText(RGBstring) self.page.lineEdit_visColor.setText(RGBstring)

View File

@ -2,7 +2,7 @@ from PyQt5 import QtGui, QtCore, QtWidgets
import os import os
from component import Component from component import Component
from frame import BlankFrame from toolkit.frame import BlankFrame
class Component(Component): class Component(Component):

View File

@ -4,7 +4,8 @@ from PyQt5 import QtGui, QtCore, QtWidgets
import os import os
from component import Component from component import Component
from frame import FramePainter from toolkit.frame import FramePainter
from toolkit import rgbFromString, pickColor
class Component(Component): class Component(Component):
@ -64,7 +65,7 @@ class Component(Component):
self.fontSize = self.page.spinBox_fontSize.value() self.fontSize = self.page.spinBox_fontSize.value()
self.xPosition = self.page.spinBox_xTextAlign.value() self.xPosition = self.page.spinBox_xTextAlign.value()
self.yPosition = self.page.spinBox_yTextAlign.value() self.yPosition = self.page.spinBox_yTextAlign.value()
self.textColor = self.RGBFromString( self.textColor = rgbFromString(
self.page.lineEdit_textColor.text()) self.page.lineEdit_textColor.text())
btnStyle = "QPushButton { background-color : %s; outline: none; }" \ btnStyle = "QPushButton { background-color : %s; outline: none; }" \
% QColor(*self.textColor).name() % QColor(*self.textColor).name()
@ -146,7 +147,7 @@ class Component(Component):
return image.finalize() return image.finalize()
def pickColor(self): def pickColor(self):
RGBstring, btnStyle = super().pickColor() RGBstring, btnStyle = pickColor()
if not RGBstring: if not RGBstring:
return return
self.page.lineEdit_textColor.setText(RGBstring) self.page.lineEdit_textColor.setText(RGBstring)

View File

@ -7,7 +7,7 @@ import threading
from queue import PriorityQueue from queue import PriorityQueue
from component import Component, BadComponentInit from component import Component, BadComponentInit
from frame import BlankFrame from toolkit.frame import BlankFrame
from toolkit import openPipe, checkOutput from toolkit import openPipe, checkOutput

View File

@ -11,7 +11,7 @@ from importlib import import_module
from PyQt5.QtCore import QStandardPaths from PyQt5.QtCore import QStandardPaths
import toolkit import toolkit
from frame import Frame from toolkit.frame import Frame
import video_thread import video_thread

View File

@ -9,7 +9,7 @@ from PIL.ImageQt import ImageQt
from queue import Queue, Empty from queue import Queue, Empty
import os import os
from frame import Checkerboard from toolkit.frame import Checkerboard
class Worker(QtCore.QObject): class Worker(QtCore.QObject):

1
src/toolkit/__init__.py Normal file
View File

@ -0,0 +1 @@
from toolkit.common import *

View File

@ -1,6 +1,7 @@
''' '''
Common functions Common functions
''' '''
from PyQt5 import QtWidgets
import string import string
import os import os
import sys import sys
@ -69,6 +70,39 @@ def disableWhenEncoding(func):
return decorator return decorator
def pickColor():
'''
Use color picker to get color input from the user,
and return this as an RGB string and QPushButton stylesheet.
In a subclass apply stylesheet to any color selection widgets
'''
dialog = QtWidgets.QColorDialog()
dialog.setOption(QtWidgets.QColorDialog.ShowAlphaChannel, True)
color = dialog.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
else:
return None, None
def rgbFromString(string):
'''Turns an RGB string like "255, 255, 255" into a tuple'''
try:
tup = tuple([int(i) for i in string.split(',')])
if len(tup) != 3:
raise ValueError
for i in tup:
if i > 255 or i < 0:
raise ValueError
return tup
except:
return (255, 255, 255)
def LoadDefaultSettings(self): def LoadDefaultSettings(self):
''' Runs once at each program start-up. Fills in default settings ''' Runs once at each program start-up. Fills in default settings
for any settings not found in settings.ini for any settings not found in settings.ini

View File

@ -19,7 +19,7 @@ import time
import signal import signal
from toolkit import openPipe from toolkit import openPipe
from frame import Checkerboard from toolkit.frame import Checkerboard
class Worker(QtCore.QObject): class Worker(QtCore.QObject):