Skip to content

Commit 1a917c6

Browse files
committed
Multiple fixes and additions:
- Widgets: CustomButton and Spinbox + button combo; - Messages: Point and Service array warnings; - Glyph: Revised warnings/errors for set point and service arrays.
1 parent a138056 commit 1a917c6

File tree

4 files changed

+74
-28
lines changed

4 files changed

+74
-28
lines changed

Lib/typerig/core/base/message.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import os, warnings
1717

1818
# - Init -----------------------------
19-
__version__ = '0.1.2'
19+
__version__ = '0.1.3'
2020

2121
# - Strings --------------------------
2222
# --------------> 0 1 2 3 4 5 6 7 8 9
@@ -100,6 +100,13 @@ class TRDeltaStemWarning(UserWarning):
100100
class TRDeltaArrayWarning(UserWarning):
101101
pass
102102

103+
# -- Glyph Warning ----------------
104+
class TRPointArrayWarning(UserWarning):
105+
pass
106+
107+
class TRServiceArrayWarning(UserWarning):
108+
pass
109+
103110
# - Setup ----------------------------
104111
warnings.formatwarning = warning_custom
105112

Lib/typerig/proxy/fl/gui/styles.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
background: none;
4646
margin: 2 0 2 0;
4747
padding: 2 0 2 0;
48-
min-height: 24px;
49-
min-width: 24px;
48+
min-height: 22px;
49+
min-width: 22px;
5050
}
5151
5252
QPushButton#btn_mast {
@@ -57,7 +57,7 @@
5757
border-radius: 5px;
5858
margin: 2 0 2 0;
5959
padding: 2 0 2 0;
60-
min-height: 24px;
60+
min-height: 22px;
6161
}
6262
6363
QPushButton#btn_mast:checked {
@@ -68,8 +68,8 @@
6868
}
6969
7070
QPushButton#btn_mast:hover {
71-
background-color: #ffffff;
72-
color: #212121;
71+
/*background-color: #ffffff;*/
72+
/*color: #212121;*/
7373
border: 1px solid #dadbdc;
7474
border-bottom-color: #d1d2d3;
7575
}

Lib/typerig/proxy/fl/gui/widgets.py

+36
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,42 @@ def FLIconButton(button_text, icon_path, icon_size=32, checkable=False):
140140
new_button.setIconSize(QtCore.QSize(icon_size,icon_size))
141141
return new_button
142142

143+
# -- Miniwidgets --------------------------
144+
class CustomSpinButton(QtGui.QWidget):
145+
def __init__(button_text, init_values=(0., 100., 0., 1.), tooltip=(None, None), obj_name=(None, None)):
146+
super(CustomSpinButton, self).__init__()
147+
148+
# - Init
149+
spb_min, spb_max, spb_value, spb_step = init_values
150+
151+
# - Widgets
152+
self.button = QtGui.QPushButton(button_text)
153+
154+
self.input = QtGui.QtGui.QDoubleSpinBox()
155+
self.input.setMinimum(spb_min)
156+
self.input.setMaximum(spb_max)
157+
self.input.setValue(spb_value)
158+
self.input.setSingleStep(spb_step)
159+
160+
if len(tooltip) == 2:
161+
if tooltip[0] is not None:
162+
self.input.setToolTip(tooltip)
163+
164+
if tooltip[1] is not None:
165+
self.button.setToolTip(tooltip)
166+
167+
if len(tooltip) == 2:
168+
if obj_name[0] is not None:
169+
self.input.setObjectName(obj_name)
170+
171+
if obj_name[1] is not None:
172+
self.button.setObjectName(obj_name)
173+
174+
# - Layout
175+
self.box = QtGui.QHBoxLayout()
176+
self.box.addWidget(self.input)
177+
self.box.addWidget(self.button)
178+
143179
# -- Sub Dialogs --------------------------
144180
class TRLayerSelectDLG(QtGui.QDialog):
145181
def __init__(self, parent, mode, font=None, glyph=None):

Lib/typerig/proxy/fl/objects/glyph.py

+25-22
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# - Dependencies -----------------------------------
1212
from __future__ import print_function
1313
import math
14+
import warnings
1415
from itertools import combinations
1516
from operator import itemgetter
1617

