1# -*- coding: utf-8 -*-2# Copyright 2011 Takeshi KOMIYA3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.1516from blockdiag.noderenderer import install_renderer17from blockdiag.noderenderer.base import NodeShape18from blockdiag.utils import XY, Box192021class Mail(NodeShape):22 def __init__(self, node, metrics=None):23 super(Mail, self).__init__(node, metrics)2425 m = self.metrics.cell(self.node)26 r = self.metrics.cellsize * 227 self.textbox = Box(m.topleft.x, m.topleft.y + r,28 m.bottomright.x, m.bottomright.y)2930 def render_shape(self, drawer, _, **kwargs):31 fill = kwargs.get('fill')3233 m = self.metrics.cell(self.node)34 r = self.metrics.cellsize * 23536 # draw outline37 box = self.metrics.cell(self.node).box38 if kwargs.get('shadow'):39 box = self.shift_shadow(box)40 if kwargs.get('style') == 'blur':41 drawer.rectangle(box, fill=fill, outline=fill,42 filter='transp-blur')43 else:44 drawer.rectangle(box, fill=fill, outline=fill)45 elif self.node.background:46 drawer.rectangle(box, fill=self.node.color,47 outline=self.node.color)48 drawer.image(self.textbox, self.node.background)49 drawer.rectangle(box, outline=self.node.linecolor,50 style=self.node.style)51 else:52 drawer.rectangle(box, fill=self.node.color,53 outline=self.node.linecolor,54 style=self.node.style)5556 # draw flap57 if not kwargs.get('shadow'):58 flap = [m.topleft, XY(m.top.x, m.top.y + r), m.topright]59 drawer.line(flap, fill=self.node.linecolor, style=self.node.style)606162def setup(self):63 install_renderer('mail', Mail)