Changeset 347

Show
Ignore:
Timestamp:
06/21/08 22:08:10 (4 years ago)
Author:
simon
Message:

Use new-style classes.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • hodgestar/Talks/PythonObjects/slides.py

    r346 r347  
    3434 
    3535 
    36 class Lecture: 
     36class Lecture(object): 
    3737    """A series of slides. 
    3838 
     
    114114        fp.close() 
    115115 
    116  
    117 class Slide: 
     116class LecturePart(object): 
     117    """Base class for parts of a lecture.""" 
     118 
     119    def toHTML(self): 
     120        """Return HTML for inclusion in lecture.""" 
     121        raise NotImplementedError 
     122 
     123class Slide(LecturePart): 
    118124    """A slide that contains unnumbered bullets. 
    119125 
     
    150156 
    151157 
    152 class SubBullet: 
     158class SubBullet(LecturePart): 
    153159    """A list of bullets that isn't a slide. 
    154160 
     
    167173 
    168174 
    169 class Bullet: 
     175class Bullet(LecturePart): 
    170176    """A bullet.""" 
    171177 
     
    177183 
    178184 
    179 class PRE: 
     185class PRE(LecturePart): 
    180186    """A quoted text.""" 
    181187 
     
    187193 
    188194 
    189 class URL: 
     195class URL(LecturePart): 
    190196    """A URL.""" 
    191197    def __init__(self, text): 
     
    194200    def toHTML(self): 
    195201        return '<a href="%s">%s</a>' % (self.text, self.text) 
     202 
     203class Heading(LecturePart): 
     204    """A heading of a given level (1, 2, ...).""" 
     205    def __init__(self, num, text): 
     206        self.num = num 
     207        self.text = text 
     208 
     209    def toHTML(self): 
     210        return '<h%d>%s</h%d>' % (self.num, toHTML(self.text), self.num) 
     211 
     212 
     213class Center(LecturePart): 
     214    """Center an item.""" 
     215 
     216    def __init__(self, text): 
     217        self.text = text 
     218 
     219    def toHTML(self): 
     220        return '<center>%s</center>' % toHTML(self.text) 
     221 
     222 
     223class Image(LecturePart): 
     224    """An image.""" 
     225 
     226    def __init__(self, image, description=""): 
     227        self.image = image 
     228        self.description = description 
     229 
     230    def toHTML(self): 
     231        return "<img src='%s' alt='%s' />" % (self.image, self.description) 
     232 
     233 
     234class TitleSlide(Slide): 
     235 
     236    def toHTML(self): 
     237        title = '<h1>%s</h1>' % toHTML(Center(self.title)) 
     238        points = [] 
     239        for point in self.bullets: 
     240            points.append(Center(point).toHTML()) 
     241        return title + '\n'.join(points) 
    196242 
    197243 
     
    204250 
    205251 
    206 class Heading: 
    207     """A heading of a given level (1, 2, ...).""" 
    208     def __init__(self, num, text): 
    209         self.num = num 
    210         self.text = text 
    211  
    212     def toHTML(self): 
    213         return '<h%d>%s</h%d>' % (self.num, toHTML(self.text), self.num) 
    214  
    215  
    216 class Center: 
    217     """Center an item.""" 
    218  
    219     def __init__(self, text): 
    220         self.text = text 
    221  
    222     def toHTML(self): 
    223         return '<center>%s</center>' % toHTML(self.text) 
    224  
    225  
    226 class Image: 
    227     """An image.""" 
    228  
    229     def __init__(self, image, description=""): 
    230         self.image = image 
    231         self.description = description 
    232  
    233     def toHTML(self): 
    234         return "<img src='%s' alt='%s' />" % (self.image, self.description) 
    235  
    236  
    237 class TitleSlide(Slide): 
    238  
    239     def toHTML(self): 
    240         title = '<h1>%s</h1>' % toHTML(Center(self.title)) 
    241         points = [] 
    242         for point in self.bullets: 
    243             points.append(Center(point).toHTML()) 
    244         return title + '\n'.join(points) 
    245  
    246  
    247252__all__ = ["Lecture", "Slide", "NumSlide", "PRE", "URL", "Bullet", 
    248253           "SubBullet", "toHTML", "Center", "Heading", "Image", "TitleSlide"]