@@ -26,11 +27,12 @@
2627
from typerig.core.objects.point import Point
2728
from typerig.core.func.math import linInterp
2829

30+
from typerig.core.base.message import *
2931
from typerig.proxy.fl.application.app import pWorkspace
3032
from typerig.proxy.fl.objects.string import diactiricalMarks
3133

3234
# - Init -------------------------------------------
33-
__version__ = '0.30.8'
35+
__version__ = '0.30.9'
3436

3537
# - Keep compatibility for basestring checks
3638
try:
@@ -1497,6 +1499,10 @@ def _getPointArray(self, layer=None):
14971499
def _setPointArray(self, PointArray, layer=None, keep_center=False):
14981500
nodeArray = self.nodes(layer)
14991501
PointArray = list(PointArray)
1502+
1503+
if len(PointArray) != len(nodeArray):
1504+
warnings.warn('Glyph: {}'.format(self.name), TRPointArrayWarning)
1505+
return
15001506

15011507
if keep_center:
15021508
layer_BBox = self.getBounds(layer)
@@ -1509,15 +1515,12 @@ def _setPointArray(self, PointArray, layer=None, keep_center=False):
15091515
center_array = pqt.QtCore.QPointF((array_BBox[0] + array_BBox[2])/2., (array_BBox[1] + array_BBox[3])/2)
15101516
recenter_shift = layer_center - center_array
15111517

1512-
if len(PointArray) == len(nodeArray):
1513-
for nid in range(len(PointArray)):
1514-
if keep_center:
1515-
nodeArray[nid].x = PointArray[nid][0] + recenter_shift.x()
1516-
nodeArray[nid].y = PointArray[nid][1] + recenter_shift.y()
1517-
else:
1518-
nodeArray[nid].x, nodeArray[nid].y = PointArray[nid]
1519-
else:
1520-
print('ERROR:\t Incompatible coordinate array provided.')
1518+
for nid in range(len(PointArray)):
1519+
if keep_center:
1520+
nodeArray[nid].x = PointArray[nid][0] + recenter_shift.x()
1521+
nodeArray[nid].y = PointArray[nid][1] + recenter_shift.y()
1522+
else:
1523+
nodeArray[nid].x, nodeArray[nid].y = PointArray[nid]
15211524

15221525
def _getServiceArray(self, layer=None):
15231526
layer_advance = [(float(self.layer(layer).advanceWidth), float(self.layer(layer).advanceHeight))]
@@ -1527,21 +1530,21 @@ def _getServiceArray(self, layer=None):
15271530
def _setServiceArray(self, PointArray, layer=None, set_metrics=True, set_anchors=True):
15281531
PointArray = list(PointArray)
15291532

1530-
if len(PointArray) > 2:
1531-
if set_metrics:
1532-
layer_advance = PointArray[0]
1533-
self.setAdvance(layer_advance[0], layer)
1533+
if len(PointArray) == 0:
1534+
warnings.warn('Glyph: {}'.format(self.name), TRServiceArrayWarning)
1535+
return
15341536

1535-
if set_anchors:
1536-
layer_anchors = PointArray[1:]
1537-
anchorArray = self.anchors(layer)
1537+
if set_metrics:
1538+
layer_advance = PointArray[0]
1539+
self.setAdvance(layer_advance[0], layer)
15381540

1539-
if len(layer_anchors) == len(anchorArray):
1540-
for aid in range(len(layer_anchors)):
1541-
anchorArray[aid].point = pqt.QtCore.QPointF(*layer_anchors[aid])
1542-
else:
1543-
print('ERROR:\t Incompatible coordinate array provided.')
1541+
if set_anchors and len(PointArray) > 2:
1542+
layer_anchors = PointArray[1:]
1543+
anchorArray = self.anchors(layer)
15441544

1545+
if len(layer_anchors) == len(anchorArray):
1546+
for aid in range(len(layer_anchors)):
1547+
anchorArray[aid].point = pqt.QtCore.QPointF(*layer_anchors[aid])
15451548

15461549
# - Nodes ----------------------------------------------
15471550
def breakContour(self, contourId, nodeId, layer=None, expand=0):

0 commit comments

Comments
 (0)