Пример #1
0
    def __layoutBlocks( self, messageDoc, captionDoc ):
        """
        Determines how the documents messageDoc and captionDoc should
        be combined to form a complete message window.

        Returns a tuple:
          ( width, height, messagePosition, captionPosition )
        """

        capDoc, msgDoc = captionDoc, messageDoc
        if capDoc == None:
            width = computeWidth( msgDoc )
            height = msgDoc.height
            msgPos = ( PRIM_MSG_MARGIN, PRIM_MSG_MARGIN )
            capPos = None
        elif self.__isOneLineMsg( msgDoc, capDoc ):
            msgWidth = computeWidth( msgDoc )
            capWidth = computeWidth( capDoc )
            width = max( msgWidth, capWidth )
            height = msgDoc.height + capDoc.height
            msgPos = ( PRIM_MSG_MARGIN + ( ( width - msgWidth ) / 2 ), 
                       PRIM_MSG_MARGIN )
            capPos = ( PRIM_MSG_MARGIN + ( ( width - capWidth ) / 2 ),
                       msgPos[1] + msgDoc.height )
        else:
            msgWidth = computeWidth( msgDoc )
            capWidth = computeWidth( capDoc ) 
            width = max( msgWidth, capWidth )
            height = msgDoc.height + capDoc.height
            msgPos = ( PRIM_MSG_MARGIN, PRIM_MSG_MARGIN )
            capPos = ( width - capWidth + PRIM_MSG_MARGIN,
                       msgPos[1] + msgDoc.height )
        return width, height, msgPos, capPos
    def __draw( self, msg, xPos, yPos ):
        width, height = MINI_WIND_SIZE
        self.setSize( width, height )

        self.setPos( xPos, yPos )

        docSize = width - 2*MINI_MARGIN, height - 2*MINI_MARGIN
        doc = self.__layout( msg, docSize[0], docSize[1] )

        afterWidth = computeWidth( doc )
        afterHeight = doc.height

        xPos = ( width - afterWidth ) / 2
        yPos = ( height - afterHeight ) / 2

        cr = self._context
        if self.__isRounded:
            corners = [rounded_rect.UPPER_LEFT]
        else:
            corners = []

        cr.set_source_rgba( *MINI_BG_COLOR )
        rounded_rect.drawRoundedRect(
            context = cr,
            rect = ( 0, 0, width, height),
            softenedCorners = corners,
            )
        cr.fill_preserve()

        doc.draw( xPos, yPos, cr )
    def __draw(self, msg, xPos, yPos):
        width, height = MINI_WIND_SIZE
        self.setSize(width, height)

        self.setPos(xPos, yPos)

        docSize = width - 2 * MINI_MARGIN, height - 2 * MINI_MARGIN
        doc = self.__layout(msg, docSize[0], docSize[1])

        afterWidth = computeWidth(doc)
        afterHeight = doc.height

        xPos = (width - afterWidth) / 2
        yPos = (height - afterHeight) / 2

        cr = self._getContext()
        if self.__isRounded:
            corners = [rounded_rect.UPPER_LEFT]
        else:
            corners = []

        cr.set_source_rgba(*MINI_BG_COLOR)
        rounded_rect.drawRoundedRect(
            context=cr,
            rect=(0, 0, width, height),
            softenedCorners=corners,
        )
        cr.fill_preserve()

        doc.draw(xPos, yPos, cr)
    def __refreshParameterSuggestionsList(self, timePassed):
        self.__lastParameterSuggestionsCheck += timePassed

        # Check only each 10 milliseconds
        if self.__lastParameterSuggestionsCheck < 5:
            return

        self.__lastParameterSuggestionsCheck = 0

        # Check active command
        cmd = self.__suggestionList.getActiveCommand()
        if not cmd:
            return

        try:
            suggestions = cmd.getParameterSuggestions()
        except AttributeError as e:
            # Check if it is arbitrary-postfix command that supports
            # suggestions
            return
        except Exception as e:
            logging.error(
                "Error calling command.getParameterSuggestions(): %s", e)
            return

        if not suggestions and not self.__lastParameterSuggestions:
            return

        # No suggestions returned or the list has not changed since last time
        if suggestions is None or suggestions == self.__lastParameterSuggestions:
            return

        if not self.__parameterSuggestionList.getSuggestions():
            # The window has not been displayed yet, compute its horizontal
            # position
            line = layout.layoutXmlLine(
                xml_data="<document><line>%s</line></document>" % cmd.PREFIX,
                styles=layout.retrieveAutocompleteStyles(),
                scale=layout.AUTOCOMPLETE_SCALE
            )
            xPos = computeWidth(line)
        else:
            xPos = None

        # Display and refresh the suggestion window
        self.__parameterSuggestionList.setSuggestions(suggestions, xPos)
        self.__lastParameterSuggestions = suggestions