Draws optional frame or borders to display element space. self.fill defines the color of the element background. Instead of the DrawBot stroke and strokeWidth attributes, use borders or (borderTop, borderRight, borderBottom, borderLeft) attributes. TODO: move to view
(self, view, p)
| 919 | return s |
| 920 | |
| 921 | def buildFrame(self, view, p): |
| 922 | """Draws optional frame or borders to display element space. self.fill |
| 923 | defines the color of the element background. Instead of the DrawBot |
| 924 | stroke and strokeWidth attributes, use borders or (borderTop, |
| 925 | borderRight, borderBottom, borderLeft) attributes. |
| 926 | |
| 927 | TODO: move to view. |
| 928 | """ |
| 929 | c = view.context |
| 930 | eShadow = self.shadow |
| 931 | |
| 932 | if eShadow: |
| 933 | c.save() |
| 934 | c.setShadow(eShadow) |
| 935 | c.rect(p[0], p[1], self.w, self.h) |
| 936 | c.restore() |
| 937 | |
| 938 | eFill = self.fill # Default is noColor |
| 939 | eStroke = self.stroke #self.css('stroke', default=noColor) |
| 940 | eGradient = self.gradient |
| 941 | |
| 942 | #if eStroke is not noColor or eFill is not noColor or eGradient: |
| 943 | c.save() |
| 944 | |
| 945 | # Drawing element fill and / or frame. |
| 946 | if eGradient: |
| 947 | # Gradient overwrites setting of fill. |
| 948 | # TODO: Make bleed work here too. |
| 949 | # Add self.w and self.h to define start/end from relative size. |
| 950 | c.setGradient(eGradient, p, self.w, self.h) |
| 951 | elif eFill is None or eFill is noColor: |
| 952 | c.fill(None) |
| 953 | else: |
| 954 | c.fill(eFill) |
| 955 | |
| 956 | if eStroke in (None, noColor): |
| 957 | c.stroke(None, 0) |
| 958 | else: # Separate from border behavior if set. |
| 959 | c.stroke(eStroke, self.strokeWidth) |
| 960 | |
| 961 | if self.framePath is not None: # In case defined, use instead of bounding box. |
| 962 | c.drawPath(self.framePath) |
| 963 | |
| 964 | w = None |
| 965 | h = None |
| 966 | if len(p) == 4: |
| 967 | x, y, w, h = p |
| 968 | elif len(p) == 2: |
| 969 | x, y = p |
| 970 | else: |
| 971 | x = y = 0 |
| 972 | #msg = 'Element.buildFrame(): Badly formatted position argument p' |
| 973 | #print(msg) |
| 974 | # TODO: raise error. |
| 975 | |
| 976 | w = w or self.w |
| 977 | h = h or self.h |
| 978 |
no test coverage detected