Beispiel #1
0
 def on_paint(self, event):
     if self.buffer is None: return
     wx.BufferedPaintDC(self, self.buffer)
 def OnPaint(self, event):
     #print "colonyview on paint"
     dc = wx.BufferedPaintDC(self, self.buffer)
Beispiel #3
0
    def OnPaint(self, event):
        """
        Handles the ``wx.EVT_PAINT`` event for L{RoundButton}.

        :param `event`: a `wx.PaintEvent` event to be processed.
        """

        dc = wx.BufferedPaintDC(self)
        
        am = AM.ArtManager()
        
        gc = wx.GraphicsContext.Create(dc)
        dc.SetBackground(wx.Brush(self.GetParent().GetBackgroundColour()))
        dc.Clear()
        
        clientRect = self.GetClientRect()
        boundaryRect = clientRect

        x, y, width, height = clientRect
        colour = self.GetForegroundColour()
        textColour = am.DarkColour(wx.WHITE, 3.0) if am.IsDark(colour) else am.LightColour(wx.BLACK, 3.0)
                    
        pressed = False
        if wx.Window.GetCapture() != self:
            if self._mouseAction == HOVER:
                colour = am.LightColour(colour, 10.0)
        else:
            colour = am.DarkColour(colour, 10.0)
            textColour = am.DarkColour(textColour, 10.0)
            pressed = True

        r = min(boundaryRect.GetWidth(), boundaryRect.GetHeight()) // 2
        xCenter = x + width // 2
        yCenter = y + height // 2
        
        gc.SetPen( wx.TRANSPARENT_PEN )
        
        def drawCircle( x, y, r ):
            gc.DrawEllipse( x - r, y - r, r * 2, r * 2 )
        
        # Draw the metal ring
        gc.SetBrush( gc.CreateRadialGradientBrush(
                        xCenter, yCenter - r,
                        xCenter, yCenter - r,
                        r * 2,
                        wx.WHITE, wx.Colour(33,33,33) ) )
        drawCircle( xCenter, yCenter, r )
        
        rSmaller = r * 0.80
        gc.SetBrush( gc.CreateRadialGradientBrush(
                        xCenter, yCenter + rSmaller,
                        xCenter, yCenter + rSmaller,
                        rSmaller * 2,
                        wx.WHITE, wx.Colour(33,33,33) ) )
        drawCircle( xCenter, yCenter, rSmaller )
        
        # Draw the body of the button.
        rSmaller *= 0.93
        if pressed:
            shrink = 0.025
            yCenter -= r * shrink / 2.0
            
        dc.SetFont( self.GetFont() )
        cRegular = colour
        gc.SetBrush( gc.CreateRadialGradientBrush(
                        xCenter, yCenter + rSmaller * 0.9,
                        xCenter, yCenter + rSmaller,
                        rSmaller * 2,
                        am.LightColour(colour, 75.0), cRegular ) )
        drawCircle( xCenter, yCenter, rSmaller )
        self._buttonRadius = rSmaller
        
        # Draw the flare at the top of the button (a shaded ellipse with a linear gradient).
        gc.SetBrush( gc.CreateLinearGradientBrush(
                        xCenter - rSmaller, yCenter - rSmaller,
                        xCenter - rSmaller, yCenter,
                        am.LightColour(colour, 40.0), am.LightColour(colour, 30.0)) )
                        
        # Magic constants to get things to look right.
        rWidth = rSmaller * (2.0 * 0.7 * 0.9)
        rHeight = rSmaller * (0.8 * 0.9)
        gc.DrawEllipse( xCenter - rWidth / 2, yCenter - rSmaller, rWidth, rHeight )
        
        # Draw an outline around the button body.
        # Also covers up the gap between the flare and the top edge of the button.
        gc.SetPen( wx.Pen(wx.Colour(50,50,50), r * 0.025) )
        gc.SetBrush( wx.TRANSPARENT_BRUSH )
        gc.DrawEllipse( xCenter - rSmaller, yCenter - rSmaller, rSmaller * 2, rSmaller * 2 )
        
        dc.SetTextForeground( textColour )

        label = self.GetLabel().strip()
        if not label:
            return
        lines = label.split('\n') 
        textWidth, textHeight = dc.GetTextExtent( label[0] )
        
        yText = yCenter - textHeight * len(lines) / 2.0
        for line in lines:
            dc.DrawText( line, xCenter - dc.GetTextExtent(line)[0] // 2, yText )
            yText += textHeight
 def OnPaint(self, event):
     if not self:
         return
     dc = wx.BufferedPaintDC(self)
     dc.Clear()
     dc.DrawBitmap(self.backgroundBitmap, 0, 0, True)
Beispiel #5
0
 def OnPaint(self, evt):
     dc = wx.BufferedPaintDC(self)
     self.Draw(dc)
Beispiel #6
0
 def OnPaint(self, event):
     dc = wx.BufferedPaintDC(self, self._buffer)
Beispiel #7
0
    def OnPaint(self, event):
        """
        Handles the ``wx.EVT_PAINT`` event for :class:`PyGauge`.

        :param `event`: a :class:`PaintEvent` event to be processed.
        """

        dc = wx.BufferedPaintDC(self)
        rect = self.GetClientRect()

        dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
        dc.Clear()
        colour = self.GetBackgroundColour()
        dc.SetBrush(wx.Brush(colour))
        dc.SetPen(wx.Pen(colour))
        dc.DrawRectangle(rect)


        if self._border_colour:
            dc.SetPen(wx.Pen(self.GetBorderColour()))
            dc.DrawRectangle(rect)
            pad = 1 + self.GetBorderPadding()
            rect.Deflate(pad,pad)


        if self.GetBarGradient():
            for i, gradient in enumerate(self._barGradientSorted):
                c1,c2 = gradient
                w = rect.width * (float(self._valueSorted[i]) / self._range)
                r = copy.copy(rect)
                r.width = w
                dc.GradientFillLinear(r, c1, c2, wx.EAST)
        else:
            for i, colour in enumerate(self._barColourSorted):
                dc.SetBrush(wx.Brush(colour))
                dc.SetPen(wx.Pen(colour))
                w = rect.width * (float(self._valueSorted[i]) / self._range)
                r = copy.copy(rect)
                r.width = w
                dc.DrawRectangle(r)


        if self._drawIndicatorText:
            dc.SetFont(self._drawIndicatorText_font)
            dc.SetTextForeground(self._drawIndicatorText_colour)
            drawValue = self._valueSorted[i]

            if self._drawIndicatorText_drawPercent:
                drawValue = (float(self._valueSorted[i]) * 100)  / self._range

            drawString = self._drawIndicatorText_formatString.format(drawValue)
            rect = self.GetClientRect()
            (textWidth, textHeight, descent, extraLeading) = dc.GetFullTextExtent(drawString)
            textYPos = (rect.height-textHeight)/2

            if textHeight > rect.height:
                textYPos = 0-descent+extraLeading

            textXPos = (rect.width-textWidth)/2

            if textWidth>rect.width:
                textXPos = 0

            dc.DrawText(drawString, textXPos, textYPos)
Beispiel #8
0
    def OnPaint(self, event):
        """
        Handles the ``wx.EVT_PAINT`` event for L{SuperToolTip}.

        :param `event`: a `wx.PaintEvent` event to be processed.
        """

        # Go with double buffering...
        dc = wx.BufferedPaintDC(self)
        
        frameRect = self.GetClientRect()
        x, y, width, height = frameRect
        # Store the rects for the hyperlink lines
        self._hyperlinkRect, self._hyperlinkWeb = [], []
        classParent = self._classParent

        # Retrieve the colours for the blended triple-gradient background
        topColour, middleColour, bottomColour = classParent.GetTopGradientColour(), \
                                                classParent.GetMiddleGradientColour(), \
                                                classParent.GetBottomGradientColour()

        # Get the user options for header, bitmaps etc...        
        drawHeader, drawFooter = classParent.GetDrawHeaderLine(), classParent.GetDrawFooterLine()
        topRect = wx.Rect(frameRect.x, frameRect.y, frameRect.width, frameRect.height/2)
        bottomRect = wx.Rect(frameRect.x, frameRect.y+frameRect.height/2, frameRect.width, frameRect.height/2+1)
        # Fill the triple-gradient
        dc.GradientFillLinear(topRect, topColour, middleColour, wx.SOUTH)
        dc.GradientFillLinear(bottomRect, middleColour, bottomColour, wx.SOUTH)

        header, headerBmp = classParent.GetHeader(), classParent.GetHeaderBitmap()
        headerFont, messageFont, footerFont, hyperlinkFont = classParent.GetHeaderFont(), classParent.GetMessageFont(), \
                                                             classParent.GetFooterFont(), classParent.GetHyperlinkFont()
        
        xPos, yPos = self._spacing, 0
        bmpXPos = bmpYPos = 0
        bmpHeight = textHeight = bmpWidth = 0

        if headerBmp and headerBmp.IsOk():
            # We got the header bitmap
            bmpHeight, bmpWidth = headerBmp.GetHeight(), headerBmp.GetWidth()
            bmpXPos = self._spacing
            
        if header:
            # We got the header text
            dc.SetFont(headerFont)
            textWidth, textHeight = dc.GetTextExtent(header)

        # Calculate the header height
        height = max(textHeight, bmpHeight)
        if header:
            dc.DrawText(header, bmpXPos+bmpWidth+self._spacing, (height-textHeight+self._spacing)/2)
        if headerBmp and headerBmp.IsOk():
            dc.DrawBitmap(headerBmp, bmpXPos, (height-bmpHeight+self._spacing)/2, True)

        if header or (headerBmp and headerBmp.IsOk()):
            yPos += height
            if drawHeader:
                # Draw the separator line after the header
                dc.SetPen(wx.GREY_PEN)
                dc.DrawLine(self._spacing, yPos+self._spacing, width-self._spacing, yPos+self._spacing)

        # Get the big body image (if any)
        embeddedImage = classParent.GetBodyImage()    
        bmpWidth = bmpHeight = -1
        if embeddedImage and embeddedImage.IsOk():
            bmpWidth, bmpHeight = embeddedImage.GetWidth(), embeddedImage.GetHeight()

        # A bunch of calculations to draw the main body message
        messageHeight = 0
        textSpacing = (bmpWidth > 0 and [3*self._spacing] or [2*self._spacing])[0]
        lines = classParent.GetMessage().split("\n")
        yText = yPos
        normalText = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUTEXT)
        hyperLinkText = wx.BLUE
        
        for indx, line in enumerate(lines):
            # Loop over all the lines in the message
            isLink = False
            dc.SetTextForeground(normalText)
            if line.startswith("</b>"):      # is a bold line
                line = line[4:]
                font = MakeBold(messageFont)
                dc.SetFont(font)
            elif line.startswith("</l>"):    # is a link
                dc.SetFont(hyperlinkFont)
                isLink = True
                line, hl = ExtractLink(line)
                dc.SetTextForeground(hyperLinkText)
            else:
                # Is a normal line
                dc.SetFont(messageFont)

            textWidth, textHeight = dc.GetTextExtent(line)
            if textHeight == 0:
                textWidth, textHeight = dc.GetTextExtent("a")

            messageHeight += textHeight

            xText = (bmpWidth > 0 and [bmpWidth+2*self._spacing] or [self._spacing])[0]
            yText += textHeight/2+self._spacing
            
            dc.DrawText(line, xText, yText)
            if isLink:
                # Store the hyperlink rectangle and link
                self._hyperlinkRect.append(wx.Rect(xText, yText, textWidth, textHeight))
                self._hyperlinkWeb.append(hl)

            if indx == 0:
                messagePos = yText

        toAdd = 0
        if bmpHeight > textHeight:
            yPos += 2*self._spacing + bmpHeight
            toAdd = self._spacing
        else:
            yPos += messageHeight + 2*self._spacing
            
        yText = max(messageHeight, bmpHeight+2*self._spacing)
        if embeddedImage and embeddedImage.IsOk():
            # Draw the main body image
            dc.DrawBitmap(embeddedImage, self._spacing, messagePos, True)
        
        footer, footerBmp = classParent.GetFooter(), classParent.GetFooterBitmap()
        bmpHeight = bmpWidth = textHeight = textWidth = 0
        bmpXPos = bmpYPos = 0
        
        if footerBmp and footerBmp.IsOk():
            # Got the footer bitmap
            bmpHeight, bmpWidth = footerBmp.GetHeight(), footerBmp.GetWidth()
            bmpXPos = self._spacing
            
        if footer:
            # Got the footer text
            dc.SetFont(footerFont)
            textWidth, textHeight = dc.GetTextExtent(footer)

        if textHeight or bmpHeight:
            if drawFooter:
                # Draw the separator line before the footer
                dc.SetPen(wx.GREY_PEN)
                dc.DrawLine(self._spacing, yPos-self._spacing/2+toAdd, width-self._spacing, yPos-self._spacing/2+toAdd)

        # Draw the footer and footer bitmap (if any)
        dc.SetTextForeground(normalText)
        height = max(textHeight, bmpHeight)
        yPos += toAdd
        if footer:
            dc.DrawText(footer, bmpXPos+bmpWidth+self._spacing, yPos + (height-textHeight+self._spacing)/2)
        if footerBmp and footerBmp.IsOk():
            dc.DrawBitmap(footerBmp, bmpXPos, yPos + (height-bmpHeight+self._spacing)/2, True)
    def OnPaint(self, event):
        """ Handles the wx.EVT_PAINT event for CustomCheckBox. """

        dc = wx.BufferedPaintDC(self)
        self.Draw(dc)
