示例#1
0
    def __init__(self, config):
        window_config = config['window']
        title = window_config['title']
        self.background_color = wx.Colour(window_config['background'])

        self.assets = asset.load_assets(config.get('assets', []))

        full_region = wx.Region()
        for single_asset in self.assets.values():
            full_region.Union(single_asset.region)

        box = full_region.GetBox()
        for single_asset in self.assets.values():
            single_asset.move(-box.GetX(), -box.GetY())
        size = box.GetSize()

        style = wx.FRAME_NO_TASKBAR | wx.STAY_ON_TOP | wx.FRAME_SHAPED | wx.BORDER_NONE
        super(DeskyFrame, self).__init__(None, title=title, size=size, style=style)
        self.active_region = wx.Region()
        self.calculate_active_region()

        self.trigger = trigger.load_trigger(config.get('trigger', []))
        self.trigger = self.trigger.activate()

        self.timer = wx.Timer(self, 1)
        self.timer.StartOnce(self.trigger.millis_until_activation())

        self.Bind(wx.EVT_PAINT, self.on_paint)
        self.Bind(wx.EVT_TIMER, self.on_timer)
示例#2
0
    def updatePluginRegions(self, clientregion=None):
        if clientregion is None:
            clientregion = wx.Region(*self.rect)

        updates = []
        self.pluginsregion = wx.Region()
        for i, plugin in enumerate(self.plugins):
            if not plugin.enabled:
                plugin.region = wx.Region()
                updates.append(False)
            else:
                updates.append(plugin.onUpdateClientRegion(clientregion))
                if plugin.background:
                    plugin.region = wx.Region()
                    plugin.region.UnionRegion(clientregion)
                elif not plugin.ignoresize:
                    self.pluginsregion.UnionRegion(plugin.region)
            plugin.buffered = wx.Region()
            plugin.buffered.UnionRegion(plugin.region)
            plugin.buffered.IntersectRegion(clientregion)

            if not plugin.hasalpha:
                for p in self.plugins[:i]:
                    p.buffered.SubtractRegion(plugin.region)

        return updates
    def getRegion(self):
        if self.bitmap is None:
            return wx.Region()

        x = self.rect.x + self.imagewindow.rect.x - self.rect.width / 2.0
        y = self.rect.y + self.imagewindow.rect.y - self.rect.height / 2.0
        x = int(round(x))
        y = int(round(y))
        region = wx.Region(x, y, self.rect.width, self.rect.height)

        return region
示例#4
0
def diffRegion(region1, region2):
    equalregion = wx.Region()
    equalregion.UnionRegion(region1)
    equalregion.IntersectRegion(region2)
    minusregion = wx.Region()
    minusregion.UnionRegion(region1)
    minusregion.SubtractRegion(equalregion)
    plusregion = wx.Region()
    plusregion.UnionRegion(region2)
    plusregion.SubtractRegion(equalregion)
    return minusregion, equalregion, plusregion
示例#5
0
    def updateClientRegion(self, offset=None, size=None):
        # TODO: alpha updates
        if offset is None:
            offset = self.offset
        if size is None:
            size = self.size

        regions = [plugin.region for plugin in self.plugins]
        bufferedregions = [plugin.buffered for plugin in self.plugins]

        offset, size = self.updateScrollbars(offset=offset, size=size)

        x, y = offset
        width, height = size
        clientregion = wx.Region(x, y, width, height)

        updates = [p.onUpdateClientRegion(clientregion) for p in self.plugins]
        self.updatePluginRegions(clientregion=clientregion)

        copyregions = {}
        sourceregion = wx.Region()
        for i, plugin in enumerate(self.plugins):
            x1, y1, w1, h1 = regions[i].GetBox()
            x2, y2, w2, h2 = plugin.region.GetBox()
            doffset = wx.Point(x2 - x1, y2 - y1)
            if updates[i]:
                copyregion = wx.Region()
                copyregion.UnionRegion(bufferedregions[i])
                copyregion.Offset(doffset.x, doffset.y)
                copyregion.IntersectRegion(plugin.buffered)
                if doffset not in copyregions:
                    copyregions[doffset] = wx.Region()
                sourceregion.UnionRegion(plugin.buffered)
                sourceregion.SubtractRegion(copyregion)
                copyregion.Offset(-doffset.x, -doffset.y)
                copyregions[doffset].UnionRegion(copyregion)
            else:
                sourceregion.UnionRegion(plugin.buffered)

        buffer = wx.EmptyBitmap(size.width, size.height)

        dc = wx.MemoryDC()
        dc.SelectObject(buffer)
        dc.SetDeviceOrigin(-offset.x, -offset.y)
        self.copyBuffer(dc, copyregions)
        self.sourceBuffer(dc, sourceregion)
        dc.SelectObject(wx.NullBitmap)

        self.offset = offset
        self.size = size
        self.buffer = buffer

        self.Refresh()
