home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 September / PCWorld_2002-09_cd.bin / Software / TemaCD / dia / dia-0.90-1-setup.exe / dia / export-render.py < prev    next >
Text File  |  2001-01-05  |  4KB  |  86 lines

  1. import sys, dia
  2.  
  3. # sys.path.insert(0, 'd:/graph/dia/dia')
  4. sys.argv = [ 'dia-python' ]
  5.  
  6. class DumpRenderer :
  7.     def __init__ (self) :
  8.         pass
  9.     def begin_render (self, data, filename) :
  10.         # DiagramData
  11.         self.f = open(filename, "w")
  12.         self.f.write("Data: " + str(data) + "\n")
  13.         self.f.write("Extents: "+ str(data.extents) + "\n")
  14.         self.f.write("active_layer: " + str(data.active_layer) + " " \
  15.                 + data.active_layer.name + "\n")
  16.         #self.f.write("grid .width: " + str(data.grid.width) \
  17.         #            + " .height" + str(data.grid.height) \
  18.         #            + "visible: " + str(data.visible) + "\n")
  19.     def end_render (self) :
  20.         self.f.close()
  21.     def set_linewidth (self, width) :
  22.         self.line_width = width
  23.     def set_linecaps (self, mode) :
  24.         self.line_caps = mode
  25.     def set_linejoin (self, mode) :
  26.         self.line_join = mode
  27.     def set_linestyle (self, style) :
  28.         self.line_style = style
  29.     def set_dashlength (self, length) :
  30.         self.dash_length = length
  31.     def set_fillstyle (self, style) :
  32.         self.fill_style = style
  33.     def set_font (self, font, size) :
  34.         self.font = font
  35.     def draw_line (self, start, end, color) :
  36.         self.f.write("draw_line:" + str(start) + str(end) + str(color) + "\n")
  37.     def draw_polyline (self, points, color) :
  38.         self.f.write("draw_polyline: " + str(color) + "\n")
  39.         for pt in points :
  40.             self.f.write ("\t" + str(pt) + "\n")
  41.     def draw_polygon (self, points, color) :
  42.         self.f.write("draw_polygon: " + str(color) + "\n")
  43.         for pt in points :
  44.             self.f.write ("\t" + str(pt) + "\n")
  45.     def fill_polygon (self, points, color) :
  46.         self.f.write("fill_polygon: " + str(color) + "\n")
  47.         for pt in points :
  48.             self.f.write ("\t" + str(pt) + "\n")
  49.     def draw_rect (self, rect, color) :
  50.         self.f.write("draw_rect: " + str(rect) + str(color) + "\n")
  51.     def fill_rect (self, rect, color) :
  52.         self.f.write("fill_rect: " + str(rect) + str(color) + "\n")
  53.     def draw_arc (self, center, width, height, angle1, angle2, color) :
  54.         self.f.write("draw_arc: " + str(center) + ";" \
  55.                 + str(width) + "x" + str(height) + ";" \
  56.                 + str(angle1) + "," + str(angle2) + ";" + str(color) + "\n")
  57.     def fill_arc (self, center, width, height, angle1, angle2, color) :
  58.         self.f.write("fill_arc: " + str(center) + ";" \
  59.                 + str(width) + "x" + str(height) + ";" \
  60.                 + str(angle1) + "," + str(angle2) + ";" + str(color) + "\n")
  61.     def draw_ellipse (self, center, width, height, color) :
  62.         self.f.write("draw_ellipse: " + str(center) \
  63.                 + str(width) + "x" +str(height) + ";" + str(color) + "\n")
  64.     def fill_ellipse (self, center, width, height, color) :
  65.         self.f.write("fill_ellipse: " + str(center) \
  66.                 + str(width) + "x" +str(height) + ";" + str(color) + "\n")
  67.     def draw_bezier (self, bezpoints, color) :
  68.         self.f.write("draw_bezier: " + str(color) + "\n")
  69.         for pt in bezpoints :
  70.             self.f.write ("\t" + str(pt) + "\n")
  71.     def fill_bezier (self, bezpoints, color) :
  72.         self.f.write("fill_bezier: " + str(color) + "\n")
  73.         for pt in bezpoints :
  74.             self.f.write ("\t" + str(pt) + "\n")
  75.     def draw_string (self, text, pos, alignment, color) :
  76.         self.f.write("draw_string: [" + text + "]; " + str(pos) \
  77.                 + str(alignment) + "; " +str(color))
  78.     def draw_image (self, point, width, height, image) :
  79.         self.f.write("draw_image: " + str(point) + str(width) + "x" +str(height) \
  80.                 + " " + image.filename + "\n")
  81.         self.f.write("<rgb_data>" + image.rgb_data + "</rgb_data>")
  82.         self.f.write("<mask_data>" + image.mask_data + "</mask_data>")
  83.  
  84. # dia-python keeps a reference to the renderer class and uses it on demand
  85. dia.register_export ("PyDia Render Export", "diapyr", DumpRenderer())
  86.