Changeset 344

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

Last minute modifications to slides.

Files:
1 modified

Legend:

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

    r339 r344  
    1 from slides import Lecture, Slide, TitleSlide, Bullet, PRE, URL, Image, SubBullet, cgi 
     1from slides import Lecture, Slide, Bullet, PRE, Image, SubBullet, cgi 
    22from pygments.lexers import get_lexer_by_name 
    33from pygments.formatters import get_formatter_by_name 
     
    7070Slide = MySlide 
    7171 
     72class TitleSlide(Slide): 
     73    def toHTML(self): 
     74        title = '<h1>%s</h1>' % cgi.escape(self.title) 
     75        bullets = [] 
     76        for bullet in self.bullets: 
     77            bullets.append(bullet.toHTML()) 
     78        return "<div style='margin: auto; width: 50%;'>" + title + self.start + "\n".join(bullets) + self.end + "</div>" 
     79 
     80class BulletlessSlide(Slide): 
     81    start = "<ul style='list-style-type: none;'>\n" 
     82    end = "</ul>\n" 
     83 
     84class BulletlessTitleSlide(TitleSlide): 
     85    start = "<ul style='list-style-type: none;'>\n" 
     86    end = "</ul>\n" 
     87 
     88class URL(object): 
     89    """A URL.""" 
     90    def __init__(self, desc, url): 
     91        self.url = url 
     92        self.desc = desc 
     93 
     94    def toHTML(self): 
     95        return '<a href="%s">%s</a>' % (self.url, self.desc) 
     96 
    7297l = MyLecture( 
    73     "Everything You Didn't Want to Known About Python Objects", 
    74     TitleSlide("Everything You Didn't Want to Known About Python Objects", 
     98    "Everything You Didn't Want to Know about Python Objects", 
     99    BulletlessTitleSlide("Everything You Didn't Want to Know about Python Objects", 
    75100        Bullet("in which I chronicle my recent findings in the depths of Object/object.c"), 
    76101    ), 
     
    82107            >>> type(Old), type(Old()) 
    83108            (<type 'classobj'>, <type 'instance'>) 
     109            >>> Old.__class__ 
     110            Traceback (most recent call last): 
     111              File "<stdin>", line 1, in <module> 
     112            AttributeError: class Old has no attribute '__class__' 
     113            >>> Old().__class__ 
     114            <class util.Old at 0xb7d4e62c> 
    84115            """)), 
    85116        Bullet("New Style:", PYCON(""" 
     
    89120            >>> type(New), type(New()) 
    90121            (<type 'type'>, <class '__main__.New'>) 
     122            >>> New.__class__ 
     123            <type 'type'> 
     124            >>> New().__class__ 
     125            <class 'util.New'> 
    91126            """)), 
     127        Bullet("Old + __metaclass__ == New"), 
    92128    ), 
    93129    Slide("Gambolling With Slots", 
     130        Bullet("Adding slots:", PYCON(""" 
     131            >>> class FooBar(object): 
     132            ...   def __str__(self): 
     133            ...     return "foobar" 
     134            ... 
     135            >>>   def __unicode__(self): 
     136            ...     return unicode("foobar") 
     137            ... 
     138            >>> str(FuBar), str(FuBar()) 
     139            ("<class 'util.FuBar'>", 'fubar') 
     140            >>> unicode(FuBar) 
     141            Traceback (most recent call last): 
     142              File "<stdin>", line 1, in <module> 
     143            TypeError: unbound method __unicode__() must be called with FuBar instance as first argument (got nothing instead) 
     144            >>> unicode(Uni()) 
     145            u'fubar' 
     146        """)), 
     147        Bullet("Same thing happens with old-style classes.") 
     148    ), 
     149    BulletlessSlide("object.c", 
     150        Bullet(Image("tabs.png")), 
    94151    ), 
    95152    Slide("Strings", 
     
    111168        """)), 
    112169        Bullet("Single characters and empty string held in permament cache (Objects/stringobject.c)."), 
    113         Bullet("Constants strings of size <= 20 cache by parser (TODO: check)."), 
     170        Bullet("Constants strings of size <= 20 interned by parser."), 
    114171        Bullet("PyString_InternInPlace (PyUnicode_InternInPlace in 3.0) results in strings being stored in internal dictionary.", 
    115172            SubBullet( 
     
    184241        Bullet("Perhaps just use numpy?"), 
    185242    ), 
    186     Slide("PyObject C API", 
    187         Bullet("List of methods unchanged between 2.5 and 2.6"), 
    188     ), 
    189     Slide("object.c", 
    190         Bullet(Image("tabs.png")), 
    191     ), 
    192     Slide("New Python Documents - ZOMG!", 
    193         Bullet("Interactive search -- in static HTML."), 
    194         Bullet("_static/searchindex.json"), 
    195         Bullet(URL("file:///home/simon/LocalProjects/PythonSpint/trunk/Doc/build/html/index.html")), 
     243    Slide("C API Documentation", 
     244        Bullet("PyObject API:", 
     245            SubBullet( 
     246                Bullet("List of methods unchanged between 2.5, 2.6 and 3.0"), 
     247            ), 
     248        ), 
     249        Bullet("New documentation!", 
     250            SubBullet( 
     251                Bullet("Interactive search -- in static HTML"), 
     252                Bullet("JSON index"), 
     253                Bullet(URL("2.6 Docs","file:///home/simon/LocalProjects/PythonSpint/trunk/Doc/build/html/index.html")), 
     254            ), 
     255        ), 
    196256    ), 
    197257)