Example #1
0
    def OnPaint(self, event):
        """
        Handles the ``wx.EVT_PAINT`` event for :class:`RibbonToolBar`.

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

        dc = wx.AutoBufferedPaintDC(self)

        if self._art == None:
            return

        self._art.DrawToolBarBackground(dc, self, wx.Rect(0, 0, *self.GetSize()))

        for group in self._groups:
            tool_count = len(group.tools)

            if tool_count != 0:            
                self._art.DrawToolGroupBackground(dc, self, wx.RectPS(group.position, group.size))

                for tool in group.tools:
                    rect = wx.RectPS(group.position + tool.position, tool.size)

                    if tool.state & RIBBON_TOOLBAR_TOOL_DISABLED:
                        self._art.DrawTool(dc, self, rect, tool.bitmap_disabled, tool.kind, tool.state)
                    else:
                        self._art.DrawTool(dc, self, rect, tool.bitmap, tool.kind, tool.state)
Example #2
0
def test_Rect():
    r = wx.Rect()
    attrs = 'X Y x y Width Height width height'.split()
    assert all(0 == val for val in (getattr(r, a) for a in attrs))

    r2 = wx.Rect(1, 2, 3, 4)
    assert r2.x == r2.GetX() == 1
    assert r2.y == r2.GetY() == 2
    assert r2.width == r2.GetWidth() == r2.Width == 3
    assert r2.height == r2.GetHeight() == r2.Height == 4

    assert r2[:2] == r2.Position

    assert r2.TopLeft == r2.GetTopLeft() == wx.Point(1, 2)
    assert r2.TopRight == r2.GetTopRight() == wx.Point(3, 2)
    assert r2.BottomLeft == r2.GetBottomLeft() == wx.Point(1, 5)
    assert r2.BottomRight == r2.GetBottomRight() == wx.Point(3, 5)

    assert r2 == (1, 2, 3, 4)
    assert r2 != (4, 3, 2, 1)

    r3 = wx.RectPS(wx.Point(20, 30), wx.Size(40, 50))
    r4 = wx.RectPS((20, 30), (40, 50))
    assert r3 == r4

    r5 = r3.Inflate(10, 10)

    r6 = wx.Rect(40, 40, 20, 20)
    r6.Offset((20, -10))
    assert r6 == (60, 30, 20, 20)
Example #3
0
    def paint_bitmap(self, dc, pickerPos=None):
        '''
        If dc is None, returns a PIL image
        '''

        bw, bh = self.bitmap.Width, self.bitmap.Height

        # get the 0,0 point of the image if centered
        imagecenter = Point(self.Rect.Width / 2, self.Rect.Height / 2) - Point(
            bw / 2, bh / 2)

        # adjust away from center
        xy = imagecenter + (self.adjustment[0] * bw, self.adjustment[1] * bh)

        # adjust the offset by how far into the picture the selection is
        #        if pickerPos:
        #            xy[0] += pickerPos[0]; xy[1] += pickerPos[1]

        if dc is not None:
            #            dc.SetBrush(wx.TRANSPARENT_BRUSH) #@UndefinedVariable
            #            dc.SetPen(wx.RED_PEN) #@UndefinedVariable
            dc.DrawBitmap(self.bitmap, *xy)


#            dc.DrawRectangleRect(cropRect)
        else:

            pickWidth = int(self.picksize[0])
            pickHeight = int(self.picksize[1])
            pickRect = wx.RectPS(
                pickerPos or ((self.Rect.width // 2 - self.picksize[0] // 2),
                              (self.Rect.height // 2 - self.picksize[1] // 2)),
                (pickWidth, pickHeight))
            pickRect.Position -= xy
            imageRect = wx.RectPS((0, 0), (bw, bh))
            cropRect = imageRect.Intersect(pickRect)

            crop_box = (cropRect.left, cropRect.top, cropRect.right,
                        cropRect.bottom)

            croppedImage = self.bitmap.PIL.crop(crop_box)
            #            croppedImage.Show("croppedImage")

            offsetX = max(-(pickRect.x - cropRect.x), 0)
            offsetY = max(-(pickRect.y - cropRect.y), 0)
            if (offsetX or offsetY):
                paddedImage = Image.new('RGBA',
                                        (pickRect.width, pickRect.height),
                                        (0, 0, 0, 0))
                paddedImage.paste(croppedImage, (offsetX, offsetY))
                return paddedImage

            return croppedImage
Example #4
0
    def on_capture(self):
        self.slider.Enable(True)
        dragger = self.dragger
        self.Freeze()

        try:
            if config.platform == 'win':
                try:
                    from cgui import getScreenBitmap
                except ImportError:
                    print_exc()
                    return

                bitmap = getScreenBitmap(
                    wx.RectPS(dragger.ScreenRect.Position, dragger.ClientSize))
            else:
                screendc = wx.ScreenDC()
                bitmap = screendc.GetAsBitmap()

            if bitmap is not None:
                self.set_image(wx.ImageFromBitmap(bitmap))

            s = self.slider
            s.Value = (s.Max - s.Min) / 2
        finally:
            wx.CallAfter(self.ThawLater)
    def DrawHorzBand(self, dc, rect):
        """ Draw Vertical bands - No falloff effect for vertical bands. """

        horzBands = (self._ledBands > 1 and [self._ledBands]
                     or [self._maxValue * BAND_PERCENT / 100])[0]
        minHorzLimit = self._minValue * horzBands / self._maxValue
        medHorzLimit = self._medValue * horzBands / self._maxValue
        maxHorzLimit = horzBands

        size = wx.Size(rect.width / horzBands, rect.height / self._numBands)
        rectBand = wx.RectPS(rect.GetTopLeft(), size)

        # Draw band from top
        rectBand.OffsetXY(0, rect.height - size.y * self._numBands)
        xDecal = (self._ledBands > 1 and [1] or [0])[0]
        yDecal = (self._numBands > 1 and [1] or [0])[0]

        for vert in xrange(self._numBands):

            self._value = self._meterData[vert]._value
            horzLimit = self._value * horzBands / self._maxValue

            for horz in xrange(horzBands):

                rectBand.Deflate(0, yDecal)

                # Find color based on range value
                colorRect = self._clrBackground
                if self._showGrid:
                    colorRect = DarkenColor(self._clrBackground,
                                            GRID_INCREASEBY)

                if self._showGrid and (horz == minHorzLimit
                                       or horz == (horzBands - 1)):

                    points = [wx.Point() for i in xrange(2)]
                    points[0].x = rectBand.GetTopLeft().x + (
                        rectBand.width >> 1)
                    points[0].y = rectBand.GetTopLeft().y - yDecal
                    points[1].x = points[0].x
                    points[1].y = rectBand.GetBottomRight().y + yDecal
                    dc.DrawLinePoint(points[0], points[1])

                if horz < horzLimit:

                    if InRange(horz, 0, minHorzLimit - 1):
                        colorRect = self._clrNormal
                    elif InRange(horz, minHorzLimit, medHorzLimit - 1):
                        colorRect = self._clrMedium
                    elif InRange(horz, medHorzLimit, maxHorzLimit):
                        colorRect = self._clrHigh

                dc.SetBrush(wx.Brush(colorRect))
                dc.DrawRectangleRect(rectBand)

                rectBand.Inflate(0, yDecal)
                rectBand.OffsetXY(size.x, 0)

            # Move to Next Vertical band
            rectBand.OffsetXY(-size.x * horzBands, size.y)
    def ShowExpanded(self):
        """
        Show the panel externally expanded.

        When a panel is minimised, it can be shown full-size in a pop-out window, which
        is refered to as being (externally) expanded.

        :returns: ``True`` if the panel was expanded, ``False`` if it was not (possibly
         due to it not being minimised, or already being expanded).

        :note: When a panel is expanded, there exist two panels - the original panel
         (which is refered to as the dummy panel) and the expanded panel. The original
         is termed a dummy as it sits in the ribbon bar doing nothing, while the expanded
         panel holds the panel children.
         
        :see: :meth:`~RibbonPanel.HideExpanded`, :meth:`~RibbonPanel.GetExpandedPanel`
        """

        if not self.IsMinimised():        
            return False
        
        if self._expanded_dummy != None or self._expanded_panel != None:        
            return False

        size = self.GetBestSize()
        pos = self.GetExpandedPosition(wx.RectPS(self.GetScreenPosition(), self.GetSize()), size, self._preferred_expand_direction).GetTopLeft()

        # Need a top-level frame to contain the expanded panel
        container = wx.Frame(None, wx.ID_ANY, self.GetLabel(), pos, size, wx.FRAME_NO_TASKBAR | wx.BORDER_NONE)

        self._expanded_panel = RibbonPanel(container, wx.ID_ANY, self.GetLabel(), self._minimised_icon, wx.Point(0, 0), size, self._flags)
        self._expanded_panel.SetArtProvider(self._art)
        self._expanded_panel._expanded_dummy = self

        # Move all children to the new panel.
        # Conceptually it might be simpler to reparent self entire panel to the
        # container and create a new panel to sit in its place while expanded.
        # This approach has a problem though - when the panel is reinserted into
        # its original parent, it'll be at a different position in the child list
        # and thus assume a new position.
        # NB: Children iterators not used as behaviour is not well defined
        # when iterating over a container which is being emptied
        
        for child in self.GetChildren(): 
            child.Reparent(self._expanded_panel)
            child.Show()
        

        # Move sizer to new panel
        if self.GetSizer():
            sizer = self.GetSizer()
            self.SetSizer(None, False)
            self._expanded_panel.SetSizer(sizer)

        self._expanded_panel.Realize()
        self.Refresh()
        container.Show()
        self._expanded_panel.SetFocus()

        return True
Example #7
0
    def OnPaint(self, event):
        """
            Painting when skined, otherwise it lets the system handle it
        """
        if self.native:
            event.Skip()
            return

        dc = wx.AutoBufferedPaintDC(self)

        rect = wx.RectS(self.Size)

        #Background drawing
        if self.bg:
            self.bg.Draw(dc, rect)

        rect.width = int(float(self.value) / float(self.range) * self.Size.x)

        #forground drawing
        if self.repeat:
            curser = wx.Point(self.padding, 0)
            while curser.x < self.fill:
                self.fg.Draw(dc, wx.RectPS(curser,
                                           (self.fg.width, rect.height)))
                curser.x += self.fg.width + self.padding

        else:
            self.fg.Draw(dc, wx.RectS((self.fill, rect.height)))
Example #8
0
    def OnMouseMotion(self, event):
        """
            Ensures mouse in and mouse out capture events occure, also handels
            hover for the button and link
        """

        #If the left mouse button is not down, make sure the panel gets/losses
        # capture accordingly
        if not event.LeftIsDown():
            mouseisin = wx.FindWindowAtPointer() is self

            if mouseisin and not self.HasCapture():
                self.OnMouseIn(event)

            elif not mouseisin and self.HasCapture():
                self.OnMouseOut(event)

        #Handle button statethings on mouse over
        if not self.Parent.ShowAll and self.HasCapture() and self.buttonshown:
            bstate = self.buttonstate
            bisdown = self.buttonisdown
            mouseinb = wx.RectPS(self.riconpos,
                                 (16, 16)).Contains(event.Position)
            if bstate == 0 and mouseinb:
                self.buttonstate = 2 if bisdown else 1
                self.Refresh()
            elif bstate in (1, 2) and not mouseinb:
                self.buttonstate = 0
                self.Refresh()

        #handle link mouseover
        mouseinl = self.linkhovered = self.linkrect.Contains(event.Position)
        self.SetCursor(
            wx.StockCursor(wx.CURSOR_HAND if mouseinl else wx.CURSOR_DEFAULT))
Example #9
0
 def OnSize(self, event):
     if self.aui.GetPane("filebrowser").IsShown(
     ):  # Adjust overflow state of file browser toolbar if visible
         wx.CallAfter(self.filebrowser.GetSizer().Layout)
     if self.HasCapture():
         self.rect = wx.RectPS(self.GetPosition(), self.GetSize())
     event.Skip()
Example #10
0
    def OnPaint(self, event):

        dc = wx.AutoBufferedPaintDC(self)

        if self._art == None:
            return

        self._art.DrawToolBarBackground(dc, self, wx.Rect(0, 0, *self.GetSize()))

        for group in self._groups:
            tool_count = len(group.tools)

            if tool_count != 0:            
                self._art.DrawToolGroupBackground(dc, self, wx.RectPS(group.position, group.size))

                for tool in group.tools:
                    rect = wx.RectPS(group.position + tool.position, tool.size)
                    self._art.DrawTool(dc, self, rect, tool.bitmap, tool.kind, tool.state)
 def OnSize(self, evt):
     if not self._managedChild:
         return
     sz = self.GetSize()
     self._managedChild.SetRect(
         wx.RectPS((0, 0), sz - (RW_THICKNESS, RW_THICKNESS)))
     r = wx.Rect(sz.width - RW_LENGTH, sz.height - RW_LENGTH, RW_LENGTH,
                 RW_LENGTH)
     r.Inflate(2, 2)
     self.RefreshRect(r)
Example #12
0
 def OnSize(self, evt):
     if not self._managedChild:
         return
     sz = self.GetSize()
     cr = wx.RectPS((0, 0), sz - (RW_THICKNESS, RW_THICKNESS))
     self._managedChild.SetRect(cr)
     r1 = wx.Rect(0, cr.height, sz.width, RW_THICKNESS)
     r2 = wx.Rect(cr.width, 0, RW_THICKNESS, sz.height)
     self.RefreshRect(r1)
     self.RefreshRect(r2)
Example #13
0
    def OnPaint(self, event):
        dc = wx.AutoBufferedPaintDC(self)
        rect = wx.RectPS(wx.Point(0, 0), self.GetSize())

        if self.content:
            skin = self.content.skinCML
            skin["frame"].Draw(dc, rect)
        else:
            dc.SetBrush(wx.BLACK_BRUSH)  #@UndefinedVariable
            dc.SetPen(wx.TRANSPARENT_PEN)  #@UndefinedVariable
            dc.DrawRectangleRect(rect)
Example #14
0
    def SetPopupRect(self, popup, rect, quick=False):
        t = int(self.slidetime)
        if t == 0: quick = True

        oldrect = popup.Rect

        if quick:
            popup.SetRect(rect)
        else:
            if oldrect.Size != rect.Size:
                popup.SetRect(wx.RectPS(oldrect.Position, rect.Size))

            move_smoothly(popup, rect.Position, time=t)
Example #15
0
    def SetEnabled(self, val):
        """
            Enable or disable docking, called by buddy list when the pref changes.
        """

        if not isinstance(val, bool):
            raise TypeError('Enabled must be a boolean')

        self._enabled = val

        #turn docking off docking
        if not val and self.docked:
            self.Undock()
            p = self.dockedRect[:2]
            self.docking = self.docked = self.autohidden = False
            wx.CallLater(50, self.SetRectSimple, wx.Rect(p[0],p[1], *wx.Size(*self.oldSize)))

            self.UpdateTaskbar()

        #turn docking on
        elif val and not self.docked and self.win.IsShownOnScreen():
            self.docking = False

            #emulate a motion event to initiate docking if the buddylist is in position
            if self.OnMoving():

                #emulate a finished moving event to finish docking procedure
                self.OnExitSizeMove()

                #if autohide preference is set, start timer to autohide the buddylist
                if self.AutoHide:
                    self.timer.Start(AUTOHIDE_TIMER_MS)
                    self.motiontrigger = False

                self.win.SetRect(self.dockedRect)

        elif self.wasDocked:
            SetToolStyle(self.win,val)
            self.bypassMoveEvents = True
            if val:
                self.win.Rect = self.dockedRect
            else:
                self.win.Rect = wx.RectPS(self.dockedRect.Position, self.oldSize)
            self.bypassMoveEvents = False

            self.UpdateTaskbar()


        if not val:
            self.oldSize = None
Example #16
0
    def OnPaint(self, e):
        e.Skip()
        icon, dc = self.icon, wx.PaintDC(self)
        if icon is not None:
            # draw a centered buddy icon
            w, h = self.Size
            assert isinstance(icon, wx.Bitmap), str(type(icon))

            icopos = (w / 2 - icon.Width / 2, h / 2 - icon.Height / 2)

            dc.DrawBitmap(icon, *icopos)

            dc.Brush = wx.TRANSPARENT_BRUSH
            dc.Pen = wx.Pen(wx.Color(213, 213, 213))
            dc.DrawRectangleRect(wx.RectPS(icopos, (icon.Width, icon.Height)))
Example #17
0
    def Display(self,rect):
        'Set Position and popup'

        pos = rect.BottomLeft
        newrect = wx.RectPS(pos, self.Size)

        screenrect = Monitor.GetFromRect(newrect).ClientArea

        if newrect.bottom > screenrect.bottom:
            pos.y -= rect.height + self.Size.height
        if newrect.right > screenrect.right:
            pos.x += rect.width - self.Size.width

        self.SetPosition(pos) # Position property doesn't work for PopTransWin
        self.Popup()
Example #18
0
    def __DrawSection(self, dc):
        if not self._imgProxy.IsOk():
            return

        sectRect = self.__SectRectToClientRect()

        dc.SetBrush(wx.TRANSPARENT_BRUSH)
        iRect = wx.RectPS(sectRect.GetPosition(), sectRect.GetSize())
        dc.SetPen(wx.WHITE_PEN)
        iRect.Inflate(1, 1)
        dc.DrawRectangleRect(iRect)

        # draw background
        color = wx.Colour(0, 0, 0, 153)
        dc.SetBrush(wx.Brush(color))
        dc.SetPen(wx.TRANSPARENT_PEN)  # wx.Pen(color))
        # left
        left, top = self.__GetBmpTopLeft()
        bmpWidth, bmpHeight = self._imgProxy.GetCurrentSize()
        dc.DrawRectangle(left, top, iRect.x - left, bmpHeight)
        lWidth = left + bmpWidth - iRect.GetWidth() - iRect.x
        left = iRect.x + iRect.GetWidth()
        dc.DrawRectangle(left, top, lWidth, bmpHeight)
        dc.DrawRectangle(iRect.x, top, iRect.GetWidth(), iRect.y - top)
        dc.DrawRectangle(iRect.x, iRect.y + iRect.GetHeight(),
                         iRect.GetWidth(),
                         top + bmpHeight - iRect.GetHeight() - iRect.y)

        now = time.time()
        alpha = 255
        if now - self._lastRectUpdate > self.INFO_TIME_OUT / 2:
            alpha = (1 - ((now - self._lastRectUpdate) - (self.INFO_TIME_OUT / 2)) / (self.INFO_TIME_OUT / 2)) * 255
            alpha = int(round(alpha))
        if alpha < 0:
            alpha = 0
        dc.SetTextForeground(wx.Colour(255, 255, 255, alpha))
        font = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FIXED_FONT)
        font.SetPointSize(16)
        font.SetWeight(wx.BOLD)
        dc.SetFont(font)
        dc.SetPen(wx.WHITE_PEN)
        dc.SetBrush(wx.TRANSPARENT_BRUSH)
        dc.DrawRectangleRect(sectRect)
        dc.DrawLabel("%d, %d - %d x %d" % tuple(self._sectRect),
                     sectRect,
                     wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL)
Example #19
0
    def ShowExpanded(self):

        if not self.IsMinimised():
            return False

        if self._expanded_dummy != None or self._expanded_panel != None:
            return False

        size = self.GetBestSize()
        pos = self.GetExpandedPosition(
            wx.RectPS(self.GetScreenPosition(), self.GetSize()), size,
            self._preferred_expand_direction).GetTopLeft()

        # Need a top-level frame to contain the expanded panel
        container = wx.Frame(None, wx.ID_ANY, self.GetLabel(), pos, size,
                             wx.FRAME_NO_TASKBAR | wx.BORDER_NONE)

        self._expanded_panel = RibbonPanel(container, wx.ID_ANY,
                                           self.GetLabel(),
                                           self._minimised_icon,
                                           wx.Point(0, 0), size, self._flags)
        self._expanded_panel.SetArtProvider(self._art)
        self._expanded_panel._expanded_dummy = self

        # Move all children to the new panel.
        # Conceptually it might be simpler to reparent self entire panel to the
        # container and create a new panel to sit in its place while expanded.
        # This approach has a problem though - when the panel is reinserted into
        # its original parent, it'll be at a different position in the child list
        # and thus assume a new position.
        # NB: Children iterators not used as behaviour is not well defined
        # when iterating over a container which is being emptied

        for child in self.GetChildren():
            child.Reparent(self._expanded_panel)
            child.Show()

        # TODO: Move sizer to new panel
        self._expanded_panel.Realize()
        self.Refresh()
        container.Show()
        self._expanded_panel.SetFocus()

        return True
Example #20
0
    def OnPaint(self, event):

        dc = wx.AutoBufferedPaintDC(self)
        self._art.DrawButtonBarBackground(dc, self, wx.Rect(0, 0, *self.GetSize()))

        layout = self._layouts[self._current_layout]

        for button in layout.buttons:
            base = button.base

            bitmap = base.bitmap_large
            bitmap_small = base.bitmap_small
            
            if base.state & RIBBON_BUTTONBAR_BUTTON_DISABLED:            
                bitmap = base.bitmap_large_disabled
                bitmap_small = base.bitmap_small_disabled

            rect = wx.RectPS(button.position + self._layout_offset, base.sizes[button.size].size)
            self._art.DrawButtonBarButton(dc, self, rect, base.kind, base.state | button.size, base.label, bitmap, bitmap_small)
Example #21
0
 def getRect(self, obj):
     rects = [wx.RectPS(obj.GetPosition(), obj.GetSize())]
     for sizerItem in obj.GetChildren():
         rect = sizerItem.GetRect()
         rects.append(rect)
         # Add lines to show borders
         flag = sizerItem.GetFlag()
         border = sizerItem.GetBorder()
         if border == 0: continue
         x = (rect.GetLeft() + rect.GetRight()) / 2
         if flag & wx.TOP:
             rects.append(wx.Rect(x, rect.GetTop() - border, 0, border))
         if flag & wx.BOTTOM:
             rects.append(wx.Rect(x, rect.GetBottom() + 1, 0, border))
         y = (rect.GetTop() + rect.GetBottom()) / 2
         if flag & wx.LEFT:
             rects.append(wx.Rect(rect.GetLeft() - border, y, border, 0))
         if flag & wx.RIGHT:
             rects.append(wx.Rect(rect.GetRight() + 1, y, border, 0))
     return rects
Example #22
0
    def PopUp(self, rect):
        self.rect = rect
        monarea = Monitor.GetFromRect(rect).ClientArea

        below = wx.Point(rect.BottomLeft)
        above = wx.Point(rect.TopLeft - wx.Point(0, self.frame.Size.height))

        if getattr(self, 'valign', 'bottom') == 'top':
            prefer, second = above, below
        else:
            prefer, second = below, above

        if monarea.ContainsRect(wx.RectPS(prefer, self.frame.Size)):
            chose = prefer
        else:
            chose = second

        self.frame.SetPosition(chose)

        if not hasattr(self, 'valign'):
            self.valign = 'bottom' if chose == below else 'top'

        return self.frame.ShowNoActivate(True)
Example #23
0
    def DrawVertBand(self, dc, rect):
        """
        Draws vertical bands.

        :param `dc`: an instance of :class:`DC`;
        :param `rect`: the vertical bands client rectangle.
        """

        vertBands = (self._ledBands > 1 and [self._ledBands]
                     or [self._maxValue * BAND_PERCENT / 100])[0]
        minVertLimit = self._minValue * vertBands / self._maxValue
        medVertLimit = self._medValue * vertBands / self._maxValue
        maxVertLimit = vertBands

        size = wx.Size(rect.width / self._numBands, rect.height / vertBands)
        rectBand = wx.RectPS(rect.GetTopLeft(), size)

        # Draw band from bottom
        rectBand.OffsetXY(0, rect.bottom - size.y)
        xDecal = (self._numBands > 1 and [1] or [0])[0]
        yDecal = (self._ledBands > 1 and [1] or [0])[0]

        for horz in xrange(self._numBands):

            self._value = self._meterData[horz]._value
            vertLimit = self._value * vertBands / self._maxValue
            rectPrev = wx.Rect(*rectBand)

            for vert in xrange(vertBands):

                rectBand.Deflate(xDecal, 0)

                # Find colour based on range value
                colourRect = self._clrBackground
                if self._showGrid:
                    colourRect = DarkenColour(self._clrBackground,
                                              GRID_INCREASEBY)

                # Draw grid line (level) bar
                if self._showGrid and (vert == minVertLimit
                                       or vert == (vertBands - 1)):

                    points = [wx.Point() for i in xrange(2)]
                    points[0].x = rectBand.GetTopLeft().x - xDecal
                    points[0].y = rectBand.GetTopLeft().y + (
                        rectBand.height >> 1)
                    points[1].x = rectBand.GetBottomRight().x + xDecal
                    points[1].y = points[0].y
                    dc.DrawLinePoint(points[0], points[1])

                if vert < vertLimit:

                    if InRange(vert, 0, minVertLimit - 1):
                        colourRect = self._clrNormal
                    elif InRange(vert, minVertLimit, medVertLimit - 1):
                        colourRect = self._clrMedium
                    elif InRange(vert, medVertLimit, maxVertLimit):
                        colourRect = self._clrHigh

                dc.SetBrush(wx.Brush(colourRect))
                dc.DrawRectangleRect(rectBand)

                rectBand.Inflate(xDecal, 0)
                rectBand.OffsetXY(0, -size.y)

            # Draw falloff effect
            if self._showFalloff:

                oldPen = dc.GetPen()
                pen = wx.Pen(DarkenColour(self._clrBackground,
                                          FALL_INCREASEBY))
                maxHeight = size.y * vertBands
                points = [wx.Point() for i in xrange(2)]
                points[0].x = rectPrev.GetTopLeft().x + xDecal
                points[0].y = rectPrev.GetBottomRight().y - self._meterData[
                    horz]._falloff * maxHeight / self._maxValue
                points[1].x = rectPrev.GetBottomRight().x - xDecal
                points[1].y = points[0].y
                dc.SetPen(pen)
                dc.DrawLinePoint(points[0], points[1])
                dc.SetPen(oldPen)

            # Move to Next Horizontal band
            rectBand.OffsetXY(size.x, size.y * vertBands)
Example #24
0
    def SetPosition(self, x, y, size):

        self._position = wx.RectPS(wx.Point(x, y), size)
Example #25
0
    def Layout(self):

        if self._art == None:
            return False

        dc = wx.MemoryDC()
        origin = wx.Point()

        client_size, origin, self._scroll_up_button_rect, self._scroll_down_button_rect, self._extension_button_rect = \
                     self._art.GetGalleryClientSize(dc, self, wx.Size(*self.GetSize()))

        self._client_rect = wx.RectPS(origin, client_size)

        x_cursor = y_cursor = 0
        art_flags = self._art.GetFlags()

        for indx, item in enumerate(self._items):

            item.SetIsVisible(True)

            if art_flags & RIBBON_BAR_FLOW_VERTICAL:
                if y_cursor + self._bitmap_padded_size.y > client_size.GetHeight(
                ):
                    if y_cursor == 0:
                        break

                    y_cursor = 0
                    x_cursor += self._bitmap_padded_size.x

                item.SetPosition(origin.x + x_cursor, origin.y + y_cursor,
                                 self._bitmap_padded_size)
                y_cursor += self._bitmap_padded_size.y

            else:
                if x_cursor + self._bitmap_padded_size.x > client_size.GetWidth(
                ):
                    if x_cursor == 0:
                        break

                    x_cursor = 0
                    y_cursor += self._bitmap_padded_size.y

                item.SetPosition(origin.x + x_cursor, origin.y + y_cursor,
                                 self._bitmap_padded_size)
                x_cursor += self._bitmap_padded_size.x

        for item in self._items[indx:]:
            item.SetIsVisible(False)

        if art_flags & RIBBON_BAR_FLOW_VERTICAL:
            self._scroll_limit = x_cursor
        else:
            self._scroll_limit = y_cursor

        if self._scroll_amount >= self._scroll_limit:
            self._scroll_amount = self._scroll_limit
            self._down_button_state = RIBBON_GALLERY_BUTTON_DISABLED

        elif self._down_button_state == RIBBON_GALLERY_BUTTON_DISABLED:
            self._down_button_state = RIBBON_GALLERY_BUTTON_NORMAL

        if self._scroll_amount <= 0:
            self._scroll_amount = 0
            self._up_button_state = RIBBON_GALLERY_BUTTON_DISABLED

        elif self._up_button_state == RIBBON_GALLERY_BUTTON_DISABLED:
            self._up_button_state = RIBBON_GALLERY_BUTTON_NORMAL

        return True
Example #26
0
    def GetExpandedPosition(self, panel, expanded_size, direction):

        # Strategy:
        # 1) Determine primary position based on requested direction
        # 2) Move the position so that it sits entirely within a display
        #    (for single monitor systems, this moves it into the display region,
        #     but for multiple monitors, it does so without splitting it over
        #     more than one display)
        # 2.1) Move in the primary axis
        # 2.2) Move in the secondary axis

        primary_x = False
        secondary_x = secondary_y = 0
        pos = wx.Point()

        if direction == wx.NORTH:
            pos.x = panel.GetX() + (panel.GetWidth() -
                                    expanded_size.GetWidth()) / 2
            pos.y = panel.GetY() - expanded_size.GetHeight()
            primary_x = True
            secondary_y = 1

        elif direction == wx.EAST:
            pos.x = panel.GetRight()
            pos.y = panel.GetY() + (panel.GetHeight() -
                                    expanded_size.GetHeight()) / 2
            secondary_x = -1

        elif direction == wx.SOUTH:
            pos.x = panel.GetX() + (panel.GetWidth() -
                                    expanded_size.GetWidth()) / 2
            pos.y = panel.GetBottom()
            primary_x = True
            secondary_y = -1

        else:
            pos.x = panel.GetX() - expanded_size.GetWidth()
            pos.y = panel.GetY() + (panel.GetHeight() -
                                    expanded_size.GetHeight()) / 2
            secondary_x = 1

        expanded = wx.RectPS(pos, expanded_size)
        best = wx.Rect(*expanded)
        best_distance = 10000

        display_n = wx.Display.GetCount()

        for display_i in xrange(display_n):
            display = wx.Display(display_i).GetGeometry()
            if display.ContainsRect(expanded):
                return expanded

            elif display.Intersects(expanded):
                new_rect = wx.Rect(*expanded)
                distance = 0

                if primary_x:
                    if expanded.GetRight() > display.GetRight():
                        distance = expanded.GetRight() - display.GetRight()
                        new_rect.x -= distance

                    elif expanded.GetLeft() < display.GetLeft():
                        distance = display.GetLeft() - expanded.GetLeft()
                        new_rect.x += distance

                else:
                    if expanded.GetBottom() > display.GetBottom():
                        distance = expanded.GetBottom() - display.GetBottom()
                        new_rect.y -= distance

                    elif expanded.GetTop() < display.GetTop():
                        distance = display.GetTop() - expanded.GetTop()
                        new_rect.y += distance

                if not display.Contains(new_rect):
                    # Tried moving in primary axis, but failed.
                    # Hence try moving in the secondary axis.
                    dx = secondary_x * (panel.GetWidth() +
                                        expanded_size.GetWidth())
                    dy = secondary_y * (panel.GetHeight() +
                                        expanded_size.GetHeight())
                    new_rect.x += dx
                    new_rect.y += dy

                    # Squaring makes secondary moves more expensive (and also
                    # prevents a negative cost)
                    distance += dx * dx + dy * dy

                if display.Contains(new_rect) and distance < best_distance:
                    best = new_rect
                    best_distance = distance

        return best
Example #27
0
 def AdjustRect(self, tlw, win, rect):
     pos, j = self.FindHighlightPos(tlw, win.ClientToScreen(rect.Position))
     rect.Position = pos
     return wx.RectPS(pos, rect.Size)
Example #28
0
    def HighlightSizer(self, sizer):
        # first do the outline of the whole sizer like normal
        win = sizer.GetContainingWindow()
        tlw = win.GetTopLevelParent()
        pos = sizer.GetPosition()
        pos, useWinDC = self.FindHighlightPos(tlw, win.ClientToScreen(pos))
        rect = wx.RectPS(pos, sizer.GetSize())
        dc = self.DoHighlight(tlw, rect, self.color1, useWinDC)

        # Now highlight the actual items within the sizer.  This may
        # get overdrawn by the code below for item boundaries, but if
        # there is border padding then this will help make it more
        # obvious.
        dc.SetPen(wx.Pen(self.color3, 1))
        for item in sizer.GetChildren():
            if item.IsShown():
                if item.IsWindow():
                    r = item.GetWindow().GetRect()
                elif item.IsSizer():
                    p = item.GetSizer().GetPosition()
                    s = item.GetSizer().GetSize()
                    r = wx.RectPS(p, s)
                else:
                    continue
                r = self.AdjustRect(tlw, win, r)
                dc.DrawRectangleRect(r)

        # Next highlight the area allocated to each item in the sizer.
        # Each kind of sizer will need to be done a little
        # differently.
        dc.SetPen(wx.Pen(self.color2, 1))

        # wx.BoxSizer, wx.StaticBoxSizer
        if isinstance(sizer, wx.BoxSizer):
            # NOTE: we have to do some reverse-engineering here for
            # borders because the sizer and sizer item don't give us
            # enough information to know for sure where item
            # (allocated) boundaries are, just the boundaries of the
            # actual widgets. TODO: It would be nice to add something
            # to wx.SizerItem that would give us the full bounds, but
            # that will have to wait until 2.9...
            x, y = rect.GetPosition()
            if sizer.Orientation == wx.HORIZONTAL:
                y1 = y + rect.height
                for item in sizer.GetChildren():
                    ir = self.AdjustRect(tlw, win, item.Rect)
                    x = ir.x
                    if item.Flag & wx.LEFT:
                        x -= item.Border
                    dc.DrawLine(x, y, x, y1)
                    if item.IsSizer():
                        dc.DrawRectangleRect(ir)

            if sizer.Orientation == wx.VERTICAL:
                x1 = x + rect.width
                for item in sizer.GetChildren():
                    ir = self.AdjustRect(tlw, win, item.Rect)
                    y = ir.y
                    if item.Flag & wx.TOP:
                        y -= item.Border
                    dc.DrawLine(x, y, x1, y)
                    if item.IsSizer():
                        dc.DrawRectangleRect(ir)

        # wx.FlexGridSizer, wx.GridBagSizer
        elif isinstance(sizer, wx.FlexGridSizer):
            sizer.Layout()
            y = rect.y
            for rh in sizer.RowHeights[:-1]:
                y += rh
                dc.DrawLine(rect.x, y, rect.x + rect.width, y)
                y += sizer.VGap
                dc.DrawLine(rect.x, y, rect.x + rect.width, y)
            x = rect.x
            for cw in sizer.ColWidths[:-1]:
                x += cw
                dc.DrawLine(x, rect.y, x, rect.y + rect.height)
                x += sizer.HGap
                dc.DrawLine(x, rect.y, x, rect.y + rect.height)

        # wx.GridSizer
        elif isinstance(sizer, wx.GridSizer):
            # NOTE: More reverse engineering (see above.) This time we
            # need to determine what the sizer is using for row
            # heights and column widths.
            #rh = cw = 0
            #for item in sizer.GetChildren():
            #    rh = max(rh, item.Size.height)
            #    cw = max(cw, item.Size.width)
            cw = (rect.width - sizer.HGap * (sizer.Cols - 1)) / sizer.Cols
            rh = (rect.height - sizer.VGap * (sizer.Rows - 1)) / sizer.Rows
            y = rect.y
            for i in range(sizer.Rows - 1):
                y += rh
                dc.DrawLine(rect.x, y, rect.x + rect.width, y)
                y += sizer.VGap
                dc.DrawLine(rect.x, y, rect.x + rect.width, y)
            x = rect.x
            for i in range(sizer.Cols - 1):
                x += cw
                dc.DrawLine(x, rect.y, x, rect.y + rect.height)
                x += sizer.HGap
                dc.DrawLine(x, rect.y, x, rect.y + rect.height)

        # Anything else is probably a custom sizer, just highlight the items
        else:
            del dc
            for item in sizer.GetChildren():
                self.HighlightSizerItem(item, sizer, 1)
Example #29
0
def ScreenCapture(captureStartPos, captureBmapSize, debug=False):
    """
    General Desktop screen portion capture - partial or entire Desktop.

    My particular screen hardware configuration:
        wx.Display( 0 ) refers to the primary  Desktop display monitor screen.
        wx.Display( 1 ) refers to the extended Desktop display monitor screen (above the primary screen).

    Any particular Desktop screen size is :
        screenRect = wx.Display( n ).GetGeometry()

    Different wx.Display's in a single system may have different dimensions.
    """

    # A wx.ScreenDC provides access to the entire Desktop.
    # This includes any extended Desktop monitor screens that are enabled in the OS.
    scrDC = wx.ScreenDC(
    )  # MSW HAS BUG:  DOES NOT INCLUDE ANY EXTENDED SCREENS.
    scrDcSize = scrDC.Size
    scrDcSizeX, scrDcSizeY = scrDcSize

    # Cross-platform adaptations :
    scrDcBmap = scrDC.GetAsBitmap()
    scrDcBmapSize = scrDcBmap.GetSize()
    if debug:
        print 'DEBUG:  Size of scrDC.GetAsBitmap() ', scrDcBmapSize

    # Check if scrDC.GetAsBitmap() method has been implemented on this platform.
    if not scrDcBmap.IsOk(
    ):  # Not implemented :  Get the screen bitmap the long way.

        if debug:
            print 'DEBUG:  Using memDC.Blit() since scrDC.GetAsBitmap() is nonfunctional.'

        # Create a new empty (black) destination bitmap the size of the scrDC.
        scrDcBmap = wx.EmptyBitmap(
            *scrDcSize)  # Overwrire the invalid original assignment.
        scrDcBmapSizeX, scrDcBmapSizeY = scrDcSize

        # Create a DC tool that is associated with scrDcBmap.
        memDC = wx.MemoryDC(scrDcBmap)

        # Copy (blit, "Block Level Transfer") a portion of the screen bitmap
        #   into the returned capture bitmap.
        # The bitmap associated with memDC (scrDcBmap) is the blit destination.

        memDC.Blit(
            0,
            0,  # Copy to this start coordinate.
            scrDcBmapSizeX,
            scrDcBmapSizeY,  # Copy an area this size.
            scrDC,  # Copy from this DC's bitmap.
            0,
            0,
        )  # Copy from this start coordinate.

        memDC.SelectObject(wx.NullBitmap)  # Finish using this wx.MemoryDC.
        # Release scrDcBmap for other uses.
    else:

        if debug:
            print 'DEBUG:  Using scrDC.GetAsBitmap()'

        # This platform has scrDC.GetAsBitmap() implemented.
        scrDcBmap = scrDC.GetAsBitmap(
        )  # So easy !  Copy the entire Desktop bitmap.

        if debug:
            print 'DEBUG:  scrDcBmap.GetSize() ', scrDcBmap.GetSize()

    #end if

    return scrDcBmap.GetSubBitmap(wx.RectPS(captureStartPos, captureBmapSize))
Example #30
0
    def CalculateDockSizerLimits(self, dock):
        # Replacement for default calculation for min/max dock sizes. Instead
        # of adjusting the sizes of all the docks, only adjusts one to make the
        # dock insertion process a little more like what the user expected.

        docks, panes = aui.CopyDocksAndPanes2(self._docks, self._panes)

        sash_size = self._art.GetMetric(aui.AUI_DOCKART_SASH_SIZE)
        caption_size = self._art.GetMetric(aui.AUI_DOCKART_CAPTION_SIZE)
        opposite_size = self.GetOppositeDockTotalSize(docks,
                                                      dock.dock_direction)

        for tmpDock in docks:

            if tmpDock.dock_direction == dock.dock_direction and \
               tmpDock.dock_layer == dock.dock_layer and \
               tmpDock.dock_row == dock.dock_row:

                tmpDock.size = 1
                break
        neighbor_docks = []
        horizontal = dock.dock_direction == aui.AUI_DOCK_LEFT or dock.dock_direction == aui.AUI_DOCK_RIGHT
        right_or_down = dock.dock_direction == aui.AUI_DOCK_RIGHT or dock.dock_direction == aui.AUI_DOCK_BOTTOM
        for d in docks:
            if d.dock_direction == dock.dock_direction and d.dock_layer == dock.dock_layer:
                if horizontal:
                    neighbor_docks.append((d.rect.x, d.rect.width))
                else:
                    neighbor_docks.append((d.rect.y, d.rect.height))
        neighbor_docks.sort()

        sizer, panes, docks, uiparts = self.LayoutAll(panes, docks, [], True,
                                                      False)
        client_size = self._frame.GetClientSize()
        sizer.SetDimension(0, 0, client_size.x, client_size.y)
        sizer.Layout()

        for part in uiparts:

            part.rect = wx.RectPS(part.sizer_item.GetPosition(),
                                  part.sizer_item.GetSize())
            if part.type == aui.AuiDockUIPart.typeDock:
                part.dock.rect = part.rect

        sizer.Destroy()
        new_dock = None

        for tmpDock in docks:
            if tmpDock.dock_direction == dock.dock_direction and \
               tmpDock.dock_layer == dock.dock_layer and \
               tmpDock.dock_row == dock.dock_row:

                new_dock = tmpDock
                break

        partnerDock = self.GetPartnerDock(dock)

        if partnerDock:
            if horizontal:
                pos = dock.rect.x
                size = dock.rect.width
            else:
                pos = dock.rect.y
                size = dock.rect.height

            min_pos = pos
            max_pos = pos + size
            if right_or_down:
                for p, s in neighbor_docks:
                    if p >= pos:
                        max_pos = p + s - sash_size
                        break
                    else:
                        min_pos = p + sash_size
            else:
                for p, s in neighbor_docks:
                    if p > pos:
                        max_pos = p + s - sash_size
                        break
                    else:
                        min_pos = p + sash_size

            return min_pos, max_pos

        direction = new_dock.dock_direction

        if direction == aui.AUI_DOCK_LEFT:
            minPix = new_dock.rect.x + new_dock.rect.width
            maxPix = client_size.x - opposite_size - sash_size

        elif direction == aui.AUI_DOCK_TOP:
            minPix = new_dock.rect.y + new_dock.rect.height
            maxPix = client_size.y - opposite_size - sash_size

        elif direction == aui.AUI_DOCK_RIGHT:
            minPix = opposite_size
            maxPix = new_dock.rect.x - sash_size

        elif direction == aui.AUI_DOCK_BOTTOM:
            minPix = opposite_size
            maxPix = new_dock.rect.y - sash_size

        return minPix, maxPix