Esempio n. 1
0
    def __init__(self):
        """
        Instantiates the quasimode window, creating all the necessary
        windows.
        """

        # Create a window for each line, keeping track of how tall
        # that window is.  Use a "top" variable to know how far down
        # the screen the top of the next window should start.

        height = DESCRIPTION_SCALE[-1] * HEIGHT_FACTOR
        self.__descriptionWindow = TextWindow(height=height, position=[0, 0])
        top = height

        height = AUTOCOMPLETE_SCALE[-1] * HEIGHT_FACTOR
        self.__userTextWindow = TextWindow(height=height, position=[0, top])
        top += height

        self.__suggestionWindows = []
        for i in range(config.QUASIMODE_MAX_SUGGESTIONS):
            height = SUGGESTION_SCALE[-1] * HEIGHT_FACTOR
            self.__suggestionWindows.append(TextWindow(height=height, position=[0, top]))
            top += height

        # The time, in float seconds since the epoch, when the last
        # drawing of the quasimode display started.
        self.__drawStart = 0
Esempio n. 2
0
    def __init__(self):
        """
        Instantiates the quasimode window, creating all the necessary
        windows.
        """

        # Create a window for each line, keeping track of how tall
        # that window is.  Use a "top" variable to know how far down
        # the screen the top of the next window should start.

        height = DESCRIPTION_SCALE[-1] * HEIGHT_FACTOR
        self.__descriptionWindow = TextWindow(
            height=height,
            position=[0, 0],
        )
        top = height

        height = AUTOCOMPLETE_SCALE[-1] * HEIGHT_FACTOR
        self.__userTextWindow = TextWindow(
            height=height,
            position=[0, top],
        )
        top += height

        self.__suggestionWindows = []
        for i in range(config.QUASIMODE_MAX_SUGGESTIONS):
            height = SUGGESTION_SCALE[-1] * HEIGHT_FACTOR
            self.__suggestionWindows.append(
                TextWindow(
                    height=height,
                    position=[0, top],
                ))
            top += height

        # The time, in float seconds since the epoch, when the last
        # drawing of the quasimode display started.
        self.__drawStart = 0
        atexit.register(self.__finalize)
