January 2, 2006

Presentations with Pylize

Author: Keith Fieldhouse

If you need to give a presentation, you're going to need slides. If you don't give presentations often, you may spend a lot of time playing hunt-the-feature with a traditional presentation application as you try to bring the slides in your mind's eye to the screen. Pylize, a Python-based command-line tool, lets you use familiar HTML coding techniques to get the job done.

In addition to a standard Python installation, Pylize depends on HTMLgen, a Python package used to generate HTML; Empy, one of the templating packages available for Python; and, optionally, the Python Imaging Library. The Python Imaging Library and HTMLgen have been packaged for a number of distributions (for example, there are Ubuntu and Fedora packages available). Empy comes with a standard setup.py which you can use to install the package with the python setup.py install command. To install Pylize itself, run the install.py Python script that comes with the distribution (after you've installed the prerequisites).

Once you've installed Pylize, you can start building a presentation by running the pylize create command in an empty directory to create the file all.html, which you edit to create your presentation. When you edit this file, you will see a set of <meta> tags. Review these and edit them to your satisfaction. For example, the <meta> tag with a "name" attribute of "author" should have its "content" attribute set to your name:

<meta name="author" content="Keith Fieldhouse">

While you're editing this file, remove the line after the <body> tag that reads:

<!-- Example: to process example remove comment markers here and at the end

You should also remove the line near the end of the file that reads:

Example ends here //-->

Save the file and execute the command pylize in your presentation directory. This will create an index.html and a series of slide_nn.html files. Open index.html in a browser and click on the Start Presentation link to display the sample presentation's table of contents. Now you can begin editing the all.html file to create the slides for your presentation.

Each slide begins with a <h1> tag. The contents of the tag will be your slide's title. An optional following <h2> tag provides a subtitle. The body of the slide can be virtually any valid HTML. For example, to create a typical bullet-point slide, use the unordered list (<UL>) and list item (<LI>) tags. Bear in mind that you have the full expressive capability of HTML available to you. Image and table tags provide different ways to present information. You can even embed Flash and other dynamic content. Pylize controls the headers and footers of your slides, but the body is available for whatever purposes you require.

Pylize presentations come equipped with some JavaScript and CSS features that help you put together presentations. Chief among these is the JavaScript code that controls slide advancement. Striking the space bar advances to the next slide, while pressing the backspace key returns you to the previously displayed slide.

If you add a "delayed" class attribute to an HTML element, that element will not be displayed when the slide first appears, but rather will appear when you press the space bar. If there are multiple elements with a class of "delayed," each will be revealed in turn, after which the next space will advance to the next slide. This allows you to easily construct a bulleted list where each item is revealed one at a time:

<li>This is the first bullet. It appears immediately when the slide is shown.</li>
<li class="delayed">This is the second bullet. It appears when you press the space bar.</li>
<li class=delayed>This is the last bullet. After this, the next slide will be displayed.</li>

A number of other CSS classes in the default installation are helpful when you're building presentations. If you enclose some content in a <pre> tag with a class attribute of "code" (e.g. <pre class="code>), the content will be displayed as you write it in a monospaced font (ideal for code examples). Using "fancy" as a class attribute for a <UL> tag will result in the list items having a push pin graphic as their "bullet." <TABLE> tags with a "fancytable" class attribute will be formatted with nice borders and a white background.

Even with this collection of CSS features, it's possible that you'll want to add features of your own. This is easy to do. Find the Pylize "share" directory (on Linux systems it's likely /usr/share/pylize), and copy the Empy templating syntax file default.tmpl to mine.tmpl. You can adjust this file in a number of ways to change the way Pylize constructs your slides. For instance, to change the default CSS stylesheet, search for default.css and change it to mine.css. Then go to the "css" sub-directory of the "share" directory and copy default.css to mine.css to create the file you should edit to suit your needs.

To use your new template and new stylesheet, use the -t argument to the pylize command: pylize -t mine. This will cause Pylize to use your new template, and as a result, reference your new stylesheet. The command copies the entire contents of the "css" directory, and thus it will be available in your presentation directory.

Once you're satisfied with your presentation, you need to deliver it. Your presentation's working directory is self-contained and has no external dependencies. You can use it where it is or move it to some other convenient location. One useful technique is to simply upload the presentation to a Web server, thus making it available to any Internet-connected computer. Open the file index.html and use your browser's full-screen mode for your presentation.

With a little bit of HTML knowledge and Pylize you can quickly build professional presentations.

Click Here!