Beispiel #10
0
 def OnPaint(self, event):
     if self.IsShown():
         dc = wx.BufferedPaintDC(self)
         self.Draw(dc)
    def OnPaint(self, event):
        """
        Handles the ``wx.EVT_PAINT`` event for L{AquaButton}.

        :param `event`: a `wx.PaintEvent` event to be processed.
        """

        dc = wx.BufferedPaintDC(self)
        gc = wx.GraphicsContext.Create(dc)

        xpos, ypos, width, height = self.GetClientRect()
        
        dc.SetBackground(wx.Brush(self.GetParent().GetBackgroundColour()))        
        dc.Clear()
        gc.SetBrush(wx.WHITE_BRUSH)

        shadowOffset = 5
        btnOffset = 0
        clr = self._backColour
        
        if self._mouseAction == CLICK:
            shadowOffset = 3
            clr = self._hoverColour
            btnOffset = 2

        elif self._mouseAction == HOVER:
            clr = self._hoverColour
        
        rc1 = wx.Rect(btnOffset, btnOffset, width-8-btnOffset, height-8-btnOffset)
        path1 = self.GetPath(gc, rc1, 10)
        br1 = gc.CreateLinearGradientBrush(0, 0, 0, rc1.height+6, clr, wx.WHITE)
        
        # Create shadow
        rc2 = wx.Rect(*rc1)
        rc2.Offset((shadowOffset, shadowOffset))
        path2 = self.GetPath(gc, rc2, 10)        
        br2 = gc.CreateRadialGradientBrush(rc2.x, rc2.y,
                                           rc2.x+rc2.width, rc2.y+rc2.height,
                                           rc2.width, wx.NamedColour("grey"), wx.WHITE)

        # Create top water colour to give "aqua" effect
        rc3 = wx.Rect(*rc1)
        rc3.Inflate(-5, -5)
        rc3.height = 15
        path3 = self.GetPath(gc, rc3, 10)
        
        br3 = gc.CreateLinearGradientBrush(rc3.x, rc3.y, rc3.x, rc3.y+rc3.height,
                                           wx.Colour(255, 255, 255, 255), wx.Colour(255, 255, 255, 0))

        # draw shapes
        gc.SetBrush(br2)
        gc.FillPath(path2)  #draw shadow
        gc.SetBrush(br1)
        gc.FillPath(path1) #draw main
        gc.SetBrush(br3)
        gc.FillPath(path3) #draw top bubble

        font = gc.CreateFont(self.GetFont(), self._textColour)
        
        gc.SetFont(font)
        label = self.GetLabel()
        tw, th = gc.GetTextExtent(label)

        if self._bitmap:
            bw, bh = self._bitmap.GetWidth(), self._bitmap.GetHeight()
        else:
            bw = bh = 0
            
        pos_x = (width-bw-tw)/2+btnOffset-shadowOffset      # adjust for bitmap and text to centre        
        if self._bitmap:
            pos_y =  (height-bh-shadowOffset)/2+btnOffset
            gc.DrawBitmap(self._bitmap, pos_x, pos_y, bw, bh) # draw bitmap if available
            pos_x = pos_x + 2   # extra spacing from bitmap

        # Create a Path to draw the text
        gc.DrawText(label, pos_x + bw + btnOffset, (height-th-shadowOffset)/2+btnOffset)      # draw the text

        if self._saveBitmap:
            # Save the bitmap using wx.MemoryDC for later use
            self._saveBitmap = False
            memory = wx.MemoryDC()
            self._storedBitmap = wx.EmptyBitmapRGBA(width, height)
            memory.SelectObject(self._storedBitmap)
            
            gcMemory = wx.GraphicsContext.Create(memory)

            gcMemory.SetBrush(br1)
            gcMemory.FillPath(path1) #draw main
            gcMemory.SetBrush(br3)
            gcMemory.FillPath(path3) #draw top bubble

            if self._bitmap:
                gcMemory.DrawBitmap(self._bitmap, pos_x - 2, pos_y, bw, bh)

            gcMemory.SetFont(font)
            gcMemory.DrawText(label, pos_x + bw + btnOffset, (height-th-shadowOffset)/2+btnOffset)

            memory.SelectObject(wx.NullBitmap)
            self._storedBitmap = self._storedBitmap.ConvertToImage()