Esempio n. 3
0
class QuasimodeWindow:
    """
    Implements the quasimode's display, in a multi-line transparent window.
    """

    # LONGTERM TODO: We will eventually need to deal with the overflow
    # cases in the correct ways: the autocompletion/user text should
    # wrap (as much as necessary), the suggestion list entries should
    # (1) have a max size using ellipses and (2) should "vertically
    # wrap" if there are more suggestions than will fit on one screen,
    # the help text should have a max length with ellipsis

    def __init__( self ):
        """
        Instantiates the quasimode window, creating all the necessary
        windows.
        """

        # Create a window for each line, keeping track of how tall
        # that window is.  Use a "top" variable to know how far down
        # the screen the top of the next window should start.

        height = DESCRIPTION_SCALE[-1]*HEIGHT_FACTOR
        self.__descriptionWindow = TextWindow(
            height = height,
            position = [ 0, 0 ],
            )
        top = height

        height = AUTOCOMPLETE_SCALE[-1]*HEIGHT_FACTOR
        self.__userTextWindow = TextWindow(
            height = height,
            position = [ 0, top ],
            )
        top += height

        self.__suggestionWindows = []
        for i in range( config.QUASIMODE_MAX_SUGGESTIONS ):
            height = SUGGESTION_SCALE[-1]*HEIGHT_FACTOR
            self.__suggestionWindows.append( TextWindow(
                height = height,
                position = [ 0, top ],
                ) )
            top += height

        # The time, in float seconds since the epoch, when the last
        # drawing of the quasimode display started.
        self.__drawStart = 0
        atexit.register(self.__finalize)
        

    def hide( self ):
        self.__descriptionWindow.hide()
        self.__userTextWindow.hide()
        for window in self.__suggestionWindows:
            window.hide()


    def update( self, quasimode, isFullRedraw ):
        """
        Fetches updated information from the quasimode, lays out and
        draws the quasimode window.

        This should only be called when the quasimode itself has
        changed.

        'isFullRedraw' is a boolean; if it is True, then the entire
        quasimode display, including suggestion list, will be redrawn
        when this function returns.  Otherwise, only the description
        text and user text will be redrawn, and the suggestions will
        be scheduled for redraw later.
        """

        # Instantiate a layout object, effectively laying out the
        # quasimode display.
        layout = QuasimodeLayout( quasimode )

        self.__drawStart = time.time()

        newLines = layout.newLines

        self.__descriptionWindow.draw( newLines[0] )

        suggestions = quasimode.getSuggestionList().getSuggestions()
        # TODO: Remake this so the line bear information about type, then
        # we can dynamically add did-you-mean hint window and don't need
        # to juggle with list index here
        suggestions_start = 3
        if len( suggestions[0].toXml() ) == 0 \
           and len( suggestions[0].getSource() ) == 0:
            self.__userTextWindow.hide()
        else:
            self.__userTextWindow.draw( newLines[1] )
        suggestionLines = newLines[suggestions_start:]

        # We now need to hide all line windows.
        for i in range( len( suggestionLines ),
                        len( self.__suggestionWindows ) ):
            self.__suggestionWindows[i].hide()

        self.__suggestionsLeft = _makeSuggestionIterator(
            suggestionLines,
            self.__suggestionWindows
            )

        if isFullRedraw:
            # Draw suggestions
            while self.continueDrawing( ignoreTimeElapsed = True ):
                pass


    # TODO: Finish this
    def ___updateSuggestionList_____( self, quasimode ):
        """
        Fetches updated information from the quasimode, lays out and
        draws the quasimode window.

        This should only be called when the quasimode itself has
        changed.

        'isFullRedraw' is a boolean; if it is True, then the entire
        quasimode display, including suggestion list, will be redrawn
        when this function returns.  Otherwise, only the description
        text and user text will be redrawn, and the suggestions will
        be scheduled for redraw later.
        """
        
        # Instantiate a layout object, effectively laying out the
        # quasimode display.
        layout = QuasimodeLayout( quasimode )

        self.__drawStart = time.time()

        newLines = layout.newLines

        self.__descriptionWindow.draw( newLines[0] )

        suggestions = quasimode.getSuggestionList().getSuggestions()
        # TODO: Remake this so the line bear information about type, then
        # we can dynamically add did-you-mean hint window and don't need
        # to juggle with list index here
        suggestions_start = 2
        if len( suggestions[0].toXml() ) == 0 \
           and len( suggestions[0].getSource() ) == 0:
            self.__userTextWindow.hide()
        else:
            self.__userTextWindow.draw( newLines[1] )
            didyoumean_hint = quasimode.getSuggestionList().getDidyoumeanHint()
            if didyoumean_hint:
                suggestions_start += 1
                self.__didyoumeanHintWindow.draw( newLines[2] )
            else:
                self.__didyoumeanHintWindow.hide()


        suggestionLines = newLines[suggestions_start:]

        # We now need to hide all line windows.
        #for i in range( len( suggestionLines ),
        #                len( self.__suggestionWindows ) ):
        #    self.__suggestionWindows[i].hide()

        self.__suggestionsLeft = _makeSuggestionIterator(
            suggestionLines,
            self.__suggestionWindows
            )

        while self.continueDrawing( ignoreTimeElapsed=True ):
            pass


    def continueDrawing( self, ignoreTimeElapsed=False ):
        """
        Continues drawing any parts of the quasimode display that
        haven't yet been drawn, such as the suggestion list.

        If 'ignoreTimeElapsed' is True, then the
        QUASIMODE_SUGGESTION_DELAY constant will be ignored and any
        pending suggestion waiting to be drawn will be rendered.

        Returns whether a suggestion was drawn.

        This function should only be called after update() has been
        called.
        """

        if self.__suggestionsLeft:
            timeElapsed = time.time() - self.__drawStart
            if ( (not ignoreTimeElapsed) and
                 (timeElapsed < config.QUASIMODE_SUGGESTION_DELAY) ):
                return False
            try:
                suggestionDrawer = self.__suggestionsLeft.next()
                suggestionDrawer.draw()
                return True
            except StopIteration:
                self.__suggestionsLeft = None
        return False


    def __finalize( self ):
        del self.__descriptionWindow
        self.__descriptionWindow = None
        del self.__userTextWindow
        self.__userTextWindow = None
        del self.__didyoumeanHintWindow
        self.__didyoumeanHintWindow = None
        for window in self.__suggestionWindows:
            del window