示例#6
0
    def InitTabRegions(self):
        """
        Initializes regions for tab, which makes it easier to determine if
        given coordinates are included in a region
        """
        self.tab_region = wx.Region(self.tab_back_bitmap)
        self.close_region = wx.Region(self.ctab_close_bmp)

        x_offset = self.content_width \
            + self.left_width \
            - self.ctab_close_bmp.GetWidth() / 2
        y_offset = (self.tab_height - self.ctab_close_bmp.GetHeight()) / 2
        self.close_region.Offset(x_offset, y_offset)
 def getRegion(self, clientregion=None):
     if self.plugin.region.IsEmpty():
         return wx.Region()
     x, y, width, height = self.plugin.region.GetBox()
     center = (int(round(width / 2.0 + x - self.width / 2.0)),
               int(round(height / 2.0 + y - self.width / 2.0)))
     if clientregion is None:
         crect = self.imagewindow.rect
     else:
         crect = clientregion.GetBox()
     region = wx.Region()
     region.Union(center[0], crect.y, self.width, crect.height)
     region.Union(crect.x, center[1], crect.width, self.width)
     return region
示例#8
0
    def CopyRegion(self, region):
        rect = region.GetBox()

        new_region = wx.Region(rect.X, rect.Y, rect.Width, rect.Height)
        new_region.Intersect(region)

        return new_region
示例#9
0
    def __init__(self, **kwargs):

        #构造基类方法
        super(myFrame, self).__init__(**kwargs)

        self.SetWindowStyle(wx.FRAME_SHAPED | wx.SIMPLE_BORDER
                            | wx.FRAME_NO_TASKBAR)

        img = wx.Image(name="images/tiger1.png")
        bmp = img.ConvertToBitmap()

        clientSize = img.GetWidth(), img.GetHeight()

        self.SetClientSize(img.GetWidth(), img.GetHeight())
        self.SetClientSize(clientSize)

        dc = wx.ClientDC(self)
        #dc.DrawBitmap(img.ConvertToBitmap(),0,0)
        dc.DrawBitmap(bmp, 0, 0, useMask=True)

        r = wx.Region(bmp)
        self.SetShape(r)

        self.bmp = bmp
        self.Bind(wx.EVT_PAINT, self.onPaint)
示例#10
0
    def OnPaint(self, e):

        dc = wx.PaintDC(self)

        dc.SetPen(wx.Pen('#424242'))
        size_x, size_y = self.GetClientSize()
        dc.SetDeviceOrigin(size_x/2, size_y/2)

        points = (((0, 85), (75, 75), (100, 10), (125, 75), (200, 85),
            (150, 125), (160, 190), (100, 150), (40, 190), (50, 125)))

        region = wx.Region(points)
        dc.SetDeviceClippingRegion(region)

        radius = hypot(size_x/2, size_y/2)
        angle = 0

        while (angle < 2*pi):

            x = radius*cos(angle)
            y = radius*sin(angle)
            dc.DrawLine((0, 0), (x, y))
            angle = angle + 2*pi/360

        dc.DestroyClippingRegion()
示例#11
0
 def test_regionIterator2(self):
     region = wx.Region([(10, 10), (100, 100), (10, 100)])
     count = 0
     for rect in region:
         self.assertTrue(isinstance(rect, wx.Rect))
         count += 1
     self.assertTrue(count > 0)
示例#12
0
    def OnEraseBk(self,event):
        if self.GetItemCount() >0:
            width, height = self.GetClientSize()
            dc = event.GetDC()

            dc.DestroyClippingRegion()
            dc.SetClippingRegion(0, 0, width, height)
            x,y,w,h = dc.GetClippingBox()

            topItem = self.GetTopItem()
            bottomItem = topItem + self.GetCountPerPage()

            if bottomItem >= self.GetItemCount():
                bottomItem = self.GetItemCount() - 1

            topRect = self.GetItemRect(topItem, wx.LIST_RECT_LABEL)
            bottomRect = self.GetItemRect(bottomItem, wx.LIST_RECT_BOUNDS)


            items_rect = wx.Rect(topRect.left, 0, bottomRect.right - topRect.left, bottomRect.bottom )

            updateRegion = wx.Region(x,y,w,h)
            updateRegion.SubtractRect(items_rect)

            dc.DestroyClippingRegion()
            dc.SetClippingRegionAsRegion(updateRegion)

            dc.SetBackground(wx.Brush(self.GetBackgroundColour(), wx.SOLID))
            dc.Clear()

            dc.DestroyClippingRegion()

        else:
            event.Skip()
