diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/component.py | 56 | ||||
| -rw-r--r-- | src/components/text.py | 18 | ||||
| -rw-r--r-- | src/components/text.ui | 114 | ||||
| -rw-r--r-- | src/core.py | 2 |
4 files changed, 127 insertions, 63 deletions
diff --git a/src/component.py b/src/component.py index ea4b5ec..5b38473 100644 --- a/src/component.py +++ b/src/component.py @@ -346,16 +346,29 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass): % QColor(*val).name() ) self._colorWidgets[attr].setStyleSheet(btnStyle) + elif attr in self._relativeWidgets: + self._relativeValues[attr] = val + pixelVal = self.pixelValForAttr(attr, val) + setWidgetValue(widget, pixelVal) else: setWidgetValue(widget, val) def savePreset(self): saveValueStore = {} for attr, widget in self._trackedWidgets.items(): - saveValueStore[ + presetAttrName = ( attr if attr not in self._presetNames else self._presetNames[attr] - ] = getattr(self, attr) + ) + if attr in self._relativeWidgets: + try: + val = self._relativeValues[attr] + except AttributeError: + val = self.floatValForAttr(attr) + else: + val = getattr(self, attr) + + saveValueStore[presetAttrName] = val return saveValueStore def commandHelp(self): @@ -490,17 +503,42 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass): self.unlockProperties() self.unlockError() + def relativeWidgetAxis(func): + def relativeWidgetAxis(self, attr, *args, **kwargs): + if 'axis' not in kwargs: + axis = self.width + if 'height' in attr.lower() \ + or 'ypos' in attr.lower() or attr == 'y': + axis = self.height + kwargs['axis'] = axis + return func(self, attr, *args, **kwargs) + return relativeWidgetAxis + + @relativeWidgetAxis + def pixelValForAttr(self, attr, val=None, **kwargs): + if val is None: + val = self._relativeValues[attr] + return math.ceil(kwargs['axis'] * val) + + @relativeWidgetAxis + def floatValForAttr(self, attr, val=None, **kwargs): + if val is None: + val = self._trackedWidgets[attr].value() + return val / kwargs['axis'] + + def setRelativeWidget(self, attr, floatVal): + '''Set a relative widget using a float''' + pixelVal = self.pixelValForAttr(attr, floatVal) + self._trackedWidgets[attr].setValue(pixelVal) + + def updateRelativeWidget(self, attr): - dimension = self.width - if 'height' in attr.lower() \ - or 'ypos' in attr.lower() or attr == 'y': - dimension = self.height try: oldUserValue = getattr(self, attr) except AttributeError: oldUserValue = self._trackedWidgets[attr].value() newUserValue = self._trackedWidgets[attr].value() - newRelativeVal = newUserValue / dimension + newRelativeVal = self.floatValForAttr(attr, newUserValue) if attr in self._relativeValues: oldRelativeVal = self._relativeValues[attr] @@ -510,8 +548,8 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass): # means the pixel value needs to be updated self._trackedWidgets[attr].blockSignals(True) self.updateRelativeWidgetMaximum(attr) - self._trackedWidgets[attr].setValue( - math.ceil(dimension * oldRelativeVal)) + pixelVal = self.pixelValForAttr(attr, oldRelativeVal) + self._trackedWidgets[attr].setValue(pixelVal) self._trackedWidgets[attr].blockSignals(False) if attr not in self._relativeValues \ diff --git a/src/components/text.py b/src/components/text.py index b7c244e..c3f3bdc 100644 --- a/src/components/text.py +++ b/src/components/text.py @@ -9,7 +9,7 @@ from toolkit.frame import FramePainter class Component(Component): name = 'Title Text' - version = '1.0.0' + version = '1.0.1' def __init__(self, *args): super().__init__(*args) @@ -25,20 +25,17 @@ class Component(Component): self.page.comboBox_textAlign.addItem("Left") self.page.comboBox_textAlign.addItem("Middle") self.page.comboBox_textAlign.addItem("Right") + self.page.comboBox_textAlign.setCurrentIndex(int(self.alignment)) self.page.lineEdit_textColor.setText('%s,%s,%s' % self.textColor) - self.page.lineEdit_title.setText(self.title) - self.page.comboBox_textAlign.setCurrentIndex(int(self.alignment)) self.page.spinBox_fontSize.setValue(int(self.fontSize)) + self.page.lineEdit_title.setText(self.title) - fm = QtGui.QFontMetrics(self.titleFont) - self.page.spinBox_xTextAlign.setValue( - self.width / 2 - fm.width(self.title)/2) - self.page.spinBox_yTextAlign.setValue(self.height / 2 * 1.036) - + self.page.pushButton_center.clicked.connect(self.centerXY) self.page.fontComboBox_titleFont.currentFontChanged.connect( self.update ) + self.trackWidgets({ 'textColor': self.page.lineEdit_textColor, 'title': self.page.lineEdit_title, @@ -51,11 +48,16 @@ class Component(Component): }, relativeWidgets=[ 'xPosition', 'yPosition', 'fontSize', ]) + self.centerXY() def update(self): self.titleFont = self.page.fontComboBox_titleFont.currentFont() super().update() + def centerXY(self): + self.setRelativeWidget('xPosition', 0.5) + self.setRelativeWidget('yPosition', 0.5) + def getXY(self): '''Returns true x, y after considering alignment settings''' fm = QtGui.QFontMetrics(self.titleFont) diff --git a/src/components/text.ui b/src/components/text.ui index bb5e5af..f76979c 100644 --- a/src/components/text.ui +++ b/src/components/text.ui @@ -20,6 +20,36 @@ <number>4</number> </property> <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="label_title"> + <property name="text"> + <string>Title</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="lineEdit_title"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> + <property name="text"> + <string>Testing New GUI</string> + </property> + </widget> + </item> + </layout> + </item> + <item> <layout class="QHBoxLayout" name="horizontalLayout_8"> <item> <widget class="QLabel" name="label"> @@ -94,38 +124,6 @@ <item> <layout class="QHBoxLayout" name="horizontalLayout_12"> <item> - <widget class="QLabel" name="label_textLayout"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Text Layout</string> - </property> - </widget> - </item> - <item> - <widget class="QComboBox" name="comboBox_textAlign"/> - </item> - <item> - <spacer name="horizontalSpacer_2"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType"> - <enum>QSizePolicy::Fixed</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>5</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> <widget class="QLabel" name="label_textColor"> <property name="text"> <string>Text Color</string> @@ -133,6 +131,9 @@ </widget> </item> <item> + <widget class="QLineEdit" name="lineEdit_textColor"/> + </item> + <item> <widget class="QPushButton" name="pushButton_textColor"> <property name="maximumSize"> <size> @@ -152,7 +153,17 @@ </widget> </item> <item> - <widget class="QLineEdit" name="lineEdit_textColor"/> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> </item> </layout> </item> @@ -162,28 +173,41 @@ <number>0</number> </property> <item> - <widget class="QLabel" name="label_title"> + <widget class="QLabel" name="label_textLayout"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="text"> - <string>Title</string> + <string>Text Layout</string> </property> </widget> </item> <item> - <widget class="QLineEdit" name="lineEdit_title"> - <property name="sizePolicy"> - <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> + <widget class="QComboBox" name="comboBox_textAlign"/> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> </property> - <property name="minimumSize"> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> <size> - <width>0</width> - <height>0</height> + <width>5</width> + <height>20</height> </size> </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="pushButton_center"> <property name="text"> - <string>Testing New GUI</string> + <string>Center</string> </property> </widget> </item> diff --git a/src/core.py b/src/core.py index afb1e45..61905eb 100644 --- a/src/core.py +++ b/src/core.py @@ -161,7 +161,7 @@ class Core: for widget, value in data['WindowFields']: widget = eval('loader.window.%s' % widget) widget.blockSignals(True) - widget.setText(value) + toolkit.setWidgetValue(widget, value) widget.blockSignals(False) for key, value in data['Settings']: |
