Commits

Hiroki MIZUNO  committed 6183cce

support seqdiag

  • Participants
  • Parent commits 263291d

Comments (0)

Files changed (3)

File blockdiagcontrib_excelshape/excelshape.py

-# -*- coding: utf-8 -*- #  Copyright 2012 MIZUNO Hiroki
-# 
+# -*- coding: utf-8 -*- #  Copyright 2012 MIZUNO Hiroki # 
 #  Licensed under the Apache License, Version 2.0 (the "License");
 #  you may not use this file except in compliance with the License.
 #  You may obtain a copy of the License at
 import win32com.client
 import os
 import os.path
-from blockdiag.utils import XY
-from blockdiag.imagedraw import base
-
+from blockdiag.utils import XY,Box,Size
+from types import StringType
+from webcolors import name_to_rgb
+from blockdiag.imagedraw import base, textfolder
 class ExcelShapeImageDraw(base.ImageDraw):
     MSO_SHAPE_RECTANGE = 1
     MSO_SHAPE_OVAL     = 9
     MSO_SHAPE_ARC      = 25
+    MSO_LINE_DASH      = 4
     XL_CENTER = -4108
 
     def __init__(self, filename, **kwargs):
         self.excel         = win32com.client.Dispatch("Excel.Application") 
         self.excel.Visible = True
-        self.DisplayAlerts = False 
+        self.DisplayAlerts = False
         self.book = self.excel.Workbooks.Add()
 
     def set_canvas_size(self, size):
         pass
 
     def rgb(self, rgb):
-        if rgb == "white":
-            return 0xFFFFFF
-        else:
-            r,g,b = rgb
-            return (r << 16) + (g << 8) + b
+        if type(rgb) is StringType:
+            rgb = name_to_rgb(rgb)
+        r,g,b = rgb
+        return (b << 16) + (g << 8) + r
 
     def width(self, box):
         return box[2] - box[0]
         shape.TextFrame.VerticalAlignment = self.XL_CENTER
 
     def line(self, xy, **kwargs):
+        fill    = kwargs.get('fill')
+        style   = kwargs.get('style')
         x1,y1 = xy[0]
         x2,y2 = xy[1]
-        self.book.ActiveSheet.Shapes.AddLine(x1, y1, x2, y2)
+
+        line = self.book.ActiveSheet.Shapes.AddLine(x1, y1, x2, y2)
+
+        if fill != None:
+            line.Line.ForeColor.RGB = self.rgb(kwargs['fill'])
+        if style == 'dashed':
+            line.Line.DashStyle = self.MSO_LINE_DASH
 
     def arc(self, xy, start, end, **kwargs):
         w = self.width(xy)
         shape = form.ConvertToShape()
         self.set_style(shape, kwargs)
 
-    def loadImage(self, filename, box):
-        pass
-
     def save(self, filename, size, format):
         path = os.path.abspath(filename)
         if os.path.exists(path):
         self.book.SaveAs(path, 56)
         self.excel.Quit()
 
+    def textlinesize(self, string, font, **kwargs):
+        return Size(len(string)*15,10)
+
+    def textsize(self, string, font, maxwidth=None, **kwargs):
+        if maxwidth is None:
+            maxwidth = 65535
+
+        box = Box(0, 0, maxwidth, 65535)
+        textbox = textfolder.get(self, box, string, font=None, **kwargs)
+        return textbox.outlinebox.size
+
 def setup(self):
     from blockdiag.imagedraw import install_imagedrawer
     install_imagedrawer('shape.xls', ExcelShapeImageDraw)

File buildout.cfg

 [app]
 recipe = zc.recipe.egg
 eggs =
-     sphinx
-     sphinxcontrib-blockdiag
      blockdiag
+     seqdiag
      blockdiagcontrib-excelshape
 interpreter = py
      include_package_data=True,
      install_requires=[
         'blockdiag>=1.2.1',
+        'webcolors>=1.3',
         'setuptools'
      ],
      entry_points="""