Beispiel #12
0
	def OnPaint(self, event):
		"""
		Handles the ``wx.EVT_PAINT`` event for L{CalendarHeatmap}.

		:param `event`: a `wx.PaintEvent` event to be processed.
		"""

		dc = wx.BufferedPaintDC(self)
		
		self._getGridDate()
		self._setDimensions( dc )
		
		am = AM.ArtManager()
		
		gc = wx.GraphicsContext.Create(dc)

		dc.SetBackground(wx.Brush(self.GetParent().GetBackgroundColour()))
		dc.Clear()
		
		colour = self.GetForegroundColour()
		textColour = am.DarkColour(wx.WHITE, 3.0) if am.IsDark(colour) else am.LightColour(wx.BLACK, 3.0)
		
		valueMax = max( v for v in self.dates.values() )
		
		gc = wx.GraphicsContext.Create(dc)
		
		for r, w in enumerate('MTWTFSS'):
			x, y = self.leftLabelRect.GetX(), self.leftLabelRect.GetY() + self.rowHeight*r
			width = dc.GetTextExtent(w)[0]
			dc.DrawText( w, x + (self.leftLabelRect.GetWidth() - width) // 2, y )
		
		if self.date:
			x, y = self._xyFromDate( self.date )
			dText = '{}: {}'.format( self.date.strftime('%Y-%m-%d'), self.dates.get(self.date, 0) )
			width = dc.GetTextExtent( dText )[0]
			if x+width > self.bodyRect.GetRight():
				x = self.bodyRect.GetRight() - width
			dc.DrawText( dText, x, self.bottomLabelRect.GetY() )
		else:
			dText = '{}'.format( self.year )
			dc.DrawText( dText, self.bottomLabelRect.GetX(), self.bottomLabelRect.GetY() )
		
		backgrounds = [wx.Brush(wx.Colour(200,200,200), wx.SOLID), wx.Brush(wx.Colour(230,230,230), wx.SOLID)]
		monthCur = 0
		gc.SetPen( wx.TRANSPARENT_PEN )
		for d in daterange(datetime.date(self.year, 1, 1), datetime.date(self.year+1, 1, 1)):
			x, y = self._xyFromDate( d )
			gc.SetBrush( backgrounds[d.month&1] if d != self.date else wx.GREEN_BRUSH )			
			gc.DrawRectangle( x, y, self.rowHeight, self.rowHeight )
			
			s = self.dates.get(d, None)
			if s:
				gc.SetBrush( wx.RED_BRUSH )
				size = max(3, self.rowHeight * sqrt((float(s) / valueMax)))
				cc = (self.rowHeight - size) / 2
				gc.DrawEllipse( x + cc, y + cc, size, size )
			
			if d.month != monthCur:
				y = self.topLabelRect.GetY()
				dc.DrawText( d.strftime('%b'), x, y )
				monthCur = d.month
		
		if self.dateSelect:
			x, y = self._xyFromDate( self.dateSelect )
			gc.SetBrush( wx.TRANSPARENT_BRUSH )
			gc.SetPen( wx.Pen(wx.BLACK, 2) )
			gc.DrawRectangle( x-1, y-1, self.rowHeight+1, self.rowHeight+1 )
Beispiel #13
0
 def onPaint(self, evt):
     dc = wx.BufferedPaintDC(self, self.buffer)  # @UnusedVariable
Beispiel #14
0
 def paintRegion(self, evt):
     if self.bitmap:
         dc = wx.BufferedPaintDC(self)
         dc.DrawBitmap(self.bitmap, 0, 0)
Beispiel #15
0
    def on_paint(self, event):
        """Handle the paint event"""
        assert isinstance(event, wx.PaintEvent)
        paint_dc = wx.BufferedPaintDC(self)
        if self.schmutzy:
            self.recalc()
        width, height = self.GetSize()
        rn = wx.RendererNative.Get()
        background_color = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW)
        background_brush = wx.Brush(background_color)
        paint_dc.SetBrush(background_brush)
        paint_dc.Clear()
        paint_dc.SetFont(self.GetFont())
        paint_dc.SetBackgroundMode(wx.PENSTYLE_TRANSPARENT)
        has_focus = self.FindFocus() == self
        if has_focus:
            dir_color = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HOTLIGHT)
        else:
            dir_color = wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT)

        enabled_color = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)
        disabled_color = wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT)
        if len(self) == 0:
            text = self.DROP_FILES_AND_FOLDERS_HERE
            font = self.DROP_FILES_AND_FOLDERS_FONT
            paint_dc.SetTextForeground(
                wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT))
            paint_dc.SetFont(font)
            text_width, text_height = paint_dc.GetTextExtent(text)
            paint_dc.DrawText(text, (width - text_width) / 2,
                              (height - text_height) / 2)
            paint_dc.SetFont(self.GetFont())

        selected_text = wx.SystemSettings.GetColour(
            wx.SYS_COLOUR_HIGHLIGHTTEXT)
        try:
            x = self.GetScrollPos(wx.SB_HORIZONTAL)
            y = self.GetScrollPos(wx.SB_VERTICAL)
            line_height = self.line_height + self.leading
            yline = min(y, len(self))
            yline_max = min(yline + (height + line_height - 1) // line_height,
                            len(self))
            sel_width = 0
            #
            # Precompute the width of the selection rectangle
            #
            for idx in range(yline + 1, yline_max):
                item, pidx = self[idx]
                if item is None:
                    break
                if pidx is None:
                    continue
                if self.show_idx_as_selected(idx) or self.focus_item == idx:
                    item_width = paint_dc.GetTextExtent(
                        item.file_display_names[pidx])[0]
                    sel_width = max(sel_width, item_width)

            #
            # Paint the strings
            #
            for idx in range(yline, yline_max):
                yy = (idx - yline) * line_height
                item, pidx = self[idx]
                if item is None:
                    break
                if pidx is None or idx == yline:
                    # A directory
                    paint_dc.SetTextForeground(dir_color)
                    rTreeItem = wx.Rect(-x, yy, self.TREEITEM_WIDTH,
                                        self.TREEITEM_HEIGHT)
                    rn.DrawTreeItemButton(
                        self,
                        paint_dc,
                        rTreeItem,
                        wx.CONTROL_EXPANDED if item.opened else 0,
                    )
                    paint_dc.DrawText(
                        item.folder_display_name,
                        self.TREEITEM_WIDTH + self.TREEITEM_GAP - x,
                        yy,
                    )
                else:
                    # A file
                    selected = self.show_idx_as_selected(idx)
                    flags = wx.CONTROL_FOCUSED if has_focus else 0
                    if selected:
                        flags += wx.CONTROL_SELECTED
                    if idx == self.focus_item:
                        flags += wx.CONTROL_CURRENT
                    cellprofiler.gui.draw_item_selection_rect(
                        self,
                        paint_dc,
                        wx.Rect(
                            self.TREEITEM_WIDTH - x,
                            yy,
                            sel_width + 2 * self.TREEITEM_GAP,
                            line_height,
                        ),
                        flags,
                    )
                    if selected:
                        paint_dc.SetTextForeground(selected_text)
                    else:
                        paint_dc.SetTextForeground(
                            enabled_color if item.
                            enabled[pidx] else disabled_color)
                    paint_dc.DrawText(
                        item.file_display_names[pidx],
                        self.TREEITEM_WIDTH + self.TREEITEM_GAP - x,
                        yy,
                    )
        finally:
            paint_dc.SetBrush(wx.NullBrush)
            paint_dc.SetFont(wx.NullFont)
            background_brush.Destroy()
            paint_dc.Destroy()