Esempio n. 4
0
class TheQuasimodeWindow:
    """
    Implements the quasimode's display, in a multi-line transparent window.
    """

    # LONGTERM TODO: We will eventually need to deal with the overflow
    # cases in the correct ways: the autocompletion/user text should
    # wrap (as much as necessary), the suggestion list entries should
    # (1) have a max size using ellipses and (2) should "vertically
    # wrap" if there are more suggestions than will fit on one screen,
    # the help text should have a max length with ellipsis

    def __init__(self):
        """
        Instantiates the quasimode window, creating all the necessary
        windows.
        """

        # Create a window for each line, keeping track of how tall
        # that window is.  Use a "top" variable to know how far down
        # the screen the top of the next window should start.

        height = DESCRIPTION_SCALE[-1] * HEIGHT_FACTOR
        self.__descriptionWindow = TextWindow(
            height=height,
            position=[0, 0],
        )
        top = height

        height = AUTOCOMPLETE_SCALE[-1] * HEIGHT_FACTOR
        self.__userTextWindow = TextWindow(
            height=height,
            position=[0, top],
        )
        top += height

        self.__suggestionWindows = []
        for i in range(config.QUASIMODE_MAX_SUGGESTIONS):
            height = SUGGESTION_SCALE[-1] * HEIGHT_FACTOR
            self.__suggestionWindows.append(
                TextWindow(
                    height=height,
                    position=[0, top],
                ))
            top += height

        # The time, in float seconds since the epoch, when the last
        # drawing of the quasimode display started.
        self.__drawStart = 0
        atexit.register(self.__finalize)

    def hide(self):
        self.__descriptionWindow.hide()
        self.__userTextWindow.hide()
        for window in self.__suggestionWindows:
            window.hide()

    def update(self, quasimode, isFullRedraw):
        """
        Fetches updated information from the quasimode, lays out and
        draws the quasimode window.

        This should only be called when the quasimode itself has
        changed.

        'isFullRedraw' is a boolean; if it is True, then the entire
        quasimode display, including suggestion list, will be redrawn
        when this function returns.  Otherwise, only the description
        text and user text will be redrawn, and the suggestions will
        be scheduled for redraw later.
        """

        # Instantiate a layout object, effectively laying out the
        # quasimode display.
        layout = QuasimodeLayout(quasimode)

        self.__drawStart = time.time()

        newLines = layout.newLines

        self.__descriptionWindow.draw(newLines[0])

        suggestions = quasimode.getSuggestionList().getSuggestions()
        if len( suggestions[0].toXml() ) == 0 \
           and len( suggestions[0].getSource() ) == 0:
            self.__userTextWindow.hide()
        else:
            self.__userTextWindow.draw(newLines[1])

        suggestionLines = newLines[2:]

        # We now need to hide all line windows.
        for i in range(len(suggestionLines), len(self.__suggestionWindows)):
            self.__suggestionWindows[i].hide()

        self.__suggestionsLeft = _makeSuggestionIterator(
            suggestionLines, self.__suggestionWindows)

        if isFullRedraw:
            while self.continueDrawing(ignoreTimeElapsed=True):
                pass

    def continueDrawing(self, ignoreTimeElapsed=False):
        """
        Continues drawing any parts of the quasimode display that
        haven't yet been drawn, such as the suggestion list.

        If 'ignoreTimeElapsed' is True, then the
        QUASIMODE_SUGGESTION_DELAY constant will be ignored and any
        pending suggestion waiting to be drawn will be rendered.

        Returns whether a suggestion was drawn.

        This function should only be called after update() has been
        called.
        """

        if self.__suggestionsLeft:
            timeElapsed = time.time() - self.__drawStart
            if ((not ignoreTimeElapsed)
                    and (timeElapsed < config.QUASIMODE_SUGGESTION_DELAY)):
                return False
            try:
                suggestionDrawer = self.__suggestionsLeft.next()
                suggestionDrawer.draw()
                return True
            except StopIteration:
                self.__suggestionsLeft = None
        return False

    def __finalize(self):
        logging.info("__finalize(): Deleting windows")
        del self.__descriptionWindow
        self.__descriptionWindow = None
        del self.__userTextWindow
        self.__userTextWindow = None
        for window in self.__suggestionWindows:
            del window
