/usr/share/pyshared/pyscript/lib/presentation.py is in python-pyscript 0.6.1-4.
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 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 | # 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.
# $Id: presentation.py,v 1.39 2006/04/24 14:07:10 paultcochrane Exp $
'''
PyScript presentation library (posters and talks)
There are some common useful component classes such as TeXBox and Box_1,
followed by Poster and Talk classes
'''
__revision__ = '$Revision: 1.39 $'
from pyscript.defaults import defaults
from pyscript import Color, Group, Epsf, Area, P, Align, Rectangle, TeX, \
Page, Distribute, Text, Pages, VAlign, Path
from pyscript.render import render
import os, types
class TeXBox(Group):
'''
Typeset some LaTeX within a fixed width box.
@ivar fixed_width: the width of the box
@type fixed_width: float
@ivar tex_scale: The amount by which to scale the TeX
@type tex_scale: float
@ivar align: alignment of the LaTeX to box if it is smaller
@type align: anchor string
'''
def __init__(self, text, fixed_width=9.4, tex_scale=0.7, align="w",
fg = Color(0), text_style="",
**options):
Group.__init__(self, **options)
self.text = text
self.fixed_width = fixed_width
self.tex_scale = tex_scale
self.fg = fg
self.align = align
self.text_style = text_style
def set_fg(self, fg):
"""
Set the foreground colour
"""
self.fg = fg
def set_fixed_width(self, fixed_width):
"""
Set the fixed width attribute
"""
self.fixed_width = fixed_width
def set_tex_scale(self, tex_scale):
"""
Set the scale of TeX objects
"""
self.tex_scale = tex_scale
def set_align(self, align):
"""
Set the anchor point where to align objects
"""
self.align = align
def set_text_style(self, text_style):
"""
Set the text style (in LaTeX)
"""
self.text_style = text_style
def make(self):
"""
Make the TeXBox
"""
width_pp = int(self.fixed_width/float(self.tex_scale)*defaults.units)
al = Align(a1=self.align, a2=self.align, space=0)
t = TeX(r'\begin{minipage}{%dpt}%s %s\end{minipage}' \
% (width_pp, self.text_style, self.text),
fg=self.fg)
t.scale(self.tex_scale, self.tex_scale)
al.append(t)
a = Area(width=self.fixed_width, height=0)
al.append(a)
self.append(al)
return self
#apply(self, (), options) # why do we do this???
class Box_1(Group):
'''
A box of fixed width. Items added to it are aligned vertically and
separated by a specified padding
@cvar border: width of the border (in pts)
@type border: int
@cvar fg: color of border
@type fg: L{Color} object
@cvar bg: color of box background
@type bg: L{Color} object
@cvar fixed_width: width of box
@type fixed_width: float
@cvar pad: vertical padding between items
@type pad: float
@cvar r: corner radius
@type r: float
'''
bg = Color('Lavender')
fg = Color(0)
border = 1
fixed_width = 9.6
pad = 0.2
r = 0
def __init__(self, *items, **options):
Group.__init__(self, **options)
apply(self.append, items)
Align(self, a1="s", a2="n", angle=180, space=self.pad)
gb = self.bbox()
r = Rectangle(n=gb.n+P(0, self.pad),
width=self.fixed_width,
height=gb.height+2*self.pad,
bg=self.bg,
fg=self.fg,
linewidth=self.border,
r=self.r,
)
self.insert(0, r)
class CodeBox(Group):
"""
A box with a 'dog-ear' to contain code fragments
"""
def __init__(self, text, **options):
Group.__init__(self, **options)
obj = TeXBox(text)
obj.make()
bg = Color('Orange')*1.3
fg = Color('black')*0.4
border = 0.75
#fixed_width = 2.5
pad = 0.2
dogear = 0.25
gb = obj.bbox()
h = gb.height
w = gb.width
self.append(Path(
P(-pad, -pad),
P(-pad, h+pad),
P(w+pad, h+pad),
P(w+pad, -pad+dogear),
P(w+pad-dogear, -pad),
P(w+pad-dogear, -pad+dogear),
P(w+pad, -pad+dogear),
P(w+pad-dogear, -pad),
P(-pad, -pad),
bg=bg,
fg=fg,
linewidth=border,
miterlimit=1.0)
)
obj.c = self.bbox().c
self.append(obj)
class Poster(Page):
"""
A poster class.
More docs forthcoming...
"""
def __init__(self, size, style=None):
Page.__init__(self)
# set stuff up
self.size = size
self.orientation = "Portrait"
self.num_columns = 2
# set the default style settings
self.title = ""
self.title_fg = Color(0)
self.title_scale = 1.4
self.title_width = 0.8 # as a fraction of the total poster width
self.title_text_style = "\large"
self.authors = ""
self.authors_fg = Color(0)
self.authors_scale = 1
self.authors_width = 0.8 # as a fraction of the total poster width
self.authors_text_style = ""
self.address = ""
self.address_fg = Color(0)
self.address_scale = 0.9
self.address_width = 0.8 # as a fraction of the total poster width
self.address_text_style = ""
self.abstract = ""
self.abstract_fg = Color(0)
self.abstract_scale = 0.8
self.abstract_width = 0.92 # relative to total width of poster
self.abstract_text_style = ""
self.gutter = 0.2
self.pad = 0 # should get set by add_column()
self.item_sep = 0.3
self.bg = Color(1)
self.signature_fg = Color(0)
self.logo_height = 1.2
# styles for columns
self.column_item_sep = 0.3
# styles for column boxes
# the title's style...
self.column_box_title_align = "c"
self.column_box_title_tex_scale = 1.4
self.column_box_title_fixed_width = 9.4
self.column_box_title_text_style = r""
self.column_box_title_fg = Color(0)
# the text styles of the column box
self.column_box_text_align = "w"
self.column_box_tex_scale = 0.7
self.column_box_text_width = 9.4
self.column_box_text_style = r""
self.column_box_text_fg = Color(0)
# the column box styles
self.column_box_item_sep = 0.1
self.column_box_width = 9.9
self.column_box_bg = Color(1)
self.column_box_border = 1
# process the style option
if style is not None:
# make sure the file exists in either the .pyscript/styles
# directory, or the current directory
styleFname = style + ".py"
HOME = os.path.expandvars("$HOME")
if os.path.exists(HOME + "/.pyscript/styles/" + styleFname):
print "Found %s in .pyscript/styles dir" % style
self._read_style(HOME + "/.pyscript/styles/" + styleFname)
elif os.path.exists(styleFname):
print "Found %s in current dir" % style
self._read_style(styleFname)
else:
# barf
raise ValueError, "Style %s not found!" % style
self.logos = []
self.columns = []
self.area = self.area()
# subtract the gutter to get the printing area
self.printing_area = Area(
sw=self.area.sw + P(1, 1)*self.gutter,
width=self.area.width - 2*self.gutter,
height=self.area.height - 2*self.gutter
)
def _read_style(self, styleFname):
"""
Read the talk style file
@param styleFname: The name of the style file to process
@type styleFname: string
"""
# slurp in the text
fp = open(styleFname, "r")
lines = fp.readlines()
fp.close()
# make one big string...
styleText = ""
for line in lines:
styleText += line
# exec the text
exec(styleText)
def set_title(self, title):
"""
Set the title to use for the poster
@param title: the text of the poster title
@type title: string
"""
self.title = title
pass
def set_authors(self, authors):
"""
Set the authors of the poster
@param authors: the text of the poster authors
@type authors: string
"""
self.authors = authors
pass
def set_address(self, address):
"""
Set the address of the institution of those presenting the poster
@param address: the text of the address
@type address: string
"""
self.address = address
pass
def set_abstract(self, abstract):
"""
Set the abstract of the poster
@param abstract: the text of the poster abstract
@type abstract: string
"""
self.abstract = abstract
pass
def set_size(self, size):
"""
Set the size of the poster.
These are standard page sizes. It is a good idea to develop a
poster at a size of "a4" and then for the final poster use "a0". It
is also handy when at a poster session at a conference to have a4
size versions of the a0 poster to give out to people, so the a4
setting is also handy for that.
@param size: the size of the poster
@type size: string
"""
self.size = size
pass
def set_style(self, style):
"""
Set the style of the poster. This is the name of a set of
predefined fonts, sizes, colours etc for the text, the columns of
the poster and the poster background.
@param style: the text of the name of the poster style to use
@type style: string
"""
self.style = style
pass
def set_orientation(self, orientation):
"""
Set the orientation of the poster. Options are "portrait" or
"landscape".
@param orientation: the page orientation of the poster
@type orientation: string
"""
self.orientation = orientation
pass
def set_num_columns(self, num_columns):
"""
Set the number of columns to use for the poster. Typically one
would use two columns for portrait, and three for landscape.
@param num_columns: the number of columns to use
@type num_columns: int
"""
self.num_columns = num_columns
pass
def add_logo(self, logo, height=None):
"""
Add a logo to the poster.
If only one logo is added to the poster, it is by default located at
the top left-hand corner. The second logo is then positioned in the
top right-hand corner. The third is positioned in the top middle.
If you add more than that, the logos are distributed evenly across
the top of the poster.
@param logo: the file name of the eps file of the logo to add
@type logo: text
@param height: the height of the logo
@type height: float
"""
if height is None:
height = self.logo_height
obj = Epsf(logo, height=height)
self.logos.append(obj)
def add_logos(self, *logos, **options):
"""
Add several logos to the poster at one time.
If only one logo is added to the poster, it is by default located at
the top left-hand corner. The second logo is then positioned in the
top right-hand corner. The third is positioned in the top middle.
If you add more than that, the logos are distributed evenly across
the top of the poster.
@param logos: list of file names of the eps files of the logos to add
@type logos: list of strings
@keyword height: the height of the logo
@type height: float
"""
# process the options, if any
if options.has_key('height'):
height = options['height']
else:
height = self.logo_height
for logo in logos:
obj = Epsf(logo, height=height)
self.logos.append(obj)
def add_column(self, column, side):
"""
Add a column of the poster.
@param column: the Column object to add as the poster column
@type column: Column object
@param side: the side on which the column is to be on the poster.
Valid values are "left", "middle" (useful for landscape only) and
"right".
@type side: string
"""
# there must be a better way to write this if statement,
# something like if side is not in [left, middle, right] ???
if side != 'left' and side != 'middle' and side != 'right':
errMsg = "You must specify either 'left', 'middle', or 'right'\n"
errMsg += "I got: '%s'" % side
raise ValueError, errMsg
self.columns.append(column._make())
def _make_title(self):
"""
Make the title
"""
titlebox = TeXBox(text=self.title)
titlebox.set_fg(self.title_fg)
titlebox.set_fixed_width(self.printing_area.width*self.title_width)
titlebox.set_tex_scale(self.title_scale)
titlebox.set_align("c")
titlebox.set_text_style(self.title_text_style)
titlebox.make()
return titlebox
def _make_authors(self):
"""
Make the authors
"""
authorbox = TeXBox(self.authors)
authorbox.set_fg(self.authors_fg)
authorbox.set_tex_scale(self.authors_scale)
authorbox.set_fixed_width(self.printing_area.width*self.authors_width)
authorbox.set_align("c")
authorbox.set_text_style(self.authors_text_style)
authorbox.make()
return authorbox
def _make_address(self):
"""
Make the address
"""
addressbox = TeXBox(self.address)
addressbox.set_fg(self.address_fg)
addressbox.set_tex_scale(self.address_scale)
addressbox.set_fixed_width(self.printing_area.width*self.address_width)
addressbox.set_align("c")
addressbox.set_text_style(self.address_text_style)
addressbox.make()
return addressbox
def _make_abstract(self):
"""
Make the abstract
"""
abstractbox = TeXBox(self.abstract)
abstractbox.set_fg(self.abstract_fg)
abstractbox.set_tex_scale(self.abstract_scale)
abstractbox.set_fixed_width(
self.printing_area.width*self.abstract_width)
abstractbox.set_align("c")
abstractbox.set_text_style(self.abstract_text_style)
abstractbox.make()
return abstractbox
def _make_logos(self):
"""
Make the logos
"""
logos = Align(a1="e", a2="w", angle=90, space=None)
for logo in self.logos:
logos.append(logo)
Distribute(logos, a1="e", a2="w",
p1=self.printing_area.nw,
p2=self.printing_area.ne,
)
return logos
def _make_columns(self):
"""
Make the columns
"""
#print "Number of columns is: %d" % len(self.columns)
# vertically align the columns items, but with no spacing yet
#for col in self.columns:
#VAlign(col, space=None)
# distribute the columns horizontally
if self.num_columns == 2:
Distribute(Area(width=0, height=0),
self.columns[0], self.columns[1],
Area(width=0, height=0),
p1=self.printing_area.w,
p2=self.printing_area.e,
a1="e", a2="w")
elif self.num_columns == 3:
Distribute(Area(width=0, height=0),
self.columns[0], self.columns[1], self.columns[2],
Area(width=0, height=0),
p1=self.printing_area.w,
p2=self.printing_area.e,
a1="e", a2="w")
else:
raise ValueError, \
"Incorrect number of columns. Should be 2 or 3. I got %d" % \
self.num_columns
# find the distance between two of the columns
self.pad = (self.columns[1].bbox().w - self.columns[0].bbox().e)[0]
# vertically align the column items
#print self.pad
#for col in self.columns:
#VAlign(col, space=self.pad)
# now align the columns themselves
all_cols = Align(angle=90, space=None, a1="ne", a2="nw")
for col in self.columns:
#col.set_space(self.pad)
col.set_space(0)
#print col.get_space()
all_cols.append(col._make())
return all_cols
def _make_background(self):
"""
Make the background of the poster
"""
area = self.area()
return Rectangle(width=area.width,
height=area.height,
fg=None,
bg=self.bg
)
def make(self, file):
"""
Make the poster.
@param file: the file name of the poster output eps file
@type file: string
"""
all = Align(a1="s", a2="n", angle=180, space=self.item_sep)
all.append(self._make_logos())
all.append(self._make_title())
all.append(self._make_authors())
all.append(self._make_address())
all.append(self._make_abstract())
all.append(self._make_columns())
all.n = self.printing_area.n - P(0, 0.1)
back = self._make_background()
p = self.printing_area.se+P(0, 1.2)
signature = Text(
"Created with PyScript. http://pyscript.sourceforge.net",
size=6, sw=p, fg=self.signature_fg).rotate(-90, p)
self.append(back)
self.append(all)
self.append(signature)
# actually generate the postscript
render(self, file=file)
class Column(VAlign): # I *think* this should inherit from VAlign...
"""
A column of a poster. Basically just a container for various boxes.
More docs forthcoming...
"""
def __init__(self, poster):
VAlign.__init__(self)
#Group.__init__(self)
self.boxes = []
self.space = poster.column_item_sep
def add_box(self, box):
"""
Add a box to the column
@param box: the box to add to the column
@type box: ColumnBox object
"""
self.append(box._make())
def set_space(self, space):
"""
Set the spacing of the column items
@param space: the space between the items
@type space: float
"""
#print "Column.set_space()"
self.space = space
def get_space(self):
"""
Get the spacing of the column items
"""
return self.space
def _make(self):
"""
Make the column
"""
#print "Column._make()"
for box in self.boxes:
self.append(box._make())
return self
class ColumnBox(Group):
"""
A box, containing various objects, with a fixed width, but variable
height
Should add more docs here too...
"""
def __init__(self, poster):
Group.__init__(self)
self.title_align = poster.column_box_title_align
self.title_tex_scale = poster.column_box_title_tex_scale
self.title_fixed_width = poster.column_box_title_fixed_width
self.title_text_style = poster.column_box_title_text_style
self.title_fg = poster.column_box_title_fg
self.align = poster.column_box_text_align
self.tex_scale = poster.column_box_tex_scale
self.fixed_width = poster.column_box_text_width
self.text_style = poster.column_box_text_style
self.fg = poster.column_box_text_fg
self.item_sep = poster.column_box_item_sep
self.box_width = poster.column_box_width
self.box_bg = poster.column_box_bg
self.box_border = poster.column_box_border
self.title = ""
self.items = []
def set_title(self, title):
"""
Set the title of the box within the column
@param title: the title of the column box
@type title: string
"""
self.title = title
def add_TeXBox(self, text):
"""
Adds a TeXBox object to the column
@param text: the text of the TeXBox object to add
@type text: string
"""
texbox = TeXBox(text)
texbox.make()
# other settings here...
self.items.append(texbox)
def add_fig(self, fig, height=None, width=None, bg=Color(1)):
"""
Add an arbitrary figure to the column box, with a background.
This could be a previously defined pyscript diagram (for instance).
If only one of the height or width is given then the figure is
scaled appropriately, maintaining the original aspect ratio.
@param fig: the figure to add
@type fig: PyScript object
@param width: the width of the figure
@type width: float
@param height: the height of the figure
@type height: float
@param bg: the colour of the figure background
@type bg: Color object
"""
# get the figure's current height and width
oldHeight = fig.bbox().height
oldWidth = fig.bbox().width
# scale the figure appropriately
if height is not None and width is None:
scale = height/oldHeight
fig = fig.scale(scale, scale)
elif height is None and width is not None:
scale = width/oldWidth
fig = fig.scale(scale, scale)
elif height is not None and width is not None:
xscale = width/oldWidth
yscale = height/oldHeight
fig = fig.scale(xscale, yscale)
else:
# leave well alone...
pass
# put a white background on it
gutter = 0.1
rect = Rectangle(width=fig.bbox().width+gutter,
height=fig.bbox().height+gutter,
c=fig.bbox().c,
bg=bg, fg=None)
# group everything together
all = Group()
all.append(rect, fig)
# append it to the list of items in the ColumnBox
self.items.append(all)
def add_epsf(self, file, height=None, width=None):
"""
Add an eps file to the column box.
If only one of the height or width is given then the figure is
scaled appropriately, maintaining the original aspect ratio.
@param file: the file name of the eps file to add
@type file: string
@param width: the width of the figure
@type width: float
@param height: the height of the figure
@type height: float
"""
# load the eps with the appropriate dimensions
if height is not None and width is None:
eps = Epsf(file=file, height=height)
elif height is None and width is not None:
eps = Epsf(file=file, width=width)
elif height is not None and width is not None:
eps = Epsf(file=file, width=width, height=height)
else:
# use the file's own size
eps = Epsf(file=file)
# append it to the list of items in the ColumnBox
self.items.append(eps)
def add_object(self, obj):
"""
Add a pre-defined object to the box, this could be an Align or Group
object for example
@param obj: the object to be added
@type obj: pyscript object
"""
self.items.append(obj)
def add_text(self, text):
"""
Add arbitrarily placed text to the box
@param text: the text to be added
@type text: string
"""
tex = TeX(text)
self.items.append(tex)
def _make_title(self):
"""
Make the title
"""
titlebox = TeXBox(self.title)
titlebox.set_align(self.title_align)
titlebox.set_tex_scale(self.title_tex_scale)
titlebox.set_fixed_width(self.title_fixed_width)
titlebox.set_text_style(self.title_text_style)
titlebox.set_fg(self.title_fg)
titlebox.make()
return titlebox
def _make(self):
"""
Make the column box object
"""
valign = VAlign(space=self.item_sep)
valign.append(self._make_title())
#print "Number of items in the column box is: %d" % len(self.items)
for item in self.items:
valign.append(item)
# the reason for the BasicBox class is to let the overall poster
# style handle the width, foreground, etc. etc.
box = BasicBox()
box.set_height(valign.bbox().height + 2*box.pad)
box.set_width(self.box_width)
box.set_anchor("n", valign.bbox().n+P(0, 0.2))
#box.n = valign.bbox().n+P(0, 0.2) # absorb into style ???
box.set_bg(self.box_bg)
box.set_border(self.box_border)
# append the objects to the group
self.append(box)
self.append(valign)
return self
class BasicBox(Rectangle):
"""
A basic box, with border, and background to use in behind textual and
other objects
"""
def __init__(self):
Rectangle.__init__(self)
self.bg = Color("lavender")
self.fg = Color(0)
self.border = 1
self.fixed_width = 9.6
self.pad = 0.2
self.radius = 0
self.width = 9.9
self.height = 1
self.anchor = "n"
def set_height(self, height):
"""
Set the height of the box
"""
self.height = height
def set_width(self, width):
"""
Set the width of the box
"""
self.width = width
def set_bg(self, bg):
"""
Set the background colour
"""
self.bg = bg
def set_fg(self, fg):
"""
Set the foreground colour
"""
self.fg = fg
def set_border(self, border):
"""
Set the width of the border around the box
"""
self.linewidth = border
def set_radius(self, radius):
"""
Set the radius of the corners of the box, if they are rounded
"""
self.r = radius
def set_pad(self, pad):
"""
Set the padding around the box
"""
self.pad = pad
def set_anchor(self, anchor, location):
"""
Set the anchor location (c, n, ne, e, se, s, sw, w, nw)
"""
exec("self.%s = location" % anchor)
class Poster_1(Page):
'''
A poster style, portrait orientation very similar to a
journal article's front page. Title, authors and abstract across
top. two columns for boxes with details. It is set up for A4 paper
which can then be scaled for A0 etc.
@cvar bg: poster background
@cvar gutter: nonprintable margin around entire poster
@cvar title: TeX of title
@cvar title_fg: fg color of title
@cvar title_scale: scale of title TeX
@cvar title_width: proportion of total width for title
@cvar authors: TeX of authors
@cvar authors_fg: fg color of authors
@cvar authors_scale: scale of authors TeX
@cvar authors_width: proportion of total width for authors
@cvar address: TeX of address
@cvar address_fg: fg color of address
@cvar address_scale: scale of address TeX
@cvar address_width: proportion of total width for address
@cvar abstract: TeX of abstract
@cvar abstract_fg: fg color of abstract
@cvar abstract_scale: scale of abstract TeX
@cvar abstract_width: proportion of total width for abstract
@cvar logos: a list of filenames for the logos
@cvar logo_height: the height to which to scale the logos
@cvar printing_area: an Area the size of the page minus the gutter
@cvar col1: a Group() containing left column objects
@cvar col2: a Group() containing right column objects
'''
col1 = Group()
col2 = Group()
logos = ()
def __init__(self):
Page.__init__(self)
self.size = "A4"
self.gutter = 0.2 # paper margin for A4 in cm
self.bg = Color('DarkSlateBlue')
self.title = ""
self.title_fg = Color('Yellow')
self.title_scale = 1.4
self.title_width = 0.8
self.address = ""
self.address_fg = Color(0)
self.address_scale = 1
self.address_width = 0.8
self.authors = ""
self.authors_fg = Color(0)
self.authors_scale = 1
self.authors_width = 0.8
self.abstract = ""
self.abstract_fg = Color(0)
self.abstract_scale = 0.8
self.abstract_width = 0.8
self.logo_height = 0.8
#self.logos = ()
#self.col1 = Group()
#self.col2 = Group()
self.signature_fg = self.bg*0.8
area = self.area()
# subtract the gutter to get printing area
self.printing_area = Area(
sw=area.sw+P(1, 1)*self.gutter,
width=area.width-2*self.gutter,
height=area.height-2*self.gutter
)
def add_fig(self, file, width=5.0):
"""
This method needs to be fixed up. It's not to put a figure on the
page, but an eps file...
"""
fig = Epsf(file)
rect1 = Rectangle(c=fig.c,
width=fig.bbox().width+0.1,
height=fig.bbox().height+0.1,
fg=Color('black'),
bg=Color('white'),
linewidth=0.5,
)
out_fig = Group(rect1,fig)
out_fig.scale(width/out_fig.bbox().width,width/out_fig.bbox().width)
return out_fig
def add_epsf(self):
"""
Add and EPS file to the poster
"""
pass
def _make_logos(self):
"""
Make and return a Group object of the logos
"""
#thelogos = Group()
thelogos = Align(a1="e", a2="w", angle=90, space=None)
for logo in self.logos:
thelogos.append(Epsf(logo, height=self.logo_height))
Distribute(thelogos, a1="e", a2="w",
p1=self.printing_area.nw,
p2=self.printing_area.ne)
#Align(thelogos, a1="e", a2="w", angle=90, space=None)
return thelogos
def _make_title(self):
'''
Return a title object
'''
return TeXBox(self.title, fg=self.title_fg,
fixed_width=self.printing_area.width*self.title_width,
tex_scale=self.title_scale,
align="c").make()
def _make_address(self):
"""
Return an address object
"""
return TeXBox(self.address,
fg=self.address_fg,
fixed_width=self.printing_area.width*self.address_width,
tex_scale=self.address_scale,
align="c").make()
def _make_abstract(self):
'''
Return the abstract object
'''
return TeXBox(self.abstract,
fixed_width=self.printing_area.width*self.abstract_width,
tex_scale=self.abstract_scale,
fg=self.abstract_fg, align="c").make()
def _make_authors(self):
'''
Return authorlist object
'''
return TeXBox(self.authors,
fg=self.authors_fg,
tex_scale=self.authors_scale,
fixed_width=self.printing_area.width*self.authors_width,
align="c").make()
def _make_background(self):
'''
Return background (block color)
'''
area = self.area()
return Rectangle(width=area.width,
height=area.height,
fg=None,
bg=self.bg
)
def make(self):
'''
Create the actual poster aligning everything up.
calls make_title(), make_authors() etc
'''
# NB: A0 = 4x A4
# vertically align the column items ... no spacing yet!
Align(self.col1, a1="s", a2="n", angle=180, space=None)
Align(self.col2, a1="s", a2="n", angle=180, space=None)
# Distribute the cols horizontally
Distribute(Area(width=0, height=0),
self.col1, self.col2,
Area(width=0, height=0),
p1=self.printing_area.w,
p2=self.printing_area.e,
a1="e", a2="w")
# find the distance between the cols
pad = (self.col2.bbox().w-self.col1.bbox().e)[0]
# vertically align the column items
Align(self.col1, a1="s", a2="n", angle=180, space=pad)
Align(self.col2, a1="s", a2="n", angle=180, space=pad)
# align the two columns themselves
cols = Align(self.col1, self.col2,
angle=90, space=None, a1="ne", a2="nw")
all = Align(
self._make_logos(),
self._make_title(),
self._make_authors(),
self._make_address(),
self._make_abstract(),
cols,
a1="s", a2="n", angle=180, space=pad
)
all.n = self.printing_area.n-P(0, 0.1)
back = self._make_background()
p = self.printing_area.se+P(0, 1.2)
signature = Text(
'Created with PyScript. http://pyscript.sourceforge.net',
size=6, sw=p, fg=self.signature_fg
).rotate(-90, p)
self.append(back, all, signature)
# return a reference for convenience
return self
class Talk(Pages):
"""
A talk class
"""
def __init__(self, style=None):
Pages.__init__(self)
self.slides = []
self.bg = Color('RoyalBlue')*0.9
self.fg = self.bg
self.logos = []
self.logo_height = 0.8
self.title = ""
self.title_fg = Color('white')
self.title_scale = 5
self.title_textstyle = ""
self.slide_title = ""
self.slide_title_fg = Color('white')
self.slide_title_scale = 5
self.slide_title_textstyle = ""
self.footerScale = 1
self.waitbar_fg = Color('orangered')
self.waitbar_bg = Color('black')
self.authors = ""
self.authors_fg = Color('white')
self.authors_scale = 3
self.authors_textstyle = ""
self.speaker = "" # i.e. who's actually giving the talk
self.speaker_fg = Color(0)
self.speaker_textstyle = ""
self.address = ""
self.address_fg = Color('white')
self.address_scale = 2
self.address_textstyle = ""
self.box_bg = Color('lavender')
self.box_fg = Color(0)
self.box_border = 2
self.text_scale = 3
self.text_fg = Color(0)
self.text_textstyle = ""
self.headings_fgs = {
1 : Color('white'),
2 : Color('white'),
3 : Color('white'),
"equation" : Color('white'),
"default" : Color('white'),
"space" : self.fg,
}
self.headings_scales = {
1 : 3,
2 : 2.5,
3 : 2.2,
"equation" : 2.5,
"default" : 1.5,
"space" : 3,
}
self.headings_bullets = {
1 : TeX(r"$\bullet$"),
2 : TeX(r"--"),
3 : TeX(r"$\gg$"),
"equation" : Rectangle(height=1, fg=self.bg, bg=self.bg),
"default" : TeX(r"$\cdot$"),
"space" : Rectangle(height=1, fg=self.bg, bg=self.bg),
}
self.headings_indent = {
1 : 0,
2 : 0.5,
3 : 1,
"equation" : 2,
"default" : 2,
"space" : 0,
}
self.headings_textstyle = {
1 : "",
2 : "",
3 : "",
"equation" : "",
"default" : "",
"space" : "",
}
# process the style option
if style is not None:
# make sure the file exists in either the .pyscript/styles
# directory, or the current directory
styleFname = style + ".py"
HOME = os.path.expandvars("$HOME")
if os.path.exists(HOME + "/.pyscript/styles/" + styleFname):
print "Found %s in .pyscript/styles dir" % style
self._read_style(HOME + "/.pyscript/styles/" + styleFname)
elif os.path.exists(styleFname):
print "Found %s in current dir" % style
self._read_style(styleFname)
else:
# barf
raise ValueError, "Style %s not found!" % style
def _read_style(self, styleFname):
"""
Read the talk style file
@param styleFname: The name of the style file to process
@type styleFname: string
"""
# slurp in the text
fp = open(styleFname, "r")
lines = fp.readlines()
fp.close()
# make one big string...
styleText = ""
for line in lines:
styleText += line
# exec the text
exec(styleText)
def set_title(self, title):
"""
Set the title of the talk as a whole
@param title: the title of the talk
@type title: string
"""
self.title = title
return
def set_authors(self, authors):
"""
Set the authors of the talk
@param authors: the author list for the talk
@type authors: string
"""
self.authors = authors
return
def set_speaker(self, speaker):
"""
Set the name of the person actually giving the talk/presentation
@param speaker: the name of the person giving the talk
@type speaker: string
"""
self.speaker = speaker
return
def set_address(self, address):
"""
Set the address for the institution (or equivalent) of the speaker
@param address: the address to use
@type address: string
"""
self.address = address
return
def add_logo(self, logo, height=None):
"""
Add a logo to the talk
@param logo: eps file name of logo
@type logo: string
"""
if height is None:
height = self.logo_height
self.logos.append(Epsf(file=logo, height=height))
def _make_authors(self):
"""
Generate the authors text on the titlepage
"""
ttext = "%s %s" % (self.authors_textstyle, self.authors)
return TeX(ttext, fg=self.authors_fg
).scale(self.authors_scale, self.authors_scale)
def _make_address(self):
"""
Generate the address text on the titlepage
"""
if isinstance(self.address, types.StringType):
ttext = "%s %s" % (self.address_textstyle, self.address)
return TeX(ttext, fg=self.address_fg
).scale(self.address_scale, self.address_scale)
else:
#raise ValueError, "Can't handle non-string arguments yet"
return self.address
def make(self, *slides, **options):
"""
Routine to collect all of slides together and render them all as
the one document
"""
# create the titlepage automatically
titlepage = Slide(self)
titlepage.set_titlepage()
self.slides.append(titlepage)
# create the list of slides
for slide in slides:
self.slides.append(slide)
# add all the slides to the talk
i = 1
temp = Pages()
for slide in self.slides:
slide.pageNumber = i
print 'Adding slide', str(i), '...'
temp.append(slide._make(self))
i += 1
# determine the file name to use
if not options.has_key('file'):
raise ValueError, "No filename given"
file = options['file']
# render it!
render(temp, file=file)
class Slide(Page):
"""
A slide class. Use this class to generate the individual slides in a talk
"""
def __init__(self, talk):
Page.__init__(self)
self.size = "a4"
self.orientation = "Landscape"
self.pageNumber = None
self.pages = 0 # need to set up an initial value
self.titlepage = False
self.authors = None
self.headings = []
self.epsf = []
self.figs = []
self.area = self.area()
self.title = None
self.logos = talk.logos
self.text_scale = talk.text_scale
self.text_textstyle = talk.text_textstyle
self.text_fg = talk.text_fg
self.textObjs = []
def _make_logos(self):
"""
Put the logos on the page
"""
if len(self.logos) == 0:
return Area(width=0, height=0)
elif len(self.logos) == 1:
return Group(
Area(width=self.area.width-0.4, height=0),
self.logos[0]
)
width = self.area.width -\
self.logos[0].bbox().width -\
self.logos[-1].bbox().width -\
0.4
for logo in self.logos[1:-1]:
width -= logo.bbox().width
space = width/(len(self.logos)-1)
a = Align(a1="e", a2="w", angle=90, space=space)
for logo in self.logos:
a.append(logo)
return a
def add_fig(self, obj, **options):
"""
Put an arbitrary figure onto the page, with a white background
@param obj: the PyScript object to use for the figure
@type obj: PyScript object
"""
if options.has_key('bg'):
backColor = options['bg']
else:
backColor = Color('white')
if options.has_key('fg'):
frontColor = options['fg']
else:
frontColor = None
if options.has_key('height'):
figHeight = options['height']
else:
figHeight = None
if options.has_key('width'):
figWidth = options['width']
else:
figWidth = None
gutter = 0.1
back = Rectangle(width=obj.bbox().width+gutter,
height=obj.bbox().height+gutter,
bg=backColor, fg=frontColor)
back.sw = obj.bbox().sw-P(gutter/2.0, gutter/2.0)
fig = Group(back, obj)
# now scale the height/width appropriately if figWidth and/or
# figHeight are set
if figHeight is not None and figWidth is None:
if fig.bbox().height == 0.0:
raise ValueError, "Initial figure height is zero!!"
else:
scale = figHeight/fig.bbox().height
fig.scale(scale, scale)
elif figHeight is None and figWidth is not None:
if fig.bbox().width == 0.0:
raise ValueError, "Initial figure width is zero!!"
else:
scale = figWidth/fig.bbox().width
fig.scale(scale, scale)
elif figHeight is not None and figWidth is not None:
if fig.bbox().height == 0.0:
raise ValueError, "Initial figure height is zero!!"
elif fig.bbox().width == 0.0:
raise ValueError, "Initial figure width is zero!!"
else:
scalex = figWidth/fig.bbox().width
scaley = figHeight/fig.bbox().height
fig.scale(scalex, scaley)
# there must be a better way to do this!!!
if options.has_key('e'):
fig.e = options['e']
elif options.has_key('se'):
fig.se = options['se']
elif options.has_key('s'):
fig.s = options['s']
elif options.has_key('sw'):
fig.sw = options['sw']
elif options.has_key('w'):
fig.w = options['w']
elif options.has_key('nw'):
fig.nw = options['nw']
elif options.has_key('n'):
fig.n = options['n']
elif options.has_key('ne'):
fig.ne = options['ne']
elif options.has_key('c'):
fig.c = options['c']
else:
fig.sw = P(0.0, 0.0)
# add the figure to the list of figures
self.figs.append(fig)
def set_titlepage(self):
"""
Set the current slide to be the titlepage
"""
self.titlepage = True
return
def set_title(self, title=None):
"""
Set the title of the slide
"""
self.title = title
return
def _make_title(self, talk):
"""
Make the title of the slide (note that this is *not* the title of
the talk)
"""
if self.title is None or self.title == "":
return Area(width=0, height=0)
# if we just get a string, put it in a TeX object in the current style
if isinstance(self.title, types.StringType):
ttext = "%s %s" % (talk.title_textstyle, self.title)
return TeX(ttext, fg=talk.title_fg).scale(talk.title_scale*0.8,
talk.title_scale)
else:
# just return the object itself
return self.title
def add_heading(self, level, text):
"""
Add a heading to the slide
@param level: the heading level as a number starting from 1 (the most
significant level)
@type level: int (1,2,3) or string ("space", "equation")
@param text: the text to be used for the heading
@type text: string
"""
temp = [ level, text ]
self.headings.append(temp)
def add_text(self, text, **options):
"""
Add, and arbitrarily place, text on the slide
@param text: the text to place
@type text: string, TeX object or Text object
"""
# process options
if options.has_key('fg'):
frontColor = options['fg']
else:
frontColor = self.text_fg
if options.has_key('scale'):
scale = options['scale']
else:
scale = self.text_scale
# check for what kind of object we have...
if isinstance(text, types.StringType):
# prepend the style if it is just a string
text = self.text_textstyle + " " + text
obj = TeX(text, fg=frontColor).scale(scale, scale)
else:
raise ValueError, \
"Cannot yet handle non-string objects in Slide.add_text()"
# there must be a better way to do this!!!
if options.has_key('e'):
obj.e = options['e']
elif options.has_key('se'):
obj.se = options['se']
elif options.has_key('s'):
obj.s = options['s']
elif options.has_key('sw'):
obj.sw = options['sw']
elif options.has_key('w'):
obj.w = options['w']
elif options.has_key('nw'):
obj.nw = options['nw']
elif options.has_key('n'):
obj.n = options['n']
elif options.has_key('ne'):
obj.ne = options['ne']
elif options.has_key('c'):
obj.c = options['c']
else:
obj.sw = P(0.0, 0.0)
#obj = TeX(r"test", fg=frontColor)
#obj.c = self.area.c
self.textObjs.append(obj)
def _make_headings(self, talk):
"""
Make the headings
"""
heading_block = Align(a1="sw", a2="nw", angle=180, space=0.5)
for heading in self.headings:
heading_level = heading[0]
if not talk.headings_bullets.has_key(heading_level):
heading_level = "default"
heading_text = "%s %s" % (talk.headings_textstyle[heading_level]
, heading[1])
heading_bullet = talk.headings_bullets[heading_level]
heading_fg = talk.headings_fgs[heading_level]
heading_scale = talk.headings_scales[heading_level]
heading_indent = talk.headings_indent[heading_level]
tex = Align(a1='ne', a2='nw', angle=90, space=0.2)
tex.append(heading_bullet)
tex.append(TeXBox(text=heading_text,
fixed_width=self.area.width-5,
fg=heading_fg,
tex_scale=heading_scale))
padding = Area(sw=tex.sw, width=heading_indent, height=0)
heading_proper = Align(a1="e", a2="w", angle=90, space=0)
heading_proper.append(padding, tex)
heading_block.append(heading_proper)
return heading_block
def _make_waitbar(self, talk):
"""
Make a waitbar
"""
waitBarBack = Rectangle(se=self.area.se+P(-0.8, 0.4),
width=2.5,
height=0.5,
r=0.2,
fg=talk.waitbar_bg,
bg=talk.waitbar_bg)
offset = 0.05
waitBarFront = Rectangle(w=waitBarBack.w+P(offset, 0),
width=(waitBarBack.width-2*offset)*\
self.pageNumber/self.pages,
height=waitBarBack.height-2*offset,
r=0.2,
fg=talk.waitbar_fg,
bg=talk.waitbar_fg)
waitBar = Group(waitBarBack, waitBarFront)
return waitBar
def _make_footer(self, talk):
"""
Make the footer. A text block giving the title and the name of the
person giving the talk
"""
pageOf = False
if pageOf:
footerText = " - %s; page %i of %i" % \
(talk.speaker, self.pageNumber, self.pages)
else:
footerText = " - %s" % (talk.speaker, )
footer = Align(a1="e", a2="w", angle=90, space=0.1)
footer.append(TeX(text="%s %s"%(talk.title_textstyle, talk.title),
fg=talk.title_fg,
).scale(talk.footerScale, talk.footerScale))
footer.append(TeX(text="%s %s"%(talk.speaker_textstyle, footerText),
fg=talk.title_fg
).scale(talk.footerScale, talk.footerScale))
footer.sw = self.area.sw+P(0.4, 0.4)
return footer
def add_epsf(self, file="", **options):
"""
Add an eps file to the slide
@param file: the filename of the eps file
@type file: string
@keyword width: the width of the image in the current default units.
If only this variable is given, then the aspect ratio of the image is
maintained.
@type width: float
@keyword height: the height of the image in the current default
units. If only this variable is given, then the aspect ratio of
the image is maintainted.
@type height: float
@keyword c, n, ne, e, se, s, sw, w, nw: the location of the anchor point
"""
if options.has_key('width'):
picture = Epsf(file, width=options['width'])
elif options.has_key('height'):
picture = Epsf(file, height=options['height'])
elif options.has_key('width') and options.has_key('height'):
picture = Epsf(file, width=options['width'],
height=options['height'])
else:
picture = Epsf(file)
# there must be a better way to do this!!!
if options.has_key('e'):
picture.e = options['e']
elif options.has_key('se'):
picture.se = options['se']
elif options.has_key('s'):
picture.s = options['s']
elif options.has_key('sw'):
picture.sw = options['sw']
elif options.has_key('w'):
picture.w = options['w']
elif options.has_key('nw'):
picture.nw = options['nw']
elif options.has_key('n'):
picture.n = options['n']
elif options.has_key('ne'):
picture.ne = options['ne']
elif options.has_key('c'):
picture.c = options['c']
else:
picture.sw = P(0.0, 0.0)
offset = 0.2
background = Rectangle(width=picture.bbox().width+offset,
height=picture.bbox().height+offset,
bg=Color('white'),
fg=Color('white'),
)
background.sw = picture.sw-P(offset/2.0, offset/2.0)
figure = Group(background, picture)
self.epsf.append(figure)
def _make_epsf(self):
"""
Collects all of the eps images together
"""
pictures = Group()
for file in self.epsf:
pictures.append(file)
return pictures
def _make_figs(self):
"""
Collects all of the figures together
"""
figs = Group()
for fig in self.figs:
figs.append(fig)
return figs
def _make_textObjs(self):
"""
Collects all the text objects together
"""
textObjs = Group()
for text in self.textObjs:
textObjs.append(text)
return textObjs
def _make_titlepage(self, talk):
"""
Makes the titlepage of the talk
"""
titlepage = Align(a1="s", a2="n", angle=180, space=0.4)
if isinstance(talk.title, types.StringType):
ttext = "%s %s" % (talk.title_textstyle, talk.title)
titlepage.append(TeX(ttext,
fg=talk.title_fg)\
.scale(talk.title_scale, talk.title_scale))
else:
#raise ValueError, "Can't yet handle non-string arguments")
titlepage.append(Text(ttext))
if talk.authors is not None:
titlepage.append(talk._make_authors())
if talk.address is not None:
titlepage.append(talk._make_address())
return titlepage
def _make_background(self, talk):
"""
Makes the background of the slide
"""
back = Group()
back.append(Rectangle(sw=self.area.sw,
width=self.area.width,
height=self.area.height,
fg=None,
bg=talk.bg,
)
)
back.append(Rectangle(sw=self.area.sw,
width=2.5,
height=self.area.height,
fg=None,
bg=talk.bg*0.5,
)
)
back.append(Rectangle(sw=self.area.sw,
width=self.area.width,
height=1.5,
fg=None,
bg=talk.bg*0.5,
)
)
back.append(Rectangle(nw=self.area.nw,
width=self.area.width,
height=2.5,
fg=None,
bg=talk.bg*0.5,
)
)
back.append(Rectangle(nw=self.area.nw,
width=2.5,
height=2.5,
fg=None,
bg=Color('firebrick'),
)
)
return back
def _make(self, talk, scale=1):
"""
Make the slide. Collect all of the objects together into one Page()
object ready for rendering.
"""
if self.titlepage:
all = self._make_titlepage(talk)
all.c = self.area.c + P(0.0, 0.8)
else:
all = Align(a1="s", a2="n", angle=180, space=0.4)
all.append(self._make_title(talk))
all.nw = self.area.nw + P(2.5, -0.2)
# I'm aware that this isn't a good way to do this, but
# it's late at night, and I want to get *something* going
headings = self._make_headings(talk)
headings.nw = self.area.nw + P(3.0, -3.0)
back = self._make_background(talk)
p = self.area.se + P(-0.1, 0.1)
signature = Text(
'Created with PyScript. http://pyscript.sourceforge.net',
size=15,
sw=p,
fg=talk.bg*0.8
).rotate(-90, p)
logos = self._make_logos()
logos.nw = self.area.nw + P(0.2, -0.2)
self.pages = len(talk.slides)
All = Group(
back,
all,
headings,
self._make_epsf(),
self._make_figs(),
self._make_textObjs(),
signature,
self._make_footer(talk),
logos,
self._make_waitbar(talk)
).scale(scale, scale)
return Page(All, orientation=self.orientation)
# vim: expandtab shiftwidth=4:
|