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 Input(NodeShape):22 def __init__(self, node, metrics=None):23 super(Input, self).__init__(node, metrics)2425 m = self.metrics.cell(self.node)26 r = self.metrics.cellsize * 32728 self.textbox = Box(m.topleft.x + r, m.topleft.y,29 m.bottomright.x - r, m.bottomright.y)3031 def render_shape(self, drawer, _, **kwargs):32 fill = kwargs.get('fill')3334 m = self.metrics.cell(self.node)35 r = self.metrics.cellsize * 33637 shape = [XY(m.topleft.x + r, m.topleft.y),38 XY(m.topright.x, m.topright.y),39 XY(m.bottomright.x - r, m.bottomright.y),40 XY(m.bottomleft.x, m.bottomleft.y),41 XY(m.topleft.x + r, m.topleft.y)]4243 # draw outline44 if kwargs.get('shadow'):45 shape = self.shift_shadow(shape)46 if kwargs.get('style') == 'blur':47 drawer.polygon(shape, fill=fill, outline=fill,48 filter='transp-blur')49 else:50 drawer.polygon(shape, fill=fill, outline=fill)51 elif self.node.background:52 drawer.polygon(shape, fill=self.node.color,53 outline=self.node.color)54 drawer.image(self.textbox, self.node.background)55 drawer.polygon(shape, fill="none",56 outline=self.node.linecolor, style=self.node.style)57 else:58 drawer.polygon(shape, fill=self.node.color,59 outline=self.node.linecolor, style=self.node.style)606162def setup(self):63 install_renderer('flowchart.input', Input)