/usr/share/pyshared/pyscript/lib/present.py is in python-pyscript 0.6.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | # Copyright (C) 2003-2006 Alexei Gilchrist and Paul Cochrane
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
'''
PyScript presentation library (posters and talks)
'''
from pyscript.defaults import defaults
from pyscript import Group, Rectangle, Color, TeX, Area, Align, Page, \
VAlign, Page, Text, P, Bbox, Pages
__revision__ = '$Revision: 1.8 $'
# ----------------------------------------------------------------------
# First some useful components
# ----------------------------------------------------------------------
class Box(Group, Rectangle):
'''
Draws a box around an object,
the box can be placed acording to standard Area tags
@cvar pad: padding around object
@cvar width: overide the width of the box
@cvar height: override the height of the box
'''
# set these preferences different from Rectangle:
fg = Color(0)
bg = Color(1)
pad = .2
width = None
height = None
def __init__(self, obj, **options):
Rectangle.__init__(self, **options)
Group.__init__(self, **options)
bbox = obj.bbox()
self.object = obj
w = bbox.width+2*self.pad
h = bbox.height+2*self.pad
# overide the width and height if supplied
if self.width is None:
self.width = options.get('width', w)
if self.height is None:
self.height = options.get('height', h)
self.append(
Rectangle(width=self.width, height=self.height,
bg=self.bg, fg=self.fg,
c=obj.c, r=self.r,
linewidth=self.linewidth, dash=self.dash),
obj,
)
# ----------------------------------------------------------------------
class TeXArea(Group):
'''
Typeset some LaTeX within a fixed width minipage environment.
@cvar width: the width of the environment
@type width: float
@cvar iscale: initial scale of the tex
@type iscale: float
@cvar align: alignment of the LaTeX to box if it iss smaller than
the full width
@type align: string (anchor point)
@cvar fg: color of TeX
@type fg: L{Color} object
'''
# has to be different from groups width attribute
width = 9.4
iscale = 1
fg = Color(0)
align = "w"
def __init__(self, text, **options):
Group.__init__(self, **options)
# set up tex width ... this relies on latex notion of
# a point being accurate ... adjust for tex_scale too
width_pp = int(self.width/float(self.iscale)*defaults.units)
t = TeX(r'\begin{minipage}{%dpt}%s\end{minipage}'%(width_pp, text),
fg=self.fg, iscale=self.iscale)
# use this for alignment as the latex bounding box may be smaller
# than the full width
a = Area(width=self.width, height=0)
Align(t, a, a1=self.align, a2=self.align, space=0)
self.append(a, t)
#apply(self, (), options)
# ----------------------------------------------------------------------
# Poster class
# ----------------------------------------------------------------------
class Poster(Page, VAlign):
'''
A poster class
@cvar size: the size of the poster eg A0
@cvar orientation: portrait or landscape
@cvar space: space between vertically aligned objects appended to poster
@cvar topspace: initial space at top of poster
@cvar bg: background color of poster (unless background() method
is overiden)
'''
size = "A0"
orientation = "portrait"
bg = Color('DarkSlateBlue')
space = 1
topspace = 2
def __init__(self, *objects, **options):
Page.__init__(self, **options)
VAlign.__init__(self, **options)
back = self.background()
# use Page's append so background doesn't get aligned
Page.append(self, back)
# add invisible area at top to start alignment
a = Area(width=0, height=self.topspace-self.space, n=self.area().n)
self.append(a)
def background(self):
'''
Return background for poster
'''
area = self.area()
signature = Text(
'Created with PyScript. http://pyscript.sourceforge.net',
size=14, fg=Color(1))
signature.se = area.se+P(-.5, .5)
return Group(
Rectangle(width=area.width, height=area.height,
fg=None, bg=self.bg),
signature,
)
# ----------------------------------------------------------------------
# Talk Class
# ----------------------------------------------------------------------
class Pause(object):
'''
A marker object to split slides to simulate a pause
can appear anywhere in the talk
'''
def bbox(self):
"""
Return the bounding box
"""
return Bbox()
# ----------------------------------------------------------------------
class Talk(Pages):
"""
A Talk class for seminar presentations
"""
def append(self, *slides_raw):
"""
Append slides to the Talk
@param slides_raw: list of slides to append to the talk
@type slides_raw: list
"""
slides = []
pg = 1
for slide in slides_raw:
slide(label = str(pg))
pg += 1
# find any Pauses present
pauses = []
f = slide.flatten()
for ii in range(len(f)):
if isinstance(f[ii][0], Pause):
pauses.append(ii)
for pause in pauses:
# create a copy and remove everything from Pause onwards
print "Found Pause(): splitting slide in two"
s = slide.copy()
fs = s.flatten()
for obj, group in fs[pause:]:
group.objects.remove(obj)
slides.append(s)
slides.append(slide)
for slide in slides:
Pages.append(self, slide)
def write(self, fp, title="PyScriptPS"):
"""
Write the talk out to file
@param fp: the file handle of the file to write to
@type fp: filehandle
@param title: the title to use in the output postscript
@type title: string
"""
tot = len(self)
for pp in range(tot):
self[pp].make(page=pp, total=tot)
Pages.write(self, fp, title)
# ----------------------------------------------------------------------
class EmptySlide(Page):
"""
An empty slide class
"""
title = None
orientation = "Landscape"
size = "screen"
def flatten(self, thegroup=None, objects=[]):
'''
Return a flattened list of objects
'''
if thegroup is None:
objects = []
objects = self.flatten(self.objects, objects)
else:
for obj in thegroup:
objects.append((obj, thegroup))
if isinstance(obj, Group):
objects = self.flatten(obj, objects)
return objects
def append(self, *items, **options):
"""
Append items to the slide
@param items: list of PyScript objects to append
@type items: list
@param options: dictionary of options (where to append object etc)
@type options: dict
"""
a1 = options.get('a1', None)
a2 = options.get('a2', None)
if (a1 is not None) and (a2 is not None) and len(items)>0:
assert a1 in ["n", "ne", "e", "se", "s", "sw", "w", "nw", "c"]
assert a2 in ["n", "ne", "e", "se", "s", "sw", "w", "nw", "c"]
area = self.main()
setattr(items[0], a1, getattr(area, a2))
return Page.append(self, *items)
def append_n(self, *items):
"""
Append items using the "north" attribute of the objects
@param items: list of objects to append
@type items: list
"""
return apply(self.append, items, {'a1':'n', 'a2':'n'})
def append_s(self, *items):
"""
Append items using the "south" attribute of the objects
@param items: list of objects to append
@type items: list
"""
return apply(self.append, items, {'a1':'s', 'a2':'s'})
def append_e(self, *items):
"""
Append items using the "east" attribute of the objects
@param items: list of objects to append
@type items: list
"""
return apply(self.append, items, {'a1':'e', 'a2':'e'})
def append_w(self, *items):
"""
Append items using the "west" attribute of the objects
@param items: list of objects to append
@type items: list
"""
return apply(self.append, items, {'a1':'w', 'a2':'w'})
def append_c(self, *items):
"""
Append items using the "centre" attribute of the objects
@param items: list of objects to append
@type items: list
"""
return apply(self.append, items, {'a1':'c', 'a2':'c'})
def main(self):
"""
Return the bounding box of the slide
"""
bbox = self.bbox()
return bbox
def make_back(self):
"""
Make the background of the slide
"""
return None
def make_title(self):
"""
Make the title of the slide
"""
return None
def clear(self):
"""
Clear the slide of objects
"""
Page.clear(self)
def make(self, page=1, total=1):
"""
Make the slide
@param page: the page in the sequence of slides to make (default=1)
@type page: int
@param total: the total number of slides in the talk (default=1)
@type total: int
"""
self.page = page
self.total = total
b = self.make_back()
if b is not None:
self.insert(0, b)
t = self.make_title()
if t is not None:
self.append(t)
# vim: expandtab shiftwidth=4:
|