Ejemplo n.º 1
0
 def handle_updateDom(self, ctx):
     client = livepage.IClientHandle(ctx)
     yield livepage.set('question', client.node.question), livepage.eol
     if client.node.isLeaf():
         yield livepage.set('answer-inputs', inevow.IQ(AnimalPage.docFactory).onePattern('leaf')), livepage.eol
     else:
         yield livepage.set('answer-inputs', inevow.IQ(AnimalPage.docFactory).onePattern('branch')), livepage.eol
Ejemplo n.º 2
0
 def update(self, ctx):
     '''Emit paginated view update'''
     session = inevow.ISession(ctx)
     
     # Verify if live request came from same session, our view was created
     # Nevow doesn't do it :(
     if session.uid == self.sessionUid:
         # nevow.livepage has problems with flattening complex objects
         # so render it into string prematurely
         flt = flat.flatten(self.render_mainTable(ctx, None), ctx)
         
         yield livepage.set('pagination', self.render_pagination(ctx, None)), livepage.eol
         yield livepage.set('mainTable', flt) 
Ejemplo n.º 3
0
    def update(self, ctx):
        '''Emit paginated view update'''
        session = inevow.ISession(ctx)

        # Verify if live request came from same session, our view was created
        # Nevow doesn't do it :(
        if session.uid == self.sessionUid:
            # nevow.livepage has problems with flattening complex objects
            # so render it into string prematurely
            flt = flat.flatten(self.render_mainTable(ctx, None), ctx)

            yield livepage.set('pagination',
                               self.render_pagination(ctx, None)), livepage.eol
            yield livepage.set('mainTable', flt)
Ejemplo n.º 4
0
 def handle_positiveResponse(self, ctx):
     client = livepage.IClientHandle(ctx)
     client.oldNode = client.node
     client.node = client.node.positive
     if client.node == win:
         client.node = knowledge
         yield livepage.set('question', "I win!"), livepage.eol
         yield livepage.set(
             'answer-inputs',
             tags.button(
                 id="start-over",
                 onclick=livepage.server.handle('updateDom'))["Start over"]), livepage.eol
     else:
         yield self.handle_updateDom(ctx), livepage.eol
Ejemplo n.º 5
0
    def tor_update(self, percent, tag, summary):
        if self.ctx is None:
            print "I have no Web client yet, but got a Tor update:", percent, tag, summary
            return

        point = int(300 * (float(percent) / 100.0))
        self.client.send(
            livepage.
            js('''document.getElementById('progress_done').style.width = "%dpx";'''
               % point))

        if percent == 100:
            # done, turn message box green too
            self.client.send(
                livepage.
                js('''document.getElementById("status").style.backgroundColor="#aaffaa";'''
                   ))

        if self.continuous_update:
            # add a text node for each update, creating a continuous list
            self.client.send(
                livepage.js('''var newNode = document.createElement('div');
newNode.appendChild(document.createTextNode("%d%% -- %s"));
document.getElementById('status').appendChild(newNode);''' %
                            (percent, summary)))

        else:
            self.client.send(
                livepage.set('status', "%d%% — %s" % (percent, summary)))
Ejemplo n.º 6
0
    def tor_update(self, percent, tag, summary):
        if self.ctx is None:
            print "I have no Web client yet, but got a Tor update:", percent, tag, summary
            return

        client = livepage.IClientHandle(self.ctx)

        point = int(300 * (float(percent) / 100.0))
        self.client.send(livepage.js("""document.getElementById('progress_done').style.width = "%dpx";""" % point))

        if percent == 100:
            ## done, turn message box green too
            self.client.send(livepage.js("""document.getElementById("status").style.backgroundColor="#aaffaa";"""))

        if self.continuous_update:
            ## add a text node for each update, creating a continuous list
            self.client.send(
                livepage.js(
                    """var newNode = document.createElement('div');
newNode.appendChild(document.createTextNode("%d%% -- %s"));
document.getElementById('status').appendChild(newNode);"""
                    % (percent, summary)
                )
            )

        else:
            self.client.send(livepage.set("status", "%d%% — %s" % (percent, summary)))
Ejemplo n.º 7
0
    def handle_changeNick(self, ctx, nick):
        changer = livepage.IClientHandle(ctx)
        rv = self.sendEvent(
            changer, set('user-list-%s' % (changer.userId, ), nick), eol,
            js.changeId('user-list-%s' % (changer.userId, ),
                        'user-list-%s' % (nick, )), eol,
            self.content(changer, 'changed nick to %r.' % (nick, )))

        changer.userId = nick
        return rv
Ejemplo n.º 8
0
    def drive(self):
        for i, test in enumerate(self.suite):
            self.state = i
            action, target, parameter = test
            actionCallable = getattr(self, 'action_%s' % (action, ), None)
            if actionCallable is not None:
                test = actionCallable(target, parameter)
                if test is not None:
                    yield  test

        self.handle.send(livepage.set('test-status', 'Complete'))
Ejemplo n.º 9
0
    def drive(self):
        for i, test in enumerate(self.suite):
            self.state = i
            action, target, parameter = test
            actionCallable = getattr(self, 'action_%s' % (action, ), None)
            if actionCallable is not None:
                test = actionCallable(target, parameter)
                if test is not None:
                    yield  test

        self.handle.send(livepage.set('test-status', 'Complete'))
Ejemplo n.º 10
0
    def _searchNotify(self, notification):
        visibility = 'visible' if notification else 'hidden'
        visJS = "document.getElementById('searchNotification').style.visibility='%s'" % visibility

        yield livepage.set('searchNotification', notification), livepage.eol
        yield livepage.js(visJS), livepage.eol
Ejemplo n.º 11
0
 def _searchNotify(self, notification):
     visibility = 'visible' if notification else 'hidden'
     visJS = "document.getElementById('searchNotification').style.visibility='%s'" % visibility
     
     yield livepage.set('searchNotification', notification), livepage.eol
     yield livepage.js(visJS), livepage.eol