Beispiel #16
0
    def OnPaint(self, event):
        if "wxGTK" in wx.PlatformInfo:
            mdc = wx.AutoBufferedPaintDC(self)

        else:
            rect = self.GetRect()
            mdc = wx.BufferedPaintDC(self)

        selected = 0

        if 'wxMac' in wx.PlatformInfo and wx.VERSION < (3, 0):
            color = wx.Colour(0, 0, 0)
            brush = wx.Brush(color)

            from Carbon.Appearance import kThemeBrushDialogBackgroundActive
            brush.MacSetTheme(kThemeBrushDialogBackgroundActive)
        else:
            color = wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DFACE)
            brush = wx.Brush(color)

        if "wxGTK" not in wx.PlatformInfo:
            mdc.SetBackground(brush)
            mdc.Clear()

        selected = None

        tabsWidth = 0

        for tab in self.tabs:
            tabsWidth += tab.tabWidth - self.inclination * 2

        pos = tabsWidth

        if self.showAddButton:
            ax, ay = self.addButton.GetPosition()
            mdc.DrawBitmap(self.addButton.Render(), ax, ay, True)

        for i in xrange(len(self.tabs) - 1, -1, -1):
            tab = self.tabs[i]
            width = tab.tabWidth - 6
            posx, posy = tab.GetPosition()

            if not tab.IsSelected():
                mdc.DrawBitmap(self.efxBmp, posx, posy, True)
                bmp = tab.Render()
                img = bmp.ConvertToImage()
                img = img.AdjustChannels(1, 1, 1, 0.85)
                bmp = wx.BitmapFromImage(img)
                mdc.DrawBitmap(bmp, posx, posy, True)

            else:
                selected = tab

        if selected:
            posx, posy = selected.GetPosition()
            mdc.DrawBitmap(self.efxBmp, posx, posy, True)

            bmp = selected.Render()

            if self.dragging:
                img = bmp.ConvertToImage()
                img = img.AdjustChannels(1.2, 1.2, 1.2, 0.7)
                bmp = wx.BitmapFromImage(img)

            mdc.DrawBitmap(bmp, posx, posy, True)
