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 __future__ import division1718from blockdiag.noderenderer import install_renderer19from blockdiag.noderenderer.base import NodeShape20from blockdiag.utils import XY, Box, images212223class TextBox(NodeShape):24 def __init__(self, node, metrics=None):25 super(TextBox, self).__init__(node, metrics)2627 if self.node.background:28 size = images.get_image_size(self.node.background)29 size = images.calc_image_size(size, self.textbox.size)3031 pt = self.textbox.center32 self.textbox = Box(pt.x - size[0] // 2, pt.y - size[1] // 2,33 pt.x + size[0] // 2, pt.y + size[1] // 2)3435 self.connectors[0] = XY(pt.x, self.textbox[1])36 self.connectors[1] = XY(self.textbox[2], pt.y)37 self.connectors[2] = XY(pt.x, self.textbox[3])38 self.connectors[3] = XY(self.textbox[0], pt.y)3940 if self.node.icon:41 self.connectors[3] = XY(self.iconbox[0], pt.y)4243 def render_shape(self, drawer, _, **kwargs):44 if not kwargs.get('shadow') and self.node.background:45 drawer.image(self.textbox, self.node.background)464748def setup(self):49 install_renderer('textbox', TextBox)