Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/slideshow.py
blob: 78f4488c931a5721fb1d5baa0427c7bb050ea001 (plain)
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
# -*- mode:python; tab-width:4; indent-tabs-mode:t;  -*-

# slideshow.py
#
# Classes to represent a deck of slides, and handle things like file I/O and
# formats
# B. Mayton <bmayton@cs.washington.edu>
#
# 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import os, sys, subprocess
from time import strftime
import gtk
import xml.dom.minidom
import gobject
import logging
from path import path
from sugar.activity import activity
from sugar.datastore import datastore

class Deck(gobject.GObject):

    __gsignals__ = {
        'slide-changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
        'decktitle-changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
        'slide-redraw' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
        'remove-path' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_INT,)),
        'deck-changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
        'local-ink-added' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,)),
        'remote-ink-added' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,)),
        'instr-state-propagate' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_BOOLEAN,)),
        'lock-state-propagate' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_BOOLEAN,)),
        'ink-submitted' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING, gobject.TYPE_STRING)),
        'ink-broadcast' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
                            (gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)),
        'update-submissions' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_INT,)),
        'instructor-ink-cleared' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_INT,)),
        'instructor-ink-removed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_INT, gobject.TYPE_INT)),
    }

    def __init__(self, sugaractivity, handle, rsrc, base="/nfs/show"):
        gobject.GObject.__init__(self)
        self.__handle = handle
        if self.__handle.object_id == None:
            print 'slideshow - from home view'
        else:
            obj = datastore.get(self.__handle.object_id)
            print 'object:', obj.get_file_path()
        self.__logger = logging.getLogger('Deck')
        self.__base = base
        self.__rsrc = rsrc
        self.__activity = sugaractivity

        self.__is_initiating = True
        self.__nav_locked = False
        self.__active_sub = -1
        self.__self_text = ""
        self.__text_tag = None
        self.__xmlpath = os.path.join(base, "deck.xml")
        #we always create a new presentation and copy over it on resume
        if path(base).exists():
            #we can't have permissions.info for this to work
            subprocess.call("cp -r " + base + " /home/olpc/save", shell=True)
            subprocess.call("rm -rf " + base + '/*', shell=True)
        else:
            path.mkdir(base)
        path.copy(self.__rsrc / 'deck.xml', base / 'deck.xml')
        path.copy(self.__rsrc / 'title.html', base / 'title.html')
        path.copy(self.__rsrc / 'title_thumb.png', base / 'title_thumb.png')
        self.reload()
        self.set_title('New')

    def set_locked_mode(self, locked):
        """ Setter method for the navigation lock flag"""
        self.__logger.debug("Lock state: " +str(locked))
        self.__nav_locked = locked
        self.emit('lock-state-propagate', locked)

    def set_is_initiating(self, is_init):
        """ Setter method for the instructor flag """
        self.__logger.debug("Instructor state: " +str(is_init))
        self.__is_initiating = is_init
        self.emit('instr-state-propagate', is_init)

    def getIsInitiating(self):
        return self.__is_initiating

    def make_title_slide(self, title):
        #open and read title.html
        self.__work_path = os.path.join(activity.get_activity_root(), 'instance')
        deckpath = path(activity.get_activity_root()) / 'instance' / 'deck'
        slide = open(deckpath / 'title.html', 'r')
        txt = slide.read()
        slide.close()
        #here change title.html - change between <h1> and </h1>
        h1pos = txt.find('<h1>')
        h1end = txt.find('</h1>')
        txtmod = txt[:h1pos+4] + title + txt[h1end:]
        #here change date       - change between <h3> and </h3>
        h3pos = txtmod.find('<h3>')
        h3end = txtmod.find('</h3>')
        txt = txtmod[:h3pos+4] + strftime("%a, %b %d, %Y %H:%M") + txtmod[h3end:]
        #save title.html and close
        slide = open(deckpath / 'title.html', 'w')
        slide.write(txt)
        slide.close()
        print 'title slide changed', title

    def set_title(self, title):
        nodes = self.__dom.getElementsByTagName("title")
        nodes[0].firstChild.data = title
        self.make_title_slide(title)
        self.save()
        self.goToIndex(0, is_local=False)
        self.emit('deck-changed')
        print 'set_title', self.get_title()

    def get_title(self):
        nodes = self.__dom.getElementsByTagName("title")
        return nodes[0].firstChild.data

    def reload(self):
        self.__logger.debug("Reading deck")
        print 'reload:', self.__xmlpath
        if os.path.exists(self.__xmlpath):
            self.__dom = xml.dom.minidom.parse(self.__xmlpath)
        decks = self.__dom.getElementsByTagName("deck")
        self.__deck = decks[0]
        # Get the slides from the show
        self.__slides = self.__deck.getElementsByTagName("slide")
        self.__nslides = len(self.__slides)
        self.__logger.debug(str(self.__nslides) + " slides in show")
        self.goToIndex(0, is_local=False)
        print 'deck reloaded'

    def save(self, path=None):
        """Writes the XML DOM in memory out to disk"""
        print 'save:', path
        if not path:
            path = self.__xmlpath

        """
        print '***************save************************'
        print self.__dom.toprettyxml()
        print '***************save************************'
        """

        outfile = open(path, "w")
        self.__dom.writexml(outfile)
        outfile.close()

    def rebuild_dom(self, title, slides):
        dom = xml.dom.minidom.Document()
        deck = dom.createElement("deck")
        title = dom.createElement("title")
        title.appendChild(dom.createTextNode("new"))
        deck.appendChild(title)
        for slide in slides:
            deck.appendChild(slide)
        dom.appendChild(deck)
        print '*************rebuild**************************'
        print dom.toprettyxml()
        print '**********************************************'
        return dom

    def getDeckPath(self):
        """Returns the path to the folder that stores this slide deck"""
        return self.__base

    def resizeImage(self, inpath, outpath, w, h):
        # resize an image
        pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(inpath, w, h)
        #scaled_buf = pixbuf.scale.simple(w, h, gtk.gdk.INTERP_BILINEAR)
        pixbuf.save(outpath, "png")

    def get_SlideTitle(self):
        n = self.getIndex()
        slide = self.__slides[n]
        return slide.getAttribute('title')

    def set_SlideTitle(self, slideTitle):
        n = self.getIndex()
        slide = self.__slides[n]
        slide.setAttribute('title', slideTitle)

    def addSlide(self,file_path):

        INSTANCE = path(activity.get_activity_root()) / 'instance'
        filepath = path(file_path)
        print 'addSlide file_path', filepath.exists(), filepath
        filename = filepath.name
        inpath = INSTANCE / 'deck' / filename
        print 'inpath', inpath.exists(), inpath
        path.copy(filepath, inpath)
        outpath = path(activity.get_activity_root() ) / 'instance' / 'deck' / filename
        print 'outpath=', outpath.exists(), outpath
        self.resizeImage(inpath, outpath, 640, 480)
        print 'outpath=', outpath.exists(), outpath

        print 'get slide dimensions'
        dims = self.getSlideDimensionsFromXML(0)
        if dims == False:
            wf = 640
            hf = 480
        else:
            wf, hf = dims
        w = str(int(wf))
        h = str(int(hf))
        print 'add slide', w, h
        newslide = self.__dom.createElement("slide")
        newslide.setAttribute("height", h)
        newslide.setAttribute("title", "newslide")
        newslide.setAttribute("width", w)
        newlayer = self.__dom.createElement("layer")
        txt = self.__dom.createTextNode(filename)
        newlayer.appendChild(txt)
        newslide.appendChild(newlayer)
        self.__deck.appendChild(newslide)
        print '**************addSlide*************'
        print self.__dom.toprettyxml()
        print '***********************************'
        self.save()

    def removeSlide(self, n):
        del self.__slides[n]
        self.__dom = self.rebuild_dom("modified deck", self.__slides)

    def moveSlide(self, f, t):
        if f < t:
            self.__slides.insert(t, self.__slides[f])
            del self.__slides[f]
        elif t < f:
            self.__slides.insert(t, self.__slides[f])
            del self.__slides[f+1]
        self.__dom = self.rebuild_dom("modified deck", self.__slides)

    def getSlideLayers(self, n=-1):
        """Returns a list of the layers that comprise this slide"""
        if n == -1:
            n = self.__pos
        slide = self.__slides[n]
        self.__layers = slide.getElementsByTagName("layer")
        layers = []
        for l in self.__layers:
            p = os.path.join(self.__base, l.firstChild.nodeValue)
            layers.append(p)
        return layers

    def getInstructorInk(self):
        self.__instructor_ink = []
        instr = self.__slide.getElementsByTagName("instructor")
        if len(instr) > 0:
            self.__instructor_tag = instr[0]
            pathtags = self.__instructor_tag.getElementsByTagName("path")
            for pathstr in pathtags:
                self.__instructor_ink.append(pathstr.firstChild.nodeValue)
        return self.__instructor_ink

    def getSelfInkOrSubmission(self):
        if self.__active_sub == -1:
            return (self.__self_ink, self.__self_text)
        subtags = self.__slide.getElementsByTagName("submission")
        if self.__active_sub > -1 and self.__active_sub < len(subtags):
            active_subtag = subtags[self.__active_sub]
            text = ""
            texts = active_subtag.getElementsByTagName("text")
            if len(texts) > 0:
                if texts[0].firstChild:
                    text = texts[0].firstChild.nodeValue
            pathlist = []
            paths = active_subtag.getElementsByTagName("path")
            for path in paths:
                if path.firstChild:
                    pathlist.append(path.firstChild.nodeValue)
            return (pathlist, text)
        return None

    def setActiveSubmission(self, sub):
        self.__active_sub = sub
        self.emit('slide-redraw')

    def getActiveSubmission(self):
        return self.__active_sub

    def getSubmissionList(self, n=None):
        if n is None:
            n = self.__pos
        subtags = self.__slide.getElementsByTagName("submission")
        sublist = []
        for subtag in subtags:
            sublist.append(subtag.getAttribute("from"))
        return sublist

    def addSubmission(self, whofrom, inks, text="", n=None):
        if n is None:
            n = self.__pos
        if n >= 0 and n < self.getSlideCount():
            slide = self.__slides[n]
        else:
            slide = self.__slides[self.__pos]
        newsub = self.__dom.createElement("submission")
        newsub.setAttribute("from", whofrom)
        substrparts = inks.split("$")
        for part in substrparts:
            if len(part) > 0:
                newpath = self.__dom.createElement("path")
                newpath.appendChild(self.__dom.createTextNode(part))
                newsub.appendChild(newpath)
        subtext = self.__dom.createElement("text")
        subtext.appendChild(self.__dom.createTextNode(text))
        newsub.appendChild(subtext)
        subs = slide.getElementsByTagName("submission")
        for sub in subs:
            if sub.getAttribute("from") == whofrom:
                slide.removeChild(sub)
        slide.appendChild(newsub)
        subs = slide.getElementsByTagName("submission")
        if n == self.__pos:
            self.emit('update-submissions', len(subs) - 1)

    def addInkToSlide(self, pathstr, islocal, n=None):
        """Adds ink to the current slide, or slide n if given.  Instructor ink may be added to any slide;
        but it only makes sense to add student ink to the current slide (n will be ignored)"""
        if n is None:
            slide = self.__slide
            instr_tag = self.__instructor_tag
            if instr_tag == None:
                instr_tag = self.__dom.createElement("instructor")
                slide.appendChild(instr_tag)
                self.__instructor_tag = instr_tag
        else:
            if n < self.getSlideCount and n >= 0:
                slide = self.__slides[n]
            else:
                slide = self.__slides[self.__pos]
            instr_tags = slide.getElementsByTagName("instructor")
            if len(instr_tags) > 0:
                instr_tag = instr_tags[0]
            else:
                instr_tag = self.__dom.createElement("instructor")
                slide.appendChild(instr_tag)
        if not islocal or self.__is_initiating:
            self.__instructor_ink.append(pathstr)
            path = self.__dom.createElement("path")
            path.appendChild(self.__dom.createTextNode(pathstr))
            instr_tag.appendChild(path)
        else:
            self.__self_ink.append(pathstr)
            if not self.__self_ink_tag:
                self.__self_ink_tag = self.__dom.createElement("self")
                self.__slide.appendChild(self.__self_ink_tag)
            path = self.__dom.createElement("path")
            path.appendChild(self.__dom.createTextNode(pathstr))
            self.__self_ink_tag.appendChild(path)
        if islocal:
            self.emit("local-ink-added", pathstr)
        else:
            if n is None or n == self.__pos:
                self.emit("remote-ink-added", pathstr)

    def clearInk(self, n=None):
        if n is None:
            n = self.__pos
        slide = self.__slides[n]
        if self.__is_initiating:
            self.clearInstructorInk(n)
            self.emit('instructor-ink-cleared', n)
        self_tags = slide.getElementsByTagName("self")
        for self_tag in self_tags:
            slide.removeChild(self_tag)
        self.__self_ink = []
        self.__self_ink_tag = None

    def clearInstructorInk(self, n=None):
        if n is None:
            n = self.__pos
        slide = self.__slides[n]
        instructor_tags = slide.getElementsByTagName("instructor")
        for instructor_tag in instructor_tags:
            slide.removeChild(instructor_tag)
        if n == self.__pos:
            self.__instructor_ink = []
            self.__instructor_tag = None
            self.emit('slide-redraw')

    def removeInstructorPathByUID(self, uid, n=None):
        if n is None:
            n = self.__pos
        needs_redraw = False
        slide = self.__slides[n]
        instructor_tags = slide.getElementsByTagName("instructor")
        if len(instructor_tags) > 0:
            instructor_tag = instructor_tags[0]
        else:
            return
        path_tags = instructor_tag.getElementsByTagName("path")
        for path_tag in path_tags:
            if path_tag.firstChild:
                pathstr = path_tag.firstChild.nodeValue
                path_uid = 0
                try:
                    path_uid = int(pathstr[0:pathstr.find(';')])
                except Exception, e:
                    pass
                if path_uid == uid:
                    instructor_tag.removeChild(path_tag)
                    needs_redraw = True
        if n == self.__pos and needs_redraw:
            self.emit('remove-path', uid)

    def removeLocalPathByUID(self, uid, n=None):
        if n is None:
            n = self.__pos
        slide = self.__slides[n]
        if self.__is_initiating:
            self.emit('instructor_ink_removed', uid, n)
            tags = slide.getElementsByTagName("instructor")
        else:
            tags = slide.getElementsByTagName("self")
        if len(tags) > 0:
            tag = tags[0]
        else:
            return
        path_tags = tag.getElementsByTagName("path")
        for path_tag in path_tags:
            if path_tag.firstChild:
                pathstr = path_tag.firstChild.nodeValue
                path_uid = 0
                try:
                    path_uid = int(pathstr[0:pathstr.find(';')])
                except Exception, e:
                    pass
                if path_uid == uid:
                    tag.removeChild(path_tag)

    def doSubmit(self):
        inks, text, whofrom = self.getSerializedInkSubmission()
        self.__logger.debug("Submitting ink: " + str(inks) + " text: " + text)
        self.emit('ink-submitted', inks, text)

    def doBroadcast(self):
        inks, text, whofrom = self.getSerializedInkSubmission()
        self.emit('ink-broadcast', whofrom, inks, text)

    def getSerializedInkSubmission(self):
        sub = ""
        text = ""
        if self.__active_sub == -1:
            self_tags = self.__slide.getElementsByTagName("self")
            if len(self_tags) > 0:
                texts = self_tags[0].getElementsByTagName("text")
                if len(texts) > 0:
                    if texts[0].firstChild:
                        text = texts[0].firstChild.nodeValue
                for path in self_tags[0].getElementsByTagName("path"):
                    sub = sub + path.firstChild.nodeValue + "$"
            return sub, text, "myself"
        else:
            sub = ""
            whofrom = "unknown"
            subtags = self.__slide.getElementsByTagName("submission")
            if self.__active_sub > -1 and self.__active_sub < len(subtags):
                active_subtag = subtags[self.__active_sub]
                text = ""
                whofrom = active_subtag.getAttribute("from")
                texts = active_subtag.getElementsByTagName("text")
                if len(texts) > 0:
                    if texts[0].firstChild:
                        text = texts[0].firstChild.nodeValue
                pathlist = []
                paths = active_subtag.getElementsByTagName("path")
                for path in paths:
                    if path.firstChild:
                        sub = sub + path.firstChild.nodeValue + "$"
            return sub, text, whofrom

    def getSlideThumb(self, n=-1):
        """Returns the full path to the thumbnail for this slide if it is defined; otherwise False"""
        if n == -1:
            n = self.__pos
        slide = self.__slides[n]
        print slide.toprettyxml()
        thumbs = slide.getElementsByTagName("thumb")
        if len(thumbs) < 1:
            return False
        return os.path.join(self.__base, thumbs[0].firstChild.nodeValue)

    def setSlideThumb(self, filename, n=-1):
        """Sets the thumbnail for this slide to filename (provide a *relative* path!)"""
        if n == -1:
            n = self.__pos
        slide = self.__slides[n]
        thumbs = slide.getElementsByTagName("thumb")
        for t in thumbs:
            slide.removeChild(t)
        thumb = self.__dom.createElement("thumb")
        thumb.appendChild(self.__dom.createTextNode(filename))
        slide.appendChild(thumb)

    def getSlideClip(self, n=-1):
        """Returns the full path to the audio clip for this slide if it is defined; otherwise False"""
        if n == -1:
            n = self.__pos
        slide = self.__slides[n]
        clip = slide.getElementsByTagName("clip")
        if len(clip) < 1:
            return False
        return os.path.join(self.__base, clip[0].firstChild.nodeValue)

    def setSlideClip(self, filename, n=-1):
        """Sets the clip for this slide to filename (provide a *relative* path!)"""
        if n == -1:
            n = self.__pos
        slide = self.__slides[n]
        clips = slide.getElementsByTagName("clip")
        for clip in clips:
            slide.removeChild(clip)
        clip = self.__dom.createElement("clip")
        clip.appendChild(self.__dom.createTextNode(filename))
        slide.appendChild(clip)

    def setSlideText(self, textval):
        self.__self_text = textval
        if self.__text_tag:
            if self.__text_tag.firstChild:
                self.__text_tag.firstChild.nodeValue = textval
            else:
                self.__text_tag.appendChild(self.__dom.createTextNode(textval))

    def doNewIndex(self):
        """Updates any necessary state associated with moving to a new slide"""
        self.__slide = self.__slides[self.__pos]
        #set slide title - entry text from xml
        self.set_SlideTitle(self.__slide.getAttribute('title'))

        self_ink = self.__slide.getElementsByTagName("self")
        self.__instructor_tag = None
        self.__self_ink_tag = None
        self.__instructor_ink = []
        self.__self_ink = []
        self.__self_text = ""
        self.__text_tag = None
        self.__active_sub = -1
        if len(self_ink) > 0:
            self.__self_ink_tag = self_ink[0]
            texttags = self.__self_ink_tag.getElementsByTagName("text")
            if len(texttags) > 0:
                self.__text_tag = texttags[0]
            else:
                self.__text_tag = self.__dom.createElement(text)
                self.__text_tag.appendChild(self.__dom.createTextNode(""))
                self.__self_ink_tag.appendChild(text)
            pathtags = self.__self_ink_tag.getElementsByTagName("path")
            for pathstr in pathtags:
                self.__self_ink.append(pathstr.firstChild.nodeValue)
        else:
            self.__self_ink_tag = self.__dom.createElement("self")
            self.__slide.appendChild(self.__self_ink_tag)
            self.__text_tag = self.__dom.createElement("text")
            self.__text_tag.appendChild(self.__dom.createTextNode(""))
            self.__self_ink_tag.appendChild(self.__text_tag)
        if self.__text_tag.firstChild:
            self.__self_text = self.__text_tag.firstChild.nodeValue
        self.__activity.set_screen(0)

        self.emit("slide-changed")
        self.emit("update-submissions", self.__active_sub)
        self.emit("slide-redraw")

    def goToIndex(self, index, is_local):
        """Jumps to the slide at the given index, if it's valid"""
        self.__logger.debug("Trying to change slides: locked? %u, instructor? %u, is_local? %u",
            self.__nav_locked, self.__is_initiating, is_local)

        in_range = index < self.__nslides and index >= 0

        if (self.__is_initiating or not is_local or not self.__nav_locked) and in_range:
            self.__logger.debug("Changing slide to index: %u", index)
            self.__pos = index
            self.doNewIndex()
        else:
            self.__pos = index
            print 'invalid index', index

    def getIndex(self):
        """Returns the index of the current slide"""
        return self.__pos

    def next(self):
        """Moves to the next slide"""
        self.goToIndex(self.__pos + 1, is_local=True)

    def previous(self):
        """Moves to the previous slide"""
        self.goToIndex(self.__pos - 1, is_local=True)

    def isAtBeginning(self):
        """Returns true if show is on the first slide in the deck"""
        if self.__nslides < 1:
            return True

        if self.__pos == 0:
            return True
        else:
            return False

    def isAtEnd(self):
        """Returns true if the show is at the last slide in the deck"""
        if self.__nslides < 1:
            return True

        if self.__pos == self.__nslides - 1:
            return True
        else:
            return False

    def getSlideDimensionsFromXML(self, n=-1):
        """Returns the dimensions for the slide at index n, if they're specified"""
        if n == -1:
            n = self.__pos
        slide = self.__slides[n]
        wstring = slide.getAttribute("width")
        hstring = slide.getAttribute("height")
        if wstring != '' and hstring != '':
            return [float(wstring), float(hstring)]
        return False

    def getSlideCount(self):
        return self.__nslides

gobject.type_register(Deck)