def __setupBackground( self, width, height ): """ Given a text region of width and height, sets the size of the underlying window to be that plus margins, and draws a rounded background rectangle. """ width += (2*PRIM_MSG_MARGIN)-2 height += (2*PRIM_MSG_MARGIN)-2 width = int(width) height = int(height) assert width <= self.getMaxSize()[0], \ "width %s, self.getMaxSize()[0] %s" \ % (width, self.getMaxSize()[0]) self.setSize( width, height ) self.__position() cr = self._context rounded_rect.drawRoundedRect( context = cr, rect = ( 0, 0, width, height ), softenedCorners = rounded_rect.ALL_CORNERS, ) cr.set_source_rgba( *MSG_BGCOLOR ) cr.fill_preserve()
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 __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, document): """ Draws the text described by document. An updating call; at the end of this method, the displayed window should reflect the drawn content. """ if self.__width != graphics.getDesktopSize()[0]: del self.__window self.__setupWindow() width = document.ragWidth + layout.L_MARGIN + layout.R_MARGIN height = self.__window.getMaxHeight() cr = self.__context # Clear the areas where the corners of the rounded rectangle will be. cr.save() cr.set_source_rgba(0, 0, 0, 0) cr.set_operator(cairo.OPERATOR_SOURCE) cr.rectangle(width - rounded_rect.CORNER_RADIUS, height - rounded_rect.CORNER_RADIUS, rounded_rect.CORNER_RADIUS, rounded_rect.CORNER_RADIUS) cr.rectangle(width - rounded_rect.CORNER_RADIUS, 0, rounded_rect.CORNER_RADIUS, rounded_rect.CORNER_RADIUS) cr.paint() # Draw the background rounded rectangle. corners = [] if document.roundUpperRight: corners.append(rounded_rect.UPPER_RIGHT) if document.roundLowerRight: corners.append(rounded_rect.LOWER_RIGHT) if document.roundLowerLeft: corners.append(rounded_rect.LOWER_LEFT) cr.set_source_rgba(*document.background) rounded_rect.drawRoundedRect(context=cr, rect=(0, 0, width, height), softenedCorners=corners) cr.fill_preserve() cr.restore() # Next, draw the text. document.draw(layout.L_MARGIN, document.shrinkOffset, self.__context) width = min(self.__window.getMaxWidth(), width) height = min(self.__window.getMaxHeight(), height) self.__window.setSize(width, height) self.__window.update() self.__is_visible = True
def draw( self, document ): """ Draws the text described by document. An updating call; at the end of this method, the displayed window should reflect the drawn content. """ if self.__width != graphics.getDesktopSize()[0]: del self.__window self.__setupWindow() width = document.ragWidth + layout.L_MARGIN + layout.R_MARGIN height = self.__window.getMaxHeight() cr = self.__context # Clear the areas where the corners of the rounded rectangle will be. cr.save() cr.set_source_rgba( 0, 0, 0, 0 ) cr.set_operator( cairo.OPERATOR_SOURCE ) cr.rectangle( width - rounded_rect.CORNER_RADIUS, height - rounded_rect.CORNER_RADIUS, rounded_rect.CORNER_RADIUS, rounded_rect.CORNER_RADIUS ) cr.rectangle( width - rounded_rect.CORNER_RADIUS, 0, rounded_rect.CORNER_RADIUS, rounded_rect.CORNER_RADIUS ) cr.paint() # Draw the background rounded rectangle. corners = [] if document.roundUpperRight: corners.append( rounded_rect.UPPER_RIGHT ) if document.roundLowerRight: corners.append( rounded_rect.LOWER_RIGHT ) if document.roundLowerLeft: corners.append( rounded_rect.LOWER_LEFT ) cr.set_source_rgba( *document.background ) rounded_rect.drawRoundedRect( context = cr, rect = ( 0, 0, width, height ), softenedCorners = corners ) cr.fill_preserve() cr.restore() # Next, draw the text. document.draw( layout.L_MARGIN, document.shrinkOffset, self.__context ) width = min( self.__window.getMaxWidth(), width ) height = min( self.__window.getMaxHeight(), height ) self.__window.setSize( width, height ) self.__window.update() self.__is_visible = True
def draw(self, document, activeIndex): """ Draws the text described by document. An updating call; at the end of this method, the displayed window should reflect the drawn content. """ def _computeWidth(doc): lines = [] for b in doc.blocks: lines.extend(b.lines) if len(lines) == 0: return 0 return max([l.xMax for l in lines]) def _computeHeight(doc): height = 0 for b in doc.blocks: height += b.height # for line in b.lines: # height += line.lineHeight return height width = _computeWidth(document) + layout.L_MARGIN + layout.R_MARGIN width = max(width, 300) height = document.height # _computeHeight(document) cr = self.__context # Clear the areas where the corners of the rounded rectangle will be. cr.save() cr.set_source_rgba(0, 0, 0, 0) cr.set_operator(cairo.OPERATOR_SOURCE) # IGNORE:E1101 @UndefinedVariable cr.rectangle(width - rounded_rect.CORNER_RADIUS, height - rounded_rect.CORNER_RADIUS, rounded_rect.CORNER_RADIUS, rounded_rect.CORNER_RADIUS) cr.rectangle(width - rounded_rect.CORNER_RADIUS, 0, rounded_rect.CORNER_RADIUS, rounded_rect.CORNER_RADIUS) cr.paint() """ # Draw the background rounded rectangle. corners = [] #corners.append( rounded_rect.UPPER_LEFT ) #if document.roundUpperRight: corners.append( rounded_rect.UPPER_RIGHT ) #if document.roundLowerRight: corners.append( rounded_rect.LOWER_RIGHT ) #if document.roundLowerLeft: corners.append( rounded_rect.LOWER_LEFT ) """ corners = { rounded_rect.UPPER_RIGHT: None, rounded_rect.LOWER_RIGHT: 14, rounded_rect.LOWER_LEFT: None } document.background = xmltextlayout.colorHashToRgba( layout.MAIN_BACKGROUND_COLOR) cr.set_source_rgba(*document.background) rounded_rect.drawRoundedRect(context=cr, rect=(0, 0, width, height), softenedCorners=corners) cr.fill_preserve() cr.set_source_rgba(*xmltextlayout.colorHashToRgba("#404040")) cr.set_line_width(1.0) if activeIndex is not None: bar_left = layout.L_MARGIN - 2 bar_width = width - bar_left - layout.L_MARGIN + 2 bar_height = document.blocks[0].height bar_top = activeIndex * bar_height + document.marginTop rounded_rect.drawRoundedRect(context=cr, rect=( bar_left, bar_top, bar_width, bar_height), softenedCorners=rounded_rect.ALL_CORNERS, radius=2) cr.fill_preserve() # cr.stroke() cr.restore() # Next, draw the text. document.draw(layout.L_MARGIN, document.shrinkOffset, self.__context) width = min(self.__window.getMaxWidth(), width) # height = document.blocks[0].height * len(document.blocks) #layout.PARAMETERSUGGESTION_SCALE[-1]*layout.HEIGHT_FACTOR #height = min( self.__window.getMaxHeight(), height ) #self.__window.setSize( width, height ) if not self.__is_visible and not self.__animatingShow: self.__animatingShow = True self.__animatingHide = False self.__is_visible = True self.__timeSinceDismissal = 0 with suppress(AssertionError): self.__evtManager.registerResponder( self.animationTick, "timer") else: # Just refreshing started = time.time() self.__window.setOpacity(MAX_OPACITY) # print time.time() - started self.__window.update()