Beispiel #17
0
 def _on_paint(self, event):
     wx.BufferedPaintDC(self, self.buffer_image, wx.BUFFER_VIRTUAL_AREA)
Beispiel #18
0
 def on_paint(self, event):
     wx.BufferedPaintDC(self, self.buffer)
Beispiel #19
0
 def OnPaint(self, evt):
     dc = wx.BufferedPaintDC(self, self.buffer)
    def OnPaint(self, event):
        """
        Handles the ``wx.EVT_PAINT`` event for :class:`SuperToolTip`.
        
        If the `event` parameter is ``None``, calculates best size and returns it. 

        :param `event`: a :class:`PaintEvent` event to be processed or ``None``.
        """

        maxWidth = 0
        if event is None:
            dc = wx.ClientDC(self)
        else:
            # Go with double buffering...
            dc = wx.BufferedPaintDC(self)

        frameRect = self.GetClientRect()
        x, y, width, _height = frameRect
        # Store the rects for the hyperlink lines
        self._hyperlinkRect, self._hyperlinkWeb = [], []
        classParent = self._classParent

        # Retrieve the colours for the blended triple-gradient background
        topColour, middleColour, bottomColour = classParent.GetTopGradientColour(), \
                                                classParent.GetMiddleGradientColour(), \
                                                classParent.GetBottomGradientColour()

        # Get the user options for header, bitmaps etc...
        drawHeader, drawFooter = classParent.GetDrawHeaderLine(), classParent.GetDrawFooterLine()
        topRect = wx.Rect(frameRect.x, frameRect.y, frameRect.width, frameRect.height/2)
        bottomRect = wx.Rect(frameRect.x, frameRect.y+frameRect.height/2, frameRect.width, frameRect.height/2+1)
        # Fill the triple-gradient
        dc.GradientFillLinear(topRect, topColour, middleColour, wx.SOUTH)
        dc.GradientFillLinear(bottomRect, middleColour, bottomColour, wx.SOUTH)

        header, headerBmp = classParent.GetHeader(), classParent.GetHeaderBitmap()
        headerFont, messageFont, footerFont, hyperlinkFont = classParent.GetHeaderFont(), classParent.GetMessageFont(), \
                                                             classParent.GetFooterFont(), classParent.GetHyperlinkFont()

        yPos = 0
        bmpXPos = 0
        bmpHeight = textHeight = bmpWidth = 0

        if headerBmp and headerBmp.IsOk():
            # We got the header bitmap
            bmpHeight, bmpWidth = headerBmp.GetHeight(), headerBmp.GetWidth()
            bmpXPos = self._spacing

        if header:
            # We got the header text
            dc.SetFont(headerFont)
            textWidth, textHeight = dc.GetTextExtent(header)
        maxWidth = max(bmpWidth+(textWidth+self._spacing*3), maxWidth)
        # Calculate the header height
        height = max(textHeight, bmpHeight)
        if header:
            dc.DrawText(header, bmpXPos+bmpWidth+self._spacing, (height-textHeight+self._spacing)/2)
        if headerBmp and headerBmp.IsOk():
            dc.DrawBitmap(headerBmp, bmpXPos, (height-bmpHeight+self._spacing)/2, True)

        if header or (headerBmp and headerBmp.IsOk()):
            yPos += height
            if drawHeader:
                # Draw the separator line after the header
                dc.SetPen(wx.GREY_PEN)
                dc.DrawLine(self._spacing, yPos+self._spacing, width-self._spacing, yPos+self._spacing)
                yPos += self._spacing
                
        maxWidth = max(bmpXPos + bmpWidth + self._spacing, maxWidth)
        # Get the big body image (if any)
        embeddedImage = classParent.GetBodyImage()
        bmpWidth = bmpHeight = -1
        if embeddedImage and embeddedImage.IsOk():
            bmpWidth, bmpHeight = embeddedImage.GetWidth(), embeddedImage.GetHeight()
        
        # A bunch of calculations to draw the main body message
        messageHeight = 0
        lines = classParent.GetMessage().split("\n")
        yText = yPos
        embImgPos = yPos
        normalText = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUTEXT)
        hyperLinkText = wx.BLUE
        messagePos = self._getTextExtent(dc, lines[0] if lines else "")[1] / 2 + self._spacing
        for line in lines:
            # Loop over all the lines in the message
            if line.startswith("<hr>"):     # draw a line
                yText += self._spacing * 2
                dc.DrawLine(self._spacing, yText+self._spacing, width-self._spacing, yText+self._spacing)
            else:
                isLink = False
                dc.SetTextForeground(normalText)
                if line.startswith("</b>"):      # is a bold line
                    line = line[4:]
                    font = MakeBold(messageFont)
                    dc.SetFont(font)
                elif line.startswith("</l>"):    # is a link
                    dc.SetFont(hyperlinkFont)
                    isLink = True
                    line, hl = ExtractLink(line)
                    dc.SetTextForeground(hyperLinkText)
                else:
                    # Is a normal line
                    dc.SetFont(messageFont)
    
                textWidth, textHeight = self._getTextExtent(dc, line)
    
                messageHeight += textHeight
                
                xText = (bmpWidth + 2 * self._spacing) if bmpWidth > 0 else self._spacing
                yText += textHeight / 2 + self._spacing
                maxWidth = max(xText + textWidth + self._spacing, maxWidth)
                dc.DrawText(line, xText, yText)
                if isLink:
                    self._storeHyperLinkInfo(xText, yText, textWidth, textHeight, hl)

        toAdd = 0
        if bmpHeight > messageHeight:
            yPos += 2*self._spacing + bmpHeight
            toAdd = self._spacing
        else:
            yPos += messageHeight + 2*self._spacing

        yText = max(messageHeight, bmpHeight+2*self._spacing)
        if embeddedImage and embeddedImage.IsOk():
            # Draw the main body image
            dc.DrawBitmap(embeddedImage, self._spacing, embImgPos + (self._spacing * 2), True)

        footer, footerBmp = classParent.GetFooter(), classParent.GetFooterBitmap()
        bmpHeight = bmpWidth = textHeight = textWidth = 0
        bmpXPos = 0

        if footerBmp and footerBmp.IsOk():
            # Got the footer bitmap
            bmpHeight, bmpWidth = footerBmp.GetHeight(), footerBmp.GetWidth()
            bmpXPos = self._spacing

        if footer:
            # Got the footer text
            dc.SetFont(footerFont)
            textWidth, textHeight = dc.GetTextExtent(footer)

        if textHeight or bmpHeight:
            if drawFooter:
                # Draw the separator line before the footer
                dc.SetPen(wx.GREY_PEN)
                dc.DrawLine(self._spacing, yPos-self._spacing/2+toAdd, 
                            width-self._spacing, yPos-self._spacing/2+toAdd)
        # Draw the footer and footer bitmap (if any)
        dc.SetTextForeground(normalText)
        height = max(textHeight, bmpHeight)
        yPos += toAdd
        if footer:
            toAdd = (height - textHeight + self._spacing) / 2
            dc.DrawText(footer, bmpXPos + bmpWidth + self._spacing, yPos + toAdd)
            maxWidth = max(bmpXPos + bmpWidth + (self._spacing*2) + textWidth, maxWidth)
        if footerBmp and footerBmp.IsOk():
            toAdd = (height - bmpHeight + self._spacing) / 2
            dc.DrawBitmap(footerBmp, bmpXPos, yPos + toAdd, True)
            maxWidth = max(footerBmp.GetSize().GetWidth() + bmpXPos, maxWidth)
        
        maxHeight = yPos + height + toAdd
        if event is None:
            return maxWidth, maxHeight