Esempio n. 5
0
class QuasimodeWindow(object):
    """
    Implements the quasimode's display, in a multi-line transparent window.
    """

    # LONGTERM TODO: We will eventually need to deal with the overflow
    # cases in the correct ways: the autocompletion/user text should
    # wrap (as much as necessary), the suggestion list entries should
    # (1) have a max size using ellipses and (2) should "vertically
    # wrap" if there are more suggestions than will fit on one screen,
    # the help text should have a max length with ellipsis

    def __init__(self):
        """
        Instantiates the quasimode window, creating all the necessary
        windows.
        """

        # Create a window for each line, keeping track of how tall
        # that window is.  Use a "top" variable to know how far down
        # the screen the top of the next window should start.

        top = POSITION[1]
        height = DESCRIPTION_SCALE[-1] * HEIGHT_FACTOR
        self.__descriptionWindow = TextWindow(
            height=height,
            position=POSITION,
        )
        top += height

        height = AUTOCOMPLETE_SCALE[-1] * HEIGHT_FACTOR
        self.__userTextWindow = TextWindow(
            height=height,
            position=[POSITION[0], top],
        )
        top += height

        height = DIDYOUMEANHINT_SCALE[-1] * HEIGHT_FACTOR
        self.__didyoumeanHintWindow = TextWindow(
            height=height,
            position=[POSITION[0] + 250, top],
        )

        self.__suggestionWindows = []
        for _ in range(config.QUASIMODE_MAX_SUGGESTIONS):
            height = SUGGESTION_SCALE[-1] * HEIGHT_FACTOR
            self.__suggestionWindows.append(TextWindow(
                height=height,
                position=[POSITION[0], top],
            ))
            top += height

        # The time, in float seconds since the epoch, when the last
        # drawing of the quasimode display started.
        self.__drawStart = 0
        atexit.register(self.__finalize)

    def setPosition(self, x, y):
        self.__descriptionWindow.setPosition(x, y)

    def hide(self):
        self.__descriptionWindow.hide()
        self.__userTextWindow.hide()
        if self.__didyoumeanHintWindow:
            self.__didyoumeanHintWindow.hide()
            #self.__didyoumeanHintWindow = None
        for window in self.__suggestionWindows:
            window.hide()

    def update(self, quasimode, isFullRedraw):
        """
        Fetches updated information from the quasimode, lays out and
        draws the quasimode window.

        This should only be called when the quasimode itself has
        changed.

        'isFullRedraw' is a boolean; if it is True, then the entire
        quasimode display, including suggestion list, will be redrawn
        when this function returns.  Otherwise, only the description
        text and user text will be redrawn, and the suggestions will
        be scheduled for redraw later.
        """

        # Instantiate a layout object, effectively laying out the
        # quasimode display.
        layout = QuasimodeLayout(quasimode)

        self.__drawStart = time.time()

        newLines = layout.newLines

        self.__descriptionWindow.draw(newLines[0])

        suggestions = quasimode.getSuggestionList().getSuggestions()
        # TODO: Remake this so the line bear information about type, then
        # we can dynamically add did-you-mean hint window and don't need
        # to juggle with list index here
        suggestions_start = 3
        if suggestions[0].isEmpty() \
           and len(suggestions[0].getSource()) == 0:
            self.__userTextWindow.hide()
            self.__didyoumeanHintWindow.hide()
        else:
            self.__userTextWindow.draw(newLines[1])
            didyoumean_hint = quasimode.getSuggestionList().getDidyoumeanHint()
            if didyoumean_hint:
                if len(newLines) - suggestions_start > 0:
                    # If there is at least one suggestion, draw it first as we want
                    # to overlay it with the did-you-mean hint window
                    self.__suggestionWindows[0].draw(
                        newLines[suggestions_start])
                    suggestions_start += 1
                w = layout.getCurrentCommandWidth(quasimode)
                if w:
                    _, y = self.__didyoumeanHintWindow.getPosition()
                    self.__didyoumeanHintWindow.setPosition(w, y)
                self.__didyoumeanHintWindow.draw(newLines[2])
            else:
                self.__didyoumeanHintWindow.hide()
        suggestionLines = newLines[suggestions_start:]

        # We now need to hide all line windows.
        for i in range(len(suggestionLines),
                       len(self.__suggestionWindows)):
            self.__suggestionWindows[i].hide()

        self.__suggestionsLeft = _makeSuggestionIterator(
            suggestionLines,
            self.__suggestionWindows
        )

        if isFullRedraw:
            # Draw suggestions
            while self.continueDrawing(ignoreTimeElapsed=True):
                pass

    def continueDrawing(self, ignoreTimeElapsed=False):
        """
        Continues drawing any parts of the quasimode display that
        haven't yet been drawn, such as the suggestion list.

        If 'ignoreTimeElapsed' is True, then the
        QUASIMODE_SUGGESTION_DELAY constant will be ignored and any
        pending suggestion waiting to be drawn will be rendered.

        Returns whether a suggestion was drawn.

        This function should only be called after update() has been
        called.
        """

        if not self.__suggestionsLeft:
            return False

        timeElapsed = time.time() - self.__drawStart
        if ((not ignoreTimeElapsed) and
                (timeElapsed < config.QUASIMODE_SUGGESTION_DELAY)):
            return False
        try:
            suggestionDrawer = self.__suggestionsLeft.next()
            suggestionDrawer.draw()
            return True
        except StopIteration:
            self.__suggestionsLeft = None

    def __finalize(self):
        del self.__descriptionWindow
        self.__descriptionWindow = None
        del self.__userTextWindow
        self.__userTextWindow = None
        del self.__didyoumeanHintWindow
        self.__didyoumeanHintWindow = None
        for window in self.__suggestionWindows:
            del window