1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2000-2005 by Yasushi Saito (yasushi.saito@gmail.com)
5 # Jockey is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2, or (at your option) any
10 # Jockey is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 invalid_coord = -999999
30 def init(fname = None, format = None):
32 """This is a "factory" procedure that creates a new canvas.T object.
33 Both parameters, <fname> and
34 <format>, are optional. Parameter <fname> specifies either the output
35 file name or a file object. Parameter <format>, if specified, defines the
36 file's format. Its value must be one of "ps", "pdf", "svg", "x11", or
39 When <fname> is omitted or is None, the output is sent to standard
40 output. When <format> is omitted, it is guessed from the <fname>'s
41 suffix; failing that, "ps" is selected."""
43 fname = fname or theme.output_file
44 format = format or theme.output_format
47 if not isinstance(fname, str):
49 elif re.search("pdf$", fname):
51 elif re.search("png$", fname):
53 elif re.search("svg$", fname):
59 can = pscanvas.T(fname)
61 can = pngcanvas.T(fname)
63 can = x11canvas.T(fname)
65 can = svgcanvas.T(fname)
67 can = pdfcanvas.T(fname, theme.compress_output)
71 if len(basecanvas.active_canvases) > 0:
72 return basecanvas.active_canvases[0]
77 global _oldexitfunc, _active_canvases
79 for can in basecanvas.active_canvases[:]:
88 # The following procedures are there just for backward compatibility.
90 def line(style, x1, y1, x2, y2):
91 default_canvas().line(style, x1, y1, x2, y2)
92 def curve(style, points):
93 default_canvas().curve(style, points)
94 def clip(x1, y1, x2, y2):
95 default_canvas().clip(x1, y1, x2, y2)
97 default_canvas().endclip()
98 def clip_polygon(points):
99 default_canvas().clip_polygon(points)
100 def clip_ellipsis(x, y, radius, ratio = 1.0):
101 default_canvas().clip_ellipsis(x, y, radius, ratio)
102 def ellipsis(line_style, pattern, x, y, radius, ratio = 1.0,
103 start_angle=0, end_angle=360, shadow=None):
104 default_canvas().ellipsis(line_style, pattern, x, y, radius, ratio,
105 start_angle, end_angle, shadow)
106 def rectangle(edge_style, pat, x1, y1, x2, y2, shadow = None):
107 default_canvas().rectangle(edge_style, pat, x1, y1, x2, y2, shadow)
108 def polygon(edge_style, pat, points, shadow = None):
109 default_canvas().polygon(edge_style, pat, points, shadow = None)
111 default_canvas().close()
112 def round_rectangle(style, fill, x1, y1, x2, y2, radius, shadow=None):
113 default_canvas().round_rectangle(style, fill, x1, y1, x2, y2, radius, shadow)
115 default_canvas().show(x, y, str)
118 if not vars(sys).has_key("exitfunc"):
120 elif sys.exitfunc != _exit:
121 _oldexitfunc = sys.exitfunc
124 #theme.add_reinitialization_hook(lambda: init(None))