Beispiel #21
0
class Track(wx.Panel):
    """
	A class representing a track in the timeline
	"""
    def __init__(self, name, parent, **kws):
        wx.Panel.__init__(self, parent, -1, style=wx.SIMPLE_BORDER)
        self.paintOverlay = 0
        self.overlayColor = ((255, 255, 255), 25)
        self.number = 0
        self.duration = 0
        self.frames = 0
        self.closed = 0
        self.bold = 0
        self.height = 80
        self.startOfTrack = 0
        self.editable = 1
        self.selectedItem = None
        self.dragItem = None
        self.SetBackgroundColour((255, 255, 255))
        self.control = kws["control"]
        self.splineEditor = self.control.getSplineEditor()
        self.label = name
        self.previtem = None
        if kws.has_key("height"):
            #print "Setting height to ",kws["height"]
            self.height = kws["height"]
        if kws.has_key("editable"):
            self.editable = kws["editable"]
        self.timescale = kws["timescale"]
        if kws.has_key("number"):
            self.number = kws["number"]

        self.overlayPosInPixels = 0
        self.overlayPosInPixelsEnd = 0
        self.overlayPos = -1
        self.overlayItem = None

        self.color = None
        self.parent = parent

        self.enabled = 1
        w, h = self.parent.GetSize()
        d = self.control.getDuration()
        self.width = d * self.timescale.getPixelsPerSecond(
        ) + self.getLabelWidth()

        self.buffer = wx.EmptyBitmap(self.width, self.height)
        self.SetMinSize((self.width, self.height))
        self.dragEndPosition = 0

        self.items = []
        self.itemAmount = 0
        self.oldNamePanelColor = 0

        self.initTrack()
        self.timePos = -1
        self.timePosItem = None
        self.timePosInPixels = 0
        self.timePosInPixelsEnd = 0

        self.Bind(wx.EVT_MOTION, self.onDrag)
        self.Bind(wx.EVT_LEFT_DOWN, self.onDown)
        self.Bind(wx.EVT_LEFT_UP, self.onUp)

        self.Bind(wx.EVT_PAINT, self.onPaint)

        self.renew = 0
        s = self.control.getFrames()
        #print "duration=",d,"frames=",s
        self.setDuration(d, s)
        self.paintTrack()
        lib.messenger.connect(None, "show_time_pos", self.onShowTimePosition)

    def getStartOfTrack(self):
        """
		return the starting position of track, in pixels
		"""
        return self.startOfTrack

    def onShowTimePosition(self, obj, evt, arg):
        """
		Show the frame position
		"""
        #print "showtimePos",obj,evt,arg
        self.timePos = arg
        # When renew=2 it means that only the time position needs to be re-drawn
        self.renew = 2

    def onPaint(self, event):
        """
		Blit the buffer
		"""
        if self.renew:
            try:
                self.paintTrack()
            except Exception, e:
                Logging.backtrace()
                Logging.info("Failed to paint track", kw="animator")
                event.Skip()
            self.renew = False
        print "Buffered painting", self.buffer.GetWidth(
        ), self.buffer.GetHeight()
        print self.GetSize()
        dc = wx.BufferedPaintDC(self, self.buffer)
