fixed relative image scale bug & Life preset bug

dicts must be alphabetized in AV files
This commit is contained in:
tassaron 2017-08-10 17:27:59 -04:00
parent c5a0c9b364
commit bdb006f25d
4 changed files with 49 additions and 8 deletions

View File

@ -2,7 +2,7 @@ from setuptools import setup
import os
__version__ = '2.0.0.rc3'
__version__ = '2.0.0.rc4'
def package_files(directory):

View File

@ -8,7 +8,7 @@ from toolkit.frame import BlankFrame
class Component(Component):
name = 'Image'
version = '1.0.0'
version = '1.0.1'
def widget(self, *args):
super().widget(*args)
@ -16,6 +16,7 @@ class Component(Component):
self.trackWidgets({
'imagePath': self.page.lineEdit_image,
'scale': self.page.spinBox_scale,
'stretchScale': self.page.spinBox_scale_stretch,
'rotate': self.page.spinBox_rotate,
'color': self.page.spinBox_color,
'xPosition': self.page.spinBox_x,
@ -51,6 +52,7 @@ class Component(Component):
def drawFrame(self, width, height):
frame = BlankFrame(width, height)
if self.imagePath and os.path.exists(self.imagePath):
scale = self.scale if not self.stretched else self.stretchScale
image = Image.open(self.imagePath)
# Modify image's appearance
@ -62,9 +64,9 @@ class Component(Component):
image = image.transpose(Image.FLIP_LEFT_RIGHT)
if self.stretched and image.size != (width, height):
image = image.resize((width, height), Image.ANTIALIAS)
if self.scale != 100:
newHeight = int((image.height / 100) * self.scale)
newWidth = int((image.width / 100) * self.scale)
if scale != 100:
newHeight = int((image.height / 100) * scale)
newWidth = int((image.width / 100) * scale)
image = image.resize((newWidth, newHeight), Image.ANTIALIAS)
# Paste image at correct position
@ -100,3 +102,25 @@ class Component(Component):
def commandHelp(self):
print('Load an image:\n path=/filepath/to/image.png')
def savePreset(self):
# Maintain the illusion that the scale spinbox is one widget
scaleBox = self.page.spinBox_scale
stretchScaleBox = self.page.spinBox_scale_stretch
if self.page.checkBox_stretch.isChecked():
scaleBox.setValue(stretchScaleBox.value())
else:
stretchScaleBox.setValue(scaleBox.value())
return super().savePreset()
def update(self):
# Maintain the illusion that the scale spinbox is one widget
scaleBox = self.page.spinBox_scale
stretchScaleBox = self.page.spinBox_scale_stretch
if self.page.checkBox_stretch.isChecked():
scaleBox.setVisible(False)
stretchScaleBox.setVisible(True)
else:
scaleBox.setVisible(True)
stretchScaleBox.setVisible(False)
super().update()

View File

@ -293,6 +293,22 @@
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox_scale_stretch">
<property name="suffix">
<string>%</string>
</property>
<property name="minimum">
<number>10</number>
</property>
<property name="maximum">
<number>400</number>
</property>
<property name="value">
<number>100</number>
</property>
</widget>
</item>
</layout>
</item>
<item>

View File

@ -4,12 +4,13 @@ import os
import math
from component import Component
from toolkit import alphabetizeDict
from toolkit.frame import BlankFrame, scale
class Component(Component):
name = 'Conway\'s Game of Life'
version = '1.0.0a'
version = '1.0.0'
def widget(self, *args):
super().widget(*args)
@ -329,12 +330,12 @@ class Component(Component):
def savePreset(self):
pr = super().savePreset()
pr['GRID'] = self.startingGrid
pr['GRID'] = alphabetizeDict(self.startingGrid)
return pr
def loadPreset(self, pr, *args):
super().loadPreset(pr, *args)
self.startingGrid = pr['GRID']
self.startingGrid = dict(pr['GRID'])
def nearbyCoords(x, y):