| 965 | |
| 966 | |
| 967 | class EditorAttributeInputCssSize(EditorAttributeInputBase): |
| 968 | def __init__(self, widget, attributeName, propertyDef, attributeDict, appInstance, *args, **kwargs): |
| 969 | super(EditorAttributeInputCssSize, self).__init__( |
| 970 | widget, attributeName, propertyDef, attributeDict, appInstance, *args, **kwargs) |
| 971 | self.numInput = gui.SpinBox( |
| 972 | '0', -999999999, 999999999, 1, width='100%', height='100%') |
| 973 | self.numInput.onchange.do(self.onchange) |
| 974 | self.numInput.style['text-align'] = 'right' |
| 975 | |
| 976 | self.dropMeasureUnit = gui.DropDown(width='100%', height='100%') |
| 977 | self.dropMeasureUnit.append(gui.DropDownItem('px'), 'px') |
| 978 | self.dropMeasureUnit.append(gui.DropDownItem('%'), '%') |
| 979 | self.dropMeasureUnit.select_by_key('px') |
| 980 | self.dropMeasureUnit.onchange.do(self.onchange) |
| 981 | ''' |
| 982 | self.set_from_asciiart(""" |
| 983 | |del|lbl |input |meas | |
| 984 | """) |
| 985 | ''' |
| 986 | self.style.update({'grid-template-columns': "6% 46% 33% 15%", |
| 987 | 'grid-template-rows': "100%", 'grid-template-areas': "'del lbl input meas'"}) |
| 988 | self.append({'del': self.removeAttribute, 'lbl': self.label, |
| 989 | 'input': self.numInput, 'meas': self.dropMeasureUnit}) |
| 990 | |
| 991 | def onchange(self, widget, new_value): |
| 992 | new_size = str(self.numInput.get_value()) + \ |
| 993 | str(self.dropMeasureUnit.get_value()) |
| 994 | self.on_attribute_changed(self, new_size) |
| 995 | |
| 996 | def set_value(self, value): |
| 997 | """The value have to be in the form '10px' or '10%', so numeric value plus measure unit |
| 998 | """ |
| 999 | v = 0 |
| 1000 | measure_unit = 'px' |
| 1001 | if not value is None: |
| 1002 | try: |
| 1003 | v = int(float(value.replace('px', ''))) |
| 1004 | except ValueError: |
| 1005 | try: |
| 1006 | v = int(float(value.replace('%', ''))) |
| 1007 | measure_unit = '%' |
| 1008 | except ValueError: |
| 1009 | pass |
| 1010 | self.numInput.set_value(v) |
| 1011 | self.dropMeasureUnit.set_value(measure_unit) |
| 1012 | self.set_valid(not value is None) |
| 1013 | |
| 1014 | |
| 1015 | class EditorAttributeInputColor(EditorAttributeInputBase): |