Beispiel #22
0
	def OnPaint(self, event):
		dc = wx.BufferedPaintDC(self, self.buffer, wx.BUFFER_VIRTUAL_AREA)
Beispiel #23
0
 def OnPaint(self, evt):
     dc = wx.BufferedPaintDC(self)
     self.Draw(dc, self.GetSize())
Beispiel #24
0
    def OnPaint(self, event):
        """
		Does the actual blitting of the bitmap
		"""
        dc = wx.BufferedPaintDC(self, self.buffer)  #, self.buffer)
Beispiel #25
0
	def OnDraw(self, e):
		dc = wx.BufferedPaintDC(self, self.backBuffer)
Beispiel #26
0
 def OnPaint(self, evt):
     dc = wx.BufferedPaintDC(self)
     dc.Clear()
     self.Paint(dc)
Beispiel #27
0
 def onPaint(self, event):
     dc = wx.BufferedPaintDC(self, self.buffer)
Beispiel #28
0
 def OnPaint(self, evt):
     dc = wx.BufferedPaintDC(self)
     dc.DrawBitmap(self.bmp, 0, 0)
 def OnDraw(self, e):
     dc = wx.BufferedPaintDC(self, self._backgroundImage)
Beispiel #30
0
 def OnPaint(self, event):
     """ Handles the wx.EVT_PAINT event for MyChessButton. """
     dc = wx.BufferedPaintDC(self)
     self.Draw(dc)