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_renderer1718try:19 from blockdiag.noderenderer.base import NodeShape20except ImportError:21 from blockdiag.noderenderer import NodeShape222324class PacketNode(NodeShape):25 def render_shape(self, drawer, _, **kwargs):26 # draw outline27 box = self.metrics.cell(self.node).box28 if kwargs.get('shadow'):29 pass30 else:31 drawer.rectangle(box, fill=self.node.color,32 outline=self.node.color)33 if self.node.background:34 drawer.loadImage(self.node.background, self.textbox)3536 self.line(drawer, box.topleft, box.topright, False)37 self.line(drawer, box.topright, box.bottomright,38 self.node.separated_right)39 self.line(drawer, box.bottomright, box.bottomleft, False)40 self.line(drawer, box.bottomleft, box.topleft,41 self.node.separated_left)4243 def line(self, drawer, _from, _to, is_dashed):44 if is_dashed:45 style = 'dashed'46 else:47 style = self.node.style4849 drawer.line((_from, _to), fill=self.node.linecolor, style=style)505152def setup(self):53 install_renderer('_packet_node', PacketNode)