Example #1
0
 def goForward(self):
     index = wait(self.get('selectedIndex'))
     yield index
     index = index.getResult()
     if index + 1 < len(self.children):
         index = wait(self.set('selectedIndex', index + 1))
         yield index
         index = index.getResult()
         yield index
     else:
         yield None
Example #2
0
 def goBack(self):
     index = wait(self.get('selectedIndex'))
     yield index
     index = index.getResult()
     if index != 0:
         index = wait(self.set('selectedIndex', index - 1))
         yield index
         index = index.getResult()
         yield index
     else:
         yield None
Example #3
0
 def _updateBackForward(self, curIndex):
     if curIndex == 0 and self.curCanGoBack:
         self.curCanGoBack = False
         yield wait(self.dispatch(signal.canGoBack, False))
     elif curIndex != 0 and not self.curCanGoBack:
         self.curCanGoBack = True
         yield wait(self.dispatch(signal.canGoBack, True))
     if curIndex + 1 == len(self.children) and self.curCanGoForward:
         self.curCanGoForward = False
         yield wait(self.dispatch(signal.canGoForward, False))
     elif curIndex + 1 < len(self.children) and not self.curCanGoForward:
         self.curCanGoForward = True
         yield wait(self.dispatch(signal.canGoForward, True))
     yield curIndex
Example #4
0
 def dimensions(self):
     """dimensions() -> deferred (width, height) of window"""
     yield wait(DeferredList([
         self.getAttr(u'width'),
         self.getAttr(u'height'),
         ]))
     yield tuple(result for success, result in results)
Example #5
0
 def addPage(self, page):
     # First, remove pages beyond the current index.
     index = wait(self.get('selectedIndex'))
     yield index
     index = index.getResult()
     toRemove = self.children[index + 1:]
     yield wait(DeferredList([
         self.removePage(rpage) for rpage in toRemove
         ]))
     # Next, add the new page.
     index = wait(std.Deck.addPage(self, page))
     yield index
     index = index.getResult()
     # Select the page after adding it.
     yield wait(self.set('selectedIndex', index))
     # Update back/forward.
     yield wait(self._updateBackForward(index))
     yield index
Example #6
0
 def setTitle(self, title):
     """setTitle(title) -> deferred title of window."""
     # Set the `title` attribute of the XUL window, and also set
     # the title of the browser window.
     yield wait(DeferredList([
         self.setAttr(u'title', title),
         self.pageCtx.callRemote('setWindowTitle', title),
         ]))
     yield title
Example #7
0
 def get(self, attr, default=u''):
     """Get the value of a remote attribute."""
     if not self.alive:
         yield self.kwargs.get(attr, default)
     else:
         value = wait(self.callGlobal(
             'getAttr', self.id, attr.decode('ascii')))
         yield value
         value = value.getResult()
         yield value[0][0]
Example #8
0
 def setDimensions(self, width=None, height=None):
     """setDimensions(width, height) -> deferred (width, height) of
     window"""
     if not width or not height:
         # Get existing dimensions.
         dimensions = wait(self.dimensions())
         yield dimensions
         dimensions = dimensions.getResult()
         # Update new dimensions as necessary.
         curWidth, curHeight = dimensions
         width = width or curWidth
         height = height or curHeight
     # Set the height and width of the XUL window, and resize the
     # browser window.
     yield wait(DeferredList([
         self.setAttr(u'width', width),
         self.setAttr(u'height', height),
         self.pageCtx.callRemote(u'resizeWindow', width, height),
         ]))
     yield (width, height)
Example #9
0
    def dispatch(self, signal, *args):
        """Dispatch ``signal`` with optional ``args`` to listeners.

        Returns a deferred that calls back with a list of
        (receiver, result) tuples after all receivers have finished.
        """
        receiver_results = louie.send_minimal(signal, self, *args)
        results = []
        for receiver, result in receiver_results:
            if isinstance(result, Deferred):
                result = wait(result)
                yield result
                result = result.getResult()
            results.append((receiver, result))
        yield results
Example #10
0
 def on_jsOncommand(self):
     value = wait(self.get('value'))
     yield value
     value = value.getResult()
     self.dispatch(signal.itemSelected, value)
     yield None
Example #11
0
 def addPage(self, page):
     """Returns the index of ``page`` after adding it."""
     yield wait(self.liveAppend(page))
     yield self.children.index(page)