示例#13
0
    def __init__(self, window, pos, bitmaps, revision, showLanguages,
                 profiles):
        self._useGlass = isGlassEnabled()
        style = wx.DEFAULT_FRAME_STYLE & ~(wx.RESIZE_BORDER | wx.MAXIMIZE_BOX
                                           | wx.MINIMIZE_BOX)
        if not self.useGlass():
            style |= wx.FRAME_SHAPED

        wx.Frame.__init__(self, window, wx.ID_ANY, u'', pos, wx.DefaultSize,
                          style, _(u'Welcome to Digsby'))
        self._logoBitmap = bitmaps.logo
        self._helpBitmap = bitmaps.help
        self._settingsBitmap = bitmaps.settings
        self._languageBitmap = bitmaps.language

        self._helpHover = False
        self.revisionString = revision
        self._showRevision = False

        self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
        self.createComponents(showLanguages, profiles)

        self.setupGlass()
        if not self.useGlass():
            self.SetShape(
                wx.Region(0, 0,
                          self.GetClientSize().x,
                          self.GetClientSize().y))

        self.dragMixin = DragMixin(self.panel)
        self.panel.PushEventHandler(self.dragMixin)
示例#14
0
 def draw_scope(self, gcdc: wx.GCDC, x: int, y: int, lines: List[str]):
     magnification = CONSTANTS.UI.PREVIEW.MAGNIFIER_SCALING
     points = [(x - self.x_orig + cos(a * 6.283 / 15) * self.scope_radius,
                y - self.y_orig + sin(a * 6.283 / 15) * self.scope_radius)
               for a in range(15)]
     region = wx.Region(points)
     gcdc.SetDeviceClippingRegion(region)
     gcdc.SetLogicalOrigin(x - ((x - self.x_orig) / magnification),
                           y - ((y - self.y_orig) / magnification))
     gcdc.SetLogicalScale(self.scale * magnification,
                          self.scale * magnification)
     self.draw_content(gcdc, wx.Colour(*CONSTANTS.UI.PREVIEW.MEDIUM_GREY),
                       wx.Colour(*CONSTANTS.UI.PREVIEW.LIGHT_GREY))
     gcdc.DestroyClippingRegion()
     gcdc.SetLogicalOrigin(self.x_orig, self.y_orig)
     gcdc.SetLogicalScale(self.scale, self.scale)
     gcdc.SetBrush(wx.NullBrush)
     black = self.color_db.Find("BLACK")
     gcdc.SetPen(wx.Pen(black))
     gcdc.SetTextForeground(black)
     gcdc.DrawCircle(x, y, self.scope_radius)
     font_size = 0.02 * self.measure_to_twips
     gcdc.SetFont(
         wx.Font(font_size, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL,
                 wx.FONTWEIGHT_NORMAL))
     line_spacing = font_size * CONSTANTS.UI.PREVIEW.LINE_SPACING
     height = font_size + (line_spacing * (len(lines) - 1))
     y_pos = y - (height // 2)
     for text in lines:
         size = gcdc.GetTextExtent(text)
         gcdc.DrawText(text, x - (size.width // 2), y_pos)
         y_pos += line_spacing
示例#15
0
    def SetWindowTransparencies(self, opacity=100):

        if self.transparencyMode == 0:
            # Partial window (overall) transparency
            self.SetTransparent(opacity * 255 / 100)
            # Bitmap transparency enabled (cn't see background)
            self.bmap = self.bmap_convertedAlpha
            self.SetShape(wx.RegionFromBitmap(self.bmap))

        elif self.transparencyMode == 1:
            # No window transparency (what bitmaps mask shows is 100% opaque)
            self.SetTransparent(255)
            # Bitmap transparency enabled
            self.bmap = self.bmap_convertedAlpha
            self.SetShape(wx.RegionFromBitmap(self.bmap))

        elif self.transparencyMode == 2:
            # No window transparency (what is seen is 100% opaque)
            self.SetTransparent(255)
            # Bitmap transparency mask is disabled
            self.bmap = self.bmap_unconvertedAplha
            self.SetShape(wx.Region())

        self.transparencyMode += 1
        if self.transparencyMode > 2: self.transparencyMode = 0
示例#16
0
 def test_regionOtherRandomStuff(self):
     region = wx.Region([(10, 10), (100, 100), (10, 100)])
     bmp = wx.Bitmap(pngFile)
     region.Union(bmp)
     region.Contains(10, 20)
     region.Contains(wx.Point(10, 20))
     region.Contains(wx.Rect(10, 20, 4, 4))
     region.Subtract(wx.Rect(10, 20, 4, 4))
示例#17
0
 def test_regionCtors(self):
     r = wx.Region()
     r = wx.Region(10, 10, 100, 100)
     r = wx.Region(wx.Point(10, 10), wx.Point(100, 100))
     r = wx.Region(wx.Rect(10, 10, 100, 100))
     r2 = wx.Region(r)
     r = wx.Region([(10, 10), (100, 10), (100, 100), (10, 100)])
     bmp = wx.Bitmap(pngFile)
     r = wx.Region(bmp)
     r = wx.Region(bmp, 'black')
示例#18
0
 def sourceBuffer(self, dc, sourceregion=None):
     for plugin in self.plugins:
         region = wx.Region()
         region.UnionRegion(plugin.buffered)
         if sourceregion is not None:
             region.IntersectRegion(sourceregion)
         if not region.IsEmpty():
             plugin.draw(dc, region)
             '''
 def __init__(self, imagewindow):
     Plugin.__init__(self, imagewindow)
     self.region = wx.Region()
     self.array = None
     self.scale = 1.0
     self.rect = self.getRect()
     self.extrema = None
     self.valuerange = None
     self.fitclient = False
示例#20
0
 def test_regionIterator1(self):
     region = wx.Region([(10, 10), (100, 100), (10, 100)])
     iterator = wx.RegionIterator(region)
     count = 0
     while iterator:
         rect = iterator.GetRect()
         self.assertTrue(isinstance(rect, wx.Rect))
         iterator.Next()
         count += 1
     self.assertTrue(count > 0)
    def getRegion(self):
        if self.bitmap is None:
            return wx.Region()

        crect = self.imagewindow.rect

        rect = wx.Rect(*self.rect)

        if rect.x - crect.x < crect.width / 2:
            rect.x += self.offsets[0][0]
        else:
            rect.x -= self.rect.width + self.offsets[0][1]

        if rect.y - crect.y < crect.size.height / 2:
            rect.y += self.offsets[1][0]
        else:
            rect.y -= self.rect.height + self.offsets[1][1]

        return wx.Region(*rect)
示例#22
0
    def SetBalloonShape(self, event=None):
        width, height = self.GetSize()
        bmp = wx.EmptyBitmap(width, height)
        dc = wx.BufferedDC(None, bmp)
        dc.SetBackground(wx.Brush(wx.Colour(0, 0, 0), wx.SOLID))
        dc.Clear()

        dc.DrawRoundedRectangle(0, 0, width - 1, height - 1, 4)

        r = wx.Region(bmp, wx.Colour(0, 0, 0))
        self.hasShape = self.SetShape(r)
示例#23
0
    def onUpdateClientRegion(self, clientregion):
        if self.array is None:
            return False

        size = self.getSize(clientregion)
        copy = self.size == size
        self.size = size
        self.offset = self.getOffset(clientregion)
        (x, y), (width, height) = self.offset, self.size
        self.region = wx.Region(x, y, width, height)
        return copy
示例#24
0
 def test_DCClipper(self):
     dc = wx.ClientDC(self.frame)
     c = wx.DCClipper(dc, wx.Rect(10,10,25,25))
     del c
     c = wx.DCClipper(dc, (10,10,25,25))
     del c
     c = wx.DCClipper(dc, 10,10,25,25)
     del c
     r = wx.Region(10,10,25,25)
     c = wx.DCClipper(dc, r)
     del c
    def onUpdateClientRegion(self, clientregion):
        Plugin.onUpdateClientRegion(self, clientregion)

        if self.array is None:
            return False

        size = wx.Size(*self.rect.size)
        self.rect = self.getRect(clientregion)
        self.region = wx.Region(*self.rect)

        return size == self.rect.size
示例#26
0
    def __init__(self, parent, message, title, icon):
        """
        Default class constructor.
        
        :param `parent`: the frame parent;
        :param `message`: the message to display in the :class:`PyBusyInfo`;
        :param `title`: the main :class:`PyBusyInfo` title;
        :param `icon`: an icon to draw as the frame icon, an instance of :class:`Bitmap`.
        """

        wx.Frame.__init__(
            self, parent, wx.ID_ANY, title, wx.DefaultPosition, wx.DefaultSize,
            wx.NO_BORDER | wx.FRAME_TOOL_WINDOW | wx.FRAME_SHAPED
            | wx.STAY_ON_TOP)

        panel = wx.Panel(self)
        panel.SetCursor(wx.HOURGLASS_CURSOR)

        self._message = message
        self._title = title
        self._icon = icon

        dc = wx.ClientDC(self)
        textWidth, textHeight, dummy = dc.GetFullMultiLineTextExtent(
            self._message)
        sizeText = wx.Size(textWidth, textHeight)

        self.SetClientSize(
            (max(sizeText.x, 340) + 60, max(sizeText.y, 40) + 60))
        # need to size the panel correctly first so that text.Centre() works
        panel.SetSize(self.GetClientSize())

        # Bind the events to draw ourselves
        panel.Bind(wx.EVT_PAINT, self.OnPaint)
        panel.Bind(wx.EVT_ERASE_BACKGROUND, self.OnErase)

        self.Centre(wx.BOTH)

        # Create a non-rectangular region to set the frame shape
        size = self.GetSize()
        bmp = wx.Bitmap(size.x, size.y)
        dc = wx.BufferedDC(None, bmp)
        dc.SetBackground(wx.Brush(wx.Colour(0, 0, 0)))
        dc.Clear()
        dc.SetPen(wx.Pen(wx.Colour(0, 0, 0), 1))
        dc.DrawRoundedRectangle(0, 0, size.x, size.y, 12)
        r = wx.Region(bmp, wx.Colour(0, 0, 0))
        # Store the non-rectangular region
        self.reg = r

        if wx.Platform == "__WXGTK__":
            self.Bind(wx.EVT_WINDOW_CREATE, self.SetBusyShape)
        else:
            self.SetBusyShape()
示例#27
0
    def __init__(self, parent, title, x, y, w, h):
        wx.Frame.__init__(self, parent, title=title,style = wx.FRAME_SHAPED | wx.STAY_ON_TOP)
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        image = wx.Image('redwhiteframe.png', wx.BITMAP_TYPE_PNG)
        image = image.Scale(w, h, wx.IMAGE_QUALITY_HIGH)
        self.bitmap = image.ConvertToBitmap()

        self.SetClientSize(image.GetSize())
        region = wx.Region(self.bitmap,wx.Colour(255,255,255))
        self.SetShape(region)
        self.SetPosition(wx.Point(x, y))
示例#28
0
    def updatePluginRegions(self, clientregion=None):
        if clientregion is None:
            x, y, = self.offset
            width, height = self.size
            clientregion = wx.Region(x, y, width, height)

        self.pluginsregion = wx.Region()

        for i, plugin in enumerate(self.plugins):
            if plugin.background:
                plugin.region = wx.Region()
                plugin.region.UnionRegion(clientregion)
            else:
                self.pluginsregion.UnionRegion(plugin.region)
            plugin.buffered = wx.Region()
            plugin.buffered.UnionRegion(plugin.region)
            plugin.buffered.IntersectRegion(clientregion)

            if not plugin.hasalpha:
                for p in self.plugins[:i]:
                    p.buffered.SubtractRegion(plugin.region)
示例#29
0
 def SetWindowShape(self, *event):
     # Use the bitmap's mask to determine the region
     if PHOENIX:
         r = wx.Region(self.bmp,
                       transColour=wx.Colour(255, 255, 255, 0),
                       tolerance=0)
     else:
         self.bmp
         mask = wx.Mask(self.bmp, wx.Colour(255, 255, 255, 0))
         self.bmp.SetMask(mask)
         r = wx.RegionFromBitmap(self.bmp)
     self.hasShape = self.SetShape(r)
示例#30
0
def cuthole(ctrl):
    top = wx.GetTopLevelParent(ctrl)
    x = ctrl.ScreenRect.X - top.ScreenRect.X
    y = ctrl.ScreenRect.Y - top.ScreenRect.Y
    w, h = ctrl.ClientSize

    winsz = top.Size
    region = wx.Region(0, 0, winsz[0], y)
    region.UnionRect((0, 0, x, winsz[1]))
    region.UnionRect((x + w, y, winsz[0] - w - x, h))
    region.UnionRect((0, y + h, winsz[0], winsz[1] - h - y))

    ApplySmokeAndMirrors(top, region)